invoice_item_edit.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. //includes files
  25. require_once dirname(__DIR__, 2) . "/resources/require.php";
  26. require_once "resources/check_auth.php";
  27. //check permissionss
  28. if (permission_exists('invoice_item_add') || permission_exists('invoice_item_edit')) {
  29. //access granted
  30. }
  31. else {
  32. echo "access denied";
  33. exit;
  34. }
  35. //add multi-lingual support
  36. $language = new text;
  37. $text = $language->get();
  38. //action add or update
  39. if (isset($_REQUEST["id"])) {
  40. $action = "update";
  41. $invoice_item_uuid = check_str($_REQUEST["id"]);
  42. $back = check_str($_REQUEST['back']);
  43. }
  44. else {
  45. $action = "add";
  46. $back = check_str($_REQUEST['back']);
  47. }
  48. //get http post variables and set them to php variables
  49. if (strlen(count($_REQUEST)) > 0) {
  50. $contact_uuid = check_str($_REQUEST["contact_uuid"]);
  51. $invoice_uuid = check_str($_REQUEST["invoice_uuid"]);
  52. }
  53. if (count($_POST) > 0) {
  54. $item_qty = check_str($_POST["item_qty"]);
  55. $item_desc = check_str($_POST["item_desc"]);
  56. $item_unit_price = check_str($_POST["item_unit_price"]);
  57. }
  58. //process the data from the http post
  59. if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
  60. //get the id
  61. if ($action == "update") {
  62. $invoice_item_uuid = check_str($_POST["invoice_item_uuid"]);
  63. }
  64. //check for all required data
  65. $msg = '';
  66. //if (strlen($invoice_item_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-invoice_item_uuid']."<br>\n"; }
  67. //if (strlen($domain_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-domain_uuid']."<br>\n"; }
  68. //if (strlen($invoice_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-invoice_uuid']."<br>\n"; }
  69. if (strlen($item_qty) == 0) { $msg .= $text['message-required']." ".$text['label-item_qty']."<br>\n"; }
  70. //if (strlen($item_desc) == 0) { $msg .= $text['message-required']." ".$text['label-item_desc']."<br>\n"; }
  71. //if (strlen($item_unit_price) == 0) { $msg .= $text['message-required']." ".$text['label-item_unit_price']."<br>\n"; }
  72. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  73. require_once "resources/header.php";
  74. require_once "resources/persist_form_var.php";
  75. echo "<div align='center'>\n";
  76. echo "<table><tr><td>\n";
  77. echo $msg."<br />";
  78. echo "</td></tr></table>\n";
  79. persistformvar($_POST);
  80. echo "</div>\n";
  81. require_once "resources/footer.php";
  82. return;
  83. }
  84. //add or update the database
  85. if ($_POST["persistformvar"] != "true") {
  86. if ($action == "add" && permission_exists('invoice_item_add')) {
  87. $invoice_item_uuid = uuid();
  88. $sql = "insert into v_invoice_items ";
  89. $sql .= "(";
  90. $sql .= "domain_uuid, ";
  91. $sql .= "invoice_uuid, ";
  92. $sql .= "invoice_item_uuid, ";
  93. $sql .= "item_qty, ";
  94. $sql .= "item_desc, ";
  95. $sql .= "item_unit_price ";
  96. $sql .= ")";
  97. $sql .= "values ";
  98. $sql .= "(";
  99. $sql .= "'$domain_uuid', ";
  100. $sql .= "'$invoice_uuid', ";
  101. $sql .= "'$invoice_item_uuid', ";
  102. $sql .= "'$item_qty', ";
  103. $sql .= "'$item_desc', ";
  104. $sql .= "'$item_unit_price' ";
  105. $sql .= ")";
  106. $db->exec(check_sql($sql));
  107. unset($sql);
  108. //set redirect
  109. $_SESSION['message'] = $text['message-add'];
  110. $back = ($back != '') ? "&back=".$back : null;
  111. header("Location: invoice_edit.php?id=".$invoice_uuid."&contact_uuid=".$contact_uuid.$back);
  112. return;
  113. } //if ($action == "add")
  114. if ($action == "update" && permission_exists('invoice_item_edit')) {
  115. $sql = "update v_invoice_items set ";
  116. $sql .= "item_qty = '$item_qty', ";
  117. $sql .= "item_desc = '$item_desc', ";
  118. $sql .= "item_unit_price = '$item_unit_price' ";
  119. $sql .= "where domain_uuid = '$domain_uuid' ";
  120. $sql .= "and invoice_item_uuid = '$invoice_item_uuid'";
  121. $db->exec(check_sql($sql));
  122. unset($sql);
  123. //set redirect
  124. $_SESSION['message'] = $text['message-update'];
  125. $back = ($back != '') ? "&back=".$back : null;
  126. header("Location: invoice_edit.php?id=".$invoice_uuid."&contact_uuid=".$contact_uuid.$back);
  127. return;
  128. } //if ($action == "update")
  129. } //if ($_POST["persistformvar"] != "true")
  130. } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
  131. //pre-populate the form
  132. if (count($_GET) > 0 && $_POST["persistformvar"] != "true") {
  133. $invoice_item_uuid = check_str($_GET["id"]);
  134. $sql = "select * from v_invoice_items ";
  135. $sql .= "where domain_uuid = '$domain_uuid' ";
  136. $sql .= "and invoice_item_uuid = '$invoice_item_uuid' ";
  137. $prep_statement = $db->prepare(check_sql($sql));
  138. $prep_statement->execute();
  139. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  140. foreach ($result as &$row) {
  141. $item_qty = $row["item_qty"];
  142. $item_desc = $row["item_desc"];
  143. $item_unit_price = $row["item_unit_price"];
  144. break; //limit to 1 row
  145. }
  146. unset ($prep_statement);
  147. }
  148. //show the header
  149. require_once "resources/header.php";
  150. //show the content
  151. echo "<form method='post' name='frm' action=''>\n";
  152. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  153. echo "<tr>\n";
  154. echo "<td align='left' width='30%' valign='top' nowrap='nowrap'><b>".$text['title-invoice_item']."</b></td>\n";
  155. echo "<td width='70%' align='right' valign='top'>\n";
  156. echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"history.go(-1);\" value='".$text['button-back']."'>\n";
  157. echo "</td>\n";
  158. echo "</tr>\n";
  159. echo "<tr>\n";
  160. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  161. echo " ".$text['label-item_qty']."\n";
  162. echo "</td>\n";
  163. echo "<td class='vtable' align='left'>\n";
  164. echo " <input class='formfld' type='text' name='item_qty' maxlength='255' value='".escape($item_qty)."'>\n";
  165. echo "<br />\n";
  166. echo $text['description-item_qty']."\n";
  167. echo "</td>\n";
  168. echo "</tr>\n";
  169. echo "<tr>\n";
  170. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  171. echo " ".$text['label-item_unit_price']."\n";
  172. echo "</td>\n";
  173. echo "<td class='vtable' align='left'>\n";
  174. echo " <input class='formfld' type='text' name='item_unit_price' maxlength='255' value='".escape($item_unit_price)."'>\n";
  175. echo "<br />\n";
  176. echo $text['description-item_unit_price']."\n";
  177. echo "</td>\n";
  178. echo "</tr>\n";
  179. echo "<tr>\n";
  180. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  181. echo " ".$text['label-item_desc']."\n";
  182. echo "</td>\n";
  183. echo "<td class='vtable' align='left'>\n";
  184. echo " <textarea class='formfld' type='text' rows='15' name='item_desc'>".escape($item_desc)."</textarea>\n";
  185. echo "<br />\n";
  186. //echo $text['description-item_desc']."\n";
  187. echo "</td>\n";
  188. echo "</tr>\n";
  189. echo " <tr>\n";
  190. echo " <td colspan='2' align='right'>\n";
  191. echo " <input type='hidden' name='invoice_uuid' value='".escape($invoice_uuid)."'>\n";
  192. echo " <input type='hidden' name='contact_uuid' value='".escape($contact_uuid)."'>\n";
  193. if ($action == "update") {
  194. if ($back != '') {
  195. echo " <input type='hidden' name='back' value='".escape($back)."'>";
  196. }
  197. echo " <input type='hidden' name='invoice_item_uuid' value='".escape($invoice_item_uuid)."'>\n";
  198. }
  199. echo " <br><input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
  200. echo " </td>\n";
  201. echo " </tr>";
  202. echo "</table>";
  203. echo "<br><br>";
  204. echo "</form>";
  205. //include the footer
  206. require_once "resources/footer.php";
  207. ?>