From 078d01b4ee38f45a3f736ce101bad1e2d2359739 Mon Sep 17 00:00:00 2001 From: Grand Philippe Date: Sat, 21 Apr 2012 18:31:20 +0200 Subject: [PATCH] Prepair to display receiptdocument within a custom place and uniformize code --- htdocs/admin/livraison.php | 222 +++++++++++++++++-------------------- 1 file changed, 99 insertions(+), 123 deletions(-) diff --git a/htdocs/admin/livraison.php b/htdocs/admin/livraison.php index f0c857a7ca2..01b60b15c97 100644 --- a/htdocs/admin/livraison.php +++ b/htdocs/admin/livraison.php @@ -6,6 +6,7 @@ * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2011-2012 Juanjo Menent + * Copyright (C) 2011-2012 Philippe Grand * * 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 @@ -36,8 +37,11 @@ $langs->load("deliveries"); if (!$user->admin) accessforbidden(); -$action = GETPOST('action','alpha'); -$value = GETPOST('value','alpha'); +$action = GETPOST('action','alpha'); +$value = GETPOST('value','alpha'); +$label = GETPOST('label','alpha'); +$scandir = GETPOST('scandir','alpha'); +$type='delivery'; /* * Actions @@ -61,105 +65,6 @@ if ($action == 'updateMask') } } -if ($action == 'specimen') -{ - $modele=GETPOST('module','alpha'); - - $sending = new Livraison($db); - $sending->initAsSpecimen(); - //$sending->fetch_commande(); - - // Charge le modele - $dir = DOL_DOCUMENT_ROOT . "/core/modules/livraison/pdf/"; - $file = "pdf_".$modele.".modules.php"; - if (file_exists($dir.$file)) - { - $classname = "pdf_".$modele; - require_once($dir.$file); - - $obj = new $classname($db); - - if ($obj->write_file($sending,$langs) > 0) - { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=livraison&file=SPECIMEN.pdf"); - return; - } - else - { - $mesg=''.$obj->error.''; - dol_syslog($obj->error, LOG_ERR); - } - } - else - { - $mesg=''.$langs->trans("ErrorModuleNotFound").''; - dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); - } -} - -if ($action == 'set') -{ - $label = GETPOST('label','alpha'); - $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') -{ - $type='delivery'; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; - $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 ($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)) - { - $conf->global->LIVRAISON_ADDON_PDF = $value; - } - - // On active le modele - $type='delivery'; - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; - $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(); - } -} - if ($action == 'set_DELIVERY_FREE_TEXT') { $free=GETPOST('DELIVERY_FREE_TEXT','alpha'); @@ -177,6 +82,82 @@ if ($action == 'set_DELIVERY_FREE_TEXT') } } +if ($action == 'specimen') +{ + $modele=GETPOST('module','alpha'); + + $sending = new Livraison($db); + $sending->initAsSpecimen(); + + // Search template files + $file=''; $classname=''; $filefound=0; + $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); + 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; + break; + } + } + + if ($filefound) + { + require_once($file); + + $module = new $classname($db); + + if ($module->write_file($sending,$langs) > 0) + { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=livraison&file=SPECIMEN.pdf"); + return; + } + else + { + $mesg=''.$module->error.''; + dol_syslog($module->error, LOG_ERR); + } + } + else + { + $mesg=''.$langs->trans("ErrorModuleNotFound").''; + dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); + } +} + +if ($action == 'set') +{ + $ret = addDocumentModel($value, $type, $label, $scandir); +} + +if ($action == 'del') +{ + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + if ($conf->global->LIVRAISON_ADDON_PDF == "$value") dolibarr_del_const($db, 'LIVRAISON_ADDON_PDF',$conf->entity); + } +} + +if ($action == 'setdoc') +{ + 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; + } + + // On active le modele + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + $ret = addDocumentModel($value, $type, $label, $scandir); + } +} + if ($action == 'setmod') { // TODO Verifier si module numerotation choisi peut etre active @@ -190,10 +171,12 @@ if ($action == 'setmod') * View */ -$form=new Form($db); +$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); llxHeader("",""); +$form=new Form($db); + $linkback=''.$langs->trans("BackToModuleList").''; print_fiche_titre($langs->trans("SendingsSetup"),$linkback,'setup'); print '
'; @@ -236,9 +219,9 @@ print ''."\n"; 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)) { @@ -365,9 +348,10 @@ print "\n"; 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)) { @@ -382,7 +366,8 @@ foreach ($conf->file->dol_document_root as $dirroot) $classname = substr($file, 0, dol_strlen($file) - 12); $var=!$var; - print ""; + + print ''; print $name; print "\n"; require_once($dir.$file); @@ -394,17 +379,10 @@ foreach ($conf->file->dol_document_root as $dirroot) // Activ if (in_array($name, $def)) { - print "\n"; - //if ($conf->global->LIVRAISON_ADDON_PDF != "$name") - //{ - print 'scandir.'&label='.urlencode($module->name).'">'; - print img_picto($langs->trans("Enabled"),'switch_on'); - print ''; - //} - //else - //{ - // print img_picto($langs->trans("Enabled"),'switch_on'); - //} + print "\n"; + print 'scandir.'&label='.urlencode($module->name).'">'; + print img_picto($langs->trans("Enabled"),'switch_on'); + print ''; print ""; } else @@ -447,11 +425,9 @@ foreach ($conf->file->dol_document_root as $dirroot) } print ''; - /* -* -* -*/ + * Autres Options + */ print "
"; print_titre($langs->trans("OtherOptions")); @@ -482,4 +458,4 @@ dol_htmloutput_mesg($mesg); $db->close(); llxFooter(); -?> +?> \ No newline at end of file