PHP 8.3 compatibility

Improve DOC & Log
This commit is contained in:
sparkyx 2025-04-03 22:06:55 +02:00
parent 0dfa2f1246
commit 8724903961
4 changed files with 33 additions and 18 deletions

View file

@ -37,7 +37,9 @@ class Anc_Print
var $from; /*!< $from end date */
var $from_poste; /*!< $from_poste from poste */
var $to_poste; /*!< $to_poste to the poste */
var $has_data; /*!< array of data */
protected $pa_id; /*!< axis for analytic : plan */
function __construct($p_cn)
{
global $g_user;

View file

@ -26,6 +26,10 @@
*/
class Document_Export
{
var $feedback; /*!< contains feedback */
var $store_convert; /*!< temporary folder for files*/
var $store_pdf; /*!< temporary folder for PDF */
var $progress; /*!< contain value for progressbar*/
/**
*@brief create 2 temporary folders, store_pdf and store_convert, initialize
* an array feedback containing messages
@ -43,9 +47,9 @@ class Document_Export
$this->progress=NULL;
umask(0);
if ( mkdir($this->store_convert) == FALSE )
throw new Exception(sprintf("Create %s failed",$this->store_onvert));
throw new Exception(sprintf("ERR DE50-Create %s failed",$this->store_onvert));
if ( mkdir($this->store_pdf)== FALSE )
throw new Exception(sprintf("Create %s failed",$this->store_pdf));
throw new Exception(sprintf("ERR DE52 Create %s failed",$this->store_pdf));
}
/**
* @brief concatenate all PDF into a single one and save it into the
@ -66,7 +70,7 @@ class Document_Export
{
$cnt_feedback=count($this->feedback);
$this->feedback[$cnt_feedback]['file']='result.pdf';
$this->feedback[$cnt_feedback]['message']=' cannot concatenate PDF';
$this->feedback[$cnt_feedback]['message']='DE73 cannot concatenate PDF';
$this->feedback[$cnt_feedback]['error']=$status;
}
}
@ -88,14 +92,16 @@ class Document_Export
$res=$zip->open("{$this->store_pdf}/result.zip",ZipArchive::CREATE);
if ($res !== true) {
error_log("ERR-DE89 cannot create zip file");
throw new Exception ( __FILE__.":".__LINE__."cannot recreate zip");
record_log($this);
throw new Exception ("ERR-DE89 cannot recreate zip");
}
chdir($this->store_pdf);
// addGmpn
$res=$zip->add_file_pattern($this->store_pdf,"/.*.pdf/");
$res=$zip->add_file_pattern($this->store_pdf,"/.*pdf/");
if ($res == 0) {
error_log("ERR-DE96 aucun fichier trouvé");
throw new Exception ( __FILE__.":".__LINE__."cannot recreate zip");
record_log($this);
throw new Exception ( "ERR-DE96 cannot recreate zip");
}
$zip->close();
@ -271,7 +277,9 @@ class Document_Export
}
$progress->set_value(93);
if (DEBUGNOALYSS>1) {
tracedebug(date('y-m-d')."-debug.log",$this->feedback,'feedback');
}
if ($p_separate==1)
{
// concatenate all pdf into one
@ -358,7 +366,7 @@ class Document_Export
if ($status<>0)
{
$this->feedback[$cnt_feedback]['file']=$filename;
$this->feedback[$cnt_feedback]['message']=' cannot convert to PDF';
$this->feedback[$cnt_feedback]['message']=' OFFICE cannot convert to PDF';
$this->feedback[$cnt_feedback]['error']=$status;
return null;
}
@ -368,13 +376,13 @@ class Document_Export
$font=imagecolorallocatealpha($img, 100, 100, 100, 110);
imagettftext($img, 40, 25, 500, 1000, $font,
NOALYSS_INCLUDE.'/tfpdf/font/unifont/DejaVuSans.ttf'
, _("Copie certifiée conforme à l'original"));
, _("Copie certifiee conforme a l'original"));
imagettftext($img, 40, 25, 550, 1100, $font,
NOALYSS_INCLUDE.'/tfpdf/font/unifont/DejaVuSans.ttf'
, $file[0]['jr_pj_number']);
imagettftext($img, 40, 25, 600, 1200, $font,
NOALYSS_INCLUDE.'/tfpdf/font/unifont/DejaVuSans.ttf'
, $file[0]['jr_pj_name']);
,$filename);
imagegif($img, $this->store_convert.'/'.'stamp.gif');
// transform gif file to pdf with convert tool
@ -384,7 +392,7 @@ class Document_Export
if ($status<>0)
{
$this->feedback[$cnt_feedback]['file']='stamp.pdf';
$this->feedback[$cnt_feedback]['message']=' cannot convert to PDF';
$this->feedback[$cnt_feedback]['message']=' CONVERT_GIF_PDF cannot convert to PDF';
$this->feedback[$cnt_feedback]['error']=$status;
return null;
}
@ -444,7 +452,7 @@ class Document_Export
{
$this->feedback[$cnt_feedback]['file']=$file_pdf;
$this->feedback[$cnt_feedback]['message']=_(' ne peut pas convertir en PDF');
$this->feedback[$cnt_feedback]['message']=_('PDFTK ne peut pas convertir en PDF')." cmd =[$stmt] status [$status]";
$this->feedback[$cnt_feedback]['error']=$status;
return null;
}

View file

@ -42,5 +42,10 @@ $reconcilied_document=$http->get("reconcilied_document","number",1);
$task_id=$http->request("task_id");
$progress=new Progress_Bar($task_id);
$anc->export_all($ck,$progress,$type_pdf,$reconcilied_document);
try {
$anc->export_all($ck,$progress,$type_pdf,$reconcilied_document);
} catch (Exception $ex) {
record_log($ex);
}

View file

@ -1341,7 +1341,7 @@ function is_msie()
*/
function record_log($p_message)
{
$date=date('Y.m.d');
$date= date ('Y-m-d');
// variable: $handle_log resource on log file ,
$handle_log=fopen(NOALYSS_BASE."/log/noalyss-{$date}.log","a+");
@ -1374,7 +1374,7 @@ function record_log($p_message)
}
$now=date('y-m-d H:i');
$now=date ('Y-m-d H:i:s');
fwrite ($handle_log,str_repeat("=", 80)."\n");
fwrite ($handle_log,"ERROR: {$now}\n");
fwrite($handle_log,"noalyss GET [".var_export($_GET,true)."]");
@ -1409,7 +1409,8 @@ if(!function_exists('tracedebug')) {
function tracedebug($file,$var, $label = NULL) {
$tmp_file = sys_get_temp_dir().DIRECTORY_SEPARATOR.$file;
if ( ! is_writable($tmp_file)) return;
$file_loginput=fopen( $tmp_file,'a+');
if ( $file_loginput == false) { return;}
$output = '';
$output .= date('d-m-y H:i');
if(!is_null($label)) {
@ -1854,4 +1855,3 @@ function sanitize_filename($filename)
$new_filename=strtolower($filename_no)."-".date("Ymd-Hi").$filename_suff;
return $new_filename;
}