From e15d4c045dc6094bc7b4cbdb33c190959a4d81b0 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Sat, 18 Apr 2015 18:44:05 +0200 Subject: [PATCH] NEW : Propal merge product card PDF into azur --- .../modules/propale/doc/pdf_azur.modules.php | 51 ++ .../install/mysql/migration/3.7.0-3.8.0.sql | 11 + .../tables/llx_propal_merge_pdf_product.sql | 28 + htdocs/langs/en_US/admin.lang | 1 + htdocs/langs/en_US/products.lang | 4 +- htdocs/product/admin/product.php | 19 + .../class/propalmergepdfproduct.class.php | 656 ++++++++++++++++++ htdocs/product/document.php | 194 +++++- 8 files changed, 961 insertions(+), 3 deletions(-) create mode 100644 htdocs/install/mysql/tables/llx_propal_merge_pdf_product.sql create mode 100644 htdocs/product/class/propalmergepdfproduct.class.php diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index b3ff4710f1b..2d4300f76da 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -589,6 +589,57 @@ class pdf_azur extends ModelePDFPropales $this->_pagefoot($pdf,$object,$outputlangs); if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); + //If propal merge product PDF is active + if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL)) + { + require_once DOL_DOCUMENT_ROOT.'/product/class/propalmergepdfproduct.class.php'; + + $already_merged = array (); + foreach ( $object->lines as $line ) { + if (! empty($line->fk_product) && ! (in_array($line->fk_product, $already_merged))) { + // Find the desire PDF + $filetomerge = new Propalmergepdfproduct($this->db); + + if ($conf->global->MAIN_MULTILANGS) { + $filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang); + } else { + $filetomerge->fetch_by_product($line->fk_product); + } + + $already_merged[] = $line->fk_product; + + // If PDF is selected and file is not empty + if (count($filetomerge->lines) > 0) { + foreach ( $filetomerge->lines as $linefile ) { + if (! empty($linefile->id) && ! empty($linefile->file_name)) { + if (! empty($conf->product->enabled)) + $filetomerge_dir = $conf->product->multidir_output[$conf->entity] . '/' . dol_sanitizeFileName($line->product_ref); + elseif (! empty($conf->service->enabled)) + $filetomerge_dir = $conf->service->multidir_output[$conf->entity] . '/' . dol_sanitizeFileName($line->product_ref); + + dol_syslog(get_class($this) . ':: upload_dir=' . $filetomerge_dir, LOG_DEBUG); + + $infile = $filetomerge_dir . '/' . $linefile->file_name; + if (is_file($infile)) { + $pagecount = $pdf->setSourceFile($infile); + for($i = 1; $i <= $pagecount; $i ++) { + $tplidx = $pdf->ImportPage($i); + $s = $pdf->getTemplatesize($tplidx); + $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); + $pdf->useTemplate($tplidx); + } + } + } + } + } + } + } + } + + //exit; + + + $pdf->Close(); $pdf->Output($file,'F'); diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql index 6c70b73030f..c8b2ad9a057 100644 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -520,3 +520,14 @@ create table llx_c_price_global_variable_updater ALTER TABLE llx_adherent CHANGE COLUMN note note_private text DEFAULT NULL; ALTER TABLE llx_adherent ADD COLUMN note_public text DEFAULT NULL after note_private; +CREATE TABLE IF NOT EXISTS llx_propal_merge_pdf_product ( + rowid integer NOT NULL auto_increment PRIMARY KEY, + fk_product integer NOT NULL, + file_name varchar(200) NOT NULL, + lang varchar(5) DEFAULT NULL, + fk_user_author integer DEFAULT NULL, + fk_user_mod integer NOT NULL, + datec datetime NOT NULL, + tms timestamp NOT NULL, + import_key varchar(14) DEFAULT NULL +) ENGINE=InnoDB; \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_propal_merge_pdf_product.sql b/htdocs/install/mysql/tables/llx_propal_merge_pdf_product.sql new file mode 100644 index 00000000000..93af93c9190 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_propal_merge_pdf_product.sql @@ -0,0 +1,28 @@ +-- +-- Copyright (C) 2013 Florian HENRY +-- +-- 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 . + +CREATE TABLE IF NOT EXISTS llx_propal_merge_pdf_product ( + rowid integer NOT NULL auto_increment PRIMARY KEY, + fk_product integer NOT NULL, + file_name varchar(200) NOT NULL, + lang varchar(5) DEFAULT NULL, + fk_user_author integer DEFAULT NULL, + fk_user_mod integer NOT NULL, + datec datetime NOT NULL, + tms timestamp NOT NULL, + import_key varchar(14) DEFAULT NULL +) ENGINE=InnoDB; + diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 4b7ddfe0143..64cb90263ab 100755 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1384,6 +1384,7 @@ NumberOfProductShowInSelect=Max number of products in combos select lists (0=no ConfirmDeleteProductLineAbility=Confirmation when removing product lines in forms ModifyProductDescAbility=Personalization of product descriptions in forms ViewProductDescInFormAbility=Visualization of product descriptions in the forms (otherwise as popup tooltip) +MergePropalProductCard=Activate in product/service Attached Files tab an option to merge product PDF document to proposal PDF azur if product/service is in the proposal ViewProductDescInThirdpartyLanguageAbility=Visualization of products descriptions in the thirdparty language UseSearchToSelectProductTooltip=Also if you have a large number of product (> 100 000), you can increase speed by setting constant PRODUCT_DONOTSEARCH_ANYWHERE to 1 in Setup->Other. Search will then be limited to start of string. UseSearchToSelectProduct=Use a search form to choose a product (rather than a drop-down list). diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 1b9a49b559d..987639b5ca2 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -266,4 +266,6 @@ GlobalVariableUpdaterHelp1=Parses WebService data from specified URL, NS specifi GlobalVariableUpdaterHelpFormat1=format is {"URL": "http://example.com/urlofws", "VALUE": "array,targetvalue", "NS": "http://example.com/urlofns", "METHOD": "myWSMethod", "DATA": {"your": "data, "to": "send"}} UpdateInterval=Update interval (minutes) LastUpdated=Last updated -CorrectlyUpdated=Correctly updated \ No newline at end of file +CorrectlyUpdated=Correctly updated +PropalMergePdfProductActualFile=Files use to add into PDF Azur_plus are/is +PropalMergePdfProductChooseFile=Select PDF files \ No newline at end of file diff --git a/htdocs/product/admin/product.php b/htdocs/product/admin/product.php index c3de8edd468..05f77597cb2 100644 --- a/htdocs/product/admin/product.php +++ b/htdocs/product/admin/product.php @@ -159,6 +159,10 @@ else if ($action == 'viewProdTextsInThirdpartyLanguage') $view = GETPOST('activate_viewProdTextsInThirdpartyLanguage','alpha'); $res = dolibarr_set_const($db, "PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE", $view,'chaine',0,'',$conf->entity); } +elseif ($action == 'mergePropalProductCard') { + $view = GETPOST('activate_mergePropalProductCard','alpha'); + $res = dolibarr_set_const($db, "PRODUIT_PDF_MERGE_PROPAL", $view,'chaine',0,'',$conf->entity); +} else if ($action == 'usesearchtoselectproduct') { $usesearch = GETPOST('activate_usesearchtoselectproduct','alpha'); @@ -428,6 +432,21 @@ print ''; print ''; print ''; +// Activate propal merge produt card +$var=!$var; +print '
'; +print ''; +print ''; +print ''; +print ''.$langs->trans("MergePropalProductCard").''; +print ''; +print $form->selectyesno("activate_mergePropalProductCard",$conf->global->PRODUIT_PDF_MERGE_PROPAL,1); +print ''; +print ''; +print ''; +print ''; +print '
'; + // View product description in thirdparty language if (! empty($conf->global->MAIN_MULTILANGS)) { diff --git a/htdocs/product/class/propalmergepdfproduct.class.php b/htdocs/product/class/propalmergepdfproduct.class.php new file mode 100644 index 00000000000..b2b7296d311 --- /dev/null +++ b/htdocs/product/class/propalmergepdfproduct.class.php @@ -0,0 +1,656 @@ + + * Copyright (C) 2015 Florian HENRY + * + * 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/product/class/propalmergepdfproduct.class.php + * \ingroup product + * \brief This file is an CRUD class file (Create/Read/Update/Delete) + */ + +require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php"); + + + +/** + * Put here description of your class + */ +class Propalmergepdfproduct extends CommonObject +{ + var $db; //!< To store db handler + var $error; //!< To return error code (or message) + var $errors=array(); //!< To return several error codes (or messages) + var $element='propal_merge_pdf_product'; //!< Id that identify managed objects + var $table_element='propal_merge_pdf_product'; //!< Name of table without prefix where object is stored + + var $id; + + var $fk_product; + var $file_name; + var $fk_user_author; + var $fk_user_mod; + var $datec=''; + var $tms=''; + var $import_key; + var $lang; + + var $lines=array(); + + + + + /** + * Constructor + * + * @param DoliDb $db Database handler + */ + function __construct($db) + { + $this->db = $db; + return 1; + } + + + /** + * Create object into database + * + * @param User $user User that creates + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, Id of created object if OK + */ + function create($user, $notrigger=0) + { + global $conf, $langs; + $error=0; + + // Clean parameters + + if (isset($this->fk_product)) $this->fk_product=trim($this->fk_product); + if (isset($this->file_name)) $this->file_name=trim($this->file_name); + if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author); + if (isset($this->fk_user_mod)) $this->fk_user_mod=trim($this->fk_user_mod); + if (isset($this->lang)) $this->lang=trim($this->lang); + if (isset($this->import_key)) $this->import_key=trim($this->import_key); + + + + // Check parameters + // Put here code to add control on parameters values + + // Insert request + $sql = "INSERT INTO ".MAIN_DB_PREFIX."propal_merge_pdf_product("; + + $sql.= "fk_product,"; + $sql.= "file_name,"; + if ($conf->global->MAIN_MULTILANGS) { + $sql.= "lang,"; + } + $sql.= "fk_user_author,"; + $sql.= "fk_user_mod,"; + $sql.= "datec"; + + + $sql.= ") VALUES ("; + + $sql.= " ".(! isset($this->fk_product)?'NULL':"'".$this->fk_product."'").","; + $sql.= " ".(! isset($this->file_name)?'NULL':"'".$this->db->escape($this->file_name)."'").","; + if ($conf->global->MAIN_MULTILANGS) { + $sql.= " ".(! isset($this->lang)?'NULL':"'".$this->db->escape($this->lang)."'").","; + } + $sql.= " ".$user->id.","; + $sql.= " ".$user->id.","; + $sql.= " '".$this->db->idate(dol_now())."'"; + + + $sql.= ")"; + + $this->db->begin(); + + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."propal_merge_pdf_product"); + + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return $this->id; + } + } + + + /** + * Load object in memory from the database + * + * @param int $id Id object + * @return int <0 if KO, >0 if OK + */ + function fetch($id) + { + global $langs,$conf; + + $sql = "SELECT"; + $sql.= " t.rowid,"; + + $sql.= " t.fk_product,"; + $sql.= " t.file_name,"; + $sql.= " t.lang,"; + $sql.= " t.fk_user_author,"; + $sql.= " t.fk_user_mod,"; + $sql.= " t.datec,"; + $sql.= " t.tms,"; + $sql.= " t.import_key"; + + + $sql.= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t"; + $sql.= " WHERE t.rowid = ".$id; + + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + + $this->fk_product = $obj->fk_product; + $this->file_name = $obj->file_name; + if ($conf->global->MAIN_MULTILANGS) { + $this->lang = $obj->lang; + } + $this->fk_user_author = $obj->fk_user_author; + $this->fk_user_mod = $obj->fk_user_mod; + $this->datec = $this->db->jdate($obj->datec); + $this->tms = $this->db->jdate($obj->tms); + $this->import_key = $obj->import_key; + + + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); + return -1; + } + } + + /** + * Load object in memory from the database + * + * @param int $id Id object + * @param string $lang lang string id + * @return int <0 if KO, >0 if OK + */ + function fetch_by_product($product_id, $lang='') + { + global $langs,$conf; + + $sql = "SELECT"; + $sql.= " t.rowid,"; + + $sql.= " t.fk_product,"; + $sql.= " t.file_name,"; + $sql.= " t.lang,"; + $sql.= " t.fk_user_author,"; + $sql.= " t.fk_user_mod,"; + $sql.= " t.datec,"; + $sql.= " t.tms,"; + $sql.= " t.import_key"; + + + $sql.= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t"; + $sql.= " WHERE t.fk_product = ".$product_id; + if ($conf->global->MAIN_MULTILANGS && !empty($lang)) { + $sql.= " AND t.lang = '".$lang."'"; + } + + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + while($obj = $this->db->fetch_object($resql)) { + + $line = new PropalmergepdfproductLine(); + + $line->id = $obj->rowid; + + $line->fk_product = $obj->fk_product; + $line->file_name = $obj->file_name; + if ($conf->global->MAIN_MULTILANGS) { + $line->lang = $obj->lang; + } + $line->fk_user_author = $obj->fk_user_author; + $line->fk_user_mod = $obj->fk_user_mod; + $line->datec = $this->db->jdate($obj->datec); + $line->tms = $this->db->jdate($obj->tms); + $line->import_key = $obj->import_key; + + + if ($conf->global->MAIN_MULTILANGS) { + $this->lines[$obj->file_name.'_'.$obj->lang]=$line; + }else { + $this->lines[$obj->file_name]=$line; + } + + + } + + + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::fetch_by_product ".$this->error, LOG_ERR); + return -1; + } + } + + + /** + * Update object into database + * + * @param User $user User that modifies + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + function update($user=0, $notrigger=0) + { + global $conf, $langs; + $error=0; + + // Clean parameters + + if (isset($this->fk_product)) $this->fk_product=trim($this->fk_product); + if (isset($this->file_name)) $this->file_name=trim($this->file_name); + if (isset($this->fk_user_mod)) $this->fk_user_mod=trim($this->fk_user_mod); + if (isset($this->lang)) $this->lang=trim($this->lang); + + + + + // Check parameters + // Put here code to add a control on parameters values + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."propal_merge_pdf_product SET"; + + $sql.= " fk_product=".(isset($this->fk_product)?$this->fk_product:"null").","; + $sql.= " file_name=".(isset($this->file_name)?"'".$this->db->escape($this->file_name)."'":"null").","; + if ($conf->global->MAIN_MULTILANGS) { + $sql.= " lang=".(isset($this->lang)?"'".$this->db->escape($this->lang)."'":"null").","; + } + $sql.= " fk_user_mod=".$user->id; + + + $sql.= " WHERE rowid=".$this->id; + + $this->db->begin(); + + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + /** + * Delete object in database + * + * @param User $user User that deletes + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + function delete($user, $notrigger=0) + { + global $conf, $langs; + $error=0; + + $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 + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product"; + $sql.= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + /** + * Delete object in database + * + * @param User $user User that deletes + * @param int $product_id product_id + * @param string $lang_id language + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + function delete_by_product($user, $product_id, $lang_id='', $notrigger=0) + { + global $conf, $langs; + $error=0; + + $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 + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product"; + $sql.= " WHERE fk_product=".$product_id; + + if ($conf->global->MAIN_MULTILANGS && !empty($lang_id)) { + $sql.= " AND lang='".$lang_id."'"; + } + + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + /** + * Delete object in database + * + * @param User $user User that deletes + * @return int <0 if KO, >0 if OK + */ + function delete_by_file($user) + { + global $conf, $langs; + $error=0; + + $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 + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product"; + $sql.= " WHERE fk_product=".$this->fk_product." AND file_name='".$this->db->escape($this->file_name)."'"; + + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + + /** + * Load an object from its id and create a new one in database + * + * @param int $fromid Id of object to clone + * @return int New id of clone + */ + function createFromClone($fromid) + { + global $user,$langs; + + $error=0; + + $object=new Propalmergepdfproduct($this->db); + + $this->db->begin(); + + // Load source object + $object->fetch($fromid); + $object->id=0; + $object->statut=0; + + // Clear fields + // ... + + // Create clone + $result=$object->create($user); + + // Other options + if ($result < 0) + { + $this->error=$object->error; + $error++; + } + + if (! $error) + { + + + } + + // End + if (! $error) + { + $this->db->commit(); + return $object->id; + } + else + { + $this->db->rollback(); + return -1; + } + } + + + /** + * Initialise object with example values + * Id must be 0 if object instance is a specimen + * + * @return void + */ + function initAsSpecimen() + { + $this->id=0; + + $this->fk_product=''; + $this->file_name=''; + $this->fk_user_author=''; + $this->fk_user_mod=''; + $this->datec=''; + $this->tms=''; + $this->import_key=''; + + + } + +} + +class PropalmergepdfproductLine{ + var $id; + + var $fk_product; + var $file_name; + var $lang; + var $fk_user_author; + var $fk_user_mod; + var $datec=''; + var $tms=''; + var $import_key; + + function __construct() { + return 1; + } + +} diff --git a/htdocs/product/document.php b/htdocs/product/document.php index 810a131be60..615f4accf70 100644 --- a/htdocs/product/document.php +++ b/htdocs/product/document.php @@ -33,6 +33,8 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL)) + require_once DOL_DOCUMENT_ROOT.'/product/class/propalmergepdfproduct.class.php'; $langs->load("other"); $langs->load("products"); @@ -84,8 +86,70 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { + //Delete line if product propal merge is linked to a file + if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL)) { + if ($action == 'confirm_deletefile' && $confirm == 'yes') + { + print 'toto'; + //extract file name + $urlfile = GETPOST('urlfile', 'alpha'); + $filename = basename($urlfile); + $filetomerge = new Propalmergepdfproduct($db); + $filetomerge->fk_product=$object->id; + $filetomerge->file_name=$filename; + $result=$filetomerge->delete_by_file($user); + if ($result<0) { + setEventMessage($filetomerge->error,'errors'); + } + } + } + // Action sending file include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_pre_headers.tpl.php'; + +} + +if ($action=='filemerge') { + $is_refresh = GETPOST('refresh'); + if (empty($is_refresh)) { + + $filetomerge_file_array = GETPOST('filetoadd'); + + $filetomerge_file_array = GETPOST('filetoadd'); + + if ($conf->global->MAIN_MULTILANGS) { + $lang_id = GETPOST('lang_id'); + } + + // Delete all file already associated + $filetomerge = new Propalmergepdfproduct($db); + + if ($conf->global->MAIN_MULTILANGS) { + $result=$filetomerge->delete_by_product($user, $object->id, $lang_id); + } else { + $result=$filetomerge->delete_by_product($user, $object->id); + } + if ($result<0) { + setEventMessage($filetomerge->error,'errors'); + } + + // for each file checked add it to the product + if (is_array($filetomerge_file_array)) { + foreach ( $filetomerge_file_array as $filetomerge_file ) { + $filetomerge->fk_product = $object->id; + $filetomerge->file_name = $filetomerge_file; + + if ($conf->global->MAIN_MULTILANGS) { + $filetomerge->lang = $lang_id; + } + + $result=$filetomerge->create($user); + if ($result<0) { + setEventMessage($filetomerge->error,'errors'); + } + } + } + } } @@ -142,13 +206,139 @@ if ($object->id) print ''.$langs->trans("NbOfAttachedFiles").''.count($filearray).''; print ''.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").''; print ''; - + print ''; $modulepart = 'produit'; $permission = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer)); $param = '&id=' . $object->id; include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; + + + //Merge propal PDF docuemnt PDF files + if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL)) + { + $filetomerge = new Propalmergepdfproduct($db); + + if ($conf->global->MAIN_MULTILANGS) { + $lang_id = GETPOST('lang_id'); + $result = $filetomerge->fetch_by_product($object->id, $lang_id); + } else { + $result = $filetomerge->fetch_by_product($object->id); + } + + $form = new Form($db); + + $filearray = dol_dir_list($upload_dir, "files", 0, '', '\.meta$', 'name', SORT_ASC, 1); + + // For each file build select list with PDF extention + if (count($filearray) > 0) { + print '
'; + // Actual file to merge is : + if (count($filetomerge->lines) > 0) { + print $langs->trans('PropalMergePdfProductActualFile'); + } + + print '
'; + print ''; + print ''; + if (count($filetomerge->lines) == 0) { + print $langs->trans('PropalMergePdfProductChooseFile'); + } + + print ''; + + // Get language + if ($conf->global->MAIN_MULTILANGS) { + + $langs->load("languages"); + + print ''; + } + + $style = 'impair'; + foreach ( $filearray as $filetoadd ) { + + if ($ext = pathinfo($filetoadd['name'], PATHINFO_EXTENSION) == 'pdf') { + + if ($style == 'pair') { + $style = 'impair'; + } else { + $style = 'pair'; + } + + $checked = ''; + $filename = $filetoadd['name']; + + if ($conf->global->MAIN_MULTILANGS) { + if (array_key_exists($filetoadd['name'] . '_' . $delauft_lang, $filetomerge->lines)) { + $filename = $filetoadd['name'] . ' - ' . $langs->trans('Language_' . $delauft_lang); + $checked = ' checked="checked" '; + } + } else { + if (array_key_exists($filetoadd['name'], $filetomerge->lines)) { + $checked = ' checked="checked" '; + } + } + + print ''; + } + } + print ''; + print '
'; + + $delauft_lang = (empty($lang_id)) ? $langs->getDefaultLang() : $lang_id; + + $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 12); + + print ''; + + if ($conf->global->MAIN_MULTILANGS) { + print ''; + } + + print '
'; + + print '' . $filename . ''; + print '
'; + + print ''; + print '
'; + + print '
'; + } + } + } else { @@ -157,4 +347,4 @@ else llxFooter(); -$db->close(); +$db->close(); \ No newline at end of file