Location: PHPKode > projects > php movie db > old/index.php
<?
	if (!eregi("modules.php", $PHP_SELF)) {
    die ("You can't access this file directly...");
	}
	
	$module_name = basename(dirname(__FILE__));
	get_lang($module_name);
	require_once("modules/$module_name/film_config.php");
	include("header.php");
	echo "<link href=\"style/scheda_film.css\" rel=\"stylesheet\" type=\"text/css\">";
	title("$sitename: "._MODULE_HEADER."");
	
	//ricavo Elenco delle categorie
	$testo="select * from ".$prefix."_film_categorie";
	$res_cat=sql_query($testo,$dbi);
	$num_cat=sql_num_rows($res_cat);
	
	
	//********************************************************************
	//UPLOAD immagini Per il Film
	//********************************************************************
	if (($upload=='yes')and($id_film>0)and(is_admin($admin)))
	{
		$testo="select * from ".$prefix."_film where id=$id_film";
		$res=sql_query($testo,$dbi);
		$num=sql_num_rows($res);
		if ($num==1)
		{
			$path=FISICAL_PATH."/".$id_film."/";
			
			if (!is_dir($path))
			{
				mkdir($path, 0777);
			}
			
			$temp= $_FILES['userfile']['error'];
			$invia='agg_img';
			if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
    			copy($_FILES['userfile']['tmp_name'], $path.$_FILES['userfile']['name']);
				$nome=$_FILES['userfile']['name'];
				$filename=$path.$nome;
				$size=getimagesize($filename);
				$img_width=$size[0];
				$img_height=$size[1];
				$dimensione=$_FILES['userfile']['size'];
				$pos=strrpos($nome,".");
				$len=strlen($nome)-$pos-1;
				$estensione=substr($nome,($pos+1),$len);
				$senza_ext=substr($nome,0,$pos);
								
				if (($estensione=='jpeg')or($estensione=='jpg'))
				{
					$dest_file_name=$path.$senza_ext.THUMB_NAME.".jpg";
					$perc=(100*THUMB_HEIGHT)/$img_height;
					$thumb_width=$img_width*$perc/100;
					
					$dst_img=ImageCreatetruecolor($thumb_width,THUMB_HEIGHT); 

					$src_img=ImageCreateFromjpeg($filename); 
					
					ImageCopyResized($dst_img,$src_img,0,0,0,0,$thumb_width,THUMB_HEIGHT,ImageSX($src_img),ImageSY($src_img));
					
					Imagejpeg($dst_img,$dest_file_name); 
				}
				if ($estensione=='gif')
				{
					$dest_file_name=$path.$senza_ext.THUMB_NAME.".jpg";
					$perc=(100*THUMB_HEIGHT)/$img_height;
					$thumb_width=$img_width*$perc/100;
					
					$dst_img=ImageCreatetruecolor($thumb_width,THUMB_HEIGHT); 

					$src_img=ImageCreateFromgif($filename); 
					
					ImageCopyResized($dst_img,$src_img,0,0,0,0,$thumb_width,THUMB_HEIGHT,ImageSX($src_img),ImageSY($src_img));
					
					imagejpeg($dst_img,$dest_file_name); 
				}
				if (($estensione=='jpeg')or($estensione=='jpg')or($estensione=='gif'))
				{
					$testo="insert into ".$prefix."_film_img (id_film, nome_file, descrizione, width,height) values ";
					$testo.="($id_film,'$nome','$descrizione',$img_width,$img_height)";
					//echo "<p>$testo</p>";
					sql_query($testo, $dbi);
				
					$errno=mysql_errno();
					if ($errno==0)
					{	
						$dimensione=number_format($dimensione,0,",",".");
						echo "<h3>Upload Effettuato di $nome ($dimensione)</h3>";
						$id=$id_film;				
					}
					else
					{
						$error=mysql_error();
						echo "<h3>$error</h3>";
						echo "<h3>$testo</h3>";
					}
				}
				else
				{
					echo "<h3>File non corretto</h3>";
				}
			} else {
    			echo "<h3>Problemi nel trasferimento del file</h3>";
			}		
		}
	}
	
	
	//********************************************************************
	//Scheda Film
	//********************************************************************
	if (($id>0)and($invia!=_MODIFICA))
	{
	
		$testo="select * from ".$prefix."_film where id=$id";
		$res=sql_query($testo,$dbi);
		$num=sql_num_rows($res);
		if ($num==1)
		{
			//Asseganzioni variabili
			$titolo=mysql_result($res,0,titolo);
			$id=mysql_result($res,0,id);
			$durata=mysql_result($res,0,durata);
			$anno=mysql_result($res,0,anno);
			$regia=mysql_result($res,0,regia);
			?>
				<STYLE>
					table#sc_film {display: block; left:10%; width: 80%; position: relative;}
					td#TITOLO {font-size: 18px;	text-align: left; background-color: #0099FF; width: 70%; height: 25px; vertical-align: middle;	border: medium ridge #0099FF;}
					td#CELLA {font-size: 14px; float: left;	text-align: center; background-color: cyan;}
					div#H_CELLA {font-size: 16px;	text-align:left; float:left; background-color: #0099FF; width: 100px;	font-weight: bold; border: thin ridge #0099FF;}
				</STYLE>
			<?
			$trama=mysql_result($res,0,trama);
			$recensione=mysql_result($res,0,recensione);
			$attori=mysql_result($res,0,attori);
			$cast=mysql_result($res,0,cast);
			$titolo_originale=mysql_result($res,0,titolo_originale);
			$categorie=mysql_result($res,0,categorie);
			$nome_cat=converti_id_cat($categorie,$db);
			$cast=str_replace(chr(13).chr(10),",",$cast);
			$attori=str_replace(chr(13).chr(10),",",$attori);
			echo "<table id='sc_film'>";
				echo "<tr><td colspan='4' id='TITOLO'>$titolo</td></tr>";
				echo "<tr><td colspan='4' id='CELLA'>&nbsp;</td></tr>";
				
				echo "<tr>";
					echo "<td colspan='4'  id='CELLA'><div id='H_CELLA'>Regia: </div>$regia</td>\n";
				echo "</tr>";
				echo "<tr>";
					echo "<td colspan='2' id='CELLA'><div id='H_CELLA'>Durata: </div> $durata</td>\n";
					echo "<td colspan='2' id='CELLA'><div id='H_CELLA'>Anno: </div> $anno</td>\n";
				echo "</tr>";
				echo "<tr>";
					echo "<td colspan='4' id='CELLA'><div id='H_CELLA'>Categoria: </div> $nome_cat</td>\n";
				echo "</tr>";
				echo "<tr>";
					echo "<td colspan='4' id='CELLA'><div id='H_CELLA'>Attori: </div> $attori</td>\n";
				echo "</tr>";
				echo "<tr>";
					echo "<td colspan='4' id='CELLA'><div id='H_CELLA'>Cast: </div> $cast</td>\n";
				echo "</tr>";				
				echo "<tr>";
					echo "<td colspan='4' id='CELLA'><div id='H_CELLA'>Trama:</div></td>\n";
				echo "</tr>";												
				echo "<tr>";
					echo "<td colspan='4' id='CELLA'>$trama</td>\n";
				echo "</tr>";
				
				
			ECHO "</table>";
			if (!$offset)
				$offset=0;
			$testo="select * from ".$prefix."_film_img where id_film=$id limit $offset,".IMG_X_PAGE;
			$res=sql_query($testo,$dbi);
			$num=sql_num_rows($res);
			$testo="select count(*) from ".$prefix."_film_img where id_film=$id";
			$res2=sql_query($testo,$dbi);
			$tot=mysql_result($res2,0,0);
			echo "<hr>";
			
			//********************************************************************
			//Gallery Film
			//********************************************************************
			if ($num>0) {
				OpenTable();

				$offa=$offset+IMG_X_PAGE;
				$offb=$offset-IMG_X_PAGE;
				echo "<tr>";
					if ($offset>0)
						echo "<td align='left'><a href=\"modules.php?name=$module_name&id=$id&offset=$offb\"><img src=\"images/left.gif\"></a></td>";
					else
						echo "<td></td>";
					echo "<td></td><td align='center'><font class=\"title\">Gallery</font></td><td></td>";	
					if ($tot>$num+$offset)
						echo "<td align='right'><a href=\"modules.php?name=$module_name&id=$id&offset=$offa\"><img src=\"images/right.gif\"></a></td>";
					else
						echo "<td></td>";
				echo "</tr>";
				echo "<tr>";
				for ($i=0; $i<5; $i++)
				{
					
					if ($i<$num) {
						$nome_img=mysql_result($res,$i,nome_file);
						$pos=strrpos($nome_img,".");
						$len=strlen($nome_img)-$pos-1;
						$estensione=substr($nome_img,($pos+1),$len);
						$senza_ext=substr($nome_img,0,$pos);
						$percorso_tmb=LOGICAL_PATH."/".$id."/".$senza_ext.THUMB_NAME.".jpg";
						$percorso_high=LOGICAL_PATH."/".$id."/".$nome_img;	
						echo "<td align='center' width='20%'><a href='$percorso_high'><img src=\"$percorso_tmb\" height=\"100\"></a></td>";	
					}
					else
						echo "<td width='20%'>&nbsp;</td>";
				}
				echo "</tr>";	
				CloseTable();
			}
			
			//********************************************************************
			//Form Per Upload Immagini
			//********************************************************************
			if(is_admin($admin)) {
				OpenTable();
					echo "<tr><form action=\"modules.php?name=$module_name&upload=yes&id_film=$id\" method=\"post\" enctype=\"multipart/form-data\" name=\"FORM_UPL\">";
					echo "<td align='left' colspan='2'><font class=\"title\"><b>Upload Immagini</b></font></td></tr>";
					echo "<tr><td align='center' colspan='2'>File: <input name='userfile' type='file'></td></tr>";
					echo "<tr><td align='center' colspan='2'>Descrizione: <input name='descrizione' type='text'></td></tr>";
					echo "<tr><td align='center' colspan='2'><input type='submit' name='send' value='Invia file'></td></tr>";
					echo "</form>";	
				CloseTable();
			}
		}
	}
	
	//********************************************************************
	//Elenco Film
	//********************************************************************
	if ($cerca==_CERCA)
	{
		$testo="select * from ".$prefix."_film";
		$mod=0;
		if (($cerca==_CERCA)and($categorie>0))
		{
			$testo.=" where categorie=$categorie";
			$mod=1;
		}
		if ($regia!="")
		{
			if ($mod==1)
				$testo.=" and";
			else
				$testo.=" where";
				
			$testo.=" MATCH (regia) AGAINST ('$regia')";
		
		}
		if ($nome_att!="")
		{
			if ($mod==1)
				$testo.=" and";
			else
				$testo.=" where";
				
			$testo.=" MATCH (attori) AGAINST ('$nome_att')";
		}
		if ($titolo!="")
		{
			if ($mod==1)
				$testo.=" and";
			else
				$testo.=" where";
				
			$testo.=" MATCH (titolo) AGAINST ('$titolo')";
		}
		$testo.=" order by categorie,id";
		
		$res=sql_query($testo,$dbi);
		//echo "<p>$testo</p>";
		$num=mysql_num_rows($res);
		Opentable();
		echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\">\n";
		echo "<tr bgcolor='yellow'>";
			echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\">";
				echo "<font color=\"$textcolor2\"><b>Titolo</b></font>";
			echo "</td>\n";
			echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\">";
				echo "<font color=\"$textcolor2\"><b>Durata</b></font>";
			echo "</td>\n";
			echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\">";
				echo "<font color=\"$textcolor2\"><b>Categoria</b></font>";
			echo "</td>\n";
			echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\">";
				echo "<font color=\"$textcolor2\"><b>Anno</b></font>";
			echo "</td>\n";
			echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\">";
				echo "<font color=\"$textcolor2\"><b>Regia</b></font>";
			echo "</td>\n";
			echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\">";
				echo "<font color=\"$textcolor2\"><b>Scheda</b></font>";
			echo "</td>\n";
			if (is_admin($admin))
			{
				echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\">";
					echo "<font color=\"$textcolor2\"><b>Modifica</b></font>";
				echo "</td>\n";
			
			}
		echo "</tr>";
		
		$a = 0;
        $dcolor_A = "$bgcolor2";
        $dcolor_B = "$bgcolor3";
		
		for ($i=0;$i<$num; $i++)
		{
			$titolo=mysql_result($res,$i,titolo);
			$id=mysql_result($res,$i,id);
			$durata=mysql_result($res,$i,durata);
			$anno=mysql_result($res,$i,anno);
			$regia=mysql_result($res,$i,regia);
			$categorie=mysql_result($res,$i,categorie);
			$nome_cat=converti_id_cat($categorie);
			$dcolor = ($a == 0 ? $dcolor_A : $dcolor_B);
			
			echo "<tr bgcolor=$dcolor><td>$id - $titolo</td>";
			echo "<td align=center>$durata</td>";
			echo "<td>$nome_cat</td>";
			echo "<td>$anno</td>";
			echo "<td>$regia</td>";
			echo "<td><a href='modules.php?name=$module_name&id=$id'>Scheda</a></td>";
			if (is_admin($admin))
			{
				echo "<td><a href='modules.php?name=$module_name&id=$id&invia="._MODIFICA."'>modifica</a></td>";
			}
			echo "</tr>";
			$a = ($dcolor == $dcolor_A ? 1 : 0);
		}
		echo "</table>";
		closetable();
	}
	
	
	//********************************************************************
	//Query Per aggiunta Film Nel DB
	//********************************************************************
	if (($aggiungi==_AGGIUNGI)and(is_admin($admin)))
	{
		if ($titolo!=NULL)
		{

			$testo="insert into ".$prefix."_film";
			$testo.="(titolo,durata,anno,regia,trama,attori,cast,titolo_originale,categorie)";
			$testo.="values('$titolo', '$durata', '$anno','$regia', '$trama','$attori','$cast','$titolo_originale',$categorie)";
			sql_query($testo,$dbi);
			$errno=mysql_errno();
			OpenTable();
			if ($errno==0)
			{
				echo "<tr><td><font class=\"title\"><b>"._AGG_OK."</b></font></td></tr>";
			}
			else
			{
				$error=mysql_error();
				echo "<tr><td>$testo</td></tr>";
				echo "<tr><td>$error</td></tr>";
			}
			closetable();
		}
	}
	
	
	//********************************************************************
	//Query nel DB per modifica Film
	//********************************************************************
	if (($modifica==_MODIFICA)and(is_admin($admin)))
	{
	    //$titolo=str_replace("'","''",$titolo);
		//$durata=str_replace("'","''",$durata);
		//$regia=str_replace("'","''",$regia);
		//$trama=str_replace("'","''",$trama);
		//$attori=str_replace("'","''",$attori);
		//$cast=str_replace("'","''",$cast);
		//$titolo_originale=str_replace("'","''",$titolo_originale);
		$testo="update ".$prefix."_film set titolo='$titolo', durata='$durata', anno=$anno, regia='$regia', ";
		$testo.="trama='$trama',attori='$attori', cast='$cast',titolo_originale='$titolo_originale' ";
		$testo.=",categorie=$categorie";
		$testo.=" where id=$id_film";
		sql_query($testo,$dbi);
		$errno=mysql_errno();
		OpenTable();
		if ($errno==0)
		{
			echo "<tr><td><font class=\"title\"><b>Modifica Effettuata</b></font></td></tr>";
		}
		else
		{
			$error=mysql_error();
			echo "<tr><td>$error</td></tr>";
		}
		closetable();
	}
	
	
	//********************************************************************
	//Form Di Modifica Film
	//********************************************************************
	if (($invia==_MODIFICA)and(is_admin($admin)))
	{
		$testo="select * from ".$prefix."_film where id=$id";
		$res=sql_query($testo,$dbi);
		$num=sql_num_rows($res);
		if ($num==1)
		{
				
			$titolo=mysql_result($res,0,titolo);
			$id=mysql_result($res,0,id);
			$durata=mysql_result($res,0,durata);
			$anno=mysql_result($res,0,anno);
			$regia=mysql_result($res,0,regia);
			$trama=mysql_result($res,0,trama);
			$attori=mysql_result($res,0,attori);
			$cast=mysql_result($res,0,cast);
			$titolo_originale=mysql_result($res,0,titolo_originale);
			$categorie=mysql_result($res,$i,categorie);
			$nome_cat=converti_id_cat($categorie,$db);
			echo "<form name='form_mod' method=\"post\" action=\"modules.php?name=$module_name\">";
			OpenTable();
				echo "<tr>";
					echo "<td colspan='2'>";
						echo "<font class=\"title\"><b>"._MODIFICA_FILM."</b></font>";
					echo "</td>";
				echo "</tr>";
				echo "<tr>";
					echo "<td><b>Titolo: </b></td>";
					echo "<td><input type='text' size='70' name='titolo' value='$titolo'></td>";
				echo "</tr>";
				echo "<tr>";
					echo "<td><b>Titolo originale: </b></td>";
					echo "<td>";
						echo "<input type='text' size='70' name='titolo_originale' value='$titolo_originale'>";
					echo "</td>";
				echo "</tr>";
				echo "<tr>";
					echo "<td><b>Durata: </b></td>";
					echo "<td><input type='text' name='durata' value='$durata'></td>";
				echo "</tr>";
				echo "<tr>";
					echo "<td><b>Anno: </b></td>";
					echo "<td><input type='text' name='anno' value='$anno'></td>";
				echo "</tr>";
				echo "<tr>";
					echo "<td><b>Regia: </b></td>";
					echo "<td><input type='text' size='70' name='regia' value='$regia'></td>";
				echo "</tr>";
				echo "<tr>";
					echo "<td><b>Trama: </b></td>";
					echo "<td align='center'><textarea name='trama' cols='70' rows='5'>$trama</textarea></td>";
				echo "</tr>";
				echo "<tr>";
					echo "<td><b>Attori: </b></td>";
					echo "<td align='center'><textarea name='attori' cols='70' rows='5'>$attori</textarea></td>";
				echo "</tr>";
				echo "<tr>";
					echo "<td><b>Cast: </b></td>";
					echo "<td align='center'><textarea name='cast' cols='70' rows='5'>$cast</textarea></td>";
				echo "</tr>";
				echo "<tr>";
					echo "<td><b>Categoria: </b></td>";
					echo "<td>";
						echo "<select name='categorie'>";
						for ($i=0; $i<$num_cat; $i++)
						{
							$id_cat=mysql_result($res_cat,$i,id);
							$nome_cat=mysql_result($res_cat,$i,nome);
							if ($id_cat==$categorie)
							{
								echo "<option value='$id_cat' selected>$nome_cat</option>";
							}
							else
							{
								echo "<option value='$id_cat'>$nome_cat</option>";
							}
						}
						echo "</select>";
					echo "</td>";
				echo "</tr>";
				echo "<tr>";
					echo "<td align='center' colspan='2'><input type='submit' name='modifica' value='"._MODIFICA."'></td>";
				echo "</tr>";
				echo "<input type='hidden' name='id_film' value='$id'>";
			closetable();
			echo "</form>";
		}
	}
	
	if (($nuovo==_NUOVO)and(is_admin($admin)))
	{
	
		//********************************************************************
		//Form Per Aggiunta Nuovo Film
		//********************************************************************
		OpenTable();
			//ricavo Elenco delle categorie
			$testo="select * from ".$prefix."_film_categorie";
			$res_cat=sql_query($testo,$dbi);
			$num_cat=mysql_num_rows($res_cat);
		
			echo "<form name='form_film' method=\"post\" action=\"modules.php?name=$module_name\">";
			
			echo "<tr>";
				echo "<td colspan='2'>";
					echo "<font class=\"title\"><b>"._AGGIUNTA_FILM."</b></font>";
				echo "</td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td><b>Titolo: </b></td>";
				echo "<td align='center'><input type='text' size='70' name='titolo' ></td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td><b>Titolo originale: </b></td>";
				echo "<td align='center'><input type='text' size='70' name='titolo_originale'></td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td><b>Durata: </b></td>";
				echo "<td align='center'><input type='text' name='durata'></td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td><b>Anno: </b></td>";
				echo "<td align='center'><input type='text' name='anno'></td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td><b>Regia: </b></td>";
				echo "<td align='center'><input type='text' size='70' name='regia'></td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td><b>Trama: </b></td>";
				echo "<td align='center'><textarea name='trama' cols='70' rows='5'></textarea></td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td><b>Attori: </b></td>";
				echo "<td align='center'>";
					echo "<textarea name='attori' cols='70' rows='5'></textarea>";
				echo "</td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td><b>Cast: </b></td>";
				echo "<td align='center'><textarea name='cast' cols='70' rows='5'></textarea></td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td><b>Categoria: </b></td>";
				echo "<td align='center'>";
					echo "<select name='categorie'>";
					for ($i=0; $i<$num_cat; $i++)
					{
						$id_cat=mysql_result($res_cat,$i,id);
						$nome_cat=mysql_result($res_cat,$i,nome);
						echo "<option value='$id_cat'>$nome_cat</option>";
					}
					echo "</select>";
				echo "</td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td align='center' colspan='2'>";
					echo "<input type='submit' name='aggiungi' value='"._AGGIUNGI."'>";
				echo "</td>";
			echo "</tr>";
			echo "<input type='hidden' name='id_film' value='$id'>";
			echo "</form>";
		closetable();
	
	}
	else
	{
		//********************************************************************
		//Form Per Ricerca Film
		//********************************************************************
		OpenTable();
			echo "<tr>";
				echo "<td colspan='2'>";
					echo "<font class=\"title\"><b>"._RICERCA_FILM."</b></font>";
				echo "</td>";
			echo "</tr>";
			echo "<form name='forma' method=\"post\" action=\"modules.php?name=$module_name\">";
			echo "<tr>";
				echo "<td align='center'>";
					echo "<b>"._CAT."</b>";
					echo "<select name='categorie'>";
					echo "<option value='0'>Tutte</option>";
					for ($i=0; $i<$num_cat; $i++)
					{
						$id_cat=mysql_result($res_cat,$i,id);
						$nome_cat=mysql_result($res_cat,$i,nome);
						echo "<option value='$id_cat'>$nome_cat</option>";
					}
					echo "</select>";
				echo "</td>";
				echo "<td align='center'>";
					echo "<b>"._NOME_ATTORI." :</b><input type='text' name='nome_att'>";
				echo "</td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td align='center'>";
					echo "<b>"._TITOLO_FILM." :</b><input type='text' name='titolo'>";
				echo "</td>";
				echo "<td align='center'>";
					echo "<b>"._REGIA." :</b><input type='text' name='regia'>";
				echo "</td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td colspan='2' align='center'>";
					echo "<input type='submit' name='cerca' value='"._CERCA."'>";
				echo "</td>";
			echo "</tr>";
			echo "</FORM>";
		CloseTable();
		if ((is_admin($admin))and($cerca!=_CERCA))
		{
			//********************************************************************
			//Bottone Per accesso a Form Aggiunta Film
			//********************************************************************
			OpenTable();
				echo "<form name='form_f' method=\"post\" action=\"modules.php?name=$module_name\">";
				echo "<tr>";
					echo "<td colspan='2'>";
						echo "<font class=\"title\"><b>"._AGGIUNTA_FILM."</b></font>";
					echo "</td>";
					echo "<td>";
						echo "<input type='submit' name='nuovo' value='"._NUOVO."'>";
					echo "</td>";
				echo "</tr>";
			
		
				echo "</FORM>";
			CloseTable();
		}
	
	}
	
	include("footer.php");
?>
Return current item: php movie db