Skip to content

Commit

Permalink
Merge remote-tracking branch 'uptream/develop' into 6.0-pcard
Browse files Browse the repository at this point in the history
  • Loading branch information
aspangaro committed May 22, 2017
2 parents d834cbf + dd59760 commit 7520a55
Show file tree
Hide file tree
Showing 21 changed files with 82 additions and 1,824 deletions.
1,787 changes: 0 additions & 1,787 deletions htdocs/adherents/card.php.bak

This file was deleted.

5 changes: 2 additions & 3 deletions htdocs/compta/bank/class/account.class.php
Expand Up @@ -569,7 +569,7 @@ function create(User $user = null, $notrigger=0)
$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."'";
Expand Down Expand Up @@ -702,8 +702,7 @@ function update(User $user = null, $notrigger = 0)
$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)."'";
Expand Down
11 changes: 6 additions & 5 deletions htdocs/core/lib/files.lib.php
Expand Up @@ -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
*/
Expand Down Expand Up @@ -1624,12 +1625,12 @@ function dol_compress_file($inputfile, $outputfile, $mode="gz")
*/
function dol_uncompress($inputfile,$outputdir)
{
global $conf, $langs;
global $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);
Expand Down Expand Up @@ -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
*/
Expand Down
15 changes: 8 additions & 7 deletions htdocs/core/lib/functions.lib.php
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions htdocs/core/lib/functions2.lib.php
Expand Up @@ -781,25 +781,25 @@ 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))
{
$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);
Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/modules/DolibarrModules.class.php
Expand Up @@ -848,8 +848,8 @@ function _active()
$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);
Expand Down
2 changes: 1 addition & 1 deletion htdocs/societe/class/societe.class.php
Expand Up @@ -841,7 +841,7 @@ function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmod
$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");

Expand Down
5 changes: 4 additions & 1 deletion test/phpunit/AdherentTest.php
Expand Up @@ -83,7 +83,9 @@ public static function setUpBeforeClass()
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";
}

Expand Down Expand Up @@ -320,6 +322,7 @@ public function testAdherentMakeSubstitution(Adherent $localobject)
'%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,dolibspec,New firstname,New name,New company,New address,New zip,New town,Belgium';
Expand Down
2 changes: 1 addition & 1 deletion test/phpunit/AllTests.php
Expand Up @@ -121,7 +121,7 @@ public static function suite()
$suite->addTestSuite('BuildDocTest');
require_once dirname(__FILE__).'/CMailFileTest.php';
$suite->addTestSuite('CMailFileTest');

require_once dirname(__FILE__).'/CommonObjectTest.php';
$suite->addTestSuite('CommonObjectTest');

Expand Down
14 changes: 13 additions & 1 deletion test/phpunit/FilesLibTest.php
Expand Up @@ -431,10 +431,17 @@ public function testDolCheckSecureAccessDocument()
$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
Expand Down Expand Up @@ -473,6 +480,11 @@ public function testDolCheckSecureAccessDocument()
$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;
}

}
2 changes: 2 additions & 0 deletions test/phpunit/FunctionsLibTest.php
Expand Up @@ -81,6 +81,8 @@ public static function setUpBeforeClass()
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";
}

Expand Down
5 changes: 5 additions & 0 deletions test/phpunit/ModulesTest.php
Expand Up @@ -143,6 +143,11 @@ public function testModulesInit()
$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;
Expand Down
23 changes: 14 additions & 9 deletions test/phpunit/NumberingModulesTest.php
Expand Up @@ -128,7 +128,7 @@ public function testFactureMercure()
$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';

Expand All @@ -138,20 +138,22 @@ public function testFactureMercure()
$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();
$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
$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)
Expand All @@ -160,10 +162,13 @@ public function testFactureMercure()
print __METHOD__." result=".$result."\n";
$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
Expand Down
2 changes: 1 addition & 1 deletion test/phpunit/SocieteTest.php
Expand Up @@ -79,7 +79,7 @@ public static function setUpBeforeClass()

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.

Expand Down
5 changes: 4 additions & 1 deletion test/phpunit/UserTest.php
Expand Up @@ -75,6 +75,9 @@ function __construct()
public static function setUpBeforeClass()
{
global $conf,$user,$langs,$db;

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.

print __METHOD__."\n";
Expand Down Expand Up @@ -187,7 +190,7 @@ public function testUserUpdate($localobject)
$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;
}
Expand Down
2 changes: 2 additions & 0 deletions test/phpunit/WebservicesInvoicesTest.php
Expand Up @@ -39,6 +39,8 @@
}
$conf->global->MAIN_DISABLE_ALL_MAILS=1;

$conf->global->MAIN_UMASK='0666';


/**
* Class for PHPUnit tests
Expand Down
2 changes: 2 additions & 0 deletions test/phpunit/WebservicesOrdersTest.php
Expand Up @@ -38,6 +38,8 @@
}
$conf->global->MAIN_DISABLE_ALL_MAILS=1;

$conf->global->MAIN_UMASK='0666';


/**
* Class for PHPUnit tests
Expand Down
2 changes: 2 additions & 0 deletions test/phpunit/WebservicesOtherTest.php
Expand Up @@ -38,6 +38,8 @@
}
$conf->global->MAIN_DISABLE_ALL_MAILS=1;

$conf->global->MAIN_UMASK='0666';


/**
* Class for PHPUnit tests
Expand Down
6 changes: 5 additions & 1 deletion test/phpunit/WebservicesProductsTest.php
Expand Up @@ -40,6 +40,8 @@
}
$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";
Expand Down Expand Up @@ -167,7 +169,9 @@ public function testWSProductsCreateProductOrService()
'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";
Expand Down
2 changes: 2 additions & 0 deletions test/phpunit/WebservicesThirdpartyTest.php
Expand Up @@ -38,6 +38,8 @@
}
$conf->global->MAIN_DISABLE_ALL_MAILS=1;

$conf->global->MAIN_UMASK='0666';


/**
* Class for PHPUnit tests
Expand Down
2 changes: 2 additions & 0 deletions test/phpunit/WebservicesUserTest.php
Expand Up @@ -38,6 +38,8 @@
}
$conf->global->MAIN_DISABLE_ALL_MAILS=1;

$conf->global->MAIN_UMASK='0666';


/**
* Class for PHPUnit tests
Expand Down

0 comments on commit 7520a55

Please sign in to comment.