3 class sml_data_authors extends mw_data
6 # ----------------------------------------------------------------------------------------
10 function groupes($id_user = null, $start = null, $alpha = null){
11 $sgbd = $this->sgbd();
13 $groupes = array("list" => array(), "total" => 0);
16 $FROM = " FROM #--sml_authors";
18 $WHERE .= (isset($id_user) ? ($WHERE ? " AND" : " WHERE")." id_user=".$id_user : "");
19 $WHERE .= (isset($alpha) ? ($WHERE ? " AND" : " WHERE")." LEFT(login, 1)=".$this->eq($alpha) : "");
20 $LIMIT = (isset($start) && $env->config("max_list") ? " LIMIT ".$env->config("max_list")." OFFSET ".$start : "");
21 $sql = "SELECT count(*) as n FROM(".$SELECT.$FROM.$WHERE.") res";
22 $rst = $sgbd->query($sql);
23 if($v_rst = $sgbd->fetch_assoc($rst)) $groupes["total"] = $v_rst["n"];
24 $sgbd->free_result($rst);
25 if($groupes["total"] > 0){
26 $sql = "SELECT * FROM(".$SELECT.$FROM.$WHERE.$LIMIT.") res";
27 $rst = $sgbd->query($sql);
28 while($v_rst = $sgbd->fetch_assoc($rst)){
29 $groupes["list"][$v_rst["id"]] = $v_rst;
30 $groupes["list"][$v_rst["id"]]["image_uri"] = (
32 $env->path("content")."uploads/".$v_rst["image"]
36 $sgbd->free_result($rst);
46 $sgbd = $this->sgbd();
50 $sql = "SELECT * from #--sml_authors WHERE id=".$this->eq($id);
51 $rst = $sgbd->query($sql);
52 if($v_rst = $sgbd->fetch_assoc($rst)){
54 $groupe["image_uri"] = (
56 $env->path("content")."uploads/".$groupe["image"]
60 $sgbd->free_result($rst);
62 catch(Exception $e) { return false; }
66 function groupe_exists($nom, $other_than_id = null){
67 $sgbd = $this->sgbd();
70 $sql = "SELECT count(*) as n from #--sml_authors WHERE nom=".$this->eq($nom);
71 if(isset($other_than_id)) $sql .= " AND id!=".$this->eq($other_than_id);
72 $rst = $sgbd->query($sql);
73 if($v_rst = $sgbd->fetch_assoc($rst)) $EXISTS = $v_rst["n"];
74 $sgbd->free_result($rst);
82 function add_groupe($id_user, $nom, $image, $description, $email, $contact_form, $captcha){
83 $sgbd = $this->sgbd();
86 "INSERT INTO #--sml_authors(id_user, nom, image, description, email, contact_form, captcha) VALUES"
87 ."( ".$this->eq($id_user)
89 .", ".$this->eq($image)
90 .", ".$this->eq($description)
91 .", ".$this->eq($email)
92 .", ".$this->eq($contact_form)
93 .", ".$this->eq($captcha)
103 function set_groupe($id, $nom, $image, $description, $email, $contact_form, $captcha){
104 if(($groupe = $this->groupe($id)) === false) return false;
105 $sgbd = $this->sgbd();
108 "UPDATE #--sml_authors SET"
109 ." nom=".$this->eq($nom)
110 .", image=".$this->eq($image)
111 .", description=".$this->eq($description)
112 .", email=".$this->eq($email)
113 .", contact_form=".$this->eq($contact_form)
114 .", captcha=".$this->eq($captcha)
121 if($nom != $groupe["nom"]){
122 $groupe["nom"] = $nom;
123 if(!$this->maj_source_xml_groupe($groupe)) return false;
128 function del_groupe($id){
129 $sgbd = $this->sgbd();
131 $sql = "SELECT count(*) as n FROM #--sml_sources_authors WHERE id_author=".$this->eq($id);
132 $rst = $sgbd->query($sql);
133 if($v_rst = $sgbd->fetch_assoc($rst)) $HAS_SOURCES = $v_rst["n"];
134 $sgbd->free_result($rst);
135 if($HAS_SOURCES) return 1;
136 $sql = "DELETE FROM #--sml_authors WHERE id=".$this->eq($id);