PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/editor/htmlarea/custom_plugins/filemanager/dialog.php

https://github.com/galitush2005/RTL-BIDI-Hebrew-Moodle-Plugins
PHP | 273 lines | 194 code | 20 blank | 59 comment | 62 complexity | 5878fd59b0ad8b0658a4ec289d0cea9b MD5 | raw file
  1. <?php // $Id: insert_table.php,v 1.4 2007/01/27 23:23:44 skodak Exp $
  2. require_once("../../../../../config.php");
  3. $id = optional_param('id', SITEID, PARAM_INT);
  4. require_course_login($id);
  5. @header('Content-Type: text/html; charset=utf-8');
  6. //include $CFG->dirroot."/blocks/file_manager/print_lib.php";
  7. include $CFG->dirroot."/blocks/file_manager/lib.php";
  8. // $id = course id
  9. // $groupid = group id if we want to see files of this group
  10. // $rootdir = target directory
  11. function filemanager_print_user_files_form($id=1, $rootdir=0, $action='none', $groupid=0,$readonlyaccess=false) {
  12. global $CFG, $USER;
  13. // TO ADD :
  14. // if the user is not member of the group, he can't change anything, he just has the reading right only if the group mode is GROUP VISIBLE
  15. unset($table);
  16. $fmdir = fm_get_root_dir();
  17. $strcbx = "<input type=\"checkbox\" name=\"cb[]\" value=\"0\" onClick=\"selectboxes(this, 1)\">&nbsp;".get_string("selectall", 'block_file_manager');
  18. $strnamename = "<a href=\"$CFG->wwwroot/$fmdir/view.php?id={$id}&groupid=$groupid&rootdir=$rootdir&tsort=sortname\">".get_string('namename','block_file_manager')."</a>";
  19. $strcatname = "<a href=\"$CFG->wwwroot/$fmdir/view.php?id={$id}&groupid=$groupid&rootdir=$rootdir&tsort=sortcat\">".get_string('catname','block_file_manager')."</a>";
  20. $strdescname = "<a href=\"$CFG->wwwroot/$fmdir/view.php?id={$id}&groupid=$groupid&rootdir=$rootdir&tsort=sortdesc\">".get_string('descname','block_file_manager')."</a>";
  21. $strfilesizename = "<a href=\"$CFG->wwwroot/$fmdir/view.php?id={$id}&groupid=$groupid&rootdir=$rootdir&tsort=sortsize\">".get_string('filesizename','block_file_manager')."</a>";
  22. $strdatename = "<a href=\"$CFG->wwwroot/$fmdir/view.php?id={$id}&groupid=$groupid&rootdir=$rootdir&tsort=sortdate\">".get_string('datename','block_file_manager')."</a>";
  23. $stractionname = get_string('actionsname','block_file_manager');
  24. if(!$readonlyaccess){
  25. $table->head = array($strcbx, $strnamename, $strcatname, $strfilesizename, $strdatename, $stractionname);
  26. }else{
  27. $table->head = array("", $strnamename, $strcatname, $strfilesizename, $strdatename);
  28. }
  29. $table->align = array("center", "left", "center", "center", "center");
  30. $table->width = "90%";
  31. $table->size = array("5%", "20%", "15%", "10%", "10%", "12%");
  32. $table->wrap = array(NULL, 'no', 'no', 'no', 'no');
  33. $table->data = array();
  34. if ($action == 'movesel') {
  35. $moveurl = "&what='$action'";
  36. } else {
  37. $moveurl = '';
  38. }
  39. // Not at root...so print an up folder link
  40. if ($rootdir != 0) {
  41. $tmpfold = get_record('fmanager_folders', "id", $rootdir);
  42. $name = "<a href=\"view.php?id=$id&groupid=$groupid&rootdir=$tmpfold->pathid$moveurl\"><img border=\"0\" src=\"$CFG->pixpath/f/parent.gif\" alt=\"".get_string("msgrootdir",'block_file_manager')."\" />&nbsp;".get_string("msgrootdir",'block_file_manager')."</a>";
  43. $table->data[] = array("", $name, "", "", "","", "");
  44. }
  45. // Prints folders
  46. if ($groupid==0){
  47. $ownertype = OWNERISUSER;
  48. $allfolders = get_records('fmanager_folders', "owner=$USER->id AND ownertype = {$ownertype} AND pathid", $rootdir, "name");
  49. } else {
  50. $ownertype = OWNERISGROUP;
  51. $allfolders = get_records('fmanager_folders', "owner=$groupid AND ownertype = {$ownertype} AND pathid", $rootdir, "name");
  52. }
  53. if ($allfolders) {
  54. foreach($allfolders as $folder) {
  55. $date = "<font size=1>".userdate($folder->timemodified, "%m/%d/%Y %H:%I")."</font>";
  56. $cbx = "<input type=\"checkbox\" name=\"".format_text($folder->name,FORMAT_PLAIN)."\" value=\"fold$folder->id\">";
  57. $actions = "<a title=\"".get_string('edit')."\" href=\"folder_manage.php?id=$id&groupid=$groupid&foldid=$folder->id&rootdir=$rootdir\"><img border=\"0\" src=\"$CFG->pixpath/i/edit.gif\" alt=\"" . get_string("edit"). "\" /></a>&nbsp;
  58. <a title=\"".get_string('delete')."\" href=\"conf_delete.php?id=$id&groupid=$groupid&from=folder&fromid=$folder->id&rootdir=$rootdir\"><img border=\"0\" src=\"../file_manager/pix/delete.gif\" alt=\"" . get_string("delete"). "\" /></a>";
  59. // Determines if the user can view the share option in the main course (default is no)
  60. $userinttype = fm_get_user_int_type();
  61. $tmpcount = count_records('fmanager_shared',"sharedlink",$folder->id,"type",2,"course",$id);
  62. if ($tmpcount > 0) {
  63. $icon = "group.gif";
  64. } else {
  65. $icon = "group_noshare.gif";
  66. }
  67. $priv = NULL;
  68. $priv = get_record('fmanager_admin', 'usertype', $userinttype);
  69. if ($id == 1) {
  70. // They can share from the main page to anyone
  71. if ($priv->sharetoany == 1) {
  72. $actions .= "&nbsp;&nbsp;<a title=\"".get_string('sharetoany','block_file_manager')."\" href=\"sharing.php?id={$id}&groupid=$groupid&linkid={$folder->id}&groupid={$groupid}&from=folder&rootdir={$rootdir}\"><img border=\"0\" src=\"$CFG->wwwroot/blocks/file_manager/pix/".$icon."\" alt=\"".get_string('sharetoany','block_file_manager')."\" /></a>";
  73. }
  74. } else {
  75. if ($priv->allowsharing == 1) {
  76. $actions .= "&nbsp;&nbsp;<a title=\"".get_string('msgsharetoothers','block_file_manager')."\" href=\"sharing.php?id=$id&groupid=$groupid&linkid=$folder->id&from=folder&groupid={$groupid}&rootdir=$rootdir\"><img border=\"0\" src=\"$CFG->wwwroot/blocks/file_manager/pix/".$icon."\" alt=\"".get_string('msgsharetoothers','block_file_manager')."!\" /></a>";
  77. }
  78. }
  79. $name = "<a href=\"{$CFG->wwwroot}/".fm_get_root_dir()."/view.php?id={$id}&groupid={$groupid}&rootdir={$folder->id}{$moveurl}\"><img border=\"0\" src=\"$CFG->wwwroot/blocks/file_manager/pix/folder.gif\" alt=\"".get_string('msgfolder','block_file_manager',format_text($folder->name,FORMAT_PLAIN))."\" />". format_text($folder->name,FORMAT_PLAIN)."</a>";
  80. $catname = get_record('fmanager_categories', 'id', $folder->category);
  81. if (isset($catname->name)){
  82. $catname = format_text($catname->name,FORMAT_PLAIN);
  83. }
  84. // Finds size of folder
  85. if ($groupid == 0){
  86. $tmpdir = $CFG->dataroot."/".fm_get_user_dir_space().fm_get_folder_path($folder->id, false, $groupid);
  87. } else {
  88. $tmpdir = $CFG->dataroot."/".fm_get_group_dir_space($groupid).fm_get_folder_path($folder->id, false, $groupid);
  89. }
  90. $filesize = fm_get_size($tmpdir);
  91. $desc = ''; // There is no description for folders
  92. if(!$readonlyaccess){
  93. $table->data[] = array($cbx, $name, $catname, $filesize, $date, $actions);
  94. }else{
  95. $table->data[] = array("", $name, $catname, $filesize, $date);
  96. }
  97. }
  98. }
  99. // Prints all links
  100. if ($groupid==0){
  101. $ownertype = OWNERISUSER;
  102. $alllinks = get_records('fmanager_link', "owner={$USER->id} AND ownertype={$ownertype} AND folder", $rootdir, 'name');
  103. } else {
  104. $ownertype = OWNERISGROUP;
  105. $alllinks = get_records('fmanager_link', "owner={$groupid} AND ownertype={$ownertype} AND folder", $rootdir, 'name');
  106. }
  107. if (!$alllinks) {
  108. $table->data[] = array('', '<center><i><b>'.get_string('msgnolinks', 'block_file_manager').'</b></i></center>', '', '', '', '', '');
  109. } else {
  110. // Gets all associative information tied with user's links
  111. foreach($alllinks as $link) {
  112. $catname = fm_get_user_categories($link->category);
  113. $date = "<font size=\"1\">".userdate($link->timemodified, "%m/%d/%Y %H:%I")."</font>";
  114. $cbx = "<input type=\"checkbox\" name=\"".format_text($link->name,FORMAT_PLAIN)."\" value=\"{$link->id}\" />";
  115. $actions = "<a title=\"".get_string('edit')."\" href=\"{$CFG->wwwroot}/blocks/file_manager/link_manage.php?id={$id}&groupid={$groupid}&linkid={$link->id}&rootdir={$rootdir}\"><img border=\"0\" src=\"{$CFG->pixpath}/i/edit.gif\" alt=\"" . get_string('edit'). "\" /></a>&nbsp;
  116. <a title=\"".get_string('delete')."\" href=\"{$CFG->wwwroot}/blocks/file_manager/conf_delete.php?id=$id&groupid={$groupid}&from=link&fromid={$link->id}&rootdir={$rootdir}\"><img border=\"0\" src=\"../file_manager/pix/delete.gif\" alt=\"" . get_string('delete'). "\"></a>";
  117. // Determines if the user can view the share option in the main course (default is no)
  118. $userinttype = fm_get_user_int_type();
  119. $tmpcount = count_records('fmanager_shared', 'sharedlink', $link->id, 'type', 0, 'course', $id);
  120. if ($tmpcount > 0) {
  121. $icon = "group.gif";
  122. } else {
  123. $icon = "group_noshare.gif";
  124. }
  125. $priv = NULL;
  126. $priv = get_record('fmanager_admin', 'usertype', $userinttype);
  127. if ($id == 1) {
  128. // They can share from the main page to anyone
  129. if ($priv->sharetoany == 1) {
  130. $actions .= "&nbsp;&nbsp;<a title=\"".get_string('sharetoany','block_file_manager')."\" href=\"{$CFG->wwwroot}/blocks/file_manager/sharing.php?id=$id&groupid={$groupid}&linkid=$link->id&from='link'&rootdir=$rootdir\"><img border=\"0\" src=\"$CFG->wwwroot/blocks/file_manager/pix/".$icon."\" alt=\"".get_string('sharetoany','block_file_manager')."\"></a>";
  131. }
  132. } else {
  133. if ($priv->allowsharing == 1) {
  134. $actions .= "&nbsp;&nbsp;<a title=\"".get_string('msgsharetoothers','block_file_manager')."\" href=\"{$CFG->wwwroot}/blocks/file_manager/sharing.php?id=$id&groupid={$groupid}&linkid=$link->id&from='link'&rootdir=$rootdir\"><img border=\"0\" src=\"$CFG->wwwroot/blocks/file_manager/pix/".$icon."\" alt=\"".get_string('msgsharetoothers','block_file_manager')."!\"></a>";
  135. }
  136. }
  137. $options = "menubar=1,toolbar=1,status=1,location=0,scrollbars,resizable,width=700,height=500,top=20,left=20";
  138. if ($link->type == TYPE_FILE) {
  139. if ($link->folder != 0) {
  140. $folderinfo->path = fm_get_folder_path($link->folder, false, $groupid);
  141. $bdir = $folderinfo->path.$link->link;
  142. } else {
  143. $bdir = $link->link;
  144. }
  145. $tmphref = "{$CFG->wwwroot}/blocks/file_manager/file.php?cid={$id}&groupid=$groupid&fileid={$link->id}";
  146. $name = "<a target=\"urlpopup\" title=\"".get_string('msgopenfile', 'block_file_manager', $link->link)."\" href=\"$tmphref\" onClick=\"window.open('$tmphref','urlpopup','$options');\"><img src=\"$CFG->wwwroot/blocks/file_manager/pix/file.gif\" >&nbsp;".format_text($link->name,FORMAT_PLAIN)."</a>";
  147. } else if ($link->type == TYPE_URL) {
  148. $name = "<a target=\"urlpopup\" title=\"".get_string("msgopenlink",'block_file_manager')."\" href=\"$link->link\"".
  149. "onClick=\"window.open('$link->link','urlpopup','$options');\"><img src=\"$CFG->wwwroot/blocks/file_manager/pix/www.gif\">&nbsp;".format_text($link->name,FORMAT_PLAIN)."</a>";
  150. } else if ($link->type == TYPE_ZIP) {
  151. if ($link->folder != 0) {
  152. $folderinfo = fm_get_folder_path($link->folder, false, $groupid);
  153. if (isset($folderinfo->path)){
  154. $bdir = $folderinfo->path.$link->link;
  155. }
  156. } else {
  157. $bdir = $link->link;
  158. }
  159. $tmphref = "{$CFG->wwwroot}/blocks/file_manager/file.php?cid={$id}&groupid=$groupid&fileid={$link->id}";
  160. $name = "<a target=\"urlpopup\" title=\"".get_string('msgopenfile', 'block_file_manager', $link->link)."\" href=\"$tmphref\" onClick=\"window.open('$tmphref','urlpopup','$options');\"><img src=\"$CFG->wwwroot/blocks/file_manager/pix/zip.gif\" >&nbsp;".format_text($link->name,FORMAT_PLAIN)."</a>";
  161. }
  162. /*
  163. $desc = wordwrap($link->description, 70, '<br/>');
  164. $tmp = '';
  165. if (strlen($desc) > 120) {
  166. $tmp = "&nbsp;&nbsp;<b><i>(More)...</i></b>";
  167. }
  168. $desc = substr($desc, 0, 120);
  169. $desc = $desc.$tmp;
  170. */
  171. $desc = format_text(shorten_text($link->description, 120));
  172. // Finds size of file
  173. $filesize = '';
  174. if ($link->type == TYPE_FILE || $link->type == TYPE_ZIP) {
  175. if ($groupid == 0){
  176. $tmpdir = $CFG->dataroot."/".fm_get_user_dir_space().fm_get_folder_path($link->folder, false, $groupid)."/".$link->link;
  177. } else {
  178. $tmpdir = $CFG->dataroot."/".fm_get_group_dir_space($groupid).fm_get_folder_path($link->folder, false, $groupid)."/".$link->link;
  179. }
  180. $filesize = fm_get_size($tmpdir);
  181. }
  182. if(!$readonlyaccess){
  183. $table->data[] = array($cbx, $name, $catname, $filesize, $date, $actions);
  184. }else{
  185. $table->data[] = array("", $name, $catname, $filesize, $date);
  186. }
  187. }
  188. }
  189. return $table;
  190. }
  191. print_header_simple();
  192. echo "<form id=\"filemanager\" method=\"post\" action=\"dialog.php\">";
  193. print_table( filemanager_print_user_files_form($USER->id));
  194. echo "<input type=\"button\" onclick=\"onOK();\" value=\"".get_string('add')."\">";
  195. echo "</form>";
  196. print_footer();
  197. ?>
  198. <script type="text/javascript">
  199. //<![CDATA[
  200. function Init() {
  201. var param = window.dialogArguments;
  202. /*
  203. if (param) {
  204. var alt = param["f_url"].substring(param["f_url"].lastIndexOf('/') + 1);
  205. document.getElementById("f_url").value = param["f_url"];
  206. document.getElementById("f_alt").value = param["f_alt"] ? param["f_alt"] : alt;
  207. document.getElementById("f_border").value = parseInt(param["f_border"] || 0);
  208. window.ipreview.location.replace('preview.php?id='+ <?php print($course->id);?> +'&imageurl='+ param.f_url);
  209. }
  210. */
  211. document.getElementById('filelink').focus();
  212. };
  213. function onOK() {
  214. // var required = {
  215. // "filelink": "You should better choose some files, before we move on..."
  216. // };
  217. // for (var i in required) {
  218. // var el = document.getElementById(i);
  219. // if (!el.innerHTML) {
  220. // alert(required[i]);
  221. // el.focus();
  222. // return false;
  223. // }
  224. // }
  225. var param = new Object();
  226. var inputs = document.getElementsByTagName('input');
  227. for(var i = 0; i < inputs.length; i++) {
  228. if (inputs[i].checked == true){
  229. //alert(inputs[i].value);
  230. param[i] = '<a href="<?php echo $CFG->wwwroot; ?>/blocks/file_manager/file.php?cid=<?php echo $USER->id; ?>&groupid=0&fileid='+inputs[i].value+'">'+inputs[i].name+'</a>';
  231. };
  232. }
  233. // var fields = ["filelink"];
  234. // var param = new Object();
  235. // for (var i in fields) {
  236. // var id = fields[i];
  237. // var el = document.getElementById(id);
  238. // param[id] = el.innerHTML;
  239. // //alert(document.getElementById('objective').innerHTML);
  240. // }
  241. opener.nbWin.retFunc(param);
  242. window.close();
  243. return false;
  244. };
  245. function onCancel() {
  246. // if (preview_window) {
  247. // preview_window.close();
  248. // }
  249. window.close();
  250. return false;
  251. };
  252. //[[>
  253. </script>