Location: PHPKode > projects > Top Music module > Top Music 3.0.7/html/modules/topMusic/lib/com/sergids/topmusic/view/GenericView.php
<?php
require_once("modules/topMusic/lib/com/sergids/common/Image.php");
require_once("modules/topMusic/lib/com/sergids/common/File.php");
class GenericView{
	/**
	* Prints a select field in a form with de argument pairs name-value
	* @param $name string name of form field
	* @param $aSelect Array pairs of value (position 0) and name (position 1)
	* @return void
	*/
	function printSelect($name,$aSelect,$value="",$behavior=""){
		echo "<select name=\"".$name."\" ".$behavior.">\n";
		echo "	<option value=\"\">...</option>\n";
		for ($i = 0; $i < sizeof($aSelect); $i++) {
			if($value==$aSelect[$i][0])
				$sel="selected";
			else
				$sel="";
			echo "	<option value=\"".$aSelect[$i][0]."\" ".$sel.">".$aSelect[$i][1]."</option>\n";
		}
		echo "</select>\n";
	}
	function printText($name,$value,$behavior=""){
		echo "<input type=\"text\" name=\"".$name."\" value=\"".$value."\" ".$behavior.">";
	}
	function printHidden($name,$value,$behavior=""){
		echo "<input type=\"hidden\" name=\"".$name."\" value=\"".$value."\" ".$behavior.">";
	}
	function printCheckbox($name,$checked){
		$val="";
		if($checked)
			$val="checked";
		echo "<input type=\"checkbox\" name=\"".$name."\" ".$val.">";
	}
	function getRateCode($num,$module_name,$theme){
     	$num=round($num,1);
     	$decimals=$num-floor($num);
     	//unitats
     	$code="";
     	for($i=0;$i<floor($num);$i++){
     		$code.="<img src=\"modules/".$module_name."/themes/".$theme."/images/star_on.gif\" alt=\"".($i+1)."\" border=\"0\" title=\"".($i+1)."\" border=\"0\">";
     	}
     	//decimals
     	$dec=$decimals*100;
     	if($dec>75){
     		//una estrella m�s
     		$code.="<img src=\"modules/".$module_name."/themes/".$theme."/images/star_on.gif\" alt=\"".($i+$decimals)."\" border=\"0\" title=\"".($i+$decimals)."\">";
     	}elseif($dec<=75 && $dec>=25){
     		//mitja estrella m�s
     		$code.="<img src=\"modules/".$module_name."/themes/".$theme."/images/star_mid.gif\" alt=\"".($i+$decimals)."\" border=\"0\" title=\"".($i+$decimals)."\">";
     	}
     	if($num==0 && $decimals==0){
	     	for($i=0;$i<5;$i++){
	     		$code.="<img src=\"modules/".$module_name."/themes/".$theme."/images/star_off.gif\" alt=\"0\" title=\"0\" border=\"0\">";
	     	}	
     	}
     	return $code;
     }
     function printCustomField($field){
     	switch($field->type){
     		case "image":
     			$code="<a href=\"modules/topMusic/".$field->file_path."/".$field->value."\" target=\"_blank\">";
     			if($thumb=Image::createThumbnail("modules/topMusic/".$field->file_path."/".$field->value,$field->image_width,0))
					$code.="<img src=\"".$thumb."\" border=\"0\">";
				else
					$code.="<img src=\"modules/topMusic/".$field->file_path."/".$field->value."\" width=\"".$field->image_width."\" border=\"0\">";
				$code.="</a>";
				return $code;
			case "file":
				$path="modules/topMusic/".$field->file_path."/".$field->value;
				$encPath=File::encodePath($path);
				$code='<a href="modules/topMusic/getFile.php?path='.$encPath.'" target="_blank">';
     			if($field->file_icon!="")
					$code.="<img src=\"modules/topMusic/".$field->file_icon."\" border=\"0\">";
				else
					$code.="<img src=\"modules/topMusic/images/download.gif\" border=\"0\">";
				$code.="</a>";
				return $code;
			case "link":
				$code="<a href=\"".$field->value."\" target=\"_blank\">".$field->value."</a>";
				return $code;
     		default:
     		case "select":
     		case "text":
     		case "textarea":
     			return $field->value;
     	}
     }
     function generatePlayer($song,$type,$module_name,$config){
     	$tm_theme=$config->theme;
     	$tm_host=$config->base_url;
		if($song->track!=""){
           	if(substr($song->track,-3)=="mp3"){
           		$player="mp3player.swf";
	           	switch($type){
					case "block":
					case "button":
						$width="17";
						$height="20";
						break;
					case "slim":
						$width="320";
						$height="20";
						break;
					default:
						$width="320";
						$height="140";
				}
				$randnum=rand(0,25);
            	$player_html= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8"
width="'.$width.'" height="'.$height.'"
id="topmusic_player">
<param name=movie value="modules/topMusic/themes/sergids/mp3player.swf">
<param name=quality value="high">
<param name=bgcolor value="#FFFFFF">
<param name=allowFullScreen value="false">
<param name=swLiveConnect value="true">
<param name=allowScriptAccess value="sameDomain">
<param name="FlashVars" value="width='.$width.'&height='.$height.'&displaywidth=0&displayheight=0&autostart=false&type=mp3&showfsbutton=false&file=modules/topMusic/getSongTrack.php?idsong='.$song->id.'">

<embed type="application/x-shockwave-flash" 
pluginspage="http://www.macromedia.com/go/getflashplayer" 
width="'.$width.'" height="'.$height.'" 
name="theMediaPlayer"
src="modules/topMusic/themes/sergids/mp3player.swf"
flashvars="width='.$width.'&height='.$height.'&displaywidth=0&displayheight=0&autostart=false&type=mp3&showfsbutton=false&thumbsinplaylist=true&file=modules/topMusic/getSongTrack.php?idsong='.$song->id.'">
</embed>
</object>';
           	}else{
				$width="22";
           		if($iniTitle!="http"){
           			$player_html= '<a href="modules/'.$module_name.'/getSongTrack.php?idsong='.$song->id.'"><img src="modules/'.$module_name.'/themes/'.$tm_theme.'/images/sound.gif" border="0"></a>';
				}else{ 
					$player_html= '<a href="'.$song->track.'"><img src="modules/'.$module_name.'/themes/'.$tm_theme.'/images/sound.gif" border="0"></a>'; 
				} 
			}
			if($tm_fileinfo)
				$player_html.= '&nbsp;&nbsp;<a href="#" onClick="window.open(\'modules/'.$module_name.'/fileinfo.php?filename='.$song->track.'\',\'fileinfo\',\'width=200,height=180\');">File info</a>';
		}else{
			$player_html= '<img src="modules/'.$module_name.'/themes/'.$tm_theme.'/images/sound_off.gif">';
     	}
     	return $player_html;
     }
     function printPlayer($song,$type,$module_name,$config){
     	echo GenericView::generatePlayer($song,$type,$module_name,$config);
     }
 	function printAlbumPlayer($album,$module_name,$tm_BaseURL,$tm_theme){
		$tm_host=$tm_BaseURL;
		$width="400";
		$height="140";
		$player="mp3player.swf";
        echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8"
width="'.$width.'" height="'.$height.'"
id="player">
<param name=movie value="modules/topMusic/themes/sergids/'.$player.'">
<param name=quality value="high">
<param name=bgcolor value="#FFFFFF">
<param name=allowFullScreen value="false">
<param name=swLiveConnect value="true">
<param name=allowScriptAccess value="sameDomain">
<param name="FlashVars" value="width='.$width.'&height='.$height.'&displaywidth=120&autostart=false&showfsbutton=false&thumbsinplaylist=false&allowfullscreen=true&file=modules/topMusic/getAlbumXspf.php?idalbum='.$album->id.'">
<embed type="application/x-shockwave-flash" 
pluginspage="http://www.macromedia.com/go/getflashplayer" 
width="'.$width.'" height="'.$height.'" 
name="player"
src="modules/topMusic/themes/sergids/'.$player.'"
flashvars="width='.$width.'&height='.$height.'&displaywidth=120&autostart=false&showfsbutton=false&thumbsinplaylist=false&allowfullscreen=true&file=modules/topMusic/getAlbumXspf.php?idalbum='.$album->id.'">
</embed>
</object>';

     }
}
?>
Return current item: Top Music module