PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/nadavkav/RTL-BIDI-Hebrew-Moodle-Plugins
PHP | 275 lines | 192 code | 20 blank | 63 comment | 62 complexity | 54ad84e564cbf35612f3af33bad0991f MD5 | raw file
Possible License(s): Apache-2.0, GPL-3.0
  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. // deleting shared resources is disabled, from this dialog
  59. //<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>";
  60. // Determines if the user can view the share option in the main course (default is no)
  61. $userinttype = fm_get_user_int_type();
  62. $tmpcount = count_records('fmanager_shared',"sharedlink",$folder->id,"type",2,"course",$id);
  63. if ($tmpcount > 0) {
  64. $icon = "group.gif";
  65. } else {
  66. $icon = "group_noshare.gif";
  67. }
  68. $priv = NULL;
  69. $priv = get_record('fmanager_admin', 'usertype', $userinttype);
  70. if ($id == 1) {
  71. // They can share from the main page to anyone
  72. if ($priv->sharetoany == 1) {
  73. $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>";
  74. }
  75. } else {
  76. if ($priv->allowsharing == 1) {
  77. $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>";
  78. }
  79. }
  80. $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>";
  81. $catname = get_record('fmanager_categories', 'id', $folder->category);
  82. if (isset($catname->name)){
  83. $catname = format_text($catname->name,FORMAT_PLAIN);
  84. }
  85. // Finds size of folder
  86. if ($groupid == 0){
  87. $tmpdir = $CFG->dataroot."/".fm_get_user_dir_space().fm_get_folder_path($folder->id, false, $groupid);
  88. } else {
  89. $tmpdir = $CFG->dataroot."/".fm_get_group_dir_space($groupid).fm_get_folder_path($folder->id, false, $groupid);
  90. }
  91. $filesize = fm_get_size($tmpdir);
  92. $desc = ''; // There is no description for folders
  93. if(!$readonlyaccess){
  94. $table->data[] = array($cbx, $name, $catname, $filesize, $date, $actions);
  95. }else{
  96. $table->data[] = array("", $name, $catname, $filesize, $date);
  97. }
  98. }
  99. }
  100. // Prints all links
  101. if ($groupid==0){
  102. $ownertype = OWNERISUSER;
  103. $alllinks = get_records('fmanager_link', "owner={$USER->id} AND ownertype={$ownertype} AND folder", $rootdir, 'name');
  104. } else {
  105. $ownertype = OWNERISGROUP;
  106. $alllinks = get_records('fmanager_link', "owner={$groupid} AND ownertype={$ownertype} AND folder", $rootdir, 'name');
  107. }
  108. if (!$alllinks) {
  109. $table->data[] = array('', '<center><i><b>'.get_string('msgnolinks', 'block_file_manager').'</b></i></center>', '', '', '', '', '');
  110. } else {
  111. // Gets all associative information tied with user's links
  112. foreach($alllinks as $link) {
  113. $catname = fm_get_user_categories($link->category);
  114. $date = "<font size=\"1\">".userdate($link->timemodified, "%m/%d/%Y %H:%I")."</font>";
  115. $cbx = "<input type=\"checkbox\" name=\"".format_text($link->name,FORMAT_PLAIN)."\" value=\"{$link->id}\" />";
  116. $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;";
  117. // deleting shared resources is disabled, from this dialog
  118. //<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>";
  119. // Determines if the user can view the share option in the main course (default is no)
  120. $userinttype = fm_get_user_int_type();
  121. $tmpcount = count_records('fmanager_shared', 'sharedlink', $link->id, 'type', 0, 'course', $id);
  122. if ($tmpcount > 0) {
  123. $icon = "group.gif";
  124. } else {
  125. $icon = "group_noshare.gif";
  126. }
  127. $priv = NULL;
  128. $priv = get_record('fmanager_admin', 'usertype', $userinttype);
  129. if ($id == 1) {
  130. // They can share from the main page to anyone
  131. if ($priv->sharetoany == 1) {
  132. $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>";
  133. }
  134. } else {
  135. if ($priv->allowsharing == 1) {
  136. $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>";
  137. }
  138. }
  139. $options = "menubar=1,toolbar=1,status=1,location=0,scrollbars,resizable,width=700,height=500,top=20,left=20";
  140. if ($link->type == TYPE_FILE) {
  141. if ($link->folder != 0) {
  142. $folderinfo->path = fm_get_folder_path($link->folder, false, $groupid);
  143. $bdir = $folderinfo->path.$link->link;
  144. } else {
  145. $bdir = $link->link;
  146. }
  147. $tmphref = "{$CFG->wwwroot}/blocks/file_manager/file.php?cid={$id}&groupid=$groupid&fileid={$link->id}";
  148. $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>";
  149. } else if ($link->type == TYPE_URL) {
  150. $name = "<a target=\"urlpopup\" title=\"".get_string("msgopenlink",'block_file_manager')."\" href=\"$link->link\"".
  151. "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>";
  152. } else if ($link->type == TYPE_ZIP) {
  153. if ($link->folder != 0) {
  154. $folderinfo = fm_get_folder_path($link->folder, false, $groupid);
  155. if (isset($folderinfo->path)){
  156. $bdir = $folderinfo->path.$link->link;
  157. }
  158. } else {
  159. $bdir = $link->link;
  160. }
  161. $tmphref = "{$CFG->wwwroot}/blocks/file_manager/file.php?cid={$id}&groupid=$groupid&fileid={$link->id}";
  162. $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>";
  163. }
  164. /*
  165. $desc = wordwrap($link->description, 70, '<br/>');
  166. $tmp = '';
  167. if (strlen($desc) > 120) {
  168. $tmp = "&nbsp;&nbsp;<b><i>(More)...</i></b>";
  169. }
  170. $desc = substr($desc, 0, 120);
  171. $desc = $desc.$tmp;
  172. */
  173. $desc = format_text(shorten_text($link->description, 120));
  174. // Finds size of file
  175. $filesize = '';
  176. if ($link->type == TYPE_FILE || $link->type == TYPE_ZIP) {
  177. if ($groupid == 0){
  178. $tmpdir = $CFG->dataroot."/".fm_get_user_dir_space().fm_get_folder_path($link->folder, false, $groupid)."/".$link->link;
  179. } else {
  180. $tmpdir = $CFG->dataroot."/".fm_get_group_dir_space($groupid).fm_get_folder_path($link->folder, false, $groupid)."/".$link->link;
  181. }
  182. $filesize = fm_get_size($tmpdir);
  183. }
  184. if(!$readonlyaccess){
  185. $table->data[] = array($cbx, $name, $catname, $filesize, $date, $actions);
  186. }else{
  187. $table->data[] = array("", $name, $catname, $filesize, $date);
  188. }
  189. }
  190. }
  191. return $table;
  192. }
  193. print_header_simple();
  194. echo "<form id=\"filemanager\" method=\"post\" action=\"dialog.php\">";
  195. print_table( filemanager_print_user_files_form($id));
  196. echo "<input type=\"button\" onclick=\"onOK();\" value=\"".get_string('add')."\">";
  197. echo "</form>";
  198. print_footer();
  199. ?>
  200. <script type="text/javascript">
  201. //<![CDATA[
  202. function Init() {
  203. var param = window.dialogArguments;
  204. /*
  205. if (param) {
  206. var alt = param["f_url"].substring(param["f_url"].lastIndexOf('/') + 1);
  207. document.getElementById("f_url").value = param["f_url"];
  208. document.getElementById("f_alt").value = param["f_alt"] ? param["f_alt"] : alt;
  209. document.getElementById("f_border").value = parseInt(param["f_border"] || 0);
  210. window.ipreview.location.replace('preview.php?id='+ <?php print($course->id);?> +'&imageurl='+ param.f_url);
  211. }
  212. */
  213. document.getElementById('filelink').focus();
  214. };
  215. function onOK() {
  216. // var required = {
  217. // "filelink": "You should better choose some files, before we move on..."
  218. // };
  219. // for (var i in required) {
  220. // var el = document.getElementById(i);
  221. // if (!el.innerHTML) {
  222. // alert(required[i]);
  223. // el.focus();
  224. // return false;
  225. // }
  226. // }
  227. var param = new Object();
  228. var inputs = document.getElementsByTagName('input');
  229. for(var i = 0; i < inputs.length; i++) {
  230. if (inputs[i].checked == true){
  231. //alert(inputs[i].value);
  232. param[i] = '<a target="_new" href="<?php echo $CFG->wwwroot; ?>/blocks/file_manager/file.php?cid=<?php echo $id; ?>&groupid=0&fileid='+inputs[i].value+'">'+inputs[i].name+'</a>';
  233. };
  234. }
  235. // var fields = ["filelink"];
  236. // var param = new Object();
  237. // for (var i in fields) {
  238. // var id = fields[i];
  239. // var el = document.getElementById(id);
  240. // param[id] = el.innerHTML;
  241. // //alert(document.getElementById('objective').innerHTML);
  242. // }
  243. opener.nbWin.retFunc(param);
  244. window.close();
  245. return false;
  246. };
  247. function onCancel() {
  248. // if (preview_window) {
  249. // preview_window.close();
  250. // }
  251. window.close();
  252. return false;
  253. };
  254. //[[>
  255. </script>