From d26024d8fc44009e1366139408f1646ca71f5faf Mon Sep 17 00:00:00 2001 From: frederic34 Date: Thu, 21 Feb 2013 23:40:25 +0100 Subject: [PATCH] WIP : Admin for Carriers (Activate/Desactivate) --- htdocs/admin/carrier.php | 140 +++++++ htdocs/admin/confexped.php | 4 + htdocs/admin/expedition.php | 10 +- htdocs/admin/livraison.php | 370 ++++++++++--------- htdocs/expedition/class/expedition.class.php | 59 +++ 5 files changed, 397 insertions(+), 186 deletions(-) create mode 100644 htdocs/admin/carrier.php diff --git a/htdocs/admin/carrier.php b/htdocs/admin/carrier.php new file mode 100644 index 00000000000..5b8eb3724cc --- /dev/null +++ b/htdocs/admin/carrier.php @@ -0,0 +1,140 @@ +. + */ + +/** + * \file htdocs/admin/carrier.php + * \ingroup expedition + * \brief Page d'administration des Transporteurs + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; + +$langs->load("admin"); +$langs->load("sendings"); +$langs->load("deliveries"); +$langs->load('other'); + +if (! $user->admin) + accessforbidden(); + +$action=GETPOST('action','alpha'); +$carrier=GETPOST('carrier','int'); + +$object = new Expedition($db); + + +/* + * Actions + */ + +if ($action==activate_carrier AND $carrier) +{ + $object->activ_delivery_method($carrier); +} + +if ($action==disable_carrier AND $carrier) +{ + $object->disable_delivery_method($carrier); +} + +/* + * View + */ + +$form=new Form($db); + +llxHeader("",""); + +$linkback=''.$langs->trans("BackToModuleList").''; +print_fiche_titre($langs->trans("SendingsSetup"),$linkback,'setup'); +print '
'; + + +//if ($mesg) print $mesg.'
'; + + +$h = 0; + +$head[$h][0] = DOL_URL_ROOT."/admin/confexped.php"; +$head[$h][1] = $langs->trans("Setup"); +$h++; + +$head[$h][0] = DOL_URL_ROOT."/admin/carrier.php"; +$head[$h][1] = $langs->trans("Carriers"); +$hselected=$h; +$h++; + +if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION)) +{ + $head[$h][0] = DOL_URL_ROOT."/admin/expedition.php"; + $head[$h][1] = $langs->trans("Sending"); + $h++; +} + +if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) +{ + $head[$h][0] = DOL_URL_ROOT."/admin/livraison.php"; + $head[$h][1] = $langs->trans("Receivings"); + $h++; +} + +dol_fiche_head($head, $hselected, $langs->trans("ModuleSetup")); + +/* + * Carrier List + */ + +$object->all_delivery_methods(); +$var=true; +print_titre($langs->trans("CarrierList")); + +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; +for ($i=0; $ilistmeths); $i++) +{ + $var=!$var; + print ""; + print ''; + print ''; + print ''; + print ''; + print ''; +print "\n"; + +print '
'.$langs->trans("Code").''.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("TracingUrl").''.$langs->trans("Status").'
'.$object->listmeths[$i][code].''.$object->listmeths[$i][libelle].''.$object->listmeths[$i][description].''.$object->listmeths[$i][tracing].''; + if($object->listmeths[$i][active] == 0) + { + print ''.img_picto($langs->trans("Disabled"),'switch_off').''; + } + else + { + print ''.img_picto($langs->trans("Enabled"),'switch_on').''; + } +} +print '

'; + +llxFooter(); + +$db->close(); +?> \ No newline at end of file diff --git a/htdocs/admin/confexped.php b/htdocs/admin/confexped.php index d9be768461f..6653badfb36 100644 --- a/htdocs/admin/confexped.php +++ b/htdocs/admin/confexped.php @@ -84,6 +84,10 @@ $head[$h][1] = $langs->trans("Setup"); $hselected=$h; $h++; +$head[$h][0] = DOL_URL_ROOT."/admin/carrier.php"; +$head[$h][1] = $langs->trans("Carriers"); +$h++; + if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION)) { $head[$h][0] = DOL_URL_ROOT."/admin/expedition.php"; diff --git a/htdocs/admin/expedition.php b/htdocs/admin/expedition.php index 709832b1968..c012d52efb1 100644 --- a/htdocs/admin/expedition.php +++ b/htdocs/admin/expedition.php @@ -201,6 +201,10 @@ $head[$h][0] = DOL_URL_ROOT."/admin/confexped.php"; $head[$h][1] = $langs->trans("Setup"); $h++; +$head[$h][0] = DOL_URL_ROOT."/admin/carrier.php"; +$head[$h][1] = $langs->trans("Carriers"); +$h++; + $head[$h][0] = DOL_URL_ROOT."/admin/expedition.php"; $head[$h][1] = $langs->trans("Sending"); $hselected=$h; @@ -208,9 +212,9 @@ $h++; if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) { - $head[$h][0] = DOL_URL_ROOT."/admin/livraison.php"; - $head[$h][1] = $langs->trans("Receivings"); - $h++; + $head[$h][0] = DOL_URL_ROOT."/admin/livraison.php"; + $head[$h][1] = $langs->trans("Receivings"); + $h++; } dol_fiche_head($head, $hselected, $langs->trans("ModuleSetup")); diff --git a/htdocs/admin/livraison.php b/htdocs/admin/livraison.php index 2603a0a1d51..fa4b7b3c1d4 100644 --- a/htdocs/admin/livraison.php +++ b/htdocs/admin/livraison.php @@ -5,8 +5,8 @@ * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2011-2012 Juanjo Menent - * Copyright (C) 2011-2012 Philippe Grand + * 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 @@ -50,13 +50,13 @@ $type='delivery'; if ($action == 'updateMask') { - $maskconstdelivery=GETPOST('maskconstdelivery','alpha'); - $maskdelivery=GETPOST('maskdelivery','alpha'); - if ($maskconstdelivery) $res = dolibarr_set_const($db,$maskconstdelivery,$maskdelivery,'chaine',0,'',$conf->entity); + $maskconstdelivery=GETPOST('maskconstdelivery','alpha'); + $maskdelivery=GETPOST('maskdelivery','alpha'); + if ($maskconstdelivery) $res = dolibarr_set_const($db,$maskconstdelivery,$maskdelivery,'chaine',0,'',$conf->entity); - if (! $res > 0) $error++; + if (! $res > 0) $error++; - if (! $error) + if (! $error) { $mesg = "".$langs->trans("SetupSaved").""; } @@ -68,12 +68,12 @@ if ($action == 'updateMask') if ($action == 'set_DELIVERY_FREE_TEXT') { - $free=GETPOST('DELIVERY_FREE_TEXT','alpha'); + $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) + if (! $error) { $mesg = "".$langs->trans("SetupSaved").""; } @@ -85,58 +85,58 @@ if ($action == 'set_DELIVERY_FREE_TEXT') if ($action == 'specimen') { - $modele=GETPOST('module','alpha'); + $modele=GETPOST('module','alpha'); - $sending = new Livraison($db); - $sending->initAsSpecimen(); + $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; - } - } + // 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; + if ($filefound) + { + require_once $file; - $module = new $classname($db); + $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 ($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); +{ + $ret = addDocumentModel($value, $type, $label, $scandir); } if ($action == 'del') { $ret = delDocumentModel($value, $type); - if ($ret > 0) + if ($ret > 0) { if ($conf->global->LIVRAISON_ADDON_PDF == "$value") dolibarr_del_const($db, 'LIVRAISON_ADDON_PDF',$conf->entity); } @@ -146,17 +146,17 @@ 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 + // 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); - } + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + $ret = addDocumentModel($value, $type, $label, $scandir); + } } if ($action == 'setmod') @@ -164,7 +164,7 @@ if ($action == 'setmod') // TODO Verifier si module numerotation choisi peut etre active // par appel methode canBeActivated - dolibarr_set_const($db, "LIVRAISON_ADDON",$value,'chaine',0,'',$conf->entity); + dolibarr_set_const($db, "LIVRAISON_ADDON",$value,'chaine',0,'',$conf->entity); } @@ -189,11 +189,15 @@ $head[$h][0] = DOL_URL_ROOT."/admin/confexped.php"; $head[$h][1] = $langs->trans("Setup"); $h++; +$head[$h][0] = DOL_URL_ROOT."/admin/carrier.php"; +$head[$h][1] = $langs->trans("Carriers"); +$h++; + if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION)) { - $head[$h][0] = DOL_URL_ROOT."/admin/expedition.php"; - $head[$h][1] = $langs->trans("Sending"); - $h++; + $head[$h][0] = DOL_URL_ROOT."/admin/expedition.php"; + $head[$h][1] = $langs->trans("Sending"); + $h++; } $head[$h][0] = DOL_URL_ROOT."/admin/livraison.php"; @@ -222,34 +226,34 @@ clearstatcache(); foreach ($dirmodels as $reldir) { - $dir = dol_buildpath($reldir."core/modules/livraison/"); + $dir = dol_buildpath($reldir."core/modules/livraison/"); - if (is_dir($dir)) - { - $handle = opendir($dir); - if (is_resource($handle)) - { - $var=true; - while (($file = readdir($handle))!==false) - { - if (substr($file, 0, 14) == 'mod_livraison_' && substr($file, dol_strlen($file)-3, 3) == 'php') - { - $file = substr($file, 0, dol_strlen($file)-4); + if (is_dir($dir)) + { + $handle = opendir($dir); + if (is_resource($handle)) + { + $var=true; + while (($file = readdir($handle))!==false) + { + if (substr($file, 0, 14) == 'mod_livraison_' && substr($file, dol_strlen($file)-3, 3) == 'php') + { + $file = substr($file, 0, dol_strlen($file)-4); - require_once DOL_DOCUMENT_ROOT ."/core/modules/livraison/".$file.'.php'; + require_once DOL_DOCUMENT_ROOT ."/core/modules/livraison/".$file.'.php'; - $module = new $file; + $module = new $file; - // Show modules according to features level - if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; - if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; + // Show modules according to features level + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; - if ($module->isEnabled()) - { - $var=!$var; - print ''.$module->nom."\n"; - print $module->info(); - print ''; + if ($module->isEnabled()) + { + $var=!$var; + print ''.$module->nom."\n"; + print $module->info(); + print ''; // Show example of numbering module print ''; @@ -259,48 +263,48 @@ foreach ($dirmodels as $reldir) else print $tmp; print ''."\n"; - print ''; - if ($conf->global->LIVRAISON_ADDON == "$file") - { - print img_picto($langs->trans("Activated"),'switch_on'); - } - else - { - print ''.img_picto($langs->trans("Disabled"),'switch_off').''; - } - print ''; + print ''; + if ($conf->global->LIVRAISON_ADDON == "$file") + { + print img_picto($langs->trans("Activated"),'switch_on'); + } + else + { + print ''.img_picto($langs->trans("Disabled"),'switch_off').''; + } + print ''; - $livraison=new Livraison($db); - $livraison->initAsSpecimen(); + $livraison=new Livraison($db); + $livraison->initAsSpecimen(); - // Info - $htmltooltip=''; - $htmltooltip.=''.$langs->trans("Version").': '.$module->getVersion().'
'; - $nextval=$module->getNextValue($mysoc,$livraison); - if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval - { - $htmltooltip.=''.$langs->trans("NextValue").': '; - if ($nextval) - { - $htmltooltip.=$nextval.'
'; - } - else - { - $htmltooltip.=$langs->trans($module->error).'
'; - } - } + // Info + $htmltooltip=''; + $htmltooltip.=''.$langs->trans("Version").': '.$module->getVersion().'
'; + $nextval=$module->getNextValue($mysoc,$livraison); + if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval + { + $htmltooltip.=''.$langs->trans("NextValue").': '; + if ($nextval) + { + $htmltooltip.=$nextval.'
'; + } + else + { + $htmltooltip.=$langs->trans($module->error).'
'; + } + } - print ''; - print $form->textwithpicto('',$htmltooltip,1,0); - print ''; + print ''; + print $form->textwithpicto('',$htmltooltip,1,0); + print ''; - print ''; - } - } - } - closedir($handle); - } - } + print ''; + } + } + } + closedir($handle); + } + } } print ''; @@ -352,77 +356,77 @@ clearstatcache(); $var=true; foreach ($dirmodels as $reldir) { - $dir = dol_buildpath($reldir."core/modules/livraison/pdf/"); + $dir = dol_buildpath($reldir."core/modules/livraison/pdf/"); - if (is_dir($dir)) - { - $handle = opendir($dir); - if (is_resource($handle)) - { - while (($file = readdir($handle))!==false) - { - if (substr($file, dol_strlen($file) -12) == '.modules.php' && substr($file,0,4) == 'pdf_') - { - $name = substr($file, 4, dol_strlen($file) - 16); - $classname = substr($file, 0, dol_strlen($file) - 12); + if (is_dir($dir)) + { + $handle = opendir($dir); + if (is_resource($handle)) + { + while (($file = readdir($handle))!==false) + { + if (substr($file, dol_strlen($file) -12) == '.modules.php' && substr($file,0,4) == 'pdf_') + { + $name = substr($file, 4, dol_strlen($file) - 16); + $classname = substr($file, 0, dol_strlen($file) - 12); - $var=!$var; + $var=!$var; - print ''; - print $name; - print "\n"; - require_once $dir.$file; - $module = new $classname($db); + print ''; + print $name; + print "\n"; + require_once $dir.$file; + $module = new $classname($db); - print $module->description; - print ''; + print $module->description; + print ''; - // Activ - if (in_array($name, $def)) - { - print "\n"; - print 'scandir.'&label='.urlencode($module->name).'">'; - print img_picto($langs->trans("Enabled"),'switch_on'); - print ''; - print ""; - } - else - { - print "\n"; - print 'scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').''; - print ""; - } + // Activ + if (in_array($name, $def)) + { + print "\n"; + print 'scandir.'&label='.urlencode($module->name).'">'; + print img_picto($langs->trans("Enabled"),'switch_on'); + print ''; + print ""; + } + else + { + print "\n"; + print 'scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').''; + print ""; + } - // Defaut - print ""; - if ($conf->global->LIVRAISON_ADDON_PDF == "$name") - { - print img_picto($langs->trans("Default"),'on'); - } - else - { - print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').''; - } - print ''; + // Defaut + print ""; + if ($conf->global->LIVRAISON_ADDON_PDF == "$name") + { + print img_picto($langs->trans("Default"),'on'); + } + else + { + print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').''; + } + print ''; - // Info - $htmltooltip = ''.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); - $htmltooltip.='
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; - $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; - $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); - print ''; - print $form->textwithpicto('',$htmltooltip,1,0); - print ''; - print ''; - print ''.img_object($langs->trans("Preview"),'sending').''; - print ''; + // Info + $htmltooltip = ''.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); + $htmltooltip.='
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; + $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; + $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); + print ''; + print $form->textwithpicto('',$htmltooltip,1,0); + print ''; + print ''; + print ''.img_object($langs->trans("Preview"),'sending').''; + print ''; - print ''; - } - } - closedir($handle); - } - } + print ''; + } + } + closedir($handle); + } + } } print ''; diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 1840713b0e6..ca8c5ea2dfe 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1168,6 +1168,65 @@ class Expedition extends CommonObject } } + /** + * Fetch all deliveries method and return an array. Load array this->listmeths. + * + * @return void + */ + function all_delivery_methods() + { + global $langs; + $meths = array(); + $i=0; + + $sql = "SELECT em.rowid, em.code, em.libelle, em.description, em.active"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em"; + //$sql.= " ORDER BY em.libelle ASC"; + + $resql = $this->db->query($sql); + if ($resql) + { + while ($obj = $this->db->fetch_object($resql)) + { + $this->listmeths[$i][rowid] = $obj->rowid; + $this->listmeths[$i][code] = $obj->code; + $label=$langs->trans('SendingMethod'.$obj->code); + $this->listmeths[$i][libelle] = ($label != 'SendingMethod'.$obj->code?$label:$obj->libelle); + $this->listmeths[$i][description] = $obj->description; + $this->listmeths[$i][active] = $obj->active; + $i++; + } + } + } + + /** + * Activate delivery method. + * @param id $id id method to activate + * @return void + */ + function activ_delivery_method($id) + { + $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=1'; + $sql.= ' WHERE rowid='.$id; + + $resql = $this->db->query($sql); + + } + + /** + * DesActivate delivery method. + * @param id $id id method to desactivate + * @return void + */ + function disable_delivery_method($id) + { + $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=0'; + $sql.= ' WHERE rowid='.$id; + + $resql = $this->db->query($sql); + + } + /** * Get tracking url status *