dolibarr 21.0.0-beta
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";
42 public $boxlabel;
43 //var $depends = array("projet");
44
45 public $enabled = 1;
46
53 public function __construct($db, $param = '')
54 {
55 global $conf, $user, $langs;
56
57 // Load translation files required by the page
58 $langs->loadLangs(array('boxes', 'projects'));
59
60 $this->db = $db;
61 $this->boxlabel = "ProjectTasksWithoutTimeSpent";
62
63 $this->hidden = !$user->hasRight('projet', 'lire');
64
65 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
66 $this->enabled = 0;
67 }
68 }
69
76 public function loadBox($max = 5)
77 {
78 global $conf, $user, $langs;
79
80 $this->max = $max;
81
82 $totalMnt = 0;
83 $totalnb = 0;
84 $totalnbTask = 0;
85
86 $textHead = $langs->trans("ProjectTasksWithoutTimeSpent");
87 $this->info_box_head = array('text' => $textHead, 'limit' => dol_strlen($textHead));
88
89 // list the summary of the orders
90 if ($user->hasRight('projet', 'lire')) {
91 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
92 $projectstatic = new Project($this->db);
93
94 $socid = 0;
95 //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.
96
97 // Get list of project id allowed to user (in a string list separated by coma)
98 $projectsListId = '';
99 if (!$user->hasRight('projet', 'all', 'lire')) {
100 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
101 }
102
103 // I tried to solve sql error and performance problem, rewriting sql request but it is not clear what we want.
104 // Count of tasks without time spent for tasks we are assigned too or
105 // Count of tasks without time spent for all tasks of projects we are allowed to read (what it does) ?
106 $sql = "SELECT p.rowid, p.ref, p.fk_soc, p.dateo as startdate,";
107 $sql .= " COUNT(DISTINCT t.rowid) as tasknumber";
108 $sql .= " FROM ".MAIN_DB_PREFIX."projet AS p";
109 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."projet_task AS t ON p.rowid = t.fk_projet";
110 // 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.
111 $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)";
112 $sql .= " WHERE p.fk_statut = 1"; // Only open projects
113 if ($projectsListId) {
114 $sql .= ' AND p.rowid IN ('.$this->db->sanitize($projectsListId).')'; // Only projects that are allowed
115 }
116 $sql .= " AND t.rowid NOT IN (SELECT fk_element FROM ".MAIN_DB_PREFIX."element_time WHERE elementtype = 'task' AND fk_user = ".((int) $user->id).")";
117 $sql .= " GROUP BY p.rowid, p.ref, p.fk_soc, p.dateo";
118 $sql .= " ORDER BY p.dateo ASC";
119
120 $result = $this->db->query($sql);
121 if ($result) {
122 $num = $this->db->num_rows($result);
123 $i = 0;
124 $this->info_box_contents[$i][] = array(
125 'td' => 'class="nowraponall"',
126 'text' => "Reference projet",
127 );
128 $this->info_box_contents[$i][] = array(
129 'td' => 'class="center"',
130 'text' => 'Client',
131 );
132 $this->info_box_contents[$i][] = array(
133 'td' => 'class="center"',
134 'text' => 'Date debut de projet',
135 );
136 $this->info_box_contents[$i][] = array(
137 'td' => 'class="center"',
138 'text' => 'Nombre de mes tâches sans temps saisi',
139 );
140 $i++;
141
142 while ($i < min($num + 1, $max + 1)) {
143 $objp = $this->db->fetch_object($result);
144
145 $projectstatic->id = $objp->rowid;
146 $projectstatic->ref = $objp->ref;
147
148 $this->info_box_contents[$i][] = array(
149 'td' => 'class="nowraponall"',
150 'text' => $projectstatic->getNomUrl(1),
151 'asis' => 1
152 );
153
154 if ($objp->fk_soc > 0) {
155 $sql = "SELECT rowid, nom as name FROM ".MAIN_DB_PREFIX."societe WHERE rowid = ".((int) $objp->fk_soc);
156 $resql = $this->db->query($sql);
157 //$socstatic = new Societe($this->db);
158 $obj2 = $this->db->fetch_object($resql);
159 $this->info_box_contents[$i][] = array(
160 'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
161 'text' => $obj2->name,
162 'asis' => 1,
163 'url' => DOL_URL_ROOT.'/societe/card.php?socid='.urlencode($obj2->rowid)
164 );
165 } else {
166 $this->info_box_contents[$i][] = array(
167 'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
168 'text' => '',
169 'asis' => 1,
170 'url' => ''
171 );
172 }
173
174 $this->info_box_contents[$i][] = array(
175 'td' => 'class="center"',
176 'text' => $objp->startDate,
177 );
178
179 $this->info_box_contents[$i][] = array(
180 'td' => 'class="center"',
181 'text' => $objp->tasknumber."&nbsp;".$langs->trans("Tasks"),
182 'asis' => 1,
183 );
184 $i++;
185 }
186 } else {
187 dol_print_error($this->db);
188 }
189 }
190 }
191
192
193
202 public function showBox($head = null, $contents = null, $nooutput = 0)
203 {
204 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
205 }
206}
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79