2 ///////////////////////////////////////////////////////////////////////////
4 // NOTICE OF COPYRIGHT //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // http://moodle.org //
9 // Copyright (C) 1999-onwards Moodle Pty Ltd http://moodle.com //
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. //
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: //
21 // http://www.gnu.org/copyleft/gpl.html //
23 ///////////////////////////////////////////////////////////////////////////
25 class data_field_url
extends data_field_base
{
29 function data_field_text($field=0, $data=0) {
30 parent
::data_field_base($field, $data);
33 function display_add_field($recordid=0){
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>';
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" />';
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://')) {
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.
88 $str = '<a href="'.$url.'">'.$text.'</a>';
90 $str = '<a href="'.$url.'">'.$url.'</a>';
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);
107 case 0: // update link
108 $content->content
= clean_param($value, PARAM_URL
);
111 $content->content1
= clean_param($value, PARAM_NOTAGS
);
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);
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));