dolibarr  7.0.0-beta
box_ficheinter.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
3  * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
4  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
27 
28 
33 {
34  var $boxcode="ficheinter";
35  var $boximg="object_intervention";
36  var $boxlabel="BoxFicheInter";
37  var $depends = array("ficheinter"); // conf->contrat->enabled
38 
39  var $db;
40  var $param;
41 
42  var $info_box_head = array();
43  var $info_box_contents = array();
44 
45 
52  function __construct($db,$param)
53  {
54  global $user;
55 
56  $this->db=$db;
57 
58  $this->hidden=! ($user->rights->ficheinter->lire);
59  }
60 
67  function loadBox($max=10)
68  {
69  global $user, $langs, $db, $conf;
70 
71  $this->max=$max;
72 
73  include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
74  $ficheinterstatic=new Fichinter($db);
75 
76  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastFicheInter",$max));
77 
78  if (! empty($user->rights->ficheinter->lire))
79  {
80  $sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut,";
81  $sql.= " f.datec,";
82  $sql.= " f.date_valid as datev,";
83  $sql.= " f.tms as datem,";
84  $sql.= " s.nom as name, s.rowid as socid, s.client";
85  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
86  if (! $user->rights->societe->client->voir) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
87  $sql.= ", ".MAIN_DB_PREFIX."fichinter as f";
88  $sql.= " WHERE f.fk_soc = s.rowid ";
89  $sql.= " AND f.entity = ".$conf->entity;
90  if (! $user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
91  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
92  $sql.= " ORDER BY f.tms DESC";
93  $sql.= $db->plimit($max, 0);
94 
95  dol_syslog(get_class($this).'::loadBox', LOG_DEBUG);
96  $resql = $db->query($sql);
97  if ($resql)
98  {
99  $num = $db->num_rows($resql);
100  $now=dol_now();
101 
102  $i = 0;
103 
104  while ($i < $num)
105  {
106  $objp = $db->fetch_object($resql);
107  $datec=$db->jdate($objp->datec);
108 
109  $ficheinterstatic->statut=$objp->fk_statut;
110  $ficheinterstatic->id=$objp->rowid;
111  $ficheinterstatic->ref=$objp->ref;
112 
113  $this->info_box_contents[$i][] = array('td' => '',
114  'text' => $ficheinterstatic->getNomUrl(1),
115  'asis' => 1
116  );
117 
118  $this->info_box_contents[$i][] = array('td' => 'align="left" width="16"',
119  'logo' => 'company',
120  'url' => DOL_URL_ROOT."/comm/card.php?socid=".$objp->socid);
121 
122  $this->info_box_contents[$i][] = array('td' => '',
123  'text' => dol_trunc($objp->name,40),
124  'url' => DOL_URL_ROOT."/comm/card.php?socid=".$objp->socid);
125 
126  $this->info_box_contents[$i][] = array('td' => 'class="right"',
127  'text' => dol_print_date($datec,'day'));
128 
129  $this->info_box_contents[$i][] = array('td' => 'align="right" class="nowrap"',
130  'text' => $ficheinterstatic->getLibStatut(6),
131  'asis'=>1
132  );
133 
134  $i++;
135  }
136 
137  if ($num==0) $this->info_box_contents[$i][] = array('td' => 'align="center"','text'=>$langs->trans("NoRecordedInterventions"));
138 
139  $db->free($resql);
140  }
141  else
142  {
143  $this->info_box_contents[0][] = array( 'td' => '',
144  'maxlength'=>500,
145  'text' => ($db->error().' sql='.$sql));
146  }
147  }
148  else
149  {
150  $this->info_box_contents[0][] = array(
151  'td' => 'align="left" class="nohover opacitymedium"',
152  'text' => $langs->trans("ReadPermissionNotAllowed")
153  );
154  }
155  }
156 
165  function showBox($head = null, $contents = null, $nooutput=0)
166  {
167  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
168  }
169 
170 }
171 
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
Class to manage interventions.
Class ModeleBoxes.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
dol_now($mode='gmt')
Return date for now.
__construct($db, $param)
Constructor.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
loadBox($max=10)
Load data for box to show them later.
Class to manage the box to show last interventions.