Location: PHPKode > projects > ChiCoMaS - Chilek CMS > chicomas/modules/style/general_operation.php
<link rel="stylesheet" href="./modules/style/js_color_picker_v2.css" media="screen">
<script src="./modules/style/color_functions.js"></script>		
<script type="text/javascript" src="./modules/style/js_color_picker_v2.js"></script>

<?
//*****************************************************************************
function GeneralView($request){
	$content = null;

	global $title, $width, $keywords, $description, $logoname, $bodyposition, $thisurl, $textlogo;

	$obj_style = new CStyle();
	$obj_stylearray = new CStyleArray();
	$obj_styleengine = new CStyleEngine();

	if (!isset($f)) $f="style";
	if (!isset($sf)) $sf="general";

	$styleid = $request['styleid'];

	$bgim = $request['bgim'];
	$bgcol = $request['bgcol'];
	$bgrep = $request['bgrep'];
	$bgpos = $request['bgpos'];
	$ext_bg = $request['ext_bg'];
	$tmp_name = $request['tmp_name'];
	$name = $request['name'];

	$new_bgim = $request['new_bgim'];
	$newbgfile = $request['newbgfile'];
	$new_title = $request['new_title'];
	$new_keywords = $request['new_keywords'];
	$new_description = $request['new_description'];
	$new_width = $request['new_width'];
	$new_bodyposition = $request['new_bodyposition'];
	$replace_bg = $request['replace_bg'];

	if (!isset($new_width)) $new_width = $width;
	if (!isset($new_bodyposition)) $new_bodyposition = $bodyposition;
	if (!isset($new_title)) $new_title = $title;
	if (!isset($new_keywords)) $new_keywords = $keywords;
	if (!isset($new_description)) $new_description = $description;

	if (!isset($newbgfile)) $newbgfile="";
	if (!isset($ext_bg)) $ext_bg="";

	/* Read the db values */
	if (!isset($bgcol)){
		$obj_style = $obj_styleengine->GetActiveStyle();
		$styleid = $obj_style->style_id;
		$bgcol = $obj_style->bgcol;
		$bgim = $obj_style->bgim;
		$bgrep = $obj_style->bgrep;
		$bgpos = $obj_style->bgpos;
	}

	$bgimage=$_FILES['new_bgim']['tmp_name'];
	$bgimage_name=$_FILES['new_bgim']['name'];
	if ($bgimage_name!=""){
		$extension=explode(".",$bgimage_name);
		$num_els=count($extension);
		$ext_bg=$extension[$num_els - 1];
		$newbgfile="./siteimages/temp_bgimage";
		/* if (file_exists($newbgfile)) unlink($newbgfile); */
		move_uploaded_file ($bgimage, $newbgfile);
	}


	$header = _CONTROL_PANEL_."<br>";
	$header .= _CP_STYLE_ADMINISTRATION_._CMN_DASH_._CP_SA_GENERAL_;

	$info = _CP_SA_GENERAL_MSG_;


	$content = "
	<!-- Dynamically switch the action of the form between delete/rename -->
	<script language=\"JavaScript\" type=\"text/javascript\">
	function OnSubmitForm(){
		if(document.pressed == '"._CMN_SAVE_."'){
			document.headform.action =\"".basename($PHP_SELF)."?f=style&sf=general&operation=save\";
		}
		else
			if(document.pressed == '"._CMN_PREVIEW_."'){
				document.headform.action =\"".basename($PHP_SELF)."?f=style&sf=general&operation=preview\";
		}
		return true;
	}
	</SCRIPT>

	<center><h3>".$header."</h3></center>
	<i><ul>".$info."</ul></i>
	<center>
	<div id=\"formular\">
	<form enctype=\"multipart/form-data\" name=\"headform\" onsubmit=\"return OnSubmitForm();\" method='post'>
	<table width=\"95%\" cellpadding=\"5\" cellspacing=\"5\" border=\"1\">
	<tr>
		<td colspan=\"3\" align=\"center\">
			<input type=\"submit\" value=\""._CMN_PREVIEW_."\" name=\"preview\" onclick=\"document.pressed=this.value\" /> "._CMN_OR_." 
			<input type=\"submit\" value=\""._CMN_SAVE_."\" name=\"save\" onclick=\"document.pressed=this.value\" />
		</td>
	</tr>
	<tr>
		<td colspan=\"3\" align=\"left\">
			<b>"._CP_SA_GENERAL_."</b>
			<input type=\"hidden\" name=\"newbgfile\" value=\"$newbgfile\" />
			<input type=\"hidden\" name=\"ext_bg\" value=\"$ext_bg\" />
			<input type=\"hidden\" name=\"bgim\" value=\"$bgim\" />
			<input type=\"hidden\" name=\"styleid\" value=\"$styleid\" />
		</td>
	</tr>
	<tr>
		<td align=\"left\" width=\"45%\">"._CP_SA_GP_HEADER_."</td>
		<td align=\"left\" width=\"55%\" colspan=\"2\">
			<input type=\"text\" name=\"new_title\" value=\"$new_title\" size=\"50\" />
		</td>
	</tr>
	<tr>
		<td align=\"left\">"._CP_SA_GP_KEYWORDS_."</td>
		<td align=\"left\" colspan=\"2\">
			<textarea cols=\"50\" rows=\"3\" name=\"new_keywords\">$new_keywords</textarea>
		</td>
	</tr>
	<tr>
		<td align=\"left\">"._CP_SA_GP_DEFINITION_."</td>
		<td align=\"left\" colspan=\"2\">
			<textarea cols=\"50\" rows=\"3\" name=\"new_description\">$new_description</textarea>
		</td>
	</tr>
	<tr>
		<td colspan=\"3\" align=\"left\">
			<b>"._CP_SA_GP_DOCUMENT_PROPERTIES_."</b>
		</td>
	</tr>
	<tr>
		<td align=\"left\">"._CP_SA_GP_DOCUMENT_WIDTH_."</td>
		<td align=\"left\" colspan=\"2\">
			<select name=\"new_width\">";
			if ($new_width=="100%")
				$content .= "<option selected=\"selected\" value=\"100%\">"._CP_SA_GP_DOCUMENT_WIDTH_OPTION_1_."</option>";
			else
				$content .= "<option value=\"100%\">"._CP_SA_GP_DOCUMENT_WIDTH_OPTION_1_."</option>";

			if ($new_width=="980px")
				$content .= "<option selected=\"selected\" value=\"980px\">"._CP_SA_GP_DOCUMENT_WIDTH_OPTION_2_."</option>";
			else
				$content .= "<option value=\"980px\">"._CP_SA_GP_DOCUMENT_WIDTH_OPTION_2_."</option>";

			if ($new_width=="800px")
				$content .= "<option selected=\"selected\" value=\"800px\">"._CP_SA_GP_DOCUMENT_WIDTH_OPTION_3_."</option>";
			else
				$content .= "<option value=\"800px\">"._CP_SA_GP_DOCUMENT_WIDTH_OPTION_3_."</option>";

			if ($new_width=="600px")
				$content .= "<option selected=\"selected\" value=\"600px\">"._CP_SA_GP_DOCUMENT_WIDTH_OPTION_4_."</option>";
			else
				$content .= "<option value=\"600px\">"._CP_SA_GP_DOCUMENT_WIDTH_OPTION_4_."</option>";
			$content .= "
			</select>
		</td>
	</tr>

	<tr>
		<td align=\"left\">"._CP_SA_GP_DOCUMENT_POSITION_."</td>
		<td align=\"left\" colspan=\"2\">
			<select name=\"new_bodyposition\">";
			if ($new_bodyposition=="left")
				$content .= "<option selected=\"selected\" value=\"left\">"._CP_SA_GP_DOCUMENT_POSITION_OPTION_1_."</option>"; 
			else
				$content .= "<option value=\"left\">"._CP_SA_GP_DOCUMENT_POSITION_OPTION_1_."</option>";

			if ($new_bodyposition=="center")
				$content .= "<option selected=\"selected\" value=\"center\">"._CP_SA_GP_DOCUMENT_POSITION_OPTION_2_."</option>";
			else
				$content .= "<option value=\"center\">"._CP_SA_GP_DOCUMENT_POSITION_OPTION_2_."</option>";
			$content .= "
			</select>
		</td>
	</tr>";

	$content .= "
	<tr>
		<td colspan=\"3\" align=\"left\">
			<b>"._CP_SA_BACKGROUND_."</b>
		</td>
	</tr>
	<tr>
		<td align=\"left\">"._CP_SA_BACKGROUND_COLOR_."</td>
		<td colspan=\"2\">
			<input type=\"text\" size=\"10\" maxlength=\"7\" name=\"bgcol\" value=\"$bgcol\" readonly>
			<input type=\"button\" value=\""._CP_SA_COLOR_CATALOG_."\" onclick=\"showColorPicker(this,document.forms[0].bgcol)\">
		</td>
	</tr>

	<tr>
		<td align=\"left\">"._CP_SA_BACKGROUND_PICTURE_."</td>
		<td align=\"left\" colspan=\"2\">
			<input type=\"file\" name=\"new_bgim\" />
		</td>
	</tr>
	
	<tr>
		<td align=\"left\">"._CP_SA_REPEAT_BACKGROUND_PICTURE_."</td>
		<td align=\"left\">
		<select name=\"bgrep\">";
		if ($bgrep=="no-repeat")
			$content .= "<option value=\"no-repeat\" selected=\"selected\">"._CP_SA_RBP_OPTION_1_."</option>";
		else
			$content .= "<option value=\"no-repeat\">"._CP_SA_RBP_OPTION_1_."</option>";
	
		if ($bgrep=="repeat-x")
			$content .= "<option value=\"repeat-x\" selected=\"selected\">"._CP_SA_RBP_OPTION_2_."</option>";
		else
			$content .= "<option value=\"repeat-x\">"._CP_SA_RBP_OPTION_2_."</option>";
	
		if ($bgrep=="repeat-y")
			$content .= "<option value=\"repeat-y\" selected=\"selected\">"._CP_SA_RBP_OPTION_3_."</option>";
		else
			$content .= "<option value=\"repeat-y\">"._CP_SA_RBP_OPTION_3_."</option>";
	
		if ($bgrep=="repeat")
			$content .= "<option value=\"repeat\" selected=\"selected\">"._CP_SA_RBP_OPTION_4_."</option>";
		else
			$content .= "<option value=\"repeat\">"._CP_SA_RBP_OPTION_4_."</option>";
		$content .= "
		</select>
		</td>
	</tr>
	
	<tr>
		<td align=\"left\">"._CP_SA_BACKGROUND_PICTURE_POSITION_."</td>
		<td align=\"left\">
			<select name=\"bgpos\">";
			if ($bgpos=="0% 0%")
				$content .= "<option value=\"0% 0%\" selected=\"selected\">"._CP_SA_UPPER_LEFT_."</option>";
			else
				$content .= "<option value=\"0% 0%\">"._CP_SA_UPPER_LEFT_."</option>";
	
			if ($bgpos=="0% 50%")
				$content .= "<option value=\"0% 50%\" selected=\"selected\">"._CP_SA_MIDDLE_LEFT_."</option>";
			else
				$content .= "<option value=\"0% 50%\">"._CP_SA_MIDDLE_LEFT_."</option>";
	
			if ($bgpos=="0% 100%")
				$content .= "<option value=\"0% 100%\" selected=\"selected\">"._CP_SA_LOWER_LEFT_."</option>";
			else
				$content .= "<option value=\"0% 100%\">"._CP_SA_LOWER_LEFT_."</option>";
	
			if ($bgpos=="50% 0%")
				$content .= "<option value=\"50% 0%\" selected=\"selected\">"._CP_SA_UPPER_MIDDLE_."</option>";
			else
				$content .= "<option value=\"50% 0%\">"._CP_SA_UPPER_MIDDLE_."</option>";
	
			if ($bgpos=="50% 50%")
				$content .= "<option value=\"50% 50%\" selected=\"selected\">"._CP_SA_MIDDLE_MIDDLE_."</option>";
			else
				$content .= "<option value=\"50% 50%\">"._CP_SA_MIDDLE_MIDDLE_."</option>";
	
			if ($bgpos=="50% 100%")
				$content .= "<option value=\"50% 100%\" selected=\"selected\">"._CP_SA_LOWER_MIDDLE_."</option>";
			else
				$content .= "<option value=\"50% 100%\">"._CP_SA_LOWER_MIDDLE_."</option>";
	
			if ($bgpos=="100% 0%")
				$content .= "<option value=\"100% 0%\" selected=\"selected\">"._CP_SA_UPPER_RIGHT_."</option>";
			else
				$content .= "<option value=\"100% 0%\">"._CP_SA_UPPER_RIGHT_."</option>";
	
			if ($bgpos=="100% 50%")
				$content .= "<option value=\"100% 50%\" selected=\"selected\">"._CP_SA_MIDDLE_RIGHT_."</option>";
			else
				$content .= "<option value=\"100% 50%\">"._CP_SA_MIDDLE_RIGHT_."</option>";
	
			if ($bgpos=="100% 100%")
				$content .= "<option value=\"100% 100%\" selected=\"selected\">"._CP_SA_LOWER_RIGHT_."</option>";
			else
				$content .= "<option value=\"100% 100%\">"._CP_SA_LOWER_RIGHT_."</option>";
			$content .= "
			</select>
		</td>
	</tr>";
	
	if ($newbgfile!="" || $bgim!=""){
	$content .= "
	<tr>
		<td align=\"left\">"._CP_SA_CHANGE_BACKGROUND_PICTURE_."</td>
		<td align=\"left\" colspan=\"2\">
			<input type=\"checkbox\" name=\"replace_bg\" ";
			if (!isset($replace_bg))
				$content .= "unchecked=\"unchecked\" />";
			else
				$content .= "checked=\"checked\" />";
	}
	
	$content .= "
	<tr>
		<td colspan=\"3\" align=\"center\">
			<input type=\"submit\" value=\""._CMN_PREVIEW_."\" name=\"preview\" onclick=\"document.pressed=this.value\" /> "._CMN_OR_." 
			<input type=\"submit\" value=\""._CMN_SAVE_."\" name=\"save\" onclick=\"document.pressed=this.value\" />
		</td>
	</tr>	
	</table>
	</form>
	</div>
	</center>
	</td>
	</tr>
	</table>
	
	<table width=\"100%\">
	<tr>
		<td>
			<center>
			<b>"._CP_SA_PREVIEW_."</b><br/>";
	
			$content .= "
			<div style=\"background-color: $bgcol;";
			if ($newbgfile!="" && !isset($replace_bg)){
				$content .= "background-image:url('$newbgfile'); background-repeat:$bgrep; background-position: $bgpos;";
			}
			elseif($bgim!="" && !isset($replace_bg)){
				$bgim=str_replace("./","./",$bgim);
				$content .= "background-image:url('$bgim'); background-repeat:$bgrep; background-position: $bgpos;";
			}
	
			$content .= "
			\">
			<table width=\"100%\">
			<tr>
				<td align=\"left\" valign=\"middle\" style=\"border:solid 1px black\" height=\"50px\">
				</td>
			</tr>
			</table>
			</div>
		</center>";

	return $content;
}

//*****************************************************************************
function GeneralSave($request){
	$content = null;

	global $title, $width, $keywords, $description, $logoname, $bodyposition, $thisurl, $textlogo;

	$obj_style = new CStyle();
	$obj_stylearray = new CStyleArray();
	$obj_styleengine = new CStyleEngine();

	if (!isset($f)) $f="style";
	if (!isset($sf)) $sf="general";

	$styleid = $request['styleid'];

	$bgim = $request['bgim'];
	$bgcol = $request['bgcol'];
	$bgrep = $request['bgrep'];
	$bgpos = $request['bgpos'];
	$ext_bg = $request['ext_bg'];
	$tmp_name = $request['tmp_name'];
	$name = $request['name'];

	$new_bgim = $request['new_bgim'];
	$newbgfile = $request['newbgfile'];
	$new_title = $request['new_title'];
	$new_keywords = $request['new_keywords'];
	$new_description = $request['new_description'];
	$new_width = $request['new_width'];
	$new_bodyposition = $request['new_bodyposition'];
	$replace_bg = $request['replace_bg'];

	/* Manage the files */
	$bgimage=$_FILES['new_bgim']['tmp_name'];
	$bgimage_name=$_FILES['new_bgim']['name'];
	if ($bgimage_name!=""){
		$extension=explode(".",$bgimage_name);
		$num_els=count($extension);
		$ext_bg=$extension[$num_els - 1];
		$newbgfile="./siteimages/temp_bgimage";
		/* if (file_exists($newbgfile)) unlink($newbgfile); */
		move_uploaded_file ($bgimage,$newbgfile);
	}
	
	
	/* Set the background values */
	
	if ($newbgfile!="" && !isset($replace_bg)){
		if (file_exists("./siteimages/bgimage.$ext_bg"))
			unlink ("./siteimages/bgimage.$ext_bg");
		rename("./siteimages/temp_bgimage","./siteimages/bgimage.$ext_bg");
		$bgim="./siteimages/bgimage.$ext_bg";
	}
	elseif ($bgim!="" && !isset($replace_bg))
	{
		if (file_exists("./siteimages/temp_bgimage"))
			unlink("./siteimages/temp_bgimage");
	}
	else{
		if (file_exists("./siteimages/temp_bgimage"))
			unlink("./siteimages/temp_bgimage");
		$bgim="";
	}
	
	
	/* Update the DB */
	$obj_style = $obj_styleengine->GetStyle($styleid);
	$obj_style->bgcol = $bgcol;
	$obj_style->bgim = $bgim;
	$obj_style->bgrep = $bgrep;
	$obj_style->bgpos = $bgpos;
	if (!$obj_styleengine->UpdateStyle($obj_style))
		echo "Update error on Style Engine<br>";
	
	
	/* Update the config.inc file */
	$conf = new ConfigTool();
	$conf->setConfigFromFile( CONFIGFILE );

	//********************
	// title
	//********************
	if ($conf->isDefined('title'))
		$conf->updateKeyValue( "title", "'".$new_title."'" );
	else{
		$title = "ChiCoMaS - Chilek Content Management System";
		$conf->addKeyValue( "title", "'ChiCoMaS - Chilek Content Management System'" );
	}

	//********************
	// width
	//********************
	if ($conf->isDefined('width'))
		$conf->updateKeyValue( "width", "'".$new_width."'" );
	else{
		$width = "800px";
		$conf->addKeyValue( "width", "'800px'" );
	}
	
	//********************
	// keywords
	//********************
	if ($conf->isDefined('keywords'))
		$conf->updateKeyValue( "keywords", "'".$new_keywords."'" );
	else{
		$keywords = "chicomas, content, management, system, cms, tinymce, quixplorer, mysqlbackuppro, php, mysql";
		$conf->addKeyValue( "keywords", "'chicomas, content, management, system, cms, tinymce, quixplorer, mysqlbackuppro, php, mysql'" );
	}

	//********************
	// description
	//********************
	if ($conf->isDefined('description'))
		$conf->updateKeyValue( "description", "'".$new_description."'" );
	else{
		$description = "ChiCoMaS - Chilek Content Management System";
		$conf->addKeyValue( "description", "'ChiCoMaS - Chilek Content Management System'" );
	}

	//********************
	// bodyposition
	//********************
	if ($conf->isDefined('bodyposition'))
		$conf->updateKeyValue( "bodyposition", "'".$new_bodyposition."'" );
	else{
		$bodyposition = "center";
		$conf->addKeyValue( "bodyposition", "'center'" );
	}

	//********************
	// Save Config File
	//********************
	$conf->setFileName( CONFIGFILE );
	$conf->saveToFile();

	/* Create a new css file! */
	$obj_style = $obj_styleengine->GetStyle($styleid);
	CreateCSSFile($obj_style);
	
	ReDirection(basename($PHP_SELF)."?f=style&sf=general&operation=view");

	return $content;
}


//*****************************************************************************
function General_Operation($request){
	$content = null;

	$operation = $request['operation'];

	switch ($operation){
	default:
	case 'view':
	case 'preview':
		$content = GeneralView($request);
	break;
	case 'save':
		$content = GeneralSave($request);
	break;
	}

	return $content;
}
?>
Return current item: ChiCoMaS - Chilek CMS