sgbd(); $env = $this->env(); $licences = array("list" => array(), "total" => 0); try{ $SELECT = "SELECT *"; $FROM = " FROM #--sml_licences"; $WHERE = ""; $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)) $licences["total"] = $v_rst["n"]; $sgbd->free_result($rst); if($licences["total"] > 0){ $sql = "SELECT * FROM(".$SELECT.$FROM.$WHERE.$LIMIT.") res"; $rst = $sgbd->query($sql); while($v_rst = $sgbd->fetch_assoc($rst)) $licences["list"][$v_rst["id"]] = $v_rst; $sgbd->free_result($rst); } } catch(Exception $e){ $licences = false; } return $licences; } public function licence($id){ $sgbd = $this->sgbd(); $licence = array(); try{ $sql = "SELECT * from #--sml_licences WHERE id=".$this->eq($id); $rst = $sgbd->query($sql); if($v_rst = $sgbd->fetch_assoc($rst)) $licence = $v_rst; $sgbd->free_result($rst); } catch(Exception $e){ $licence = false; } return $licence; } public function add_licence($nom, $url){ $sgbd = $this->sgbd(); try{ $sql = "INSERT INTO #--sml_licences(nom, url) VALUES" ."( ".$this->eq($nom) .", ".$this->eq($url) .")"; $sgbd->query($sql); } catch(Exception $e){ return false; } return true; } public function set_licence($id, $nom, $url){ if(($licence = $this->licence($id)) !== false){ $sgbd = $this->sgbd(); try{ $sql = "UPDATE #--sml_licences SET" ." nom=".$this->eq($nom) .", url=".$this->eq($url) ." WHERE id=".$id; $sgbd->query($sql); if($nom != $licence["nom"] || $url != $licence["url"]){ $licence["nom"] = $nom; $licence["url"] = $url; if(!$this->maj_source_xml_licence($licence)) return false; } } catch(Exception $e){ return false; } return true; } return false; } public function del_licence($id){ $sgbd = $this->sgbd(); try{ $sql = "SELECT count(*) as n FROM #--sml_sources WHERE licence=".$this->eq($id); $rst = $sgbd->query($sql); if($v_rst = $sgbd->fetch_assoc($rst)) $USED = $v_rst["n"]; $sgbd->free_result($rst); if($USED) return 1; $sql = "DELETE FROM #--sml_licences WHERE id=".$this->eq($id); $sgbd->query($sql); } catch(Exception $e){ return false; } return true; } }