clip_list.php 8.3 KB

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