Beispiel #1
0
function fm_view_zipped($file, $groupid)
{
    global $CFG, $USER;
    if ($file->folder == 0) {
        if ($groupid == 0) {
            $ziploc = $CFG->dataroot . "/" . fm_get_user_dir_space();
            //."/".$file->link;
        } else {
            $ziploc = $CFG->dataroot . "/" . fm_get_group_dir_space($groupid);
            //."/".$file->link;
        }
    } else {
        if ($groupid == 0) {
            $ziploc = $CFG->dataroot . "/" . fm_get_user_dir_space() . fm_get_folder_path($file->folder, false, $goupid);
            //."/".$file->link;
        } else {
            $ziploc = $CFG->dataroot . "/" . fm_get_group_dir_space($groupid) . fm_get_folder_path($file->folder, false, $goupid);
            //."/".$file->link;
        }
    }
    /*$filelist = array();
    	$zip = zip_open($ziploc);
    	if ($zip) {
    		$count = 0;
    		while ($zip_entry = zip_read($zip)) {
    		   $filelist[$count]->name = zip_entry_name($zip_entry);
    		   $filelist[$count]->actualsize = zip_entry_filesize($zip_entry);
    		   $filelist[$count]->compsize = zip_entry_compressedsize($zip_entry);
    		   $count++;
    		}
    		zip_close($zip);
    	}*/
    include_once "{$CFG->libdir}/pclzip/pclzip.lib.php";
    $archive = new PclZip(cleardoubleslashes("{$ziploc}/{$file->link}"));
    if (!($zip = $archive->listContent(cleardoubleslashes("{$ziploc}")))) {
        notify($archive->errorInfo(true));
    } else {
        $count = 0;
        foreach ($zip as $file) {
            $filelist[$count]->name = $file['filename'];
            $filelist[$count]->actualsize = $file['size'];
            $filelist[$count]->compsize = $file['compressed_size'];
            $count++;
        }
    }
    return $filelist;
}
Beispiel #2
0
     echo "</form>";
     break;
 case 'unzip':
     /*if (isset($_POST['cancel'])) {
     			print_simple_box(get_string('msgcancelok', 'block_file_manager'), 'center');
     			redirect("link_manage.php?id=$id&linkid=$zipid&rootdir=$rootdir");
     		} else if (isset($_POST['unzip'])) {*/
     if ($groupid == 0) {
         $zipfile = fm_get_user_link($zipid);
     } else {
         $zipfile = fm_get_group_link($zipid, $groupid);
     }
     if ($groupid == 0) {
         $zipfileloc = $CFG->dataroot . "/" . fm_get_user_dir_space() . fm_get_folder_path($zipfile->folder, false, $groupid) . "/" . $zipfile->link;
     } else {
         $zipfileloc = $CFG->dataroot . "/" . fm_get_group_dir_space($groupid) . fm_get_folder_path($zipfile->folder, false, $groupid) . "/" . $zipfile->link;
     }
     fm_unzip_file($zipfileloc, '', false, $zipfile->folder, $groupid);
     print_simple_box(get_string('msgmodificationok', 'block_file_manager'), "center", "", "#FFFFFF");
     redirect("view.php?id={$id}&rootdir={$rootdir}&groupid={$groupid}");
     //}
     /*$list = fm_view_zipped(fm_get_user_link($zipid), $groupid);
     		$fmdir = fm_get_root_dir();
     		echo "<form name=\"unzipform\" method=\"post\" action=\"$CFG->wwwroot/$fmdir/zip.php?id={$id}&rootdir={$rootdir}&zipid=$zipid&what='$action'\">";
     		print_simple_box_start('center','500','#C0C0C0');
     		echo "<table name=\"viewziptable\" cellspacing=\"5\" align=\"center\" width=\"375\">";
     			echo "<tr>";
     			echo "<td align='center' nowrap><b><u>".get_string("file",'block_file_manager')."</u></b></td>";
     			echo "<td align='center' nowrap><b><u>".get_string("compressedsize",'block_file_manager')."</u></b></td>";
     			echo "<td align='center' nowrap><b><u>".get_string("actualsize",'block_file_manager')."</u></b></td>";
     			echo "</tr>";
Beispiel #3
0
 if ($linkname == '' || $linkurl == '') {
     // verify's input
     notify(get_string('msgneedinputname', 'block_file_manager'));
     if ($linkname == '') {
         $missinginput['name'] = true;
     }
     if ($linkurl == '') {
         $missinginput['link'] = true;
     }
 } else {
     if ($store->radioval == 'file') {
         // If hd space exceeded...unlinks file and issue warning
         if ($groupid == 0) {
             $tmpdir = $CFG->dataroot . "/" . fm_get_user_dir_space();
         } else {
             $tmpdir = $CFG->dataroot . "/" . fm_get_group_dir_space($groupid);
         }
         $usertype = fm_get_user_int_type();
         $adminsettings = get_record('fmanager_admin', 'usertype', $usertype);
         if ($_FILES['linkfile']['size'] > $adminsettings->maxupload * 1048576) {
             error(get_string('errfiletoolarge', 'block_file_manager'));
         } else {
             $store->url = fm_upload_file($_FILES['linkfile'], $linkrename, $rootdir, $groupid);
             $dirsize = fm_get_size($tmpdir, 1);
             if ($adminsettings->maxdir * 1048576 - $dirsize < 0 && $adminsettings->maxdir != 0) {
                 unlink($tmpdir . fm_get_folder_path($store->folder, false, $groupid) . "/" . $store->url);
                 error(get_string('errmaxdirexceeded', 'block_file_manager'), "link_manage.php?id={$id}&groupid={$groupid}&rootdir={$rootdir}");
             }
         }
     }
     if ($store->url != '') {
         $entry->timemodified = time();
         $newpath = $CFG->dataroot;
         //var_dump($oldpath);
         if ($groupid == 0) {
             $newpath .= "/" . fm_get_user_dir_space() . "{$oldpath->path}{$oldpath->name}/{$foldername}";
         } else {
             $newpath .= "/" . fm_get_group_dir_space($groupid) . "{$oldpath->path}{$oldpath->name}/{$foldername}";
         }
         if (file_exists($newpath)) {
             print_simple_box(get_string('msgduplicate', 'block_file_manager'), 'center', '', '#FFFFFF');
             $dupname = true;
         }
         if ($groupid == 0) {
             $newpath = fm_get_user_dir_space();
         } else {
             $newpath = fm_get_group_dir_space($groupid);
         }
         $newpath = make_upload_directory($newpath);
         $newpath .= "{$oldpath->path}{$oldpath->name}/{$foldername}";
         if (!$dupname && !@mkdir($newpath)) {
             error(get_string('errnocreatefold', 'block_file_manager'));
         }
         if (!$dupname && !insert_record('fmanager_folders', $entry)) {
             error(get_string('errnoinsert', 'block_file_manager'));
         }
         if ($dupname != true) {
             print_simple_box(get_string('msgcreationok', 'block_file_manager'), "center", "", "#FFFFFF");
             redirect("view.php?id={$id}&amp;groupid={$groupid}&amp;rootdir={$rootdir}");
         }
     }
 }
function fm_print_user_files_form($id = 1, $rootdir = 0, $action = 'none', $groupid = 0, $readonlyaccess = false)
{
    global $CFG, $USER;
    // TO ADD :
    // 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
    unset($table);
    $fmdir = fm_get_root_dir();
    $strcbx = "<input type=\"checkbox\" name=\"cb[]\" value=\"0\" onClick=\"selectboxes(this, 1)\">&nbsp;" . get_string("selectall", 'block_file_manager');
    $strnamename = "<a href=\"{$CFG->wwwroot}/{$fmdir}/view.php?id={$id}&groupid={$groupid}&rootdir={$rootdir}&tsort=sortname\">" . get_string('namename', 'block_file_manager') . "</a>";
    $strcatname = "<a href=\"{$CFG->wwwroot}/{$fmdir}/view.php?id={$id}&groupid={$groupid}&rootdir={$rootdir}&tsort=sortcat\">" . get_string('catname', 'block_file_manager') . "</a>";
    $strdescname = "<a href=\"{$CFG->wwwroot}/{$fmdir}/view.php?id={$id}&groupid={$groupid}&rootdir={$rootdir}&tsort=sortdesc\">" . get_string('descname', 'block_file_manager') . "</a>";
    $strfilesizename = "<a href=\"{$CFG->wwwroot}/{$fmdir}/view.php?id={$id}&groupid={$groupid}&rootdir={$rootdir}&tsort=sortsize\">" . get_string('filesizename', 'block_file_manager') . "</a>";
    $strdatename = "<a href=\"{$CFG->wwwroot}/{$fmdir}/view.php?id={$id}&groupid={$groupid}&rootdir={$rootdir}&tsort=sortdate\">" . get_string('datename', 'block_file_manager') . "</a>";
    $stractionname = get_string('actionsname', 'block_file_manager');
    if (!$readonlyaccess) {
        $table->head = array($strcbx, $strnamename, $strcatname, $strdescname, $strfilesizename, $strdatename, $stractionname);
    } else {
        $table->head = array("", $strnamename, $strcatname, $strdescname, $strfilesizename, $strdatename);
    }
    $table->align = array("center", "left", "center", "center", "center", "center");
    $table->width = "90%";
    $table->size = array("5%", "20%", "15%", "25%", "10%", "10%", "12%");
    $table->wrap = array(NULL, 'no', 'no', 'no', 'no', 'no');
    $table->data = array();
    if ($action == 'movesel') {
        $moveurl = "&what='{$action}'";
    } else {
        $moveurl = '';
    }
    // Not at root...so print an up folder link
    if ($rootdir != 0) {
        $tmpfold = get_record('fmanager_folders', "id", $rootdir);
        $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>";
        $table->data[] = array("", $name, "", "", "", "", "", "");
    }
    // Prints folders
    if ($groupid == 0) {
        $ownertype = OWNERISUSER;
        $allfolders = get_records('fmanager_folders', "owner={$USER->id} AND ownertype = {$ownertype} AND pathid", $rootdir, "name");
    } else {
        $ownertype = OWNERISGROUP;
        $allfolders = get_records('fmanager_folders', "owner={$groupid} AND ownertype = {$ownertype} AND pathid", $rootdir, "name");
    }
    if ($allfolders) {
        foreach ($allfolders as $folder) {
            $date = "<font size=1>" . userdate($folder->timemodified, "%m/%d/%Y  %H:%I") . "</font>";
            $cbx = "<input type=\"checkbox\" name=\"cb[]\" value=\"fold{$folder->id}\">";
            $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;\n              <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>";
            // Determines if the user can view the share option in the main course (default is no)
            $userinttype = fm_get_user_int_type();
            $tmpcount = count_records('fmanager_shared', "sharedlink", $folder->id, "type", 2, "course", $id);
            if ($tmpcount > 0) {
                $icon = "group.gif";
            } else {
                $icon = "group_noshare.gif";
            }
            $priv = NULL;
            $priv = get_record('fmanager_admin', 'usertype', $userinttype);
            if ($id == 1) {
                // They can share from the main page to anyone
                if ($priv->sharetoany == 1) {
                    $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>";
                }
            } else {
                if ($priv->allowsharing == 1) {
                    $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>";
                }
            }
            $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>";
            $catname = get_record('fmanager_categories', 'id', $folder->category);
            if (isset($catname->name)) {
                $catname = format_text($catname->name, FORMAT_PLAIN);
            }
            // Finds size of folder
            if ($groupid == 0) {
                $tmpdir = $CFG->dataroot . "/" . fm_get_user_dir_space() . fm_get_folder_path($folder->id, false, $groupid);
            } else {
                $tmpdir = $CFG->dataroot . "/" . fm_get_group_dir_space($groupid) . fm_get_folder_path($folder->id, false, $groupid);
            }
            $filesize = fm_get_size($tmpdir);
            $desc = '';
            // There is no description for folders
            if (!$readonlyaccess) {
                $table->data[] = array($cbx, $name, $catname, $desc, $filesize, $date, $actions);
            } else {
                $table->data[] = array("", $name, $catname, $desc, $filesize, $date);
            }
        }
    }
    // Prints all links
    if ($groupid == 0) {
        $ownertype = OWNERISUSER;
        $alllinks = get_records('fmanager_link', "owner={$USER->id} AND ownertype={$ownertype} AND folder", $rootdir, 'name');
    } else {
        $ownertype = OWNERISGROUP;
        $alllinks = get_records('fmanager_link', "owner={$groupid} AND ownertype={$ownertype} AND folder", $rootdir, 'name');
    }
    if (!$alllinks) {
        $table->data[] = array('', '<center><i><b>' . get_string('msgnolinks', 'block_file_manager') . '</b></i></center>', '', '', '', '', '');
    } else {
        // Gets all associative information tied with user's links
        foreach ($alllinks as $link) {
            $catname = fm_get_user_categories($link->category);
            $date = "<font size=\"1\">" . userdate($link->timemodified, "%m/%d/%Y  %H:%I") . "</font>";
            $cbx = "<input type=\"checkbox\" name=\"cb[]\" value=\"{$link->id}\" />";
            $actions = "<a title=\"" . get_string('edit') . "\" href=\"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;\n              <a title=\"" . get_string('delete') . "\" href=\"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>";
            // Determines if the user can view the share option in the main course (default is no)
            $userinttype = fm_get_user_int_type();
            $tmpcount = count_records('fmanager_shared', 'sharedlink', $link->id, 'type', 0, 'course', $id);
            if ($tmpcount > 0) {
                $icon = "group.gif";
            } else {
                $icon = "group_noshare.gif";
            }
            $priv = NULL;
            $priv = get_record('fmanager_admin', 'usertype', $userinttype);
            if ($id == 1) {
                // They can share from the main page to anyone
                if ($priv->sharetoany == 1) {
                    $actions .= "&nbsp;&nbsp;<a title=\"" . get_string('sharetoany', 'block_file_manager') . "\" href=\"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>";
                }
            } else {
                if ($priv->allowsharing == 1) {
                    $actions .= "&nbsp;&nbsp;<a title=\"" . get_string('msgsharetoothers', 'block_file_manager') . "\" href=\"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>";
                }
            }
            $options = "menubar=1,toolbar=1,status=1,location=0,scrollbars,resizable,width=700,height=500,top=20,left=20";
            if ($link->type == TYPE_FILE) {
                if ($link->folder != 0) {
                    $folderinfo->path = fm_get_folder_path($link->folder, false, $groupid);
                    $bdir = $folderinfo->path . $link->link;
                } else {
                    $bdir = $link->link;
                }
                $tmphref = "{$CFG->wwwroot}/blocks/file_manager/file.php?cid={$id}&groupid={$groupid}&fileid={$link->id}";
                $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>";
            } else {
                if ($link->type == TYPE_URL) {
                    $name = "<a target=\"urlpopup\" title=\"" . get_string("msgopenlink", 'block_file_manager') . "\" href=\"{$link->link}\"" . "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>";
                } else {
                    if ($link->type == TYPE_ZIP) {
                        if ($link->folder != 0) {
                            $folderinfo = fm_get_folder_path($link->folder, false, $groupid);
                            if (isset($folderinfo->path)) {
                                $bdir = $folderinfo->path . $link->link;
                            }
                        } else {
                            $bdir = $link->link;
                        }
                        $tmphref = "{$CFG->wwwroot}/blocks/file_manager/file.php?cid={$id}&groupid={$groupid}&fileid={$link->id}";
                        $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>";
                    }
                }
            }
            /*
            $desc = wordwrap($link->description, 70, '<br/>');
            $tmp = '';
            if (strlen($desc) > 120) {
              $tmp = "&nbsp;&nbsp;<b><i>(More)...</i></b>";
            }
            $desc = substr($desc, 0, 120);
            $desc = $desc.$tmp;
            */
            $desc = format_text(shorten_text($link->description, 120));
            // Finds size of file
            $filesize = '';
            if ($link->type == TYPE_FILE || $link->type == TYPE_ZIP) {
                if ($groupid == 0) {
                    $tmpdir = $CFG->dataroot . "/" . fm_get_user_dir_space() . fm_get_folder_path($link->folder, false, $groupid) . "/" . $link->link;
                } else {
                    $tmpdir = $CFG->dataroot . "/" . fm_get_group_dir_space($groupid) . fm_get_folder_path($link->folder, false, $groupid) . "/" . $link->link;
                }
                $filesize = fm_get_size($tmpdir);
            }
            if (!$readonlyaccess) {
                $table->data[] = array($cbx, $name, $catname, $desc, $filesize, $date, $actions);
            } else {
                $table->data[] = array("", $name, $catname, $desc, $filesize, $date);
            }
        }
    }
    return $table;
}
function fm_view_zipped($file, $groupid)
{
    global $CFG, $USER;
    if ($file->folder == 0) {
        if ($groupid == 0) {
            $ziploc = $CFG->dataroot . "/" . fm_get_user_dir_space();
            //."/".$file->link;
        } else {
            $ziploc = $CFG->dataroot . "/" . fm_get_group_dir_space($groupid);
            //."/".$file->link;
        }
    } else {
        if ($groupid == 0) {
            $ziploc = $CFG->dataroot . "/" . fm_get_user_dir_space() . fm_get_folder_path($file->folder, false, $goupid);
            //."/".$file->link;
        } else {
            $ziploc = $CFG->dataroot . "/" . fm_get_group_dir_space($groupid) . fm_get_folder_path($file->folder, false, $goupid);
            //."/".$file->link;
        }
    }
    $filelist = array();
    $zip = zip_open($ziploc);
    if ($zip) {
        $count = 0;
        while ($zip_entry = zip_read($zip)) {
            $filelist[$count]->name = zip_entry_name($zip_entry);
            $filelist[$count]->actualsize = zip_entry_filesize($zip_entry);
            $filelist[$count]->compsize = zip_entry_compressedsize($zip_entry);
            $count++;
        }
        zip_close($zip);
    }
    return $filelist;
}
global $CFG, $USER;
$fileid = required_param('linkid', PARAM_INT);
//
$groupid = optional_param('groupid', "0", PARAM_INT);
$cid = required_param('id', PARAM_INT);
//
// Checks if user is owner of file, if not, checks if file is shared to them...if not...errors are displayed
if (!fm_user_can_view_file($course->id, $fileid, $groupid)) {
    error(get_string("errnoviewfile", 'block_file_manager'));
}
$filerec = get_record('fmanager_link', "id", $fileid);
$filename = $filerec->link;
if ($groupid == 0) {
    $pathinfo = fm_get_user_dir_space($filerec->owner);
} else {
    $pathinfo = fm_get_group_dir_space($groupid);
}
if ($tmpfolder = fm_get_folder_path($filerec->folder, true, $groupid)) {
    $pathinfo = $pathinfo . $tmpfolder;
}
$pathname = $CFG->dataroot . "/" . $pathinfo . "/" . $filename;
// check that file exists
if (!file_exists("{$pathname}")) {
    not_found($course->id);
}
$firstcourseid = 0;
/*        if (empty($CFG->disablemycourses) and 
          !empty($USER->id) and 
          !(has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) and $adminseesall) and
          !isguest()) {    // Just print My Courses*/
if ($courses = get_my_courses($USER->id, 'visible DESC, fullname ASC')) {