* Copyright (C) 2011 Dimitri Mouillard * Copyright (C) 2012 Regis Houssin * * 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 * along with this program. If not, see . */ /** * Page module configuration paid holiday. * * \file holiday.php * \ingroup holiday * \brief Page module configuration paid holiday. */ require '../../main.inc.php'; require DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; require_once DOL_DOCUMENT_ROOT. '/core/class/html.form.class.php'; require_once DOL_DOCUMENT_ROOT. '/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT. '/user/class/usergroup.class.php'; $action=GETPOST('action'); $optName=GETPOST('optName'); $optValue=GETPOST('optValue'); $langs->load("admin"); $langs->load("holiday"); // Si pas administrateur if (! $user->admin) accessforbidden(); /* * View */ // Vérification si module activé if (empty($conf->holiday->enabled)) print $langs->trans('NotActiveModCP'); llxheader('',$langs->trans('TitleAdminCP')); $linkback=''.$langs->trans("BackToModuleList").''; print_fiche_titre($langs->trans('ConfCP'), $linkback); $cp = new Holiday($db); // Contrôle du formulaire if ($action == "add") { $message = ''; $error = false; // Option du groupe de validation /*if (!$cp->updateConfCP('userGroup',$_POST['userGroup'])) { $error = true; }*/ // Option du délai pour faire une demande de congés payés if (!$cp->updateConfCP('delayForRequest',$_POST['delayForRequest'])) { $error = true; } // Option du nombre de jours à ajouter chaque mois $nbHolidayEveryMonth = price2num($_POST['nbHolidayEveryMonth'],5); if(!$cp->updateConfCP('nbHolidayEveryMonth',$nbHolidayEveryMonth)) { $error = true; } // Option du nombre de jours pour un mariage $OptMariageCP = price2num($_POST['OptMariage'],5); if(!$cp->updateConfCP('OptMariage',$OptMariageCP)) { $error = true; } // Option du nombre de jours pour un décés d'un proche $OptDecesProcheCP = price2num($_POST['OptDecesProche'],5); if(!$cp->updateConfCP('OptDecesProche',$OptDecesProcheCP)) { $error = true; } // Option du nombre de jours pour un mariage d'un enfant $OptMariageProcheCP = price2num($_POST['OptMariageProche'],5); if(!$cp->updateConfCP('OptMariageProche',$OptMariageProcheCP)) { $error = true; } // Option du nombre de jours pour un décés d'un parent $OptDecesParentsCP = price2num($_POST['OptDecesParents'],5); if(!$cp->updateConfCP('OptDecesParents',$OptDecesParentsCP)) { $error = true; } // Option pour avertir le valideur si délai de demande incorrect if(isset($_POST['AlertValidatorDelay'])) { if(!$cp->updateConfCP('AlertValidatorDelay','1')) { $error = true; } } else { if(!$cp->updateConfCP('AlertValidatorDelay','0')) { $error = true; } } // Option pour avertir le valideur si solde des congés de l'utilisateur inccorect if(isset($_POST['AlertValidatorSolde'])) { if(!$cp->updateConfCP('AlertValidatorSolde','1')) { $error = true; } } else { if(!$cp->updateConfCP('AlertValidatorSolde','0')) { $error = true; } } // Option du nombre de jours à déduire pour 1 jour de congés $nbHolidayDeducted = price2num($_POST['nbHolidayDeducted'],2); if(!$cp->updateConfCP('nbHolidayDeducted',$nbHolidayDeducted)) { $error = true; } if ($error) { $message = '
'.$langs->trans('ErrorUpdateConfCP').'
'; } else { $message = '
'.$langs->trans('UpdateConfCPOK').'
'; } // Si première mise à jour, prévenir l'utilisateur de mettre à jour le solde des congés payés $sql = "SELECT *"; $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users"; $result = $db->query($sql); $num = $db->num_rows($sql); if($num < 1) { $cp->createCPusers(); $message.= '
'.$langs->trans('AddCPforUsers').'
'; } dol_htmloutput_mesg($message); // Si il s'agit de créer un event } elseif ($action == 'create_event') { $error = 0; $optName = trim($optName); $optValue = price2num($optValue,2); if (! $optName) { $message='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Name")).'
'; $error++; } if (! $optValue > 0) { $message='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Value")).'
'; $error++; } $cp->optName = $optName; $cp->optValue = $optValue; if (! $error) { $result = $cp->createEventCP($user); if($result > 0) { $message = 'OkCreateEventCP'; $optName=''; $optValue=''; } else { $message = '
'.$cp->error.'
'; } } dol_htmloutput_mesg($message); } elseif($action == 'event' && isset($_POST['update_event'])) { $error = false; $eventId = array_keys($_POST['update_event']); $eventId = $eventId[0]; $eventName = $optName; $eventName = $eventName[$eventId]; $eventValue = $optValue; $eventValue = $eventValue[$eventId]; if(!empty($eventName)) { $eventName = trim($eventName); } else { $error = true; } if(!empty($eventValue)) { $eventValue = price2num($eventValue,2); } else { $error = true; } if(!$error) { // Mise à jour des congés de l'utilisateur $update = $cp->updateEventCP($eventId,$eventName,$eventValue); if(!$update) { $message='ErrorUpdateEventCP'; } else { $message='UpdateEventOkCP'; } } else { $message='ErrorUpdateEventCP'; } dol_htmloutput_mesg($message); } elseif($action && isset($_POST['delete_event'])) { $eventId = array_keys($_POST['delete_event']); $eventId = $eventId[0]; $result = $cp->deleteEventCP($eventId); if($result) { print '
'; print $langs->trans('DeleteEventOkCP'); print '
'; } else { print '
'; print $langs->trans('ErrorDeleteEventCP'); print '
'; } } print '
'; print_fiche_titre($langs->trans('TitleOptionMainCP'),'',''); dol_fiche_head(array(),'',''); print '
'."\n"; print ''."\n"; print ''; print ''; print ''; print ''; $var=true; /*$var=!$var; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; */ $var=!$var; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; $var=!$var; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; $var=!$var; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; $var=!$var; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; $var=!$var; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print '
'.$langs->trans('DescOptionCP').''; print ''.$langs->trans('ValueOptionCP').''; print '
'.$langs->trans('GroupToValidateCP').''.$cp->selectUserGroup('userGroup').'
'.$langs->trans('DelayForSubmitCP').' '.$langs->trans('DurationDays').'
'.$langs->trans('AlertValidatorDelayCP').'getCheckOption('AlertValidatorDelay').'/>
'.$langs->trans('AlertValidorSoldeCP').'getCheckOption('AlertValidatorSolde').'/>
'.$langs->trans('nbHolidayEveryMonthCP').' '.$langs->trans('DurationDays').'
'.$langs->trans('nbHolidayDeductedCP').' '.$langs->trans('DurationDays').'
'."\n"; print '
'."\n"; print '
'."\n\n"; dol_fiche_end(); /*$var=!$var; print $langs->trans('nbUserCP').': '."\n"; print $cp->getConfCP('nbUser')."
\n"; */ $var=!$var; print $langs->trans('LastUpdateCP').': '."\n"; if ($cp->getConfCP('lastUpdate')) print dol_print_date($db->jdate($cp->getConfCP('lastUpdate')),'dayhour','tzuser'); else print $langs->trans('None'); print "
\n"; print '
'; print_fiche_titre($langs->trans('TitleOptionEventCP'),'',''); dol_fiche_head(array(),'',''); $cp_events = $cp->fetchEventsCP(); if($cp_events == 1) { $var = false; $i = 0; print '
'."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; foreach($cp->events as $infos_event) { $var=!$var; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''; $i++; } print ''."\n"; print '
'.$langs->trans('NameEventCP').''.$langs->trans('ValueOptionCP').'  
'.$langs->trans('DurationDays').'
'."\n"; print '
'."\n"; print '
'."\n\n"; } print '
'."\n"; print ''."\n"; print $langs->trans('TitleCreateEventCP'); print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''; print '
'.$langs->trans('NameEventCP').''.$langs->trans('ValueOptionCP').' 
'.$langs->trans('DurationDays').'
'; print '
'; dol_fiche_end(); // Fin de page llxFooter(); if (is_object($db)) $db->close();