// // This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License. // // To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/1.0/ // // or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. // // Francais (brouillon): http://creativecommons.org/projects/international/fr/translated-license // ////////////////////////////////////////////////////////////////////////////////////////////////////// // Gestion des groupes // v0.1.1 class groupes { var $err = array( "stop" => "oui", "log" => "oui", "debug" => "oui"); var $chemin = "../datas/"; // Gestion des erreurs function _err($err,$debug="") { // Si le debug est activé if($this->err[debug] == "oui" && !empty($debug)) $err.= "\n// DEBUG //\n".$debug; // Si on log les erreurs if($this->err[log] == "oui") $this->erreurs[] = $err; // Si on s'arrête sur les erreurs if($this->err[stop] == "oui") { echo "
".htmlentities(stripslashes($err))."
"; exit; } $this->erreur = $err; return FALSE; } function lire() { $f = file($this->chemin."groupes.txt"); if(!$f) return $this->_err("Impossible d'ouvrir le fichier de groupes."); $f = implode("",$f); $f = unserialize($f); return $f; } function ecrire($array) { $a = serialize($array); $fp = @fopen($this->chemin."groupes.txt","w"); if(!$fp) return $this->_err("Impossible d'écrire dans le fichier de groupes."); fputs($fp,$a); fclose($fp); unset($this->groupes); return TRUE; } function get($id) { if(!is_array($this->groupes)) $this->groupes = $this->lire(); return $this->groupes[$id]; } function get_all() { if(!is_array($this->groupes)) $this->groupes = $this->lire(); return $this->groupes; } # $array = array( # string nom, string description, int niveau, enum statut (normal,moderateur,administrateur), int nb_journaux, # int nb_messages, int nb_ecrits, int quota, int max_journaux, int max_membres, function add($id,$array) { if(!is_array($this->groupes)) $this->groupes = $this->lire(); $this->groupes[$id] = $array; $this->ecrire($this->groupes); } function nouveau() { if(!is_array($this->groupes)) $this->groupes = $this->lire(); for($i=1;$i < count($this->groupes)+1;$i++) { if(!array_key_exists($i,$this->groupes)) break; } $this->groupes[$i] = array("nom"=>"Nouveau groupe","description"=>"...","niveau"=>0,"statut"=>"normal", "nb_journaux"=>0,"nb_messages"=>0,"nb_ecrits"=>0,"quota"=>0,"max_journaux"=>0,"max_membres"=>0); $this->ecrire($this->groupes); return $i; } function supprimer($id) { if(!is_array($this->groupes)) $this->groupes = $this->lire(); unset($this->groupes[$id]); $this->ecrire($this->groupes); } function count_membres($groupe) { $requete = "SELECT COUNT(id) FROM membres WHERE groupe='".$groupe."'"; $res = mysql_query($requete); $rec = @mysql_fetch_row($res); return $rec[0]; } } ?>