forked from ATM-Consulting/dolibarr_module_absence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rechercheAbsence.php
307 lines (251 loc) · 9.79 KB
/
rechercheAbsence.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<?php
require('config.php');
require('./class/absence.class.php');
require('./lib/absence.lib.php');
$langs->load('absence@absence');
$ATMdb=new TPDOdb;
$absence=new TRH_Absence;
if(isset($_REQUEST['action'])) {
switch($_REQUEST['action']) {
case 'recherche':
_listeResult($ATMdb,$absence);
break;
case 'view':
_fiche($ATMdb,$absence, 'edit');
break;
case 'edit':
break;
}
}
else if(isset($_REQUEST['valider'])){
_listeResult($ATMdb,$absence);
}
else{
_listeResult($ATMdb,$absence);
}
$ATMdb->close();
llxFooter();
function _fiche(&$ATMdb, $absence, $mode) {
global $db,$user, $langs, $conf;
llxHeader('','Recherche Absences');
print dol_get_fiche_head(adminRecherchePrepareHead($absence, '') , '', $langs->trans('Search'));
$form=new TFormCore($_SERVER['PHP_SELF'],'form1','POST');
$form->Set_typeaff($mode);
echo $form->hidden('fk_user', $user->id);
echo $form->hidden('entity', $conf->entity);
$idTagRecherche=isset($_REQUEST['libelle']) ? $_REQUEST['libelle'] : 0;
$idGroupeRecherche=isset($_REQUEST['groupe']) ? $_REQUEST['groupe'] : 0;
$idUserRecherche=isset($_REQUEST['user']) ? $_REQUEST['user'] : 0;
$typeRecherche=isset($_REQUEST['typeAbsence']) ? $_REQUEST['typeAbsence'] :'Tous';
//tableau pour la combobox des groupes
$TGroupe = array();
$TGroupe[0] = 'Tous';
$sqlReq="SELECT rowid, nom FROM ".MAIN_DB_PREFIX."usergroup WHERE entity IN (0,".$conf->entity.")";
$ATMdb->Execute($sqlReq);
while($ATMdb->Get_line()) {
$TGroupe[$ATMdb->Get_field('rowid')] = htmlentities($ATMdb->Get_field('nom'), ENT_COMPAT , 'UTF-8');
}
//tableau pour la combobox des utilisateurs
$TUser=array();
$TUser[0]='Tous';
$sqlReqUser="SELECT u.rowid, u.lastname, u.firstname FROM `".MAIN_DB_PREFIX."user` as u";
$ATMdb->Execute($sqlReqUser);
while($ATMdb->Get_line()) {
$TUser[$ATMdb->Get_field('rowid')]=htmlentities($ATMdb->Get_field('firstname'), ENT_COMPAT , 'UTF-8')." ".htmlentities($ATMdb->Get_field('lastname'), ENT_COMPAT , 'ISO8859-1');
}
//on récupère tous les types d'absences existants
$TTypeAbsence=array();
$TTypeAbsence['Tous']='Tous';
$sql="SELECT typeAbsence, libelleAbsence FROM `".MAIN_DB_PREFIX."rh_type_absence` ";
$ATMdb->Execute($sql);
while($ATMdb->Get_line()) {
$TTypeAbsence[$ATMdb->Get_field('typeAbsence')]=$ATMdb->Get_field('libelleAbsence');
}
$TBS=new TTemplateTBS();
print $TBS->render('./tpl/rechercheAbsence.tpl.php'
,array(
)
,array(
'recherche'=>array(
'TGroupe'=>$form->combo('','groupe',$TGroupe,$idGroupeRecherche)
,'TUser'=>$form->combo('','user',$TUser,$idUserRecherche)
,'TTypeAbsence'=>$form->combo('','typeAbsence',$TTypeAbsence,$typeRecherche)
,'btValider'=>$form->btsubmit($langs->trans('Submit'), 'valider')
,'date_debut'=> $form->calendrier('', 'date_debut', $absence->date_debut, 12)
,'date_fin'=> $form->calendrier('', 'date_fin', $absence->date_fin, 12)
,'horsConges'=>$form->checkbox1('','horsConges','1','')
,'titreRecherche'=>load_fiche_titre($langs->trans('SearchCollabsAbsences'),'', 'title.png', 0, '')
)
,'userCourant'=>array(
'id'=>$fuser->id
,'nom'=>$fuser->lastname
,'prenom'=>$fuser->firstname
,'droitRecherche'=>$user->rights->absence->myactions->rechercherAbsence?1:0
)
,'view'=>array(
'mode'=>$mode
,'head'=>dol_get_fiche_head(adminRecherchePrepareHead($absence, '') , '', $langs->trans('Search'))
)
,'translate' => array(
'InformSearchAbsencesParameters' => $langs->trans('InformSearchAbsencesParameters'),
'StartDate' => $langs->trans('StartDate'),
'EndDate' => $langs->trans('EndDate'),
'Group' => $langs->trans('Group'),
'User' => $langs->trans('User'),
'Type' => $langs->trans('Type'),
'NoHolidays' => $langs->trans('NoHolidays'),
'NoRightsForSearchCollabAbsences' => $langs->trans('NoRightsForSearchCollabAbsences')
)
)
);
echo $form->end_form();
global $mesg, $error;
dol_htmloutput_mesg($mesg, '', ($error ? 'error' : 'ok'));
llxFooter();
}
function _listeResult(&$ATMdb, &$absence) {
global $langs, $conf, $db, $user;
llxHeader('', $langs->trans('Summary'));
print dol_get_fiche_head(adminRecherchePrepareHead($absence, '') , '', $langs->trans('Search'));
$r = new TSSRenderControler($absence);
if(isset($_REQUEST['groupe'])) $idGroupeRecherche=$_REQUEST['idGroupeRecherche'];
if(isset($_REQUEST['user'])) $idUserRecherche=$_REQUEST['idUserRecherche'];
if(isset($_REQUEST['horsConges'])) $horsConges=$_REQUEST['horsConges'];
if(isset($_REQUEST['date_debut'])) $date_debut=$_REQUEST['date_debut'];
if(isset($_REQUEST['date_fin'])) $date_fin=$_REQUEST['date_fin'];
$idGroupeRecherche=$_REQUEST['groupe'];
$idUserRecherche=$_REQUEST['user'];
$typeAbsence=$_REQUEST['typeAbsence'];
if($idGroupeRecherche!=0){ // on recherche le nom du groupe
$sql="SELECT nom FROM ".MAIN_DB_PREFIX."usergroup
WHERE rowid =".$idGroupeRecherche;
$ATMdb->Execute($sql);
while($ATMdb->Get_line()) {
$nomGroupeRecherche=$ATMdb->Get_field('nom');
}
}else{
$nomGroupeRecherche='Tous';
}
if($idUserRecherche!=0){ // on recherche le nom de l'utilisateur
$sql="SELECT name, firstname FROM ".MAIN_DB_PREFIX."user
WHERE rowid =".$idUserRecherche;
$ATMdb->Execute($sql);
while($ATMdb->Get_line()) {
$nomUserRecherche=htmlentities($ATMdb->Get_field('firstname'), ENT_COMPAT , 'UTF-8')." ".htmlentities($ATMdb->Get_field('lastname'), ENT_COMPAT , 'UTF-8');
}
}else{
$nomUserRecherche='Tous';
}
if($typeAbsence!='Tous'){ // on recherche le type d'absence
$sql="SELECT libelleAbsence FROM ".MAIN_DB_PREFIX."rh_type_absence
WHERE typeAbsence LIKE '".$typeAbsence."'";
$ATMdb->Execute($sql);
while($ATMdb->Get_line()) {
$typeAbsenceVisu=$ATMdb->Get_field('libelleAbsence');
}
}else{
$typeAbsenceVisu='Tous';
}
$horsConges=$_REQUEST['horsConges']==1?'1':'0';
if($horsConges==1){
$typeRecherche= $langs->trans('ThoseNotTakeHolidaysDuringPeriod');
}else $typeRecherche= $langs->trans('AbsencesDuringThisPeriod');
print load_fiche_titre($langs->trans('KeywordsUsed'),'', 'title.png', 0, '');
?>
<div>
<br/>
<table class="border" style="width:100%">
<tr>
<td colspan="2"><b><?php echo $langs->trans('KeywordsUsed'); ?></b></td>
</tr>
<tr>
<td style="width:30%"><?php echo $langs->trans('StartDate'); ?></td>
<td ><?php echo $_REQUEST['date_debut'];?></td>
</tr>
<tr>
<td style="width:30%"><?php echo $langs->trans('EndDate'); ?></td>
<td><?php echo $_REQUEST['date_fin']; ?></td>
</tr>
<tr>
<td style="width:30%"><?php echo $langs->trans('Group'); ?></td>
<td><?php echo $nomGroupeRecherche;?></td>
</tr>
<tr>
<td style="width:30%"><?php echo $langs->trans('User'); ?></td>
<td><?php echo $nomUserRecherche;?></td>
</tr>
<tr>
<td style="width:30%"><?php echo $langs->trans('AbsenceType'); ?></td>
<td><?php echo $typeAbsenceVisu;?></td>
</tr>
<tr>
<td style="width:30%"><?php echo $langs->trans('SearchType'); ?></td>
<td><?php echo $typeRecherche;?></td>
</tr>
</table>
</div><br/><br/>
<?php
//on va obtenir la requête correspondant à la recherche désirée
$sql=$absence->requeteRechercheAbsence($ATMdb, $idGroupeRecherche, $idUserRecherche, $horsConges, $_REQUEST['date_debut'], $_REQUEST['date_fin'], $typeAbsence);
$TOrder = array('lastname'=>'ASC');
if(isset($_REQUEST['orderDown']))$TOrder = array($_REQUEST['orderDown']=>'DESC');
if(isset($_REQUEST['orderUp']))$TOrder = array($_REQUEST['orderUp']=>'ASC');
$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
$form=new TFormCore($_SERVER['PHP_SELF'],'formtranslateList','GET');
echo $form->hidden('action','recherche');
echo $form->hidden('groupe',$idGroupeRecherche);
echo $form->hidden('user',$idUserRecherche);
echo $form->hidden('horsConges',$horsConges);
echo $form->hidden('date_debut',$_REQUEST['date_debut']);
echo $form->hidden('date_fin',$_REQUEST['date_fin']);
$r->liste($ATMdb, $sql, array(
'limit'=>array(
'page'=>$page
,'nbLine'=>'10000'
)
,'link'=>array(
'libelle'=>'<a href="absence.php?id=@ID@&action=view">@val@</a>'
)
,'translate'=>array('libelleEtat'=>array(
'Refusée'=>'<b style="color:#A72947">' . $langs->trans('Refused') . '</b>',
'En attente de validation'=>'<b style="color:#5691F9">' . $langs->trans('WaitingValidation') . '</b>' ,
'Acceptée'=>'<b style="color:#30B300">' . $langs->trans('Accepted') . '</b>')
,'avertissement'=>array('1'=>'<img src="./img/warning.png" title="' . $langs->trans('DoNotRespectRules') . '"></img>')
)
,'hide'=>array('fk_user', 'ID')
,'type'=>array()
,'liste'=>array(
'titre'=> $langs->trans('SearchResult')
,'image'=>img_picto('','title.png', '', 0)
,'picto_precedent'=>img_picto('','previous.png', '', 0)
,'picto_suivant'=>img_picto('','next.png', '', 0)
,'noheader'=> (int)isset($_REQUEST['socid'])
,'messageNothing'=> $langs->trans('MessageNothingAbsence')
,'order_down'=>img_picto('','1downarrow.png', '', 0)
,'order_up'=>img_picto('','1uparrow.png', '', 0)
,'picto_search'=>'<img src="../../theme/rh/img/search.png">'
)
,'title'=>array(
'date_debut'=> $langs->trans('StartDate')
,'date_fin'=> $langs->trans('EndDate')
,'libelle'=>$langs->trans('AbsenceType')
,'firstname'=> $langs->trans('FirstName')
,'lastname'=> $langs->trans('LastName')
,'login'=> $langs->trans('Login')
,'libelleEtat'=> $langs->trans('RequestStatus')
)
,'search'=>array(
'login'=>true
,'lastname'=>true
,'firstname'=>true
)
,'eval'=>array(
'lastname'=>'htmlentities("@val@", ENT_COMPAT , "UTF-8")'
,'firstname'=>'htmlentities("@val@", ENT_COMPAT , "UTF-8")'
)
,'orderBy'=>$TOrder
));
$form->end();
?><a class="butAction" href="?action=view"><?php echo $langs->trans('Back'); ?></a><div style="clear:both"></div><?php
llxFooter();
}