diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 3c060ffdc39..d21b392088a 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -337,6 +337,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 @@ -2008,4 +2022,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 = ".(int) $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; + } + } } 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++; diff --git a/htdocs/langs/en_US/agenda.lang b/htdocs/langs/en_US/agenda.lang index 6463b4eb9a0..bb2ba38b297 100644 --- a/htdocs/langs/en_US/agenda.lang +++ b/htdocs/langs/en_US/agenda.lang @@ -154,3 +154,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