invoice_item_edit.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. /* $Id$ */
  3. /*
  4. Copyright (C) 2008-2013 Mark J Crane
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions are met:
  8. 1. Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions and the following disclaimer in the
  12. documentation and/or other materials provided with the distribution.
  13. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
  14. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  15. AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16. AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  17. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  18. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  19. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  20. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  21. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  22. POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. require_once "root.php";
  25. require_once "resources/require.php";
  26. require_once "resources/check_auth.php";
  27. if (permission_exists('invoice_item_add') || permission_exists('invoice_item_edit')) {
  28. //access granted
  29. }
  30. else {
  31. echo "access denied";
  32. exit;
  33. }
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. //action add or update
  38. if (isset($_REQUEST["id"])) {
  39. $action = "update";
  40. $invoice_item_uuid = check_str($_REQUEST["id"]);
  41. $back = check_str($_REQUEST['back']);
  42. }
  43. else {
  44. $action = "add";
  45. $back = check_str($_REQUEST['back']);
  46. }
  47. if (strlen(count($_REQUEST)) > 0) {
  48. $contact_uuid = check_str($_REQUEST["contact_uuid"]);
  49. $invoice_uuid = check_str($_REQUEST["invoice_uuid"]);
  50. }
  51. //get http post variables and set them to php variables
  52. if (count($_POST)>0) {
  53. $item_qty = check_str($_POST["item_qty"]);
  54. $item_desc = check_str($_POST["item_desc"]);
  55. $item_unit_price = check_str($_POST["item_unit_price"]);
  56. }
  57. if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
  58. $msg = '';
  59. if ($action == "update") {
  60. $invoice_item_uuid = check_str($_POST["invoice_item_uuid"]);
  61. }
  62. //check for all required data
  63. //if (strlen($invoice_item_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-invoice_item_uuid']."<br>\n"; }
  64. //if (strlen($domain_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-domain_uuid']."<br>\n"; }
  65. //if (strlen($invoice_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-invoice_uuid']."<br>\n"; }
  66. //if (strlen($item_qty) == 0) { $msg .= $text['message-required']." ".$text['label-item_qty']."<br>\n"; }
  67. //if (strlen($item_desc) == 0) { $msg .= $text['message-required']." ".$text['label-item_desc']."<br>\n"; }
  68. //if (strlen($item_unit_price) == 0) { $msg .= $text['message-required']." ".$text['label-item_unit_price']."<br>\n"; }
  69. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  70. require_once "resources/header.php";
  71. require_once "resources/persist_form_var.php";
  72. echo "<div align='center'>\n";
  73. echo "<table><tr><td>\n";
  74. echo $msg."<br />";
  75. echo "</td></tr></table>\n";
  76. persistformvar($_POST);
  77. echo "</div>\n";
  78. require_once "resources/footer.php";
  79. return;
  80. }
  81. //add or update the database
  82. if ($_POST["persistformvar"] != "true") {
  83. if ($action == "add" && permission_exists('invoice_item_add')) {
  84. $invoice_item_uuid = uuid();
  85. $sql = "insert into v_invoice_items ";
  86. $sql .= "(";
  87. $sql .= "domain_uuid, ";
  88. $sql .= "invoice_uuid, ";
  89. $sql .= "invoice_item_uuid, ";
  90. $sql .= "item_qty, ";
  91. $sql .= "item_desc, ";
  92. $sql .= "item_unit_price ";
  93. $sql .= ")";
  94. $sql .= "values ";
  95. $sql .= "(";
  96. $sql .= "'$domain_uuid', ";
  97. $sql .= "'$invoice_uuid', ";
  98. $sql .= "'$invoice_item_uuid', ";
  99. $sql .= "'$item_qty', ";
  100. $sql .= "'$item_desc', ";
  101. $sql .= "'$item_unit_price' ";
  102. $sql .= ")";
  103. $db->exec(check_sql($sql));
  104. unset($sql);
  105. //set redirect
  106. $_SESSION['message'] = $text['message-add'];
  107. $back = ($back != '') ? "&back=".$back : null;
  108. header("Location: invoice_edit.php?id=".$invoice_uuid."&contact_uuid=".$contact_uuid.$back);
  109. exit;
  110. } //if ($action == "add")
  111. if ($action == "update" && permission_exists('invoice_item_edit')) {
  112. $sql = "update v_invoice_items set ";
  113. $sql .= "item_qty = '$item_qty', ";
  114. $sql .= "item_desc = '$item_desc', ";
  115. $sql .= "item_unit_price = '$item_unit_price' ";
  116. $sql .= "where domain_uuid = '$domain_uuid' ";
  117. $sql .= "and invoice_item_uuid = '$invoice_item_uuid'";
  118. $db->exec(check_sql($sql));
  119. unset($sql);
  120. //set redirect
  121. $_SESSION['message'] = $text['message-update'];
  122. $back = ($back != '') ? "&back=".$back : null;
  123. header("Location: invoice_edit.php?id=".$invoice_uuid."&contact_uuid=".$contact_uuid.$back);
  124. exit;
  125. } //if ($action == "update")
  126. } //if ($_POST["persistformvar"] != "true")
  127. } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
  128. //pre-populate the form
  129. if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
  130. $invoice_item_uuid = check_str($_GET["id"]);
  131. $sql = "select * from v_invoice_items ";
  132. $sql .= "where domain_uuid = '$domain_uuid' ";
  133. $sql .= "and invoice_item_uuid = '$invoice_item_uuid' ";
  134. $prep_statement = $db->prepare(check_sql($sql));
  135. $prep_statement->execute();
  136. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  137. foreach ($result as &$row) {
  138. $item_qty = $row["item_qty"];
  139. $item_desc = $row["item_desc"];
  140. $item_unit_price = $row["item_unit_price"];
  141. break; //limit to 1 row
  142. }
  143. unset ($prep_statement);
  144. }
  145. //show the header
  146. require_once "resources/header.php";
  147. //show the content
  148. echo "<form method='post' name='frm' action=''>\n";
  149. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  150. echo "<tr>\n";
  151. echo "<td align='left' width='30%' valign='top' nowrap='nowrap'><b>".$text['title-invoice_item']."</b></td>\n";
  152. echo "<td width='70%' align='right' valign='top'>\n";
  153. echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"history.go(-1);\" value='".$text['button-back']."'>\n";
  154. echo "</td>\n";
  155. echo "</tr>\n";
  156. echo "<tr>\n";
  157. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  158. echo " ".$text['label-item_qty']."\n";
  159. echo "</td>\n";
  160. echo "<td class='vtable' align='left'>\n";
  161. echo " <input class='formfld' type='text' name='item_qty' maxlength='255' value='$item_qty'>\n";
  162. echo "<br />\n";
  163. echo $text['description-item_qty']."\n";
  164. echo "</td>\n";
  165. echo "</tr>\n";
  166. echo "<tr>\n";
  167. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  168. echo " ".$text['label-item_unit_price']."\n";
  169. echo "</td>\n";
  170. echo "<td class='vtable' align='left'>\n";
  171. echo " <input class='formfld' type='text' name='item_unit_price' maxlength='255' value='$item_unit_price'>\n";
  172. echo "<br />\n";
  173. echo $text['description-item_unit_price']."\n";
  174. echo "</td>\n";
  175. echo "</tr>\n";
  176. echo "<tr>\n";
  177. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  178. echo " ".$text['label-item_desc']."\n";
  179. echo "</td>\n";
  180. echo "<td class='vtable' align='left'>\n";
  181. echo " <textarea class='formfld' type='text' rows='15' name='item_desc'>$item_desc</textarea>\n";
  182. echo "<br />\n";
  183. //echo $text['description-item_desc']."\n";
  184. echo "</td>\n";
  185. echo "</tr>\n";
  186. echo " <tr>\n";
  187. echo " <td colspan='2' align='right'>\n";
  188. echo " <input type='hidden' name='invoice_uuid' value='$invoice_uuid'>\n";
  189. echo " <input type='hidden' name='contact_uuid' value='$contact_uuid'>\n";
  190. if ($action == "update") {
  191. if ($back != '') {
  192. echo " <input type='hidden' name='back' value='".$back."'>";
  193. }
  194. echo " <input type='hidden' name='invoice_item_uuid' value='$invoice_item_uuid'>\n";
  195. }
  196. echo " <br><input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
  197. echo " </td>\n";
  198. echo " </tr>";
  199. echo "</table>";
  200. echo "<br><br>";
  201. echo "</form>";
  202. //include the footer
  203. require_once "resources/footer.php";
  204. ?>