Location: PHPKode > projects > ChiCoMaS - Chilek CMS > chicomas/modules/style/document_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 DocumentView($request){
	$content = null;

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

	if (!isset($f)) $f="style";
	if (!isset($sf)) $sf="document";
	
	$styleid = $request['styleid'];
	$docbgcol = $request['docbgcol'];
	$docbgim = $request['docbgim'];
	$docbgrep = $request['docbgrep'];
	$docbgpos = $request['docbgpos'];
	$docborstyle = $request['docborstyle'];
	$docborw = $request['docborw'];
	$docborcol = $request['docborcol'];

	$newbgfile = $request['newbgfile'];
	$ext_bg = $request['ext_bg'];
	$docbgim = $request['docbgim'];
	$replace_bg = $request['replace_bg'];

	if (!isset($newbgfile)) $newbgfile="";
	if (!isset($ext_bg)) $ext_bg="";
	
	/* Read the values */
	
	if (!isset($docbgcol)){
		$obj_style = $obj_styleengine->GetActiveStyle();
		$styleid = $obj_style->style_id;
		$docbgcol = $obj_style->docbgcol;
		$docbgim = $obj_style->docbgim;
		$docbgrep = $obj_style->docbgrep;
		$docbgpos = $obj_style->docbgpos;
		$docborstyle = $obj_style->docborstyle;
		$docborw = $obj_style->docborw;
		$docborcol = $obj_style->docborcol;
	}
	
	
	$bgimage=$_FILES['new_docbgim']['tmp_name'];
	$bgimage_name=$_FILES['new_docbgim']['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_DOCUMENT_;

	$info = _CP_SA_DOCUMENT_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=document&operation=save\";
		}
		else
			if(document.pressed == '"._CMN_PREVIEW_."'){
				document.headform.action =\"".basename($PHP_SELF)."?f=style&sf=document&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_BACKGROUND_."</b>
		</td>
	</tr>

	<tr>
		<td width=\"45%\">
			<input type=\"hidden\" name=\"newbgfile\" value=\"$newbgfile\" />
			<input type=\"hidden\" name=\"ext_bg\" value=\"$ext_bg\" />
			<input type=\"hidden\" name=\"docbgim\" value=\"$docbgim\" />
			<input type=\"hidden\" name=\"styleid\" value=\"$styleid\" />
			"._CP_SA_BACKGROUND_COLOR_."
		</td>
		<td align=\"left\" colspan=\"2\" width=\"55%\">
			<input type=\"text\" size=\"10\" maxlength=\"7\" name=\"docbgcol\" value=\"$docbgcol\" readonly>
			<input type=\"button\" value=\""._CP_SA_COLOR_CATALOG_."\" onclick=\"showColorPicker(this,document.forms[0].docbgcol)\">
		</td>
	</tr>

	<tr>
		<td>"._CP_SA_BACKGROUND_PICTURE_."</td>
		<td align=\"left\" colspan=\"2\">
			<input type=\"file\" name=\"new_docbgim\" />
		</td>
	</tr>

	<tr>
		<td>"._CP_SA_REPEAT_BACKGROUND_PICTURE_."</td>
		<td align=\"left\">
			<select name=\"docbgrep\">";
			if ($docbgrep=="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 ($docbgrep=="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 ($docbgrep=="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 ($docbgrep=="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>"._CP_SA_BACKGROUND_PICTURE_POSITION_."</td>
		<td align=\"left\">
		<select name=\"docbgpos\">";
			if ($docbgpos=="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 ($docbgpos=="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 ($docbgpos=="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 ($docbgpos=="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 ($docbgpos=="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 ($docbgpos=="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 ($docbgpos=="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 ($docbgpos=="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 ($docbgpos=="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!="" || $docbgim!=""){
	$content .= "
	<tr>
		<td>"._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=\"left\">
			<b>"._CP_SA_BORDER_."</b>
		</td>
	</tr>

	<tr>
		<td>"._CP_SA_BORDER_STYLE_."</td>
		<td colspan=\"2\">
			<select name=\"docborstyle\">";
			if ($docborstyle=="solid")
				$content .= "<option selected=\"selected\" value=\"solid\">"._CP_SA_BORDER_TYPE_OPTION_1_."</option>";
			else
				$content .= "<option value=\"solid\">"._CP_SA_BORDER_TYPE_OPTION_1_."</option>";

			if ($docborstyle=="dashed")
				$content .= "<option selected=\"selected\" value=\"dashed\">"._CP_SA_BORDER_TYPE_OPTION_2_."</option>";
			else
				$content .= "<option value=\"dashed\">"._CP_SA_BORDER_TYPE_OPTION_2_."</option>";

			if ($docborstyle=="dotted")
				$content .= "<option selected=\"selected\" value=\"dotted\">"._CP_SA_BORDER_TYPE_OPTION_3_."</option>";
			else
				$content .= "<option value=\"dotted\">"._CP_SA_BORDER_TYPE_OPTION_3_."</option>";

			$content .= "
			</select>
		</td>
	</tr>

	<tr>
		<td>"._CP_SA_BORDER_WIDTH_."</td>
		<td colspan=\"2\">
			<input type=\"text\" size=\"4\" name=\"docborw\" value=\"$docborw\" />
		</td>
	</tr>


	<tr>
		<td>
			<input type=\"hidden\" name=\"newbgfile\" value=\"$newbgfile\" />
			<input type=\"hidden\" name=\"ext_bg\" value=\"$ext_bg\" />
			"._CP_SA_BORDER_COLOR_."
		</td>
		<td align=\"left\" colspan=\"2\">
			<input type=\"text\" size=\"10\" maxlength=\"7\" name=\"docborcol\" value=\"$docborcol\" readonly>
			<input type=\"button\" value=\""._CP_SA_COLOR_CATALOG_."\" onclick=\"showColorPicker(this,document.forms[0].docborcol)\">
		</td>
	</tr>

	<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 .= "
		<table width=\"100%\">
		<tr>
			<td height=\"100px\" align=\"left\" valign=\"middle\" style=\"background-color: $docbgcol;";
				if ($newbgfile!="" && !isset($replace_bg)){
					$content .= "background-image:url('$newbgfile'); background-repeat:$docbgrep; background-position: $docbgpos;";
				}
				elseif ($docbgim!="" && !isset($replace_bg)){
					$docbgim=str_replace("./","./",$docbgim);
					$content .= "background-image:url('$docbgim'); background-repeat:$docbgrep; background-position: $docbgpos;";
				}
				$content .= "border: $docborstyle $docborw $docborcol\">
				<br />
				"._CP_SA_DOCUMENT_MSG_1_."
				<br /><br />
			</td>
		</tr>
		</table>
	</div>

	</center>";

	return $content;
}

function DocumentSave($request){
	$content = null;

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

	$styleid = $request['styleid'];
	$docbgcol = $request['docbgcol'];
	$docbgim = $request['docbgim'];
	$docbgrep = $request['docbgrep'];
	$docbgpos = $request['docbgpos'];
	$docborstyle = $request['docborstyle'];
	$docborw = $request['docborw'];
	$docborcol = $request['docborcol'];

	$newbgfile = $request['newbgfile'];
	$ext_bg = $request['ext_bg'];
	$docbgim = $request['docbgim'];
	$replace_bg = $request['replace_bg'];

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

	$bgimage=$_FILES['new_docbgim']['tmp_name'];
	$bgimage_name=$_FILES['new_docbgim']['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/docbgimage.$ext_bg"))
			unlink ("./siteimages/docbgimage.$ext_bg");
		rename("./siteimages/temp_bgimage","./siteimages/docbgimage.$ext_bg");
		$docbgim="./siteimages/docbgimage.$ext_bg";
	}
	elseif ($docbgim!="" && !isset($replace_bg)){
		if (file_exists("./siteimages/temp_bgimage"))
			unlink("./siteimages/temp_bgimage");
	}
	else {
		if (file_exists("./siteimages/temp_bgimage"))
			unlink("./siteimages/temp_bgimage");
		$docbgim="";
	}
		
	/* Update the DB */
	$obj_style = $obj_styleengine->GetStyle($styleid);
	$obj_style->docbgcol = $docbgcol;
	$obj_style->docbgim = $docbgim;
	$obj_style->docbgrep = $docbgrep;
	$obj_style->docbgpos = $docbgpos;
	$obj_style->docborstyle = $docborstyle;
	$obj_style->docborw = $docborw;
	$obj_style->docborcol = $docborcol;
	if (!$obj_styleengine->UpdateStyle($obj_style))
		echo "Update error on Style Engine<br>";
	
	/* Create a new css file! */
	$obj_style = $obj_styleengine->GetStyle($styleid);
	CreateCSSFile($obj_style);
	
	/* Create a new styleedit file - for edition in the Content Management */
	CreateCSSEditFile($obj_style);
	
	ReDirection(basename($PHP_SELF)."?f=style&sf=document&operation=view");

	return $content;
}

function Document_Operation($request){
	$content = null;

	$operation = $request['operation'];

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

	return $content;
}

?>
Return current item: ChiCoMaS - Chilek CMS