-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils.inc.php
259 lines (213 loc) · 7.4 KB
/
utils.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
<?php
require_once('config.inc.php');
require_once('db.inc.php');
require_once('manage_users.inc.php');
require_once('manage_unites.inc.php');
//set_exception_handler('exception_handler');
//set_error_handler('error_handler');
function getTypesEval($id_session,$section)
{
$finalResult = array();
$sql = "SELECT DISTINCT type FROM (SELECT tt.*, ss.nom AS nom_session, ss.date AS date_session FROM ";
$sql .= reports_db." tt INNER JOIN ( SELECT id, MAX(date) AS date FROM ".reports_db;
$sql .= " GROUP BY id_origine) mostrecent ON tt.date = mostrecent.date, ".sessions_db;
$sql .=" ss WHERE ss.id=tt.id_session) difftypes WHERE id_session=$id_session AND section=$section ORDER BY type DESC;";
$result=mysql_query($sql);
while ($row = mysql_fetch_object($result))
{
if ($row->type)
$finalResult[] = $row->type;
}
return $finalResult;
}
function highlightDiff(&$prevVals,$key,$val)
{
if (isset($prevVals[$key]))
{
if ($prevVals[$key]==$val)
{
$prevVals[$key] = $val;
return "<span class=\"faded\">$val</span>";
}
else
{
$prevVals[$key] = $val;
return "<span class=\"highlight\">$val</span>";
}
}
$prevVals[$key] = $val;
return $val;
}
function fieldDiffers($prevVals,$key,$val)
{
if(isset($prevVals[$key]))
{
if ($prevVals[$key]==$val)
{
return false;
}
else {
return true;
}
} return true;
}
function remove_br($str)
{
return str_replace("<br />","",$str);
}
function insert_br($str)
{
return str_replace("\n","<br />",$str);
}
function array_remove_by_value($array, $value)
{
return array_values(array_diff($array, array($value)));
}
function is_picture($file)
{
if(strlen($file) < 4) return false;
$suffix = strtolower(substr($file,-3,3));
return $suffix == "png" || $suffix == "jpg" || $suffix == "bmp";
}
function message_handler($subject,$body)
{
$headers = 'From: '.get_config("webmaster"). "\r\n" . 'Reply-To: '.get_config("webmaster"). "\r\n" .'X-Mailer: PHP/' . phpversion()."\r\n";
mail(get_config("webmaster"), $subject, "\r\n".$body."\r\n", $headers);
}
function email_handler($recipient,$subject,$body, $cc = "",$from="")
{
if($from == "") $from = get_config("webmaster");
echo "Envoi d'email a '".$recipient."' avec sujet '".$subject."'... ";
$headers = 'From: '.$from. "\r\n";
if($cc != "")
$headers.= 'CC: ' .$cc . "\r\n";
$headers .= 'Reply-To: '.$from. "\r\n".'Content-Type: text/plain; charset="UTF-8"\r\n'.'X-Mailer: PHP/' . phpversion()."\r\n";
$result = mail($recipient, $subject, "\r\n".$body."\r\n", $headers);
if($result == false)
{
echo "failed!<br/>\n";
throw new Exception("Could not send email to ".$recipient." with subject ".$subject);
}
echo "ok<br/>\n.";
}
function replace_accents($string)
{
return str_replace( array('à','á','â','ã','ä', 'ç', 'è','é','ê','ë', 'ì','í','î','ï', 'ñ', 'ò','ó','ô','õ','ö', 'ù','ú','û','ü', 'ý','ÿ', 'À','Á','Â','Ã','Ä', 'Ç', 'È','É','Ê','Ë', 'Ì','Í','Î','Ï', 'Ñ', 'Ò','Ó','Ô','Õ','Ö', 'Ù','Ú','Û','Ü', 'Ý'), array('a','a','a','a','a', 'c', 'e','e','e','e', 'i','i','i','i', 'n', 'o','o','o','o','o', 'u','u','u','u', 'y','y', 'A','A','A','A','A', 'C', 'E','E','E','E', 'I','I','I','I', 'N', 'O','O','O','O','O', 'U','U','U','U', 'Y'), $string);
}
function normalizeName($name)
{
return str_replace('\' ', '\'', ucwords(strtolower($name)));
}
/*
function stripAccents($string){
return strtr($string,"'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ",
' aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
}*/
function exception_handler($exception)
{
echo "<h1>".$exception->getMessage()."</h1>";
//message_handler("Marmotte webpage :exception ",$exception->getMessage());
}
function error_handler($errno, $errstr, $errfile, $errline)
{
$body= "Number:".$errno."\r\n String:".$errstr."\r\n File:".$errfile."\r\n Line:".$errline;
echo "<h1>".$body."</h1>";
//message_handler("Marmotte webpage :error ",$body);
}
function curPageURL() {
$pageURL = 'http';
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if (isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= (isset($_SERVER["SERVER_NAME"]) ? $_SERVER["SERVER_NAME"] : "").(isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : "");
}
return $pageURL;
}
function my_iconv($text)
{
ini_set('mbstring.substitute_character', "none");
$text= mb_convert_encoding($text, "UTF-8", "UTF-8");
return iconv("UTF-8","ASCII//TRANSLIT",$text);
}
//Returns the name of the file
function filename_from_doc($doc)
{
global $id_rapport_to_label;
$nom = str_replace( array("'"," ","/"), array("","_"," ") , mb_convert_case(replace_accents($doc->nom), MB_CASE_TITLE));
$prenom = mb_convert_case(replace_accents($doc->prenom), MB_CASE_TITLE);
$type = $doc->type;
//substr($id_rapport_to_label[$doc->type], 0, 10);
$nom = my_iconv($nom);
$prenom = my_iconv($prenom);
$sessions = sessionArrays();
$session = isset($sessions[$doc->id_session]) ? $sessions[$doc->id_session] : "";
return filename_from_params($nom, $prenom, $doc->grade_rapport, $doc->unite, $type, $session, $doc->avis, $doc->concours, $doc->sousjury, $doc->intitule);
}
function filename_from_params($nom, $prenom, $grade, $unite, $type, $session, $avis, $concours = "", $sousjury="", $intitule = "")
{
global $typesRapportsAll;
global $tous_avis;
if(isset($tous_avis[$avis]))
$avis = $tous_avis[$avis];
$pretty_type = ($intitule == "") ? ( isset($typesRapportsAll[$type]) ? $typesRapportsAll[$type] : $type) : $intitule;
$pretty_type = str_replace("Candidature pour une promotion","Promo",$pretty_type);
if(strlen($pretty_type) >= 20)
{
$offs = strpos($pretty_type," ",20);
if($offs !== false)
$pretty_type = substr($pretty_type,0,$offs);
}
$liste_unite = unitsList();
$section = "S".currentSection();
if(strlen($session) >5)
$session = substr($session,0,1).substr($session,strlen($session)-2);
if(isset($liste_unite[$unite]))
$unite = $unite . " - " . $liste_unite[$unite]->nickname;
if(is_unite_type($type))
{
if(is_ecole_type($type))
$result = $session." - ".$section." - ".$pretty_type." - ".$avis." - ".$intitule." - ".$nom." - ".$unite;
else
$result = $session." - ".$section." - ".$pretty_type." - ".$avis." - ".$unite;
}
else if( is_concours_type($type) || $type == "Audition" || $type == "Classement")
{
if(is_classement($type))
$result = $session." - ".$concours." - ".$pretty_type." - ".$avis." - ".$nom." ".$prenom;
else
$result = $session." - ".$concours." - ".$pretty_type." - ".$grade." - ".$avis." - ".$nom." ".$prenom;
}
else
$result = $session." - ".$section." - ".$pretty_type." - ".$grade." - ".$avis." - ".$unite." - ".$nom." ".$prenom;
$result = str_replace(array("'","(",")","/"),array(" ","","","-"),$result);
return replace_accents($result);
}
function getStyle($fieldId,$odd, $conflict = false)
{
global $fieldsIndividualAll;
global $fieldsCandidat;
$individual = isset($fieldsIndividualAll[$fieldId]) or isset($fieldsCandidat[$fieldId]);
$rapp2 = ((substr($fieldId, -1)==="2")and !($individual));
if ($odd)
{
$style = "oddrow";
}
else
{
$style = "evenrow";
}
if ($rapp2)
{ $style .= "Bis"; }
else if ($individual)
{ $style .= "Individual"; }
if ($conflict)
{
$style .= "Conflict";
}
return $style;
}
?>