Location: PHPKode > projects > SiteX > admin/title_add.php
<?PHP
ob_start();
session_start();

ini_set("memory_limit","100M");

include("../includes/globals.php.inc");
include("../includes/functions.php");
include("../lang/English.php");
if(strtolower($sxSetup['Language']) != 'english') include("../lang/".$sxSetup['Language'].".php");
include("../themes/$THEME_FOLDER/config.php.inc");

protectWriteMode();

if(!userAdmin())
	loginError($sxLang['LoginRequired']);

if($Submit)
{
	// Fetch width/height of image
	$query = "SELECT * FROM $DB_Themes WHERE id='$title_themeid'";
	$result = mysql_query($query, $Link) or queryError("12", mysql_error());
	$ROW = mysql_fetch_object($result);
	
	$rec_title_width = $ROW->title_width;
	$rec_title_height = $ROW->title_height;
	
	$sxFileName = basename($_FILES['File']['name']);
	
	// Check to make sure file is an acceptable type
	if (eregi ("(.)+\\.(jp(e){0,1}g$|gif$|png$|bmp$)", strtolower($sxFileName)))
	{
		$sxFileNameParts = explode('.',$sxFileName);

		$query = "SELECT * FROM $DB_Title_Pictures ORDER BY id DESC LIMIT 0,1";
		$result = mysql_query($query, $Link) or queryError("12", mysql_error());
		
		if(mysql_num_rows($result))
		{
			$ROW = mysql_fetch_object($result);
			$filename = ($ROW->id + 1) . "." . $sxFileNameParts[1];
		}
		else
			$filename = "1." . $sxFileNameParts[1];
	
		if (@move_uploaded_file($_FILES['File']['tmp_name'], "../".$sxContentDir['TitleImage'].$filename))
		{
			if((imageCompatibility() == "truecolor")OR(imageCompatibility() == "normal"))
			{
				$sxImageInfo = getimagesize("../".$sxContentDir['TitleImage'].$filename);

				switch($sxImageInfo[2])
				{
					case 1: $image = imagecreatefromgif("../".$sxContentDir['TitleImage'].$filename); 	break;
					case 2: $image = imagecreatefromjpeg("../".$sxContentDir['TitleImage'].$filename); 	break;
					case 3: $image = imagecreatefrompng("../".$sxContentDir['TitleImage'].$filename); 	break;
					case 6: $image = imagecreatefromwbmp("../".$sxContentDir['TitleImage'].$filename); 	break;
				}
				$width_original = $sxImageInfo[0];
				$height_original = $sxImageInfo[1];
			}
			
			$title_width = $width_original;
			$title_height = $height_original;
			
			switch(intval($image_option))
			{
				// Resize
				case 1:
				
					if(($width_original > $rec_title_width)OR($height_original > $rec_title_height))
					{
						if(imageCompatibility() == "truecolor")
						{
							$image_new = imagecreatetruecolor($rec_title_width, $rec_title_height);
							imagecopyresampled($image_new, $image, 0, 0, 0, 0, $rec_title_width, $rec_title_height, $width_original, $height_original);
						}
						elseif(imageCompatibility() == "normal")
						{
							$image_new = imagecreate($rec_title_width, $rec_title_height);
							imagecopyresized($image_new, $image, 0, 0, 0, 0, $rec_title_width, $rec_title_height, $width_original, $height_original);
						}
						
						switch($sxImageInfo[2])
						{
							case 1: imagegif($image_new, "../".$sxContentDir['TitleImage'].$filename); 		break;
							case 2: imagejpeg($image_new, "../".$sxContentDir['TitleImage'].$filename, 90); break;
							case 3: imagepng($image_new, "../".$sxContentDir['TitleImage'].$filename); 		break;
							case 6: imagewbmp($image_new, "../".$sxContentDir['TitleImage'].$filename); 	break;
						}
						
						imagedestroy($image_new);
						
						$title_width = $rec_title_width;
						$title_height = $rec_title_height;
					}
					
					$filesize = filesize("../".$sxContentDir['TitleImage'].$filename);
					imagedestroy($image);
					
					break;
					
				// Crop
				case 2:
					
					if(($width_original > $rec_title_width)OR($height_original > $rec_title_height))
					{
						$x_pos = ($width_original/2)-($rec_title_width/2);
						$y_pos = ($height_original/2)-($rec_title_height/2);
						
						if(imageCompatibility() == "truecolor")
							$image_new = imagecreatetruecolor($rec_title_width, $rec_title_height);
						elseif(imageCompatibility() == "normal")
							$image_new = imagecreate($rec_title_width, $rec_title_height);
						echo $x_pos . '---' . $y_pos;
						imagecopy($image_new, $image, 0, 0, $x_pos, $y_pos, $rec_title_width, $rec_title_height);
						
						switch($sxImageInfo[2])
						{
							case 1: imagegif($image_new,  "../".$sxContentDir['TitleImage'].$filename); 	break;
							case 2: imagejpeg($image_new, "../".$sxContentDir['TitleImage'].$filename, 90); break;
							case 3: imagepng($image_new,  "../".$sxContentDir['TitleImage'].$filename); 	break;
							case 6: imagewbmp($image_new, "../".$sxContentDir['TitleImage'].$filename); 	break;
						}
						
						imagedestroy($image_new);
						
						$title_width = $rec_title_width;
						$title_height = $rec_title_height;
					}
					
					$filesize = filesize("../".$sxContentDir['TitleImage'].$filename);
					imagedestroy($image);
					
					break;
			}
			
			$message = $sxLang['MessageFileUploaded'];
	
			$query = "INSERT INTO $DB_Title_Pictures (name, filename, filesize, themeid, active, width, height) VALUES ('$name', '$filename', '$filesize', '$title_themeid', '$active', '$title_width', '$title_height')";
			$result = mysql_query($query, $Link) or queryError("13", mysql_error());
		}
		else $message = $sxLang['MessageFileCopyError'];
		@unlink($File);
		
	}else{
		$message = $sxLang['MessagePhotoResourceError'];
	}
}

$sxTitleAddendum = $sxLang['AdminHeading'];
include("../themes/$THEME_FOLDER/header.php");
?>
  <div class="bodyWrapper">
   <h1 class="sxAdminHeading"><?PHP echo $sxLang['TitleHeadingAdd']; ?></h1>
   <div class="sxAdminBreadcrumbs"><?PHP if(userAdmin()) { ?><a href="index.php"><?PHP echo $sxLang['AdminBreadcrumb']; ?><?PHP }?><?PHP if(userEditor()) { ?><a href="editor_index.php"><?PHP echo $sxLang['EditorBreadcrumb']; ?><?PHP }?></a> > <a href="titles.php"><?PHP echo $sxLang['TitleHeadingManager']; ?></a> > <?PHP echo $sxLang['TitleHeadingAdd']; ?></div>
   <?PHP echoMessage($message); ?>
	<table border="0" cellspacing="3" cellpadding="5">
	  <form name="sxFormTitleAdd" action="<?PHP print $PHP_SELF; ?>" method="post" enctype="multipart/form-data">
		<tr> 
		  <td class="sxTdItem"><?PHP echo $sxLang['GeneralItemName']; ?></td>
		  <td><input name="name" type="text" id="name" /></td>
		</tr>
		<tr> 
		  <td class="sxTdItem"><?PHP echo $sxLang['GeneralItemFile']; ?></td>
		  <td><input type="file" name="File" /></td>
		</tr>
		<tr> 
		  <td class="sxTdItem"><?PHP echo $sxLang['ThemesItemTheme']; ?></td>
		  <td><select name="title_themeid">
			  <?PHP
			  	$sxRecWidth = 0;
				$sxRecHeight = 0;
				$query = "SELECT * FROM $DB_Themes ORDER BY name";
				$result = mysql_query($query, $Link) or queryError("12", mysql_error());
				while($ROW = mysql_fetch_object($result)){
					if($ROW->selected == 1){
						$selected = ' selected';
						$sxRecWidth = $ROW->title_width;
						$sxRecHeight = $ROW->title_height;
					}
					else $selected = '';
					echo '<option value="' . $ROW->id . '"' . $selected . '>' . $ROW->name . '</option>';
				}
			  ?>
			  </select></td>
		</tr>
		<tr>
		  <td class="sxTdItem"><?PHP echo $sxLang['TitleItemOptions']; ?></td>
		  <td><input name="image_option" type="radio" value="1" /> <?PHP echo $sxLang['TitleItemOptionsResize']; ?><br />
              <input name="image_option" type="radio" value="2" /> <?PHP echo $sxLang['TitleItemOptionsCrop']; ?><br />
              <input name="image_option" type="radio" value="3" checked /> <?PHP echo $sxLang['TitleItemOptionsNoResize']; ?><br /><br />
              <span class="sxSmallText"><?PHP echo $sxLang['TitleItemOptionsRecommendedSize'] . ': ' . $sxRecWidth . ' ' . $sxLang['Width'] . ' x ' . $sxRecHeight . ' ' . $sxLang['Height']; ; ?></span></td>
		</tr>
		<tr> 
		  <td class="sxTdItem"><?PHP echo $sxLang['GeneralItemActive']; ?></td>
		  <td><input name="active" type="checkbox" id="active" value="1" checked /></td>
		</tr>
		<tr> 
		  <td colspan="2" valign="top" align="right"><input type="submit" name="Submit" value="<?PHP echo $sxLang['TitleButonAdd']; ?>" class="sxButton" /></td>
		</tr>
	  </form>
	</table>
  </div>
<?PHP
include("../themes/$THEME_FOLDER/footer.php");
ob_end_flush();
?>
Return current item: SiteX