transcribe_queue_edit.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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) 2025
  17. the Initial Developer. All Rights Reserved.
  18. */
  19. //includes files
  20. require_once dirname(__DIR__, 2) . "/resources/require.php";
  21. require_once "resources/check_auth.php";
  22. //check permissions
  23. if (!(permission_exists('transcribe_queue_add') || permission_exists('transcribe_queue_edit'))) {
  24. echo "access denied";
  25. exit;
  26. }
  27. //add multi-lingual support
  28. $language = new text;
  29. $text = $language->get();
  30. //connect to the database
  31. $database = database::new();
  32. //add the settings object
  33. $settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]);
  34. //set from session variables
  35. $button_icon_back = $settings->get('theme', 'button_icon_back', '');
  36. $button_icon_copy = $settings->get('theme', 'button_icon_copy', '');
  37. $button_icon_delete = $settings->get('theme', 'button_icon_delete', '');
  38. $button_icon_save = $settings->get('theme', 'button_icon_save', '');
  39. $input_toggle_style = $settings->get('theme', 'input_toggle_style', 'switch round');
  40. //action add or update
  41. if (is_uuid($_REQUEST["id"])) {
  42. $action = "update";
  43. $transcribe_queue_uuid = $_REQUEST["id"];
  44. $id = $_REQUEST["id"];
  45. }
  46. else {
  47. $action = "add";
  48. }
  49. //get http post variables and set them to php variables
  50. if (!empty($_POST)) {
  51. $hostname = $_POST["hostname"];
  52. $transcribe_status = $_POST["transcribe_status"];
  53. $transcribe_app_class = $_POST["transcribe_app_class"];
  54. $transcribe_app_method = $_POST["transcribe_app_method"];
  55. $transcribe_audio_path = $_POST["transcribe_audio_path"];
  56. $transcribe_audio_name = $_POST["transcribe_audio_name"];
  57. $transcribe_message = $_POST["transcribe_message"];
  58. }
  59. //process the data and save it to the database
  60. if (!empty($_POST) && empty($_POST["persistformvar"])) {
  61. //validate the token
  62. $token = new token;
  63. if (!$token->validate($_SERVER['PHP_SELF'])) {
  64. message::add($text['message-invalid_token'],'negative');
  65. header('Location: transcribe_queue.php');
  66. exit;
  67. }
  68. //process the http post data by submitted action
  69. if ($_POST['action'] != '' && strlen($_POST['action']) > 0) {
  70. //prepare the array(s)
  71. //send the array to the database class
  72. switch ($_POST['action']) {
  73. case 'copy':
  74. if (permission_exists('transcribe_queue_add')) {
  75. $obj = new transcribe_queue;
  76. $obj->copy($array);
  77. }
  78. break;
  79. case 'delete':
  80. if (permission_exists('transcribe_queue_delete')) {
  81. $obj = new transcribe_queue;
  82. $obj->delete($array);
  83. }
  84. break;
  85. case 'toggle':
  86. if (permission_exists('transcribe_queue_update')) {
  87. $obj = new transcribe_queue;
  88. $obj->toggle($array);
  89. }
  90. break;
  91. }
  92. //redirect the user
  93. if (in_array($_POST['action'], array('copy', 'delete', 'toggle'))) {
  94. header('Location: transcribe_queue_edit.php?id='.$id);
  95. exit;
  96. }
  97. }
  98. //check for all required data
  99. $msg = '';
  100. if (strlen($hostname) == 0) { $msg .= $text['message-required']." ".$text['label-hostname']."<br>\n"; }
  101. if (strlen($transcribe_status) == 0) { $msg .= $text['message-required']." ".$text['label-transcribe_status']."<br>\n"; }
  102. if (strlen($transcribe_app_class) == 0) { $msg .= $text['message-required']." ".$text['label-transcribe_app_class']."<br>\n"; }
  103. if (strlen($transcribe_app_method) == 0) { $msg .= $text['message-required']." ".$text['label-transcribe_app_method']."<br>\n"; }
  104. if (strlen($transcribe_audio_path) == 0) { $msg .= $text['message-required']." ".$text['label-transcribe_audio_path']."<br>\n"; }
  105. if (strlen($transcribe_audio_name) == 0) { $msg .= $text['message-required']." ".$text['label-transcribe_audio_name']."<br>\n"; }
  106. //if (strlen($transcribe_message) == 0) { $msg .= $text['message-required']." ".$text['label-transcribe_message']."<br>\n"; }
  107. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  108. require_once "resources/header.php";
  109. require_once "resources/persist_form_var.php";
  110. echo "<div align='center'>\n";
  111. echo "<table><tr><td>\n";
  112. echo $msg."<br />";
  113. echo "</td></tr></table>\n";
  114. persistformvar($_POST);
  115. echo "</div>\n";
  116. require_once "resources/footer.php";
  117. return;
  118. }
  119. //add the transcribe_queue_uuid
  120. if (!is_uuid($_POST["transcribe_queue_uuid"])) {
  121. $transcribe_queue_uuid = uuid();
  122. }
  123. //prepare the array
  124. $array['transcribe_queue'][0]['transcribe_queue_uuid'] = $transcribe_queue_uuid;
  125. $array['transcribe_queue'][0]['domain_uuid'] = $_SESSION['domain_uuid'];
  126. $array['transcribe_queue'][0]['hostname'] = $hostname;
  127. $array['transcribe_queue'][0]['transcribe_status'] = $transcribe_status;
  128. $array['transcribe_queue'][0]['transcribe_app_name'] = $transcribe_app_name;
  129. $array['transcribe_queue'][0]['transcribe_app_method'] = $transcribe_app_method;
  130. $array['transcribe_queue'][0]['transcribe_audio_path'] = $transcribe_audio_path;
  131. $array['transcribe_queue'][0]['transcribe_audio_name'] = $transcribe_audio_name;
  132. $array['transcribe_queue'][0]['transcribe_message'] = $transcribe_message;
  133. //save the data
  134. $database->app_name = 'transcribe queue';
  135. $database->app_uuid = '8da245ba-e559-4094-9862-4bfaf5cec713';
  136. $database->save($array);
  137. //redirect the user
  138. if (isset($action)) {
  139. if ($action == "add") {
  140. $_SESSION["message"] = $text['message-add'];
  141. }
  142. if ($action == "update") {
  143. $_SESSION["message"] = $text['message-update'];
  144. }
  145. //header('Location: transcribe_queue.php');
  146. header('Location: transcribe_queue_edit.php?id='.urlencode($transcribe_queue_uuid));
  147. return;
  148. }
  149. }
  150. //pre-populate the form
  151. if (is_array($_GET) && $_POST["persistformvar"] != "true") {
  152. $sql = "select ";
  153. $sql .= " transcribe_queue_uuid, ";
  154. $sql .= " hostname, ";
  155. $sql .= " transcribe_status, ";
  156. $sql .= " transcribe_app_class, ";
  157. $sql .= " transcribe_app_method, ";
  158. $sql .= " transcribe_audio_path, ";
  159. $sql .= " transcribe_audio_name, ";
  160. $sql .= " transcribe_message ";
  161. $sql .= "from v_transcribe_queue ";
  162. $sql .= "where transcribe_queue_uuid = :transcribe_queue_uuid ";
  163. $sql .= "and domain_uuid = :domain_uuid ";
  164. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  165. $parameters['transcribe_queue_uuid'] = $transcribe_queue_uuid;
  166. $row = $database->select($sql, $parameters, 'row');
  167. if (is_array($row) && @sizeof($row) != 0) {
  168. $hostname = $row["hostname"];
  169. $transcribe_status = $row["transcribe_status"];
  170. $transcribe_app_class = $row["transcribe_app_class"];
  171. $transcribe_app_method = $row["transcribe_app_method"];
  172. $transcribe_audio_path = $row["transcribe_audio_path"];
  173. $transcribe_audio_name = $row["transcribe_audio_name"];
  174. $transcribe_message = $row["transcribe_message"];
  175. }
  176. unset($sql, $parameters, $row);
  177. }
  178. //create token
  179. $object = new token;
  180. $token = $object->create($_SERVER['PHP_SELF']);
  181. //show the header
  182. $document['title'] = $text['title-transcribe_queue'];
  183. require_once "resources/header.php";
  184. //show the content
  185. echo "<form name='frm' id='frm' method='post' action=''>\n";
  186. echo "<input class='formfld' type='hidden' name='transcribe_queue_uuid' value='".escape($transcribe_queue_uuid)."'>\n";
  187. echo "<div class='action_bar' id='action_bar'>\n";
  188. echo " <div class='heading'><b>".$text['title-transcribe_queue']."</b></div>\n";
  189. echo " <div class='actions'>\n";
  190. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$button_icon_back,'id'=>'btn_back','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'transcribe_queue.php']);
  191. if ($action == 'update') {
  192. if (permission_exists('_add')) {
  193. echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$button_icon_copy,'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]);
  194. }
  195. if (permission_exists('_delete')) {
  196. echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$button_icon_delete,'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none; margin-right: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
  197. }
  198. }
  199. echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$button_icon_save,'id'=>'btn_save','collapse'=>'hide-xs']);
  200. echo " </div>\n";
  201. echo " <div style='clear: both;'></div>\n";
  202. echo "</div>\n";
  203. //echo $text['title_description-transcribe_queue']."\n";
  204. //echo "<br /><br />\n";
  205. if ($action == 'update') {
  206. if (permission_exists('transcribe_queue_add')) {
  207. echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'copy','onclick'=>"modal_close();"])]);
  208. }
  209. if (permission_exists('transcribe_queue_delete')) {
  210. 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();"])]);
  211. }
  212. }
  213. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  214. echo "<tr>\n";
  215. echo "<td width='20%' class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  216. echo " ".$text['label-hostname']."\n";
  217. echo "</td>\n";
  218. echo "<td width='80%' class='vtable' style='position: relative;' align='left'>\n";
  219. echo " <input class='formfld' type='text' name='hostname' maxlength='255' value='".escape($hostname)."'>\n";
  220. echo "<br />\n";
  221. echo $text['description-hostname']."\n";
  222. echo "</td>\n";
  223. echo "</tr>\n";
  224. echo "<tr>\n";
  225. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  226. echo " ".$text['label-transcribe_status']."\n";
  227. echo "</td>\n";
  228. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  229. echo " <select class='formfld' name='transcribe_status'>\n";
  230. echo " <option value=''></option>\n";
  231. if ($transcribe_status == "pending") {
  232. echo " <option value='pending' selected='selected'>".$text['label-pending']."</option>\n";
  233. }
  234. else {
  235. echo " <option value='pending'>".$text['label-pending']."</option>\n";
  236. }
  237. if ($transcribe_status == "processing") {
  238. echo " <option value='processing' selected='selected'>".$text['label-processing']."</option>\n";
  239. }
  240. else {
  241. echo " <option value='processing'>".$text['label-processing']."</option>\n";
  242. }
  243. if ($transcribe_status == "completed") {
  244. echo " <option value='completed' selected='selected'>".$text['label-completed']."</option>\n";
  245. }
  246. else {
  247. echo " <option value='completed'>".$text['label-completed']."</option>\n";
  248. }
  249. if ($transcribe_status == "failed") {
  250. echo " <option value='failed' selected='selected'>".$text['label-failed']."</option>\n";
  251. }
  252. else {
  253. echo " <option value='failed'>".$text['label-failed']."</option>\n";
  254. }
  255. echo " </select>\n";
  256. echo "<br />\n";
  257. echo $text['description-transcribe_status']."\n";
  258. echo "</td>\n";
  259. echo "</tr>\n";
  260. echo "<tr>\n";
  261. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  262. echo " ".$text['label-transcribe_app_class']."\n";
  263. echo "</td>\n";
  264. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  265. echo " <input class='formfld' type='text' name='transcribe_app_class' maxlength='255' value='".escape($transcribe_app_class)."'>\n";
  266. echo "<br />\n";
  267. echo $text['description-transcribe_app_class']."\n";
  268. echo "</td>\n";
  269. echo "</tr>\n";
  270. echo "<tr>\n";
  271. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  272. echo " ".$text['label-transcribe_app_method']."\n";
  273. echo "</td>\n";
  274. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  275. echo " <input class='formfld' type='text' name='transcribe_app_method' maxlength='255' value='".escape($transcribe_app_method)."'>\n";
  276. echo "<br />\n";
  277. echo $text['description-transcribe_app_method']."\n";
  278. echo "</td>\n";
  279. echo "</tr>\n";
  280. echo "<tr>\n";
  281. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  282. echo " ".$text['label-transcribe_audio_path']."\n";
  283. echo "</td>\n";
  284. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  285. echo " <input class='formfld' type='text' name='transcribe_audio_path' maxlength='255' value='".escape($transcribe_audio_path)."'>\n";
  286. echo "<br />\n";
  287. echo $text['description-transcribe_audio_path']."\n";
  288. echo "</td>\n";
  289. echo "</tr>\n";
  290. echo "<tr>\n";
  291. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  292. echo " ".$text['label-transcribe_audio_name']."\n";
  293. echo "</td>\n";
  294. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  295. echo " <input class='formfld' type='text' name='transcribe_audio_name' maxlength='255' value='".escape($transcribe_audio_name)."'>\n";
  296. echo "<br />\n";
  297. echo $text['description-transcribe_audio_name']."\n";
  298. echo "</td>\n";
  299. echo "</tr>\n";
  300. echo "<tr>\n";
  301. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  302. echo " ".$text['label-transcribe_message']."\n";
  303. echo "</td>\n";
  304. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  305. echo " <textarea class='formfld' style='width: 450px; height: 100px;' name='transcribe_message'>";
  306. echo escape($transcribe_message)."\n";
  307. echo " </textarea>";
  308. echo "<br />\n";
  309. echo $text['description-transcribe_message']."\n";
  310. echo "</td>\n";
  311. echo "</tr>\n";
  312. echo "</table>";
  313. echo "<br /><br />";
  314. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  315. echo "</form>";
  316. //include the footer
  317. require_once "resources/footer.php";
  318. ?>