2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2008-09-28 15:08:56 +02:00
|
|
|
* A field that will upload attached images within the CMS through an iframe.
|
|
|
|
* If you want to upload images without iframes, see {@link SimpleImageField}.
|
|
|
|
*
|
|
|
|
* @uses Image_Upload
|
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-files
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class ImageField extends FileField {
|
2007-09-15 23:40:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
public function Field($id = null) {
|
|
|
|
$data = $this->form->getRecord();
|
|
|
|
|
2007-09-15 23:40:28 +02:00
|
|
|
if($id && is_numeric($id)) {
|
|
|
|
$parentID = $id;
|
|
|
|
} elseif($data) {
|
|
|
|
$parentID = $data->ID;
|
|
|
|
} else {
|
|
|
|
$parentID = null;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if($data && $parentID && is_numeric($parentID)) {
|
|
|
|
$idxField = $this->name . 'ID';
|
2007-09-15 23:40:28 +02:00
|
|
|
$hiddenField = "<input class=\"hidden\" type=\"hidden\" id=\"" .
|
|
|
|
$this->id() . "\" name=\"$idxField\" value=\"" . $this->attrValue() . "\" />";
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
$parentClass = $data->class;
|
|
|
|
$parentField = $this->name;
|
2007-09-15 23:40:28 +02:00
|
|
|
|
2008-01-30 21:12:19 +01:00
|
|
|
$iframe = "<iframe name=\"{$this->name}_iframe\" src=\"images/iframe/$parentClass/$parentID/$parentField\" style=\"height: 152px; width: 525px; border: none;\" frameborder=\"0\"></iframe>";
|
2007-09-15 23:40:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $iframe . $hiddenField;
|
|
|
|
} else {
|
2007-10-25 04:47:45 +02:00
|
|
|
$this->value = _t('ImageField.NOTEADDIMAGES', 'You can add images once you have saved for the first time.');
|
2007-07-19 12:40:28 +02:00
|
|
|
return FormField::Field();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-15 23:40:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
public function saveInto($record) {
|
|
|
|
$data = $this->form->getRecord();
|
2007-09-15 23:40:28 +02:00
|
|
|
// if the record was written for the first time (has an arbitrary "new"-ID),
|
|
|
|
// update the imagefield to enable uploading
|
2007-09-16 03:50:43 +02:00
|
|
|
if($record->ID && $data && substr($data->ID, 0, 3) == 'new') {
|
2007-07-19 12:40:28 +02:00
|
|
|
FormResponse::update_dom_id($this->id(), $this->Field($record->ID));
|
|
|
|
}
|
|
|
|
}
|
2007-09-15 23:40:28 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a readonly version of this field
|
|
|
|
*/
|
|
|
|
function performReadonlyTransformation() {
|
2008-12-04 23:38:32 +01:00
|
|
|
$field = new SimpleImageField_Disabled($this->name, $this->title, $this->value);
|
2007-07-19 12:40:28 +02:00
|
|
|
$field->setForm($this->form);
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
}
|
2007-09-15 23:40:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
?>
|