mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
"MDL-17316, fix upload form in non-js file picker"
This commit is contained in:
parent
b556308033
commit
ab9cdbb976
6 changed files with 41 additions and 17 deletions
|
@ -1,7 +1,7 @@
|
|||
<?php //$Id$
|
||||
$string['accessiblefilepicker']='Accessible file picker';
|
||||
$string['activerepository'] = 'Active repository plugins';
|
||||
$string['add'] = 'Add';
|
||||
$string['add'] = 'Add...';
|
||||
$string['addplugin'] = 'Add a repository plugin';
|
||||
$string['activaterep'] = 'Active repositories';
|
||||
$string['areabackup'] = 'Backups';
|
||||
|
@ -104,5 +104,6 @@ $string['typenotvisible'] = 'Type not visible';
|
|||
$string['updown'] = 'Display order';
|
||||
$string['upload'] = 'Upload this file';
|
||||
$string['uploading'] = 'Uploading...';
|
||||
$string['uploadsucc'] = 'The file has been uploaded successfully';
|
||||
$string['wrongcontext'] = 'You cannot access to this context';
|
||||
$string['xhtmlerror'] = 'You are probably using XHTML strict header, some YUI Component doesn\'t work in this mode, please turn it off in moodle';
|
||||
|
|
|
@ -173,7 +173,12 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
|||
$str .= $repo_info['js'];
|
||||
$str .= <<<EOD
|
||||
<input value="$draftitemid" name="{$this->_attributes['name']}" type="hidden" />
|
||||
<a href="#nonjsfp" class="btnaddfile" onclick="return callpicker('$id', '$client_id', '$draftitemid')">$straddfile</a>
|
||||
<a href="###" id="btnadd-{$client_id}" style="display:none" class="btnaddfile" onclick="return callpicker('$id', '$client_id', '$draftitemid')">$straddfile</a>
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
document.getElementById('btnadd-{$client_id}').style.display="inline";
|
||||
//]]>
|
||||
</script>
|
||||
EOD;
|
||||
if (empty($CFG->filemanagerjsloaded)) {
|
||||
$str .= <<<EOD
|
||||
|
@ -224,7 +229,6 @@ function callpicker(el_id, client_id, itemid) {
|
|||
//]]>
|
||||
</script>
|
||||
<noscript>
|
||||
<a name="nonjsfp"></a>
|
||||
<object type="text/html" data="{$CFG->httpswwwroot}/repository/filepicker.php?action=embedded&itemid={$draftitemid}&ctx_id=$context->id" height="300" width="800" style="border:1px solid #000">Error</object>
|
||||
</noscript>
|
||||
EOD;
|
||||
|
|
|
@ -65,6 +65,8 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
|
|||
return $this->getFrozenHtml();
|
||||
}
|
||||
|
||||
$strsaved = get_string('filesaved', 'repository');
|
||||
$straddfile = get_string('openpicker', 'repository');
|
||||
$currentfile = '';
|
||||
$draftvalue = '';
|
||||
if ($draftid = (int)$this->getValue()) {
|
||||
|
@ -76,7 +78,6 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
|
|||
$draftvalue = 'value="'.$draftid.'"';
|
||||
}
|
||||
}
|
||||
$strsaved = get_string('filesaved', 'repository');
|
||||
if ($COURSE->id == SITEID) {
|
||||
$context = get_context_instance(CONTEXT_SYSTEM);
|
||||
} else {
|
||||
|
@ -90,8 +91,11 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
|
|||
|
||||
$str = $this->_getTabs();
|
||||
$str .= '<input type="hidden" name="'.$elname.'" id="'.$id.'" '.$draftvalue.' />';
|
||||
$str .= $repository_info['css'].$repository_info['js'];
|
||||
|
||||
$str .= <<<EOD
|
||||
<a href="#nonjsfp" class="btnaddfile" onclick="return callpicker('$client_id', '$id', '$draftvalue')">$straddfile</a>
|
||||
<span id="repo_info_{$client_id}" class="notifysuccess">$currentfile</span>
|
||||
<script type="text/javascript">
|
||||
function updatefile(client_id, obj) {
|
||||
document.getElementById('repo_info_'+client_id).innerHTML = obj['file'];
|
||||
|
@ -104,15 +108,20 @@ function callpicker(client_id, id) {
|
|||
var el=document.getElementById(id);
|
||||
var params = {};
|
||||
params.env = 'filepicker';
|
||||
params.itemid = itemid;
|
||||
params.maxbytes = $this->_options['maxbytes'];
|
||||
params.maxfiles = $this->_options['maxfiles'];
|
||||
params.target = el;
|
||||
params.callback = updatefile;
|
||||
open_filepicker(client_id, params);
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
<noscript>
|
||||
<a name="nonjsfp"></a>
|
||||
<object type="text/html" data="{$CFG->httpswwwroot}/repository/filepicker.php?action=embedded&itemid={$draftitemid}&ctx_id=$context->id" height="300" width="800" style="border:1px solid #000">Error</object>
|
||||
</noscript>
|
||||
EOD;
|
||||
$str .= '<input value="'.get_string('openpicker', 'repository').'" type="button" onclick="callpicker(\''.$client_id.'\', \''.$id.'\')" />'.'<span id="repo_info_'.$client_id.'" class="notifysuccess">'.$currentfile.'</span>'.$repository_info['css'].$repository_info['js'];
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,9 @@ if (file_exists($CFG->dirroot.'/repository/'.$type.'/repository.class.php')) {
|
|||
//$PAGE->set_course($context);
|
||||
|
||||
switch ($action) {
|
||||
case 'upload':
|
||||
redirect($url, get_string('uploadsucc','repository'));
|
||||
break;
|
||||
case 'deletedraft':
|
||||
if (!$context = get_context_instance(CONTEXT_USER, $USER->id)) {
|
||||
print_error('wrongcontextid', 'error');
|
||||
|
@ -85,9 +88,11 @@ case 'sign':
|
|||
$list = $repo->get_listing($req_path);
|
||||
$dynload = !empty($list['dynload'])?true:false;
|
||||
if (!empty($list['upload'])) {
|
||||
echo '<form method="post" style="display:inline">';
|
||||
echo '<label>'.$list['upload']['label'].'</label>';
|
||||
echo '<form action="'.$url.'" method="post" enctype="multipart/form-data" style="display:inline">';
|
||||
echo '<label>'.$list['upload']['label'].': </label>';
|
||||
echo '<input type="file" name="repo_upload_file" /><br />';
|
||||
echo '<input type="hidden" name="action" value="upload" /><br />';
|
||||
echo '<input type="hidden" name="repo_id" value="'.$repo_id.'" /><br />';
|
||||
echo '<input type="submit" value="'.get_string('upload', 'repository').'" />';
|
||||
echo '</form>';
|
||||
} else {
|
||||
|
@ -194,6 +199,17 @@ case 'confirm':
|
|||
echo '</form>';
|
||||
print_footer('empty');
|
||||
break;
|
||||
case 'plugins':
|
||||
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$repos = repository::get_instances(array($user_context, get_system_context()), null, true, null, '*', 'ref_id');
|
||||
print_header();
|
||||
echo '<div><ul>';
|
||||
foreach($repos as $repo) {
|
||||
$info = $repo->get_meta();
|
||||
echo '<li><img src="'.$info->icon.'" width="16px" height="16px"/> <a href="'.$url.'&action=list&repo_id='.$info->id.'">'.$info->name.'</a></li>';
|
||||
}
|
||||
echo '</ul></div>';
|
||||
break;
|
||||
default:
|
||||
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$repos = repository::get_instances(array($user_context, get_system_context()), null, true, null, '*', 'ref_id');
|
||||
|
@ -201,7 +217,6 @@ default:
|
|||
$fs = get_file_storage();
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$files = $fs->get_area_files($context->id, 'user_draft', $itemid);
|
||||
echo '<h2>'.get_string('attachedfiles', 'repository').'</h2>';
|
||||
if (empty($files)) {
|
||||
echo get_string('nofilesattached', 'repository');
|
||||
} else {
|
||||
|
@ -215,13 +230,7 @@ default:
|
|||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
echo '<h2>'.get_string('plugin', 'repository').'</h2>';
|
||||
echo '<div><ul>';
|
||||
foreach($repos as $repo) {
|
||||
$info = $repo->get_meta();
|
||||
echo '<li><img src="'.$info->icon.'" width="16px" height="16px"/> <a href="'.$url.'&action=list&repo_id='.$info->id.'">'.$info->name.'</a></li>';
|
||||
}
|
||||
echo '</ul></div>';
|
||||
echo '<div><a href="'.$url.'&action=plugins">'.get_string('add', 'repository').'</a></div>';
|
||||
print_footer('empty');
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -571,7 +571,8 @@ repository_client.select_file = function(oldname, url, icon, client_id, repo_id)
|
|||
if (repository_client.files[client_id] == undefined) {
|
||||
repository_client.files[client_id] = 0;
|
||||
}
|
||||
if (repository_client.files[client_id] >= repository_client.fp[client_id].maxfiles)
|
||||
if (repository_client.files[client_id] >= repository_client.fp[client_id].maxfiles &&
|
||||
repository_client.fp[client_id].maxfiles != -1)
|
||||
{
|
||||
alert('Only '+repository_client.fp[client_id].maxfiles+' files are allowed!');
|
||||
return false;
|
||||
|
|
|
@ -19,7 +19,7 @@ class repository_upload extends repository {
|
|||
* @param array $options
|
||||
*/
|
||||
public function __construct($repositoryid, $context = SITEID, $options = array()){
|
||||
global $SESSION, $action, $CFG;
|
||||
global $_FILES, $SESSION, $action, $CFG;
|
||||
parent::__construct($repositoryid, $context, $options);
|
||||
$itemid = optional_param('itemid', '', PARAM_INT);
|
||||
if($action=='upload'){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue