Skip to content
Snippets Groups Projects
Commit 078d01b4 authored by Philippe Grand's avatar Philippe Grand
Browse files

Prepair to display receiptdocument within a custom place and uniformize code

parent 3afbd182
Branches
Tags
No related merge requests found
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2011-2012 Philippe Grand <philippe.grand@atoo-net.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -38,6 +39,9 @@ if (!$user->admin) accessforbidden(); ...@@ -38,6 +39,9 @@ if (!$user->admin) accessforbidden();
$action = GETPOST('action','alpha'); $action = GETPOST('action','alpha');
$value = GETPOST('value','alpha'); $value = GETPOST('value','alpha');
$label = GETPOST('label','alpha');
$scandir = GETPOST('scandir','alpha');
$type='delivery';
/* /*
* Actions * Actions
...@@ -61,33 +65,59 @@ if ($action == 'updateMask') ...@@ -61,33 +65,59 @@ if ($action == 'updateMask')
} }
} }
if ($action == 'set_DELIVERY_FREE_TEXT')
{
$free=GETPOST('DELIVERY_FREE_TEXT','alpha');
$res=dolibarr_set_const($db, "DELIVERY_FREE_TEXT",$free,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
if (! $error)
{
$mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
}
else
{
$mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
}
}
if ($action == 'specimen') if ($action == 'specimen')
{ {
$modele=GETPOST('module','alpha'); $modele=GETPOST('module','alpha');
$sending = new Livraison($db); $sending = new Livraison($db);
$sending->initAsSpecimen(); $sending->initAsSpecimen();
//$sending->fetch_commande();
// Charge le modele // Search template files
$dir = DOL_DOCUMENT_ROOT . "/core/modules/livraison/pdf/"; $file=''; $classname=''; $filefound=0;
$file = "pdf_".$modele.".modules.php"; $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
if (file_exists($dir.$file)) foreach($dirmodels as $reldir)
{
$file=dol_buildpath($reldir."core/modules/livraison/pdf/pdf_".$modele.".modules.php",0);
if (file_exists($file))
{ {
$filefound=1;
$classname = "pdf_".$modele; $classname = "pdf_".$modele;
require_once($dir.$file); break;
}
}
if ($filefound)
{
require_once($file);
$obj = new $classname($db); $module = new $classname($db);
if ($obj->write_file($sending,$langs) > 0) if ($module->write_file($sending,$langs) > 0)
{ {
header("Location: ".DOL_URL_ROOT."/document.php?modulepart=livraison&file=SPECIMEN.pdf"); header("Location: ".DOL_URL_ROOT."/document.php?modulepart=livraison&file=SPECIMEN.pdf");
return; return;
} }
else else
{ {
$mesg='<font class="error">'.$obj->error.'</font>'; $mesg='<font class="error">'.$module->error.'</font>';
dol_syslog($obj->error, LOG_ERR); dol_syslog($module->error, LOG_ERR);
} }
} }
else else
...@@ -99,27 +129,13 @@ if ($action == 'specimen') ...@@ -99,27 +129,13 @@ if ($action == 'specimen')
if ($action == 'set') if ($action == 'set')
{ {
$label = GETPOST('label','alpha'); $ret = addDocumentModel($value, $type, $label, $scandir);
$scandir = GETPOST('scandir','alpha');
$type='delivery';
$sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
$sql.= " VALUES ('".$db->escape($value)."','".$type."',".$conf->entity.", ";
$sql.= ($label?"'".$db->escape($label)."'":'null').", ";
$sql.= (! empty($scandir)?"'".$db->escape($scandir)."'":"null");
$sql.= ")";
$resql=$db->query($sql);
} }
if ($action == 'del') if ($action == 'del')
{ {
$type='delivery'; $ret = delDocumentModel($value, $type);
$sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; if ($ret > 0)
$sql.= " WHERE nom = '".$db->escape($value)."'";
$sql.= " AND type = '".$type."'";
$sql.= " AND entity = ".$conf->entity;
if ($db->query($sql))
{ {
if ($conf->global->LIVRAISON_ADDON_PDF == "$value") dolibarr_del_const($db, 'LIVRAISON_ADDON_PDF',$conf->entity); if ($conf->global->LIVRAISON_ADDON_PDF == "$value") dolibarr_del_const($db, 'LIVRAISON_ADDON_PDF',$conf->entity);
} }
...@@ -127,53 +143,18 @@ if ($action == 'del') ...@@ -127,53 +143,18 @@ if ($action == 'del')
if ($action == 'setdoc') if ($action == 'setdoc')
{ {
$label = GETPOST('label','alpha');
$scandir = GETPOST('scandir','alpha');
$db->begin();
if (dolibarr_set_const($db, "LIVRAISON_ADDON_PDF",$value,'chaine',0,'',$conf->entity)) if (dolibarr_set_const($db, "LIVRAISON_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
{ {
// La constante qui a ete lue en avant du nouveau set
// on passe donc par une variable pour avoir un affichage coherent
$conf->global->LIVRAISON_ADDON_PDF = $value; $conf->global->LIVRAISON_ADDON_PDF = $value;
} }
// On active le modele // On active le modele
$type='delivery'; $ret = delDocumentModel($value, $type);
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; if ($ret > 0)
$sql_del.= " WHERE nom = '".$db->escape($value)."'";
$sql_del.= " AND type = '".$type."'";
$sql_del.= " AND entity = ".$conf->entity;
$result1=$db->query($sql_del);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
$sql.= " VALUES ('".$db->escape($value)."', '".$type."', ".$conf->entity.", ";
$sql.= ($label?"'".$db->escape($label)."'":'null').", ";
$sql.= (! empty($scandir)?"'".$db->escape($scandir)."'":"null");
$sql.= ")";
$result2=$db->query($sql);
if ($result1 && $result2)
{
$db->commit();
}
else
{ {
$db->rollback(); $ret = addDocumentModel($value, $type, $label, $scandir);
}
}
if ($action == 'set_DELIVERY_FREE_TEXT')
{
$free=GETPOST('DELIVERY_FREE_TEXT','alpha');
$res=dolibarr_set_const($db, "DELIVERY_FREE_TEXT",$free,'chaine',0,'',$conf->entity);
if (! $res > 0) $error++;
if (! $error)
{
$mesg = "<font class=\"ok\">".$langs->trans("SetupSaved")."</font>";
}
else
{
$mesg = "<font class=\"error\">".$langs->trans("Error")."</font>";
} }
} }
...@@ -190,10 +171,12 @@ if ($action == 'setmod') ...@@ -190,10 +171,12 @@ if ($action == 'setmod')
* View * View
*/ */
$form=new Form($db); $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
llxHeader("",""); llxHeader("","");
$form=new Form($db);
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>'; $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print_fiche_titre($langs->trans("SendingsSetup"),$linkback,'setup'); print_fiche_titre($langs->trans("SendingsSetup"),$linkback,'setup');
print '<br>'; print '<br>';
...@@ -236,9 +219,9 @@ print '</tr>'."\n"; ...@@ -236,9 +219,9 @@ print '</tr>'."\n";
clearstatcache(); clearstatcache();
foreach ($conf->file->dol_document_root as $dirroot) foreach ($dirmodels as $reldir)
{ {
$dir = $dirroot . "/core/modules/livraison/"; $dir = dol_buildpath($reldir."core/modules/livraison/");
if (is_dir($dir)) if (is_dir($dir))
{ {
...@@ -365,9 +348,10 @@ print "</tr>\n"; ...@@ -365,9 +348,10 @@ print "</tr>\n";
clearstatcache(); clearstatcache();
foreach ($conf->file->dol_document_root as $dirroot) $var=true;
foreach ($dirmodels as $reldir)
{ {
$dir = $dirroot . "/core/modules/livraison/pdf/"; $dir = dol_buildpath($reldir."core/modules/livraison/pdf/");
if (is_dir($dir)) if (is_dir($dir))
{ {
...@@ -382,7 +366,8 @@ foreach ($conf->file->dol_document_root as $dirroot) ...@@ -382,7 +366,8 @@ foreach ($conf->file->dol_document_root as $dirroot)
$classname = substr($file, 0, dol_strlen($file) - 12); $classname = substr($file, 0, dol_strlen($file) - 12);
$var=!$var; $var=!$var;
print "<tr $bc[$var]><td>";
print '<tr '.$bc[$var].'><td>';
print $name; print $name;
print "</td><td>\n"; print "</td><td>\n";
require_once($dir.$file); require_once($dir.$file);
...@@ -395,16 +380,9 @@ foreach ($conf->file->dol_document_root as $dirroot) ...@@ -395,16 +380,9 @@ foreach ($conf->file->dol_document_root as $dirroot)
if (in_array($name, $def)) if (in_array($name, $def))
{ {
print "<td align=\"center\">\n"; print "<td align=\"center\">\n";
//if ($conf->global->LIVRAISON_ADDON_PDF != "$name")
//{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'; print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
print img_picto($langs->trans("Enabled"),'switch_on'); print img_picto($langs->trans("Enabled"),'switch_on');
print '</a>'; print '</a>';
//}
//else
//{
// print img_picto($langs->trans("Enabled"),'switch_on');
//}
print "</td>"; print "</td>";
} }
else else
...@@ -447,10 +425,8 @@ foreach ($conf->file->dol_document_root as $dirroot) ...@@ -447,10 +425,8 @@ foreach ($conf->file->dol_document_root as $dirroot)
} }
print '</table>'; print '</table>';
/* /*
* * Autres Options
*
*/ */
print "<br>"; print "<br>";
print_titre($langs->trans("OtherOptions")); print_titre($langs->trans("OtherOptions"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment