clip_list.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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-2023
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. James Rose <[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('clip_view')) {
  27. //access granted
  28. }
  29. else {
  30. echo "access denied";
  31. exit;
  32. }
  33. //include the header
  34. require_once "header.php";
  35. //add multi-lingual support
  36. $language = new text;
  37. $text = $language->get();
  38. //check if this is a file
  39. function isfile($filename) {
  40. return @filesize($filename) > 0 ? true : false;
  41. }
  42. //count the spaces
  43. function space($count) {
  44. $r=''; $i=0;
  45. while($i < $count) {
  46. $r .= ' ';
  47. $i++;
  48. }
  49. return $r;
  50. }
  51. //setup ajax
  52. echo "<script type=\"text/javascript\" language=\"javascript\">\n";
  53. echo " function makeRequest(url, strpost) {\n";
  54. echo " var http_request = false;\n";
  55. echo "\n";
  56. echo " if (window.XMLHttpRequest) { // Mozilla, Safari, ...\n";
  57. echo " http_request = new XMLHttpRequest();\n";
  58. echo " if (http_request.overrideMimeType) {\n";
  59. echo " http_request.overrideMimeType('text/xml');\n";
  60. echo " // See note below about this line\n";
  61. echo " }\n";
  62. echo " } else if (window.ActiveXObject) { // IE\n";
  63. echo " try {\n";
  64. echo " http_request = new ActiveXObject(\"Msxml2.XMLHTTP\");\n";
  65. echo " } catch (e) {\n";
  66. echo " try {\n";
  67. echo " http_request = new ActiveXObject(\"Microsoft.XMLHTTP\");\n";
  68. echo " } catch (e) {}\n";
  69. echo " }\n";
  70. echo " }\n";
  71. echo "\n";
  72. echo " if (!http_request) {\n";
  73. echo " alert('".$text['message-give-up']."');\n";
  74. echo " return false;\n";
  75. echo " }\n";
  76. echo " http_request.onreadystatechange = function() { returnContent(http_request); };\n";
  77. echo " if (http_request.overrideMimeType) {\n";
  78. echo " http_request.overrideMimeType('text/html');\n";
  79. echo " }\n";
  80. echo " http_request.open('POST', url, true);\n";
  81. echo "\n";
  82. echo "\n";
  83. echo " if (strpost.length == 0) {\n";
  84. echo " //http_request.send(null);\n";
  85. echo " http_request.send('name=value&foo=bar');\n";
  86. echo " }\n";
  87. echo " else {\n";
  88. echo " http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');\n";
  89. echo " http_request.send(strpost);\n";
  90. echo " }\n";
  91. echo "\n";
  92. echo " }\n";
  93. echo "\n";
  94. echo " function returnContent(http_request) {\n";
  95. echo "\n";
  96. echo " if (http_request.readyState == 4) {\n";
  97. echo " if (http_request.status == 200) {\n";
  98. echo " parent.editAreaLoader.setValue('edit1', http_request.responseText); \n";
  99. echo "\n";
  100. echo " }\n";
  101. echo " else {\n";
  102. echo " alert('".$text['message-problem']."');\n";
  103. echo " }\n";
  104. echo " }\n";
  105. echo "\n";
  106. echo " }\n";
  107. echo "</script>";
  108. //setup the tree view
  109. //echo "// ---------------------------------------------\n";
  110. //echo "// --- http://www.codeproject.com/jscript/dhtml_treeview.asp\n";
  111. //echo "// --- Name: Easy DHTML Treeview --\n";
  112. //echo "// --- Author: D.D. de Kerf --\n";
  113. //echo "// --- Version: 0.2 Date: 13-6-2001 --\n";
  114. //echo "// ---------------------------------------------\n";
  115. echo "<script language='JavaScript'>\n";
  116. echo "function Toggle(node) {\n";
  117. echo " // Unfold the branch if it isn't visible\n";
  118. echo " if (node.nextSibling.style.display == 'none') {\n";
  119. echo " node.nextSibling.style.display = 'block';\n";
  120. echo " }\n";
  121. echo " // Collapse the branch if it IS visible\n";
  122. echo " else {\n";
  123. echo " node.nextSibling.style.display = 'none';\n";
  124. echo " }\n";
  125. echo "\n";
  126. echo "}\n";
  127. echo "</script>";
  128. // keyboard shortcut bindings
  129. echo "<script language='JavaScript' type='text/javascript' src='".PROJECT_PATH."/resources/jquery/jquery-3.6.1.min.js'></script>\n";
  130. echo "<script src='https://code.jquery.com/jquery-migrate-3.1.0.js'></script>\n";
  131. //save file
  132. key_press('ctrl+s', 'down', 'window', null, null, "if (parent.document.getElementById('frm_edit')) { parent.$('form#frm_edit').submit(); return false; }", true);
  133. //open file manager/clip library pane
  134. key_press('ctrl+q', 'down', 'window', null, null, "if (parent.document.getElementById('sidebar')) { parent.toggle_sidebar(); parent.focus_editor(); return false; }", true);
  135. //prevent backspace (browser history back)
  136. key_press('backspace', 'down', 'window', null, null, 'return false;', true);
  137. //keyboard shortcut to execute command (when included on command page)
  138. key_press('ctrl+enter', 'down', 'window', null, null, "if (!parent.document.getElementById('sidebar')) { parent.$('form#frm').submit(); return false; }", true);
  139. //show the content
  140. echo "</head>\n";
  141. echo "<body style='margin: 0; padding: 5px;' onfocus='blur();'>\n";
  142. echo "<div style='text-align: left; padding-top: 3px;'>\n";
  143. echo "<div style='padding-bottom: 3px;'><a href='javascript:void(0);' onclick=\"window.open('clip_options.php','clipwin','left=20,top=20,width=310,height=350,toolbar=0,resizable=0');\" style='text-decoration:none; cursor: pointer;' title=\"".$text['label-clip-library']."\"><img src='resources/images/icon_gear.png' border='0' align='absmiddle' style='margin: 0px 2px 4px -1px;'>".$text['label-clip-library']."</a></div>\n";
  144. $sql = "select * from v_clips order by clip_folder asc, clip_name asc";
  145. $database = new database;
  146. $result = $database->select($sql, null, 'all');
  147. unset($sql);
  148. if (!empty($result) && is_array($result) && @sizeof($result) != 0) {
  149. $master_array = array();
  150. foreach ($result as $row) {
  151. if (!empty($row['clip_folder'])) {
  152. $clip_folder = rtrim($row['clip_folder'], '/');
  153. }
  154. $clip_folder .= '/'.$row['clip_name'];
  155. $parts = explode('/', $clip_folder);
  156. $folders = array();
  157. while ($bottom = array_pop($parts)) {
  158. if (sizeof($folders) > 0) {
  159. $folders = array($bottom => $folders);
  160. }
  161. else {
  162. $clip['uuid'] = $row['clip_uuid'];
  163. $clip['name'] = $row['clip_name'];
  164. $clip['before'] = $row['clip_text_start'];
  165. $clip['after'] = $row['clip_text_end'];
  166. $folders = array($bottom => $clip);
  167. }
  168. }
  169. $master_array = array_merge_recursive($master_array, $folders);
  170. }
  171. unset($result, $row);
  172. function parse_array($array) {
  173. if (!empty(is_array($array)) && is_array($array)) {
  174. foreach ($array as $folder_name => $clips) {
  175. //folder
  176. echo "<a onclick='Toggle(this);' style='display: block; cursor: pointer; text-decoration: none;'><img src='resources/images/icon_folder.png' border='none' align='absmiddle' style='margin: 1px 2px 3px 0px;'>".$folder_name."</a>";
  177. echo "<div style='display: none; padding-left: 16px;'>\n";
  178. //clips
  179. foreach($clips as $row) {
  180. //clip
  181. echo "<div style='white-space: nowrap;'>\n";
  182. echo "<a href='javascript:void(0);' onclick=\"parent.insert_clip(document.getElementById('before_".$row['uuid']."').value, document.getElementById('after_".$row['uuid']."').value);\">";
  183. echo "<img src='resources/images/icon_file.png' border='0' align='absmiddle' style='margin: 1px 2px 3px -1px;'>";
  184. echo escape($row['name']);
  185. echo "</a>\n";
  186. echo "<textarea style='display: none' id='before_".$row['uuid']."'>".$row['before']."</textarea>\n";
  187. echo "<textarea style='display: none' id='after_".$row['uuid']."'>".$row['after']."</textarea>\n";
  188. echo "</div>\n";
  189. }
  190. echo "</div>\n";
  191. }
  192. }
  193. }
  194. parse_array($master_array);
  195. }
  196. echo "</div>\n";
  197. //inclue the footer
  198. require_once "footer.php";