<?php
class ChartAdminView{
function printChartList($chartList) {
echo "<script language=\"javascript\" type=\"text/javascript\">\n";
echo "function delItem(idchart){\n";
echo " if(confirm('"._TOPMUSIC_SURECHART."')){\n";
echo " document.delForm.action='admin.php?op=topmusic&action=delChart&idchart='+idchart;\n";
echo " document.delForm.submit();\n";
echo " }\n";
echo "}\n";
echo "function setDefault(idchart){\n";
echo " document.delForm.action='admin.php?op=topmusic&action=setDefaultChart&idchart='+idchart;\n";
echo " document.delForm.submit();\n";
echo "}\n";
echo "</script>\n";
echo "<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\">\n";
echo "<form name=\"delForm\" method=\"post\" action=\"\">\n";
echo " <tr><td><b>"._TOPMUSIC_TITLE."</b></td><td> </td><td><b>"._TOPMUSIC_TYPE."</b></td><td> </td><td> </td><td> </td><td> </td></tr>\n";
for($i=0;$i<count($chartList);$i++){
$chartO=$chartList[$i];
echo " <tr>\n";
echo " <td>".$chartO->title."</td><td> </td>\n";
echo " <td>".$chartO->type."</td><td> </td>\n";
echo " <td><a href=\"admin.php?op=topmusic&action=editChart&idchart=".$chartO->id."\"><img src=\"images/edit.gif\" border=\"0\" title=\"Edit\"></td>\n";
echo " <td> </td>";
if(!$chartO->default)
echo " <td><a href=\"javascript:setDefault(".$chartO->id.")\"><img src=\"images/key.gif\" border=\"0\" title=\"Set as default\"></a></td>\n";
else
echo " <td><img src=\"images/key_x.gif\" border=\"0\" title=\"Default\"></td>\n";
echo " <td> </td>";
echo " <td><a href=\"javascript:delItem(".$chartO->id.")\"><img src=\"images/delete.gif\" border=\"0\" title=\"Delete\"></a></td>\n";
echo " </tr>\n";
}
echo "</form>\n";
echo "</table>\n";
}
function printChart ($chart){
echo "<script type=\"text/javascript\" src=\"modules/topMusic/admin/js/common.js\"></script>";
echo "<script type=\"text/javascript\">
<!--
if(document.all)
alert('Chart administration is not compatible with Internet Explorer');
//-->
</script>";
echo "<LINK REL=\"StyleSheet\" HREF=\"modules/topMusic/themes/sergids/css/charts.css\" TYPE=\"text/css\">";
echo "<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\">\n";
echo " <tr>\n";
echo " <td> </td>";
echo " <td>Title: <b>$chart->title</b></td>";
echo " <td> </td>";
echo " </tr>\n";
echo " <tr>\n";
echo " <td> </td>";
echo " <td>Description: <b>$chart->description</b></td>";
echo " <td> </td>";
echo " </tr>\n";
echo " <tr>\n";
echo " <td> </td>";
echo " <td>Type: <b>$chart->type</b></td>";
echo " <td> </td>";
echo " </tr>\n";
echo " <tr>\n";
echo " <td> </td>";
echo " <td> </td>";
echo " <td> </td>";
echo " </tr>\n";
echo "</table>\n";
}
function printElements ($chart){
echo "<div id='elementsList'>";
echo "<script language=\"javascript\">\n";
echo "function move(dir,id){\n";
echo " document.location.href='admin.php?op=topmusic&action=moveElement&dir='+dir+'&idchart=$chart->id&idelement='+id;";
echo "}";
echo "var mySort='';\n";
echo "</script>\n";
echo '<script type="text/javascript" src="modules/topMusic/admin/js/mootools.js"></script>';
echo "<table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" width=\"100%\">\n";
echo "<tr>\n";
echo " <td colspan='7'>";
ChartAdminView::printElementsList($chart);
echo "</td></tr></table>\n";
echo "<table width='300'>";
echo "<tr>\n";
echo " <td>";
if(count($chart->elements)<$chart->number_elements)
echo "<a href=\"javascript:newElement()\"><img src=\"images/add.gif\" border=\"0\" title=\"New\"></a>";
echo "</td>\n";
echo " <td><input type=\"button\" name='Save' onClick='savePosition(mySort.serialize())' value=\"Save\"></td>\n";
echo " <td> </td>\n";
echo " <td> </td>\n";
echo " <td> </td>\n";
echo " <td> </td>\n";
echo " <td> </td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</div>";
echo "<div id=\"newElementDiv\"></div>";
echo "<script>
function savePosition(newPos){
setWait('SortableList');
var myAjax = new Ajax('modules/topMusic/admin/index_ajax.php?action=savePosition&newPos='+newPos+'&idchart=".$chart->id."', {method:'get', update:$('SortableList'), evalScripts:'true'});
myAjax.request();
}
function newElement(){
if($('newElementDiv').innerHTML==''){
setWait('newElementDiv');
var myAjax = new Ajax('modules/topMusic/admin/index_ajax.php?action=loadNewElementForm&type=".$chart->type."', {method:'get', update:$('newElementDiv'), evalScripts:'true'});
myAjax.request();
}else{
$('newElementDiv').innerHTML='';
}
}
function addElement(){
setWait('SortableList');
var wSelect;
if(document.getElementById('newElementSong'))
wSelect=document.getElementById('newElementSong');
else if(document.getElementById('newElementAlbum'))
wSelect=document.getElementById('newElementAlbum');
else if(document.getElementById('newElementArtist'))
wSelect=document.getElementById('newElementArtist');
var myAjax = new Ajax('modules/topMusic/admin/index_ajax.php?action=addElement&idchart=".$chart->id."&idelement='+wSelect[wSelect.selectedIndex].value, {method:'get', update:$('SortableList'), evalScripts:'true'});
myAjax.request();
}
function delElement(id,pos){
setWait('SortableList');
var myAjax = new Ajax('modules/topMusic/admin/index_ajax.php?action=delElement&idchart=".$chart->id."&idelement='+id+'&pos='+pos, {method:'get', update:$('SortableList'), evalScripts:'true'});
myAjax.request();
}
</script>";
}
function printElementsList($chart){
echo "<style>#SortableList .drag { cursor: n-resize}</style>";
echo "<div id='SortableList'>";
if(count($chart->elements)>0){
switch($chart->type){
case "song":
foreach($chart->elements as $element){
$song=$element->element;
echo "<div id='".$element->position."'>\n
<table width='100%'><tr>\n";
echo "<td width='60'><b>".$element->position."</b> ";
if( $element->chartsince==0){
echo "<img src=\"modules/topMusic/admin/images/new.gif\" align=\"absmiddle\" title=\"New\">";
}elseif($element->position_ant-$element->position>0){
echo "<img src=\"modules/topMusic/admin/images/up.png\" align=\"absmiddle\" title=\"Up\">";
}elseif($element->position_ant-$element->position<0){
echo "<img src=\"modules/topMusic/admin/images/down.png\" align=\"absmiddle\" title=\"Down\">";
}
$steps=$element->position_ant-$element->position;
if($steps>0)
$steps="+".$steps;
elseif($steps==0)
$steps="=";
echo "<i>".$steps."</i></td>\n";
echo "<td><a href=\"admin.php?op=topmusic&action=editSong&idartist=".$song->idartist."&idalbum=".$song->idalbum."&idsong=".$song->id."\" title=\"Edit song\">".$song->title."</a></td>\n";
echo "<td width='120'><a href=\"admin.php?op=topmusic&action=editAlbum&idartist=".$song->idartist."&idalbum=".$song->idalbum."\" title=\"Edit album\">".$song->albumname."</a></td>\n";
echo "<td width='120'><a href=\"admin.php?op=topmusic&action=editArtist&idartist=".$song->idartist."\" title=\"Edit artist\">".$song->artistname."</a></td>\n";
echo "<td width='40'><a title=\"Since\">".date("Y-m-d",strtotime($element->createdon))."</a></td>\n";
echo "<td width='10' align=\"right\"><a title=\"Days in position\">".$element->positionsince."</a></td>\n";
echo "<td width=\"17\"><a href=\"javascript:delElement(".$song->id.",".$element->position.")\"><img src=\"images/delete.gif\" border=\"0\" title=\"delete\"></a></td>";
echo "<td width=\"17\"><img class=\"drag\" src=\"modules/topMusic/admin/images/n-resize.gif\" border=\"0\" title=\"Drag and drop\"></td>";
echo "</tr></table></div>\n";
}
break;
case "album":
foreach($chart->elements as $element){
$album=$element->element;
echo "<div id='".$element->position."'>\n
<table width='100%'><tr>\n";
echo "<td width='60'><b>".$element->position."</b> ";
if( $element->chartsince==0){
echo "<img src=\"modules/topMusic/admin/images/new.gif\" align=\"absmiddle\" title=\"New\">";
}elseif($element->position_ant-$element->position>0){
echo "<img src=\"modules/topMusic/admin/images/up.png\" align=\"absmiddle\" title=\"Up\">";
}elseif($element->position_ant-$element->position<0){
echo "<img src=\"modules/topMusic/admin/images/down.png\" align=\"absmiddle\" title=\"Down\">";
}
$steps=$element->position_ant-$element->position;
if($steps>0)
$steps="+".$steps;
elseif($steps==0)
$steps="=";
echo "<i>".$steps."</i></td>\n";
echo "<td><a href=\"admin.php?op=topmusic&action=editAlbum&idartist=".$album->idartist."&idalbum=".$album->id."\" title=\"Edit album\">".$album->title."</a></td>\n";
echo "<td width='120'><a href=\"admin.php?op=topmusic&action=editArtist&idartist=".$album->idartist."\" title=\"Edit artist\">".$album->artistname."</a></td>\n";
echo "<td width='40'><a title=\"Since\">".date("Y-m-d",strtotime($element->createdon))."</a></td>\n";
echo "<td width='10' align=\"right\"><a title=\"Days in position\">".$element->positionsince."</a></td>\n";
echo "<td width=\"17\"><a href=\"javascript:delElement(".$album->id.",".$element->position.")\"><img src=\"images/delete.gif\" border=\"0\" title=\"delete\"></a></td>";
echo "<td width=\"17\"><img class=\"drag\" src=\"modules/topMusic/admin/images/n-resize.gif\" border=\"0\" title=\"Drag and drop\"></td>";
echo "</tr></table></div>\n";
}
break;
case "artist":
foreach($chart->elements as $element){
$artist=$element->element;
echo "<div id='".$element->position."'>\n
<table width='100%'><tr>\n";
echo "<td width='60'><b>".$element->position."</b> ";
if( $element->chartsince==0){
echo "<img src=\"modules/topMusic/admin/images/new.gif\" align=\"absmiddle\" title=\"New\">";
}elseif($element->position_ant-$element->position>0){
echo "<img src=\"modules/topMusic/admin/images/up.png\" align=\"absmiddle\" title=\"Up\">";
}elseif($element->position_ant-$element->position<0){
echo "<img src=\"modules/topMusic/admin/images/down.png\" align=\"absmiddle\" title=\"Down\">";
}
$steps=$element->position_ant-$element->position;
if($steps>0)
$steps="+".$steps;
elseif($steps==0)
$steps="=";
echo "<i>".$steps."</i></td>\n";
echo "<td><a href=\"admin.php?op=topmusic&action=editArtist&idartist=".$artist->id."\" title=\"Edit artist\">".$artist->name."</a></td>\n";
echo "<td width='40'><a title=\"Since\">".date("Y-m-d",strtotime($element->createdon))."</a></td>\n";
echo "<td width='10' align=\"right\"><a title=\"Days in position\">".$element->positionsince."</a></td>\n";
echo "<td width=\"17\"><a href=\"javascript:delElement(".$artist->id.",".$element->position.")\"><img src=\"images/delete.gif\" border=\"0\" title=\"delete\"></a></td>";
echo "<td width=\"17\"><img class=\"drag\" src=\"modules/topMusic/admin/images/n-resize.gif\" border=\"0\" title=\"Drag and drop\"></td>";
echo "</tr></table></div>\n";
}
break;
}
}else{
echo "no elements in chart";
}
echo "</div>";
echo "<script type=\"text/javascript\"> window.onload = function() { mySort=new Sortables( $('SortableList'), {handles: $('SortableList').getElements('.drag')} ); } </script>";
//echo "<script>var mySort = new Sortables($('SortableList'));</script>";
}
}
?>