Statistiques
| Branche: | Révision :

root / functions.php @ 500dec614eca3bebb0c83b8a50d96e69442f1435

Historique | Voir | Annoter | Télécharger (4,02 ko)

1
<?php
2
3
$DIVISION = array(
4
        "PRO" => "PRO",
5
        "N" => "National",
6
        "PN" => "Pr&eacute;-National",
7
        "R" => "R&eacute;gional",
8
        "PR" => "Pr&eacute;-R&eacute;gional",
9
        "D" => "D&eacute;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 authent() {
67
        return (basename(dirname($_SERVER['PHP_SELF'])) == "admin" && isset($_SERVER['PHP_AUTH_USER']));
68
}
69
70
function IamAdmin() {
71
        return (authent() && $_SERVER['PHP_AUTH_USER'] == "admin");
72
}
73
74
function IamCaptain() {
75
        return (authent() && $_SERVER['PHP_AUTH_USER'] == "capitaine");
76
}
77
78
function monRmdir($dir) {
79
        if (file_exists("trash")) {
80
                // rmdir pour free.fr (bande de nazes)
81
                rename($dir, "trash/".basename($dir));
82
        } else {
83
                rmdir($dir);
84
        }
85
}
86
87
// Récupération des équipes/joueurs d'une compétitions identifiée par $path
88
function getEquipes($path) {
89
        $file = "$path/equipes";
90
        if (file_exists($file) && $equipes = file($file)) {
91
                foreach ($equipes as $n => $e) $equipes[$n] = rtrim($e);
92
                return $equipes;
93
        }
94
        return array();
95
}
96
97
// Récupération des journées/tours d'une compétition identifiée par $path
98
function getJournees($path) {
99
        $file = "$path/journees";
100
        if (file_exists($file) && $journees = file($file)) {
101
                foreach ($journees as $n => $e) $journees[$n] = rtrim($e);
102
                return $journees;
103
        }
104
        return array();
105
}
106
107
function getPenalites($path) {
108
        $Pen = array();
109
        $file = "$path/penalites";
110
        if (file_exists($file) && $penalites = file($file)) {
111
                foreach ($penalites as $p) {
112
                        list($equipe, $penalite) = explode(":", rtrim($p));
113
                        $Pen[$equipe] = $penalite;
114
                }
115
        }
116
        return $Pen;
117
}
118
119
function getAjustements($path) {
120
        $Adjust = array();
121
        $file = "$path/ajustements";
122
        if (file_exists($file) && $ajustements = file($file)) {
123
                foreach ($ajustements as $a) {
124
                        list($equipe, $ajustement) = explode(":", rtrim($a));
125
                        $Adjust[$equipe] = $ajustement;
126
                }
127
        }
128
        return $Adjust;
129
}
130
131
function getForfaitsG($path) {
132
        $ForfaitsG = array();
133
        $file = "$path/forfaits";
134
        if (file_exists($file) && $forfaits = file($file)) {
135
                foreach ($forfaits as $f) {
136
                        list($equipe, $forfait) = explode(":", rtrim($f));
137
                        $ForfaitsG[$equipe] = $forfait;
138
                }
139
        }
140
        return $ForfaitsG;
141
}
142
143
function getCommentaires($path) {
144
        $Comments = array();
145
        $file = "$path/commentaires";
146
        if (file_exists($file) && $commentaires = file($file)) {
147
                foreach ($commentaires as $c) {
148
                        list($equipe, $commentaire) = explode(":", rtrim($c));
149
                        $Comments[$equipe] = $commentaire;
150
                }
151
        }
152
        return $Comments;
153
}
154
155
function backup(&$zip, $dir, $zipdir) {
156
        if ($dh = opendir($dir)) {
157
                while (($file = readdir($dh)) !== false) {
158
                        if ($file == "." || $file == "..") continue;
159
                        $filename = "$dir/$file";
160
                        if (is_dir($filename)) {
161
                                backup($zip, $filename, "$zipdir/$file");
162
                        } else {
163
                                $fp = fopen($filename, 'r');
164
                                $contenu = "";
165
                                if (filesize($filename) > 0) $contenu = fread($fp, filesize($filename));
166
                                fclose($fp);
167
                                $zip->addfile($contenu, "$zipdir/$file");
168
                        }
169
                }
170
                closedir($dh);
171
        }
172
}
173
174
?>