transcribe_queue.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. //includes files
  23. require_once "resources/paging.php";
  24. //check permissions
  25. if (!permission_exists('transcribe_queue_view')) {
  26. echo "access denied";
  27. exit;
  28. }
  29. //add multi-lingual support
  30. $language = new text;
  31. $text = $language->get();
  32. //connect to the database
  33. $database = database::new();
  34. //add the settings object
  35. $settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]);
  36. //set from session variables
  37. $list_row_edit_button = $settings->get('theme', 'list_row_edit_button', 'false');
  38. //get the http post data
  39. if (!empty($_POST['transcribe_queue']) && is_array($_POST['transcribe_queue'])) {
  40. $action = $_POST['action'];
  41. $search = $_POST['search'];
  42. $transcribe_queue = $_POST['transcribe_queue'];
  43. }
  44. //process the http post data by action
  45. if (!empty($action) && !empty($transcribe_queue) && is_array($transcribe_queue) && @sizeof($transcribe_queue) != 0) {
  46. //validate the token
  47. $token = new token;
  48. if (!$token->validate($_SERVER['PHP_SELF'])) {
  49. message::add($text['message-invalid_token'],'negative');
  50. header('Location: transcribe_queue.php');
  51. exit;
  52. }
  53. //prepare the array
  54. if (!empty($transcribe_queue)) {
  55. foreach ($transcribe_queue as $row) {
  56. $array['transcribe_queue'][$x]['checked'] = $row['checked'];
  57. $array['transcribe_queue'][$x]['transcribe_queue_uuid'] = $row['transcribe_queue_uuid'];
  58. $x++;
  59. }
  60. }
  61. //prepare the database object
  62. $database->app_name = 'transcribe_queue';
  63. $database->app_uuid = '8da245ba-e559-4094-9862-4bfaf5cec713';
  64. //send the array to the database class
  65. switch ($action) {
  66. case 'copy':
  67. if (permission_exists('transcribe_queue_add')) {
  68. $database->copy($array);
  69. //$obj = new transcribe_queue;
  70. //$obj->copy($transcribe_queue);
  71. }
  72. break;
  73. case 'toggle':
  74. if (permission_exists('transcribe_queue_edit')) {
  75. $database->toggle($array);
  76. //$obj = new transcribe_queue;
  77. //$obj->toggle($transcribe_queue);
  78. }
  79. break;
  80. case 'delete':
  81. if (permission_exists('transcribe_queue_delete')) {
  82. $database->delete($array);
  83. //$obj = new transcribe_queue;
  84. //$obj->delete($transcribe_queue);
  85. }
  86. break;
  87. }
  88. //redirect the user
  89. header('Location: transcribe_queue.php'.($search != '' ? '?search='.urlencode($search) : null));
  90. exit;
  91. }
  92. //get order and order by
  93. $order_by = $_GET["order_by"] ?? 'u.insert_date';
  94. $order = $_GET["order"] ?? 'desc';
  95. //define the variables
  96. $search = '';
  97. $show = '';
  98. $list_row_url = '';
  99. //add the search variable
  100. if (!empty($_GET["search"])) {
  101. $search = strtolower($_GET["search"]);
  102. }
  103. //add the show variable
  104. if (!empty($_GET["show"])) {
  105. $show = $_GET["show"];
  106. }
  107. //set the time zone
  108. $time_zone = $settings->get('domain', 'time_zone', date_default_timezone_get());
  109. //get the count
  110. $sql = "select count(transcribe_queue_uuid) ";
  111. $sql .= "from v_transcribe_queue ";
  112. if (permission_exists('transcribe_queue_all') && $show == 'all') {
  113. $sql .= "where true ";
  114. }
  115. else {
  116. $sql .= "where domain_uuid = :domain_uuid ";
  117. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  118. }
  119. if (!empty($search)) {
  120. $sql .= "and ( ";
  121. $sql .= " lower(hostname) like :search ";
  122. $sql .= " or lower(transcribe_status) like :search ";
  123. $sql .= " or lower(transcribe_app_class) like :search ";
  124. $sql .= " or lower(transcribe_app_method) like :search ";
  125. $sql .= " or lower(transcribe_message) like :search ";
  126. $sql .= ") ";
  127. $parameters['search'] = '%'.$search.'%';
  128. }
  129. $num_rows = $database->select($sql, $parameters ?? null, 'column');
  130. unset($sql, $parameters);
  131. //prepare to page the results
  132. $rows_per_page = $settings->get('domain', 'paging', 50);
  133. $param = !empty($search) ? "&search=".$search : null;
  134. $param .= (!empty($_GET['page']) && $show == 'all' && permission_exists('transcribe_queue_all')) ? "&show=all" : null;
  135. $page = !empty($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 0;
  136. list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
  137. list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
  138. $offset = $rows_per_page * $page;
  139. //get the list
  140. $sql = "select ";
  141. $sql .= "transcribe_queue_uuid, ";
  142. $sql .= "u.domain_uuid, ";
  143. $sql .= "d.domain_name, ";
  144. $sql .= "hostname, ";
  145. $sql .= "to_char(timezone(:time_zone, u.insert_date), 'DD Mon YYYY') as date_formatted, \n";
  146. $sql .= "to_char(timezone(:time_zone, u.insert_date), 'HH12:MI:SS am') as time_formatted, \n";
  147. $sql .= "transcribe_status, ";
  148. $sql .= "transcribe_duration, ";
  149. $sql .= "transcribe_app_class, ";
  150. $sql .= "transcribe_app_method ";
  151. $sql .= "from v_transcribe_queue as u, v_domains as d ";
  152. if (permission_exists('transcribe_queue_all') && $show == 'all') {
  153. $sql .= "where true ";
  154. }
  155. else {
  156. $sql .= "where u.domain_uuid = :domain_uuid ";
  157. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  158. }
  159. if (!empty($search)) {
  160. $sql .= "and ( ";
  161. $sql .= " lower(hostname) like :search ";
  162. $sql .= " or lower(transcribe_status) like :search ";
  163. $sql .= " or lower(transcribe_app_class) like :search ";
  164. $sql .= " or lower(transcribe_app_method) like :search ";
  165. $sql .= " or lower(transcribe_message) like :search ";
  166. $sql .= ") ";
  167. $parameters['search'] = '%'.$search.'%';
  168. }
  169. $sql .= "and u.domain_uuid = d.domain_uuid ";
  170. $sql .= order_by($order_by, $order, '', '');
  171. $sql .= limit_offset($rows_per_page, $offset);
  172. $parameters['time_zone'] = $time_zone;
  173. $transcribe_queue = $database->select($sql, $parameters ?? null, 'all');
  174. unset($sql, $parameters);
  175. //create token
  176. $object = new token;
  177. $token = $object->create($_SERVER['PHP_SELF']);
  178. //additional includes
  179. $document['title'] = $text['title-transcribe_queue'];
  180. require_once "resources/header.php";
  181. //show the content
  182. echo "<div class='action_bar' id='action_bar'>\n";
  183. echo " <div class='heading'><b>".$text['title-transcribe_queue']." (".$num_rows.")</b></div>\n";
  184. echo " <div class='actions'>\n";
  185. if (permission_exists('transcribe_queue_add') && $transcribe_queue) {
  186. echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$settings->get('theme', 'button_icon_copy'),'id'=>'btn_copy','name'=>'btn_copy','style'=>'display:none;','onclick'=>"modal_open('modal-copy','btn_copy');"]);
  187. }
  188. if (permission_exists('transcribe_queue_edit') && $transcribe_queue) {
  189. echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$settings->get('theme', 'button_icon_toggle'),'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display:none;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]);
  190. }
  191. if (permission_exists('transcribe_queue_delete') && $transcribe_queue) {
  192. echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$settings->get('theme', 'button_icon_delete'),'id'=>'btn_delete','name'=>'btn_delete','style'=>'display:none;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
  193. }
  194. echo "<form id='form_search' class='inline' method='get'>\n";
  195. if (permission_exists('transcribe_queue_all')) {
  196. if ($show == 'all') {
  197. echo " <input type='hidden' name='show' value='all'>\n";
  198. }
  199. else {
  200. echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$settings->get('theme', 'button_icon_all'),'link'=>'?show=all&search='.$search]);
  201. }
  202. }
  203. echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
  204. echo button::create(['label'=>$text['button-search'],'icon'=>$settings->get('theme', 'button_icon_search'),'type'=>'submit','id'=>'btn_search']);
  205. if ($paging_controls_mini != '') {
  206. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  207. }
  208. echo " </form>\n";
  209. echo " </div>\n";
  210. echo " <div style='clear: both;'></div>\n";
  211. echo "</div>\n";
  212. if (permission_exists('transcribe_queue_add') && $transcribe_queue) {
  213. echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]);
  214. }
  215. if (permission_exists('transcribe_queue_edit') && $transcribe_queue) {
  216. echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]);
  217. }
  218. if (permission_exists('transcribe_queue_delete') && $transcribe_queue) {
  219. echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]);
  220. }
  221. echo "<form id='form_list' method='post'>\n";
  222. echo "<input type='hidden' id='action' name='action' value=''>\n";
  223. echo "<input type='hidden' name='search' value=\"".escape($search ?? '')."\">\n";
  224. echo "<table class='list'>\n";
  225. echo "<tr class='list-header'>\n";
  226. if (permission_exists('transcribe_queue_add') || permission_exists('transcribe_queue_edit') || permission_exists('transcribe_queue_delete')) {
  227. echo " <th class='checkbox'>\n";
  228. echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".empty($transcribe_queue ? "style='visibility: hidden;'" : null).">\n";
  229. echo " </th>\n";
  230. }
  231. if ($show == 'all' && permission_exists('transcribe_queue_all')) {
  232. echo th_order_by('domain_name', $text['label-domain'], $order_by, $order);
  233. }
  234. echo "<th class=''>".$text['label-date']."</th>\n";
  235. echo "<th class='hide-md-dn'>".$text['label-time']."</th>\n";
  236. echo "<th class='hide-md-dn'>".$text['label-hostname']."</th>\n";
  237. echo "<th class='hide-md-dn'>".$text['label-transcribe_application_name']."</th>\n";
  238. //echo th_order_by('transcribe_application_name', $text['label-transcribe_application_name'], $order_by, $order);
  239. echo "<th class=''>".$text['label-transcribe_duration']."</th>\n";
  240. echo th_order_by('transcribe_status', $text['label-transcribe_status'], $order_by, $order);
  241. //echo th_order_by('transcribe_target_table', $text['label-transcribe_target_table'], $order_by, $order);
  242. //echo th_order_by('transcribe_target_key_name', $text['label-transcribe_target_key_name'], $order_by, $order);
  243. //echo th_order_by('transcribe_target_column_name', $text['label-transcribe_target_column_name'], $order_by, $order);
  244. if (permission_exists('transcribe_queue_edit') && $list_row_edit_button == 'true') {
  245. echo " <td class='action-button'>&nbsp;</td>\n";
  246. }
  247. echo "</tr>\n";
  248. if (!empty($transcribe_queue) && is_array($transcribe_queue) && @sizeof($transcribe_queue) != 0) {
  249. $x = 0;
  250. foreach ($transcribe_queue as $row) {
  251. if (permission_exists('transcribe_queue_edit')) {
  252. $list_row_url = "transcribe_queue_edit.php?id=".urlencode($row['transcribe_queue_uuid']);
  253. }
  254. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  255. if (permission_exists('transcribe_queue_add') || permission_exists('transcribe_queue_edit') || permission_exists('transcribe_queue_delete')) {
  256. echo " <td class='checkbox'>\n";
  257. echo " <input type='checkbox' name='transcribe_queue[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
  258. echo " <input type='hidden' name='transcribe_queue[$x][transcribe_queue_uuid]' value='".escape($row['transcribe_queue_uuid'])."' />\n";
  259. echo " </td>\n";
  260. }
  261. if ($show == 'all' && permission_exists('transcribe_queue_all')) {
  262. echo " <td>".escape($row['domain_name'])."</td>\n";
  263. }
  264. echo " <td nowrap='nowrap'>".escape($row['date_formatted'])." </td>\n";
  265. echo " <td nowrap='nowrap' class='shrink hide-md-dn'>".escape($row['time_formatted'])." </td>\n";
  266. echo " <td class='hide-md-dn'>\n";
  267. if (permission_exists('transcribe_queue_edit')) {
  268. echo " <a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['hostname'])."</a>\n";
  269. }
  270. else {
  271. echo " ".escape($row['hostname']);
  272. }
  273. echo " </td>\n";
  274. echo " <td>".escape($row['transcribe_app_model'])."</td>\n";
  275. echo " <td class='hide-md-dn'>".escape($row['transcribe_duration'])."</td>\n";
  276. echo " <td>".escape($row['transcribe_status'])."</td>\n";
  277. //echo " <td>".escape($row['transcribe_target_table'])."</td>\n";
  278. //echo " <td>".escape($row['transcribe_target_key_name'])."</td>\n";
  279. //echo " <td>".escape($row['transcribe_target_column_name'])."</td>\n";
  280. if (permission_exists('transcribe_queue_edit') && $list_row_edit_button == 'true') {
  281. echo " <td class='action-button'>\n";
  282. echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$settings->get('theme', 'button_icon_edit'),'link'=>$list_row_url]);
  283. echo " </td>\n";
  284. }
  285. echo "</tr>\n";
  286. $x++;
  287. }
  288. unset($transcribe_queue);
  289. }
  290. echo "</table>\n";
  291. echo "<br />\n";
  292. echo "<div align='center'>".$paging_controls."</div>\n";
  293. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  294. echo "</form>\n";
  295. //include the footer
  296. require_once "resources/footer.php";
  297. ?>