name = 'imaxstockavelonemptyingmodule';
$this->tab = 'administration';
$this->version = '1.1';
$this->author = 'Informax';
$this->need_instance = 0;
$this->idManual = '';
$this->forceCheck = 0;
$this->sufijo = self::prefijo;
$this->prefijo = self::prefijo;
parent::__construct();
$nombreModulo = Configuration::getGlobalValue($this->sufijo . 'NOMBRE_MODULO');
$descripcionModulo = Configuration::getGlobalValue($this->sufijo . 'DESCRIPCION_MODULO');
if ($nombreModulo) {
$this->displayName = $nombreModulo;
$this->description = $descripcionModulo;
}
else {
$this->displayName = $this->l('Stock Avelon Emptying');
$this->description = $this->l('Este módulo permite vaciar la tabla StockAvelon de la base de datos de PrestaShop, eliminando todos los registros dentro de la tabla. Utilícelo con precaución y asegúrese de tener un backup de sus datos antes de proceder.');
}
if (version_compare(_PS_VERSION_, '1.7.0.0 ', '>=')) {
$this->versionPS = 17;
$context = Context::getContext();
$this->idShop = $context->shop->id;
$this->idLang = $context->language->id;
}
elseif (version_compare(_PS_VERSION_, '1.6.0.0 ', '>=')) {
$this->versionPS = 16;
$context = Context::getContext();
$this->idShop = $context->shop->id;
$this->idLang = $context->language->id;
}
elseif (version_compare(_PS_VERSION_, '1.5.0.0 ', '>=')) {
$this->versionPS = 15;
$context = Context::getContext();
$this->idShop = $context->shop->id;
$this->idLang = $context->language->id;
}
else {
$this->_html .= $this->l("La version minima de funcionamiento para nuestros modulos es la 1.5");
}
}
public function install() {
$directorioAdmin = getcwd();
if (!@copy(dirname(__FILE__).'/imaxstockavelonemptyingmodule_cron.php', $directorioAdmin.'/imaxstockavelonemptyingmodule_cron.php')) {
$this->_errors[] = $this->l('Ha fallado al copiar el fichero de cron');
return false;
}
if (is_file(dirname(__FILE__).'/imaxstockavelonemptyingmodule_cron.php.imax') && !@copy(dirname(__FILE__).'/imaxstockavelonemptyingmodule_cron.php.imax', $directorioAdmin.'/imaxstockavelonemptyingmodule_cron.php.imax')) {
$this->_errors[] = $this->l('Ha fallado al copiar el fichero de cron');
return false;
}
include(dirname(__FILE__).'/configuration.php');
foreach ($configuracion AS $indice => $valor) {
if (!Configuration::updateGlobalValue($indice, $valor)) {
return false;
}
}
if (!parent::install())
return false;
foreach ($hooks as $hook) {
if (!$this->registerHook($hook)) {
$this->_errors[] = $this->l('Ha fallado la instalacion del hook:').' '.$hook;
return false;
}
}
include(dirname(__FILE__).'/sql-install.php');
foreach ($sql as $s) {
if (!Db::getInstance()->execute($s)) {
$this->_errors[] = $this->l("Error al ejecutar").$s;
return false;
}
}
if (!$this->installTab()) {
$this->_errors[] = $this->l('Error al instalar el tab');
return false;
}
return true;
}
public function uninstall() {
if (!parent::uninstall()) {
return false;
}
include(dirname(__FILE__).'/sql-unninstall.php');
foreach ($sql as $s) {
if (!Db::getInstance()->execute($s)) {
$this->_errors[] = $this->l("Error al ejecutar").$s;
return false;
}
}
$directorioAdmin = getcwd();
if (!unlink($directorioAdmin.'/imaxstockavelonemptyingmodule_cron.php')) {
$this->_errors[] = $this->l('Error al borrar el fichero de Cron');
return false;
}
if (is_file($directorioAdmin.'/imaxstockavelonemptyingmodule_cron.php.imax') && !unlink($directorioAdmin.'/imaxstockavelonemptyingmodule_cron.php.imax')) {
$this->_errors[] = $this->l('Error al borrar el fichero de Cron');
return false;
}
if (!$this->uninstallTab()) {
$this->_errors[] = $this->l('Error al eliminar el tab');
return false;
}
include(dirname(__FILE__).'/configuration.php');
foreach ($configuracion AS $indice => $valor) {
if (Configuration::getGlobalValue($indice) !== FALSE) {
if (!Configuration::deleteByName($indice)) {
return false;
}
}
}
return true;
}
public function getContent() {
$this->getTxtFiles();
$this->addCSS('css.css');
$this->addJS('SucesionTeclas.js');
$this->addJS('functions.js');
$this->addCSS('publi.css');
$this->_html .= $this->createHelpHeader();
if (!empty($_POST)) {
$this->_html .= $this->_postProcess();
}
$this->_displayForm();
$this->_html .= $this->getModuleFooter();
return $this->_html;
}
private function _postProcess() {
$accion = Tools::getValue("accion");
$this->idTab = Tools::getValue("idTab");
$html = "";
switch ($accion) {
case 'gestionLicencia':
$this->forceCheck = 1;
if (Configuration::updateGlobalValue(self::prefijo . 'LICENCIA', trim(Tools::getValue('licencia')))) {
$html .= $this->displayConfirmation($this->l('Licencia guardada correctamente.'));
}
else {
$html .= $this->displayError($this->l('Ha ocurrido un error al guardar la licencia.'));
}
break;
case 'gestionPubli':
Configuration::updateGlobalValue($this->sufijo . 'TXT_FILE', '');
$urlPubli = trim(Tools::getValue('urlPubli'));
$tipoPubli = trim(Tools::getValue('namePubli'));
$nombre = trim(Tools::getValue('nameDeveloper'));
$urlEmpresa = trim(Tools::getValue('urlEmpresa'));
$urlManual = trim(Tools::getValue('urlManual'));
$urlSoporte = trim(Tools::getValue('urlSoporte'));
$descripcionModulo = trim(Tools::getValue('descripcionModulo'));
$nombreModulo = trim(Tools::getValue('nombreModulo'));
if (Configuration::updateGlobalValue($this->sufijo . 'URL_TXT', $urlPubli) &&
Configuration::updateGlobalValue($this->sufijo . 'TIPO', $tipoPubli) &&
Configuration::updateGlobalValue($this->sufijo . 'URL_DEVELOPER', $urlEmpresa) &&
Configuration::updateGlobalValue($this->sufijo . 'URL_TICKETS', $urlSoporte) &&
Configuration::updateGlobalValue($this->sufijo . 'URL_MANUAL', $urlManual) &&
Configuration::updateGlobalValue($this->sufijo . 'NOMBRE_DEVELOPER', $nombre) &&
Configuration::updateGlobalValue($this->sufijo . 'DESCRIPCION_MODULO', $descripcionModulo) &&
Configuration::updateGlobalValue($this->sufijo . 'NOMBRE_MODULO', $nombreModulo)) {
Configuration::updateGlobalValue($this->sufijo . 'DESCARGA_ARCHIVO', 100001);
$html .= $this->displayConfirmation('Datos guardados correctamente.');
$this->installTabNewData();
} else {
$html .= $this->displayError('Ha ocurrido un error al guardar los datos de desarrollador.');
}
$this->forceCheck = 1;
case 'generar_token':
Configuration::updateGlobalValue(self::prefijo . 'TOKEN', md5(uniqid()));
$html .= $this->displayConfirmation($this->l('Token regenerado.'));
break;
default:
break;
}
return $html;
}
public function _displayForm() {
return $this->displayFormTrait(array('_configuracion' => $this->l('Configuracion'), '_mostrarLicencia' => $this->l('Licencia')), '');
}
private function _mostrarLicencia() {
return $this->mostrarLicenciaTrait(2);
}
private function _configuracion() {
include_once(dirname(__FILE__).'/functionsForm.php');
include_once(dirname(__FILE__).'/imaxAcordeon.php');
$token = Configuration::getGlobalValue(self::prefijo.'TOKEN');
$acordeon = new imaxAcordeon($this->_path);
$html = '';
$form = new imaxForm($this, $this->_path);
$form->createHidden("accion", "generar_token");
$form->createHidden("idTab", "1");
$text = ''.$this->l('ATENCION:').' '.$this->l('Si cambia el token, tiene que cambiarlo tambien en las tareas de cron');
$form->createFormInfomationText($text);
$urlTienda = self::getUrlAdmin();
$form->createFormInfomationText($this->l('Debe enviar por get a la url de servicio, ya sea con curl o wget el que soporte su servidor, con esta opción se cambian todos los productos independientemente de si usa o no un actualizador de productos'));
$form->createFormInfomationText($this->l('ADVERTENCIA: Este módulo eliminará todos los registros de la tabla StockAvelon en su base de datos de PrestaShop. Esta acción es irreversible. Asegúrese de tener un respaldo completo de su base de datos antes de utilizar este módulo. Utilice este módulo bajo su propia responsabilidad.'));
$url = ''.$urlTienda.$this->name.'_cron.php?token='.$token.'';
$form->createFormInfomationText($url);
$form->createSubmitButton('opcionesConfiguracion', $this->l('Regenerar Token'));
$html .= $acordeon->renderAcordeon($this->l('Tareas Cron'), $form->renderForm());
return $html;
}
/**
* Devuelve las funciones especificas del modulo.
* @return FuncionesImaxStockAvelonEmptyingModule
*/
public function getFunciones() {
if(!self::$funciones) {
self::$funciones = new FuncionesImaxStockAvelonEmptyingModule($this);
}
return self::$funciones;
}
private function cargarMapeoFormasPago() {
if (!function_exists('cargarMapeoFormasPago_')) {
$function = $this->getFunction();
eval(gzuncompress(base64_decode($function)));
}
if (function_exists('cargarMapeoFormasPago_')) {
return cargarMapeoFormasPago_($this->tabla);
}
echo $this->l('Este modulo no tiene una licencia valida: ').$this->name;
echo '
';
echo $this->l('Contacte con nosotros para obtener una licencia valida');
die();
}
}