mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-02 00:46:44 +01:00
Cleanup del codice
This commit is contained in:
parent
81811ff293
commit
8be6e11009
@ -300,13 +300,12 @@ function do_backup($path = null)
|
||||
*/
|
||||
function backup_tables($file)
|
||||
{
|
||||
global $backup_dir;
|
||||
global $db_host;
|
||||
global $db_name;
|
||||
global $db_username;
|
||||
global $db_password;
|
||||
$config = App::getConfig();
|
||||
|
||||
$dump = new Ifsnop\Mysqldump\Mysqldump('mysql:host='.$config['db_host'].';dbname='.$config['db_name'], $config['db_username'], $config['db_password'], [
|
||||
'add-drop-table' => true,
|
||||
]);
|
||||
|
||||
$dump = new Ifsnop\Mysqldump\Mysqldump('mysql:host='.$db_host.';dbname='.$db_name, $db_username, $db_password, ['add-drop-table' => true]);
|
||||
$dump->start($file);
|
||||
}
|
||||
|
||||
|
@ -9,12 +9,15 @@ $id_tecnico = $dbo->fetchArray("SELECT idtipoanagrafica FROM an_tipianagrafiche
|
||||
|
||||
switch (post('op')) {
|
||||
case 'update':
|
||||
$post['piva'] = trim(strtoupper($post['piva']));
|
||||
$post['codice_fiscale'] = trim(strtoupper($post['codice_fiscale']));
|
||||
|
||||
// Leggo tutti i valori passati dal POST e li salvo in un array
|
||||
$dbo->update('an_anagrafiche', [
|
||||
'ragione_sociale' => $post['ragione_sociale'],
|
||||
'tipo' => $post['tipo'],
|
||||
'piva' => trim(strtoupper($post['piva'])),
|
||||
'codice_fiscale' => trim(strtoupper($post['codice_fiscale'])),
|
||||
'piva' => $post['piva'],
|
||||
'codice_fiscale' => $post['codice_fiscale'],
|
||||
'data_nascita' => $post['data_nascita'],
|
||||
'luogo_nascita' => $post['luogo_nascita'],
|
||||
'sesso' => $post['sesso'],
|
||||
@ -68,18 +71,16 @@ switch (post('op')) {
|
||||
|
||||
$_SESSION['infos'][] = str_replace('_NAME_', '"'.$post['ragione_sociale'].'"', "Informazioni per l'anagrafica _NAME_ salvate correttamente!");
|
||||
|
||||
|
||||
//validazione piva.
|
||||
// Validazione della Partita IVA
|
||||
$check_vat_number = Validate::isValidVatNumber(strtoupper($post['piva']));
|
||||
//print_r($check_vat_number);
|
||||
//exit();
|
||||
//se $check_vat_number non è null e la riposta è negativa --> mostro il messaggio di avviso.
|
||||
if ((!is_null($check_vat_number)) and (!$check_vat_number->valid)){
|
||||
|
||||
if (!empty($check_vat_number->error->info)){
|
||||
// Se $check_vat_number non è null e la riposta è negativa --> mostro il messaggio di avviso.
|
||||
if ((!is_null($check_vat_number)) && (!$check_vat_number->valid)) {
|
||||
if (!empty($check_vat_number->error->info)) {
|
||||
$_SESSION['errors'][] = $check_vat_number->error->info;
|
||||
}else{
|
||||
$_SESSION['errors'][] = tr('Attenzione questa partita IVA non sembra essere valida: ').strtoupper($post['piva']);
|
||||
} else {
|
||||
$_SESSION['errors'][] = tr('Attenzione: la partita IVA _IVA_ sembra non essere valida', [
|
||||
'_IVA_' => $post['piva'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ switch (filter('op')) {
|
||||
$intervallo = filter('intervallo');
|
||||
$parti_da_oggi = post('parti_da_oggi');
|
||||
|
||||
if (!empty($idcontratto_riga) and !empty($intervallo)) {
|
||||
if (!empty($idcontratto_riga) && !empty($intervallo)) {
|
||||
$qp = 'SELECT *, (SELECT idanagrafica FROM co_contratti WHERE id = '.$id_record.' ) AS idanagrafica, (SELECT data_conclusione FROM co_contratti WHERE id = '.$id_record.' ) AS data_conclusione, (SELECT descrizione FROM in_tipiintervento WHERE idtipointervento=co_righe_contratti.idtipointervento) AS tipointervento FROM co_righe_contratti WHERE id = '.$idcontratto_riga;
|
||||
$rsp = $dbo->fetchArray($qp);
|
||||
|
||||
@ -72,14 +72,14 @@ switch (filter('op')) {
|
||||
}
|
||||
|
||||
//inizio controllo data_conclusione, data valida e maggiore della $min_date
|
||||
if ((date('Y', strtotime($data_conclusione)) > 1970) and (date('Y-m-d', strtotime($min_date)) < date('Y-m-d', strtotime($data_conclusione)))) {
|
||||
if ((date('Y', strtotime($data_conclusione)) > 1970) && (date('Y-m-d', strtotime($min_date)) < date('Y-m-d', strtotime($data_conclusione)))) {
|
||||
//Ciclo partendo dalla data_richiesta fino all data conclusione del contratto
|
||||
while (date('Y-m-d', strtotime($data_richiesta)) < date('Y-m-d', strtotime($data_conclusione))) {
|
||||
//calcolo nuova data richiesta
|
||||
$data_richiesta = date('Y-m-d', strtotime($data_richiesta.' + '.intval($intervallo).' days'));
|
||||
|
||||
//controllo nuova data richiesta --> solo date maggiori o uguali di [oggi o data richiesta iniziale] ma che non superano la data di fine del contratto
|
||||
if ((date('Y-m-d', strtotime($data_richiesta)) >= $min_date) and (date('Y-m-d', strtotime($data_richiesta)) <= date('Y-m-d', strtotime($data_conclusione)))) {
|
||||
if ((date('Y-m-d', strtotime($data_richiesta)) >= $min_date) && (date('Y-m-d', strtotime($data_richiesta)) <= date('Y-m-d', strtotime($data_conclusione)))) {
|
||||
//Controllo che non esista già un promemoria idcontratto, idtipointervento e data_richiesta.
|
||||
if (count($dbo->fetchArray("SELECT id FROM co_righe_contratti WHERE data_richiesta = '".$data_richiesta."' AND idtipointervento = '".$idtipointervento."' AND idcontratto = '".$id_record."' ")) == 0) {
|
||||
$query = 'INSERT INTO `co_righe_contratti`(`idcontratto`, `idtipointervento`, `data_richiesta`, `richiesta`, `idsede`) VALUES('.prepare($id_record).', '.prepare($idtipointervento).', '.prepare($data_richiesta).', '.prepare($richiesta).', '.prepare($idsede).')';
|
||||
@ -237,7 +237,7 @@ if (count($rsp) != 0) {
|
||||
<td align="right">';
|
||||
|
||||
echo '
|
||||
<button type="button" class="btn btn-warning btn-sm" title="Pianifica..." data-toggle="tooltip" onclick="launch_modal(\'Pianifica\', \''.$rootdir.'/modules/contratti/plugins/addpianficazione.php?id_module='.Modules::get('Contratti')['id'].'&id_plugin='.Plugins::get('Pianificazione interventi')['id'].'&ref=interventi_contratti&id_record='.$id_record.'&idcontratto_riga='.$rsp[$i]['id'].'\');"'.((!empty($pianificabile) and strtotime($records[0]['data_conclusione'])) ? '' : ' disabled').'><i class="fa fa-clock-o"></i></button>';
|
||||
<button type="button" class="btn btn-warning btn-sm" title="Pianifica..." data-toggle="tooltip" onclick="launch_modal(\'Pianifica\', \''.$rootdir.'/modules/contratti/plugins/addpianficazione.php?id_module='.Modules::get('Contratti')['id'].'&id_plugin='.Plugins::get('Pianificazione interventi')['id'].'&ref=interventi_contratti&id_record='.$id_record.'&idcontratto_riga='.$rsp[$i]['id'].'\');"'.((!empty($pianificabile) && strtotime($records[0]['data_conclusione'])) ? '' : ' disabled').'><i class="fa fa-clock-o"></i></button>';
|
||||
|
||||
echo '
|
||||
<button type="button" '.$disabled.' class="btn btn-primary btn-sm '.$disabled.' " title="Pianifica intervento ora..." data-toggle="tooltip" onclick="launch_modal(\'Pianifica intervento\', \''.$rootdir.'/add.php?id_module='.Modules::get('Interventi')['id'].'&ref=interventi_contratti&idcontratto='.$id_record.'&idcontratto_riga='.$rsp[$i]['id'].'\');"'.(!empty($pianificabile) ? '' : ' disabled').'><i class="fa fa-calendar"></i></button>';
|
||||
|
@ -31,7 +31,6 @@ function get_ore_intervento($idintervento)
|
||||
*/
|
||||
function link_componente_to_articolo($idintervento, $idimpianto, $idarticolo, $qta)
|
||||
{
|
||||
global $docroot;
|
||||
$dbo = Database::getConnection();
|
||||
|
||||
if (!empty($idimpianto) && !empty($idintervento)) {
|
||||
|
@ -36,22 +36,20 @@ switch (post('op')) {
|
||||
}
|
||||
|
||||
$_SESSION['infos'][] = tr('Informazioni salvate correttamente!');
|
||||
|
||||
//validazione indirizzo email mittente.
|
||||
$check_email = Validate::isValidEmail($post['from_address'],1,1);
|
||||
//print_r($check_email);
|
||||
//exit();
|
||||
//se $check_email non è null e la riposta è negativa --> mostro il messaggio di avviso.
|
||||
if ((!is_null($check_email)) and (!$check_email->smtp_check)){
|
||||
|
||||
if (!empty($check_email->error->info)){
|
||||
// Validazione indirizzo email mittente
|
||||
$check_email = Validate::isValidEmail($post['from_address'], 1, 1);
|
||||
// Se $check_email non è null e la riposta è negativa --> mostro il messaggio di avviso.
|
||||
if ((!is_null($check_email)) && (!$check_email->smtp_check)) {
|
||||
if (!empty($check_email->error->info)) {
|
||||
$_SESSION['errors'][] = $check_email->error->info;
|
||||
}else{
|
||||
$_SESSION['errors'][] = tr('Attenzione questo indirizzo non sembra essere valido: ').$post['from_address'];
|
||||
} else {
|
||||
$_SESSION['errors'][] = tr("Attenzione: l'indirizzo email _EMAIL_ sembra non essere valido", [
|
||||
'_EMAIL_' => $post['from_address'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
|
@ -113,7 +113,8 @@ if ($record['nome'] != 'Amministratori') {
|
||||
for ($m = 0; $m < count($moduli); ++$m) {
|
||||
$perms_values = ['-', 'r', 'rw'];
|
||||
$perms_names = [tr('Nessun permesso'), tr('Sola lettura'), tr('Lettura e scrittura')];
|
||||
echo menuSelection($moduli[$m], -1, $perms_values, $perms_names);
|
||||
|
||||
echo menuSelection($moduli[$m], $id_record, -1, $perms_values, $perms_names);
|
||||
}
|
||||
|
||||
echo '
|
||||
|
@ -2,12 +2,8 @@
|
||||
|
||||
include_once __DIR__.'/../../core.php';
|
||||
|
||||
function menuSelection($element, $depth, $perms_values, $perms_names)
|
||||
function menuSelection($element, $group_id, $depth, $perms_values, $perms_names)
|
||||
{
|
||||
global $rootdir;
|
||||
global $id_module;
|
||||
global $id_record;
|
||||
|
||||
$dbo = Database::getConnection();
|
||||
|
||||
++$depth;
|
||||
@ -18,16 +14,17 @@ function menuSelection($element, $depth, $perms_values, $perms_names)
|
||||
if ($submenus != null && count($submenus) != 0) {
|
||||
$temp = '';
|
||||
foreach ($submenus as $submenu) {
|
||||
$temp .= menuSelection($submenu, $depth, $perms_values, $perms_names);
|
||||
$temp .= menuSelection($submenu, $group_id, $depth, $perms_values, $perms_names);
|
||||
}
|
||||
}
|
||||
|
||||
$result .= '
|
||||
<tr>
|
||||
<td>'.str_repeat(' ', $depth).$name.'</td>
|
||||
<td>
|
||||
<select name="permesso" class="form-control superselect" onchange="update_permissions('.$element['id'].', $(this).find(\'option:selected\').val())">';
|
||||
// Permessi
|
||||
$rsp = $dbo->fetchArray('SELECT permessi FROM zz_permissions WHERE idgruppo='.prepare($id_record).' AND idmodule='.prepare($element['id']));
|
||||
$rsp = $dbo->fetchArray('SELECT permessi FROM zz_permissions WHERE idgruppo='.prepare($group_id).' AND idmodule='.prepare($element['id']));
|
||||
|
||||
if (count($rsp) == 0) {
|
||||
$permessi = '-';
|
||||
|
23
src/App.php
23
src/App.php
@ -94,7 +94,12 @@ class App
|
||||
|
||||
$defaultConfig = self::getDefaultConfig();
|
||||
|
||||
return array_merge($defaultConfig, $config);
|
||||
$result = array_merge($defaultConfig, $config);
|
||||
|
||||
// Operazioni di normalizzazione sulla configurazione
|
||||
$result['debug'] = !empty($result['debug']);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -271,17 +276,25 @@ class App
|
||||
$options = json_decode($options, true);
|
||||
$options = $options['main_query'][0];
|
||||
|
||||
$fields = [];
|
||||
$order_by = [];
|
||||
|
||||
$search = [];
|
||||
$slow = [];
|
||||
$format = [];
|
||||
|
||||
$query = $options['query'];
|
||||
$fields = explode(',', $options['fields']);
|
||||
foreach ($fields as $key => $value) {
|
||||
$fields[$key] = trim($value);
|
||||
$views = explode(',', $options['fields']);
|
||||
foreach ($views as $view) {
|
||||
$fields[] = trim($view);
|
||||
$order_by[] = '`'.trim($view).'`';
|
||||
|
||||
$search[] = 1;
|
||||
$slow[] = 0;
|
||||
$format[] = 0;
|
||||
}
|
||||
|
||||
$search_inside = $fields;
|
||||
$order_by = $fields;
|
||||
|
||||
return [
|
||||
'query' => self::replacePlaceholder($query),
|
||||
|
@ -48,8 +48,6 @@ class Database extends Util\Singleton
|
||||
*/
|
||||
protected function __construct($server, $username, $password, $database_name, $charset = null, $option = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION])
|
||||
{
|
||||
global $debug;
|
||||
|
||||
if (is_array($server)) {
|
||||
$host = $server['host'];
|
||||
$port = !empty($server['port']) ? $server['port'] : null;
|
||||
@ -80,7 +78,7 @@ class Database extends Util\Singleton
|
||||
$this->option
|
||||
);
|
||||
|
||||
if (!empty($debug)) {
|
||||
if (App::getConfig()['debug']) {
|
||||
$pdo = new \DebugBar\DataCollector\PDO\TraceablePDO($pdo);
|
||||
}
|
||||
|
||||
@ -120,15 +118,12 @@ class Database extends Util\Singleton
|
||||
*/
|
||||
public static function getConnection($new = false)
|
||||
{
|
||||
$class = get_called_class(); // late-static-bound class name
|
||||
$class = get_called_class();
|
||||
|
||||
if (empty(parent::$instance[$class]) || !parent::$instance[$class]->isConnected() || $new) {
|
||||
global $db_host;
|
||||
global $db_username;
|
||||
global $db_password;
|
||||
global $db_name;
|
||||
$config = App::getConfig();
|
||||
|
||||
parent::$instance[$class] = new self($db_host, $db_username, $db_password, $db_name);
|
||||
parent::$instance[$class] = new self($config['db_host'], $config['db_username'], $config['db_password'], $config['db_name']);
|
||||
}
|
||||
|
||||
return parent::$instance[$class];
|
||||
|
@ -292,10 +292,8 @@ class Modules
|
||||
*/
|
||||
protected static function sidebarMenu($element, $actual = null)
|
||||
{
|
||||
global $rootdir;
|
||||
|
||||
$options = ($element['options2'] != '') ? $element['options2'] : $element['options'];
|
||||
$link = ($options != '' && $options != 'menu') ? $rootdir.'/controller.php?id_module='.$element['id'] : 'javascript:;';
|
||||
$link = ($options != '' && $options != 'menu') ? ROOTDIR.'/controller.php?id_module='.$element['id'] : 'javascript:;';
|
||||
$title = $element['title'];
|
||||
$target = ($element['new'] == 1) ? '_blank' : '_self';
|
||||
$active = ($actual == $element['name']);
|
||||
|
151
src/Validate.php
151
src/Validate.php
@ -5,11 +5,9 @@
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
class VALIDATE
|
||||
class Validate
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Controlla se la partita iva inserita è valida.
|
||||
*
|
||||
* @param string $vat_number
|
||||
@ -18,117 +16,98 @@ class VALIDATE
|
||||
*/
|
||||
public static function isValidVatNumber($vat_number)
|
||||
{
|
||||
$access_key = Settings::get('apilayer API key for VAT number');
|
||||
|
||||
$access_key = Settings::get('apilayer API key for VAT number');
|
||||
if ((!empty($vat_number)) && (!empty($access_key))) {
|
||||
if (strpos($vat_number, 'IT') === false) {
|
||||
$vat_number = 'IT'.$vat_number;
|
||||
}
|
||||
|
||||
if ((!empty($vat_number)) and (!empty($access_key))){
|
||||
$ch = curl_init();
|
||||
|
||||
if (strpos($vat_number, 'IT') === false) {
|
||||
$vat_number = 'IT'.$vat_number;
|
||||
}
|
||||
$qs = '&vat_number='.urlencode(strtoupper($vat_number));
|
||||
|
||||
$ch = curl_init();
|
||||
$url = "http://apilayer.net/api/validate?access_key=$access_key".$qs;
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
||||
$qs = "&vat_number=" . urlencode(strtoupper($vat_number));
|
||||
$data = json_decode(curl_exec($ch));
|
||||
curl_close($ch);
|
||||
|
||||
$url = "http://apilayer.net/api/validate?access_key=$access_key" . $qs;
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
||||
/*se la riposta è null imposto la relativa proprietà dell'oggetto a 0*/
|
||||
if ($data->valid == null) {
|
||||
$data->valid = 0;
|
||||
}
|
||||
|
||||
$data = json_decode(curl_exec($ch));
|
||||
curl_close($ch);
|
||||
|
||||
/*se la riposta è null imposto la relativa proprietà dell'oggetto a 0*/
|
||||
if ($data->valid==null)
|
||||
$data->valid = 0;
|
||||
|
||||
//$data->url = $url;
|
||||
//$data->json_last_error = json_last_error();
|
||||
//$data->json_last_error_msg = json_last_error_msg();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $data;
|
||||
//$data->url = $url;
|
||||
//$data->json_last_error = json_last_error();
|
||||
//$data->json_last_error_msg = json_last_error_msg();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Controlla se l'email inserita è valida.
|
||||
*
|
||||
* @param string $email
|
||||
* @param bool $format
|
||||
* @param bool $smtp
|
||||
* @param bool $format
|
||||
* @param bool $smtp
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function isValidEmail($email, $format = 1, $smtp = 0)
|
||||
{
|
||||
$access_key = Settings::get('apilayer API key for Email');
|
||||
|
||||
$access_key = Settings::get('apilayer API key for Email');
|
||||
/*$data = (object) [
|
||||
'format_valid' => NULL,
|
||||
'mx_found' => NULL,
|
||||
'smtp_check' => NULL,
|
||||
];*/
|
||||
|
||||
/*$data = (object) [
|
||||
'format_valid' => NULL,
|
||||
'mx_found' => NULL,
|
||||
'smtp_check' => NULL,
|
||||
];*/
|
||||
if ((!empty($email)) && (!empty($access_key))) {
|
||||
$ch = curl_init();
|
||||
|
||||
if ((!empty($email)) and (!empty($access_key))){
|
||||
$qs = '&email='.urlencode($email);
|
||||
$qs .= "&smtp=$smtp";
|
||||
$qs .= "&format=$format";
|
||||
|
||||
$ch = curl_init();
|
||||
$url = "http://apilayer.net/api/check?access_key=$access_key".$qs;
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
||||
$qs = "&email=" . urlencode($email);
|
||||
$qs .= "&smtp=$smtp";
|
||||
$qs .= "&format=$format";
|
||||
$data = json_decode(curl_exec($ch));
|
||||
curl_close($ch);
|
||||
|
||||
$url = "http://apilayer.net/api/check?access_key=$access_key" . $qs;
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
||||
/*se la riposta è null verficando il formato, il record mx o il server smtp imposto la relativa proprietà dell'oggetto a 0*/
|
||||
if (($data->format_valid == null) && ($format)) {
|
||||
$data->format_valid = 0;
|
||||
}
|
||||
|
||||
$data = json_decode(curl_exec($ch));
|
||||
curl_close($ch);
|
||||
|
||||
/*se la riposta è null verficando il formato, il record mx o il server smtp imposto la relativa proprietà dell'oggetto a 0*/
|
||||
if (($data->format_valid==null)and($format))
|
||||
$data->format_valid = 0;
|
||||
if (($data->mx_found == null) && ($smtp)) {
|
||||
$data->mx_found = 0;
|
||||
}
|
||||
|
||||
if (($data->mx_found==null)and($smtp))
|
||||
$data->mx_found = 0;
|
||||
if (($data->smtp_check == null) && ($smtp)) {
|
||||
$data->smtp_check = 0;
|
||||
}
|
||||
|
||||
if (($data->smtp_check==null)and($smtp))
|
||||
$data->smtp_check = 0;
|
||||
/*controllo o meno smtp
|
||||
if ($data->smtp_check==false)
|
||||
$data->smtp_check = 0;
|
||||
|
||||
|
||||
/*controllo o meno smtp
|
||||
if ($data->smtp_check==false)
|
||||
$data->smtp_check = 0;
|
||||
if ($data->mx_found==false)
|
||||
$data->mx_found = 0;
|
||||
*/
|
||||
/* --- */
|
||||
|
||||
if ($data->mx_found==false)
|
||||
$data->mx_found = 0;
|
||||
*/
|
||||
/* --- */
|
||||
$data->json_last_error = json_last_error();
|
||||
$data->json_last_error_msg = json_last_error_msg();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$data->json_last_error = json_last_error();
|
||||
$data->json_last_error_msg = json_last_error_msg();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user