2008-07-31 02:51:28 +00:00
|
|
|
<?php
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
require_once("HTML/QuickForm/button.php");
|
|
|
|
require_once(dirname(dirname(dirname(__FILE__))) . '/repository/lib.php');
|
|
|
|
|
|
|
|
/**
|
2008-09-08 05:41:45 +00:00
|
|
|
* HTML class for a single filepicker element (based on button)
|
2008-07-31 02:51:28 +00:00
|
|
|
*
|
2008-09-08 05:41:45 +00:00
|
|
|
* @author Moodle.com
|
2008-07-31 02:51:28 +00:00
|
|
|
* @version 1.0
|
|
|
|
* @since Moodle 2.0
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-09-07 13:30:46 +00:00
|
|
|
class MoodleQuickForm_filepicker extends HTML_QuickForm_button {
|
2008-07-31 02:51:28 +00:00
|
|
|
var $_helpbutton='';
|
2008-09-07 13:30:46 +00:00
|
|
|
|
|
|
|
function MoodleQuickForm_filepicker($elementName=null, $value=null, $attributes=null) {
|
2008-09-01 06:17:23 +00:00
|
|
|
HTML_QuickForm_input::HTML_QuickForm_input($elementName, $value, $attributes); // Set label cause button doesn't
|
2008-08-27 07:57:54 +00:00
|
|
|
parent::HTML_QuickForm_button($elementName, $value, $attributes);
|
|
|
|
}
|
2008-09-07 13:30:46 +00:00
|
|
|
|
2008-07-31 02:51:28 +00:00
|
|
|
function setHelpButton($helpbuttonargs, $function='helpbutton'){
|
|
|
|
if (!is_array($helpbuttonargs)){
|
|
|
|
$helpbuttonargs=array($helpbuttonargs);
|
|
|
|
}else{
|
|
|
|
$helpbuttonargs=$helpbuttonargs;
|
|
|
|
}
|
|
|
|
//we do this to to return html instead of printing it
|
|
|
|
//without having to specify it in every call to make a button.
|
|
|
|
if ('helpbutton' == $function){
|
|
|
|
$defaultargs=array('', '', 'moodle', true, false, '', true);
|
|
|
|
$helpbuttonargs=$helpbuttonargs + $defaultargs ;
|
|
|
|
}
|
|
|
|
$this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
|
|
|
|
}
|
2008-09-07 13:30:46 +00:00
|
|
|
|
2008-07-31 02:51:28 +00:00
|
|
|
function getHelpButton(){
|
|
|
|
return $this->_helpbutton;
|
|
|
|
}
|
2008-09-07 13:30:46 +00:00
|
|
|
|
2008-07-31 02:51:28 +00:00
|
|
|
function getElementTemplateType(){
|
|
|
|
if ($this->_flagFrozen){
|
|
|
|
return 'nodisplay';
|
|
|
|
} else {
|
|
|
|
return 'default';
|
|
|
|
}
|
|
|
|
}
|
2008-09-07 13:30:46 +00:00
|
|
|
|
2008-07-31 02:51:28 +00:00
|
|
|
function toHtml() {
|
2008-08-07 03:33:47 +00:00
|
|
|
global $CFG, $COURSE;
|
2008-07-31 02:51:28 +00:00
|
|
|
if ($this->_flagFrozen) {
|
|
|
|
return $this->getFrozenHtml();
|
|
|
|
} else {
|
2008-09-08 05:41:45 +00:00
|
|
|
$currentvalue = $this->getValue();
|
2008-09-07 13:30:46 +00:00
|
|
|
|
2008-09-08 05:41:45 +00:00
|
|
|
$strsaved = get_string('filesaved', 'repository');
|
2008-09-07 13:30:46 +00:00
|
|
|
if (empty($COURSE->context)) {
|
2008-09-08 05:41:45 +00:00
|
|
|
$context = get_context_instance(CONTEXT_SYSTEM);
|
2008-08-07 03:33:47 +00:00
|
|
|
} else {
|
2008-09-08 05:41:45 +00:00
|
|
|
$context = $COURSE->context;
|
2008-08-07 03:33:47 +00:00
|
|
|
}
|
2008-09-08 05:41:45 +00:00
|
|
|
$repository_info = repository_get_client($context);
|
|
|
|
$suffix = $repository_info['suffix'];
|
2008-09-07 13:30:46 +00:00
|
|
|
|
|
|
|
$id = $this->_attributes['id'];
|
|
|
|
$elname = $this->_attributes['name'];
|
|
|
|
|
2008-08-05 05:58:06 +00:00
|
|
|
$str = $this->_getTabs();
|
2008-09-08 05:41:45 +00:00
|
|
|
$str .= '<input type="hidden" value="'.$currentvalue.'" name="'.$this->_attributes['name'].'" id="'.$this->_attributes['id'].'_'.$suffix.'" />';
|
|
|
|
$id = $this->_attributes['id'];
|
|
|
|
|
2008-08-04 05:53:53 +00:00
|
|
|
$str .= <<<EOD
|
|
|
|
<script type="text/javascript">
|
2008-09-01 02:00:15 +00:00
|
|
|
function updatefile_$suffix(str){
|
|
|
|
document.getElementById('repo_info_$suffix').innerHTML = str;
|
2008-08-05 05:12:30 +00:00
|
|
|
}
|
|
|
|
function callpicker_$suffix(){
|
2008-08-20 02:52:29 +00:00
|
|
|
document.body.className += ' yui-skin-sam';
|
|
|
|
var picker = document.createElement('DIV');
|
|
|
|
picker.id = 'file-picker-$suffix';
|
2008-09-10 07:11:47 +00:00
|
|
|
picker.className = "file-picker";
|
2008-08-20 02:52:29 +00:00
|
|
|
document.body.appendChild(picker);
|
2008-08-06 03:26:57 +00:00
|
|
|
var el=document.getElementById('${id}_${suffix}');
|
2008-09-07 13:30:46 +00:00
|
|
|
openpicker_$suffix({"env":"form", 'target':el, 'callback':updatefile_$suffix})
|
2008-08-04 05:53:53 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
EOD;
|
2008-09-08 05:41:45 +00:00
|
|
|
$str .= '<input value ="'.get_string('openpicker', 'repository').'" type="button" onclick=\'callpicker_'.$suffix.'()\' />'.'<span id="repo_info_'.$suffix.'" class="notifysuccess">'.$currentvalue.'</span>'.$repository_info['css'].$repository_info['js'];
|
2008-08-04 05:53:53 +00:00
|
|
|
return $str;
|
2008-07-31 02:51:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-07 13:30:46 +00:00
|
|
|
|
2008-09-02 02:59:01 +00:00
|
|
|
function exportValue(&$submitValues, $assoc = false) {
|
|
|
|
return array($this->_attributes['name'] => $submitValues[$this->_attributes['name']]);
|
|
|
|
}
|
2008-07-31 02:51:28 +00:00
|
|
|
}
|