From d2ae90f938c6c34022bfec61196431ee2c22b38f Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 2 Sep 2012 22:48:52 +0200 Subject: [PATCH] Fix: strict mode everywhere --- htdocs/core/db/mysql.class.php | 14 +++++------ htdocs/core/db/mysqli.class.php | 14 +++++------ htdocs/core/lib/ajax.lib.php | 2 +- htdocs/core/lib/functions.lib.php | 19 ++++++++++----- htdocs/core/modules/DolibarrModules.class.php | 16 ++++++------- .../modules/expedition/modules_expedition.php | 2 +- .../modules/livraison/modules_livraison.php | 2 +- htdocs/imports/import.php | 24 ++++++++++++------- htdocs/main.inc.php | 2 +- 9 files changed, 55 insertions(+), 40 deletions(-) diff --git a/htdocs/core/db/mysql.class.php b/htdocs/core/db/mysql.class.php index 8d6b08d90de..7bb8b77f399 100644 --- a/htdocs/core/db/mysql.class.php +++ b/htdocs/core/db/mysql.class.php @@ -1,9 +1,9 @@ - * Copyright (C) 2002-2007 Rodolphe Quiedeville - * Copyright (C) 2004-2011 Laurent Destailleur - * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2005-2009 Regis Houssin +/* Copyright (C) 2001 Fabien Seisen + * Copyright (C) 2002-2007 Rodolphe Quiedeville + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2006 Andre Cianfarani + * Copyright (C) 2005-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -714,10 +714,10 @@ class DoliDBMysql global $conf; // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) - $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); + $cryptType = (isset($conf->db->dolibarr_main_db_encryption)?$conf->db->dolibarr_main_db_encryption:0); //Encryption key - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); + $cryptKey = (! empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); $return = ($withQuotes?"'":"").$this->escape($fieldorvalue).($withQuotes?"'":""); diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 3db424d4db2..4d4b9d9be1b 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -1,9 +1,9 @@ - * Copyright (C) 2002-2005 Rodolphe Quiedeville - * Copyright (C) 2004-2011 Laurent Destailleur - * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2005-2009 Regis Houssin +/* Copyright (C) 2001 Fabien Seisen + * Copyright (C) 2002-2005 Rodolphe Quiedeville + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2006 Andre Cianfarani + * Copyright (C) 2005-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -709,10 +709,10 @@ class DoliDBMysqli global $conf; // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) - $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); + $cryptType = (isset($conf->db->dolibarr_main_db_encryption)?$conf->db->dolibarr_main_db_encryption:0); //Encryption key - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); + $cryptKey = (! empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); $return = ($withQuotes?"'":"").$this->escape($fieldorvalue).($withQuotes?"'":""); diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 70a88760adf..e5b8a1d5f12 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -350,7 +350,7 @@ function ajax_combobox($htmlname, $event=array()) * @param int $entity Entity to set * @return void */ -function ajax_constantonoff($code,$input=array(),$entity=false) +function ajax_constantonoff($code, $input=array(), $entity=false) { global $conf, $langs; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index cccc2429817..86ad6f2a2fb 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3033,12 +3033,13 @@ function get_exdir($num,$level=3,$alpha=0,$withoutslash=0) /** * Creation of a directory (this can create recursive subdir) * - * @param string $dir Directory to create (Separator must be '/'. Example: '/mydir/mysubdir') - * @return int < 0 if KO, 0 = already exists, > 0 if OK + * @param string $dir Directory to create (Separator must be '/'. Example: '/mydir/mysubdir') + * @param string $dataroot Data root directory (to avoid having the data root in the loop) + * @return int < 0 if KO, 0 = already exists, > 0 if OK */ -function dol_mkdir($dir) +function dol_mkdir($dir, $dataroot='') { - global $conf; + global $db, $conf; dol_syslog("functions.lib::dol_mkdir: dir=".$dir,LOG_INFO); @@ -3048,8 +3049,14 @@ function dol_mkdir($dir) $nberr=0; $nbcreated=0; - $ccdir = ''; - $cdir = explode("/",$dir); + $ccdir=''; + if (! empty($dataroot)) { + // Remove data root from loop + $dir = str_replace($dataroot.'/', '', $dir); + $ccdir = $dataroot.'/'; + } + + $cdir = explode("/", $dir); $num=count($cdir); for ($i = 0; $i < $num; $i++) { diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index ab33d464c8d..0e676200fcb 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -1170,7 +1170,7 @@ abstract class DolibarrModules $err=0; - if (is_array($this->dirs)) + if (isset($this->dirs) && is_array($this->dirs) && ! empty($this->dirs)) { foreach ($this->dirs as $key => $value) { @@ -1184,19 +1184,19 @@ abstract class DolibarrModules $subname = empty($this->dirs[$key][3])?'':strtoupper($this->dirs[$key][3]); // Add submodule name (ex: $conf->module->submodule->dir_output) $forcename = empty($this->dirs[$key][4])?'':strtoupper($this->dirs[$key][4]); // Change the module name if different - if ($forcename) $constname = 'MAIN_MODULE_'.$forcename."_DIR_"; - if ($subname) $constname = $constname.$subname."_"; + if (! empty($forcename)) $constname = 'MAIN_MODULE_'.$forcename."_DIR_"; + if (! empty($subname)) $constname = $constname.$subname."_"; - $name = $constname.strtoupper($this->dirs[$key][0]); + $name = $constname.strtoupper($this->dirs[$key][0]); } // Define directory full path ($dir must start with "/") if (empty($conf->global->MAIN_MODULE_MULTICOMPANY) || $conf->entity == 1) $fulldir = DOL_DATA_ROOT.$dir; else $fulldir = DOL_DATA_ROOT."/".$conf->entity.$dir; // Create dir if it does not exists - if ($fulldir && ! file_exists($fulldir)) + if (! empty($fulldir) && ! file_exists($fulldir)) { - if (dol_mkdir($fulldir) < 0) + if (dol_mkdir($fulldir, DOL_DATA_ROOT) < 0) { $this->error = $langs->trans("ErrorCanNotCreateDir",$fulldir); dol_syslog(get_class($this)."::_init ".$this->error, LOG_ERR); @@ -1205,9 +1205,9 @@ abstract class DolibarrModules } // Define the constant in database if requested (not the default mode) - if ($addtodatabase) + if (! empty($addtodatabase)) { - $result = $this->insert_dirs($name,$dir); + $result = $this->insert_dirs($name, $dir); if ($result) $err++; } } diff --git a/htdocs/core/modules/expedition/modules_expedition.php b/htdocs/core/modules/expedition/modules_expedition.php index f650e4bd84f..a40fddc9ef6 100644 --- a/htdocs/core/modules/expedition/modules_expedition.php +++ b/htdocs/core/modules/expedition/modules_expedition.php @@ -246,4 +246,4 @@ function expedition_pdf_create($db, $object, $modele, $outputlangs) return -1; } } -?> +?> \ No newline at end of file diff --git a/htdocs/core/modules/livraison/modules_livraison.php b/htdocs/core/modules/livraison/modules_livraison.php index de778563c46..663c7198755 100644 --- a/htdocs/core/modules/livraison/modules_livraison.php +++ b/htdocs/core/modules/livraison/modules_livraison.php @@ -251,4 +251,4 @@ function delivery_order_pdf_create($db, $object, $modele, $outputlangs='') } } -?> +?> \ No newline at end of file diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index c9bd77bacb6..5b28b54af5a 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -35,8 +35,8 @@ $langs->load("exports"); $langs->load("errors"); // Security check -if ($user->societe_id) $socid=$user->societe_id; -$result=restrictedArea($user,'import',$origin_id,''); +if (! empty($user->societe_id)) $socid=$user->societe_id; +$result=restrictedArea($user, 'import'); $entitytoicon=array( 'invoice'=>'bill','invoice_line'=>'bill', @@ -68,7 +68,8 @@ $entitytolang=array( // Translation code $datatoimport = GETPOST('datatoimport'); $format = GETPOST('format'); $filetoimport = GETPOST('filetoimport'); -$action = GETPOST('action'); +$action = GETPOST('action','alpha'); +$confirm = GETPOST('confirm','alpha'); $step = (GETPOST('step') ? GETPOST('step') : 1); $import_name = GETPOST('import_name'); $hexa = GETPOST('hexa'); @@ -92,7 +93,7 @@ foreach($fieldsarray as $elem) { $tabelem=explode('=',$elem,2); $key=$tabelem[0]; - $val=$tabelem[1]; + $val=(isset($tabelem[1])?$tabelem[1]:''); if ($key && $val) { $array_match_file_to_database[$key]=$val; @@ -192,7 +193,7 @@ if ($action == 'add_import_model') if ($step == 3 && $datatoimport) { - if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) + if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) { dol_mkdir($conf->import->dir_temp); $nowyearmonth=dol_print_date(dol_now(),'%Y%m%d%H%M%S'); @@ -451,6 +452,14 @@ if ($step == 3 && $datatoimport) dol_fiche_head($head, 'step3', $langs->trans("NewImport")); + /* + * Confirm delete file + */ + if ($action == 'delete') + { + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?urlfile='.urlencode(GETPOST('urlfile')).'&step=3'.$param, $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1); + if ($ret == 'html') print '
'; + } print ''; @@ -511,7 +520,7 @@ if ($step == 3 && $datatoimport) print "\n"; // Search available imports - $filearray=dol_dir_list($conf->import->dir_temp,'files',0,'','','name',SORT_DESC); + $filearray=dol_dir_list($conf->import->dir_temp, 'files', 0, '', '', 'name', SORT_DESC); if (count($filearray) > 0) { $dir=$conf->import->dir_temp; @@ -545,8 +554,7 @@ if ($step == 3 && $datatoimport) // Affiche date fichier print ''; // Del button - print ''; // Action button print '
'.dol_print_date(dol_filemtime($dir.'/'.$file),'dayhour').''.img_delete().''; diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 06e0d7df71f..3c1b9e99493 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1000,7 +1000,7 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs print ''."\n"; } // jQuery File Upload - if (! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD)) + if (! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD) || defined('REQUIRE_JQUERY_FILEUPLOAD')) { print ''."\n"; print ''."\n";