root / functions.php @ 765cf74636d34cd9fdb1dc3a2a727a4d031c9d12
Historique | Voir | Annoter | Télécharger (2,86 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 | "C" => "coupe", |
11 | "T" => "tournoi" |
12 | ); |
13 | |
14 | $SEP_DIV = "_"; |
15 | |
16 | /* Equivalent de file_put_contents disponible uniquement en PHP 5 */
|
17 | function my_file_put_contents($filename, $content, $flag = false) { |
18 | if (!$flag) $mode = 'w'; |
19 | $f = @fopen($filename, $mode); |
20 | if ($f === false) { |
21 | return 0; |
22 | } else {
|
23 | if (is_array($content)) $content = implode($content); |
24 | $bytes_written = fwrite($f, $content); |
25 | fclose($f); |
26 | return $bytes_written; |
27 | } |
28 | } |
29 | |
30 | function getDirs($path, &$var) { |
31 | if ($dir = opendir($path)) { |
32 | while (($file = readdir($dir)) !== FALSE) { |
33 | if (is_dir("$path/$file") && $file != "." && $file != "..") |
34 | $var[] = $file; |
35 | } |
36 | closedir($dir); |
37 | } |
38 | } |
39 | |
40 | function mkdirRecursive($path) { |
41 | if (!file_exists($path)) { |
42 | mkdirRecursive(dirname($path)); |
43 | mkdir($path); |
44 | } |
45 | } |
46 | |
47 | // Teste si le répertoire existe et est vide
|
48 | function isEmptyDir($dirname) { |
49 | $result = false; |
50 | if (is_dir($dirname)) { |
51 | $result = true; |
52 | $files = opendir($dirname); |
53 | while (($name = readdir($files)) !== false) { |
54 | if ($name != "." && $name != "..") { |
55 | $result = false; |
56 | break;
|
57 | } |
58 | } |
59 | closedir($files); |
60 | } |
61 | return $result; |
62 | } |
63 | |
64 | function IamAdmin() { |
65 | return (basename(dirname($_SERVER['PHP_SELF'])) == "admin"); |
66 | } |
67 | |
68 | function monRmdir($dir) { |
69 | if (file_exists("trash")) { |
70 | // rmdir pour free.fr (bande de nazes)
|
71 | rename($dir, "trash/".basename($dir)); |
72 | } else {
|
73 | rmdir($dir); |
74 | } |
75 | } |
76 | |
77 | // Récupération des équipes/joueurs d'une compétitions identifiée par $path
|
78 | function getEquipes($path) { |
79 | $file = "$path/equipes"; |
80 | if (file_exists($file) && $equipes = file($file)) { |
81 | foreach ($equipes as $n => $e) $equipes[$n] = rtrim($e); |
82 | return $equipes; |
83 | } |
84 | return array(); |
85 | } |
86 | |
87 | // Récupération des journées/tours d'une compétition identifiée par $path
|
88 | function getJournees($path) { |
89 | $file = "$path/journees"; |
90 | if (file_exists($file) && $journees = file($file)) { |
91 | foreach ($journees as $n => $e) $journees[$n] = rtrim($e); |
92 | return $journees; |
93 | } |
94 | return array(); |
95 | } |
96 | |
97 | function getPenalites($path) { |
98 | $Pen = array(); |
99 | $file = "$path/penalites"; |
100 | if (file_exists($file) && $penalites = file($file)) { |
101 | foreach ($penalites as $n => $p) { |
102 | list($equipe, $penalite) = explode(":", rtrim($penalites[$n])); |
103 | $Pen[$equipe] = $penalite; |
104 | } |
105 | } |
106 | return $Pen; |
107 | } |
108 | |
109 | function backup(&$zip, $dir, $zipdir) { |
110 | if ($dh = opendir($dir)) { |
111 | while (($file = readdir($dh)) !== false) { |
112 | if ($file == "." || $file == "..") continue; |
113 | $filename = "$dir/$file"; |
114 | if (is_dir($filename)) { |
115 | backup($zip, $filename, "$zipdir/$file"); |
116 | } else {
|
117 | $fp = fopen($filename, 'r'); |
118 | $contenu = ""; |
119 | if (filesize($filename) > 0) $contenu = fread($fp, filesize($filename)); |
120 | fclose($fp); |
121 | $zip->addfile($contenu, "$zipdir/$file"); |
122 | } |
123 | } |
124 | closedir($dh); |
125 | } |
126 | } |
127 | |
128 | ?>
|