dolibarr 21.0.0-alpha
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
45 public function __construct($db, $param)
46 {
47 global $user;
48
49 $this->db = $db;
50
51 $this->hidden = !($user->hasRight('ficheinter', 'lire'));
52 }
53
60 public function loadBox($max = 10)
61 {
62 global $user, $langs, $conf;
63
64 $this->max = $max;
65
66 include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
67 $ficheinterstatic = new Fichinter($this->db);
68 $thirdpartystatic = new Societe($this->db);
69
70 $this->info_box_head = array(
71 'text' => $langs->trans("BoxTitleLastFicheInter", $max).'<a class="paddingleft" href="'.DOL_URL_ROOT.'/fichinter/list.php?sortfield=f.tms&sortorder=DESC"><span class="badge">...</span></a>'
72 );
73
74 if ($user->hasRight('ficheinter', 'lire')) {
75 $sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut as status";
76 $sql .= ", f.datec";
77 $sql .= ", f.date_valid as datev";
78 $sql .= ", f.tms as datem";
79 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
80 $sql .= ", s.code_client, s.code_compta, s.client";
81 $sql .= ", s.logo, s.email, s.entity";
82 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
83 if (!$user->hasRight('societe', 'client', 'voir')) {
84 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
85 }
86 $sql .= ", ".MAIN_DB_PREFIX."fichinter as f";
87 $sql .= " WHERE f.fk_soc = s.rowid ";
88 $sql .= " AND f.entity = ".$conf->entity;
89 if (!$user->hasRight('societe', 'client', 'voir')) {
90 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
91 }
92 if ($user->socid) {
93 $sql .= " AND s.rowid = ".((int) $user->socid);
94 }
95 $sql .= " ORDER BY f.tms DESC";
96 $sql .= $this->db->plimit($max, 0);
97
98 dol_syslog(get_class($this).'::loadBox', LOG_DEBUG);
99 $resql = $this->db->query($sql);
100 if ($resql) {
101 $num = $this->db->num_rows($resql);
102 $now = dol_now();
103
104 $i = 0;
105
106 while ($i < $num) {
107 $objp = $this->db->fetch_object($resql);
108 $datec = $this->db->jdate($objp->datec);
109 $datem = $this->db->jdate($objp->datem);
110
111 $ficheinterstatic->statut = $objp->status;
112 $ficheinterstatic->status = $objp->status;
113 $ficheinterstatic->id = $objp->rowid;
114 $ficheinterstatic->ref = $objp->ref;
115
116 $thirdpartystatic->id = $objp->socid;
117 $thirdpartystatic->name = $objp->name;
118 //$thirdpartystatic->name_alias = $objp->name_alias;
119 $thirdpartystatic->code_client = $objp->code_client;
120 $thirdpartystatic->code_compta = $objp->code_compta;
121 $thirdpartystatic->client = $objp->client;
122 $thirdpartystatic->logo = $objp->logo;
123 $thirdpartystatic->email = $objp->email;
124 $thirdpartystatic->entity = $objp->entity;
125
126 $this->info_box_contents[$i][] = array(
127 'td' => 'class="nowraponall"',
128 'text' => $ficheinterstatic->getNomUrl(1),
129 'asis' => 1,
130 );
131
132 $this->info_box_contents[$i][] = array(
133 'td' => 'class="tdoverflowmax150"',
134 'text' => $thirdpartystatic->getNomUrl(1),
135 'asis' => 1,
136 );
137
138 $this->info_box_contents[$i][] = array(
139 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
140 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
141 );
142
143 $this->info_box_contents[$i][] = array(
144 'td' => 'class="nowrap right"',
145 'text' => $ficheinterstatic->getLibStatut(3),
146 'asis' => 1,
147 );
148
149 $i++;
150 }
151
152 if ($num == 0) {
153 $this->info_box_contents[$i][0] = array(
154 'td' => 'class="center"',
155 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedInterventions").'</span>'
156 );
157 }
158
159 $this->db->free($resql);
160 } else {
161 $this->info_box_contents[0][0] = array(
162 'td' => '',
163 'maxlength'=>500,
164 'text' => ($this->db->error().' sql='.$sql),
165 );
166 }
167 } else {
168 $this->info_box_contents[0][0] = array(
169 'td' => 'class="nohover left"',
170 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
171 );
172 }
173 }
174
183 public function showBox($head = null, $contents = null, $nooutput = 0)
184 {
185 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
186 }
187}
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_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...