Example #1
0
             } else {
                 $file = get_record('fmanager_link', "id", $c);
                 // File type
                 if ($file->type == TYPE_FILE) {
                     $originalfiles[] = $destination . fm_get_folder_path($file->folder, false, $groupid) . "/" . $file->link;
                 }
             }
         }
     }
     $destination = $destination . "/";
     if (!fm_zip_files($originalfiles, $destination, $zipname, $rootdir, $groupid)) {
         error(get_string("errnozip", 'block_file_manager'));
     }
     break;
 }
 $fmdir = fm_get_root_dir();
 echo "<form name=\"zipform\" method=\"post\" action=\"{$CFG->wwwroot}/{$fmdir}/zip.php?id={$id}&rootdir={$rootdir}&what={$action}&groupid={$groupid}\">";
 // Prints how many files are being zipped
 print_simple_box_start("center", "500", "#C0C0C0");
 $msgbox = get_string('msgzipthese', 'block_file_manager');
 $count = 0;
 foreach ($USER->fm_cb as $c) {
     if ($c != 0 || substr($c, 0, 2) == "f-") {
         if (substr($c, 0, 2) == "f-") {
             $folder = get_record('fmanager_folders', "id", substr($c, 2));
             $msgbox .= "<br/>&nbsp;&nbsp;&nbsp;&nbsp;<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);
             $count++;
         } else {
             $link = get_record('fmanager_link', "id", $c);
             if ($link->type == TYPE_URL) {
                 $msgbox .= "<br/>&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"{$CFG->wwwroot}/blocks/file_manager/pix/www.gif\" >" . format_text($link->name, FORMAT_PLAIN) . " &nbsp;&nbsp;&nbsp;&nbsp;<font color=\"red\">" . get_string("msgnotincludedzip", 'block_file_manager') . "</font>";
function fm_print_user_shared_folder($id, $foldid, $original, $ownertype, $ownerisuser, $ownerisgroup)
{
    global $USER, $CFG;
    if ($ownertype == $ownerisuser) {
        $groupid = 0;
    } else {
        if ($ownertype == $ownerisgroup) {
            $groupid = $original;
        }
    }
    $fmdir = fm_get_root_dir();
    $options = "menubar=1,toolbar=1,status=1,location=0,scrollbars,resizable,width=600,height=400,top=150,left=100";
    $table->align = array("", "center", "center", "center");
    $table->width = "100%";
    $table->size = array("25%", "25%", "30%", "20%");
    $table->wrap = array('no', 'no', 'yes', 'no');
    $table->data = array();
    $strnamename = "<a href=\"{$CFG->wwwroot}/{$fmdir}/view_shared.php?id={$id}&ownertype={$ownertype}&original={$original}&catlinkid={$foldid}&tsort=sortname\">" . get_string("namename", 'block_file_manager') . "</a>";
    $strcatname = "<a href=\"{$CFG->wwwroot}/{$fmdir}/view_shared.php?id={$id}&ownertype={$ownertype}&original={$original}&catlinkid={$foldid}&tsort=sortcat\">" . get_string("catname", 'block_file_manager') . "</a>";
    $strdescname = "<a href=\"{$CFG->wwwroot}/{$fmdir}/view_shared.php?id={$id}&ownertype={$ownertype}&original={$original}&catlinkid={$foldid}&tsort=sortdesc\">" . get_string("descname", 'block_file_manager') . "</a>";
    $strdatename = "<a href=\"{$CFG->wwwroot}/{$fmdir}/view_shared.php?id={$id}&ownertype={$ownertype}&original={$original}&catlinkid={$foldid}&tsort=sortdate\">" . get_string("datename", 'block_file_manager') . "</a>";
    $table->head = array($strnamename, $strcatname, $strdescname, $strdatename);
    // Get all shared folders under folder
    $sharedfolder = fm_get_all_sharedf_by_folder($original, $foldid);
    if ($sharedfolder) {
        foreach ($sharedfolder as $sf) {
            $name = "";
            $cat = "";
            $desc = "";
            $date = "";
            $tmpurl = "{$CFG->wwwroot}/blocks/file_manager/view_shared.php?id={$id}&ownertype={$ownertype}&original={$original}&foldlinkid={$sf->id}";
            $name = "<a target=\"foldpopup\" title=\"" . get_string("msgopenfold", 'block_file_manager') . "\" href=\"{$tmpurl}\">" . "<img src=\"{$CFG->wwwroot}/blocks/file_manager/pix/folder.gif\" >&nbsp;" . format_text($sf->name, FORMAT_PLAIN) . "</a>";
            $table->data[] = array($name, $cat, $desc, $date);
        }
    }
    // Get all shared files under folder
    $sharedfiles = fm_get_all_shared_by_folder($original, $foldid);
    if ($sharedfiles) {
        foreach ($sharedfiles as $sf) {
            $name = "";
            $cat = "";
            $desc = "";
            $date = "";
            if ($sf->type == TYPE_FILE) {
                if ($sf->folder != 0) {
                    $folderinfo = fm_get_folder_path($sf->folder, true);
                    $bdir = $folderinfo . $sf->link;
                } else {
                    $bdir = $sf->link;
                }
                $tmphref = "{$CFG->wwwroot}/blocks/file_manager/file.php?cid={$id}&groupid={$groupid}&ownertype={$ownertype}&fileid={$sf->id}";
                $name = "<a target=\"urlpopup\" title=\"" . get_string("msgopenfile", 'block_file_manager', $sf->link) . "\" href=\"{$tmphref}\" onClick=\"window.open('{$tmphref}','urlpopup','{$options}');\"><img src=\"{$CFG->wwwroot}/blocks/file_manager/pix/file.gif\" >&nbsp;" . format_text($sf->name, FORMAT_PLAIN) . "</a>";
            } else {
                if ($sf->type == TYPE_URL) {
                    $name = "<a target=\"urlpopup\" title=\"" . get_string("msgopenlink", 'block_file_manager') . "\" href=\"{$sf->link}\"" . "onClick=\"window.open('{$sf->link}','urlpopup','{$options}');\"><img src=\"{$CFG->wwwroot}/blocks/file_manager/pix/www.gif\" >&nbsp;" . format_text($sf->name, FORMAT_PLAIN) . "</a>";
                } else {
                    if ($sf->type == TYPE_ZIP) {
                        $tmphref = "{$CFG->wwwroot}/blocks/file_manager/file.php?cid={$id}&groupid={$groupid}&ownertype={$ownertype}&fileid={$sf->id}";
                        $name = "<a target=\"urlpopup\" title=\"" . get_string("msgopenfile", 'block_file_manager', $sf->link) . "\" href=\"{$tmphref}\" onClick=\"window.open('{$tmphref}','urlpopup','{$options}');\"><img src=\"{$CFG->wwwroot}/blocks/file_manager/pix/zip.gif\" >&nbsp;" . format_text($sf->name, FORMAT_PLAIN) . "</a>";
                    }
                }
            }
            $desc = $sf->description;
            $cat = fm_get_user_categories($sf->category);
            $date = "<font size=1>" . userdate($sf->timemodified, "%m/%d/%Y  %H:%I") . "</font>";
            $table->data[] = array($name, $cat, $desc, $date);
        }
    }
    // If folder is empty
    if (!$sharedfiles && !$sharedfolder) {
        $table->data[] = array(get_string("msgnosharedfoldlink", 'block_file_manager'));
    }
    return $table;
}
Example #3
0
function upgrade_file_manager_db($continueto)
{
    global $CFG, $db;
    $fmdir = fm_get_root_dir();
    require_once "{$CFG->dirroot}/{$fmdir}/version.php";
    // Get code versions
    if (empty($CFG->file_manager_version)) {
        // file_manager has never been installed.
        $strdatabaseupgrades = get_string("databaseupgrades");
        print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades, "", "", false, "&nbsp;", "&nbsp;");
        $db->debug = true;
        if (modify_database("{$CFG->dirroot}/{$fmdir}/db/{$CFG->dbtype}.sql")) {
            $db->debug = false;
            if (set_config("file_manager_version", $file_manager_version) and set_config("file_manager_release", $file_manager_release)) {
                notify(get_string("databasesuccess"), "green");
                print_continue($continueto);
                exit;
            } else {
                error("Upgrade of file_manager system failed! (Could not update version in config table)", "view.php?id={$id}&rootdir={$rootdir}");
            }
        } else {
            error("file_manager tables could NOT be set up successfully!", "view.php?id={$id}&rootdir={$rootdir}");
        }
    }
    if ($file_manager_version > $CFG->file_manager_version) {
        // Upgrade tables
        $strdatabaseupgrades = get_string("databaseupgrades");
        print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades);
        require_once "{$CFG->dirroot}/{$fmdir}/db/{$CFG->dbtype}.php";
        $db->debug = true;
        if (file_manager_upgrade($CFG->file_manager_version)) {
            $db->debug = false;
            if (set_config("file_manager_version", $file_manager_version) and set_config("file_manager_release", $file_manager_release)) {
                notify(get_string("databasesuccess"), "green");
                notify(get_string("databaseupgradebackups", "", $file_manager_release));
                print_continue($continueto);
                exit;
            } else {
                error("Upgrade of file_manager system failed! (Could not update version in config table)", "view.php?id={$id}&rootdir={$rootdir}");
            }
        } else {
            $db->debug = false;
            error("Upgrade failed!  See file_manager/version.php", "view.php?id={$id}&rootdir={$rootdir}");
        }
    } else {
        if ($file_manager_version < $CFG->file_manager_version) {
            notify("WARNING!!!  The code you are using ({$file_manager_version}) is OLDER than the version that made the current database ({$CFG->file_manager_version})!");
        }
    }
}
function filemanager_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, $strfilesizename, $strdatename, $stractionname);
    } else {
        $table->head = array("", $strnamename, $strcatname, $strfilesizename, $strdatename);
    }
    $table->align = array("center", "left", "center", "center", "center");
    $table->width = "90%";
    $table->size = array("5%", "20%", "15%", "10%", "10%", "12%");
    $table->wrap = array(NULL, '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=\"" . format_text($folder->name, FORMAT_PLAIN) . "\" 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;";
            // deleting shared resources is disabled, from this dialog
            //<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, $filesize, $date, $actions);
            } else {
                $table->data[] = array("", $name, $catname, $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=\"" . format_text($link->name, FORMAT_PLAIN) . "\" value=\"{$link->id}\" />";
            $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;";
            // deleting shared resources is disabled, from this dialog
            //<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>";
            // 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=\"{$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>";
                }
            } else {
                if ($priv->allowsharing == 1) {
                    $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>";
                }
            }
            $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, $filesize, $date, $actions);
            } else {
                $table->data[] = array("", $name, $catname, $filesize, $date);
            }
        }
    }
    return $table;
}