Location: PHPKode > projects > ChiCoMaS - Chilek CMS > chicomas/modules/structure/editpage_operation.php
<?
function RecursivePageSelect($pageid, $activepageid, $activerefid, $recursivecount){
	$content = null;

	$obj_page = new CPage();
	$obj_pagearray = new CPageArray();
	$obj_pageengine = new CPageEngine();

	$obj_content = new CContent();
	$obj_contentarray = new CContentArray();
	$obj_contentengine = new CContentEngine();

	$obj_pagearray = $obj_pageengine->GetChildPages($pageid, -1);
	$num_rows = $obj_pagearray->count();

	if ($num_rows!=0){
		$recursivecount++;
		for ( $counter = 1; $counter <= $recursivecount; $counter++)
			$braket = $braket."|--";
		while( $obj_page = $obj_pagearray->get() ){
			$thispageid=$obj_page->page_id;
			$thisrefid=$obj_page->ref_id;
			$thisactive=$obj_page->active;
			$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $thispageid, "name");
			$thisname = $obj_content->context;

			if ($thispageid==$activepageid)
				$disabled = "disabled";
			else
				$disabled = "";

			if ($thispageid==$activerefid)
				$selected="selected=\"selected\" style=\"background-color:gold;color:navy\"";
			else
				$selected="";

			if ($thisactive==0)
					$activepage="style=\"background-color:gray;color:white\"";
			else
				$activepage="";

			$content .= "<option value=\"$thispageid\" $selected $disabled $activepage>";
			$content .= "$braket";
			$content .= "$thisname</option>";;
			$content .= RecursivePageSelect($thispageid, $activepageid, $activerefid, $recursivecount);
		}
	}
	else{
		$content = null;
		$recursivecount--;
		$braket = null;
	}

	return $content;
}


function EditPageSelect(){
	$content = null;

	$obj_page = new CPage();
	$obj_pagearray = new CPageArray();
	$obj_pageengine = new CPageEngine();

	$obj_subpage = new CPage();
	$obj_subpagearray = new CPageArray();
	$obj_subpageengine = new CPageEngine();

	$obj_pagetype = new CPageType();
	$obj_pagetypearray = new CPageTypeArray();
	$obj_pagetypeengine = new CPageTypeEngine();

	$obj_content = new CContent();
	$obj_contentarray = new CContentArray();
	$obj_contentengine = new CContentEngine();

	global $recursivecount;

	if (!isset($f)) $f="structure";
	if (!isset($sf)) $sf="edit";

	$recursivecount = 0;
	$activepageid = 0;
	$activerefid = 0;
	$obj_pagearray = $obj_pageengine->GetParentPages(-1);
	$num_rows = $obj_pagearray->count();

	if ($num_rows!=0){
		$content = "
		<center>
		<form action='".basename($PHP_SELF)."?f=structure&sf=edit' method='post'>
		<input type=\"hidden\" name=\"operation\" value=\"editpage\" />
		<fieldset>
		<img style=\"float:right;\" src=\"./images/icon48/edit.png\" width=\"48\" height=\"48\" border=\"0\">
		<legend>"._CP_PA_EDIT_PAGE_."</legend>
			<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\">
			<tr>";
				if ($num_rows!=0){
					$content .= "
					<td align=\"left\">"._CP_PA_EP_SELECT_PAGE_."</td>
					<td align=\"left\">
						<select name=\"pageid\">
						";
						while( $obj_page = $obj_pagearray->get() ){
							$thispageid = $obj_page->page_id;
							$thisactive=$obj_page->active;
							$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $thispageid, "name");
							$thisname = $obj_content->context;
							if ($thisactive==0)
								$activepage="style=\"background-color:gray;color:white\"";
							else
								$activepage="";
							$content .= "<option value=\"$thispageid\" $activepage>$thisname</option>";
			
							$recursivecount = 0;
							$content .= RecursivePageSelect($thispageid, $activepageid, $activerefid, $recursivecount);
						}
						$content .= "
						</select>
					</td>
				</tr>
				<tr>
					<td colspan=\"2\" align=\"center\">
						<br>";
						$content .= "<input type=\"submit\" value=\""._CMN_SELECT_."\" style=\"float:center;\"/>";
						$content .= go_back();
						$content .= "
					</td>
				</tr>";
				}
			$content .= "
			</table>
			<br>
		</fieldset>
		</form>
		</center>";
	}
	else{
		$content = "
		<div class=note>
			<h3>"._CMN_NOTE_."</h3>
			<p>";
			$content .= "<img src=\"./images/icon48/warning.png\" alt=\"\" width=\"48\" height=\"48\" border=\"0\">";
			$content .= "<br><br>";
			$content .= _CP_NO_PAGE_FOUND_;
			$content .= "<br><br>";
			$content .= go_back();
			$content .= "
			</p>
		</div>
		";
	}

	return $content;
}

function EditPage($pageid){
	$content = null;

	$obj_page = new CPage();
	$obj_pagearray = new CPageArray();
	$obj_pageengine = new CPageEngine();

	$obj_pagetype = new CPageType();
	$obj_pagetypearray = new CPageTypeArray();
	$obj_pagetypeengine = new CPageTypeEngine();

	$obj_content = new CContent();
	$obj_contentarray = new CContentArray();
	$obj_contentengine = new CContentEngine();

	global $recursivecount;

	if (!isset($f)) $f="structure";
	if (!isset($sf)) $sf="edit";
	
	if (!isset($action)) $action="0";
	
	if (!isset($name)){
	
		$obj_page = $obj_pageengine->GetPage($pageid);
		$refid = $obj_page->ref_id;
		$orderid = $obj_page->order_id;
		$pagetypeid = $obj_page->page_type_id;
	
		$alias = $obj_page->alias;
		$active = $obj_page->active;
		$menuitem = $obj_page->menu_item;
		$topmenuitem = $obj_page->topmenu_item;
		$thisdescription = $obj_page->description;
		$thiskeywords = $obj_page->keywords;
	
		$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $pageid, "name");
		$name = $obj_content->context;
	
		$alias_old = $alias;
	}

	$activepageid = $pageid;
	$activerefid = $refid;
	$recursivecount = 0;
	$obj_pagearray = $obj_pageengine->GetParentPages(-1);
	$num_rows = $obj_pagearray->count();

	$content = "
	<center>
	<form action='".basename($PHP_SELF)."?f=structure&sf=edit' method='post'>
	<input type=\"hidden\" name=\"pageid\" value=\"$pageid\" />
	<input type=\"hidden\" name=\"alias_old\" value=\"$alias_old\" />
	<input type=\"hidden\" name=\"orderid\" value=\"$orderid\" />
	<input type=\"hidden\" name=\"operation\" value=\"editmenusave\" />
	<fieldset>
	<img style=\"float:right;\" src=\"./images/icon48/edit.png\" width=\"48\" height=\"48\" border=\"0\">
	<legend>"._CP_PA_EDIT_PAGE_."</legend>
		<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\">
		<tr>
			<td><label for=\"name\">"._CP_PA_NP_NAME_."</label></td>
			<td><input type=\"text\" name=\"name\" value=\"$name\" /></td>
		</tr>
		<tr>
			<td><label for=\"alias\">"._CP_PA_NP_ALIAS_."</label></td>
			<td><input type=\"text\" name=\"alias\" value=\"$alias\" /></td>
		</tr>
		<tr>
			<td><label for=\"thisdescription\">"._CP_PA_NP_DEFINITION_."</label></td>
			<td><input type=\"text\" name=\"thisdescription\" value=\"$thisdescription\" /></td>
		</tr>
		<tr>
			<td><label for=\"thiskeywords\">"._CP_PA_NP_KEYWORDS_."</label></td>
			<td><input type=\"text\" name=\"thiskeywords\" value=\"$thiskeywords\" /></td>
		</tr>
		<tr>
			<td><label for=\"refid\">"._CP_PA_NP_PARENT_OR_CHILD_."</label></td>
			<td>
				<select name=\"refid\">
				<option value=\"0\">"._CP_PA_NP_TOP_LEVEL_."</option>
				";
				if ($num_rows!=0){
					while( $obj_page = $obj_pagearray->get() ){
						$thisrefid = $obj_page->page_id;
						$thisactive=$obj_page->active;
						$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $thisrefid, "name");
						$thisname = $obj_content->context;
						if ($thisrefid==$pageid)
							$disabled = "disabled";
						else
							$disabled = "";
	
						if ($thisrefid==$refid)
							$selected="selected=\"selected\" style=\"background-color:gold;color:navy\"";
						else
							$selected="";
	
						if ($thisactive==0)
							$activepage="style=\"background-color:gray;color:white\"";
						else
							$activepage="";
	
						$content .= "<option value=\"$thisrefid\" $selected $disabled $activepage>$thisname</option>";
	
						$recursivecount = 0;
						$content .= RecursivePageSelect($thisrefid, $activepageid, $activerefid, $recursivecount);
					}
				}
	
				$content .= "
				</select>
			</td>
		</tr>

		<tr>
			<td><label for=\"active\">"._CP_PA_NP_STATUS_."</label></td>
			<td>";
				$selected0="";
				$selected1="";
				if ($active==0)
					$selected0="selected=\"selected\" style=\"background-color:gray;color:white\"";
				if ($active==1)
					$selected1="selected=\"selected\" style=\"background-color:gold;color:navy\"";
				$content .= "
				<select name=\"active\">
				<option value=\"0\" $selected0>"._CP_PA_NP_NOT_ACTIVE_."</option>
				<option value=\"1\"  $selected1>"._CP_PA_NP_ACTIVE_."</option>
				</select>
			</td>
		</tr>

		<tr>
			<td><label for=\"menuitem\">"._CP_PA_NP_VIEW_ON_MAINMENU_."</label></td>
			<td>";
				$selected0="";
				$selected1="";
				if ($menuitem==0)
					$selected0="selected=\"selected\" style=\"background-color:gold;color:navy\"";
				if ($menuitem==1)
					$selected1="selected=\"selected\" style=\"background-color:gold;color:navy\"";
				$content .= "
				<select name=\"menuitem\">
				<option value=\"0\" $selected0>"._CMN_NO_."</option>
				<option value=\"1\" $selected1>"._CMN_YES_."</option>
				</select>
			</td>
		</tr>

		<tr>
			<td><label for=\"topmenuitem\">"._CP_PA_NP_VIEW_ON_TOPMENU_."</label></td>
			<td>";
				$selected0="";
				$selected1="";
				if ($topmenuitem==0)
					$selected0="selected=\"selected\" style=\"background-color:gold;color:navy\"";
				if ($topmenuitem==1)
					$selected1="selected=\"selected\" style=\"background-color:gold;color:navy\"";
				$content .= "
				<select name=\"topmenuitem\">
				<option value=\"0\" $selected0>"._CMN_NO_."</option>
				<option value=\"1\" $selected1>"._CMN_YES_."</option>
				</select>
			</td>
		</tr>

		<tr>
			<td><label for=\"pagetypeid\">"._CP_PA_NP_TYPE_."</label></td>
			<td>
				<select name=\"pagetypeid\">";
					$obj_pagetypearray = $obj_pagetypeengine->GetPageTypes(1);
					while( $obj_pagetype = $obj_pagetypearray->get() ){
						$thispagetypeid = $obj_pagetype->page_type_id;
						$thispagetype = $obj_pagetype->page_type;
						if ($pagetypeid==$thispagetypeid)
							$selected="selected=\"selected\" style=\"background-color:gold;color:navy\"";
						else 
							$selected = "";
						$content .= "<option value=\"$thispagetypeid\" $selected>$thispagetype</option>";
					}
				$content .= "
				</select>
			</td>
		</tr>

		<tr>
			<td colspan=\"2\" align=\"center\">
				<br>";
				$content .= "<input type=\"submit\" value=\""._CMN_SAVE_."\" style=\"float:center;\"/>";
				$content .= go_back();
				$content .= "
			</td>
		</tr>
		</table>
		<br>
	</fieldset>
	</form>
	</center>";

	return $content;

}

function EditPageSave($request){

	$content = null;

	$obj_page = new CPage();
	$obj_pagearray = new CPageArray();
	$obj_pageengine = new CPageEngine();

	$obj_pagetype = new CPageType();
	$obj_pagetypearray = new CPageTypeArray();
	$obj_pagetypeengine = new CPageTypeEngine();

	$obj_content = new CContent();
	$obj_contentarray = new CContentArray();
	$obj_contentengine = new CContentEngine();

	$my_validator = new validator();

	$name = $request['name'];
	$pageid = $request['pageid'];
	$alias = $request['alias'];
	$thisdescription = $request['thisdescription'];
	$thiskeywords = $request['thiskeywords'];
	$active = $request['active'];
	$menuitem = $request['menuitem'];
	$topmenuitem = $request['topmenuitem'];
	$refid = $request['refid'];
	$orderid = $request['orderid'];
	$pagetypeid = $request['pagetypeid'];

	if (!$my_validator->validate_fields("name")) {
		//echo $my_validator->error;
		$failed = true;
	}
	else {
		$obj_content->context = $name;
		$obj_content->page_id = $pageid;
		if (!$obj_contentengine->UpdateContent(ActiveLanguage(), $obj_content, "name"))
			echo "Update Error on ContentEngine<br>";
	
		$obj_page->page_id = $pageid;
		$obj_page->description = $thisdescription;
		$obj_page->keywords = $thiskeywords;
		$obj_page->active = $active;
		$obj_page->menu_item = $menuitem;
		$obj_page->topmenu_item = $topmenuitem;
		$obj_page->alias = $alias;
		$obj_page->ref_id = $refid;
	
		$obj_page->order_id = $orderid;
		$obj_page->page_type_id = $pagetypeid;
		if (!$obj_pageengine->UpdatePage($obj_page))
			echo "Update Error on PageEngine<br>";
	
		if ($alias!="" && $alias!=$alias_old){
			$file = "./.htaccess";
			$file_cont=file_get_contents($file);
			$file_cont_new=str_replace("$alias_old","$alias",$file_cont);
			$handle=fopen($file,"w");
			fwrite($handle,$file_cont_new);
			fclose($handle);
		}
	}
	
	/* Create the page */
	if (!isset($f)) $f="structure";
	if (!isset($sf)) $sf="edit";

	$content .= "
	<div class=note>
		<h3>"._CMN_NOTE_."</h3>
		<p>";
		if (!$failed){
			$content .= "<img src=\"./images/icon48/info.png\" alt=\"\" width=\"48\" height=\"48\" border=\"0\">";
			$content .= "<br><br>";
			$content .= _CP_PA_EP_COMPLETED_;
		}
		else{
			$content .= _CP_PA_EP_ERROR_."
			<center>";
			$content .= "<img src=\"./images/icon48/warning.png\" alt=\"\" width=\"48\" height=\"48\" border=\"0\">";
			$content .= "<br><br>";
			$content .= go_back();
		}
		$content .= "
		</p>
	</div>
	";

	return $content;
}

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

	$pageid = $request['pageid'];
	$operation = $request['operation'];

	switch ($operation){
	default:
	case 'editpageselect':
		$content = EditPageSelect();
	break;
	case 'editpage':
		$content = EditPage($pageid);
	break;
	case 'editmenusave':
		$content = EditPageSave($request);
	break;
	}

	return $content;
}

?>

Return current item: ChiCoMaS - Chilek CMS