2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A field that will upload attached images.
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
2007-09-14 21:20:43 +02:00
|
|
|
$iframe = "<iframe name=\"{$this->name}_iframe\" src=\"images/iframe/$parentClass/$parentID/$parentField\" style=\"height: 152px; width: 600px; border-style: none;\"></iframe>";
|
2007-09-15 23:40:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $iframe . $hiddenField;
|
|
|
|
} else {
|
|
|
|
$this->value = 'You can add images once you have saved for the first time.';
|
|
|
|
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() {
|
2007-09-15 23:40:28 +02: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
|
|
|
?>
|