72 global
$conf, $user, $langs;
75 include_once DOL_DOCUMENT_ROOT.
"/projet/class/task.class.php";
76 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
77 require_once DOL_DOCUMENT_ROOT.
"/core/lib/project.lib.php";
78 $projectstatic =
new Project($this->db);
79 $taskstatic =
new Task($this->db);
80 $form =
new Form($this->db);
81 $cookie_name =
'DOLUSER_boxfilter_task';
83 $socid = $user->socid;
85 $textHead = $langs->trans(
"CurentlyOpenedTasks");
88 if (in_array(
GETPOST($cookie_name), array(
'all',
'im_project_contact',
'im_task_contact'))) {
89 $filterValue =
GETPOST($cookie_name);
90 } elseif (!empty($_COOKIE[$cookie_name])) {
91 $filterValue = preg_replace(
'/[^a-z_]/',
'', $_COOKIE[$cookie_name]);
94 if ($filterValue ==
'im_task_contact') {
95 $textHead .=
' : '.$langs->trans(
"WhichIamLinkedTo");
96 } elseif ($filterValue ==
'im_project_contact') {
97 $textHead .=
' : '.$langs->trans(
"WhichIamLinkedToProject");
101 $this->info_box_head = array(
105 'subtext' => $langs->trans(
"Filter"),
106 'subpicto' =>
'filter.png',
107 'subclass' =>
'linkobject boxfilter',
112 if ($user->hasRight(
'projet',
'lire')) {
113 $boxcontent .=
'<div id="ancor-idfilter'.$this->boxcode.
'" style="display: block; position: absolute; margin-top: -100px"></div>'.
"\n";
114 $boxcontent .=
'<div id="idfilter'.$this->boxcode.
'" class="center" >'.
"\n";
115 $boxcontent .=
'<form class="flat " method="POST" action="'.$_SERVER[
"PHP_SELF"].
'#ancor-idfilter'.$this->boxcode.
'">'.
"\n";
116 $boxcontent .=
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
117 $selectArray = array(
'all' => $langs->trans(
"NoFilter"),
'im_task_contact' => $langs->trans(
"WhichIamLinkedTo"),
'im_project_contact' => $langs->trans(
"WhichIamLinkedToProject"));
118 $boxcontent .= $form->selectArray($cookie_name, $selectArray, $filterValue);
119 $boxcontent .=
'<button type="submit" class="button buttongen button-save">'.$langs->trans(
"Refresh").
'</button>';
120 $boxcontent .=
'</form>'.
"\n";
121 $boxcontent .=
'</div>'.
"\n";
122 if (!empty(
$conf->use_javascript_ajax)) {
123 $boxcontent .=
'<script nonce="'.getNonce().
'" type="text/javascript">
124 jQuery(document).ready(function() {
125 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
126 jQuery(".showiffilter'.$this->boxcode.
'").toggle();
131 $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>';
133 $this->info_box_contents[0][] = array(
134 'tr' =>
'class="nohover showiffilter'.$this->boxcode.
' hideobject"',
135 'td' =>
'class="nohover"',
136 'textnoformat' => $boxcontent,
141 $projectsListId =
'';
142 if (!$user->hasRight(
'projet',
'all',
'lire')) {
143 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
146 $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";
147 $sql .=
", p.rowid project_id, p.ref project_ref, p.title project_title, p.fk_statut";
149 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as pt";
150 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"projet as p ON (pt.fk_projet = p.rowid)";
152 if ($filterValue ===
'im_task_contact') {
153 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"element_contact as ec ON (ec.element_id = pt.rowid AND ec.fk_socpeople = ".((int) $user->id).
")";
154 $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' )";
155 } elseif ($filterValue ===
'im_project_contact') {
156 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"element_contact as ec ON (ec.element_id = p.rowid AND ec.fk_socpeople = ".((int) $user->id).
")";
157 $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' )";
161 $sql .=
" pt.entity = ".$conf->entity;
162 $sql .=
" AND p.fk_statut = ".Project::STATUS_VALIDATED;
163 $sql .=
" AND (pt.progress < 100 OR pt.progress IS NULL ) ";
164 $sql .=
" AND p.usage_task = 1 ";
165 if (!$user->hasRight(
'projet',
'all',
'lire')) {
166 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
169 $sql .=
" ORDER BY pt.datee ASC, pt.dateo ASC";
170 $sql .= $this->db->plimit($max, 0);
172 $result = $this->db->query($sql);
175 $num = $this->db->num_rows($result);
176 while ($objp = $this->db->fetch_object($result)) {
177 $taskstatic->id = $objp->rowid;
178 $taskstatic->ref = $objp->ref;
179 $taskstatic->label = $objp->label;
180 $taskstatic->progress = $objp->progress;
181 $taskstatic->status = $objp->fk_statut;
182 $taskstatic->date_end = $this->db->jdate($objp->datee);
183 $taskstatic->planned_workload = $objp->planned_workload;
184 $taskstatic->duration_effective = $objp->duration_effective;
186 $projectstatic->id = $objp->project_id;
187 $projectstatic->ref = $objp->project_ref;
188 $projectstatic->title = $objp->project_title;
190 $label = $projectstatic->getNomUrl(1).
' '.$taskstatic->getNomUrl(1).
' '.
dol_htmlentities($taskstatic->label);
194 $this->info_box_contents[$i][] = array(
196 'text' => $boxcontent,