PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/fusionpbx/mod/php_edit/index.php

https://github.com/bfritz/fusionpbx
PHP | 249 lines | 171 code | 23 blank | 55 comment | 21 complexity | 31885b93983b4166d90dc301c1709932 MD5 | raw file
  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 <markjcrane@fusionpbx.com>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2010
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <markjcrane@fusionpbx.com>
  20. */
  21. include "root.php";
  22. require_once "includes/config.php";
  23. require_once "includes/checkauth.php";
  24. if (ifgroup("admin")) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. echo "<html>\n";
  32. echo "<head>\n";
  33. echo " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n";
  34. echo " <title></title>";
  35. echo "<script type=\"text/javascript\" language=\"javascript\">\n";
  36. echo "// Replaces all instances of the given substring.\n";
  37. echo "String.prototype.replaceall = function(\n";
  38. echo "strTarget, \n"; // The substring you want to replace
  39. echo "strSubString \n"; // The string you want to replace in
  40. echo ")\n";
  41. echo "{\n";
  42. echo " var strText = this;\n";
  43. echo " var intIndexOfMatch = strText.indexOf( strTarget );\n";
  44. echo " \n";
  45. echo " // Keep looping while an instance of the target string\n";
  46. echo " // still exists in the string.\n";
  47. echo " while (intIndexOfMatch != -1){\n";
  48. echo " // Relace out the current instance.\n";
  49. echo " strText = strText.replace( strTarget, strSubString )\n";
  50. echo " \n";
  51. echo " // Get the index of any next matching substring.\n";
  52. echo " intIndexOfMatch = strText.indexOf( strTarget );\n";
  53. echo "}\n";
  54. //echo "// Return the updated string with ALL the target strings\n";
  55. //echo "// replaced out with the new substring.\n";
  56. echo "return( strText );\n";
  57. echo "}\n";
  58. echo "function urlencode(str) {\n";
  59. echo " str=escape(str); \n"; //Escape does not encode '/' and '+' character
  60. echo " str=str.replaceall(\"+\", \"%2B\");\n";
  61. echo " str=str.replaceall(\"/\", \"%2F\");\n";
  62. echo " return str;\n";
  63. echo "}";
  64. echo "</script>\n";
  65. echo "<script type=\"text/javascript\" language=\"javascript\">\n";
  66. echo " function makeRequest(url, strpost) {\n";
  67. //echo " alert(url); \n";
  68. echo " var http_request = false;\n";
  69. echo "\n";
  70. echo " if (window.XMLHttpRequest) { // Mozilla, Safari, ...\n";
  71. echo " http_request = new XMLHttpRequest();\n";
  72. echo " if (http_request.overrideMimeType) {\n";
  73. echo " http_request.overrideMimeType('text/xml');\n";
  74. echo " // See note below about this line\n";
  75. echo " }\n";
  76. echo " } else if (window.ActiveXObject) { // IE\n";
  77. echo " try {\n";
  78. echo " http_request = new ActiveXObject(\"Msxml2.XMLHTTP\");\n";
  79. echo " } catch (e) {\n";
  80. echo " try {\n";
  81. echo " http_request = new ActiveXObject(\"Microsoft.XMLHTTP\");\n";
  82. echo " } catch (e) {}\n";
  83. echo " }\n";
  84. echo " }\n";
  85. echo "\n";
  86. echo " if (!http_request) {\n";
  87. echo " alert('Giving up :( Cannot create an XMLHTTP instance');\n";
  88. echo " return false;\n";
  89. echo " }\n";
  90. echo " http_request.onreadystatechange = function() { returnContent(http_request); };\n";
  91. echo " if (http_request.overrideMimeType) {\n";
  92. echo " http_request.overrideMimeType('text/html');\n";
  93. echo " }\n";
  94. echo " http_request.open('POST', url, true);\n";
  95. echo "\n";
  96. echo "\n";
  97. echo " if (strpost.length == 0) {\n";
  98. //echo " alert('none');\n";
  99. echo " //http_request.send(null);\n";
  100. echo " http_request.send('name=value&foo=bar');\n";
  101. echo " }\n";
  102. echo " else {\n";
  103. //echo " alert(strpost);\n";
  104. echo " http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');\n";
  105. //echo " http_request.send('name=value&foo=bar');\n";
  106. echo " http_request.send(strpost);\n";
  107. echo " }\n";
  108. echo "\n";
  109. echo " }\n";
  110. echo "\n";
  111. echo " function returnContent(http_request) {\n";
  112. echo "\n";
  113. echo " if (http_request.readyState == 4) {\n";
  114. echo " if (http_request.status == 200) {\n";
  115. echo " parent.editAreaLoader.setValue('edit1', http_request.responseText); \n";
  116. //echo " alert(http_request.responseText);\n";
  117. echo "\n";
  118. //echo " //var xmldoc = http_request.responseXML;\n";
  119. //echo " //var root_node = xmldoc.getElementsByTagName('doc').item(0);\n";
  120. //echo " //alert(xmldoc.getElementByID('fr1').value);\n";
  121. //echo " //alert(root_node.firstChild.data);\n";
  122. //echo "\n";
  123. echo " }\n";
  124. echo " else {\n";
  125. echo " alert('There was a problem with the request.');\n";
  126. echo " }\n";
  127. echo " }\n";
  128. echo "\n";
  129. echo " }\n";
  130. echo "</script>";
  131. ?>
  132. <script language="Javascript" type="text/javascript" src="<?php echo PROJECT_PATH; ?>/includes/edit_area/edit_area_full.js"></script>
  133. <script language="Javascript" type="text/javascript">
  134. // initialisation
  135. editAreaLoader.init({
  136. id: "edit1" // id of the textarea to transform
  137. ,start_highlight: true
  138. ,allow_toggle: false
  139. ,language: "en"
  140. ,word_wrap: false
  141. ,syntax: "xml"
  142. ,toolbar: "save, |, search, go_to_line,|, fullscreen, |, undo, redo, |, select_font, |, syntax_selection, |, change_smooth_selection, highlight, reset_highlight, |, help"
  143. ,syntax_selection_allow: "css,html,js,php,xml,c,cpp,sql"
  144. ,show_line_colors: true
  145. ,load_callback: "my_load"
  146. ,save_callback: "my_save"
  147. });
  148. // callback functions
  149. function my_save(id, content){
  150. //alert(content);
  151. makeRequest('filesave.php','file='+document.getElementById('file').value+'&content='+urlencode(content));
  152. parent.document.title=''+unescape(document.getElementById('file').value)+' :: Saved';
  153. //setTimeout("parent.document.title='<?=$applicationname?> - '+unescape(document.getElementById('file').value);", 5);
  154. //setTimeout("alert('test')", 5);
  155. }
  156. function my_load(elem){
  157. elem.value="The content is loaded from the load_callback function into EditArea";
  158. }
  159. function my_setSelectionRange(id){
  160. editAreaLoader.setSelectionRange(id, 0, 0);
  161. }
  162. function test_setSelectionRange(id){
  163. editAreaLoader.setSelectionRange(id, 0, 0);
  164. }
  165. function test_getSelectionRange(id){
  166. var sel =editAreaLoader.getSelectionRange(id);
  167. alert("start: "+sel["start"]+"\nend: "+sel["end"]);
  168. }
  169. function test_setSelectedText(id){
  170. text= "[REPLACED SELECTION]";
  171. editAreaLoader.setSelectedText(id, text);
  172. }
  173. function test_getSelectedText(id){
  174. alert(editAreaLoader.getSelectedText(id));
  175. }
  176. </script>
  177. </head>
  178. <?php
  179. //<body marginwidth="0" marginheight="0" style="margin: 0" onresize="elem = document.getElementById('edit1'); elem.style.height='100%'; elem.style.width='100%'; document.getElementById('toolbar').style.width='200px';">
  180. ?>
  181. <table border='0' style="height: 100%; width: 100%;">
  182. <tr>
  183. <td id='toolbar' valign='top' width='200' style="width: 200;" height='100%' nowrap='nowrap'>
  184. <IFRAME SRC='filelist.php' style='border: solid 1px #CCCCCC; height: 50%; width: 100%;' TITLE=''>
  185. <!-- File List: Requires IFRAME support -->
  186. </IFRAME>
  187. <IFRAME SRC='cliplist.php' style='border: solid 1px #CCCCCC; height: 50%; width: 100%;' TITLE=''>
  188. <!-- Clip List: Requires IFRAME support -->
  189. </IFRAME>
  190. </td>
  191. <td valign='top' width="100%" height='100%' style="height: 100%;">
  192. <?php
  193. if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)) {
  194. //IE doesn't work with the 100% width with the IFRAME
  195. echo "<textarea id='edit1' wrap='off' style='height: 100%; width: 800px; white-space: nowrap;' name=''>\n";
  196. echo "</textarea>\n";
  197. }
  198. else {
  199. echo "<textarea id='edit1' wrap='off' style='height: 100%; width: 100%; white-space: nowrap;' name=''>\n";
  200. echo "</textarea>\n";
  201. }
  202. ?>
  203. <input type='hidden' id='file' name='file' value='' />
  204. </td>
  205. </tr>
  206. </table>
  207. <?php
  208. /*
  209. echo " <p>Custom controls:<br />\n";
  210. echo " <input type='button' onclick='alert(editAreaLoader.getValue(\"edit1\"));' value='get value' />\n";
  211. echo " <input type='button' onclick='editAreaLoader.setValue(\"edit1\", \"new_value\");' value='set value' />\n";
  212. echo " <input type='button' onclick='test_getSelectionRange(\"edit1\");' value='getSelectionRange' />\n";
  213. echo " <input type='button' onclick='test_setSelectionRange(\"edit1\");' value='setSelectionRange' />\n";
  214. echo " <input type='button' onclick='test_getSelectedText(\"edit1\");' value='getSelectedText' />\n";
  215. echo " <input type='button' onclick='test_setSelectedText(\"edit1\");' value='setSelectedText' />\n";
  216. echo " <input type='button' onclick='editAreaLoader.insertTags(\"edit1\", \"[OPEN]\", \"[CLOSE]\");' value='insertTags' />\n";
  217. echo " </p>";
  218. */
  219. ?>
  220. </body>
  221. </html>