dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
30
31
36{
37 public $boxcode = "validated_project";
38 public $boximg = "object_projectpub";
39 public $boxlabel;
40 //var $depends = array("projet");
41
42 public $enabled = 1;
43
50 public function __construct($db, $param = '')
51 {
52 global $conf, $user, $langs;
53
54 // Load translation files required by the page
55 $langs->loadLangs(array('boxes', 'projects'));
56
57 $this->db = $db;
58 $this->boxlabel = "ProjectTasksWithoutTimeSpent";
59
60 $this->hidden = !$user->hasRight('projet', 'lire');
61
62 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
63 $this->enabled = 0;
64 }
65 }
66
73 public function loadBox($max = 5)
74 {
75 global $conf, $user, $langs;
76
77 $this->max = $max;
78
79 $totalMnt = 0;
80 $totalnb = 0;
81 $totalnbTask = 0;
82
83 $textHead = $langs->trans("ProjectTasksWithoutTimeSpent");
84 $this->info_box_head = array('text' => $textHead, 'limit' => dol_strlen($textHead));
85
86 // list the summary of the orders
87 if ($user->hasRight('projet', 'lire')) {
88 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
89 $projectstatic = new Project($this->db);
90
91 $socid = 0;
92 //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 assignment.
93
94 // Get list of project id allowed to user (in a string list separated by coma)
95 $projectsListId = '';
96 if (!$user->hasRight('projet', 'all', 'lire')) {
97 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
98 }
99
100 // I tried to solve sql error and performance problem, rewriting sql request but it is not clear what we want.
101 // Count of tasks without time spent for tasks we are assigned too or
102 // Count of tasks without time spent for all tasks of projects we are allowed to read (what it does) ?
103 $sql = "SELECT p.rowid, p.ref, p.fk_soc, p.dateo as startdate,";
104 $sql .= " COUNT(DISTINCT t.rowid) as tasknumber";
105 $sql .= " FROM ".MAIN_DB_PREFIX."projet AS p";
106 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."projet_task AS t ON p.rowid = t.fk_projet";
107 // 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.
108 $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)";
109 $sql .= " WHERE p.fk_statut = 1"; // Only open projects
110 if ($projectsListId) {
111 $sql .= ' AND p.rowid IN ('.$this->db->sanitize($projectsListId).')'; // Only projects that are allowed
112 }
113 $sql .= " AND t.rowid NOT IN (SELECT fk_element FROM ".MAIN_DB_PREFIX."element_time WHERE elementtype = 'task' AND fk_user = ".((int) $user->id).")";
114 $sql .= " GROUP BY p.rowid, p.ref, p.fk_soc, p.dateo";
115 $sql .= " ORDER BY p.dateo ASC";
116
117 $result = $this->db->query($sql);
118 if ($result) {
119 $num = $this->db->num_rows($result);
120 $i = 0;
121 $this->info_box_contents[$i][] = array(
122 'td' => 'class="nowraponall"',
123 'text' => "Reference projet",
124 );
125 $this->info_box_contents[$i][] = array(
126 'td' => 'class="center"',
127 'text' => 'Client',
128 );
129 $this->info_box_contents[$i][] = array(
130 'td' => 'class="center"',
131 'text' => 'Date debut de projet',
132 );
133 $this->info_box_contents[$i][] = array(
134 'td' => 'class="center"',
135 'text' => 'Nombre de mes tâches sans temps saisi',
136 );
137 $i++;
138
139 while ($i < min($num + 1, $max + 1)) {
140 $objp = $this->db->fetch_object($result);
141
142 $projectstatic->id = $objp->rowid;
143 $projectstatic->ref = $objp->ref;
144
145 $this->info_box_contents[$i][] = array(
146 'td' => 'class="nowraponall"',
147 'text' => $projectstatic->getNomUrl(1),
148 'asis' => 1
149 );
150
151 if ($objp->fk_soc > 0) {
152 $sql = "SELECT rowid, nom as name FROM ".MAIN_DB_PREFIX."societe WHERE rowid = ".((int) $objp->fk_soc);
153 $resql = $this->db->query($sql);
154 //$socstatic = new Societe($this->db);
155 $obj2 = $this->db->fetch_object($resql);
156 $this->info_box_contents[$i][] = array(
157 'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
158 'text' => $obj2->name,
159 'asis' => 1,
160 'url' => DOL_URL_ROOT.'/societe/card.php?socid='.urlencode($obj2->rowid)
161 );
162 } else {
163 $this->info_box_contents[$i][] = array(
164 'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
165 'text' => '',
166 'asis' => 1,
167 'url' => ''
168 );
169 }
170
171 $this->info_box_contents[$i][] = array(
172 'td' => 'class="center"',
173 'text' => $objp->startDate,
174 );
175
176 $this->info_box_contents[$i][] = array(
177 'td' => 'class="center"',
178 'text' => $objp->tasknumber."&nbsp;".$langs->trans("Tasks"),
179 'asis' => 1,
180 );
181 $i++;
182 }
183 } else {
184 dol_print_error($this->db);
185 }
186 }
187 }
188
189
190
199 public function showBox($head = null, $contents = null, $nooutput = 0)
200 {
201 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
202 }
203}
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_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...