예제 #1
0
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);
}
예제 #2
0
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('"', '&quot;', $row['name'])));
    return array($t, sprintf(MSG_TITLE_EDIT_ALBUM, $row['name']));
}
function dok_ask_sound_artist($VARS, $update, $theme_path)
{
    if (!is_array($VARS['soundex']) || !sizeof($VARS['soundex'])) {
        $t = dok_error_template(MSG_ERR_ARTIST_NOT_FOUND);
        return array($t, MSG_TITLE_SOUNDEX_TEST);
    }
    $t = new template($theme_path);
    $t->set_file('page', 'artist_soundex.tpl');
    $t->set_block('page', 'artists', 'artists_block');
    $t->set_var('NEW_ARTIST_NAME', $VARS['name']);
    $t->set_var('ARTIST_CREATE_FORM', '<form method="post" action="' . $_SERVER['PHP_SELF'] . '"><input type=hidden name="update" value="create_artist"><input type=hidden name="soundex_checked" value="1"><input type=hidden name="name" value="' . str_replace('"', '&quot;', $VARS['name']) . '">');
    foreach ($VARS['soundex'] as $id => $name) {
        $t->set_var('ARTIST_NAME', $name);
        $t->parse('artists_block', 'artists', 'true');
    }
    return array($t, MSG_TITLE_SOUNDEX_TEST);
}
예제 #4
0
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']));
}
예제 #5
0
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']));
}
예제 #6
0
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('"', '&quot;', $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']));
}
예제 #7
0
function dok_new_song($VARS, $update_module, $theme_path)
{
    global $SONGS_LABELS;
    $albums = dok_albums_list();
    if (!sizeof($albums)) {
        $t = dok_error_template(MSG_ERR_NO_ALBUM);
        return array($t, MSG_TITLE_NEW_SONG);
    }
    $artists = dok_artists_list();
    if (!sizeof($artists)) {
        $t = dok_error_template(MSG_ERR_NO_ARTIST);
        return array($t, MSG_TITLE_NEW_SONG);
    }
    $album_select = '';
    foreach ($albums as $id => $vars) {
        $album_select .= '<option value="' . $id . '"';
        if ($_SESSION['song_select_album'] == $id) {
            $album_select .= ' selected';
        }
        $album_select .= '>' . $vars['name'] . '</option>' . "\n";
    }
    $artist_select = '';
    if (!DOK_USE_HTML4) {
        foreach ($artists as $id => $vars) {
            $artist_select .= '<option value="' . $id . '"';
            if ($_SESSION['song_select_artist'] == $id) {
                $artist_select .= ' selected';
            }
            $artist_select .= '>' . $vars['name'] . '</option>' . "\n";
        }
    } else {
        $current_letter = '';
        foreach ($artists as $id => $vars) {
            $c_letter = substr($vars['name'], 0, 1);
            if ($c_letter != $current_letter) {
                if (strlen($current_letter)) {
                    $artist_select .= '</optgroup>';
                }
                $artist_select .= '<OPTGROUP label="' . $c_letter . '">';
                $current_letter = $c_letter;
            }
            $artist_select .= '<option value="' . $id . '"';
            if ($_SESSION['song_select_artist'] == $id) {
                $artist_select .= ' selected';
            }
            $artist_select .= '>' . $vars['name'] . '</option>' . "\n";
        }
        if (strlen($current_letter)) {
            $artist_select .= '</optgroup>';
        }
    }
    if (isset($_SESSION['song_select_genre']) && is_numeric($_SESSION['song_select_genre']) && $_SESSION['song_select_genre'] >= 0) {
        $genre_select = dok_get_genre_select('genre', $_SESSION['song_select_genre']);
    } else {
        $genre_select = dok_get_genre_select('genre');
    }
    $next_radio = '<input type=radio name="album_track" value="next"';
    if ($_SESSION['album_track'] != 'text') {
        $next_radio .= 'checked';
    }
    $next_radio .= '>';
    $text_radio = '<input type=radio name="album_track" value="text"';
    if ($_SESSION['album_track'] == 'text') {
        $text_radio .= 'checked';
    }
    $text_radio .= '>';
    $label_select = '<option value="" SELECTED>' . MSG_LABEL_NONE . '</option>';
    foreach ($SONGS_LABELS as $key => $val) {
        if (is_numeric($key) && $key > 0) {
            $label_select .= '<option value="' . $key . '">' . $val['label'] . '</option>' . "\n";
        }
    }
    $t = new template($theme_path);
    $t->set_file('page', 'song_new.tpl');
    $t->set_var(array('ARTISTS_SELECT' => $artist_select, 'ALBUMS_SELECT' => $album_select, 'GENRES_SELECT' => $genre_select, 'LABELS_SELECT' => $label_select, 'TRACK_NEXT_RADIO' => $next_radio, 'TRACK_TEXT_RADIO' => $text_radio));
    return array($t, MSG_TITLE_NEW_SONG);
}
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);
}
예제 #9
0
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('"', '&quot;', $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);
}
예제 #10
0
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']));
}
예제 #11
0
function dok_ask_dup_song($VARS, $update, $theme_path)
{
    global $SONGS_LABELS;
    if (!is_array($VARS['duplicates']) || !sizeof($VARS['duplicates'])) {
        $t = dok_error_template(MSG_ERR_NO_DUP_SONG);
        return array($t, sprintf(MSG_TITLE_DUP_SONG, ''));
    }
    if (!$VARS['label'] || $VARS['label'] == 0) {
        $new_song_label = MSG_LABEL_NONE;
    } else {
        $new_song_label = $SONGS_LABELS[$VARS['label']]['label'];
    }
    if (!$VARS['track'] || $VARS['track'] == 0) {
        $new_song_track = MSG_ALBUM_NEXT_TRACK;
    } else {
        $new_song_track = $VARS['track'];
    }
    /*
     *find related songs
     *
     */
    //$res = dok_oquery('select * from '.dok_tn('rel_songs').' where song_id1 =
    $t = new template($theme_path);
    $t->set_file('page', 'song_dup.tpl');
    $t->set_block('page', 'duplicate', 'dup_block');
    $query = 'select * from ' . dok_tn('song') . ' where id in(' . implode(',', $VARS['duplicates']) . ')';
    $res = mysql_query($query);
    $relations = dok_songs_links_array();
    while ($row = mysql_fetch_array($res)) {
        $t->set_var(dok_song_format($row));
        $relations_select = '<select name="link[' . $row['id'] . ']"><option value="" SELECTED>' . MSG_RELATION_NONE . '</option>' . "\n";
        foreach ($relations as $key => $val) {
            $relations_select .= '<option value="' . $key . '">' . $val . '</option>' . "\n";
        }
        $relations_select .= '</select>';
        $t->set_var('SONG_RELATION_SELECT', $relations_select);
        $t->parse('dup_block', 'duplicate', 'true');
    }
    if ($update == 'create_song') {
        $res = mysql_query('select name from ' . dok_tn('album') . ' where id = ' . $VARS['album']);
        if (!mysql_numrows($res)) {
            $album = MSG_UNKNOWN;
        } else {
            $album = mysql_result($res, 0, 'name');
        }
        $res = mysql_query('select name from ' . dok_tn('artist') . ' where id = ' . $VARS['artist']);
        if (!mysql_numrows($res)) {
            $artist = MSG_UNKNOWN;
        } else {
            $artist = mysql_result($res, 0, 'name');
        }
        $t->set_var(array('NEW_SONG_NAME' => $VARS['name'], 'NEW_SONG_COMMENT' => dok_textarea_2_db($VARS['comment']), 'NEW_SONG_TRACK' => $new_song_track, 'NEW_SONG_LENGTH' => $VARS['length'], 'NEW_SONG_LABEL' => $new_song_label, 'NEW_SONG_ARTIST' => $artist, 'NEW_SONG_ALBUM' => $album, 'NEW_SONG_GENRE' => dok_genre_name($VARS['genre']), 'NEW_SONG_RELEASE' => dok_year2str($VARS['release'])));
    } else {
        $t->set_var(array('NEW_SONG_NAME' => $VARS['name'], 'NEW_SONG_COMMENT' => dok_textarea_2_db($VARS['comment']), 'NEW_SONG_TRACK' => $new_song_track, 'NEW_SONG_LENGTH' => dok_sec2str($VARS['length']), 'NEW_SONG_GENRE' => dok_genre_name($VARS['genre']), 'NEW_SONG_LABEL' => $new_song_label, 'NEW_SONG_ARTIST' => '', 'NEW_SONG_ALBUM' => '', 'NEW_SONG_RELEASE' => dok_year2str($VARS['release'])));
    }
    $yes_form = '<form method="post" action="' . $_SERVER['PHP_SELF'] . '"><input type=hidden name="update" value="' . $update . '">';
    $yes_form .= '<input type=hidden name="dup_checked" value="1">';
    if ($update == 'update_song') {
        $yes_form .= '<input type=hidden name="id" value="' . $VARS['id'] . '">';
    }
    $yes_form .= '<input type=hidden name="artist" value="' . $VARS['artist'] . '">';
    $yes_form .= '<input type=hidden name="album" value="' . $VARS['album'] . '">';
    $yes_form .= '<input type=hidden name="track" value="' . str_replace('"', '&quot;', $VARS['track']) . '">';
    $yes_form .= '<input type=hidden name="name" value="' . str_replace('"', '&quot;', $VARS['name']) . '">';
    $yes_form .= '<input type=hidden name="length" value="' . str_replace('"', '&quot;', $VARS['length']) . '">';
    $yes_form .= '<input type=hidden name="release" value="' . str_replace('"', '&quot;', $VARS['release']) . '">';
    $yes_form .= '<input type=hidden name="comment" value="' . str_replace('"', '&quot;', $VARS['comment']) . '">';
    $yes_form .= '<input type=hidden name="label" value="' . str_replace('"', '&quot;', $VARS['label']) . '">';
    $yes_form .= '<input type=hidden name="genre" value="' . $VARS['genre'] . '">';
    $t->set_var('SONG_RECORD_FORM', $yes_form);
    return array($t, MSG_TITLE_DUP_SONG);
}
예제 #12
0
function dok_view_artist($VARS, $update_module, $tpl_path)
{
    global $THEME_DATE, $USER;
    if (!isset($VARS['id']) || !is_numeric($VARS['id']) || $VARS['id'] < 1) {
        $t = dok_error_template(MSG_ERR_ARTIST_DISPLAY);
        return array($t, sprintf(MSG_TITLE_DISPLAY_ARTIST, ''));
    }
    $res = mysql_query('select name, creation from ' . dok_tn('artist') . ' where id = ' . $VARS['id']);
    if (!mysql_numrows($res)) {
        $t = dok_error_template(MSG_ERR_ARTIST_DISPLAY);
        return array($t, sprintf(MSG_TITLE_DISPLAY_ARTIST, ''));
    }
    $row = mysql_fetch_assoc($res);
    $t = new template($tpl_path);
    $t->set_file('page', 'artist_display.tpl');
    $t->set_block('page', 'all_albums', 'all_albums_block');
    $t->set_block('page', 'all_songs', 'all_songs_block');
    $t->set_block('page', 'if_artisteditor', 'editor_block');
    $t->set_block('page', 'artist_albums', 'albums_block');
    $t->set_block('page', 'artist_songs', 'songs_block');
    $t->set_block('page', 'related_artists', 'related_artists_block');
    $t->set_var(array('ARTIST_NAME' => $row['name'], 'ARTIST_DB_CREATION' => date($THEME_DATE, $row['creation'])));
    if (DOK_ENABLE_USER && !$USER->editor && !$USER->admin) {
        $t->set_var('editor_block', '');
    } else {
        $t->set_var('ARTIST_EDIT_LINK', $_SERVER['PHP_SELF'] . '?display=edit_artist&id=' . $VARS['id']);
        $t->parse('editor_block', 'if_artisteditor');
    }
    $songs =& dok_rel_song_artist(array(), array($VARS['id']));
    $display_songs = array();
    echo mysql_error();
    if (!$songs->numrows()) {
        $t->set_var('songs_block', MSG_NO_SONG);
        $t->set_var('albums_block', MSG_NO_ALBUM);
        $t->set_var('related_artists_block', MSG_NO_RELATED_ARTIST);
        $t->set_var('all_songs_block', '');
        $t->set_var('all_albums_block', '');
    } else {
        $all_songs = $songs->fetch_col_array('song_id');
        $t->set_var('ARTIST_SONGS', sizeof($all_songs));
        if (sizeof($all_songs) > DOK_SONGS_ON_ARTIST_PAGE) {
            $t->set_var('ALL_SONGS_LINK', $_SERVER['PHP_SELF'] . '?display=list_songs&artist=' . $VARS['id']);
            $t->set_var('ARTIST_REMAINING_SONGS', sizeof($all_songs) - DOK_SONGS_ON_ARTIST_PAGE);
            $t->parse('all_songs_block', 'all_songs');
            $display_songs = array_slice($all_songs, 0, DOK_SONGS_ON_ARTIST_PAGE);
        } else {
            $display_songs = $all_songs;
            $t->set_var('all_songs_block', '');
        }
        $query = 'select * from ' . dok_tn('song') . ' where id in(' . implode(',', $display_songs) . ') order by hits desc,name, creation desc';
        unset($songs);
        $songs = dok_oquery($query);
        $pager_data = array('related' => 'artist', 'related_id' => $VARS['id']);
        while ($song = $songs->fetch_array()) {
            //$sl = dok_sec2min($song['length']);
            $song['ignore_artist'] = $VARS['id'];
            $t->set_var(dok_song_format($song, $pager_data));
            $t->parse('songs_block', 'artist_songs', 'true');
        }
        //$all_songs = $songs->fetch_col_array('id');
        unset($songs);
        $query = 'select distinct(album_id) from ' . dok_tn('rel_song_album') . ' where song_id in(' . implode(',', $all_songs) . ')';
        $albums = dok_oquery($query);
        $t->set_var('ARTIST_ALBUMS', $albums->numrows());
        if (!$albums->numrows()) {
            $t->set_var('albums_block', MSG_NO_ALBUM);
            $t->set_var('all_albums_block', '');
        } else {
            $albums_display = array();
            $albums_id = $albums->fetch_col_array('album_id');
            unset($albums);
            if (sizeof($albums_id) > DOK_ALBUMS_ON_ARTIST_PAGE) {
                $albums_display = array_slice($albums_id, 0, DOK_ALBUMS_ON_ARTIST_PAGE);
                $t->set_var('ALL_ALBUMS_LINK', $_SERVER['PHP_SELF'] . '?display=list_albums&artist=' . $VARS['id']);
                $t->set_var('ARTIST_REMAINING_ALBUMS', sizeof($albums_id) - DOK_ALBUMS_ON_ARTIST_PAGE);
                $t->parse('all_albums_block', 'all_albums');
            } else {
                $albums_display = $albums_id;
                $t->set_var('all_albums_block', '');
            }
            $albums = dok_oquery('select a.id, a.name, a.creation, count(s.id) as count, sum(s.length) as length from ' . dok_tn('album') . ' as a left join ' . dok_tn('rel_song_album') . ' as r on a.id=r.album_id left join ' . dok_tn('song') . ' as s on r.song_id=s.id where a.id in (' . implode(',', $albums_display) . ') group by r.album_id order by a.name');
            while ($album = $albums->fetch_array()) {
                $t->set_var(array('ALBUM_LINK' => $_SERVER['PHP_SELF'] . '?display=view_album&id=' . $album['id'], 'ALBUM_NAME' => $album['name'], 'ALBUM_LENGTH' => dok_sec2str($album['length']), 'ALBUM_SONGS' => $album['count'], 'ALBUM_DB_CREATION' => date($THEME_DATE, $album['creation'])));
                $t->parse('albums_block', 'artist_albums', 'true');
            }
        }
        $query = 'select a.name, a.id, 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 r.song_id in(' . implode(',', $all_songs) . ') and artist_id != ' . $VARS['id'] . ' group by r.artist_id order by c desc limit 7';
        //echo $query;
        $res = mysql_query($query);
        if (!mysql_numrows($res)) {
            $t->set_var('related_artists_block', MSG_NO_RELATED_ARTIST);
        } else {
            while ($row = mysql_fetch_array($res)) {
                $t->set_var(array('RELATED_ARTIST_LINK' => $_SERVER['PHP_SELF'] . '?display=view_artist&id=' . $row['id'], 'RELATED_ARTIST_NAME' => $row['name']));
                $t->parse('related_artists_block', 'related_artists', 'true');
            }
        }
    }
    return array($t, sprintf(MSG_TITLE_DISPLAY_ARTIST, $row['name']));
}
예제 #13
0
function dok_edit_song($VARS, $update_module, $theme_path)
{
    global $SONGS_LINKS, $SONGS_LABELS;
    if (!$VARS['id'] || !is_numeric($VARS['id']) || $VARS['id'] < 1) {
        $t = dok_error_template(MSG_ERR_SONG_NOT_FOUND);
        return array($t, sprintf(MSG_TITLE_EDIT_SONG, MSG_UNKNOWN));
    }
    $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, sprintf(MSG_TITLE_EDIT_SONG, MSG_UNKNOWN));
    }
    $row = mysql_fetch_assoc($res);
    if (!$row['label']) {
        $row['label'] = 0;
    }
    $label_select = '<option value="0"';
    if ($row['label'] == 0) {
        $label_select .= ' SELECTED';
    }
    $label_select .= '>' . MSG_LABEL_NONE . '</option>';
    foreach ($SONGS_LABELS as $key => $val) {
        $label_select .= '<option value="' . $key . '"';
        if ($row['label'] == $key) {
            $label_select .= ' SELECTED';
        }
        $label_select .= '>' . $val['label'] . '</option>';
    }
    $t = new template($theme_path);
    $t->set_file('page', 'song_edit.tpl');
    $main_song_data = dok_song_format($row);
    $main_song_data['SONG_ID'] = $VARS['id'];
    $t->set_var('SONG_NAME_TF', str_replace('"', '&quot;', $row['name']));
    $t->set_var('SONG_LENGTH_TF', str_replace('"', '&quot;', $row['length']));
    $t->set_var('SONG_RELEASE_TF', str_replace('"', '&quot;', $row['release']));
    $t->set_var('SONG_LABELS_SELECT', $label_select);
    $t->set_var('SONG_COMMENT_TF', dok_db_2_textarea($row['comment']));
    $t->set_var('SONG_GENRE_SELECT', dok_get_genre_select('genre', $row['genre']));
    $t->set_block('page', 'artist_remove', 'artist_remove_block');
    $t->set_block('page', 'artist', 'artist_block');
    $t->set_block('page', 'relation', 'relation_block');
    $res = mysql_query('select a.name, a.id from ' . dok_tn('rel_song_artist') . ' as r left join ' . dok_tn('artist') . ' as a on r.artist_id = a.id where r.song_id = ' . $VARS['id']);
    if (!mysql_numrows($res)) {
        $t->set_var('artist_block', '');
    } elseif (mysql_numrows($res) == 1) {
        $a_row = mysql_fetch_array($res);
        $t->set_var('ARTIST_NAME', $a_row['name']);
        $t->parse('artist_block', 'artist');
        $t->set_var('artist_remove_block', '');
    } else {
        while ($a_row = mysql_fetch_array($res)) {
            $t->set_var('ARTIST_REMOVE_LINK', $_SERVER['PHP_SELF'] . '?update=unlink_song_artist&artist=' . $a_row['id'] . '&id=' . $row['id'] . '&nohit=1');
            $t->parse('artist_remove_block', 'artist_remove');
            $t->set_var('ARTIST_NAME', $a_row['name']);
            $t->parse('artist_block', 'artist', 'true');
        }
    }
    $t->set_var('ARTIST_ADD_LINK', $_SERVER['PHP_SELF'] . '?display=link_song_artist&id=' . $row['id']);
    $t->set_block('page', 'album_remove', 'album_remove_block');
    $t->set_block('page', 'album', 'album_block');
    $res = mysql_query('select a.name, 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']);
    if (!mysql_numrows($res)) {
        $t->set_var('album_block', '');
    } elseif (mysql_numrows($res) == 1) {
        $a_row = mysql_fetch_array($res);
        $t->set_var('ALBUM_NAME', $a_row['name']);
        $t->set_var('ALBUM_TRACK_FORM', '<form method=post action="' . $_SERVER['PHP_SELF'] . '"><input type=hidden name=update value="song_track"><input type="hidden" name="album_id" value="' . $a_row['id'] . '"><input type="hidden" name="song_id" value="' . $row['id'] . '">');
        $t->set_var('ALBUM_TRACK', $a_row['track']);
        $t->parse('album_block', 'album');
        $t->set_var('album_remove_block', '');
    } else {
        while ($a_row = mysql_fetch_array($res)) {
            //echo "parsing ".$a_row['name'].' ( '.$a_row['id'].' )';
            $t->set_var('ALBUM_REMOVE_LINK', $_SERVER['PHP_SELF'] . '?update=unlink_song_album&album=' . $a_row['id'] . '&id=' . $row['id']);
            $t->parse('album_remove_block', 'album_remove');
            $t->set_var('ALBUM_NAME', $a_row['name']);
            $t->set_var('ALBUM_TRACK_FORM', '<form method=post action="' . $_SERVER['PHP_SELF'] . '"><input type=hidden name=update value="song_track"><input type="hidden" name="album_id" value="' . $a_row['id'] . '"><input type="hidden" name="song_id" value="' . $row['id'] . '">');
            $t->set_var('ALBUM_TRACK', $a_row['track']);
            $t->parse('album_block', 'album', 'true');
        }
    }
    $t->set_var('ALBUM_ADD_LINK', $_SERVER['PHP_SELF'] . '?display=link_song_album&id=' . $row['id']);
    $fields = array_keys($row);
    $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 = $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 = $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;
        }
    }
    if (sizeof($relations)) {
        $link_array = dok_songs_links_array();
        foreach ($relations as $selected => $songs) {
            foreach ($songs as $other_song) {
                //print_r($other_song);
                $t->set_var('RELATION_FORM', '<form method=post action="' . $_SERVER['PHP_SELF'] . '"><input type=hidden name=update value="create_song_link"><input type="hidden" name="other_id" value="' . $other_song['id'] . '"><input type="hidden" name="id" value="' . $row['id'] . '"><input type="hidden" name="old_link" value="' . preg_replace('/-.*$/', '', $selected) . '">');
                $sel = '';
                foreach ($link_array as $key => $val) {
                    $sel .= '<option value="' . $key . '"';
                    if ($key == $selected || $key == preg_replace('/-.*$/', '', $selected)) {
                        $sel .= ' SELECTED';
                    }
                    $sel .= '>' . $val . '</option>' . "\n";
                }
                $t->set_var('RELATION_OPTIONS', $sel);
                $t->set_var('RELATION_REMOVE_LINK', $_SERVER['PHP_SELF'] . '?update=unlink_song_link&link=' . $selected . '&id=' . $row['id'] . '&other_id=' . $other_song['id']);
                $al = $SONGS_LINKS[preg_replace('/-.*$/', '', $selected)];
                if (preg_replace('/^[^-]+-/', '', $selected) == 1) {
                    $t->set_var('RELATION_NAME', $al[1]);
                } else {
                    $t->set_var('RELATION_NAME', $al[0]);
                }
                $t->set_var(dok_song_format($other_song));
                $t->parse('relation_block', 'relation', 'true');
            }
        }
    } else {
        $t->set_var('relation_block', '');
    }
    $t->set_var('RELATION_ADD_LINK', $_SERVER['PHP_SELF'] . '?display=link_songs&id=' . $row['id'] . '&alpha=a');
    $t->set_var($main_song_data);
    return array($t, sprintf(MSG_TITLE_EDIT_SONG, $row['name']));
}