sms_edit.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. /* $Id$ */
  3. /*
  4. call.php
  5. Copyright (C) 2008, 2009 Mark J Crane
  6. All rights reserved.
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions are met:
  9. 1. Redistributions of source code must retain the above copyright notice,
  10. this list of conditions and the following disclaimer.
  11. 2. Redistributions in binary form must reproduce the above copyright
  12. notice, this list of conditions and the following disclaimer in the
  13. documentation and/or other materials provided with the distribution.
  14. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
  15. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  16. AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  17. AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  18. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23. POSSIBILITY OF SUCH DAMAGE.
  24. Contributor(s):
  25. Mark J Crane <[email protected]>
  26. James Rose <[email protected]>
  27. */
  28. //includes files
  29. require_once dirname(__DIR__, 2) . "/resources/require.php";
  30. require_once "resources/check_auth.php";
  31. if (permission_exists('sms_add') || permission_exists('sms_edit')) {
  32. //access granted
  33. }
  34. else {
  35. echo "access denied";
  36. exit;
  37. }
  38. //add multi-lingual support
  39. $language = new text;
  40. $text = $language->get();
  41. //set the action as an add or an update
  42. if (isset($_REQUEST["id"])) {
  43. $action = "update";
  44. $sms_uuid = check_str($_REQUEST["id"]);
  45. $sql = "select * from v_sms_destinations ";
  46. $sql .= "where sms_destination_uuid = '" . $_REQUEST["id"] . "' ";
  47. $sql .= "and domain_uuid = '" . $_SESSION['domain_uuid'] . "' LIMIT 1";
  48. $prep_statement = $db->prepare(check_sql($sql));
  49. $prep_statement->execute();
  50. $sms_destinations = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  51. foreach ($sms_destinations as $row) {
  52. $destination = check_str($row["destination"]);
  53. $carrier = check_str($row["carrier"]);
  54. $description = check_str($row["description"]);
  55. $enabled = check_str($row["enabled"]);
  56. $sms_destination_uuid = $row['sms_destination_uuid'];
  57. $chatplan_detail_data = $row['chatplan_detail_data'];
  58. $email = $row['email'];
  59. }
  60. unset ($prep_statement);
  61. }
  62. else {
  63. $action = "add";
  64. }
  65. //get the http values and set them as php variables
  66. if (count($_POST) > 0 && $action != "update") {
  67. //get the values from the HTTP POST and save them as PHP variables
  68. $destination = str_replace(' ','-',check_str($_POST["destination"]));
  69. $carrier = check_str($_POST["carrier"]);
  70. $description = check_str($_POST["description"]);
  71. $enabled = check_str($_POST["enabled"]);
  72. $sms_destination_uuid = uuid();
  73. $chatplan_detail_data = check_str($_POST["chatplan_detail_data"]);
  74. $email = check_str($_POST["email"]);
  75. if ($action == "add") {
  76. $sql_insert = "insert into v_sms_destinations ";
  77. $sql_insert .= "(";
  78. $sql_insert .= "sms_destination_uuid, ";
  79. $sql_insert .= "carrier, ";
  80. $sql_insert .= "domain_uuid, ";
  81. $sql_insert .= "destination, ";
  82. $sql_insert .= "enabled, ";
  83. $sql_insert .= "description, ";
  84. $sql_insert .= "chatplan_detail_data, ";
  85. $sql_insert .= "email ";
  86. $sql_insert .= ")";
  87. $sql_insert .= "values ";
  88. $sql_insert .= "(";
  89. $sql_insert .= ":sms_destination_uuid, ";
  90. $sql_insert .= ":carrier, ";
  91. $sql_insert .= ":domain_uuid, ";
  92. $sql_insert .= ":destination, ";
  93. $sql_insert .= ":enabled, ";
  94. $sql_insert .= ":description, ";
  95. $sql_insert .= ":chatplan_detail_data, ";
  96. $sql_insert .= ":email ";
  97. $sql_insert .= ")";
  98. $prep_statement = $db->prepare(check_sql($sql_insert));
  99. $prep_statement->execute(array(':sms_destination_uuid' => $sms_destination_uuid, ':carrier' => $carrier,
  100. 'domain_uuid' => $_SESSION['domain_uuid'], ':destination' => $destination, ':enabled' => $enabled,
  101. ':description' => $description, ':chatplan_detail_data' => $chatplan_detail_data, ':email' => $email));
  102. $prep_statement->execute();
  103. unset ($prep_statement);
  104. header( 'Location: sms.php') ;
  105. }
  106. } elseif (count($_POST) > 0 && $action == "update") {
  107. $destination = str_replace(' ','-',check_str($_POST["destination"]));
  108. $carrier = check_str($_POST["carrier"]);
  109. $description = check_str($_POST["description"]);
  110. $enabled = check_str($_POST["enabled"]);
  111. $chatplan_detail_data = check_str($_POST["chatplan_detail_data"]);
  112. $email = check_str($_POST["email"]);
  113. $sql_insert = "update v_sms_destinations set";
  114. $sql_insert .= " ";
  115. $sql_insert .= "carrier = :carrier, ";
  116. $sql_insert .= "destination = :destination, ";
  117. $sql_insert .= "enabled = :enabled, ";
  118. $sql_insert .= "description = :description, ";
  119. $sql_insert .= "chatplan_detail_data = :chatplan_detail_data, ";
  120. $sql_insert .= "email = :email ";
  121. $sql_insert .= "where sms_destination_uuid = :sms_destination_uuid and domain_uuid = :domain_uuid";
  122. $prep_statement = $db->prepare(check_sql($sql_insert));
  123. $prep_statement->execute(array(':carrier' => $carrier, ':destination' => $destination, ':enabled' => $enabled,
  124. ':description' => $description, ':chatplan_detail_data' => $chatplan_detail_data, ':email' => $email,
  125. ':sms_destination_uuid' => $sms_destination_uuid, ':domain_uuid' => $_SESSION['domain_uuid']));
  126. $prep_statement->execute();
  127. error_log($sql_insert);
  128. unset ($prep_statement);
  129. header( 'Location: sms.php') ;
  130. }
  131. //include the header
  132. require_once "resources/header.php";
  133. require_once "resources/paging.php";
  134. echo "<form method='post' name='frm' id='frm' action=''>\n";
  135. echo "<table width='100%' border='0' cellpdding='0' cellspacing='0'>\n";
  136. echo "<tr>\n";
  137. if ($action == "add") {
  138. echo "<td width='30%' nowrap='nowrap' align='left' valign='top'><b>".$text['header-sms-add']."</b></td>\n";
  139. }
  140. if ($action == "update") {
  141. echo "<td width='30%' nowrap='nowrap' align='left' valign='top'><b>".$text['header-sms-edit']."</b></td>\n";
  142. }
  143. echo "<td width='70%' align='right' valign='top'>\n";
  144. echo " <input type='button' class='btn' alt='".$text['button-back']."' onclick=\"window.location='sms.php'\" value='".$text['button-back']."'>\n";
  145. echo " <input type='button' class='btn' value='".$text['button-save']."' onclick='submit_form();'>\n";
  146. echo " <br /><br />\n";
  147. echo "</td>\n";
  148. echo "</tr>\n";
  149. echo "<tr>\n";
  150. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  151. echo " ".$text['label-destination']."\n";
  152. echo "</td>\n";
  153. echo "<td class='vtable' align='left'>\n";
  154. echo " <input class='formfld' type='text' name='destination' autocomplete='off' maxlength='255' value=\"$destination\" required='required'>\n";
  155. echo "<br />\n";
  156. echo $text['description-destination']."\n";
  157. echo "</td>\n";
  158. echo "</tr>\n";
  159. echo "<tr>\n";
  160. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  161. echo " ".$text['label-carrier']."\n";
  162. echo "</td>\n";
  163. echo "<td class='vtable' align='left'>\n";
  164. if (count($_SESSION['sms']['carriers']) > 0) {
  165. echo "<select name='carrier' class='formfld'>\n";
  166. echo " <option value=''></option>\n";
  167. sort($_SESSION['sms']['carriers']);
  168. foreach ($_SESSION['sms']['carriers'] as &$row) {
  169. echo " <option value='$row'";
  170. if ($row == $carrier) {
  171. echo " selected='selected'";
  172. }
  173. echo ">$row</option>\n";
  174. }
  175. echo "</select><br />\n";
  176. }
  177. echo $text['description-carrier']."\n";
  178. echo "</td>\n";
  179. echo "</tr>\n";
  180. echo "<tr>\n";
  181. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  182. echo " ".$text['label-chatplan_detail_data']."\n";
  183. echo "</td>\n";
  184. echo "<td class='vtable' align='left'>\n";
  185. echo " <input class='formfld' type='text' name='chatplan_detail_data' autocomplete='off' maxlength='255' value=\"$chatplan_detail_data\" >\n";
  186. echo "<br />\n";
  187. echo $text['description-chatplan_detail_data']."\n";
  188. echo "</td>\n";
  189. echo "</tr>\n";
  190. echo "<tr>\n";
  191. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  192. echo " ".$text['label-sms_email']."\n";
  193. echo "</td>\n";
  194. echo "<td class='vtable' align='left'>\n";
  195. echo " <input class='formfld' type='text' name='email' autocomplete='off' maxlength='255' value=\"$email\" >\n";
  196. echo "<br />\n";
  197. echo $text['description-sms_email']."\n";
  198. echo "</td>\n";
  199. echo "</tr>\n";
  200. if (permission_exists('sms_enabled')) {
  201. echo "<tr>\n";
  202. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  203. echo " ".$text['label-enabled']."\n";
  204. echo "</td>\n";
  205. echo "<td class='vtable' align='left'>\n";
  206. echo " <select class='formfld' name='enabled'>\n";
  207. if ($enabled == "true") {
  208. echo " <option value='true' selected='selected'>".$text['label-true']."</option>\n";
  209. }
  210. else {
  211. echo " <option value='true'>".$text['label-true']."</option>\n";
  212. }
  213. if ($enabled == "false") {
  214. echo " <option value='false' selected='selected'>".$text['label-false']."</option>\n";
  215. }
  216. else {
  217. echo " <option value='false'>".$text['label-false']."</option>\n";
  218. }
  219. echo " </select>\n";
  220. echo "<br />\n";
  221. echo $text['description-enabled']."\n";
  222. echo "</td>\n";
  223. echo "</tr>\n";
  224. }
  225. echo "<tr>\n";
  226. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  227. echo " ".$text['label-description']."\n";
  228. echo "</td>\n";
  229. echo "<td class='vtable' align='left'>\n";
  230. echo " <textarea class='formfld' name='description' rows='4'>$description</textarea>\n";
  231. echo "<br />\n";
  232. echo $text['description-description']."\n";
  233. echo "</td>\n";
  234. echo "</tr>\n";
  235. if ($action == "update") {
  236. echo " <input type='hidden' name='sms_destination_uuid' value='".$sms_destination_uuid."'>\n";
  237. echo " <input type='hidden' name='id' id='id' value='".$sms_destination_uuid."'>";
  238. }
  239. echo "</table>\n";
  240. echo "</form>\n";
  241. echo "<script>\n";
  242. //capture enter key to submit form
  243. echo " $(window).keypress(function(event){\n";
  244. echo " if (event.which == 13) { submit_form(); }\n";
  245. echo " });\n";
  246. // convert password fields to
  247. echo " function submit_form() {\n";
  248. echo " $('input:password').css('visibility','hidden');\n";
  249. echo " $('input:password').attr({type:'text'});\n";
  250. echo " $('form#frm').submit();\n";
  251. echo " }\n";
  252. echo "</script>\n";
  253. //show the footer
  254. require_once "resources/footer.php";
  255. ?>