sql->query($query); while($v_rst = $this->sql->fetch_assoc($rst)) { $downloads[$v_rst["id"]] = $v_rst; $downloads[$v_rst["id"]]["compteur"] = 0; $downloads[$v_rst["id"]]["urls"] = array(); $u_query = "SELECT #--download_urls.*, #--formats.nom as format" ." FROM #--download_urls, #--formats" ." WHERE id_download=".$v_rst["id"] ." AND #--download_urls.id_format=#--formats.id"; $u_rst = $this->sql->query($u_query); while($v_u_rst = $this->sql->fetch_assoc($u_rst)) { $downloads[$v_rst["id"]]["urls"][$v_u_rst["id"]] = $v_u_rst; $downloads[$v_rst["id"]]["compteur"] += $v_u_rst["compteur"]; if($v_u_rst["format"] === "mp3") { $downloads[$v_rst["id"]]["mp3_id_url"] = $v_u_rst["id"]; $downloads[$v_rst["id"]]["mp3_url"] = $v_u_rst["url"]; } } $this->sql->free_result($u_rst); } $this->sql->free_result($rst); } catch(Exception $_e) { $downloads = false; } return $downloads; } function nb_downloads($public = false) { $n = 0; try { $select = "SELECT count(*) as n" ." FROM #--downloads"; $where = $public ? " WHERE actif=1 AND id_licence IS NOT NULL" : ""; $rst = $this->sql->query($select.$where); if($v_rst = $this->sql->fetch_assoc($rst)) $n = $v_rst["n"]; $this->sql->free_result($rst); } catch(Exception $_e) { $n = false; } return $n; } function nb_mp3($id, $public = false, $album = null) { $n = 0; try { $query = "SELECT #--downloads.id" ." FROM #--artistes, #--downloads" ." WHERE #--downloads.id_artiste=#--artistes.id" ." AND #--artistes.id=".$id .($public ? " AND actif=1 AND id_licence IS NOT NULL" : "") .(isset($album) ? " AND id_album=".$album : ""); $rst = $this->sql->query($query); while($v_rst = $this->sql->fetch_assoc($rst)) { $u_query = "SELECT count(*) as n" ." FROM #--download_urls, #--formats" ." WHERE id_download=".$v_rst["id"] ." AND #--download_urls.id_format=#--formats.id" ." AND #--formats.nom='mp3'"; $u_rst = $this->sql->query($u_query); if($v_u_rst = $this->sql->fetch_assoc($u_rst)) $n += $v_u_rst["n"]; $this->sql->free_result($u_rst); } $this->sql->free_result($rst); } catch(Exception $_e) { $n = false; } return $n; } function artiste_download($id) { $download = array(); try { $query = "SELECT #--downloads.*" .", #--licences.nom as licence" .", #--licences.lien as licence_url" ." FROM #--downloads, #--licences" ." WHERE #--downloads.id=".$id ." AND #--downloads.id_licence=#--licences.id"; $rst = $this->sql->query($query); if($v_rst = $this->sql->fetch_assoc($rst)) { $download = $v_rst; $download["urls"] = array(); $u_query = "SELECT #--download_urls.*, #--formats.nom as format" ." FROM #--download_urls, #--formats" ." WHERE id_download=".$v_rst["id"] ." AND #--download_urls.id_format=#--formats.id"; $u_rst = $this->sql->query($u_query); while($v_u_rst = $this->sql->fetch_assoc($u_rst)) { $download["urls"][$v_u_rst["id"]] = $v_u_rst; if($v_u_rst["format"] === "mp3") $download["mp3_url"] = $v_u_rst["url"]; } $this->sql->free_result($u_rst); } $this->sql->free_result($rst); } catch(Exception $_e) { $download = false; } return $download; } function licences() { $licences = array(); try { $query = "SELECT * FROM #--licences"; $rst = $this->sql->query($query); while($v_rst = $this->sql->fetch_assoc($rst)) $licences[$v_rst["id"]] = $v_rst; $this->sql->free_result($rst); } catch(Exception $_e) { $licences = false; } return $licences; } function formats() { $formats = array(); try { $query = "SELECT * FROM #--formats"; $rst = $this->sql->query($query); while($v_rst = $this->sql->fetch_assoc($rst)) $formats[$v_rst["id"]] = $v_rst; $this->sql->free_result($rst); } catch(Exception $_e) { $formats = false; } return $formats; } function add_download($id_artiste, $nom, $album, $style, $id_licence, $date_creation, $id_format, $url) { try { $query = "INSERT INTO #--downloads VALUES" ."(NULL" .", ".$id_artiste .", ".$this->eq($album) .", ".$id_licence .", ".$this->eq($nom) .", '".$date_creation."'" .", ".$this->eq($style) .", NULL" .", 0" .", 1" .")"; $this->sql->query($query); $id_download = $this->sql->insert_id(); $query = "INSERT INTO #--download_urls VALUES" ."(NULL" .", ".$id_download .", ".$id_format .", NULL" .", ".$this->eq($url) .", NULL" .", '".date("Y-m-d")."'" .", 0" .")"; $this->sql->query($query); } catch(Exception $_e) { return false; } return true; } function set_download($id, $nom, $album, $style, $id_licence, $date_creation) { try { $query = "UPDATE #--downloads SET" ." nom=".$this->eq($nom) .", id_album=".$this->eq($album) .", style=".$this->eq($style) .", id_licence=".$id_licence .", date_creation='".$date_creation."'" ." WHERE id=".$id; $this->sql->query($query); } catch(Exception $_e) { return false; } return true; } function del_download($id_download) { try { $this->sql->query("DELETE FROM #--downloads WHERE id=".$this->eq($id_download)); $this->sql->query("DELETE FROM #--download_urls WHERE id_download=".$this->eq($id_download)); } catch(Exception $_e) { return false; } return true; } function add_download_url($id_download, $url, $id_format) { try { $query = "INSERT INTO #--download_urls(id_download, id_format, url, date_publication) VALUES" ."( ".$id_download .", ".$id_format .", ".$this->eq($url) .", '".date("Y-m-d")."'" .")"; $this->sql->query($query); } catch(Exception $_e) { return false; } return true; } function set_download_url($id_download_url, $url, $id_format) { try { $query = "UPDATE #--download_urls SET" ." url=".$this->eq($url) .", id_format=".$id_format ." WHERE id=".$id_download_url; $this->sql->query($query); } catch(Exception $_e) { return false; } return true; } function del_download_url($id_download, $id_download_url) { if(($download = $this->artiste_download($id_download)) !== false) { try { $this->sql->query("DELETE FROM #--download_urls WHERE id=".$this->eq($id_download_url)); if(count($download["urls"]) <= 1) { if($this->del_download($id_download)) return 2; else return false; } } catch(Exception $_e) { return false; } } else return false; return 1; } function set_downloads($ordre, $actif) { try { foreach($ordre as $id => $_ordre) { $query = "UPDATE #--downloads SET" ." ordre=".$_ordre .", actif=".($actif[$id] ? 1 : 0) ." WHERE id=".$id; $this->sql->query($query); } } catch(Exception $_e) { return false; } return true; } function inc_download_compteur($id_download) { $url = false; try { $sql = "SELECT url FROM #--download_urls WHERE id=".$id_download; $rst = $this->sql->query($sql); if($v_rst = $this->sql->fetch_assoc($rst)) $url = $v_rst["url"]; if($url) { $sql = "UPDATE #--download_urls SET compteur=(compteur + 1) WHERE id=".$id_download; $this->sql->query($sql); } } catch(Exception $_e) { $url = false; } return $url; } } ?>