[6] | 1 | <?php |
---|
| 2 | |
---|
| 3 | class da_downloads extends data |
---|
| 4 | { |
---|
| 5 | |
---|
| 6 | function artiste_downloads($id = null, $public = false, $album = null, $_sql = null) |
---|
| 7 | { $downloads = array(); |
---|
| 8 | try |
---|
| 9 | { $query = |
---|
| 10 | "SELECT #--downloads.*" |
---|
| 11 | .", #--artistes.nom as auteur" |
---|
| 12 | .", #--licences.nom as licence" |
---|
| 13 | .", #--licences.lien as licence_url" |
---|
| 14 | ." FROM #--artistes" |
---|
| 15 | .", #--downloads" |
---|
| 16 | .", #--licences" |
---|
| 17 | ." WHERE #--downloads.id_artiste=#--artistes.id" |
---|
| 18 | .(isset($id) ? " AND #--artistes.id=".$id : "") |
---|
| 19 | ." AND #--downloads.id_licence=#--licences.id" |
---|
| 20 | .($public ? " AND actif=1" : "") |
---|
| 21 | .(isset($album) ? " AND id_album=".$album : "") |
---|
| 22 | .(isset($_sql) ? $_sql : " ORDER BY #--downloads.ordre ASC"); |
---|
| 23 | $rst = $this->sql->query($query); |
---|
| 24 | while($v_rst = $this->sql->fetch_assoc($rst)) |
---|
| 25 | { $downloads[$v_rst["id"]] = $v_rst; |
---|
| 26 | $downloads[$v_rst["id"]]["compteur"] = 0; |
---|
| 27 | $downloads[$v_rst["id"]]["urls"] = array(); |
---|
| 28 | $u_query = |
---|
| 29 | "SELECT #--download_urls.*, #--formats.nom as format" |
---|
| 30 | ." FROM #--download_urls, #--formats" |
---|
| 31 | ." WHERE id_download=".$v_rst["id"] |
---|
| 32 | ." AND #--download_urls.id_format=#--formats.id"; |
---|
| 33 | $u_rst = $this->sql->query($u_query); |
---|
| 34 | while($v_u_rst = $this->sql->fetch_assoc($u_rst)) |
---|
| 35 | { $downloads[$v_rst["id"]]["urls"][$v_u_rst["id"]] = $v_u_rst; |
---|
| 36 | $downloads[$v_rst["id"]]["compteur"] += $v_u_rst["compteur"]; |
---|
| 37 | if($v_u_rst["format"] === "mp3") |
---|
| 38 | { $downloads[$v_rst["id"]]["mp3_id_url"] = $v_u_rst["id"]; |
---|
| 39 | $downloads[$v_rst["id"]]["mp3_url"] = $v_u_rst["url"]; |
---|
| 40 | } |
---|
| 41 | } |
---|
| 42 | $this->sql->free_result($u_rst); |
---|
| 43 | } |
---|
| 44 | $this->sql->free_result($rst); |
---|
| 45 | } |
---|
| 46 | catch(Exception $_e) { $downloads = false; } |
---|
| 47 | return $downloads; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | function nb_downloads($public = false) |
---|
| 51 | { $n = 0; |
---|
| 52 | try |
---|
| 53 | { $select = |
---|
| 54 | "SELECT count(*) as n" |
---|
| 55 | ." FROM #--downloads"; |
---|
| 56 | $where = $public ? " WHERE actif=1 AND id_licence IS NOT NULL" : ""; |
---|
| 57 | $rst = $this->sql->query($select.$where); |
---|
| 58 | if($v_rst = $this->sql->fetch_assoc($rst)) $n = $v_rst["n"]; |
---|
| 59 | $this->sql->free_result($rst); |
---|
| 60 | } |
---|
| 61 | catch(Exception $_e) { $n = false; } |
---|
| 62 | return $n; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | function nb_mp3($id, $public = false, $album = null) |
---|
| 66 | { $n = 0; |
---|
| 67 | try |
---|
| 68 | { $query = |
---|
| 69 | "SELECT #--downloads.id" |
---|
| 70 | ." FROM #--artistes, #--downloads" |
---|
| 71 | ." WHERE #--downloads.id_artiste=#--artistes.id" |
---|
| 72 | ." AND #--artistes.id=".$id |
---|
| 73 | .($public ? " AND actif=1 AND id_licence IS NOT NULL" : "") |
---|
| 74 | .(isset($album) ? " AND id_album=".$album : ""); |
---|
| 75 | $rst = $this->sql->query($query); |
---|
| 76 | while($v_rst = $this->sql->fetch_assoc($rst)) |
---|
| 77 | { $u_query = |
---|
| 78 | "SELECT count(*) as n" |
---|
| 79 | ." FROM #--download_urls, #--formats" |
---|
| 80 | ." WHERE id_download=".$v_rst["id"] |
---|
| 81 | ." AND #--download_urls.id_format=#--formats.id" |
---|
| 82 | ." AND #--formats.nom='mp3'"; |
---|
| 83 | $u_rst = $this->sql->query($u_query); |
---|
| 84 | if($v_u_rst = $this->sql->fetch_assoc($u_rst)) $n += $v_u_rst["n"]; |
---|
| 85 | $this->sql->free_result($u_rst); |
---|
| 86 | } |
---|
| 87 | $this->sql->free_result($rst); |
---|
| 88 | } |
---|
| 89 | catch(Exception $_e) { $n = false; } |
---|
| 90 | return $n; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | function artiste_download($id) |
---|
| 94 | { $download = array(); |
---|
| 95 | try |
---|
| 96 | { $query = |
---|
| 97 | "SELECT #--downloads.*" |
---|
| 98 | .", #--licences.nom as licence" |
---|
| 99 | .", #--licences.lien as licence_url" |
---|
| 100 | ." FROM #--downloads, #--licences" |
---|
| 101 | ." WHERE #--downloads.id=".$id |
---|
| 102 | ." AND #--downloads.id_licence=#--licences.id"; |
---|
| 103 | $rst = $this->sql->query($query); |
---|
| 104 | if($v_rst = $this->sql->fetch_assoc($rst)) |
---|
| 105 | { $download = $v_rst; |
---|
| 106 | $download["urls"] = array(); |
---|
| 107 | $u_query = |
---|
| 108 | "SELECT #--download_urls.*, #--formats.nom as format" |
---|
| 109 | ." FROM #--download_urls, #--formats" |
---|
| 110 | ." WHERE id_download=".$v_rst["id"] |
---|
| 111 | ." AND #--download_urls.id_format=#--formats.id"; |
---|
| 112 | $u_rst = $this->sql->query($u_query); |
---|
| 113 | while($v_u_rst = $this->sql->fetch_assoc($u_rst)) |
---|
| 114 | { $download["urls"][$v_u_rst["id"]] = $v_u_rst; |
---|
| 115 | if($v_u_rst["format"] === "mp3") $download["mp3_url"] = $v_u_rst["url"]; |
---|
| 116 | } |
---|
| 117 | $this->sql->free_result($u_rst); |
---|
| 118 | } |
---|
| 119 | $this->sql->free_result($rst); |
---|
| 120 | } |
---|
| 121 | catch(Exception $_e) { $download = false; } |
---|
| 122 | return $download; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | function licences() |
---|
| 126 | { $licences = array(); |
---|
| 127 | try |
---|
| 128 | { $query = "SELECT * FROM #--licences"; |
---|
| 129 | $rst = $this->sql->query($query); |
---|
| 130 | while($v_rst = $this->sql->fetch_assoc($rst)) $licences[$v_rst["id"]] = $v_rst; |
---|
| 131 | $this->sql->free_result($rst); |
---|
| 132 | } |
---|
| 133 | catch(Exception $_e) { $licences = false; } |
---|
| 134 | return $licences; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | function formats() |
---|
| 138 | { $formats = array(); |
---|
| 139 | try |
---|
| 140 | { $query = "SELECT * FROM #--formats"; |
---|
| 141 | $rst = $this->sql->query($query); |
---|
| 142 | while($v_rst = $this->sql->fetch_assoc($rst)) $formats[$v_rst["id"]] = $v_rst; |
---|
| 143 | $this->sql->free_result($rst); |
---|
| 144 | } |
---|
| 145 | catch(Exception $_e) { $formats = false; } |
---|
| 146 | return $formats; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | function add_download($id_artiste, $nom, $album, $style, $id_licence, $date_creation, $id_format, $url) |
---|
| 150 | { try |
---|
| 151 | { $query = |
---|
| 152 | "INSERT INTO #--downloads VALUES" |
---|
| 153 | ."(NULL" |
---|
| 154 | .", ".$id_artiste |
---|
| 155 | .", ".$this->eq($album) |
---|
| 156 | .", ".$id_licence |
---|
| 157 | .", ".$this->eq($nom) |
---|
| 158 | .", '".$date_creation."'" |
---|
| 159 | .", ".$this->eq($style) |
---|
| 160 | .", NULL" |
---|
| 161 | .", 0" |
---|
| 162 | .", 1" |
---|
| 163 | .")"; |
---|
| 164 | $this->sql->query($query); |
---|
| 165 | $id_download = $this->sql->insert_id(); |
---|
| 166 | $query = |
---|
| 167 | "INSERT INTO #--download_urls VALUES" |
---|
| 168 | ."(NULL" |
---|
| 169 | .", ".$id_download |
---|
| 170 | .", ".$id_format |
---|
| 171 | .", NULL" |
---|
| 172 | .", ".$this->eq($url) |
---|
| 173 | .", NULL" |
---|
| 174 | .", '".date("Y-m-d")."'" |
---|
| 175 | .", 0" |
---|
| 176 | .")"; |
---|
| 177 | $this->sql->query($query); |
---|
| 178 | } |
---|
| 179 | catch(Exception $_e) { return false; } |
---|
| 180 | return true; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | function set_download($id, $nom, $album, $style, $id_licence, $date_creation) |
---|
| 184 | { try |
---|
| 185 | { $query = |
---|
| 186 | "UPDATE #--downloads SET" |
---|
| 187 | ." nom=".$this->eq($nom) |
---|
| 188 | .", id_album=".$this->eq($album) |
---|
| 189 | .", style=".$this->eq($style) |
---|
| 190 | .", id_licence=".$id_licence |
---|
| 191 | .", date_creation='".$date_creation."'" |
---|
| 192 | ." WHERE id=".$id; |
---|
| 193 | $this->sql->query($query); |
---|
| 194 | } |
---|
| 195 | catch(Exception $_e) { return false; } |
---|
| 196 | return true; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | function del_download($id_download) |
---|
| 200 | { try |
---|
| 201 | { $this->sql->query("DELETE FROM #--downloads WHERE id=".$this->eq($id_download)); |
---|
| 202 | $this->sql->query("DELETE FROM #--download_urls WHERE id_download=".$this->eq($id_download)); |
---|
| 203 | } |
---|
| 204 | catch(Exception $_e) { return false; } |
---|
| 205 | return true; |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | function add_download_url($id_download, $url, $id_format) |
---|
| 209 | { try |
---|
| 210 | { $query = |
---|
| 211 | "INSERT INTO #--download_urls(id_download, id_format, url, date_publication) VALUES" |
---|
| 212 | ."( ".$id_download |
---|
| 213 | .", ".$id_format |
---|
| 214 | .", ".$this->eq($url) |
---|
| 215 | .", '".date("Y-m-d")."'" |
---|
| 216 | .")"; |
---|
| 217 | $this->sql->query($query); |
---|
| 218 | } |
---|
| 219 | catch(Exception $_e) { return false; } |
---|
| 220 | return true; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | function set_download_url($id_download_url, $url, $id_format) |
---|
| 224 | { try |
---|
| 225 | { $query = |
---|
| 226 | "UPDATE #--download_urls SET" |
---|
| 227 | ." url=".$this->eq($url) |
---|
| 228 | .", id_format=".$id_format |
---|
| 229 | ." WHERE id=".$id_download_url; |
---|
| 230 | $this->sql->query($query); |
---|
| 231 | } |
---|
| 232 | catch(Exception $_e) { return false; } |
---|
| 233 | return true; |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | function del_download_url($id_download, $id_download_url) |
---|
| 237 | { if(($download = $this->artiste_download($id_download)) !== false) |
---|
| 238 | { try |
---|
| 239 | { $this->sql->query("DELETE FROM #--download_urls WHERE id=".$this->eq($id_download_url)); |
---|
| 240 | if(count($download["urls"]) <= 1) |
---|
| 241 | { if($this->del_download($id_download)) return 2; |
---|
| 242 | else return false; |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | catch(Exception $_e) { return false; } |
---|
| 246 | } |
---|
| 247 | else return false; |
---|
| 248 | return 1; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | function set_downloads($ordre, $actif) |
---|
| 252 | { try |
---|
| 253 | { foreach($ordre as $id => $_ordre) |
---|
| 254 | { $query = |
---|
| 255 | "UPDATE #--downloads SET" |
---|
| 256 | ." ordre=".$_ordre |
---|
| 257 | .", actif=".($actif[$id] ? 1 : 0) |
---|
| 258 | ." WHERE id=".$id; |
---|
| 259 | $this->sql->query($query); |
---|
| 260 | } |
---|
| 261 | } |
---|
| 262 | catch(Exception $_e) { return false; } |
---|
| 263 | return true; |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | function inc_download_compteur($id_download) |
---|
| 267 | { $url = false; |
---|
| 268 | try |
---|
| 269 | { $sql = "SELECT url FROM #--download_urls WHERE id=".$id_download; |
---|
| 270 | $rst = $this->sql->query($sql); |
---|
| 271 | if($v_rst = $this->sql->fetch_assoc($rst)) $url = $v_rst["url"]; |
---|
| 272 | if($url) |
---|
| 273 | { $sql = |
---|
| 274 | "UPDATE #--download_urls SET compteur=(compteur + 1) WHERE id=".$id_download; |
---|
| 275 | $this->sql->query($sql); |
---|
| 276 | } |
---|
| 277 | } |
---|
| 278 | catch(Exception $_e) { $url = false; } |
---|
| 279 | return $url; |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | ?> |
---|