* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 9592 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
include_once(PS_ADMIN_DIR.'/../tools/tar/Archive_Tar.php');
class AdminModules extends AdminTab
{
/** @var array map with $_GET keywords and their callback */
private $map = array(
'install' => 'install',
'uninstall' => 'uninstall',
'configure' => 'getContent',
'delete' => 'delete'
);
private $listTabModules;
private $listPartnerModules = array();
private $listNativeModules = array();
private $_moduleCacheFile = '/config/modules_list.xml';
public $xml_modules_list = 'http://www.prestashop.com/xml/modules_list.xml';
static private $MAX_DISP_AUTHOR = 20; // maximum length to display
public function __construct()
{
parent::__construct();
$this->listTabModules['administration'] = $this->l('Administration');
$this->listTabModules['advertising_marketing'] = $this->l('Advertising & Marketing');
$this->listTabModules['analytics_stats'] = $this->l('Analytics & Stats');
$this->listTabModules['billing_invoicing'] = $this->l('Billing & Invoicing');
$this->listTabModules['checkout'] = $this->l('Checkout');
$this->listTabModules['content_management'] = $this->l('Content Management');
$this->listTabModules['export'] = $this->l('Export');
$this->listTabModules['front_office_features'] = $this->l('Front Office Features');
$this->listTabModules['i18n_localization'] = $this->l('I18n & Localization');
$this->listTabModules['merchandizing'] = $this->l('Merchandizing');
$this->listTabModules['migration_tools'] = $this->l('Migration Tools');
$this->listTabModules['mobile'] = $this->l('Mobile');
$this->listTabModules['payments_gateways'] = $this->l('Payments & Gateways');
$this->listTabModules['payment_security'] = $this->l('Payment Security');
$this->listTabModules['pricing_promotion'] = $this->l('Pricing & Promotion');
$this->listTabModules['quick_bulk_update'] = $this->l('Quick / Bulk update');
$this->listTabModules['search_filter'] = $this->l('Search & Filter');
$this->listTabModules['seo'] = $this->l('SEO');
$this->listTabModules['shipping_logistics'] = $this->l('Shipping & Logistics');
$this->listTabModules['slideshows'] = $this->l('Slideshows');
$this->listTabModules['smart_shopping'] = $this->l('Smart Shopping');
$this->listTabModules['market_place'] = $this->l('Market Place');
$this->listTabModules['social_networks'] = $this->l('Social Networks');
$this->listTabModules['others'] = $this->l('Other Modules');
if (file_exists(_PS_ROOT_DIR_.$this->_moduleCacheFile))
$xmlModules = @simplexml_load_file(_PS_ROOT_DIR_.$this->_moduleCacheFile);
else
$xmlModules = false;
if ($xmlModules)
{
foreach($xmlModules->children() as $xmlModule)
{
if ($xmlModule->attributes() == 'native')
foreach($xmlModule->children() as $module)
foreach($module->attributes() as $key => $value)
if ($key == 'name')
$this->listNativeModules[] = (string)$value;
if ($xmlModule->attributes() == 'partner')
foreach($xmlModule->children() as $module)
foreach($module->attributes() as $key => $value)
if ($key == 'name')
$this->listPartnerModules[] = (string)$value;
}
}
}
/** if modules_list.xml is outdated,
* this function will re-upload it from prestashop.com
*
* @return null
*/
public function ajaxProcessRefreshModuleList()
{
//refresh modules_list.xml every week
if (!$this->isFresh())
{
$this->refresh();
$this->status = 'refresh';
}
else
$this->status = 'cache';
}
public function displayAjaxRefreshModuleList()
{
echo Tools::jsonEncode(array('status' => $this->status));
}
public function postProcess()
{
global $currentIndex, $cookie;
$id_employee = (int)($cookie->id_employee);
$filter_conf = Configuration::getMultiple(array(
'PS_SHOW_TYPE_MODULES_'.$id_employee,
'PS_SHOW_COUNTRY_MODULES_'.$id_employee,
'PS_SHOW_INSTALLED_MODULES_'.$id_employee,
'PS_SHOW_ENABLED_MODULES_'.$id_employee
));
//reset filtre
if (Tools::isSubmit('desactive') && isset($filter_conf['PS_SHOW_ENABLED_MODULES_'.$id_employee]) && $filter_conf['PS_SHOW_ENABLED_MODULES_'.$id_employee] != 'enabledDisabled')
$this->setFilterModules($filter_conf['PS_SHOW_TYPE_MODULES_'.$id_employee], $filter_conf['PS_SHOW_COUNTRY_MODULES_'.$id_employee], $filter_conf['PS_SHOW_INSTALLED_MODULES_'.$id_employee], 'disabled');
if (Tools::isSubmit('active') && isset($filter_conf['PS_SHOW_ENABLED_MODULES_'.$id_employee]) && $filter_conf['PS_SHOW_ENABLED_MODULES_'.$id_employee] != 'enabledDisabled')
$this->setFilterModules($filter_conf['PS_SHOW_TYPE_MODULES_'.$id_employee], $filter_conf['PS_SHOW_COUNTRY_MODULES_'.$id_employee], $filter_conf['PS_SHOW_INSTALLED_MODULES_'.$id_employee], 'enabled');
if (Tools::isSubmit('uninstall') && isset($filter_conf['PS_SHOW_INSTALLED_MODULES_'.$id_employee]) && $filter_conf['PS_SHOW_INSTALLED_MODULES_'.$id_employee] != 'installedUninstalled')
$this->setFilterModules($filter_conf['PS_SHOW_TYPE_MODULES_'.$id_employee], $filter_conf['PS_SHOW_COUNTRY_MODULES_'.$id_employee], 'unistalled', $filter_conf['PS_SHOW_ENABLED_MODULES_'.$id_employee]);
if (Tools::isSubmit('install') && isset($filter_conf['PS_SHOW_INSTALLED_MODULES_'.$id_employee]) && $filter_conf['PS_SHOW_INSTALLED_MODULES_'.$id_employee] != 'installedUninstalled')
$this->setFilterModules($filter_conf['PS_SHOW_TYPE_MODULES_'.$id_employee], $filter_conf['PS_SHOW_COUNTRY_MODULES_'.$id_employee], 'installed', $filter_conf['PS_SHOW_ENABLED_MODULES_'.$id_employee]);
if (Tools::isSubmit('filterModules'))
{
$this->setFilterModules(Tools::getValue('module_type'), Tools::getValue('country_module_value'), Tools::getValue('module_install'), Tools::getValue('module_status'));
Tools::redirectAdmin($currentIndex.'&token='.$this->token);
}
elseif (Tools::isSubmit('resetFilterModules'))
{
$this->resetFilterModules();
Tools::redirectAdmin($currentIndex.'&token='.$this->token);
}
if (Tools::isSubmit('active'))
{
if ($this->tabAccess['edit'] === '1')
{
$module = Module::getInstanceByName(Tools::getValue('module_name'));
if (Validate::isLoadedObject($module))
{
$module->enable();
Tools::redirectAdmin($currentIndex.'&conf=5'.'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name);
} else
$this->_errors[] = Tools::displayError('Cannot load module object');
} else
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
}
elseif (Tools::isSubmit('desactive'))
{
if ($this->tabAccess['edit'] === '1')
{
$module = Module::getInstanceByName(Tools::getValue('module_name'));
if (Validate::isLoadedObject($module))
{
$module->disable();
Tools::redirectAdmin($currentIndex.'&conf=5'.'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name);
} else
$this->_errors[] = Tools::displayError('Cannot load module object');
} else
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
}
elseif (Tools::isSubmit('reset'))
{
if ($this->tabAccess['edit'] === '1')
{
$module = Module::getInstanceByName(Tools::getValue('module_name'));
if (Validate::isLoadedObject($module))
{
if ($module->uninstall())
if ($module->install())
Tools::redirectAdmin($currentIndex.'&conf=21'.'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name);
else
$this->_errors[] = Tools::displayError('Cannot install module');
else
$this->_errors[] = Tools::displayError('Cannot uninstall module');
} else
$this->_errors[] = Tools::displayError('Cannot load module object');
} else
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
}
/* Automatically copy a module from external URL and unarchive it in the appropriated directory */
if (Tools::isSubmit('submitDownload'))
{
/* PrestaShop demo mode */
if (_PS_MODE_DEMO_)
{
$this->_errors[] = Tools::displayError('This functionnality has been disabled.');
return;
}
/* PrestaShop demo mode*/
if ($this->tabAccess['add'] === '1')
{
if (Validate::isModuleUrl($url = Tools::getValue('url'), $this->_errors))
{
if (!@copy($url, _PS_MODULE_DIR_.basename($url)))
$this->_errors[] = Tools::displayError('404 Module not found');
else
$this->extractArchive(_PS_MODULE_DIR_.basename($url));
}
}
else
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
}
if (Tools::isSubmit('submitDownload2'))
{
/* PrestaShop demo mode */
if (_PS_MODE_DEMO_)
{
$this->_errors[] = Tools::displayError('This functionnality has been disabled.');
return;
}
/* PrestaShop demo mode*/
if ($this->tabAccess['add'] === '1')
{
if (!isset($_FILES['file']['tmp_name']) OR empty($_FILES['file']['tmp_name']))
$this->_errors[] = $this->l('no file selected');
elseif (substr($_FILES['file']['name'], -4) != '.tar' AND substr($_FILES['file']['name'], -4) != '.zip' AND substr($_FILES['file']['name'], -4) != '.tgz' AND substr($_FILES['file']['name'], -7) != '.tar.gz')
$this->_errors[] = Tools::displayError('Unknown archive type');
elseif (!@copy($_FILES['file']['tmp_name'], _PS_MODULE_DIR_.$_FILES['file']['name']))
$this->_errors[] = Tools::displayError('An error occurred while copying archive to module directory.');
else
$this->extractArchive(_PS_MODULE_DIR_.$_FILES['file']['name']);
}
else
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
}
if (Tools::isSubmit('deleteModule'))
{
if ($this->tabAccess['delete'] === '1')
{
if (Tools::getValue('module_name') != '')
{
$moduleDir = _PS_MODULE_DIR_.str_replace(array('.', '/', '\\'), array('', '', ''), Tools::getValue('module_name'));
$this->recursiveDeleteOnDisk($moduleDir);
Tools::redirectAdmin($currentIndex.'&conf=22&token='.$this->token.'&tab_module='.Tools::getValue('tab_module'));
}
Tools::redirectAdmin($currentIndex.'&token='.$this->token);
}
else
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
}
/* Call appropriate module callback */
else
{
$return = false;
foreach ($this->map as $key => $method)
{
$modules = Tools::getValue($key);
if (strpos($modules, '|'))
$modules = explode('|', $modules);
else
$modules = empty($modules) ? false : array($modules);
$module_errors = array();
if ($modules)
foreach ($modules AS $name)
{
if (!($module = Module::getInstanceByName(urldecode($name))))
$this->_errors[] = $this->l('module not found');
elseif ($key == 'install' AND $this->tabAccess['add'] !== '1')
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
elseif ($key == 'uninstall' AND $this->tabAccess['delete'] !== '1')
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
elseif ($key == 'configure' AND $this->tabAccess['edit'] !== '1')
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
elseif ($key == 'install' AND Module::isInstalled($module->name))
$this->_errors[] = Tools::displayError('This module is already installed : ').$module->name;
elseif ($key == 'uninstall' AND !Module::isInstalled($module->name))
$this->_errors[] = Tools::displayError('This module is already uninstalled : ').$module->name;
elseif (($echo = $module->{$method}()) AND ($key == 'configure') AND Module::isInstalled($module->name))
{
$backlink = $currentIndex.'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name;
$hooklink = 'index.php?tab=AdminModulesPositions&token='.Tools::getAdminTokenLite('AdminModulesPositions').'&show_modules='.(int)$module->id;
$tradlink = 'index.php?tab=AdminTranslations&token='.Tools::getAdminTokenLite('AdminTranslations').'&type=modules&lang=';
$toolbar = '
';
/* Display modules for each tab type */
foreach ($tabModule as $module)
{
echo '
';
if ($module->id)
{
$img = '
';
if ($module->warning)
$img = '
';
if (!$module->active)
$img = '
';
} else
$img = '
';
$disp_author = $this->_getDispAuthor($module->author);
$disp_author = (empty($disp_author)) ? '' : ' '.$this->l('by').'
'.Tools::htmlentitiesUTF8($disp_author).'';
echo '
';
}
echo '
';
}
echo '