sgbd(); $env = $this->env(); $groupes = array("list" => array(), "total" => 0); try{ $SELECT = "SELECT *"; $FROM = " FROM #--sml_authors"; $WHERE = ""; $WHERE .= (isset($id_user) ? ($WHERE ? " AND" : " WHERE")." id_user=".$id_user : ""); $WHERE .= (isset($alpha) ? ($WHERE ? " AND" : " WHERE")." LEFT(login, 1)=".$this->eq($alpha) : ""); $LIMIT = (isset($start) && $env->config("max_list") ? " LIMIT ".$env->config("max_list")." OFFSET ".$start : ""); $sql = "SELECT count(*) as n FROM(".$SELECT.$FROM.$WHERE.") res"; $rst = $sgbd->query($sql); if($v_rst = $sgbd->fetch_assoc($rst)) $groupes["total"] = $v_rst["n"]; $sgbd->free_result($rst); if($groupes["total"] > 0){ $sql = "SELECT * FROM(".$SELECT.$FROM.$WHERE.$LIMIT.") res"; $rst = $sgbd->query($sql); while($v_rst = $sgbd->fetch_assoc($rst)){ if(!isset($v_rst["image"])) $v_rst["image"] = ""; $groupes["list"][$v_rst["id"]] = $v_rst; $groupes["list"][$v_rst["id"]]["image_uri"] = ( $v_rst["image"] ? $env->path("content")."uploads/".$v_rst["image"] : "" ); } $sgbd->free_result($rst); } } catch(Exception $e){ return false; } return $groupes; } function groupe($id){ $sgbd = $this->sgbd(); $env = $this->env(); $groupe = array(); try{ $sql = "SELECT * from #--sml_authors WHERE id=".$this->eq($id); $rst = $sgbd->query($sql); if($v_rst = $sgbd->fetch_assoc($rst)){ if(!isset($v_rst["image"])) $v_rst["image"] = ""; $groupe = $v_rst; $groupe["image_uri"] = ( $groupe["image"] ? $env->path("content")."uploads/".$groupe["image"] : "" ); } $sgbd->free_result($rst); } catch(Exception $e) { return false; } return $groupe; } function groupe_exists($nom, $other_than_id = null){ $sgbd = $this->sgbd(); $EXISTS = 0; try{ $sql = "SELECT count(*) as n from #--sml_authors WHERE nom=".$this->eq($nom); if(isset($other_than_id)) $sql .= " AND id!=".$this->eq($other_than_id); $rst = $sgbd->query($sql); if($v_rst = $sgbd->fetch_assoc($rst)) $EXISTS = $v_rst["n"]; $sgbd->free_result($rst); } catch(Exception $e){ return false; } return $EXISTS; } function add_groupe($id_user, $nom, $image, $description, $email, $contact_form, $captcha){ $sgbd = $this->sgbd(); try{ $sql = "INSERT INTO #--sml_authors(id_user, nom, image, description, email, contact_form, captcha) VALUES" ."( ".$this->eq($id_user) .", ".$this->eq($nom) .", ".$this->eq($image) .", ".$this->eq($description) .", ".$this->eq($email) .", ".$this->eq($contact_form) .", ".$this->eq($captcha) .")"; $sgbd->query($sql); } catch(Exception $e){ return false; } return true; } function set_groupe($id, $nom, $image, $description, $email, $contact_form, $captcha){ if(($groupe = $this->groupe($id)) === false) return false; $sgbd = $this->sgbd(); try{ $sql = "UPDATE #--sml_authors SET" ." nom=".$this->eq($nom) .", image=".$this->eq($image) .", description=".$this->eq($description) .", email=".$this->eq($email) .", contact_form=".$this->eq($contact_form) .", captcha=".$this->eq($captcha) ." WHERE id=".$id; $sgbd->query($sql); } catch(Exception $e){ return false; } if($nom != $groupe["nom"]){ $groupe["nom"] = $nom; if(!$this->maj_source_xml_groupe($groupe)) return false; } return true; } function del_groupe($id){ $sgbd = $this->sgbd(); try{ $sql = "SELECT count(*) as n FROM #--sml_sources_authors WHERE id_author=".$this->eq($id); $rst = $sgbd->query($sql); if($v_rst = $sgbd->fetch_assoc($rst)) $HAS_SOURCES = $v_rst["n"]; $sgbd->free_result($rst); if($HAS_SOURCES) return 1; $sql = "DELETE FROM #--sml_authors WHERE id=".$this->eq($id); $sgbd->query($sql); } catch(Exception $e){ return false; } return true; } } ?>