From e7000109b409c7e0fb393d3bd92d5e35459b2bb6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 10 Oct 2009 16:26:06 +0000 Subject: [PATCH] Qual: Mutualize code --- htdocs/contrat/contrat.class.php | 10 +- htdocs/contrat/services.php | 26 ++-- htdocs/product.class.php | 14 +- htdocs/service.class.php | 241 +++++++------------------------ 4 files changed, 77 insertions(+), 214 deletions(-) diff --git a/htdocs/contrat/contrat.class.php b/htdocs/contrat/contrat.class.php index ea5dcd7ec5d..1def65faa58 100644 --- a/htdocs/contrat/contrat.class.php +++ b/htdocs/contrat/contrat.class.php @@ -1094,11 +1094,11 @@ class Contrat extends CommonObject /** - \brief Renvoie nom clicable (avec eventuellement le picto) - \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul - \param maxlength Max length of ref - \return string Chaine avec URL - */ + * \brief Renvoie nom clicable (avec eventuellement le picto) + * \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul + * \param maxlength Max length of ref + * \return string Chaine avec URL + */ function getNomUrl($withpicto=0,$maxlength=0) { global $langs; diff --git a/htdocs/contrat/services.php b/htdocs/contrat/services.php index c9052da3602..50db3f1b21b 100644 --- a/htdocs/contrat/services.php +++ b/htdocs/contrat/services.php @@ -27,6 +27,7 @@ require("./pre.inc.php"); require_once (DOL_DOCUMENT_ROOT."/contrat/contrat.class.php"); +require_once (DOL_DOCUMENT_ROOT."/product.class.php"); require_once (DOL_DOCUMENT_ROOT."/societe.class.php"); $langs->load("products"); @@ -72,7 +73,8 @@ llxHeader(); $sql = "SELECT c.rowid as cid, c.ref, c.statut as cstatut,"; $sql.= " s.rowid as socid, s.nom,"; -$sql.= " cd.rowid, cd.description, cd.statut, p.rowid as pid, p.label as label,"; +$sql.= " cd.rowid, cd.description, cd.statut,"; +$sql.= " p.rowid as pid, p.label as label, p.fk_product_type as ptype,"; if (!$user->rights->societe->client->voir && !$socid) $sql .= " sc.fk_soc, sc.fk_user,"; $sql.= " ".$db->pdate("cd.date_ouverture_prevue")." as date_ouverture_prevue,"; $sql.= " ".$db->pdate("cd.date_ouverture")." as date_ouverture,"; @@ -151,13 +153,13 @@ if ($resql) print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; $arrayofoperators=array('<'=>'<','>'=>'>'); @@ -178,6 +180,9 @@ if ($resql) print "\n"; print ''; + $contractstatic=new Contrat($db); + $productstatic=new Product($db); + $var=True; while ($i < min($num,$limit)) { @@ -185,7 +190,6 @@ if ($resql) $var=!$var; print ""; print ''; - $contractstatic=new Contrat($db); $contractstatic->id=$obj->cid; $contractstatic->ref=$obj->ref?$obj->ref:$obj->cid; print $contractstatic->getNomUrl(1,16); @@ -193,14 +197,10 @@ if ($resql) // Service print ''; - if ($obj->pid) - { - print ''.img_object($langs->trans("ShowService"),"service").' '.dol_trunc($obj->label,20).''; - } - else - { - print dol_trunc($obj->description,20); - } + $productstatic->id=$obj->pid; + $productstatic->type=$obj->ptype; + $productstatic->ref=$obj->label?$obj->label:$obj->pid; + print $productstatic->getNomUrl(1,20); print ''; // Third party diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 4729c4897dd..34ebab31ace 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -2050,7 +2050,7 @@ class Product extends CommonObject } /** - * \brief Renvoie nom clicable (avec eventuellement le picto) + * \brief Return clicable link of object (with eventually picto) * \param withpicto Inclut le picto dans le lien * \param option Sur quoi pointe le lien * \param maxlength Maxlength of ref @@ -2084,9 +2084,9 @@ class Product extends CommonObject } /** - * \brief Retourne le libell� du statut d'une facture (brouillon, valid�e, abandonn�e, pay�e) - * \param mode 0=libell� long, 1=libell� court, 2=Picto + Libell� court, 3=Picto, 4=Picto + Libell� long, 5=Libell� court + Picto - * \return string Libelle + * \brief Return label of status of object + * \param mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto + * \return string Label of status */ function getLibStatut($mode=0) { @@ -2094,10 +2094,10 @@ class Product extends CommonObject } /** - * \brief Renvoi le libell� d'un statut donne + * \brief Return label of a given status * \param status Statut - * \param mode 0=libell� long, 1=libell� court, 2=Picto + Libell� court, 3=Picto, 4=Picto + Libell� long, 5=Libell� court + Picto - * \return string Libell� du statut + * \param mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto + * \return string Label of status */ function LibStatut($status,$mode=0) { diff --git a/htdocs/service.class.php b/htdocs/service.class.php index 5d5fbbaec21..b8430312cde 100644 --- a/htdocs/service.class.php +++ b/htdocs/service.class.php @@ -1,7 +1,7 @@ * 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 @@ -31,204 +31,67 @@ */ class Service { - var $db; + var $db; - var $id; - var $libelle; - var $price; - var $tms; - var $debut; - var $fin; + var $id; + var $libelle; + var $price; + var $tms; + var $debut; + var $fin; - var $debut_epoch; - var $fin_epoch; + var $debut_epoch; + var $fin_epoch; - function Service($DB, $id=0) { - $this->db = $DB; - $this->id = $id; - - return 1; - } - - /* - * - * - * - */ - - function create($user) { + function Service($DB, $id=0) { + $this->db = $DB; + $this->id = $id; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."service (datec, fk_user_author) VALUES (".$this->db->idate(mktime()).", ".$user->id.")"; + return 1; + } - if ($this->db->query($sql) ) { - $id = $this->db->last_insert_id(MAIN_DB_PREFIX."service"); - if ( $this->update($id, $user) ) { - return $id; - } - } else { - print $this->db->error() . ' in ' . $sql; - return -1; - } - } - - /* - * - * - * - */ - - function update($id, $user) { + /** + * \brief Charge indicateurs this->nb de tableau de bord + * \return int <0 si ko, >0 si ok + */ + function load_state_board() + { + global $conf, $user; - $sql = "UPDATE ".MAIN_DB_PREFIX."service "; - $sql .= " SET label = '" . trim($this->libelle) ."'"; - $sql .= ",ref = '" . trim($this->ref) ."'"; - $sql .= ",price = " . $this->price ; - $sql .= ",description = '" . trim($this->description) ."'"; - $sql .= ",fk_user_modif = " . $user->id ; + $this->nb=array(); - $sql .= " WHERE rowid = " . $id; + $sql = "SELECT count(p.rowid) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; + if ($conf->categorie->enabled && !$user->rights->categorie->voir) + { + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cp.fk_categorie = c.rowid"; + } + $sql.= " WHERE p.fk_product_type = 1"; + $sql.= " AND p.entity = ".$conf->entity; + if ($conf->categorie->enabled && !$user->rights->categorie->voir) + { + $sql.= " AND IFNULL(c.visible,1)=1"; + } + $resql=$this->db->query($sql); + if ($resql) + { + while ($obj=$this->db->fetch_object($resql)) + { + $this->nb["services"]=$obj->nb; + } + return 1; + } + else + { + dol_print_error($this->db); + $this->error=$this->db->error(); + return -1; + } - if ( $this->db->query($sql) ) { - return 1; - } else { - print $this->db->error() . ' in ' . $sql; - } - } - - /* - * - * - * - */ - - function start_comm($id, $user, $datedeb=0) { + } - $sql = "UPDATE ".MAIN_DB_PREFIX."service "; - if ($datedeb) { - $sql .= " SET debut_comm = '$datedeb'"; - } else { - $sql .= " SET debut_comm = ".$this->db->idate(mktime()); - } - $sql .= ",fk_user_modif = " . $user->id ; - - $sql .= " WHERE rowid = " . $id; - - if ( $this->db->query($sql) ) { - return 1; - } else { - print $this->db->error() . ' in ' . $sql; - } - } - - /* - * - * - * - */ - - function stop_comm($id, $user, $datefin=0) { - - $sql = "UPDATE ".MAIN_DB_PREFIX."service "; - if ($datefin) { - $sql .= " SET fin_comm = '$datefin'"; - } else { - $sql .= " SET fin_comm = ".$this->db->idate(mktime()); - } - $sql .= ",fk_user_modif = " . $user->id ; - - $sql .= " WHERE rowid = " . $id; - - if ( $this->db->query($sql) ) { - return 1; - } else { - print $this->db->error() . ' in ' . $sql; - } - } - - /* - * - * - * - */ - - function fetch($id) { - - $sql = "SELECT s.ref,s.label,s.price,s.tms,s.debut_comm,s.fin_comm,s.description,"; - $sql .= $this->db->pdate("s.debut_comm") . ' as debut_epoch,'; - $sql .= $this->db->pdate("s.fin_comm") . ' as fin_epoch'; - $sql .= " FROM ".MAIN_DB_PREFIX."service as s"; - $sql .= " WHERE s.rowid = $id"; - - $result = $this->db->query($sql); - - if ($result) { - if ($this->db->num_rows()) { - $obj = $this->db->fetch_object($result); - - $this->id = $obj->rowid; - $this->ref = $obj->ref; - $this->libelle = $obj->label; - $this->price = $obj->price; - $this->description = $obj->description; - - $this->tms = $obj->tms; - - $this->debut = $obj->debut_comm; - $this->fin = $obj->fin_comm; - - $this->debut_epoch = $obj->debut_epoch; - $this->fin_epoch = $obj->fin_epoch; - - } - $this->db->free(); - - } else { - print $this->db->error(); - } - } - - /** - * \brief Charge indicateurs this->nb de tableau de bord - * \return int <0 si ko, >0 si ok - */ - function load_state_board() - { - global $conf, $user; - - $this->nb=array(); - - $sql = "SELECT count(p.rowid) as nb"; - $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; - if ($conf->categorie->enabled && !$user->rights->categorie->voir) - { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cp.fk_categorie = c.rowid"; - } - $sql.= " WHERE p.fk_product_type = 1"; - $sql.= " AND p.entity = ".$conf->entity; - if ($conf->categorie->enabled && !$user->rights->categorie->voir) - { - $sql.= " AND IFNULL(c.visible,1)=1"; - } - $resql=$this->db->query($sql); - if ($resql) - { - while ($obj=$this->db->fetch_object($resql)) - { - $this->nb["services"]=$obj->nb; - } - return 1; - } - else - { - dol_print_error($this->db); - $this->error=$this->db->error(); - return -1; - } - - } - } ?>