コード例 #1
0
ファイル: mod_form.php プロジェクト: OctaveBabel/moodle-itop
 /**
  * Returns the options array to use in forum text editor
  *
  * @return array
  */
 public static function editor_options()
 {
     global $COURSE, $PAGE, $CFG;
     // TODO: add max files and max size support
     $maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes);
     return array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes, 'trusttext' => true);
 }
コード例 #2
0
ファイル: post_form.php プロジェクト: Gavinthisisit/Moodle
 /**
  * Returns the options array to use in twf text editor
  *
  * @param context_module $context
  * @param int $postid post id, use null when adding new post
  * @return array
  */
 public static function editor_options(context_module $context, $postid)
 {
     global $COURSE, $PAGE, $CFG;
     // TODO: add max files and max size support
     $maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes);
     return array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes, 'trusttext' => true, 'return_types' => FILE_INTERNAL | FILE_EXTERNAL, 'subdirs' => file_area_contains_subdirs($context, 'mod_twf', 'post', $postid));
 }
コード例 #3
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->maxbytes)) {
         $coursemaxbytes = $PAGE->course->maxbytes;
     }
     $this->_options['maxbytes'] = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $coursemaxbytes, $fpmaxbytes);
     $this->_type = 'filepicker';
     parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
 }
コード例 #4
0
ファイル: filemanager.php プロジェクト: JP-Git/moodle
 /**
  * Constructor
  *
  * @param stdClass $options options for filemanager
  *   default options are:
  *       maxbytes=>-1,
  *       maxfiles=>-1,
  *       itemid=>0,
  *       subdirs=>false,
  *       client_id=>uniqid(),
  *       acepted_types=>'*',
  *       return_types=>FILE_INTERNAL,
  *       context=>$PAGE->context,
  *       author=>fullname($USER),
  *       licenses=>array build from $CFG->licenses,
  *       defaultlicense=>$CFG->sitedefaultlicense
  */
 public function __construct(stdClass $options)
 {
     global $CFG, $USER, $PAGE;
     require_once $CFG->dirroot . '/repository/lib.php';
     $defaults = array('maxbytes' => -1, 'maxfiles' => -1, 'itemid' => 0, 'subdirs' => 0, 'client_id' => uniqid(), 'accepted_types' => '*', 'return_types' => FILE_INTERNAL, 'context' => $PAGE->context, 'author' => fullname($USER), 'licenses' => array());
     if (!empty($CFG->licenses)) {
         $array = explode(',', $CFG->licenses);
         foreach ($array as $license) {
             $l = new stdClass();
             $l->shortname = $license;
             $l->fullname = get_string($license, 'license');
             $defaults['licenses'][] = $l;
         }
     }
     if (!empty($CFG->sitedefaultlicense)) {
         $defaults['defaultlicense'] = $CFG->sitedefaultlicense;
     }
     foreach ($defaults as $key => $value) {
         if (empty($options->{$key})) {
             $options->{$key} = $value;
         }
     }
     $fs = get_file_storage();
     // initilise options, getting files in root path
     $this->options = file_get_drafarea_files($options->itemid, '/');
     // calculate file count
     $usercontext = context_user::instance($USER->id);
     $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $options->itemid, 'id', false);
     $filecount = count($files);
     $this->options->filecount = $filecount;
     // copying other options
     foreach ($options as $name => $value) {
         $this->options->{$name} = $value;
     }
     // calculate the maximum file size as minimum from what is specified in filepicker options,
     // course options, global configuration and php settings
     $coursebytes = $maxbytes = 0;
     list($context, $course, $cm) = get_context_info_array($this->options->context->id);
     if (is_object($course)) {
         $coursebytes = $course->maxbytes;
     }
     if (!empty($this->options->maxbytes) && $this->options->maxbytes > 0) {
         $maxbytes = $this->options->maxbytes;
     }
     $this->options->maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $coursebytes, $maxbytes);
     // building file picker options
     $params = new stdClass();
     $params->accepted_types = $options->accepted_types;
     $params->return_types = $options->return_types;
     $params->context = $options->context;
     $params->env = 'filemanager';
     $params->disable_types = !empty($options->disable_types) ? $options->disable_types : array();
     $filepicker_options = initialise_filepicker($params);
     $this->options->filepicker = $filepicker_options;
 }
コード例 #5
0
ファイル: externallib.php プロジェクト: educakanchay/campus
 /**
  * Return user information including profile picture + basic site information
  * Note:
  * - no capability checking because we return only known information about logged user
  *
  * @param array $serviceshortnames - DEPRECATED PARAMETER - values will be ignored -
  * it was an original design error, we keep for backward compatibility.
  * @return array site info
  * @since Moodle 2.2
  */
 public static function get_site_info($serviceshortnames = array())
 {
     global $USER, $SITE, $CFG, $DB;
     $params = self::validate_parameters(self::get_site_info_parameters(), array('serviceshortnames' => $serviceshortnames));
     $context = context_user::instance($USER->id);
     $profileimageurl = moodle_url::make_pluginfile_url($context->id, 'user', 'icon', null, '/', 'f1');
     // Site information.
     $siteinfo = array('sitename' => $SITE->fullname, 'siteurl' => $CFG->wwwroot, 'username' => $USER->username, 'firstname' => $USER->firstname, 'lastname' => $USER->lastname, 'fullname' => fullname($USER), 'lang' => current_language(), 'userid' => $USER->id, 'userpictureurl' => $profileimageurl->out(false));
     // Retrieve the service and functions from the web service linked to the token
     // If you call this function directly from external (not a web service call),
     // then it will still return site info without information about a service
     // Note: wsusername/wspassword ws authentication is not supported.
     $functions = array();
     if ($CFG->enablewebservices) {
         // No need to check token if web service are disabled and not a ws call.
         $token = optional_param('wstoken', '', PARAM_ALPHANUM);
         if (!empty($token)) {
             // No need to run if not a ws call.
             // Retrieve service shortname.
             $servicesql = 'SELECT s.*
                            FROM {external_services} s, {external_tokens} t
                            WHERE t.externalserviceid = s.id AND token = ? AND t.userid = ? AND s.enabled = 1';
             $service = $DB->get_record_sql($servicesql, array($token, $USER->id));
             $siteinfo['downloadfiles'] = $service->downloadfiles;
             $siteinfo['uploadfiles'] = $service->uploadfiles;
             if (!empty($service)) {
                 // Return the release and version number for web service users only.
                 $siteinfo['release'] = $CFG->release;
                 $siteinfo['version'] = $CFG->version;
                 // Retrieve the functions.
                 $functionssql = "SELECT f.*\n                            FROM {external_functions} f, {external_services_functions} sf\n                            WHERE f.name = sf.functionname AND sf.externalserviceid = ?";
                 $functions = $DB->get_records_sql($functionssql, array($service->id));
             } else {
                 throw new coding_exception('No service found in get_site_info: something is buggy, \\
                                             it should have fail at the ws server authentication layer.');
             }
         }
     }
     // Build up the returned values of the list of functions.
     $componentversions = array();
     $availablefunctions = array();
     foreach ($functions as $function) {
         $functioninfo = array();
         $functioninfo['name'] = $function->name;
         if ($function->component == 'moodle' || $function->component == 'core') {
             $version = $CFG->version;
             // Moodle version.
         } else {
             $versionpath = core_component::get_component_directory($function->component) . '/version.php';
             if (is_readable($versionpath)) {
                 // We store the component version once retrieved (so we don't load twice the version.php).
                 if (!isset($componentversions[$function->component])) {
                     $plugin = new stdClass();
                     include $versionpath;
                     $componentversions[$function->component] = $plugin->version;
                     $version = $plugin->version;
                 } else {
                     $version = $componentversions[$function->component];
                 }
             } else {
                 // Function component should always have a version.php,
                 // otherwise the function should have been described with component => 'moodle'.
                 throw new moodle_exception('missingversionfile', 'webservice', '', $function->component);
             }
         }
         $functioninfo['version'] = $version;
         $availablefunctions[] = $functioninfo;
     }
     $siteinfo['functions'] = $availablefunctions;
     // Mobile CSS theme and alternative login url.
     $siteinfo['mobilecssurl'] = $CFG->mobilecssurl;
     // Retrieve some advanced features. Only enable/disable ones (bool).
     $advancedfeatures = array("usecomments", "usetags", "enablenotes", "messaging", "enableblogs", "enablecompletion", "enablebadges");
     foreach ($advancedfeatures as $feature) {
         if (isset($CFG->{$feature})) {
             $siteinfo['advancedfeatures'][] = array('name' => $feature, 'value' => (int) $CFG->{$feature});
         }
     }
     // Special case mnet_dispatcher_mode.
     $siteinfo['advancedfeatures'][] = array('name' => 'mnet_dispatcher_mode', 'value' => $CFG->mnet_dispatcher_mode == 'strict' ? 1 : 0);
     // User can manage own files.
     $siteinfo['usercanmanageownfiles'] = has_capability('moodle/user:manageownfiles', $context);
     // User quota. 0 means user can ignore the quota.
     $siteinfo['userquota'] = 0;
     if (!has_capability('moodle/user:ignoreuserquota', $context)) {
         $siteinfo['userquota'] = $CFG->userquota;
     }
     // User max upload file size. -1 means the user can ignore the upload file size.
     $siteinfo['usermaxuploadfilesize'] = get_user_max_upload_file_size($context, $CFG->maxbytes);
     return $siteinfo;
 }
コード例 #6
0
    $filename = date("Y-m-d_H_i_s", time()) . "_" . rand(100000, 900000) . ".jpg";
    //open a stream on the posted data,
    //this is better than $GLOBALS["HTTP_RAW_POST_DATA"], php.ini settings dont affect
    $input = fopen("php://input", "r");
    file_put_contents($CFG->dataroot . '/temp/download/' . $filename, $input);
    //we should really check the filesize here but I don't know how
    //HERE: check file size
    //tell our widget what the filename we made up is
    echo $filename;
    //if receiveing a file with a name, eg from mp3recorder
} elseif (isset($_FILES["newfile"])) {
    //make sure the user is logged in
    require_login();
    // make sure the file is not too big
    $user_context = context_user::instance($USER->id);
    $maxbytes = get_user_max_upload_file_size($user_context);
    if ($maxbytes !== -1 && filesize($_FILES[$newfile]['tmp_name']) > $maxbytes) {
        throw new file_exception('maxbytes');
    }
    //make sure the filename is clean, and then make the savepath
    $filename = clean_param($_FILES["newfile"]['name'], PARAM_FILE);
    if (preg_match('/\\.([a-z0-9]+)$/i', $filename, $match)) {
        if (isset($match[1])) {
            $ext = $match[1];
        }
    }
    $ext = !empty($ext) ? $ext : '';
    if ($ext != 'mp3') {
        throw new moodle_exception('invalidfiletype', 'repository', '', get_mimetype_description(array('filename' => $filename)));
    }
    //make savepath
コード例 #7
0
 public function definition()
 {
     global $CFG, $USER, $COURSE, $cm, $turnitintool;
     $cm = $this->_customdata['cm'];
     $turnitintool = $this->_customdata['turnitintool'];
     $optional_params = $this->_customdata['optional_params'];
     $cansubmit = $this->_customdata['cansubmit'];
     if (has_capability('mod/turnitintool:grade', turnitintool_get_context('MODULE', $cm->id))) {
         $submissions = turnitintool_get_records_select('turnitintool_submissions', 'turnitintoolid=' . $turnitintool->id);
     } else {
         $submissions = turnitintool_get_records_select('turnitintool_submissions', 'userid=' . $USER->id . ' AND turnitintoolid=' . $turnitintool->id);
     }
     $output_js = '<script language="javascript" type="text/javascript">' . PHP_EOL;
     $output_js .= 'var stringsArray = new Array("' . get_string('addsubmission', 'turnitintool') . '","' . get_string('resubmit', 'turnitintool') . '","' . get_string('resubmission', 'turnitintool') . '","' . get_string('resubmissionnotenabled', 'turnitintool') . '","' . get_string('anonenabled', 'turnitintool') . '");' . PHP_EOL;
     $output_js .= 'var submissionArray = new Array();' . PHP_EOL;
     if ($turnitintool->allowlate == 1) {
         $parts = turnitintool_get_records_select('turnitintool_parts', "turnitintoolid='" . $turnitintool->id . "' AND deleted=0 AND dtstart < '" . time() . "'", null, 'dtstart,dtdue,dtpost,id');
     } else {
         $parts = turnitintool_get_records_select('turnitintool_parts', "turnitintoolid='" . $turnitintool->id . "' AND deleted=0 AND dtstart < '" . time() . "' AND dtdue > '" . time() . "'", NULL, 'dtstart,dtdue,dtpost,id');
     }
     if (is_array($submissions)) {
         $i = 0;
         foreach ($submissions as $submission) {
             $lockresubmission = 0;
             if (isset($parts[$submission->submission_part]) and $parts[$submission->submission_part]->dtdue < time()) {
                 $lockresubmission = 1;
             }
             $output_js .= 'submissionArray[' . $i . '] = new Array("' . $submission->userid . '","' . $submission->submission_part . '","' . $submission->submission_title . '","' . $submission->submission_unanon . '",' . $lockresubmission . ');' . PHP_EOL;
             $submittedparts[] = $submission->submission_part;
             $i++;
         }
     }
     $output_js .= '</script>' . PHP_EOL;
     echo $output_js;
     $mform = $this->_form;
     // Display file upload error if need be.
     if (isset($_SESSION["notice"]["type"]) and $_SESSION["notice"]["type"] == "error") {
         $mform->addElement('html', '<div id="upload_error" class="felement ftext error"><span id="upload_error_text" class="error">' . $_SESSION["notice"]["message"] . '</span></div>');
         unset($_SESSION["notice"]["type"]);
         unset($_SESSION["notice"]["message"]);
     }
     if (!empty($parts)) {
         // Upload type.
         switch ($turnitintool->type) {
             case 0:
                 $options = array("1" => "File Upload", "2" => "Text Submission");
                 $mform->addElement('select', 'submissiontype', get_string('selectoption', 'turnitintool'), $options, array("class" => "formnarrow"));
                 $mform->addHelpButton('submissiontype', 'submissiontype', 'turnitintool');
                 break;
             case 1:
             case 2:
                 $mform->addElement('hidden', 'submissiontype', $turnitintool->type);
                 $mform->setType('submissiontype', PARAM_INT);
         }
         $istutor = turnitintool_istutor($USER->email);
         $userid = $USER->id;
         // User id if applicable.
         if ($istutor) {
             $mform->addElement('hidden', 'studentsname', $USER->id);
             $mform->setType('studentsname', PARAM_INT);
         }
         $context = turnitintool_get_context('MODULE', $cm->id);
         $submissiontitle = optional_param('submissiontitle', '', PARAM_CLEAN);
         $disableform = false;
         if (has_capability('mod/turnitintool:grade', turnitintool_get_context('MODULE', $cm->id))) {
             $utype = "tutor";
             // If tutor submitting on behalf of student
             if (count($cansubmit) > 0) {
                 $module_group = turnitintool_module_group($cm);
                 $studentusers = array_keys(get_users_by_capability($context, 'mod/turnitintool:submit', 'u.id', '', '', '', $module_group, '', false));
                 // Append course users.
                 $courseusers = array();
                 $selected = "";
                 foreach ($cansubmit as $courseuser) {
                     // Filter Guest users, admins and grader users
                     if (in_array($courseuser->id, $studentusers)) {
                         if (!is_null($optional_params->userid) and $optional_params->userid == $courseuser->id) {
                             $selected = $courseuser->id;
                         }
                         $courseusers[$courseuser->id] = $courseuser->lastname . ', ' . $courseuser->firstname;
                     }
                 }
                 $select = $mform->addElement('select', 'userid', get_string('studentsname', 'turnitintool'), $courseusers, array("class" => "formnarrow", "onchange" => "updateSubForm(submissionArray,stringsArray,this.form," . $turnitintool->reportgenspeed . ")"));
                 $mform->addHelpButton('userid', 'studentsname', 'turnitintool');
                 if ($selected != "") {
                     $select->setSelected($selected);
                 }
                 if (empty($courseusers)) {
                     $mform->addElement('static', 'allsubmissionsmade', get_string('allsubmissionsmade', 'turnitintool'));
                 }
             } else {
                 $mform->addElement('static', 'noenrolledstudents', get_string('noenrolledstudents', 'turnitintool'));
             }
         } else {
             // If student submitting
             $utype = "student";
             $mform->addElement('hidden', 'userid', $USER->id);
             $mform->setType('userid', PARAM_INT);
         }
         if (!$disableform) {
             // Submission Title.
             $mform->addElement('text', 'submissiontitle', get_string('submissiontitle', 'turnitintool'), array("class" => "formwide"));
             $mform->setType('submissiontitle', PARAM_TEXT);
             $mform->addHelpButton('submissiontitle', 'submissiontitle', 'turnitintool');
             $mform->addRule('submissiontitle', get_string('submissiontitleerror', 'turnitintool'), 'required', '', 'client');
             // Handle assignment parts.
             if (count($parts) > 1) {
                 foreach ($parts as $part) {
                     $options_parts[$part->id] = $part->partname;
                 }
                 $mform->addElement('select', 'submissionpart', get_string('submissionpart', 'turnitintool'), $options_parts, array("class" => "formnarrow", "onchange" => "updateSubForm(submissionArray,stringsArray,this.form," . $turnitintool->reportgenspeed . ",'" . $utype . "')"));
                 $mform->addHelpButton('submissionpart', 'submissionpart', 'turnitintool');
             } else {
                 foreach ($parts as $part) {
                     $mform->addElement('hidden', 'submissionpart', $part->id);
                     $mform->setType('submissionpart', PARAM_INT);
                     break;
                 }
             }
             // File input.
             $maxbytessite = $CFG->maxbytes == 0 || $CFG->maxbytes > TURNITINTOOL_MAX_FILE_UPLOAD_SIZE ? TURNITINTOOL_MAX_FILE_UPLOAD_SIZE : $CFG->maxbytes;
             $maxbytescourse = $COURSE->maxbytes == 0 || $COURSE->maxbytes > TURNITINTOOL_MAX_FILE_UPLOAD_SIZE ? TURNITINTOOL_MAX_FILE_UPLOAD_SIZE : $COURSE->maxbytes;
             $maxfilesize = get_user_max_upload_file_size(context_module::instance($cm->id), $maxbytessite, $maxbytescourse, $turnitintool->maxfilesize);
             $maxfilesize = $maxfilesize <= 0 ? TURNITINTOOL_MAX_FILE_UPLOAD_SIZE : $maxfilesize;
             $turnitintoolfileuploadoptions = array('maxbytes' => $maxfilesize, 'subdirs' => false, 'maxfiles' => 1, 'accepted_types' => array('.doc', '.docx', '.rtf', '.txt', '.pdf', '.htm', '.html', '.odt', '.eps', '.ps', '.wpd', '.hwp', '.ppt', '.pptx', '.ppsx', '.pps'));
             $mform->addElement('filemanager', 'submissionfile', get_string('filetosubmit', 'turnitintool'), null, $turnitintoolfileuploadoptions);
             $mform->addHelpButton('submissionfile', 'filetosubmit', 'turnitintool');
             // Text input input.
             $mform->addElement('textarea', 'submissiontext', get_string('texttosubmit', 'turnitintool'), array("class" => "submissionText"));
             $mform->addHelpButton('submissiontext', 'texttosubmit', 'turnitintool');
             $checked = '';
             if (!is_null($optional_params->agreement)) {
                 $checked = ' checked';
             }
             if (has_capability('mod/turnitintool:grade', $context) or empty($CFG->turnitin_agreement)) {
                 $mform->addElement('hidden', 'agreement', '1');
                 $mform->setType('agreement', PARAM_INT);
             } else {
                 $mform->addElement('checkbox', 'agreement', '', $CFG->turnitin_agreement);
                 $mform->setDefault('agreement', '1', true);
             }
             $mform->addElement('submit', 'submitbutton', get_string('addsubmission', 'turnitintool'));
         }
     }
 }
コード例 #8
0
ファイル: locallib.php プロジェクト: nikitskynikita/moodle
 /**
  * Updates a lesson page and its answers within the database
  *
  * @param object $properties
  * @return bool
  */
 public function update($properties, $context = null, $maxbytes = null)
 {
     global $DB, $PAGE;
     $answers = $this->get_answers();
     $properties->id = $this->properties->id;
     $properties->lessonid = $this->lesson->id;
     if (empty($properties->qoption)) {
         $properties->qoption = '0';
     }
     if (empty($context)) {
         $context = $PAGE->context;
     }
     if ($maxbytes === null) {
         $maxbytes = get_user_max_upload_file_size($context);
     }
     $properties->timemodified = time();
     $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes), $context, 'mod_lesson', 'page_contents', $properties->id);
     $DB->update_record("lesson_pages", $properties);
     for ($i = 0; $i < $this->lesson->maxanswers; $i++) {
         if (!array_key_exists($i, $this->answers)) {
             $this->answers[$i] = new stdClass();
             $this->answers[$i]->lessonid = $this->lesson->id;
             $this->answers[$i]->pageid = $this->id;
             $this->answers[$i]->timecreated = $this->timecreated;
         }
         if (!empty($properties->answer_editor[$i]) && is_array($properties->answer_editor[$i])) {
             $this->answers[$i]->answer = $properties->answer_editor[$i]['text'];
             $this->answers[$i]->answerformat = $properties->answer_editor[$i]['format'];
         }
         if (!empty($properties->response_editor[$i]) && is_array($properties->response_editor[$i])) {
             $this->answers[$i]->response = $properties->response_editor[$i]['text'];
             $this->answers[$i]->responseformat = $properties->response_editor[$i]['format'];
         }
         // we don't need to check for isset here because properties called it's own isset method.
         if ($this->answers[$i]->answer != '') {
             if (isset($properties->jumpto[$i])) {
                 $this->answers[$i]->jumpto = $properties->jumpto[$i];
             }
             if ($this->lesson->custom && isset($properties->score[$i])) {
                 $this->answers[$i]->score = $properties->score[$i];
             }
             if (!isset($this->answers[$i]->id)) {
                 $this->answers[$i]->id = $DB->insert_record("lesson_answers", $this->answers[$i]);
             } else {
                 $DB->update_record("lesson_answers", $this->answers[$i]->properties());
             }
             // Save files in answers and responses.
             $this->save_answers_files($context, $maxbytes, $this->answers[$i], $properties->answer_editor[$i], $properties->response_editor[$i]);
         } else {
             if (isset($this->answers[$i]->id)) {
                 $DB->delete_records('lesson_answers', array('id' => $this->answers[$i]->id));
                 unset($this->answers[$i]);
             }
         }
     }
     return true;
 }
コード例 #9
0
ファイル: upload.php プロジェクト: alanaipe2015/moodle
        $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();
if ($filearea == 'draft' && $itemid <= 0) {
    $itemid = file_get_unused_draft_itemid();
}
// Get any existing file size limits.
$maxareabytes = FILE_AREA_MAX_BYTES_UNLIMITED;
$maxupload = get_user_max_upload_file_size($context, $CFG->maxbytes);
if ($filearea == 'private') {
    // Private files area is limited by $CFG->userquota.
    if (!has_capability('moodle/user:ignoreuserquota', $context)) {
        $maxareabytes = $CFG->userquota;
    }
    // Count the size of all existing files in this area.
    if ($maxareabytes > 0) {
        $usedspace = 0;
        $existingfiles = $fs->get_area_files($context->id, 'user', $filearea, false, 'id', false);
        foreach ($existingfiles as $file) {
            $usedspace += $file->get_filesize();
        }
        if ($totalsize > $maxareabytes - $usedspace) {
            throw new file_exception('userquotalimit');
        }
コード例 #10
0
 public static function file_options()
 {
     global $COURSE, $PAGE, $CFG;
     $configmaxbytes = get_config('local_mail', 'maxbytes') ?: LOCAL_MAIL_MAXBYTES;
     $configmaxfiles = get_config('local_mail', 'maxfiles');
     $maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes, $configmaxbytes);
     $maxfiles = is_numeric($configmaxfiles) ? $configmaxfiles : LOCAL_MAIL_MAXFILES;
     return array('accepted_types' => '*', 'maxbytes' => $maxbytes, 'maxfiles' => $maxfiles, 'return_types' => FILE_INTERNAL | FILE_EXTERNAL, 'subdirs' => false);
 }
コード例 #11
0
 /**
  * @return int Max bytes for attachments or -1 if upload is prevented
  */
 public function get_max_bytes()
 {
     if ($this->forumfields->attachmentmaxbytes) {
         if ($this->forumfields->attachmentmaxbytes == -1) {
             return -1;
         } else {
             return get_user_max_upload_file_size($this->get_context(), $this->forumfields->attachmentmaxbytes);
         }
     } else {
         return get_user_max_upload_file_size($this->get_context(), $this->get_course()->maxbytes);
     }
 }
コード例 #12
0
ファイル: repository_ajax.php プロジェクト: IFPBMoodle/moodle
if (!confirm_sesskey()) {
    $err->error = get_string('invalidsesskey', 'error');
    die(json_encode($err));
}
// Get repository instance information
$repooptions = array('ajax' => true, 'mimetypes' => $accepted_types);
ajax_capture_output();
$repo = repository::get_repository_by_id($repo_id, $contextid, $repooptions);
// Check permissions
$repo->check_capability();
$coursemaxbytes = 0;
if (!empty($course)) {
    $coursemaxbytes = $course->maxbytes;
}
// Make sure maxbytes passed is within site filesize limits.
$maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $coursemaxbytes, $maxbytes, null, $repo->uses_post_requests());
// Wait as long as it takes for this script to finish
core_php_time_limit::raise();
// These actions all occur on the currently active repository instance
switch ($action) {
    case 'sign':
    case 'signin':
    case 'list':
        if ($repo->check_login()) {
            $listing = repository::prepare_listing($repo->get_listing($req_path, $page));
            $listing['repo_id'] = $repo_id;
            ajax_check_captured_output();
            echo json_encode($listing);
            break;
        } else {
            $action = 'login';
コード例 #13
0
ファイル: locallib.php プロジェクト: educacionbe/cursos
 /**
  * Updates a lesson page and its answers within the database
  *
  * @param object $properties
  * @return bool
  */
 public function update($properties, $context = null, $maxbytes = null)
 {
     global $DB, $PAGE;
     $answers = $this->get_answers();
     $properties->id = $this->properties->id;
     $properties->lessonid = $this->lesson->id;
     if (empty($properties->qoption)) {
         $properties->qoption = '0';
     }
     if (empty($context)) {
         $context = $PAGE->context;
     }
     if ($maxbytes === null) {
         $maxbytes = get_user_max_upload_file_size($context);
     }
     $properties->timemodified = time();
     $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes), $context, 'mod_lesson', 'page_contents', $properties->id);
     $DB->update_record("lesson_pages", $properties);
     if ($this->type == self::TYPE_STRUCTURE && $this->get_typeid() != LESSON_PAGE_BRANCHTABLE) {
         if (count($answers) > 1) {
             $answer = array_shift($answers);
             foreach ($answers as $a) {
                 $DB->delete_record('lesson_answers', array('id' => $a->id));
             }
         } else {
             if (count($answers) == 1) {
                 $answer = array_shift($answers);
             } else {
                 $answer = new stdClass();
                 $answer->lessonid = $properties->lessonid;
                 $answer->pageid = $properties->id;
                 $answer->timecreated = time();
             }
         }
         $answer->timemodified = time();
         if (isset($properties->jumpto[0])) {
             $answer->jumpto = $properties->jumpto[0];
         }
         if (isset($properties->score[0])) {
             $answer->score = $properties->score[0];
         }
         if (!empty($answer->id)) {
             $DB->update_record("lesson_answers", $answer->properties());
         } else {
             $DB->insert_record("lesson_answers", $answer);
         }
     } else {
         for ($i = 0; $i < $this->lesson->maxanswers; $i++) {
             if (!array_key_exists($i, $this->answers)) {
                 $this->answers[$i] = new stdClass();
                 $this->answers[$i]->lessonid = $this->lesson->id;
                 $this->answers[$i]->pageid = $this->id;
                 $this->answers[$i]->timecreated = $this->timecreated;
             }
             if (!empty($properties->answer_editor[$i]) && is_array($properties->answer_editor[$i])) {
                 $this->answers[$i]->answer = $properties->answer_editor[$i]['text'];
                 $this->answers[$i]->answerformat = $properties->answer_editor[$i]['format'];
             }
             if (!empty($properties->response_editor[$i]) && is_array($properties->response_editor[$i])) {
                 $this->answers[$i]->response = $properties->response_editor[$i]['text'];
                 $this->answers[$i]->responseformat = $properties->response_editor[$i]['format'];
             }
             if (isset($this->answers[$i]->answer) && $this->answers[$i]->answer != '') {
                 if (isset($properties->jumpto[$i])) {
                     $this->answers[$i]->jumpto = $properties->jumpto[$i];
                 }
                 if ($this->lesson->custom && isset($properties->score[$i])) {
                     $this->answers[$i]->score = $properties->score[$i];
                 }
                 if (!isset($this->answers[$i]->id)) {
                     $this->answers[$i]->id = $DB->insert_record("lesson_answers", $this->answers[$i]);
                 } else {
                     $DB->update_record("lesson_answers", $this->answers[$i]->properties());
                 }
             } else {
                 if (isset($this->answers[$i]->id)) {
                     $DB->delete_records('lesson_answers', array('id' => $this->answers[$i]->id));
                     unset($this->answers[$i]);
                 }
             }
         }
     }
     return true;
 }
コード例 #14
0
ファイル: submission_form.php プロジェクト: jrlamb/alexBado
 public static function attachment_options()
 {
     global $COURSE, $PAGE, $CFG;
     $maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes, 0);
     return array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => 1, 'accepted_types' => '*', 'return_types' => FILE_INTERNAL);
 }
コード例 #15
0
         print_error('notcreatestage', 'treasurehunt', $returnurl);
     }
     $stage = new stdClass();
     $stage->id = null;
     $stage->roadid = $roadid;
 }
 if (!isset($stage->questiontext) || $stage->questiontext === '') {
     $stage->addsimplequestion = optional_param('addsimplequestion', 0, PARAM_INT);
     $stage->noanswers = optional_param('noanswers', 2, PARAM_INT);
     if (!empty($addanswers)) {
         $stage->noanswers += NUMBER_NEW_ANSWERS;
     }
 }
 $stage->cmid = $cmid;
 $returnurl = new moodle_url('/mod/treasurehunt/edit.php', array('id' => $cmid, 'roadid' => $stage->roadid));
 $maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes);
 $editoroptions = array('trusttext' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes, 'context' => $context, 'subdirs' => file_area_contains_subdirs($context, 'mod_treasurehunt', 'cluetext', $stage->id));
 // List activities with Completion enabled
 $completioninfo = new completion_info($course);
 $completionactivities = $completioninfo->get_activities();
 $mform = new stage_form(null, array('current' => $stage, 'context' => $context, 'editoroptions' => $editoroptions, 'completionactivities' => $completionactivities));
 //name of the form you defined in file above.
 if ($mform->is_reloaded()) {
     // Si se ha recargado es porque hemos cambiado algo
 } else {
     if ($mform->is_cancelled()) {
         // You need this section if you have a cancel button on your form
         // here you tell php what to do if your user presses cancel
         // probably a redirect is called for!
         // PLEASE NOTE: is_cancelled() should be called before get_data().
         redirect($returnurl);
コード例 #16
0
ファイル: repository_ajax.php プロジェクト: covex-nn/moodle
}
if (!confirm_sesskey()) {
    $err->error = get_string('invalidsesskey', 'error');
    die(json_encode($err));
}
// Get repository instance information
$repooptions = array('ajax' => true, 'mimetypes' => $accepted_types);
$repo = repository::get_repository_by_id($repo_id, $contextid, $repooptions);
// Check permissions
$repo->check_capability();
$coursemaxbytes = 0;
if (!empty($course)) {
    $coursemaxbytes = $course->maxbytes;
}
// Make sure maxbytes passed is within site filesize limits.
$maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $coursemaxbytes, $maxbytes);
// Wait as long as it takes for this script to finish
core_php_time_limit::raise();
// These actions all occur on the currently active repository instance
switch ($action) {
    case 'sign':
    case 'signin':
    case 'list':
        if ($repo->check_login()) {
            $listing = repository::prepare_listing($repo->get_listing($req_path, $page));
            $listing['repo_id'] = $repo_id;
            echo json_encode($listing);
            break;
        } else {
            $action = 'login';
        }
コード例 #17
0
ファイル: lib.php プロジェクト: JP-Git/moodle
 /**
  * Options for displaying the rubric description field in the form
  *
  * @param object $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_user_max_upload_file_size($context, $CFG->maxbytes), 'context' => $context);
 }
コード例 #18
0
ファイル: locallib.php プロジェクト: mongo0se/moodle
 /**
  * Updates a lesson page and its answers within the database
  *
  * @param object $properties
  * @return bool
  */
 public function update($properties, $context = null, $maxbytes = null)
 {
     global $DB, $PAGE;
     $answers = $this->get_answers();
     $properties->id = $this->properties->id;
     $properties->lessonid = $this->lesson->id;
     if (empty($properties->qoption)) {
         $properties->qoption = '0';
     }
     if (empty($context)) {
         $context = $PAGE->context;
     }
     if ($maxbytes === null) {
         $maxbytes = get_user_max_upload_file_size($context);
     }
     $properties->timemodified = time();
     $properties = file_postupdate_standard_editor($properties, 'contents', array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes), $context, 'mod_lesson', 'page_contents', $properties->id);
     $DB->update_record("lesson_pages", $properties);
     // Trigger an event: page updated.
     \mod_lesson\event\page_updated::create_from_lesson_page($this, $context)->trigger();
     if ($this->type == self::TYPE_STRUCTURE && $this->get_typeid() != LESSON_PAGE_BRANCHTABLE) {
         // These page types have only one answer to save the jump and score.
         if (count($answers) > 1) {
             $answer = array_shift($answers);
             foreach ($answers as $a) {
                 $DB->delete_record('lesson_answers', array('id' => $a->id));
             }
         } else {
             if (count($answers) == 1) {
                 $answer = array_shift($answers);
             } else {
                 $answer = new stdClass();
                 $answer->lessonid = $properties->lessonid;
                 $answer->pageid = $properties->id;
                 $answer->timecreated = time();
             }
         }
         $answer->timemodified = time();
         if (isset($properties->jumpto[0])) {
             $answer->jumpto = $properties->jumpto[0];
         }
         if (isset($properties->score[0])) {
             $answer->score = $properties->score[0];
         }
         if (!empty($answer->id)) {
             $DB->update_record("lesson_answers", $answer->properties());
         } else {
             $DB->insert_record("lesson_answers", $answer);
         }
     } else {
         for ($i = 0; $i < $this->lesson->maxanswers; $i++) {
             if (!array_key_exists($i, $this->answers)) {
                 $this->answers[$i] = new stdClass();
                 $this->answers[$i]->lessonid = $this->lesson->id;
                 $this->answers[$i]->pageid = $this->id;
                 $this->answers[$i]->timecreated = $this->timecreated;
             }
             if (isset($properties->answer_editor[$i])) {
                 if (is_array($properties->answer_editor[$i])) {
                     // Multichoice and true/false pages have an HTML editor.
                     $this->answers[$i]->answer = $properties->answer_editor[$i]['text'];
                     $this->answers[$i]->answerformat = $properties->answer_editor[$i]['format'];
                 } else {
                     // Branch tables, shortanswer and mumerical pages have only a text field.
                     $this->answers[$i]->answer = $properties->answer_editor[$i];
                     $this->answers[$i]->answerformat = FORMAT_MOODLE;
                 }
             }
             if (!empty($properties->response_editor[$i]) && is_array($properties->response_editor[$i])) {
                 $this->answers[$i]->response = $properties->response_editor[$i]['text'];
                 $this->answers[$i]->responseformat = $properties->response_editor[$i]['format'];
             }
             if (isset($this->answers[$i]->answer) && $this->answers[$i]->answer != '') {
                 if (isset($properties->jumpto[$i])) {
                     $this->answers[$i]->jumpto = $properties->jumpto[$i];
                 }
                 if ($this->lesson->custom && isset($properties->score[$i])) {
                     $this->answers[$i]->score = $properties->score[$i];
                 }
                 if (!isset($this->answers[$i]->id)) {
                     $this->answers[$i]->id = $DB->insert_record("lesson_answers", $this->answers[$i]);
                 } else {
                     $DB->update_record("lesson_answers", $this->answers[$i]->properties());
                 }
                 // Save files in answers and responses.
                 if (isset($properties->response_editor[$i])) {
                     $this->save_answers_files($context, $maxbytes, $this->answers[$i], $properties->answer_editor[$i], $properties->response_editor[$i]);
                 } else {
                     $this->save_answers_files($context, $maxbytes, $this->answers[$i], $properties->answer_editor[$i]);
                 }
             } else {
                 if (isset($this->answers[$i]->id)) {
                     $DB->delete_records('lesson_answers', array('id' => $this->answers[$i]->id));
                     unset($this->answers[$i]);
                 }
             }
         }
     }
     return true;
 }
コード例 #19
0
}
// Don't show messages popup if we are in submission modal.
$forbiddenmsgscreens = array('submission_success', 'submitpaper');
if (in_array($do, $forbiddenmsgscreens)) {
    $PAGE->set_popup_notification_allowed(false);
}
// Configure URL correctly.
$urlparams = array('id' => $id, 'a' => $a, 'part' => $part, 'user' => $user, 'do' => $do, 'action' => $action, 'view_context' => $viewcontext);
$url = new moodle_url('/mod/turnitintooltwo/view.php', $urlparams);
// Load Javascript and CSS.
$turnitintooltwoview->load_page_components();
$turnitintooltwoassignment = new turnitintooltwo_assignment($turnitintooltwo->id, $turnitintooltwo);
// Define file upload options.
$maxbytessite = $CFG->maxbytes == 0 || $CFG->maxbytes > TURNITINTOOLTWO_MAX_FILE_UPLOAD_SIZE ? TURNITINTOOLTWO_MAX_FILE_UPLOAD_SIZE : $CFG->maxbytes;
$maxbytescourse = $COURSE->maxbytes == 0 || $COURSE->maxbytes > TURNITINTOOLTWO_MAX_FILE_UPLOAD_SIZE ? TURNITINTOOLTWO_MAX_FILE_UPLOAD_SIZE : $COURSE->maxbytes;
$maxfilesize = get_user_max_upload_file_size(context_module::instance($cm->id), $maxbytessite, $maxbytescourse, $turnitintooltwoassignment->turnitintooltwo->maxfilesize);
$maxfilesize = $maxfilesize <= 0 ? TURNITINTOOLTWO_MAX_FILE_UPLOAD_SIZE : $maxfilesize;
$turnitintooltwofileuploadoptions = array('maxbytes' => $maxfilesize, 'subdirs' => false, 'maxfiles' => 1, 'accepted_types' => '*');
if (!($parts = $turnitintooltwoassignment->get_parts())) {
    turnitintooltwo_print_error('partgeterror', 'turnitintooltwo', null, null, __FILE__, __LINE__);
}
// Get whether user is a tutor/student.
$istutor = has_capability('mod/turnitintooltwo:grade', context_module::instance($cm->id));
$userrole = $istutor ? 'Instructor' : 'Learner';
// Deal with actions here.
if (!empty($action)) {
    turnitintooltwo_activitylog("Action: " . $action . " | Id: " . $turnitintooltwo->id . " | Part: " . $part, "REQUEST");
    switch ($action) {
        case "delpart":
            if (!confirm_sesskey()) {
                throw new moodle_exception('invalidsesskey', 'error');
コード例 #20
0
ファイル: filepicker.php プロジェクト: aleph-n/lms.aaenl
if (!($course = $DB->get_record('course', array('id' => $courseid)))) {
    print_error('invalidcourseid');
}
$PAGE->set_course($course);
$usespost = true;
if ($repo_id) {
    // Get repository instance information
    $repooptions = array('ajax' => false, 'mimetypes' => $accepted_types);
    $repo = repository::get_repository_by_id($repo_id, $contextid, $repooptions);
    // Check permissions
    $repo->check_capability();
    $usespost = $repo->uses_post_requests();
}
$context = context::instance_by_id($contextid);
// Make sure maxbytes passed is within site filesize limits.
$maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $course->maxbytes, $maxbytes, null, $usespost);
$params = array('ctx_id' => $contextid, 'itemid' => $itemid, 'env' => $env, 'course' => $courseid, 'maxbytes' => $maxbytes, 'areamaxbytes' => $areamaxbytes, '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);
switch ($action) {
    case 'upload':
        // The uploaded file has been processed in plugin construct function
        // redirect to default page
        try {
            $repo->upload('', $maxbytes);
            redirect($home_url, get_string('uploadsucc', 'repository'));