';
// foreach ($languages as $language)
// {
// $this->_html .= '
';
// $this->_html .= '
';
// /* Sets image as hidden in case it does not change */
// if ($livredor && $livredor->image[$language['id_lang']])
// $this->_html .= '
';
// /* Display image */
// if ($livredor && $livredor->image[$language['id_lang']])
// $this->_html .= '
';
// $this->_html .= '
';
// }
// $this->_html .= $this->displayFlags($languages, $id_lang_default, $divLangName, 'image', true);
// /* End Fieldset Upload */
// $this->_html .= '
';
/* Fieldset edit/add */
$this->_html .= '
';
/* Form content */
/* Form content */
$this->_html .= '
';
/* Form content */
/* Form content */
$this->_html .= '
';
}
private function _displayAddThemeForm()
{
/* Sets livredor : depends if edited or added */
$livredor = null;
if (Tools::isSubmit('id_theme') && $this->livredorThemeExists((int)Tools::getValue('id_theme')))
$livredor = new livredorTheme((int)Tools::getValue('id_theme'));
// print_r($livredor);
/* Checks if directory is writable */
// if (!is_writable('.'))
// $this->adminDisplayWarning(sprintf($this->l('Modules %s must be writable (CHMOD 755 / 777)'), $this->name));
/* Gets languages and sets which div requires translations */
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
$languages = Language::getLanguages(false);
$divLangName = 'title';
$this->_html .= '';
/* Form */
$this->_html .= '
';
}
private function _postValidation()
{
$errors = array();
if (Tools::isSubmit('changeStatus'))
{
if (!Validate::isInt(Tools::getValue('id_livredor')))
$errors[] = $this->l('Invalid livredor');
}
/* Validation for livredor */
elseif (Tools::isSubmit('changeStatusEnavant'))
{
if (!Validate::isInt(Tools::getValue('id_livredor')))
$errors[] = $this->l('Invalid livredor');
}
/* Validation for livredor */
elseif (Tools::isSubmit('submitlivredor'))
{
/* Checks state (active) */
if (!Validate::isInt(Tools::getValue('active_livredor')) || (Tools::getValue('active_livredor') != 0 && Tools::getValue('active_livredor') != 1))
$errors[] = $this->l('Invalid "active" state');
if (!Validate::isInt(Tools::getValue('en_avant_livredor')) || (Tools::getValue('en_avant_livredor') != 0 && Tools::getValue('en_avant_livredor') != 1))
$errors[] = $this->l('Invalid "en avant" state');
/* Checks position */
if (!Validate::isInt(Tools::getValue('position')) || (Tools::getValue('position') < 0))
$errors[] = $this->l('Invalid livredor position');
/* If edit : checks id_livredor */
if (Tools::isSubmit('id_livredor'))
{
if (!Validate::isInt(Tools::getValue('id_livredor')) && !$this->livredorExists(Tools::getValue('id_livredor')))
$errors[] = $this->l('Invalid id_livredor');
}
/* Checks title/url/legend/phrase/image */
$languages = Language::getLanguages(false);
foreach ($languages as $language)
{
if (Tools::strlen(Tools::getValue('phrase_'.$language['id_lang'])) > 255)
$errors[] = $this->l('La phrase est trop longue');
// if (Tools::strlen(Tools::getValue('phrase_'.$language['id_lang'])) > 4000)
// $errors[] = $this->l('The phrase is too long.');
// if (Tools::getValue('image_'.$language['id_lang']) != null && !Validate::isFileName(Tools::getValue('image_'.$language['id_lang'])))
// $errors[] = $this->l('Invalid filename');
// if (Tools::getValue('image_old_'.$language['id_lang']) != null && !Validate::isFileName(Tools::getValue('image_old_'.$language['id_lang'])))
// $errors[] = $this->l('Invalid filename');
}
/* Checks title/url/legend/phrase for default lang */
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
if (Tools::strlen(Tools::getValue('titre_'.$id_lang_default)) == 0)
$errors[] = $this->l('Le titre est obligatoire');
if (Tools::strlen(Tools::getValue('phrase_'.$id_lang_default)) == 0)
$errors[] = $this->l('La phrase obligatoire');
if (Tools::strlen(Tools::getValue('prenom_'.$id_lang_default)) == 0)
$errors[] = $this->l('Le prénom obligatoire');
if (Tools::strlen(Tools::getValue('nom_'.$id_lang_default)) == 0)
$errors[] = $this->l('Le nom obligatoire');
if (Tools::strlen(Tools::getValue('note')) == 0)
$errors[] = $this->l('La note obligatoire');
// if (!Tools::isSubmit('has_picture') && (!isset($_FILES['image_'.$id_lang_default]) || empty($_FILES['image_'.$id_lang_default]['tmp_name'])))
// $errors[] = $this->l('The image is not set.');
// if (Tools::getValue('image_old_'.$id_lang_default) && !Validate::isFileName(Tools::getValue('image_old_'.$id_lang_default)))
// $errors[] = $this->l('The image is not set.');
} /* Validation for deletion */
elseif (Tools::isSubmit('delete_id_livredor') && (!Validate::isInt(Tools::getValue('delete_id_livredor')) || !$this->livredorExists((int)Tools::getValue('delete_id_livredor'))))
$errors[] = $this->l('Invalid id_livredor');
elseif (Tools::isSubmit('submittheme'))
{
/* Checks state (active) */
if (!Validate::isInt(Tools::getValue('active_theme')) || (Tools::getValue('active_theme') != 0 && Tools::getValue('active_theme') != 1))
$errors[] = $this->l('Invalid theme state');
/* Checks position */
if (!Validate::isInt(Tools::getValue('position')) || (Tools::getValue('position') < 0))
$errors[] = $this->l('Invalid theme position');
/* If edit : checks id_theme */
if (Tools::isSubmit('id_theme'))
{
if (!Validate::isInt(Tools::getValue('id_theme')) && !$this->livredorExists(Tools::getValue('id_theme')))
$errors[] = $this->l('Invalid id_theme');
}
/* Checks title/url/legend/phrase/image */
$languages = Language::getLanguages(false);
foreach ($languages as $language)
{
// if (Tools::strlen(Tools::getValue('title_'.$language['id_lang'])) > 255)
// $errors[] = $this->l('The title is too long.');
// if (Tools::strlen(Tools::getValue('phrase_'.$language['id_lang'])) > 4000)
// $errors[] = $this->l('The phrase is too long.');
// if (Tools::getValue('image_'.$language['id_lang']) != null && !Validate::isFileName(Tools::getValue('image_'.$language['id_lang'])))
// $errors[] = $this->l('Invalid filename');
// if (Tools::getValue('image_old_'.$language['id_lang']) != null && !Validate::isFileName(Tools::getValue('image_old_'.$language['id_lang'])))
// $errors[] = $this->l('Invalid filename');
}
/* Checks title/url/legend/phrase for default lang */
$id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
if (Tools::strlen(Tools::getValue('title_'.$id_lang_default)) == 0)
$errors[] = $this->l('Nom du thème obligatoire');
} /* Validation for deletion */
elseif (Tools::isSubmit('delete_id_theme') && (!Validate::isInt(Tools::getValue('delete_id_theme')) || !$this->livredorExists((int)Tools::getValue('delete_id_theme'))))
$errors[] = $this->l('Invalid id_theme');
/* Display errors if needed */
if (count($errors))
{
$this->_html .= $this->displayError(implode('
', $errors));
return false;
}
/* Returns if validation is ok */
return true;
}
private function _postProcess()
{
$errors = array();
if (Tools::isSubmit('changeStatusEnavant') && Tools::isSubmit('id_livredor'))
{
$livredor = new livredorItem((int)Tools::getValue('id_livredor'));
if ($livredor->en_avant == 0){
Db::getInstance()->execute('update '._DB_PREFIX_.'devspelivredor_item set en_avant=0');
$livredor->en_avant = 1;
}else
$livredor->en_avant = 0;
$res = $livredor->update();
$this->clearCache();
$this->_html .= ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')));
}
/* Processes livredor */
elseif (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_livredor'))
{
$livredor = new livredorItem((int)Tools::getValue('id_livredor'));
if ($livredor->active == 0)
$livredor->active = 1;
else
$livredor->active = 0;
$res = $livredor->update();
$this->clearCache();
$this->_html .= ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')));
}
/* Processes livredor */
elseif (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_theme'))
{
$livredor = new livredorTheme((int)Tools::getValue('id_theme'));
if ($livredor->active == 0)
$livredor->active = 1;
else
$livredor->active = 0;
$res = $livredor->update();
$this->clearCache();
$this->_html .= ($res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')));
}
/* Processes livredor */
elseif (Tools::isSubmit('submitlivredor'))
{
/* Sets ID if needed */
if (Tools::getValue('id_livredor'))
{
$livredor = new livredorItem((int)Tools::getValue('id_livredor'));
if (!Validate::isLoadedObject($livredor))
{
$this->_html .= $this->displayError($this->l('Invalid id_livredor'));
return;
}
}
else
$livredor = new livredorItem();
/* Sets position */
$livredor->position = (int)Tools::getValue('position');
$livredor->id_theme = (int)Tools::getValue('id_theme');
/* Sets active */
$livredor->active = (int)Tools::getValue('active_livredor');
$livredor->en_avant = (int)Tools::getValue('en_avant_livredor');
/* Sets each langue fields */
$languages = Language::getLanguages(false);
foreach ($languages as $language)
{
$livredor->prenom[$language['id_lang']] = Tools::getValue('prenom_'.$language['id_lang']);
$livredor->nom[$language['id_lang']] = Tools::getValue('nom_'.$language['id_lang']);
$livredor->departement[$language['id_lang']] = Tools::getValue('departement_'.$language['id_lang']);
$livredor->ville[$language['id_lang']] = Tools::getValue('ville_'.$language['id_lang']);
$livredor->titre[$language['id_lang']] = Tools::getValue('titre_'.$language['id_lang']);
$livredor->phrase[$language['id_lang']] = Tools::getValue('phrase_'.$language['id_lang']);
$livredor->note = Tools::getValue('note');
$livredor->age = Tools::getValue('age');
// /* Uploads image and sets livredor */
// $type = strtolower(substr(strrchr($_FILES['image_'.$language['id_lang']]['name'], '.'), 1));
// $imagesize = array();
// $imagesize = @getimagesize($_FILES['image_'.$language['id_lang']]['tmp_name']);
// if (isset($_FILES['image_'.$language['id_lang']]) &&
// isset($_FILES['image_'.$language['id_lang']]['tmp_name']) &&
// !empty($_FILES['image_'.$language['id_lang']]['tmp_name']) &&
// !empty($imagesize) &&
// in_array(strtolower(substr(strrchr($imagesize['mime'], '/'), 1)), array('jpg', 'gif', 'jpeg', 'png')) &&
// in_array($type, array('jpg', 'gif', 'jpeg', 'png')))
// {
// $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
// $salt = sha1(microtime());
// if ($error = ImageManager::validateUpload($_FILES['image_'.$language['id_lang']]))
// $errors[] = $error;
// elseif (!$temp_name || !move_uploaded_file($_FILES['image_'.$language['id_lang']]['tmp_name'], $temp_name))
// return false;
// elseif (!ImageManager::resize($temp_name, dirname(__FILE__).'/images/'.Tools::encrypt($_FILES['image_'.$language['id_lang']]['name'].$salt).'.'.$type, null, null, $type))
// $errors[] = $this->displayError($this->l('An error occurred during the image upload process.'));
// if (isset($temp_name))
// @unlink($temp_name);
// $livredor->image[$language['id_lang']] = Tools::encrypt($_FILES['image_'.($language['id_lang'])]['name'].$salt).'.'.$type;
// }
// elseif (Tools::getValue('image_old_'.$language['id_lang']) != '')
// $livredor->image[$language['id_lang']] = Tools::getValue('image_old_'.$language['id_lang']);
}
/* Processes if no errors */
if (!$errors)
{
/* Adds */
if($livredor->en_avant==1)
Db::getInstance()->execute('update '._DB_PREFIX_.'devspelivredor_item set en_avant=0');
if (!Tools::getValue('id_livredor'))
{
if (!$livredor->add())
$errors[] = $this->displayError($this->l('The livredor could not be added.'));
}
/* Update */
elseif (!$livredor->update())
$errors[] = $this->displayError($this->l('The livredor could not be updated.'));
$this->clearCache();
}
} /* Deletes */
elseif (Tools::isSubmit('delete_id_livredor'))
{
$livredor = new livredorItem((int)Tools::getValue('delete_id_livredor'));
$res = $livredor->delete();
$this->clearCache();
if (!$res)
$this->_html .= $this->displayError('Could not delete');
else
$this->_html .= $this->displayConfirmation($this->l('livredor deleted'));
}
elseif (Tools::isSubmit('submittheme'))
{
/* Sets ID if needed */
if (Tools::getValue('id_theme'))
{
$livredor = new livredorTheme((int)Tools::getValue('id_theme'));
if (!Validate::isLoadedObject($livredor))
{
$this->_html .= $this->displayError($this->l('Invalid id_theme'));
return;
}
}
else
$livredor = new livredorTheme();
/* Sets position */
$livredor->id_livredor_parent = (int)Tools::getValue('id_livredor_parent');
$livredor->position = (int)Tools::getValue('position');
/* Sets active */
$livredor->active = (int)Tools::getValue('active_theme');
/* Sets each langue fields */
$languages = Language::getLanguages(false);
foreach ($languages as $language)
{
$livredor->title[$language['id_lang']] = Tools::getValue('title_'.$language['id_lang']);
}
/* Processes if no errors */
if (!$errors)
{
/* Adds */
if (!Tools::getValue('id_theme'))
{
$livredor->add();
// $errors[] = $this->displayError($this->l('Le thème ne peut être créé'));
}
/* Update */
elseif (!$livredor->update())
$errors[] = $this->displayError($this->l('Le thème n\'a pas été modifié'));
$this->clearCache();
}
} /* Deletes */
elseif (Tools::isSubmit('delete_id_theme'))
{
$livredor = new livredorTheme((int)Tools::getValue('delete_id_theme'));
$res = $livredor->delete();
$this->clearCache();
if (!$res)
$this->_html .= $this->displayError('Could not delete');
else
$this->_html .= $this->displayConfirmation($this->l('Thème supprimé'));
}
/* Display errors if needed */
if (count($errors))
$this->_html .= $this->displayError(implode('
', $errors));
elseif (Tools::isSubmit('submittheme') && Tools::getValue('id_theme'))
$this->_html .= $this->displayConfirmation($this->l('Thème updated'));
elseif (Tools::isSubmit('submittheme'))
$this->_html .= $this->displayConfirmation($this->l('Thème added'));
}
private function _prepareHook()
{
if (!$this->isCached('devspelivredor.tpl', $this->getCacheId()))
{
// $livredorr = array(
// 'width' => Configuration::get('devspelivredor_WIDTH'),
// 'height' => Configuration::get('devspelivredor_HEIGHT'),
// 'speed' => Configuration::get('devspelivredor_SPEED'),
// 'pause' => Configuration::get('devspelivredor_PAUSE'),
// 'loop' => Configuration::get('devspelivredor_LOOP'),
// );
$livredors = $this->getItemslivredor(true);
if (!$livredors)
return false;
$this->smarty->assign('devspelivredor_item', $livredors);
// $this->smarty->assign('devspelivredor', $livredorr);
}
return true;
}
public function hookTop()
{
// if(!$this->_prepareHook())
// return;
// Check if not a mobile theme
/*
if ($this->context->getMobileDevice() != false)
return false;
// $this->context->controller->addJS($this->_path.'js/jquery.bxlivredorr.min.js');
$this->context->controller->addCSS($this->_path.'devspelivredor.css');
$this->context->controller->addJS($this->_path.'js/devspelivredor.js');
return $this->display(__FILE__, 'devspelivredor.tpl', $this->getCacheId());
*/
}
public function clearCache()
{
$this->_clearCache('devspelivredor.tpl');
}
public function hookActionShopDataDuplication($params)
{
Db::getInstance()->execute('
INSERT IGNORE INTO '._DB_PREFIX_.'devspelivredor (id_livredor_item, id_shop)
SELECT id_livredor_item, '.(int)$params['new_id_shop'].'
FROM '._DB_PREFIX_.'devspelivredor
WHERE id_shop = '.(int)$params['old_id_shop']);
$this->clearCache();
}
public function headerHTML()
{
if (Tools::getValue('controller') != 'AdminModules' && Tools::getValue('configure') != $this->name)
return;
$this->context->controller->addJqueryUI('ui.sortable');
/* Style & js for fieldset 'livredors configuration' */
$html = '
';
return $html;
}
public function getNextPosition()
{
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT MAX(hss.`position`) AS `next_position`
FROM `'._DB_PREFIX_.'devspelivredor_item` hss, `'._DB_PREFIX_.'devspelivredor` hs
WHERE hss.`id_livredor_item` = hs.`id_livredor_item` AND hs.`id_shop` = '.(int)$this->context->shop->id
);
return (++$row['next_position']);
}
public function getNextPositionTheme()
{
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT MAX(hss.`position`) AS `next_position`
FROM `'._DB_PREFIX_.'devspelivredor_theme` hss'
);
return (++$row['next_position']);
}
public function getItemslivredor($active = null)
{
$this->context = Context::getContext();
$id_shop = $this->context->shop->id;
$id_lang = $this->context->language->id;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT hs.`id_livredor_item` as id_livredor,
hss.`position`,
hss.`id_theme`,
hss.`active`,
hss.`en_avant`,
hss.`note`,
hss.`age`,
hssl.`prenom`,
hssl.`nom`,
hssl.`nom`,
hssl.`departement`,
hssl.`ville`,
hssl.`titre`,
hssl.`phrase`
FROM '._DB_PREFIX_.'devspelivredor hs
LEFT JOIN '._DB_PREFIX_.'devspelivredor_item hss ON (hs.id_livredor_item = hss.id_livredor_item)
LEFT JOIN '._DB_PREFIX_.'devspelivredor_item_lang hssl ON (hss.id_livredor_item = hssl.id_livredor_item)
WHERE (id_shop = '.(int)$id_shop.')
AND hssl.id_lang = '.(int)$id_lang.
($active ? ' AND hss.`active` = 1' : ' ').'
ORDER BY hss.position');
}
public function getItemsTheme($active = null,$zero=null)
{
$this->context = Context::getContext();
$id_shop = $this->context->shop->id;
$id_lang = $this->context->language->id;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT hss.`id_livredor_theme` as id_theme,
hss.`position`,
hss.`active`,
hss.`id_livredor_parent`,
hssl.`title`
FROM '._DB_PREFIX_.'devspelivredor_theme hss
LEFT JOIN '._DB_PREFIX_.'devspelivredor_theme_lang hssl ON (hss.id_livredor_theme = hssl.id_livredor_theme)
WHERE hssl.id_lang = '.(int)$id_lang.
($active ? ' AND hss.`active` = 1' : ' ').
($zero ? ' AND hss.`id_livredor_parent` = 0' : ' ').'
ORDER BY hss.position');
}
public function displayStatusEnavant($id_livredor, $en_avant)
{
$title = ((int)$en_avant == 0 ? $this->l('Mettre ce message en avant') : $this->l('Ce message est mis en avant'));
$img = ((int)$en_avant == 0 ? 'en_avant_off.jpg' : 'en_avant_on.jpg');
$html = '
';
return $html;
}
public function displayStatus($id_livredor, $active)
{
$title = ((int)$active == 0 ? $this->l('Disabled') : $this->l('Enabled'));
$img = ((int)$active == 0 ? 'disabled.gif' : 'enabled.gif');
$html = '
';
return $html;
}
public function livredorExists($id_livredor)
{
$req = 'SELECT hs.`id_livredor_item` as id_livredor
FROM `'._DB_PREFIX_.'devspelivredor` hs
WHERE hs.`id_livredor_item` = '.(int)$id_livredor;
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($req);
return ($row);
}
public function livredorThemeExists($id_theme)
{
$req = 'SELECT hs.`id_livredor_theme` as id_theme
FROM `'._DB_PREFIX_.'devspelivredor_theme` hs
WHERE hs.`id_livredor_theme` = '.(int)$id_theme;
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($req);
return ($row);
}
}