Merge branch 'develop' of https://github.com/Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2013-10-18 14:03:35 +02:00
commit df930d08b2
13 changed files with 278 additions and 85 deletions

View File

@ -1436,18 +1436,21 @@ class AccountLine extends CommonObject
if ($withpicto) $result.=($lien.img_object($langs->trans("ShowTransaction"),'account').$lienfin.' '); if ($withpicto) $result.=($lien.img_object($langs->trans("ShowTransaction"),'account').$lienfin.' ');
$result.=$lien.$this->rowid.$lienfin; $result.=$lien.$this->rowid.$lienfin;
if ($option == 'showall' || $option == 'showconciliated') $result.=' (';
if ($option == 'showall') if ($option == 'showall')
{ {
$result.=' (';
$result.=$langs->trans("BankAccount").': '; $result.=$langs->trans("BankAccount").': ';
$accountstatic=new Account($this->db); $accountstatic=new Account($this->db);
$accountstatic->id=$this->fk_account; $accountstatic->id=$this->fk_account;
$accountstatic->label=$this->bank_account_label; $accountstatic->label=$this->bank_account_label;
$result.=$accountstatic->getNomUrl(0).', '; $result.=$accountstatic->getNomUrl(0).', ';
}
if ($option == 'showall' || $option == 'showconciliated')
{
$result.=$langs->trans("BankLineConciliated").': '; $result.=$langs->trans("BankLineConciliated").': ';
$result.=yn($this->rappro); $result.=yn($this->rappro);
$result.=')';
} }
if ($option == 'showall' || $option == 'showconciliated') $result.=')';
return $result; return $result;
} }

View File

@ -1788,8 +1788,8 @@ class Facture extends CommonInvoice
// Rename directory if dir was a temporary ref // Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref)) if (preg_match('/^[\(]?PROV/i', $this->ref))
{ {
// On renomme repertoire facture ($this->ref = ancienne ref, $num = nouvelle ref) // Rename of object directory ($this->ref = old ref, $num = new ref)
// afin de ne pas perdre les fichiers attaches // to not lose the linked files
$facref = dol_sanitizeFileName($this->ref); $facref = dol_sanitizeFileName($this->ref);
$snumfa = dol_sanitizeFileName($num); $snumfa = dol_sanitizeFileName($num);
$dirsource = $conf->facture->dir_output.'/'.$facref; $dirsource = $conf->facture->dir_output.'/'.$facref;

View File

@ -230,7 +230,7 @@ print $form->editfieldval("Numero",'num_paiement',$object->numero,$object,$objec
print '</td></tr>'; print '</td></tr>';
// Amount // Amount
print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->montant).'&nbsp;'.$langs->trans('Currency'.$conf->currency).'</td></tr>'; print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->montant,'',$langs,0,0,-1,$conf->currency).'</td></tr>';
// Note // Note
print '<tr><td valign="top">'.$form->editfieldkey("Note",'note',$object->note,$object,$user->rights->facture->paiement).'</td><td colspan="3">'; print '<tr><td valign="top">'.$form->editfieldkey("Note",'note',$object->note,$object,$user->rights->facture->paiement).'</td><td colspan="3">';
@ -248,7 +248,17 @@ if (! empty($conf->banque->enabled))
print '<tr>'; print '<tr>';
print '<td>'.$langs->trans('BankTransactionLine').'</td>'; print '<td>'.$langs->trans('BankTransactionLine').'</td>';
print '<td colspan="3">'; print '<td colspan="3">';
print $bankline->getNomUrl(1,0,'showall'); print $bankline->getNomUrl(1,0,'showconciliated');
print '</td>';
print '</tr>';
print '<tr>';
print '<td>'.$langs->trans('BankAccount').'</td>';
print '<td colspan="3">';
$accountstatic=new Account($db);
$accountstatic->id=$bankline->fk_account;
$accountstatic->label=$bankline->bank_account_ref.' - '.$bankline->bank_account_label;
print $accountstatic->getNomUrl(0);
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';

View File

@ -277,51 +277,60 @@ class Contrat extends CommonObject
* Validate a contract * Validate a contract
* *
* @param User $user Objet User * @param User $user Objet User
* @param string $force_number Reference to force on contract (not implemented yet)
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function validate($user) function validate($user, $force_number='')
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
global $langs, $conf; global $langs, $conf;
$now=dol_now();
$error=0; $error=0;
dol_syslog(get_class($this).'::validate user='.$user->id.', force_number='.$force_number);
// Definition du nom de module de numerotation de commande
$soc = new Societe($this->db);
$soc->fetch($this->socid);
// Class of company linked to order $this->db->begin();
$result=$soc->set_as_client();
$this->fetch_thirdparty();
// A contract is validated so we can move thirdparty to status customer
$result=$this->thirdparty->set_as_client();
// Define new ref // Define new ref
if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref))) if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref)))
{ {
$num = $this->getNextNumRef($soc); $num = $this->getNextNumRef($this->thirdparty);
} }
else else
{ {
$num = $this->ref; $num = $this->ref;
} }
if ($num)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET ref = '".$num."', statut = 1"; $sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET ref = '".$num."', statut = 1";
//$sql.= ", fk_user_valid = ".$user->id.", date_valid = '".$this->db->idate($now)."'";
$sql .= " WHERE rowid = ".$this->id . " AND statut = 0"; $sql .= " WHERE rowid = ".$this->id . " AND statut = 0";
dol_syslog(get_class($this)."::validate sql=".$sql);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if (! $resql)
{ {
// Appel des triggers dol_syslog(get_class($this)."::validate Echec update - 10 - sql=".$sql, LOG_ERR);
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; dol_print_error($this->db);
$interface=new Interfaces($this->db); $error++;
$result=$interface->run_triggers('CONTRACT_VALIDATE',$this,$user,$langs,$conf); }
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
if (! $error) if (! $error)
{ {
$this->oldref = '';
// Rename directory if dir was a temporary ref // Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref)) if (preg_match('/^[\(]?PROV/i', $this->ref))
{ {
// Rename of propal directory ($this->ref = old ref, $num = new ref) // Rename of object directory ($this->ref = old ref, $num = new ref)
// to not lose the linked files // to not lose the linked files
$facref = dol_sanitizeFileName($this->ref); $facref = dol_sanitizeFileName($this->ref);
$snumfa = dol_sanitizeFileName($num); $snumfa = dol_sanitizeFileName($num);
@ -333,25 +342,53 @@ class Contrat extends CommonObject
if (@rename($dirsource, $dirdest)) if (@rename($dirsource, $dirdest))
{ {
$this->oldref = $facref;
dol_syslog("Rename ok"); dol_syslog("Rename ok");
// Deleting old PDF in new rep // Deleting old PDF in new rep
dol_delete_file($conf->contract->dir_output.'/'.$snumfa.'/'.$facref.'*.*'); dol_delete_file($conf->contract->dir_output.'/'.$snumfa.'/'.$facref.'*.*');
} }
} }
} }
}
// Set new ref and define current statut
if (! $error)
{
$this->ref = $num;
$this->statut=1;
$this->brouillon=0;
$this->date_validation=$now;
}
// Trigger calls
if (! $error)
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('CONTRACT_VALIDATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
}
}
else
{
$error++;
}
if (! $error)
{
$this->db->commit();
return 1; return 1;
} }
else else
{ {
$this->db->rollback();
$this->error=$this->db->lasterror();
return -1; return -1;
} }
}
else
{
$this->error=$this->db->error();
return -1;
}
} }

View File

@ -515,22 +515,7 @@ function quotedPrintEncode($str,$forcal=0)
function quotedPrintDecode($str) function quotedPrintDecode($str)
{ {
$out = preg_replace('/=\r?\n/', '', $str); $out = preg_replace('/=\r?\n/', '', $str);
/* $out = quoted_printable_decode($out); // Available with PHP 4+
* preg_replace /e modifier is deprecated in PHP 5.5
* but anonymous functions for use in preg_replace_callback are only available from 5.3.0
*/
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
$out = preg_replace_callback(
'/=([A-F0-9]{2})/',
function ($m) {
return chr(hexdec($m[1]));
},
$out
);
} else {
$out = preg_replace('/=([A-F0-9]{2})/e', chr(hexdec('\\1')), $out);
}
return trim($out); return trim($out);
} }

View File

@ -115,7 +115,7 @@ if ($action == 'setnum' && ! empty($_POST['num_paiement']))
} }
} }
if ($action == 'setdate' && ! empty($_POST['datepday'])) if ($action == 'setdatep' && ! empty($_POST['datepday']))
{ {
$object->fetch($id); $object->fetch($id);
$datepaye = dol_mktime(12, 0, 0, $_POST['datepmonth'], $_POST['datepday'], $_POST['datepyear']); $datepaye = dol_mktime(12, 0, 0, $_POST['datepmonth'], $_POST['datepday'], $_POST['datepyear']);
@ -195,7 +195,7 @@ if ($result > 0)
print '</td></tr>'; print '</td></tr>';
// Amount // Amount
print '<tr><td valign="top" colspan="2">'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->montant).'&nbsp;'.$langs->trans('Currency'.$conf->currency).'</td></tr>'; print '<tr><td valign="top" colspan="2">'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->montant,'',$langs,0,0,-1,$conf->currency).'</td></tr>';
if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
{ {
@ -218,7 +218,17 @@ if ($result > 0)
print '<tr>'; print '<tr>';
print '<td colspan="2">'.$langs->trans('BankTransactionLine').'</td>'; print '<td colspan="2">'.$langs->trans('BankTransactionLine').'</td>';
print '<td colspan="3">'; print '<td colspan="3">';
print $bankline->getNomUrl(1,0,'showall'); print $bankline->getNomUrl(1,0,'showconciliated');
print '</td>';
print '</tr>';
print '<tr>';
print '<td colspan="2">'.$langs->trans('BankAccount').'</td>';
print '<td colspan="3">';
$accountstatic=new Account($db);
$accountstatic->id=$bankline->fk_account;
$accountstatic->label=$bankline->bank_account_ref.' - '.$bankline->bank_account_label;
print $accountstatic->getNomUrl(0);
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
} }

View File

@ -301,6 +301,7 @@ ALTER TABLE llx_facture_fourn MODIFY COLUMN fk_cond_reglement integer NULL;
insert into llx_c_action_trigger (rowid,code,label,description,elementtype,rang) values (9,'COMPANY_SENTBYMAIL','Mails sent from third party card','Executed when you send email from third party card','societe',1); insert into llx_c_action_trigger (rowid,code,label,description,elementtype,rang) values (9,'COMPANY_SENTBYMAIL','Mails sent from third party card','Executed when you send email from third party card','societe',1);
ALTER TABLE llx_contratdet ADD column product_type integer DEFAULT 1 after total_ttc;
create table llx_contrat_extrafields create table llx_contrat_extrafields
( (

View File

@ -52,6 +52,7 @@ create table llx_contratdet
total_localtax1 double(24,8) DEFAULT 0, -- Total Local tax 1 de la ligne total_localtax1 double(24,8) DEFAULT 0, -- Total Local tax 1 de la ligne
total_localtax2 double(24,8) DEFAULT 0, -- Total Local tax 2 de la ligne total_localtax2 double(24,8) DEFAULT 0, -- Total Local tax 2 de la ligne
total_ttc double(24,8) DEFAULT 0, -- Total TTC de la ligne toute quantite et incluant remise ligne et globale total_ttc double(24,8) DEFAULT 0, -- Total TTC de la ligne toute quantite et incluant remise ligne et globale
product_type integer DEFAULT 1, -- Product type (1=service by default)
info_bits integer DEFAULT 0, -- TVA NPR ou non info_bits integer DEFAULT 0, -- TVA NPR ou non
buy_price_ht double(24,8) DEFAULT NULL, -- buying price buy_price_ht double(24,8) DEFAULT NULL, -- buying price

View File

@ -125,7 +125,7 @@ function analyse_sql_and_script(&$var, $type)
} }
else else
{ {
print 'Access refused by SQL/Script injection protection in main.inc.php'; print 'Access refused by SQL/Script injection protection in main.inc.php (type='.htmlentities($type).' key='.htmlentities($key).' value='.htmlentities($value).' page='.htmlentities($_SERVER["REQUEST_URI"]).')';
exit; exit;
} }
} }

View File

@ -65,7 +65,6 @@ class Societe extends CommonObject
var $country_code; var $country_code;
var $country; var $country;
var $tel; // deprecated
var $phone; var $phone;
var $fax; var $fax;
var $email; var $email;
@ -402,7 +401,7 @@ class Societe extends CommonObject
$this->zip = $this->zip?trim($this->zip):trim($this->zip); $this->zip = $this->zip?trim($this->zip):trim($this->zip);
$this->town = $this->town?trim($this->town):trim($this->town); $this->town = $this->town?trim($this->town):trim($this->town);
$this->state_id = trim($this->state_id); $this->state_id = trim($this->state_id);
$this->country_id = ($this->country_id > 0)?$this->country_id:$this->country_id; $this->country_id = ($this->country_id > 0)?$this->country_id:0;
$this->phone = trim($this->phone); $this->phone = trim($this->phone);
$this->phone = preg_replace("/\s/","",$this->phone); $this->phone = preg_replace("/\s/","",$this->phone);
$this->phone = preg_replace("/\./","",$this->phone); $this->phone = preg_replace("/\./","",$this->phone);

View File

@ -174,6 +174,7 @@ if (empty($reshook))
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if (GETPOST('deletephoto')) $object->logo = ''; if (GETPOST('deletephoto')) $object->logo = '';
else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']); else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
@ -200,7 +201,7 @@ if (empty($reshook))
} }
// We set country_id, country_code and country for the selected country // We set country_id, country_code and country for the selected country
$object->country_id=GETPOST('country_id')?GETPOST('country_id'):$mysoc->country_id; $object->country_id=GETPOST('country_id')!=''?GETPOST('country_id'):$mysoc->country_id;
if ($object->country_id) if ($object->country_id)
{ {
$tmparray=getCountry($object->country_id,'all'); $tmparray=getCountry($object->country_id,'all');
@ -827,7 +828,7 @@ else
// Country // Country
print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">'; print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
print $form->select_country($object->country_id,'country_id'); print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id),'country_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
print '</td></tr>'; print '</td></tr>';
@ -1245,7 +1246,7 @@ else
// Country // Country
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'; print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
print $form->select_country($object->country_id,'country_id'); print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id),'country_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
print '</td></tr>'; print '</td></tr>';
@ -1548,9 +1549,12 @@ else
// Country // Country
print '<tr><td>'.$langs->trans("Country").'</td><td colspan="'.(2+(($showlogo || $showbarcode)?0:1)).'" class="nowrap">'; print '<tr><td>'.$langs->trans("Country").'</td><td colspan="'.(2+(($showlogo || $showbarcode)?0:1)).'" class="nowrap">';
if ($object->country_code)
{
$img=picto_from_langcode($object->country_code); $img=picto_from_langcode($object->country_code);
if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0); if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0);
else print ($img?$img.' ':'').$object->country; else print ($img?$img.' ':'').$object->country;
}
print '</td></tr>'; print '</td></tr>';
// State // State

View File

@ -78,6 +78,8 @@ class AllTests
$suite->addTestSuite('FunctionsTest'); $suite->addTestSuite('FunctionsTest');
require_once dirname(__FILE__).'/Functions2Test.php'; require_once dirname(__FILE__).'/Functions2Test.php';
$suite->addTestSuite('Functions2Test'); $suite->addTestSuite('Functions2Test');
require_once dirname(__FILE__).'/XCalLibTest.php';
$suite->addTestSuite('XCalLibTest');
require_once dirname(__FILE__).'/SecurityTest.php'; require_once dirname(__FILE__).'/SecurityTest.php';
$suite->addTestSuite('SecurityTest'); $suite->addTestSuite('SecurityTest');

View File

@ -0,0 +1,141 @@
<?php
/* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \file test/phpunit/XCalLibTest.php
* \ingroup test
* \brief PHPUnit test
* \remarks To run this script as CLI: phpunit filename.php
*/
global $conf,$user,$langs,$db;
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
require_once 'PHPUnit/Autoload.php';
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
require_once dirname(__FILE__).'/../../htdocs/core/lib/xcal.lib.php';
if (empty($user->id))
{
print "Load permissions for admin user nb 1\n";
$user->fetch(1);
$user->getrights();
}
$conf->global->MAIN_DISABLE_ALL_MAILS=1;
/**
* Class for PHPUnit tests
*
* @backupGlobals disabled
* @backupStaticAttributes enabled
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
*/
class XCalLibTest extends PHPUnit_Framework_TestCase
{
protected $savconf;
protected $savuser;
protected $savlangs;
protected $savdb;
/**
* Constructor
* We save global variables into local variables
*
* @return FilesLibTest
*/
function __construct()
{
//$this->sharedFixture
global $conf,$user,$langs,$db;
$this->savconf=$conf;
$this->savuser=$user;
$this->savlangs=$langs;
$this->savdb=$db;
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
//print " - db ".$db->db;
print "\n";
}
// Static methods
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.
print __METHOD__."\n";
}
public static function tearDownAfterClass()
{
global $conf,$user,$langs,$db;
$db->rollback();
print __METHOD__."\n";
}
/**
* Init phpunit tests
*
* @return void
*/
protected function setUp()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
print __METHOD__."\n";
}
/**
* End phpunit tests
*
* @return void
*/
protected function tearDown()
{
print __METHOD__."\n";
}
/**
* testQuotedPrintEncodeDecode
*
* @return void
*/
public function testQuotedPrintEncodeDecode()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$stringtoencode='ABCD=1234;';
$result=quotedPrintEncode($stringtoencode);
print __METHOD__." result=".$result."\n";
$this->assertEquals('ABCD=3D1234;',$result);
$resultback=quotedPrintDecode($result);
print __METHOD__." result=".$resultback."\n";
$this->assertEquals($stringtoencode,$resultback);
}
}
?>