From 6aa6ef1f9f1a13db8853935b6030db5ff13584ac Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 May 2017 18:30:43 +0200 Subject: [PATCH 01/15] Fix travis error --- htdocs/core/lib/files.lib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 008f4c15e3c..0920158b720 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -657,6 +657,7 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists) * @param string $destfile Destination file (can't be a directory. use native php @rename() to move a directory) * @param integer $newmask Mask in octal string for new file (0 by default means $conf->global->MAIN_UMASK) * @param int $overwriteifexists Overwrite file if exists (1 by default) + * @param int $testvirus Do an antivirus test. Move is canceled if a virus is found. * @return boolean True if OK, false if KO * @see dol_move_uploaded_file */ @@ -1698,7 +1699,7 @@ function dol_most_recent_file($dir,$regexfilter='',$excludefilter=array('(\.meta * @param string $entity Restrict onto entity (0=no restriction) * @param User $fuser User object (forced) * @param string $refname Ref of object to check permission for external users (autodetect if not provided) - * @param string $more Check permission for 'read' or 'write' + * @param string $mode Check permission for 'read' or 'write' * @return mixed Array with access information : 'accessallowed' & 'sqlprotectagainstexternals' & 'original_file' (as a full path name) * @see restrictedArea */ From 5cb38ece19b6922a2646ca45a01fbde90b874ae4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 May 2017 19:37:15 +0200 Subject: [PATCH 02/15] Fix travis errors --- htdocs/core/lib/functions.lib.php | 2 +- htdocs/core/modules/DolibarrModules.class.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 14f61d99590..8462cdc76ff 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -281,7 +281,7 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL) $relativepathstring = preg_replace('/^\//', '', $relativepathstring); // Retrieve values if restore_lastsearch_values is set and there is saved values - if ($_GET['restore_lastsearch_values'] && ! empty($_SESSION['lastsearch_values_'.$relativepathstring])) // Keep $_GET here + if (! empty($_GET['restore_lastsearch_values']) && ! empty($_SESSION['lastsearch_values_'.$relativepathstring])) // Keep $_GET here { $tmp=json_decode($_SESSION['lastsearch_values_'.$relativepathstring], true); if (is_array($tmp)) diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index cdb4ea33f73..71de341a769 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -848,8 +848,8 @@ class DolibarrModules // Can not be abstract, because we need to insta $resql=$this->db->query($sql); if (! $resql) $err++; - $note=json_encode(array('authorid'=>$user->id, 'ip'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR']))); - + $note=json_encode(array('authorid'=>(is_object($user)?$user->id:0), 'ip'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR']))); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."const (name, value, visible, entity, note) VALUES"; $sql.= " (".$this->db->encrypt($this->const_name,1); $sql.= ", ".$this->db->encrypt('1',1); From 965e23b71190a8d77e2042e4f568d5233d9b664a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 May 2017 19:45:47 +0200 Subject: [PATCH 03/15] Test to fix a regression --- htdocs/core/lib/functions2.lib.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index c8d617ec99d..8934447fdfe 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -781,7 +781,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m } // Personalized field {XXX-1} à {XXX-9} - $maskperso=array(); + /*$maskperso=array(); $maskpersonew=array(); $tmpmask=$mask; while (preg_match('/\{([A-Z]+)\-([1-9])\}/i',$tmpmask,$regKey)) @@ -789,17 +789,17 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m $maskperso[$regKey[1]]='\{'.$regKey[1]+'\-'.$regKey[2].'\}'; $maskpersonew[$regKey[1]]=str_pad('', '_', $regKey[2], STR_PAD_RIGHT); $tmpmask=preg_replace('/\{'.$regKey[1].'\-'.$regKey[2].'\}/i', $maskpersonew, $tmpmask); - } + }*/ $maskwithonlyymcode=$mask; $maskwithonlyymcode=preg_replace('/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i',$maskcounter,$maskwithonlyymcode); $maskwithonlyymcode=preg_replace('/\{dd\}/i','dd',$maskwithonlyymcode); $maskwithonlyymcode=preg_replace('/\{(c+)(0*)\}/i',$maskrefclient,$maskwithonlyymcode); $maskwithonlyymcode=preg_replace('/\{(t+)\}/i',$masktype_value,$maskwithonlyymcode); - foreach($maskperso as $key => $val) + /*foreach($maskperso as $key => $val) { $maskwithonlyymcode=preg_replace('/'.$val.'/i', $maskpersonew[$key], $maskwithonlyymcode); - } + }*/ $maskwithnocode=$maskwithonlyymcode; $maskwithnocode=preg_replace('/\{yyyy\}/i','yyyy',$maskwithnocode); $maskwithnocode=preg_replace('/\{yy\}/i','yy',$maskwithnocode); From 6e31de731b8cd376a0b185b30cf8a78e7d7e8b57 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 May 2017 20:24:56 +0200 Subject: [PATCH 04/15] Fix phpunit --- htdocs/societe/class/societe.class.php | 2 +- test/phpunit/SocieteTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 6aebf0e8786..995c16719cb 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -841,7 +841,7 @@ class Societe extends CommonObject $sql .= ",fk_effectif = ".(! empty($this->effectif_id)?"'".$this->db->escape($this->effectif_id)."'":"null"); if (isset($this->stcomm_id)) { - $sql .= ",fk_stcomm=".($this->stcomm_id > 0 ? $this->stcomm_id : "null"); + $sql .= ",fk_stcomm=".($this->stcomm_id > 0 ? $this->stcomm_id : "0"); } $sql .= ",fk_typent = ".(! empty($this->typent_id)?"'".$this->db->escape($this->typent_id)."'":"0"); diff --git a/test/phpunit/SocieteTest.php b/test/phpunit/SocieteTest.php index 24b868b743e..31aa98fd082 100755 --- a/test/phpunit/SocieteTest.php +++ b/test/phpunit/SocieteTest.php @@ -79,7 +79,7 @@ class SocieteTest extends PHPUnit_Framework_TestCase if ($conf->global->SOCIETE_CODECLIENT_ADDON != 'mod_codeclient_monkey') { print "\n".__METHOD__." third party ref checker must be setup to 'mod_codeclient_monkey' not to '".$conf->global->SOCIETE_CODECLIENT_ADDON."'.\n"; die(); } - if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) { print "\n".__METHOD__." constant MAIN_DISABLEPROFIDRULE must be empty (if a module set it, disable module).\n"; die(); } + if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) { print "\n".__METHOD__." constant MAIN_DISABLEPROFIDRULES must be empty (if a module set it, disable module).\n"; die(); } $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. From ff35229be58e84c049540c47f0a2c12fb0b874b7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 May 2017 20:46:11 +0200 Subject: [PATCH 05/15] Fix phpunit --- test/phpunit/UserTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/phpunit/UserTest.php b/test/phpunit/UserTest.php index 4e0c0ba58ca..e0802ff17a2 100644 --- a/test/phpunit/UserTest.php +++ b/test/phpunit/UserTest.php @@ -75,6 +75,9 @@ class UserTest extends PHPUnit_Framework_TestCase public static function setUpBeforeClass() { global $conf,$user,$langs,$db; + + if (! empty($conf->global->MAIN_LDAP_ENABLED)) { print "\n".__METHOD__." module LDAP must be disabled.\n"; die(); } + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. print __METHOD__."\n"; @@ -187,7 +190,7 @@ class UserTest extends PHPUnit_Framework_TestCase $newlocalobject=new User($this->savdb); $newlocalobject->initAsSpecimen(); $this->changeProperties($newlocalobject); - $this->assertEquals($this->objCompare($localobject,$newlocalobject,true,array('id','socid','societe_id','ref','pass_indatabase','pass_indatabase_crypted','datec','datem','datelastlogin','datepreviouslogin')), array()); // Actual, Expected + $this->assertEquals($this->objCompare($localobject,$newlocalobject,true,array('id','socid','societe_id','ref','pass','pass_indatabase','pass_indatabase_crypted','datec','datem','datelastlogin','datepreviouslogin')), array()); // Actual, Expected return $localobject; } From 3e381aa5a29345136f1468e731948187d5b7fcfb Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 May 2017 21:04:20 +0200 Subject: [PATCH 06/15] Fix phpunit --- test/phpunit/AdherentTest.php | 6 ++++-- test/phpunit/UserTest.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/phpunit/AdherentTest.php b/test/phpunit/AdherentTest.php index 42b4ff7cf7f..b998c346b7b 100644 --- a/test/phpunit/AdherentTest.php +++ b/test/phpunit/AdherentTest.php @@ -83,7 +83,9 @@ class AdherentTest extends PHPUnit_Framework_TestCase print "\n".__METHOD__." Company must be setup to have name-firstname in order 'Firstname Lastname'\n"; die(); } - + if (! empty($conf->global->MAIN_MODULE_LDAP)) { print "\n".__METHOD__." module LDAP must be disabled.\n"; die(); } + if (! empty($conf->global->MAIN_MODULE_MAILMANSPIP)) { print "\n".__METHOD__." module MailmanSpip must be disabled.\n"; die(); } + print __METHOD__."\n"; } @@ -322,7 +324,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase $expected = DOL_MAIN_URL_ROOT.','.$localobject->id.',,New firstname,New name,New firstname New name,'. 'New company,New address,New zip,New town,Belgium,newemail@newemail.com,'.dol_print_date($localobject->birth,'day').',,'. - 'newlogin,dolibspec,New firstname,New name,New company,New address,New zip,New town,Belgium'; + 'newlogin,,New firstname,New name,New company,New address,New zip,New town,Belgium'; $result = $localobject->makeSubstitution($template); print __METHOD__." result=".$result."\n"; diff --git a/test/phpunit/UserTest.php b/test/phpunit/UserTest.php index e0802ff17a2..b932d2e2221 100644 --- a/test/phpunit/UserTest.php +++ b/test/phpunit/UserTest.php @@ -76,7 +76,7 @@ class UserTest extends PHPUnit_Framework_TestCase { global $conf,$user,$langs,$db; - if (! empty($conf->global->MAIN_LDAP_ENABLED)) { print "\n".__METHOD__." module LDAP must be disabled.\n"; die(); } + if (! empty($conf->global->MAIN_MODULE_LDAP)) { print "\n".__METHOD__." module LDAP must be disabled.\n"; die(); } $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. From 4a085a8cc0ebf22036b97b9f1b5c1532fd77cbec Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 May 2017 21:21:44 +0200 Subject: [PATCH 07/15] Fix phpunit --- htdocs/compta/bank/class/account.class.php | 5 ++--- test/phpunit/WebservicesInvoicesTest.php | 2 ++ test/phpunit/WebservicesOrdersTest.php | 2 ++ test/phpunit/WebservicesOtherTest.php | 2 ++ test/phpunit/WebservicesProductsTest.php | 2 ++ test/phpunit/WebservicesThirdpartyTest.php | 2 ++ test/phpunit/WebservicesUserTest.php | 2 ++ 7 files changed, 14 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 2a615ad4b69..b77ed4db1a5 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -569,7 +569,7 @@ class Account extends CommonObject $sql.= ", '".$this->db->escape($this->label)."'"; $sql.= ", ".$conf->entity; $sql.= ", '".$this->db->escape($this->account_number)."'"; - $sql.= ", '".$this->db->escape($this->fk_accountancy_journal)."'"; + $sql.= ", ".($this->fk_accountancy_journal > 0 ? $this->db->escape($this->fk_accountancy_journal) : "null"); $sql.= ", '".$this->db->escape($this->bank)."'"; $sql.= ", '".$this->code_banque."'"; $sql.= ", '".$this->code_guichet."'"; @@ -702,8 +702,7 @@ class Account extends CommonObject $sql.= ",rappro = ".$this->rappro; $sql.= ",url = ".($this->url?"'".$this->url."'":"null"); $sql.= ",account_number = '".$this->db->escape($this->account_number)."'"; - $sql.= ",fk_accountancy_journal = '".$this->db->escape($this->fk_accountancy_journal)."'"; - + $sql.= ",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? $this->db->escape($this->fk_accountancy_journal) : "null"); $sql.= ",bank = '".$this->db->escape($this->bank)."'"; $sql.= ",code_banque='".$this->db->escape($this->code_banque)."'"; $sql.= ",code_guichet='".$this->db->escape($this->code_guichet)."'"; diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index 470bcbf4900..07bd95e01f2 100644 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -39,6 +39,8 @@ if (empty($user->id)) } $conf->global->MAIN_DISABLE_ALL_MAILS=1; +$conf->global->MAIN_UMASK='0666'; + /** * Class for PHPUnit tests diff --git a/test/phpunit/WebservicesOrdersTest.php b/test/phpunit/WebservicesOrdersTest.php index 06ead4f4873..e81ee2d3604 100644 --- a/test/phpunit/WebservicesOrdersTest.php +++ b/test/phpunit/WebservicesOrdersTest.php @@ -38,6 +38,8 @@ if (empty($user->id)) { } $conf->global->MAIN_DISABLE_ALL_MAILS=1; +$conf->global->MAIN_UMASK='0666'; + /** * Class for PHPUnit tests diff --git a/test/phpunit/WebservicesOtherTest.php b/test/phpunit/WebservicesOtherTest.php index d04fc6b9b9c..e3725c8609c 100644 --- a/test/phpunit/WebservicesOtherTest.php +++ b/test/phpunit/WebservicesOtherTest.php @@ -38,6 +38,8 @@ if (empty($user->id)) { } $conf->global->MAIN_DISABLE_ALL_MAILS=1; +$conf->global->MAIN_UMASK='0666'; + /** * Class for PHPUnit tests diff --git a/test/phpunit/WebservicesProductsTest.php b/test/phpunit/WebservicesProductsTest.php index fecc58a65e1..796ee700221 100644 --- a/test/phpunit/WebservicesProductsTest.php +++ b/test/phpunit/WebservicesProductsTest.php @@ -40,6 +40,8 @@ if (empty($user->id)) { } $conf->global->MAIN_DISABLE_ALL_MAILS=1; +$conf->global->MAIN_UMASK='0666'; + if (empty($conf->service->enabled)) { print "Error: Module service must be enabled.\n"; diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 2888c432e73..59907b36194 100644 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -38,6 +38,8 @@ if (empty($user->id)) { } $conf->global->MAIN_DISABLE_ALL_MAILS=1; +$conf->global->MAIN_UMASK='0666'; + /** * Class for PHPUnit tests diff --git a/test/phpunit/WebservicesUserTest.php b/test/phpunit/WebservicesUserTest.php index 78d3d311fe0..5098da22e6e 100644 --- a/test/phpunit/WebservicesUserTest.php +++ b/test/phpunit/WebservicesUserTest.php @@ -38,6 +38,8 @@ if (empty($user->id)) { } $conf->global->MAIN_DISABLE_ALL_MAILS=1; +$conf->global->MAIN_UMASK='0666'; + /** * Class for PHPUnit tests From e85f31f456068c1ed8998a4ab3dca38811dcf546 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 May 2017 21:33:24 +0200 Subject: [PATCH 08/15] Fix phpunit --- test/phpunit/WebservicesProductsTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/phpunit/WebservicesProductsTest.php b/test/phpunit/WebservicesProductsTest.php index 796ee700221..e3500a68f5b 100644 --- a/test/phpunit/WebservicesProductsTest.php +++ b/test/phpunit/WebservicesProductsTest.php @@ -169,7 +169,9 @@ class WebservicesProductsTest extends PHPUnit_Framework_TestCase 'ref'=>'NewProductFromWS'.$datestring, 'label'=>'New Product From WS '.$datestring, 'type'=>1, - 'description'=>'This is a new product created from WS PHPUnit test case' + 'description'=>'This is a new product created from WS PHPUnit test case', + 'barcode'=>'123456789012', + 'barcode_type'=>2 ) ); print __METHOD__." call method ".$WS_METHOD."\n"; From 6052d2d8ed3dbfa965469838a2aa2c8b4d660f96 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 May 2017 21:37:33 +0200 Subject: [PATCH 09/15] Try to output log after error --- test/phpunit/NumberingModulesTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/phpunit/NumberingModulesTest.php b/test/phpunit/NumberingModulesTest.php index b29cd03b2c9..e0d175b75d5 100644 --- a/test/phpunit/NumberingModulesTest.php +++ b/test/phpunit/NumberingModulesTest.php @@ -158,6 +158,10 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject2, 'last'); print __METHOD__." result=".$result."\n"; + + $out=file_get_contents(DOL_DATA_ROOT.'/dolibarr.log'); + print $out; + $this->assertEquals('1915-0001', $result, "Test to get last value with param 'last'"); $result=$numbering->getNextValue($mysoc, $localobject2); $result2=$localobject2->create($user,1); From 246fa9748b708ed2cbc9f86eda4aa713e7b307de Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 May 2017 23:06:45 +0200 Subject: [PATCH 10/15] Debug travis error --- test/phpunit/ModulesTest.php | 5 +++++ test/phpunit/NumberingModulesTest.php | 23 ++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/test/phpunit/ModulesTest.php b/test/phpunit/ModulesTest.php index e769ce9dd51..a4ff51333e0 100755 --- a/test/phpunit/ModulesTest.php +++ b/test/phpunit/ModulesTest.php @@ -143,6 +143,11 @@ class ModulesTest extends PHPUnit_Framework_TestCase $result=$mod->init(); $this->assertLessThan($result, 0, $modlabel); print __METHOD__." test remove/init for module ".$modlabel.", result=".$result."\n"; + + if (in_array($modlabel, array('Ldap', 'MailmanSpip'))) + { + $result=$mod->remove(); + } } return 0; diff --git a/test/phpunit/NumberingModulesTest.php b/test/phpunit/NumberingModulesTest.php index e0d175b75d5..d7f3eaf611c 100644 --- a/test/phpunit/NumberingModulesTest.php +++ b/test/phpunit/NumberingModulesTest.php @@ -144,30 +144,35 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1915); // we use year 1915 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user,1); - $result3=$localobject->validate($user, $result); // create invoice by forcing ref print __METHOD__." result=".$result."\n"; $this->assertEquals('1915-0001', $result, 'Test for {yyyy}-{0000}, 1st invoice'); // counter must start to 1 + $result2=$localobject->create($user,1); + print __METHOD__." result2=".$result."\n"; + $result3=$localobject->validate($user, $result); // create invoice by forcing ref + print __METHOD__." result3=".$result."\n"; + $this->assertEquals(1, $result3, 'Test validation of invoice with forced ref is ok'); // counter must start to 1 $result=$localobject->is_erasable(); print __METHOD__." is_erasable=".$result."\n"; - $this->assertEquals(1, $result, 'Test for is_erasable, 1st invoice'); // Can be deleted + $this->assertEquals(1, $result, 'Test for is_erasable, 1st invoice'); // Can be deleted + $out=file_get_contents(DOL_DATA_ROOT.'/dolibarr.log'); + print $out; + $localobject2=new Facture($this->savdb); $localobject2->initAsSpecimen(); $localobject2->date=dol_mktime(12, 0, 0, 1, 1, 1916); // we use following year for second invoice (there is no reset into mask) $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject2, 'last'); print __METHOD__." result=".$result."\n"; - - $out=file_get_contents(DOL_DATA_ROOT.'/dolibarr.log'); - print $out; - $this->assertEquals('1915-0001', $result, "Test to get last value with param 'last'"); $result=$numbering->getNextValue($mysoc, $localobject2); - $result2=$localobject2->create($user,1); - $result3=$localobject2->validate($user, $result); // create invoice by forcing ref print __METHOD__." result=".$result."\n"; $this->assertEquals('1916-0002', $result); // counter must be now 2 (not reseted) + $result2=$localobject2->create($user,1); + print __METHOD__." result2=".$result."\n"; + $result3=$localobject2->validate($user, $result); // create invoice by forcing ref + print __METHOD__." result3=".$result."\n"; + $this->assertEquals(1, $result3, 'Test validation of invoice with forced ref is ok'); // counter must start to 1 $result=$localobject2->is_erasable(); print __METHOD__." is_erasable=".$result."\n"; $this->assertEquals(1, $result); // Can be deleted From 090a7028d77d9c702d21dbe3169b6d690bf1a9ff Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 May 2017 23:41:04 +0200 Subject: [PATCH 11/15] Fix constant usage --- htdocs/core/lib/files.lib.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 0920158b720..9d04cb82a1e 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1572,6 +1572,8 @@ function dol_convert_file($fileinput,$ext='png',$fileoutput='') */ function dol_compress_file($inputfile, $outputfile, $mode="gz") { + global $conf; + $foundhandler=0; try @@ -1627,10 +1629,10 @@ function dol_uncompress($inputfile,$outputdir) { global $conf, $langs; - if (! empty($conf->global->ODTPHP_PATHTOPCLZIP)) + if (defined('ODTPHP_PATHTOPCLZIP')) { - dol_syslog("Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".$conf->global->ODTPHP_PATHTOPCLZIP.", so we use Pclzip to unzip into ".$outputdir); - include_once $conf->global->ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php'; + dol_syslog("Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.", so we use Pclzip to unzip into ".$outputdir); + include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php'; $archive = new PclZip($inputfile); $result=$archive->extract(PCLZIP_OPT_PATH, $outputdir); //var_dump($result); From ef9cf6ef5235ef37ecfbb03dea295809bcc7d17c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 May 2017 23:54:37 +0200 Subject: [PATCH 12/15] Add test on phpunit --- test/phpunit/FunctionsLibTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 28e55fd793b..8c57e8a178a 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -81,6 +81,8 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase global $conf,$user,$langs,$db; //$db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + if (! function_exists('mb_substr')) { print "\n".__METHOD__." function mb_substr must be enabled.\n"; die(); } + print __METHOD__."\n"; } From ecce1c20374ed1ab51cea9211b8a07751351b7f7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 21 May 2017 23:58:19 +0200 Subject: [PATCH 13/15] Remove conf --- htdocs/core/lib/files.lib.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 9d04cb82a1e..c60464ed0fd 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1572,8 +1572,6 @@ function dol_convert_file($fileinput,$ext='png',$fileoutput='') */ function dol_compress_file($inputfile, $outputfile, $mode="gz") { - global $conf; - $foundhandler=0; try @@ -1627,7 +1625,7 @@ function dol_compress_file($inputfile, $outputfile, $mode="gz") */ function dol_uncompress($inputfile,$outputdir) { - global $conf, $langs; + global $langs; if (defined('ODTPHP_PATHTOPCLZIP')) { From a3eef35ce647dbc17d1e5f5e1b3ea36815a95f40 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 22 May 2017 01:19:16 +0200 Subject: [PATCH 14/15] Fix travis error --- htdocs/adherents/card.php.bak | 1787 ------------------------- htdocs/core/lib/functions.lib.php | 13 +- test/phpunit/AllTests.php | 2 +- test/phpunit/FilesLibTest.php | 14 +- test/phpunit/NumberingModulesTest.php | 10 +- 5 files changed, 24 insertions(+), 1802 deletions(-) delete mode 100644 htdocs/adherents/card.php.bak diff --git a/htdocs/adherents/card.php.bak b/htdocs/adherents/card.php.bak deleted file mode 100644 index 48461c64b02..00000000000 --- a/htdocs/adherents/card.php.bak +++ /dev/null @@ -1,1787 +0,0 @@ - - * Copyright (C) 2002-2003 Jean-Louis Bergamo - * Copyright (C) 2004-2012 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2012 Marcos García - * Copyright (C) 2012-2016 Philippe Grand - * Copyright (C) 2015-2016 Alexandre Spangaro - * - * 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 - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/adherents/card.php - * \ingroup member - * \brief Page of member - */ - -require '../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; -require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php'; -require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php'; -require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; - -$langs->load("companies"); -$langs->load("bills"); -$langs->load("members"); -$langs->load("users"); -$langs->load('other'); - -$action=GETPOST('action','alpha'); -$cancel=GETPOST('cancel','alpha'); -$backtopage=GETPOST('backtopage','alpha'); -$confirm=GETPOST('confirm','alpha'); -$rowid=GETPOST('rowid','int'); -$id=GETPOST('id')?GETPOST('id','int'):$rowid; -$typeid=GETPOST('typeid','int'); -$userid=GETPOST('userid','int'); -$socid=GETPOST('socid','int'); - -if (! empty($conf->mailmanspip->enabled)) -{ - include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php'; - - $langs->load('mailmanspip'); - - $mailmanspip = new MailmanSpip($db); -} - -$object = new Adherent($db); -$extrafields = new ExtraFields($db); - -// fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); - -// Get object canvas (By default, this is not defined, so standard usage of dolibarr) -$object->getCanvas($id); -$canvas = $object->canvas?$object->canvas:GETPOST("canvas"); -$objcanvas=null; -if (! empty($canvas)) -{ - require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; - $objcanvas = new Canvas($db, $action); - $objcanvas->getCanvas('adherent', 'membercard', $canvas); -} - -// Security check -$result=restrictedArea($user, 'adherent', $id, '', '', 'fk_soc', 'rowid', $objcanvas); - -if ($id > 0) -{ - // Load member - $result = $object->fetch($id); - - // Define variables to know what current user can do on users - $canadduser=($user->admin || $user->rights->user->user->creer); - // Define variables to know what current user can do on properties of user linked to edited member - if ($object->user_id) - { - // $ User is the user who edits, $ object->user_id is the id of the related user in the edited member - $caneditfielduser=((($user->id == $object->user_id) && $user->rights->user->self->creer) - || (($user->id != $object->user_id) && $user->rights->user->user->creer)); - $caneditpassworduser=((($user->id == $object->user_id) && $user->rights->user->self->password) - || (($user->id != $object->user_id) && $user->rights->user->user->password)); - } -} - -// Define variables to determine what the current user can do on the members -$canaddmember=$user->rights->adherent->creer; -// Define variables to determine what the current user can do on the properties of a member -if ($id) -{ - $caneditfieldmember=$user->rights->adherent->creer; -} - -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -$hookmanager->initHooks(array('membercard','globalcard')); - - - -/* - * Actions - */ - -if ($cancel) $action=''; - -$parameters=array('id'=>$id, 'rowid'=>$id, 'objcanvas'=>$objcanvas); -$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - -if (empty($reshook)) -{ - if ($action == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer)) - { - $error=0; - if (empty($user->rights->user->user->creer)) // If can edit only itself user, we can link to itself only - { - if ($userid != $user->id && $userid != $object->user_id) - { - $error++; - setEventMessages($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), null, 'errors'); - } - } - - if (! $error) - { - if ($userid != $object->user_id) // If link differs from currently in database - { - $result=$object->setUserId($userid); - if ($result < 0) dol_print_error($object->db,$object->error); - $action=''; - } - } - } - - if ($action == 'setsocid') - { - $error=0; - if (! $error) - { - if ($socid != $object->fk_soc) // If link differs from currently in database - { - $sql ="SELECT rowid FROM ".MAIN_DB_PREFIX."adherent"; - $sql.=" WHERE fk_soc = '".$socid."'"; - $sql.=" AND entity = ".$conf->entity; - $resql = $db->query($sql); - if ($resql) - { - $obj = $db->fetch_object($resql); - if ($obj && $obj->rowid > 0) - { - $othermember=new Adherent($db); - $othermember->fetch($obj->rowid); - $thirdparty=new Societe($db); - $thirdparty->fetch($socid); - $error++; - setEventMessages($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty",$othermember->getFullName($langs),$othermember->login,$thirdparty->name), null, 'errors'); - } - } - - if (! $error) - { - $result=$object->setThirdPartyId($socid); - if ($result < 0) dol_print_error($object->db,$object->error); - $action=''; - } - } - } - } - - // Create user from a member - if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer) - { - if ($result > 0) - { - // Creation user - $nuser = new User($db); - $result=$nuser->create_from_member($object,GETPOST('login')); - - if ($result < 0) - { - $langs->load("errors"); - setEventMessages($langs->trans($nuser->error), null, 'errors'); - } - } - else - { - setEventMessages($object->errors, $object->error, 'errors'); - } - } - - // Create third party from a member - if ($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer) - { - if ($result > 0) - { - // User creation - $company = new Societe($db); - $result=$company->create_from_member($object,GETPOST('companyname')); - - if ($result < 0) - { - $langs->load("errors"); - setEventMessages($langs->trans($company->error), null, 'errors'); - setEventMessages($company->error, $company->errors, 'errors'); - } - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - - if ($action == 'confirm_sendinfo' && $confirm == 'yes') - { - if ($object->email) - { - $from=$conf->email_from; - if (! empty($conf->global->ADHERENT_MAIL_FROM)) $from=$conf->global->ADHERENT_MAIL_FROM; - - $result=$object->send_an_email($langs->transnoentitiesnoconv("ThisIsContentOfYourCard")."\n\n%INFOS%\n\n",$langs->transnoentitiesnoconv("CardContent")); - - $langs->load("mails"); - setEventMessages($langs->trans("MailSuccessfulySent", $from, $object->email), null, 'mesgs'); - } - } - - if ($action == 'update' && ! $cancel && $user->rights->adherent->creer) - { - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - - $birthdate=''; - if (isset($_POST["birthday"]) && $_POST["birthday"] - && isset($_POST["birthmonth"]) && $_POST["birthmonth"] - && isset($_POST["birthyear"]) && $_POST["birthyear"]) - { - $birthdate=dol_mktime(12, 0, 0, $_POST["birthmonth"], $_POST["birthday"], $_POST["birthyear"]); - } - $lastname=$_POST["lastname"]; - $firstname=$_POST["firstname"]; - $societe=$_POST["societe"]; - $morphy=$_POST["morphy"]; - $login=$_POST["login"]; - if ($morphy != 'mor' && empty($lastname)) { - $error++; - $langs->load("errors"); - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname")), null, 'errors'); - } - if ($morphy != 'mor' && (!isset($firstname) || $firstname=='')) { - $error++; - $langs->load("errors"); - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Firstname")), null, 'errors'); - } - if ($morphy == 'mor' && empty($societe)) { - $error++; - $langs->load("errors"); - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Company")), null, 'errors'); - } - // Test si le login existe deja - if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) - { - if (empty($login)) { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("Login")), null, 'errors'); - } - } - // Create new object - if ($result > 0 && ! $error) - { - $object->oldcopy = clone $object; - - // Change values - $object->civility_id = trim($_POST["civility_id"]); - $object->firstname = trim($_POST["firstname"]); - $object->lastname = trim($_POST["lastname"]); - $object->login = trim($_POST["login"]); - $object->pass = trim($_POST["pass"]); - - $object->societe = trim($_POST["societe"]); - $object->company = trim($_POST["societe"]); - - $object->address = trim($_POST["address"]); - $object->zip = trim($_POST["zipcode"]); - $object->town = trim($_POST["town"]); - $object->state_id = $_POST["state_id"]; - $object->country_id = $_POST["country_id"]; - - $object->phone = trim($_POST["phone"]); - $object->phone_perso = trim($_POST["phone_perso"]); - $object->phone_mobile= trim($_POST["phone_mobile"]); - $object->email = trim($_POST["email"]); - $object->skype = trim($_POST["skype"]); - $object->birth = $birthdate; - - $object->typeid = $_POST["typeid"]; - //$object->note = trim($_POST["comment"]); - $object->morphy = $_POST["morphy"]; - - if (GETPOST('deletephoto')) $object->photo=''; - elseif (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']); - - // Get status and public property - $object->statut = $_POST["statut"]; - $object->public = $_POST["public"]; - - // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels,$object); - if ($ret < 0) $error++; - - // Check if we need to also synchronize user information - $nosyncuser=0; - if ($object->user_id) // If linked to a user - { - if ($user->id != $object->user_id && empty($user->rights->user->user->creer)) $nosyncuser=1; // Disable synchronizing - } - - // Check if we need to also synchronize password information - $nosyncuserpass=0; - if ($object->user_id) // If linked to a user - { - if ($user->id != $object->user_id && empty($user->rights->user->user->password)) $nosyncuserpass=1; // Disable synchronizing - } - - $result=$object->update($user,0,$nosyncuser,$nosyncuserpass); - - if ($result >= 0 && ! count($object->errors)) - { - $categories = GETPOST('memcats', 'array'); - $object->setCategories($categories); - - // Logo/Photo save - $dir= $conf->adherent->dir_output . '/' . get_exdir(0,0,0,1,$object,'member').'/photos'; - $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']); - if ($file_OK) - { - if (GETPOST('deletephoto')) - { - require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - $fileimg=$conf->adherent->dir_output.'/'.get_exdir(0,0,0,1,$object,'member').'/photos/'.$object->photo; - $dirthumbs=$conf->adherent->dir_output.'/'.get_exdir(0,0,0,1,$object,'member').'/photos/thumbs'; - dol_delete_file($fileimg); - dol_delete_dir_recursive($dirthumbs); - } - - if (image_format_supported($_FILES['photo']['name']) > 0) - { - dol_mkdir($dir); - - if (@is_dir($dir)) - { - $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']); - if (! dol_move_uploaded_file($_FILES['photo']['tmp_name'],$newfile,1,0,$_FILES['photo']['error']) > 0) - { - setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors'); - } - else - { - // Create thumbs - $object->addThumbs($newfile); - } - } - } - else - { - setEventMessages("ErrorBadImageFormat", null, 'errors'); - } - } - else - { - switch($_FILES['photo']['error']) - { - case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini - case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form - $errors[] = "ErrorFileSizeTooLarge"; - break; - case 3: //uploaded file was only partially uploaded - $errors[] = "ErrorFilePartiallyUploaded"; - break; - } - } - - $rowid=$object->id; - $id=$object->id; - $action=''; - - if (! empty($backtopage)) - { - header("Location: ".$backtopage); - exit; - } - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - $action=''; - } - } - else - { - $action='edit'; - } - } - - if ($action == 'add' && $user->rights->adherent->creer) - { - if ($canvas) $object->canvas=$canvas; - $birthdate=''; - if (isset($_POST["birthday"]) && $_POST["birthday"] - && isset($_POST["birthmonth"]) && $_POST["birthmonth"] - && isset($_POST["birthyear"]) && $_POST["birthyear"]) - { - $birthdate=dol_mktime(12, 0, 0, $_POST["birthmonth"], $_POST["birthday"], $_POST["birthyear"]); - } - $datesubscription=''; - if (isset($_POST["reday"]) && isset($_POST["remonth"]) && isset($_POST["reyear"])) - { - $datesubscription=dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); - } - - $typeid=$_POST["typeid"]; - $civility_id=$_POST["civility_id"]; - $lastname=$_POST["lastname"]; - $firstname=$_POST["firstname"]; - $societe=$_POST["societe"]; - $address=$_POST["address"]; - $zip=$_POST["zipcode"]; - $town=$_POST["town"]; - $state_id=$_POST["state_id"]; - $country_id=$_POST["country_id"]; - - $phone=$_POST["phone"]; - $phone_perso=$_POST["phone_perso"]; - $phone_mobile=$_POST["phone_mobile"]; - $skype=$_POST["member_skype"]; - $email=$_POST["member_email"]; - $login=$_POST["member_login"]; - $pass=$_POST["password"]; - $photo=$_POST["photo"]; - //$comment=$_POST["comment"]; - $morphy=$_POST["morphy"]; - $subscription=$_POST["subscription"]; - $public=$_POST["public"]; - - $userid=$_POST["userid"]; - $socid=$_POST["socid"]; - - $object->civility_id = $civility_id; - $object->firstname = $firstname; - $object->lastname = $lastname; - $object->societe = $societe; - $object->address = $address; - $object->zip = $zip; - $object->town = $town; - $object->state_id = $state_id; - $object->country_id = $country_id; - $object->phone = $phone; - $object->phone_perso = $phone_perso; - $object->phone_mobile= $phone_mobile; - $object->skype = $skype; - $object->email = $email; - $object->login = $login; - $object->pass = $pass; - $object->birth = $birthdate; - $object->photo = $photo; - $object->typeid = $typeid; - //$object->note = $comment; - $object->morphy = $morphy; - $object->user_id = $userid; - $object->fk_soc = $socid; - $object->public = $public; - - // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels,$object); - if ($ret < 0) $error++; - - // Check parameters - if (empty($morphy) || $morphy == "-1") { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Nature")), null, 'errors'); - } - // Tests if the login already exists - if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) - { - if (empty($login)) { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("Login")), null, 'errors'); - } - else { - $sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login='".$db->escape($login)."'"; - $result = $db->query($sql); - if ($result) { - $num = $db->num_rows($result); - } - if ($num) { - $error++; - $langs->load("errors"); - setEventMessages($langs->trans("ErrorLoginAlreadyExists",$login), null, 'errors'); - } - } - if (empty($pass)) { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Password")), null, 'errors'); - } - } - if ($morphy == 'mor' && empty($societe)) { - $error++; - $langs->load("errors"); - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Company")), null, 'errors'); - } - if ($morphy != 'mor' && empty($lastname)) { - $error++; - $langs->load("errors"); - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname")), null, 'errors'); - } - if ($morphy != 'mor' && (!isset($firstname) || $firstname=='')) { - $error++; - $langs->load("errors"); - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Firstname")), null, 'errors'); - } - if (! ($typeid > 0)) { // Keep () before ! - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); - } - if ($conf->global->ADHERENT_MAIL_REQUIRED && ! isValidEMail($email)) { - $error++; - $langs->load("errors"); - setEventMessages($langs->trans("ErrorBadEMail",$email), null, 'errors'); - } - $public=0; - if (isset($public)) $public=1; - - if (! $error) - { - $db->begin(); - - // Email about right and login does not exist - $result=$object->create($user); - if ($result > 0) - { - // Foundation categories - $memcats = GETPOST('memcats', 'array'); - $object->setCategories($memcats); - - $db->commit(); - $rowid=$object->id; - $id=$object->id; - $action=''; - } - else - { - $db->rollback(); - - if ($object->error) { - setEventMessages($object->error, $object->errors, 'errors'); - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - - $action = 'create'; - } - } - else { - $action = 'create'; - } - } - - if ($user->rights->adherent->supprimer && $action == 'confirm_delete' && $confirm == 'yes') - { - $result=$object->delete($id); - if ($result > 0) - { - if (! empty($backtopage)) - { - header("Location: ".$backtopage); - exit; - } - else - { - header("Location: list.php"); - exit; - } - } - else - { - $errmesg=$object->error; - } - } - - if ($user->rights->adherent->creer && $action == 'confirm_valid' && $confirm == 'yes') - { - $error=0; - - $db->begin(); - - $adht = new AdherentType($db); - $adht->fetch($object->typeid); - - $result=$object->validate($user); - - if ($result >= 0 && ! count($object->errors)) - { - // Send confirmation email (according to parameters of member type. Otherwise generic) - if ($object->email && GETPOST("send_mail")) - { - $result=$object->send_an_email($adht->getMailOnValid(),$conf->global->ADHERENT_MAIL_VALID_SUBJECT,array(),array(),array(),"","",0,2); - if ($result < 0) - { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - } - } - else - { - $error++; - if ($object->error) { - setEventMessages($object->error, $object->errors, 'errors'); - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - - if (! $error) - { - $db->commit(); - } - else - { - $db->rollback(); - } - $action=''; - } - - if ($user->rights->adherent->supprimer && $action == 'confirm_resign') - { - $error = 0; - - if ($confirm == 'yes') - { - $adht = new AdherentType($db); - $adht->fetch($object->typeid); - - $result=$object->resiliate($user); - - if ($result >= 0 && ! count($object->errors)) - { - if ($object->email && GETPOST("send_mail")) - { - $result=$object->send_an_email($adht->getMailOnResiliate(),$conf->global->ADHERENT_MAIL_RESIL_SUBJECT,array(),array(),array(),"","",0,-1); - } - if ($result < 0) - { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - } - } - else - { - $error++; - - if ($object->error) { - setEventMessages($object->error, $object->errors, 'errors'); - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - $action=''; - } - } - if (! empty($backtopage) && ! $error) - { - header("Location: ".$backtopage); - exit; - } - } - - // SPIP Management - if ($user->rights->adherent->supprimer && $action == 'confirm_del_spip' && $confirm == 'yes') - { - if (! count($object->errors)) - { - if (!$mailmanspip->del_to_spip($object)) - { - setEventMessages($langs->trans('DeleteIntoSpipError').': '.$mailmanspip->error, null, 'errors'); - } - } - } - - if ($user->rights->adherent->creer && $action == 'confirm_add_spip' && $confirm == 'yes') - { - if (! count($object->errors)) - { - if (!$mailmanspip->add_to_spip($object)) - { - setEventMessages($langs->trans('AddIntoSpipError').': '.$mailmanspip->error, null, 'errors'); - } - } - } - - // Actions to build doc - $upload_dir = $conf->adherent->dir_output; - $permissioncreate=$user->rights->adherent->creer; - include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; -} - - -/* - * View - */ - -$form = new Form($db); -$formfile = new FormFile($db); -$formcompany = new FormCompany($db); - -$title=$langs->trans("Member") . " - " . $langs->trans("Card"); -$help_url='EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros'; -llxHeader('',$title,$help_url); - -$countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; - -if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) -{ - // ----------------------------------------- - // When used with CANVAS - // ----------------------------------------- - if (empty($object->error) && $id) - { - $object = new Adherent($db); - $result=$object->fetch($id); - if ($result <= 0) dol_print_error('',$object->error); - } - $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates - $objcanvas->display_canvas($action); // Show template -} -else -{ - // ----------------------------------------- - // When used in standard mode - // ----------------------------------------- - - if ($action == 'create') - { - /* ************************************************************************** */ - /* */ - /* Creation mode */ - /* */ - /* ************************************************************************** */ - $object->canvas=$canvas; - $object->state_id = GETPOST('state_id', 'int'); - - // We set country_id, country_code and country for the selected country - $object->country_id=GETPOST('country_id','int')?GETPOST('country_id','int'):$mysoc->country_id; - if ($object->country_id) - { - $tmparray=getCountry($object->country_id,'all'); - $object->country_code=$tmparray['code']; - $object->country=$tmparray['label']; - } - - $adht = new AdherentType($db); - - print load_fiche_titre($langs->trans("NewMember")); - - if ($conf->use_javascript_ajax) - { - print "\n".''."\n"; - } - - print '
'; - print ''; - print ''; - - dol_fiche_head(''); - - print ''; - print ''; - - // Login - if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) - { - print ''; - } - - // Type - print '\n"; - - // Morphy - $morphys["phy"] = $langs->trans("Physical"); - $morphys["mor"] = $langs->trans("Moral"); - print '\n"; - - // Company - print ''; - - // Civility - print ''; - print ''; - - // Lastname - print ''; - print ''; - - // Firstname - print ''; - print ''; - - // EMail - print ''; - - // Password - if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) - { - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; - $generated_password=getRandomPassword(false); - print ''; - } - - // Address - print ''; - - // Zip / Town - print ''; - - // Country - $object->country_id=$object->country_id?$object->country_id:$mysoc->country_id; - print ''; - - // State - if (empty($conf->global->MEMBER_DISABLE_STATE)) - { - print ''; - } - - // Pro phone - print ''; - - // Personal phone - print ''; - - // Mobile phone - print ''; - - // Skype - if (! empty($conf->skype->enabled)) - { - print ''; - } - - // Birthday - print "\n"; - - // Public profil - print "\n"; - - // Categories - if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) - { - print '"; - } - - // Other attributes - $parameters=array(); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook) && ! empty($extrafields->attribute_label)) - { - print $object->showOptionals($extrafields,'edit'); - } - - /* - // Third party Dolibarr - if (! empty($conf->societe->enabled)) - { - print ''; - } - - // Login Dolibarr - print ''; - */ - print ''; - print "
'.$langs->trans("Login").' / '.$langs->trans("Id").'login).'">
'.$langs->trans("MemberType").''; - $listetype=$adht->liste_array(); - if (count($listetype)) - { - print $form->selectarray("typeid", $listetype, GETPOST('typeid','int')?GETPOST('typeid','int'):$typeid, count($listetype)>1?1:0); - } else { - print ''.$langs->trans("NoTypeDefinedGoToSetup").''; - } - print "
'.$langs->trans("Nature")."\n"; - print $form->selectarray("morphy", $morphys, GETPOST('morphy','alpha')?GETPOST('morphy','alpha'):$object->morphy, 1); - print "
'.$langs->trans("Company").'
'.$langs->trans("UserTitle").''; - print $formcompany->select_civility(GETPOST('civility_id','int')?GETPOST('civility_id','int'):$object->civility_id,'civility_id').'
'.$langs->trans("Lastname").'
'.$langs->trans("Firstname").'
'.($conf->global->ADHERENT_MAIL_REQUIRED?'':'').$langs->trans("EMail").($conf->global->ADHERENT_MAIL_REQUIRED?'':'').'
'.$langs->trans("Password").''; - print ''; - print '
'.$langs->trans("Address").''; - print ''; - print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").''; - print $formcompany->select_ziptown((GETPOST('zipcode','alpha')?GETPOST('zipcode','alpha'):$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6); - print ' '; - print $formcompany->select_ziptown((GETPOST('town','alpha')?GETPOST('town','alpha'):$object->town),'town',array('zipcode','selectcountry_id','state_id')); - print '
'.$langs->trans('Country').''; - print $form->select_country(GETPOST('country_id','alpha')?GETPOST('country_id','alpha'):$object->country_id,'country_id'); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); - print '
'.$langs->trans('State').''; - if ($object->country_id) - { - print $formcompany->select_state(GETPOST('state_id','int')?GETPOST('state_id','int'):$object->state_id,$object->country_code); - } - else - { - print $countrynotdefined; - } - print '
'.$langs->trans("PhonePro").'
'.$langs->trans("PhonePerso").'
'.$langs->trans("PhoneMobile").'
'.$langs->trans("Skype").'
".$langs->trans("Birthday")."\n"; - $form->select_date(($object->birth ? $object->birth : -1),'birth','','',1,'formsoc'); - print "
".$langs->trans("Public")."\n"; - print $form->selectyesno("public",$object->public,1); - print "
' . fieldLabel('Categories', 'memcars') . ''; - $cate_arbo = $form->select_all_categories(Categorie::TYPE_MEMBER, null, 'parent', null, null, 1); - print $form->multiselectarray('memcats', $cate_arbo, GETPOST('memcats', 'array'), null, null, null, null, '100%'); - print "
'.$langs->trans("LinkedToDolibarrThirdParty").''; - print $form->select_company($object->fk_soc,'socid','',1); - print '
'.$langs->trans("LinkedToDolibarrUser").''; - print $form->select_dolusers($object->user_id, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); - print '
\n"; - - dol_fiche_end(); - - print '
'; - print ''; - print '     '; - print ''; - print '
'; - - print "
\n"; - } - - if ($action == 'edit') - { - /******************************************** - * - * Edition mode - * - ********************************************/ - - $res=$object->fetch($id); - if ($res < 0) { - dol_print_error($db,$object->error); exit; - } - $res=$object->fetch_optionals($object->id,$extralabels); - if ($res < 0) { - dol_print_error($db); exit; - } - - $adht = new AdherentType($db); - $adht->fetch($object->typeid); - - // We set country_id, and country_code, country of the chosen country - $country=GETPOST('country','int'); - if (!empty($country) || $object->country_id) - { - $sql = "SELECT rowid, code, label from ".MAIN_DB_PREFIX."c_country where rowid = ".(!empty($country)?$country:$object->country_id); - $resql=$db->query($sql); - if ($resql) - { - $obj = $db->fetch_object($resql); - } - else - { - dol_print_error($db); - } - $object->country_id=$obj->rowid; - $object->country_code=$obj->code; - $object->country=$langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->label; - } - - $head = member_prepare_head($object); - - - if ($conf->use_javascript_ajax) - { - print "\n".''."\n"; - } - - print '
'; - print ''; - print ''; - print ''; - print ''; - if ($backtopage) print ''; - - dol_fiche_head($head, 'general', $langs->trans("Member"), 0, 'user'); - - print ''; - - // Ref - print ''; - - // Login - if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) - { - print ''; - } - - // Morphy - $morphys["phy"] = $langs->trans("Physical"); - $morphys["mor"] = $langs->trans("Morale"); - print '"; - - // Type - print '"; - - // Company - print ''; - - // Civility - print ''; - print ''; - - // Lastname - print ''; - print ''; - - // Firstname - print ''; - print ''; - - // Photo - print ''; - print ''; - - // EMail - print ''; - - // Password - if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) - { - print ''; - } - - // Address - print ''; - - // Zip / Town - print ''; - - // Country - //$object->country_id=$object->country_id?$object->country_id:$mysoc->country_id; // In edit mode we don't force to company country if not defined - print ''; - - // State - if (empty($conf->global->MEMBER_DISABLE_STATE)) - { - print ''; - } - - // Pro phone - print ''; - - // Personal phone - print ''; - - // Mobile phone - print ''; - - // Skype - if (! empty($conf->skype->enabled)) - { - print ''; - } - - // Birthday - print "\n"; - - // Public profil - print "\n"; - - // Categories - if (! empty( $conf->categorie->enabled ) && !empty( $user->rights->categorie->lire )) - { - print ''; - print '"; - } - - // Other attributes - $parameters=array("colspan"=>2); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook) && ! empty($extrafields->attribute_label)) - { - print $object->showOptionals($extrafields,'edit',$parameters); - } - - // Third party Dolibarr - if (! empty($conf->societe->enabled)) - { - print ''; - } - - // Login Dolibarr - print ''; - - print '
'.$langs->trans("Ref").''.$object->id.'
'.$langs->trans("Login").' / '.$langs->trans("Id").'login).'">
'.$langs->trans("Nature").''; - print $form->selectarray("morphy", $morphys, isset($_POST["morphy"])?$_POST["morphy"]:$object->morphy); - print "
'.$langs->trans("Type").''; - if ($user->rights->adherent->creer) - { - print $form->selectarray("typeid", $adht->liste_array(), (isset($_POST["typeid"])?$_POST["typeid"]:$object->typeid)); - } - else - { - print $adht->getNomUrl(1); - print ''; - } - print "
'.$langs->trans("Company").'societe).'">
'.$langs->trans("UserTitle").''; - print $formcompany->select_civility(isset($_POST["civility_id"])?$_POST["civility_id"]:$object->civility_id)."\n"; - print '
'.$langs->trans("Lastname").'lastname).'">
'.$langs->trans("Firstname").'firstname).'">
'.$langs->trans("Photo").''; - print $form->showphoto('memberphoto',$object)."\n"; - if ($caneditfieldmember) - { - if ($object->photo) print "
\n"; - print ''; - if ($object->photo) print ''; - print ''; - print ''; - print '
'.$langs->trans("Delete").'

'.$langs->trans("PhotoFile").'
'; - } - print '
'.($conf->global->ADHERENT_MAIL_REQUIRED?'':'').$langs->trans("EMail").($conf->global->ADHERENT_MAIL_REQUIRED?'':'').'email).'">
'.$langs->trans("Password").'pass).'">
'.$langs->trans("Address").''; - print ''; - print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").''; - print $formcompany->select_ziptown((isset($_POST["zipcode"])?GETPOST("zipcode",'',2):$object->zip),'zipcode',array('town','selectcountry_id','state_id'),6); - print ' '; - print $formcompany->select_ziptown((isset($_POST["town"])?GETPOST("town",'',2):$object->town),'town',array('zipcode','selectcountry_id','state_id')); - print '
'.$langs->trans('Country').''; - print $form->select_country(isset($_POST["country_id"])?$_POST["country_id"]:$object->country_id,'country_id'); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); - print '
'.$langs->trans('State').''; - print $formcompany->select_state($object->state_id,isset($_POST["country_id"])?GETPOST("country_id"):$object->country_id); - print '
'.$langs->trans("PhonePro").'phone).'">
'.$langs->trans("PhonePerso").'phone_perso).'">
'.$langs->trans("PhoneMobile").'phone_mobile).'">
'.$langs->trans("Skype").'skype).'">
".$langs->trans("Birthday")."\n"; - $form->select_date(($object->birth ? $object->birth : -1),'birth','','',1,'formsoc'); - print "
".$langs->trans("Public")."\n"; - print $form->selectyesno("public",(isset($_POST["public"])?GETPOST("public",'',2):$object->public),1); - print "
' . fieldLabel('Categories', 'memcats') . ''; - $cate_arbo = $form->select_all_categories(Categorie::TYPE_MEMBER, null, null, null, null, 1); - $c = new Categorie($db); - $cats = $c->containing($object->id, Categorie::TYPE_MEMBER); - foreach ($cats as $cat) { - $arrayselected[] = $cat->id; - } - print $form->multiselectarray('memcats', $cate_arbo, $arrayselected, '', 0, '', 0, '100%'); - print "
'.$langs->trans("LinkedToDolibarrThirdParty").''; - if ($object->fk_soc) - { - $company=new Societe($db); - $result=$company->fetch($object->fk_soc); - print $company->getNomUrl(1); - } - else - { - print $langs->trans("NoThirdPartyAssociatedToMember"); - } - print '
'.$langs->trans("LinkedToDolibarrUser").''; - if ($object->user_id) - { - $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id,$object->user_id,'none'); - } - else print $langs->trans("NoDolibarrAccess"); - print '
'; - - dol_fiche_end(); - - print '
'; - print ''; - print '     '; - print ''; - print '
'; - - print '
'; - - } - - if ($id > 0 && $action != 'edit') - { - /* ************************************************************************** */ - /* */ - /* View mode */ - /* */ - /* ************************************************************************** */ - - $res=$object->fetch($id); - if ($res < 0) { - dol_print_error($db,$object->error); exit; - } - $res=$object->fetch_optionals($object->id,$extralabels); - if ($res < 0) { - dol_print_error($db); exit; - } - - $adht = new AdherentType($db); - $res=$adht->fetch($object->typeid); - if ($res < 0) { - dol_print_error($db); exit; - } - - - /* - * Show tabs - */ - $head = member_prepare_head($object); - - dol_fiche_head($head, 'general', $langs->trans("Member"), 0, 'user'); - - // Confirm create user - if ($action == 'create_user') - { - $login=$object->login; - if (empty($login)) - { - // Full firstname and name separated with a dot : firstname.name - include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - $login=dol_buildlogin($object->lastname,$object->firstname); - } - if (empty($login)) $login=strtolower(substr($object->firstname, 0, 4)) . strtolower(substr($object->lastname, 0, 4)); - - // Create a form array - $formquestion=array( - array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login) - ); - $text=$langs->trans("ConfirmCreateLogin").'
'; - if (! empty($conf->societe->enabled)) - { - if ($object->fk_soc > 0) $text.=$langs->trans("UserWillBeExternalUser"); - else $text.=$langs->trans("UserWillBeInternalUser"); - } - print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id,$langs->trans("CreateDolibarrLogin"),$text,"confirm_create_user",$formquestion,'yes'); - } - - // Confirm create third party - if ($action == 'create_thirdparty') - { - $name = $object->getFullName($langs); - if (! empty($name)) - { - if ($object->societe) $name.=' ('.$object->societe.')'; - } - else - { - $name=$object->societe; - } - - // Create a form array - $formquestion=array( array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $name)); - - print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id,$langs->trans("CreateDolibarrThirdParty"),$langs->trans("ConfirmCreateThirdParty"),"confirm_create_thirdparty",$formquestion,1); - } - - // Confirm validate member - if ($action == 'valid') - { - $langs->load("mails"); - - $adht = new AdherentType($db); - $adht->fetch($object->typeid); - - $subjecttosend=$object->makeSubstitution($conf->global->ADHERENT_MAIL_VALID_SUBJECT); - $texttosend=$object->makeSubstitution($adht->getMailOnValid()); - - $tmp=$langs->trans("SendAnEMailToMember"); - $tmp.='
('.$langs->trans("MailFrom").': '.$conf->global->ADHERENT_MAIL_FROM.', '; - $tmp.=$langs->trans("MailRecipient").': '.$object->email.')'; - $helpcontent=''; - $helpcontent.=''.$langs->trans("MailFrom").': '.$conf->global->ADHERENT_MAIL_FROM.'
'."\n"; - $helpcontent.=''.$langs->trans("MailRecipient").': '.$object->email.'
'."\n"; - $helpcontent.=''.$langs->trans("Subject").':
'."\n"; - $helpcontent.=$subjecttosend."\n"; - $helpcontent.="
"; - $helpcontent.=''.$langs->trans("Content").':
'; - $helpcontent.=dol_htmlentitiesbr($texttosend)."\n"; - $label=$form->textwithpicto($tmp,$helpcontent,1,'help'); - - // Create form popup - $formquestion=array(); - if ($object->email) $formquestion[]=array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => ($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL?true:false)); - if (! empty($conf->mailman->enabled) && ! empty($conf->global->ADHERENT_USE_MAILMAN)) { - $formquestion[]=array('type'=>'other','label'=>$langs->transnoentitiesnoconv("SynchroMailManEnabled"),'value'=>''); - } - if (! empty($conf->mailman->enabled) && ! empty($conf->global->ADHERENT_USE_SPIP)) { - $formquestion[]=array('type'=>'other','label'=>$langs->transnoentitiesnoconv("SynchroSpipEnabled"),'value'=>''); - } - print $form->formconfirm("card.php?rowid=".$id,$langs->trans("ValidateMember"),$langs->trans("ConfirmValidateMember"),"confirm_valid",$formquestion,1,1); - } - - // Confirm send card by mail - if ($action == 'sendinfo') - { - print $form->formconfirm("card.php?rowid=".$id,$langs->trans("SendCardByMail"),$langs->trans("ConfirmSendCardByMail",$object->email),"confirm_sendinfo",'',0,1); - } - - // Confirm terminate - if ($action == 'resign') - { - $langs->load("mails"); - - $adht = new AdherentType($db); - $adht->fetch($object->typeid); - - $subjecttosend=$object->makeSubstitution($conf->global->ADHERENT_MAIL_RESIL_SUBJECT); - $texttosend=$object->makeSubstitution($adht->getMailOnResiliate()); - - $tmp=$langs->trans("SendAnEMailToMember"); - $tmp.='
('.$langs->trans("MailFrom").': '.$conf->global->ADHERENT_MAIL_FROM.', '; - $tmp.=$langs->trans("MailRecipient").': '.$object->email.')'; - $helpcontent=''; - $helpcontent.=''.$langs->trans("MailFrom").': '.$conf->global->ADHERENT_MAIL_FROM.'
'."\n"; - $helpcontent.=''.$langs->trans("MailRecipient").': '.$object->email.'
'."\n"; - $helpcontent.=''.$langs->trans("Subject").':
'."\n"; - $helpcontent.=$subjecttosend."\n"; - $helpcontent.="
"; - $helpcontent.=''.$langs->trans("Content").':
'; - $helpcontent.=dol_htmlentitiesbr($texttosend)."\n"; - $label=$form->textwithpicto($tmp,$helpcontent,1,'help'); - - // Create an array - $formquestion=array(); - if ($object->email) $formquestion[]=array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (! empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL)?'true':'false')); - if ($backtopage) $formquestion[]=array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"])); - print $form->formconfirm("card.php?rowid=".$id,$langs->trans("ResiliateMember"),$langs->trans("ConfirmResiliateMember"),"confirm_resign",$formquestion,'no',1); - } - - // Confirm remove member - if ($action == 'delete') - { - $formquestion=array(); - if ($backtopage) $formquestion[]=array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"])); - print $form->formconfirm("card.php?rowid=".$id,$langs->trans("DeleteMember"),$langs->trans("ConfirmDeleteMember"),"confirm_delete",$formquestion,0,1); - } - - // Confirm add in spip - if ($action == 'add_spip') - { - print $form->formconfirm("card.php?rowid=".$id, $langs->trans('AddIntoSpip'), $langs->trans('AddIntoSpipConfirmation'), 'confirm_add_spip'); - } - // Confirm removed from spip - if ($action == 'del_spip') - { - print $form->formconfirm("card.php?rowid=$id", $langs->trans('DeleteIntoSpip'), $langs->trans('DeleteIntoSpipConfirmation'), 'confirm_del_spip'); - } - - $rowspan=17; - if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $rowspan++; - if (! empty($conf->societe->enabled)) $rowspan++; - - $linkback = ''.$langs->trans("BackToList").''; - - dol_banner_tab($object, 'rowid', $linkback); - - print '
'; - print '
'; - - print '
'; - print ''; - - // Login - if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) - { - print ''; - } - - // Type - print '\n"; - - // Morphy - print ''; - print ''; - - // Company - print ''; - - // Civility - print ''; - print ''; - - // Password - if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) - { - print ''; - } - - print '
'.$langs->trans("Login").' / '.$langs->trans("Id").''.$object->login.' 
'.$langs->trans("Type").''.$adht->getNomUrl(1)."
'.$langs->trans("Nature").''.$object->getmorphylib().'
'.$langs->trans("Company").''.$object->societe.'
'.$langs->trans("UserTitle").''.$object->getCivilityLabel().' 
'.$langs->trans("Password").''.preg_replace('/./i','*',$object->pass); - if ($object->pass) print preg_replace('/./i','*',$object->pass); - else - { - if ($user->admin) print $langs->trans("Crypted").': '.$object->pass_indatabase_crypted; - else print $langs->trans("Hidden"); - } - if ((! empty($object->pass) || ! empty($object->pass_crypted)) && empty($object->user_id)) - { - $langs->load("errors"); - $htmltext=$langs->trans("WarningPasswordSetWithNoAccount"); - print ' '.$form->textwithpicto('', $htmltext,1,'warning'); - } - print '
'; - - print '
'; - print '
'; - - print '
'; - print ''; - - // Birthday - print ''; - - // Public - print ''; - - // Categories - if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) - { - print ''; - print ''; - } - - // Other attributes - $parameters=array('colspan'=>2); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook) && ! empty($extrafields->attribute_label)) - { - print $object->showOptionals($extrafields, 'view', $parameters); - } - - // Date end subscription - print ''; - - // Third party Dolibarr - if (! empty($conf->societe->enabled)) - { - print ''; - } - - // Login Dolibarr - print ''; - - print "
'.$langs->trans("Birthday").''.dol_print_date($object->birth,'day').'
'.$langs->trans("Public").''.yn($object->public).'
' . $langs->trans("Categories") . ''; - print $form->showCategories($object->id, 'member', 1); - print '
'.$langs->trans("SubscriptionEndDate").''; - if ($object->datefin) - { - print dol_print_date($object->datefin,'day'); - if ($object->hasDelay()) { - print " ".img_warning($langs->trans("Late")); - } - } - else - { - if (! $adht->subscription) - { - print $langs->trans("SubscriptionNotRecorded"); - if ($object->statut > 0) print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft and not terminated - } - else - { - print $langs->trans("SubscriptionNotReceived"); - if ($object->statut > 0) print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft and not terminated - } - } - print '
'; - print ''; - if ($action != 'editthirdparty' && $user->rights->adherent->creer) print ''; - print '
'; - print $langs->trans("LinkedToDolibarrThirdParty"); - print 'id.'">'.img_edit($langs->trans('SetLinkToThirdParty'),1).'
'; - print '
'; - if ($action == 'editthirdparty') - { - $htmlname='socid'; - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '
'; - print $form->select_company($object->fk_soc,'socid','',1); - print '
'; - } - else - { - if ($object->fk_soc) - { - $company=new Societe($db); - $result=$company->fetch($object->fk_soc); - print $company->getNomUrl(1); - } - else - { - print $langs->trans("NoThirdPartyAssociatedToMember"); - } - } - print '
'; - print ''; - if ($action != 'editlogin' && $user->rights->adherent->creer) - { - print ''; - } - print '
'; - print $langs->trans("LinkedToDolibarrUser"); - print ''; - if ($user->rights->user->user->creer) - { - print 'id.'">'.img_edit($langs->trans('SetLinkToUser'),1).''; - } - print '
'; - print '
'; - if ($action == 'editlogin') - { - $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id,$object->user_id,'userid',''); - } - else - { - if ($object->user_id) - { - $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id,$object->user_id,'none'); - } - else print $langs->trans("NoDolibarrAccess"); - } - print '
\n"; - - print "
\n"; - print '
'; - - dol_fiche_end(); - - - /* - * Hotbar - */ - - print '
'; - $parameters = array(); - $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been - if (empty($reshook)) { - if ($action != 'valid' && $action != 'editlogin' && $action != 'editthirdparty') - { - // Modify - if ($user->rights->adherent->creer) - { - print '"; - } - else - { - print '
'.$langs->trans("Modify").'
'; - } - - // Validate - if ($object->statut == -1) - { - if ($user->rights->adherent->creer) - { - print '\n"; - } - else - { - print '
'.$langs->trans("Validate").'
'; - } - } - - // Reactivate - if ($object->statut == 0) - { - if ($user->rights->adherent->creer) - { - print '\n"; - } - else - { - print '
'.$langs->trans("Reenable")."
"; - } - } - - // Send card by email - if ($user->rights->adherent->creer) - { - if ($object->statut >= 1) - { - if ($object->email) print '\n"; - else print '\n"; - } - else - { - print '
'.$langs->trans("SendCardByMail")."
"; - } - } - else - { - print '
'.$langs->trans("SendCardByMail")."
"; - } - - // Terminate - if ($object->statut >= 1) - { - if ($user->rights->adherent->supprimer) - { - print '\n"; - } - else - { - print '
'.$langs->trans("Resiliate")."
"; - } - } - - // Create third party - if (! empty($conf->societe->enabled) && ! $object->fk_soc) - { - if ($user->rights->societe->creer) - { - if ($object->statut != -1) print ''; - else print ''; - } - else - { - print '
'.$langs->trans("CreateDolibarrThirdParty")."
"; - } - } - - // Create user - if (! $user->societe_id && ! $object->user_id) - { - if ($user->rights->user->user->creer) - { - if ($object->statut != -1) print ''; - else print ''; - } - else - { - print '
'.$langs->trans("CreateDolibarrLogin")."
"; - } - } - - // Delete - if ($user->rights->adherent->supprimer) - { - print '\n"; - } - else - { - print '
'.$langs->trans("Delete")."
"; - } - - // Action SPIP - if (! empty($conf->mailmanspip->enabled) && ! empty($conf->global->ADHERENT_USE_SPIP)) - { - $isinspip = $mailmanspip->is_in_spip($object); - - if ($isinspip == 1) - { - print '\n"; - } - if ($isinspip == 0) - { - print '\n"; - } - } - - } - } - print '
'; - - if ($isinspip == -1) - { - print '

'.$langs->trans('SPIPConnectionFailed').': '.$mailmanspip->error.''; - } - - - - print '
'; - print ''; // ancre - - // Documents generes - $filename = dol_sanitizeFileName($object->ref); - //$filename = 'tmp_cards.php'; - //$filedir = $conf->adherent->dir_output . '/' . get_exdir($object->id, 2, 0, 0, $object, 'member') . dol_sanitizeFileName($object->ref); - $filedir = $conf->adherent->dir_output . '/' . get_exdir(0, 0, 0, 0, $object, 'member'); - $urlsource = $_SERVER['PHP_SELF'] . '?id=' . $object->id; - $genallowed = $user->rights->adherent->creer; - $delallowed = $user->rights->adherent->supprimer; - - print $formfile->showdocuments('member', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $object->default_lang, '', $object); - $somethingshown = $formfile->numoffiles; - - // Show links to link elements - //$linktoelem = $form->showLinkToObjectBlock($object, null, array('subscription')); - //$somethingshown = $form->showLinkedObjectBlock($object, ''); - - // Show links to link elements - /*$linktoelem = $form->showLinkToObjectBlock($object,array('order')); - if ($linktoelem) print ($somethingshown?'':'
').$linktoelem; - - // Link for paypal payment - /* - if (! empty($conf->paypal->enabled) && $object->statut != 0) { - include_once DOL_DOCUMENT_ROOT . '/paypal/lib/paypal.lib.php'; - print showPaypalPaymentUrl('invoice', $object->ref); - } - */ - print '
'; - - // List of actions on element - /* Already in tab Agenda/Events - include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; - $formactions = new FormActions($db); - $somethingshown = $formactions->showactions($object, 'member', $socid); - */ - print '
'; - - } -} - -llxFooter(); - -$db->close(); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 8462cdc76ff..30e1579c33e 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -615,19 +615,20 @@ function dol_buildpath($path, $type=0) } /** - * Create a clone of instance of object (new instance with same properties) - * This function works for both PHP4 and PHP5 + * Create a clone of instance of object (new instance with same value for properties) + * Property that are reference are also new object (true clone) * * @param object $object Object to clone * @return object Object clone - * @deprecated Dolibarr no longer supports PHP4, use PHP5 native clone construct * @see https://php.net/manual/language.oop5.cloning.php */ function dol_clone($object) { - dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING); + //dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING); - $myclone = clone $object; + //$myclone = clone $object; // PHP clone is a shallow copy only, not a real clone, so properties of references will keep references (refer to the same target/variable + $myclone=unserialize(serialize($object)); + return $myclone; } @@ -2469,7 +2470,7 @@ function dol_trunc($string,$size=40,$trunc='right',$stringencoding='UTF-8',$nodo if ($trunc == 'right') { $newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string; - if (dol_strlen($newstring,$stringencoding) > ($size+($nodot?0:1))) + if (dol_strlen($newstring,$stringencoding) > ($size+($nodot?0:1))) return dol_substr($newstring,0,$size,$stringencoding).($nodot?'':'...'); else return $string; diff --git a/test/phpunit/AllTests.php b/test/phpunit/AllTests.php index de8cc397cf4..a417824867b 100644 --- a/test/phpunit/AllTests.php +++ b/test/phpunit/AllTests.php @@ -121,7 +121,7 @@ class AllTests $suite->addTestSuite('BuildDocTest'); require_once dirname(__FILE__).'/CMailFileTest.php'; $suite->addTestSuite('CMailFileTest'); - + require_once dirname(__FILE__).'/CommonObjectTest.php'; $suite->addTestSuite('CommonObjectTest'); diff --git a/test/phpunit/FilesLibTest.php b/test/phpunit/FilesLibTest.php index d1a5f48ae8d..c0a4ce845a9 100644 --- a/test/phpunit/FilesLibTest.php +++ b/test/phpunit/FilesLibTest.php @@ -431,10 +431,17 @@ class FilesLibTest extends PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - + + //$dummyuser=new User($db); //$result=restrictedArea($dummyuser,'societe'); + // We save user properties + $savpermlire = $user->rights->facture->lire; + $savpermcreer = $user->rights->facture->creer; + + + // Check access to SPECIMEN $user->rights->facture->lire = 0; $user->rights->facture->creer = 0; $filename='SPECIMEN.pdf'; // Filename relative to module part @@ -473,6 +480,11 @@ class FilesLibTest extends PHPUnit_Framework_TestCase $filename='FA010101/FA010101.pdf'; // Filename relative to module part $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'write'); $this->assertEquals(0,$result['accessallowed']); + + + // We restore user properties + $user->rights->facture->lire = $savpermlire; + $user->rights->facture->creer = $savpermcreer; } } diff --git a/test/phpunit/NumberingModulesTest.php b/test/phpunit/NumberingModulesTest.php index d7f3eaf611c..401b7ce0058 100644 --- a/test/phpunit/NumberingModulesTest.php +++ b/test/phpunit/NumberingModulesTest.php @@ -128,7 +128,7 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - + require_once dirname(__FILE__).'/../../htdocs/compta/facture/class/facture.class.php'; require_once dirname(__FILE__).'/../../htdocs/core/modules/facture/mod_facture_mercure.php'; @@ -138,8 +138,8 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}-{0000}'; $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}-{0000}'; $conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED=0; - - $localobject=new Facture($this->savdb); + + $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1915); // we use year 1915 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); @@ -154,10 +154,6 @@ class NumberingModulesTest extends PHPUnit_Framework_TestCase $result=$localobject->is_erasable(); print __METHOD__." is_erasable=".$result."\n"; $this->assertEquals(1, $result, 'Test for is_erasable, 1st invoice'); // Can be deleted - - $out=file_get_contents(DOL_DATA_ROOT.'/dolibarr.log'); - print $out; - $localobject2=new Facture($this->savdb); $localobject2->initAsSpecimen(); $localobject2->date=dol_mktime(12, 0, 0, 1, 1, 1916); // we use following year for second invoice (there is no reset into mask) From dd5976066a6fe052f13d80238347a0d8ee7c0756 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 22 May 2017 02:04:43 +0200 Subject: [PATCH 15/15] Fix travis --- test/phpunit/AdherentTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/phpunit/AdherentTest.php b/test/phpunit/AdherentTest.php index b998c346b7b..5db9808c9ab 100644 --- a/test/phpunit/AdherentTest.php +++ b/test/phpunit/AdherentTest.php @@ -322,9 +322,10 @@ class AdherentTest extends PHPUnit_Framework_TestCase '%ADDRESS%,%ZIP%,%TOWN%,%COUNTRY%,%EMAIL%,%BIRTH%,%PHOTO%,%LOGIN%,%PASSWORD%,%PRENOM%,'. '%NOM%,%SOCIETE%,%ADDRESS%,%ZIP%,%TOWN%,%COUNTRY%'; + // If option to store clear password has been set, we get 'dolibspec' into PASSWORD field. $expected = DOL_MAIN_URL_ROOT.','.$localobject->id.',,New firstname,New name,New firstname New name,'. 'New company,New address,New zip,New town,Belgium,newemail@newemail.com,'.dol_print_date($localobject->birth,'day').',,'. - 'newlogin,,New firstname,New name,New company,New address,New zip,New town,Belgium'; + 'newlogin,dolibspec,New firstname,New name,New company,New address,New zip,New town,Belgium'; $result = $localobject->makeSubstitution($template); print __METHOD__." result=".$result."\n";