ÿØÿà JFIF    ÿÛ „  ( %!1"%)+...383-7(-.+  -%%--------+------------/----------------------------ÿÀ  ¶" ÿÄ     ÿÄ @    !1AQaq‘¡"±ÁÑð2’BRráS‚ñ3b¢CT²Ò #cÿÄ    ÿÄ '   1!AQ2a"‘±#ÿÚ   ? ò(/p‘—–¢·,M|¯G»R£üešT. ôŸEoCFñ‡ 4ÔkåóxR|µÁ¨ÓDà!Ç´µ˜‡p ÍQ‹§!þž^õWsŒy  åÁ§$á«%ºq˜™JyyË0y«^Ϗ -3ÃÏËÈ£Æ\P’ä„s&•‹Üs üô'àWt¹pñCp$bÚF`·7.^)¾!)ÒÙ˜–ÅÏš^h¾ø³·ìe±ŒaeÖ—Í,e=B}Jéߦ$$½—šÙÜCC¯¶è8β–Åkèwx LÉngT±æ¹£Ócœ¿Í/©Éÿ ‰ÚCÒ­mq;Tt¶–}0"zÖPcd1š­¤tˆ„ÐÓâqú[™öUCŠ2޿د­É(¸ßúçšmW,Ò ºf‹Ån™ÄLêÁ8üÁkÁ€L¥ÍuJ1œôrÂSŒÓöt!7EUíïb)AËi¬â-ÙHk8òÁiXYwÅ)O^"ÇØriÛô{»wRUKÙÏÚlÓ¬€‚’שT ] ªb—ÊîKC^×M“xùäñz¬zJ× {4[¹M'IÆeH1LCWÕ]œûº WDæà°OÅ‚¹c²ÞuA–rL`HšpCez‡V’— Ž‚Ë„–ñ­'µR0ÕÖ=À:±G»C\nÆÉ5*¢ †3šhQ4ýÒi$Õ1"Ü]¢p-q3zcQ$ªö¨¥æf›‘»´ÝÚHá„e²JÇ–iÊ:·à¬Øc5Åk»Laª*wi [0Ówk ¦a¦0Õ²ÅÅ‚T¸’³q:Æ<¹ú Ò˜Æ}2VE•Ѐp¡Ô3Úº …h³^LJºçì¥Ánó|˜ÖˆÎˆ+« ¦dø‘Mº–d\ªDðÛ„Ì×LÝ——Ð9Ç|•FèçVm™¨€™3õS–9Äå¢<̉Ìm¢±`·º˜&Z²ž Ë®D«¶»6™‰©­HÈ Àá«h­i³04æ’hxœi3ï¨(ÓL·†‹¶ËpŒ ƒÜÒ? :õdsÀ –3æÓ·Üjâ¬9—]8n¼&]I F£¼…ì–—Œ0v°LǐÅfÛ2TÖ’aµ˜N@ÖBSÏ^à´4-±°b×nÈÈœÆD=KdŒø…ÄÈK,›ÖR§fjü$^ÔÎ!„6^ s:Üun\ôkCÞò÷<—Lúl Í›G¹ÀPá¼Nc¡šÒ…ÙWͳœ±vÊáЄ×9‹P‰cEØ‘™›µŸP<×g1 º©Ø¬wiÁ^l5× I/';Ë+´Z‡ÓÄFÕp[Èð’ HÄ ó 9¬Dl4“é±Ï”V=^Hð;žLädÉa‚°Ë,#/Ž~²BÔÛ QãñQtIeórVB,ÏÂf‹4#Μc‹É3ZIÖ Œ¢¥·üxa‡Ãçè„jŠ[5 Ä!U?,3žÎ×…ðdÓ÷háŠA‰ìÄ4÷ÃÜZÃE{‰®+W\ZÍE[‰»µk»MÝ­`¢©†˜ÃV‹-f¢¡†¢a«eŠ%«Y¨©q%jâd,Ôq`) ¤¦…šˆ ¦E>0Ùb²t–Ÿ  ÷jsςҒKÈcø(é›;k(’#ôŒQ ™C> õ³M9óºÆµ¤çâ;uÀ)5>RÔ¸fÓ~Ȧ—’-$fe«"FâUˆÊwµPÏu w+"åÉó¨6s™Û9(À¨ù©hE°½†n`m~“@©›p!Vkhµ Á1šbEqqÊ@ºèl›2 –Yã%‘‚hÛ{a¶‡ÅÞM²¬çL34®Çl]®‹ŽØŒm'RÜe35æöˆ­Á­ cP9šeÁköo´L³Ì=p8]”‡B¶,šº|ɏdzXˆØk*ÇÚ{#ñ‰pã(€¶‡9ý'šÜ³½¯kƒ†Â’ëSOƒ•Å®H6+a¢µˆ‹Y¨b˜b+XˆÖ!°u!¢"µˆˆn2ˆ Å0Ä`Å Ô®c(ÓÜGº•Ä»Œ âWî%q.áÐÄ÷î%umÍ£+ÜQ,Vn¦-GphU¸¢X­&,Gt ·K¢ÅÅ·¥RÄÊÉbKn N­R2g$VµÕó Qr#–ÓZUÏð0ÎtÙÀœz ëöo“Îk¯n„T°"SÞ+³/…€½"ižãO%Í%&Δâ‘ËØ´IˆÓ°Ë‰ÞM3.™yçÁzit›`4C`k¢¼á!álÄï sÂ[×!¤l¾æo"ƒIÔ'@ªu)3›ô®“@Z à¾] üœ'‡4¸PÞkÁ-qÄH‰ÓÍBd´ÿ —¹°ÄA&ÊUC„öz‚‚RæŠtf¬>˜ÑidšEçÑL÷áý¡V±h§­c¿¥¨ƒ@g¼…Ýö^ÞËc.ž„æ“I[ ª+·zÐÒÚ,½Ð»¶€C›7jk$๖€Ž¾ÅÙpp¶ÍþéΤ ½ØÎŒq ñpæžÅ¥#Øâ49ÃÂK^MYV“,¶Éz_òæ:…;Õ«¦I3âJ£¤û5$7Èxün\â]Êe¯(Ÿ&Ž‹¶2<6Ćf× æ¢ƱqWı[(ÙÂŽç‚T7¨@ÈÉÍß‚ïÙ"&3TYlGށ†)†#5ŠA©^T2ÆÁ†)©†©†¤yGXÁ†©"†)©¼ÅV WS†#©]R–r‹q5ÕbâWþBh¯u+ªÅÄ×ü„nÑ^êkªÁj‰jeœWˆÕÕ`µDµ2Ì+Ä µDµµ5Ô{¤Þ0RF’H÷AÛ<ÊÁ§ ƈæ0Ñ£ê4 öÚµ[¬/1²€â<-¬šö²r×0o×w ´xÐÒË„ g01¬„åEM蛇Ã\6µE›‘fÙO k÷CºnÓ1`iîÒ² áÂ!ÑLÄÿ ³¬\õ*:M=Ç»c‹2[‰ØsÕLò\ŒK L^™üÄN\¶#» Ç\……ßïIœÉ$¸ÎñÍ®ÔHÇ Ûí/´>Li”„†g^$ 7NÍÑÑ2M2ªNg=k½Ð}Ÿl6‡ —JWˆ”ÞéT·+µ¦üÂFè¢Vs6ýÆ4»2+2IÝ9ô9®ÇGÙÇ1+Ä8;*Õ§ž½D*îÑWÚçá3Ma¤·ˆ¥t}š²Ü…Q+Æüµ8HíS”üxGéÁˆ¦Ël„éÈ 5 µÄƒ6äÜ(kIš¯S†fÖ&¸®×v|Äyˆ*禌Éù@7-®Ä[]ÎÖ¿ê`º…=:…žJVnݳvðÖKE¼‚ »mà ÷f®:Ë ™–4rð¡4` ܹçž~‹C=œ…¾Ïj|VDtK.ƒ"9 Ï ­–éXá³6WÒïIL-Ї Ç home/smkb8269/public_html/lms.smk-almanshuriyah.sch.id/repository/filepicker.php000064400000043223152266602360023742 0ustar00. // /** * This file is used to browse repositories in non-javascript mode * * @since Moodle 2.0 * @package core * @subpackage repository * @copyright 2009 Dongsheng Cai * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once('../config.php'); require_once($CFG->libdir.'/filelib.php'); require_once('lib.php'); /// Wait as long as it takes for this script to finish core_php_time_limit::raise(); require_sesskey(); require_login(); // disable blocks in this page $PAGE->set_pagelayout('embedded'); // general parameters $action = optional_param('action', '', PARAM_ALPHA); $client_id = optional_param('client_id', '', PARAM_RAW); // client ID $itemid = optional_param('itemid', '', PARAM_INT); // parameters for repository $callback = optional_param('callback', '', PARAM_CLEANHTML); $contextid = optional_param('ctx_id', SYSCONTEXTID, PARAM_INT); // context ID $courseid = optional_param('course', SITEID, PARAM_INT); // course ID $env = optional_param('env', 'filepicker', PARAM_ALPHA); // opened in file picker, file manager or html editor $filename = optional_param('filename', '', PARAM_FILE); $fileurl = optional_param('fileurl', '', PARAM_RAW); $thumbnail = optional_param('thumbnail', '', PARAM_RAW); $targetpath = optional_param('targetpath', '', PARAM_PATH); $repo_id = optional_param('repo_id', 0, PARAM_INT); // repository ID $req_path = optional_param('p', '', PARAM_RAW); // the path in repository $curr_page = optional_param('page', '', PARAM_RAW); // What page in repository? $search_text = optional_param('s', '', PARAM_CLEANHTML); $maxfiles = optional_param('maxfiles', -1, PARAM_INT); // maxfiles $maxbytes = optional_param('maxbytes', 0, PARAM_INT); // maxbytes $subdirs = optional_param('subdirs', 0, PARAM_INT); // maxbytes $areamaxbytes = optional_param('areamaxbytes', FILE_AREA_MAX_BYTES_UNLIMITED, PARAM_INT); // Area maxbytes. $accepted_types = optional_param_array('accepted_types', '*', PARAM_RAW); // the path to save files $savepath = optional_param('savepath', '/', PARAM_PATH); // path in draft area $draftpath = optional_param('draftpath', '/', PARAM_PATH); // user context $user_context = context_user::instance($USER->id); $PAGE->set_context($user_context); if (!$course = $DB->get_record('course', array('id'=>$courseid))) { throw new \moodle_exception('invalidcourseid'); } $PAGE->set_course($course); 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(); } $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); $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("/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')); } catch (moodle_exception $e) { // inject target URL $e->link = $PAGE->url->out(); echo $OUTPUT->header(); // hack: we need the embedded header here, standard error printing would not use it throw $e; } break; case 'search': echo '
'.get_string('back', 'repository')."
"; try { $search_result = $repo->search($search_text); $search_result['issearchresult'] = true; $search_result['repo_id'] = $repo_id; // TODO: need a better solution $purl = new moodle_url($url, array('search_paging' => 1, 'action' => 'search', 'repo_id' => $repo_id)); $pagingbar = new paging_bar($search_result['total'], $search_result['page'] - 1, $search_result['perpage'], $purl, 'p'); echo $OUTPUT->render($pagingbar); echo ''; foreach ($search_result['list'] as $item) { echo ''; echo ''; echo ''; echo ''; } echo '
'; $style = ''; if (isset($item['thumbnail_height'])) { $style .= 'max-height:'.$item['thumbnail_height'].'px;'; } if (isset($item['thumbnail_width'])) { $style .= 'max-width:'.$item['thumbnail_width'].'px;'; } echo html_writer::empty_tag('img', array('src' => $item['thumbnail'], 'alt' => '', 'style' => $style)); echo ''; if (!empty($item['url'])) { echo html_writer::link($item['url'], s($item['title']), array('target'=>'_blank')); } else { echo s($item['title']); } echo ''; echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; echo '
'; } catch (repository_exception $e) { } break; case 'list': case 'sign': echo $OUTPUT->header(); echo $OUTPUT->container_start(); echo html_writer::link($url, get_string('back', 'repository')); echo $OUTPUT->container_end(); if ($repo->check_login()) { $list = $repo->get_listing($req_path, $curr_page); $dynload = !empty($list['dynload'])?true:false; if (!empty($list['upload'])) { echo '
'; echo ''; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo ''; echo '
'; } else { if (!empty($list['path'])) { foreach ($list['path'] as $p) { //echo '
'; //echo '
'; //echo '
'; //echo ''; //echo '
'; $pathurl = new moodle_url($url, array( 'p'=>$p['path'], 'action'=>'list', 'draftpath'=>$draftpath, 'savepath'=>$savepath )); echo '' . html_writer::link($pathurl, s($p['name'])) . ''; echo ' / '; } } if (!empty($list['page'])) { // TODO MDL-28482: need a better solution // paging_bar is not a good option because it starts page numbering from 0 and // repositories number pages starting from 1. $pagingurl = new moodle_url("/repository/filepicker.php?action=list&itemid=$itemid&ctx_id=$contextid&repo_id=$repo_id&course=$courseid&sesskey=". sesskey()); if (!isset($list['perpage']) && !isset($list['total'])) { $list['perpage'] = 10; // instead of setting perpage&total we use number of pages, the result is the same } if (empty($list['total'])) { if ($list['pages'] == -1) { $total = ($list['page'] + 2) * $list['perpage']; } else { $total = $list['pages'] * $list['perpage']; } } else { $total = $list['total']; } echo $OUTPUT->paging_bar($total, $list['page'], $list['perpage'], $pagingurl); } echo ''; foreach ($list['list'] as $item) { echo ''; echo ''; echo ''; echo ''; } echo '
'; $style = ''; if (isset($item['thumbnail_height'])) { $style .= 'max-height:'.$item['thumbnail_height'].'px;'; } if (isset($item['thumbnail_width'])) { $style .= 'max-width:'.$item['thumbnail_width'].'px;'; } echo html_writer::empty_tag('img', array('src' => $item['thumbnail'], 'style' => $style)); echo ''; if (!empty($item['url'])) { echo html_writer::link($item['url'], s($item['title']), array('target'=>'_blank')); } else { echo s($item['title']); } echo ''; if (!isset($item['children'])) { echo '
'; echo ''; echo ''; echo '
'; echo '
'; echo ''; echo ''; echo ''; echo '
'; } else { echo '
'; echo ''; echo ''; echo '
'; } echo '
'; } } else { echo '
'; echo ''; echo ''; $repo->print_login(); echo '
'; } echo $OUTPUT->footer(); break; case 'download': // Check that user has permission to access this file if (!$repo->file_is_accessible($fileurl)) { throw new \moodle_exception('storedfilecannotread'); } $record = new stdClass(); $reference = $repo->get_file_reference($fileurl); $sourcefield = $repo->get_file_source_info($fileurl); $record->source = repository::build_source_field($sourcefield); // If file is already a reference, set $fileurl = file source, $repo = file repository // note that in this case user may not have permission to access the source file directly // so no file_browser/file_info can be used below if ($repo->has_moodle_files()) { $file = repository::get_moodle_file($reference); if ($file && $file->is_external_file()) { $sourcefield = $file->get_source(); // remember the original source $record->source = $repo::build_source_field($sourcefield); $reference = $file->get_reference(); $repo_id = $file->get_repository_id(); $repo = repository::get_repository_by_id($repo_id, $contextid, $repooptions); } } $record->filepath = $savepath; $record->filename = $filename; $record->component = 'user'; $record->filearea = 'draft'; $record->itemid = $itemid; $record->license = ''; $record->author = ''; $now = time(); $record->timecreated = $now; $record->timemodified = $now; $record->userid = $USER->id; $record->contextid = $user_context->id; $record->sortorder = 0; if ($repo->has_moodle_files()) { $fileinfo = $repo->copy_to_area($reference, $record, $maxbytes, $areamaxbytes); redirect($home_url, get_string('downloadsucc', 'repository')); } else { $thefile = $repo->get_file($reference, $filename); if (!empty($thefile['path'])) { $filesize = filesize($thefile['path']); if ($maxbytes != -1 && $filesize>$maxbytes) { unlink($thefile['path']); throw new \moodle_exception('maxbytes'); } // Ensure the file will not make the area exceed its size limit. if (file_is_draft_area_limit_reached($record->itemid, $areamaxbytes, $filesize)) { unlink($thefile['path']); throw new \moodle_exception('maxareabytes'); } // Ensure the user does not upload too many draft files in a short period. if (file_is_draft_areas_limit_reached($USER->id)) { unlink($thefile['path']); throw new \moodle_exception('maxdraftitemids'); } try { $info = repository::move_to_filepool($thefile['path'], $record); redirect($home_url, get_string('downloadsucc', 'repository')); } catch (moodle_exception $e) { // inject target URL $e->link = $PAGE->url->out(); echo $OUTPUT->header(); // hack: we need the embedded header here, standard error printing would not use it throw $e; } } else { throw new \moodle_exception('cannotdownload', 'repository'); } } break; case 'confirm': echo $OUTPUT->header(); echo '
'.get_string('back', 'repository').'
'; echo ''; echo '
'; echo ''; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo '
'. html_writer::label(get_string('filename', 'repository'), 'filename'). '
'; echo '
'; // the save path echo ' '; echo ' '; echo ' '; echo '
'; echo '
'; echo $OUTPUT->footer(); break; default: case 'plugins': $params = array(); $params['context'] = array($user_context, context_system::instance()); $params['currentcontext'] = $PAGE->context; $params['return_types'] = FILE_INTERNAL; $repos = repository::get_instances($params); echo $OUTPUT->header(); echo html_writer::link($home_url->out(false), get_string('backtodraftfiles', 'repository')); echo '
'; echo '
    '; foreach($repos as $repo) { $info = $repo->get_meta(); $aurl = clone($url); $aurl->params(array('savepath'=>$savepath, 'action' => 'list', 'repo_id' => $info->id, 'draftpath'=>$draftpath)); echo '
  • '; echo html_writer::empty_tag('img', ['src' => $info->icon, 'alt' => $info->name, 'class' => 'icon']); echo html_writer::link($aurl, s($info->name)); echo '
  • '; } echo '
'; echo '
'; echo $OUTPUT->footer(); break; } home/smkb8269/public_html/lms.smk-almanshuriyah.sch.id/lib/form/filepicker.php000064400000023537152267641470023250 0ustar00. /** * Filepicker form element * * Contains HTML class for a single filepicker form element * * @package core_form * @copyright 2009 Dongsheng Cai * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ global $CFG; require_once("HTML/QuickForm/button.php"); require_once($CFG->dirroot.'/repository/lib.php'); require_once('templatable_form_element.php'); /** * Filepicker form element * * HTML class for a single filepicker element (based on button) * * @package core_form * @category form * @copyright 2009 Dongsheng Cai * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class MoodleQuickForm_filepicker extends HTML_QuickForm_input implements templatable { use templatable_form_element { export_for_template as export_for_template_base; } /** @var string html for help button, if empty then no help will icon will be dispalyed. */ public $_helpbutton = ''; /** @var array options provided to initalize filemanager */ // PHP doesn't support 'key' => $value1 | $value2 in class definition // We cannot do $_options = array('return_types'=> FILE_INTERNAL | FILE_REFERENCE); // So I have to set null here, and do it in constructor protected $_options = array('maxbytes'=>0, 'accepted_types'=>'*', 'return_types'=>null); /** * 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 */ public function __construct($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::__construct($elementName, $elementLabel, $attributes); } /** * Old syntax of class constructor. Deprecated in PHP7. * * @deprecated since Moodle 3.1 */ public function MoodleQuickForm_filepicker($elementName=null, $elementLabel=null, $attributes=null, $options=null) { debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER); self::__construct($elementName, $elementLabel, $attributes, $options); } /** * Returns html for help button. * * @return string html for help button */ function getHelpButton() { return $this->_helpbutton; } /** * Returns type of filepicker element * * @return string */ function getElementTemplateType() { if ($this->_flagFrozen){ return 'nodisplay'; } else { return 'default'; } } /** * Returns HTML for filepicker form element. * * @return string */ function toHtml() { global $CFG, $COURSE, $USER, $PAGE, $OUTPUT; $id = $this->_attributes['id']; $elname = $this->_attributes['name']; if ($this->_flagFrozen) { return $this->getFrozenHtml(); } if (!$draftitemid = (int)$this->getValue()) { // no existing area info provided - let's use fresh new draft area $draftitemid = file_get_unused_draft_itemid(); $this->setValue($draftitemid); } if ($COURSE->id == SITEID) { $context = context_system::instance(); } else { $context = context_course::instance($COURSE->id); } $client_id = uniqid(); $args = new stdClass(); // need these three to filter repositories list $args->accepted_types = $this->_options['accepted_types']?$this->_options['accepted_types']:'*'; $args->return_types = $this->_options['return_types']; $args->itemid = $draftitemid; $args->maxbytes = $this->_options['maxbytes']; $args->context = $PAGE->context; $args->buttonname = $elname.'choose'; $args->elementid = $id; $html = $this->_getTabs(); $fp = new file_picker($args); $options = $fp->options; $options->context = $PAGE->context; $html .= $OUTPUT->render($fp); $html .= ''; $module = array('name'=>'form_filepicker', 'fullpath'=>'/lib/form/filepicker.js', 'requires'=>array('core_filepicker', 'node', 'node-event-simulate', 'core_dndupload')); $PAGE->requires->js_init_call('M.form_filepicker.init', array($fp->options), true, $module); $nonjsfilepicker = new moodle_url('/repository/draftfiles_manager.php', array( 'env'=>'filepicker', 'action'=>'browse', 'itemid'=>$draftitemid, 'subdirs'=>0, 'maxbytes'=>$options->maxbytes, 'maxfiles'=>1, 'ctx_id'=>$PAGE->context->id, 'course'=>$PAGE->course->id, 'sesskey'=>sesskey(), )); // non js file picker $html .= ''; if (!empty($args->accepted_types) && $args->accepted_types != '*') { $html .= html_writer::tag('p', get_string('filesofthesetypes', 'form')); $util = new \core_form\filetypes_util(); $filetypedescriptions = $util->describe_file_types($args->accepted_types); $html .= $OUTPUT->render_from_template('core_form/filetypes-descriptions', $filetypedescriptions); } return $html; } /** * export uploaded file * * @param array $submitValues values submitted. * @param bool $assoc specifies if returned array is associative * @return array */ function exportValue(&$submitValues, $assoc = false) { global $USER; $draftitemid = $this->_findValue($submitValues); if (null === $draftitemid) { $draftitemid = $this->getValue(); } // make sure max one file is present and it is not too big if (!is_null($draftitemid)) { $fs = get_file_storage(); $usercontext = context_user::instance($USER->id); if ($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id DESC', false)) { $file = array_shift($files); if ($this->_options['maxbytes'] and $this->_options['maxbytes'] !== USER_CAN_IGNORE_FILE_SIZE_LIMITS and $file->get_filesize() > $this->_options['maxbytes']) { // bad luck, somebody tries to sneak in oversized file $file->delete(); } foreach ($files as $file) { // only one file expected $file->delete(); } } } return $this->_prepareValue($draftitemid, true); } public function export_for_template(renderer_base $output) { $context = $this->export_for_template_base($output); $context['html'] = $this->toHtml(); return $context; } /** * Check that the file has the allowed type. * * @param array $value Draft item id with the uploaded files. * @return string|null Validation error message or null. */ public function validateSubmitValue($value) { $filetypesutil = new \core_form\filetypes_util(); $allowlist = $filetypesutil->normalize_file_types($this->_options['accepted_types']); if (empty($allowlist) || $allowlist === ['*']) { // Any file type is allowed, nothing to check here. return; } $draftfiles = file_get_drafarea_files($value); $wrongfiles = array(); if (empty($draftfiles)) { // No file uploaded, nothing to check here. return; } foreach ($draftfiles->list as $file) { if (!$filetypesutil->is_allowed_file_type($file->filename, $allowlist)) { $wrongfiles[] = $file->filename; } } if ($wrongfiles) { $a = array( 'allowlist' => implode(', ', $allowlist), 'wrongfiles' => implode(', ', $wrongfiles), ); return get_string('err_wrongfileextension', 'core_form', $a); } return; } }