PageRenderTime 26ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/fusionpbx/mod/php_edit/fileoptionslist.php

https://github.com/bfritz/fusionpbx
PHP | 288 lines | 155 code | 34 blank | 99 comment | 32 complexity | c55b42c2c00d2dbad6df12a60595fa56 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. require_once "config.php";
  32. require_once "header.php";
  33. function isfile($filename) {
  34. if (@filesize($filename) > 0) { return true; } else { return false; }
  35. }
  36. function space($count) {
  37. $r=''; $i=0;
  38. while($i < $count) {
  39. $r .= ' ';
  40. $i++;
  41. }
  42. return $r;
  43. }
  44. function recur_dir($dir) {
  45. clearstatcache();
  46. $htmldirlist = '';
  47. $htmlfilelist = '';
  48. $dirlist = opendir($dir);
  49. while ($file = readdir ($dirlist)) {
  50. if ($file != '.' && $file != '..') {
  51. $newpath = $dir.'/'.$file;
  52. $level = explode('/',$newpath);
  53. if (is_dir($newpath)) {
  54. /*$mod_array[] = array(
  55. 'level'=>count($level)-1,
  56. 'path'=>$newpath,
  57. 'name'=>end($level),
  58. 'type'=>'dir',
  59. 'mod_time'=>filemtime($newpath),
  60. 'size'=>'');
  61. $mod_array[] = recur_dir($newpath);
  62. */
  63. $dirname = end($level);
  64. $htmldirlist .= space(count($level))."<TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD nowrap WIDTH=12></TD><TD nowrap><A onClick=\"Toggle(this, '".$newpath."');\"><IMG SRC=\"images/plus.gif\"> <IMG SRC=\"images/folder.gif\" border='0'> $dirname </a><DIV style='display:none'>\n";
  65. //$htmldirlist .= space(count($level))." <TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD nowrap WIDTH=12></TD><TD nowrap><A onClick=\"Toggle(this)\"><IMG SRC=\"images/plus.gif\"> <IMG SRC=\"images/gear.png\"> Tools </A><DIV style='display:none'>\n";
  66. //$htmldirlist .= space(count($level))." <TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD nowrap WIDTH=12></TD><TD nowrap align='bottom'><IMG SRC=\"images/file.png\"><a href='foldernew.php?folder=".urlencode($newpath)."' title=''>New Folder </a><DIV style='display:none'>\n"; //parent.document.getElementById('file').value='".urlencode($newpath)."'
  67. //$htmldirlist .= space(count($level))." </DIV></TD></TR></TABLE>\n";
  68. //$htmldirlist .= space(count($level))." <TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD nowrap WIDTH=12></TD><TD nowrap align='bottom'><IMG SRC=\"images/file.png\"><a href='filenew.php?folder=".urlencode($newpath)."' title=''>New File </a><DIV style='display:none'>\n"; //parent.document.getElementById('file').value='".urlencode($newpath)."'
  69. //$htmldirlist .= space(count($level))." </DIV></TD></TR></TABLE>\n";
  70. //$htmldirlist .= space(count($level))." </DIV></TD></TR></TABLE>\n";
  71. //$htmldirlist .= space(count($level))." <TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD nowrap WIDTH=12></TD><TD nowrap align='bottom'><IMG SRC=\"images/gear.png\"><a href='fileoptions.php?folder=".urlencode($newpath)."' title=''>Options </a><DIV style='display:none'>\n"; //parent.document.getElementById('file').value='".urlencode($newpath)."'
  72. //$htmldirlist .= space(count($level))." </DIV></TD></TR></TABLE>\n";
  73. $htmldirlist .= recur_dir($newpath);
  74. $htmldirlist .= space(count($level))."</DIV></TD></TR></TABLE>\n";
  75. }
  76. else {
  77. /*$mod_array[] = array(
  78. 'level'=>count($level)-1,
  79. 'path'=>$newpath,
  80. 'name'=>end($level),
  81. 'type'=>'file',
  82. 'mod_time'=>filemtime($newpath),
  83. 'size'=>filesize($newpath));
  84. */
  85. $filename = end($level);
  86. $filesize = round(filesize($newpath)/1024, 2);
  87. $newpath = str_replace ($filename, "", $newpath);
  88. $htmlfilelist .= space(count($level))."<TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD nowrap WIDTH=12></TD><TD nowrap align='bottom'><a href='javascript:void(0);' onclick=\"parent.document.getElementById('filename').value='".$filename."'; parent.document.getElementById('folder').value='".$newpath."';\" title='$filesize KB'><IMG SRC=\"images/file.png\" border='none'>$filename</a><DIV style='display:none'>\n";
  89. $htmlfilelist .= space(count($level))."</DIV></TD></TR></TABLE>\n";
  90. }
  91. }
  92. }
  93. closedir($dirlist);
  94. return $htmldirlist ."\n". $htmlfilelist;
  95. }
  96. echo "<script type=\"text/javascript\" language=\"javascript\">\n";
  97. echo " function makeRequest(url, strpost) {\n";
  98. //echo " alert(url); \n";
  99. echo " var http_request = false;\n";
  100. echo "\n";
  101. echo " if (window.XMLHttpRequest) { // Mozilla, Safari, ...\n";
  102. echo " http_request = new XMLHttpRequest();\n";
  103. echo " if (http_request.overrideMimeType) {\n";
  104. echo " http_request.overrideMimeType('text/xml');\n";
  105. echo " // See note below about this line\n";
  106. echo " }\n";
  107. echo " } else if (window.ActiveXObject) { // IE\n";
  108. echo " try {\n";
  109. echo " http_request = new ActiveXObject(\"Msxml2.XMLHTTP\");\n";
  110. echo " } catch (e) {\n";
  111. echo " try {\n";
  112. echo " http_request = new ActiveXObject(\"Microsoft.XMLHTTP\");\n";
  113. echo " } catch (e) {}\n";
  114. echo " }\n";
  115. echo " }\n";
  116. echo "\n";
  117. echo " if (!http_request) {\n";
  118. echo " alert('Giving up :( Cannot create an XMLHTTP instance');\n";
  119. echo " return false;\n";
  120. echo " }\n";
  121. echo " http_request.onreadystatechange = function() { returnContent(http_request); };\n";
  122. echo " http_request.overrideMimeType('text/html');\n";
  123. echo " http_request.open('POST', url, true);\n";
  124. echo "\n";
  125. echo "\n";
  126. echo " if (strpost.length == 0) {\n";
  127. //echo " alert('none');\n";
  128. echo " //http_request.send(null);\n";
  129. echo " http_request.send('name=value&foo=bar');\n";
  130. echo " }\n";
  131. echo " else {\n";
  132. //echo " alert(strpost);\n";
  133. echo " http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');\n";
  134. //echo " http_request.send('name=value&foo=bar');\n";
  135. echo " http_request.send(strpost);\n";
  136. echo " }\n";
  137. echo "\n";
  138. echo " }\n";
  139. echo "\n";
  140. echo " function returnContent(http_request) {\n";
  141. echo "\n";
  142. echo " if (http_request.readyState == 4) {\n";
  143. echo " if (http_request.status == 200) {\n";
  144. echo " parent.editAreaLoader.setValue('edit1', http_request.responseText); \n";
  145. //echo " alert(http_request.responseText);\n";
  146. echo "\n";
  147. //echo " //var xmldoc = http_request.responseXML;\n";
  148. //echo " //var root_node = xmldoc.getElementsByTagName('doc').item(0);\n";
  149. //echo " //alert(xmldoc.getElementByID('fr1').value);\n";
  150. //echo " //alert(root_node.firstChild.data);\n";
  151. //echo "\n";
  152. echo " }\n";
  153. echo " else {\n";
  154. echo " alert('There was a problem with the request.');\n";
  155. echo " }\n";
  156. echo " }\n";
  157. echo "\n";
  158. echo " }\n";
  159. echo "</script>\n";
  160. echo "<SCRIPT LANGUAGE=\"JavaScript\">\n";
  161. //echo "// ---------------------------------------------\n";
  162. //echo "// --- http://www.codeproject.com/jscript/dhtml_treeview.asp\n";
  163. //echo "// --- Name: Easy DHTML Treeview --\n";
  164. //echo "// --- Author: D.D. de Kerf --\n";
  165. //echo "// --- Version: 0.2 Date: 13-6-2001 --\n";
  166. //echo "// ---------------------------------------------\n";
  167. echo "function Toggle(node, path) {\n";
  168. echo " parent.document.getElementById('folder').value=path; \n";
  169. echo " parent.document.getElementById('filename').value='';\n";
  170. echo " parent.document.getElementById('folder').focus();\n";
  171. echo " // Unfold the branch if it isn't visible\n";
  172. echo " if (node.nextSibling.style.display == 'none') {\n";
  173. echo " // Change the image (if there is an image)\n";
  174. echo " if (node.childNodes.length > 0) {\n";
  175. echo " if (node.childNodes.item(0).nodeName == \"IMG\") {\n";
  176. echo " node.childNodes.item(0).src = \"images/minus.gif\";\n";
  177. echo " }\n";
  178. echo " }\n";
  179. echo " \n";
  180. echo " node.nextSibling.style.display = 'block';\n";
  181. echo " }\n";
  182. echo " // Collapse the branch if it IS visible\n";
  183. echo " else {\n";
  184. echo " // Change the image (if there is an image)\n";
  185. echo " if (node.childNodes.length > 0) {\n";
  186. echo " if (node.childNodes.item(0).nodeName == \"IMG\") {\n";
  187. echo " node.childNodes.item(0).src = \"images/plus.gif\";\n";
  188. echo " }\n";
  189. echo " }\n";
  190. echo " node.nextSibling.style.display = 'none';\n";
  191. echo " }\n";
  192. echo "\n";
  193. echo "}\n";
  194. echo "</SCRIPT>\n";
  195. echo "<div align='center' valign='1'>";
  196. echo "<table width='100%' height='100%' border='0' cellpadding='0' cellspacing='2'>\n";
  197. echo "<tr class='border'>\n";
  198. echo " <td align=\"left\" valign='top' nowrap>\n";
  199. //echo " <br>";
  200. echo "\n";
  201. echo " <TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD><IMG SRC=\"images/folder.gif\" border='0'> Files <DIV style=''>\n"; //display:none
  202. //echo " <TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD><A onClick=\"Toggle(this, '')\"><IMG SRC=\"images/plus.gif\"> <IMG SRC=\"images/folder.gif\"> Files </A><DIV style=''>\n"; //display:none
  203. //echo "<TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD nowrap WIDTH=12></TD><TD nowrap><A onClick=\"Toggle(this, '')\"><IMG SRC=\"images/plus.gif\"> <IMG SRC=\"images/gear.png\"> Tools </A><DIV style='display:none'>\n";
  204. //echo "<TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD nowrap WIDTH=12></TD><TD nowrap align='bottom'><IMG SRC=\"images/file.png\"><a href='foldernew.php?folder=".urlencode($_SERVER["DOCUMENT_ROOT"])."' title=''>New Folder </a><DIV style='display:none'>\n"; //parent.document.getElementById('file').value='".urlencode($newpath)."'
  205. //echo "</DIV></TD></TR></TABLE>\n";
  206. //echo "<TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD nowrap WIDTH=12></TD><TD nowrap align='bottom'><IMG SRC=\"images/file.png\"><a href='filenew.php?folder=".urlencode($_SERVER["DOCUMENT_ROOT"])."' title=''>New File </a><DIV style='display:none'>\n"; //parent.document.getElementById('file').value='".urlencode($newpath)."'
  207. //echo "</DIV></TD></TR></TABLE>\n";
  208. //echo "</DIV></TD></TR></TABLE>\n";
  209. echo recur_dir($_SERVER["DOCUMENT_ROOT"]);
  210. echo "</DIV></TD></TR></TABLE>\n";
  211. /*
  212. echo " <TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD><A onClick=\"Toggle(this, '')\"><IMG SRC=\"/images/plus.gif\"> <IMG SRC=\"/images/folder.gif\"> Files </A><DIV style='display:none'>\n";
  213. echo "\n";
  214. echo " <TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD WIDTH=10></TD><TD><A onClick=\"Toggle(this, '')\"><IMG SRC=\"/images/plus.gif\"> <IMG SRC=\"/images/folder.gif\"> Folder 1</A><DIV style='display:none'>\n";
  215. echo "\n";
  216. echo " <TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD WIDTH=10></TD><TD align='bottom'><IMG SRC=\"/images/file.png\"> demo1.php <DIV style='display:none'>\n";
  217. echo " </DIV></TD></TR></TABLE>\n";
  218. echo "\n";
  219. echo " <TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD WIDTH=10></TD><TD align='bottom'><IMG SRC=\"/images/file.png\"> demo2.php <DIV style='display:none'>\n";
  220. echo " </DIV></TD></TR></TABLE>\n";
  221. echo "\n";
  222. echo " </DIV></TD></TR></TABLE>\n";
  223. echo "\n";
  224. echo " <TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD WIDTH=10></TD><TD><A onClick=\"Toggle(this, '')\"><IMG SRC=\"/images/plus.gif\"> <IMG SRC=\"/images/folder.gif\"> Folder 2</A><DIV style='display:none'>\n";
  225. echo "\n";
  226. echo " <TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD WIDTH=10></TD><TD align='bottom'><IMG SRC=\"/images/file.png\"> demo3.php <DIV style='display:none'>\n";
  227. echo " </DIV></TD></TR></TABLE>\n";
  228. echo "\n";
  229. echo " <TABLE BORDER=0 cellpadding='0' cellspacing='0'><TR><TD WIDTH=10></TD><TD align='bottom'><IMG SRC=\"/images/file.png\"> demo4.php <DIV style='display:none'>\n";
  230. echo " </DIV></TD></TR></TABLE>\n";
  231. echo "\n";
  232. echo " </DIV></TD></TR></TABLE>\n";
  233. echo "\n";
  234. echo " </DIV></TD></TR></TABLE>\n";
  235. */
  236. echo "</td>\n";
  237. echo "</tr>\n";
  238. echo "</table>\n";
  239. echo "</div>";
  240. echo "<br><br>";
  241. require_once "footer.php";
  242. unset ($resultcount);
  243. unset ($result);
  244. unset ($key);
  245. unset ($val);
  246. unset ($c);
  247. echo "</body>";
  248. echo "</html>";
  249. ?>