2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* A field that will upload files to a page
|
|
|
|
* for use within the CMS.
|
|
|
|
*/
|
|
|
|
class FileIFrameField extends FileField {
|
|
|
|
|
|
|
|
public function Field() {
|
|
|
|
$data = $this->form->getRecord();
|
|
|
|
|
|
|
|
if($data->ID && is_numeric($data->ID)) {
|
|
|
|
$idxField = $this->name . 'ID';
|
|
|
|
$hiddenField = "<input type=\"hidden\" id=\"" . $this->id() . "\" name=\"$idxField\" value=\"" . $this->attrValue() . "\" />";
|
|
|
|
|
|
|
|
$parentClass = $data->class;
|
|
|
|
|
|
|
|
$parentID = $data->ID;
|
|
|
|
$parentField = $this->name;
|
2007-11-12 23:20:54 +01:00
|
|
|
$iframe = "<iframe name=\"{$this->name}_iframe\" src=\"images/iframe/$parentClass/$parentID/$parentField\" style=\"height: 152px; width: 600px; border-style: none;\"></iframe>";
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
return $iframe . $hiddenField;
|
|
|
|
|
|
|
|
} else {
|
2007-10-25 04:47:45 +02:00
|
|
|
$this->value = _t('FileIframeField.NOTEADDFILES', 'You can add files once you have saved for the first time.');
|
2007-07-19 12:40:28 +02:00
|
|
|
return FormField::Field();
|
|
|
|
}
|
|
|
|
}
|
2007-10-18 01:10:04 +02:00
|
|
|
|
|
|
|
public function saveInto(DataObject $record) {
|
|
|
|
$fieldName = $this->name . 'ID';
|
|
|
|
$hasOnes = $record->has_one($this->name);
|
|
|
|
if(!$hasOnes) $hasOnes = $record->has_one($fieldName);
|
|
|
|
|
|
|
|
// assume that the file is connected via a has-one
|
|
|
|
if( !$hasOnes || !$_FILES[$this->name]['name']){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$file = new File();
|
|
|
|
$file->loadUploaded($_FILES[$this->name]);
|
|
|
|
|
|
|
|
$record->$fieldName = $file->ID;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
?>
|