MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / mod / data / field / url / field.class.php
blob23c9138b4d62ed7261e91c4ef821634776d745af
1 <?php // $Id$
2 ///////////////////////////////////////////////////////////////////////////
3 // //
4 // NOTICE OF COPYRIGHT //
5 // //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // http://moodle.org //
8 // //
9 // Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
10 // //
11 // This program is free software; you can redistribute it and/or modify //
12 // it under the terms of the GNU General Public License as published by //
13 // the Free Software Foundation; either version 2 of the License, or //
14 // (at your option) any later version. //
15 // //
16 // This program is distributed in the hope that it will be useful, //
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
19 // GNU General Public License for more details: //
20 // //
21 // http://www.gnu.org/copyleft/gpl.html //
22 // //
23 ///////////////////////////////////////////////////////////////////////////
25 class data_field_url extends data_field_base {
27 var $type = 'url';
29 function data_field_text($field=0, $data=0) {
30 parent::data_field_base($field, $data);
33 function display_add_field($recordid=0){
34 global $CFG;
36 $url = '';
37 $text = '';
39 if ($recordid){
40 if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
41 $url = $content->content;
42 $text = $content->content1;
45 $url = empty($url) ? 'http://' : $url;
47 $str = '<div title="'.s($this->field->description).'">';
48 if (!empty($this->field->param1) and empty($this->field->param2)) {
49 $str .= '<table><tr><td align="right">';
50 $str .= get_string('url','data').':</td><td><input type="text" name="field_'.$this->field->id.'_0" id="field_'.$this->field->id.'_0" value="'.$url.'" size="60" /></td></tr>';
51 $str .= '<tr><td align="right">'.get_string('text','data').':</td><td><input type="text" name="field_'.$this->field->id.'_1" id="field_'.$this->field->id.'_1" value="'.s($text).'" size="60" /></td></tr>';
52 $str .= '</table>';
53 } else { // Just the URL field
54 $str .= '<input type="text" name="field_'.$this->field->id.'_0" id="field_'.$this->field->id.'_0" value="'.s($url).'" size="60" />';
56 $str .= '</div>';
58 return $str;
61 function display_search_field($value = '') {
62 return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />';
65 function parse_search_field() {
66 return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
69 function generate_sql($tablealias, $value) {
70 return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') ";
73 function display_browse_field($recordid, $template) {
74 if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){
75 $url = empty($content->content)? '':$content->content;
76 $text = empty($content->content1)? '':$content->content1;
78 if (empty($url) or ($url == 'http://')) {
79 return '';
82 if (!empty($this->field->param2)) { // param2 forces the text to something
83 $text = $this->field->param2;
86 if ($this->field->param1) { // param1 defines whether we want to autolink the url.
87 if (!empty($text)) {
88 $str = '<a href="'.$url.'">'.$text.'</a>';
89 } else {
90 $str = '<a href="'.$url.'">'.$url.'</a>';
92 } else {
93 $str = $url;
95 return $str;
97 return false;
100 function update_content($recordid, $value, $name='') {
101 $content = new object;
102 $content->fieldid = $this->field->id;
103 $content->recordid = $recordid;
105 $names = explode('_', $name);
106 switch ($names[2]){
107 case 0: // update link
108 $content->content = clean_param($value, PARAM_URL);
109 break;
110 case 1: // add text
111 $content->content1 = clean_param($value, PARAM_NOTAGS);
112 break;
113 default:
114 break;
117 if ($oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) {
118 $content->id = $oldcontent->id;
119 return update_record('data_content', $content);
120 } else {
121 return insert_record('data_content', $content);
125 function notemptyfield($value, $name){
126 $names = explode('_',$name);
127 $value = clean_param($value, PARAM_URL); //clean first
128 if ($names[2] == '0'){
129 return ($value!='http://' && !empty($value));
131 return false;