dolibarr/htdocs/core/boxes/box_task.php

215 lines
8.2 KiB
PHP
Raw Normal View History

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>
2024-03-21 19:13:33 +01:00
* Copyright (C) 2015-2024 Frédéric France <frederic.france@free.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
{
public $boxcode = "projettask";
public $boximg = "object_projecttask";
public $boxlabel;
public $depends = array("projet");
2018-09-09 12:07:14 +02:00
2024-01-07 16:57:14 +01:00
public $enabled = 1;
2017-06-12 14:09:00 +02: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
// Load translation files required by the page
$langs->loadLangs(array('boxes', 'projects'));
2018-09-09 12:07:14 +02:00
$this->boxlabel = "Tasks";
$this->db = $db;
2017-06-12 14:09:00 +02:00
Fix #28071 - New branch to fix bad merge (#28083) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Qual: Introduce getDataToShowPhoto to prepare generic code * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix missing trans * Fix langs * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Remove useless files in web templates * Clean code * Fix duplicate translation key * Fix duplicate translation key * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix duplicate key * Fix $object * Debug v19 * WIP SMSing * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP EMAILINGS_SUPPORT_ALSO_SMS * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * WIP SMSing * Debug the "validate" feature * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Clean code * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Move rights->x->y into hasRight('x', 'y') * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Enhance rector to fix empty($user->rights->modulex->perm1) * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Fix template to use v19 dev rules * Fix use v19 dev rules * Fix phpunit * Debug v19 * Clean code * Use rector to convert user->rights into user->hasRight * Clean code * Use rector to convert user->rights into user->hasRight * Use rector to convert user->rights into user->hasRight * Clean code * Fix phpcs * add editorconfig for sql files (#27999) Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * add model_pdf field in llx_ticket-ticket.sql (#27996) * add model_pdf field in llx_ticket-ticket.sql * Update 19.0.0-20.0.0.sql * Update 19.0.0-20.0.0.sql * Improve wording in README (#27994) * fix phpstan (#27989) * fix phpstan * Update UserRightsToFunction.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> * Qual: Fix spelling/working in datapolicy translations (#28006) # Qual: Fix spelling/wording in datapolicy translations Fixed some spelling and wording in datapolicy translations. * qual: phpstan for htdocs/ticket/class/ticketstats.class.php (#27986) htdocs/ticket/class/ticketstats.class.php 98 Parameter #1 $year (string) of method TicketStats::getNbByMonth() should be compatible with parameter $year (int) of method Stats::getNbByMonth() * Merge branch '19.0' of git@github.com:Dolibarr/dolibarr.git into develop * Fix user with readonly perm on email template must be able to read. * Fix doc * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Better message * Add missing fields in merge of thirdparty * Debug v19 selection of ticket printer per terminal * Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop * Use constant * NEW: Adding a recipient on emails sent, change status to sent partialy. * fix travis (#28052) * fix travis * Update partnership.class.php * fix php doc (#28047) * fix undefined array key (#28048) * Add region and departament for Cuba (#28046) * Update llx_10_c_regions.sql Add Cuba Regions (id_country=77) * Update llx_20_c_departements.sql Add Provinces Cuba (id country=77) * Find the typo (#28050) * Find the typo * clean code * add last_main_doc field to product (#28045) * add las_main_doc field to product * add field fetch * NEW Add Categorie filter for ActionComm (#28041) * New Add Categorie filter for ActionComm New Add Categorie filter for ActionComm * Fix space errors Fix space errors * Fix space errors 2 Fix space errors 2 * Update cunits.class.php (#28056) FIX: error SQL when creating a Cunit * Update codespell-lines-ignore.txt to avoid PR merge conflict --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr> Co-authored-by: Frédéric FRANCE <frederic34@users.noreply.github.com> Co-authored-by: thibdrev <thibault.drevet@gmail.com> Co-authored-by: sonikf <93765174+sonikf@users.noreply.github.com> Co-authored-by: Ikarus <44511582+LeKarSol@users.noreply.github.com> Co-authored-by: Anthony Damhet <73399671+EchoLoGeek@users.noreply.github.com> Co-authored-by: Quentin-Seekness <72733832+Quentin-Seekness@users.noreply.github.com>
2024-02-09 15:58:49 +01:00
$this->hidden = (getDolGlobalString('PROJECT_HIDE_TASKS') || !$user->hasRight('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
$this->max = $max;
2018-07-26 11:57:25 +02:00
include_once DOL_DOCUMENT_ROOT."/projet/class/task.class.php";
include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT."/core/lib/project.lib.php";
$projectstatic = new Project($this->db);
$taskstatic = new Task($this->db);
$form = new Form($this->db);
$cookie_name = 'DOLUSERCOOKIE_boxfilter_task';
$boxcontent = '';
$socid = $user->socid;
2019-08-12 01:01:16 +02:00
$textHead = $langs->trans("CurentlyOpenedTasks");
2019-08-12 01:01:16 +02: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
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(
'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
2023-10-11 19:32:04 +02:00
if ($user->hasRight('projet', 'lire')) {
$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);
2021-09-16 11:33:42 +02:00
$boxcontent .= '<button type="submit" class="button buttongen button-save">'.$langs->trans("Refresh").'</button>';
$boxcontent .= '</form>'."\n";
$boxcontent .= '</div>'."\n";
if (!empty($conf->use_javascript_ajax)) {
2023-02-18 15:10:05 +01:00
$boxcontent .= '<script nonce="'.getNonce().'" type="text/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>';
// set cookie by js
2023-02-18 15:10:05 +01:00
$boxcontent .= '<script nonce="'.getNonce().'">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(
'tr' => 'class="nohover showiffilter'.$this->boxcode.' hideobject"',
'td' => 'class="nohover"',
'textnoformat' => $boxcontent,
);
2019-08-12 15:24:07 +02:00
// Get list of project id allowed to user (in a string list separated by coma)
$projectsListId = '';
2023-10-11 19:32:04 +02:00
if (!$user->hasRight('projet', 'all', 'lire')) {
2021-02-23 22:03:23 +01:00
$projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
}
$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";
2021-05-11 08:26:03 +02:00
$sql .= ", p.rowid project_id, p.ref project_ref, p.title project_title, p.fk_statut";
$sql .= " FROM ".MAIN_DB_PREFIX."projet_task as pt";
$sql .= " JOIN ".MAIN_DB_PREFIX."projet as p ON (pt.fk_projet = p.rowid)";
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
$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
$sql .= " AND p.usage_task = 1 ";
2023-10-11 19:32:04 +02:00
if (!$user->hasRight('projet', 'all', 'lire')) {
2021-03-22 11:30:18 +01:00
$sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
2021-02-23 22:03:23 +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);
while ($objp = $this->db->fetch_object($result)) {
$taskstatic->id = $objp->rowid;
$taskstatic->ref = $objp->ref;
$taskstatic->label = $objp->label;
$taskstatic->progress = $objp->progress;
2024-03-21 19:13:33 +01:00
$taskstatic->status = $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).' &nbsp; '.$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 {
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
}
}