From 223224d12c21791162343ee88370eebbe91c2f93 Mon Sep 17 00:00:00 2001 From: Tobias Sekan Date: Tue, 19 May 2020 08:07:21 +0200 Subject: [PATCH 1/5] Add function to update the event percent + const --- htdocs/comm/action/class/actioncomm.class.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index bf906989d16..6df61e3bc72 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -343,6 +343,20 @@ class ActionComm extends CommonObject */ public $errors_to; + /** + * Typical value for a event that is in a todo state + */ + const EVENT_TODO = 0; + + /** + * Typical value for a event that is in a progress state + */ + const EVENT_IN_PROGRESS = 50; + + /** + * Typical value for a event that is in a finished state + */ + const EVENT_FINISHED = 100; /** * Constructor @@ -2021,4 +2035,32 @@ class ActionComm extends CommonObject return $error; } + + /** + * Udpate the percent value of a event with the given id + * + * @param int $id The id of the event + * @param int $percent The new percent value for the event + * @return int 1 when update of the event was suscessfull, otherwise -1 + */ + public function updatePercent($id, $percent) + { + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm "; + $sql .= " SET percent = '".$percent."'"; + $sql .= " WHERE id=".$id; + + if ($this->db->query($sql)) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + $this->error = $this->db->lasterror(); + return -1; + } + } } From 7fd6151c432957d94232c5fba8d46dc799ebd9e6 Mon Sep 17 00:00:00 2001 From: Tobias Sekan Date: Tue, 19 May 2020 08:18:38 +0200 Subject: [PATCH 2/5] Add massactions for event list --- htdocs/comm/action/list.php | 60 +++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/action/list.php b/htdocs/comm/action/list.php index 2391f9ca491..be841ea8506 100644 --- a/htdocs/comm/action/list.php +++ b/htdocs/comm/action/list.php @@ -5,6 +5,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2017 Open-DSI * Copyright (C) 2018 Frédéric France + * Copyright (C) 2020 Tobias Sekan * * 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 @@ -40,6 +41,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $langs->loadLangs(array("users", "companies", "agenda", "commercial", "other")); $action = GETPOST('action', 'alpha'); +$massaction = GETPOST('massaction', 'alpha'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'actioncommlist'; // To manage different context of search $resourceid = GETPOST("search_resourceid", "int") ?GETPOST("search_resourceid", "int") : GETPOST("resourceid", "int"); $pid = GETPOST("search_projectid", 'int', 3) ?GETPOST("search_projectid", 'int', 3) : GETPOST("projectid", 'int', 3); @@ -49,6 +51,8 @@ $optioncss = GETPOST('optioncss', 'alpha'); $year = GETPOST("year", 'int'); $month = GETPOST("month", 'int'); $day = GETPOST("day", 'int'); +$toselect = GETPOST('toselect', 'array'); + // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index) if (GETPOST('search_actioncode', 'array')) { @@ -185,9 +189,42 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $datestart = ''; $dateend = ''; $search_status = ''; + $toselect = ''; $search_array_options = array(); } +if (empty($reshook) && !empty($massaction)) +{ + unset($percent); + + switch ($massaction) + { + case 'set_all_events_to_todo': + $percent = ActionComm::EVENT_TODO; + break; + + case 'set_all_events_to_in_progress': + $percent = ActionComm::EVENT_IN_PROGRESS; + break; + + case 'set_all_events_to_finished': + $percent = ActionComm::EVENT_FINISHED; + break; + } + + if(isset($percent)) + { + foreach ($toselect as $toselectid) + { + $result = $object->updatePercent($toselectid, $percent); + if($result < 0) + { + dol_print_error($db); + break; + } + } + } +} /* * View @@ -239,6 +276,15 @@ if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; +// List of mass actions available +$arrayofmassactions = array( + 'set_all_events_to_todo' => $langs->trans("SetAllEventsToTodo"), + 'set_all_events_to_in_progress' => $langs->trans("SetAllEventsToInProgress"), + 'set_all_events_to_finished' => $langs->trans("SetAllEventsToFinished"), +); + +$massactionbutton = $form->selectMassAction('', $arrayofmassactions); + $sql = "SELECT"; if ($usergroup > 0) $sql .= " DISTINCT"; $sql .= " s.nom as societe, s.rowid as socid, s.client, s.email as socemail,"; @@ -366,6 +412,8 @@ if ($resql) $num = $db->num_rows($resql); + $arrayofselected = is_array($toselect) ? $toselect : array(); + // Local calendar $newtitle = '
'.$langs->trans("LocalAgenda").'  
'; //$newtitle=$langs->trans($title); @@ -436,7 +484,7 @@ if ($resql) $newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.sprintf("%04d%02d%02d", $tmpforcreatebutton['year'], $tmpforcreatebutton['mon'], $tmpforcreatebutton['mday']).$hourminsec.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : ''))); } - print_barre_liste($s, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, -1 * $nbtotalofrecords, '', 0, $nav.$newcardbutton, '', $limit, 0, 0, 1); + print_barre_liste($s, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, -1 * $nbtotalofrecords, '', 0, $nav.$newcardbutton, '', $limit, 0, 0, 1); $moreforfilter = ''; @@ -740,7 +788,15 @@ if ($resql) $datep = $db->jdate($obj->datep); print ''.$actionstatic->LibStatut($obj->percent, 5, 0, $datep).''; } - print ''; + // Action column + print ''; + if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + { + $selected = 0; + if (in_array($obj->id, $arrayofselected)) $selected = 1; + print ''; + } + print ''; print "\n"; $i++; From 0cba74277a69a49e4b46aba10b89b74a7ee98a87 Mon Sep 17 00:00:00 2001 From: Tobias Sekan Date: Tue, 19 May 2020 08:19:14 +0200 Subject: [PATCH 3/5] Update agenda.lang --- htdocs/langs/en_US/agenda.lang | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/langs/en_US/agenda.lang b/htdocs/langs/en_US/agenda.lang index f4c8c5b4fbc..869a312910e 100644 --- a/htdocs/langs/en_US/agenda.lang +++ b/htdocs/langs/en_US/agenda.lang @@ -152,3 +152,6 @@ EveryMonth=Every month DayOfMonth=Day of month DayOfWeek=Day of week DateStartPlusOne=Date start + 1 hour +SetAllEventsToTodo=Set all events to todo +SetAllEventsToInProgress=Set all events to in progress +SetAllEventsToFinished=Set all events to finished From f0bb7d233fb211d706dc70be9a0147c54e700a08 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 19 May 2020 06:29:23 +0000 Subject: [PATCH 4/5] Fixing style errors. --- htdocs/comm/action/class/actioncomm.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 6df61e3bc72..dadc180ce08 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -2035,7 +2035,7 @@ class ActionComm extends CommonObject return $error; } - + /** * Udpate the percent value of a event with the given id * From 7397806ae770b6a03ce030711a11341fc0d3b554 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 23 May 2020 14:26:28 +0200 Subject: [PATCH 5/5] Update actioncomm.class.php --- htdocs/comm/action/class/actioncomm.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index dadc180ce08..f3ec464e7c0 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -2048,7 +2048,7 @@ class ActionComm extends CommonObject $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm "; - $sql .= " SET percent = '".$percent."'"; + $sql .= " SET percent = ".(int) $percent; $sql .= " WHERE id=".$id; if ($this->db->query($sql))