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];
$path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid;
if ($CFG->slasharguments) {
$source = $CFG->wwwroot.'/file.php/'.$path;
} else {
$source = $CFG->wwwroot.'/file.php?file=/'.$path;
}
} else {
$src = '';
$name = '';
$displayname = '';
$source = '';
}
$str = '
';
$str .= '
';
$str .= '';
if ($recordid and isset($content)){ // Print icon
require_once($CFG->libdir.'/filelib.php');
$icon = mimeinfo('icon', $src);
$str .= '
'.
''.$name.'';
}
return $str;
}
function display_browse_field($recordid, $template) {
global $CFG;
if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)){
$contents[0] = $content->content;
$contents[1] = $content->content1;
$src = empty($contents[0])? '':$contents[0];
$name = empty($contents[1])? $src:$contents[1];
$path = $this->data->course.'/'.$CFG->moddata.'/data/'.$this->data->id.'/'.$this->field->id.'/'.$recordid;
if ($CFG->slasharguments) {
$source = $CFG->wwwroot.'/file.php/'.$path;
} else {
$source = $CFG->wwwroot.'/file.php?file=/'.$path;
}
$width = $this->field->param1 ? ' width = "'.s($this->field->param1).'" ':' ';
$height = $this->field->param2 ? ' height = "'.s($this->field->param2).'" ':' ';
require_once($CFG->libdir.'/filelib.php');
$icon = mimeinfo('icon', $src);
$str = '
'.
''.$name.'';
return $str;
}
return false;
}
/// content = a ## b where a is the filename, b is the display file 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 heer!!
$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;
}
}
?>