69 global
$conf, $user, $langs;
72 include_once DOL_DOCUMENT_ROOT.
"/projet/class/task.class.php";
73 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
74 require_once DOL_DOCUMENT_ROOT.
"/core/lib/project.lib.php";
75 $projectstatic =
new Project($this->db);
76 $taskstatic =
new Task($this->db);
77 $form =
new Form($this->db);
78 $cookie_name =
'DOLUSER_boxfilter_task';
80 $socid = $user->socid;
82 $textHead = $langs->trans(
"CurentlyOpenedTasks");
85 if (in_array(
GETPOST($cookie_name), array(
'all',
'im_project_contact',
'im_task_contact'))) {
86 $filterValue =
GETPOST($cookie_name);
87 } elseif (!empty($_COOKIE[$cookie_name])) {
88 $filterValue = preg_replace(
'/[^a-z_]/',
'', $_COOKIE[$cookie_name]);
91 if ($filterValue ==
'im_task_contact') {
92 $textHead .=
' : '.$langs->trans(
"WhichIamLinkedTo");
93 } elseif ($filterValue ==
'im_project_contact') {
94 $textHead .=
' : '.$langs->trans(
"WhichIamLinkedToProject");
98 $this->info_box_head = array(
102 'subtext' => $langs->trans(
"Filter"),
103 'subpicto' =>
'filter.png',
104 'subclass' =>
'linkobject boxfilter',
109 if ($user->hasRight(
'projet',
'lire')) {
110 $boxcontent .=
'<div id="ancor-idfilter'.$this->boxcode.
'" style="display: block; position: absolute; margin-top: -100px"></div>'.
"\n";
111 $boxcontent .=
'<div id="idfilter'.$this->boxcode.
'" class="center" >'.
"\n";
112 $boxcontent .=
'<form class="flat " method="POST" action="'.$_SERVER[
"PHP_SELF"].
'#ancor-idfilter'.$this->boxcode.
'">'.
"\n";
113 $boxcontent .=
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
114 $selectArray = array(
'all' => $langs->trans(
"NoFilter"),
'im_task_contact' => $langs->trans(
"WhichIamLinkedTo"),
'im_project_contact' => $langs->trans(
"WhichIamLinkedToProject"));
115 $boxcontent .= $form->selectArray($cookie_name, $selectArray, $filterValue);
116 $boxcontent .=
'<button type="submit" class="button buttongen button-save">'.$langs->trans(
"Refresh").
'</button>';
117 $boxcontent .=
'</form>'.
"\n";
118 $boxcontent .=
'</div>'.
"\n";
119 if (!empty(
$conf->use_javascript_ajax)) {
120 $boxcontent .=
'<script nonce="'.getNonce().
'" type="text/javascript">
121 jQuery(document).ready(function() {
122 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
123 jQuery(".showiffilter'.$this->boxcode.
'").toggle();
128 $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>';
130 $this->info_box_contents[0][] = array(
131 'tr' =>
'class="nohover showiffilter'.$this->boxcode.
' hideobject"',
132 'td' =>
'class="nohover"',
133 'textnoformat' => $boxcontent,
138 $projectsListId =
'';
139 if (!$user->hasRight(
'projet',
'all',
'lire')) {
140 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
143 $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";
144 $sql .=
", p.rowid project_id, p.ref project_ref, p.title project_title, p.fk_statut";
146 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task as pt";
147 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"projet as p ON (pt.fk_projet = p.rowid)";
149 if ($filterValue ===
'im_task_contact') {
150 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"element_contact as ec ON (ec.element_id = pt.rowid AND ec.fk_socpeople = ".((int) $user->id).
")";
151 $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' )";
152 } elseif ($filterValue ===
'im_project_contact') {
153 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"element_contact as ec ON (ec.element_id = p.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' AND tc.source = 'internal' )";
158 $sql .=
" pt.entity = ".$conf->entity;
159 $sql .=
" AND p.fk_statut = ".Project::STATUS_VALIDATED;
160 $sql .=
" AND (pt.progress < 100 OR pt.progress IS NULL ) ";
161 $sql .=
" AND p.usage_task = 1 ";
162 if (!$user->hasRight(
'projet',
'all',
'lire')) {
163 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
166 $sql .=
" ORDER BY pt.datee ASC, pt.dateo ASC";
167 $sql .= $this->db->plimit($max, 0);
169 $result = $this->db->query($sql);
172 $num = $this->db->num_rows($result);
173 while ($objp = $this->db->fetch_object($result)) {
174 $taskstatic->id = $objp->rowid;
175 $taskstatic->ref = $objp->ref;
176 $taskstatic->label = $objp->label;
177 $taskstatic->progress = $objp->progress;
178 $taskstatic->status = $objp->fk_statut;
179 $taskstatic->date_end = $this->db->jdate($objp->datee);
180 $taskstatic->planned_workload = $objp->planned_workload;
181 $taskstatic->duration_effective = $objp->duration_effective;
183 $projectstatic->id = $objp->project_id;
184 $projectstatic->ref = $objp->project_ref;
185 $projectstatic->title = $objp->project_title;
187 $label = $projectstatic->getNomUrl(1).
' '.$taskstatic->getNomUrl(1).
' '.
dol_htmlentities($taskstatic->label);
191 $this->info_box_contents[$i][] = array(
193 'text' => $boxcontent,