dolibarr  7.0.0-beta
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  var $db;
38  var $param;
39 
40  var $info_box_head = array();
41  var $info_box_contents = array();
42 
49  function __construct($db,$param='')
50  {
51  global $user, $langs;
52  $langs->load("boxes");
53  $langs->load("projects");
54 
55  $this->db = $db;
56  $this->boxlabel="Projects";
57 
58  $this->hidden=! ($user->rights->projet->lire);
59  }
60 
67  function loadBox($max=5)
68  {
69  global $conf, $user, $langs, $db;
70 
71  $this->max=$max;
72 
73  $totalMnt = 0;
74  $totalnb = 0;
75  $totalnbTask=0;
76 
77  $textHead = $langs->trans("OpenedProjects");
78  $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
79 
80  // list the summary of the orders
81  if ($user->rights->projet->lire) {
82 
83  include_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php');
84  $projectstatic = new Project($this->db);
85 
86  $socid=$user->societe_id;
87 
88  // Get list of project id allowed to user (in a string list separated by coma)
89  $projectsListId='';
90  if (! $user->rights->projet->all->lire) $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1,$socid);
91 
92  $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut, p.public";
93  $sql.= " FROM ".MAIN_DB_PREFIX."projet as p";
94  if($user->socid) $sql.= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=p.fk_soc";
95  $sql.= " WHERE p.entity IN (".getEntity('project').')';
96  if (! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")"; // public and assigned to, or restricted to company for external users
97  if ($user->socid) $sql.= " AND s.rowid = ".$user->socid;
98  $sql.= " AND p.fk_statut = 1"; // Seulement les projets ouverts
99  if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
100  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))";
101 
102  $sql.= " ORDER BY p.datec DESC";
103  //$sql.= $db->plimit($max, 0);
104 
105  $result = $db->query($sql);
106 
107  if ($result) {
108  $num = $db->num_rows($result);
109  $i = 0;
110  while ($i < min($num, $max)) {
111  $objp = $db->fetch_object($result);
112 
113  $projectstatic->id = $objp->rowid;
114  $projectstatic->ref = $objp->ref;
115  $projectstatic->title = $objp->title;
116  $projectstatic->public = $objp->public;
117 
118  $this->info_box_contents[$i][] = array(
119  'td' => '',
120  'text' => $projectstatic->getNomUrl(1),
121  'asis' => 1
122  );
123 
124  $this->info_box_contents[$i][] = array(
125  'td' => '',
126  'text' => $objp->title,
127  );
128 
129  $sql ="SELECT count(*) as nb, sum(progress) as totprogress";
130  $sql.=" FROM ".MAIN_DB_PREFIX."projet as p LEFT JOIN ".MAIN_DB_PREFIX."projet_task as pt on pt.fk_projet = p.rowid";
131  $sql.= " WHERE p.entity IN (".getEntity('project').')';
132  $sql.=" AND p.rowid = ".$objp->rowid;
133  $resultTask = $db->query($sql);
134  if ($resultTask) {
135  $objTask = $db->fetch_object($resultTask);
136  $this->info_box_contents[$i][] = array(
137  'td' => 'class="right"',
138  'text' => $objTask->nb."&nbsp;".$langs->trans("Tasks"),
139  );
140  if ($objTask->nb > 0)
141  $this->info_box_contents[$i][] = array(
142  'td' => 'class="right"',
143  'text' => round($objTask->totprogress/$objTask->nb, 0)."%",
144  );
145  else
146  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
147  $totalnbTask += $objTask->nb;
148  } else {
149  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => round(0));
150  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
151  }
152 
153  $i++;
154  }
155  if ($max < $num)
156  {
157  $this->info_box_contents[$i][] = array('td' => 'colspan="5"', 'text' => '...');
158  $i++;
159  }
160  }
161  }
162 
163 
164  // Add the sum à the bottom of the boxes
165  $this->info_box_contents[$i][] = array(
166  'td' => '',
167  'text' => $langs->trans("Total")."&nbsp;".$textHead,
168  'text' => "&nbsp;",
169  );
170  $this->info_box_contents[$i][] = array(
171  'td' => 'align="right" ',
172  'text' => round($num, 0)."&nbsp;".$langs->trans("Projects"),
173  );
174  $this->info_box_contents[$i][] = array(
175  'td' => 'align="right" ',
176  'text' => (($max < $num) ? '' : (round($totalnbTask, 0)."&nbsp;".$langs->trans("Tasks"))),
177  );
178  $this->info_box_contents[$i][] = array(
179  'td' => '',
180  'text' => "&nbsp;",
181  );
182 
183  }
184 
193  function showBox($head = null, $contents = null, $nooutput=0)
194  {
195  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
196  }
197 }
198 
Class ModeleBoxes.
loadBox($max=5)
Load data for box to show them later.
Definition: box_project.php:67
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:49
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.