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');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HTML class for a button type element
|
|
|
|
*
|
|
|
|
* @author Dongsheng Cai <dongsheng@cvs.moodle.org>
|
|
|
|
* @version 1.0
|
|
|
|
* @since Moodle 2.0
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
class MoodleQuickForm_filepicker extends HTML_QuickForm_button
|
|
|
|
{
|
|
|
|
var $_helpbutton='';
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
function getHelpButton(){
|
|
|
|
return $this->_helpbutton;
|
|
|
|
}
|
|
|
|
function getElementTemplateType(){
|
|
|
|
if ($this->_flagFrozen){
|
|
|
|
return 'nodisplay';
|
|
|
|
} else {
|
|
|
|
return 'default';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function toHtml() {
|
|
|
|
global $CFG;
|
|
|
|
if ($this->_flagFrozen) {
|
|
|
|
return $this->getFrozenHtml();
|
|
|
|
} else {
|
2008-08-05 05:12:30 +00:00
|
|
|
$strsaved = get_string('filesaved', 'repository');
|
|
|
|
$itemid = time();
|
2008-07-31 02:51:28 +00:00
|
|
|
$ret = get_repository_client();
|
2008-08-04 05:53:53 +00:00
|
|
|
$str = $this->_getTabs();
|
2008-08-05 05:12:30 +00:00
|
|
|
$str .= '<input type="hidden" value="'.$itemid.'" name="repo_attachment" id="repo_value" />';
|
|
|
|
$suffix = $ret['suffix'];
|
2008-08-04 05:53:53 +00:00
|
|
|
$str .= <<<EOD
|
|
|
|
<script type="text/javascript">
|
2008-08-05 05:12:30 +00:00
|
|
|
function updatefile(){
|
|
|
|
alert('$strsaved');
|
|
|
|
document.getElementById('repo_info').innerHTML = '$strsaved';
|
|
|
|
}
|
|
|
|
function callpicker_$suffix(){
|
2008-08-04 05:53:53 +00:00
|
|
|
var el=document.getElementById('repo_value');
|
2008-08-05 05:12:30 +00:00
|
|
|
openpicker_$suffix({"env":"form", 'itemid': $itemid, 'target':el, 'callback':updatefile})
|
2008-08-04 05:53:53 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
EOD;
|
2008-08-05 05:12:30 +00:00
|
|
|
$str .= '<input' . $this->_getAttrString($this->_attributes) . ' onclick=\'callpicker_'.$suffix.'()\' />'.'<span id="repo_info" style="color:green"></span>'.$ret['html'].$ret['js'];
|
2008-08-04 05:53:53 +00:00
|
|
|
return $str;
|
2008-07-31 02:51:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|