3 class sml_data_licences extends mw_data{
5 public function licences($start = null){
8 $licences = array("list" => array(), "total" => 0);
11 $FROM = " FROM #--sml_licences";
13 $LIMIT = (isset($start) && $env->config("max_list") ? " LIMIT ".$env->config("max_list")." OFFSET ".$start : "");
14 $sql = "SELECT count(*) as n FROM(".$SELECT.$FROM.$WHERE.") res";
15 $rst = $sgbd->query($sql);
16 if($v_rst = $sgbd->fetch_assoc($rst)) $licences["total"] = $v_rst["n"];
17 $sgbd->free_result($rst);
18 if($licences["total"] > 0){
19 $sql = "SELECT * FROM(".$SELECT.$FROM.$WHERE.$LIMIT.") res";
20 $rst = $sgbd->query($sql);
21 while($v_rst = $sgbd->fetch_assoc($rst)) $licences["list"][$v_rst["id"]] = $v_rst;
22 $sgbd->free_result($rst);
31 public function licence($id){
32 $sgbd = $this->sgbd();
35 $sql = "SELECT * from #--sml_licences WHERE id=".$this->eq($id);
36 $rst = $sgbd->query($sql);
37 if($v_rst = $sgbd->fetch_assoc($rst)) $licence = $v_rst;
38 $sgbd->free_result($rst);
46 public function add_licence($nom, $url){
47 $sgbd = $this->sgbd();
50 "INSERT INTO #--sml_licences(nom, url) VALUES"
62 public function set_licence($id, $nom, $url){
63 if(($licence = $this->licence($id)) !== false){
64 $sgbd = $this->sgbd();
67 "UPDATE #--sml_licences SET"
68 ." nom=".$this->eq($nom)
69 .", url=".$this->eq($url)
72 if($nom != $licence["nom"] || $url != $licence["url"]){
73 $licence["nom"] = $nom;
74 $licence["url"] = $url;
75 if(!$this->maj_source_xml_licence($licence)) return false;
86 public function del_licence($id){
87 $sgbd = $this->sgbd();
89 $sql = "SELECT count(*) as n FROM #--sml_sources WHERE licence=".$this->eq($id);
90 $rst = $sgbd->query($sql);
91 if($v_rst = $sgbd->fetch_assoc($rst)) $USED = $v_rst["n"];
92 $sgbd->free_result($rst);
94 $sql = "DELETE FROM #--sml_licences WHERE id=".$this->eq($id);