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
{
28 function data_field_text($field=0, $data=0) {
29 parent
::data_field_base($field, $data);
32 function display_add_field($recordid=0) {
37 if ($content = get_record('data_content', 'fieldid', $this->field
->id
, 'recordid', $recordid)) {
38 $url = $content->content
;
39 $text = $content->content1
;
42 $url = empty($url) ?
'http://' : $url;
43 $str = '<div title="'.s($this->field
->description
).'">';
44 if (!empty($this->field
->param1
) and empty($this->field
->param2
)) {
45 $str .= '<table><tr><td align="right">';
46 $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>';
47 $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>';
51 $str .= '<input type="text" name="field_'.$this->field
->id
.'_0" id="field_'.$this->field
->id
.'_0" value="'.s($url).'" size="60" />';
57 function display_search_field($value = '') {
58 return '<input type="text" size="16" name="f_'.$this->field
->id
.'" value="'.$value.'" />';
61 function parse_search_field() {
62 return optional_param('f_'.$this->field
->id
, '', PARAM_NOTAGS
);
65 function generate_sql($tablealias, $value) {
66 return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') ";
69 function display_browse_field($recordid, $template) {
70 if ($content = get_record('data_content', 'fieldid', $this->field
->id
, 'recordid', $recordid)) {
71 $url = empty($content->content
)?
'':$content->content
;
72 $text = empty($content->content1
)?
'':$content->content1
;
73 if (empty($url) or ($url == 'http://')) {
76 if (!empty($this->field
->param2
)) {
77 // param2 forces the text to something
78 $text = $this->field
->param2
;
80 if ($this->field
->param1
) {
81 // param1 defines whether we want to autolink the url.
83 $str = '<a href="'.$url.'">'.$text.'</a>';
85 $str = '<a href="'.$url.'">'.$url.'</a>';
95 function update_content($recordid, $value, $name='') {
96 $content = new object;
97 $content->fieldid
= $this->field
->id
;
98 $content->recordid
= $recordid;
99 $names = explode('_', $name);
103 $content->content
= clean_param($value, PARAM_URL
);
107 $content->content1
= clean_param($value, PARAM_NOTAGS
);
113 if ($oldcontent = get_record('data_content','fieldid', $this->field
->id
, 'recordid', $recordid)) {
114 $content->id
= $oldcontent->id
;
115 return update_record('data_content', $content);
117 return insert_record('data_content', $content);
121 function notemptyfield($value, $name) {
122 $names = explode('_',$name);
123 $value = clean_param($value, PARAM_URL
);
125 if ($names[2] == '0') {
126 return ($value!='http://' && !empty($value));
131 function export_text_value($record) {
132 return $record->content
. " " . $record->content1
;