dolibarr  17.0.4
box_task.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2012-2018 Charlene BENKE <charlie@patas-monkey.com>
3  * Copyright (C) 2015-2021 Frederic France <frederic.france@netlogic.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
26 require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
27 
28 
32 class box_task extends ModeleBoxes
33 {
34  public $boxcode = "projettask";
35  public $boximg = "object_projecttask";
36  public $boxlabel;
37  public $depends = array("projet");
38 
42  public $db;
43 
44  public $param;
45  public $enabled = 1; // enable because fixed ;-).
46 
47  public $info_box_head = array();
48  public $info_box_contents = array();
49 
50 
57  public function __construct($db, $param = '')
58  {
59  global $conf, $user, $langs;
60 
61  // Load translation files required by the page
62  $langs->loadLangs(array('boxes', 'projects'));
63 
64  $this->boxlabel = "Tasks";
65  $this->db = $db;
66 
67  $this->hidden = (!empty($conf->global->PROJECT_HIDE_TASKS) || empty($user->rights->projet->lire));
68  }
69 
76  public function loadBox($max = 5)
77  {
78  global $conf, $user, $langs;
79 
80  $this->max = $max;
81  include_once DOL_DOCUMENT_ROOT."/projet/class/task.class.php";
82  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
83  require_once DOL_DOCUMENT_ROOT."/core/lib/project.lib.php";
84  $projectstatic = new Project($this->db);
85  $taskstatic = new Task($this->db);
86  $form = new Form($this->db);
87  $cookie_name = 'DOLUSERCOOKIE_boxfilter_task';
88  $boxcontent = '';
89  $socid = $user->socid;
90 
91  $textHead = $langs->trans("CurentlyOpenedTasks");
92 
93  $filterValue = 'all';
94  if (in_array(GETPOST($cookie_name), array('all', 'im_project_contact', 'im_task_contact'))) {
95  $filterValue = GETPOST($cookie_name);
96  } elseif (!empty($_COOKIE[$cookie_name])) {
97  $filterValue = preg_replace('/[^a-z_]/', '', $_COOKIE[$cookie_name]); // Clean cookie from evil data
98  }
99 
100  if ($filterValue == 'im_task_contact') {
101  $textHead .= ' : '.$langs->trans("WhichIamLinkedTo");
102  } elseif ($filterValue == 'im_project_contact') {
103  $textHead .= ' : '.$langs->trans("WhichIamLinkedToProject");
104  }
105 
106 
107  $this->info_box_head = array(
108  'text' => $textHead,
109  'limit'=> dol_strlen($textHead),
110  'sublink'=>'',
111  'subtext'=>$langs->trans("Filter"),
112  'subpicto'=>'filter.png',
113  'subclass'=>'linkobject boxfilter',
114  'target'=>'none' // Set '' to get target="_blank"
115  );
116 
117  // list the summary of the orders
118  if ($user->rights->projet->lire) {
119  $boxcontent .= '<div id="ancor-idfilter'.$this->boxcode.'" style="display: block; position: absolute; margin-top: -100px"></div>'."\n";
120  $boxcontent .= '<div id="idfilter'.$this->boxcode.'" class="center" >'."\n";
121  $boxcontent .= '<form class="flat " method="POST" action="'.$_SERVER["PHP_SELF"].'#ancor-idfilter'.$this->boxcode.'">'."\n";
122  $boxcontent .= '<input type="hidden" name="token" value="'.newToken().'">'."\n";
123  $selectArray = array('all' => $langs->trans("NoFilter"), 'im_task_contact' => $langs->trans("WhichIamLinkedTo"), 'im_project_contact' => $langs->trans("WhichIamLinkedToProject"));
124  $boxcontent .= $form->selectArray($cookie_name, $selectArray, $filterValue);
125  $boxcontent .= '<button type="submit" class="button buttongen button-save">'.$langs->trans("Refresh").'</button>';
126  $boxcontent .= '</form>'."\n";
127  $boxcontent .= '</div>'."\n";
128  if (!empty($conf->use_javascript_ajax)) {
129  $boxcontent .= '<script type="text/javascript">
130  jQuery(document).ready(function() {
131  jQuery("#idsubimg'.$this->boxcode.'").click(function() {
132  jQuery(".showiffilter'.$this->boxcode.'").toggle();
133  });
134  });
135  </script>';
136  // set cookie by js
137  $boxcontent .= '<script>date = new Date(); date.setTime(date.getTime()+(30*86400000)); document.cookie = "'.$cookie_name.'='.$filterValue.'; expires= " + date.toGMTString() + "; path=/ "; </script>';
138  }
139  $this->info_box_contents[0][] = array(
140  'tr' => 'class="nohover showiffilter'.$this->boxcode.' hideobject"',
141  'td' => 'class="nohover"',
142  'textnoformat' => $boxcontent,
143  );
144 
145 
146  // Get list of project id allowed to user (in a string list separated by coma)
147  $projectsListId = '';
148  if (empty($user->rights->projet->all->lire)) {
149  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
150  }
151 
152  $sql = "SELECT pt.rowid, pt.ref, pt.fk_projet, pt.fk_task_parent, pt.datec, pt.dateo, pt.datee, pt.datev, pt.label, pt.description, pt.duration_effective, pt.planned_workload, pt.progress";
153  $sql .= ", p.rowid project_id, p.ref project_ref, p.title project_title, p.fk_statut";
154 
155  $sql .= " FROM ".MAIN_DB_PREFIX."projet_task as pt";
156  $sql .= " JOIN ".MAIN_DB_PREFIX."projet as p ON (pt.fk_projet = p.rowid)";
157 
158  if ($filterValue === 'im_task_contact') {
159  $sql .= " JOIN ".MAIN_DB_PREFIX."element_contact as ec ON (ec.element_id = pt.rowid AND ec.fk_socpeople = ".((int) $user->id).")";
160  $sql .= " JOIN ".MAIN_DB_PREFIX."c_type_contact as tc ON (ec.fk_c_type_contact = tc.rowid AND tc.element = 'project_task' AND tc.source = 'internal' )";
161  } elseif ($filterValue === 'im_project_contact') {
162  $sql .= " JOIN ".MAIN_DB_PREFIX."element_contact as ec ON (ec.element_id = p.rowid AND ec.fk_socpeople = ".((int) $user->id).")";
163  $sql .= " JOIN ".MAIN_DB_PREFIX."c_type_contact as tc ON (ec.fk_c_type_contact = tc.rowid AND tc.element = 'project' AND tc.source = 'internal' )";
164  }
165 
166  $sql .= " WHERE ";
167  $sql .= " pt.entity = ".$conf->entity;
168  $sql .= " AND p.fk_statut = ".Project::STATUS_VALIDATED;
169  $sql .= " AND (pt.progress < 100 OR pt.progress IS NULL ) "; // 100% is done and not displayed
170  $sql .= " AND p.usage_task = 1 ";
171  if (empty($user->rights->projet->all->lire)) {
172  $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
173  }
174 
175  $sql .= " ORDER BY pt.datee ASC, pt.dateo ASC";
176  $sql .= $this->db->plimit($max, 0);
177 
178  $result = $this->db->query($sql);
179  $i = 1;
180  if ($result) {
181  $num = $this->db->num_rows($result);
182  while ($objp = $this->db->fetch_object($result)) {
183  $taskstatic->id = $objp->rowid;
184  $taskstatic->ref = $objp->ref;
185  $taskstatic->label = $objp->label;
186  $taskstatic->progress = $objp->progress;
187  $taskstatic->fk_statut = $objp->fk_statut;
188  $taskstatic->date_end = $this->db->jdate($objp->datee);
189  $taskstatic->planned_workload = $objp->planned_workload;
190  $taskstatic->duration_effective = $objp->duration_effective;
191 
192  $projectstatic->id = $objp->project_id;
193  $projectstatic->ref = $objp->project_ref;
194  $projectstatic->title = $objp->project_title;
195 
196  $label = $projectstatic->getNomUrl(1).' &nbsp; '.$taskstatic->getNomUrl(1).' '.dol_htmlentities($taskstatic->label);
197 
198  $boxcontent = getTaskProgressView($taskstatic, $label, true, false, false);
199 
200  $this->info_box_contents[$i][] = array(
201  'td' => '',
202  'text' => $boxcontent,
203  );
204  $i++;
205  }
206  } else {
207  dol_print_error($this->db);
208  }
209  }
210  }
211 
220  public function showBox($head = null, $contents = null, $nooutput = 0)
221  {
222  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
223  }
224 }
Class to manage generation of HTML components Only common components must be here.
Class ModeleBoxes.
Class to manage projects.
Class to manage tasks.
Definition: task.class.php:38
Class to manage the box to show last task.
Definition: box_task.php:33
loadBox($max=5)
Load data for box to show them later.
Definition: box_task.php:76
__construct($db, $param='')
Constructor.
Definition: box_task.php:57
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_task.php:220
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getTaskProgressView($task, $label=true, $progressNumber=true, $hideOnProgressNull=false, $spaced=false)
$conf db
API class for accounts.
Definition: inc.php:41