-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0_fonctions.php
executable file
·419 lines (362 loc) · 18.9 KB
/
0_fonctions.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
<?php
// ########### liens ▲ ▼ ###########
function orderbylink($id) {
global $ALL_GET, $ORDER;
if ($id=="lab_id") {
if ($ORDER=="ORDER BY $id ASC") echo "▲ "; else echo "<a href=?$ALL_GET&ORDER=ORDER%20BY%20length($id)%20ASC,%20$id%20ASC>▲</a> ";
if ($ORDER=="ORDER BY $id DESC") echo "▼"; else echo "<a href=?$ALL_GET&ORDER=ORDER%20BY%20length($id)%20DESC,%20$id%20DESC>▼</a> ";
}
else {
if ($ORDER=="ORDER BY $id ASC") echo "▲ "; else echo "<a href=?$ALL_GET&ORDER=ORDER%20BY%20$id%20ASC>▲</a> ";
if ($ORDER=="ORDER BY $id DESC") echo "▼"; else echo "<a href=?$ALL_GET&ORDER=ORDER%20BY%20$id%20DESC>▼</a> ";
}
}
function dateformat($date, $to="fr") {
if ($to=="en") {$date = explode('/',$date); $dateout="".$date[2]."-".$date[1]."-".$date[0]."";}
else {$date = explode('-',$date); $dateout="".$date[2]."/".$date[1]."/".$date[0]."";}
if ($dateout=="//") $dateout="";
return $dateout;
}
function formatBytes($size, $precision = 2)
{ $base = log($size, 1024);
$suffixes = array('', 'K', 'M', 'G', 'T');
return round(pow(1024, $base - floor($base)), $precision) .' '. $suffixes[floor($base)];
}
// in_array only operates on a one dimensional array
function in_array_r($item , $array){
return preg_match('/"'.$item.'"/i' , json_encode($array));
}
function phone_display($n, $display) {
$char = array(" ", " ", ".", "-", ",", " ", "_");
if ($display=="") $n = str_replace($char, "", $n);
else $n = wordwrap($n, 2, $display,1);
return "$n";
}
/*
███████╗███████╗██╗ ███████╗ ██████╗████████╗
██╔════╝██╔════╝██║ ██╔════╝██╔════╝╚══██╔══╝
███████╗█████╗ ██║ █████╗ ██║ ██║
╚════██║██╔══╝ ██║ ██╔══╝ ██║ ██║
███████║███████╗███████╗███████╗╚██████╗ ██║
╚══════╝╚══════╝╚══════╝╚══════╝ ╚═════╝ ╚═╝
*/
function selecteur_chosen($nom, $table, $intitule, $A="0", $B="1", $complement="0",$complement_display="") {
global $$nom;
echo "<select name=\"$nom\" onchange=\"submit();\" data-placeholder=\"Choose…\" class=\"chosen-select\" tabindex=\"0\" >";
echo "<option value=\"\" "; if ($$nom=="") echo "selected"; echo ">— $intitule —</option>";
foreach ($table as &$l){
$selected= ($$nom==$l[$A]) ? "selected > $nom =" : " > " ;
$complement_info= ( ($complement!=0)||(array_key_exists($complement, $l)) ) ? "$l[$complement]" : "";
$c= ($complement_display!="") ? "($complement_info)" : "$complement_info";
echo "<option value=\"$l[$A]\" $selected $l[$B] $c</option>";
}
echo "</select> ";
echo "<script type=\"text/javascript\">
var config = {
'.chosen-select' : {no_results_text:'Aucun résultat pour :', width:\"250px\"},
}
for (var selector in config) {
$(selector).chosen(config[selector]);
}
</script>";
}
function option_selecteur($select, $table, $A="0", $B="1", $complement="0",$complement_display="") {
# Chaque entrée du tableau fourni est affiché sous forme d’option pour un sélecteur avec un selected sur une entrée spécifique
## select : entrée à selectionner
## table : tabeau avec toutes les entrées à proposer
## A : ?
## B : ?
## complement : ?
## complement_display : ?
foreach ($table as &$l){
$complement_info= ( ($complement!=0)||(array_key_exists($complement, $l)) ) ? "$l[$complement]" : "" ;
$c= ($complement_display!="") ? "($complement_info)" : "$complement_info";
echo "<option value=\"$l[$A]\" "; echo ($select==$l[$A]) ? "selected >" : " >"; echo "$l[$B] $c</option>";
}
}
function echodatatables($tableid,$iDisplayLength="10") {
echo "<script type=\"text/javascript\" charset=\"utf8\" src=\"datatables/jquery.dataTables.min.js\"></script>\n";
echo " <script>\n";
echo "\$(function(){\n";
echo "\$(\"#".$tableid."\").dataTable({\n";
echo "\"lengthMenu\": [5, 10, 25, 50 ],\n"; // ne fonctionne pas ?
// echo "\"bStateSave\": true,\n";
// echo "\"fnStateSave\": function (oSettings, oData) {\n";
// echo "localStorage.setItem( 'DataTables', JSON.stringify(oData) );\n";
// echo "},\n";
// echo "\"fnStateLoad\": function (oSettings) {\n";
// echo "return JSON.parse( localStorage.getItem('DataTables') );\n";
// echo "},\n";
// echo "\"iCookieDuration\": 60,\n"; // 2 minute
echo "sPaginationType: \"two_button\",\n";
echo "bPaginate: true,\n";
echo "bLengthChange: true,\n";
echo "iDisplayLength: ".$iDisplayLength.",\n";
echo "aaSorting: [],\n";
echo "});\n";
echo "})\n";
echo "</script>\n";
}
/*
██████╗ ██████╗ ███████╗███████╗██╗███████╗██████╗ ███████╗
██╔══██╗██╔═══██╗██╔════╝██╔════╝██║██╔════╝██╔══██╗██╔════╝
██║ ██║██║ ██║███████╗███████╗██║█████╗ ██████╔╝███████╗
██║ ██║██║ ██║╚════██║╚════██║██║██╔══╝ ██╔══██╗╚════██║
██████╔╝╚██████╔╝███████║███████║██║███████╗██║ ██║███████║
╚═════╝ ╚═════╝ ╚══════╝╚══════╝╚═╝╚══════╝╚═╝ ╚═╝╚══════╝
*/
function is_dir_empty($dir) {
$dir=str_replace("&", "&", $dir);
if (!is_readable($dir)) return NULL;
$handle = opendir($dir);
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") return FALSE;
}
return TRUE;
}
function displayDir($database, $i, $dir, $del=FALSE, $allowmv=FALSE) {
global $racine;
global $dossierdesfichiers;
//$dir=str_replace("&", "&", $dir);
$dir=str_replace("&", "amp", $dir);
$dir=str_replace(";", "semicolon", $dir);
$quick= ( isset($_GET["quick_page"]) ) ? "&quick_page=".$_GET["quick_page"]."&quick_name=".$_GET["quick_name"]."" : "";
// Si le dossier n’existe pas, on le crée
if (!file_exists("$dir")) {
$umask_bak=umask(0);
mkdir("$dir", 0775);
umask($umask_bak);
echo "Dossier ".str_replace($dossierdesfichiers, "", "$dir")." créé. ";
}
// Si le dossier est vide on l’indique
if (is_dir_empty("$dir")) {
echo "Aucun fichier trouvé dans ".str_replace($dossierdesfichiers, "", "$dir")."";
}
// Si le dossier n’est pas vide on liste
else {
$files = scandir("$dir");
if ($files != FALSE) {
$tableid=str_replace('/', "", $dir);
echo "\n\n<table id=\"".$tableid."\">";
echo "<thead><tr>";
echo "<th width=\"5%\"><span title=\"Type\">.*</span></th>";
echo "<th style=\"text-align:left;\">Fichier</th>";
echo "<th width=\"15%\">Taille</th>";
if ($del) echo "<th width=\"10%\"> </th>";
echo "</tr></thead>\n";
foreach ($files as $f) {
if (($f!=".")&&($f!="..")) {
echo "<tr>";
echo "<td><span style=\"display:none;\">".extension($f)."</span><span title=\"".extension($f)."\">".icone($f)."</span></td>";
echo "<td><a href=\"".str_replace($racine, "", "$dir$f")."\" target=\"_blank\">$f</a></td>";
echo "<td style=\"text-align:right;\"><span style=\"display:none;\">".filesize("$dir$f")."</span>".formatBytes(filesize("$dir$f"),"0")."o</td>";
if ($del) echo "<td style=\"text-align:center;\">";
echo "<span id=\"linkbox\" onclick=\"TINY.box.show({url:'0_rename_confirm.php?BASE=$database&i=$i&dir=".$dir."&f=".$f."".$quick."',width:280,height:110})\" title=\"renommer fichier (".$f.")\">✍</span> ";
if ($allowmv) echo "<a href=\"quick.php?BASE=$database&i=$i&quick_page=documents&quick_name=documents&move=$dir&filename=$f\" title=\"déplacer ce fichier (".$f.")\">⇆</a> ";
echo "<span id=\"linkbox\" onclick=\"TINY.box.show({url:'0_del_confirm.php?BASE=$database&i=$i&f=".$dir.$f."".$quick."',width:280,height:110})\" title=\"supprimer ce fichier (".$f.")\">×</span>
</td>";
echo"</tr>\n";
}
}
echo "</table>";
echodatatables($tableid,"5");
}
}
}
function extension($file) {
$info = new SplFileInfo($file);
return $info->getExtension();
}
function icone($f) {
if ("mime-icons/".extension($f).".png" != FALSE) $r="<img src=\"mime-icons/".mb_strtolower(extension($f)).".png\" /> ";
else $r="<img src=\"mime-icons/unknown.png\" /> ";
return $r;
}
function display_dir_compact($d) {
global $database; global $racine;
$dir=str_replace("$racine", "", $d);
//$dir=str_replace("&", "&", $dir);
$dir=str_replace("&", "amp", $dir);
$dir=str_replace(";", "semicolon", $dir);
$r="";
if (file_exists("$d")) {
if ( ! is_dir_empty("$d")) {
$files = scandir("$d");
if ($files != FALSE) {
foreach ($files as $f) {
if (($f!=".")&&($f!="..")) {
$r.="<a href=\"$dir/$f\" target=\"_blank\" title=\"".$f."\">";
$r.=icone($f);
$r.="</a> ";}
}
}
else $r=false;
}
else $r=false;
}
return $r;
}
/*
███╗ ███╗ █████╗ ██╗ ██╗ ███████╗██╗███████╗███████╗ ██╗ ██╗██████╗ ██╗ ██████╗ █████╗ ██████╗
████╗ ████║██╔══██╗╚██╗██╔╝ ██╔════╝██║╚══███╔╝██╔════╝ ██║ ██║██╔══██╗██║ ██╔═══██╗██╔══██╗██╔══██╗
██╔████╔██║███████║ ╚███╔╝ ███████╗██║ ███╔╝ █████╗ ██║ ██║██████╔╝██║ ██║ ██║███████║██║ ██║
██║╚██╔╝██║██╔══██║ ██╔██╗ ╚════██║██║ ███╔╝ ██╔══╝ ██║ ██║██╔═══╝ ██║ ██║ ██║██╔══██║██║ ██║
██║ ╚═╝ ██║██║ ██║██╔╝ ██╗ ███████║██║███████╗███████╗ ╚██████╔╝██║ ███████╗╚██████╔╝██║ ██║██████╔╝
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚══════╝╚═╝╚══════╝╚══════╝ ╚═════╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚═════╝
from drupal */
function file_upload_max_size() {
static $max_size = -1;
if ($max_size < 0) {
// Start with post_max_size.
$max_size = parse_size(ini_get('post_max_size'));
// If upload_max_size is less, then reduce. Except if upload_max_size is
// zero, which indicates no limit.
$upload_max = parse_size(ini_get('upload_max_filesize'));
if ($upload_max > 0 && $upload_max < $max_size) {
$max_size = $upload_max;
}
}
return $max_size;
}
function parse_size($size) {
$unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size.
$size = preg_replace('/[^0-9\.]/', '', $size); // Remove the non-numeric characters from the size.
if ($unit) {
// Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by.
return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
}
else {
return round($size);
}
}
function new_lab_id($categorie) {
global $dbh;
// quelle est l’abbréviation de la catégorie ?
$sth = $dbh->query("SELECT categorie_lettres FROM categorie WHERE categorie_index='".$categorie."' ;");
$tabbr = ($sth) ? $sth->fetchAll(PDO::FETCH_ASSOC) : FALSE ;
$abbr=$tabbr[0]["categorie_lettres"];
// recherche du labid max
$sth = $dbh->query("SELECT lab_id FROM base WHERE categorie='".$categorie."' ORDER BY lab_id ASC ;");
$allid = ($sth) ? $sth->fetchAll(PDO::FETCH_ASSOC) : FALSE ;
// on supprime les lettres des lab_id, on met les chiffres dans un tableau
$allidnum=array();
foreach ($allid as $a) array_push ( $allidnum, preg_replace('`[^0-9]`', '', $a["lab_id"]) );
$newid= ($allid) ? max($allidnum)+1 : 1 ;
$new_lab_id="".$abbr."".$newid."";
// TODO : Vérifier avant qu’aucune autre entrée ainsi nommée n’existe ! dans le cas d’un nommage manuel
$new_lab_id = ($categorie==0) ? "" : $new_lab_id;
return $new_lab_id;
}
function return_last_id($col,$table) {
global $dbh;
$sth = $dbh->query("SELECT $col FROM $table ORDER BY $col DESC LIMIT 1 ;");
$t = ($sth) ? $sth->fetchAll(PDO::FETCH_ASSOC) : FALSE ;
$r = ($t) ? $t[0][$col] : 0 ;
return $r;
}
function quickdisplayincarac ($t) {
global $categories; global $database;
if ($t["sortie"]=="1") echo "<strike>";
echo "<a href=\"info.php?BASE=$database&i=".$t["base_index"]."\" title=\"#".$t["base_index"]."\" target=\"_blank\">";
echo $t["lab_id"];
echo "</a>";
if (isset($t["categorie"])) {
$keys = array_keys(array_column($categories, 'categorie_index'), $t["categorie"]);
if (isset($keys[0])) {
echo " : ";
echo "<abbr title=\"Catégorie : ".$categories[$keys[0]]["categorie_nom"]." [".$categories[$keys[0]]["categorie_lettres"]."] \">";
echo $t["designation"];
echo " </abbr>";
}
}
else echo " : ".$t["designation"]." ";
if (isset($t["reference"])) echo " {".$t["reference"]."} ";
if ($t["sortie"]=="1") echo "</strike>";
}
function quickdisplaymini ($t) {
global $categories;
global $database;
if ($t["sortie"]=="1") echo "<strike>";
echo "<a href=\"info.php?BASE=$database&i=".$t["base_index"]."\" title=\"#".$t["base_index"]."";
if (isset($t["designation"])) echo " ".$t["designation"]." ";
if (isset($t["reference"])) echo "{".$t["reference"]."} ";
echo "\" target=\"_blank\">";
echo $t["lab_id"];
echo "</a>";
if ($t["sortie"]=="1") echo "</strike>";
}
function quickdisplayincarac_b ($t) {
global $categories;
$txt="";
if ($t["sortie"]=="1") $txt.="<strike>";
$txt.="<a href='info.php?BASE=$database&i=".$t["base_index"]."' title='#".$t["base_index"]."' target='_blank'>";
$txt.=$t["lab_id"];
$txt.="</a>";
if (isset($t["categorie"])) {
$keys = array_keys(array_column($categories, 'categorie_index'), $t["categorie"]);
if (isset($keys[0])) {
$txt.=" : ";
$txt.="<abbr title='Catégorie : ".$categories[$keys[0]]["categorie_nom"]." [".$categories[$keys[0]]["categorie_lettres"]."] '>";
$txt.=$t["designation"];
$txt.=" </abbr>";
}
}
else $txt.=" : ".$t["designation"]." ";
if (isset($t["reference"])) $txt.=" {".$t["reference"]."} ";
if ($t["sortie"]=="1") $txt.="</strike>";
return $txt;
}
function spanquick($p,$i) {
global $database;
$s="<span id=\"linkbox\" ";
$s.="onclick=\"TINY.box.show({iframe:'quick.php?BASE=$database&i=".$i."&quick_page=".$p."&quick_name=".$p."', width:440,height:750,closejs:function(){location.reload()}})\"";
$s.="title=\"modification rapide ".$p."\">";
return $s;
}
function vnum($s) {
$last_char=substr($s, -1);
$f_char=substr_replace($s, "", -1);
//$f_char=number_format($f_char);
if (is_numeric($f_char)) {
switch ($last_char) { // https://fr.wikipedia.org/wiki/Pr%C3%A9fixes_du_Syst%C3%A8me_international_d%27unit%C3%A9s
case "P": $v_num = $f_char*10^15; break;
case "T": $v_num = $f_char*10^12; break;
case "G": $v_num = $f_char*10^9; break;
case "M": $v_num = $f_char*10^6; break;
case "k": $v_num = $f_char*10^3; break;
case "c": $v_num = $f_char*10^-2; break;
case "m": $v_num = $f_char*10^-3; break;
case "µ": $v_num = $f_char*10^-6; break;
case "μ": $v_num = $f_char*10^-6; break;
case "n": $v_num = $f_char*10^-9; break;
case "p": $v_num = $f_char*10^-12; break;
case "f": $v_num = $f_char*10^-15; break;
default: $v_num=$s;
}
}
else $v_num="";
return $v_num;
}
function dejadanslabase($select) {
// $s="$sSELECT DISTINCT `categorie_lettres` FROM `categorie` ;"
// Ne pas oublier les ` car ils servent à récupérer une info !
global $dbh;
$abr = $dbh->query("$select");
$abrev = ($abr) ? $abr->fetchAll(PDO::FETCH_ASSOC) : FALSE ;
$listab="";
$distinct = explode("`", $select);
$d=$distinct[1];
foreach ($abrev as $a) {
$listab.="".$a["$d"]."";
$listab.="|";
}
$listab=substr("$listab", 0, -1);
return $listab;
}
$message_error_add="<p class=\"error_message\" id=\"disappear_delay\">Une erreur inconnue est survenue. L’entrée n’a pas été ajoutée.</p>";
$message_success_add="<p class=\"success_message\" id=\"disappear_delay\">L’entrée a été ajoutée à la base de donnée.</p>";
$message_error_modif="<p class=\"error_message\" id=\"disappear_delay\">Une erreur inconnue est survenue. L’entrée n’a pas été modifiée.</p>";
$message_success_modif="<p class=\"success_message\" id=\"disappear_delay\">L’entrée a été modifiée dans la base de donnée.</p>";
$message_error_del="<p class=\"error_message\" id=\"disappear_delay\">Une erreur inconnue est survenue. L’entrée n’a pas été supprimée.</p>";
$message_success_del="<p class=\"success_message\" id=\"disappear_delay\">L’entrée a été supprimée de la base de donnée.</p>";
?>