-
Notifications
You must be signed in to change notification settings - Fork 4
/
manage_rapports.inc.php
1580 lines (1340 loc) · 47 KB
/
manage_rapports.inc.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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
require_once('manage_sessions.inc.php');
require_once('manage_unites.inc.php');
require_once('manage_people.inc.php');
require_once("config.inc.php");
require_once('manage_filters_and_sort.inc.php');
function compute_title($row, $fieldId)
{
global $id_rapport_to_label;
global $fieldsAll;
$title = "";
if( substr($fieldId, 0, 4) == "Info" )
{
global $add_rubriques_people;
global $add_rubriques_candidats;
$suff = intval(substr($fieldId,4));
if( is_rapport_chercheur($row) && isset($add_rubriques_people[$suff]))
$title = $add_rubriques_people[$suff];
else if( is_rapport_concours($row) && isset($add_rubriques_candidats[$suff]))
$title = $add_rubriques_candidats[$suff];
}
else if( substr($fieldId, 0, 7) == "Generic" )
{
global $add_rubriques_concours;
global $add_rubriques_chercheurs;
global $add_rubriques_unites;
global $add_rubriques_delegations;
$suff = intval(substr($fieldId,7))/3;
if(is_delegation($row->type))
$title = $add_rubriques_delegations[$suff];
else if( is_rapport_chercheur($row) )
$title = $add_rubriques_chercheurs[$suff];
else if( is_rapport_concours($row) )
$title = $add_rubriques_concours[$suff];
else if( is_rapport_unite($row) )
$title = $add_rubriques_unites[$suff];
}
else if(isset($fieldsAll[$fieldId]))
$title = $fieldsAll[$fieldId];
return $title;
}
function needs_audition_report($report)
{
global $concours_ouverts;
global $tous_sous_jury;
return (isset($concours_ouverts[$report->concours]) && substr($concours_ouverts[$report->concours],0,2)=="CR")
&& isset($tous_sous_jury[$report->concours])
&& (count($tous_sous_jury[$report->concours]) >= 2)
&& (is_classe($report) || $report->avis==avis_oral || $report->avis==avis_non_classe || $report->avis==avis_non || $report->avis == avis_classe);
}
function getIDOrigine($id_rapport)
{
if($id_rapport <= 0)
return 0;
$sql = "SELECT id_origine FROM ".reports_db." WHERE id=$id_rapport";
$result=sql_request($sql);
$report = mysqli_fetch_object($result);
if($report == false)
{
throw new Exception("No report with id ".$id_rapport);
}
else
return $report->id_origine;
}
function deleteCurrentSelection()
{
if(is_current_session_concours())
throw new Exception("Cannot delete reports in a session concours");
if(isset($_SESSION['rows_id']))
{
$rows_id = $_SESSION['rows_id'];
$errors = "";
$n = count($rows_id) -1;
for($i = 0; $i <= $n; $i++)
try {
deleteReport($rows_id[$i], true);
}
catch(Exception $e)
{
$errors .= "Failed to delete report with id ".$rows_id[$i].": ".$e."\n<br/>";
}
if($errors != "")
throw new Exception($errors);
}
}
/*
* returns an object
*/
function getDSIReport($DKEY)
{
$sql = "SELECT * FROM ".dsidbname.".".dsi_evaluation_db." WHERE DKEY=\"".$DKEY."\";";
$res = sql_request($sql);
while($row = mysqli_fetch_object($res))
return $row;
$sql = "SELECT * FROM ".dsidbname.".".dsi_evaluation_units_db." WHERE DKEY=\"".$DKEY."\";";
$res = sql_request($sql);
while($row = mysqli_fetch_object($res))
return $row;
return null;
}
function getReport($id_rapport, $most_recent = true)
{
if($most_recent)
$id_rapport = getIDOrigine($id_rapport);
if(isSuperUser())
$sql = "SELECT * FROM ".reports_db." WHERE id=".real_escape_string($id_rapport);
else
$sql = "SELECT * FROM ".reports_db." WHERE id=".real_escape_string($id_rapport)." AND section=".real_escape_string(currentSection());
$result=sql_request($sql);
$report = mysqli_fetch_object($result);
try
{
if(isset($report->unite) && $report->unite != "")
createUnitIfNeeded($report->unite);
}
catch(Exception $e){};
if($report == false)
throw new Exception("Ce rapport n'est pas un rapport de la section/CID ".currentSection());
if(is_rapport_concours($report) && $report->concoursid != "")
{
$sql = "SELECT * FROM ".dsidbname.".".celcc_candidatures." WHERE num_conc=\"".$report->concours."\" AND user_id=\"".$report->concoursid."\"";
while($cand = mysqli_fetch_object(sql_request($sql)))
{
$report->voeux = $cand->rappel_int_labo;
break;
}
}
else
$report->voeux = "";
return normalizeReport($report);
}
function reportShortSummary($report)
{
$nom = $report->nom;
$prenom = $report->prenom;
$grade = $report->grade_rapport;
$unite = $report->unite;
$type = $report->type;
$session = "Session ".$report->id_session;
if($type == "Promotion")
{
switch($grade)
{
case "CR2": $grade = "CR1"; break;
case "DR2": $grade = "DR1"; break;
case "DR1": $grade = "DRCE1"; break;
case "DRCE1": $grade = "DRCE2"; break;
}
$grade .= " - ".$avis;
}
if(is_rapport_unite($report) )
return $session." - ".$type." - ".$report->unite;
else
return $session." - ".$type." - ".$grade." - ".$nom."_".$prenom;
}
function getAllReportsOfType($type,$id_session=-1)
{
if($id_session==-1)
$id_session = current_session_id();
$filter_values = array('type'=> $type,'id_session' => $id_session);
return filterSortReports(getCurrentFiltersList(), $filter_values);
}
function filterSortReports($filters, $filter_values = array(), $sorting_value = array(), $rapporteur_or = true)
{
$section = currentSection();
if(is_current_session_concours())
{
if(session_year(current_session_id()) >= 2016) {
$sql = "SELECT *, ".reports_db.".id AS report_id, ".people_db.".id AS people_id, ".people_db.".nom AS people_nom, ".people_db.".prenom AS people_prenom, ".people_db.".conflits AS people_conflits, ".reports_db.".nom AS nom, ".reports_db.".prenom AS prenom FROM ".reports_db;
$sql .=" left join ".people_db." on ".reports_db.".concoursid=".people_db.".concoursid AND ".reports_db.".section=".people_db.".section WHERE ";
$sql .= reports_db.".id=".reports_db.".id_origine AND ".reports_db.".concoursid!=\"\" AND ".reports_db.".statut!=\"supprime\" AND ".reports_db.".section=\"".$section."\"";
} else {
// echo "retro";
$sql = "SELECT *, ".reports_db.".id AS report_id, ".people_db.".id AS people_id, ".people_db.".nom AS people_nom, ".people_db.".prenom AS people_prenom, ".people_db.".conflits AS people_conflits, ".reports_db.".nom AS nom, ".reports_db.".prenom AS prenom FROM ".reports_db;
$sql .=" join ".people_db." on ";
$sql .= reports_db.".nom LIKE ".people_db.".nom ";
$sql .= " AND ".reports_db.".prenom LIKE ".people_db.".prenom ";
$sql .= " AND ".reports_db.".section=".people_db.".section WHERE ";
$sql .= reports_db.".id=".reports_db.".id_origine AND ".reports_db.".concours!='' AND ".reports_db.".statut!=\"supprime\" AND ".reports_db.".section=\"".$section."\"";
}
}
else
{
$sql = "SELECT *, ".reports_db.".id AS report_id, ".people_db.".id AS people_id, ".people_db.".nom AS people_nom, ".people_db.".prenom AS people_prenom, ".people_db.".conflits AS people_conflits, ".reports_db.".nom AS nom, ".reports_db.".prenom AS prenom FROM ".reports_db;
$sql .=" left join ".people_db." on ".reports_db.".peopleid=".people_db.".id WHERE ";
$sql .= reports_db.".id=".reports_db.".id_origine AND ".reports_db.".statut!=\"supprime\" AND ".reports_db.".section=\"".$section."\"";
// $sql .= "AND (".people_db.".concoursid=\"\" OR ".people_db.".concoursid is NULL)";
}
$sql .= filtersCriteriaToSQL($filters,$filter_values, $rapporteur_or);
$sql .= sortCriteriaToSQL($sorting_value);
$sql .= ";";
// echo $sql;
// rr();
$result=sql_request($sql);
if($result == false)
throw new Exception("Echec de l'execution de la requete <br/>".$sql."<br/>");
$rows = array();
//echo $sql."<br/>".count($rows)." rows ".mysqli_num_rows($result)." sqlrows<br/>";
global $my_conc;
global $conc_year;
while ($row = mysqli_fetch_object($result))
{
/*dirty rule to skip reports that I am not allowed to see */
if(!isSecretaire("",false) && isset($row->concours) && $row->concours!="" && ($row->id_session=="Concours".$conc_year) && !isset($my_conc[$row->concours]))
{
continue;
}
$row->id = $row->report_id;
$rows[] = $row;
}
// echo count($rows)."<br/>";
return $rows;
}
function updatePeopleIds()
{
$sql = "UPDATE ".reports_db." reports JOIN ".people_db." people ON reports.section=people.section AND reports.nom=people.nom AND reports.prenom=people.prenom AND (reports.concoursid = people.concoursid) SET reports.peopleid=people.id WHERE reports.peopleid=0";
sql_request($sql);
}
function sortCriteriaToSQL($sorting_values)
{
global $fieldsIndividualAll;
global $fieldsRapportAll;
$sql = "";
foreach($sorting_values as $crit => $value)
{
$sql .= ($sql == "") ? "ORDER BY " : ", ";
if(isset($fieldsRapportAll[$crit]))
$pref = reports_db.".";
else if(isset($fieldsIndividualAll[$crit]))
$pref = people_db.".";
else
{
throw new Exception("Sort criterion ".$crit." is neither in the list of rapport fields nor in the list of individual fields");
}
$sql .= $pref.$crit." ".( ( substr($sorting_values[$crit],strlen($sorting_values[$crit]) -1) == "+" ) ? "ASC" : "DESC");
}
return $sql;
}
function filtersCriteriaToSQL($filters, $filter_values, $rapporteur_or = true)
{
global $fieldsTypes;
global $fieldsRapportAll;
global $fieldsIndividualAll;
$sql = "";
foreach($filters as $filter => $data)
{
if(isset($filter_values[$filter]) && (!isset($data['default_value']) || $filter_values[$filter] != $data['default_value']))
{
if($filter == "rapporteur" && $rapporteur_or)
{
//dirty hack to have an OR clause on rapporteurs...
$val = $filter_values[$filter];
$sql .= " AND (".reports_db.".rapporteur=\"".$val."\" OR ".reports_db.".rapporteur2=\"".$val."\" OR ".reports_db.".rapporteur3=\"".$val."\") ";
}
else if($rapporteur_or && $filter =="rapporteur2")
{
continue;
}
else if($rapporteur_or && $filter =="rapporteur3")
{
continue;
}
else if($filter == "avancement")
{
$login = "";
if(isset($filter_values["rapporteur"]))
$login = $filter_values["rapporteur"];
//dirty hack tfor "Mes rapport sà faire/ faits"
$val = $filter_values[$filter];
if($val == "todo")
{
if($login != "")
$sql .= "AND ( (".reports_db.".rapporteur=\"$login\" AND ".reports_db.".avis1 = \"\") OR (".reports_db.".rapporteur2=\"$login\" AND ".reports_db.".avis2 = \"\") OR (".reports_db.".rapporteur3=\"$login\" AND ".reports_db.".avis3 = \"\")) ";
else
$sql .= "AND ( (".reports_db.".rapporteur!=\"\" AND ".reports_db.".avis1 = \"\") OR (".reports_db.".rapporteur2!=\"\" AND ".reports_db.".avis2 = \"\") OR (".reports_db.".rapporteur3!=\"\" AND ".reports_db.".avis3 = \"\")) ";
}
else if($val == "done")
{
if($login != "")
$sql .= "AND ( (".reports_db.".rapporteur=\"$login\" AND ".reports_db.".avis1 != \"\") OR (".reports_db.".rapporteur2=\"$login\" AND ".reports_db.".avis2 != \"\") OR (".reports_db.".rapporteur3=\"$login\" AND ".reports_db.".avis3 != \"\")) ";
else
$sql .= "AND ( (".reports_db.".rapporteur=\"\" OR ".reports_db.".avis1 != \"\") AND (".reports_db.".rapporteur2=\"\" OR ".reports_db.".avis2 != \"\") AND (".reports_db.".rapporteur3=\"\" OR ".reports_db.".avis3 != \"\")) ";
}
}
else if($filter == "concours")
{
global $concours_ouverts;
if(isset($filter_values[$filter]))
{
$val = $filter_values[$filter];
$listeconcours = array();
//gere le cas de "concours=CR" dans ce cas il faut générer r.g. "concours=0602 OR concours=0603"
foreach($concours_ouverts as $code => $intitule)
if($val == $code || strncmp($intitule, $val, strlen($val)) == 0)
$listeconcours[] = $code;
if(count($listeconcours) == 0)
continue;
$first = true;
$sql .= " AND (";
$field = (isset($data['sql_col']) ? $data['sql_col'] : $filter);
foreach($listeconcours as $code)
{
$sql .= ($first ? "" : " OR ".reports_db.".") . $field."=\"$code\" ";
$first = false;
}
$sql .= " ) ";
}
}
else if(isset($fieldsTypes[$filter]) && $fieldsTypes[$filter] == "avis")
{
if($filter_values[$filter] == avis_classe) {
$sql .= " AND (".reports_db.".$filter REGEXP \"^c[0-9]\" OR ".reports_db.".$filter=\"".avis_classe."\") ";
}
else if($filter_values[$filter] == avis_oral) {
$sql .= " AND (".reports_db.".$filter=\"".avis_oral."\" OR ".reports_db.".$filter=\"".avis_classe."\"";
$sql .= " OR ".reports_db.".$filter=\"".avis_non_classe."\" OR ".reports_db.".$filter REGEXP \"^c[0-9]\" )";
}
else if($filter_values[$filter] == avis_admis_a_concourir) {
$sql .= " AND ".reports_db.".statut_celcc!=\"non admis à concourir\" AND ".reports_db.".$filter!=\"".avis_desistement."\" ";
} else {
$sql .= " AND ".reports_db.".$filter=\"$filter_values[$filter]\" ";
}
//echo $sql;
}
else if($filter == "statut_celcc" && $filter_values[$filter] == "admissible")
{
$sql .= " AND (".reports_db.".avis REGEXP \"^c[0-9]\" OR ".reports_db.".avis=\"".avis_classe."\") ";
}
else
{
if(isset($fieldsRapportAll[$filter]))
$pref = reports_db.".";
else if(isset($fieldsIndividualAll[$filter]))
$pref = people_db.".";
else
throw new Exception("Filter criterion ".$filter." is neither in the list of rapport fields nor in the list of individual fields");
$sql .= " AND ". (isset($data['sql_col']) ? $data['sql_col'] : ($pref.$filter))."=\"$filter_values[$filter]\" ";
}
}
}
// echo $sql;
return $sql;
}
function getTriTypes($sorting_values)
{
$result = array();
$result[(count($sorting_values) + 5)."+"] = "";
for($i = 1; $i < count($sorting_values) + 5 ; $i++)
{
$result[ $i."+"] = $i."+";
$result[ $i."-"] = $i."-";
}
return $result;
}
function getStatus($id_rapport)
{
$report = getReport($id_rapport);
return $report->statut;
}
function isReportEditable($rapport)
{
try
{
checkReportIsEditable($rapport);
return true;
}
catch(Exception $exc)
{
return false;
}
}
function checkReportIsEditable($rapport)
{
$login = getLogin();
if (isBureauUser())
{
return true;
}
else if($rapport->statut != "doubleaveugle" && $rapport->statut != "prerapport")
{
throw new Exception("Ce rapport n'a plus le statut de prerapport et n'est donc plus éditable par ses rapporteurs. Si nécessaire veuillez demander un changement de statut au secrétaire.");
}
else if($rapport->type == REPORT_CANDIDATURE)
{
$concours = $rapport->concours;
$sousjury = $rapport->sousjury;
global $tous_sous_jury;
if(isset($tous_sous_jury[$concours]) && isset($tous_sous_jury[$concours][$sousjury]) && $login == $tous_sous_jury[$concours][$sousjury]["president"])
return true;
}
else if( ($rapport->rapporteur != "") && ($rapport->rapporteur != $login) && ($rapport->rapporteur2 != $login)&& ($rapport->rapporteur3 != $login))
throw new Exception("Vous n'êtes pas rapporteur<br/>. Si nécessaire veuillez demander un changement de rapporteur au bureau.");
else
return true;
}
function checkReportDeletable($rapport)
{
if (isSecretaire() && $rapport->statut == 'publie')
throw new Exception("Les rapports publies ne sont pas supprimables, demandez à votre ACN de changer le statut du rapport");
if (isSecretaire() && $rapport->statut == 'avistransmis')
throw new Exception("Les rapports dont l'avis a été transmis ne sont pas supprimables, demandez à votre ACN de changer le statut du rapport");
else if (isSecretaire())
return true;
else if( $rapport->rapporteur != getLogin())
throw new Exception("Le rapporteur de ce rapport est ".$rapport->rapporteur." mais vous êtes loggés sous l'identité ".getLogin());
else if ($rapport->statut != 'doubleaveugle')
throw new Exception("Ce rapport a le statut ".$rapport->statut." et n'est donc pas supprimable, seuls les prérapports sont supprimables par un rapporteur.");
else
return true;
}
function isReportCreatable()
{
return isSecretaire();
}
function deleteReport($id_rapport, $all_versions = false)
{
$report = getReport($id_rapport);
checkReportDeletable($report);
$report = getReport($id_rapport);
//Finding newest report before this one, if exists, and making it the newest
$sql = "SELECT * FROM ".reports_db." WHERE date = (SELECT MAX(date) FROM ".reports_db." AS mostrecent WHERE mostrecent.id_origine=$id_rapport AND mostrecent.id != $id_rapport AND mostrecent.statut!=\"supprime\")";
$result= sql_request($sql);
$before = mysqli_fetch_object($result);
if($before != false && !$all_versions)
{
$previous_id = $before->id;
$sql = "UPDATE ".reports_db." SET id_origine=".intval($previous_id)." WHERE id_origine=".intval($id_rapport)." ;";
sql_request($sql);
}
if(!$all_versions)
{
$sql = "DELETE FROM ".reports_db." WHERE id=".intval($id_rapport)." ;";
sql_request($sql);
}
else
{
$sql = "DELETE FROM ".reports_db." WHERE id_origine=".intval($id_rapport)." ;";
sql_request($sql);
}
return ($before !=false) ? $before->id : -1;
};
function newReport($type_rapport,$nom="",$prenom="")
{
if(!isReportCreatable())
throw new Exception("Vous n'avez pas les droits nécessaires à la création d'un rapport. Veuillez contacter le secrétaire scientifique.");
$row = array();
$row['type'] = $type_rapport;
$row["DKEY"] = "";
$row['section'] = currentSection();
$row["nom"]=$nom;
$row["prenom"]=$prenom;
return normalizeReport($row);
} ;
function addReport($report)
{
if(!isReportCreatable())
throw new Exception("Le compte ".$login." n'a pas la permission de créer un rapport, veuillez contacter le secrétaire scientifique.");
global $empty_report;
foreach($empty_report as $key => $value)
if(!isset($report->$key))
$report->$key = $value;
if(!isSuperUser() && isset($report->section) && ($report->section != currentSection()))
throw new Exception("Le compte ".$login." n'a pas la permission de créer un rapport pour une autre section que la sienne.");
$report->section = currentSection();
return addReportToDatabase($report);
};
function addReportFromRequest($id_origine, $request)
{
$concoursid = "";
if($id_origine != 0)
{
try
{
$report = getReport($id_origine);
$concoursid = $report->concoursid;
global $typesRapportsAll;
if(
isset($report->type)
&& isset($request["fieldtype"])
&& isset($typesRapportsAll[$request["fieldtype"]])
&& ($report->type != $request["fieldtype"])
)
$request["fieldintitule"] = $typesRapportsAll[$request["fieldtype"]];
}
catch (Exception $e)
{
$id_origine = 0;
}
}
else
{
if(!isReportCreatable())
throw new Exception("Le compte ".getLogin()." n'a pas la permission de créer un rapport, veuillez contacter le bureau");
}
$report = createReportFromRequest($id_origine, $request);
if(isset($report->section) && ($report->section != currentSection()))
throw new Exception("Impossible de créer un rapport pour une autre section que la sienne.");
$report->section = currentSection();
if(isset($report->NUMSIRHUS))
{
$cand = get_candidate_from_SIRHUS($report->NUMSIRHUS);
if($cand != null)
{
$report->nom = $cand->nom;
$report->prenom = $cand->prenom;
}
}
else if($concoursid != "")
{
$cand = get_candidate_from_concoursid($concoursid);
if($cand != null)
{
$report->nom = $cand->nom;
$report->prenom = $cand->prenom;
}
}
$id_nouveau = addReportToDatabase($report,false);
if(is_rapport_chercheur($report) || is_rapport_concours($report))
updateCandidateFromRequest($request, $concoursid);
return getReport($id_nouveau);
}
function createReportFromRequest($id_origine, $request)
{
global $fieldsRapportAll;
global $fieldsTypes;
$row = (object) array();
if(!isset($row->id_session))
$row->id_session = current_session_id();
foreach($fieldsRapportAll as $field => $comment)
if (isset($request["field".$field]))
$row->$field = nl2br(trim($request["field".$field]),true);
$row->id_origine = $id_origine;
return $row;
}
function normalizeReport($report)
{
global $report_prototypes;
global $id_rapport_to_label;
global $typesRapportsAll;
$report = (object) $report;
$default = array(
"DKEY"=>"",
"NUMSIRHUS"=>"",
"id_session" => current_session_id(),
"id_origine" => "",
"id" => "",
"nom" => "",
"prenom" => "",
"avis" => "",
"rapport" => "",
"prerapport" => "",
"concours" => "",
"statut" => "doubleaveugle",
"rapporteur" => "",
"rapporteur2" => "",
"rapporteur3" => "",
);
foreach($default as $key => $value)
if(!isset($report->$key))
$report->$key = $value;
if(!isset($report->statut))
$report->statut = "doubleaveugle";
if(isset($report->type))
{
if(!isset($report->intitule))
$report->intitule = (isset($typesRapportsAll[$report->type])) ? $typesRapportsAll[$report->type] : ("Type inconnu ".$report->type);
/// if(!isset($typesRapportsAll[$report->type]))
//foreach($typesRapportsAll as $key => $label)
// echo ("key ".$key." label ".$label."<br>\n");
if(isset($report_prototypes[$report->type]))
{
$prototype = $report_prototypes[$report->type];
foreach($prototype as $field => $value)
if(isset($report->$field) && $report->$field=="")
$report->$field = $value;
}
}
return $report;
}
function addReportToDatabase($report,$normalize = true)
{
global $fieldsRapportAll;
global $fieldsPermissions;
if($normalize)
$report = normalizeReport($report);
if(isset($report->unite))
try
{
createUnitIfNeeded($report->unite);
}
catch(Exception $e){}
if((is_rapport_concours($report) || is_rapport_chercheur($report)) && ( !isset($report->peopleid) || $report->peopleid=="0" ) ) {
$candidate = get_or_create_candidate($report);
$report->peopleid = $candidate->id;
}
$specialRule = array("date","id","id_origine","voeux");
$id_origine = isset($report->id_origine) ? $report->id_origine : 0;
if($id_origine == 0)
{
global $empty_report;
foreach($empty_report as $key => $value)
if(!isset($report->$key))
$report->$key = $value;
}
$level = getUserPermissionLevel();
try
{
$current_report = array();
try
{
$previous_report = getReport($id_origine, false);
$current_report = getReport($id_origine);
//echo "id_origine $id_origine current_id ".$current_report->id."<br/>";
foreach($fieldsRapportAll as $field => $comment)
{
if (!in_array($field,$specialRule))
{
if(
isset($report->$field) && isset($previous_report->$field)
&&($previous_report->$field !== $report->$field) && isset($fieldsPermissions[$field])
&& $fieldsPermissions[$field] > $level)
throw new Exception("Vous n'avez pas les autorisations nécessaires (".$level."<".$fieldsPermissions[$field].") pour modifier le champ ".$field);
if(isset($report->$field))
{
if(!isset($previous_report->$field) || $previous_report->$field !== $report->$field)
{
if(! is_field_editable($previous_report, $field))
$report->field = $previous_report->$field;
// {
// $msg = "Le compte ".getLogin()." n'a pas la permission de mettre à jour le champ ".$field;
// $msg .= " du rapport ".$id_origine.".";
// $msg .= "Ancienne valeur '".$previous_report->$field."' nouvelle valeur '".$report->$field."'";
// throw new Exception($msg);
// }
if(
isset($current_report->$field)
&& isset($report->$field)
&& isset($previous_report->$field)
&& ($previous_report->$field !== $current_report->$field)
&& ($current_report->$field !== $report->$field)
)
{
global $mergeableTypes;
global $fieldsTypes;
$type = isset($fieldsTypes[$field]) ? $fieldsTypes[$field] : "";
if(in_array($type, $mergeableTypes))
{
echo "<h2>Merge with parallel edition of field $field :</h2>'".$current_report->$field."'";
echo "<h2>Your edition:</h2> '".$report->$field."'";
$current_report->$field ="!!!EDITION PARALLELE!!!\n".$current_report->$field;
$current_report->$field .= "\n* FROM '".getLogin()."':\n".$report->$field;
}
else
{
/*
echo "<h2>Cannot merge with parallel edition of field</h2>";
echo "<h2>Parallel edition:</h2>".$current_report->$field;
echo "<h2>Your edition:</h2>".$report->$field;
echo "<h2>Erasing parallel edition...</h2>";
*/
$current_report->$field = $report->$field;
}
}
else
{
$current_report->$field = $report->$field;
}
}
}
}
}
}
catch(Exception $e)
{
if(!isReportCreatable())
throw new Exception("Echec de l'édition du rapport<br/>".$e->getMessage());
$current_report = $report;
}
$sqlfields = "";
$sqlvalues = "";
$specialRule = array("date","id","voeux");
$first = true;
foreach($current_report as $field => $value)
{
if (key_exists($field, $fieldsRapportAll) && !in_array($field,$specialRule))
{
$sqlfields.= ($first ? "" : ",").$field;
$sqlvalues.=($first ? "" : ",")."\"".real_escape_string($value)."\"";
$first = false;
}
}
$sql = "INSERT INTO ".reports_db." ($sqlfields) VALUES ($sqlvalues);";
// echo $sql."<br/>\n";
sql_request($sql);
global $dbh;
$new_id = mysqli_insert_id($dbh);
if($id_origine != 0 && isset($current_report->id))
{
$current_id = $current_report->id;
$sql = "UPDATE ".reports_db." SET id_origine=".intval($new_id);
$sql .= " WHERE id_origine=".intval($id_origine)." OR id=".intval($new_id);
$sql .= " OR id=".intval($current_id)." OR id_origine=".intval($current_id).";";
// echo $sql;
sql_request($sql);
}
else
{
$sql = "UPDATE ".reports_db." SET id_origine=".intval($new_id)." WHERE id=".intval($new_id).";";
// echo $sql;
sql_request($sql);
}
}
catch(Exception $e)
{
throw $e;
}
return $new_id;
}
function next_report($id)
{
if(!isset($_SESSION['current_id']) || !isset($_SESSION['rows_id']) || (count($_SESSION['rows_id']) == 0))
return -1;
else
{
$c = $_SESSION['current_id'];
$cc = count($_SESSION['rows_id']);
$n = ($c+ 1) % $cc;
return $_SESSION['rows_id'][$n];
}
}
function previous_report($id)
{
if(!isset($_SESSION['current_id']) || !isset($_SESSION['rows_id']) || (count($_SESSION['rows_id']) == 0))
return -1;
else
{
$c = $_SESSION['current_id'];
$cc = count($_SESSION['rows_id']);
if($c <= 0) $c += $cc;
$n = ($c - 1) % $cc;
return $_SESSION['rows_id'][$n];
}
}
function is_rapporteur_allowed($data, $row)
{
if(is_in_conflict_efficient($row, $data->login))
return false;
$college = $data->college;
$type = $row->type;
if(is_promotion_DR($type))
return ($college == "A1" || $college == "A2");
if($type == "4505" || $type == "7777")
return ($college == "A1" || $college == "A2" || $college == "B1" || $college == "B2");
return true;
}
function is_seeing_allowed($college, $type)
{
if(isSecretaire(getLogin(), false)) return true;
if(is_promotion_DR($type))
return ($college == "A1" || $college == "A2");
if($type == "7777")
return ($college != "C");
return true;
}
function set_property($property,$id_origine, $value, $all_reports = false)
{
change_report_property($id_origine, $property, $value);
$report = getReport($id_origine);
if($report->nom != "" && $report->prenom != "")
{
if($all_reports)
{
$sql = "UPDATE reports SET `".real_escape_string($property)."`=\"".real_escape_string($value)."\" ";
$sql .= " WHERE `".real_escape_string($property)."`=\"\" AND nom=\"".$report->nom."\" and prenom=\"".$report->prenom."\"";
$sql .= " AND id_session=\"".current_session()."\" AND unite=\"".$report->unite."\" AND section=\"".$report->section."\" AND type=\"".$report->type."\"";
}
else
{
$sql = "UPDATE reports SET `".real_escape_string($property)."`=\"".real_escape_string($value)."\" ";
$sql .= "WHERE id=".$id_origine.";";
}
sql_request($sql);
}
}
/* Hugo could be optimized in one sql update request?*/
function change_statuts($new_statut)
{
$rows = filterSortReports(getCurrentFiltersList(), getFilterValues(), getSortingValues());
foreach($rows as $row)
if($row->avis == "" && ($new_statut == "avistransmis" || $new_statut == "publie"))
throw new Exception("La DE ".$row->DKEY." n'a pas d'avis. Veuillez renseigner tous les avis avant de transmettre dans e-valuation.");
if($new_statut == "publie" && !isPresident())
throw new Exception("Seul le président peut transmettre et signer les rapports");
foreach($rows as $row)
{
/* if($row->statut == "validation" && $new_statut != "publie" && $new_statut != "validation" && $new_statut != "avistranmis")
{
echo "Impossible de changer le statut du rapport ".$row->DKEY." qui est en mode validation";
echo " et ne peut que basculer vers les modes publie et avistransmis.<br/>";
continue;
}*/
if($row->statut == "publie" && !isACN())
{
echo "Impossible de changer le statut du rapport ".$row->DKEY." qui est déjà publié.<br/>";
continue;
}
if($new_statut == "publie" && (isACN() || !isSecretaire()))
{
echo "Seuls le secrétaire et le président peuvent publier le rapport ".$row->DKEY.".<br/>";
continue;
}
if($row->statut == "avistransmis" && !isACN() && $new_statut != "publie" && $new_statut != "validation")
{
echo "Impossible de changer le statut du rapport ".$row->DKEY." dont l'avis est déjà transmis, car vous n'êtes pas ACN.<br/>";
continue;
}
if($row->statut == "validation" && !isSecretaire())
{
echo "Impossible de changer le statut du rapport ".$row->DKEY." qui est en mode 'validation', car vous n'êtes pas secrétaire.<br/>";
continue;
}
if($row->statut == "validation" && !isPresident() && !isACN() && !get_option("sec_can_edit_valid"))
{
echo "Impossible de changer le statut du rapport ".$row->DKEY." qui est en mode 'validation', car vous n'êtes pas président et l'option d'édition par le secrétaire en mode 'validation' n'est pas activée.<br/>";
continue;
}
if($row->statut == "validation" && isACN() && !get_option("acn_can_edit_valid"))
{
echo "Impossible de changer le statut du rapport ".$row->DKEY." qui est en mode 'validation', car vous n'êtes pas président et l'option d'édition par l'ACN en mode 'validation' n'est pas activée.<br/>";
continue;
}
change_statut($row->id, $new_statut);
}
}
function updateRapportAvis($id,$avis,$rapport)
{
$data = array("avis" => $avis, "rapport" => $rapport);
return change_report_properties($id, $data);
}
function change_rapporteur($id, $newrapporteur)
{
return change_report_property($id, "rapporteur", $newrapporteur);
}
function change_rapporteur2($id, $newrapporteur)
{
return change_report_property($id, "rapporteur2", $newrapporteur);
}
function change_statut($id, $newstatut)
{
return change_report_property($id, "statut", $newstatut);
}
function change_report_property($id_origine, $property_name, $newvalue)
{
if(substr($property_name,0,10) == "rapporteur")
{
$emails =
is_current_session_concours() ? array(get_config("email_scc"))
: is_current_session_delegation() ? array()
: emailsACN();
$sql = "SELECT * FROM reports WHERE id='".$id_origine."';";
$res = sql_request($sql);
while($rap = mysqli_fetch_object($res))