forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
choosecoursefile.php
147 lines (133 loc) · 5.06 KB
/
choosecoursefile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php //$Id$
global $CFG;
require_once "$CFG->libdir/form/group.php";
/**
* Class for an element used to choose a file from the course files folder.
*
*
* @author Jamie Pratt <[email protected]>
* @access public
*/
class MoodleQuickForm_choosecoursefile extends MoodleQuickForm_group
{
/**
* Options for element :
*
* $url must be relative to home page eg /mod/survey/stuff.php
* courseid => int course id if null then uses $COURSE global
* width => int Height to assign to popup window
* title => string Text to be displayed as popup page title
* options => string List of additional options for popup window
*/
var $_options = array('courseid'=>null,
'height'=>500, 'width'=>750, 'options'=>'none');
/**
* These complement separators, they are appended to the resultant HTML
* @access private
* @var array
*/
var $_wrap = array('', '');
/**
* Class constructor
*
* @access public
* @param string Element's name
* @param mixed Label(s) for an element
* @param array Options to control the element's display
* @param mixed Either a typical HTML attribute string or an associative array
*/
function MoodleQuickForm_choosecoursefile($elementName = null, $elementLabel = null, $options = array(), $attributes = null)
{
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
$this->_appendName = true;
$this->_type = 'choosecoursefile';
// set the options, do not bother setting bogus ones
if (is_array($options)) {
foreach ($options as $name => $value) {
if (isset($this->_options[$name])) {
if (is_array($value) && is_array($this->_options[$name])) {
$this->_options[$name] = @array_merge($this->_options[$name], $value);
} else {
$this->_options[$name] = $value;
}
}
}
}
}
// }}}
// {{{ _createElements()
function _createElements() {
global $COURSE;
$this->_elements = array();
$this->_elements[0] =& MoodleQuickForm::createElement('text', 'value', '', array('size'=>'48'));
$this->_elements[1] =& MoodleQuickForm::createElement('button', 'popup', get_string('chooseafile', 'resource') .' ...');
$button =& $this->_elements[1];
if ($this->_options['courseid']!==null){
$courseid=$this->_options['courseid'];
} else {
$courseid=$COURSE->id;
}
// first find out the text field id - this is a bit hacky, is there a better way?
$choose = 'id_'.str_replace(array('[', ']'), array('_', ''), $this->getElementName(0));
$url="/files/index.php?id=$courseid&choose=".$choose;
if ($this->_options['options'] == 'none') {
$options = 'menubar=0,location=0,scrollbars,resizable,width='. $this->_options['width'] .',height='. $this->_options['height'];
}else{
$options = $this->_options['options'];
}
$fullscreen = 0;
$buttonattributes = array('title'=>get_string("chooseafile", "resource"),
'onclick'=>"return openpopup('$url', '".$button->getName()."', '$options', $fullscreen);");
$button->updateAttributes($buttonattributes);
}
/**
* Output a timestamp. Give it the name of the group.
*
* @param array $submitValues
* @param bool $assoc
* @return array
*/
function exportValue(&$submitValues, $assoc = false)
{
$value = null;
$valuearray = $this->_elements[0]->exportValue($submitValues[$this->getName()], true);
$value[$this->getName()]=$valuearray['value'];
return $value;
}
// }}}
/**
* Called by HTML_QuickForm whenever form event is made on this element
*
* @param string $event Name of event
* @param mixed $arg event arguments
* @param object $caller calling object
* @since 1.0
* @access public
* @return void
*/
function onQuickFormEvent($event, $arg, &$caller)
{
switch ($event) {
case 'updateValue':
// constant values override both default and submitted ones
// default values are overriden by submitted
$value = $this->_findValue($caller->_constantValues);
if (null === $value) {
$value = $this->_findValue($caller->_submitValues);
if (null === $value) {
$value = $this->_findValue($caller->_defaultValues);
}
}
if (!is_array($value)) {
$value = array('value' => $value);
}
if (null !== $value) {
$this->setValue($value);
}
return true;
break;
}
return parent::onQuickFormEvent($event, $arg, $caller);
} // end func onQuickFormEvent
}
?>