diff --git a/htdocs/admin/pdf.php b/htdocs/admin/pdf.php index 2f1ae179948..8484539528d 100644 --- a/htdocs/admin/pdf.php +++ b/htdocs/admin/pdf.php @@ -644,7 +644,6 @@ else // Show print ' ('.@constant('TCPDI_PATH').')'; $i++; } - print ''; print ''."\n"; print ''."\n"; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 3bc64310b9e..b66e1661be0 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5792,7 +5792,7 @@ function dol_concatdesc($text1,$text2,$forxml=false) */ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null) { - global $db, $conf, $mysoc, $user; + global $db, $conf, $mysoc, $user, $extrafields; $substitutionarray=array(); @@ -5966,11 +5966,14 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob { if (! is_object($extrafields)) $extrafields = new ExtraFields($db); $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) { - $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key]; + if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) + { + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) { + $substitutionarray['__EXTRAFIELD_' . strtoupper($key) . '__'] = $object->array_options['options_' . $key]; + } } } } diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 43f5aaaf579..573a562d467 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -119,14 +119,10 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P') define('K_TCPDF_THROW_EXCEPTION_ERROR', false); } - if (! empty($conf->global->MAIN_USE_FPDF) && ! empty($conf->global->MAIN_DISABLE_FPDI)) - return "Error MAIN_USE_FPDF and MAIN_DISABLE_FPDI can't be set together"; + // Load TCPDF + require_once TCPDF_PATH.'tcpdf.php'; - // We use by default TCPDF else FPDF - 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). + // 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_DISABLE_TCPDI)) require_once TCPDI_PATH.'tcpdi.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']; // 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 - 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 $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('
',"\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; } @@ -362,7 +297,7 @@ function pdfBuildThirdpartyName($thirdparty, Translate $outputlangs, $includeali } elseif ($thirdparty instanceof Contact) { $socname = $thirdparty->socname; } 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); @@ -1076,8 +1011,7 @@ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_bass { $pdf->SetXY($dims['wk']-$dims['rm']-15, -$posy); //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); - else $pdf->MultiCell(15, 2, $pdf->PageNo().'/{nb}', 0, 'R', 0); + $pdf->MultiCell(15, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0); } return $marginwithfooter; diff --git a/htdocs/ecm/class/ecmfiles.class.php b/htdocs/ecm/class/ecmfiles.class.php index 698960974d5..5581d10fe7a 100644 --- a/htdocs/ecm/class/ecmfiles.class.php +++ b/htdocs/ecm/class/ecmfiles.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2014-2016 Juanjo Menent * Copyright (C) 2015 Florian Henry * Copyright (C) 2015 Raphaƫl Doursenaud + * Copyright (C) 2018 Francis Appels * Copyright (C) ---Put here your own copyright and developer email--- * * 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 EcmFiles //extends CommonObject +class EcmFiles extends CommonObject { /** * @var string Id to identify managed objects @@ -65,6 +66,8 @@ class EcmFiles //extends CommonObject public $fk_user_c; public $fk_user_m; public $acl; + public $src_object_type; + public $src_object_id; /** */ @@ -142,6 +145,9 @@ class EcmFiles //extends CommonObject if (isset($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_m)) $this->date_m = dol_now(); @@ -161,15 +167,27 @@ class EcmFiles //extends CommonObject $obj = $this->db->fetch_object($resql); $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 if (empty($this->filename) || empty($this->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 @@ -192,12 +210,14 @@ class EcmFiles //extends CommonObject $sql.= 'date_m,'; $sql.= 'fk_user_c,'; $sql.= 'fk_user_m,'; - $sql.= 'acl'; + $sql.= 'acl,'; + $sql.= 'src_object_type,'; + $sql.= 'src_object_id'; $sql .= ') VALUES ('; $sql .= " '".$ref."', "; $sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").','; $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->filepath)?'NULL':"'".$this->db->escape($this->filepath)."'").','; $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->fk_user_c)?$user->id:$this->fk_user_c).','; $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 .= ')'; $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->position = $maxposition; - if (!$notrigger) { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action to call a trigger. - - //// Call triggers - //$result=$this->call_trigger('MYOBJECT_CREATE',$user); - //if ($result < 0) $error++; - //// End call triggers + // Triggers + if (! $notrigger) + { + // Call triggers + $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user); + if ($result < 0) { $error++; } + // End call triggers } } @@ -283,7 +304,9 @@ class EcmFiles //extends CommonObject $sql .= " t.date_m,"; $sql .= " t.fk_user_c,"; $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.= ' WHERE 1 = 1'; /* 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_m = $obj->fk_user_m; $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 // fetch optionals attributes and labels // $this->fetch_optionals(); - + // $this->fetch_lines(); $this->db->free($resql); @@ -390,7 +415,9 @@ class EcmFiles //extends CommonObject $sql .= " t.date_m,"; $sql .= " t.fk_user_c,"; $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'; // Manage filter @@ -443,6 +470,9 @@ class EcmFiles //extends CommonObject $line->fk_user_c = $obj->fk_user_c; $line->fk_user_m = $obj->fk_user_m; $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); @@ -465,6 +495,8 @@ class EcmFiles //extends CommonObject */ public function update(User $user, $notrigger = false) { + global $conf; + $error = 0; dol_syslog(__METHOD__, LOG_DEBUG); @@ -507,16 +539,15 @@ class EcmFiles //extends CommonObject if (isset($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)) { $this->fk_user_m = trim($this->fk_user_m); } if (isset($this->acl)) { $this->acl = trim($this->acl); } - + if (isset($this->src_object_type)) { + $this->src_object_type = trim($this->src_object_type); + } // Check parameters // 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 .= ' 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 .= ' 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 .= ' 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; $this->db->begin(); @@ -552,14 +584,13 @@ class EcmFiles //extends CommonObject dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); } - if (!$error && !$notrigger) { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action calls a trigger. - - //// Call triggers - //$result=$this->call_trigger('MYOBJECT_MODIFY',$user); - //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} - //// End call triggers + // Triggers + if (! $error && ! $notrigger) + { + // Call triggers + $result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user); + if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail + // End call triggers } // Commit or rollback @@ -590,16 +621,13 @@ class EcmFiles //extends CommonObject $this->db->begin(); - if (!$error) { - 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('MYOBJECT_DELETE',$user); - //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} - //// End call triggers - } + // Triggers + if (! $notrigger) + { + // Call triggers + $result=$this->call_trigger(strtoupper(get_class($this)).'_DELETE',$user); + if ($result < 0) { $error++; } //Do also here 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 @@ -781,8 +809,9 @@ class EcmFiles //extends CommonObject $this->fk_user_c = $user->id; $this->fk_user_m = ''; $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_m; public $acl; + public $src_object_type; + public $src_object_id; }