Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r8687 -r8705 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 8687) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 8705) @@ -715,6 +715,17 @@ if ( substr($event->Special, -6) == 'import') { $this->setCustomExportColumns($event); } + + if (!$this->Application->IsAdmin()) { + $image_helper =& $this->Application->recallObject('ImageHelper'); + /* @var $image_helper ImageHelper */ + + $object =& $event->getObject(); + /* @var $object kDBItem */ + + // process image upload in virtual fields + $image_helper->SaveItemImages($object); + } } /** @@ -727,6 +738,17 @@ if ( substr($event->Special, -6) == 'import') { $this->setCustomExportColumns($event); } + + if (!$this->Application->IsAdmin()) { + $image_helper =& $this->Application->recallObject('ImageHelper'); + /* @var $image_helper ImageHelper */ + + $object =& $event->getObject(); + /* @var $object kDBItem */ + + // process image upload in virtual fields + $image_helper->SaveItemImages($object); + } } /** Index: trunk/core/units/images/image_tag_processor.php =================================================================== diff -u -N -r8687 -r8705 --- trunk/core/units/images/image_tag_processor.php (.../image_tag_processor.php) (revision 8687) +++ trunk/core/units/images/image_tag_processor.php (.../image_tag_processor.php) (revision 8705) @@ -48,6 +48,7 @@ function LoadItemImage($params) { $parent_item =& $this->Application->recallObject($params['PrefixSpecial']); + /* @var $parent_item kCatDBItem */ $object =& $this->Application->recallObject($this->getPrefixSpecial(), null, Array('skip_autoload' => true)); /* @var $object kDBItem */ @@ -88,7 +89,7 @@ elseif (getArrayValue($params, 'field')) { // by virtual field name in main object $field_options = $parent_item->GetFieldOptions($params['field']); - $keys['Name'] = $field_options['original_field']; + $keys['Name'] = isset($field_options['original_field']) ? $field_options['original_field'] : $params['field']; } elseif ($image_id) { // by ID @@ -100,6 +101,29 @@ } $object->Load($keys); + + if (isset($params['field'])) { + $image_src = $parent_item->GetDBField($params['field']); + + // when image is uploaded to virtual field in main item, but not saved to db + $object->SetDBField('ThumbPath', $image_src); + + if (!$object->isLoaded()) { + // set fields for displaing new image during main item suggestion with errors + $fields_hash = Array ( + 'Url' => '', + 'ThumbUrl' => '', + 'LocalPath' => '', + + 'SameImages' => 1, + 'LocalThumb' => 1, + 'LocalImage' => 1, + ); + + $object->SetDBFieldsFromHash($fields_hash); + $object->Loaded = true; + } + } } } Index: trunk/core/units/general/helpers/image_helper.php =================================================================== diff -u -N -r8687 -r8705 --- trunk/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 8687) +++ trunk/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 8705) @@ -161,6 +161,7 @@ if (preg_match('/^(Image[\d]+|PrimaryImage)$/', $field_name)) { $fields[$field_name] = $field_options; $virtual_fields[$field_name] = $field_options; + $virtual_fields['Delete'.$field_name] = Array ('type' => 'int', 'not_null' => 1, 'default' => 0); $image_count++; } } @@ -203,7 +204,7 @@ $image_counter = 1; foreach ($item_images as $item_image) { - $image_path = preg_replace('/^'.preg_quote(IMAGES_PATH, '/').'(.*)/', '\\1', $item_image['ThumbPath']); + $image_path = $item_image['ThumbPath']; if ($item_image['DefaultImg'] == 1 || $item_image['Name'] == 'main') { // process primary image separately $object->SetDBField('PrimaryImage', $image_path); @@ -216,6 +217,65 @@ $image_counter++; } } + + /** + * Saves newly uploaded images to external image table + * + * @param kCatDBItem $object + */ + function SaveItemImages(&$object) + { + $table_name = $this->Application->getUnitOption('img', 'TableName'); + $max_image_count = $this->Application->getUnitOption($object->Prefix, 'ImageCount'); // $this->Application->ConfigValue($object->Prefix.'_MaxImageCount'); + + $i = 0; + while ($i < $max_image_count) { + $field = $i ? 'Image'.$i : 'PrimaryImage'; + $field_options = $object->GetFieldOptions($field); + + $image_src = $object->GetDBField($field); + if ($image_src) { + if (isset($field_options['original_field'])) { + $key_clause = 'Name = '.$this->Conn->qstr($field_options['original_field']).' AND ResourceId = '.$object->GetDBField('ResourceId'); + + if ($object->GetDBField('Delete'.$field)) { + // if item was cloned, then new filename is in db (not in $image_src) + $sql = 'SELECT ThumbPath + FROM '.$table_name.' + WHERE '.$key_clause; + $image_src = $this->Conn->GetOne($sql); + if (@unlink(FULL_PATH.$image_src)) { + $sql = 'DELETE FROM '.$table_name.' + WHERE '.$key_clause; + $this->Conn->Query($sql); + } + } + else { + // image record found -> update + $fields_hash = Array ( + 'ThumbPath' => $image_src, + ); + + $this->Conn->doUpdate($fields_hash, $table_name, $key_clause); + } + } + else { + // image record not found -> create + $fields_hash = Array ( + 'ResourceId' => $object->GetDBField('ResourceId'), + 'Name' => $field, + 'AltName' => $field, + 'Enabled' => STATUS_ACTIVE, + 'DefaultImg' => $i ? 0 : 1, // first image is primary, others not primary + 'ThumbPath' => $image_src, + ); + + $this->Conn->doInsert($fields_hash, $table_name); + } + } + $i++; + } + } } ?> \ No newline at end of file Index: trunk/kernel/units/images/image_tag_processor.php =================================================================== diff -u -N -r8687 -r8705 --- trunk/kernel/units/images/image_tag_processor.php (.../image_tag_processor.php) (revision 8687) +++ trunk/kernel/units/images/image_tag_processor.php (.../image_tag_processor.php) (revision 8705) @@ -48,6 +48,7 @@ function LoadItemImage($params) { $parent_item =& $this->Application->recallObject($params['PrefixSpecial']); + /* @var $parent_item kCatDBItem */ $object =& $this->Application->recallObject($this->getPrefixSpecial(), null, Array('skip_autoload' => true)); /* @var $object kDBItem */ @@ -88,7 +89,7 @@ elseif (getArrayValue($params, 'field')) { // by virtual field name in main object $field_options = $parent_item->GetFieldOptions($params['field']); - $keys['Name'] = $field_options['original_field']; + $keys['Name'] = isset($field_options['original_field']) ? $field_options['original_field'] : $params['field']; } elseif ($image_id) { // by ID @@ -100,6 +101,29 @@ } $object->Load($keys); + + if (isset($params['field'])) { + $image_src = $parent_item->GetDBField($params['field']); + + // when image is uploaded to virtual field in main item, but not saved to db + $object->SetDBField('ThumbPath', $image_src); + + if (!$object->isLoaded()) { + // set fields for displaing new image during main item suggestion with errors + $fields_hash = Array ( + 'Url' => '', + 'ThumbUrl' => '', + 'LocalPath' => '', + + 'SameImages' => 1, + 'LocalThumb' => 1, + 'LocalImage' => 1, + ); + + $object->SetDBFieldsFromHash($fields_hash); + $object->Loaded = true; + } + } } } Index: trunk/themes/default2007/platform/elements/forms.tpl =================================================================== diff -u -N -r8693 -r8705 --- trunk/themes/default2007/platform/elements/forms.tpl (.../forms.tpl) (revision 8693) +++ trunk/themes/default2007/platform/elements/forms.tpl (.../forms.tpl) (revision 8705) @@ -111,6 +111,17 @@
+ + + + + +
+ " name="" value="0" /> + " onchange="update_checkbox(this, document.getElementById(''));"> + + +
" tabindex="" style=""> [upload]" value="" />