2014-06-18 21:34:18 +02:00
< ? php
2020-10-27 08:10:19 +01:00
/* Copyright ( C ) 2012 - 2018 Charlene BENKE < charlie @ patas - monkey . com >
* Copyright ( C ) 2015 - 2020 Frederic France < frederic . france @ netlogic . fr >
2015-01-06 17:54:36 +01:00
*
2014-06-18 21:34:18 +02:00
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2014-06-18 21:34:18 +02:00
*/
/**
2015-01-06 17:54:36 +01:00
* \file htdocs / core / boxes / box_task . php
* \ingroup Projet
* \brief Module to Task activity of the current year
2014-06-18 21:34:18 +02:00
*/
2018-07-26 11:57:25 +02:00
include_once DOL_DOCUMENT_ROOT . " /core/boxes/modules_boxes.php " ;
require_once DOL_DOCUMENT_ROOT . " /core/lib/date.lib.php " ;
2014-06-18 21:34:18 +02:00
2015-12-24 11:38:30 +01:00
2014-06-20 23:17:26 +02:00
/**
* Class to manage the box to show last task
*/
2014-06-20 23:56:03 +02:00
class box_task extends ModeleBoxes
2014-06-20 23:17:26 +02:00
{
2020-10-31 14:32:18 +01:00
public $boxcode = " projettask " ;
public $boximg = " object_projecttask " ;
public $boxlabel ;
public $depends = array ( " projet " );
2018-09-09 12:07:14 +02:00
2020-10-31 14:32:18 +01:00
/**
* @ var DoliDB Database handler .
*/
public $db ;
2015-01-06 17:54:36 +01:00
2020-10-31 14:32:18 +01:00
public $param ;
public $enabled = 1 ; // enable because fixed ;-).
2018-09-09 12:07:14 +02:00
2020-10-31 14:32:18 +01:00
public $info_box_head = array ();
public $info_box_contents = array ();
2015-01-06 17:54:36 +01:00
2017-06-12 14:09:00 +02:00
2020-10-31 14:32:18 +01:00
/**
* Constructor
*
* @ param DoliDB $db Database handler
* @ param string $param More parameters
*/
public function __construct ( $db , $param = '' )
{
global $conf , $user , $langs ;
2018-09-09 12:07:14 +02:00
2020-10-31 14:32:18 +01:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'boxes' , 'projects' ));
2018-09-09 12:07:14 +02:00
2020-10-31 14:32:18 +01:00
$this -> boxlabel = " Tasks " ;
$this -> db = $db ;
2017-06-12 14:09:00 +02:00
2020-10-31 14:32:18 +01:00
$this -> hidden = ( ! empty ( $conf -> global -> PROJECT_HIDE_TASKS ) || ! ( $user -> rights -> projet -> lire ));
}
2014-07-08 01:02:30 +02:00
2014-06-20 23:56:03 +02:00
/**
* Load data for box to show them later
*
2015-01-06 17:54:36 +01:00
* @ param int $max Maximum number of records to load
* @ return void
2014-06-20 23:56:03 +02:00
*/
2019-02-28 00:15:32 +01:00
public function loadBox ( $max = 5 )
2014-06-18 21:34:18 +02:00
{
2019-09-23 18:39:21 +02:00
global $conf , $user , $langs ;
2014-07-08 01:02:30 +02:00
2019-11-14 12:09:15 +01:00
$this -> max = $max ;
2018-07-26 11:57:25 +02:00
include_once DOL_DOCUMENT_ROOT . " /projet/class/task.class.php " ;
2019-08-10 22:48:07 +02:00
include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
2020-10-31 18:51:30 +01:00
require_once DOL_DOCUMENT_ROOT . " /core/lib/project.lib.php " ;
$projectstatic = new Project ( $this -> db );
2019-11-14 12:09:15 +01:00
$taskstatic = new Task ( $this -> db );
$form = new Form ( $this -> db );
2020-10-31 18:51:30 +01:00
$cookie_name = 'DOLUSERCOOKIE_boxfilter_task' ;
$boxcontent = '' ;
$socid = $user -> socid ;
2019-08-12 01:01:16 +02:00
2020-10-31 18:51:30 +01:00
$textHead = $langs -> trans ( " CurentlyOpenedTasks " );
2019-08-12 01:01:16 +02:00
2020-10-31 18:51:30 +01:00
$filterValue = 'all' ;
if ( in_array ( GETPOST ( $cookie_name ), array ( 'all' , 'im_project_contact' , 'im_task_contact' ))) {
$filterValue = GETPOST ( $cookie_name );
} elseif ( ! empty ( $_COOKIE [ $cookie_name ])) {
$filterValue = preg_replace ( '/[^a-z_]/' , '' , $_COOKIE [ $cookie_name ]); // Clean cookie from evil data
}
2019-08-12 15:24:07 +02:00
2020-10-31 18:51:30 +01:00
if ( $filterValue == 'im_task_contact' ) {
$textHead .= ' : ' . $langs -> trans ( " WhichIamLinkedTo " );
} elseif ( $filterValue == 'im_project_contact' ) {
$textHead .= ' : ' . $langs -> trans ( " WhichIamLinkedToProject " );
}
2019-08-12 01:01:16 +02:00
$this -> info_box_head = array (
2020-10-31 18:51:30 +01:00
'text' => $textHead ,
'limit' => dol_strlen ( $textHead ),
'sublink' => '' ,
'subtext' => $langs -> trans ( " Filter " ),
'subpicto' => 'filter.png' ,
'subclass' => 'linkobject boxfilter' ,
'target' => 'none' // Set '' to get target="_blank"
);
2014-06-18 21:34:18 +02:00
// list the summary of the orders
2015-01-06 17:54:36 +01:00
if ( $user -> rights -> projet -> lire ) {
2020-10-31 18:51:30 +01:00
$boxcontent .= '<div id="ancor-idfilter' . $this -> boxcode . '" style="display: block; position: absolute; margin-top: -100px"></div>' . " \n " ;
$boxcontent .= '<div id="idfilter' . $this -> boxcode . '" class="center" >' . " \n " ;
$boxcontent .= '<form class="flat " method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '#ancor-idfilter' . $this -> boxcode . '">' . " \n " ;
$boxcontent .= '<input type="hidden" name="token" value="' . newToken () . '">' . " \n " ;
$selectArray = array ( 'all' => $langs -> trans ( " NoFilter " ), 'im_task_contact' => $langs -> trans ( " WhichIamLinkedTo " ), 'im_project_contact' => $langs -> trans ( " WhichIamLinkedToProject " ));
$boxcontent .= $form -> selectArray ( $cookie_name , $selectArray , $filterValue );
$boxcontent .= '<button type="submit" class="button buttongen">' . $langs -> trans ( " Refresh " ) . '</button>' ;
$boxcontent .= '</form>' . " \n " ;
$boxcontent .= '</div>' . " \n " ;
if ( ! empty ( $conf -> use_javascript_ajax )) {
$boxcontent .= ' < script type = " text/javascript " language = " javascript " >
2020-02-26 16:17:31 +01:00
jQuery ( document ) . ready ( function () {
jQuery ( " #idsubimg'. $this->boxcode .' " ) . click ( function () {
jQuery ( " .showiffilter'. $this->boxcode .' " ) . toggle ();
});
2019-08-12 15:24:07 +02:00
});
2020-02-26 16:17:31 +01:00
</ script > ' ;
2020-10-31 18:51:30 +01:00
// set cookie by js
$boxcontent .= '<script>date = new Date(); date.setTime(date.getTime()+(30*86400000)); document.cookie = "' . $cookie_name . '=' . $filterValue . '; expires= " + date.toGMTString() + "; path=/ "; </script>' ;
}
$this -> info_box_contents [ 0 ][] = array (
2020-11-27 15:45:12 +01:00
'tr' => 'class="nohover showiffilter' . $this -> boxcode . ' hideobject"' ,
2020-10-31 18:51:30 +01:00
'td' => 'class="nohover"' ,
'textnoformat' => $boxcontent ,
);
2019-08-12 15:24:07 +02:00
2020-10-31 18:51:30 +01:00
// Get list of project id allowed to user (in a string list separated by coma)
$projectsListId = '' ;
if ( ! $user -> rights -> projet -> all -> lire ) $projectsListId = $projectstatic -> getProjectsAuthorizedForUser ( $user , 0 , 1 , $socid );
2020-02-18 12:40:50 +01:00
2020-10-31 18:51:30 +01:00
$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 " ;
2019-11-14 12:09:15 +01:00
$sql .= " , p.rowid project_id, p.ref project_ref, p.title project_title " ;
2019-08-10 22:48:07 +02:00
2019-11-14 12:09:15 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " projet_task as pt " ;
$sql .= " JOIN " . MAIN_DB_PREFIX . " projet as p ON (pt.fk_projet = p.rowid) " ;
2019-08-10 22:48:07 +02:00
2020-10-31 18:51:30 +01:00
if ( $filterValue === 'im_task_contact' ) {
$sql .= " JOIN " . MAIN_DB_PREFIX . " element_contact as ec ON (ec.element_id = pt.rowid AND ec.fk_socpeople = " . (( int ) $user -> id ) . " ) " ;
$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' ) " ;
} elseif ( $filterValue === 'im_project_contact' ) {
$sql .= " JOIN " . MAIN_DB_PREFIX . " element_contact as ec ON (ec.element_id = p.rowid AND ec.fk_socpeople = " . (( int ) $user -> id ) . " ) " ;
$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' ) " ;
}
2019-08-12 01:01:16 +02:00
2019-11-14 12:09:15 +01:00
$sql .= " WHERE " ;
$sql .= " pt.entity = " . $conf -> entity ;
$sql .= " AND p.fk_statut = " . Project :: STATUS_VALIDATED ;
$sql .= " AND (pt.progress < 100 OR pt.progress IS NULL ) " ; // 100% is done and not displayed
2020-10-31 18:51:30 +01:00
$sql .= " AND p.usage_task = 1 " ;
if ( ! $user -> rights -> projet -> all -> lire ) $sql .= " AND p.rowid IN ( " . $projectsListId . " ) " ; // public and assigned to, or restricted to company for external users
2019-08-10 22:48:07 +02:00
2019-11-14 12:09:15 +01:00
$sql .= " ORDER BY pt.datee ASC, pt.dateo ASC " ;
$sql .= $this -> db -> plimit ( $max , 0 );
2014-06-18 21:34:18 +02:00
2019-09-23 18:39:21 +02:00
$result = $this -> db -> query ( $sql );
2019-10-14 23:27:37 +02:00
$i = 1 ;
2019-01-28 00:07:38 +01:00
if ( $result ) {
2019-09-23 18:39:21 +02:00
$num = $this -> db -> num_rows ( $result );
2020-10-31 14:32:18 +01:00
while ( $objp = $this -> db -> fetch_object ( $result )) {
$taskstatic -> id = $objp -> rowid ;
$taskstatic -> ref = $objp -> ref ;
$taskstatic -> label = $objp -> label ;
$taskstatic -> progress = $objp -> progress ;
$taskstatic -> fk_statut = $objp -> fk_statut ;
$taskstatic -> date_end = $this -> db -> jdate ( $objp -> datee );
$taskstatic -> planned_workload = $objp -> planned_workload ;
$taskstatic -> duration_effective = $objp -> duration_effective ;
$projectstatic -> id = $objp -> project_id ;
$projectstatic -> ref = $objp -> project_ref ;
$projectstatic -> title = $objp -> project_title ;
$label = $projectstatic -> getNomUrl ( 1 ) . ' ' . $taskstatic -> getNomUrl ( 1 ) . ' ' . dol_htmlentities ( $taskstatic -> label );
$boxcontent = getTaskProgressView ( $taskstatic , $label , true , false , false );
$this -> info_box_contents [ $i ][] = array (
'td' => '' ,
'text' => $boxcontent ,
);
2014-06-18 21:34:18 +02:00
$i ++ ;
}
2019-01-28 00:07:38 +01:00
} else {
2020-10-31 14:32:18 +01:00
dol_print_error ( $this -> db );
}
2014-06-18 21:34:18 +02:00
}
}
2014-06-20 23:39:43 +02:00
/**
* Method to show box
*
* @ param array $head Array with properties of box title
* @ param array $contents Array with properties of box lines
2016-06-27 13:57:10 +02:00
* @ param int $nooutput No print , only return string
2017-06-12 14:09:00 +02:00
* @ return string
2014-06-20 23:39:43 +02:00
*/
2019-02-28 00:15:32 +01:00
public function showBox ( $head = null , $contents = null , $nooutput = 0 )
2014-06-18 21:34:18 +02:00
{
2017-06-12 14:09:00 +02:00
return parent :: showBox ( $this -> info_box_head , $this -> info_box_contents , $nooutput );
2014-06-18 21:34:18 +02:00
}
}