function dok_link_song_album($VARS, $update, $theme_path) { if (!is_numeric($VARS['id']) || $VARS['id'] < 1) { $VARS['id'] = 0; } $res = mysql_query('select * from ' . dok_tn('song') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { $t = dok_error_template(MSG_ERR_SONG_NOT_FOUND); return array($t, MSG_TITLE_ADD_SONG_ALBUM); } $song = mysql_fetch_array($res); /** $res = dok_oquery('select distinct(album_id) as aid from '.dok_tn('rel_song_album').' where song_id = '.$song['id']); $current_albums = $res->fetch_col_array('aid'); $where = ''; if ( sizeof($current_albums) ) $where = ' where id not in('.implode(',',$current_albums).')';*/ $where = ''; $res = mysql_query('select id, name from ' . dok_tn('album') . $where . ' order by name'); $a_select = ''; while ($row = mysql_fetch_array($res)) { $a_select .= '<option value="' . $row['id'] . '"'; if ($_SESSION['song_select_album'] == $row['id']) { $a_select .= ' selected'; } $a_select .= '>' . $row['name'] . '</option>'; } $t = new template($theme_path); $t->set_file('page', 'song_album_link.tpl'); $t->set_var(dok_song_format($song)); $t->set_var('ALBUM_SELECT', $a_select); $t->set_var('SONG_ID', $song['id']); return array($t, MSG_TITLE_ADD_SONG_ALBUM); }
function dok_create_album() { global $VARS, $USER; if (!isset($VARS['name'])) { dok_msg(MSG_ERR_NO_ALBUM_NAME, 'dok_create_album', 'e'); return false; } if (!strlen(trim($VARS['name']))) { dok_msg(MSG_ERR_NO_ALBUM_NAME, 'dok_create_album', 'e'); return false; } $album_name = ucwords(substr($VARS['name'], 0, 255)); $res = mysql_query('select id from ' . dok_tn('album') . ' where name = \'' . addslashes($album_name) . '\''); if (mysql_numrows($res)) { dok_msg(sprintf(MSG_ERR_DUP_ALBUM_NAME, $album_name), 'dok_create_album', 'e'); return false; } if (DOK_ENABLE_USER) { $creation_uid = $USER->id; } else { $creation_uid = 0; } //add artist $res = dok_uquery('insert into ' . dok_tn('album') . ' (name,creation,creation_uid) values (\'' . addslashes($album_name) . '\',' . time() . ',' . $creation_uid . ')'); if (!$res) { dok_msg(mysql_error(), 'dok_create_album', 'e'); return false; } $VARS['id'] = mysql_insert_id(); $_SESSION['song_select_album'] = $VARS['id']; return 'view_album'; }
function dok_update_album() { global $VARS; if (!isset($VARS['id']) || !is_numeric($VARS['id']) || $VARS['id'] < 1) { dok_msg(MSG_ERR_ALBUM_NOT_FOUND, 'dok_update_album', 'e'); return false; } if (!isset($VARS['name']) || !strlen(trim($VARS['name']))) { return 'view_album'; } $name = substr(trim($VARS['name']), 0, 255); $res = mysql_query('select * from ' . dok_tn('album') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { dok_msg(MSG_ERR_ALBUM_NOT_FOUND, 'dok_update_album', 'e'); return false; } $artist = mysql_fetch_array($res); if (strtolower($artist['name']) == strtolower($name)) { return 'view_album'; } $res = dok_uquery('update ' . dok_tn('album') . ' set name = \'' . addslashes(ucwords($name)) . '\' where id = ' . $VARS['id']); if ($res) { return 'view_album'; } else { dok_msg(MSG_ERR_DB_UPDATE_FAILED, 'dok_update_album', 'e'); return false; } }
function dok_box_ranked($display_module, $theme_path) { if (DOK_USE_CACHE) { $fname = dok_c_box_filename('ranked', 'ignored'); $cache = dok_c_get($fname); if ($cache) { return $cache; } } $res = mysql_query('select name, id from ' . dok_tn('song') . ' order by hits desc limit 10'); echo mysql_error(); if (!mysql_numrows($res)) { return; } $t = new template($theme_path); $t->set_file('page', 'box_default.tpl'); $t->set_var('BOXTITLE', MSG_TITLE_BOX_RANKED_SONG); $t->set_block('page', 'boxlink', 'boxlinktag'); $t->set_var('boxlinktag', ''); if (!mysql_numrows($res)) { $t->set_var('BOXCONTENT', ''); } while ($row = mysql_fetch_array($res)) { $t->set_var('LINK', $_SERVER['PHP_SELF'] . '?display=view_song&id=' . $row['id']); $t->set_var('LABEL', $row['name']); $t->parse('BOXCONTENT', 'boxlink', 'true'); } $html = $t->parse('out', 'page'); if (DOK_USE_CACHE) { dok_c_write($fname, $html); } return $html; }
function dok_update_user() { global $VARS, $USER; if (!isset($VARS['id']) || !is_numeric($VARS['id']) || $VARS['id'] < 1) { dok_msg(MSG_ERR_USER_NOT_FOUND, 'dok_update_user', 'e'); return false; } $res = mysql_query('select * from ' . dok_tn('user') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { dok_msg(MSG_ERR_USER_NOT_FOUND, 'dok_update_user', 'e'); return false; } $user = mysql_fetch_array($res); if (DOK_ENABLE_USER && !$USER->admin && $USER->id != $user['id']) { dok_msg(MSG_ERR_USER_UPDATE_NOT_ALLOWED, 'dok_update_user', 'e'); return false; } $set = array(); if (isset($VARS['password']) && strlen(trim($VARS['password'])) > 0) { $VARS['password'] = substr($VARS['password'], 0, 255); $set[] = 'password = \'' . md5($VARS['password']) . '\''; } if (!DOK_ENABLE_USER || $USER->admin) { if ($VARS['editor'] != '1') { $VARS['editor'] = 0; } if ($VARS['admin'] != '1') { $VARS['admin'] = 0; } if ($VARS['disabled'] != '1') { $VARS['disabled'] = 0; } if (isset($VARS['name']) && trim($VARS['name']) != $user['name']) { $VARS['name'] = substr($VARS['name'], 0, 255); $res = mysql_query('select id from ' . dok_tn('user') . ' where name = \'' . addslashes($VARS['name']) . '\''); if (!mysql_numrows($res)) { $set[] = 'name = \'' . addslashes($VARS['name']) . '\''; } } if ($VARS['editor'] xor $user['editor']) { $set[] = 'editor = \'' . $VARS['editor'] . '\''; } if ($VARS['admin'] xor $user['admin']) { $set[] = 'admin = \'' . $VARS['admin'] . '\''; } if ($VARS['disabled'] xor $user['disabled']) { $set[] = 'disabled = \'' . $VARS['disabled'] . '\''; } } if (sizeof($set)) { $query = 'update ' . dok_tn('user') . ' set ' . implode(', ', $set) . ' where id = ' . $VARS['id']; $res = dok_uquery($query); if (!$res) { dok_msg(MSG_ERR_DB_UPDATE_FAILED, 'dok_update_user', 'e'); } } return 'view_user'; }
function dok_list_users($VARS, $up, $theme_path) { $t = new template($theme_path); $t->set_file('page', 'user_list.tpl'); $t->set_block('page', 'user', 'user_block'); $t->set_block('page', 'next_page', 'next_page_block'); if (!isset($VARS['alpha'])) { $VARS['alpha'] = '-'; } if (!strlen($VARS['offset']) || $VARS['offset'] < 0) { $VARS['offset'] = '0'; } $VARS['alpha'] = mysql_real_escape_string($VARS['alpha']); $query = 'select id, name, editor, admin, disabled, creation, last_login from ' . dok_tn('user') . ' where substring(name from 1 for 1) >= \'' . $VARS['alpha'] . '\' order by name limit ' . $VARS['offset'] . ', ' . DOK_LIST_EPP; $res = dok_oquery($query); if ($res->numrows()) { //$ids = $res->fetch_col_array('id'); //$n_res = dok_oquery('select album_id, count(*) as c from '.dok_tn('rel_song_album').' where album_id in('.implode(',',$ids).') group by album_id'); //$n_array = $n_res->fetch_col_array('c','album_id'); while ($user = $res->fetch_array()) { if ($user['admin']) { $admin = MSG_YES; } else { $admin = MSG_NO; } if ($user['editor']) { $editor = MSG_YES; } else { $editor = MSG_NO; } if ($user['disabled']) { $disabled = MSG_YES; } else { $disabled = MSG_NO; } if ($user['last_login'] == 0) { $last_login = MSG_USER_NEVER_LOGGED; } else { $last_login = date($THEME_DATE, $user['last_login']); } $t->set_var('USER_LINK', $_SERVER['PHP_SELF'] . '?display=view_user&id=' . $user['id']); $t->set_var(array('USER_NAME' => $user['name'], 'USER_DB_CREATION' => date($THEME_DATE, $user['creation']), 'USER_LAST_LOGIN' => $last_login, 'USER_ADMIN' => $admin, 'USER_EDITOR' => $editor, 'USER_DISABLED' => $disabled)); $t->parse('user_block', 'user', 'true'); } $res = mysql_query('select count(*) as c from ' . dok_tn('user') . ' where substring(name from 1 for 1) >= \'' . $VARS['alpha'] . '\''); $total = mysql_result($res, 0, 'c'); if ($total > $VARS['offset'] + DOK_LIST_EPP) { $t->set_var('NEXT_PAGE_LINK', $_SERVER['PHP_SELF'] . '?display=list_users&alpha=' . $VARS['alpha'] . '&offset=' . ($VARS['offset'] + DOK_LIST_EPP)); $t->parse('next_page_block', 'next_page'); } else { $t->set_var('next_page_block', ''); } } else { $t->set_var('user_block', MSG_NO_USER); $t->set_var('next_page_block', ''); } return array($t, MSG_TITLE_LIST_USER); }
function dok_edit_album($VARS, $update_module, $theme_path) { if (!$VARS['id'] || !is_numeric($VARS['id']) || $VARS['id'] < 1) { $t = dok_error_template(MSG_ERR_ALBUM_NOT_FOUND); return array($t, sprintf(MSG_TITLE_EDIT_ALBUM, MSG_UNKNOWN)); } $res = mysql_query('select * from ' . dok_tn('album') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { $t = dok_error_template(MSG_ERR_ALBUM_NOT_FOUND); return array($t, sprintf(MSG_TITLE_EDIT_ALBUM, MSG_UNKNOWN)); } $row = mysql_fetch_array($res); $t = new template($theme_path); $t->set_file('page', 'album_edit.tpl'); $t->set_var(array('ALBUM_ID' => $row['id'], 'ALBUM_NAME' => $row['name'], 'ALBUM_NAME_TF' => str_replace('"', '"', $row['name']))); return array($t, sprintf(MSG_TITLE_EDIT_ALBUM, $row['name'])); }
function dok_song_track() { global $VARS; //check input if (!isset($VARS['song_id']) || !is_numeric($VARS['song_id']) || $VARS['song_id'] < 1) { dok_msg(MSG_ERR_SONG_NOT_FOUND, 'dok_song_track', 'e'); return false; } $res = mysql_query('select name from ' . dok_tn('song') . ' where id = ' . $VARS['song_id']); if (!mysql_numrows($res)) { dok_msg(MSG_ERR_SONG_NOT_FOUND, 'dok_song_track', 'e'); return false; } $song_name = mysql_result($res, 0, 'name'); if (!isset($VARS['album_id']) || !is_numeric($VARS['album_id']) || $VARS['album_id'] < 1) { dok_msg(MSG_ERR_ALBUM_NOT_FOUND, 'dok_song_track', 'e'); return false; } $res = mysql_query('select name from ' . dok_tn('album') . ' where id = ' . $VARS['album_id']); if (!mysql_numrows($res)) { dok_msg(MSG_ERR_ALBUM_NOT_FOUND, 'dok_song_track', 'e'); return false; } if (!isset($VARS['track']) || !is_numeric($VARS['track']) || $VARS['track'] < 1) { dok_msg(MSG_ERR_NO_TRACK, 'dok_song_track', 'e'); return false; } $res = mysql_query('select song_id from ' . dok_tn('rel_song_album') . ' where album_id = ' . $VARS['album_id'] . ' and track = ' . $VARS['track'] . ' and song_id != ' . $VARS['song_id']); if (mysql_numrows($res)) { dok_msg(sprintf(MSG_ERR_ALBUM_TRACK_ASSIGNED, $VARS['track']), 'dok_song_track', 'e'); return false; } $res = dok_uquery('delete from ' . dok_tn('rel_song_album') . ' where song_id = ' . $VARS['song_id'] . ' and album_id = ' . $VARS['album_id']); if (!$res) { echo mysql_error(); return false; } $res = dok_uquery('insert into ' . dok_tn('rel_song_album') . ' (song_id, album_id, track) values (' . $VARS['song_id'] . ',' . $VARS['album_id'] . ',' . $VARS['track'] . ')'); if (!$res) { echo mysql_error(); return false; } $VARS['id'] = $VARS['album_id']; return 'view_album'; }
function dok_view_album($VARS, $update_module, $tpl_path) { global $THEME_DATE, $ARTIST_SONG_LINKS, $USER; if (!isset($VARS['id']) || !is_numeric($VARS['id']) || $VARS['id'] < 1) { $t = dok_error_template(MSG_ERR_ALBUM_DISPLAY); return array($t, sprintf(MSG_TITLE_DISPLAY_ALBUM, '')); } $res = mysql_query('select name, creation from ' . dok_tn('album') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { $t = dok_error_template(MSG_ERR_ALBUM_DISPLAY); return array($t, sprintf(MSG_TITLE_DISPLAY_ALBUM, '')); } $row = mysql_fetch_assoc($res); $t = new template($tpl_path); $t->set_file('page', 'album_display.tpl'); $t->set_block('page', 'if_albumeditor', 'editor_block'); $t->set_block('page', 'album_songs', 'songs_block'); $t->set_var(array('ALBUM_NAME' => $row['name'], 'ALBUM_DB_CREATION' => date($THEME_DATE, $row['creation']))); if (DOK_ENABLE_USER && !$USER->editor && !$USER->admin) { $t->set_var('editor_block', ''); } else { $t->set_var('ALBUM_EDIT_LINK', $_SERVER['PHP_SELF'] . '?display=edit_album&id=' . $VARS['id']); $t->parse('editor_block', 'if_albumeditor'); } $query = 'select s.id, s.name, s.creation, s.length, s.release, s.comment, r.track from ' . dok_tn('rel_song_album') . ' as r left join ' . dok_tn('song') . ' as s on r.song_id = s.id where r.album_id = ' . $VARS['id'] . ' order by r.track'; $songs = dok_oquery($query); $album_length = 0; if (!$songs->numrows()) { $t->set_var('songs_block', MSG_NO_SONG); } else { $pager_data = array('related' => 'album', 'related_id' => $VARS['id']); while ($song = $songs->fetch_array()) { $song_data = dok_song_format($song, $pager_data); $song_data['SONG_ARTIST'] = preg_replace('/^' . $ARTIST_SONG_LINKS[0] . '/', '', $song_data['SONG_ARTIST']); $t->set_var($song_data); $t->set_var('SONG_TRACK', $song['track']); $t->parse('songs_block', 'album_songs', 'true'); $album_length += $song['length']; } } $t->set_var('ALBUM_LENGTH', dok_sec2str($album_length)); $t->set_var('ALBUM_SONGS', $songs->numrows()); return array($t, sprintf(MSG_TITLE_DISPLAY_ALBUM, $row['name'])); }
function dok_view_user($VARS, $update, $theme_path) { global $USER, $THEME_DATE; if (!isset($VARS['id']) || !is_numeric($VARS['id']) || $VARS['id'] < 1) { $t = dok_error_template(MSG_ERR_USER_DISPLAY); return array($t, sprintf(MSG_TITLE_DISLAY_USER, '')); } $res = mysql_query('select * from ' . dok_tn('user') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { $t = dok_error_template(MSG_ERR_USER_DISPLAY); return array($t, sprintf(MSG_TITLE_DISPLAY_USER, '')); } $user = mysql_fetch_array($res); $t = new template($theme_path); $t->set_file('page', 'user_display.tpl'); $t->set_block('page', 'if_could_edit', 'if_could_edit_block'); if (DOK_ENABLE_USER && ($USER->admin || $USER->id == $user['id']) || !DOK_ENABLE_USER) { $t->parse('if_could_edit_block', 'if_could_edit'); } else { $t->set_var('if_could_edit_block', ''); } if ($user['admin']) { $admin = MSG_YES; } else { $admin = MSG_NO; } if ($user['editor']) { $editor = MSG_YES; } else { $editor = MSG_NO; } if ($user['disabled']) { $disabled = MSG_YES; } else { $disabled = MSG_NO; } if ($user['last_login'] == 0) { $last_login = MSG_USER_NEVER_LOGGED; } else { $last_login = date($THEME_DATE, $user['last_login']); } $t->set_var(array('USER_NAME' => $user['name'], 'USER_DB_CREATION' => date($THEME_DATE, $user['creation']), 'USER_LAST_LOGIN' => $last_login, 'USER_ADMIN' => $admin, 'USER_EDITOR' => $editor, 'USER_DISABLED' => $disabled, 'USER_EDIT_LINK' => $_SERVER['PHP_SELF'] . '?display=edit_user&id=' . $user['id'])); return array($t, sprintf(MSG_TITLE_DISPLAY_USER, $user['name'])); }
function dok_edit_user($VARS, $update_module, $theme_path) { global $USER; if (!$VARS['id'] || !is_numeric($VARS['id']) || $VARS['id'] < 1) { $t = dok_error_template(MSG_ERR_USER_NOT_FOUND); return array($t, sprintf(MSG_TITLE_EDIT_USER, MSG_UNKNOWN)); } $res = mysql_query('select * from ' . dok_tn('user') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { $t = dok_error_template(MSG_ERR_USER_NOT_FOUND); return array($t, sprintf(MSG_TITLE_EDIT_USER, MSG_UNKNOWN)); } $row = mysql_fetch_array($res); if (DOK_ENABLE_USER && (!$USER->admin && $USER->id != $row['id'])) { $t = dok_error_template(MSG_ERR_USER_EDITION_NOT_ALLOWED); return array($t, sprintf(MSG_TITLE_EDIT_USER, MSG_UNKNOWN)); } $t = new template($theme_path); $editor_cb = '<input type="checkbox" name="editor" value="1"'; if ($row['editor']) { $editor_cb .= ' CHECKED'; } $editor_cb .= '>'; $admin_cb = '<input type="checkbox" name="admin" value="1"'; if ($row['admin']) { $admin_cb .= ' CHECKED'; } $admin_cb .= '>'; $disabled_cb = '<input type="checkbox" name="disabled" value="1"'; if ($row['disabled']) { $disabled_cb .= ' CHECKED'; } $disabled_cb .= '>'; $t->set_file('page', 'user_edit.tpl'); $t->set_block('page', 'if_admin', 'if_admin_block'); if (!DOK_ENABLE_USER || $USER->admin) { $t->parse('if_admin_block', 'if_admin'); } else { $t->set_var('if_admin_block', ''); } $t->set_var(array('USER_ID' => $row['id'], 'USER_NAME' => $row['name'], 'USER_NAME_TF' => str_replace('"', '"', $row['name']), 'USER_EDITOR_CB' => $editor_cb, 'USER_DISABLED_CB' => $disabled_cb, 'USER_ADMIN_CB' => $admin_cb)); return array($t, sprintf(MSG_TITLE_EDIT_USER, $row['name'])); }
function dok_unlink_song_link() { global $VARS, $GENRES, $USER; if (!isset($VARS['id']) || !strlen(trim($VARS['id'])) || !is_numeric(trim($VARS['id'])) || trim($VARS['id']) < 1) { dok_msg(MSG_ERR_SONG_NOT_FOUND, 'dok_create_song_link', 'e'); return false; } if (!isset($VARS['other_id']) || !strlen(trim($VARS['other_id'])) || !is_numeric(trim($VARS['other_id'])) || trim($VARS['other_id']) < 1) { dok_msg(MSG_ERR_SONG_NOT_FOUND, 'dok_create_song_link', 'e'); return false; } $options = dok_songs_links_array(); if (!in_array($VARS['link'], array_keys($options))) { dok_msg(MSG_ERR_SONG_NO_LINK_NAME, 'dok_create_song_link', 'e'); return false; } $VARS['other_id'] = trim($VARS['other_id']); $VARS['id'] = trim($VARS['id']); $VARS['nohit'] = 1; $relation = explode('-', $VARS['link']); $query = 'delete from ' . dok_tn('rel_songs') . ' where link = ' . $relation[0] . ' '; if (sizeof($relation)) { if ($relation[1]) { $query .= 'AND song_id1=' . $VARS['other_id'] . ' AND song_id2=' . $VARS['id'] . ' '; } else { $query .= 'AND song_id1=' . $VARS['id'] . ' AND song_id2=' . $VARS['other_id'] . ' '; } } else { if ($VARS['id'] <= $VARS['other_id']) { $query .= 'AND song_id1=' . $VARS['id'] . ' AND song_id2=' . $VARS['other_id'] . ' '; } else { $query .= 'AND song_id1=' . $VARS['other_id'] . ' AND song_id2=' . $VARS['id'] . ' '; } } $res = dok_uquery($query); if ($res) { return 'view_song'; } else { dok_msg(MSG_ERR_DB_UPDATE_FAILED, 'dok_unlink_song_link', 'e'); return false; } }
function dok_create_artist() { global $VARS, $USER; if (!isset($VARS['name'])) { dok_msg(MSG_ERR_NO_ARTIST_NAME, 'dok_create_artist', 'e'); return false; } if (!strlen(trim($VARS['name']))) { dok_msg(MSG_ERR_NO_ARTIST_NAME, 'dok_create_artist', 'e'); return false; } $artist_name = ucwords(substr($VARS['name'], 0, 255)); $res = mysql_query('select id from ' . dok_tn('artist') . ' where name = \'' . addslashes($artist_name) . '\''); if (mysql_numrows($res)) { dok_msg(sprintf(MSG_ERR_DUP_ARTIST_NAME, $artist_name), 'dok_create_artist', 'e'); return false; } //test for soundex if (DOK_USE_SOUNDEX && !$VARS['soundex_checked']) { $query = 'select id, name from ' . dok_tn('artist') . ' where substring(soundex(name) from 2) = substring(soundex(\'' . addslashes($artist_name) . '\') from 2)'; $res = dok_oquery($query); if ($res->numrows()) { $VARS['soundex'] = $res->fetch_col_array('name', 'id'); return 'ask_sound_artist'; } } if (DOK_ENABLE_USER) { $creation_uid = $USER->id; } else { $creation_uid = 0; } //add artist $res = dok_uquery('insert into ' . dok_tn('artist') . ' (name,creation,creation_uid) values (\'' . addslashes($artist_name) . '\',' . time() . ',' . $creation_uid . ')'); if (!$res) { dok_msg(mysql_error(), 'dok_create_artist', 'e'); return false; } $VARS['id'] = mysql_insert_id(); $_SESSION['song_select_artist'] = $VARS['id']; return 'view_artist'; }
function dok_update_song_album_link() { global $VARS; if (!isset($VARS['id']) || !is_numeric($VARS['id']) || $VARS['id'] < 1) { dok_msg(MSG_ERR_SONG_NOT_FOUND_UPDATE, 'dok_update_song_album_link', 'e'); return false; } $res = mysql_query('select * from ' . dok_tn('song') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { dok_msg(MSG_ERR_SONG_NOT_FOUND_UPDATE, 'dok_update_song_album_link', 'e'); return false; } $song = mysql_fetch_array($res); if (!isset($VARS['album']) || !is_numeric($VARS['album']) || $VARS['album'] < 1) { dok_msg(MSG_ERR_ALBUM_NOT_FOUND, 'dok_update_song_album_link', 'e'); return false; } $res = mysql_query('select * from ' . dok_tn('album') . ' where id = ' . $VARS['album']); if (!mysql_numrows($res)) { dok_msg(MSG_ERR_ALBUM_NOT_FOUND, 'dok_update_song_album_link', 'e'); return false; } $album = mysql_fetch_array($res); if (!isset($VARS['track']) || !is_numeric($VARS['track']) || $VARS['track'] < 1) { $VARS['track'] = 1; } $res = mysql_query('select r.song_id, s.name from ' . dok_tn('rel_song_album') . ' as r left join ' . dok_tn('song') . ' as s on r.song_id = s.id where r.album_id = ' . $album['id'] . ' and r.track = ' . $VARS['track']); if (mysql_numrows($res)) { dok_msg(sprintf(MSG_ERR_SONG_TRACK_DUP, mysql_result($res, 0, 'name'), $VARS['track']), 'dok_update_song_album_link', 'e'); return false; } //cool we could update $res = dok_uquery('insert into ' . dok_tn('rel_song_album') . ' (song_id, album_id, track) values (' . $song['id'] . ',' . $album['id'] . ',' . $VARS['track'] . ')'); if ($res) { $VARS['id'] = $album['id']; return 'view_album'; } else { dok_msg(MSG_ERR_DB_UPDATE_FAILED, 'dok_update_song_album_link', 'e'); return false; } }
function login($user, $password) { $query = 'select * from ' . dok_tn('user') . ' where name = \'' . addslashes($user) . '\' and password = \'' . md5($password) . '\' and disabled = \'0\''; //echo $query; $res = mysql_query($query); echo mysql_error(); if (mysql_numrows($res)) { $row = mysql_fetch_array($res); $_SESSION['user_id'] = $row['id']; $_SESSION['user_password'] = $row['password']; $this->name = $row['name']; $this->id = $row['id']; $this->editor = $row['editor']; $this->admin = $row['admin']; $this->lang = $row['lang']; $this->theme = $row['theme']; $this->creation = $row['creation']; $this->last_login = $row['last_login']; } return true; }
function dok_update_song_artist_link() { global $VARS, $ARTIST_SONG_LINKS; if (!isset($VARS['id']) || !is_numeric($VARS['id']) || $VARS['id'] < 1) { dok_msg(MSG_ERR_SONG_NOT_FOUND_UPDATE, 'dok_update_song_artist_link', 'e'); return false; } $res = mysql_query('select * from ' . dok_tn('song') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { dok_msg(MSG_ERR_SONG_NOT_FOUND_UPDATE, 'dok_update_song_artist_link', 'e'); return false; } $song = mysql_fetch_array($res); if (!isset($VARS['artist']) || !is_numeric($VARS['artist']) || $VARS['artist'] < 1) { dok_msg(MSG_ERR_ARTIST_NOT_FOUND, 'dok_update_song_artist_link', 'e'); return false; } $res = mysql_query('select * from ' . dok_tn('artist') . ' where id = ' . $VARS['artist']); if (!mysql_numrows($res)) { dok_msg(MSG_ERR_ARTIST_NOT_FOUND, 'dok_update_song_artist_link', 'e'); return false; } $artist = mysql_fetch_array($res); if (!in_array($VARS['link'], array_keys($ARTIST_SONG_LINKS))) { $VARS['link'] = 0; } //cool we could update $res = dok_uquery('insert into ' . dok_tn('rel_song_artist') . ' (song_id, artist_id, link) values (' . $song['id'] . ',' . $artist['id'] . ',' . $VARS['link'] . ')'); if ($res) { $VARS['nohit'] = 1; if (isset($VARS['back2edit'])) { return 'link_song_artist'; } else { return 'view_song'; } } else { dok_msg(MSG_ERR_DB_UPDATE_FAILED, 'dok_update_song_artist_link', 'e'); return false; } }
function dok_create_song_link() { global $VARS, $GENRES, $USER; if ( !isset($VARS['id']) || !strlen(trim($VARS['id'])) || !is_numeric(trim($VARS['id'])) || trim($VARS['id']) < 1 ) { dok_msg(MSG_ERR_SONG_NOT_FOUND,'dok_create_song_link','e'); return false; } if ( !isset($VARS['other_id']) || !strlen(trim($VARS['other_id'])) || !is_numeric(trim($VARS['other_id'])) || trim($VARS['other_id']) < 1 ) { dok_msg(MSG_ERR_SONG_NOT_FOUND,'dok_create_song_link','e'); return false; } $options = dok_songs_links_array(); if ( !in_array($VARS['link'],array_keys($options)) ) { dok_msg(MSG_ERR_SONG_NO_LINK_NAME,'dok_create_song_link','e'); return false; } $VARS['other_id']=trim($VARS['other_id']); $VARS['id']=trim($VARS['id']); $VARS['nohit']=1; if ( !$VARS['old_link'] || !is_numeric($VARS['old_link']) ) $VARS['old_link'] = 0; $res = mysql_query('select name from '.dok_tn('song').' where id = '.$VARS['id'].' or id = '.$VARS['other_id']); if ( mysql_numrows($res) != 2 ) { dok_msg(MSG_ERR_SONG_NOT_FOUND,'dok_create_song_link','e'); return false; } $ok = dok_song_link_add($VARS['id'],$VARS['other_id'],$VARS['link'],$VARS['old_link']); if ( !$ok ) { echo mysql_error(); return false; } return 'view_song'; }
function dok_unlink_song_album() { global $VARS; if (!isset($VARS['id']) || !is_numeric($VARS['id']) || $VARS['id'] < 1) { dok_msg(MSG_ERR_SONG_NOT_FOUND_UPDATE, 'dok_unlink_song_album', 'e'); return false; } $res = mysql_query('select * from ' . dok_tn('song') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { dok_msg(MSG_ERR_SONG_NOT_FOUND_UPDATE, 'dok_unlink_song_album', 'e'); return false; } $song = mysql_fetch_array($res); if (!isset($VARS['album']) || !is_numeric($VARS['album']) || $VARS['album'] < 1) { dok_msg(MSG_ERR_ALBUM_NOT_FOUND, 'dok_unlink_song_album', 'e'); return false; } $res = mysql_query('select * from ' . dok_tn('album') . ' where id = ' . $VARS['album']); if (!mysql_numrows($res)) { dok_msg(MSG_ERR_ALBUM_NOT_FOUND, 'dok_unlink_song_album', 'e'); return false; } $album = mysql_fetch_array($res); $res = mysql_query('select album_id from ' . dok_tn('rel_song_album') . ' where song_id = ' . $VARS['id'] . ' AND album_id != ' . $album['id']); if (!mysql_numrows($res)) { dok_msg(MSG_ERR_DB_UPDATE_FAILED, 'dok_update_song_album_link', 'e'); return false; } $res = dok_uquery('delete from ' . dok_tn('rel_song_album') . ' where song_id = ' . $song['id'] . ' and album_id = ' . $album['id']); if ($res) { return 'edit_song'; } else { dok_msg(MSG_ERR_DB_UPDATE_FAILED, 'dok_update_song_album_link', 'e'); return false; } }
function dok_create_user() { global $VARS, $USER; if (!isset($VARS['name'])) { dok_msg(MSG_ERR_NO_USER_NAME, 'dok_create_user', 'e'); return false; } $VARS['name'] = substr($VARS['name'], 0, 255); if (!isset($VARS['password']) || !strlen($VARS['password'])) { dok_msg(MSG_ERR_NO_USER_PASSWORD, 'dok_create_user', 'e'); return false; } if ($VARS['password'] != $VARS['password_again']) { dok_msg(MSG_ERR_PASSWORD_MISMATCH, 'dok_create_user', 'e'); return false; } $VARS['password'] = substr($VARS['password'], 0, 255); $res = mysql_query('select id from ' . dok_tn('user') . ' where name = \'' . addslashes($VARS['name']) . '\''); if (mysql_numrows($res)) { dok_msg(sprintf(MSG_ERR_USER_NAME_EXISTS, $VARS['name']), 'dok_create_user', 'e'); return false; } if ($VARS['editor'] != '1') { $VARS['editor'] = 0; } if ($VARS['admin'] != '1') { $VARS['admin'] = 0; } $res = dok_uquery('insert into ' . dok_tn('user') . ' (name, password, editor, admin, creation) values (\'' . addslashes($VARS['name']) . '\', \'' . md5($VARS['password']) . '\', \'' . $VARS['editor'] . '\', \'' . $VARS['admin'] . '\', ' . time() . ')'); if (!$res) { dok_msg(MSG_ERR_DB_UPDATE_FAILED, 'dok_create_user', 'e'); return false; } $VARS['id'] = mysql_insert_id(); return 'view_user'; }
function dok_link_songs($VARS, $update, $theme_path) { if (!is_numeric($VARS['id']) || $VARS['id'] < 1) { $VARS['id'] = 0; } $res = mysql_query('select * from ' . dok_tn('song') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { $t = dok_error_template(MSG_ERR_SONG_NOT_FOUND); return array($t, MSG_TITLE_ADD_SONG_ALBUM); } $song = mysql_fetch_array($res); if (!isset($VARS['alpha'])) { $VARS['alpha'] = ' '; } if (!isset($VARS['alpha'])) { $VARS['alpha'] = 'a'; //could change again later with $letters array } /** $res = dok_oquery('select distinct(album_id) as aid from '.dok_tn('rel_song_album').' where song_id = '.$song['id']); $current_albums = $res->fetch_col_array('aid'); $where = ''; if ( sizeof($current_albums) ) $where = ' where id not in('.implode(',',$current_albums).')';*/ $t = new template($theme_path); $t->set_file('page', 'song_song_link.tpl'); $t->set_block('page', 'alphalink', 'alphalink_block'); $t->set_block('page', 'song', 'song_block'); //make alphalinks $letters = dok_letter_array('song'); if (!sizeof($letters)) { $t->set_var('alphalink_block', ''); } else { if (!isset($VARS['alpha'])) { $VARS['alpha'] = reset($letters); } foreach ($letters as $letter) { $lnk = $_SERVER['PHP_SELF'] . '?display=link_songs&id=' . $VARS['id']; if ($VARS['link']) { $lnk .= '&link=' . urlencode($VARS['link']); } $lnk .= '&alpha=' . urlencode($letter); $t->set_var('ALPHALINK_LINK', $lnk); $t->set_var('ALPHALINK_LETTER', $letter); $t->parse('alphalink_block', 'alphalink', 'true'); } } $where = ' where substring(name from 1 for 1) = \'' . addslashes($VARS['alpha']) . '\' and id != ' . $VARS['id']; $res = mysql_query('select * from ' . dok_tn('song') . $where . ' order by name'); while ($row = mysql_fetch_array($res)) { $t->set_var('SONG_CB', '<input type=radio name="other_id" value="' . $row['id'] . '">'); $t->set_var(dok_song_format($row)); $t->parse('song_block', 'song', 'true'); } $la = dok_songs_links_array(); $options = ''; foreach ($la as $value => $legend) { $options .= '<option value="' . str_replace('"', '"', $value) . '">' . $legend . '</option>' . "\n"; } $t->set_var('RELATION_OPTIONS', $options); $t->set_var(dok_song_format($song)); $t->set_var('ALBUM_SELECT', $a_select); $t->set_var('SONG_ID', $song['id']); return array($t, MSG_TITLE_ADD_SONG_LINK); }
function dok_list_albums($VARS, $up, $theme_path) { $orders = array('hits', 'length'); $t = new template($theme_path); $t->set_file('page', 'album_list.tpl'); $t->set_block('page', 'if_artist', 'artist_block'); $t->set_block('page', 'if_artist_2', 'artist_2_block'); $t->set_block('page', 'album', 'album_block'); $t->set_block('page', 'next_page', 'next_page_block'); if (!isset($VARS['alpha'])) { $VARS['alpha'] = '-'; } if (!strlen($VARS['offset']) || $VARS['offset'] < 0) { $VARS['offset'] = '0'; } $VARS['alpha'] = mysql_real_escape_string($VARS['alpha']); //$query = 'select id, name from '.dok_tn('album').' where substring(name from 1 for 1) >= \''.$VARS['alpha'].'\' order by name limit '.$VARS['offset'].', '.DOK_LIST_EPP; $query = 'select sum(s.length) as length, count(s.id) as c, sum(s.hits) as hits, a.id, a.name from ' . dok_tn('song') . ' as s left join ' . dok_tn('rel_song_album') . ' as r on s.id=r.song_id left join ' . dok_tn('album') . ' as a on r.album_id=a.id '; $where = array(); if (isset($VARS['sort']) && !in_array($VARS['sort'], $orders) || !isset($VARS['sort'])) { unset($VARS['sort']); $where[] = 'substring(a.name from 1 for 1) >= \'' . $VARS['alpha'] . '\' '; } if (isset($VARS['artist']) && is_numeric($VARS['artist']) && $VARS['artist'] > 0) { $res = mysql_query('select * from ' . dok_tn('artist') . ' where id = ' . $VARS['artist']); if (mysql_numrows($res)) { $row = mysql_fetch_assoc($res); $t->set_var('ARTIST_NAME', $row['name']); $t->set_var('ARTIST_ID', $row['id']); $t->parse('artist_block', 'if_artist'); $res = dok_oquery('select distinct(r.album_id) from ' . dok_tn('rel_song_album') . ' as r left join ' . dok_tn('rel_song_artist') . ' as r2 on r.song_id=r2.song_id where r2.artist_id = ' . $VARS['artist']); $al_ids = $res->fetch_col_array('album_id'); if (sizeof($al_ids)) { $where[] = 'a.id in(' . implode(', ', $al_ids) . ')'; } } else { unset($VARS['artist']); $t->set_var('artist_block', ''); } } else { unset($VARS['artist']); $t->set_var('artist_block', ''); } if (sizeof($where)) { $query .= ' where ' . implode(' AND ', $where); } $query .= 'group by r.album_id '; if (isset($VARS['sort'])) { $query .= 'order by ' . $VARS['sort'] . ' desc '; } else { $query .= 'order by a.name '; } $query .= 'limit ' . $VARS['offset'] . ', ' . DOK_LIST_EPP; $res = dok_oquery($query); echo mysql_error(); if ($res->numrows()) { //$ids = $res->fetch_col_array('id'); //$n_res = dok_oquery('select album_id, count(*) as c from '.dok_tn('rel_song_album').' where album_id in('.implode(',',$ids).') group by album_id'); //$n_array = $n_res->fetch_col_array('c','album_id'); while ($row = $res->fetch_array()) { $t->set_var('ALBUM_LINK', $_SERVER['PHP_SELF'] . '?display=view_album&id=' . $row['id']); $t->set_var('ALBUM_NAME', $row['name']); $t->set_var('ALBUM_HITS', $row['hits']); $t->set_var('ALBUM_LENGTH', dok_sec2str($row['length'])); if ($row['c'] > 0) { $t->set_var('ALBUM_SONGS', $row['c']); } else { $t->set_var('ALBUM_SONGS', 0); } $t->parse('album_block', 'album', 'true'); } $t_query = 'select count(*) as c from ' . dok_tn('album') . ' as a'; if (sizeof($where)) { $t_query .= ' where ' . implode(' AND ', $where); } $res = mysql_query($t_query); $total = mysql_result($res, 0, 'c'); if ($total > $VARS['offset'] + DOK_LIST_EPP) { $link = $_SERVER['PHP_SELF'] . '?display=list_albums&alpha=' . $VARS['alpha'] . '&offset=' . ($VARS['offset'] + DOK_LIST_EPP . '&artist=' . $VARS['artist']); if (isset($VARS['sort'])) { $link .= '&sort=' . $VARS['sort']; } $t->set_var('NEXT_PAGE_LINK', $link); $t->parse('next_page_block', 'next_page'); } else { $t->set_var('next_page_block', ''); } } else { $t->set_var('album_block', MSG_NO_ALBUM); $t->set_var('next_page_block', ''); } return array($t, MSG_TITLE_LIST_ALBUM); }
function dok_list_full($VARS, $up, $theme_path) { global $THEME_FULL_LIST_COLUMN; $t = new template($theme_path); $t->set_file('page', 'full_list.tpl'); $t->set_block('page', 'element_letter', 'element_letter_block'); $t->set_block('page', 'element', 'element_block'); $t->set_block('page', 'next_block', 'next_block_block'); $t->set_var('element_letter_block', ''); $t->set_var('next_block_block', ''); if (!isset($VARS['element']) || !in_array($VARS['element'], array('artist', 'song', 'album', 'user'))) { $VARS['element'] = 'song'; } if ($VARS['element'] == 'album') { $msg = MSG_NO_ALBUM; $element_name = MSG_ALBUMS; } elseif ($VARS['element'] == 'artist') { $msg = MSG_NO_ARTIST; $element_name = MSG_ARTISTS; } elseif ($VARS['element'] == 'user') { $msg = MSG_NO_USER; $element_name = MSG_USERS; } else { $msg = MSG_NO_SONG; $element_name = MSG_SONGS; } $t->set_var('LIST_ELEMENT_NAME', $element_name); $where = ''; if (($VARS['element'] == 'album' || $VARS['element'] == 'song') && isset($VARS['artist_id']) && is_numeric($VARS['artist_id']) && $VARS['artist_id'] > 0) { $res = mysql_query('select name from ' . dok_tn('artist') . ' where id = ' . $VARS['artist_id']); if (mysql_numrows($res)) { $row = mysql_fetch_array($res); $t->set_var('ARTIST_NAME', $row['name']); $t->set_var('ARTIST_LINK', $_SERVER['PHP_SELF'] . '?display=view_artist&id=' . $VARS['artist_id']); if ($VARS['element'] == 'song') { $where = 'left join ' . dok_tn('rel_song_artist') . ' as r on a.id=r.song_id where r.artist_id = ' . $VARS['artist_id']; } else { $where = 'left join ' . dok_tn('rel_song_album') . ' as r on a.id=r.album_id left join ' . dok_tn('rel_song_artist') . ' as r2 on r.song_id=r2.song_id where r2.artist_id = ' . $VARS['artist_id'] . ' group by a.id'; } } } else { $t->set_var('ARTIST_NAME', ''); $t->set_var('ARTIST_LINK', $_SERVER['PHP_SELF']); } $query = 'select a.id, a.name, substring(a.name from 1 for 1) as letter from ' . dok_tn($VARS['element']) . ' as a ' . $where . ' order by a.name'; //echo $query.'<BR>'; $res = dok_oquery($query); //echo mysql_error(); if ($res->numrows()) { $letter = false; $count = -1; $div = 1; if ($res->numrows() <= reset($THEME_FULL_LIST_COLUMN)) { $el_per_block = $res->numrows(); $div = 1; } elseif ($res->numrows() >= end($THEME_FULL_LIST_COLUMN)) { $div = key($THEME_FULL_LIST_COLUMN); $el_per_block = ceil($res->numrows() / $div); } else { $ak = array_keys($THEME_FULL_LIST_COLUMN); $i = 1; foreach ($THEME_FULL_LIST_COLUMN as $key => $val) { if ($res->numrows() >= $val && $res->numrows() <= $THEME_FULL_LIST_COLUMN[$ak[$i]]) { $div = $key; $el_per_block = ceil($res->numrows() / $key); break; } $i++; } } $t->set_var('BLOCK_PERCENT', (int) (100 / $div)); //if ( $res->numrows() < $THEME_FULL_LIST_COLUMN[0] && $res->numrows() < $THEME_FULL_LIST_COLUMN[0] //$el_per_block = ceil($res->numrows() /3); while ($row = $res->fetch_array()) { $count++; if ($count && !($count % $el_per_block)) { $t->parse('element_block', 'next_block', 'true'); } if (!$letter || $letter != $row['letter']) { $letter = $row['letter']; $t->set_var('LIST_LETTER', strtoupper($letter)); $t->parse('element_block', 'element_letter', 'true'); } $t->set_var('LIST_LINK', $_SERVER['PHP_SELF'] . '?display=view_' . $VARS['element'] . '&id=' . $row['id']); $t->set_var('LIST_NAME', $row['name']); $t->parse('element_block', 'element', 'true'); } } else { $t->set_var('element_block', $msg); } return array($t, $element_name . MSG_TITLE_LIST_FULL); }
<?php $pager_where = 'where a.id=' . $VARS['pager_related_id']; $pager_query = 'select r.artist_id, r.song_id, a.name as artist, s.name as song from ' . dok_tn('rel_song_artist') . ' as r left join ' . dok_tn('song') . ' as s on r.song_id = s.id left join ' . dok_tn('artist') . ' as a on r.artist_id = a.id ' . $pager_where . ' order by s.name'; $pager_res = dok_oquery($pager_query); if ($pager_res->numrows() < 2) { $t = dok_pager_clean($t); } else { $pager_prev = ''; $pager_next = ''; while ($tmp = $pager_res->fetch_array()) { if ($tmp['song_id'] == $row['id']) { if ($tmp = $pager_res->fetch_array()) { $pager_next = $tmp; } break; } $pager_prev = $tmp; } if ($pager_prev == '' && $pager_next == '') { $t = dok_pager_clean($t); } else { if ($pager_prev == '') { $pager_prev = $pager_res->fetch_last_array(); } if ($pager_next == '') { $pager_next = $pager_res->fetch_first_array(); } $t->set_block('page', 'pager', 'pager_block'); $t->set_var(array('PAGER_PREV_LINK' => $_SERVER['PHP_SELF'] . '?display=view_song&id=' . $pager_prev['song_id'] . '&pager_related=' . $VARS['pager_related'] . '&pager_related_id=' . $VARS['pager_related_id'], 'PAGER_PREV_NAME' => $pager_prev['song'], 'PAGER_NEXT_LINK' => $_SERVER['PHP_SELF'] . '?display=view_song&id=' . $pager_next['song_id'] . '&pager_related=' . $VARS['pager_related'] . '&pager_related_id=' . $VARS['pager_related_id'], 'PAGER_NEXT_NAME' => $pager_next['song'], 'PAGER_RELATED_LINK' => $_SERVER['PHP_SELF'] . '?display=list_songs&artist=' . $pager_next['artist_id'], 'PAGER_RELATED_NAME' => $pager_next['artist'])); $t->parse('pager_block', 'pager');
function dok_link_song_artist($VARS, $update, $theme_path) { global $ARTIST_SONG_LINKS; if (!is_numeric($VARS['id']) || $VARS['id'] < 1) { $VARS['id'] = 0; } $res = mysql_query('select * from ' . dok_tn('song') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { $t = dok_error_template(MSG_ERR_SONG_NOT_FOUND); return array($t, MSG_TITLE_ADD_SONG_ARTIST); } $song = mysql_fetch_array($res); $res = dok_oquery('select distinct(artist_id) as aid from ' . dok_tn('rel_song_artist') . ' where song_id = ' . $song['id']); $current_artists = $res->fetch_col_array('aid'); $where = ''; if (sizeof($current_artists)) { $where = ' where id not in(' . implode(',', $current_artists) . ')'; } $res = mysql_query('select id, name from ' . dok_tn('artist') . $where . ' order by name'); $a_select = ''; if (!DOK_USE_HTML4) { while ($row = mysql_fetch_array($res)) { $a_select .= '<option value="' . $row['id'] . '"'; if ($_SESSION['song_select_artist'] == $row['id']) { $a_select .= ' selected'; } $a_select .= '>' . $row['name'] . '</option>'; } } else { $current_letter = ''; while ($row = mysql_fetch_array($res)) { $c_letter = substr($row['name'], 0, 1); if ($c_letter != $current_letter) { if (strlen($current_letter)) { $a_select .= '</optgroup>'; } $a_select .= '<OPTGROUP label="' . $c_letter . '">'; $current_letter = $c_letter; } $a_select .= '<option value="' . $row['id'] . '"'; if ($_SESSION['song_select_artist'] == $row['id']) { $a_select .= ' selected'; } $a_select .= '>' . $row['name'] . '</option>' . "\n"; } if (strlen($current_letter)) { $a_select .= '</optgroup>'; } } $l_select = ''; foreach ($ARTIST_SONG_LINKS as $link_id => $link_name) { $l_select .= '<option value="' . $link_id . '">' . $link_name . '</option>'; } $t = new template($theme_path); $t->set_file('page', 'song_artist_link.tpl'); $t->set_var(dok_song_format($song)); $t->set_var('ARTIST_SELECT', $a_select); $t->set_var('LINK_SELECT', $l_select); $t->set_var('SONG_ID', $song['id']); return array($t, MSG_TITLE_ADD_SONG_ARTIST); }
function dok_view_song($VARS, $update, $theme_path) { global $THEME_DATE, $USER, $SONGS_LINKS; if (!isset($VARS['id']) || !is_numeric($VARS['id']) || $VARS['id'] < 1) { $t = dok_error_template(MSG_ERR_SONG_DISPLAY); return array($t, sprintf(MSG_TITLE_DISPLAY_SONG, '')); } $res = mysql_query('select * from ' . dok_tn('song') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { $t = dok_error_template(MSG_ERR_SONG_DISPLAY); return array($t, sprintf(MSG_TITLE_DISPLAY_SONG, '')); } $row = mysql_fetch_assoc($res); $fields = array_keys($row); $t = new template($theme_path); $t->set_file('page', 'song_display.tpl'); $t->set_block('page', 'song', 'song_block'); $t->set_block('page', 'relation', 'relation_block'); $t->set_block('page', 'if_relation', 'if_relation_block'); $t->set_block('page', 'if_songeditor', 'songeditor_block'); $t->set_block('page', 'if_label', 'label_block'); if (DOK_ENABLE_USER && !$USER->editor && !$USER->admin) { $t->set_var('songeditor_block', ''); } else { $t->parse('songeditor_block', 'if_songeditor'); $t->set_var('SONG_EDIT_LINK', $_SERVER['PHP_SELF'] . '?display=edit_song&id=' . $row['id']); } $t->set_block('page', 'song_albums', 'albums_block'); $query = 'select a.name, a.creation, a.id, r.track from ' . dok_tn('rel_song_album') . ' as r left join ' . dok_tn('album') . ' as a on r.album_id = a.id where r.song_id = ' . $VARS['id'] . ' order by a.name'; $res = mysql_query($query); if (!mysql_numrows($res)) { $t->set_var('albums_block', MSG_NO_ALBUM); } else { while ($a_row = mysql_fetch_array($res)) { $t->set_var(array('ALBUM_LINK' => $_SERVER['PHP_SELF'] . '?display=view_album&id=' . $a_row['id'], 'ALBUM_NAME' => $a_row['name'], 'ALBUM_TRACK' => $a_row['track'])); $t->parse('albums_block', 'song_albums', 'true'); } } // song relations $rel = 0; $query = 'select '; foreach ($fields as $field) { $query .= ' s1.' . $field . ' as s1' . $field . ', s2.' . $field . ' as s2' . $field . ','; } $query .= 'r.link from ' . dok_tn('rel_songs') . ' as r left join ' . dok_tn('song') . ' as s1 on r.song_id1=s1.id left join ' . dok_tn('song') . ' as s2 on r.song_id2=s2.id where song_id1=' . $row['id'] . ' or song_id2=' . $row['id'] . ' order by link'; //echo $query; $res = mysql_query($query); $link = false; $relations = array(); while ($subrow = mysql_fetch_assoc($res)) { if ($subrow['s1id'] == $row['id']) { if (is_array($SONGS_LINKS[$subrow['link']]) && $SONGS_LINKS[$subrow['link']][0]) { $good_song = 's2'; $good_link = $SONGS_LINKS[$subrow['link']][0]; } else { unset($good_song); unset($good_link); } } else { if (is_array($SONGS_LINKS[$subrow['link']]) && $SONGS_LINKS[$subrow['link']][1]) { $good_song = 's1'; $good_link = $SONGS_LINKS[$subrow['link']][1]; } else { unset($good_song); unset($good_link); } } if (isset($good_song)) { $myrow = array(); foreach ($fields as $field) { $myrow[$field] = $subrow[$good_song . $field]; } $relations[$good_link][] = $myrow; } } $related_ids = array($row['id']); if (sizeof($relations)) { foreach ($relations as $relation => $songs) { $t->set_var('song_block', ''); $t->set_var('SONG_RELATION', $relation); foreach ($songs as $song) { $rel++; $t->set_var(dok_song_format($song)); $t->parse('song_block', 'song', 'true'); $related_ids[] = $song['id']; } $t->parse('relation_block', 'relation', 'true'); } } //same title $res = mysql_query('select * from ' . dok_tn('song') . ' where id not in(' . implode(', ', $related_ids) . ') and name = \'' . mysql_real_escape_string($row['name']) . '\''); if (mysql_numrows($res)) { $t->set_var('song_block', ''); $t->set_var('SONG_RELATION', MSG_SONG_LINK_SAME_TITLE); while ($dup_row = mysql_fetch_array($res)) { $rel++; $t->set_var(dok_song_format($dup_row)); $t->parse('song_block', 'song', 'true'); } $t->parse('relation_block', 'relation', 'true'); } if ($rel) { $t->parse('if_relation_block', 'if_relation'); } else { $t->set_var('if_relation_block', ''); } $t->set_var('SONG_RELATIONS', $rel); $t->set_var(dok_song_format($row)); if ($row['label'] > 0) { $t->parse('label_block', 'if_label'); } else { $t->set_var('label_block', ''); } //pager related if (DOK_ENABLE_PAGER) { global $THEME_PAGER_TYPE; if (isset($VARS['pager_related'])) { if ($VARS['pager_related'] == 'artist') { include_once 'php/pager_song_artist.php'; } elseif ($VARS['pager_related'] == 'album') { include_once 'php/pager_song_album.php'; } else { $t = dok_pager_clean($t); } } else { $t = dok_pager_clean($t); } } else { $t = dok_pager_clean($t); } if (!isset($VARS['nohit'])) { $res = mysql_query('update ' . dok_tn('song') . ' set hits = hits + 1 where id = ' . $VARS['id']); } return array($t, sprintf(MSG_TITLE_DISPLAY_SONG, $row['name'])); }
function dok_search_artist($query) { $return = array(); $sql_query = 'select *, MATCH (name) AGAINST (\'' . $query . '\') as score from ' . dok_tn('artist') . ' as s where MATCH (name) AGAINST (\'' . $query . '\')'; $res = mysql_query($sql_query); while ($row = mysql_fetch_array($res)) { $vars['ARTIST_NAME'] = $row['name']; $vars['ARTIST_LINK'] = $_SERVER['PHP_SELF'] . '?display=view_artist&id=' . $row['id']; $vars['ARTIST_SCORE'] = sprintf('%2f', $row['score']); $return[] = $vars; } return $return; }
function dok_list_artists($VARS, $up, $theme_path) { $orders = array('count', 'length', 'albums'); $t = new template($theme_path); $t->set_file('page', 'artist_list.tpl'); $t->set_block('page', 'artist', 'artist_block'); $t->set_block('page', 'next_page', 'next_page_block'); if (!isset($VARS['alpha'])) { $VARS['alpha'] = '-'; } $VARS['alpha'] = mysql_real_escape_string($VARS['alpha']); if (isset($VARS['sort']) && !in_array($VARS['sort'], $orders)) { unset($VARS['sort']); } if (!strlen($VARS['offset']) || $VARS['offset'] < 0) { $VARS['offset'] = '0'; } $display = array(); // here we do 2 queries: it's better than 1 for mysql if (isset($VARS['sort'])) { $my_display = array(); $query = "select r.artist_id as id, count(distinct r.song_id) as count, sum(s.length) as length, count(distinct al.album_id) as albums from " . dok_tn("rel_song_artist") . ' as r left join ' . dok_tn('song') . ' as s on r.song_id=s.id left join ' . dok_tn('rel_song_album') . ' as al on r.song_id=al.song_id group by r.artist_id order by ' . $VARS['sort'] . ' desc limit ' . $VARS['offset'] . ', ' . DOK_LIST_EPP; //echo $query; $res = dok_oquery($query); while ($row = $res->fetch_array()) { $my_display[$row['id']] = array('id' => $row['id'], 'count' => $row['count'], 'length' => $row['length'], 'albums' => $row['albums']); } if (sizeof($my_display)) { $query = 'select name,id from ' . dok_tn('artist') . ' where id in(' . implode(', ', array_keys($my_display)) . ')'; $res = dok_oquery($query); while ($row = $res->fetch_array()) { $my_display[$row['id']]['name'] = $row['name']; } foreach ($my_display as $one) { $display[] = $one; } } } else { $my_display = array(); $query = 'select name,id from ' . dok_tn('artist') . ' where LEFT(name,1) >= \'' . $VARS['alpha'] . '\' order by name limit ' . $VARS['offset'] . ', ' . DOK_LIST_EPP; $res = dok_oquery($query); while ($row = $res->fetch_array()) { $my_display[$row['id']] = array('name' => $row['name'], 'id' => $row['id']); } if (sizeof($my_display)) { $query = "select r.artist_id as id, count(DISTINCT r.song_id) as count, sum(s.length) as length, count(distinct al.album_id) as albums from " . dok_tn("rel_song_artist") . ' as r left join ' . dok_tn('song') . ' as s on r.song_id=s.id left join ' . dok_tn('rel_song_album') . ' as al on r.song_id=al.song_id where r.artist_id in(' . implode(', ', array_keys($my_display)) . ') group by r.artist_id'; $res = dok_oquery($query); while ($row = $res->fetch_array()) { $my_display[$row['id']]['count'] = $row['count']; $my_display[$row['id']]['length'] = $row['length']; $my_display[$row['id']]['albums'] = $row['albums']; } foreach ($my_display as $one) { $display[] = $one; } } } if (sizeof($display)) { $display_first = $VARS['offset'] + 1; $display_last = $display_first - 1; foreach ($display as $row) { $t->set_var('ARTIST_LINK', $_SERVER['PHP_SELF'] . '?display=view_artist&id=' . $row['id']); $t->set_var('ARTIST_NAME', $row['name']); $t->set_var('ARTIST_SONGS', $row['count']); $t->set_var('ARTIST_ALBUMS', $row['albums']); $t->set_var('ARTIST_LENGTH', dok_sec2str($row['length'])); $t->parse('artist_block', 'artist', 'true'); $display_last++; } if (isset($VARS['sort'])) { $t_query = 'select count(*) as c from ' . dok_tn('rel_song_artist') . ' as r group by r.artist_id'; } else { $t_query = 'select id from ' . dok_tn('artist') . ' where LEFT(name,1) >= \'' . $VARS['alpha'] . '\''; //$t_query='select count(*) as c from '.dok_tn('rel_song_artist').' as r left join '.dok_tn('artist').' as a on r.artist_id = a.id where substring(a.name from 1 for 1) >= \''.$VARS['alpha'].'\' group by r.artist_id'; //echo $t_query; } $res = mysql_query($t_query); $total = mysql_numrows($res); if ($total > $VARS['offset'] + DOK_LIST_EPP) { $t->set_var('NEXT_PAGE_LINK', $_SERVER['PHP_SELF'] . '?display=list_artists&alpha=' . $VARS['alpha'] . '&offset=' . ($VARS['offset'] + DOK_LIST_EPP) . '&sort=' . $VARS['sort']); $t->parse('next_page_block', 'next_page'); } else { $t->set_var('next_page_block', ''); } } else { $t->set_var('artist_block', MSG_NO_ARTIST); $t->set_var('next_page_block', ''); } return array($t, MSG_TITLE_LIST_ARTIST); }
function dok_list_songs($VARS, $up, $theme_path) { $t = new template($theme_path); $t->set_file('page', 'song_list.tpl'); $t->set_block('page', 'song', 'song_block'); $t->set_block('page', 'next_page', 'next_page_block'); $t->set_block('page', 'if_artist', 'if_artist_block'); if (!isset($VARS['alpha'])) { $VARS['alpha'] = '-'; } if (!strlen($VARS['offset']) || $VARS['offset'] < 0) { $VARS['offset'] = '0'; } $VARS['alpha'] = mysql_real_escape_string($VARS['alpha']); if (isset($VARS['artist']) && is_numeric($VARS['artist']) && $VARS['artist'] > 0) { $query = 'select s.* from ' . dok_tn('rel_song_artist') . ' as r left join ' . dok_tn('song') . ' as s on r.song_id = s.id where substring(s.name from 1 for 1) >= \'' . $VARS['alpha'] . '\' and r.artist_id = ' . $VARS['artist'] . ' order by s.name limit ' . $VARS['offset'] . ', ' . DOK_LIST_EPP; $total_query = 'select count(*) as c from ' . dok_tn('rel_song_artist') . ' as r left join ' . dok_tn('song') . ' as s on r.song_id = s.id where substring(s.name from 1 for 1) >= \'' . $VARS['alpha'] . '\' and r.artist_id = ' . $VARS['artist']; $res = mysql_query('select name from ' . dok_tn('artist') . ' where id = ' . $VARS['artist']); if (!mysql_numrows($res)) { $t->set_var('ARTIST_NAME', ''); $t->set_var('ARTIST_LINK', ''); $t->set_var('ARTIST_ID', ''); } else { $t->set_var('ARTIST_NAME', mysql_result($res, 0, 'name')); $t->set_var('ARTIST_LINK', $_SERVER['PHP_SELF'] . '?display=view_artist&id=' . $VARS['artist']); $t->set_var('ARTIST_ID', $VARS['artist']); } $t->parse('if_artist_block', 'if_artist'); $pager_infos = array('related' => 'artist', 'related_id' => $VARS['artist']); } else { $query = 'select * from ' . dok_tn('song') . ' where substring(name from 1 for 1) >= \'' . $VARS['alpha'] . '\' order by name limit ' . $VARS['offset'] . ', ' . DOK_LIST_EPP; $total_query = 'select count(*) as c from ' . dok_tn('song') . ' where substring(name from 1 for 1) >= \'' . $VARS['alpha'] . '\''; $t->set_var('if_artist_block', ''); $t->set_var('ARTIST_ID', ''); $t->set_var('ARTIST_NAME', ''); $t->set_var('ARTIST_LINK', ''); $pager_infos = ''; } $res = dok_oquery($query); if ($res->numrows()) { $ids = $res->fetch_col_array('id'); while ($row = $res->fetch_array()) { $t->set_var(dok_song_format($row, $pager_infos)); $t->parse('song_block', 'song', 'true'); } $res = mysql_query($total_query); $total = mysql_result($res, 0, 'c'); if ($total > $VARS['offset'] + DOK_LIST_EPP) { $lnk = $_SERVER['PHP_SELF'] . '?display=list_songs&alpha=' . $VARS['alpha'] . '&offset=' . ($VARS['offset'] + DOK_LIST_EPP); if ($t->get_var('ARTIST_ID')) { $lnk .= '&artist=' . $t->get_var('ARTIST_ID'); } $t->set_var('NEXT_PAGE_LINK', $lnk); $t->parse('next_page_block', 'next_page'); } else { $t->set_var('next_page_block', ''); } } else { $t->set_var('song_block', MSG_NO_SONG); $t->set_var('next_page_block', ''); } return array($t, MSG_TITLE_LIST_SONG); }
function dok_update_song() { global $VARS, $SONGS_LABELS; if (!isset($VARS['id']) || !is_numeric($VARS['id']) || $VARS['id'] < 1) { dok_msg(MSG_ERR_SONG_NOT_FOUND_UPDATE, 'dok_update_song', 'e'); return false; } $res = mysql_query('select * from ' . dok_tn('song') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { dok_msg(MSG_ERR_SONG_NOT_FOUND_UPDATE, 'dok_update_song', 'e'); return false; } $song = mysql_fetch_array($res); $set = array(); $name = ucwords(trim($VARS['name'])); if (is_string($name) && strlen($name) && $name != $song['name']) { if (!$VARS['dup_checked']) { //check if name is already known $res = dok_oquery('select id from ' . dok_tn('song') . ' where name = \'' . addslashes($name) . '\' and id != ' . $VARS['id']); if ($res->numrows()) { $VARS['duplicates'] = $res->fetch_col_array('id'); return 'ask_dup_song'; } } $set[] = 'name = \'' . addslashes($name) . '\''; } $comment = dok_textarea_2_db($VARS['comment']); if ($comment != $song['comment']) { $set[] = 'comment = \'' . addslashes($VARS['comment']) . '\''; } if (!isset($VARS['release']) || !is_numeric($VARS['release']) || $VARS['release'] < 1901 || $VARS['release'] > 2155) { $VARS['release'] = 0; } if ($VARS['release'] != $song['release']) { $set[] = 'release = ' . $VARS['release']; } $length = 0; if (isset($VARS['length'])) { if (preg_match('/:/', $VARS['length'])) { $test = explode(':', $VARS['length']); if (sizeof($test) > 1) { $sec = 0; if (is_numeric($test[0])) { $sec = $test[0] * 60; } if (is_numeric($test[1])) { $sec += $test[1]; } $length = $sec; } } elseif (is_numeric($VARS['length']) && $VARS['length'] > 0) { $length = $VARS['length']; } } if ($length != $song['length']) { $set[] = 'length = ' . $length; } if (is_numeric($VARS['genre']) && $VARS['genre'] >= 0 && $VARS['genre'] != $song['genre']) { $set[] = 'genre = ' . $VARS['genre']; } if (is_numeric($VARS['label']) && $VARS['label'] != $song['label'] && (in_array($VARS['label'], array_keys($SONGS_LABELS)) && strlen($SONGS_LABELS[$VARS['label']]['label']) || $VARS['label'] == 0)) { $set[] = 'label = ' . $VARS['label']; } // print_r($set); if (sizeof($set)) { $res = dok_uquery('update ' . dok_tn('song') . ' set ' . implode(',', $set) . ' where id = ' . $VARS['id']); } if ($res) { $VARS['nohit'] = 1; return 'view_song'; } else { dok_msg(MSG_ERR_DB_UPDATE_FAILED, 'dok_update_song', 'e'); return false; } }
/** *returns a list of beginning letters of table $table names * *@param string $table name of the db table *@return array array of letters */ function dok_letter_array($table) { $tables = array('user', 'song', 'artist', 'album'); if (!in_array($table, $tables)) { return false; } $res = dok_oquery('select distinct(substring(a.name from 1 for 1)) as letter from ' . dok_tn($table) . ' as a order by letter'); return $res->fetch_col_array('letter'); }