From 87bbcaf9f649b7165a16a54f31f9199ed1458e15 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 21 Oct 2011 11:03:19 +0200 Subject: [PATCH 1/7] Fix: remove obsolete code use objectlinked for retrieve origin and origin_id of an object --- htdocs/compta/facture/class/facture.class.php | 98 ++++++++----------- 1 file changed, 39 insertions(+), 59 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 5db4b42a54e..aa1f4b48816 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -742,11 +742,9 @@ class Facture extends CommonObject $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet'; $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; $sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc'; - $sql.= ', el.fk_source'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id'; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = '".$this->element."'"; $sql.= ' WHERE f.entity = '.$conf->entity; if ($rowid) $sql.= " AND f.rowid=".$rowid; if ($ref) $sql.= " AND f.facnumber='".$this->db->escape($ref)."'"; @@ -761,63 +759,45 @@ class Facture extends CommonObject { $obj = $this->db->fetch_object($result); - $this->id = $obj->rowid; - $this->ref = $obj->facnumber; - $this->ref_client = $obj->ref_client; - $this->ref_ext = $obj->ref_ext; - $this->ref_int = $obj->ref_int; - $this->type = $obj->type; - $this->date = $this->db->jdate($obj->df); - $this->date_creation = $this->db->jdate($obj->datec); - $this->date_validation = $this->db->jdate($obj->datev); - $this->datem = $this->db->jdate($obj->datem); - $this->amount = $obj->amount; - $this->remise_percent = $obj->remise_percent; - $this->remise_absolue = $obj->remise_absolue; - $this->remise = $obj->remise; - $this->total_ht = $obj->total; - $this->total_tva = $obj->tva; - $this->total_localtax1 = $obj->localtax1; - $this->total_localtax2 = $obj->localtax2; - $this->total_ttc = $obj->total_ttc; - $this->paye = $obj->paye; - $this->close_code = $obj->close_code; - $this->close_note = $obj->close_note; - $this->socid = $obj->fk_soc; - $this->statut = $obj->fk_statut; - $this->date_lim_reglement = $this->db->jdate($obj->dlr); - $this->mode_reglement_id = $obj->fk_mode_reglement; - $this->mode_reglement_code = $obj->mode_reglement_code; - $this->mode_reglement = $obj->mode_reglement_libelle; - $this->cond_reglement_id = $obj->fk_cond_reglement; - $this->cond_reglement_code = $obj->cond_reglement_code; - $this->cond_reglement = $obj->cond_reglement_libelle; - $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc; - $this->fk_project = $obj->fk_projet; - $this->fk_facture_source = $obj->fk_facture_source; - $this->note = $obj->note; - $this->note_public = $obj->note_public; - $this->user_author = $obj->fk_user_author; - $this->user_valid = $obj->fk_user_valid; - $this->modelpdf = $obj->model_pdf; - - $this->commande_id = $obj->fk_commande; - - if ($this->commande_id) - { - $sql = "SELECT ref"; - $sql.= " FROM ".MAIN_DB_PREFIX."commande"; - $sql.= " WHERE rowid = ".$this->commande_id; - - $resqlcomm = $this->db->query($sql); - - if ($resqlcomm) - { - $objc = $this->db->fetch_object($resqlcomm); - $this->commande_ref = $objc->ref; - $this->db->free($resqlcomm); - } - } + $this->id = $obj->rowid; + $this->ref = $obj->facnumber; + $this->ref_client = $obj->ref_client; + $this->ref_ext = $obj->ref_ext; + $this->ref_int = $obj->ref_int; + $this->type = $obj->type; + $this->date = $this->db->jdate($obj->df); + $this->date_creation = $this->db->jdate($obj->datec); + $this->date_validation = $this->db->jdate($obj->datev); + $this->datem = $this->db->jdate($obj->datem); + $this->amount = $obj->amount; + $this->remise_percent = $obj->remise_percent; + $this->remise_absolue = $obj->remise_absolue; + $this->remise = $obj->remise; + $this->total_ht = $obj->total; + $this->total_tva = $obj->tva; + $this->total_localtax1 = $obj->localtax1; + $this->total_localtax2 = $obj->localtax2; + $this->total_ttc = $obj->total_ttc; + $this->paye = $obj->paye; + $this->close_code = $obj->close_code; + $this->close_note = $obj->close_note; + $this->socid = $obj->fk_soc; + $this->statut = $obj->fk_statut; + $this->date_lim_reglement = $this->db->jdate($obj->dlr); + $this->mode_reglement_id = $obj->fk_mode_reglement; + $this->mode_reglement_code = $obj->mode_reglement_code; + $this->mode_reglement = $obj->mode_reglement_libelle; + $this->cond_reglement_id = $obj->fk_cond_reglement; + $this->cond_reglement_code = $obj->cond_reglement_code; + $this->cond_reglement = $obj->cond_reglement_libelle; + $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc; + $this->fk_project = $obj->fk_projet; + $this->fk_facture_source = $obj->fk_facture_source; + $this->note = $obj->note; + $this->note_public = $obj->note_public; + $this->user_author = $obj->fk_user_author; + $this->user_valid = $obj->fk_user_valid; + $this->modelpdf = $obj->model_pdf; if ($this->statut == 0) $this->brouillon = 1; From 58708b7cf02129da0a7ee5e3bba85ac72c31f3f5 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 22 Oct 2011 11:56:04 +0200 Subject: [PATCH 2/7] Fix: hide php error message if dir not exist --- htdocs/admin/system/modules.php | 8 ++++---- htdocs/user/perms.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/admin/system/modules.php b/htdocs/admin/system/modules.php index d7f68fbe605..08bcd0329ed 100644 --- a/htdocs/admin/system/modules.php +++ b/htdocs/admin/system/modules.php @@ -1,7 +1,7 @@ - * Copyright (C) 2007 Rodolphe Quiedeville - * Copyright (C) 2010 Regis Houssin +/* Copyright (C) 2005-2009 Laurent Destailleur + * Copyright (C) 2007 Rodolphe Quiedeville + * Copyright (C) 2010-2011 Regis Houssin * * 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 @@ -74,7 +74,7 @@ foreach ($conf->file->dol_document_root as $type => $dirroot) // Load list of modules foreach($modulesdir as $dir) { - $handle=opendir($dir); + $handle=@opendir($dir); if (is_resource($handle)) { while (($file = readdir($handle))!==false) diff --git a/htdocs/user/perms.php b/htdocs/user/perms.php index 0ebbc059b96..618a9a560c4 100644 --- a/htdocs/user/perms.php +++ b/htdocs/user/perms.php @@ -150,7 +150,7 @@ foreach ($conf->file->dol_document_root as $type => $dirroot) foreach($modulesdir as $dir) { - $handle=opendir($dir); + $handle=@opendir($dir); if (is_resource($handle)) { while (($file = readdir($handle))!==false) From 5a20fa8169c3481b99851791275304d4c03e8a92 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 22 Oct 2011 12:27:31 +0200 Subject: [PATCH 3/7] Fix: uniformize code --- htdocs/admin/perms.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/htdocs/admin/perms.php b/htdocs/admin/perms.php index a62041acd48..c08f3522fff 100644 --- a/htdocs/admin/perms.php +++ b/htdocs/admin/perms.php @@ -120,15 +120,25 @@ foreach ($modulesdir as $dir) if ($modName) { - include_once($dir."/".$file); - $objMod = new $modName($db); - if ($objMod->rights_class) { + include_once($dir.$file); + $objMod = new $modName($db); - $ret=$objMod->insert_permissions(0); + // Load all lang files of module + if (isset($objMod->langfiles) && is_array($objMod->langfiles)) + { + foreach($objMod->langfiles as $domain) + { + $langs->load($domain); + } + } + // Load all permissions + if ($objMod->rights_class) + { + $ret=$objMod->insert_permissions(0); - $modules[$objMod->rights_class]=$objMod; - //print "modules[".$objMod->rights_class."]=$objMod;"; - } + $modules[$objMod->rights_class]=$objMod; + //print "modules[".$objMod->rights_class."]=$objMod;"; + } } } } From 9924b2f17da242cd3ed595b9e071fa53eb0abfbf Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 22 Oct 2011 19:26:25 +0800 Subject: [PATCH 4/7] Fix: use bad object --- htdocs/admin/perms.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/htdocs/admin/perms.php b/htdocs/admin/perms.php index c08f3522fff..c9ed93052fe 100644 --- a/htdocs/admin/perms.php +++ b/htdocs/admin/perms.php @@ -147,7 +147,6 @@ foreach ($modulesdir as $dir) $db->commit(); - // Affiche lignes des permissions $sql = "SELECT r.id, r.libelle, r.module, r.perms, r.subperms, r.bydefault"; $sql.= " FROM ".MAIN_DB_PREFIX."rights_def as r"; @@ -159,10 +158,11 @@ $sql.= " ORDER BY r.module, r.id"; $result = $db->query($sql); if ($result) { - $num = $db->num_rows($result); - $i = 0; - $var=True; - $old = ""; + $num = $db->num_rows($result); + $i = 0; + $var = True; + $oldmod = ""; + while ($i < $num) { $obj = $db->fetch_object($result); @@ -176,7 +176,7 @@ if ($result) // Check if permission we found is inside a module definition. If not, we discard it. $found=false; - foreach($objMod->rights as $key => $val) + foreach($modules[$obj->module]->rights as $key => $val) { $rights_class=$objMod->rights_class; if ($val[4] == $obj->perms && (empty($val[5]) || $val[5] == $obj->subperms)) @@ -190,12 +190,13 @@ if ($result) $i++; continue; } - + // Break found, it's a new module to catch - if ($old <> $obj->module) + if ($oldmod <> $obj->module) { - $objMod=$modules[$obj->module]; - $picto=($objMod->picto?$objMod->picto:'generic'); + $oldmod = $obj->module; + $objMod = $modules[$obj->module]; + $picto = ($objMod->picto?$objMod->picto:'generic'); print ''; print ''.$langs->trans("Module").''; @@ -203,7 +204,6 @@ if ($result) print ''.$langs->trans("Default").''; print ' '; print "\n"; - $old = $obj->module; } $var=!$var; From 130a9f2e6efd4ea3b5e2b14e5d5c5bd70e18f8e0 Mon Sep 17 00:00:00 2001 From: Spangaro Alexandre Date: Sun, 23 Oct 2011 10:06:01 +0200 Subject: [PATCH 5/7] Add page "info" for trip --- htdocs/compta/deplacement/fiche.php | 5 ++ htdocs/compta/deplacement/info.php | 79 +++++++++++++++++++ htdocs/compta/deplacement/note.php | 5 ++ .../install/mysql/tables/llx_deplacement.sql | 1 + 4 files changed, 90 insertions(+) create mode 100644 htdocs/compta/deplacement/info.php diff --git a/htdocs/compta/deplacement/fiche.php b/htdocs/compta/deplacement/fiche.php index ce36b404709..f8bb30cff04 100644 --- a/htdocs/compta/deplacement/fiche.php +++ b/htdocs/compta/deplacement/fiche.php @@ -274,6 +274,11 @@ else $head[$h][1] = $langs->trans("Note"); $head[$h][2] = 'note'; $h++; + + $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/info.php?id=$deplacement->id"; + $head[$h][1] = $langs->trans("Info"); + $head[$h][2] = 'info'; + $h++; dol_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip'); diff --git a/htdocs/compta/deplacement/info.php b/htdocs/compta/deplacement/info.php new file mode 100644 index 00000000000..60b5e199bd8 --- /dev/null +++ b/htdocs/compta/deplacement/info.php @@ -0,0 +1,79 @@ + + * Copyright (C) 2004-2005 Laurent Destailleur + * + * 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 2 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/compta/deplacement/info.php + * \ingroup facture + * \brief Page to show a trip information + */ + +require("../../main.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/deplacement/class/deplacement.class.php"); + +$langs->load("trips"); + +/* + * View + */ +llxHeader(); + +if ($id) +{ + $deplacement = new Deplacement($db); + $deplacement->fetch($_GET["id"], $user); + $deplacement->info($_GET["id"]); + if ($deplacement > 0) + { + if ($mesg) print $mesg."
"; + + $h=0; + + $head[$h][0] = DOL_URL_ROOT.'/compta/deplacement/fiche.php?id='.$_GET["id"]; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'card'; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/compta/deplacement/note.php?id='.$_GET["id"]; + $head[$h][1] = $langs->trans("Note"); + $head[$h][2] = 'note'; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/compta/deplacement/info.php?id='.$_GET["id"]; + $head[$h][1] = $langs->trans("Info"); + $head[$h][2] = 'info'; + $h++; + + dol_fiche_head($head, 'info', $langs->trans("TripCard"), 0, 'trip'); + + print '
'; + dol_print_object_info($deplacement); + print '
'; + + print ''; + } + else + { + dol_print_error($db); + } +} + +$db->close(); + +llxFooter(); +?> diff --git a/htdocs/compta/deplacement/note.php b/htdocs/compta/deplacement/note.php index 2ef51313192..1aaf5005f5f 100644 --- a/htdocs/compta/deplacement/note.php +++ b/htdocs/compta/deplacement/note.php @@ -116,6 +116,11 @@ if ($id > 0 || ! empty($ref)) $head[$h][1] = $langs->trans("Note"); $head[$h][2] = 'note'; $h++; + + $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/info.php?id=$deplacement->id"; + $head[$h][1] = $langs->trans("Info"); + $head[$h][2] = 'info'; + $h++; dol_fiche_head($head, 'note', $langs->trans("TripCard"), 0, 'trip'); diff --git a/htdocs/install/mysql/tables/llx_deplacement.sql b/htdocs/install/mysql/tables/llx_deplacement.sql index ee508bd3a1f..02560f47ab2 100644 --- a/htdocs/install/mysql/tables/llx_deplacement.sql +++ b/htdocs/install/mysql/tables/llx_deplacement.sql @@ -28,6 +28,7 @@ create table llx_deplacement dated datetime, fk_user integer NOT NULL, fk_user_author integer, + fk_user_modif integer, -- utilisateur qui a modifie l'info type varchar(12) NOT NULL, fk_statut integer DEFAULT 1 NOT NULL, km real, From a7deb7c23adaaa3ddea2f89bb27570bfda0e9eb3 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 23 Oct 2011 14:55:37 +0200 Subject: [PATCH 6/7] Fix: uniformize code --- htdocs/compta/deplacement/fiche.php | 147 ++++++++---------- htdocs/compta/deplacement/index.php | 10 +- htdocs/compta/deplacement/info.php | 49 ++---- htdocs/compta/deplacement/list.php | 10 +- htdocs/compta/deplacement/note.php | 89 ++++------- .../install/mysql/migration/3.1.0-3.2.0.sql | 2 + .../install/mysql/tables/llx_deplacement.sql | 12 +- htdocs/lib/trip.lib.php | 61 ++++++++ 8 files changed, 195 insertions(+), 185 deletions(-) create mode 100644 htdocs/lib/trip.lib.php diff --git a/htdocs/compta/deplacement/fiche.php b/htdocs/compta/deplacement/fiche.php index f8bb30cff04..12cfd81ac65 100644 --- a/htdocs/compta/deplacement/fiche.php +++ b/htdocs/compta/deplacement/fiche.php @@ -1,7 +1,7 @@ - * Copyright (C) 2004-2011 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin +/* Copyright (C) 2003 Rodolphe Quiedeville + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2005-2011 Regis Houssin * * 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 @@ -23,6 +23,7 @@ */ require("../../main.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/trip.lib.php"); require_once(DOL_DOCUMENT_ROOT."/compta/deplacement/class/deplacement.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php"); if ($conf->projet->enabled) @@ -35,21 +36,23 @@ $langs->load("trips"); // Security check -$id=isset($_GET["id"])?$_GET["id"]:$_POST["id"]; +$id = GETPOST('id'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'deplacement', $id,''); +$action = GETPOST('action'); +$confirm = GETPOST('confirm'); + $mesg = ''; - +$object = new Deplacement($db); /* * Actions */ -if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->deplacement->supprimer) +if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->deplacement->supprimer) { - $deplacement = new Deplacement($db); - $result=$deplacement->delete($_GET["id"]); + $result=$object->delete($id); if ($result >= 0) { Header("Location: index.php"); @@ -57,11 +60,11 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user- } else { - $mesg=$deplacement->error; + $mesg=$object->error; } } -if ($_POST["action"] == 'add' && $user->rights->deplacement->creer) +if ($action == 'add' && $user->rights->deplacement->creer) { if (! $_POST["cancel"]) { @@ -72,26 +75,25 @@ if ($_POST["action"] == 'add' && $user->rights->deplacement->creer) $_POST["reday"], $_POST["reyear"]); - $deplacement = new Deplacement($db); - $deplacement->date = $dated; - $deplacement->km = $_POST["km"]; - $deplacement->type = $_POST["type"]; - $deplacement->socid = $_POST["socid"]; - $deplacement->fk_user = $_POST["fk_user"]; - $deplacement->note = $_POST["note"]; - $deplacement->note_public = $_POST["note_public"]; + $object->date = $dated; + $object->km = $_POST["km"]; + $object->type = $_POST["type"]; + $object->socid = $_POST["socid"]; + $object->fk_user = $_POST["fk_user"]; + $object->note = $_POST["note"]; + $object->note_public = $_POST["note_public"]; - if (! $deplacement->date) + if (! $object->date) { $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")); $error++; } - if ($deplacement->type == '-1') // Otherwise it is TF_LUNCH,... + if ($object->type == '-1') // Otherwise it is TF_LUNCH,... { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'
'; $error++; } - if (! ($deplacement->fk_user > 0)) + if (! ($object->fk_user > 0)) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Person")).'
'; $error++; @@ -99,22 +101,22 @@ if ($_POST["action"] == 'add' && $user->rights->deplacement->creer) if (! $error) { - $id = $deplacement->create($user); + $id = $object->create($user); if ($id > 0) { - Header("Location: fiche.php?id=".$id); + Header("Location: " . $_SERVER["PHP_SELF"] . "?id=".$id); exit; } else { - $mesg=$deplacement->error; - $_GET["action"]='create'; + $mesg=$object->error; + $action='create'; } } else { - $_GET["action"]='create'; + $action='create'; } } else @@ -124,45 +126,44 @@ if ($_POST["action"] == 'add' && $user->rights->deplacement->creer) } } -if ($_POST["action"] == 'update' && $user->rights->deplacement->creer) +if ($action == 'update' && $user->rights->deplacement->creer) { if (empty($_POST["cancel"])) { - $deplacement = new Deplacement($db); - $result = $deplacement->fetch($_POST["id"]); + $result = $object->fetch($id); - $deplacement->date = dol_mktime(12, 0 , 0, + $object->date = dol_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); - $deplacement->km = $_POST["km"]; - $deplacement->type = $_POST["type"]; - $deplacement->fk_user = $_POST["fk_user"]; - $deplacement->socid = $_POST["socid"]; - $result = $deplacement->update($user); + $object->km = $_POST["km"]; + $object->type = $_POST["type"]; + $object->fk_user = $_POST["fk_user"]; + $object->socid = $_POST["socid"]; + $result = $object->update($user); if ($result > 0) { - Header("Location: fiche.php?id=".$_POST["id"]); + Header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); exit; } else { - $mesg=$deplacement->error; + $mesg=$object->error; } } else { - Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST["id"]); + Header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); exit; } } // Set into a project -if ($_POST['action'] == 'classin') +if ($action == 'classin') { $trip = new Deplacement($db); - $trip->fetch($_GET['id']); + $trip->fetch($id); $result=$trip->setProject($_POST['projectid']); if ($result < 0) dol_print_error($db,$trip->error); } @@ -180,7 +181,7 @@ $html = new Form($db); /* * Action create */ -if ($_GET["action"] == 'create') +if ($action == 'create') { print_fiche_titre($langs->trans("NewTrip")); @@ -191,7 +192,7 @@ if ($_GET["action"] == 'create') $_POST["reday"], $_POST["reyear"]); - print "
\n"; + print '' . "\n"; print ''; print ''; @@ -257,40 +258,24 @@ else { if ($id) { - $deplacement = new Deplacement($db); - $result = $deplacement->fetch($id); + $result = $object->fetch($id); if ($result > 0) { - if ($mesg) print $mesg."
"; + dol_htmloutput_mesg($mesg); - $h=0; - - $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/fiche.php?id=$deplacement->id"; - $head[$h][1] = $langs->trans("Card"); - $head[$h][2] = 'card'; - $h++; - - $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/note.php?id=$deplacement->id"; - $head[$h][1] = $langs->trans("Note"); - $head[$h][2] = 'note'; - $h++; - - $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/info.php?id=$deplacement->id"; - $head[$h][1] = $langs->trans("Info"); - $head[$h][2] = 'info'; - $h++; + $head = trip_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("TripCard"), 0, 'trip'); if ($_GET["action"] == 'edit') { $soc = new Societe($db); - if ($deplacement->socid) + if ($object->socid) { - $soc->fetch($deplacement->socid); + $soc->fetch($object->socid); } - print "\n"; + print '' . "\n"; print ''; print ''; print ''; @@ -300,28 +285,28 @@ else // Ref print ""; print ''.$langs->trans("Ref").''; - print $deplacement->ref; + print $object->ref; print ''; // Type print ""; print ''.$langs->trans("Type").''; - print $html->select_type_fees($_POST["type"]?$_POST["type"]:$deplacement->type,'type',0); + print $html->select_type_fees($_POST["type"]?$_POST["type"]:$object->type,'type',0); print ''; // Who print ""; print ''.$langs->trans("Person").''; - print $html->select_users($_POST["fk_user"]?$_POST["fk_user"]:$deplacement->fk_user,'fk_user',0); + print $html->select_users($_POST["fk_user"]?$_POST["fk_user"]:$object->fk_user,'fk_user',0); print ''; // Date print ''.$langs->trans("Date").''; - print $html->select_date($deplacement->date,'','','','','update'); + print $html->select_date($object->date,'','','','','update'); print ''; // Km - print ''.$langs->trans("FeesKilometersOrAmout").''; + print ''.$langs->trans("FeesKilometersOrAmout").''; // Where print ""; @@ -344,40 +329,40 @@ else /* * Confirmation de la suppression du deplacement */ - if ($_GET["action"] == 'delete') + if ($action == 'delete') { $ret=$html->form_confirm("fiche.php?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete"); if ($ret == 'html') print '
'; } $soc = new Societe($db); - if ($deplacement->socid) $soc->fetch($deplacement->socid); + if ($object->socid) $soc->fetch($object->socid); print ''; // Ref print ""; print ''; // Type - print ''; + print ''; // Who print ''; // Date print ''; // Km/Price - print ''; + print ''; // Where print ''; @@ -397,7 +382,7 @@ else print ''; if ($_GET['action'] != 'classify') { - print ''; } @@ -405,18 +390,18 @@ else print ''; print ''; } // Statut - print ''; + print ''; print "
'.$langs->trans("Ref").''; - print $html->showrefnav($deplacement,'id','',1,'rowid','ref',''); + print $html->showrefnav($object,'id','',1,'rowid','ref',''); print '
'.$langs->trans("Type").''.$langs->trans($deplacement->type).'
'.$langs->trans("Type").''.$langs->trans($object->type).'
'.$langs->trans("Person").''; $userfee=new User($db); - $userfee->fetch($deplacement->fk_user); + $userfee->fetch($object->fk_user); print $userfee->getNomUrl(1); print '
'.$langs->trans("Date").''; - print dol_print_date($deplacement->date,'day'); + print dol_print_date($object->date,'day'); print '
'.$langs->trans("FeesKilometersOrAmout").''.$deplacement->km.'
'.$langs->trans("FeesKilometersOrAmout").''.$object->km.'
'.$langs->trans("CompanyVisited").'id.'">'; + print 'id.'">'; print img_edit($langs->trans('SetProject'),1); print ''; if ($_GET['action'] == 'classify') { - $html->form_project($_SERVER['PHP_SELF'].'?id='.$deplacement->id, $deplacement->socid, $deplacement->fk_project,'projectid'); + $html->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'projectid'); } else { - $html->form_project($_SERVER['PHP_SELF'].'?id='.$deplacement->id, $deplacement->socid, $deplacement->fk_project,'none'); + $html->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project,'none'); } print '
'.$langs->trans("Status").''.$deplacement->getLibStatut(4).'
'.$langs->trans("Status").''.$object->getLibStatut(4).'
"; @@ -439,7 +424,7 @@ else print '
'; -if ($_GET["action"] != 'create' && $_GET["action"] != 'edit') +if ($action != 'create' && $action != 'edit') { if ($user->rights->deplacement->creer) { diff --git a/htdocs/compta/deplacement/index.php b/htdocs/compta/deplacement/index.php index 46220223823..995ae8966c4 100644 --- a/htdocs/compta/deplacement/index.php +++ b/htdocs/compta/deplacement/index.php @@ -1,8 +1,8 @@ - * Copyright (C) 2004-2011 Laurent Destailleur - * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005-2009 Regis Houssin +/* Copyright (C) 2003 Rodolphe Quiedeville + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005-2011 Regis Houssin * * 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 @@ -32,7 +32,7 @@ $langs->load("users"); $langs->load("trips"); // Security check -$socid = $_GET["socid"]?$_GET["socid"]:''; +$socid = GETPOST('socid'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'deplacement','',''); diff --git a/htdocs/compta/deplacement/info.php b/htdocs/compta/deplacement/info.php index 60b5e199bd8..788759148e9 100644 --- a/htdocs/compta/deplacement/info.php +++ b/htdocs/compta/deplacement/info.php @@ -17,60 +17,45 @@ */ /** - * \file htdocs/compta/deplacement/info.php - * \ingroup facture - * \brief Page to show a trip information + * \file htdocs/compta/deplacement/info.php + * \ingroup trip + * \brief Page to show a trip information */ require("../../main.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/trip.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); require_once(DOL_DOCUMENT_ROOT."/compta/deplacement/class/deplacement.class.php"); $langs->load("trips"); +// Security check +$id = GETPOST('id'); +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'deplacement', $id, ''); + + /* * View */ + llxHeader(); if ($id) { - $deplacement = new Deplacement($db); - $deplacement->fetch($_GET["id"], $user); - $deplacement->info($_GET["id"]); - if ($deplacement > 0) - { - if ($mesg) print $mesg."
"; - - $h=0; - - $head[$h][0] = DOL_URL_ROOT.'/compta/deplacement/fiche.php?id='.$_GET["id"]; - $head[$h][1] = $langs->trans("Card"); - $head[$h][2] = 'card'; - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/compta/deplacement/note.php?id='.$_GET["id"]; - $head[$h][1] = $langs->trans("Note"); - $head[$h][2] = 'note'; - $h++; + $object = new Deplacement($db); + $object->fetch($id); + $object->info($id); - $head[$h][0] = DOL_URL_ROOT.'/compta/deplacement/info.php?id='.$_GET["id"]; - $head[$h][1] = $langs->trans("Info"); - $head[$h][2] = 'info'; - $h++; + $head = trip_prepare_head($object); - dol_fiche_head($head, 'info', $langs->trans("TripCard"), 0, 'trip'); + dol_fiche_head($head, 'info', $langs->trans("TripCard"), 0, 'trip'); print '
'; - dol_print_object_info($deplacement); + dol_print_object_info($object); print '
'; print '
'; - } - else - { - dol_print_error($db); - } } $db->close(); diff --git a/htdocs/compta/deplacement/list.php b/htdocs/compta/deplacement/list.php index 8ac93658241..5a74877adc3 100755 --- a/htdocs/compta/deplacement/list.php +++ b/htdocs/compta/deplacement/list.php @@ -1,8 +1,8 @@ - * Copyright (C) 2004-2011 Laurent Destailleur - * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005-2009 Regis Houssin +/* Copyright (C) 2003 Rodolphe Quiedeville + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005-2011 Regis Houssin * * 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 @@ -32,7 +32,7 @@ $langs->load("users"); $langs->load("trips"); // Security check -$socid = $_GET["socid"]?$_GET["socid"]:''; +$socid = GETPOST('socid'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'deplacement','',''); diff --git a/htdocs/compta/deplacement/note.php b/htdocs/compta/deplacement/note.php index 1aaf5005f5f..cb0ef37b83d 100644 --- a/htdocs/compta/deplacement/note.php +++ b/htdocs/compta/deplacement/note.php @@ -23,42 +23,38 @@ */ require("../../main.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/trip.lib.php"); require_once(DOL_DOCUMENT_ROOT."/compta/deplacement/class/deplacement.class.php"); -$socid=isset($_GET["socid"])?$_GET["socid"]:isset($_POST["socid"])?$_POST["socid"]:""; - -if (!$user->rights->deplacement->lire) - accessforbidden(); - $langs->load("companies"); -$langs->load("bills"); $langs->load("trips"); -// Securiy check -if ($user->societe_id > 0) -{ - unset($_GET["action"]); - $socid = $user->societe_id; -} +$id = GETPOST('id'); +$ref = GETPOST('ref'); +$action = GETPOST('action'); +$confirm = GETPOST('confirm'); +// Security check +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'deplacement', $id, ''); -$trip = new Deplacement($db); +$object = new Deplacement($db); /******************************************************************************/ /* Actions */ /******************************************************************************/ -if ($_POST["action"] == 'update_public' && $user->rights->deplacement->creer) +if ($action == 'update_public' && $user->rights->deplacement->creer) { $db->begin(); - $trip->fetch($_GET["id"]); + $object->fetch($id); - $res=$trip->update_note_public($_POST["note_public"],$user); + $res=$object->update_note_public($_POST["note_public"]); if ($res < 0) { - $mesg='
'.$fac->error.'
'; + $mesg='
'.$object->error.'
'; $db->rollback(); } else @@ -67,16 +63,16 @@ if ($_POST["action"] == 'update_public' && $user->rights->deplacement->creer) } } -if ($_POST["action"] == 'update' && $user->rights->deplacement->creer) +if ($action == 'update' && $user->rights->deplacement->creer) { $db->begin(); - $trip->fetch($_GET["id"]); + $object->fetch($id); - $res=$trip->update_note($_POST["note"],$user); + $res=$object->update_note($_POST["note"]); if ($res < 0) { - $mesg='
'.$fac->error.'
'; + $mesg='
'.$object->error.'
'; $db->rollback(); } else @@ -95,53 +91,34 @@ llxHeader(); $html = new Form($db); -$id = $_GET['id']; -$ref= $_GET['ref']; if ($id > 0 || ! empty($ref)) { - $trip = new Deplacement($db); - $trip->fetch($id,$ref); + $object->fetch($id, $ref); $soc = new Societe($db); - $soc->fetch($trip->socid); + $soc->fetch($object->socid); - $h=0; - - $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/fiche.php?id=$trip->id"; - $head[$h][1] = $langs->trans("Card"); - $head[$h][2] = 'card'; - $h++; - - $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/note.php?id=$trip->id"; - $head[$h][1] = $langs->trans("Note"); - $head[$h][2] = 'note'; - $h++; - - $head[$h][0] = DOL_URL_ROOT."/compta/deplacement/info.php?id=$deplacement->id"; - $head[$h][1] = $langs->trans("Info"); - $head[$h][2] = 'info'; - $h++; + $head = trip_prepare_head($object); dol_fiche_head($head, 'note', $langs->trans("TripCard"), 0, 'trip'); - print ''; // Ref print ''; print ''; // Type - print ''; + print ''; // Who print ""; print ''; @@ -153,18 +130,18 @@ if ($id > 0 || ! empty($ref)) // Note publique print ''; print '"; @@ -173,18 +150,18 @@ if ($id > 0 || ! empty($ref)) { print ''; print '"; } @@ -198,9 +175,9 @@ if ($id > 0 || ! empty($ref)) print ''; print '
'; - if ($user->rights->deplacement->creer && $_GET["action"] <> 'edit') + if ($action <> 'edit' && $user->rights->deplacement->creer) { - print "id&action=edit\">".$langs->trans('Modify').""; + print '' . $langs->trans('Modify') . ''; } print "
"; diff --git a/htdocs/install/mysql/migration/3.1.0-3.2.0.sql b/htdocs/install/mysql/migration/3.1.0-3.2.0.sql index 60bf0d26d74..db1a3928437 100755 --- a/htdocs/install/mysql/migration/3.1.0-3.2.0.sql +++ b/htdocs/install/mysql/migration/3.1.0-3.2.0.sql @@ -67,3 +67,5 @@ ALTER TABLE llx_product_fournisseur_price DROP FOREIGN KEY fk_product_fournisseu DROP TABLE IF EXISTS llx_pos_tmp; +ALTER TABLE llx_deplacement ADD COLUMN fk_user_modif integer AFTER fk_user_author; + diff --git a/htdocs/install/mysql/tables/llx_deplacement.sql b/htdocs/install/mysql/tables/llx_deplacement.sql index 02560f47ab2..46f240e18d5 100644 --- a/htdocs/install/mysql/tables/llx_deplacement.sql +++ b/htdocs/install/mysql/tables/llx_deplacement.sql @@ -1,7 +1,7 @@ -- ============================================================================ --- Copyright (C) 2003 Rodolphe Quiedeville --- Copyright (C) 2009 Regis Houssin --- Copyright (C) 2010 Laurent Destailleur +-- Copyright (C) 2003 Rodolphe Quiedeville +-- Copyright (C) 2009-2011 Regis Houssin +-- Copyright (C) 2010 Laurent Destailleur -- -- 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 @@ -21,14 +21,14 @@ create table llx_deplacement ( rowid integer AUTO_INCREMENT PRIMARY KEY, - ref varchar(30) DEFAULT NULL, -- Ref donation (TODO change to NOT NULL) - entity integer DEFAULT 1 NOT NULL, -- multi company id + ref varchar(30) DEFAULT NULL, -- Ref donation (TODO change to NOT NULL) + entity integer DEFAULT 1 NOT NULL, -- multi company id datec datetime NOT NULL, tms timestamp, dated datetime, fk_user integer NOT NULL, fk_user_author integer, - fk_user_modif integer, -- utilisateur qui a modifie l'info + fk_user_modif integer, -- utilisateur qui a modifie l'info type varchar(12) NOT NULL, fk_statut integer DEFAULT 1 NOT NULL, km real, diff --git a/htdocs/lib/trip.lib.php b/htdocs/lib/trip.lib.php new file mode 100644 index 00000000000..726f1575b8e --- /dev/null +++ b/htdocs/lib/trip.lib.php @@ -0,0 +1,61 @@ + + * + * 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 2 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 . + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/lib/trip.lib.php + * \brief Ensemble de fonctions de base pour les deplacements + */ + +/** + * Enter description here... + * + * @param $object + * @return array + */ +function trip_prepare_head($object) +{ + global $langs, $conf; + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT . '/compta/deplacement/fiche.php?id=' . $object->id; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'card'; + $h++; + + $head[$h][0] = DOL_URL_ROOT . '/compta/deplacement/note.php?id=' . $object->id; + $head[$h][1] = $langs->trans("Note"); + $head[$h][2] = 'note'; + $h++; + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab + complete_head_from_modules($conf,$langs,$object,$head,$h,'trip'); + + $head[$h][0] = DOL_URL_ROOT . '/compta/deplacement/info.php?id=' . $object->id; + $head[$h][1] = $langs->trans("Info"); + $head[$h][2] = 'info'; + $h++; + + return $head; +} + +?> \ No newline at end of file From a308a666e40ba2f891c5cb9204fc69b41f20f3df Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 23 Oct 2011 18:36:47 +0200 Subject: [PATCH 7/7] Added temporarily before to find another solution --- htdocs/core/class/commonobject.class.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index e3167957336..eef6a4aadde 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1345,11 +1345,14 @@ abstract class CommonObject if ($objecttype == 'delivery') { $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; } if ($objecttype == 'invoice_supplier') { $classpath = 'fourn/class'; } if ($objecttype == 'order_supplier') { $classpath = 'fourn/class'; } - if ($objecttype == 'fichinter') { $classpath = 'fichinter/class'; $subelement ='fichinter'; $module ='ficheinter'; } + if ($objecttype == 'fichinter') { $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; } + + // TODO ajout temporaire - MAXIME MANGIN + if ($objecttype == 'contratabonnement') { $classpath = 'contrat/class'; $subelement = 'contrat'; $module = 'contratabonnement'; } $classfile = strtolower($subelement); $classname = ucfirst($subelement); - if ($objecttype == 'invoice_supplier') { $classfile = 'fournisseur.facture'; $classname='FactureFournisseur'; } - if ($objecttype == 'order_supplier') { $classfile = 'fournisseur.commande'; $classname='CommandeFournisseur'; } + if ($objecttype == 'invoice_supplier') { $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; } + if ($objecttype == 'order_supplier') { $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; } if ($conf->$module->enabled && $element != $this->element) {
'.$langs->trans('Ref').''; $morehtmlref=''; - print $html->showrefnav($trip,'ref','',1,'ref','ref',$morehtmlref); + print $html->showrefnav($object,'ref','',1,'ref','ref',$morehtmlref); print '
'.$langs->trans("Type").''.$langs->trans($trip->type).'
'.$langs->trans("Type").''.$langs->trans($object->type).'
'.$langs->trans("Person").''; $userfee=new User($db); - $userfee->fetch($trip->fk_user); + $userfee->fetch($object->fk_user); print $userfee->getNomUrl(1); print '
'.$langs->trans("NotePublic").''; - if ($_GET["action"] == 'edit') + if ($action == 'edit') { - print ''; + print ''; print ''; print ''; - print '
"; + print '
"; print ''; print ''; } else { - print ($trip->note_public?nl2br($trip->note_public):" "); + print ($object->note_public?nl2br($object->note_public):" "); } print "
'.$langs->trans("NotePrivate").''; - if ($_GET["action"] == 'edit') + if ($action == 'edit') { - print '
'; + print ''; print ''; print ''; - print '
"; + print '
"; print ''; print '
'; } else { - print ($trip->note?nl2br($trip->note):" "); + print ($object->note?nl2br($object->note):" "); } print "