Files
GestioneSpiaggia.it/application/modules/admin/controllers/IndexController.php
T
giacomo 21bf9acf48 Add "Identificativo DB" field to Log Licenze functionality
Added support for the "Identificativo DB" field across Log Licenze views, controller actions, and database operations. Updated UI elements, including table headers, rows, and search filters, to display and manage the new field.
2026-04-23 08:55:44 +02:00

330 lines
13 KiB
PHP

<?php
class Admin_IndexController extends App_Controller_Sections_Section
{
public $_configs;
protected Application_Model_Generic $_genericModel;
protected $_authService;
protected $_ipManager;
protected $_parametriSito;
protected $_datiAziendali;
protected $_VariabiliSito;
public $_MENUITEM;
public $_PAGETITLE;
public $_ICONTITLE;
public $_SECONDLEVEL;
public $_SECONDLEVEL_ACTION;
public $_SIDEBAR_COLLAPSED;
public $_EVENTLOADER;
public $_ANGULARJS_MODULE_NAME;
public function init()
{
$this->_helper->layout->setLayout('admin');
$this->_authService = new App_Service_Auth();
$this->_genericModel = new Application_Model_Generic();
$this->_configs = new App_Service_ConfigManager();
$this->_ipManager = new App_Service_IpManager();
$this->_parametriSito = new App_Service_JsonConfiguration('parametri_sito');
$this->_datiAziendali = new App_Service_JsonConfiguration('dati_aziendali');
$this->_VariabiliSito = new App_Service_VariabiliSito();
$this->_MENUITEM = 'dashboard';
$this->_PAGETITLE = 'DashBoard';
$this->_ICONTITLE = 'fa-dashboard';
$this->_SECONDLEVEL = null;
$this->_SECONDLEVEL_ACTION = null;
$this->_EVENTLOADER = FALSE;
$this->_ANGULARJS_MODULE_NAME = false;
}
public function preDispatch()
{
$this->_SIDEBAR_COLLAPSED = boolval($_COOKIE['ui_sidebar_collapsed']) || false;
$this->view->enableTestSdk = $this->_ipManager->controllaAbilitazioneTestSdk();
}
public function postDispatch()
{
$this->view->controller = $this->getRequest()->getControllerName();
$this->view->action = $this->getRequest()->getActionName();
$this->view->menu = $this->_MENUITEM;
$this->view->pageTitle = $this->_PAGETITLE;
$this->view->iconTitle = $this->_ICONTITLE;
$this->view->secondLevel = $this->_SECONDLEVEL;
$this->view->secondLevelAction = $this->_SECONDLEVEL_ACTION;
$this->view->eventLoader = $this->_EVENTLOADER;
$this->view->sideBarCollapsed = $this->_SIDEBAR_COLLAPSED;
$this->view->angularModuleName = $this->_ANGULARJS_MODULE_NAME;
$this->view->parametriSito = $this->_parametriSito->getAllParams();
$this->view->datiAziendali = $this->_datiAziendali->getAllParams();
}
public function logoutAction()
{
$this->_authService->clear();
return $this->_helper->redirector('index', 'index', 'default');
}
public function indexAction()
{
$this->_EVENTLOADER = 'dashboard';
// $this->_ANGULARJS_MODULE_NAME = 'dashboard';
$this->render('dashboard');
}
public function infoAction()
{
$this->_helper->getHelper('layout')->disableLayout();
$this->_helper->viewRenderer->setNoRender();
phpinfo();
}
/*===============================================================================================
* =========================== GESTIONE SETTINGS ============================
* =============================================================================================*/
public function settingsAction()
{
$this->_MENUITEM = "settings";
$this->_PAGETITLE = 'Impostazioni';
$this->_ICONTITLE = 'fa-cogs';
$this->_EVENTLOADER = 'settings';
$this->view->assign($this->_configs->getAllParam());
$this->view->assign($this->_parametriSito->getAllParams());
$this->view->tabname = (!$_COOKIE['settings_tabname']) ? 'generico' : $_COOKIE['settings_tabname'];
$this->view->email_templates = $this->_genericModel->getList('EmailTemplate', null, null);
$this->view->popover_default_param_content = $this->getDefaultParamsPopoverTemplate();
}
public function savesettingsAction()
{
if ($this->getRequest()->isXmlHttpRequest()) {
$this->_helper->getHelper('layout')->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$params = $this->getAllParams();
unset($params['controller']);
unset($params['module']);
unset($params['action']);
unset($params['section']);
$response = array();
switch ($this->_getParam('section')) {
case 'generico':
$params['interrutore_sito'] = (isset($params['interrutore_sito'])) ? 'on' : 'off';
$params['interrutore_services'] = (isset($params['interrutore_services'])) ? 'on' : 'off';
$params['interrutore_webservices_v1'] = (isset($params['interrutore_webservices_v1'])) ? 'on' : 'off';
$response = $this->saveConfigParams($params);
break;
case 'sito':
foreach ($params as $key => $value) {
$this->_parametriSito->set($key, $value);
$response[$key] = 'OK';
}
break;
case 'test':
$params['interrutore_testdb'] = (isset($params['interrutore_testdb'])) ? 'on' : 'off';
$params['interrutore_paypal_test'] = (isset($params['interrutore_paypal_test'])) ? 'on' : 'off';
$params['interrutore_stripe_test'] = (isset($params['interrutore_stripe_test'])) ? 'on' : 'off';
$response = $this->saveConfigParams($params);
break;
case 'accesso':
$response = $this->saveConfigParams($params);
break;
}
if ($this->check_has_error_value($response)) {
$response['stato'] = 'success';
} else {
$response['stato'] = 'error';
}
$response = Zend_Json::encode($response);
$this->getResponse()->setHeader('Content-type', 'application/json;charset=UTF-8')->setBody($response);
}
}
public function savenewpasswordAction()
{
if ($this->getRequest()->isXmlHttpRequest()) {
$this->_helper->getHelper('layout')->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$params = $this->getAllParams();
unset($params['controller']);
unset($params['module']);
unset($params['action']);
$response = array();
if (!$params['vecchia_pwd']) {
return $this->getResponse()->setHeader('Content-type', 'application/json;charset=UTF-8')->setBody(Zend_Json::encode(array('status' => false, 'message' => 'Inserire la vecchia password')));
}
if (!$params['nuova_pwd']) {
return $this->getResponse()->setHeader('Content-type', 'application/json;charset=UTF-8')->setBody(Zend_Json::encode(array('status' => false, 'message' => 'Inserire la nuova password')));
}
if (!$params['nuova_pwd2']) {
return $this->getResponse()->setHeader('Content-type', 'application/json;charset=UTF-8')->setBody(Zend_Json::encode(array('status' => false, 'message' => 'Ripeti la nuova password')));
}
if (strtolower($params['nuova_pwd']) == strtolower($params['vecchia_pwd'])) {
return $this->getResponse()->setHeader('Content-type', 'application/json;charset=UTF-8')->setBody(Zend_Json::encode(array('status' => false, 'message' => 'La nuova password non può essere uguale a quella corrente')));
}
if (strtolower($params['nuova_pwd']) != strtolower($params['nuova_pwd2'])) {
return $this->getResponse()->setHeader('Content-type', 'application/json;charset=UTF-8')->setBody(Zend_Json::encode(array('status' => false, 'message' => 'Le password non coincidono')));
}
$admin = $this->_genericModel->getByColumnName('Users', 'username', 'admin');
//Confronto le password
$passwordSalt = Zend_Registry::get('ENVIROMENTS')->get('password_salt');
if (md5($passwordSalt . $params['vecchia_pwd']) != $admin['password']) {
return $this->getResponse()->setHeader('Content-type', 'application/json;charset=UTF-8')->setBody(Zend_Json::encode(array('status' => false, 'message' => 'La vecchia password è errata', 'resetForm' => true)));
}
//Salvo la nuova password
$this->_genericModel->update('Users', $admin['id'], array('password' => md5($passwordSalt . $params['nuova_pwd'])));
$this->getResponse()->setHeader('Content-type', 'application/json;charset=UTF-8')->setBody(Zend_Json::encode(array('status' => true)));
}
}
public function testrootAction()
{
$this->getHelper('layout')->disableLayout();
$this->getHelper('viewRenderer')->setNoRender();
$userHostAdapter = new Zend_Db_Adapter_Pdo_Mysql([
'host' => '127.0.0.1',
'username' => 'root',
'password' => 'Adriatica108-110@',
'dbname' => 'gestionespiaggia_test',
'charset' => 'utf8'
]);
try {
// $res = $userHostAdapter->query("CREATE DATABASE IF NOT EXISTS gestionespiaggia_test")->fetch();
// $res = $userHostAdapter->query("GRANT ALL PRIVILEGES ON `gestionespiaggia\_test`.* TO `gestionespiaggia`@`localhost`")->fetch();
// $res = $userHostAdapter->query("SELECT user, host FROM mysql.user;")->fetchAll();
// $res = $userHostAdapter->query("SHOW DATABASES;")->fetchAll();
// $res = $userHostAdapter->query("SHOW GRANTS FOR 'gestionespiaggia'@'localhost';")->fetchAll();
/*$res = $userHostAdapter->query("SELECT
schema_name AS database_name,
default_character_set_name AS charset,
default_collation_name AS collation
FROM information_schema.schemata;")->fetchAll();*/
/*$res = $userHostAdapter->query("SELECT
user,
host,
Super_priv,
Create_priv,
Drop_priv,
Grant_priv,
Select_priv,
Insert_priv,
Update_priv,
Delete_priv
FROM mysql.user;")->fetchAll();*/
echo "<pre>" . print_r($res, true) . "</pre>";
} catch (Exception $e) {
echo "<pre>" . print_r($e, true) . "</pre>";
}
}
private function checkNullValue($value)
{
return (!$value || strtolower($value) === 'null') ? null : $value;
}
/*===============================================================================================
* =========================== FUNZIONI PRIVATE DEL CONTROLLER =========================
* =============================================================================================*/
public function getMainModel()
{
return $this->_genericModel;
}
protected function saveConfigParams($params)
{
$response = array();
foreach ($params as $key => $value) {
$valori_non_null = array();
if (!$value && in_array($key, $valori_non_null)) {
$response[$key] = 'Errore';
} else {
$this->_configs->set($key, $value);
$response[$key] = 'OK';
}
}
$this->_configs->write();
return $response;
}
/**
* Scorre l'array se trova un valore riconosciuto come errore restituisce false altrimenti true
* @param array $array
* @return boolean
*/
protected function check_has_error_value($array)
{
foreach ($array as $key => $value) {
if ($value == 'Error' || $value == 'Errore' || $value == '0') {
return FALSE;
}
}
return true;
}
/**
* Funzione che genera le indicazioni dei valori dei parametri di default leggendoli dal file di configurazione
* @return string
*/
public function getDefaultParamsPopoverTemplate()
{
$html = '<div><small class=&quot;text-danger&quot;>Inserire il nome variabile senza gli apici</small><br>';
//$html .= '<table class=&quot;table table-bordered table-striped table-popover&quot; ><thead><tr><th>Variabile</th><th>Valore</th></tr></thead><tbody>';
$params = $this->_datiAziendali->getAllParams();
foreach ($params as $key => $val) {
$html .= "<b>%default_" . $key . "%<br> - <small>" . $val . "</small></br>";
}
$html .= '</div>';
return $html;
}
} //Close Class