2
0
forked from Wavyzz/dolibarr

Merge pull request #2650 from FHenry/dev_pdfpropalmergeproductpdf

NEW : Propal merge PDF product attached files (on option)
This commit is contained in:
Laurent Destailleur
2015-04-18 20:18:57 +02:00
8 changed files with 961 additions and 3 deletions

View File

@@ -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');

View File

@@ -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;

View File

@@ -0,0 +1,28 @@
-- <Product - Quote - PDF>
-- Copyright (C) 2013 Florian HENRY <florian.henry@open-concept.pro>
--
-- 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/>.
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;

View File

@@ -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).

View File

@@ -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
CorrectlyUpdated=Correctly updated
PropalMergePdfProductActualFile=Files use to add into PDF Azur_plus are/is
PropalMergePdfProductChooseFile=Select PDF files

View File

@@ -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 '</td>';
print '</tr>';
print '</form>';
// Activate propal merge produt card
$var=!$var;
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="mergePropalProductCard">';
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("MergePropalProductCard").'</td>';
print '<td width="60" align="right">';
print $form->selectyesno("activate_mergePropalProductCard",$conf->global->PRODUIT_PDF_MERGE_PROPAL,1);
print '</td><td align="right">';
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print '</td>';
print '</tr>';
print '</form>';
// View product description in thirdparty language
if (! empty($conf->global->MAIN_MULTILANGS))
{

View File

@@ -0,0 +1,656 @@
<?php
/* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2015 Florian HENRY <florian.henry@open-concept.pro>
*
* 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/>.
*/
/**
* \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;
}
}

View File

@@ -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 '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
print '</table>';
print '</div>';
$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 '<br>';
// Actual file to merge is :
if (count($filetomerge->lines) > 0) {
print $langs->trans('PropalMergePdfProductActualFile');
}
print '<form name="filemerge" action="' . DOL_URL_ROOT . '/product/document.php?id=' . $object->id . '" method="post">';
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="filemerge">';
if (count($filetomerge->lines) == 0) {
print $langs->trans('PropalMergePdfProductChooseFile');
}
print '<table class="noborder">';
// Get language
if ($conf->global->MAIN_MULTILANGS) {
$langs->load("languages");
print '<tr class="liste_titre"><td>';
$delauft_lang = (empty($lang_id)) ? $langs->getDefaultLang() : $lang_id;
$langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 12);
print '<select class="flat" id="lang_id" name="lang_id">';
asort($langs_available);
$uncompletelanguages = array (
'da_DA',
'fi_FI',
'hu_HU',
'is_IS',
'pl_PL',
'ro_RO',
'ru_RU',
'sv_SV',
'tr_TR',
'zh_CN'
);
foreach ( $langs_available as $key => $value ) {
if ($showwarning && in_array($key, $uncompletelanguages)) {
// $value.=' - '.$langs->trans("TranslationUncomplete",$key);
}
if ($filter && is_array($filter)) {
if (! array_key_exists($key, $filter)) {
print '<option value="' . $key . '">' . $value . '</option>';
}
} else if ($delauft_lang == $key) {
print '<option value="' . $key . '" selected="selected">' . $value . '</option>';
} else {
print '<option value="' . $key . '">' . $value . '</option>';
}
}
print '</select>';
if ($conf->global->MAIN_MULTILANGS) {
print '<input type="submit" class="button" name="refresh" value="' . $langs->trans('Refresh') . '">';
}
print '</td></tr>';
}
$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 '<tr class="' . $style . '"><td>';
print '<input type="checkbox" ' . $checked . ' name="filetoadd[]" id="filetoadd" value="' . $filetoadd['name'] . '">' . $filename . '</input>';
print '</td></tr>';
}
}
print '<tr><td>';
print '<input type="submit" class="button" name="save" value="' . $langs->trans('Save') . '">';
print '</td></tr>';
print '</table>';
print '</form>';
}
}
}
else
{
@@ -157,4 +347,4 @@ else
llxFooter();
$db->close();
$db->close();