diff --git a/modules/layout/conf/module.xml b/modules/layout/conf/module.xml
index 136fcb376..e6c88917f 100644
--- a/modules/layout/conf/module.xml
+++ b/modules/layout/conf/module.xml
@@ -24,6 +24,8 @@
+
+
diff --git a/modules/layout/layout.admin.controller.php b/modules/layout/layout.admin.controller.php
index f77287207..4e172ba1d 100644
--- a/modules/layout/layout.admin.controller.php
+++ b/modules/layout/layout.admin.controller.php
@@ -148,31 +148,7 @@
foreach($layout_info->extra_var as $name => $vars) {
if($vars->type!='image') continue;
- $image_obj = $extra_vars->{$name};
- $extra_vars->{$name} = $layout_info->extra_var->{$name}->value;
- // Get a variable on a request to delete
- $del_var = $extra_vars->{"del_".$name};
- unset($extra_vars->{"del_".$name});
- // Delete the old file if there is a request to delete or a new file is uploaded
- if($del_var == 'Y' || $image_obj['tmp_name']) {
- FileHandler::removeFile($extra_vars->{$name});
- $extra_vars->{$name} = '';
- if($del_var == 'Y' && !$image_obj['tmp_name']) continue;
- }
- // Ignore if the file is not successfully uploaded
- if(!$image_obj['tmp_name'] || !is_uploaded_file($image_obj['tmp_name'])) continue;
- // Ignore if the file is not an image (swf the paths ~)
- if(!preg_match("/\.(jpg|jpeg|gif|png|swf)$/i", $image_obj['name'])) continue;
- // Upload the file to a path
- $path = sprintf("./files/attach/images/%s/", $args->layout_srl);
- // Create a directory
- if(!FileHandler::makeDir($path)) continue;
-
- $filename = $path.$image_obj['name'];
- // Move the file
- if(!move_uploaded_file($image_obj['tmp_name'], $filename)) continue;
-
- $extra_vars->{$name} = $filename;
+ $extra_vars->{$name} = $vars->value;
}
}
// Save header script into "config" of layout module
@@ -760,5 +736,110 @@
// Remove uploaded file
FileHandler::removeFile($source_file);
}
+
+ /**
+ * Upload config image
+ */
+ function procLayoutAdminConfigImageUpload()
+ {
+ $layoutSrl = Context::get('layout_srl');
+ $name = Context::get('name');
+ $img = Context::get('img');
+
+ $this->setTemplatePath($this->module_path.'tpl');
+ $this->setTemplateFile("after_upload_config_image.html");
+
+ if(!$img['tmp_name'] || !is_uploaded_file($img['tmp_name']))
+ {
+ Context::set('msg', Context::getLang('upload failed'));
+ return;
+ }
+
+ if(!preg_match('/\.(jpg|jpeg|gif|png|swf)$/i', $img['name']))
+ {
+ Context::set('msg', Context::getLang('not allowed extension'));
+ return;
+ }
+
+ $path = sprintf('./files/attach/images/%s/', $layoutSrl);
+ if(!FileHandler::makeDir($path))
+ {
+ Context::set('msg', Context::getLang('make directory failed'));
+ return;
+ }
+
+ $ext = substr(strrchr($img['name'],'.'),1);
+ $_fileName = md5(crypt(rand(1000000,900000), rand(0,100))).'.'.$ext;
+ $fileName = $path . $_fileName;
+
+ if(!move_uploaded_file($img['tmp_name'], $fileName))
+ {
+ Context::set('msg', Context::getLang('move file failed'));
+ return;
+ }
+
+ $oModel = &getModel('layout');
+ $layoutInfo = $oModel->getLayout($layoutSrl);
+
+ if($layoutInfo->extra_var_count)
+ {
+ foreach($layoutInfo->extra_var as $varId => $val)
+ {
+ $newLayoutInfo->{$varId} = $val->value;
+ }
+ }
+
+ $newLayoutInfo->{$name} = $fileName;
+
+ $args->layout_srl = $layoutSrl;
+ $args->extra_vars = serialize($newLayoutInfo);
+ $output = $this->updateLayout($args);
+ if(!$output->toBool())
+ {
+ FileHandler::removeFile($fileName);
+ Context::set('msg', Context::getLang($output->getMessage()));
+ return;
+ }
+
+ Context::set('name', $name);
+ Context::set('fileName', $fileName);
+ }
+
+ /**
+ * Delete config image
+ */
+ function procLayoutAdminConfigImageDelete()
+ {
+ $layoutSrl = Context::get('layout_srl');
+ $name = Context::get('name');
+
+ $this->setTemplatePath($this->module_path.'tpl');
+ $this->setTemplateFile("after_delete_config_image.html");
+
+ $oModel = &getModel('layout');
+ $layoutInfo = $oModel->getLayout($layoutSrl);
+
+ if($layoutInfo->extra_var_count)
+ {
+ foreach($layoutInfo->extra_var as $varId => $val)
+ {
+ $newLayoutInfo->{$varId} = $val->value;
+ }
+ }
+
+ unset($newLayoutInfo->{$name});
+
+ $args->layout_srl = $layoutSrl;
+ $args->extra_vars = serialize($newLayoutInfo);
+ $output = $this->updateLayout($args);
+ if(!$output->toBool())
+ {
+ Context::set('msg', Context::getLang($output->getMessage()));
+ return $output;
+ }
+
+ FileHandler::removeFile($layoutInfo->extra_var->{$name}->value);
+ Context::set('name', $name);
+ }
}
?>
diff --git a/modules/layout/tpl/after_delete_config_image.html b/modules/layout/tpl/after_delete_config_image.html
new file mode 100644
index 000000000..ad57ea3b8
--- /dev/null
+++ b/modules/layout/tpl/after_delete_config_image.html
@@ -0,0 +1,7 @@
+
diff --git a/modules/layout/tpl/after_upload_config_image.html b/modules/layout/tpl/after_upload_config_image.html
new file mode 100644
index 000000000..d247ab08b
--- /dev/null
+++ b/modules/layout/tpl/after_upload_config_image.html
@@ -0,0 +1,7 @@
+
diff --git a/modules/layout/tpl/js/layout_modify.js b/modules/layout/tpl/js/layout_modify.js
new file mode 100644
index 000000000..7a0267c46
--- /dev/null
+++ b/modules/layout/tpl/js/layout_modify.js
@@ -0,0 +1,32 @@
+function doSubmitConfig()
+{
+ var $forms = jQuery('#layout_config').find('input[name][type="hidden"], input[name][type="text"], input[name][type="checkbox"]:checked, select[name], textarea[name]');
+ var $configForm = jQuery('#config_form');
+ var $container = $configForm.children('div');
+ $container.empty();
+
+ $forms.each(function($)
+ {
+ var $this = jQuery(this);
+
+ if($this.parents('.imageUpload').length) return;
+
+ var $input = jQuery('').attr('type', 'hidden').attr('name', $this.attr('name')).val($this.val());
+ $container.append($input);
+ });
+
+ $configForm.submit();
+}
+
+function afterUploadConfigImage(name, fileName)
+{
+ jQuery('#preview_' + name + ' img').attr('src', fileName);
+ jQuery('#preview_' + name).show();
+ jQuery('#file_' + name).val('');
+}
+
+function afterDeleteConfigImage(name)
+{
+ jQuery('#preview_' + name + ' img').removeAttr('src');
+ jQuery('#preview_' + name).hide();
+}
diff --git a/modules/layout/tpl/layout_modify.html b/modules/layout/tpl/layout_modify.html
index 9dad26b1e..bfe71b47e 100644
--- a/modules/layout/tpl/layout_modify.html
+++ b/modules/layout/tpl/layout_modify.html
@@ -1,16 +1,21 @@
+
{$selected_layout->layout_title}
{$selected_layout->title}
-
+
-
-
-
-
+ value">
+

value" alt="" style="max-width: 250px"/>
+
+
+