Initial Commit
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
class Zend_Controller_Action_Helper_Base64Image extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* Passata una stringa di un immagine base 64 la salva con il nome file passato e nel path passato ne restituisce poi il path completo
|
||||
*
|
||||
* @param $dataString
|
||||
* @param $nomeFile
|
||||
* @param $path
|
||||
* @return string
|
||||
* @throws App_Controller_Errors_WebServiceError
|
||||
*/
|
||||
public function direct($dataString, $nomeFile, $path)
|
||||
{
|
||||
|
||||
if (!$dataString) {
|
||||
throw new App_Controller_Errors_WebServiceError('Datastring non valido',
|
||||
App_Controller_Errors_WebServiceError::WEBSERVICE_GENERIC_ERROR);
|
||||
}
|
||||
|
||||
if (!$nomeFile) {
|
||||
throw new App_Controller_Errors_WebServiceError('Nome File non valido',
|
||||
App_Controller_Errors_WebServiceError::WEBSERVICE_GENERIC_ERROR);
|
||||
}
|
||||
|
||||
if (!$path) {
|
||||
throw new App_Controller_Errors_WebServiceError('Path non valido',
|
||||
App_Controller_Errors_WebServiceError::WEBSERVICE_GENERIC_ERROR);
|
||||
}
|
||||
|
||||
if (preg_match('/^data:image\/(\w+);base64,/', $dataString, $type)) {
|
||||
$dataString = substr($dataString, strpos($dataString, ',') + 1);
|
||||
$type = strtolower($type[1]); // jpg, png, gif
|
||||
|
||||
if (!in_array($type, ['jpg', 'jpeg', 'gif', 'png'])) {
|
||||
throw new App_Controller_Errors_WebServiceError('Immagine Base64 non valida',
|
||||
App_Controller_Errors_WebServiceError::WEBSERVICE_GENERIC_ERROR);
|
||||
}
|
||||
|
||||
$data = base64_decode($dataString);
|
||||
|
||||
if ($data === false) {
|
||||
throw new App_Controller_Errors_WebServiceError('Errore di decodifica Base64',
|
||||
App_Controller_Errors_WebServiceError::WEBSERVICE_GENERIC_ERROR);
|
||||
}
|
||||
} else {
|
||||
throw new App_Controller_Errors_WebServiceError('Formato stringa immagine base 64 non valido',
|
||||
App_Controller_Errors_WebServiceError::WEBSERVICE_GENERIC_ERROR);
|
||||
}
|
||||
|
||||
$nomeFile = explode('.',$nomeFile)[0];
|
||||
|
||||
$completePathFile = "$path/$nomeFile.{$type}";
|
||||
file_put_contents($completePathFile, $data);
|
||||
|
||||
return $completePathFile;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class Zend_Controller_Action_Helper_CalcUtility extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
|
||||
protected $_genericModel;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->_genericModel = new Application_Model_Generic();
|
||||
}
|
||||
|
||||
public function direct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
class Zend_Controller_Action_Helper_Currency extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
|
||||
|
||||
public function direct($number)
|
||||
{
|
||||
$currency = new Zend_Currency('it_IT');
|
||||
if ($number == null) return null;
|
||||
return $currency->toCurrency($number);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
class Zend_Controller_Action_Helper_Docsmaker extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
protected $_dataHelper;
|
||||
protected $_formatDataHelper;
|
||||
protected $_globalFunction;
|
||||
protected $_genericModel;
|
||||
protected $_view;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->_dataHelper = $this->getActionController()->getHelper('ExtractData');
|
||||
$this->_formatDataHelper = $this->getActionController()->getHelper('FormatData');
|
||||
$this->_globalFunction = $this->getActionController()->getHelper('Globalfunction');
|
||||
$this->_view = null;
|
||||
}
|
||||
|
||||
public function direct()
|
||||
{
|
||||
}
|
||||
|
||||
public function reportAttivita(Zend_View &$view, $dati, $mode = 'I', $autoprint = false, $returnHtml = false)
|
||||
{
|
||||
|
||||
$this->_view = $view;
|
||||
$preOutputScript = "";
|
||||
|
||||
if (!$this->_view) {
|
||||
throw new Zend_Exception("Errore view non presente");
|
||||
}
|
||||
|
||||
if (!$dati) {
|
||||
throw new Zend_Exception("Errore dati non ricevuti");
|
||||
}
|
||||
|
||||
/********************************************* Calcolo dei dati necessari **********************************************/
|
||||
|
||||
$totali = array_merge($dati['ElencoLicenze']);
|
||||
end($totali);
|
||||
$this->_view->lastRigaKey = key($totali);
|
||||
|
||||
//$stringa_periodo = ($data[0] === $data[1]) ? 'del ' . $this->_formatDataHelper->direct($data[0], 'd/m/Y') : 'dal ' . $this->_formatDataHelper->direct($data[0], 'd/m/Y') . ' al ' . $this->_formatDataHelper->direct($data[1], 'd/m/Y');
|
||||
|
||||
$this->_view->assign(array(
|
||||
'Data' => $dati['Data'],
|
||||
'Periodo' => $dati['Periodo'],
|
||||
'ElencoLicenze' => $dati['ElencoLicenze'],
|
||||
'TotaliAttivazioni' => $dati['TotaliAttivazioni'],
|
||||
'TotaleFe' => $dati['TotaleFe'],
|
||||
'Rivenditore' => $dati['Rivenditore']
|
||||
));
|
||||
|
||||
$this->_view->setScriptPath(APPLICATION_PATH . "/modules/default/views/scripts/");
|
||||
|
||||
$filename = 'Report ' . str_replace('/', '', $dati['Periodo']) . ' - ' . $dati['Rivenditore']['RagioneSociale'];
|
||||
|
||||
if ($mode == 'F') {
|
||||
$preOutputScript = APPLICATION_PATH . "/../public/doctmp/";
|
||||
}
|
||||
|
||||
$this->getResponse()->setBody('');
|
||||
$html = $this->_view->render('index/print/reportattivita.phtml');
|
||||
|
||||
$mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8', 'format' => 'A4',
|
||||
'margin_top' => 38, 'margin_right' => 10, 'margin_bottom' => 5, 'margin_left' => 10,
|
||||
'margin_header' => 5, 'margin_footer' => 5]);
|
||||
$mpdf->setAutoTopMargin = 'stretch';
|
||||
$mpdf->setAutoBottomMargin = 'stretch';
|
||||
$mpdf->keep_table_proportions = true;
|
||||
|
||||
$mpdf->SetTitle($filename);
|
||||
$mpdf->SetAuthor("Adriatica Sistemi soc. coop.");
|
||||
$mpdf->SetDisplayMode('fullpage');
|
||||
|
||||
//Funzione che avvia la stampa direttamente
|
||||
if ($autoprint == 'true') {
|
||||
$mpdf->SetJS('this.print();');
|
||||
}
|
||||
|
||||
if (!$returnHtml) {
|
||||
$mpdf->WriteHTML($html);
|
||||
//Il Mode 'S' restituisce il contenuto del file che codifico in base64 e lo retituisco
|
||||
if ($mode == 'S') {
|
||||
$res = array();
|
||||
$res['filename'] = $filename . ".pdf";
|
||||
$res['filecontent'] = $mpdf->Output($preOutputScript . $filename . ".pdf", $mode);
|
||||
return $res;
|
||||
} else {
|
||||
//Gestione per gli altri mode 'I' o 'F' o 'D'
|
||||
$mpdf->Output($preOutputScript . $filename . ".pdf", $mode);
|
||||
$res = array();
|
||||
$res['filename'] = $filename . ".pdf";
|
||||
$res['path'] = $preOutputScript;
|
||||
$res['completeFilePath'] = $preOutputScript . $filename . '.pdf';
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function reportAttivitaAdmin(Zend_View &$view, $dati, $mode = 'I', $autoprint = false, $returnHtml = false)
|
||||
{
|
||||
|
||||
$this->_view = $view;
|
||||
$preOutputScript = "";
|
||||
|
||||
if (!$this->_view) {
|
||||
throw new Zend_Exception("Errore view non presente");
|
||||
}
|
||||
|
||||
if (!$dati) {
|
||||
throw new Zend_Exception("Errore dati non ricevuti");
|
||||
}
|
||||
|
||||
/********************************************* Calcolo dei dati necessari **********************************************/
|
||||
|
||||
$tmp = $dati['ElencoRivenditori'];
|
||||
end($tmp);
|
||||
$this->_view->lastRigaKey = key($tmp);
|
||||
|
||||
$this->_view->assign(array(
|
||||
'Data' => $dati['Data'],
|
||||
'Periodo' => $dati['Periodo'],
|
||||
'ElencoAttivita' => $dati['ElencoAttivita']
|
||||
));
|
||||
|
||||
$this->_view->setScriptPath(APPLICATION_PATH . "/modules/default/views/scripts/");
|
||||
|
||||
$filename = 'Report Riepilogo per Attività ' . str_replace('/', '-', $dati['Periodo']);
|
||||
|
||||
if ($mode == 'F') {
|
||||
$preOutputScript = APPLICATION_PATH . "/../public/doctmp/";
|
||||
}
|
||||
|
||||
$this->getResponse()->setBody('');
|
||||
$html = $this->_view->render('index/print/reportattivitaadmin.phtml');
|
||||
|
||||
$mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8', 'format' => 'A4',
|
||||
'margin_top' => 28, 'margin_right' => 10, 'margin_bottom' => 5, 'margin_left' => 10,
|
||||
'margin_header' => 5, 'margin_footer' => 5]);
|
||||
$mpdf->setAutoTopMargin = 'stretch';
|
||||
$mpdf->setAutoBottomMargin = 'stretch';
|
||||
$mpdf->keep_table_proportions = true;
|
||||
|
||||
$mpdf->SetTitle($filename);
|
||||
$mpdf->SetAuthor("Adriatica Sistemi soc. coop.");
|
||||
$mpdf->SetDisplayMode('fullpage');
|
||||
|
||||
//Funzione che avvia la stampa direttamente
|
||||
if ($autoprint == 'true') {
|
||||
$mpdf->SetJS('this.print();');
|
||||
}
|
||||
|
||||
if (!$returnHtml) {
|
||||
$mpdf->WriteHTML($html);
|
||||
//Il Mode 'S' restituisce il contenuto del file che codifico in base64 e lo retituisco
|
||||
if ($mode == 'S') {
|
||||
$res = array();
|
||||
$res['filename'] = $filename . ".pdf";
|
||||
$res['filecontent'] = $mpdf->Output($preOutputScript . $filename . ".pdf", $mode);
|
||||
return $res;
|
||||
} else {
|
||||
//Gestione per gli altri mode 'I' o 'F' o 'D'
|
||||
$mpdf->Output($preOutputScript . $filename . ".pdf", $mode);
|
||||
$res = array();
|
||||
$res['filename'] = $filename . ".pdf";
|
||||
$res['path'] = $preOutputScript;
|
||||
$res['completeFilePath'] = $preOutputScript . $filename . '.pdf';
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
class Zend_Controller_Action_Helper_Email extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
|
||||
protected $_configs;
|
||||
protected $_ipManager;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->_configs = new App_Service_ConfigManager();
|
||||
$this->_ipManager = new App_Service_IpManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invia un email all'utente con i parametri scelti
|
||||
*
|
||||
* @param String $message | $subject | $email
|
||||
* @param boolean $text | $footer
|
||||
* @return void
|
||||
*/
|
||||
public function direct($message, $subject, $email, $text = false, $footer = false)
|
||||
{
|
||||
$mail = new App_Model_Mail('UTF-8');
|
||||
|
||||
if ($footer) {
|
||||
$message .= $this->addFooter();
|
||||
}
|
||||
|
||||
$mail->setFrom($this->_configs->get('email_mittente'), $this->_configs->get('email_mittente_nome'))->setSubject($subject)->addTo($email, 'Fatturab2b.net');
|
||||
|
||||
if ($text == false) {
|
||||
$mail->setBodyHtml($message);
|
||||
} else {
|
||||
$mail->setBodyText($message);
|
||||
}
|
||||
|
||||
$mail->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invia un email all'utente in base a un template memorizzato nel DB.
|
||||
* @param $email
|
||||
* @param $template
|
||||
* @param array $params
|
||||
* @param null $filename
|
||||
* @throws Zend_Mail_Exception
|
||||
*/
|
||||
public function sendEmailByTemplate($email, $template, $params = array(), $nomeMittente = null, $filename = null,$fileNameInterno = null)
|
||||
{
|
||||
$mail = new App_Model_Mail('UTF-8');
|
||||
|
||||
if(!$template){
|
||||
throw new Exception("Email template non trovato impossibile inviare l'email");
|
||||
}
|
||||
|
||||
$params = $this->preparaDatiPerSostituzione($params);
|
||||
|
||||
if (count($params) > 0) {
|
||||
foreach ($params as $key => $val) {
|
||||
$template['Oggetto'] = str_replace($key, $val, $template['Oggetto']);
|
||||
$template['Testo'] = str_replace($key, $val, $template['Testo']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($template['Footer'])
|
||||
$template['Testo'] .= $this->addFooter();
|
||||
|
||||
if ($filename != null) {
|
||||
if (file_exists($filename))
|
||||
$mail->createAttachment(file_get_contents($filename), 'application/pdf', Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $filename);
|
||||
}
|
||||
|
||||
$nomeMittente = ($nomeMittente) ? $nomeMittente : $this->_configs->get('email_mittente_nome');
|
||||
|
||||
$mail->setFrom($this->_configs->get('email_mittente'), $nomeMittente)->setSubject($template['Oggetto']);
|
||||
|
||||
if ($template['Tipologia'] == 'HTML') {
|
||||
$mail->setBodyHtml($template['Testo']);
|
||||
} else if ($template['Tipologia'] == 'TEXT') {
|
||||
$mail->setBodyText($template['Testo']);
|
||||
}
|
||||
|
||||
//Nel caso in cui sono in test le email vengono inviate solo a sviluppoweb
|
||||
if($this->_ipManager->controllaAbilitazioneTestSdk()){
|
||||
$email=$this->_configs->get('test_email');
|
||||
if($template['Resend'])
|
||||
$template['Resend'] = 'TEST';
|
||||
}
|
||||
|
||||
//Inserisco il o i destinatari/o
|
||||
if(is_string($email)){
|
||||
$mail->addTo($email, $email);
|
||||
}else if(is_array($email)){
|
||||
foreach($email as $val){
|
||||
$mail->addTo($val);
|
||||
}
|
||||
}
|
||||
|
||||
$mail->send();
|
||||
|
||||
//INVIO COAPIA AL NOSTRO STISTEMA
|
||||
if($template['Resend']){
|
||||
|
||||
$mail->clearRecipients();
|
||||
|
||||
//Controllo se devo reinviare la mail anche al nostro server
|
||||
if ($template['Resend'] == 'INFO')
|
||||
$mail->addTo($this->_configs->get('email_mittente'), $this->_configs->get('email_mittente_nome'));
|
||||
if ($template['Resend'] == 'ACQUISTI')
|
||||
$mail->addTo($this->_configs->get('email_ordine'), $this->_configs->get('email_mittente_nome'));
|
||||
if ($template['Resend'] == 'TEST')
|
||||
$mail->addTo($this->_configs->get('test_email'), $this->_configs->get('email_mittente_nome'));
|
||||
|
||||
if($fileNameInterno){
|
||||
$mail->setParts(array());
|
||||
if (file_exists($fileNameInterno))
|
||||
$mail->createAttachment(file_get_contents($fileNameInterno), 'application/pdf', Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $fileNameInterno);
|
||||
}
|
||||
|
||||
$mail->send();
|
||||
|
||||
//CANCELLO IL FILE DEL PDF
|
||||
if ($fileNameInterno != null) {
|
||||
if (file_exists($fileNameInterno))
|
||||
@unlink($fileNameInterno);
|
||||
}
|
||||
}
|
||||
|
||||
//Invio l'email per la stampante con il testo vuoto
|
||||
if ($template['Resend'] == 'ACQUISTI' && !$this->_ipManager->controllaAbilitazioneTestSdk()){
|
||||
$mail->clearRecipients();
|
||||
$mail->setBodyHtml("");
|
||||
$mail->setBodyText("");
|
||||
$mail->addTo("", $this->_configs->get('email_mittente_nome'));
|
||||
$mail->send();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function reportErrorToEmail($error, $shortdesc, Exception $e = null,$email = null)
|
||||
{
|
||||
$mail = new Zend_Mail('UTF-8');
|
||||
|
||||
if(!$email) $email = $this->_configs->get('test_email');
|
||||
|
||||
$subject = '--- SERVER Fatturab2b.net [EMAIL] --- ERRORE ---';
|
||||
|
||||
$message = '<br>ERROR-MESSAGE: ' . $shortdesc;
|
||||
|
||||
if ($e != null) {
|
||||
$message .= '<br><br>STACK TRACE ERRORE:<br>';
|
||||
|
||||
foreach ($e->getTrace() as $key => $value) {
|
||||
$message .= "<br>[ " . $key . "] = " . $value;
|
||||
if (is_array($value)) {
|
||||
$message .= '<br>[';
|
||||
foreach ($value as $key2 => $value2) {
|
||||
$message .= "[ " . $key2 . "] = " . $value2 . "<br>";
|
||||
}
|
||||
$message .= ']<br>';
|
||||
}
|
||||
}
|
||||
|
||||
$message .= '<br>EXCEPTION STAMP:<br>';
|
||||
|
||||
$message .= "<pre>";
|
||||
$message .= print_r($e,true);
|
||||
$message .= "</pre>";
|
||||
}
|
||||
|
||||
$message .= '<br><br>PARAMETRI RICEVUTI:<br>';
|
||||
|
||||
$message .= "<pre>";
|
||||
$message .= print_r($error,true);
|
||||
$message .= "</pre>";
|
||||
|
||||
$message .= '<br>';
|
||||
|
||||
$message .= '<br><br> Errore inviato dal server il ' . date('d/m/Y H:i:s');
|
||||
|
||||
$mail->setFrom($this->_configs->get('email_mittente'), $this->_configs->get('email_mittente_nome'))
|
||||
->setSubject($subject)
|
||||
->addTo($email, '')
|
||||
->setBodyHtml($message)
|
||||
->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione che restituisce il footer per ogni email
|
||||
*
|
||||
* @param String $ragsoc | $email
|
||||
* @return void
|
||||
*/
|
||||
public function addFooter()
|
||||
{
|
||||
$footer = '<br><br>';
|
||||
$footer .= '';
|
||||
return $footer;
|
||||
}
|
||||
|
||||
/****************************
|
||||
*** FUNZIONI PRIVATE ******
|
||||
***************************/
|
||||
|
||||
/**
|
||||
* Questa funzione presi i parametri passati nell array ne aggiunge i simboli
|
||||
* percentuale per farli riconoscere popi nel testo e sostituirli
|
||||
* @param $dati
|
||||
* @return array
|
||||
*/
|
||||
private function preparaDatiPerSostituzione($dati){
|
||||
$newParams = array();
|
||||
|
||||
foreach($dati as $key => $val){
|
||||
$newParams['%'.$key.'%'] = $val;
|
||||
}
|
||||
|
||||
return $newParams;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
|
||||
class Zend_Controller_Action_Helper_ExtractData extends Zend_Controller_Action_Helper_Abstract {
|
||||
|
||||
protected $_dateValidatorSlash;
|
||||
protected $_dateValidatorTrattino;
|
||||
|
||||
/**
|
||||
* Funzione che di default passata una data nel formato aaaa-mm-dd la converte nel formato dd/mm/aaaa
|
||||
* OPZIONI PARAMETRO return:
|
||||
*
|
||||
* -'d'|'day': restituisce il giorno numerico della data.
|
||||
*
|
||||
* -'m'|'month': restituisce il mese numerico della data.
|
||||
*
|
||||
* -'M': restituisce il nome del mese in stringa
|
||||
*
|
||||
* -'y'|'Y': restituisce l'anno numerico della data.
|
||||
*
|
||||
* @param string $data|string $return
|
||||
* @return string $data
|
||||
*/
|
||||
public function direct($data=NULL,$return=NULL,$withtime = false) {
|
||||
if($data==null) return null;
|
||||
if(!$withtime){
|
||||
$val=explode('-',$data);
|
||||
}
|
||||
else{
|
||||
$datetime = explode(' ',$data);
|
||||
$val = explode('-',$datetime[0]);
|
||||
$time = $datetime[1];
|
||||
}
|
||||
switch($return){
|
||||
case'0':
|
||||
case'day':
|
||||
return $val['2'];
|
||||
break;
|
||||
case'1':
|
||||
case'month':
|
||||
return $val['1'];
|
||||
break;
|
||||
case'mese':
|
||||
return ucfirst(strftime('%B',mktime(0,0,0,$val['1'],1,2013)));
|
||||
break;
|
||||
case'monthname':
|
||||
return ucfirst(strftime('%B',mktime(0,0,0,$data,1,2013)));
|
||||
break;
|
||||
case'3':
|
||||
case'year':
|
||||
case 'y':
|
||||
return $val['0'];
|
||||
break;
|
||||
case'yy':
|
||||
return substr($val['0'],2,3);
|
||||
break;
|
||||
case 'withtime':
|
||||
if ($val[2] == '00' && $val[1] == '00' && $val[0] == '0000') {
|
||||
return null;
|
||||
} else {
|
||||
if($withtime)
|
||||
return implode('/',array_reverse($val)) . " ".substr($time,0,5);
|
||||
else
|
||||
return implode('/',array_reverse($val));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if($val[2]=='00'&&$val[1]=='00'&&$val[0]=='0000'){
|
||||
return null;
|
||||
}else{
|
||||
$data= $val[2] . '/'.$val[1] . '/'.$val[0];
|
||||
return $data;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione che passata una data nel formato dd/mm/aaaa la converte nel formato aaaa-mm-dd
|
||||
*
|
||||
* @param string $data|date $data
|
||||
* @return string $data
|
||||
*/
|
||||
public function unslashData($data) {
|
||||
$data = explode("/", $data);
|
||||
$data = array_reverse($data);
|
||||
return implode('-', $data);
|
||||
}
|
||||
|
||||
public function unslashDataWithTime($data) {
|
||||
$data = explode(" ", $data);
|
||||
$time = $data[1];
|
||||
$data = explode("/", $data[0]);
|
||||
$data = array_reverse($data);
|
||||
return implode('-', $data) ." ". $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione che passata una data nel formato aaaa-mm-dd la converte nel formato dd/mm/aaaa
|
||||
*
|
||||
* @param string $data|date $data
|
||||
* @return string $data
|
||||
*/
|
||||
public function slashData($data) {
|
||||
$data = explode("-", $data);
|
||||
$data = array_reverse($data);
|
||||
return implode('/', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione che passate due date nel formato aaaa-mm-dd ne calcola i giorni di differenza
|
||||
*
|
||||
* @param string $data1|string $data2
|
||||
* @return string $days
|
||||
*/
|
||||
public function diff_date($data1, $data2) {
|
||||
|
||||
if(is_string($data1))
|
||||
$datetime1 = new DateTime($data1);
|
||||
else
|
||||
$datetime1 = $data1;
|
||||
|
||||
if(is_string($data2))
|
||||
$datetime2 = new DateTime($data2);
|
||||
else
|
||||
$datetime2 = $data2;
|
||||
|
||||
$interval = $datetime1 -> diff($datetime2);
|
||||
return $interval -> days;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione che passate due date nel formato aaaa-mm-dd ne calcola i giorni di differenza formatti col segno
|
||||
*
|
||||
* @param string $data1|string $data2
|
||||
* @return string $days
|
||||
*/
|
||||
public function diff_date_segno($data1, $data2) {
|
||||
if(is_string($data1))
|
||||
$datetime1 = new DateTime($data1);
|
||||
else
|
||||
$datetime1 = $data1;
|
||||
|
||||
if(is_string($data2))
|
||||
$datetime2 = new DateTime($data2);
|
||||
else
|
||||
$datetime2 = $data2;
|
||||
|
||||
$interval = $datetime1 -> diff($datetime2);
|
||||
return $interval -> format('%R%a');
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione che passata una data e i giorni da sommare restituisce la data somma
|
||||
*
|
||||
* @param string $data
|
||||
* @return string $days
|
||||
*/
|
||||
public function add_days_date($data,$days){
|
||||
$data = explode('/',$data);
|
||||
array_reverse($data);
|
||||
$data = implode('-', $data);
|
||||
$date = new DateTime($data);
|
||||
$date->add(new DateInterval('P'.$days.'D'));
|
||||
return $date->format('d/m/Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione che passata una data e i giorni da sottrarre e restituisce la data calcolata
|
||||
*
|
||||
* @param $data
|
||||
* @param $days
|
||||
* @param bool|false $slashed
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sub_days_date($data,$days,$slashed = false){
|
||||
$data = $this->getDataForDb($data);
|
||||
$date = new DateTime($data);
|
||||
$date->sub(new DateInterval('P'.$days.'D'));
|
||||
if($slashed)
|
||||
return $date->format('d/m/Y');
|
||||
else
|
||||
return $date->format('Y-m-d');
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione che passata una data e gli anni da sottrarre restituisce la data sottratta
|
||||
*
|
||||
* @param string $data
|
||||
* @return string $days
|
||||
*/
|
||||
public function diff_days_year($data,$years){
|
||||
$data = explode('/',$data);
|
||||
array_reverse($data);
|
||||
$data = implode('-', $data);
|
||||
$date = new DateTime($data);
|
||||
$date->sub(new DateInterval('P'.$years.'Y'));
|
||||
return $date->format('d/m/Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione che passata una data e i giorni da sottrarre restituisce la data sottratta
|
||||
*
|
||||
* @param string $data
|
||||
* @return string $days
|
||||
*/
|
||||
public function diff_days($data,$days){
|
||||
|
||||
$this->_dateValidatorSlash = new Zend_Validate_Date(array('format' => 'dd/mm/yyyy'));
|
||||
$this->_dateValidatorTrattino = new Zend_Validate_Date(array('format' => 'yyyy-mm-dd'));
|
||||
|
||||
if ($this->_dateValidatorSlash->isValid($data)) {
|
||||
$data = implode('-',array_reverse(explode('/',$data)));
|
||||
}
|
||||
|
||||
if(!$this->_dateValidatorTrattino->isValid($data)){
|
||||
return null;
|
||||
}
|
||||
|
||||
$date = new DateTime($data);
|
||||
$date->sub(new DateInterval('P'.$days.'D'));
|
||||
return $date->format('d/m/Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione che passata una data la ritorna pronta per l'inserimento sul db false se non � una data valida
|
||||
*
|
||||
* @param $data
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function getDataForDb($data){
|
||||
|
||||
if(is_array($data)){
|
||||
$data = new DateTime(substr($data['date'],0,10));
|
||||
return $data -> format('Y-d-m');
|
||||
}elseif(is_string($data)){
|
||||
$this->_dateValidatorSlash = new Zend_Validate_Date(array('format' => 'dd/mm/yyyy'));
|
||||
$this->_dateValidatorTrattino = new Zend_Validate_Date(array('format' => 'yyyy-mm-dd'));
|
||||
if ($this->_dateValidatorSlash->isValid($data)) {
|
||||
return $this->unslashData($data);
|
||||
}else if($this->_dateValidatorTrattino->isValid($data)){
|
||||
return $data;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}else{
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
|
||||
class Zend_Controller_Action_Helper_FilterFunctions extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
protected $_dateHelper;
|
||||
protected $_filterOperators;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->_dataHelper = $this->getActionController()->getHelper('ExtractData');
|
||||
$this->_filterOperators = array('>','<','>=','<=','=','ISNULL','NONULL');
|
||||
}
|
||||
|
||||
/**
|
||||
* Questa funzione ricevuti i parametri restitisce l'array contenente tutti i valori per eseguire la ricerca da passare alla query
|
||||
* @param $filter
|
||||
* @param bool|false $analizzaOperatori
|
||||
* @return array
|
||||
*/
|
||||
public function direct($filter, $analizzaOperatori = false)
|
||||
{
|
||||
|
||||
if ($analizzaOperatori) {
|
||||
$filter = $this->getFilterParamsWithOperator($filter);
|
||||
}
|
||||
|
||||
$where = array();
|
||||
|
||||
$filter = $this->cleanParams($filter,false);
|
||||
|
||||
foreach ($filter as $key => $val) {
|
||||
|
||||
if (substr($key, -2) == 'OP') continue;
|
||||
|
||||
$nomeCampo = explode('-', $key)[0];
|
||||
$nomeCampo = str_replace('#','.',$nomeCampo);
|
||||
|
||||
if (array_key_exists($key . 'OP', $filter))
|
||||
$op = $filter[$key . 'OP'];
|
||||
else
|
||||
$op = 'EQUAL';
|
||||
|
||||
switch ($op) {
|
||||
case'ICHECK':
|
||||
$where[$nomeCampo . ' = ?'] = ($val == 'on') ? '1':'0';
|
||||
break;
|
||||
case'EQUAL':
|
||||
$where[$nomeCampo . ' = ?'] = $val;
|
||||
break;
|
||||
case'NOTEQUAL':
|
||||
$where[$nomeCampo . ' <> ?'] = $val;
|
||||
break;
|
||||
case'MIN':
|
||||
$where[$nomeCampo . ' < ?'] = $val;
|
||||
break;
|
||||
case'MAX':
|
||||
$where[$nomeCampo . ' > ?'] = $val;
|
||||
break;
|
||||
case'EQUALMIN':
|
||||
$where[$nomeCampo . ' <= ?'] = $val;
|
||||
break;
|
||||
case'EQUALMAX':
|
||||
$where[$nomeCampo . ' >= ?'] = $val;
|
||||
break;
|
||||
case'LIKE':
|
||||
$val = '%' . $val . '%';
|
||||
$where[$nomeCampo . ' ' . $op . ' ?'] = $val;
|
||||
break;
|
||||
case'LIKEPRE':
|
||||
$val = '%' . $val;
|
||||
$where[$nomeCampo . ' LIKE ?'] = $val;
|
||||
break;
|
||||
case'LIKEPOST':
|
||||
$val = $val . '%';
|
||||
$where[$nomeCampo . ' LIKE ?'] = $val;
|
||||
break;
|
||||
case'DATEEQUAL':
|
||||
$where[$nomeCampo . ' = ?'] = $this->_dataHelper->unslashData($val);
|
||||
break;
|
||||
case'DATEEQUALMIN': //Inserisco anche l'ora perchè cosi le query funzionano sia sui i tipi "date" che "datetime"
|
||||
$where[$nomeCampo . ' <= ?'] = trim($this->_dataHelper->unslashData($val)) . ' 23:59:59';
|
||||
break;
|
||||
case'DATEEQUALMAX':
|
||||
$where[$nomeCampo . ' >= ?'] = trim($this->_dataHelper->unslashData($val)) . ' 00:00:00';
|
||||
break;
|
||||
case'DATEMIN':
|
||||
$where[$nomeCampo . ' < ?'] = trim($this->_dataHelper->unslashData($val)) . ' 23:59:59';
|
||||
break;
|
||||
case'DATEMAX':
|
||||
$where[$nomeCampo . ' > ?'] = trim($this->_dataHelper->unslashData($val)) . ' 00:00:00';
|
||||
break;
|
||||
case'DATERANGE':
|
||||
$val = explode('|', $val);
|
||||
if (trim($val[0]) && trim($val[0]) != 'undefined') $where[$nomeCampo . ' >= ?'] = $this->_dataHelper->unslashData(trim($val[0])) . ' 00:00:00';
|
||||
if (trim($val[1]) && trim($val[1]) != 'undefined') $where[$nomeCampo . ' <= ?'] = $this->_dataHelper->unslashData(trim($val[1])) . ' 23:59:59';
|
||||
break;
|
||||
case'ISNULL':
|
||||
$where[$nomeCampo . ' IS NULL'] = "";
|
||||
break;
|
||||
case'NONULL':
|
||||
$where[$nomeCampo . ' IS NOT NULL'] = "";
|
||||
break;
|
||||
case'ORWHERE':
|
||||
$where[$nomeCampo . ' #OR ?'] = $val;
|
||||
break;
|
||||
case'ANDORWHERE':
|
||||
$where[$nomeCampo . ' #ANDOR ?'] = $val;
|
||||
break;
|
||||
case'IN':
|
||||
if(!is_array($val)){
|
||||
$val = explode(',', $val);
|
||||
}
|
||||
$where[$nomeCampo . ' IN ( ? )'] = $val;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("'$op' non è un operatore di filtro valido");
|
||||
}
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* Questa funzione riceve i parametri di ricerca in ingresso gli analizza per applicare eventuali operatori applicati
|
||||
* @param $params
|
||||
* @return array
|
||||
*/
|
||||
public function getFilterParamsWithOperator($params)
|
||||
{
|
||||
|
||||
$params = $this->cleanParams($params);
|
||||
|
||||
$newParams = array();
|
||||
|
||||
foreach ($params as $key => $val) {
|
||||
if (substr($key, -2) == 'OP') continue;
|
||||
if (substr($key, -9) == 'OPDEFAULT') continue;
|
||||
if (!array_key_exists($key . "OP", $params)) {
|
||||
|
||||
$op = $this->findOperator($val);
|
||||
switch ($op) {
|
||||
case'>=':
|
||||
$newParams[$key . 'OP'] = 'EQUALMAX';
|
||||
$newParams[$key] = trim(substr($val, 2));
|
||||
break;
|
||||
case'<=':
|
||||
$newParams[$key . 'OP'] = 'EQUALMIN';
|
||||
$newParams[$key] = trim(substr($val, 2));
|
||||
break;
|
||||
case'<':
|
||||
$newParams[$key . 'OP'] = 'MIN';
|
||||
$newParams[$key] = trim(substr($val, 1));
|
||||
break;
|
||||
case'>':
|
||||
$newParams[$key . 'OP'] = 'MAX';
|
||||
$newParams[$key] = trim(substr($val, 1));
|
||||
break;
|
||||
case'=':
|
||||
$newParams[$key . 'OP'] = 'EQUAL';
|
||||
$newParams[$key] = trim(substr($val, 1));
|
||||
break;
|
||||
case'<>':
|
||||
$newParams[$key . 'OP'] = 'NOTEQUAL';
|
||||
$newParams[$key] = trim(substr($val, 2));
|
||||
break;
|
||||
case'ISNULL':
|
||||
$newParams[$key . 'OP'] = 'ISNULL';
|
||||
$newParams[$key] = "";
|
||||
break;
|
||||
case'NONULL':
|
||||
$newParams[$key . 'OP'] = 'NONULL';
|
||||
$newParams[$key] = "";
|
||||
break;
|
||||
default:
|
||||
if(isset($params[$key.'OPDEFAULT'])){
|
||||
$newParams[$key . 'OP'] = $params[$key.'OPDEFAULT'];
|
||||
}else{
|
||||
$newParams[$key . 'OP'] = 'EQUAL';
|
||||
}
|
||||
$newParams[$key] = $val;
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
$newParams[$key] = $val;
|
||||
$newParams[$key . "OP"] = $params[$key . "OP"];
|
||||
}
|
||||
}
|
||||
|
||||
return $newParams;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione che passata una stringa cerca se viene applicato un operatore e lo restuisce
|
||||
* @param $val
|
||||
* @return string
|
||||
*/
|
||||
private function findOperator($val)
|
||||
{
|
||||
$op = trim(explode(' ', $val)[0]);
|
||||
if (in_array($op, $this->_filterOperators)) return $op;
|
||||
|
||||
$op = trim(substr($val, 0, 6));
|
||||
if (in_array($op, $this->_filterOperators)) return $op;
|
||||
|
||||
$op = $op = trim(substr($val, 0, 2));
|
||||
if (in_array($op, $this->_filterOperators)) return $op;
|
||||
|
||||
$op = $op = trim(substr($val, 0, 1));
|
||||
if (in_array($op, $this->_filterOperators)) return $op;
|
||||
|
||||
return 'EQUAL';
|
||||
}
|
||||
|
||||
public function cleanParams($params,$removeEmptyValue = true,$removeOperator = false){
|
||||
unset($params['controller']);
|
||||
unset($params['module']);
|
||||
unset($params['action']);
|
||||
unset($params['method']);
|
||||
unset($params['page']);
|
||||
unset($params['count']);
|
||||
unset($params['order']);
|
||||
unset($params['tipoOrder']);
|
||||
unset($params['filtrato']);
|
||||
unset($params['orwhere']);
|
||||
unset($params['reset']);
|
||||
unset($params['iddet']);
|
||||
unset($params['select']);
|
||||
unset($params['compactlist']);
|
||||
unset($params['deliveryinfo']);
|
||||
|
||||
if($removeEmptyValue){
|
||||
//Elimino i campi vuoti tranne le select vuote
|
||||
foreach ($params as $key => $val) {
|
||||
if (empty($val) && $val !== '0') unset($params[$key]);
|
||||
|
||||
//Elimino anche i paramtri di operazione
|
||||
if ($removeOperator && preg_match('/OP$/',$key)){
|
||||
unset($params[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
class Zend_Controller_Action_Helper_FormatData extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
|
||||
public function direct($data,$format){
|
||||
$data = new DateTime($data);
|
||||
return $data -> format($format);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
|
||||
class Zend_Controller_Action_Helper_Globalfunction extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
|
||||
protected $_configs;
|
||||
protected $_dataHelper;
|
||||
protected $_genericModel;
|
||||
|
||||
public function init()
|
||||
{
|
||||
|
||||
$this->_configs = new App_Service_ConfigManager();
|
||||
$this->_dataHelper = $this->getActionController()->getHelper('ExtractData');
|
||||
$this->_genericModel = new Application_Model_Generic();
|
||||
}
|
||||
|
||||
public function direct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* =====================================================================================================================
|
||||
* ========= FUNZIONI RELATIVE ALLA SCADENZA
|
||||
* ===========================================
|
||||
* =====================================================================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* Funzione che restituisce il numero fattura successivo per l'inserimento di una nuova fattura
|
||||
* in base alla data scelta
|
||||
*
|
||||
* @param string $data (YYYY-mm-dd)
|
||||
* @return int $num
|
||||
*/
|
||||
public function getNumFatturaSucc($data,$serie = null)
|
||||
{
|
||||
$num = $this->_genericModel->getNumFatturaSucc($data,$serie);
|
||||
if ($num == NULL || $num == '' || $num == 0 || $num == FALSE)
|
||||
return 1;
|
||||
return $num;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione che restituisce il numero fattura successivo per l'inserimento di una nuova fattura
|
||||
* in base alla data scelta
|
||||
* @return int $num
|
||||
*/
|
||||
public function getProgressivoInvioSucc()
|
||||
{
|
||||
|
||||
$lastProgressivo = strtoupper($this->_genericModel->getLastProgressivoInvio());
|
||||
|
||||
if(!$lastProgressivo) $lastProgressivo = $this->_configs->get('lettera_progressivo_invio');
|
||||
|
||||
$pad = 5;
|
||||
|
||||
$char = preg_replace("/[0-9]/",'',$lastProgressivo);
|
||||
if(strlen($char) > 0) $pad -= strlen($char);
|
||||
|
||||
$num = preg_replace("/[A-Za-z]/",'',$lastProgressivo);
|
||||
|
||||
$num = intval($num);
|
||||
if (!$num) $num = 0;
|
||||
|
||||
$maxNum = intval(str_repeat("9", $pad));
|
||||
|
||||
$num += 1;
|
||||
if($num > $maxNum){
|
||||
//Incremento dell'ultimo carattere
|
||||
if(!$char)
|
||||
$char = 'A';
|
||||
else
|
||||
++$char;
|
||||
|
||||
$pad = 5 - strlen($char);
|
||||
$num = 1;
|
||||
}
|
||||
|
||||
$num = str_pad($num, $pad, "0", STR_PAD_LEFT);
|
||||
if($pad < 5) $num = $char.$num;
|
||||
|
||||
return $num;
|
||||
}
|
||||
|
||||
public function formattaNumeroFatturaXml($numero, $decimali = 2)
|
||||
{
|
||||
if ($decimali < 2) $decimali = 2;
|
||||
return number_format($numero, $decimali, '.', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione di validazione di una partita iva
|
||||
* @param $pi
|
||||
* @return string
|
||||
*/
|
||||
public function ControllaPIVA($pi)
|
||||
{
|
||||
if ($pi === '')
|
||||
return '';
|
||||
if (strlen($pi) != 11)
|
||||
return "La lunghezza della partita IVA non è\n" . "corretta: la partita IVA dovrebbe essere lunga\n" . "esattamente 11 caratteri.\n";
|
||||
if (preg_match("/^[0-9]+\$/", $pi) != 1)
|
||||
return "La partita IVA contiene dei caratteri non ammessi:\n" . "la partita IVA dovrebbe contenere solo cifre.\n";
|
||||
$s = 0;
|
||||
for ($i = 0; $i <= 9; $i += 2)
|
||||
$s += ord($pi[$i]) - ord('0');
|
||||
for ($i = 1; $i <= 9; $i += 2) {
|
||||
$c = 2 * (ord($pi[$i]) - ord('0'));
|
||||
if ($c > 9)
|
||||
$c = $c - 9;
|
||||
$s += $c;
|
||||
}
|
||||
if ((10 - $s % 10) % 10 != ord($pi[10]) - ord('0'))
|
||||
return "La partita IVA non è valida:\n" . "il codice di controllo non corrisponde.";
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return string
|
||||
* Funzione ricorsiva per codificare un array di valori in Json in modo sicuro comreso i caratteri utf-8
|
||||
*/
|
||||
public function safeJsonEncode($value)
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
|
||||
$encoded = json_encode($value,JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
$encoded = json_encode($value);
|
||||
}
|
||||
switch (json_last_error()) {
|
||||
case JSON_ERROR_NONE:
|
||||
return $encoded;
|
||||
case JSON_ERROR_DEPTH:
|
||||
return 'Maximum stack depth exceeded';
|
||||
case JSON_ERROR_STATE_MISMATCH:
|
||||
return 'Underflow or the modes mismatch';
|
||||
case JSON_ERROR_CTRL_CHAR:
|
||||
return 'Unexpected control character found';
|
||||
case JSON_ERROR_SYNTAX:
|
||||
return 'Syntax error, malformed JSON';
|
||||
case JSON_ERROR_UTF8:
|
||||
$clean = $this->utf8ize($value);
|
||||
return $this->safeJsonEncode($clean);
|
||||
default:
|
||||
return 'Unknown error';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return mixed|string
|
||||
* Funzione ricorsiva per convertire in modo sicuro compreso i caratetteri utf-8 dal formato Json
|
||||
*/
|
||||
public function safeJsonDecode($value)
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
|
||||
$encoded = json_decode($value,JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
$encoded = json_decode($value);
|
||||
}
|
||||
switch (json_last_error()) {
|
||||
case JSON_ERROR_NONE:
|
||||
return $encoded;
|
||||
case JSON_ERROR_DEPTH:
|
||||
return 'Maximum stack depth exceeded';
|
||||
case JSON_ERROR_STATE_MISMATCH:
|
||||
return 'Underflow or the modes mismatch';
|
||||
case JSON_ERROR_CTRL_CHAR:
|
||||
return 'Unexpected control character found';
|
||||
case JSON_ERROR_SYNTAX:
|
||||
return 'Syntax error, malformed JSON';
|
||||
case JSON_ERROR_UTF8:
|
||||
$clean = $this->utf8decodize($value);
|
||||
return $this->safeJsonDecode($clean);
|
||||
default:
|
||||
return 'Unknown error';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $mixed
|
||||
* @return array|string
|
||||
* Funzione ricorsiva per codificare un array di valori in utf-8
|
||||
*/
|
||||
public function utf8ize($mixed)
|
||||
{
|
||||
if (is_array($mixed)) {
|
||||
foreach ($mixed as $key => $value) {
|
||||
$mixed[$key] = $this->utf8ize($value);
|
||||
}
|
||||
} else if (is_string($mixed)) {
|
||||
return utf8_encode($mixed);
|
||||
}
|
||||
return $mixed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $mixed
|
||||
* @return array|string
|
||||
* Funzione ricorsiva per decodificare un array di valori in utf-8
|
||||
*/
|
||||
public function utf8decodize($mixed)
|
||||
{
|
||||
if (is_array($mixed)) {
|
||||
foreach ($mixed as $key => $value) {
|
||||
$mixed[$key] = $this->utf8decodize($value);
|
||||
}
|
||||
} else if (is_string($mixed)) {
|
||||
return utf8_decode($mixed);
|
||||
}
|
||||
return $mixed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $array
|
||||
* @param $key
|
||||
* @return array Questa funzione passato un array lo restituisce ragruppato per la chiave desiderata
|
||||
*/
|
||||
function groupArrayByKey($array, $key) {
|
||||
$return = array();
|
||||
foreach($array as $val) {
|
||||
$return[$val[$key]][] = $val;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
|
||||
class Zend_Controller_Action_Helper_Image extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
|
||||
public function direct($PATH, $nomeFile,$ImageName)
|
||||
{
|
||||
############ Edit settings ##############
|
||||
$ThumbSquareSize = 200; //Thumbnail will be 200x200
|
||||
$BigImageMaxSize = 500; //Image Maximum height or width
|
||||
$ThumbPrefix = "thumb_"; //Normal thumb Prefix
|
||||
$DestinationDirectory = $PATH; //specify upload directory ends with / (slash)
|
||||
$Quality = 90; //jpeg quality
|
||||
##########################################
|
||||
// check $_FILES['ImageFile'] not empty
|
||||
if (!isset($_FILES[$nomeFile]) || !is_uploaded_file($_FILES[$nomeFile]['tmp_name'])) {
|
||||
return FALSE; // output error when above checks fail.
|
||||
}
|
||||
// Random number will be added after image name
|
||||
//$RandomNumber = rand(0, 9999999999);
|
||||
//$ImageName = date('His').'_'.str_replace(' ', '-', strtolower($_FILES[$nomeFile]['name'])); //get image name
|
||||
$ImageSize = $_FILES[$nomeFile]['size']; // get original image size
|
||||
$TempSrc = $_FILES[$nomeFile]['tmp_name']; // Temp name of image file stored in PHP tmp folder
|
||||
$ImageType = $_FILES[$nomeFile]['type']; //get file type, returns "image/png", image/jpeg, text/plain etc.
|
||||
//$ImageType = 'image/png';
|
||||
//Let's check allowed $ImageType, we use PHP SWITCH statement here
|
||||
switch (strtolower($ImageType)) {
|
||||
case 'image/png':
|
||||
//Create a new image from file
|
||||
$CreatedImage = imagecreatefrompng($_FILES[$nomeFile]['tmp_name']);
|
||||
break;
|
||||
case 'image/gif':
|
||||
$CreatedImage = imagecreatefromgif($_FILES[$nomeFile]['tmp_name']);
|
||||
break;
|
||||
case 'image/jpeg':
|
||||
case 'image/pjpeg':
|
||||
$CreatedImage = imagecreatefromjpeg($_FILES[$nomeFile]['tmp_name']);
|
||||
break;
|
||||
default:
|
||||
return FALSE; //output error and exit
|
||||
}
|
||||
//PHP getimagesize() function returns height/width from image file stored in PHP tmp folder.
|
||||
//Get first two values from image, width and height.
|
||||
//list assign svalues to $CurWidth,$CurHeight
|
||||
list($CurWidth, $CurHeight) = getimagesize($TempSrc);
|
||||
//set the Destination Image
|
||||
$thumb_DestRandImageName = $DestinationDirectory . $ThumbPrefix . $ImageName; //Thumbnail name with destination directory
|
||||
$DestFolder = $DestinationDirectory . $ImageName;
|
||||
//Resize image to Specified Size by calling resizeImage function.
|
||||
if ($this->saveImage($CurWidth, $CurHeight, $CreatedImage, $DestFolder, $Quality, $ImageType)) {
|
||||
|
||||
/*
|
||||
We have succesfully resized and created thumbnail image
|
||||
We can now output image to user's browser or store information in the database
|
||||
echo '<table width="100%" border="0" cellpadding="4" cellspacing="0">';
|
||||
echo '<tr>';
|
||||
echo '<td align="center"><img src="uploads/'.$ThumbPrefix.$NewImageName.'" alt="Thumbnail"></td>';
|
||||
echo '</tr><tr>';
|
||||
echo '<td align="center"><img src="uploads/'.$NewImageName.'" alt="Resized Image"></td>';
|
||||
echo '</tr>';
|
||||
echo '</table>';*/
|
||||
|
||||
} else {
|
||||
return FALSE; //output error
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// This function will proportionally resize image
|
||||
public function resizeImage($CurWidth, $CurHeight, $MaxSize, $DestFolder, $SrcImage, $Quality, $ImageType)
|
||||
{
|
||||
//Check Image size is not 0
|
||||
if ($CurWidth <= 0 || $CurHeight <= 0) {
|
||||
return FALSE;
|
||||
}
|
||||
//Construct a proportional size of new image
|
||||
$ImageScale = min($MaxSize / $CurWidth, $MaxSize / $CurHeight);
|
||||
$NewWidth = ceil($ImageScale * $CurWidth);
|
||||
$NewHeight = ceil($ImageScale * $CurHeight);
|
||||
$NewCanves = imagecreatetruecolor($NewWidth, $NewHeight);
|
||||
// Resize Image
|
||||
if (imagecopyresampled($NewCanves, $SrcImage, 0, 0, 0, 0, $NewWidth, $NewHeight, $CurWidth, $CurHeight)) {
|
||||
switch (strtolower($ImageType)) {
|
||||
case 'image/png':
|
||||
imagepng($NewCanves, $DestFolder);
|
||||
break;
|
||||
case 'image/gif':
|
||||
imagegif($NewCanves, $DestFolder);
|
||||
break;
|
||||
case 'image/jpeg':
|
||||
case 'image/pjpeg':
|
||||
imagejpeg($NewCanves, $DestFolder, $Quality);
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
//Destroy image, frees memory
|
||||
if (is_resource($NewCanves)) {
|
||||
imagedestroy($NewCanves);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//This function corps image to create exact square images, no matter what its original size!
|
||||
public function cropImage($CurWidth, $CurHeight, $iSize, $DestFolder, $SrcImage, $Quality, $ImageType)
|
||||
{
|
||||
//Check Image size is not 0
|
||||
if ($CurWidth <= 0 || $CurHeight <= 0) {
|
||||
return FALSE;
|
||||
}
|
||||
//abeautifulsite.net has excellent article about "Cropping an Image to Make Square bit.ly/1gTwXW9
|
||||
if ($CurWidth > $CurHeight) {
|
||||
$y_offset = 0;
|
||||
$x_offset = ($CurWidth - $CurHeight) / 2;
|
||||
$square_size = $CurWidth - ($x_offset * 2);
|
||||
} else {
|
||||
$x_offset = 0;
|
||||
$y_offset = ($CurHeight - $CurWidth) / 2;
|
||||
$square_size = $CurHeight - ($y_offset * 2);
|
||||
}
|
||||
$NewCanves = imagecreatetruecolor($iSize, $iSize);
|
||||
if (imagecopyresampled($NewCanves, $SrcImage, 0, 0, $x_offset, $y_offset, $iSize, $iSize, $square_size, $square_size)) {
|
||||
switch (strtolower($ImageType)) {
|
||||
case 'image/png':
|
||||
imagepng($NewCanves, $DestFolder);
|
||||
break;
|
||||
case 'image/gif':
|
||||
imagegif($NewCanves, $DestFolder);
|
||||
break;
|
||||
case 'image/jpeg':
|
||||
case 'image/pjpeg':
|
||||
imagejpeg($NewCanves, $DestFolder, $Quality);
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
//Destroy image, frees memory
|
||||
if (is_resource($NewCanves)) {
|
||||
imagedestroy($NewCanves);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function saveImage($CurWidth, $CurHeight, $srcImage, $DestFolder, $Quality, $ImageType)
|
||||
{
|
||||
//Check Image size is not 0
|
||||
if ($CurWidth <= 0 || $CurHeight <= 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$NewCanves = $srcImage;
|
||||
|
||||
switch (strtolower($ImageType)) {
|
||||
case 'image/png':
|
||||
imagesavealpha($NewCanves, true);
|
||||
$color = imagecolorallocatealpha($NewCanves, 0, 0, 0, 127);
|
||||
imagefill($NewCanves, 0, 0, $color);
|
||||
imagepng($NewCanves, $DestFolder);
|
||||
break;
|
||||
case 'image/gif':
|
||||
imagegif($NewCanves, $DestFolder);
|
||||
break;
|
||||
case 'image/jpeg':
|
||||
case 'image/pjpeg':
|
||||
imagejpeg($NewCanves, $DestFolder, $Quality);
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
//Destroy image, frees memory
|
||||
if (is_resource($NewCanves)) {
|
||||
imagedestroy($NewCanves);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione che passati i valori esegue l'operazione relativa in base all'analisi dei file attualmente presenti
|
||||
*
|
||||
* @param $inputFileName
|
||||
* @param $formImageName
|
||||
* @param $oldImageRecord
|
||||
* @param $imagePath
|
||||
* @param $nomeFile
|
||||
* @param bool|true $randomizeImageName
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function image_operation($inputFileName, $formImageName, $oldImageRecord, $imagePath, $nomeFile, $randomizeImageName = true)
|
||||
{
|
||||
|
||||
//Controllo che il nome del file sia valido
|
||||
if (!empty($_FILES[$inputFileName]) && $_FILES[$inputFileName]['name'] != '') {
|
||||
if($randomizeImageName){
|
||||
$nomeFile = time() ."_". str_replace(' ', '-', strtolower($nomeFile));
|
||||
}else{
|
||||
$nomeFile = str_replace(' ', '-', strtolower($nomeFile));
|
||||
}
|
||||
}
|
||||
|
||||
//Vedo che operazione eseguire sul file immagine memorizzato nel file system
|
||||
if (!empty($_FILES[$inputFileName]) && $nomeFile != '') {
|
||||
if ($oldImageRecord != null) { //AGGIORNAMENTO
|
||||
if ($oldImageRecord[$formImageName] != '' && file_exists($imagePath . $oldImageRecord[$formImageName])) {
|
||||
unlink($imagePath . $oldImageRecord[$formImageName]); //Elimina la vecchia precendente dal file system
|
||||
}
|
||||
}
|
||||
if (!$this->direct($imagePath, $inputFileName,$nomeFile)) { //Memorizza la nuova immagine
|
||||
return 'error';
|
||||
}
|
||||
} elseif (empty($_FILES[$inputFileName]) && $nomeFile == '') { //CANCELLO SOLO L'IMMAGINE
|
||||
if ($oldImageRecord != null) {
|
||||
if ($oldImageRecord[$formImageName] != '' && file_exists($imagePath . $oldImageRecord[$formImageName])) {
|
||||
unlink($imagePath . $oldImageRecord[$formImageName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (!$nomeFile) ? null : $nomeFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controlla che l'immagine esiste e nel caso posistivo la elimina del fyle system
|
||||
* @param $nomeFile
|
||||
* @param $path
|
||||
*/
|
||||
public function deleteImage($nomeFile, $path)
|
||||
{
|
||||
if (file_exists($path . $nomeFile)) {
|
||||
@unlink($path . $nomeFile);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
class Zend_Controller_Action_Helper_MongoDateFunctions extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function direct($data)
|
||||
{
|
||||
$dateValidatorSlashWithTime = new Zend_Validate_Date(array('format' => 'dd/mm/yyyy HH:ii:ss'));
|
||||
$dateValidatorSlash = new Zend_Validate_Date(array('format' => 'dd/mm/yyyy'));
|
||||
$dateValidatorTrattino = new Zend_Validate_Date(array('format' => 'yyyy-mm-dd'));
|
||||
|
||||
if ($dateValidatorSlashWithTime->isValid($data)) {
|
||||
$data = explode(' ', $data);
|
||||
$dataString = implode('-', array_reverse(explode("/", $data[0]))) . " " . $data[1];
|
||||
} else if ($dateValidatorSlash->isValid($data)) {
|
||||
$dataString = implode('-', array_reverse(explode("/", $data))) . $this->checkTimeString($data);
|
||||
} else if ($dateValidatorTrattino->isValid($data)) {
|
||||
$dataString = $data . $this->checkTimeString($data);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
$orig_date = new DateTime($dataString);
|
||||
return new MongoDB\BSON\UTCDateTime($orig_date->getTimestamp() * 1000);
|
||||
}
|
||||
|
||||
private function checkTimeString($data)
|
||||
{
|
||||
return (preg_match('/[0-9]{2}:[0-9]{2}:[0-9]{2}/', $data)) ? '' : " 00:00:00";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
|
||||
class Zend_Controller_Action_Helper_MongoFilterFunctions extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
|
||||
// protected $_dateHelper;
|
||||
protected $_mongoDate;
|
||||
protected $_filterOperators;
|
||||
|
||||
public function init()
|
||||
{
|
||||
// $this->_dateHelper = $this->getActionController()->getHelper('ExtractData');
|
||||
$this->_mongoDate = $this->getActionController()->getHelper('MongoDateFunctions');
|
||||
$this->_filterOperators = array('>', '<', '>=', '<=', '=', 'ISNULL', 'NONULL');
|
||||
}
|
||||
|
||||
/**
|
||||
* Questa funzione ricevuti i parametri restitisce l'array contenente tutti i valori per eseguire la ricerca da passare alla query
|
||||
* @param $filter
|
||||
* @param bool|false $analizzaOperatori
|
||||
* @return array
|
||||
*/
|
||||
public function direct($filter, $analizzaOperatori = false)
|
||||
{
|
||||
|
||||
if (is_null($filter)) return null;
|
||||
|
||||
if ($analizzaOperatori) {
|
||||
$filter = $this->getFilterParamsWithOperator($filter);
|
||||
}
|
||||
|
||||
$where = array();
|
||||
|
||||
$filter = $this->cleanParams($filter, false);
|
||||
|
||||
foreach ($filter as $key => $val) {
|
||||
|
||||
if (substr($key, -2) == 'OP') continue;
|
||||
|
||||
$nomeCampo = explode('-', $key)[0];
|
||||
$nomeCampo = str_replace('#', '.', $nomeCampo);
|
||||
|
||||
if (array_key_exists($key . 'OP', $filter))
|
||||
$op = $filter[$key . 'OP'];
|
||||
else
|
||||
$op = 'EQUAL';
|
||||
|
||||
switch ($op) {
|
||||
case'ICHECK':
|
||||
$where[$nomeCampo] = ($val == 'on') ? true : false;
|
||||
break;
|
||||
case'EQUAL':
|
||||
$where[$nomeCampo] = $val;
|
||||
break;
|
||||
case'NOTEQUAL':
|
||||
$where[$nomeCampo] = ['$ne' => $val];
|
||||
break;
|
||||
case'MIN':
|
||||
$where[$nomeCampo] = ['$lt' => intval($val)];
|
||||
break;
|
||||
case'MAX':
|
||||
$where[$nomeCampo] = ['$gt' => intval($val)];
|
||||
break;
|
||||
case'EQUALMIN':
|
||||
$where[$nomeCampo] = ['$lte' => intval($val)];
|
||||
break;
|
||||
case'EQUALMAX':
|
||||
$where[$nomeCampo] = ['$gte' => intval($val)];
|
||||
break;
|
||||
case'LIKE':
|
||||
//$where[$nomeCampo] = ['$regex' => new MongoDB\BSON\Regex("$val",'i')];
|
||||
$where[$nomeCampo] = ['$regex' => $val, '$options' => 'i'];
|
||||
break;
|
||||
case'LIKEPRE':
|
||||
$where[$nomeCampo] = ['$regex' => "^$val", '$options' => 'i'];
|
||||
break;
|
||||
case'LIKEPOST':
|
||||
$where[$nomeCampo] = ['$regex' => "$val$", '$options' => 'i'];
|
||||
break;
|
||||
case'DATEEQUAL':
|
||||
$where[$nomeCampo] = $this->_mongoDate->direct(trim($val) . $this->checkTimeString($val));
|
||||
break;
|
||||
case'DATEEQUALMIN': //Inserisco anche l'ora perchè cosi le query funzionano sia sui i tipi "date" che "datetime"
|
||||
$where[$nomeCampo] = array('$gte' => $this->_mongoDate->direct(trim($val) . $this->checkTimeString($val)));
|
||||
break;
|
||||
case'DATEEQUALMAX':
|
||||
$where[$nomeCampo] = array('$lte' => $this->_mongoDate->direct(trim($val) . $this->checkTimeString($val, true)));
|
||||
break;
|
||||
case'DATEMIN':
|
||||
$where[$nomeCampo] = array('$gt' => $this->_mongoDate->direct(trim($val) . $this->checkTimeString($val)));
|
||||
break;
|
||||
case'DATEMAX':
|
||||
$where[$nomeCampo] = array('$lt' => $this->_mongoDate->direct(trim($val) . $this->checkTimeString($val, true)));
|
||||
break;
|
||||
case'DATERANGE':
|
||||
$val = explode('|', $val);
|
||||
if ((trim($val[0]) && trim($val[0]) != 'undefined') && (trim($val[1]) && trim($val[1]) != 'undefined')) {
|
||||
$where[$nomeCampo] = array(
|
||||
'$gte' => $this->_mongoDate->direct(trim($val[0]) . $this->checkTimeString($val[0])),
|
||||
'$lte' => $this->_mongoDate->direct(trim($val[1]) . $this->checkTimeString($val[1], true))
|
||||
);
|
||||
}
|
||||
break;
|
||||
case'ISNULL':
|
||||
$where[$nomeCampo] = ['$exists' => 0];
|
||||
break;
|
||||
case'NONULL':
|
||||
$where[$nomeCampo] = ['$exists' => 1];
|
||||
break;
|
||||
default:
|
||||
throw new Exception("'$op' non è un operatore di filtro valido");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Salvo i dati della where in modo da poterli riutilizzare in caso di necessità durante la chiamata
|
||||
if (count($where) > 0) {
|
||||
Zend_Registry::set(App_Model_Mongo_Client::WHERE_MONGO_REG_NAME, $where);
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* Questa funzione riceve i parametri di ricerca in ingresso gli analizza per applicare eventuali operatori applicati
|
||||
* @param $params
|
||||
* @return array
|
||||
*/
|
||||
public function getFilterParamsWithOperator($params)
|
||||
{
|
||||
|
||||
$params = $this->cleanParams($params);
|
||||
|
||||
$newParams = array();
|
||||
|
||||
foreach ($params as $key => $val) {
|
||||
if (substr($key, -2) == 'OP') continue;
|
||||
if (substr($key, -9) == 'OPDEFAULT') continue;
|
||||
if (!array_key_exists($key . "OP", $params)) {
|
||||
|
||||
$op = $this->findOperator($val);
|
||||
switch ($op) {
|
||||
case'>=':
|
||||
$newParams[$key . 'OP'] = 'EQUALMAX';
|
||||
$newParams[$key] = trim(substr($val, 2));
|
||||
break;
|
||||
case'<=':
|
||||
$newParams[$key . 'OP'] = 'EQUALMIN';
|
||||
$newParams[$key] = trim(substr($val, 2));
|
||||
break;
|
||||
case'<':
|
||||
$newParams[$key . 'OP'] = 'MIN';
|
||||
$newParams[$key] = trim(substr($val, 1));
|
||||
break;
|
||||
case'>':
|
||||
$newParams[$key . 'OP'] = 'MAX';
|
||||
$newParams[$key] = trim(substr($val, 1));
|
||||
break;
|
||||
case'=':
|
||||
$newParams[$key . 'OP'] = 'EQUAL';
|
||||
$newParams[$key] = trim(substr($val, 1));
|
||||
break;
|
||||
case'<>':
|
||||
$newParams[$key . 'OP'] = 'NOTEQUAL';
|
||||
$newParams[$key] = trim(substr($val, 2));
|
||||
break;
|
||||
case'ISNULL':
|
||||
$newParams[$key . 'OP'] = 'ISNULL';
|
||||
$newParams[$key] = "";
|
||||
break;
|
||||
case'NONULL':
|
||||
$newParams[$key . 'OP'] = 'NONULL';
|
||||
$newParams[$key] = "";
|
||||
break;
|
||||
default:
|
||||
if (isset($params[$key . 'OPDEFAULT'])) {
|
||||
$newParams[$key . 'OP'] = $params[$key . 'OPDEFAULT'];
|
||||
} else {
|
||||
$newParams[$key . 'OP'] = 'EQUAL';
|
||||
}
|
||||
$newParams[$key] = $val;
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
$newParams[$key] = $val;
|
||||
$newParams[$key . "OP"] = $params[$key . "OP"];
|
||||
}
|
||||
}
|
||||
|
||||
return $newParams;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Funzione che passata una stringa cerca se viene applicato un operatore e lo restuisce
|
||||
* @param $val
|
||||
* @return string
|
||||
*/
|
||||
private function findOperator($val)
|
||||
{
|
||||
$op = trim(explode(' ', $val)[0]);
|
||||
if (in_array($op, $this->_filterOperators)) return $op;
|
||||
|
||||
$op = trim(substr($val, 0, 6));
|
||||
if (in_array($op, $this->_filterOperators)) return $op;
|
||||
|
||||
$op = $op = trim(substr($val, 0, 2));
|
||||
if (in_array($op, $this->_filterOperators)) return $op;
|
||||
|
||||
$op = $op = trim(substr($val, 0, 1));
|
||||
if (in_array($op, $this->_filterOperators)) return $op;
|
||||
|
||||
return 'EQUAL';
|
||||
}
|
||||
|
||||
public function cleanParams($params, $removeEmptyValue = true, $removeOperator = false)
|
||||
{
|
||||
unset($params['controller']);
|
||||
unset($params['module']);
|
||||
unset($params['action']);
|
||||
unset($params['method']);
|
||||
unset($params['page']);
|
||||
unset($params['count']);
|
||||
unset($params['order']);
|
||||
unset($params['tipoOrder']);
|
||||
unset($params['filtrato']);
|
||||
unset($params['orwhere']);
|
||||
unset($params['reset']);
|
||||
unset($params['iddet']);
|
||||
unset($params['select']);
|
||||
|
||||
if ($removeEmptyValue) {
|
||||
//Elimino i campi vuoti tranne le select vuote
|
||||
foreach ($params as $key => $val) {
|
||||
if (empty($val) && $val !== '0') unset($params[$key]);
|
||||
|
||||
//Elimino anche i paramtri di operazione
|
||||
if ($removeOperator && preg_match('/OP$/', $key)) {
|
||||
unset($params[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
private function checkTimeString($data, $timeEnd = false)
|
||||
{
|
||||
$timeString = ($timeEnd) ? ' 23:59:59' : ' 00:00:00';
|
||||
return (preg_match('/[0-9]{2}:[0-9]{2}:[0-9]{2}/', $data)) ? '' : $timeString;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
use Fpdf\Fpdf;
|
||||
|
||||
class Zend_Controller_Action_Helper_Pdf extends Zend_Controller_Action_Helper_Abstract {
|
||||
|
||||
protected $_dataHelper;
|
||||
|
||||
public function init() {
|
||||
define('EURO', chr(128));
|
||||
$this -> _dataHelper = $this -> getActionController() -> getHelper('ExtractData');
|
||||
}
|
||||
|
||||
public function creaPdf($row,$articolo, $filename) {
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
// operazioni preliminari fattorizzate in questo punto del codice
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
$font = "Arial";
|
||||
|
||||
$font_size = 10;
|
||||
|
||||
$pdf = new Fpdf();
|
||||
|
||||
$pdf -> AddPage();
|
||||
|
||||
$pdf -> SetFillColor(238, 238, 238);
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
// Logo aziendale
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
// col seguente codice siamo in grado di eseguire correttamente sia girando come ADMIN che come Utente (sia in modalità acquisto che reinvio-fatture)
|
||||
try{
|
||||
if ($row['nome_logo'] && file_exists("public/front/img/".$row['nome_logo'])) {
|
||||
if ($row['nome_logo'] == 'IntestazioneFattura.jpg') {
|
||||
$pdf->Image("public/front/img/" . $row['nome_logo'], 10, 5, 80, 60);
|
||||
} else {
|
||||
$pdf->Image("public/front/img/" . $row['nome_logo'], 10, 10, 80, 60);
|
||||
}
|
||||
}else{
|
||||
$pdf -> Image("public/front/img/IntestazioneFattura2.jpg", 10, 10, 80, 60);
|
||||
}
|
||||
}catch(Exception $e){
|
||||
$pdf -> Image("public/front/img/IntestazioneFattura2.jpg", 10, 10, 80, 60);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
// recupero dati
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
// FINE
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
$pdf -> Output($filename, "F");
|
||||
@chmod(0777, $filename);
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
private function printEuro($x) {
|
||||
setlocale(LC_MONETARY, 'it_IT');
|
||||
$x = $this -> money_format('%.2n', $x + 0);
|
||||
$x = str_replace("EUR", EURO, $x);
|
||||
$x = trim($x);
|
||||
return $x;
|
||||
}
|
||||
|
||||
private function money_format($format, $number) {
|
||||
$regex = '/%((?:[\^!\-]|\+|\(|\=.)*)([0-9]+)?' . '(?:#([0-9]+))?(?:\.([0-9]+))?([in%])/';
|
||||
if (setlocale(LC_MONETARY, 0) == 'C') {
|
||||
setlocale(LC_MONETARY, '');
|
||||
}
|
||||
$locale = localeconv();
|
||||
preg_match_all($regex, $format, $matches, PREG_SET_ORDER);
|
||||
foreach ($matches as $fmatch) {
|
||||
$value = floatval($number);
|
||||
$flags = array('fillchar' => preg_match('/\=(.)/', $fmatch[1], $match) ? $match[1] : ' ', 'nogroup' => preg_match('/\^/', $fmatch[1]) > 0, 'usesignal' => preg_match('/\+|\(/', $fmatch[1], $match) ? $match[0] : '+', 'nosimbol' => preg_match('/\!/', $fmatch[1]) > 0, 'isleft' => preg_match('/\-/', $fmatch[1]) > 0);
|
||||
$width = trim($fmatch[2]) ? (int)$fmatch[2] : 0;
|
||||
$left = trim($fmatch[3]) ? (int)$fmatch[3] : 0;
|
||||
$right = trim($fmatch[4]) ? (int)$fmatch[4] : $locale['int_frac_digits'];
|
||||
$conversion = $fmatch[5];
|
||||
|
||||
$positive = true;
|
||||
if ($value < 0) {
|
||||
$positive = false;
|
||||
$value *= -1;
|
||||
}
|
||||
$letter = $positive ? 'p' : 'n';
|
||||
|
||||
$prefix = $suffix = $cprefix = $csuffix = $signal = '';
|
||||
|
||||
$signal = $positive ? $locale['positive_sign'] : $locale['negative_sign'];
|
||||
switch (true) {
|
||||
case $locale["{$letter}_sign_posn"] == 1 && $flags['usesignal'] == '+' :
|
||||
$prefix = $signal;
|
||||
break;
|
||||
case $locale["{$letter}_sign_posn"] == 2 && $flags['usesignal'] == '+' :
|
||||
$suffix = $signal;
|
||||
break;
|
||||
case $locale["{$letter}_sign_posn"] == 3 && $flags['usesignal'] == '+' :
|
||||
$cprefix = $signal;
|
||||
break;
|
||||
case $locale["{$letter}_sign_posn"] == 4 && $flags['usesignal'] == '+' :
|
||||
$csuffix = $signal;
|
||||
break;
|
||||
case $flags['usesignal'] == '(' :
|
||||
case $locale["{$letter}_sign_posn"] == 0 :
|
||||
$prefix = '(';
|
||||
$suffix = ')';
|
||||
break;
|
||||
}
|
||||
if (!$flags['nosimbol']) {
|
||||
$currency = $cprefix . ($conversion == 'i' ? $locale['int_curr_symbol'] : $locale['currency_symbol']) . $csuffix;
|
||||
} else {
|
||||
$currency = '';
|
||||
}
|
||||
$space = $locale["{$letter}_sep_by_space"] ? ' ' : '';
|
||||
|
||||
$value = number_format($value, $right, $locale['mon_decimal_point'], $flags['nogroup'] ? '' : $locale['mon_thousands_sep']);
|
||||
$value = @explode($locale['mon_decimal_point'], $value);
|
||||
|
||||
$n = strlen($prefix) + strlen($currency) + strlen($value[0]);
|
||||
if ($left > 0 && $left > $n) {
|
||||
$value[0] = str_repeat($flags['fillchar'], $left - $n) . $value[0];
|
||||
}
|
||||
$value = implode($locale['mon_decimal_point'], $value);
|
||||
if ($locale["{$letter}_cs_precedes"]) {
|
||||
$value = $prefix . $currency . $space . $value . $suffix;
|
||||
} else {
|
||||
$value = $prefix . $value . $space . $currency . $suffix;
|
||||
}
|
||||
if ($width > 0) {
|
||||
$value = str_pad($value, $width, $flags['fillchar'], $flags['isleft'] ? STR_PAD_RIGHT : STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
$format = str_replace($fmatch[0], $value, $format);
|
||||
}
|
||||
return $format;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user