From 59f218ab42d2525f8016c5cafaa24c099f1b1aeb Mon Sep 17 00:00:00 2001 From: fhenry Date: Tue, 30 Apr 2013 16:00:30 +0200 Subject: [PATCH 1/3] [ bug #865 ] Dolibarr navigation array in project/task do not work --- htdocs/projet/class/project.class.php | 2 ++ htdocs/projet/fiche.php | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 97eb27745a8..9465fb815e2 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -35,6 +35,7 @@ class Project extends CommonObject public $table_element = 'projet'; //!< Name of table without prefix where object is stored public $table_element_line = 'projet_task'; public $fk_element = 'fk_projet'; + protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe var $id; var $ref; @@ -51,6 +52,7 @@ class Project extends CommonObject var $statuts_short; var $statuts; var $oldcopy; + /** * Constructor diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php index f5870301860..2511a65ee10 100644 --- a/htdocs/projet/fiche.php +++ b/htdocs/projet/fiche.php @@ -43,12 +43,6 @@ if ($id == '' && $ref == '' && ($action != "create" && $action != "add" && $acti $mine = GETPOST('mode')=='mine' ? 1 : 0; //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects - -// Security check -$socid=0; -if ($user->societe_id > 0) $socid=$user->societe_id; -$result = restrictedArea($user, 'projet', $id); - // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; $hookmanager=new HookManager($db); @@ -61,6 +55,11 @@ if ($object->id > 0) $object->fetch_thirdparty(); } +// Security check +$socid=0; +if ($user->societe_id > 0) $socid=$user->societe_id; +$result = restrictedArea($user, 'projet', $object->id); + $date_start=dol_mktime(0,0,0,GETPOST('projectmonth','int'),GETPOST('projectday','int'),GETPOST('projectyear','int')); $date_end=dol_mktime(0,0,0,GETPOST('projectendmonth','int'),GETPOST('projectendday','int'),GETPOST('projectendyear','int'));; @@ -720,10 +719,13 @@ else print ''; - // List of actions on element - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; - $formactions=new FormActions($db); - $somethingshown=$formactions->showactions($object,'project',$socid); + if (!empty($object->id)) + { + // List of actions on element + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; + $formactions=new FormActions($db); + $somethingshown=$formactions->showactions($object,'project',$socid); + } print ''; } From c84427bd225ba8bb0bf860e96712784cdc812fcd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 30 Apr 2013 22:52:56 +0200 Subject: [PATCH 2/3] Fix: delete of files with [ and glob. Conflicts: test/phpunit/FilesLibTest.php --- htdocs/core/lib/files.lib.php | 6 ++++-- test/phpunit/FilesLibTest.php | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 5211841fc02..3f4331420a1 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -751,12 +751,14 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$nohook=0,$object=n { $error=0; - //print "x".$file." ".$disableglob; + //print "x".$file." ".$disableglob;exit; $ok=true; $file_osencoded=dol_osencode($file); // New filename encoded in OS filesystem encoding charset if (empty($disableglob) && ! empty($file_osencoded)) { - foreach (glob($file_osencoded) as $filename) + $globencoded=str_replace('[','\[',$file_osencoded); + $globencoded=str_replace(']','\]',$globencoded); + foreach (glob($globencoded) as $filename) { if ($nophperrors) $ok=@unlink($filename); // The unlink encapsulated by dolibarr else $ok=unlink($filename); // The unlink encapsulated by dolibarr diff --git a/test/phpunit/FilesLibTest.php b/test/phpunit/FilesLibTest.php index 7a3d0f10aa9..17d36944f86 100644 --- a/test/phpunit/FilesLibTest.php +++ b/test/phpunit/FilesLibTest.php @@ -326,7 +326,7 @@ class FilesLibTest extends PHPUnit_Framework_TestCase // Again to test with overwriting=1 $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv',0,1); print __METHOD__." result=".$result."\n"; - $this->assertGreaterThanOrEqual(1,$result); // Should be 1 + $this->assertGreaterThanOrEqual(1,$result,'copy destination already exists, overwrite'); // Should be 1 // Again to test with overwriting=1 $result=dol_move($conf->admin->dir_temp.'/file.csv',$conf->admin->dir_temp.'/file2.csv',0,1); @@ -340,7 +340,17 @@ class FilesLibTest extends PHPUnit_Framework_TestCase // Again to test no erreor when deleteing a non existing file $result=dol_delete_file($conf->admin->dir_temp.'/file2.csv'); print __METHOD__." result=".$result."\n"; - $this->assertTrue($result); + $this->assertTrue($result,'delete file that does not exists'); + + // Test copy with special char / delete with blob + $result=dol_copy($file, $conf->admin->dir_temp.'/file with [x] and é.csv',0,1); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThanOrEqual(1,$result,'copy file with special char, overwrite'); // Should be 1 + + // Try to delete using a glob criteria + $result=dol_delete_file($conf->admin->dir_temp.'/file with [x]*é.csv'); + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result,'delete file using glob criteria'); } /** @@ -377,4 +387,4 @@ class FilesLibTest extends PHPUnit_Framework_TestCase $this->assertEquals(0,count($result)); } } -?> \ No newline at end of file +?> From 7d71be2227327ec292ad5c91104fa00ecf17256a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 30 Apr 2013 22:56:52 +0200 Subject: [PATCH 3/3] Fix: Import of contact/address not complete and not working with pgsql Conflicts: htdocs/core/modules/modSociete.class.php --- htdocs/core/db/mysqli.class.php | 2 +- htdocs/core/db/pgsql.class.php | 2 +- .../modules/import/import_csv.modules.php | 32 +++++++------------ htdocs/core/modules/modSociete.class.php | 4 +-- htdocs/core/tpl/admin_extrafields_add.tpl.php | 2 +- htdocs/imports/import.php | 4 +-- 6 files changed, 18 insertions(+), 28 deletions(-) diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 5ccdb661ec2..ba24d5c53bf 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -938,7 +938,7 @@ class DoliDBMysqli * * @param string $table Name of table * @param string $field Optionnel : Name of field if we want description of field - * @return resource Resource + * @return resultset Resultset x (x->Field, x->Type, ...) */ function DDLDescTable($table,$field="") { diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 695ab573fc4..a94d9dd96ba 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1169,7 +1169,7 @@ class DoliDBPgsql * * @param string $table Name of table * @param string $field Optionnel : Name of field if we want description of field - * @return resource Resource + * @return resultset Resultset x (x->attname) */ function DDLDescTable($table,$field="") { diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index 1b6f255a4f0..b1eaa2a725f 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -66,8 +66,7 @@ class ImportCsv extends ModeleImports global $conf,$langs; $this->db = $db; - $this->separator=','; // Change also function cleansep - if (! empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE)) $this->separator=$conf->global->IMPORT_CSV_SEPARATOR_TO_USE; + $this->separator=(GETPOST('separator')?GETPOST('separator'):(empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE)?',':$conf->global->IMPORT_CSV_SEPARATOR_TO_USE)); $this->enclosure='"'; $this->escape='"'; @@ -579,7 +578,7 @@ class ImportCsv extends ModeleImports //var_dump($objimport->array_import_convertvalue); exit; // Build SQL request - if (! tablewithentity($tablename)) + if (! tablewithentity($tablename)) { $sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key'; if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$objimport->array_import_tables_creator[0][$alias]; @@ -651,25 +650,16 @@ function cleansep($value) function tablewithentity($table) { global $db; - $sql = "SHOW COLUMNS FROM ".$table." LIKE 'entity'"; - - $resql=$db->query($sql); - if ($resql) - { - $numrows=$db->num_rows($resql); - if ($numrows) - { - return 1; - } - else - { - return 0; - } - } - else - { - return -1; + + $resql=$db->DDLDescTable($table,'entity'); + if ($resql) + { + $i=0; + $obj=$db->fetch_object($resql); + if ($obj) return 1; + else return 0; } + else return -1; } ?> \ No newline at end of file diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index d532b20d5a0..d6ee18c9b6c 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -355,7 +355,7 @@ class modSociete extends DolibarrModules $this->import_label[$r]='ImportDataset_company_2'; $this->import_icon[$r]='contact'; $this->import_entities_array[$r]=array('s.fk_soc'=>'company'); // We define here only fields that use another icon that the one defined into import_icon - $this->import_tables_array[$r]=array('s'=>MAIN_DB_PREFIX.'socpeople'); // List of tables to insert into (insert done in same order) + $this->import_tables_array[$r]=array('s'=>MAIN_DB_PREFIX.'socpeople','extra'=>MAIN_DB_PREFIX.'socpeople_extrafields'); // List of tables to insert into (insert done in same order) $this->import_fields_array[$r]=array('s.fk_soc'=>'ThirdPartyName*','s.civilite'=>'UserTitle','s.name'=>"Name*",'s.firstname'=>"Firstname",'s.address'=>"Address",'s.cp'=>"Zip",'s.ville'=>"Town",'s.fk_pays'=>"CountryCode",'s.birthday'=>"BirthdayDate",'s.poste'=>"Role",'s.phone'=>"Phone",'s.phone_perso'=>"PhonePerso",'s.phone_mobile'=>"PhoneMobile",'s.fax'=>"Fax",'s.email'=>"Email",'s.note'=>"Note",'s.datec'=>"DateCreation"); // Add extra fields $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'contact'"; @@ -370,7 +370,7 @@ class modSociete extends DolibarrModules } } // End add extra fields - $this->import_fieldshidden_array[$r]=array('s.fk_user_creat'=>'user->id'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) + $this->import_fieldshidden_array[$r]=array('s.fk_user_creat'=>'user->id','extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'socpeople'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) $this->import_convertvalue_array[$r]=array( 's.fk_soc'=>array('rule'=>'fetchidfromref','file'=>'/societe/class/societe.class.php','class'=>'Societe','method'=>'fetch','element'=>'ThirdParty'), 's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/cpays.class.php','class'=>'Cpays','method'=>'fetch','dict'=>'DictionnaryCountry'), diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index eba68cc646c..90662ebb70b 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -33,7 +33,7 @@ else if (type == 'varchar') { size.val('255').removeAttr('disabled'); unique.removeAttr('disabled','disabled'); } else size.val('').attr('disabled','disabled'); } - init_typeoffields(''); + init_typeoffields(''); jQuery("#type").change(function() { init_typeoffields($(this).val()); }); diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index 85c8410da7e..01f85c32df4 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -1017,7 +1017,7 @@ if ($step == 4 && $datatoimport) } else { - print ''.$langs->trans("NextStep").''; + print ''.$langs->trans("NextStep").''; } } @@ -1281,7 +1281,7 @@ if ($step == 5 && $datatoimport) } else { - print ''.$langs->trans("RunSimulateImportFile").''; + print ''.$langs->trans("RunSimulateImportFile").''; } print ''; }