Merge branch 'add-module-ant_creationcategories' into develop
This commit is contained in:
commit
a31f38a486
@ -196,6 +196,9 @@ class HelperFormBootstrap{
|
||||
case 'file':
|
||||
$this->inputFile($input);
|
||||
break;
|
||||
case 'uploadImage':
|
||||
$this->inputUploadImage($input);
|
||||
break;
|
||||
case 'button':
|
||||
$this->inputButton($input);
|
||||
break;
|
||||
@ -343,6 +346,88 @@ class HelperFormBootstrap{
|
||||
</script>';
|
||||
}
|
||||
|
||||
public function inputUploadImage($p = array()) {
|
||||
$this->_html .='
|
||||
<div class="form-group">
|
||||
'.(isset($p['label'])?'<label class="control-label '.(isset($p['label-class']) ? $p['label-class'] : '').'">'.$p['label'].'</label>':'').'
|
||||
<div class="'.(isset($p['input-class']) ? $p['input-class'] : '').'">
|
||||
<div class="input-group image-preview">
|
||||
<input type="text" class="form-control image-preview-filename" disabled="disabled">
|
||||
<span class="input-group-btn">
|
||||
<button type="button" class="btn btn-default image-preview-clear" style="display:none;">
|
||||
<span class="glyphicon glyphicon-remove"></span> Clear
|
||||
</button>
|
||||
<div class="btn btn-default image-preview-input">
|
||||
<span class="glyphicon glyphicon-folder-open"></span>
|
||||
<span class="image-preview-input-title">Ouvrir</span>
|
||||
<input type="file" accept="image/png, image/jpeg" name="'.$p['name'].'"/>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
$this->_js .= '
|
||||
<script>
|
||||
$(document).on(\'click\', \'#close-preview\', function(){
|
||||
$(\'.image-preview\').popover(\'hide\');
|
||||
$(\'.image-preview\').hover(
|
||||
function () {
|
||||
$(\'.image-preview\').popover(\'show\');
|
||||
},
|
||||
function () {
|
||||
$(\'.image-preview\').popover(\'hide\');
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$(function() {
|
||||
var closebtn = $(\'<button/>\', {
|
||||
type:"button",
|
||||
text: \'x\',
|
||||
id: \'close-preview\',
|
||||
style: \'font-size: initial;\',
|
||||
});
|
||||
closebtn.attr("class","close pull-right");
|
||||
|
||||
$(\'.image-preview\').popover({
|
||||
trigger:\'manual\',
|
||||
html:true,
|
||||
title: "<strong>Preview</strong>"+$(closebtn)[0].outerHTML,
|
||||
content: "There\'s no image",
|
||||
placement:\'bottom\'
|
||||
});
|
||||
|
||||
$(\'.image-preview-clear\').click(function(){
|
||||
$(\'.image-preview\').attr("data-content","").popover(\'hide\');
|
||||
$(\'.image-preview-filename\').val("");
|
||||
$(\'.image-preview-clear\').hide();
|
||||
$(\'.image-preview-input input:file\').val("");
|
||||
$(".image-preview-input-title").text("Browse");
|
||||
});
|
||||
// Create the preview image
|
||||
$(".image-preview-input input:file").change(function (){
|
||||
var img = $(\'<img/>\', {
|
||||
id: \'dynamic\',
|
||||
width:250,
|
||||
height: \'auto\'
|
||||
});
|
||||
var file = this.files[0];
|
||||
var reader = new FileReader();
|
||||
|
||||
reader.onload = function (e) {
|
||||
$(".image-preview-input-title").text("Change");
|
||||
$(".image-preview-clear").show();
|
||||
$(".image-preview-filename").val(file.name);
|
||||
img.attr(\'src\', e.target.result);
|
||||
$(".image-preview").attr("data-content",$(img)[0].outerHTML).popover("show");
|
||||
}
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
public function inputText($p = array()){
|
||||
|
||||
if (isset($p['lang']) && $p['lang'] === true)
|
||||
|
@ -190,6 +190,32 @@ div.tagsinput span.tag a {
|
||||
height: 28px;
|
||||
line-height: 28px;
|
||||
}
|
||||
.image-preview-input {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
margin: 0px;
|
||||
color: #333;
|
||||
background-color: #fff;
|
||||
border-color: #ccc;
|
||||
padding: 3px 15px;
|
||||
}
|
||||
.image-preview-clear{
|
||||
padding: 3px 15px;
|
||||
}
|
||||
.image-preview-input input[type=file] {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-size: 20px;
|
||||
cursor: pointer;
|
||||
opacity: 0;
|
||||
filter: alpha(opacity=0);
|
||||
}
|
||||
.image-preview-input-title {
|
||||
margin-left:2px;
|
||||
}
|
||||
|
||||
/* table */
|
||||
table.table-custombordered {
|
||||
|
@ -4,7 +4,6 @@ if(!defined('_PS_VERSION_')) {
|
||||
}
|
||||
include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
|
||||
require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php');
|
||||
require_once(PS_ADMIN_DIR . '/helpers/HelperForm.php');
|
||||
require_once(PS_ADMIN_DIR . '/helpers/HelperList.php');
|
||||
|
||||
class AdminAntCreationcategories extends AdminTab
|
||||
@ -13,8 +12,15 @@ class AdminAntCreationcategories extends AdminTab
|
||||
global $cookie;
|
||||
if(Tools::isSubmit('submitAddCategories')) {
|
||||
if(Tools::getValue('category')) {
|
||||
$groups = array();
|
||||
foreach (Group::getGroups((int)($cookie->id_lang)) AS $row){
|
||||
$groups[] = $row['id_group'];
|
||||
}
|
||||
|
||||
$date = date('Y') . '-' . date('m');
|
||||
$name = Tools::getValue('category');
|
||||
$meta_name = 'Vente privée '.$name;
|
||||
|
||||
$category = new Category();
|
||||
$category->id_parent = 1;
|
||||
$category->active = 1;
|
||||
@ -22,12 +28,26 @@ class AdminAntCreationcategories extends AdminTab
|
||||
$category->name[3] = $name;
|
||||
$category->description[2] = $date;
|
||||
$category->description[3] = $date;
|
||||
$category->meta_title[2] = $meta_name;
|
||||
$category->meta_title[3] = $meta_name;
|
||||
$category->meta_keywords[2] = $meta_name;
|
||||
$category->meta_keywords[3] = $meta_name;
|
||||
$category->meta_description[2] = $meta_name;
|
||||
$category->meta_description[3] = $meta_name;
|
||||
$category->link_rewrite[2] = $this->str2url($name);
|
||||
$category->link_rewrite[3] = $category->link_rewrite[2];
|
||||
$category->groupBox = $groups;
|
||||
|
||||
if($category->add()) {
|
||||
if (isset($_FILES['image_thumb']) && $_FILES['image_thumb']['name'] != NULL) {
|
||||
copy($_FILES['image_thumb']['tmp_name'], _PS_CAT_IMG_DIR_.$category->id.'_thumb_vp.jpg');
|
||||
}
|
||||
|
||||
if(Tools::getValue('subcategories')) {
|
||||
$subcategories = Tools::getValue('subcategories');
|
||||
$subcategories = explode(',',$subcategories);
|
||||
foreach ($subcategories as $key => $name) {
|
||||
$meta_name = 'Vente privée '.$name;
|
||||
$subcategory = new Category();
|
||||
$subcategory->id_parent = $category->id;
|
||||
$subcategory->active = 1;
|
||||
@ -35,6 +55,15 @@ class AdminAntCreationcategories extends AdminTab
|
||||
$subcategory->name[3] = $name;
|
||||
$subcategory->description[2] = $date;
|
||||
$subcategory->description[3] = $date;
|
||||
$subcategory->meta_title[2] = $meta_name;
|
||||
$subcategory->meta_title[3] = $meta_name;
|
||||
$subcategory->meta_keywords[2] = $meta_name;
|
||||
$subcategory->meta_keywords[3] = $meta_name;
|
||||
$subcategory->meta_description[2] = $meta_name;
|
||||
$subcategory->meta_description[3] = $meta_name;
|
||||
$subcategory->link_rewrite[2] = $this->str2url($name);
|
||||
$subcategory->link_rewrite[3] = $subcategory->link_rewrite[2];
|
||||
$subcategory->groupBox = $groups;
|
||||
$subcategory->add();
|
||||
}
|
||||
}
|
||||
@ -49,13 +78,23 @@ class AdminAntCreationcategories extends AdminTab
|
||||
$subcategories = Tools::getValue('subcategories2');
|
||||
$subcategories = explode(',',$subcategories);
|
||||
foreach ($subcategories as $key => $name) {
|
||||
$meta_name = 'Vente privée '.$name;
|
||||
$subcategory = new Category();
|
||||
$subcategory->id_parent = $id_parent;
|
||||
$subcategory->id_parent = (int)$id_parent;
|
||||
$subcategory->active = 1;
|
||||
$subcategory->name[2] = $name;
|
||||
$subcategory->name[3] = $name;
|
||||
$subcategory->description[2] = $date;
|
||||
$subcategory->description[3] = $date;
|
||||
$subcategory->meta_title[2] = $meta_name;
|
||||
$subcategory->meta_title[3] = $meta_name;
|
||||
$subcategory->meta_keywords[2] = $meta_name;
|
||||
$subcategory->meta_keywords[3] = $meta_name;
|
||||
$subcategory->meta_description[2] = $meta_name;
|
||||
$subcategory->meta_description[3] = $meta_name;
|
||||
$subcategory->link_rewrite[2] = $this->str2url($name);
|
||||
$subcategory->link_rewrite[3] = $subcategory->link_rewrite[2];
|
||||
$subcategory->groupBox = $groups;
|
||||
$subcategory->add();
|
||||
}
|
||||
Category::regenerateEntireNtree();
|
||||
@ -111,6 +150,13 @@ class AdminAntCreationcategories extends AdminTab
|
||||
'input-class' => 'col-md-6',
|
||||
'name' => 'category',
|
||||
),
|
||||
array(
|
||||
'type' => 'uploadImage',
|
||||
'label' => $this->l('Logo : '),
|
||||
'label-class' => 'col-md-2',
|
||||
'input-class' => 'col-md-6',
|
||||
'name' => 'image_thumb',
|
||||
),
|
||||
array(
|
||||
'type' => 'tag',
|
||||
'label' => $this->l('Sous Catégorie : '),
|
||||
@ -205,4 +251,18 @@ class AdminAntCreationcategories extends AdminTab
|
||||
|
||||
echo $form;
|
||||
}
|
||||
|
||||
public function str2url($string, $slug = '-', $extra = null)
|
||||
{
|
||||
return strtolower(trim(preg_replace('~[^0-9a-z' . preg_quote($extra, '~') . ']+~i', $slug, $this->unaccent($string)), $slug));
|
||||
}
|
||||
|
||||
public function unaccent($string) // normalizes (romanization) accented chars
|
||||
{
|
||||
if (strpos($string = htmlentities($string, ENT_QUOTES, 'UTF-8'), '&') !== false) {
|
||||
$string = html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|tilde|uml);~i', '$1', $string), ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user