68 global $conf, $user, $langs;
71 include_once DOL_DOCUMENT_ROOT.
"/projet/class/task.class.php";
72 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
73 require_once DOL_DOCUMENT_ROOT.
"/core/lib/project.lib.php";
74 $projectstatic =
new Project($this->db);
75 $taskstatic =
new Task($this->db);
76 $form =
new Form($this->db);
77 $cookie_name =
'DOLUSERCOOKIE_boxfilter_task';
79 $socid = $user->socid;
81 $textHead = $langs->trans(
"CurentlyOpenedTasks");
84 if (in_array(
GETPOST($cookie_name), array(
'all',
'im_project_contact',
'im_task_contact'))) {
85 $filterValue =
GETPOST($cookie_name);
86 } elseif (!empty($_COOKIE[$cookie_name])) {
87 $filterValue = preg_replace(
'/[^a-z_]/',
'', $_COOKIE[$cookie_name]);
90 if ($filterValue ==
'im_task_contact') {
91 $textHead .=
' : '.$langs->trans(
"WhichIamLinkedTo");
92 } elseif ($filterValue ==
'im_project_contact') {
93 $textHead .=
' : '.$langs->trans(
"WhichIamLinkedToProject");
97 $this->info_box_head = array(
101 'subtext'=>$langs->trans(
"Filter"),
102 'subpicto'=>
'filter.png',
103 'subclass'=>
'linkobject boxfilter',
108 if ($user->hasRight(
'projet',
'lire')) {
109 $boxcontent .=
'<div id="ancor-idfilter'.$this->boxcode.
'" style="display: block; position: absolute; margin-top: -100px"></div>'.
"\n";
110 $boxcontent .=
'<div id="idfilter'.$this->boxcode.
'" class="center" >'.
"\n";
111 $boxcontent .=
'<form class="flat " method="POST" action="'.$_SERVER[
"PHP_SELF"].
'#ancor-idfilter'.$this->boxcode.
'">'.
"\n";
112 $boxcontent .=
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
113 $selectArray = array(
'all' => $langs->trans(
"NoFilter"),
'im_task_contact' => $langs->trans(
"WhichIamLinkedTo"),
'im_project_contact' => $langs->trans(
"WhichIamLinkedToProject"));
114 $boxcontent .= $form->selectArray($cookie_name, $selectArray, $filterValue);
115 $boxcontent .=
'<button type="submit" class="button buttongen button-save">'.$langs->trans(
"Refresh").
'</button>';
116 $boxcontent .=
'</form>'.
"\n";
117 $boxcontent .=
'</div>'.
"\n";
118 if (!empty($conf->use_javascript_ajax)) {
119 $boxcontent .=
'<script nonce="'.getNonce().
'" type="text/javascript">
120 jQuery(document).ready(function() {
121 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
122 jQuery(".showiffilter'.$this->boxcode.
'").toggle();
127 $boxcontent .=
'<script nonce="'.getNonce().
'">date = new Date(); date.setTime(date.getTime()+(30*86400000)); document.cookie = "'.$cookie_name.
'='.$filterValue.
'; expires= " + date.toGMTString() + "; path=/ ; SameSite=Lax"; </script>';
129 $this->info_box_contents[0][] = array(
130 'tr' =>
'class="nohover showiffilter'.$this->boxcode.
' hideobject"',
131 'td' =>
'class="nohover"',
132 'textnoformat' => $boxcontent,
137 $projectsListId =
'';
138 if (!$user->hasRight(
'projet',
'all',
'lire')) {
139 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
142 $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";
143 $sql .=
", p.rowid project_id, p.ref project_ref, p.title project_title, p.fk_statut";
145 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as pt";
146 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"projet as p ON (pt.fk_projet = p.rowid)";
148 if ($filterValue ===
'im_task_contact') {
149 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"element_contact as ec ON (ec.element_id = pt.rowid AND ec.fk_socpeople = ".((int) $user->id).
")";
150 $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' )";
151 } elseif ($filterValue ===
'im_project_contact') {
152 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"element_contact as ec ON (ec.element_id = p.rowid AND ec.fk_socpeople = ".((int) $user->id).
")";
153 $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' )";
157 $sql .=
" pt.entity = ".$conf->entity;
158 $sql .=
" AND p.fk_statut = ".Project::STATUS_VALIDATED;
159 $sql .=
" AND (pt.progress < 100 OR pt.progress IS NULL ) ";
160 $sql .=
" AND p.usage_task = 1 ";
161 if (!$user->hasRight(
'projet',
'all',
'lire')) {
162 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
165 $sql .=
" ORDER BY pt.datee ASC, pt.dateo ASC";
166 $sql .= $this->db->plimit($max, 0);
168 $result = $this->db->query($sql);
171 $num = $this->db->num_rows($result);
172 while ($objp = $this->db->fetch_object($result)) {
173 $taskstatic->id = $objp->rowid;
174 $taskstatic->ref = $objp->ref;
175 $taskstatic->label = $objp->label;
176 $taskstatic->progress = $objp->progress;
177 $taskstatic->status = $objp->fk_statut;
178 $taskstatic->date_end = $this->db->jdate($objp->datee);
179 $taskstatic->planned_workload = $objp->planned_workload;
180 $taskstatic->duration_effective = $objp->duration_effective;
182 $projectstatic->id = $objp->project_id;
183 $projectstatic->ref = $objp->project_ref;
184 $projectstatic->title = $objp->project_title;
186 $label = $projectstatic->getNomUrl(1).
' '.$taskstatic->getNomUrl(1).
' '.
dol_htmlentities($taskstatic->label);
190 $this->info_box_contents[$i][] = array(
192 'text' => $boxcontent,