--- /tmp/dsg/dolibarr/htdocs/holiday/class/github_holiday.class.php +++ /tmp/dsg/dolibarr/htdocs/holiday/class/client_holiday.class.php @@ -50,7 +50,7 @@ public $ismultientitymanaged = 0; /** - * @var string Field with ID of parent key if this field has a parent + * @var int Field with ID of parent key if this field has a parent */ public $fk_element = 'fk_holiday'; @@ -85,36 +85,36 @@ public $statut = ''; // 1=draft, 2=validated, 3=approved /** - * @var int ID - */ + * @var int ID + */ public $fk_validator; public $date_valid = ''; /** - * @var int ID - */ + * @var int ID + */ public $fk_user_valid; public $date_refuse = ''; /** - * @var int ID - */ + * @var int ID + */ public $fk_user_refuse; public $date_cancel = ''; /** - * @var int ID - */ + * @var int ID + */ public $fk_user_cancel; public $detail_refuse = ''; /** - * @var int ID - */ + * @var int ID + */ public $fk_type; public $holiday = array(); @@ -204,12 +204,16 @@ if ($numref != "") { return $numref; - } else { + } + else + { $this->error = $obj->error; //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error); return ""; } - } else { + } + else + { print $langs->trans("Error")." ".$langs->trans("Error_HOLIDAY_ADDON_NotDefined"); return ""; } @@ -234,7 +238,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { $this->db->rollback(); return -1; } @@ -338,7 +344,9 @@ } $this->db->rollback(); return -1 * $error; - } else { + } + else + { $this->db->commit(); return $this->id; } @@ -419,13 +427,16 @@ $this->fetch_optionals(); $result = 1; - } else { + } + else { $result = 0; } $this->db->free($resql); return $result; - } else { + } + else + { $this->error = "Error ".$this->db->lasterror(); return -1; } @@ -549,7 +560,9 @@ // Returns 1 with the filled array $this->holiday = $tab_result; return 1; - } else { + } + else + { // SQL Error $this->error = "Error ".$this->db->lasterror(); return -1; @@ -672,7 +685,9 @@ // Returns 1 and adds the array to the variable $this->holiday = $tab_result; return 1; - } else { + } + else + { // SQL Error $this->error = "Error ".$this->db->lasterror(); return -1; @@ -696,7 +711,9 @@ if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref) || $this->ref == $this->id)) { $num = $this->getNextNumRef(null); - } else { + } + else + { $num = $this->ref; } $this->newref = dol_sanitizeFileName($num); @@ -740,7 +757,9 @@ } $this->db->rollback(); return -1 * $error; - } else { + } + else + { $this->db->commit(); return 1; } @@ -852,7 +871,9 @@ } $this->db->rollback(); return -1 * $error; - } else { + } + else + { $this->db->commit(); return 1; } @@ -963,7 +984,9 @@ } $this->db->rollback(); return -1 * $error; - } else { + } + else + { $this->db->commit(); return 1; } @@ -1014,7 +1037,9 @@ } $this->db->rollback(); return -1 * $error; - } else { + } + else + { $this->db->commit(); return 1; } @@ -1057,7 +1082,8 @@ { return false; } - } elseif ($halfday == -1) + } + elseif ($halfday == -1) { // new start afternoon, new end afternoon if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) @@ -1069,7 +1095,8 @@ if ($dateStart < $dateEnd) return false; if ($dateEnd < $infos_CP['date_fin'] || in_array($infos_CP['halfday'], array(0, -1))) return false; } - } elseif ($halfday == 1) + } + elseif ($halfday == 1) { // new start morning, new end morning if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) @@ -1081,7 +1108,8 @@ { if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) return false; } - } elseif ($halfday == 2) + } + elseif ($halfday == 2) { // new start afternoon, new end morning if ($dateStart >= $infos_CP['date_debut'] && $dateStart <= $infos_CP['date_fin']) @@ -1092,7 +1120,9 @@ { if ($dateEnd > $infos_CP['date_debut'] || in_array($infos_CP['halfday'], array(0, 1))) return false; } - } else { + } + else + { dol_print_error('', 'Bad value of parameter halfday when calling function verifDateHolidayCP'); } } @@ -1102,7 +1132,7 @@ /** - * Check that a user is not on holiday for a particular timestamp. Can check approved leave requests and not into public holidays of company. + * Check that a user is not on holiday for a particular timestamp * * @param int $fk_user Id user * @param integer $timestamp Time stamp date for a day (YYYY-MM-DD) without hours (= 12:00AM in english and not 12:00PM that is 12:00) @@ -1117,13 +1147,12 @@ $isavailablemorning = true; $isavailableafternoon = true; - // Check into leave requests $sql = "SELECT cp.rowid, cp.date_debut as date_start, cp.date_fin as date_end, cp.halfday, cp.statut"; $sql .= " FROM ".MAIN_DB_PREFIX."holiday as cp"; $sql .= " WHERE cp.entity IN (".getEntity('holiday').")"; $sql .= " AND cp.fk_user = ".(int) $fk_user; $sql .= " AND cp.date_debut <= '".$this->db->idate($timestamp)."' AND cp.date_fin >= '".$this->db->idate($timestamp)."'"; - if ($status != '-1') $sql .= " AND cp.statut IN (".$this->db->sanitize($this->db->escape($status)).")"; + if ($status != '-1') $sql .= " AND cp.statut IN (".$this->db->escape($status).")"; $resql = $this->db->query($sql); if ($resql) @@ -1160,12 +1189,10 @@ break; } } - } else dol_print_error($this->db); - - $result = array('morning'=>$isavailablemorning, 'afternoon'=>$isavailableafternoon); - if (!$isavailablemorning) $result['morning_reason'] = 'leave_request'; - if (!$isavailableafternoon) $result['afternoon_reason'] = 'leave_request'; - return $result; + } + else dol_print_error($this->db); + + return array('morning'=>$isavailablemorning, 'afternoon'=>$isavailableafternoon); } @@ -1182,11 +1209,7 @@ $result = ''; - $label = img_picto('', $this->picto).' '.$langs->trans("Holiday").''; - if (isset($this->statut)) { - $label .= ' '.$this->getLibStatut(5); - } - $label .= '
'.$langs->trans('Ref').': '.$this->ref; + $label = $langs->trans("Show").': '.$this->ref; $url = DOL_URL_ROOT.'/holiday/card.php?id='.$this->id; @@ -1221,7 +1244,7 @@ return $this->LibStatut($this->statut, $mode, $this->date_debut); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Returns the label of a status * @@ -1267,8 +1290,8 @@ * @param string $htmlname Name of HTML select field * @return string Show select of status */ - public function selectStatutCP($selected = '', $htmlname = 'select_statut') - { + public function selectStatutCP($selected = '', $htmlname = 'select_statut') + { global $langs; @@ -1277,22 +1300,21 @@ $nb = count($name) + 1; // Select HTML - $out = ''."\n"; + $statut .= ''."\n"; // Boucle des statuts for ($i = 1; $i < $nb; $i++) { if ($i == $selected) { - $out .= ''."\n"; - } else { - $out .= ''."\n"; - } - } - - $out .= ''."\n"; - $out .= ajax_combobox($htmlname); - - print $out; + $statut .= ''."\n"; + } + else { + $statut .= ''."\n"; + } + } + + $statut .= ''."\n"; + print $statut; } /** @@ -1302,12 +1324,12 @@ * @param string $value vrai si mise à jour OK sinon faux * @return boolean ok or ko */ - public function updateConfCP($name, $value) - { + public function updateConfCP($name, $value) + { $sql = "UPDATE ".MAIN_DB_PREFIX."holiday_config SET"; - $sql .= " value = '".$this->db->escape($value)."'"; - $sql .= " WHERE name = '".$this->db->escape($name)."'"; + $sql .= " value = '".$value."'"; + $sql .= " WHERE name = '".$name."'"; dol_syslog(get_class($this).'::updateConfCP name='.$name.'', LOG_DEBUG); $result = $this->db->query($sql); @@ -1348,14 +1370,20 @@ if ($result) { return $createifnotfound; - } else { + } + else + { $this->error = $this->db->lasterror(); return -2; } - } else { + } + else + { return ''; } - } else { + } + else + { return $obj->value; } } else { @@ -1411,7 +1439,7 @@ // Update each user counter foreach ($users as $userCounter) { - $nbDaysToAdd = (isset($typeleaves[$userCounter['type']]['newByMonth']) ? $typeleaves[$userCounter['type']]['newByMonth'] : 0); + $nbDaysToAdd = $typeleaves[$userCounter['type']]['newByMonth']; if (empty($nbDaysToAdd)) continue; dol_syslog("We update leave type id ".$userCounter['type']." for user id ".$userCounter['rowid'], LOG_DEBUG); @@ -1435,14 +1463,18 @@ { $this->db->commit(); return 1; - } else { + } + else + { $this->db->rollback(); return -1; } } return 0; - } else { + } + else + { // Mise à jour pour un utilisateur $nbHoliday = price2num($nbHoliday, 5); @@ -1465,7 +1497,9 @@ $error++; $this->errors[] = $this->db->lasterror(); } - } else { + } + else + { // Insert for user $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users(nb_holiday, fk_user, fk_type) VALUES ("; $sql .= $nbHoliday; @@ -1477,7 +1511,9 @@ $this->errors[] = $this->db->lasterror(); } } - } else { + } + else + { $this->errors[] = $this->db->lasterror(); $error++; } @@ -1485,7 +1521,9 @@ if (!$error) { return 1; - } else { + } + else + { return -1; } } @@ -1497,12 +1535,12 @@ * @param string $name name du paramètre de configuration * @return string retourne checked si > 0 */ - public function getCheckOption($name) - { + public function getCheckOption($name) + { $sql = "SELECT value"; $sql .= " FROM ".MAIN_DB_PREFIX."holiday_config"; - $sql .= " WHERE name = '".$this->db->escape($name)."'"; + $sql .= " WHERE name = '".$name."'"; $result = $this->db->query($sql); @@ -1526,7 +1564,7 @@ */ public function createCPusers($single = false, $userid = '') { - // do we have to add balance for all users ? + // Si c'est l'ensemble des utilisateurs à ajouter if (!$single) { dol_syslog(get_class($this).'::createCPusers'); @@ -1536,15 +1574,17 @@ { $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users"; $sql .= " (fk_user, nb_holiday)"; - $sql .= " VALUES (".((int) $users['rowid'])."', '0')"; + $sql .= " VALUES ('".$users['rowid']."','0')"; $resql = $this->db->query($sql); if (!$resql) dol_print_error($this->db); } - } else { + } + else + { $sql = "INSERT INTO ".MAIN_DB_PREFIX."holiday_users"; $sql .= " (fk_user, nb_holiday)"; - $sql .= " VALUES (".((int) $userid)."', '0')"; + $sql .= " VALUES ('".$userid."','0')"; $resql = $this->db->query($sql); if (!$resql) dol_print_error($this->db); @@ -1557,11 +1597,11 @@ * @param int $user_id ID de l'utilisateur à supprimer * @return boolean Vrai si pas d'erreur, faut si Erreur */ - public function deleteCPuser($user_id) - { + public function deleteCPuser($user_id) + { $sql = "DELETE FROM ".MAIN_DB_PREFIX."holiday_users"; - $sql .= " WHERE fk_user = ".((int) $user_id); + $sql .= " WHERE fk_user = '".$user_id."'"; $this->db->query($sql); } @@ -1589,7 +1629,9 @@ //return number_format($obj->nb_holiday,2); if ($obj) return $obj->nb_holiday; else return null; - } else { + } + else + { return null; } } @@ -1626,7 +1668,9 @@ $sql .= " WHERE ((ug.fk_user = u.rowid"; $sql .= " AND ug.entity IN (".getEntity('usergroup')."))"; $sql .= " OR u.entity = 0)"; // Show always superadmin - } else { + } + else + { $sql .= " WHERE u.entity IN (".getEntity('user').")"; } $sql .= " AND u.statut > 0"; @@ -1655,12 +1699,16 @@ } // Retoune le tableau des utilisateurs return $stringlist; - } else { + } + else + { // Erreur SQL $this->error = "Error ".$this->db->lasterror(); return -1; } - } else { + } + else + { // We want only list of vacation balance for user ids $sql = "SELECT DISTINCT cpu.fk_user"; $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u"; @@ -1690,13 +1738,17 @@ } // Retoune le tableau des utilisateurs return $stringlist; - } else { + } + else + { // Erreur SQL $this->error = "Error ".$this->db->lasterror(); return -1; } } - } else { + } + else + { // Si faux donc return array // List for Dolibarr users if ($type) @@ -1715,7 +1767,9 @@ $sql .= " WHERE ((ug.fk_user = u.rowid"; $sql .= " AND ug.entity IN (".getEntity('usergroup')."))"; $sql .= " OR u.entity = 0)"; // Show always superadmin - } else { + } + else + { $sql .= " WHERE u.entity IN (".getEntity('user').")"; } @@ -1756,7 +1810,9 @@ $this->errors[] = "Error ".$this->db->lasterror(); return -1; } - } else { + } + else + { // List of vacation balance users $sql = "SELECT cpu.fk_type, cpu.nb_holiday, u.rowid, u.lastname, u.firstname, u.gender, u.photo, u.employee, u.statut, u.fk_user"; $sql .= " FROM ".MAIN_DB_PREFIX."holiday_users as cpu, ".MAIN_DB_PREFIX."user as u"; @@ -1794,7 +1850,9 @@ } // Retoune le tableau des utilisateurs return $tab_result; - } else { + } + else + { // Erreur SQL $this->error = "Error ".$this->db->lasterror(); return -1; @@ -1804,7 +1862,7 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return list of people with permission to validate leave requests. * Search for permission "approve leave requests" @@ -1813,7 +1871,7 @@ */ public function fetch_users_approver_holiday() { - // phpcs:enable + // phpcs:enable $users_validator = array(); $sql = "SELECT DISTINCT ur.fk_user"; @@ -1837,7 +1895,9 @@ $i++; } return $users_validator; - } else { + } + else + { $this->error = $this->db->lasterror(); dol_syslog(get_class($this)."::fetch_users_approver_holiday Error ".$this->error, LOG_ERR); return -1; @@ -1866,8 +1926,8 @@ * * @return int retourne le nombre d'utilisateur */ - public function countActiveUsersWithoutCP() - { + public function countActiveUsersWithoutCP() + { $sql = "SELECT count(u.rowid) as compteur"; $sql .= " FROM ".MAIN_DB_PREFIX."user as u LEFT OUTER JOIN ".MAIN_DB_PREFIX."holiday_users hu ON (hu.fk_user=u.rowid)"; @@ -1929,11 +1989,11 @@ $sql .= "fk_type"; $sql .= ") VALUES ("; $sql .= " '".$this->db->idate(dol_now())."',"; - $sql .= " '".$this->db->escape($fk_user_action)."',"; - $sql .= " '".$this->db->escape($fk_user_update)."',"; + $sql .= " '".$fk_user_action."',"; + $sql .= " '".$fk_user_update."',"; $sql .= " '".$this->db->escape($label)."',"; - $sql .= " '".$this->db->escape($prev_solde)."',"; - $sql .= " '".$this->db->escape($new_solde)."',"; + $sql .= " '".$prev_solde."',"; + $sql .= " '".$new_solde."',"; $sql .= " ".$fk_type; $sql .= ")"; @@ -1958,7 +2018,9 @@ } $this->db->rollback(); return -1 * $error; - } else { + } + else + { $this->db->commit(); return $this->optRowid; } @@ -2029,7 +2091,9 @@ // Retourne 1 et ajoute le tableau à la variable $this->logs = $tab_result; return 1; - } else { + } + else + { // Erreur SQL $this->error = "Error ".$this->db->lasterror(); return -1; @@ -2067,84 +2131,10 @@ return $types; } - } else dol_print_error($this->db); + } + else dol_print_error($this->db); return array(); - } - - - /** - * Load information on object - * - * @param int $id Id of object - * @return void - */ - public function info($id) - { - global $conf; - - $sql = "SELECT f.rowid,"; - $sql .= " f.date_create as datec,"; - $sql .= " f.tms as date_modification,"; - $sql .= " f.date_valid as datev,"; - //$sql .= " f.date_approve as datea,"; - $sql .= " f.date_refuse as dater,"; - $sql .= " f.fk_user_create as fk_user_creation,"; - $sql .= " f.fk_user_modif as fk_user_modification,"; - $sql .= " f.fk_user_valid,"; - $sql .= " f.fk_validator as fk_user_approve,"; - $sql .= " f.fk_user_refuse as fk_user_refuse"; - $sql .= " FROM ".MAIN_DB_PREFIX."holiday as f"; - $sql .= " WHERE f.rowid = ".$id; - $sql .= " AND f.entity = ".$conf->entity; - - $resql = $this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->rowid; - - $this->date_creation = $this->db->jdate($obj->datec); - $this->date_modification = $this->db->jdate($obj->date_modification); - $this->date_validation = $this->db->jdate($obj->datev); - $this->date_approbation = $this->db->jdate($obj->datea); - - $cuser = new User($this->db); - $cuser->fetch($obj->fk_user_author); - $this->user_creation = $cuser; - - if ($obj->fk_user_creation) - { - $cuser = new User($this->db); - $cuser->fetch($obj->fk_user_creation); - $this->user_creation = $cuser; - } - if ($obj->fk_user_valid) - { - $vuser = new User($this->db); - $vuser->fetch($obj->fk_user_valid); - $this->user_validation = $vuser; - } - if ($obj->fk_user_modification) - { - $muser = new User($this->db); - $muser->fetch($obj->fk_user_modification); - $this->user_modification = $muser; - } - if ($obj->fk_user_approve) - { - $auser = new User($this->db); - $auser->fetch($obj->fk_user_approve); - $this->user_approve = $auser; - } - } - $this->db->free($resql); - } else { - dol_print_error($this->db); - } } @@ -2176,95 +2166,99 @@ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Load this->nb for dashboard - * - * @return int <0 if KO, >0 if OK - */ - public function load_state_board() - { - // phpcs:enable + * Load this->nb for dashboard + * + * @return int <0 if KO, >0 if OK + */ + public function load_state_board() + { + // phpcs:enable global $user; - $this->nb = array(); - - $sql = "SELECT count(h.rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h"; - $sql .= " WHERE h.statut > 1"; - $sql .= " AND h.entity IN (".getEntity('holiday').")"; - if (empty($user->rights->expensereport->readall)) + $this->nb = array(); + + $sql = "SELECT count(h.rowid) as nb"; + $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h"; + $sql .= " WHERE h.statut > 1"; + $sql .= " AND h.entity IN (".getEntity('holiday').")"; + if (empty($user->rights->expensereport->read_all)) { $userchildids = $user->getAllChildIds(1); - $sql .= " AND (h.fk_user IN (".join(',', $userchildids).")"; - $sql .= " OR h.fk_validator IN (".join(',', $userchildids)."))"; - } - - $resql = $this->db->query($sql); - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { - $this->nb["holidays"] = $obj->nb; - } - $this->db->free($resql); - return 1; - } else { - dol_print_error($this->db); - $this->error = $this->db->error(); - return -1; - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Load indicators for dashboard (this->nbtodo and this->nbtodolate) - * - * @param User $user Objet user - * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK - */ - public function load_board($user) - { - // phpcs:enable - global $conf, $langs; - - if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe - - $now = dol_now(); - - $sql = "SELECT h.rowid, h.date_debut"; - $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h"; - $sql .= " WHERE h.statut = 2"; - $sql .= " AND h.entity IN (".getEntity('holiday').")"; + $sql.= " AND (h.fk_user IN (".join(',', $userchildids).")"; + $sql.= " OR h.fk_validator IN (".join(',', $userchildids)."))"; + } + + $resql = $this->db->query($sql); + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { + $this->nb["holidays"] = $obj->nb; + } + $this->db->free($resql); + return 1; + } + else + { + dol_print_error($this->db); + $this->error = $this->db->error(); + return -1; + } + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Load indicators for dashboard (this->nbtodo and this->nbtodolate) + * + * @param User $user Objet user + * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK + */ + public function load_board($user) + { + // phpcs:enable + global $conf, $langs; + + if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe + + $now = dol_now(); + + $sql = "SELECT h.rowid, h.date_debut"; + $sql .= " FROM ".MAIN_DB_PREFIX."holiday as h"; + $sql .= " WHERE h.statut = 2"; + $sql .= " AND h.entity IN (".getEntity('holiday').")"; if (empty($user->rights->expensereport->read_all)) { $userchildids = $user->getAllChildIds(1); - $sql .= " AND (h.fk_user IN (".join(',', $userchildids).")"; - $sql .= " OR h.fk_validator IN (".join(',', $userchildids)."))"; - } - - $resql = $this->db->query($sql); - if ($resql) - { - $langs->load("members"); - - $response = new WorkboardResponse(); - $response->warning_delay = $conf->holiday->approve->warning_delay / 60 / 60 / 24; - $response->label = $langs->trans("HolidaysToApprove"); - $response->labelShort = $langs->trans("ToApprove"); - $response->url = DOL_URL_ROOT.'/holiday/list.php?search_statut=2&mainmenu=hrm&leftmenu=holiday'; - $response->img = img_object('', "holiday"); - - while ($obj = $this->db->fetch_object($resql)) - { - $response->nbtodo++; - - if ($this->db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) { - $response->nbtodolate++; - } - } - - return $response; - } else { - dol_print_error($this->db); - $this->error = $this->db->error(); - return -1; - } - } + $sql.= " AND (h.fk_user IN (".join(',', $userchildids).")"; + $sql.= " OR h.fk_validator IN (".join(',', $userchildids)."))"; + } + + $resql = $this->db->query($sql); + if ($resql) + { + $langs->load("members"); + + $response = new WorkboardResponse(); + $response->warning_delay = $conf->holiday->approve->warning_delay / 60 / 60 / 24; + $response->label = $langs->trans("HolidaysToApprove"); + $response->labelShort = $langs->trans("ToApprove"); + $response->url = DOL_URL_ROOT.'/holiday/list.php?search_statut=2&mainmenu=hrm&leftmenu=holiday'; + $response->img = img_object('', "holiday"); + + while ($obj = $this->db->fetch_object($resql)) + { + $response->nbtodo++; + + if ($this->db->jdate($obj->date_debut) < ($now - $conf->holiday->approve->warning_delay)) { + $response->nbtodolate++; + } + } + + return $response; + } + else + { + dol_print_error($this->db); + $this->error = $this->db->error(); + return -1; + } + } }