dolibarr 18.0.6
box_validated_projects.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012-2014 Charles-François BENKE <charles.fr@benke.fr>
3 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
4 * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
5 * Copyright (C) 2016 Juan José Menent <jmenent@2byte.es>
6 * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
7 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
28include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
29
30
35{
36 public $boxcode = "validated_project";
37 public $boximg = "object_projectpub";
38 public $boxlabel;
39 //var $depends = array("projet");
40
44 public $db;
45
46 public $param;
47
48 public $info_box_head = array();
49 public $info_box_contents = array();
50
51 public $enabled = 1;
52
53
60 public function __construct($db, $param = '')
61 {
62 global $conf, $user, $langs;
63
64 // Load translation files required by the page
65 $langs->loadLangs(array('boxes', 'projects'));
66
67 $this->db = $db;
68 $this->boxlabel = "ProjectTasksWithoutTimeSpent";
69
70 $this->hidden = empty($user->rights->projet->lire);
71
72 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
73 $this->enabled = 0;
74 }
75 }
76
83 public function loadBox($max = 5)
84 {
85 global $conf, $user, $langs;
86
87 $this->max = $max;
88
89 $totalMnt = 0;
90 $totalnb = 0;
91 $totalnbTask = 0;
92
93 $textHead = $langs->trans("ProjectTasksWithoutTimeSpent");
94 $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
95
96 // list the summary of the orders
97 if ($user->rights->projet->lire) {
98 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
99 $projectstatic = new Project($this->db);
100
101 $socid = 0;
102 //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
103
104 // Get list of project id allowed to user (in a string list separated by coma)
105 $projectsListId = '';
106 if (empty($user->rights->projet->all->lire)) {
107 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
108 }
109
110 // I tried to solve sql error and performance problem, rewriting sql request but it is not clear what we want.
111 // Count of tasks without time spent for tasks we are assigned too or
112 // Count of tasks without time spent for all tasks of projects we are allowed to read (what it does) ?
113 $sql = "SELECT p.rowid, p.ref, p.fk_soc, p.dateo as startdate,";
114 $sql .= " COUNT(DISTINCT t.rowid) as tasknumber";
115 $sql .= " FROM ".MAIN_DB_PREFIX."projet AS p";
116 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."projet_task AS t ON p.rowid = t.fk_projet";
117 // TODO Replace -1, -2, -3 with ID used for type of contact project_task into llx_c_type_contact. Once done, we can switch widget as stable.
118 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."element_contact as ec ON ec.element_id = t.rowid AND fk_c_type_contact IN (-1, -2, -3)";
119 $sql .= " WHERE p.fk_statut = 1"; // Only open projects
120 if ($projectsListId) {
121 $sql .= ' AND p.rowid IN ('.$this->db->sanitize($projectsListId).')'; // Only projects that are allowed
122 }
123 $sql .= " AND t.rowid NOT IN (SELECT fk_element FROM ".MAIN_DB_PREFIX."element_time WHERE elementtype = 'task' AND fk_user = ".((int) $user->id).")";
124 $sql .= " GROUP BY p.rowid, p.ref, p.fk_soc, p.dateo";
125 $sql .= " ORDER BY p.dateo ASC";
126
127 $result = $this->db->query($sql);
128 if ($result) {
129 $num = $this->db->num_rows($result);
130 $i = 0;
131 $this->info_box_contents[$i][] = array(
132 'td' => 'class="nowraponall"',
133 'text' => "Reference projet",
134 );
135 $this->info_box_contents[$i][] = array(
136 'td' => 'class="center"',
137 'text' => 'Client',
138 );
139 $this->info_box_contents[$i][] = array(
140 'td' => 'class="center"',
141 'text' => 'Date debut de projet',
142 );
143 $this->info_box_contents[$i][] = array(
144 'td' => 'class="center"',
145 'text' => 'Nombre de mes tâches sans temps saisi',
146 );
147 $i++;
148
149 while ($i < min($num + 1, $max + 1)) {
150 $objp = $this->db->fetch_object($result);
151
152 $projectstatic->id = $objp->rowid;
153 $projectstatic->ref = $objp->ref;
154
155 $this->info_box_contents[$i][] = array(
156 'td' => 'class="nowraponall"',
157 'text' => $projectstatic->getNomUrl(1),
158 'asis' => 1
159 );
160
161 if ($objp->fk_soc > 0) {
162 $sql = "SELECT rowid, nom as name FROM ".MAIN_DB_PREFIX."societe WHERE rowid = ".((int) $objp->fk_soc);
163 $resql = $this->db->query($sql);
164 //$socstatic = new Societe($this->db);
165 $obj2 = $this->db->fetch_object($resql);
166 $this->info_box_contents[$i][] = array(
167 'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
168 'text' => $obj2->name,
169 'asis' => 1,
170 'url' => DOL_URL_ROOT.'/societe/card.php?socid='.urlencode($obj2->rowid)
171 );
172 } else {
173 $this->info_box_contents[$i][] = array(
174 'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
175 'text' => '',
176 'asis' => 1,
177 'url' => ''
178 );
179 }
180
181 $this->info_box_contents[$i][] = array(
182 'td' => 'class="center"',
183 'text' => $objp->startDate,
184 );
185
186 $this->info_box_contents[$i][] = array(
187 'td' => 'class="center"',
188 'text' => $objp->tasknumber."&nbsp;".$langs->trans("Tasks"),
189 'asis' => 1,
190 );
191 $i++;
192 }
193 } else {
194 dol_print_error($this->db);
195 }
196 }
197 }
198
207 public function showBox($head = null, $contents = null, $nooutput = 0)
208 {
209 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
210 }
211}
Class ModeleBoxes.
Class to manage projects.
Class to manage the box to show last projet.
__construct($db, $param='')
Constructor.
loadBox($max=5)
Load data for box to show them later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.