_defaultFormLanguage));
$id_shop = Tools::getValue('id_shop', (int)Context::getContext()->shop->id);
if (Tools::getIsset('addBlock')){
$blocks = LofBlock::getBlocks(Tools::getValue('id_position'), $cookie->id_lang, $id_shop);
$nb = count($blocks);
if($nb >= LOF_MODULE_ADVANCE_CUSTOM_LIMIT_BLOCK){
$errors[] = $module->l('Block number was limited');
}
$totalWidth = 0;
if($blocks)
foreach($blocks as $bl){
$totalWidth += $bl['width'];
}
if(Tools::isSubmit('submitAddBlock') && $nb < LOF_MODULE_ADVANCE_CUSTOM_LIMIT_BLOCK){
$titles = array();
foreach($module->_languages as $language)
$titles[$language['id_lang']] = Tools::getValue('title_'.$language['id_lang']);
if(!Tools::getValue('title_'.$module->_defaultFormLanguage))
$errors[] = $module->l('the field Title is required at least in '.$defaultLanguage->name);
foreach($titles as $key => $val)
if(!Validate::isGenericName($val))
$errors[] = $module->l('the field Title is invalid');
if(Tools::getValue('width'))
$errors[] = $module->l('the field Width is invalid');
if($totalWidth + Tools::getValue('width') > 100)
$errors[] = $module->l('Width total is invalid(>100)');
if(!Tools::getValue('id_position'))
$errors[] = $module->l('the field Position is invalid');
if (!sizeof($errors)){
$objBlock = new LofBlock();
$objBlock->title = $titles;
$objBlock->width = Tools::getValue('width');
$objBlock->show_title = Tools::getValue('show_title');
$objBlock->id_position = Tools::getValue('id_position');
if(!$objBlock->add()){
$errors[] = $module->l('An error occurred while creating object');
}else{
$module->_clearCache("tmpl/default/default.tpl");
?>
_languages as $language){
$titles[$language['id_lang']] = Tools::getValue('title_'.$language['id_lang']);
$texts[$language['id_lang']] = Tools::getValue('text_'.$language['id_lang']);
}
if(!Tools::getValue('title_'.$module->_defaultFormLanguage))
$errors[] = $module->l('the field Title is required at least in '.$defaultLanguage->name);
foreach($titles as $key => $val)
if(!Validate::isGenericName($val))
$errors[] = $module->l('the field Title is invalid');
if(Tools::getValue('type') == 'link'){
if(Tools::getValue('linktype') == 'product' && !Validate::isUnsignedId(Tools::getValue('link_type_product'))){
$errors[] = $module->l('the field Product is invalid');
}
}
if(Tools::getValue('type') == 'module'){
if( !Tools::getValue('module_name') || !Validate::isGenericName(Tools::getValue('module_name')) || !Tools::getValue('hook_name') || !Validate::isGenericName(Tools::getValue('hook_name'))){
$errors[] = $module->l('the field Module is invalid');
}
}
if (!sizeof($errors)){
$objItem = new LofItem();
$objItem->id_loffc_block_item = Tools::getValue('id_loffc_block_item');
$objItem->id_loffc_block = Tools::getValue('id_loffc_block');
$objItem->type = Tools::getValue('type');
if(Tools::getValue('type') == 'link'){
$objItem->linktype = Tools::getValue('linktype');
$objItem->target = Tools::getValue('target');
if(Tools::getValue('linktype') == 'product')
$objItem->link_content = Tools::getValue('link_type_product');
if(Tools::getValue('linktype') == 'category')
$objItem->link_content = Tools::getValue('link_type_category');
if(Tools::getValue('linktype') == 'cms')
$objItem->link_content = Tools::getValue('link_type_cms');
if(Tools::getValue('linktype') == 'link')
$objItem->link_content = Tools::getValue('link_type_link');
if(Tools::getValue('linktype') == 'manufacturer')
$objItem->link_content = Tools::getValue('link_type_manufacturer');
if(Tools::getValue('linktype') == 'supplier')
$objItem->link_content = Tools::getValue('link_type_supplier');
}elseif(Tools::getValue('type') == 'module'){
$objItem->module_name = Tools::getValue('module_name');
$objItem->hook_name = Tools::getValue('hook_name');
}elseif(Tools::getValue('type') == 'custom_html'){
$objItem->text = $texts;
}elseif(Tools::getValue('type') == 'gmap'){
$objItem->latitude = Tools::getValue('latitude');
$objItem->longitude = Tools::getValue('longitude');
}elseif(Tools::getValue('type') == 'addthis'){
$objItem->addthis = 1;
}
$objItem->title = $titles;
$objItem->show_title = Tools::getValue('show_title');
if(!$objItem->id_loffc_block_item){
if(!$objItem->add())
$errors[] = $module->l('An error occurred while creating object');
else{
$module->_clearCache("tmpl/default/default.tpl");
$items = LofBlock::getItems($objItem->id_loffc_block, $cookie->id_lang);
$id_loftable = Tools::getValue('id_loftable');
if ($id_loftable){ ?>
id = $objItem->id_loffc_block_item;
if(!$objItem->update())
$errors[] = $module->l('An error occurred while update object');
else{$module->_clearCache("tmpl/default/default.tpl");
$id_loftr = Tools::getValue('id_loftr');
if ($id_loftr){ ?>