PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/holiday/admin/holiday.php

https://bitbucket.org/speedealing/speedealing
PHP | 417 lines | 277 code | 96 blank | 44 comment | 44 complexity | 67ae52b4d130e242c797159d910d2ed9 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
  4. * Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * Page module configuration paid holiday.
  21. *
  22. * \file holiday.php
  23. * \ingroup holiday
  24. * \brief Page module configuration paid holiday.
  25. */
  26. require '../../main.inc.php';
  27. require DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
  28. require_once DOL_DOCUMENT_ROOT. '/core/class/html.form.class.php';
  29. require_once DOL_DOCUMENT_ROOT. '/user/class/user.class.php';
  30. require_once DOL_DOCUMENT_ROOT. '/user/class/usergroup.class.php';
  31. $action=GETPOST('action');
  32. $optName=GETPOST('optName');
  33. $optValue=GETPOST('optValue');
  34. $langs->load("admin");
  35. $langs->load("holiday");
  36. // Si pas administrateur
  37. if (! $user->admin) accessforbidden();
  38. /*
  39. * View
  40. */
  41. // Vérification si module activé
  42. if (empty($conf->holiday->enabled)) print $langs->trans('NotActiveModCP');
  43. llxheader('',$langs->trans('TitleAdminCP'));
  44. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  45. print_fiche_titre($langs->trans('ConfCP'), $linkback);
  46. $cp = new Holiday($db);
  47. // Contrôle du formulaire
  48. if ($action == "add")
  49. {
  50. $message = '';
  51. $error = false;
  52. // Option du groupe de validation
  53. if (!$cp->updateConfCP('userGroup',$_POST['userGroup']))
  54. {
  55. $error = true;
  56. }
  57. // Option du délai pour faire une demande de congés payés
  58. if (!$cp->updateConfCP('delayForRequest',$_POST['delayForRequest']))
  59. {
  60. $error = true;
  61. }
  62. // Option du nombre de jours à ajouter chaque mois
  63. $nbHolidayEveryMonth = price2num($_POST['nbHolidayEveryMonth'],5);
  64. if(!$cp->updateConfCP('nbHolidayEveryMonth',$nbHolidayEveryMonth))
  65. {
  66. $error = true;
  67. }
  68. // Option du nombre de jours pour un mariage
  69. $OptMariageCP = price2num($_POST['OptMariage'],5);
  70. if(!$cp->updateConfCP('OptMariage',$OptMariageCP)) {
  71. $error = true;
  72. }
  73. // Option du nombre de jours pour un décés d'un proche
  74. $OptDecesProcheCP = price2num($_POST['OptDecesProche'],5);
  75. if(!$cp->updateConfCP('OptDecesProche',$OptDecesProcheCP)) {
  76. $error = true;
  77. }
  78. // Option du nombre de jours pour un mariage d'un enfant
  79. $OptMariageProcheCP = price2num($_POST['OptMariageProche'],5);
  80. if(!$cp->updateConfCP('OptMariageProche',$OptMariageProcheCP)) {
  81. $error = true;
  82. }
  83. // Option du nombre de jours pour un décés d'un parent
  84. $OptDecesParentsCP = price2num($_POST['OptDecesParents'],5);
  85. if(!$cp->updateConfCP('OptDecesParents',$OptDecesParentsCP)) {
  86. $error = true;
  87. }
  88. // Option pour avertir le valideur si délai de demande incorrect
  89. if(isset($_POST['AlertValidatorDelay'])) {
  90. if(!$cp->updateConfCP('AlertValidatorDelay','1')) {
  91. $error = true;
  92. }
  93. } else {
  94. if(!$cp->updateConfCP('AlertValidatorDelay','0')) {
  95. $error = true;
  96. }
  97. }
  98. // Option pour avertir le valideur si solde des congés de l'utilisateur inccorect
  99. if(isset($_POST['AlertValidatorSolde'])) {
  100. if(!$cp->updateConfCP('AlertValidatorSolde','1')) {
  101. $error = true;
  102. }
  103. } else {
  104. if(!$cp->updateConfCP('AlertValidatorSolde','0')) {
  105. $error = true;
  106. }
  107. }
  108. // Option du nombre de jours à déduire pour 1 jour de congés
  109. $nbHolidayDeducted = price2num($_POST['nbHolidayDeducted'],2);
  110. if(!$cp->updateConfCP('nbHolidayDeducted',$nbHolidayDeducted)) {
  111. $error = true;
  112. }
  113. if ($error) {
  114. $message = '<div class="error">'.$langs->trans('ErrorUpdateConfCP').'</div>';
  115. } else {
  116. $message = '<div class="ok">'.$langs->trans('UpdateConfCPOK').'</div>';
  117. }
  118. // Si première mise à jour, prévenir l'utilisateur de mettre à jour le solde des congés payés
  119. $sql = "SELECT *";
  120. $sql.= " FROM ".MAIN_DB_PREFIX."holiday_users";
  121. $result = $db->query($sql);
  122. $num = $db->num_rows($sql);
  123. if($num < 1) {
  124. $cp->createCPusers();
  125. $message.= '<br /><div class="warning">'.$langs->trans('AddCPforUsers').'</div>';
  126. }
  127. dol_htmloutput_mesg($message);
  128. // Si il s'agit de créer un event
  129. }
  130. elseif ($action == 'create_event')
  131. {
  132. $error = 0;
  133. $optName = trim($optName);
  134. $optValue = price2num($optValue,2);
  135. if (! $optName)
  136. {
  137. $message='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Name")).'</div>';
  138. $error++;
  139. }
  140. if (! $optValue > 0)
  141. {
  142. $message='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Value")).'</div>';
  143. $error++;
  144. }
  145. $cp->optName = $optName;
  146. $cp->optValue = $optValue;
  147. if (! $error)
  148. {
  149. $result = $cp->createEventCP($user);
  150. if($result > 0)
  151. {
  152. $message = 'OkCreateEventCP';
  153. $optName='';
  154. $optValue='';
  155. }
  156. else
  157. {
  158. $message = '<div class="error">'.$cp->error.'</div>';
  159. }
  160. }
  161. dol_htmloutput_mesg($message);
  162. }
  163. elseif($action == 'event' && isset($_POST['update_event']))
  164. {
  165. $error = false;
  166. $eventId = array_keys($_POST['update_event']);
  167. $eventId = $eventId[0];
  168. $eventName = $optName;
  169. $eventName = $eventName[$eventId];
  170. $eventValue = $optValue;
  171. $eventValue = $eventValue[$eventId];
  172. if(!empty($eventName)) {
  173. $eventName = trim($eventName);
  174. } else {
  175. $error = true;
  176. }
  177. if(!empty($eventValue)) {
  178. $eventValue = price2num($eventValue,2);
  179. } else {
  180. $error = true;
  181. }
  182. if(!$error)
  183. {
  184. // Mise à jour des congés de l'utilisateur
  185. $update = $cp->updateEventCP($eventId,$eventName,$eventValue);
  186. if(!$update) {
  187. $message='ErrorUpdateEventCP';
  188. } else {
  189. $message='UpdateEventOkCP';
  190. }
  191. } else {
  192. $message='ErrorUpdateEventCP';
  193. }
  194. dol_htmloutput_mesg($message);
  195. }
  196. elseif($action && isset($_POST['delete_event']))
  197. {
  198. $eventId = array_keys($_POST['delete_event']);
  199. $eventId = $eventId[0];
  200. $result = $cp->deleteEventCP($eventId);
  201. if($result) {
  202. print '<div class="tabBar">';
  203. print $langs->trans('DeleteEventOkCP');
  204. print '</div>';
  205. } else {
  206. print '<div class="tabBar">';
  207. print $langs->trans('ErrorDeleteEventCP');
  208. print '</div>';
  209. }
  210. }
  211. print '<br>';
  212. print_fiche_titre($langs->trans('TitleOptionMainCP'),'','');
  213. dol_fiche_head(array(),'','');
  214. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?leftmenu=setup" name="config">'."\n";
  215. print '<input type="hidden" name="action" value="add" />'."\n";
  216. print '<table class="noborder" width="100%">';
  217. print '<tbody>';
  218. print '<tr class="liste_titre">';
  219. print '<th class="liste_titre">'.$langs->trans('DescOptionCP').'</td>';
  220. print '<th class="liste_titre">'.$langs->trans('ValueOptionCP').'</td>';
  221. print '</tr>';
  222. $var=true;
  223. $var=!$var;
  224. print '<tr '.$bc[$var].'>'."\n";
  225. print '<td style="padding:5px; width: 40%;">'.$langs->trans('GroupToValidateCP').'</td>'."\n";
  226. print '<td style="padding:5px;">'.$cp->selectUserGroup('userGroup').'</td>'."\n";
  227. print '</tr>'."\n";
  228. $var=!$var;
  229. print '<tr '.$bc[$var].'>'."\n";
  230. print '<td style="padding:5px;">'.$langs->trans('DelayForSubmitCP').'</td>'."\n";
  231. print '<td style="padding:5px;"><input class="flat" type="text" name="delayForRequest" value="'.$cp->getConfCP('delayForRequest').'" size="2" /> '.$langs->trans('Jours').'</td>'."\n";
  232. print '</tr>'."\n";
  233. $var=!$var;
  234. print '<tr '.$bc[$var].'>'."\n";
  235. print '<td style="padding:5px;">'.$langs->trans('AlertValidatorDelayCP').'</td>'."\n";
  236. print '<td style="padding:5px;"><input class="flat" type="checkbox" name="AlertValidatorDelay" '.$cp->getCheckOption('AlertValidatorDelay').'/></td>'."\n";
  237. print '</tr>'."\n";
  238. $var=!$var;
  239. print '<tr '.$bc[$var].'>'."\n";
  240. print '<td style="padding:5px;">'.$langs->trans('AlertValidorSoldeCP').'</td>'."\n";
  241. print '<td style="padding:5px;"><input class="flat" type="checkbox" name="AlertValidatorSolde" '.$cp->getCheckOption('AlertValidatorSolde').'/></td>'."\n";
  242. print '</tr>'."\n";
  243. $var=!$var;
  244. print '<tr '.$bc[$var].'>'."\n";
  245. print '<td style="padding:5px;">'.$langs->trans('nbHolidayEveryMonthCP').'</td>'."\n";
  246. print '<td style="padding:5px;"><input class="flat" type="text" name="nbHolidayEveryMonth" value="'.$cp->getConfCP('nbHolidayEveryMonth').'" size="5"/> '.$langs->trans('Jours').'</td>'."\n";
  247. print '</tr>'."\n";
  248. $var=!$var;
  249. print '<tr '.$bc[$var].'>'."\n";
  250. print '<td style="padding:5px;">'.$langs->trans('nbHolidayDeductedCP').'</td>'."\n";
  251. print '<td style="padding:5px;"><input class="flat" type="text" name="nbHolidayDeducted" value="'.$cp->getConfCP('nbHolidayDeducted').'" size="2"/> '.$langs->trans('Jours').'</td>'."\n";
  252. print '</tr>'."\n";
  253. $var=!$var;
  254. print '<tr '.$bc[$var].'>'."\n";
  255. print '<td style="padding:5px;">'.$langs->trans('nbUserCP').'</td>'."\n";
  256. print '<td style="padding:5px;"><input class="flat" type="text" name="nbUser" value="'.$cp->getConfCP('nbUser').'" disabled="disabled" size="4"/></td>'."\n";
  257. print '</tr>'."\n";
  258. $var=!$var;
  259. print '<tr '.$bc[$var].'>'."\n";
  260. print '<td style="padding:5px;">'.$langs->trans('LastUpdateCP').'</td>'."\n";
  261. print '<td style="padding:5px;"><input class="flat" type="text" name="lastUpdate" value="'.date('d-m-Y à H:i:s',$cp->getConfCP('lastUpdate')).'" disabled="disabled"/></td>'."\n";
  262. print '</tr>'."\n";
  263. print '</tbody>'."\n";
  264. print '</table>'."\n";
  265. print '<div align="center"><input type="submit" value="'.$langs->trans("ConfirmConfigCP").'" name="bouton" class="button"/></div>'."\n";
  266. print '</form>'."\n\n";
  267. dol_fiche_end();
  268. print '<br>';
  269. print_fiche_titre($langs->trans('TitleOptionEventCP'),'','');
  270. dol_fiche_head(array(),'','');
  271. $cp_events = $cp->fetchEventsCP();
  272. if($cp_events == 1) {
  273. $var = false;
  274. $i = 0;
  275. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?leftmenu=setup" name="event_update">'."\n";
  276. print '<input type="hidden" name="action" value="event" />'."\n";
  277. print '<table class="noborder" width="100%">'."\n";
  278. print '<tbody>'."\n";
  279. print '<tr class="liste_titre">'."\n";
  280. print '<td class="liste_titre" width="40%">'.$langs->trans('NameEventCP').'</td>'."\n";
  281. print '<td class="liste_titre" width="20%">'.$langs->trans('ValueOptionCP').'</td>'."\n";
  282. print '<td class="liste_titre">&nbsp;</td>'."\n";
  283. print '<td class="liste_titre">&nbsp;</td>'."\n";
  284. print '</tr>'."\n";
  285. foreach($cp->events as $infos_event) {
  286. $var=!$var;
  287. print '<tr '.$bc[$var].'>'."\n";
  288. print '<td><input class="flat" type="text" size="40" name="optName['.$infos_event['rowid'].']" value="'.$infos_event['name'].'" /></td>'."\n";
  289. print '<td><input class="flat" type="text" size="2" name="optValue['.$infos_event['rowid'].']" value="'.$infos_event['value'].'" /> '.$langs->trans('Jours').'</td>'."\n";
  290. print '<td><input type="submit" class="button" name="update_event['.$infos_event['rowid'].']" value="'.dol_escape_htmltag($langs->trans("Save")).'"/></td>'."\n";
  291. print '<td width="20px" align="right"><input type="image" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/delete.png" name="delete_event['.$infos_event['rowid'].']" style="border:0;"/></td>'."\n";
  292. print '</tr>';
  293. $i++;
  294. }
  295. print '</tbody>'."\n";
  296. print '</table>'."\n";
  297. print '</form>'."\n";
  298. print '<br />'."\n\n";
  299. }
  300. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?leftmenu=setup" name="event_create">'."\n";
  301. print '<input type="hidden" name="action" value="create_event" />'."\n";
  302. print $langs->trans('TitleCreateEventCP');
  303. print '<table class="noborder" width="100%">';
  304. print '<tbody>';
  305. print '<tr class="liste_titre">';
  306. print '<td class="liste_titre" width="40%">'.$langs->trans('NameEventCP').'</td>';
  307. print '<td class="liste_titre" width="20%">'.$langs->trans('ValueOptionCP').'</td>';
  308. print '<td class="liste_titre">&nbsp;</td>';
  309. print '</tr>';
  310. print '<tr class="pair">';
  311. print '<td><input class="flat" type="text" size="40" name="optName" value="'.(is_array($optName)?'':$optName).'" /></td>'."\n";
  312. print '<td><input class="flat" type="text" size="2" name="optValue" value="'.(is_array($optValue)?'':$optValue).'" /> '.$langs->trans('Jours').'</td>'."\n";
  313. print '<td><input type="submit" class="button" name="button" value="'.$langs->trans('CreateEventCP').'" /></td>'."\n";
  314. print '</tr>'."\n";
  315. print '</tbody>';
  316. print '</table>';
  317. print '</form>';
  318. dol_fiche_end();
  319. // Fin de page
  320. llxFooter();
  321. if (is_object($db)) $db->close();