Example #1
0
 function art_constant($name)
 {
     if (defined($GLOBALS["ART_VAR_PREFIXU"] . "_" . strtoupper($name))) {
         return CONSTANT($GLOBALS["ART_VAR_PREFIXU"] . "_" . strtoupper($name));
     } else {
         return strtolower($name);
     }
 }
 /**
  * Render the view
  */
 public function render()
 {
     if (null === $this->getLayoutPath()) {
         return;
     }
     /** @noinspection PhpUnusedLocalVariableInspection */
     $path = $this->getLayoutPath();
     $layoutPath = Steelcode_File_Helper::exists($this->getLayoutPath()) ? $this->getLayoutPath() : CONSTANT('INCLUDE_PATH') . 'includes/path-not-found.php';
     /** @noinspection PhpIncludeInspection */
     require_once $layoutPath;
 }
function displaydir($wdir, $files)
{
    //  $wdir == / or /a or /a/b/c/d  etc
    @ini_set('memory_limit', '1024M');
    global $courseid, $DB, $OUTPUT;
    global $USER, $CFG, $COURSE;
    global $choose;
    global $deptstr, $userstr;
    require_once $CFG->dirroot . '/blocks/morsle/constants.php';
    $course = $COURSE;
    $user = $USER;
    // Get the sort parameter if there is one
    $sort = optional_param('sort', 1, PARAM_INT);
    $dirlist = array();
    $filelist = array();
    $dirhref = array();
    $filehref = array();
    $courseid = $course->id;
    $coursecontext = context_course::instance($COURSE->id);
    // separate all the files list into directories and files
    foreach ($files as $name => $file) {
        if (is_folder($file)) {
            $dirlist[$name] = $file;
        } else {
            $filelist[$name] = $file;
        }
    }
    // setup variables and strings
    $strname = get_string("name", 'block_morsle');
    $strsize = get_string("size");
    $strmodified = get_string("modified");
    $straction = get_string("action");
    $strmakeafolder = get_string("morslemakecollection", 'block_morsle');
    $struploadafile = get_string("uploadafile");
    $strselectall = get_string("selectall");
    $strselectnone = get_string("deselectall");
    $strwithchosenfiles = get_string("withchosenfiles");
    $strmovetoanotherfolder = get_string("movetoanotherfolder");
    $strlinktocourse = get_string("linktocourse", 'block_morsle');
    $strmovefilestohere = get_string("movefilestohere");
    $strdeletefromcollection = get_string("deletefromcollection", 'block_morsle');
    $strcreateziparchive = get_string("createziparchive");
    $strrename = get_string("rename");
    $stredit = get_string("edit");
    $strunzip = get_string("unzip");
    $strlist = get_string("list");
    $strrestore = get_string("restore");
    $strchoose = get_string("choose");
    $strfolder = get_string("folder");
    $strfile = get_string("file");
    $strdownload = get_string("strdownload", 'block_morsle');
    $struploadthisfile = get_string("uploadthisfile");
    $struploadandlinkthisfile = get_string("uploadandlinkthisfile", 'block_morsle');
    $filesize = 'Varies as to type of document';
    $strmaxsize = get_string("maxsize", "", $filesize);
    $strcancel = get_string("cancel");
    $strmodified = get_string("strmodified", 'block_morsle');
    //CLAMP #289 set color and background-color to transparent
    //Kevin Wiliarty 2011-03-08
    $padrename = get_string("rename");
    $padedit = $padunzip = $padlist = $padrestore = $padchoose = $padfolder = $padfile = $padlink = '';
    $attsArr = array($padedit => $stredit, $padunzip => $strunzip, $padlist => $strlist, $padrestore => $strrestore, $padchoose => $strchoose, $padfolder => $strfolder, $padfile => $strfile, $padlink => $strlinktocourse);
    foreach ($attsArr as $key => $value) {
        $key = html_writer::div($value . '&nbsp', '', array('style' => 'color:transparent; background-color:transparent; display:inline;'));
    }
    /*
       $padedit = html_writer::div($stredit . '&nbsp','', array('style'=>'color:transparent; background-color:transparent; display:inline'));
       $padunzip = html_writer::div($strunzip . '&nbsp','', array('style'=>'color:transparent; background-color:transparent; display:inline'));
       $padlist = html_writer::div($strlist . '&nbsp','', array('style'=>'color:transparent; background-color:transparent; display:inline'));
       $padrestore = html_writer::div($strrestore . '&nbsp','', array('style'=>'color:transparent; background-color:transparent; display:inline'));
       $padchoose = html_writer::div($strchoose . '&nbsp','', array('style'=>'color: transparent; background-color:transparent; display:inline'));
       $padfolder = html_writer::div($strfolder . '&nbsp','', array('style'=>'color:transparent; background-color:transparent; display:inline;'));
       $padfile = html_writer::div($strfile . '&nbsp','', array('style'=>'color:transparent; background-color; transparent; display:inline;'));
       $padlink = html_writer::div($strlinktocourse . '&nbsp','', array('style'=>'color:transparent; background-color:transparent; display:inline;'));
    */
    $gdocsstr = 'Google-Docs-Storage-for-';
    // Set sort arguments so that clicking on a column that is already sorted reverses the sort order
    $sortvalues = array(1, 2, 3);
    foreach ($sortvalues as &$sortvalue) {
        if ($sortvalue == $sort) {
            $sortvalue = -$sortvalue;
        }
    }
    $upload_max_filesize = get_max_upload_file_size($CFG->maxbytes);
    // beginning of with selected files portion
    echo html_writer::start_tag('table', array('border' => '0', 'cellspacing' => '2', 'cellpadding' => '2', 'style' => 'min-width: 900px; margin-left:auto; margin-right:auto', 'class' => 'files'));
    if ($wdir !== '') {
        echo html_writer::start_tag('tr');
        //html_writer::table($table);
        if (!empty($USER->fileop) and $USER->fileop == "move" and $USER->filesource != $wdir) {
            echo html_writer::start_tag('td', array('colspan' => '3', 'align' => 'center'));
            // move files to other folder form
            echo html_writer::start_tag('form', array('action' => 'morslefiles.php', 'method' => 'get'));
            echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'choose', 'value' => $choose));
            echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'courseid', 'value' => $courseid));
            echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'wdir', 'value' => $wdir));
            echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'action', 'value' => 'paste'));
            echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'sesskey', 'value' => $USER->sesskey));
            echo html_writer::tag('input', '', array('align' => 'center', 'type' => 'submit', 'value' => $strmovefilestohere));
            //echo "<span> --> <b>$wdir</b></span><br />";
            echo html_writer::start_span() . '-->' . html_writer::tag('b', $wdir) . html_writer::end_span() . html_writer::end_tag('br');
            echo html_writer::end_tag('td');
            echo html_writer::start_tag('td');
            echo html_writer::end_tag('form');
            // cancel moving form
            echo html_writer::start_tag('form', array('action' => 'morslefiles.php', 'method' => 'get', 'align' => 'left'));
            echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'choose', 'value' => $choose));
            echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'courseid', 'value' => $courseid));
            echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'wdir', 'value' => $wdir));
            echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'action', 'value' => 'cancel'));
            echo html_writer::tag('input', '', array('type' => 'submit', 'value' => $strcancel, 'style' => 'color:red; margin-left:10px'));
            echo html_writer::end_tag('form');
            echo html_writer::end_tag('td');
        } else {
            if (has_capability('moodle/course:update', $coursecontext) || strpos($wdir, '-write')) {
                echo html_writer::start_tag('tr', array('style' => 'background-color: #ffddbb;'));
                echo html_writer::start_tag('td', array('colspan' => '3', 'align' => 'left', 'style' => 'background-color:#ffddbb; padding-left:5px;'));
                // file upload form
                // TODO: what if we're in the user or departmental dir?
                echo html_writer::start_tag('form', array('enctype' => 'multipart/form-data', 'method' => 'post', 'action' => 'morslefiles.php'));
                echo html_writer::start_span() . '&nbsp' . $struploadafile . '&nbsp(' . $strmaxsize . ')&nbsp' . html_writer::tag('b', $wdir) . html_writer::end_span() . html_writer::tag('br', '');
                echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'choose', 'value' => $choose));
                echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'courseid', 'value' => $courseid));
                echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'wdir', 'value' => $wdir));
                echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'action', 'value' => 'upload'));
                echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'sesskey', 'value' => $USER->sesskey));
                if (!isset($coursebytes)) {
                    $coursebytes = 0;
                }
                if (!isset($modbytes)) {
                    $modbytes = 0;
                }
                $maxbytes = get_max_upload_file_size($CFG->maxbytes, $coursebytes, $modbytes);
                $str = html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'MAX_FILE_SIZE', 'value' => $maxbytes)) . "\n";
                $name = 'userfile';
                $str .= html_writer::tag('input', '', array('type' => 'file', 'size' => '50', 'name' => $name, 'alt' => $name, 'style' => 'margin-left: 5px;')) . html_writer::end_tag('br') . "\n";
                echo $str;
                echo html_writer::tag('input', '', array('type' => 'submit', 'name' => 'save', 'value' => $struploadthisfile, 'style' => 'color:green; padding-left:5px;'));
                echo html_writer::tag('input', '', array('type' => 'submit', 'name' => 'savelink', 'value' => $struploadandlinkthisfile, 'style' => 'color:blue; padding-left:5px;'));
                echo html_writer::end_tag('form');
                echo html_writer::end_tag('td');
                echo html_writer::end_tag('tr');
                // cancel button div only if not in root morsle directory
                echo html_writer::start_tag('tr');
                echo html_writer::tag('td', '', array('colspan' => '2', 'style' => 'background-color:#ffddbb;'));
                echo html_writer::start_tag('td', array('style' => 'background-color:#ffddbb; padding-left:5px;', 'colspan' => '1', 'align' => 'right'));
                echo html_writer::start_tag('form', array('action' => 'morslefiles.php', 'method' => 'get', 'align' => 'left'));
                echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'choose', 'value' => $choose));
                echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'courseid', 'value' => $courseid));
                echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'wdir', 'value' => $wdir));
                echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'action', 'value' => 'cancel'));
                echo html_writer::tag('input', '', array('type' => 'submit', 'value' => $strcancel, 'align' => 'left', 'style' => 'color:red;'));
                echo html_writer::end_tag('form');
                echo html_writer::end_tag('td');
                echo html_writer::end_tag('tr');
                echo html_writer::end_tag('tr');
                echo html_writer::start_tag('tr');
                echo html_writer::start_tag('tr') . html_writer::tag('td', '<br>', array('colspace' => '4')) . html_writer::end_tag('tr');
                echo html_writer::start_tag('td', array('style' => 'max-width:50px; white-space:nowrap;', 'colspan' => '2', 'align' => 'left'));
                //dummy form - alignment only
                echo html_writer::start_tag('form', array('action' => 'morslefiles.php', 'method' => 'get'));
                echo html_writer::start_tag('fieldset', array('class' => 'invisiblefieldset'));
                echo html_writer::tag('input', '', array('type' => 'button', 'value' => $strselectall, 'onclick' => 'checkall();', 'style' => 'color:green;'));
                echo html_writer::tag('input', '', array('type' => 'button', 'value' => $strselectnone, 'onclick' => 'checknone();', 'style' => 'color:red;'));
                echo html_writer::end_tag('fieldset');
                echo html_writer::end_tag('form');
                echo html_writer::end_tag('td');
                echo html_writer::start_tag('td', array('align' => 'center', 'colspan' => '2'));
                // makedir form
                // TODO: program to allow this in user and departmental directory
                if (strpos($wdir, $deptstr) === false && strpos($wdir, $userstr) === false) {
                    // not a user or departmental folder
                    echo html_writer::start_tag('form', array('action' => 'morslefiles.php', 'method' => 'get'));
                    echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'choose', 'value' => $choose));
                    echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'courseid', 'value' => $courseid));
                    echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'wdir', 'value' => $wdir));
                    echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'action', 'value' => 'makedir'));
                    echo html_writer::tag('input', '', array('type' => 'submit', 'value' => $strmakeafolder));
                    echo html_writer::end_tag('form');
                }
                echo html_writer::end_tag('td');
                echo html_writer::end_tag('tr');
            }
        }
    }
    echo html_writer::start_tag('form', array('action' => 'morslefiles.php', 'method' => 'post', 'id' => 'dirform'));
    echo html_writer::start_div();
    echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'choose', 'value' => $choose));
    echo html_writer::start_tag('tr');
    echo html_writer::start_tag('th', array('class' => 'header', 'scope' => 'col', 'style' => 'max-width:40px;'));
    echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'courseid', 'value' => $courseid));
    echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'choose', 'value' => $choose));
    echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'wdir', 'value' => $wdir));
    echo html_writer::tag('input', '', array('type' => 'hidden', 'name' => 'sesskey', 'value' => $USER->sesskey));
    //      $options = array ("delete" => "$strdeletefromcollection");
    // only editing teachers can link items to course page
    if (has_capability('moodle/course:update', $coursecontext)) {
        $options['link'] = "{$strlinktocourse}";
    }
    if (!empty($filelist) || !empty($dirlist)) {
        //        echo html_writer::tag('label', "$strwithchosenfiles...", array('for'=>'formactionid'));
        //    	  echo html_writer::select($options, "$strwithchosenfiles...", '', array(1 => "$strwithchosenfiles..."));
        echo html_writer::start_div('', array('id' => 'noscriptgo', 'style' => 'display:inline;'));
        echo html_writer::tag('input', '', array('type' => 'submit', 'value' => get_string('go')));
        echo html_writer::script('document.getElementById("noscriptgo").style.display="none"');
        echo html_writer::end_div();
    }
    echo html_writer::end_tag('th');
    echo html_writer::start_tag('th', array('style' => 'padding-right:120px;', 'class' => 'header name', 'scope' => 'col')) . html_writer::link(qualified_me(), $strname, array('&sort' => '{' . $sortvalues[0] . '}')) . html_writer::end_tag('th');
    echo html_writer::start_tag('th', array('class' => 'header date', 'scope' => 'col')) . html_writer::link(qualified_me(), $strmodified, array('&sort' => '{' . $sortvalues[2] . '}')) . html_writer::end_tag('th');
    echo html_writer::tag('th', $straction, array('class' => 'header commands', 'scope' => 'col'));
    echo html_writer::end_tag('tr') . "\n";
    // Sort parameter indicates column to sort by, and parity gives the direction
    switch ($sort) {
        case 1:
            $sortcmp = 'return strcasecmp($a[0],$b[0]);';
            break;
        case -1:
            $sortcmp = 'return strcasecmp($b[0],$a[0]);';
            break;
        case 2:
            $sortcmp = 'return ($a[1] - $b[1]);';
            break;
        case -2:
            $sortcmp = 'return ($b[1] - $a[1]);';
            break;
        case 3:
            $sortcmp = 'return ($a[2] - $b[2]);';
            break;
        case -3:
            $sortcmp = 'return ($b[2] - $a[2]);';
            break;
    }
    // Create a 2D array of directories and sort
    $dirdetails = array();
    foreach ($dirlist as $name => $dir) {
        $dirdetails[$name] = new stdClass();
        $dirdetails[$name]->updated = docdate($dir);
        $dirdetails[$name]->link = $dir->alternateLink;
        //        usort($dirdetails, create_function('$a,$b', $sortcmp));
    }
    // TODO: change to handle cross-listed courses
    // TODO: this needs to change if we eliminate morsle table
    if ($wdir === '') {
        $shortname = is_number(substr($course->shortname, 0, 5)) ? substr($course->shortname, 6) : $course->shortname;
        // SPLIT INTO DEPARTMENTAL CODES
        $dept = explode("-", $shortname);
        $deptpart = defined($dept[0]) ? CONSTANT($dept[0]) : null;
        $deptstr = $deptpart . $deptstr;
        $deptaccount = strtolower($deptstr);
        // only show the user collection if we're in the base folder
        $dirdetails[$userstr] = new stdClass();
        $dirdetails[$userstr]->updated = date('Y-m-d');
        $dirdetails[$userstr]->link = 'https://drive.google.com';
        // always include departmental directory if exists
        // check to see if we even have a departmental account for this department but don't show the departmental collection if we're already in it indicated by $wdir
        if ($is_morsle_dept = $DB->get_record('morsle_active', array('shortname' => $deptaccount)) && has_capability('moodle/course:update', $coursecontext)) {
            $dirdetails[$deptstr] = new stdClass();
            $dirdetails[$deptstr]->updated = date('Y-m-d');
        }
    }
    // Create a 2D array of files and sort
    $filedetails = array();
    $filetitles = array();
    foreach ($filelist as $name => $file) {
        $filedetails[$name] = new stdClass();
        $filedetails[$name]->updated = docdate($file);
        $filedetails[$name]->link = $file->alternateLink;
        //        $row = array($filename, $filedate);
        //		array_push($filedetails, $row);
        //		usort($filedetails, create_function('$a,$b', $sortcmp));
    }
    // TODO: fix this hack so we're back to being able to sort
    //    ksort($filedetails); // sets the locked in sorting to name
    // need this in order to look up the link for the file based on doc title (key)
    /*
        if (sizeof($filelist) > 0) {
                $filevalues = array_values($filelist);
                $filelist = array_combine($filetitles, $filevalues);
        }
    */
    //    $count = 0;
    //    $countdir = 0;
    $edittext = $padchoose . $padedit . $padunzip . $padlist . $padrestore;
    if ($wdir !== '') {
        $pathparts = explode('/', $wdir);
        array_pop($pathparts);
        $wdir = implode('/', $pathparts);
        echo "<tr class=\"folder\">";
        print_cell();
        print_cell('left', '<a href="morslefiles.php?courseid=' . $courseid . '&amp;wdir=' . $wdir . '&amp;choose=' . $choose . '&amp;name=' . $name . '"><img src="' . $OUTPUT->pix_url('f/folder') . '" class="icon" alt="" />&nbsp;' . get_string('parentfolder') . '</a>', 'name');
        //        print_cell('left', '<a  style="padding-left:0px" href="morslefiles.php?courseid='.$courseid.'&amp;wdir='.$wdir.'/&amp;choose='.$choose.'">&nbsp;'.get_string('parentfolder').'</a>', 'parent');
        echo "</tr>";
    }
    if (!empty($dirdetails)) {
        foreach ($dirdetails as $name => $dir) {
            echo html_writer::start_tag('tr', array('class' => 'folder'));
            $filedate = $dir->updated;
            $filesafe = rawurlencode($name);
            $filename = $name;
            $fileurl = $dir->link;
            //           	$countdir++;
            // TODO: fix the parent directory
            if ($name == '..') {
                //                $fileurl = rawurlencode(dirname($wdir));
                print_cell();
                // alt attribute intentionally empty to prevent repetition in screen reader
                //CLAMP #289 change padding-left from 10 to 0px
                //Kevin Wiliarty 2011-03-08
                print_cell('left', '<a  style="padding-left:0px" href="morslefiles.php?courseid=' . $courseid . '&amp;wdir=' . $wdir . '/' . $fileurl . '&amp;choose=' . $choose . '"><img src="' . $OUTPUT->pix_url('f/parent.gif') . '" class="icon" alt="" />&nbsp;' . get_string('parentfolder') . '</a>', 'name');
                print_cell();
                print_cell();
                print_cell();
                /*
                            } else if ($name === $userstr) { // if departmental account or user collection
                            	// TODO: need to determine what $wdir is if we're coming in from one of the course subcollections
                                // don't know where this fits in
                		$branchdir = strpos($wdir,'read') !== false || strpos($wdir,'write') !== false  || $wdir === '' ? $filesafe : "$wdir/$filesafe";
                                 print_cell();
                                // alt attribute intentionally empty to prevent repetition in screen reader
                				//CLAMP #289 change padding-left from 10 to 0px
                				//Kevin Wiliarty 2011-03-08
                                print_cell('left', '<a  style="padding-left:0px" href="morslefiles.php?courseid=' . $courseid . '&amp;wdir=' . $wdir . '&amp;choose=' . $choose .'&amp;name=' . $name . '"><img src="'.$OUTPUT->pix_url('f/folder').'" class="icon" alt="" />&nbsp;'. $name .'</a>', 'name');
                //                print_cell('left', '<a  style="padding-left:0px" href="' . $fileurl . '" target="_blank"><img src="'. $OUTPUT->pix_url("f/folder") .'" class="icon" alt="" />&nbsp;'. $filename .'</a>');
                                print_cell("right", $filedate, 'date');
                //                print_cell();
                                print_cell();
                //              print_cell();
                            } else if ($name === $deptstr){
                            	// TODO: need to determine what $wdir is if we're coming in from one of the course subcollections
                		$branchdir = strpos($wdir,'read') !== false || strpos($wdir,'write') !== false  || $wdir === '' ? $filesafe : "$wdir/$filesafe";
                            	print_cell("center", "<input type=\"checkbox\" name=\"dir$countdir\" value=\"$filename\" />", 'checkbox');
                                // alt attribute intentionally empty to prevent repetition in screen reader
                				//CLAMP #289 change padding-left from 10 to 0px
                				//Kevin Wiliarty 2011-03-08
                                print_cell('left', '<a  style="padding-left:0px" href="morslefiles.php?courseid=' . $courseid . '&amp;wdir=' . $branchdir . '&amp;choose=' . $choose . '&amp;name=' . $name . '"><img src="'.$OUTPUT->pix_url('f/folder').'" class="icon" alt="" />&nbsp;'. $name .'</a>', 'name');
                                print_cell("right", $filedate, 'date');
                //                print_cell();
                				if (has_capability('moodle/course:update', $coursecontext)) {
                	                print_cell("left", "$edittext<a href=\"morslefiles.php?courseid=$courseid&amp;wdir=$branchdir&amp;file=$filename&amp;action=link&amp;type=dir&amp;choose=$choose\">$strlinktocourse</a>", 'commands');
                				}
                //              print_cell();
                */
            } else {
                // not a user or departmental folder
                print_cell();
                //               	print_cell("center", "<input type=\"checkbox\" name=\"$name\" value=\"$filename\" />", 'checkbox');
                //                print_cell("left", "<a href=\"morslefiles.php?courseid=$courseid&amp;wdir=$wdir/$filesafe&amp;choose=$choose\"><img src=\"$OUTPUT->pix_url('f/folder')\" class=\"icon\" alt=\"$strfolder\" />&nbsp;".$filename."</a>", 'name');
                $branchdir = "{$wdir}/{$filesafe}";
                //                $branchdir = strpos($wdir,'read') !== false || strpos($wdir,'write') !== false  || $wdir === '' ? $filesafe : "$wdir/$filesafe";
                print_cell('left', '<a href="morslefiles.php?courseid=' . $courseid . '&amp;wdir=' . $branchdir . '&amp;choose=' . $choose . '&amp;name=' . $name . '"><img src="' . $OUTPUT->pix_url('f/folder') . '" class="icon" alt="" />&nbsp;' . $filename . '</a>', 'name');
                print_cell("right", $filedate, 'date');
                //                print_cell();
                if (has_capability('moodle/course:update', $coursecontext)) {
                    print_cell("left", "{$edittext}<a href=\"morslefiles.php?courseid={$courseid}&amp;wdir={$branchdir}&amp;file={$filename}&amp;action=link&amp;type=dir&amp;choose={$choose}\">{$strlinktocourse}</a>", 'commands');
                    //                    print_cell("left", "$edittext<a href=\"morslefiles.php?courseid=$courseid&amp;wdir=$wdir&amp;file=$filename&amp;action=link&amp;type=dir&amp;choose=$choose\">$strlinktocourse</a>", 'commands');
                }
            }
            echo html_writer::end_tag('tr');
        }
    }
    $iconchoices = array('excel' => 'download/spreadsheets', 'powerpoint' => 'download/presentations', 'word' => 'download/documents', 'pdf' => 'application/pdf');
    if (!empty($filedetails)) {
        foreach ($filedetails as $name => $file) {
            if (isset($filelist[$name]->exportLinks)) {
                $links = array();
                $links = array_values($filelist[$name]->exportLinks);
                $exportlink = $links[0];
            } else {
                $exportlink = $filelist[$name]->alternateLink;
            }
            // positively identify the correct icon regardless of filename extension
            $icon = $filelist[$name]->iconLink;
            $filename = $name;
            $fileurl = $file->link;
            $embedlink = $filelist[$name]->embedLink;
            $embedsafe = rawurlencode($embedlink);
            $fileurlsafe = rawurlencode($fileurl);
            $filedate = $file->updated;
            $fileid = $filelist[$name]->id;
            $selectfile = trim($fileurl, "/");
            //            echo html_writer::start_tag('td', array('class'=>'file'));
            //            echo html_writer::end_tag('td');
            print_cell("center", "<input type=\"checkbox\" name=\"file\" value=\"{$filename}\" />", 'checkbox');
            //CLAMP #289 change padding-left from 10 to 0px
            //Kevin Wiliarty 2011-03-08
            //            echo html_writer::start_tag('td', array('align'=>'left','style'=>'white-space:nowrap; padding-left:0px;','class'=>'name'));
            print_cell('left', '<a href="' . $fileurl . '" class="morslefile" target="_blank">
            		<img src="' . $icon . '" class="icon" alt="' . $strfile . '" /> ' . $filename . '</a>', 'name');
            //            $echovar = '<a href="' . $fileurl . '" target="_blank">
            //            		<img src="' . $OUTPUT->pix_url("f/$icon") . '" class="icon" alt="' . $strfile . '" />&nbsp;' . htmlspecialchars($filename) . '</a>';
            //            echo $echovar;
            //html_writer::link(qualified_me(), $strname, array('&sort'=>'{'.$sortvalues[0].'}'))
            //$echovar = html_writer::tag('a', $fileurl, array('target'=>'_blank')) . html_writer::img($OUTPUT->pix_url("f/$icon"), $strfile, array('class'=>'icon')) . '&nbsp;'.htmlspecialchars($filename) . html_writer::end_tag('a');
            //echo $echovar;
            //            echo html_writer::end_tag('td');
            print_cell("right", $filedate, 'date');
            if (has_capability('moodle/course:update', $coursecontext)) {
                if (strpos($wdir, $gdocsstr) === 1) {
                    print_cell("left", "{$edittext} <a href=\"morslefiles.php?courseid={$courseid}&amp;wdir={$wdir}/{$fileid}&amp;file={$filename}&amp;name={$filename}&amp;filelink={$fileurl}&amp;action=link&amp;type=file&amp;choose={$choose}\">{$strlinktocourse}</a>", 'commands');
                } else {
                    print_cell("left", "{$edittext} <a href=\"morslefiles.php?courseid={$courseid}&amp;wdir={$wdir}&amp;file={$filename}&amp;action=link&amp;type=file&amp;choose={$choose}\">{$strlinktocourse}</a>", 'commands');
                }
                //                print_cell('left', '&nbsp&nbsp<a title="' . $name . '" href="embeddoc.php?courseid=$courseid&amp;embedlink=' . $embedsafe . '&amp;name=' . $filename . '"> Embed </a>','embed');
            }
            //            print_cell('left', '&nbsp&nbsp<a title="' . strip_tags($strdownload) . ': ' . $name . '" href="' .$CFG->wwwroot
            //                    . '/blocks/morsle/docs_export.php?exportlink=' . s($exportlink) . '&shortname=' . $course->shortname . '&title=' . $filename . '" target="_blank"> Download </a>','commands');
            print_cell();
            print_cell('left', '&nbsp&nbsp<a title="' . $name . '" href="' . s($exportlink) . '" target="_blank"> Download </a>', 'commands');
            //print_cell('left', '&nbsp&nbsp<a title="' . $name . '" href="embeddoc.php?"' . s($embedlink) . '" target="_blank"> Embed in a Page resource </a>','commands');
            echo html_writer::end_tag('tr');
        }
    }
    echo html_writer::end_div();
    echo html_writer::end_tag('form');
    echo html_writer::end_tag('table');
}
Example #4
0
 function mod_constant($name)
 {
     global $icmsModule;
     if (!empty($GLOBALS["VAR_PREFIXU"]) && @defined($GLOBALS["VAR_PREFIXU"] . "_" . strtoupper($name))) {
         return CONSTANT($GLOBALS["VAR_PREFIXU"] . "_" . strtoupper($name));
     } elseif (!empty($icmsModule) && @defined(strtoupper($icmsModule->getVar("dirname", "n") . "_" . $name))) {
         return CONSTANT(strtoupper($icmsModule->getVar("dirname", "n") . "_" . $name));
     } elseif (defined(strtoupper($name))) {
         return CONSTANT(strtoupper($name));
     } else {
         return str_replace("_", " ", strtolower($name));
     }
 }
Example #5
0
 /**
  * Perform a MySQL database query, using current database connection.
  *
  * More information can be found on the codex page.
  *
  * @since 0.71
  *
  * @param string $query
  * @return unknown
  */
 function query($query)
 {
     if (!$this->ready) {
         return false;
     }
     // filter the query, if filters are available
     // NOTE: some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
     if (function_exists('apply_filters')) {
         $query = apply_filters('query', $query);
     }
     // initialise return
     $return_val = 0;
     $this->flush();
     // Log how the function was called
     $this->func_call = "\$db->query(\"{$query}\")";
     // Keep track of the last query for debug..
     $this->last_query = $query;
     // Perform the query via std mysql_query function..
     if (defined('SAVEQUERIES') && SAVEQUERIES) {
         $this->timer_start();
     }
     // use $this->dbh for read ops, and $this->dbhwrite for write ops
     // use $this->dbhglobal for gloal table ops
     unset($dbh);
     if (defined("WP_USE_MULTIPLE_DB") && CONSTANT("WP_USE_MULTIPLE_DB") == true) {
         if ($this->blogs != '' && preg_match("/(" . $this->blogs . "|" . $this->users . "|" . $this->usermeta . "|" . $this->site . "|" . $this->sitemeta . "|" . $this->sitecategories . ")/i", $query)) {
             if (false == isset($this->dbhglobal)) {
                 $this->db_connect($query);
             }
             $dbh =& $this->dbhglobal;
             $this->last_db_used = "global";
         } elseif (preg_match("/^\\s*(alter table|create|insert|delete|update|replace) /i", $query)) {
             if (false == isset($this->dbhwrite)) {
                 $this->db_connect($query);
             }
             $dbh =& $this->dbhwrite;
             $this->last_db_used = "write";
         } else {
             $dbh =& $this->dbh;
             $this->last_db_used = "read";
         }
     } else {
         $dbh =& $this->dbh;
         $this->last_db_used = "other/read";
     }
     $this->result = @mysql_query($query, $dbh);
     ++$this->num_queries;
     if (defined('SAVEQUERIES') && SAVEQUERIES) {
         $this->queries[] = array($query, $this->timer_stop(), $this->get_caller());
     }
     // If there is an error then take note of it..
     if ($dbh) {
         if (mysql_error($dbh)) {
             $this->print_error(mysql_error($dbh));
             return false;
         }
     }
     if (preg_match("/^\\s*(insert|delete|update|replace) /i", $query)) {
         $this->rows_affected = mysql_affected_rows($dbh);
         // Take note of the insert_id
         if (preg_match("/^\\s*(insert|replace) /i", $query)) {
             $this->insert_id = mysql_insert_id($dbh);
         }
         // Return number of rows affected
         $return_val = $this->rows_affected;
     } else {
         $i = 0;
         while ($i < @mysql_num_fields($this->result)) {
             $this->col_info[$i] = @mysql_fetch_field($this->result);
             $i++;
         }
         $num_rows = 0;
         while ($row = @mysql_fetch_object($this->result)) {
             $this->last_result[$num_rows] = $row;
             $num_rows++;
         }
         @mysql_free_result($this->result);
         // Log number of rows the query returned
         $this->num_rows = $num_rows;
         // Return number of rows selected
         $return_val = $this->num_rows;
     }
     return $return_val;
 }
 public function get_listing($path = '', $page = '', $query = null)
 {
     global $CFG, $USER, $OUTPUT, $COURSE, $DB;
     require_once "{$CFG->dirroot}/google/constants.php";
     require_once 'course_constants.php';
     $ret = array();
     $ret['dynload'] = true;
     $user = build_user();
     $course = $COURSE;
     //    	$user = $USER->email; // TODO: uncomment
     $useraccount = $USER->email;
     $user = $useraccount;
     $deptstr = get_string('departmentaccountstring', 'repository_morsle');
     // get departmental folder if exists
     $shortname = is_number(substr($course->shortname, 0, 5)) ? substr($course->shortname, 6) : $course->shortname;
     $morsleaccount = strtolower($course->shortname . '@' . $this->domain);
     // SPLIT INTO DEPARTMENTAL CODES
     $dept = explode("-", $shortname);
     if (defined($dept[0])) {
         $deptstr = CONSTANT($dept[0]) . $deptstr;
         $deptshortstr = strtolower(substr($deptstr, 0, 6));
         $deptaccount = strtolower($deptstr . '@' . $this->domain);
     } else {
         $deptstr = 'nodept';
         $deptshortstr = 'nodept';
         $deptaccount = 'nodept';
     }
     // get course level folders or documents
     $maxfiles = get_config('morsle', 'maxfilesreturned');
     // get a docid if available
     $path = base64_decode($path);
     if ($path == '') {
         $root_path = null;
         $pathleftover = null;
         $search_path = null;
     } elseif ($path == $deptstr) {
         $root_path = $deptstr;
         $pathleftover = null;
         $search_path = null;
     } elseif (strpos($path, '|')) {
         list($docid, $pathleftover) = explode('|', $path);
         $search_path = 'folder%3A' . $docid;
         $root_path = strtolower(substr($pathleftover, 0, 6));
     } else {
         $root_path = strtolower(substr($path, 0, 6));
         $pathleftover = $path;
         $search_path = null;
     }
     // handle a search instance
     if ($query !== null) {
         $root_path = 'queryi';
     }
     switch ($root_path) {
         case null:
             // empty: get only the readonly and writeable folders plus any files and user folder and (if available) department folder
             $user = $morsleaccount;
             $search = array('xoauth_requestor_id' => $user, 'showfolders' => 'true', 'folder' => 'folder%3Aroot', 'max-results' => $maxfiles);
             if ($search_path !== null) {
                 // looking for another folder's contents
                 $search['folder'] = $search_path;
             }
             $mauth = new morsle_oauth_request(null, null, $search);
             // subauthtoken ignored
             //		unset($search['repo_id']);
             $mdocs = new morsle_docs($mauth);
             $ret['list'] = $mdocs->get_file_list($search, $this);
             // get user level folders or documents
             $user = $useraccount;
             $title = get_string('useraccountstring', 'repository_morsle') . $user;
             $url = DOCUMENTFEED_URL;
             $ret['list'][] = array('title' => $title, 'url' => $url, 'source' => $url, 'date' => usertime(strtotime(time())), 'children' => array(), 'path' => base64_encode('User Files'), 'thumbnail' => (string) $OUTPUT->pix_url('f/folder-64'));
             // check to see if we even have a departmental account for this department but don't show the departmental collection if we're already in it indicated by $wdir
             // TODO: this needs to change if we eliminate morsle table, but if the read-only or writeable folders get renamed then we need the table
             // department account if exists
             $conditions = " shortname = '{$deptstr}' ";
             $user = $deptaccount;
             $title = get_string('deptaccountstring', 'repository_morsle') . $user;
             if (strpos($path, $deptstr) === false && ($is_morsle_dept = $DB->get_record_select('morsle_active', $conditions))) {
                 $ret['list'][] = array('title' => $deptstr, 'url' => $url, 'source' => $url, 'date' => usertime(strtotime(time())), 'children' => array(), 'path' => base64_encode($deptstr), 'thumbnail' => (string) $OUTPUT->pix_url('f/folder-64'));
             }
             $ret['path'][]['name'] = 'Morsle Files';
             break;
         case 'queryi':
         case 'user f':
             // user account google files
             $search = array('xoauth_requestor_id' => $user, 'path' => $pathleftover, 'showfolders' => 'true', 'repo_id' => 5, 'max-results' => $maxfiles);
             if ($search_path !== null) {
                 // looking for another folder's contents
                 $search['folder'] = $search_path;
             }
             if ($query !== null) {
                 $search['q'] = $query;
             }
             $mauth = new morsle_oauth_request(null, null, $search);
             // subauthtoken ignored
             unset($search['repo_id']);
             $mdocs = new morsle_docs($mauth);
             $ret['list'] = $mdocs->get_file_list($search, $this);
             $ret['path'][]['name'] = $pathleftover;
             break;
         case '/':
             // TODO: what does this get
             $search = array('xoauth_requestor_id' => $user, 'folder' => $search_path, 'repo_id' => 5, 'max-results' => $maxfiles);
             $mauth = new morsle_oauth_request(null, null, $search);
             // subauthtoken ignored
             unset($search['repo_id']);
             $mdocs = new morsle_docs($mauth);
             $ret['list'] = $mdocs->get_file_list($search, $this);
             break;
         case $deptstr:
             // department account google files, if we got here it means department files exist
             $user = $deptaccount;
             $search = array('xoauth_requestor_id' => $user, 'path' => $pathleftover, 'showfolders' => 'true', 'repo_id' => 5, 'max-results' => $maxfiles);
             if ($search_path !== null) {
                 // looking for another folder's contents
                 $search['folder'] = $search_path;
             }
             $mauth = new morsle_oauth_request(null, null, $search);
             // subauthtoken ignored
             unset($search['repo_id']);
             $mdocs = new morsle_docs($mauth);
             $ret['list'] = $mdocs->get_file_list($search, $this);
             $ret['path'][]['name'] = $pathleftover;
             break;
         case 'morsle':
             // only way we'd get here is if the read-only or writeable folder got clicked
             $user = $morsleaccount;
             $search = array('xoauth_requestor_id' => $user, 'path' => 'Morsle Files', 'max-results' => $maxfiles);
             if ($search_path !== null) {
                 // looking for another folder's contents
                 $search['folder'] = $search_path;
             }
             $mauth = new morsle_oauth_request(null, null, $search);
             // subauthtoken ignored
             unset($search['repo_id']);
             $mdocs = new morsle_docs($mauth);
             $ret['list'] = $mdocs->get_file_list($search);
             $ret['path'][]['name'] = $pathleftover;
             break;
         default:
             // empty: get only the readonly and writeable folders user folder and (if available) department folder
             $user = $morsleaccount;
             //	        list($title, $domain) = explode('@',$user);
             $search = array('xoauth_requestor_id' => $user, 'showfolders' => 'true', 'max-results' => $maxfiles);
             if ($search_path !== null) {
                 // looking for another folder's contents
                 $search['folder'] = $search_path;
             }
             $mauth = new morsle_oauth_request(null, null, $search);
             // subauthtoken ignored
             //		unset($search['repo_id']);
             $mdocs = new morsle_docs($mauth);
             $ret['list'] = $mdocs->get_file_list($search, $this);
             // check to see if we even have a departmental account for this department but don't show the departmental collection if we're already in it indicated by $wdir
             // TODO: this needs to change if we eliminate morsle table
             $conditions = " shortname = '{$deptstr}' ";
             $user = $deptaccount;
             $title = get_string('deptaccountstring', 'repository_morsle') . $user;
             if (strpos($path, $deptstr) === false && ($is_morsle_dept = $DB->get_record_select('morsle_active', $conditions))) {
                 $ret['list'][] = array('title' => $deptstr, 'url' => $url, 'source' => $url, 'date' => usertime(strtotime(time())), 'children' => array(), 'path' => base64_encode($deptstr), 'thumbnail' => (string) $OUTPUT->pix_url('f/folder-64'));
             }
             $ret['path'][]['name'] = 'Morsle Files';
     }
     return $ret;
 }
         $newbbperm_handler->applyTemplate($forum, $module_id);
     }
     redirect_header("admin_permissions.php", 2, _AM_NEWBB_PERM_TEMPLATE_APPLIED);
     break;
 default:
     $opform = new XoopsSimpleForm(_AM_NEWBB_PERM_ACTION, 'actionform', 'admin_permissions.php', "get");
     $op_select = new XoopsFormSelect("", 'action');
     $op_select->setExtra('onchange="document.forms.actionform.submit()"');
     $op_select->addOptionArray(array("no" => _SELECT, "template" => _AM_NEWBB_PERM_TEMPLATE, "apply" => _AM_NEWBB_PERM_TEMPLATEAPP, "default" => _AM_NEWBB_PERM_SETBYGROUP));
     $opform->addElement($op_select);
     $opform->display();
     $op_options = array("category" => _AM_NEWBB_CAT_ACCESS);
     $fm_options = array("category" => array("title" => _AM_NEWBB_CAT_ACCESS, "item" => "category_access", "desc" => "", "anonymous" => true));
     foreach ($perms as $perm) {
         $op_options[$perm] = CONSTANT("_AM_NEWBB_CAN_" . strtoupper($perm));
         $fm_options[$perm] = array("title" => CONSTANT("_AM_NEWBB_CAN_" . strtoupper($perm)), "item" => "forum_" . $perm, "desc" => "", "anonymous" => true);
     }
     $op_keys = array_keys($op_options);
     $op = isset($_GET['op']) ? strtolower($_GET['op']) : (isset($_COOKIE['op']) ? strtolower($_COOKIE['op']) : "");
     if (empty($op)) {
         $op = $op_keys[0];
         setCookie("op", isset($op_keys[1]) ? $op_keys[1] : "");
     } elseif (false !== ($key = array_search($op, $op_keys))) {
         setCookie("op", isset($op_keys[$key + 1]) ? $op_keys[$key + 1] : "");
     }
     $opform = new XoopsSimpleForm('', 'opform', 'admin_permissions.php', "get");
     $op_select = new XoopsFormSelect("", 'op', $op);
     $op_select->setExtra('onchange="document.forms.opform.submit()"');
     $op_select->addOptionArray($op_options);
     $opform->addElement($op_select);
     $opform->display();
Example #8
0
<?php

/**
 * Spotlight
 *
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code 
 * which is considered copyrighted (c) material of the original comment or credit authors.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @copyright      The BEIJING XOOPS Co.Ltd. http://www.xoops.com.cn
 * @license        http://www.fsf.org/copyleft/gpl.html GNU public license
 * @package        spotlight
 * @since          1.0.0
 * @author         Mengjue Shao <*****@*****.**>
 * @author         Susheng Yang <*****@*****.**>
 * @version        $Id: config.php 1 2010-9-4 ezsky$
 */
$item_name = strtoupper(basename(dirname(__FILE__)));
return $config = array("title" => CONSTANT("_MD_TRANSFER_{$item_name}"), "desc" => CONSTANT("_MD_TRANSFER_{$item_name}_DESC"), "level" => 11, "url" => XOOPS_URL . "/modules/spotlight/action.transfer.php");
    error("That's an invalid course id");
}
require_login($id);
if (!($CONSUMER_KEY = get_config('blocks/morsle', 'consumer_key'))) {
    exit;
}
require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id));
// determine departmental account name and if exists
// constants here are defined in blocks/morsle/constants.php
if (is_numeric(substr($courseaccount, 0, 5))) {
    if (defined('DEPTLEADINGSKIP')) {
        $shortname = substr($course->shortname, DEPTLEADINGSKIP);
    }
    // SPLIT INTO DEPARTMENTAL CODES
    $dept = explode(DEPTDELIMITER, $shortname);
    $deptaccount = strtolower(CONSTANT($dept[0]) . '-Departmental-Morsle-Account');
    $deptemail = strtolower($deptaccount . '@' . $CONSUMER_KEY);
    if (!$checkaccounts) {
        $deptfeed = get_doc_feed($deptemail);
    }
}
// identify various accounts
$strcourseuser = get_string("strcourseuser", "block_morsle", $course->shortname);
$strdepartmentuser = get_string("strdepartmentuser", 'block_morsle', $deptaccount);
$strownuser = get_string("strownuser", 'block_morsle', $user->email);
$struploadtargetchoice = get_string('struploadtarget', 'block_morsle');
// find out if a course morsle account exists for this course
$courseaccount = strtolower($course->shortname);
$courseemail = $courseaccount . '@' . $CONSUMER_KEY;
if (!$checkaccounts) {
    $coursefeed = get_doc_feed($courseemail);