dolibarr 21.0.0-beta
box_project.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) 2024 MDW <mdeweerd@users.noreply.github.com>
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
34{
35 public $boxcode = "project";
36 public $boximg = "object_projectpub";
40 public $boxlabel;
41 // var $depends = array("projet");
42
49 public function __construct($db, $param = '')
50 {
51 global $user, $langs;
52
53 // Load translation files required by the page
54 $langs->loadLangs(array('boxes', 'projects'));
55
56 $this->db = $db;
57 $this->boxlabel = "OpenedProjects";
58
59 $this->hidden = !$user->hasRight('projet', 'lire');
60 $this->urltoaddentry = DOL_URL_ROOT.'/projet/card.php?action=create';
61 $this->msgNoRecords = 'NoOpenedProjects';
62 }
63
70 public function loadBox($max = 5)
71 {
72 global $conf, $user, $langs;
73
74 $this->max = $max;
75
76 $totalMnt = 0;
77 $totalnb = 0;
78 $totalnbTask = 0;
79 $num = 0;
80
81 $textHead = $langs->trans("OpenedProjects");
82 $this->info_box_head = array('text' => $textHead, 'limit' => dol_strlen($textHead));
83
84 $i = 0;
85 // list the summary of the orders
86 if ($user->hasRight('projet', 'lire')) {
87 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
88 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
89 $projectstatic = new Project($this->db);
90 $companystatic = new Societe($this->db);
91
92 $socid = 0;
93 //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.
94
95 // Get list of project id allowed to user (in a string list separated by coma)
96 $projectsListId = '';
97 if (!$user->hasRight('projet', 'all', 'lire')) {
98 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
99 }
100
101 $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut as status, p.public, p.fk_soc,";
102 $sql .= " s.nom as name, s.name_alias";
103 $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
104 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
105 $sql .= " WHERE p.entity IN (".getEntity('project').")"; // Only current entity or severals if permission ok
106 $sql .= " AND p.fk_statut = ".((int) $projectstatic::STATUS_VALIDATED); // Only open projects
107 if (!$user->hasRight('projet', 'all', 'lire')) {
108 $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
109 }
110
111 $sql .= " ORDER BY p.datec DESC";
112 //$sql.= $this->db->plimit($max, 0);
113
114 $result = $this->db->query($sql);
115
116 if ($result) {
117 $num = $this->db->num_rows($result);
118 while ($i < min($num, $max)) {
119 $objp = $this->db->fetch_object($result);
120
121 $projectstatic->id = $objp->rowid;
122 $projectstatic->ref = $objp->ref;
123 $projectstatic->title = $objp->title;
124 $projectstatic->public = $objp->public;
125 $projectstatic->statut = $objp->status;
126
127 $companystatic->id = $objp->fk_soc;
128 $companystatic->name = $objp->name;
129 $companystatic->name_alias = $objp->name_alias;
130
131 $this->info_box_contents[$i][] = array(
132 'td' => 'class="nowraponall"',
133 'text' => $projectstatic->getNomUrl(1),
134 'asis' => 1
135 );
136
137 $this->info_box_contents[$i][] = array(
138 'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
139 'text' => $objp->title,
140 );
141
142 $this->info_box_contents[$i][] = array(
143 'td' => 'class="tdoverflowmax100"',
144 'text' => ($objp->fk_soc > 0 ? $companystatic->getNomUrl(1) : ''),
145 'asis' => 1
146 );
147
148 $sql = "SELECT count(*) as nb, sum(progress) as totprogress";
149 $sql .= " FROM ".MAIN_DB_PREFIX."projet as p LEFT JOIN ".MAIN_DB_PREFIX."projet_task as pt on pt.fk_projet = p.rowid";
150 $sql .= " WHERE p.entity IN (".getEntity('project').')';
151 $sql .= " AND p.rowid = ".((int) $objp->rowid);
152
153 $resultTask = $this->db->query($sql);
154 if ($resultTask) {
155 $objTask = $this->db->fetch_object($resultTask);
156 $this->info_box_contents[$i][] = array(
157 'td' => 'class="right"',
158 'text' => $objTask->nb."&nbsp;".$langs->trans("Tasks"),
159 );
160 if ($objTask->nb > 0) {
161 $this->info_box_contents[$i][] = array(
162 'td' => 'class="right"',
163 'text' => round($objTask->totprogress / $objTask->nb, 0)."%",
164 );
165 } else {
166 $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
167 }
168 $totalnbTask += $objTask->nb;
169 } else {
170 $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => round(0));
171 $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
172 }
173 $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => $projectstatic->getLibStatut(3));
174
175 $i++;
176 }
177 if ($max < $num) {
178 $this->info_box_contents[$i][] = array('td' => 'colspan="6"', 'text' => '...');
179 $i++;
180 }
181 }
182 }
183
184 if ($num > 0) {
185 // Add the sum à the bottom of the boxes
186 $this->info_box_contents[$i][] = array(
187 'tr' => 'class="liste_total_wrap"',
188 'td' => 'class="liste_total"',
189 'text' => $langs->trans("Total")."&nbsp;".$textHead,
190 );
191 $this->info_box_contents[$i][] = array(
192 'td' => 'class="right liste_total" ',
193 'text' => round($num, 0)."&nbsp;".$langs->trans("Projects"),
194 );
195 $this->info_box_contents[$i][] = array(
196 'td' => 'class="right liste_total" ',
197 'text' => (($max < $num) ? '' : (round($totalnbTask, 0)."&nbsp;".$langs->trans("Tasks"))),
198 );
199 $this->info_box_contents[$i][] = array(
200 'td' => 'class="liste_total"',
201 'text' => "&nbsp;",
202 );
203 $this->info_box_contents[$i][] = array(
204 'td' => 'class="liste_total"',
205 'text' => "&nbsp;",
206 );
207 $this->info_box_contents[$i][] = array(
208 'td' => 'class="liste_total"',
209 'text' => "&nbsp;",
210 );
211 }
212 }
213
214
215
224 public function showBox($head = null, $contents = null, $nooutput = 0)
225 {
226 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
227 }
228}
Class ModeleBoxes.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last project.
loadBox($max=5)
Load data for box to show them later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param='')
Constructor.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79