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

develop

Conflicts:
	htdocs/core/lib/functions.lib.php
This commit is contained in:
Laurent Destailleur
2018-04-13 23:18:39 +02:00
4 changed files with 88 additions and 121 deletions

View File

@@ -644,7 +644,6 @@ else // Show
print ' ('.@constant('TCPDI_PATH').')'; print ' ('.@constant('TCPDI_PATH').')';
$i++; $i++;
} }
print '<!-- $conf->global->MAIN_USE_FPDF = '.$conf->global->MAIN_USE_FPDF.' -->';
print '</td>'."\n"; print '</td>'."\n";
print '</tr>'."\n"; print '</tr>'."\n";

View File

@@ -5792,7 +5792,7 @@ function dol_concatdesc($text1,$text2,$forxml=false)
*/ */
function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null) function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
{ {
global $db, $conf, $mysoc, $user; global $db, $conf, $mysoc, $user, $extrafields;
$substitutionarray=array(); $substitutionarray=array();
@@ -5966,11 +5966,14 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob
{ {
if (! is_object($extrafields)) $extrafields = new ExtraFields($db); if (! is_object($extrafields)) $extrafields = new ExtraFields($db);
$extrafields->fetch_name_optionals_label($object->table_element, true); $extrafields->fetch_name_optionals_label($object->table_element, true);
$object->fetch_optionals();
if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) if ($object->fetch_optionals() > 0)
{ {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) { if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0)
$substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key]; {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) {
$substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key];
}
} }
} }
} }

View File

@@ -119,14 +119,10 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P')
define('K_TCPDF_THROW_EXCEPTION_ERROR', false); define('K_TCPDF_THROW_EXCEPTION_ERROR', false);
} }
if (! empty($conf->global->MAIN_USE_FPDF) && ! empty($conf->global->MAIN_DISABLE_FPDI)) // Load TCPDF
return "Error MAIN_USE_FPDF and MAIN_DISABLE_FPDI can't be set together"; require_once TCPDF_PATH.'tcpdf.php';
// We use by default TCPDF else FPDF // We need to instantiate tcpdi object (instead of tcpdf) to use merging features. But we can disable it (this will break all merge features).
if (empty($conf->global->MAIN_USE_FPDF)) require_once TCPDF_PATH.'tcpdf.php';
else require_once FPDF_PATH.'fpdf.php';
// We need to instantiate tcpdi or fpdi object (instead of tcpdf) to use merging features. But we can disable it (this will break all merge features).
if (empty($conf->global->MAIN_DISABLE_TCPDI)) require_once TCPDI_PATH.'tcpdi.php'; if (empty($conf->global->MAIN_DISABLE_TCPDI)) require_once TCPDI_PATH.'tcpdi.php';
else if (empty($conf->global->MAIN_DISABLE_FPDI)) require_once FPDI_PATH.'fpdi.php'; else if (empty($conf->global->MAIN_DISABLE_FPDI)) require_once FPDI_PATH.'fpdi.php';
@@ -135,7 +131,7 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P')
//$metric=$arrayformat['unit']; //$metric=$arrayformat['unit'];
// Protection and encryption of pdf // Protection and encryption of pdf
if (empty($conf->global->MAIN_USE_FPDF) && ! empty($conf->global->PDF_SECURITY_ENCRYPTION)) if (! empty($conf->global->PDF_SECURITY_ENCRYPTION))
{ {
/* Permission supported by TCPDF /* Permission supported by TCPDF
- print : Print the document; - print : Print the document;
@@ -158,67 +154,6 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P')
$pdfownerpass = NULL; // Password of the owner, created randomly if not defined $pdfownerpass = NULL; // Password of the owner, created randomly if not defined
$pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass); $pdf->SetProtection($pdfrights,$pdfuserpass,$pdfownerpass);
} }
else
{
if (class_exists('TCPDI')) $pdf = new TCPDI($pagetype,$metric,$format);
else if (class_exists('FPDI')) $pdf = new FPDI($pagetype,$metric,$format);
else $pdf = new TCPDF($pagetype,$metric,$format);
}
// If we use FPDF class, we may need to add method writeHTMLCell
if (! empty($conf->global->MAIN_USE_FPDF) && ! method_exists($pdf, 'writeHTMLCell'))
{
// Declare here a class to overwrite FPDI to add method writeHTMLCell
/**
* This class is an enhanced FPDI class that support method writeHTMLCell
*/
class FPDI_DolExtended extends FPDI
{
/**
* __call
*
* @param string $method Method
* @param mixed $args Arguments
* @return void
*/
public function __call($method, $args)
{
if (isset($this->$method)) {
$func = $this->$method;
$func($args);
}
}
/**
* writeHTMLCell
*
* @param int $w Width
* @param int $h Height
* @param int $x X
* @param int $y Y
* @param string $html Html
* @param int $border Border
* @param int $ln Ln
* @param boolean $fill Fill
* @param boolean $reseth Reseth
* @param string $align Align
* @param boolean $autopadding Autopadding
* @return void
*/
public function writeHTMLCell($w, $h, $x, $y, $html = '', $border = 0, $ln = 0, $fill = false, $reseth = true, $align = '', $autopadding = true)
{
$this->SetXY($x,$y);
$val=str_replace('<br>',"\n",$html);
//$val=dol_string_nohtmltag($val,false,'ISO-8859-1');
$val=dol_string_nohtmltag($val,false,'UTF-8');
$this->MultiCell($w,$h,$val,$border,$align,$fill);
}
}
$pdf2=new FPDI_DolExtended($pagetype,$metric,$format);
unset($pdf);
$pdf=$pdf2;
}
return $pdf; return $pdf;
} }
@@ -362,7 +297,7 @@ function pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includeali
} elseif ($thirdparty instanceof Contact) { } elseif ($thirdparty instanceof Contact) {
$socname = $thirdparty->socname; $socname = $thirdparty->socname;
} else { } else {
throw new InvalidArgumentException('Parameter 1=$thirdparty is not a Societe nor Contact'); throw new InvalidArgumentException('Parameter 1 $thirdparty is not a Societe nor Contact');
} }
return $outputlangs->convToOutputCharset($socname); return $outputlangs->convToOutputCharset($socname);
@@ -1076,8 +1011,7 @@ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_bass
{ {
$pdf->SetXY($dims['wk']-$dims['rm']-15, -$posy); $pdf->SetXY($dims['wk']-$dims['rm']-15, -$posy);
//print 'xxx'.$pdf->PageNo().'-'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit; //print 'xxx'.$pdf->PageNo().'-'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit;
if (empty($conf->global->MAIN_USE_FPDF)) $pdf->MultiCell(15, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0); $pdf->MultiCell(15, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
else $pdf->MultiCell(15, 2, $pdf->PageNo().'/{nb}', 0, 'R', 0);
} }
return $marginwithfooter; return $marginwithfooter;

View File

@@ -3,6 +3,7 @@
* Copyright (C) 2014-2016 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2014-2016 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr> * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2018 Francis Appels <francis.appels@yahoo.com>
* Copyright (C) ---Put here your own copyright and developer email--- * Copyright (C) ---Put here your own copyright and developer email---
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@@ -33,7 +34,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
/** /**
* Class to manage ECM files * Class to manage ECM files
*/ */
class EcmFiles //extends CommonObject class EcmFiles extends CommonObject
{ {
/** /**
* @var string Id to identify managed objects * @var string Id to identify managed objects
@@ -65,6 +66,8 @@ class EcmFiles //extends CommonObject
public $fk_user_c; public $fk_user_c;
public $fk_user_m; public $fk_user_m;
public $acl; public $acl;
public $src_object_type;
public $src_object_id;
/** /**
*/ */
@@ -142,6 +145,9 @@ class EcmFiles //extends CommonObject
if (isset($this->acl)) { if (isset($this->acl)) {
$this->acl = trim($this->acl); $this->acl = trim($this->acl);
} }
if (isset($this->src_object_type)) {
$this->src_object_type = trim($this->src_object_type);
}
if (empty($this->date_c)) $this->date_c = dol_now(); if (empty($this->date_c)) $this->date_c = dol_now();
if (empty($this->date_m)) $this->date_m = dol_now(); if (empty($this->date_m)) $this->date_m = dol_now();
@@ -161,15 +167,27 @@ class EcmFiles //extends CommonObject
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$maxposition = (int) $obj->maxposition; $maxposition = (int) $obj->maxposition;
} }
else dol_print_error($this->db); else
{
$this->errors[] = 'Error ' . $this->db->lasterror();
return --$error;
}
$maxposition=$maxposition+1;
}
else
{
$maxposition=$this->position;
} }
$maxposition=$maxposition+1;
// Check parameters // Check parameters
if (empty($this->filename) || empty($this->filepath)) if (empty($this->filename) || empty($this->filepath))
{ {
$this->errors[] = 'Bad property filename or filepath'; $this->errors[] = 'Bad property filename or filepath';
return -1; return --$error;
}
if (! isset($this->entity))
{
$this->entity = $conf->entity;
} }
// Put here code to add control on parameters values // Put here code to add control on parameters values
@@ -192,12 +210,14 @@ class EcmFiles //extends CommonObject
$sql.= 'date_m,'; $sql.= 'date_m,';
$sql.= 'fk_user_c,'; $sql.= 'fk_user_c,';
$sql.= 'fk_user_m,'; $sql.= 'fk_user_m,';
$sql.= 'acl'; $sql.= 'acl,';
$sql.= 'src_object_type,';
$sql.= 'src_object_id';
$sql .= ') VALUES ('; $sql .= ') VALUES (';
$sql .= " '".$ref."', "; $sql .= " '".$ref."', ";
$sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").','; $sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").',';
$sql .= ' '.(! isset($this->share)?'NULL':"'".$this->db->escape($this->share)."'").','; $sql .= ' '.(! isset($this->share)?'NULL':"'".$this->db->escape($this->share)."'").',';
$sql .= ' '.(! isset($this->entity)?$conf->entity:$this->entity).','; $sql .= ' '.$this->entity.',';
$sql .= ' '.(! isset($this->filename)?'NULL':"'".$this->db->escape($this->filename)."'").','; $sql .= ' '.(! isset($this->filename)?'NULL':"'".$this->db->escape($this->filename)."'").',';
$sql .= ' '.(! isset($this->filepath)?'NULL':"'".$this->db->escape($this->filepath)."'").','; $sql .= ' '.(! isset($this->filepath)?'NULL':"'".$this->db->escape($this->filepath)."'").',';
$sql .= ' '.(! isset($this->fullpath_orig)?'NULL':"'".$this->db->escape($this->fullpath_orig)."'").','; $sql .= ' '.(! isset($this->fullpath_orig)?'NULL':"'".$this->db->escape($this->fullpath_orig)."'").',';
@@ -211,7 +231,9 @@ class EcmFiles //extends CommonObject
$sql .= ' '.(! isset($this->date_m) || dol_strlen($this->date_m)==0?'NULL':"'".$this->db->idate($this->date_m)."'").','; $sql .= ' '.(! isset($this->date_m) || dol_strlen($this->date_m)==0?'NULL':"'".$this->db->idate($this->date_m)."'").',';
$sql .= ' '.(! isset($this->fk_user_c)?$user->id:$this->fk_user_c).','; $sql .= ' '.(! isset($this->fk_user_c)?$user->id:$this->fk_user_c).',';
$sql .= ' '.(! isset($this->fk_user_m)?'NULL':$this->fk_user_m).','; $sql .= ' '.(! isset($this->fk_user_m)?'NULL':$this->fk_user_m).',';
$sql .= ' '.(! isset($this->acl)?'NULL':"'".$this->db->escape($this->acl)."'"); $sql .= ' '.(! isset($this->acl)?'NULL':"'".$this->db->escape($this->acl)."'").',';
$sql .= ' '.(! isset($this->src_object_type)?'NULL':"'".$this->db->escape($this->src_object_type)."'").',';
$sql .= ' '.(! isset($this->src_object_id)?'NULL':$this->src_object_id);
$sql .= ')'; $sql .= ')';
$this->db->begin(); $this->db->begin();
@@ -227,14 +249,13 @@ class EcmFiles //extends CommonObject
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
$this->position = $maxposition; $this->position = $maxposition;
if (!$notrigger) { // Triggers
// Uncomment this and change MYOBJECT to your own tag if you if (! $notrigger)
// want this action to call a trigger. {
// Call triggers
//// Call triggers $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user);
//$result=$this->call_trigger('MYOBJECT_CREATE',$user); if ($result < 0) { $error++; }
//if ($result < 0) $error++; // End call triggers
//// End call triggers
} }
} }
@@ -283,7 +304,9 @@ class EcmFiles //extends CommonObject
$sql .= " t.date_m,"; $sql .= " t.date_m,";
$sql .= " t.fk_user_c,"; $sql .= " t.fk_user_c,";
$sql .= " t.fk_user_m,"; $sql .= " t.fk_user_m,";
$sql .= " t.acl"; $sql .= " t.acl,";
$sql .= " t.src_object_type,";
$sql .= " t.src_object_id";
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
$sql.= ' WHERE 1 = 1'; $sql.= ' WHERE 1 = 1';
/* Fetching this table depends on filepath+filename, it must not depends on entity /* Fetching this table depends on filepath+filename, it must not depends on entity
@@ -333,12 +356,14 @@ class EcmFiles //extends CommonObject
$this->fk_user_c = $obj->fk_user_c; $this->fk_user_c = $obj->fk_user_c;
$this->fk_user_m = $obj->fk_user_m; $this->fk_user_m = $obj->fk_user_m;
$this->acl = $obj->acl; $this->acl = $obj->acl;
$this->src_object_type = $obj->src_object_type;
$this->src_object_id = $obj->src_object_id;
} }
// Retrieve all extrafields for invoice // Retrieve all extrafields for invoice
// fetch optionals attributes and labels // fetch optionals attributes and labels
// $this->fetch_optionals(); // $this->fetch_optionals();
// $this->fetch_lines(); // $this->fetch_lines();
$this->db->free($resql); $this->db->free($resql);
@@ -390,7 +415,9 @@ class EcmFiles //extends CommonObject
$sql .= " t.date_m,"; $sql .= " t.date_m,";
$sql .= " t.fk_user_c,"; $sql .= " t.fk_user_c,";
$sql .= " t.fk_user_m,"; $sql .= " t.fk_user_m,";
$sql .= " t.acl"; $sql .= " t.acl,";
$sql .= " t.src_object_type,";
$sql .= " t.src_object_id";
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
// Manage filter // Manage filter
@@ -443,6 +470,9 @@ class EcmFiles //extends CommonObject
$line->fk_user_c = $obj->fk_user_c; $line->fk_user_c = $obj->fk_user_c;
$line->fk_user_m = $obj->fk_user_m; $line->fk_user_m = $obj->fk_user_m;
$line->acl = $obj->acl; $line->acl = $obj->acl;
$line->src_object_type = $obj->src_object_type;
$line->src_object_id = $obj->src_object_id;
$this->lines[] = $line;
} }
$this->db->free($resql); $this->db->free($resql);
@@ -465,6 +495,8 @@ class EcmFiles //extends CommonObject
*/ */
public function update(User $user, $notrigger = false) public function update(User $user, $notrigger = false)
{ {
global $conf;
$error = 0; $error = 0;
dol_syslog(__METHOD__, LOG_DEBUG); dol_syslog(__METHOD__, LOG_DEBUG);
@@ -507,16 +539,15 @@ class EcmFiles //extends CommonObject
if (isset($this->extraparams)) { if (isset($this->extraparams)) {
$this->extraparams = trim($this->extraparams); $this->extraparams = trim($this->extraparams);
} }
if (isset($this->fk_user_c)) {
$this->fk_user_c = trim($this->fk_user_c);
}
if (isset($this->fk_user_m)) { if (isset($this->fk_user_m)) {
$this->fk_user_m = trim($this->fk_user_m); $this->fk_user_m = trim($this->fk_user_m);
} }
if (isset($this->acl)) { if (isset($this->acl)) {
$this->acl = trim($this->acl); $this->acl = trim($this->acl);
} }
if (isset($this->src_object_type)) {
$this->src_object_type = trim($this->src_object_type);
}
// Check parameters // Check parameters
// Put here code to add a control on parameters values // Put here code to add a control on parameters values
@@ -538,9 +569,10 @@ class EcmFiles //extends CommonObject
$sql .= ' extraparams = '.(isset($this->extraparams)?"'".$this->db->escape($this->extraparams)."'":"null").','; $sql .= ' extraparams = '.(isset($this->extraparams)?"'".$this->db->escape($this->extraparams)."'":"null").',';
$sql .= ' date_c = '.(! isset($this->date_c) || dol_strlen($this->date_c) != 0 ? "'".$this->db->idate($this->date_c)."'" : 'null').','; $sql .= ' date_c = '.(! isset($this->date_c) || dol_strlen($this->date_c) != 0 ? "'".$this->db->idate($this->date_c)."'" : 'null').',';
//$sql .= ' date_m = '.(! isset($this->date_m) || dol_strlen($this->date_m) != 0 ? "'".$this->db->idate($this->date_m)."'" : 'null').','; // Field automatically updated //$sql .= ' date_m = '.(! isset($this->date_m) || dol_strlen($this->date_m) != 0 ? "'".$this->db->idate($this->date_m)."'" : 'null').','; // Field automatically updated
$sql .= ' fk_user_c = '.(isset($this->fk_user_c)?$this->fk_user_c:"null").',';
$sql .= ' fk_user_m = '.($this->fk_user_m > 0?$this->fk_user_m:$user->id).','; $sql .= ' fk_user_m = '.($this->fk_user_m > 0?$this->fk_user_m:$user->id).',';
$sql .= ' acl = '.(isset($this->acl)?"'".$this->db->escape($this->acl)."'":"null"); $sql .= ' acl = '.(isset($this->acl)?"'".$this->db->escape($this->acl)."'":"null").',';
$sql .= ' src_object_id = '.($this->src_object_id > 0?$this->src_object_id:"null").',';
$sql .= ' src_object_type = '.(isset($this->src_object_type)?"'".$this->db->escape($this->src_object_type)."'":"null");
$sql .= ' WHERE rowid=' . $this->id; $sql .= ' WHERE rowid=' . $this->id;
$this->db->begin(); $this->db->begin();
@@ -552,14 +584,13 @@ class EcmFiles //extends CommonObject
dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
} }
if (!$error && !$notrigger) { // Triggers
// Uncomment this and change MYOBJECT to your own tag if you if (! $error && ! $notrigger)
// want this action calls a trigger. {
// Call triggers
//// Call triggers $result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user);
//$result=$this->call_trigger('MYOBJECT_MODIFY',$user); if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail
//if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} // End call triggers
//// End call triggers
} }
// Commit or rollback // Commit or rollback
@@ -590,16 +621,13 @@ class EcmFiles //extends CommonObject
$this->db->begin(); $this->db->begin();
if (!$error) { // Triggers
if (!$notrigger) { if (! $notrigger)
// Uncomment this and change MYOBJECT to your own tag if you {
// want this action calls a trigger. // Call triggers
$result=$this->call_trigger(strtoupper(get_class($this)).'_DELETE',$user);
//// Call triggers if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail
//$result=$this->call_trigger('MYOBJECT_DELETE',$user); // End call triggers
//if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
//// End call triggers
}
} }
// If you need to delete child tables to, you can insert them here // If you need to delete child tables to, you can insert them here
@@ -781,8 +809,9 @@ class EcmFiles //extends CommonObject
$this->fk_user_c = $user->id; $this->fk_user_c = $user->id;
$this->fk_user_m = ''; $this->fk_user_m = '';
$this->acl = ''; $this->acl = '';
$this->src_object_type = 'product';
$this->src_object_id = 1;
} }
} }
@@ -804,4 +833,6 @@ class EcmfilesLine
public $fk_user_c; public $fk_user_c;
public $fk_user_m; public $fk_user_m;
public $acl; public $acl;
public $src_object_type;
public $src_object_id;
} }