$playlist = new playlist($dbcon); $playlists = $tracks = ''; $playlist_id = $playlist->get_playlist($get_data['playlist']['title'], $auth_id['id'], 'id'); $pl_item = array('auth_id' => $auth_id['id'], 'title' => $get_data['playlist']['title'], 'description' => $get_data['playlist']['desc'], 'last_update' => mktime()); if (!$playlist_id) { $playlist_id['id'] = $playlist->insert_playlist($pl_item); } else { $playlist->delete_pl_tr($playlist_id['id']); $playlist->update_playlist($playlist_id['id'], $pl_item); } foreach ($get_data['playlist']['tracks'] as $val) { // $track_id = $track->get_track_itunes($val['service'], $val['itunesid'], 'id'); $track_id = $track->get_track_ipod($val['service'], $val['artistName'], $val['genreName'], $val['title'], 'id, orderid'); $track_item = array('service' => $val['service'], 'audio_url' => $val['audioUrl'], 'artist_name' => $val['artistName'], 'genre_name' => $val['genreName'], 'length' => $val['length'], 'image_url' => $val['imageUrl'], 'orderid' => $val['order'], 'release_date' => $val['releaseDate'], 'title' => $val['title'], 'itunesid' => $val['itunesid']); if (!$track_id || empty($track_id)) { $track_id['id'] = $track->insert_track($track_item); } else { $track->update_track($track_id['id'], $track_item); } /* insert/update many-to-many relations between track and playlist tables */ $pl_tr_id = $playlist->get_pl_tr_id($playlist_id['id'], $track_id['id'], 'id'); $pl_tr_item = array('playlist_id' => $playlist_id['id'], 'track_id' => $track_id['id'], 'orderid' => $val['order']); if (!$pl_tr_id or $track_id['orderid'] != $val['order']) { $playlist->insert_pl_tr($pl_tr_item); } else { $playlist->update_pl_tr($pl_tr_id['id'], $pl_tr_item); } } $server_port = $auth->get_active_masters('MAX(port) AS port'); if ($server_port[0]['port'] != null && $auth_id['port'] == null) { $new_port = $server_port[0]['port'] + 1;