Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / data / field / url / field.class.php
blob6754af116f151e90f2efdfc39fd3b84100a7578b
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 {
26 var $type = 'url';
28 function data_field_text($field=0, $data=0) {
29 parent::data_field_base($field, $data);
32 function display_add_field($recordid=0) {
33 global $CFG;
34 $url = '';
35 $text = '';
36 if ($recordid) {
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>';
48 $str .= '</table>';
49 } else {
50 // Just the URL field
51 $str .= '<input type="text" name="field_'.$this->field->id.'_0" id="field_'.$this->field->id.'_0" value="'.s($url).'" size="60" />';
53 $str .= '</div>';
54 return $str;
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://')) {
74 return '';
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.
82 if (!empty($text)) {
83 $str = '<a href="'.$url.'">'.$text.'</a>';
84 } else {
85 $str = '<a href="'.$url.'">'.$url.'</a>';
87 } else {
88 $str = $url;
90 return $str;
92 return false;
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);
100 switch ($names[2]) {
101 case 0:
102 // update link
103 $content->content = clean_param($value, PARAM_URL);
104 break;
105 case 1:
106 // add text
107 $content->content1 = clean_param($value, PARAM_NOTAGS);
108 break;
109 default:
110 break;
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);
116 } else {
117 return insert_record('data_content', $content);
121 function notemptyfield($value, $name) {
122 $names = explode('_',$name);
123 $value = clean_param($value, PARAM_URL);
124 //clean first
125 if ($names[2] == '0') {
126 return ($value!='http://' && !empty($value));
128 return false;
131 function export_text_value($record) {
132 return $record->content . " " . $record->content1;