Example #1
0
 public function definition()
 {
     global $CFG, $OUTPUT, $COURSE;
     $accepted_types = '.pdf';
     if ($CFG->emarking_enabledigitizedzipfile) {
         $accepted_types .= ',.zip';
     }
     // Options for uploading the zip file within the form.
     $options = array('subdirs' => 0, 'maxbytes' => get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes, $COURSE->maxbytes), 'maxfiles' => 1, 'accepted_types' => $accepted_types, 'return_types' => FILE_INTERNAL);
     $mform = $this->_form;
     $instance = $this->_customdata;
     // Header.
     $mform->addElement('header', 'digitizedfilepdf', get_string('uploadanswers', 'mod_emarking'));
     $mform->addHelpButton('digitizedfilepdf', 'digitizedfile', 'mod_emarking');
     // The course module id.
     $mform->addElement('hidden', 'id', $instance['coursemoduleid']);
     $mform->setType('id', PARAM_INT);
     // The activity id.
     $mform->addElement('hidden', 'emarkingid', $instance['emarkingid']);
     $mform->setType('emarkingid', PARAM_INT);
     // File picker for the digitized answers.
     $mform->addElement('filepicker', 'assignment_file', get_string('uploadexamfile', 'mod_emarking'), null, $options);
     $mform->setType('assignment_file', PARAM_FILE);
     $mform->addHelpButton('assignment_file', 'filerequiredpdf', 'mod_emarking');
     $mform->addRule('assignment_file', get_string('filerequiredpdf', 'mod_emarking'), 'required');
     // Header.
     $mform->addElement('static', 'qrprocessing_help', '', $OUTPUT->heading(get_string('usedigitizedzipfile', 'mod_emarking'), 4));
     $mform->setAdvanced('qrprocessing_help');
     // Link to desktop tool.
     $desktoplink = html_writer::link(new moodle_url('/mod/emarking/emarkingdesktop.zip'), get_string('qrprocessing', 'mod_emarking'));
     $mform->addElement('static', 'qrprocessing', '', $desktoplink);
     $mform->setAdvanced('qrprocessing');
     // Action buttons.
     $this->add_action_buttons(true, get_string('processtitle', 'mod_emarking'));
 }
Example #2
0
 function definition()
 {
     global $USER, $CFG, $COURSE;
     $mform =& $this->_form;
     $mform->addElement('text', 'name', get_string('groupname', 'group'), 'maxlength="254" size="50"');
     $mform->addRule('name', get_string('required'), 'required', null, 'client');
     $mform->setType('name', PARAM_MULTILANG);
     $mform->addElement('htmleditor', 'description', get_string('groupdescription', 'group'), array('rows' => '15', 'course' => $COURSE->id, 'cols' => '45'));
     $mform->setType('description', PARAM_RAW);
     $mform->addElement('passwordunmask', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="24"', get_string('enrolmentkey'));
     $mform->setHelpButton('enrolmentkey', array('groupenrolmentkey', get_string('enrolmentkey', 'group')), true);
     $mform->setType('enrolmentkey', PARAM_RAW);
     $maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
     if (!empty($CFG->gdversion) and $maxbytes) {
         $options = array(get_string('no'), get_string('yes'));
         $mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options);
         $this->set_upload_manager(new upload_manager('imagefile', false, false, null, false, 0, true, true, false));
         $mform->addElement('file', 'imagefile', get_string('newpicture', 'group'));
         $mform->setHelpButton('imagefile', array('picture', get_string('helppicture')), true);
     }
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'courseid');
     $mform->setType('courseid', PARAM_INT);
     $this->add_action_buttons();
 }
Example #3
0
 /**
  * Form definition
  */
 public function definition()
 {
     $mform = $this->_form;
     $data = (object) $this->_customdata;
     $mform->addElement('hidden', 'returnurl');
     $mform->setType('returnurl', PARAM_URL);
     $mform->addElement('header', 'cohortfileuploadform', get_string('uploadafile'));
     $filepickeroptions = array();
     $filepickeroptions['filetypes'] = '*';
     $filepickeroptions['maxbytes'] = get_max_upload_file_size();
     $mform->addElement('filepicker', 'cohortfile', get_string('file'), null, $filepickeroptions);
     $choices = csv_import_reader::get_delimiter_list();
     $mform->addElement('select', 'delimiter', get_string('csvdelimiter', 'tool_uploadcourse'), $choices);
     if (array_key_exists('cfg', $choices)) {
         $mform->setDefault('delimiter', 'cfg');
     } else {
         if (get_string('listsep', 'langconfig') == ';') {
             $mform->setDefault('delimiter', 'semicolon');
         } else {
             $mform->setDefault('delimiter', 'comma');
         }
     }
     $mform->addHelpButton('delimiter', 'csvdelimiter', 'tool_uploadcourse');
     $choices = core_text::get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploadcourse'), $choices);
     $mform->setDefault('encoding', 'UTF-8');
     $mform->addHelpButton('encoding', 'encoding', 'tool_uploadcourse');
     $options = $this->get_context_options();
     $mform->addElement('select', 'contextid', get_string('defaultcontext', 'cohort'), $options);
     $this->add_cohort_upload_buttons(true);
     $this->set_data($data);
 }
 /**
  * Called from Moodle to define this form
  *
  * @return void
  */
 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     /*$stringman = get_string_manager();
       $ejsapp_strings = $stringman->load_component_strings('ejsapp', current_language());*/
     // Adding atto_ejsapp settings by adding more fieldsets
     $mform->addElement('header', 'conf_parameters', get_string('jar_file', 'ejsapp'));
     $mform->addElement('hidden', 'class_file', null);
     $mform->setType('class_file', PARAM_TEXT);
     $mform->setDefault('class_file', 'null');
     $mform->addElement('hidden', 'codebase', null);
     $mform->setType('codebase', PARAM_TEXT);
     $mform->setDefault('codebase', 'null');
     $mform->addElement('hidden', 'mainframe', null);
     $mform->setType('mainframe', PARAM_TEXT);
     $mform->setDefault('mainframe', 'null');
     $mform->addElement('hidden', 'is_collaborative', null);
     $mform->setType('is_collaborative', PARAM_TEXT);
     $mform->setDefault('is_collaborative', 0);
     $mform->addElement('hidden', 'manifest', null);
     $mform->setType('manifest', PARAM_TEXT);
     $mform->setDefault('manifest', '');
     $mform->addElement('hidden', 'applet_name', null);
     $mform->setType('applet_name', PARAM_TEXT);
     $mform->setDefault('applet_name', '');
     $maxbytes = get_max_upload_file_size($CFG->maxbytes);
     $mform->addElement('filemanager', 'appletfile', get_string('file'), null, array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => 1, 'accepted_types' => array('application/java-archive', 'application/zip')));
     $mform->addRule('appletfile', get_string('appletfile_required', 'ejsapp'), 'required');
     $mform->addHelpButton('appletfile', 'appletfile', 'ejsapp');
     $mform->addElement('header', 'size_header', get_string('size_header', 'atto_ejsapp'));
     $mform->setExpanded('size_header', false);
     $mform->addElement('select', 'applet_size_conf', get_string('applet_size_conf', 'ejsapp'), array(get_string('preserve_applet_size', 'ejsapp'), get_string('moodle_resize', 'ejsapp'), get_string('user_resize', 'ejsapp')));
     $mform->addHelpButton('applet_size_conf', 'applet_size_conf', 'ejsapp');
     $mform->addElement('selectyesno', 'preserve_aspect_ratio', get_string('preserve_aspect_ratio', 'ejsapp'));
     $mform->addHelpButton('preserve_aspect_ratio', 'preserve_aspect_ratio', 'ejsapp');
     $mform->disabledIf('preserve_aspect_ratio', 'applet_size_conf', 'neq', 2);
     $mform->addElement('text', 'custom_width', get_string('custom_width', 'ejsapp'), array('size' => '3'));
     $mform->setType('custom_width', PARAM_INT);
     $mform->disabledIf('custom_width', 'applet_size_conf', 'neq', 2);
     $mform->addElement('text', 'custom_height', get_string('custom_height', 'ejsapp'), array('size' => '3'));
     $mform->setType('custom_height', PARAM_INT);
     $mform->disabledIf('custom_height', 'applet_size_conf', 'neq', 2);
     $mform->disabledIf('custom_height', 'preserve_aspect_ratio', 'eq', 1);
     $mform->addElement('header', 'state_file', get_string('state_file', 'ejsapp'));
     $mform->setExpanded('state_file', false);
     $mform->addElement('filemanager', 'statefile', get_string('file'), null, array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => 1, 'accepted_types' => array('application/xml', 'application/json')));
     $mform->addHelpButton('statefile', 'statefile', 'ejsapp');
     $mform->addElement('header', 'controller_file', get_string('controller_file', 'ejsapp'));
     $mform->setExpanded('controller_file', false);
     $mform->addElement('filemanager', 'controllerfile', get_string('file'), null, array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => 1, 'accepted_types' => '.cnt'));
     $mform->addHelpButton('controllerfile', 'controllerfile', 'ejsapp');
     $mform->addElement('header', 'recording_file', get_string('recording_file', 'ejsapp'));
     $mform->setExpanded('recording_file', false);
     $mform->addElement('filemanager', 'recordingfile', get_string('file'), null, array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => 1, 'accepted_types' => '.rec'));
     $mform->addHelpButton('recordingfile', 'recordingfile', 'ejsapp');
     $this->add_action_buttons();
 }
Example #5
0
    function MoodleQuickForm_filepicker($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
        global $CFG;

        $options = (array)$options;
        foreach ($options as $name=>$value) {
            if (array_key_exists($name, $this->_options)) {
                $this->_options[$name] = $value;
            }
        }
        if (!empty($options['maxbytes'])) {
            $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
        }
        parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
    }
Example #6
0
 /**
  * Form definition
  */
 function definition()
 {
     $mform =& $this->_form;
     $data = $this->_customdata;
     //fill in the data depending on page params
     //later using set_data
     $mform->addElement('header', 'general');
     $filepickeroptions = array();
     $filepickeroptions['filetypes'] = '*';
     $filepickeroptions['maxbytes'] = get_max_upload_file_size();
     $mform->addElement('filepicker', 'userfile', get_string('import'), null, $filepickeroptions);
     $mform->addElement('hidden', 'id');
     $this->add_action_buttons(true, get_string('importgroups', 'core_group'));
     $this->set_data($data);
 }
 /**
  * Saves the simulation file into the draft area
  * @return boolean
  */
 public function saveSimulationFilesToDraft($CFG, $context, $draftitemid_applet)
 {
     $result = false;
     $this->maxbytes = get_max_upload_file_size($CFG->maxbytes);
     //Obtains the folder number to store the file
     while (file_exists($this->folderpath . $this->incremental)) {
         $this->incremental++;
     }
     //Saves the file in draft area
     if ($draftitemid_applet) {
         file_save_draft_area_files($draftitemid_applet, $context->id, 'atto_ejsapp', 'jarfiles', $this->incremental, array('subdirs' => 0, 'maxbytes' => $this->maxbytes, 'maxfiles' => 1, 'accepted_types' => array('application/java-archive', 'application/zip')));
         $result = true;
     }
     return $result;
 }
Example #8
0
 /**
  * Constructor, sets up configuration stuff so we know how to act.
  *
  * Note: destination not taken as parameter as some modules want to use the insertid in the path and we need to check the other stuff first.
  *
  * @uses $CFG
  * @param string $inputname If this is given the upload manager will only process the file in $_FILES with this name.
  * @param boolean $deleteothers Whether to delete other files in the destination directory (optional, defaults to false)
  * @param boolean $handlecollisions Whether to use {@link handle_filename_collision()} or not. (optional, defaults to false)
  * @param boolean $recoverifmultiple If we come across a virus, or if a file doesn't validate or whatever, do we continue? optional, defaults to true.
  * @param int $maxbytes max bytes for this file {@link get_max_upload_file_size()}.
  * @param boolean $silent Whether to notify errors or not.
  * @param boolean $allownull Whether we care if there's no file when we've set the input name.
  * @param boolean $allownullmultiple Whether we care if there's no files AT ALL  when we've got multiples. This won't complain if we have file 1 and file 3 but not file 2, only for NO FILES AT ALL.
  */
 function upload_manager($inputname = '', $deleteothers = false, $handlecollisions = false, $recoverifmultiple = false, $maxbytes = 0, $silent = false, $allownull = false, $allownullmultiple = true)
 {
     global $CFG;
     $this->config->deleteothers = $deleteothers;
     $this->config->handlecollisions = $handlecollisions;
     $this->config->recoverifmultiple = $recoverifmultiple;
     $this->config->maxbytes = get_max_upload_file_size($maxbytes);
     $this->config->silent = $silent;
     $this->config->allownull = $allownull;
     $this->files = array();
     $this->status = false;
     $this->inputname = $inputname;
     if (empty($this->inputname)) {
         $this->config->allownull = $allownullmultiple;
     }
 }
 function get_content()
 {
     global $PAGE, $CFG, $OUTPUT, $COURSE;
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (!$PAGE->user_is_editing()) {
         return NULL;
     }
     $this->content = new stdClass();
     $this->content->footer = null;
     $this->content->text = '<div id="dndupload-status"><noscript>' . get_string('noscript', 'block_dndupload') . '</noscript></div>';
     $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
     if (!has_capability('moodle/course:managefiles', $context)) {
         $this->content->text = '<div id="dndupload-status">' . get_string('nopermission', 'block_dndupload') . '</div>';
         return $this->content;
     }
     $jsmodule = array('name' => 'block_dndupload', 'fullpath' => new moodle_url('/blocks/dndupload/dndupload.js'), 'strings' => array(array('addhere', 'block_dndupload'), array('addlinkhere', 'block_dndupload'), array('addwebpagehere', 'block_dndupload'), array('dndworking', 'block_dndupload'), array('filetoolarge', 'block_dndupload'), array('nameforlink', 'block_dndupload'), array('nameforwebpage', 'block_dndupload'), array('nofilereader', 'block_dndupload'), array('noajax', 'block_dndupload')));
     $vars = array(sesskey(), $CFG->wwwroot . '/blocks/dndupload', $COURSE->id, $OUTPUT->pix_url('i/ajaxloader') . '', get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes), $OUTPUT->pix_url('t/addfile') . '');
     $PAGE->requires->js_init_call('M.blocks_dndupload.init', $vars, true, $jsmodule);
     return $this->content;
 }
Example #10
0
 /**
  * Constructor, sets up configuration stuff so we know how to act.
  *
  * Note: destination not taken as parameter as some modules want to use the insertid in the path and we need to check the other stuff first.
  *
  * @uses $CFG
  * @param string $inputname If this is given the upload manager will only process the file in $_FILES with this name.
  * @param boolean $deleteothers Whether to delete other files in the destination directory (optional, defaults to false)
  * @param boolean $handlecollisions Whether to use {@link handle_filename_collision()} or not. (optional, defaults to false)
  * @param course $course The course the files are being uploaded for (for logging and virus notifications) {@link $COURSE}
  * @param boolean $recoverifmultiple If we come across a virus, or if a file doesn't validate or whatever, do we continue? optional, defaults to true.
  * @param int $modbytes Max bytes for this module - this and $course->maxbytes are used to get the maxbytes from {@link get_max_upload_file_size()}.
  * @param boolean $silent Whether to notify errors or not.
  * @param boolean $allownull Whether we care if there's no file when we've set the input name.
  * @param boolean $allownullmultiple Whether we care if there's no files AT ALL  when we've got multiples. This won't complain if we have file 1 and file 3 but not file 2, only for NO FILES AT ALL.
  */
 function upload_manager($inputname = '', $deleteothers = false, $handlecollisions = false, $course = null, $recoverifmultiple = false, $modbytes = 0, $silent = false, $allownull = false, $allownullmultiple = true)
 {
     global $CFG, $SITE;
     if (empty($course->id)) {
         $course = $SITE;
     }
     $this->config = new stdClass();
     // instantiate $this->config explicitely
     $this->config->deleteothers = $deleteothers;
     $this->config->handlecollisions = $handlecollisions;
     $this->config->recoverifmultiple = $recoverifmultiple;
     $this->config->maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $modbytes);
     $this->config->silent = $silent;
     $this->config->allownull = $allownull;
     $this->files = array();
     $this->status = false;
     $this->course = $course;
     $this->inputname = $inputname;
     if (empty($this->inputname)) {
         $this->config->allownull = $allownullmultiple;
     }
 }
Example #11
0
 /**
  * Constructor
  *
  * @param string $elementName (optional) name of the filepicker
  * @param string $elementLabel (optional) filepicker label
  * @param array $attributes (optional) Either a typical HTML attribute string
  *              or an associative array
  * @param array $options set of options to initalize filepicker
  */
 function MoodleQuickForm_filepicker($elementName = null, $elementLabel = null, $attributes = null, $options = null)
 {
     global $CFG, $PAGE;
     $options = (array) $options;
     foreach ($options as $name => $value) {
         if (array_key_exists($name, $this->_options)) {
             $this->_options[$name] = $value;
         }
     }
     if (empty($options['return_types'])) {
         $this->_options['return_types'] = FILE_INTERNAL;
     }
     $fpmaxbytes = 0;
     if (!empty($options['maxbytes'])) {
         $fpmaxbytes = $options['maxbytes'];
     }
     $coursemaxbytes = 0;
     if (!empty($PAGE->course)) {
         $coursemaxbytes = $PAGE->course->maxbytes;
     }
     $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $coursemaxbytes, $fpmaxbytes);
     $this->_type = 'filepicker';
     parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
 }
Example #12
0
if ($repository = $DB->get_record_sql($sql, array($repo_id))) {
    $type = $repository->type;
    if (file_exists($CFG->dirroot.'/repository/'.$type.'/lib.php')) {
        require_once($CFG->dirroot.'/repository/'.$type.'/lib.php');
        $classname = 'repository_' . $type;
        try {
            $repo = new $classname($repo_id, $contextid, array('ajax'=>false, 'name'=>$repository->name, 'type'=>$type));
        } catch (repository_exception $e){
            print_error('pluginerror', 'repository');
        }
    } else {
        print_error('invalidplugin', 'repository');
    }
}

$moodle_maxbytes = get_max_upload_file_size();
// to prevent maxbytes greater than moodle maxbytes setting
if ($maxbytes == 0 || $maxbytes>=$moodle_maxbytes) {
    $maxbytes = $moodle_maxbytes;
}

$params = array('ctx_id' => $contextid, 'itemid' => $itemid, 'env' => $env, 'course'=>$courseid, 'maxbytes'=>$maxbytes, 'maxfiles'=>$maxfiles, 'subdirs'=>$subdirs, 'sesskey'=>sesskey());
$params['action'] = 'browse';
$params['draftpath'] = $draftpath;
$home_url = new moodle_url('/repository/draftfiles_manager.php', $params);

$params['savepath'] = $savepath;
$params['repo_id'] = $repo_id;
$url = new moodle_url($CFG->httpswwwroot."/repository/filepicker.php", $params);
$PAGE->set_url('/repository/filepicker.php', $params);
Example #13
0
            throw new moodle_exception('upload_error_no_tmp_dir', 'repository_upload');
            break;
        case UPLOAD_ERR_CANT_WRITE:
            throw new moodle_exception('upload_error_cant_write', 'repository_upload');
            break;
        case UPLOAD_ERR_EXTENSION:
            throw new moodle_exception('upload_error_extension', 'repository_upload');
            break;
        default:
            throw new moodle_exception('nofile');
        }
    }
    $file = new stdClass();
    $file->filename = clean_param($_FILES[$fieldname]['name'], PARAM_FILE);
    // check system maxbytes setting
    if (($_FILES[$fieldname]['size'] > get_max_upload_file_size($CFG->maxbytes))) {
        // oversize file will be ignored, error added to array to notify
        // web service client
        $file->errortype = 'fileoversized';
        $file->error = get_string('maxbytes', 'error');
    } else {
        $file->filepath = $_FILES[$fieldname]['tmp_name'];
        // calculate total size of upload
        $totalsize += $_FILES[$fieldname]['size'];
    }
    $files[] = $file;
}

$fs = get_file_storage();

$usedspace = 0;
        $return = $SESSION->returnpage;
        unset($SESSION->returnpage);
        redirect($return);
    } else {
        redirect(new moodle_url('/mod/referentiel/activite.php', array('id' => $cm->id, 'userid' => $userid, 'activite_id' => $activite_id, 'mailnow' => $mailnow, 'mode' => 'listactivityall', 'filtre_auteur' => $data_filtre->filtre_auteur, 'filtre_validation' => $data_filtre->filtre_validation, 'filtre_referent' => $data_filtre->filtre_referent, 'filtre_date_modif' => $data_filtre->filtre_date_modif, 'filtre_date_modif_student' => $data_filtre->filtre_date_modif_student)));
    }
}
$PAGE->set_url($url);
$PAGE->set_context($context);
$title = strip_tags($course->fullname . ': ' . get_string('modulename', 'referentiel') . ': ' . format_string($referentiel->name, true));
$PAGE->set_title($title);
$PAGE->set_heading($title);
// DEBUG
// echo "<br />upload_Mooddle2.php :: 151 :: activite_id:: $activite_id\n";
// exit;
$options = array('subdirs' => 0, 'maxbytes' => get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $maxbytes), 'maxfiles' => 1, 'accepted_types' => '*', 'return_types' => FILE_INTERNAL);
$mform = new mod_referentiel_upload_form(null, array('d' => $referentiel->id, 'contextid' => $context->id, 'userid' => $USER->id, 'activiteid' => $activite_id, 'filearea' => 'document', 'msg' => get_string('document_associe', 'referentiel'), 'mailnow' => $mailnow, 'options' => $options));
if ($mform->is_cancelled()) {
    redirect(new moodle_url('/mod/referentiel/activite.php', array('id' => $cm->id, 'userid' => $USER->id, 'activite_id' => $activite_id, 'mailnow' => $mailnow, 'mode' => 'listactivityall', 'filtre_auteur' => $data_filtre->filtre_auteur, 'filtre_validation' => $data_filtre->filtre_validation, 'filtre_referent' => $data_filtre->filtre_referent, 'filtre_date_modif' => $data_filtre->filtre_date_modif, 'filtre_date_modif_student' => $data_filtre->filtre_date_modif_student)));
} else {
    if ($mform->get_data()) {
        // A TERMINER
        referentiel_upload_document($mform, $referentiel->id);
        die;
        //    redirect(new moodle_url('/mod/referentiel/view.php', array('id'=>$cm->id)));
    }
}
echo $OUTPUT->header();
echo $OUTPUT->box_start('generalbox');
$mform->display();
echo $OUTPUT->box_end();
 public function test_get_max_upload_sizes()
 {
     // Test with very low limits so we are not affected by php upload limits.
     // Test activity limit smallest.
     $sitebytes = 102400;
     $coursebytes = 51200;
     $modulebytes = 10240;
     $result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes);
     $this->assertSame('Activity upload limit (10KB)', $result['0']);
     $this->assertCount(2, $result);
     // Test course limit smallest.
     $sitebytes = 102400;
     $coursebytes = 10240;
     $modulebytes = 51200;
     $result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes);
     $this->assertSame('Course upload limit (10KB)', $result['0']);
     $this->assertCount(2, $result);
     // Test site limit smallest.
     $sitebytes = 10240;
     $coursebytes = 102400;
     $modulebytes = 51200;
     $result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes);
     $this->assertSame('Site upload limit (10KB)', $result['0']);
     $this->assertCount(2, $result);
     // Test site limit not set.
     $sitebytes = 0;
     $coursebytes = 102400;
     $modulebytes = 51200;
     $result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes);
     $this->assertSame('Activity upload limit (50KB)', $result['0']);
     $this->assertCount(3, $result);
     $sitebytes = 0;
     $coursebytes = 51200;
     $modulebytes = 102400;
     $result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes);
     $this->assertSame('Course upload limit (50KB)', $result['0']);
     $this->assertCount(3, $result);
     // Test custom bytes in range.
     $sitebytes = 102400;
     $coursebytes = 51200;
     $modulebytes = 51200;
     $custombytes = 10240;
     $result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes, $custombytes);
     $this->assertCount(3, $result);
     // Test custom bytes in range but non-standard.
     $sitebytes = 102400;
     $coursebytes = 51200;
     $modulebytes = 51200;
     $custombytes = 25600;
     $result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes, $custombytes);
     $this->assertCount(4, $result);
     // Test custom bytes out of range.
     $sitebytes = 102400;
     $coursebytes = 51200;
     $modulebytes = 51200;
     $custombytes = 102400;
     $result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes, $custombytes);
     $this->assertCount(3, $result);
     // Test custom bytes out of range and non-standard.
     $sitebytes = 102400;
     $coursebytes = 51200;
     $modulebytes = 51200;
     $custombytes = 256000;
     $result = get_max_upload_sizes($sitebytes, $coursebytes, $modulebytes, $custombytes);
     $this->assertCount(3, $result);
     // Test site limit only.
     $sitebytes = 51200;
     $result = get_max_upload_sizes($sitebytes);
     $this->assertSame('Site upload limit (50KB)', $result['0']);
     $this->assertSame('50KB', $result['51200']);
     $this->assertSame('10KB', $result['10240']);
     $this->assertCount(3, $result);
     // Test no limit.
     $result = get_max_upload_sizes();
     $this->assertArrayHasKey('0', $result);
     $this->assertArrayHasKey(get_max_upload_file_size(), $result);
 }
Example #16
0
 function definition()
 {
     global $CFG, $COURSE, $OUTPUT;
     $cfg_scorm = get_config('scorm');
     $mform = $this->_form;
     if (!$CFG->slasharguments) {
         $mform->addElement('static', '', '', $OUTPUT->notification(get_string('slashargs', 'scorm'), 'notifyproblem'));
     }
     $zlib = ini_get('zlib.output_compression');
     //check for zlib compression - if used, throw error because of IE bug. - SEE MDL-16185
     if (isset($zlib) && $zlib) {
         $mform->addElement('static', '', '', $OUTPUT->notification(get_string('zlibwarning', 'scorm'), 'notifyproblem'));
     }
     //-------------------------------------------------------------------------------
     $mform->addElement('header', 'general', get_string('general', 'form'));
     // Name
     $mform->addElement('text', 'name', get_string('name'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_CLEAN);
     }
     $mform->addRule('name', null, 'required', null, 'client');
     // Summary
     $this->add_intro_editor(true);
     // Scorm types
     $options = array(SCORM_TYPE_LOCAL => get_string('typelocal', 'scorm'));
     if ($cfg_scorm->allowtypeexternal) {
         $options[SCORM_TYPE_EXTERNAL] = get_string('typeexternal', 'scorm');
     }
     if ($cfg_scorm->allowtypelocalsync) {
         $options[SCORM_TYPE_LOCALSYNC] = get_string('typelocalsync', 'scorm');
     }
     if (!empty($CFG->repositoryactivate) and $cfg_scorm->allowtypeimsrepository) {
         $options[SCORM_TYPE_IMSREPOSITORY] = get_string('typeimsrepository', 'scorm');
     }
     $mform->addElement('select', 'scormtype', get_string('scormtype', 'scorm'), $options);
     // Reference
     if (count($options) > 1) {
         $mform->addElement('text', 'packageurl', get_string('url', 'scorm'), array('size' => 60));
         $mform->setType('packageurl', PARAM_RAW);
         $mform->setHelpButton('packageurl', array('packagefile', get_string('package', 'scorm'), 'scorm'));
         $mform->disabledIf('packageurl', 'scormtype', 'eq', SCORM_TYPE_LOCAL);
     }
     // New local package upload
     $maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
     $mform->setMaxFileSize($maxbytes);
     $mform->addElement('file', 'packagefile', get_string('package', 'scorm'));
     $mform->disabledIf('packagefile', 'scormtype', 'noteq', SCORM_TYPE_LOCAL);
     //-------------------------------------------------------------------------------
     // Time restrictions
     $mform->addElement('header', 'timerestricthdr', get_string('timerestrict', 'scorm'));
     $mform->addElement('checkbox', 'timerestrict', get_string('timerestrict', 'scorm'));
     $mform->setHelpButton('timerestrict', array("timerestrict", get_string("timerestrict", "scorm"), "scorm"));
     $mform->addElement('date_time_selector', 'timeopen', get_string("scormopen", "scorm"));
     $mform->disabledIf('timeopen', 'timerestrict');
     $mform->addElement('date_time_selector', 'timeclose', get_string("scormclose", "scorm"));
     $mform->disabledIf('timeclose', 'timerestrict');
     //-------------------------------------------------------------------------------
     // Other Settings
     $mform->addElement('header', 'advanced', get_string('othersettings', 'form'));
     // Grade Method
     $mform->addElement('select', 'grademethod', get_string('grademethod', 'scorm'), scorm_get_grade_method_array());
     $mform->setHelpButton('grademethod', array('grademethod', get_string('grademethod', 'scorm'), 'scorm'));
     $mform->setDefault('grademethod', $cfg_scorm->grademethod);
     // Maximum Grade
     for ($i = 0; $i <= 100; $i++) {
         $grades[$i] = "{$i}";
     }
     $mform->addElement('select', 'maxgrade', get_string('maximumgrade'), $grades);
     $mform->setDefault('maxgrade', $cfg_scorm->maxgrade);
     $mform->disabledIf('maxgrade', 'grademethod', 'eq', GRADESCOES);
     // Attempts
     $mform->addElement('static', '', '', '<hr />');
     // Max Attempts
     $mform->addElement('select', 'maxattempt', get_string('maximumattempts', 'scorm'), scorm_get_attempts_array());
     $mform->setHelpButton('maxattempt', array('maxattempt', get_string('maximumattempts', 'scorm'), 'scorm'));
     $mform->setDefault('maxattempt', $cfg_scorm->maxattempts);
     // Display attempt status
     $mform->addElement('selectyesno', 'displayattemptstatus', get_string('displayattemptstatus', 'scorm'));
     $mform->setHelpButton('displayattemptstatus', array('displayattemptstatus', get_string('displayattemptstatus', 'scorm'), 'scorm'));
     $mform->setDefault('displayattemptstatus', $cfg_scorm->displayattemptstatus);
     // Display course structure
     $mform->addElement('selectyesno', 'displaycoursestructure', get_string('displaycoursestructure', 'scorm'));
     $mform->setHelpButton('displaycoursestructure', array('displaycoursestructure', get_string('displaycoursestructure', 'scorm'), 'scorm'));
     $mform->setDefault('displaycoursestructure', $cfg_scorm->displaycoursestructure);
     // Force completed
     $mform->addElement('selectyesno', 'forcecompleted', get_string('forcecompleted', 'scorm'));
     $mform->setHelpButton('forcecompleted', array('forcecompleted', get_string('forcecompleted', 'scorm'), 'scorm'));
     $mform->setDefault('forcecompleted', $cfg_scorm->forcecompleted);
     $mform->setAdvanced('forcecompleted');
     // Force new attempt
     $mform->addElement('selectyesno', 'forcenewattempt', get_string('forcenewattempt', 'scorm'));
     $mform->setHelpButton('forcenewattempt', array('forcenewattempt', get_string('forcenewattempt', 'scorm'), 'scorm'));
     $mform->setDefault('forcenewattempt', $cfg_scorm->forcenewattempt);
     $mform->setAdvanced('forcenewattempt');
     // Last attempt lock - lock the enter button after the last available attempt has been made
     $mform->addElement('selectyesno', 'lastattemptlock', get_string('lastattemptlock', 'scorm'));
     $mform->setHelpButton('lastattemptlock', array('lastattemptlock', get_string('lastattemptlock', 'scorm'), 'scorm'));
     $mform->setDefault('lastattemptlock', $cfg_scorm->lastattemptlock);
     $mform->setAdvanced('lastattemptlock');
     // What Grade
     $mform->addElement('select', 'whatgrade', get_string('whatgrade', 'scorm'), scorm_get_what_grade_array());
     $mform->disabledIf('whatgrade', 'maxattempt', 'eq', 1);
     $mform->setHelpButton('whatgrade', array('whatgrade', get_string('whatgrade', 'scorm'), 'scorm'));
     $mform->setDefault('whatgrade', $cfg_scorm->whatgrade);
     $mform->setAdvanced('whatgrade');
     // Activation period
     /*        $mform->addElement('static', '', '' ,'<hr />');
             $mform->addElement('static', 'activation', get_string('activation','scorm'));
             $datestartgrp = array();
             $datestartgrp[] = &$mform->createElement('date_time_selector', 'startdate');
             $datestartgrp[] = &$mform->createElement('checkbox', 'startdisabled', null, get_string('disable'));
             $mform->addGroup($datestartgrp, 'startdategrp', get_string('from'), ' ', false);
             $mform->setDefault('startdate', 0);
             $mform->setDefault('startdisabled', 1);
             $mform->disabledIf('startdategrp', 'startdisabled', 'checked');
     
             $dateendgrp = array();
             $dateendgrp[] = &$mform->createElement('date_time_selector', 'enddate');
             $dateendgrp[] = &$mform->createElement('checkbox', 'enddisabled', null, get_string('disable'));
             $mform->addGroup($dateendgrp, 'dateendgrp', get_string('to'), ' ', false);
             $mform->setDefault('enddate', 0);
             $mform->setDefault('enddisabled', 1);
             $mform->disabledIf('dateendgrp', 'enddisabled', 'checked');
     */
     // Stage Size
     $mform->addElement('static', '', '', '<hr />');
     $mform->addElement('static', 'stagesize', get_string('stagesize', 'scorm'));
     $mform->setHelpButton('stagesize', array('stagesize', get_string('stagesize', 'scorm'), 'scorm'));
     // Width
     $mform->addElement('text', 'width', get_string('width', 'scorm'), 'maxlength="5" size="5"');
     $mform->setDefault('width', $cfg_scorm->framewidth);
     $mform->setType('width', PARAM_INT);
     // Height
     $mform->addElement('text', 'height', get_string('height', 'scorm'), 'maxlength="5" size="5"');
     $mform->setDefault('height', $cfg_scorm->frameheight);
     $mform->setType('height', PARAM_INT);
     // Framed / Popup Window
     $mform->addElement('select', 'popup', get_string('display', 'scorm'), scorm_get_popup_display_array());
     $mform->setDefault('popup', $cfg_scorm->popup);
     $mform->setAdvanced('popup');
     // Window Options
     $winoptgrp = array();
     foreach (scorm_get_popup_options_array() as $key => $value) {
         $winoptgrp[] =& $mform->createElement('checkbox', $key, '', get_string($key, 'scorm'));
         $mform->setDefault($key, $value);
     }
     $mform->addGroup($winoptgrp, 'winoptgrp', get_string('options', 'scorm'), '<br />', false);
     $mform->setAdvanced('winoptgrp');
     $mform->disabledIf('winoptgrp', 'popup', 'eq', 0);
     // Skip view page
     $mform->addElement('select', 'skipview', get_string('skipview', 'scorm'), scorm_get_skip_view_array());
     $mform->setHelpButton('skipview', array('skipview', get_string('skipview', 'scorm'), 'scorm'));
     $mform->setDefault('skipview', $cfg_scorm->skipview);
     $mform->setAdvanced('skipview');
     // Hide Browse
     $mform->addElement('selectyesno', 'hidebrowse', get_string('hidebrowse', 'scorm'));
     $mform->setHelpButton('hidebrowse', array('hidebrowse', get_string('hidebrowse', 'scorm'), 'scorm'));
     $mform->setDefault('hidebrowse', $cfg_scorm->hidebrowse);
     $mform->setAdvanced('hidebrowse');
     // Toc display
     $mform->addElement('select', 'hidetoc', get_string('hidetoc', 'scorm'), scorm_get_hidetoc_array());
     $mform->setDefault('hidetoc', $cfg_scorm->hidetoc);
     $mform->setAdvanced('hidetoc');
     // Hide Navigation panel
     $mform->addElement('selectyesno', 'hidenav', get_string('hidenav', 'scorm'));
     $mform->setDefault('hidenav', $cfg_scorm->hidenav);
     $mform->setAdvanced('hidenav');
     // Autocontinue
     $mform->addElement('selectyesno', 'auto', get_string('autocontinue', 'scorm'));
     $mform->setHelpButton('auto', array('autocontinue', get_string('autocontinue', 'scorm'), 'scorm'));
     $mform->setDefault('auto', $cfg_scorm->auto);
     $mform->setAdvanced('auto');
     // Update packages timing
     $mform->addElement('select', 'updatefreq', get_string('updatefreq', 'scorm'), scorm_get_updatefreq_array());
     $mform->setDefault('updatefreq', $cfg_scorm->updatefreq);
     $mform->setAdvanced('updatefreq');
     //-------------------------------------------------------------------------------
     // Hidden Settings
     $mform->addElement('hidden', 'datadir', null);
     $mform->addElement('hidden', 'pkgtype', null);
     $mform->addElement('hidden', 'launch', null);
     $mform->addElement('hidden', 'redirect', null);
     $mform->addElement('hidden', 'redirecturl', null);
     //-------------------------------------------------------------------------------
     $this->standard_coursemodule_elements();
     //-------------------------------------------------------------------------------
     // buttons
     $this->add_action_buttons();
 }
Example #17
0
    /**
     * Internal implementation of file picker rendering.
     *
     * @param file_picker $fp
     * @return string
     */
    public function render_file_picker(file_picker $fp) {
        global $CFG, $OUTPUT, $USER;
        $options = $fp->options;
        $client_id = $options->client_id;
        $strsaved = get_string('filesaved', 'repository');
        $straddfile = get_string('openpicker', 'repository');
        $strloading  = get_string('loading', 'repository');
        $strdndenabled = get_string('dndenabled_inbox', 'moodle');
        $strdroptoupload = get_string('droptoupload', 'moodle');
        $icon_progress = $OUTPUT->pix_icon('i/loading_small', $strloading).'';

        $currentfile = $options->currentfile;
        if (empty($currentfile)) {
            $currentfile = '';
        } else {
            $currentfile .= ' - ';
        }
        if ($options->maxbytes) {
            $size = $options->maxbytes;
        } else {
            $size = get_max_upload_file_size();
        }
        if ($size == -1) {
            $maxsize = '';
        } else {
            $maxsize = get_string('maxfilesize', 'moodle', display_size($size));
        }
        if ($options->buttonname) {
            $buttonname = ' name="' . $options->buttonname . '"';
        } else {
            $buttonname = '';
        }
        $html = <<<EOD
<div class="filemanager-loading mdl-align" id='filepicker-loading-{$client_id}'>
$icon_progress
</div>
<div id="filepicker-wrapper-{$client_id}" class="mdl-left" style="display:none">
    <div>
        <input type="button" class="fp-btn-choose" id="filepicker-button-{$client_id}" value="{$straddfile}"{$buttonname}/>
        <span> $maxsize </span>
    </div>
EOD;
        if ($options->env != 'url') {
            $html .= <<<EOD
    <div id="file_info_{$client_id}" class="mdl-left filepicker-filelist" style="position: relative">
    <div class="filepicker-filename">
        <div class="filepicker-container">$currentfile<div class="dndupload-message">$strdndenabled <br/><div class="dndupload-arrow"></div></div></div>
        <div class="dndupload-progressbars"></div>
    </div>
    <div><div class="dndupload-target">{$strdroptoupload}<br/><div class="dndupload-arrow"></div></div></div>
    </div>
EOD;
        }
        $html .= '</div>';
        return $html;
    }
Example #18
0
 /**
  * Handle uploads containing files - create the course module, ask the upload repository
  * to process the file, ask the mod to set itself up, then return the result to the browser
  */
 protected function handle_file_upload()
 {
     global $CFG;
     // Add the file to a draft file area.
     $draftitemid = file_get_unused_draft_itemid();
     $maxbytes = get_max_upload_file_size($CFG->maxbytes, $this->course->maxbytes);
     $types = $this->dnduploadhandler->get_handled_file_types($this->module->name);
     $repo = repository::get_instances(array('type' => 'upload'));
     if (empty($repo)) {
         throw new moodle_exception('errornouploadrepo', 'moodle');
     }
     $repo = reset($repo);
     // Get the first (and only) upload repo.
     $details = $repo->process_upload(null, $maxbytes, $types, '/', $draftitemid);
     if (empty($this->displayname)) {
         $this->displayname = $this->display_name_from_file($details['file']);
     }
     // Create a course module to hold the new instance.
     $this->create_course_module();
     // Ask the module to set itself up.
     $moduledata = $this->prepare_module_data($draftitemid);
     $instanceid = plugin_callback('mod', $this->module->name, 'dndupload', 'handle', array($moduledata), 'invalidfunction');
     if ($instanceid === 'invalidfunction') {
         throw new coding_exception("{$this->module->name} does not support drag and drop upload (missing {$this->module->name}_dndupload_handle function");
     }
     // Finish setting up the course module.
     $this->finish_setup_course_module($instanceid);
 }
Example #19
0
/**
 * Returns an array of possible sizes in local language
 *
 * Related to {@link get_max_upload_file_size()} - this function returns an
 * array of possible sizes in an array, translated to the
 * local language.
 *
 * The list of options will go up to the minimum of $sitebytes, $coursebytes or $modulebytes.
 *
 * If $coursebytes or $sitebytes is not 0, an option will be included for "Course/Site upload limit (X)"
 * with the value set to 0. This option will be the first in the list.
 *
 * @uses SORT_NUMERIC
 * @param int $sitebytes Set maximum size
 * @param int $coursebytes Current course $course->maxbytes (in bytes)
 * @param int $modulebytes Current module ->maxbytes (in bytes)
 * @param int|array $custombytes custom upload size/s which will be added to list,
 *        Only value/s smaller then maxsize will be added to list.
 * @return array
 */
function get_max_upload_sizes($sitebytes = 0, $coursebytes = 0, $modulebytes = 0, $custombytes = null)
{
    global $CFG;
    if (!($maxsize = get_max_upload_file_size($sitebytes, $coursebytes, $modulebytes))) {
        return array();
    }
    if ($sitebytes == 0) {
        // Will get the minimum of upload_max_filesize or post_max_size.
        $sitebytes = get_max_upload_file_size();
    }
    $filesize = array();
    $sizelist = array(10240, 51200, 102400, 512000, 1048576, 2097152, 5242880, 10485760, 20971520, 52428800, 104857600);
    // If custombytes is given and is valid then add it to the list.
    if (is_number($custombytes) and $custombytes > 0) {
        $custombytes = (int) $custombytes;
        if (!in_array($custombytes, $sizelist)) {
            $sizelist[] = $custombytes;
        }
    } else {
        if (is_array($custombytes)) {
            $sizelist = array_unique(array_merge($sizelist, $custombytes));
        }
    }
    // Allow maxbytes to be selected if it falls outside the above boundaries.
    if (isset($CFG->maxbytes) && !in_array(get_real_size($CFG->maxbytes), $sizelist)) {
        // Note: get_real_size() is used in order to prevent problems with invalid values.
        $sizelist[] = get_real_size($CFG->maxbytes);
    }
    foreach ($sizelist as $sizebytes) {
        if ($sizebytes < $maxsize && $sizebytes > 0) {
            $filesize[(string) intval($sizebytes)] = display_size($sizebytes);
        }
    }
    $limitlevel = '';
    $displaysize = '';
    if ($modulebytes && (($modulebytes < $coursebytes || $coursebytes == 0) && ($modulebytes < $sitebytes || $sitebytes == 0))) {
        $limitlevel = get_string('activity', 'core');
        $displaysize = display_size($modulebytes);
        $filesize[$modulebytes] = $displaysize;
        // Make sure the limit is also included in the list.
    } else {
        if ($coursebytes && ($coursebytes < $sitebytes || $sitebytes == 0)) {
            $limitlevel = get_string('course', 'core');
            $displaysize = display_size($coursebytes);
            $filesize[$coursebytes] = $displaysize;
            // Make sure the limit is also included in the list.
        } else {
            if ($sitebytes) {
                $limitlevel = get_string('site', 'core');
                $displaysize = display_size($sitebytes);
                $filesize[$sitebytes] = $displaysize;
                // Make sure the limit is also included in the list.
            }
        }
    }
    krsort($filesize, SORT_NUMERIC);
    if ($limitlevel) {
        $params = (object) array('contextname' => $limitlevel, 'displaysize' => $displaysize);
        $filesize = array('0' => get_string('uploadlimitwithsize', 'core', $params)) + $filesize;
    }
    return $filesize;
}
Example #20
0
/**
 * Returns an array of possible sizes in local language
 *
 * Related to {@link get_max_upload_file_size()} - this function returns an
 * array of possible sizes in an array, translated to the
 * local language.
 *
 * @todo Finish documenting this function
 *
 * @global object
 * @uses SORT_NUMERIC
 * @param int $sizebytes Set maximum size
 * @param int $coursebytes Current course $course->maxbytes (in bytes)
 * @param int $modulebytes Current module ->maxbytes (in bytes)
 * @return array
 */
function get_max_upload_sizes($sitebytes = 0, $coursebytes = 0, $modulebytes = 0)
{
    global $CFG;
    if (!($maxsize = get_max_upload_file_size($sitebytes, $coursebytes, $modulebytes))) {
        return array();
    }
    $filesize[intval($maxsize)] = display_size($maxsize);
    $sizelist = array(10240, 51200, 102400, 512000, 1048576, 2097152, 5242880, 10485760, 20971520, 52428800, 104857600);
    // Allow maxbytes to be selected if it falls outside the above boundaries
    if (isset($CFG->maxbytes) && !in_array(get_real_size($CFG->maxbytes), $sizelist)) {
        // note: get_real_size() is used in order to prevent problems with invalid values
        $sizelist[] = get_real_size($CFG->maxbytes);
    }
    foreach ($sizelist as $sizebytes) {
        if ($sizebytes < $maxsize) {
            $filesize[intval($sizebytes)] = display_size($sizebytes);
        }
    }
    krsort($filesize, SORT_NUMERIC);
    return $filesize;
}
function useredit_shared_definition(&$mform, $editoroptions = null)
{
    global $CFG, $USER, $DB;
    $user = $DB->get_record('user', array('id' => $USER->id));
    useredit_load_preferences($user, false);
    $strrequired = get_string('required');
    $nameordercheck = new stdClass();
    $nameordercheck->firstname = 'a';
    $nameordercheck->lastname = 'b';
    if (fullname($nameordercheck) == 'b a') {
        // See MDL-4325
        $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
        $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
    } else {
        $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
        $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
    }
    $mform->addRule('firstname', $strrequired, 'required', null, 'client');
    $mform->setType('firstname', PARAM_NOTAGS);
    $mform->addRule('lastname', $strrequired, 'required', null, 'client');
    $mform->setType('lastname', PARAM_NOTAGS);
    // Do not show email field if change confirmation is pending
    if (!empty($CFG->emailchangeconfirmation) and !empty($user->preference_newemail)) {
        $notice = get_string('emailchangepending', 'auth', $user);
        $notice .= '<br /><a href="edit.php?cancelemailchange=1&amp;id=' . $user->id . '">' . get_string('emailchangecancel', 'auth') . '</a>';
        $mform->addElement('static', 'emailpending', get_string('email'), $notice);
    } else {
        $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="30"');
        $mform->addRule('email', $strrequired, 'required', null, 'client');
    }
    $choices = array();
    $choices['0'] = get_string('emaildisplayno');
    $choices['1'] = get_string('emaildisplayyes');
    $choices['2'] = get_string('emaildisplaycourse');
    $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
    $mform->setDefault('maildisplay', 2);
    $choices = array();
    $choices['0'] = get_string('textformat');
    $choices['1'] = get_string('htmlformat');
    $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
    $mform->setDefault('mailformat', 1);
    if (!empty($CFG->allowusermailcharset)) {
        $choices = array();
        $charsets = get_list_of_charsets();
        if (!empty($CFG->sitemailcharset)) {
            $choices['0'] = get_string('site') . ' (' . $CFG->sitemailcharset . ')';
        } else {
            $choices['0'] = get_string('site') . ' (UTF-8)';
        }
        $choices = array_merge($choices, $charsets);
        $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
    }
    $choices = array();
    $choices['0'] = get_string('emaildigestoff');
    $choices['1'] = get_string('emaildigestcomplete');
    $choices['2'] = get_string('emaildigestsubjects');
    $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
    $mform->setDefault('maildigest', 0);
    $choices = array();
    $choices['1'] = get_string('autosubscribeyes');
    $choices['0'] = get_string('autosubscribeno');
    $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
    $mform->setDefault('autosubscribe', 1);
    if (!empty($CFG->forum_trackreadposts)) {
        $choices = array();
        $choices['0'] = get_string('trackforumsno');
        $choices['1'] = get_string('trackforumsyes');
        $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
        $mform->setDefault('trackforums', 0);
    }
    $editors = editors_get_enabled();
    if (count($editors) > 1) {
        $choices = array();
        $choices['0'] = get_string('texteditor');
        $choices['1'] = get_string('htmleditor');
        $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices);
        $mform->setDefault('htmleditor', 1);
    } else {
        $mform->addElement('hidden', 'htmleditor');
        $mform->setDefault('htmleditor', 1);
        $mform->setType('htmleditor', PARAM_INT);
    }
    if (empty($CFG->enableajax)) {
        $mform->addElement('static', 'ajaxdisabled', get_string('ajaxuse'), get_string('ajaxno'));
    } else {
        $choices = array();
        $choices['0'] = get_string('ajaxno');
        $choices['1'] = get_string('ajaxyes');
        $mform->addElement('select', 'ajax', get_string('ajaxuse'), $choices);
        $mform->setDefault('ajax', 0);
    }
    $choices = array();
    $choices['0'] = get_string('screenreaderno');
    $choices['1'] = get_string('screenreaderyes');
    $mform->addElement('select', 'screenreader', get_string('screenreaderuse'), $choices);
    $mform->setDefault('screenreader', 0);
    $mform->addHelpButton('screenreader', 'screenreaderuse');
    $mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="21"');
    $mform->setType('city', PARAM_MULTILANG);
    $mform->addRule('city', $strrequired, 'required', null, 'client');
    if (!empty($CFG->defaultcity)) {
        $mform->setDefault('city', $CFG->defaultcity);
    }
    $choices = get_string_manager()->get_list_of_countries();
    $choices = array('' => get_string('selectacountry') . '...') + $choices;
    $mform->addElement('select', 'country', get_string('selectacountry'), $choices);
    $mform->addRule('country', $strrequired, 'required', null, 'client');
    if (!empty($CFG->country)) {
        $mform->setDefault('country', $CFG->country);
    }
    $choices = get_list_of_timezones();
    $choices['99'] = get_string('serverlocaltime');
    if ($CFG->forcetimezone != 99) {
        $mform->addElement('static', 'forcedtimezone', get_string('timezone'), $choices[$CFG->forcetimezone]);
    } else {
        $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
        $mform->setDefault('timezone', '99');
    }
    $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
    $mform->setDefault('lang', $CFG->lang);
    if (!empty($CFG->allowuserthemes)) {
        $choices = array();
        $choices[''] = get_string('default');
        $themes = get_list_of_themes();
        foreach ($themes as $key => $theme) {
            if (empty($theme->hidefromselector)) {
                $choices[$key] = $theme->name;
            }
        }
        $mform->addElement('select', 'theme', get_string('preferredtheme'), $choices);
    }
    $mform->addElement('editor', 'description_editor', get_string('userdescription'), null, $editoroptions);
    $mform->setType('description_editor', PARAM_CLEANHTML);
    $mform->addHelpButton('description_editor', 'userdescription');
    if (!empty($CFG->gdversion) and empty($USER->newadminuser)) {
        $mform->addElement('header', 'moodle_picture', get_string('pictureofuser'));
        $mform->addElement('static', 'currentpicture', get_string('currentpicture'));
        $mform->addElement('checkbox', 'deletepicture', get_string('delete'));
        $mform->setDefault('deletepicture', 0);
        $mform->addElement('filepicker', 'imagefile', get_string('newpicture'), '', array('maxbytes' => get_max_upload_file_size($CFG->maxbytes)));
        $mform->addHelpButton('imagefile', 'newpicture');
        $mform->addElement('text', 'imagealt', get_string('imagealt'), 'maxlength="100" size="30"');
        $mform->setType('imagealt', PARAM_MULTILANG);
    }
    if (!empty($CFG->usetags) and empty($USER->newadminuser)) {
        $mform->addElement('header', 'moodle_interests', get_string('interests'));
        $mform->addElement('tags', 'interests', get_string('interestslist'), array('display' => 'noofficial'));
        $mform->addHelpButton('interests', 'interestslist');
    }
    /// Moodle optional fields
    $mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
    $mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
    $mform->setType('url', PARAM_URL);
    $mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
    $mform->setType('icq', PARAM_NOTAGS);
    $mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
    $mform->setType('skype', PARAM_NOTAGS);
    $mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
    $mform->setType('aim', PARAM_NOTAGS);
    $mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
    $mform->setType('yahoo', PARAM_NOTAGS);
    $mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
    $mform->setType('msn', PARAM_NOTAGS);
    $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="255" size="25"');
    $mform->setType('idnumber', PARAM_NOTAGS);
    $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
    $mform->setType('institution', PARAM_MULTILANG);
    $mform->addElement('text', 'department', get_string('department'), 'maxlength="30" size="25"');
    $mform->setType('department', PARAM_MULTILANG);
    $mform->addElement('text', 'phone1', get_string('phone'), 'maxlength="20" size="25"');
    $mform->setType('phone1', PARAM_NOTAGS);
    $mform->addElement('text', 'phone2', get_string('phone2'), 'maxlength="20" size="25"');
    $mform->setType('phone2', PARAM_NOTAGS);
    $mform->addElement('text', 'address', get_string('address'), 'maxlength="70" size="25"');
    $mform->setType('address', PARAM_MULTILANG);
}
Example #22
0
/**
 * Related to {@link get_max_upload_file_size()} - this function returns an
 * array of possible sizes in an array, translated to the
 * local language.
 *
 * @uses SORT_NUMERIC
 * @param int $sizebytes ?
 * @param int $coursebytes Current course $course->maxbytes (in bytes)
 * @param int $modulebytes Current module ->maxbytes (in bytes)
 * @return int
 * @todo Finish documenting this function
 */
function get_max_upload_sizes($sitebytes = 0, $coursebytes = 0, $modulebytes = 0)
{
    global $CFG;
    if (!($maxsize = get_max_upload_file_size($sitebytes, $coursebytes, $modulebytes))) {
        return array();
    }
    $filesize[$maxsize] = display_size($maxsize);
    $sizelist = array(10240, 51200, 102400, 512000, 1048576, 2097152, 5242880, 10485760, 20971520, 52428800, 104857600);
    // Allow maxbytes to be selected if it falls outside the above boundaries
    if (isset($CFG->maxbytes) && !in_array($CFG->maxbytes, $sizelist)) {
        $sizelist[] = $CFG->maxbytes;
    }
    foreach ($sizelist as $sizebytes) {
        if ($sizebytes < $maxsize) {
            $filesize[$sizebytes] = display_size($sizebytes);
        }
    }
    krsort($filesize, SORT_NUMERIC);
    return $filesize;
}
Example #23
0
    $wdir = '/';
}
switch ($action) {
    case "upload":
        html_header($course, $wdir);
        require_once $CFG->dirroot . '/lib/uploadlib.php';
        if ($save and confirm_sesskey()) {
            $um = new upload_manager('userfile', false, false, $course, false, 0);
            $dir = "{$basedir}{$wdir}";
            if ($um->process_file_uploads($dir)) {
                notify(get_string('uploadedfile'));
            }
            // um will take care of error reporting.
            displaydir($wdir);
        } else {
            $upload_max_filesize = get_max_upload_file_size($CFG->maxbytes);
            $filesize = display_size($upload_max_filesize);
            $struploadafile = get_string("uploadafile");
            $struploadthisfile = get_string("uploadthisfile");
            $strmaxsize = get_string("maxsize", "", $filesize);
            $strcancel = get_string("cancel");
            echo "<p>{$struploadafile} ({$strmaxsize}) --> <strong>{$wdir}</strong>";
            echo "<table border=\"0\"><tr><td colspan=\"2\">\n";
            echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"coursefiles.php\">\n";
            upload_print_form_fragment(1, array('userfile'), null, false, null, $course->maxbytes, 0, false);
            echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />\n";
            echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />\n";
            echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />\n";
            echo " <input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />\n";
            echo " </td><tr><td align=\"right\">";
            echo " <input type=\"submit\" name=\"save\" value=\"{$struploadthisfile}\" />\n";
Example #24
0
 /**
  * Options for displaying the guide description field in the form
  *
  * @param context $context
  * @return array options for the form description field
  */
 public static function description_form_field_options($context)
 {
     global $CFG;
     return array('maxfiles' => -1, 'maxbytes' => get_max_upload_file_size($CFG->maxbytes), 'context' => $context);
 }
Example #25
0
    /**
     * Update courses
     *
     * @param array $courses
     * @since Moodle 2.5
     */
    public static function update_courses($courses) {
        global $CFG, $DB;
        require_once($CFG->dirroot . "/course/lib.php");
        $warnings = array();

        $params = self::validate_parameters(self::update_courses_parameters(),
                        array('courses' => $courses));

        $availablethemes = core_component::get_plugin_list('theme');
        $availablelangs = get_string_manager()->get_list_of_translations();

        foreach ($params['courses'] as $course) {
            // Catch any exception while updating course and return as warning to user.
            try {
                // Ensure the current user is allowed to run this function.
                $context = context_course::instance($course['id'], MUST_EXIST);
                self::validate_context($context);

                $oldcourse = course_get_format($course['id'])->get_course();

                require_capability('moodle/course:update', $context);

                // Check if user can change category.
                if (array_key_exists('categoryid', $course) && ($oldcourse->category != $course['categoryid'])) {
                    require_capability('moodle/course:changecategory', $context);
                    $course['category'] = $course['categoryid'];
                }

                // Check if the user can change fullname.
                if (array_key_exists('fullname', $course) && ($oldcourse->fullname != $course['fullname'])) {
                    require_capability('moodle/course:changefullname', $context);
                }

                // Check if the user can change shortname.
                if (array_key_exists('shortname', $course) && ($oldcourse->shortname != $course['shortname'])) {
                    require_capability('moodle/course:changeshortname', $context);
                }

                // Check if the user can change the idnumber.
                if (array_key_exists('idnumber', $course) && ($oldcourse->idnumber != $course['idnumber'])) {
                    require_capability('moodle/course:changeidnumber', $context);
                }

                // Check if user can change summary.
                if (array_key_exists('summary', $course) && ($oldcourse->summary != $course['summary'])) {
                    require_capability('moodle/course:changesummary', $context);
                }

                // Summary format.
                if (array_key_exists('summaryformat', $course) && ($oldcourse->summaryformat != $course['summaryformat'])) {
                    require_capability('moodle/course:changesummary', $context);
                    $course['summaryformat'] = external_validate_format($course['summaryformat']);
                }

                // Check if user can change visibility.
                if (array_key_exists('visible', $course) && ($oldcourse->visible != $course['visible'])) {
                    require_capability('moodle/course:visibility', $context);
                }

                // Make sure lang is valid.
                if (array_key_exists('lang', $course) && empty($availablelangs[$course['lang']])) {
                    throw new moodle_exception('errorinvalidparam', 'webservice', '', 'lang');
                }

                // Make sure theme is valid.
                if (array_key_exists('forcetheme', $course)) {
                    if (!empty($CFG->allowcoursethemes)) {
                        if (empty($availablethemes[$course['forcetheme']])) {
                            throw new moodle_exception('errorinvalidparam', 'webservice', '', 'forcetheme');
                        } else {
                            $course['theme'] = $course['forcetheme'];
                        }
                    }
                }

                // Make sure completion is enabled before setting it.
                if (array_key_exists('enabledcompletion', $course) && !completion_info::is_enabled_for_site()) {
                    $course['enabledcompletion'] = 0;
                }

                // Make sure maxbytes are less then CFG->maxbytes.
                if (array_key_exists('maxbytes', $course)) {
                    $course['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $course['maxbytes']);
                }

                if (!empty($course['courseformatoptions'])) {
                    foreach ($course['courseformatoptions'] as $option) {
                        if (isset($option['name']) && isset($option['value'])) {
                            $course[$option['name']] = $option['value'];
                        }
                    }
                }

                // Update course if user has all required capabilities.
                update_course((object) $course);
            } catch (Exception $e) {
                $warning = array();
                $warning['item'] = 'course';
                $warning['itemid'] = $course['id'];
                if ($e instanceof moodle_exception) {
                    $warning['warningcode'] = $e->errorcode;
                } else {
                    $warning['warningcode'] = $e->getCode();
                }
                $warning['message'] = $e->getMessage();
                $warnings[] = $warning;
            }
        }

        $result = array();
        $result['warnings'] = $warnings;
        return $result;
    }
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');
}
<tr><td>teacher</td><td>String(100)</td></tr>
<tr><td>teachers</td><td>String(100)</td></tr>
<tr><td>teacher[1,2,...]_account</td><td>Search String that returns only one User Account (as used in <a href="user.php" target="_blank">Administration &raquo; Edit user accounts</a> OR Integer Database User ID</td></tr>
<tr><td>teacher[1,2,...]_role</td><td>String(40)</td></tr>
<tr><td>template</td><td>String</td></tr>
<tr><td>theme</td><td>String(50)</td></tr>
<tr><td>timecreated</td><td>String Date Literal</td></tr>
<tr><td>timemodified</td><td>String Date Literal</td></tr>
<tr><td>topic0 [main heading], topic1 ... topic52 [topic/week headings]</td><td>Text</td></tr>
<tr><td>visible</td><td>0=FALSE,1=TRUE</td></tr>
</table></center>
<?php 
}
/// Print the form
print_heading('Upload Courses');
$maxuploadsize = get_max_upload_file_size();
echo '<center>';
echo '<form method="post" enctype="multipart/form-data" action="uploadcourse.php">' . $strchoose . ':<input type="hidden" name="MAX_FILE_SIZE" value="' . $maxuploadsize . '">' . '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '">' . '<input type="file" name="coursefile" size="30">' . '<input type="submit" value="Upload">' . '</form></br>';
echo '</center>';
print_footer($course);
function my_file_get_contents($filename, $use_include_path = 0)
{
    /// Returns the file as one big long string
    $data = "";
    $file = @fopen($filename, "rb", $use_include_path);
    if ($file) {
        while (!feof($file)) {
            $data .= fread($file, 1024);
        }
        fclose($file);
    }
Example #28
0
 include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/feature/imgresize_gd.php";
 include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/moodle/moodle_highlight.php";
 include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/moodle/f_fixhtml.php";
 #include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/moodle/wikinews.php");
 include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/moodle/sitemap.php";
 include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/moodle/moodle_wikidump.php";
 include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/aview/backlinks.php";
 #include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/markup/css.php");
 include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/markup/footnotes.php";
 include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/moodle/diff.php";
 include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/page/pageindex.php";
 include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/page/orphanedpages.php";
 include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/moodle/wantedpages.php";
 # Binary Handling
 if ($wiki->ewikiacceptbinary) {
     define("EWIKI_UPLOAD_MAXSIZE", get_max_upload_file_size());
     define("EWIKI_SCRIPT_BINARY", $ewbase . "&binary=");
     define("EWIKI_ALLOW_BINARY", 1);
     define("EWIKI_IMAGE_CACHING", 1);
     #define("EWIKI_AUTOVIEW",1);
     include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/lib/mime_magic.php";
     include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/aview/downloads.php";
     include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/moodle/downloads.php";
     #include_once($CFG->dirroot."/mod/wiki/ewiki/plugins/db/binary_store.php");
     include_once $CFG->dirroot . "/mod/wiki/ewiki/plugins/moodle/moodle_binary_store.php";
 } else {
     define("EWIKI_SCRIPT_BINARY", 0);
     define("EWIKI_ALLOW_BINARY", 0);
 }
 # The mighty Wiki itself
 include_once $CFG->dirroot . "/mod/wiki/ewiki/ewiki.php";
 /**
  *
  */
 function fm_make_entries()
 {
     for ($x = 0; $x <= 2; $x++) {
         if (!($tmp = get_record('fmanager_admin', 'usertype', $x))) {
             $create = NULL;
             $create->usertype = (int) $x;
             $create->maxupload = get_max_upload_file_size();
             if (!insert_record('fmanager_admin', $create)) {
                 //error(get_string("errnoinsert",'block_file_manager'));
             }
         }
     }
 }
Example #30
0
    /**
     * Internal implementation of file picker rendering.
     * @param file_picker $fp
     * @return string
     */
    public function render_file_picker(file_picker $fp)
    {
        global $CFG, $OUTPUT, $USER;
        $options = $fp->options;
        $client_id = $options->client_id;
        $strsaved = get_string('filesaved', 'repository');
        $straddfile = get_string('openpicker', 'repository');
        $strloading = get_string('loading', 'repository');
        $icon_progress = $OUTPUT->pix_icon('i/loading_small', $strloading) . '';
        $currentfile = $options->currentfile;
        if (empty($currentfile)) {
            $currentfile = get_string('nofilesattached', 'repository');
        }
        if ($options->maxbytes) {
            $size = $options->maxbytes;
        } else {
            $size = get_max_upload_file_size();
        }
        if ($size == -1) {
            $maxsize = '';
        } else {
            $maxsize = get_string('maxfilesize', 'moodle', display_size($size));
        }
        if ($options->buttonname) {
            $buttonname = ' name="' . $options->buttonname . '"';
        } else {
            $buttonname = '';
        }
        $html = <<<EOD
<div class="filemanager-loading mdl-align" id='filepicker-loading-{$client_id}'>
{$icon_progress}
</div>
<div id="filepicker-wrapper-{$client_id}" class="mdl-left" style="display:none">
    <div>
        <input type="button" id="filepicker-button-{$client_id}" value="{$straddfile}"{$buttonname}/>
        <span> {$maxsize} </span>
    </div>
EOD;
        if ($options->env != 'url') {
            $html .= <<<EOD
    <div id="file_info_{$client_id}" class="mdl-left filepicker-filelist">{$currentfile}</div>
EOD;
        }
        $html .= '</div>';
        return $html;
    }