dolibarr 18.0.6
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 <https://www.gnu.org/licenses/>.
18 */
19
26include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
27
28
33{
34 public $boxcode = "ficheinter";
35 public $boximg = "object_intervention";
36 public $boxlabel = "BoxFicheInter";
37 public $depends = array("ficheinter"); // conf->contrat->enabled
38
42 public $db;
43
44 public $param;
45
46 public $info_box_head = array();
47 public $info_box_contents = array();
48
49
56 public function __construct($db, $param)
57 {
58 global $user;
59
60 $this->db = $db;
61
62 $this->hidden = !($user->hasRight('ficheinter', 'lire'));
63 }
64
71 public function loadBox($max = 10)
72 {
73 global $user, $langs, $conf;
74
75 $this->max = $max;
76
77 include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
78 $ficheinterstatic = new Fichinter($this->db);
79 $thirdpartystatic = new Societe($this->db);
80
81 $this->info_box_head = array('text' => $langs->trans("BoxTitleLastFicheInter", $max));
82
83 if (!empty($user->rights->ficheinter->lire)) {
84 $sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut as status";
85 $sql .= ", f.datec";
86 $sql .= ", f.date_valid as datev";
87 $sql .= ", f.tms as datem";
88 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
89 $sql .= ", s.code_client, s.code_compta, s.client";
90 $sql .= ", s.logo, s.email, s.entity";
91 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
92 if (empty($user->rights->societe->client->voir)) {
93 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
94 }
95 $sql .= ", ".MAIN_DB_PREFIX."fichinter as f";
96 $sql .= " WHERE f.fk_soc = s.rowid ";
97 $sql .= " AND f.entity = ".$conf->entity;
98 if (empty($user->rights->societe->client->voir) && !$user->socid) {
99 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
100 }
101 if ($user->socid) {
102 $sql .= " AND s.rowid = ".((int) $user->socid);
103 }
104 $sql .= " ORDER BY f.tms DESC";
105 $sql .= $this->db->plimit($max, 0);
106
107 dol_syslog(get_class($this).'::loadBox', LOG_DEBUG);
108 $resql = $this->db->query($sql);
109 if ($resql) {
110 $num = $this->db->num_rows($resql);
111 $now = dol_now();
112
113 $i = 0;
114
115 while ($i < $num) {
116 $objp = $this->db->fetch_object($resql);
117 $datec = $this->db->jdate($objp->datec);
118 $datem = $this->db->jdate($objp->datem);
119
120 $ficheinterstatic->statut = $objp->status;
121 $ficheinterstatic->status = $objp->status;
122 $ficheinterstatic->id = $objp->rowid;
123 $ficheinterstatic->ref = $objp->ref;
124
125 $thirdpartystatic->id = $objp->socid;
126 $thirdpartystatic->name = $objp->name;
127 //$thirdpartystatic->name_alias = $objp->name_alias;
128 $thirdpartystatic->code_client = $objp->code_client;
129 $thirdpartystatic->code_compta = $objp->code_compta;
130 $thirdpartystatic->client = $objp->client;
131 $thirdpartystatic->logo = $objp->logo;
132 $thirdpartystatic->email = $objp->email;
133 $thirdpartystatic->entity = $objp->entity;
134
135 $this->info_box_contents[$i][] = array(
136 'td' => 'class="nowraponall"',
137 'text' => $ficheinterstatic->getNomUrl(1),
138 'asis' => 1,
139 );
140
141 $this->info_box_contents[$i][] = array(
142 'td' => 'class="tdoverflowmax150"',
143 'text' => $thirdpartystatic->getNomUrl(1),
144 'asis' => 1,
145 );
146
147 $this->info_box_contents[$i][] = array(
148 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
149 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
150 );
151
152 $this->info_box_contents[$i][] = array(
153 'td' => 'class="nowrap right"',
154 'text' => $ficheinterstatic->getLibStatut(3),
155 'asis' => 1,
156 );
157
158 $i++;
159 }
160
161 if ($num == 0) {
162 $this->info_box_contents[$i][0] = array(
163 'td' => 'class="center opacitymedium"',
164 'text'=>$langs->trans("NoRecordedInterventions")
165 );
166 }
167
168 $this->db->free($resql);
169 } else {
170 $this->info_box_contents[0][0] = array(
171 'td' => '',
172 'maxlength'=>500,
173 'text' => ($this->db->error().' sql='.$sql),
174 );
175 }
176 } else {
177 $this->info_box_contents[0][0] = array(
178 'td' => 'class="nohover opacitymedium left"',
179 'text' => $langs->trans("ReadPermissionNotAllowed")
180 );
181 }
182 }
183
192 public function showBox($head = null, $contents = null, $nooutput = 0)
193 {
194 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
195 }
196}
Class to manage interventions.
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last interventions.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.
loadBox($max=10)
Load data for box to show them later.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...