78 global $conf, $user, $langs;
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';
89 $socid = $user->socid;
91 $textHead = $langs->trans(
"CurentlyOpenedTasks");
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]);
100 if ($filterValue ==
'im_task_contact') {
101 $textHead .=
' : '.$langs->trans(
"WhichIamLinkedTo");
102 } elseif ($filterValue ==
'im_project_contact') {
103 $textHead .=
' : '.$langs->trans(
"WhichIamLinkedToProject");
107 $this->info_box_head = array(
111 'subtext'=>$langs->trans(
"Filter"),
112 'subpicto'=>
'filter.png',
113 'subclass'=>
'linkobject boxfilter',
118 if ($user->hasRight(
'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 nonce="'.getNonce().
'" type="text/javascript">
130 jQuery(document).ready(function() {
131 jQuery("#idsubimg'.$this->boxcode.
'").click(function() {
132 jQuery(".showiffilter'.$this->boxcode.
'").toggle();
137 $boxcontent .=
'<script nonce="'.getNonce().
'">date = new Date(); date.setTime(date.getTime()+(30*86400000)); document.cookie = "'.$cookie_name.
'='.$filterValue.
'; expires= " + date.toGMTString() + "; path=/ "; </script>';
139 $this->info_box_contents[0][] = array(
140 'tr' =>
'class="nohover showiffilter'.$this->boxcode.
' hideobject"',
141 'td' =>
'class="nohover"',
142 'textnoformat' => $boxcontent,
147 $projectsListId =
'';
148 if (!$user->hasRight(
'projet',
'all',
'lire')) {
149 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
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";
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)";
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' )";
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 ) ";
170 $sql .=
" AND p.usage_task = 1 ";
171 if (!$user->hasRight(
'projet',
'all',
'lire')) {
172 $sql .=
" AND p.rowid IN (".$this->db->sanitize($projectsListId).
")";
175 $sql .=
" ORDER BY pt.datee ASC, pt.dateo ASC";
176 $sql .= $this->db->plimit($max, 0);
178 $result = $this->db->query($sql);
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;
192 $projectstatic->id = $objp->project_id;
193 $projectstatic->ref = $objp->project_ref;
194 $projectstatic->title = $objp->project_title;
196 $label = $projectstatic->getNomUrl(1).
' '.$taskstatic->getNomUrl(1).
' '.
dol_htmlentities($taskstatic->label);
200 $this->info_box_contents[$i][] = array(
202 'text' => $boxcontent,