cliplist.php 8.0 KB

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