"MDL-17316, fix upload form in non-js file picker"

This commit is contained in:
dongsheng 2009-06-18 06:31:51 +00:00
parent b556308033
commit ab9cdbb976
6 changed files with 41 additions and 17 deletions

View file

@ -1,7 +1,7 @@
<?php //$Id$ <?php //$Id$
$string['accessiblefilepicker']='Accessible file picker'; $string['accessiblefilepicker']='Accessible file picker';
$string['activerepository'] = 'Active repository plugins'; $string['activerepository'] = 'Active repository plugins';
$string['add'] = 'Add'; $string['add'] = 'Add...';
$string['addplugin'] = 'Add a repository plugin'; $string['addplugin'] = 'Add a repository plugin';
$string['activaterep'] = 'Active repositories'; $string['activaterep'] = 'Active repositories';
$string['areabackup'] = 'Backups'; $string['areabackup'] = 'Backups';
@ -104,5 +104,6 @@ $string['typenotvisible'] = 'Type not visible';
$string['updown'] = 'Display order'; $string['updown'] = 'Display order';
$string['upload'] = 'Upload this file'; $string['upload'] = 'Upload this file';
$string['uploading'] = 'Uploading...'; $string['uploading'] = 'Uploading...';
$string['uploadsucc'] = 'The file has been uploaded successfully';
$string['wrongcontext'] = 'You cannot access to this context'; $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'; $string['xhtmlerror'] = 'You are probably using XHTML strict header, some YUI Component doesn\'t work in this mode, please turn it off in moodle';

View file

@ -173,7 +173,12 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
$str .= $repo_info['js']; $str .= $repo_info['js'];
$str .= <<<EOD $str .= <<<EOD
<input value="$draftitemid" name="{$this->_attributes['name']}" type="hidden" /> <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; EOD;
if (empty($CFG->filemanagerjsloaded)) { if (empty($CFG->filemanagerjsloaded)) {
$str .= <<<EOD $str .= <<<EOD
@ -224,7 +229,6 @@ function callpicker(el_id, client_id, itemid) {
//]]> //]]>
</script> </script>
<noscript> <noscript>
<a name="nonjsfp"></a>
<object type="text/html" data="{$CFG->httpswwwroot}/repository/filepicker.php?action=embedded&amp;itemid={$draftitemid}&amp;ctx_id=$context->id" height="300" width="800" style="border:1px solid #000">Error</object> <object type="text/html" data="{$CFG->httpswwwroot}/repository/filepicker.php?action=embedded&amp;itemid={$draftitemid}&amp;ctx_id=$context->id" height="300" width="800" style="border:1px solid #000">Error</object>
</noscript> </noscript>
EOD; EOD;

View file

@ -65,6 +65,8 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
return $this->getFrozenHtml(); return $this->getFrozenHtml();
} }
$strsaved = get_string('filesaved', 'repository');
$straddfile = get_string('openpicker', 'repository');
$currentfile = ''; $currentfile = '';
$draftvalue = ''; $draftvalue = '';
if ($draftid = (int)$this->getValue()) { if ($draftid = (int)$this->getValue()) {
@ -76,7 +78,6 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
$draftvalue = 'value="'.$draftid.'"'; $draftvalue = 'value="'.$draftid.'"';
} }
} }
$strsaved = get_string('filesaved', 'repository');
if ($COURSE->id == SITEID) { if ($COURSE->id == SITEID) {
$context = get_context_instance(CONTEXT_SYSTEM); $context = get_context_instance(CONTEXT_SYSTEM);
} else { } else {
@ -90,8 +91,11 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
$str = $this->_getTabs(); $str = $this->_getTabs();
$str .= '<input type="hidden" name="'.$elname.'" id="'.$id.'" '.$draftvalue.' />'; $str .= '<input type="hidden" name="'.$elname.'" id="'.$id.'" '.$draftvalue.' />';
$str .= $repository_info['css'].$repository_info['js'];
$str .= <<<EOD $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"> <script type="text/javascript">
function updatefile(client_id, obj) { function updatefile(client_id, obj) {
document.getElementById('repo_info_'+client_id).innerHTML = obj['file']; document.getElementById('repo_info_'+client_id).innerHTML = obj['file'];
@ -104,15 +108,20 @@ function callpicker(client_id, id) {
var el=document.getElementById(id); var el=document.getElementById(id);
var params = {}; var params = {};
params.env = 'filepicker'; params.env = 'filepicker';
params.itemid = itemid;
params.maxbytes = $this->_options['maxbytes']; params.maxbytes = $this->_options['maxbytes'];
params.maxfiles = $this->_options['maxfiles']; params.maxfiles = $this->_options['maxfiles'];
params.target = el; params.target = el;
params.callback = updatefile; params.callback = updatefile;
open_filepicker(client_id, params); open_filepicker(client_id, params);
return false;
} }
</script> </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; 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; return $str;
} }

View file

@ -62,6 +62,9 @@ if (file_exists($CFG->dirroot.'/repository/'.$type.'/repository.class.php')) {
//$PAGE->set_course($context); //$PAGE->set_course($context);
switch ($action) { switch ($action) {
case 'upload':
redirect($url, get_string('uploadsucc','repository'));
break;
case 'deletedraft': case 'deletedraft':
if (!$context = get_context_instance(CONTEXT_USER, $USER->id)) { if (!$context = get_context_instance(CONTEXT_USER, $USER->id)) {
print_error('wrongcontextid', 'error'); print_error('wrongcontextid', 'error');
@ -85,9 +88,11 @@ case 'sign':
$list = $repo->get_listing($req_path); $list = $repo->get_listing($req_path);
$dynload = !empty($list['dynload'])?true:false; $dynload = !empty($list['dynload'])?true:false;
if (!empty($list['upload'])) { if (!empty($list['upload'])) {
echo '<form method="post" style="display:inline">'; echo '<form action="'.$url.'" method="post" enctype="multipart/form-data" style="display:inline">';
echo '<label>'.$list['upload']['label'].'</label>'; echo '<label>'.$list['upload']['label'].': </label>';
echo '<input type="file" name="repo_upload_file" /><br />'; 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 '<input type="submit" value="'.get_string('upload', 'repository').'" />';
echo '</form>'; echo '</form>';
} else { } else {
@ -194,6 +199,17 @@ case 'confirm':
echo '</form>'; echo '</form>';
print_footer('empty'); print_footer('empty');
break; 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: default:
$user_context = get_context_instance(CONTEXT_USER, $USER->id); $user_context = get_context_instance(CONTEXT_USER, $USER->id);
$repos = repository::get_instances(array($user_context, get_system_context()), null, true, null, '*', 'ref_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(); $fs = get_file_storage();
$context = get_context_instance(CONTEXT_USER, $USER->id); $context = get_context_instance(CONTEXT_USER, $USER->id);
$files = $fs->get_area_files($context->id, 'user_draft', $itemid); $files = $fs->get_area_files($context->id, 'user_draft', $itemid);
echo '<h2>'.get_string('attachedfiles', 'repository').'</h2>';
if (empty($files)) { if (empty($files)) {
echo get_string('nofilesattached', 'repository'); echo get_string('nofilesattached', 'repository');
} else { } else {
@ -215,13 +230,7 @@ default:
} }
echo '</ul>'; echo '</ul>';
} }
echo '<h2>'.get_string('plugin', 'repository').'</h2>'; echo '<div><a href="'.$url.'&action=plugins">'.get_string('add', 'repository').'</a></div>';
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>';
print_footer('empty'); print_footer('empty');
break; break;
} }

View file

@ -571,7 +571,8 @@ repository_client.select_file = function(oldname, url, icon, client_id, repo_id)
if (repository_client.files[client_id] == undefined) { if (repository_client.files[client_id] == undefined) {
repository_client.files[client_id] = 0; 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!'); alert('Only '+repository_client.fp[client_id].maxfiles+' files are allowed!');
return false; return false;

View file

@ -19,7 +19,7 @@ class repository_upload extends repository {
* @param array $options * @param array $options
*/ */
public function __construct($repositoryid, $context = SITEID, $options = array()){ public function __construct($repositoryid, $context = SITEID, $options = array()){
global $SESSION, $action, $CFG; global $_FILES, $SESSION, $action, $CFG;
parent::__construct($repositoryid, $context, $options); parent::__construct($repositoryid, $context, $options);
$itemid = optional_param('itemid', '', PARAM_INT); $itemid = optional_param('itemid', '', PARAM_INT);
if($action=='upload'){ if($action=='upload'){