Location: PHPKode > projects > Axis Groupware > musiclib/inc/playlist_functions.inc.php
<?php
function list_playlist_users($result)
{
	global $musiclib;

	echo "<table cellpadding=3 border=0 cellspacing=1>\n";

	echo "<tr>\n";
			
	echo "<th>User<br></th>\n";
	
	echo "</tr>\n";

	while($GLOBALS['phpgw']->db->next_record()) 
	{
		$row = $GLOBALS['phpgw']->db->Record;
				
		
#		print_r($row);
		
		echo "<tr><td><a href=".$GLOBALS['phpgw']->link("/musiclib/playlists.php"
				,"mode=user&uid=".$row['account_id']."&lid=".$row['account_lid'])
			.">".$row['account_lid']."</a></td>";

	}

  echo "</table>\n";
}

function list_playlists($account_id) 
{
	global $musiclib;

	$query = construct_playlists_select(" WHERE owner=".$account_id
									   ." ORDER BY playlist_title");
#	echo $query;
	$result = $GLOBALS['phpgw']->db->query($query,__LINE__,__FILE__);
	$NumberRows = $GLOBALS['phpgw']->db->num_rows();
#	echo "<br> NumberRows: ".$NumberRows;


	if ($NumberRows == "0") 
	{
		echo "<h2>No playlists found</h2>";
		return;
	} 
	else 
	{

		echo "<table cellpadding=3 border=0 cellspacing=1>\n";

		echo "<tr>\n";
				
		echo "<th>Edit Playlist<br></th>\n";
		echo "<th>Listen to Playlist</th>\n";
		
		echo "</tr>\n";
	}

	while($GLOBALS['phpgw']->db->next_record()) 
	{
		$row = $GLOBALS['phpgw']->db->Record;
				
		$playlist_title = $row['playlist_title'];
		$playlist_id = $row['id'];
		
#		print_r($row);
		
		echo "<tr><td><a href=".$GLOBALS['phpgw']->link("/musiclib/playlists.php"
				,"id=".$playlist_id)
			.">$playlist_title</a></td>
						
			<td><a href=".$GLOBALS['phpgw']->link("/musiclib/listen.php"
				,"mode=playlist&id=".$playlist_id).">(Listen to Playlist)</a></td></tr>";

	}

  echo "</table>\n";
}

function list_playlist_contents($playlist_id,$playlist_title)
{
	global $musiclib;
	$count = 1;

	$query = construct_playlists_content_select($playlist_id);

	$result = $GLOBALS['phpgw']->db->query($query,__LINE__,__FILE__);
	$NumberRows = $GLOBALS['phpgw']->db->num_rows();

	if ($NumberRows == "0")	
	{
		echo "<h2>No songs in this playlist!</h2>";
		echo "No point in keeping it, deleting playlist ...";
		delete_playlist($playlist_id);
		echo "Playlist Deleted";
		return;
	} 
	else 
	{
		print_checkall_js();
	
		echo "<FORM name=\"playlisttitle\" action=".$GLOBALS['phpgw']->link("/musiclib/modify_playlist.php","id=".$playlist_id)." method=\"post\">";
	
		echo "<table cellpadding=3 border=0 cellspacing=1 width=95%>\n";

		echo "<tr><td><font size=4><b>\n";

		echo "Playlist Title: ";

		echo "<INPUT name=\"playlist_title\" size=20
	          value=\"".$playlist_title."\" tabindex=\"".$count."\">";

		echo "<BUTTON name=\"mode\" value=\"title\" type=SUBMIT>Change Title</BUTTON></td>";

	    echo "<td align=center colspan=2>
	    	  <a target=\"_blank\" href=".$GLOBALS['phpgw']->link("/musiclib/playlists.php"
			  ,"mode=print&id=".$playlist_id)."><font size=2><b>[Printable View]</b></font></a><br>\n
	    
		      <a href=".$GLOBALS['phpgw']->link("/musiclib/listen.php"
			  ,"mode=playlist&id=".$playlist_id)."><font size=3><b>[Listen To Playlist]</b></font></a>\n";

		echo "</b></font></td></tr>\n";

		echo "</table></form>";
		echo "<FORM name=listform action=".$GLOBALS['phpgw']->link("/musiclib/modify_playlist.php","id=".$playlist_id)." method=\"post\">";

		echo "<table cellpadding=3 border=0 cellspacing=1>\n";
		echo "<tr>\n";

		echo "<th>[Remove Song]</th>\n";
		echo "<th>Play Order</th>";
		echo "<th>Artist / Path<br><sub>[Search by Artist]</sub></th>";
		echo "<th>Album / File<br><sub>[Listen to Album]</sub></th>";
		echo "<th>Song Title / File<br><sub>[Listen to Song]</sub></th>";
		echo "<th>[Move Up/Down]</th>";

		echo "</tr>\n";
	}

	$index=0;
	while($GLOBALS['phpgw']->db->next_record()) 
	{
		$row = $GLOBALS['phpgw']->db->Record;
		
		$id[$index]	 		= $row['id'];
		$play_order[$index] = $row['play_order'];
		$artist[$index] 	= $row['artist_name'];
		$album[$index]		= $row['album_title'];
		$track[$index]		= $row['track'];
		$song_id[$index]	= $row['song_id'];

	  	$GLOBALS['musiclib_query'] = createobject('phpgwapi.db');
		$GLOBALS['musiclib_query']->Database = $GLOBALS['phpgw_info']['server']['db_name'];
		$GLOBALS['musiclib_query']->Host 	 = $GLOBALS['phpgw_info']['server']['db_host'];
		$GLOBALS['musiclib_query']->User 	 = $GLOBALS['phpgw_info']['server']['db_user'];
		$GLOBALS['musiclib_query']->Password = $GLOBALS['phpgw_info']['server']['db_pass'];
		$GLOBALS['musiclib_query']->connect();
		
		$query = "SELECT * FROM ".$musiclib['tables']['songs']." WHERE id=".$row['song_id']; 

    	$GLOBALS['musiclib_query']->query($query,__LINE__,__FILE__);
		$GLOBALS['musiclib_query']->next_record();
        $songs_row = $GLOBALS['musiclib_query']->Record;
        
		$songs_id[$index]	  = $songs_row['id'];
		$songs_artist[$index] = $songs_row['artist_name'];
		$songs_album[$index]  = $songs_row['album_title'];
		$album_id[$index]	  = $songs_row['album_id'];
		$song_title[$index]   = $songs_row['song_title'];
		$artist_id[$index]	  = $songs_row['artist_id'];
		
		$path[$index]   	  = $songs_row['path'];
		$filename[$index]     = $songs_row['filename'];
		$repository[$index]   = $songs_row['repository'];

		$index++;
	}		
	
	for($i=0;$i<$index;$i++) 
	{
		#print_r($row);
		$count++;

		echo "<INPUT name=\"id_array[".($i)."]\" type=\"hidden\" 
	          value=\"".$id[$i]."\">\n";
		
		echo "<tr>\n";

		echo "<td align=center>
			  <INPUT name=\"remove_array[]\" type=\"checkbox\" 
	          value=\"".$id[$i]."\"></td>\n";

		echo "<td align=center>
			  <INPUT name=\"play_order[".($i)."]\" size=3
	          value=\"".$play_order[$i]."\" tabindex=\"".$count."\"></td>\n";


		if (is_numeric($songs_id[$i])) 
		{
			if ($repository[$i] == '2') 
			{
				echo "<td colspan=2 align=center>/ <a href=".$GLOBALS['phpgw']->link("/musiclib/searches.php"
					,"mode=misc&action=doSearch&search=miscpath&searchFor=".urlencode($path[$i]))
					.">$path[$i]</a>";

				if ($path[$i]) 
				{
					 echo " /";
				}
				
				echo "</td>\n"; 
				echo "<td><a href=".$GLOBALS['phpgw']->link("/musiclib/listen.php","mode=misc&id=".$song_id[$i])
					.">$filename[$i]</a></td>\n"; 
			
			} 
			else 
			{
				echo "<td><a href=\"";
				echo $GLOBALS['phpgw']->link("/musiclib/searches.php"
					,"mode=album&action=doSearch&artist=".urlencode($artist[$i])."&search=albumartistid&id=".$artist_id[$i]);
				echo "\">$artist[$i]</a></td>\n";

				echo "<td><a href=".$GLOBALS['phpgw']->link("/musiclib/listen.php"
					,"mode=album&id=".$album_id[$i])
					.">$album[$i]</a></td>\n"; 
	
				echo "<td><a href=".$GLOBALS['phpgw']->link("/musiclib/listen.php"
					,"mode=song&id=".$song_id[$i])
					.">$song_title[$i]</a></td>\n"; 
			}
		} 
		else 
		{
				echo "<td>$artist[$i]</td>\n"; 
				echo "<td>$album[$i]</td>\n"; 
				echo "<td>";
				
				if ($song_table[$i] == '1') 
				{
					echo "Track ".$track[$i]; 
				}
						
				echo " (Not Available)</td>\n"; 
		}
		
		echo "<td>";
		if ($id[$i-1]) 
		{
			echo "<a href=".$GLOBALS['phpgw']->link("/musiclib/modify_playlist.php"
				,"id=".$playlist_id."&mode=order&ids=".$id[$i].":".$id[$i-1]
				."&order=".$play_order[$i].":".$play_order[$i-1])
				.">[Move Up]</a><br>\n"; 
		} 
		if ($id[$i+1]) 
		{
			echo "<a href=".$GLOBALS['phpgw']->link("/musiclib/modify_playlist.php"
				,"id=".$playlist_id."&mode=order&ids=".$id[$i].":".$id[$i+1]
				."&order=".$play_order[$i].":".$play_order[$i+1])
				.">[Move Down]</a><br>\n"; 
		
		}
		echo "</td>";
		
		echo "</tr>\n";
	}
		
	
	echo "<tr><td colspan=2>";
		echo "<a href=\"javascript:check(true,document.listform.elements['remove_array[]'])\">
		<font face=\"Arial, Helvetica, Verdana\" size=\"2\">Check All</font></a>   
		 | <a href=\"javascript:check(false,document.listform.elements['remove_array[]'])\">
		<font face=\"Arial, Helvetica, Verdana\" size=\"2\">Uncheck All</font></a></td></tr>";

		echo "<tr><td colspan=2 valign=bottom align=center><br>
			<BUTTON name=\"mode\" value=\"updateandremove\" type=SUBMIT>Remove Selected<br>& Update Order</BUTTON>";
	
		echo "<td colspan=2 valign=bottom align=left><br></td>";
#			<BUTTON name=\"mode\" value=\"updateandremove\" type=SUBMIT>Update<br>Order</BUTTON>
			
		echo "<td colspan=1 valign=bottom align=center> <br>
		 	<BUTTON name=\"reset\" type=\"RESET\">Reset</BUTTON></td>
			</td>
			<td></td>
			<td colspan=1 valign=bottom align=right><br>";
			
		print_are_you_sure_js();
		
		echo "<BUTTON name=\"mode\" value=\"delete\" type=SUBMIT onClick=\"return Question()\">Delete<br>Playlist</BUTTON>";
	
	echo "</tr></table></form>";

	echo $navText;
}

function playlist_printable_view($playlist_id,$playlist_title) 
{
	global $musiclib;
	$count = 0;

	$query = construct_playlist_song_select($playlist_id);

	$result = $GLOBALS['phpgw']->db->query($query,__LINE__,__FILE__);
	$NumberRows = $GLOBALS['phpgw']->db->num_rows();

	echo "<table cellpadding=3 border=0 cellspacing=1 width=95%>\n";

	echo "<tr><td><font size=4><b>";

	echo $playlist_title;

	echo "</b></font></td></tr>\n";

	echo "</table>\n";

	echo "<table cellpadding=0 border=0 cellspacing=0>\n";

	while($GLOBALS['phpgw']->db->next_record()) 
	{
		$row = $GLOBALS['phpgw']->db->Record;
		
		$artist 	= $row['artist_name'];
		$repository = $row['repository'];
		$song_title = $row['song_title'];
		$path 		= $row['path'];
		$filename 	= $row['filename'];

		#print_r($row);
		$count++;

		echo "<tr align=left>";
		echo "<td align=left width=5%> &nbsp;<font size=1>".$count."&nbsp;</font> </td>";
		
		if ($repository == 2) 
		{
			echo "<td align=left colspan=2 width=95%> &nbsp;<font size=1>".$path."/".$filename."&nbsp;</font> </td>"; 
		} 
		else 
		{
			echo "<td align=left width=48%> &nbsp;<font size=1>".$song_title."</font>&nbsp; </td>"; 
			echo "<td align=left width=47%> &nbsp;<font size=1><i>by</i>&nbsp; ".$artist."</font> </td> ";
		}

		echo "</tr>\n";
	}
	
	echo "</tr></table>";

	echo $navText;
}


function print_playlist_selectbox() 
{
  	$GLOBALS['playlist'] = createobject('phpgwapi.db');
	$GLOBALS['playlist']->Database = $GLOBALS['phpgw_info']['server']['db_name'];
	$GLOBALS['playlist']->Host 	   = $GLOBALS['phpgw_info']['server']['db_host'];
	$GLOBALS['playlist']->User 	   = $GLOBALS['phpgw_info']['server']['db_user'];
	$GLOBALS['playlist']->Password = $GLOBALS['phpgw_info']['server']['db_pass'];
	$GLOBALS['playlist']->connect();

	echo "<SELECT name=\"playlist_id\">\n";

 	$query  = construct_playlists_select(" WHERE owner=".$GLOBALS['phpgw_info']['user']['account_id']
									   ." ORDER BY playlist_title");
	$result = $GLOBALS['playlist']->query($query,__LINE__,__FILE__);

	echo "<OPTION ";
	# echo " selected "
	echo " label=\"mode\" value=\"new\">- New Playlist - </OPTION>\n";

	while ($GLOBALS['playlist']->next_record()) 
	{
		$row = $GLOBALS['playlist']->Record;
		
		$playlist_id = $row['id'];
		$playlist_title = $row['playlist_title'];
		
	    echo "<OPTION ";
		# echo " selected "
	    echo " label=\"".$playlist_title."\" value=\"".$playlist_id."\">".$playlist_title."</OPTION>\n";
    } 

}
?>
Return current item: Axis Groupware