Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/data/field/textarea/field.class.php
Go to the documentation of this file.
00001 <?php
00003 //                                                                       //
00004 // NOTICE OF COPYRIGHT                                                   //
00005 //                                                                       //
00006 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
00007 //          http://moodle.org                                            //
00008 //                                                                       //
00009 // Copyright (C) 1999-onwards Moodle Pty Ltd  http://moodle.com          //
00010 //                                                                       //
00011 // This program is free software; you can redistribute it and/or modify  //
00012 // it under the terms of the GNU General Public License as published by  //
00013 // the Free Software Foundation; either version 2 of the License, or     //
00014 // (at your option) any later version.                                   // //                                                                       //
00015 // This program is distributed in the hope that it will be useful,       //
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
00018 // GNU General Public License for more details:                          //
00019 //                                                                       //
00020 //          http://www.gnu.org/copyleft/gpl.html                         //
00021 //                                                                       //
00023 
00024 require_once($CFG->dirroot.'/lib/filelib.php');
00025 require_once($CFG->dirroot.'/repository/lib.php');
00026 
00027 class data_field_textarea extends data_field_base {
00028 
00029     var $type = 'textarea';
00030 
00031     function display_add_field($recordid=0) {
00032         global $CFG, $DB, $OUTPUT, $PAGE;
00033 
00034         $text   = '';
00035         $format = 0;
00036 
00037         $str = '<div title="'.$this->field->description.'">';
00038 
00039         editors_head_setup();
00040 
00041         $options = array();
00042         $options['trusttext'] = false;
00043         $options['forcehttps'] = false;
00044         $options['subdirs'] = false;
00045         $options['maxfiles'] = 0;
00046         $options['maxbytes'] = 0;
00047         $options['changeformat'] = 0;
00048         $options['noclean'] = false;
00049 
00050         $itemid = $this->field->id;
00051         $field = 'field_'.$itemid;
00052 
00053         if ($recordid && $content = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))){
00054             $text   = $content->content;
00055             $format = $content->content1;
00056             $text = clean_text($text, $format);
00057         } else if (can_use_html_editor()) {
00058             $format = FORMAT_HTML;
00059         } else {
00060             $format = FORMAT_PLAIN;
00061         }
00062 
00063         $editor = editors_get_preferred_editor($format);
00064         $strformats = format_text_menu();
00065         $formats =  $editor->get_supported_formats();
00066         foreach ($formats as $fid) {
00067             $formats[$fid] = $strformats[$fid];
00068         }
00069         $editor->use_editor($field, $options);
00070         $str .= '<div><textarea id="'.$field.'" name="'.$field.'" rows="'.$this->field->param3.'" cols="'.$this->field->param2.'">'.s($text).'</textarea></div>';
00071         $str .= '<div><select name="'.$field.'_content1">';
00072         foreach ($formats as $key=>$desc) {
00073             $selected = ($format == $key) ? 'selected="selected"' : '';
00074             $str .= '<option value="'.s($key).'" '.$selected.'>'.$desc.'</option>';
00075         }
00076         $str .= '</select>';
00077         $str .= '</div>';
00078 
00079         $str .= '</div>';
00080         return $str;
00081     }
00082 
00083 
00084     function display_search_field($value = '') {
00085         return '<input type="text" size="16" name="f_'.$this->field->id.'" value="'.$value.'" />';
00086     }
00087 
00088     function parse_search_field() {
00089         return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS);
00090     }
00091 
00092     function generate_sql($tablealias, $value) {
00093         global $DB;
00094 
00095         static $i=0;
00096         $i++;
00097         $name = "df_textarea_$i";
00098         return array(" ({$tablealias}.fieldid = {$this->field->id} AND ".$DB->sql_like("{$tablealias}.content", ":$name", false).") ", array($name=>"%$value%"));
00099     }
00100 
00101     function print_after_form() {
00102     }
00103 
00104 
00105     function update_content($recordid, $value, $name='') {
00106         global $DB;
00107 
00108         $content = new stdClass();
00109         $content->fieldid = $this->field->id;
00110         $content->recordid = $recordid;
00111 
00112         $names = explode('_', $name);
00113         if (!empty($names[2])) {
00114             $content->$names[2] = clean_param($value, PARAM_NOTAGS);  // content[1-4]
00115         } else {
00116             $content->content = clean_param($value, PARAM_CLEAN);
00117         }
00118 
00119         if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
00120             $content->id = $oldcontent->id;
00121             return $DB->update_record('data_content', $content);
00122         } else {
00123             return $DB->insert_record('data_content', $content);
00124         }
00125     }
00126 }
00127 
 All Data Structures Namespaces Files Functions Variables Enumerations