MDL-39888 mnet: Removal of an old sql statement invloving the mdl_log table.
[moodle.git] / lib / form / url.php
blob2e62463328135ac2e9ea1d423816da0f0adb92ef
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * url type form element
21 * Contains HTML class for a url type element
23 * @package core_form
24 * @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 require_once("HTML/QuickForm/text.php");
30 /**
31 * url type form element
33 * HTML class for a url type element
34 * @package core_form
35 * @category form
36 * @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 class MoodleQuickForm_url extends HTML_QuickForm_text{
40 /** @var string html for help button, if empty then no help */
41 var $_helpbutton='';
43 /** @var bool if true label will be hidden */
44 var $_hiddenLabel=false;
46 /**
47 * Constructor
49 * @param string $elementName Element name
50 * @param mixed $elementLabel Label(s) for an element
51 * @param mixed $attributes Either a typical HTML attribute string or an associative array.
52 * @param array $options data which need to be posted.
54 function MoodleQuickForm_url($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
55 global $CFG;
56 require_once("$CFG->dirroot/repository/lib.php");
57 $options = (array)$options;
58 foreach ($options as $name=>$value) {
59 $this->_options[$name] = $value;
61 if (!isset($this->_options['usefilepicker'])) {
62 $this->_options['usefilepicker'] = true;
64 parent::HTML_QuickForm_text($elementName, $elementLabel, $attributes);
67 /**
68 * Sets label to be hidden
70 * @param bool $hiddenLabel sets if label should be hidden
72 function setHiddenLabel($hiddenLabel){
73 $this->_hiddenLabel = $hiddenLabel;
76 /**
77 * Returns HTML for this form element.
79 * @return string
81 function toHtml(){
82 global $PAGE, $OUTPUT;
84 $id = $this->_attributes['id'];
85 $elname = $this->_attributes['name'];
87 if ($this->_hiddenLabel) {
88 $this->_generateId();
89 $str = '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.
90 $this->getLabel().'</label>'.parent::toHtml();
91 } else {
92 $str = parent::toHtml();
94 if (empty($this->_options['usefilepicker'])) {
95 return $str;
98 $client_id = uniqid();
100 $args = new stdClass();
101 $args->accepted_types = '*';
102 $args->return_types = FILE_EXTERNAL;
103 $args->context = $PAGE->context;
104 $args->client_id = $client_id;
105 $args->env = 'url';
106 $fp = new file_picker($args);
107 $options = $fp->options;
109 if (count($options->repositories) > 0) {
110 $straddlink = get_string('choosealink', 'repository');
111 $str .= <<<EOD
112 <button id="filepicker-button-{$client_id}" class="visibleifjs">
113 $straddlink
114 </button>
115 EOD;
118 // print out file picker
119 $str .= $OUTPUT->render($fp);
121 $module = array('name'=>'form_url', 'fullpath'=>'/lib/form/url.js', 'requires'=>array('core_filepicker'));
122 $PAGE->requires->js_init_call('M.form_url.init', array($options), true, $module);
124 return $str;
128 * get html for help button
130 * @return string html for help button
132 function getHelpButton(){
133 return $this->_helpbutton;
137 * Slightly different container template when frozen. Don't want to use a label tag
138 * with a for attribute in that case for the element label but instead use a div.
139 * Templates are defined in renderer constructor.
141 * @return string
143 function getElementTemplateType(){
144 if ($this->_flagFrozen){
145 return 'static';
146 } else {
147 return 'default';