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_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';
}
Exemplo n.º 3
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);
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
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']));
}
Exemplo n.º 6
0
function dok_create_song()
{
    global $VARS, $GENRES, $USER, $SONGS_LABELS;
    if (!isset($VARS['name']) || !strlen(trim($VARS['name']))) {
        dok_msg(MSG_ERR_SONG_NO_NAME, 'dok_create_song', 'e');
        return false;
    }
    if (!is_numeric($VARS['album']) || $VARS['album'] < 1) {
        $VARS['album'] = 0;
    }
    $res = mysql_query('select name from ' . dok_tn('album') . ' where id = ' . $VARS['album']);
    if (!mysql_numrows($res)) {
        dok_msg(MSG_ERR_NO_ALBUM_NAME, 'dok_create_song', 'e');
        return false;
    }
    $album_name = mysql_result($res, 0, 'name');
    $_SESSION['song_select_album'] = $VARS['album'];
    if (!is_numeric($VARS['artist']) || $VARS['artist'] < 1) {
        $VARS['artist'] = 0;
    }
    $res = mysql_query('select name from ' . dok_tn('artist') . ' where id = ' . $VARS['artist']);
    if (!mysql_numrows($res)) {
        dok_msg(MSG_ERR_NO_ARTIST_NAME, 'dok_create_song', 'e');
        return false;
    }
    $artist_name = mysql_result($res, 0, 'name');
    $_SESSION['song_select_artist'] = $VARS['artist'];
    $song_name = substr($VARS['name'], 0, 255);
    if (!$VARS['dup_checked']) {
        $res = dok_oquery('select id from ' . dok_tn('song') . ' where name = \'' . addslashes($song_name) . '\'');
        if ($res->numrows()) {
            //dok_msg(MSG_ERR_SONG_DUP_NAME,'dok_create_song','e');
            $VARS['duplicates'] = $res->fetch_col_array('id');
            return 'ask_dup_song';
        }
    }
    $song_name = ucwords($song_name);
    if ($VARS['album_track'] != 'text') {
        $t_res = mysql_query('select max(track) as m from ' . dok_tn('rel_song_album') . ' where album_id = ' . $VARS['album']);
        $VARS['track'] = mysql_result($t_res, 0, 'm') + 1;
        $_SESSION['album_track'] = 'next';
    } else {
        if (!is_numeric($VARS['track']) || $VARS['track'] < 1) {
            dok_msg(MSG_ERR_NO_TRACK, 'dok_create_song', 'e');
            return false;
        }
        $_SESSION['album_track'] = 'text';
    }
    $res = mysql_query('select song_id from ' . dok_tn('rel_song_album') . ' where album_id = ' . $VARS['album'] . ' and track = ' . $VARS['track']);
    if (mysql_numrows($res)) {
        $dup_song_id = mysql_result($res, 0, 'song_id');
        $res = mysql_query('select name from ' . dok_tn('song') . ' where id = ' . $dup_song_id);
        $dup_song_name = mysql_result($res, 0, 'name');
        dok_msg(sprintf(MSG_ERR_SONG_TRACK_DUP, $dup_song_name, $VARS['track']), 'dok_create_song', 'e');
        return false;
    }
    //check comment
    $comment = dok_textarea_2_db($VARS['comment']);
    if (!isset($VARS['release']) || !is_numeric($VARS['release']) || $VARS['release'] < 1901 || $VARS['release'] > 2155) {
        $VARS['release'] = 0;
    }
    $length = dok_str2sec($VARS['length']);
    if ($VARS['genre'] >= sizeof($GENRES)) {
        $genre = 0;
    } else {
        $genre = $VARS['genre'];
        $_SESSION['song_select_genre'] = $genre;
    }
    if ($VARS['label'] && $VARS['label'] > 0 && in_array($VARS['label'], array_keys($SONGS_LABELS)) && strlen($SONGS_LABELS[$VARS['label']]['label'])) {
        $label = $VARS['label'];
    } else {
        $label = 0;
    }
    if (DOK_ENABLE_USER) {
        $creation_uid = $USER->id;
    } else {
        $creation_uid = 0;
    }
    //add
    $res = dok_uquery('insert into ' . dok_tn('song') . ' (name, length, creation, creation_uid, release, comment, genre, label) values (\'' . addslashes($song_name) . '\', ' . $length . ', ' . time() . ',' . $creation_uid . ',' . $VARS['release'] . ',\'' . addslashes($comment) . '\',' . $genre . ', ' . $label . ')');
    if (!$res) {
        echo mysql_error();
        return false;
    }
    $my_id = mysql_insert_id();
    $res = dok_uquery('insert into ' . dok_tn('rel_song_artist') . ' (song_id, artist_id) values (' . $my_id . ',' . $VARS['artist'] . ')');
    if (!$res) {
        echo mysql_error();
        return false;
    }
    $res = dok_uquery('insert into ' . dok_tn('rel_song_album') . ' (song_id, album_id,track ) values (' . $my_id . ',' . $VARS['album'] . ',' . $VARS['track'] . ')');
    if (!$res) {
        echo mysql_error();
        return false;
    }
    $VARS['id'] = $my_id;
    $VARS['nohit'] = 1;
    if (sizeof($VARS['link'])) {
        $links = array_keys(dok_songs_links_array());
        foreach ($VARS['link'] as $key => $val) {
            if (is_numeric($key) && $key > 0 && strlen($val) && in_array($val, $links)) {
                $res = mysql_query('select name from ' . dok_tn('song') . ' where id = ' . $key);
                if (mysql_numrows($res)) {
                    $res = dok_song_link_add($VARS['id'], $key, $val);
                }
            }
        }
    }
    return 'view_song';
}