dolibarr  9.0.0
box_project.php
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  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
26 include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
27 
31 class box_project extends ModeleBoxes
32 {
33  var $boxcode="project";
34  var $boximg="object_projectpub";
35  var $boxlabel;
36  //var $depends = array("projet");
37 
41  public $db;
42 
43  var $param;
44 
45  var $info_box_head = array();
46  var $info_box_contents = array();
47 
54  function __construct($db,$param='')
55  {
56  global $user, $langs;
57 
58  // Load translation files required by the page
59  $langs->loadLangs(array('boxes', 'projects'));
60 
61  $this->db = $db;
62  $this->boxlabel="Projects";
63 
64  $this->hidden=! ($user->rights->projet->lire);
65  }
66 
73  function loadBox($max=5)
74  {
75  global $conf, $user, $langs, $db;
76 
77  $this->max=$max;
78 
79  $totalMnt = 0;
80  $totalnb = 0;
81  $totalnbTask=0;
82 
83  $textHead = $langs->trans("OpenedProjects");
84  $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
85 
86  // list the summary of the orders
87  if ($user->rights->projet->lire) {
88 
89  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
90  $projectstatic = new Project($this->db);
91 
92  $socid=$user->societe_id;
93 
94  // Get list of project id allowed to user (in a string list separated by coma)
95  $projectsListId='';
96  if (! $user->rights->projet->all->lire) $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1,$socid);
97 
98  $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut, p.public";
99  $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
100  if($user->socid) $sql.= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=p.fk_soc";
101  $sql.= " WHERE p.entity IN (".getEntity('project').')';
102  if (! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")"; // public and assigned to, or restricted to company for external users
103  if ($user->socid) $sql.= " AND s.rowid = ".$user->socid;
104  $sql.= " AND p.fk_statut = 1"; // Seulement les projets ouverts
105  if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
106  if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))";
107 
108  $sql.= " ORDER BY p.datec DESC";
109  //$sql.= $db->plimit($max, 0);
110 
111  $result = $db->query($sql);
112 
113  if ($result) {
114  $num = $db->num_rows($result);
115  $i = 0;
116  while ($i < min($num, $max)) {
117  $objp = $db->fetch_object($result);
118 
119  $projectstatic->id = $objp->rowid;
120  $projectstatic->ref = $objp->ref;
121  $projectstatic->title = $objp->title;
122  $projectstatic->public = $objp->public;
123 
124  $this->info_box_contents[$i][] = array(
125  'td' => '',
126  'text' => $projectstatic->getNomUrl(1),
127  'asis' => 1
128  );
129 
130  $this->info_box_contents[$i][] = array(
131  'td' => '',
132  'text' => $objp->title,
133  );
134 
135  $sql ="SELECT count(*) as nb, sum(progress) as totprogress";
136  $sql.=" FROM ".MAIN_DB_PREFIX."projet as p LEFT JOIN ".MAIN_DB_PREFIX."projet_task as pt on pt.fk_projet = p.rowid";
137  $sql.= " WHERE p.entity IN (".getEntity('project').')';
138  $sql.=" AND p.rowid = ".$objp->rowid;
139  $resultTask = $db->query($sql);
140  if ($resultTask) {
141  $objTask = $db->fetch_object($resultTask);
142  $this->info_box_contents[$i][] = array(
143  'td' => 'class="right"',
144  'text' => $objTask->nb."&nbsp;".$langs->trans("Tasks"),
145  );
146  if ($objTask->nb > 0)
147  $this->info_box_contents[$i][] = array(
148  'td' => 'class="right"',
149  'text' => round($objTask->totprogress/$objTask->nb, 0)."%",
150  );
151  else
152  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
153  $totalnbTask += $objTask->nb;
154  } else {
155  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => round(0));
156  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
157  }
158 
159  $i++;
160  }
161  if ($max < $num)
162  {
163  $this->info_box_contents[$i][] = array('td' => 'colspan="5"', 'text' => '...');
164  $i++;
165  }
166  }
167  }
168 
169 
170  // Add the sum à the bottom of the boxes
171  $this->info_box_contents[$i][] = array(
172  'td' => '',
173  'text' => $langs->trans("Total")."&nbsp;".$textHead,
174  'text' => "&nbsp;",
175  );
176  $this->info_box_contents[$i][] = array(
177  'td' => 'align="right" ',
178  'text' => round($num, 0)."&nbsp;".$langs->trans("Projects"),
179  );
180  $this->info_box_contents[$i][] = array(
181  'td' => 'align="right" ',
182  'text' => (($max < $num) ? '' : (round($totalnbTask, 0)."&nbsp;".$langs->trans("Tasks"))),
183  );
184  $this->info_box_contents[$i][] = array(
185  'td' => '',
186  'text' => "&nbsp;",
187  );
188  }
189 
198  function showBox($head = null, $contents = null, $nooutput=0)
199  {
200  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
201  }
202 }
203 
Class ModeleBoxes.
loadBox($max=5)
Load data for box to show them later.
Definition: box_project.php:73
Class to manage the box to show last projet.
Definition: box_project.php:31
Class to manage projects.
__construct($db, $param='')
Constructor.
Definition: box_project.php:54
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.