sms_broadcast_edit.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2019
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. Luis Daniel Lucio Quiroz <[email protected]>
  21. */
  22. //includes files
  23. require_once dirname(__DIR__, 2) . "/resources/require.php";
  24. require_once "resources/check_auth.php";
  25. //check permissions
  26. if (permission_exists('sms_broadcast_edit')) {
  27. //access granted
  28. }
  29. else {
  30. echo "access denied";
  31. exit;
  32. }
  33. //add multi-lingual support
  34. $language = new text;
  35. $text = $language->get();
  36. //set the action with add or update
  37. if (is_uuid($_REQUEST["id"])) {
  38. $action = "update";
  39. $sms_broadcast_uuid = $_REQUEST["id"];
  40. }
  41. else {
  42. $action = "add";
  43. }
  44. //function to Upload CSV/TXT file
  45. function upload_file($sql, $sms_broadcast_phone_numbers) {
  46. $upload_csv = $sql = '';
  47. if (isset($_FILES['sms_broadcast_phone_numbers_file']) && !empty($_FILES['sms_broadcast_phone_numbers_file']) && $_FILES['sms_broadcast_phone_numbers_file']['size'] > 0) {
  48. $filename=$_FILES["sms_broadcast_phone_numbers_file"]["tmp_name"];
  49. $file_extension = array('application/octet-stream','application/vnd.ms-excel','text/plain','text/csv','text/tsv');
  50. if (in_array($_FILES['sms_broadcast_phone_numbers_file']['type'],$file_extension)) {
  51. $file = fopen($filename, "r");
  52. $count = 0;
  53. while (($getData = fgetcsv($file, 0, "\n")) !== FALSE)
  54. {
  55. $count++;
  56. if ($count == 1) { continue; }
  57. $getData = preg_split('/[ ,|]/', $getData[0], null, PREG_SPLIT_NO_EMPTY);
  58. $separator = $getData[0];
  59. $separator .= (isset($getData[1]) && $getData[1] != '')? '|'.$getData[1] : '';
  60. $separator .= (isset($getData[2]) && $getData[2] != '')? ','.$getData[2] : '';
  61. $separator .= '\n';
  62. $upload_csv .= $separator;
  63. }
  64. fclose($file);
  65. }
  66. else {
  67. return array('code'=>false,'sql'=>'');
  68. }
  69. }
  70. if (!empty($sms_broadcast_phone_numbers) && !empty($upload_csv)) {
  71. $sql .= $sms_broadcast_phone_numbers.'\n'.$upload_csv;
  72. }
  73. elseif (empty($sms_broadcast_phone_numbers) && !empty($upload_csv)) {
  74. $sql .= $upload_csv;
  75. }
  76. else {
  77. $sql .= $sms_broadcast_phone_numbers;
  78. }
  79. return array('code'=>true,'sql'=> $sql);
  80. }
  81. //get the http post variables and set them to php variables
  82. if (count($_POST)>0) {
  83. $sms_broadcast_name = $_POST["sms_broadcast_name"];
  84. $sms_broadcast_caller_id_number = $_POST["sms_broadcast_caller_id_number"];
  85. $sms_broadcast_phone_numbers = $_POST["sms_broadcast_phone_numbers"];
  86. $sms_broadcast_destination_data = $_POST["sms_broadcast_destination_data"];
  87. $sms_broadcast_description = $_POST["sms_broadcast_description"];
  88. }
  89. if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
  90. //delete the call broadcast
  91. if (permission_exists('sms_broadcast_delete')) {
  92. if ($_POST['action'] == 'delete' && is_uuid($sms_broadcast_uuid)) {
  93. //prepare
  94. $sms_broadcast[0]['checked'] = 'true';
  95. $sms_broadcast[0]['uuid'] = $sms_broadcast_uuid;
  96. //delete
  97. $obj = new sms_broadcast;
  98. $obj->delete($sms_broadcast);
  99. //redirect
  100. header('Location: sms_broadcast.php');
  101. exit;
  102. }
  103. }
  104. $msg = '';
  105. if ($action == "update") {
  106. $sms_broadcast_uuid = $_POST["sms_broadcast_uuid"];
  107. }
  108. //validate the token
  109. $token = new token;
  110. if (!$token->validate($_SERVER['PHP_SELF'])) {
  111. message::add($text['message-invalid_token'],'negative');
  112. header('Location: sms_broadcast.php');
  113. exit;
  114. }
  115. //check for all required data
  116. if (strlen($sms_broadcast_name) == 0) { $msg .= "".$text['confirm-name']."<br>\n"; }
  117. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  118. require_once "resources/header.php";
  119. require_once "resources/persist_form_var.php";
  120. echo "<div align='center'>\n";
  121. echo "<table><tr><td>\n";
  122. echo $msg."<br />";
  123. echo "</td></tr></table>\n";
  124. persistformvar($_POST);
  125. echo "</div>\n";
  126. require_once "resources/footer.php";
  127. return;
  128. }
  129. //add or update the database
  130. if ($_POST["persistformvar"] != "true") {
  131. //prep insert
  132. if ($action == "add" && permission_exists('sms_broadcast_add')) {
  133. //begin insert array
  134. $sms_broadcast_uuid = uuid();
  135. $array['sms_broadcast'][0]['sms_broadcast_uuid'] = $sms_broadcast_uuid;
  136. //set message
  137. message::add($text['confirm-add']);
  138. //set return url on error
  139. $error_return_url = "sms_broadcast_edit.php";
  140. }
  141. //prep update
  142. if ($action == "update" && permission_exists('sms_broadcast_edit')) {
  143. //begin update array
  144. $array['sms_broadcast'][0]['sms_broadcast_uuid'] = $sms_broadcast_uuid;
  145. //set message
  146. message::add($text['confirm-update']);
  147. //set return url on error
  148. $error_return_url = "sms_broadcast_edit.php?id=".urlencode($_GET['id']);
  149. }
  150. //execute
  151. if (is_array($array) && @sizeof($array) != 0) {
  152. //add file selection and download sample
  153. $file_res = upload_file($sql, $sms_broadcast_phone_numbers);
  154. if ($file_res['code'] != true) {
  155. $_SESSION["message_mood"] = "negative";
  156. $_SESSION["message"] = $text['file-error'];
  157. header("Location: ".$error_return_url);
  158. exit;
  159. }
  160. $sms_broadcast_phone_numbers = $file_res['sql'];
  161. //common array items
  162. $array['sms_broadcast'][0]['domain_uuid'] = $domain_uuid;
  163. $array['sms_broadcast'][0]['sms_broadcast_name'] = $sms_broadcast_name;
  164. $array['sms_broadcast'][0]['sms_broadcast_caller_id_number'] = $sms_broadcast_caller_id_number;
  165. $array['sms_broadcast'][0]['sms_broadcast_phone_numbers'] = $sms_broadcast_phone_numbers;
  166. $array['sms_broadcast'][0]['sms_broadcast_destination_data'] = $sms_broadcast_destination_data;
  167. $array['sms_broadcast'][0]['sms_broadcast_description'] = $sms_broadcast_description;
  168. //execute
  169. $database = new database;
  170. $database->app_name = 'sms';
  171. $database->app_uuid = 'f1381f06-1d33-11e6-b6ba-3e1d05defe78';
  172. $database->save($array);
  173. //print_r($database);
  174. //die();
  175. unset($array);
  176. //redirect
  177. header("Location: sms_broadcast.php");
  178. exit;
  179. }
  180. }
  181. }
  182. //pre-populate the form
  183. if (count($_GET) > 0 && $_POST["persistformvar"] != "true") {
  184. $sms_broadcast_uuid = $_GET["id"];
  185. $sql = "select * from v_sms_broadcast ";
  186. $sql .= "where domain_uuid = :domain_uuid ";
  187. $sql .= "and sms_broadcast_uuid = :sms_broadcast_uuid ";
  188. $parameters['domain_uuid'] = $domain_uuid;
  189. $parameters['sms_broadcast_uuid'] = $sms_broadcast_uuid;
  190. $database = new database;
  191. $row = $database->select($sql, $parameters, 'row');
  192. if (is_array($row) && @sizeof($row) != 0) {
  193. $sms_broadcast_name = $row["sms_broadcast_name"];
  194. $sms_broadcast_caller_id_number = $row["sms_broadcast_caller_id_number"];
  195. $sms_broadcast_phone_numbers = $row["sms_broadcast_phone_numbers"];
  196. $sms_broadcast_destination_data = $row["sms_broadcast_destination_data"];
  197. $sms_broadcast_description = $row["sms_broadcast_description"];
  198. }
  199. unset($sql, $parameters, $row);
  200. }
  201. //create token
  202. $object = new token;
  203. $token = $object->create($_SERVER['PHP_SELF']);
  204. //begin header
  205. $document['title'] = $text['title-call_broadcast'];
  206. require_once "resources/header.php";
  207. //begin content
  208. echo "<form name='frm' id='frm' method='post' enctype='multipart/form-data'>\n";
  209. echo "<div class='action_bar' id='action_bar'>\n";
  210. echo " <div class='heading'><b>".$text['title-call_broadcast']."</b></div>\n";
  211. echo " <div class='actions'>\n";
  212. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','link'=>'sms_broadcast.php']);
  213. if ($action == "update") {
  214. //echo button::create(['type'=>'button','label'=>$text['button-start'],'icon'=>$_SESSION['theme']['button_icon_start'],'style'=>'margin-left: 15px;','link'=>'call_broadcast_send.php?id='.urlencode($sms_broadcast_uuid)]);
  215. //echo button::create(['type'=>'button','label'=>$text['button-stop'],'icon'=>$_SESSION['theme']['button_icon_stop'],'link'=>'call_broadcast_stop.php?id='.urlencode($sms_broadcast_uuid)]);
  216. if (permission_exists('sms_broadcast_delete')) {
  217. echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','style'=>'margin-left: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
  218. }
  219. }
  220. echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','style'=>'margin-left: 15px;']);
  221. echo " </div>\n";
  222. echo " <div style='clear: both;'></div>\n";
  223. echo "</div>\n";
  224. if ($action == 'update' && permission_exists('sms_broadcast_delete')) {
  225. echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'delete','onclick'=>"modal_close();"])]);
  226. }
  227. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  228. echo "<tr>\n";
  229. echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap>\n";
  230. echo " ".$text['label-name']."\n";
  231. echo "</td>\n";
  232. echo "<td width='70%' class='vtable' align='left'>\n";
  233. echo " <input class='formfld' type='text' name='sms_broadcast_name' maxlength='255' value=\"".escape($sms_broadcast_name)."\" required='required'>\n";
  234. echo "<br />\n";
  235. echo "".$text['description-name']."\n";
  236. echo "</td>\n";
  237. echo "</tr>\n";
  238. echo "<tr>\n";
  239. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  240. echo " ".$text['label-callerid-number']."\n";
  241. echo "</td>\n";
  242. echo "<td class='vtable' align='left'>\n";
  243. echo " <input class='formfld' type='number' name='sms_broadcast_caller_id_number' maxlength='255' min='0' step='1' value=\"".escape($sms_broadcast_caller_id_number)."\">\n";
  244. echo "<br />\n";
  245. echo "".$text['description-caller-id-number']."\n";
  246. echo "</td>\n";
  247. echo "</tr>\n";
  248. echo "<tr>\n";
  249. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  250. echo " ".$text['label-message']."\n";
  251. echo "</td>\n";
  252. echo "<td class='vtable' align='left'>\n";
  253. echo " <input class='formfld' type='text' name='sms_broadcast_destination_data' maxlength='255' value=\"".escape($sms_broadcast_destination_data)."\">\n";
  254. echo "<br />\n";
  255. echo "".$text['description-message']." <br /><br />\n";
  256. echo "</td>\n";
  257. echo "</tr>\n";
  258. echo "<tr>\n";
  259. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  260. echo " ".$text['label-phone']."\n";
  261. echo "</td>\n";
  262. echo "<td class='vtable' align='left'>\n";
  263. echo " <textarea class='formfld' style='width: 300px; height: 200px;' type='text' name='sms_broadcast_phone_numbers' placeholder=\"".$text['label-list_example']."\">".str_replace('\n', "\n", $sms_broadcast_phone_numbers)."</textarea>";
  264. echo "<br><br>";
  265. echo " <input type='file' name='sms_broadcast_phone_numbers_file' accept='.csv,.txt' style=\"display:inline-block;\"><a href='sample.csv' download><i class='fas fa-cloud-download-alt' style='margin-right: 5px;'></i>".$text['label-sample_file']."</a>";
  266. echo "<br /><br />";
  267. echo "".$text['description-phone']." <br /><br />\n";
  268. echo "</td>\n";
  269. echo "</tr>\n";
  270. echo "<tr>\n";
  271. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  272. echo " ".$text['label-description']."\n";
  273. echo "</td>\n";
  274. echo "<td class='vtable' align='left'>\n";
  275. echo " <input class='formfld' type='text' name='sms_broadcast_description' maxlength='255' value=\"".escape($sms_broadcast_description)."\">\n";
  276. echo "<br />\n";
  277. echo "".$text['description-info']."\n";
  278. echo "</td>\n";
  279. echo "</tr>\n";
  280. echo "</table>";
  281. echo "<br><br>";
  282. if ($action == "update") {
  283. echo "<input type='hidden' name='sms_broadcast_uuid' value='".escape($sms_broadcast_uuid)."'>\n";
  284. }
  285. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  286. echo "</form>";
  287. //include the footer
  288. require_once "resources/footer.php";
  289. ?>