root / functions.php @ 66345d02c167f1e1c0f4bd8babfe72850629a0ac
Historique | Voir | Annoter | Télécharger (3,81 ko)
1 | <?php
|
---|---|
2 | |
3 | $DIVISION = array( |
4 | "PRO" => "PRO", |
5 | "N" => "National", |
6 | "PN" => "Pré-National", |
7 | "R" => "Régional", |
8 | "PR" => "Pré-Régional", |
9 | "D" => "Départemental", |
10 | "Excellence" => "Excellence", |
11 | "PromoExcellence" => "Promotion d'Excellence", |
12 | "Honneur" => "Honneur", |
13 | "PromoHonneur" => "Promotion d'Honneur" |
14 | ); |
15 | |
16 | $SEP_DIV = "_"; |
17 | |
18 | /* Equivalent de file_put_contents disponible uniquement en PHP 5 */
|
19 | function my_file_put_contents($filename, $content, $flag = false) { |
20 | if (!$flag) $mode = 'w'; |
21 | $f = @fopen($filename, $mode); |
22 | if ($f === false) { |
23 | return 0; |
24 | } else {
|
25 | if (is_array($content)) $content = implode($content); |
26 | $bytes_written = fwrite($f, $content); |
27 | fclose($f); |
28 | return $bytes_written; |
29 | } |
30 | } |
31 | |
32 | function getDirs($path, &$var) { |
33 | if ($dir = opendir($path)) { |
34 | while (($file = readdir($dir)) !== FALSE) { |
35 | if (is_dir("$path/$file") && $file != "." && $file != "..") |
36 | $var[] = $file; |
37 | } |
38 | closedir($dir); |
39 | } |
40 | } |
41 | |
42 | function mkdirRecursive($path) { |
43 | if (!file_exists($path)) { |
44 | mkdirRecursive(dirname($path)); |
45 | mkdir($path); |
46 | } |
47 | } |
48 | |
49 | // Teste si le répertoire existe et est vide
|
50 | function isEmptyDir($dirname) { |
51 | $result = false; |
52 | if (is_dir($dirname)) { |
53 | $result = true; |
54 | $files = opendir($dirname); |
55 | while (($name = readdir($files)) !== false) { |
56 | if ($name != "." && $name != "..") { |
57 | $result = false; |
58 | break;
|
59 | } |
60 | } |
61 | closedir($files); |
62 | } |
63 | return $result; |
64 | } |
65 | |
66 | function IamAdmin() { |
67 | return (basename(dirname($_SERVER['PHP_SELF'])) == "admin"); |
68 | } |
69 | |
70 | function monRmdir($dir) { |
71 | if (file_exists("trash")) { |
72 | // rmdir pour free.fr (bande de nazes)
|
73 | rename($dir, "trash/".basename($dir)); |
74 | } else {
|
75 | rmdir($dir); |
76 | } |
77 | } |
78 | |
79 | // Récupération des équipes/joueurs d'une compétitions identifiée par $path
|
80 | function getEquipes($path) { |
81 | $file = "$path/equipes"; |
82 | if (file_exists($file) && $equipes = file($file)) { |
83 | foreach ($equipes as $n => $e) $equipes[$n] = rtrim($e); |
84 | return $equipes; |
85 | } |
86 | return array(); |
87 | } |
88 | |
89 | // Récupération des journées/tours d'une compétition identifiée par $path
|
90 | function getJournees($path) { |
91 | $file = "$path/journees"; |
92 | if (file_exists($file) && $journees = file($file)) { |
93 | foreach ($journees as $n => $e) $journees[$n] = rtrim($e); |
94 | return $journees; |
95 | } |
96 | return array(); |
97 | } |
98 | |
99 | function getPenalites($path) { |
100 | $Pen = array(); |
101 | $file = "$path/penalites"; |
102 | if (file_exists($file) && $penalites = file($file)) { |
103 | foreach ($penalites as $p) { |
104 | list($equipe, $penalite) = explode(":", rtrim($p)); |
105 | $Pen[$equipe] = $penalite; |
106 | } |
107 | } |
108 | return $Pen; |
109 | } |
110 | |
111 | function getAjustements($path) { |
112 | $Adjust = array(); |
113 | $file = "$path/ajustements"; |
114 | if (file_exists($file) && $ajustements = file($file)) { |
115 | foreach ($ajustements as $a) { |
116 | list($equipe, $ajustement) = explode(":", rtrim($a)); |
117 | $Adjust[$equipe] = $ajustement; |
118 | } |
119 | } |
120 | return $Adjust; |
121 | } |
122 | |
123 | function getForfaitsG($path) { |
124 | $ForfaitsG = array(); |
125 | $file = "$path/forfaits"; |
126 | if (file_exists($file) && $forfaits = file($file)) { |
127 | foreach ($forfaits as $f) { |
128 | list($equipe, $forfait) = explode(":", rtrim($f)); |
129 | $ForfaitsG[$equipe] = $forfait; |
130 | } |
131 | } |
132 | return $ForfaitsG; |
133 | } |
134 | |
135 | function getCommentaires($path) { |
136 | $Comments = array(); |
137 | $file = "$path/commentaires"; |
138 | if (file_exists($file) && $commentaires = file($file)) { |
139 | foreach ($commentaires as $c) { |
140 | list($equipe, $commentaire) = explode(":", rtrim($c)); |
141 | $Comments[$equipe] = $commentaire; |
142 | } |
143 | } |
144 | return $Comments; |
145 | } |
146 | |
147 | function backup(&$zip, $dir, $zipdir) { |
148 | if ($dh = opendir($dir)) { |
149 | while (($file = readdir($dh)) !== false) { |
150 | if ($file == "." || $file == "..") continue; |
151 | $filename = "$dir/$file"; |
152 | if (is_dir($filename)) { |
153 | backup($zip, $filename, "$zipdir/$file"); |
154 | } else {
|
155 | $fp = fopen($filename, 'r'); |
156 | $contenu = ""; |
157 | if (filesize($filename) > 0) $contenu = fread($fp, filesize($filename)); |
158 | fclose($fp); |
159 | $zip->addfile($contenu, "$zipdir/$file"); |
160 | } |
161 | } |
162 | closedir($dh); |
163 | } |
164 | } |
165 | |
166 | ?>
|