3 class sml_data_licences extends mw_data{
5 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);
25 catch(Exception $e) { $licences = false; }
29 function licence($id){
30 $sgbd = $this->sgbd();
33 $sql = "SELECT * from #--sml_licences WHERE id=".$this->eq($id);
34 $rst = $sgbd->query($sql);
35 if($v_rst = $sgbd->fetch_assoc($rst)) $licence = $v_rst;
36 $sgbd->free_result($rst);
38 catch(Exception $e) { $licence = false; }
42 function add_licence($nom, $url){
43 $sgbd = $this->sgbd();
46 "INSERT INTO #--sml_licences(nom, url) VALUES"
52 catch(Exception $e) { return false; }
56 function set_licence($id, $nom, $url){
57 if(($licence = $this->licence($id)) !== false){
58 $sgbd = $this->sgbd();
61 "UPDATE #--sml_licences SET"
62 ." nom=".$this->eq($nom)
63 .", url=".$this->eq($url)
66 if($nom != $licence["nom"] || $url != $licence["url"]){
67 $licence["nom"] = $nom;
68 $licence["url"] = $url;
69 if(!$this->maj_source_xml_licence($licence)) return false;
72 catch(Exception $e) { return false; }
78 function del_licence($id){
79 $sgbd = $this->sgbd();
81 $sql = "SELECT count(*) as n FROM #--sml_sources WHERE licence=".$this->eq($id);
82 $rst = $sgbd->query($sql);
83 if($v_rst = $sgbd->fetch_assoc($rst)) $USED = $v_rst["n"];
84 $sgbd->free_result($rst);
86 $sql = "DELETE FROM #--sml_licences WHERE id=".$this->eq($id);
89 catch(Exception $e) { return false; }