field->id, 'recordid', $recordid)) { $contents[0] = $content->content; $contents[1] = $content->content1; } else { $contents[0] = ''; $contents[1] = ''; } $src = empty($contents[0]) ? '' : $contents[0]; $name = empty($contents[1]) ? $src : $contents[1]; $displayname = empty($contents[1]) ? '' : $contents[1]; require_once($CFG->libdir.'/filelib.php'); $source = get_file_url($this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid); } else { $src = ''; $name = ''; $displayname = ''; $source = ''; } $str = '
'; $str .= '
'.$this->field->name.''; $str .= ''; $str .= get_string('file','data'). '
'; $str .= get_string('optionalfilename','data').'
'; $str .= ''; $str .= '
'; $str .= '
'; if ($recordid and isset($content) and !empty($content->content)) { // Print icon require_once($CFG->libdir.'/filelib.php'); $icon = mimeinfo('icon', $src); $str .= ''.$icon.''. ''.$name.''; } return $str; } function display_search_field($value = '') { return ''; } function generate_sql($tablealias, $value) { return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') "; } function parse_search_field() { return optional_param('f_'.$this->field->id, '', PARAM_NOTAGS); } function display_browse_field($recordid, $template) { global $CFG; if (!$content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) { return false; } $width = $this->field->param1 ? ' width = "'.s($this->field->param1).'" ':' '; $height = $this->field->param2 ? ' height = "'.s($this->field->param2).'" ':' '; if (empty($content->content)) { return ''; } require_once($CFG->libdir.'/filelib.php'); $src = $content->content; $name = empty($content->content1) ? $src : $content->content1; $source = get_file_url($this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid); $icon = mimeinfo('icon', $src); $str = ''.$icon.' '. ''.$name.''; return $str; } // content: "a##b" where a is the file name, b is the display name function update_content($recordid, $value, $name) { global $CFG; if (!$oldcontent = get_record('data_content','fieldid', $this->field->id, 'recordid', $recordid)) { // Quickly make one now! $oldcontent = new object; $oldcontent->fieldid = $this->field->id; $oldcontent->recordid = $recordid; if ($oldcontent->id = insert_record('data_content', $oldcontent)) { error('Could not make an empty record!'); } } $content = new object; $content->id = $oldcontent->id; $names = explode('_',$name); switch ($names[2]) { case 'file': // file just uploaded # $course = get_course('course', 'id', $this->data->course); $filename = $_FILES[$names[0].'_'.$names[1]]; $filename = $filename['name']; $dir = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid; // only use the manager if file is present, to avoid "are you sure you selected a file to upload" msg if ($filename){ require_once($CFG->libdir.'/uploadlib.php'); // FIX ME: $course not defined here $um = new upload_manager($names[0].'_'.$names[1],true,false,$this->data->course,false,$this->field->param3); if ($um->process_file_uploads($dir)) { $newfile_name = $um->get_new_filename(); $content->content = $newfile_name; update_record('data_content',$content); } } break; case 'filename': // only changing alt tag $content->content1 = clean_param($value, PARAM_NOTAGS); update_record('data_content', $content); break; default: break; } } function notemptyfield($value, $name) { $names = explode('_',$name); if ($names[2] == 'file') { $filename = $_FILES[$names[0].'_'.$names[1]]; return !empty($filename['name']); // if there's a file in $_FILES, not empty } return false; } function text_export_supported() { return false; } } ?>