Location: PHPKode > projects > Top Music module > Top Music 3.0.7/html/modules/topMusic/admin/ajax/charts_ajax.php
<?php
if($_POST['action']!="")
	$_GET['action']=$_POST['action'];
if($_POST['type']!="")
	$_GET['type']=$_POST['type'];
$idchart=$_GET['idchart'];
if($idchart!="" && !is_numeric($idchart))
	die("I'm sorry, SQL injection is not allowed.");
switch($_GET['action']){
	case "savePosition":
		$pos=split(",",$_GET['newPos']);
		if($chartDAO=="")
	   		$chartDAO=new ChartAdminDAO($db,$prefix);
	   	$chartO=$chartDAO->getChart($idchart,$language);
	   	$chartDAO->moveElements($chartO,$pos);
    	$chartO=$chartDAO->getChart($idchart,$language);
		ChartAdminView::printElementsList($chartO);
		echo "<script>mySort=new Sortables( $('SortableList'), {handles: $('SortableList').getElements('.drag')} );</script>";
		break;
	case "loadNewElementForm":
		switch($_GET['type']){
			case "song":
				$artistDAO=new ArtistAdminDAO($db,$prefix);
				$artistList=$artistDAO->getSelectList();
				$artistList=array_merge(array(0=>array(0=>"orphan",1=>"No related artist")),$artistList);
				echo '<form id="newElementForm"><table cellpadding="0" cellspacing="0" border="0">
				<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
				<tr><td>1. Select an artist:</td><td>';
				GenericAdminView::printSelect("newElementArtist",$artistList,"","loadSelect('album','newElementArtist','newElementAlbum','newAlbumDiv',false,'newElementSong','newSongDiv');");
				echo '</td></tr><tr><td>2. Select an album:</td><td><div id="newAlbumDiv">';
				echo '<select id="newElementAlbum" onChange="loadSelect(\'song\',\'newElementAlbum\',\'newElementSong\',\'newSongDiv\',true);">
					<option value="...">...</option>
					<option value="orphan">No related album</option>
				</select></div></td></tr><tr><td>';
				echo '3. Select a song:</td><td>';
				echo '<div id="newSongDiv"><select id="newElementSong">
					<option value="...">...</option>
				</select></div></td></tr>';
				echo '<tr><td>&nbsp;</td><td>&nbsp;</td></tr>';
				echo "<tr><td></td><td><input type=\"hidden\" name=\"type\" value=\"".$_GET['type']."\">";
				echo "<input type=\"hidden\" name=\"action\" value=\"addElement\">";
				echo "<input type=\"button\" name=\"add\" onClick=\"addElement()\" value=\"Add element\">";
				echo "</td></tr></table></form>";
				break;
			case "album":
				$artistDAO=new ArtistAdminDAO($db,$prefix);
				$artistList=$artistDAO->getSelectList();
				$artistList=array_merge(array(0=>array(0=>"orphan",1=>"No related artist")),$artistList);
				echo "<form id=\"newElementForm\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
				<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
				<tr><td>1. Select an artist:</td><td>";
				GenericAdminView::printSelect("newElementArtist",$artistList,"","loadSelect('album','newElementArtist','newElementAlbum');");
				echo "</td></tr><tr><td>2. Select an album:</td><td>";
				echo "<select id=\"newElementAlbum\">
					<option value=\"...\">...</option>
				</select></td></tr>";
				echo "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>";
				echo "<tr><td></td><td><input type=\"hidden\" name=\"type\" value=\"".$_GET['type']."\">";
				echo "<input type=\"hidden\" name=\"action\" value=\"addElement\">";
				echo "<input type=\"button\" name=\"add\" onClick=\"addElement()\" value=\"Add element\">";
				echo "</td></tr></table></form>";
				break;
			case "artist":
				$artistDAO=new ArtistAdminDAO($db,$prefix);
				$artistList=$artistDAO->getSelectList();
				echo "<form id=\"newElementForm\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
				<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
				<tr><td>1. Select an artist:</td><td>";
				GenericAdminView::printSelect("newElementArtist",$artistList,"","");
				echo "</td></tr>";
				echo "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>";
				echo "<tr><td></td><td><input type=\"hidden\" name=\"type\" value=\"".$_GET['type']."\">";
				echo "<input type=\"hidden\" name=\"action\" value=\"addElement\">";
				echo "<input type=\"button\" name=\"add\" onClick=\"addElement()\" value=\"Add element\">";
				echo "</td></tr></table></form>";
				break;
		}
		break;
	
	case "addElement":
		$idchart=$_GET['idchart'];
		$idelement=$_GET['idelement'];
		if(!is_numeric($idelement) || !is_numeric($idchart))
			die("I'm sorry, SQL injection is not allowed.");
		if($chartDAO=="")
	   		$chartDAO=new ChartAdminDAO($db,$prefix);
	   	$chartO=$chartDAO->getChart($idchart,$language);
		$chartDAO->newElement($chartO,$idelement);
		if($error['message']==""){
			$chartO=$chartDAO->getChart($idchart,$language);
		}else{
			echo "Error inserting the new element: ".$error['message'];
		}
		ChartAdminView::printElementsList($chartO);
		echo "<script>mySort=new Sortables( $('SortableList'), {handles: $('SortableList').getElements('.drag')} );</script>";
		break;
	case "delElement":
		$idelement=$_GET['idelement'];
		$pos=$_GET['pos'];
		if(!is_numeric($idelement))
			die("I'm sorry, SQL injection is not allowed.");
		if($chartDAO=="")
	   		$chartDAO=new ChartAdminDAO($db,$prefix);
		$chartDAO->delElement($idchart,$idelement,$pos);
		if($error['message']!=""){
			echo "Error deleting the new element: ".$error['message'];
		}
		$chartO=$chartDAO->getChart($idchart,$language);
		if(count($chartO->elements)>0){
			ChartAdminView::printElementsList($chartO);
			echo "<script>mySort=new Sortables( $('SortableList'), {handles: $('SortableList').getElements('.drag')} );</script>";
		}else
			echo "no elements in chart";
		break;
}
?>
Return current item: Top Music module