Location: PHPKode > projects > ChiCoMaS - Chilek CMS > chicomas/objects/obj_pages.php
<?

/*********************************************************/
class CPage{

	var $page_id;
	var $ref_id;
	var $order_id;
	var $description;
	var $keywords;
	var $alias;
	var $active;
	var $menu_item;
	var $topmenu_item;
	var $page_type_id;
	var $order_by;

	var $title;
	var $charset;
	var $width;
	var $bodyposition;
	var $logoname;
	var $textlogo;
	var $action;

	function CPage($row=""){
		$this->page_id = $row["page_id"];
		$this->ref_id = $row["ref_id"];
		$this->order_id = $row["order_id"];
		$this->description = $row["description"];
		$this->keywords = $row["keywords"];
		$this->alias = $row["alias"];
		$this->active = $row["active"];
		$this->menu_item = $row["menu_item"];
		$this->topmenu_item = $row["topmenu_item"];
		$this->page_type_id = $row["page_type_id"];
		$this->order_by = "page_id";

		$this->title = $row["title"];
		$this->charset = $row["charset"];
		$this->width = $row["width"];
		$this->bodyposition = $row["bodyposition"];
		$this->logoname = $row["logoname"];
		$this->textlogo = $row["textlogo"];
		$this->action = $row["action"];
	}

	//*****************************************************************************
	//*****************************************************************************
	function RecursivePageSelect($pageid, $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;
				$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $thispageid, "name");
				$thisname = $obj_content->context;
				$content .= "<option value=\"".basename($PHP_SELF)."?pageid=$thispageid\">";
				$content .= "$braket";
				$content .= "$thisname</option>";;
				$content .= $this->RecursivePageSelect($thispageid, $recursivecount);
			}
		}
		else{
			$content = null;
			$recursivecount--;
			$braket = null;
		}

		return $content;
	}

	//*****************************************************************************
	//*****************************************************************************
	function html_sub_pages($pageid){
		$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();

		$recursivecount = 0;
		$obj_page = $obj_pageengine->GetPage($pageid);

		$thispageid = $pageid;
		$thisrefid = $obj_page->ref_id;

		if (($num_rows!=0) || ($thisrefid!=0)){

			if ($thisrefid==0)
				$thisrefid = $thispageid;
	
			$content = "
			<p class=\"mainpages\">";
	
			//Level 0
			$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $thispageid, "name");
			$thisname = $obj_content->context;
			$temp_level_0 = $thisname;
	
			//Level 1
			$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $thisrefid, "name");
			$thisname = $obj_content->context;
			if ($thisrefid!=$thispageid)
				$temp_level_1 = "<a href=\"".basename($PHP_SELF)."?pageid=".$thisrefid."\">".$thisname."</a> : ";
	
			//Level 2
			if ($thisrefid!=0){
				$obj_page = $obj_pageengine->GetPage($thisrefid);
	
				$thispageid = $thisrefid;
				$thisrefid = $obj_page->ref_id;
				if ($thisrefid==0)
					$thisrefid = $thispageid;
		
				$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $thisrefid, "name");
				$thisname = $obj_content->context;
				if ($thisrefid!=$thispageid)
					$temp_level_2 = "<a href=\"".basename($PHP_SELF)."?pageid=".$thisrefid."\">".$thisname."</a> : ";
			}
	
	
			$content .= $temp_level_2;
			$content .= $temp_level_1;
			$content .= $temp_level_0;
			$content .= "</p>";
	
	
	
			$recursivecount = 0;
			$obj_page = $obj_pageengine->GetPage($pageid);
	
			$content .= "
			<form name=\"quicklink\" action='".basename($PHP_SELF)."' method='post'>
			<p class=\"subpages\">
			";
				$content .= "
				<select name=\"pageid\" onChange=\"window.location=document.quicklink.pageid.options[document.quicklink.pageid.selectedIndex].value;\">";
					$thispageid = $pageid;
					$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $thispageid, "name");
					$thisname = $obj_content->context;
					$content .= "<option value=\"".basename($PHP_SELF)."?pageid=$thispageid\">$thisname</option>";
					$content .= $this->RecursivePageSelect($thispageid, $recursivecount);
				$content .= "
				</select>";
				//<input type=\"submit\" value=\""._CMN_GO_."\" />";
			$content .= "
			</p>
			</form>
			<br /><br />
			";
		}
		return $content;
	}

	//*****************************************************************************
	//*****************************************************************************
	function html_header_begin(){

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

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


		if ($this->page_id!="-1"){
			$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $this->page_id, "name");
			$name = $obj_content->context;
	
			$obj_page = $obj_pageengine->GetPage($this->page_id);
			$thiskeywords = $this->keywords;
			$thisdescription = $this->description;
			if ($thiskeywords!="") $this->keywords=$thiskeywords;
			if ($thisdescription!="") $this->description=$thisdescription;
		}

		echo "
		<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
		\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
		<html xmlns=\"http://www.w3.org/1999/xhtml\">
		<head>
		<title>$this->title</title>
		<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-9\" />
		<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$this->charset\" />
		<meta name=\"keywords\" content=\"$this->keywords\" />
		<meta name=\"description\" content=\"$this->description\" />
		<meta name=\"robots\" content=\"index,follow\" />
		<link href='style.css' rel='stylesheet' />";
	}

	//*****************************************************************************
	//*****************************************************************************
	function html_header_end(){
		echo "
		</head>
		";
	}

	//*****************************************************************************
	//*****************************************************************************
	function html_body_begin(){
		$obj_page = new CPage();
		$obj_pagearray = new CPageArray();
		$obj_pageengine = new CPageEngine();
		
		$obj_language = new CLanguage();
		$obj_languagearray = new CLanguageArray();
		$obj_languageengine = new CLanguageEngine();

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

		/* Read out the top-level sections from the DB */
		$obj_pagearray = $obj_pageengine->GetTopMenuItems();

		echo "<body>";
	
		$obj_languagearray = $obj_languageengine->GetLanguages($active=1);
		$num_rows = $obj_languagearray->count();
	
		echo "
		<div align=\"$this->bodyposition\">
		<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"width: $this->width\">
		<tr><td align=\"left\" valign=\"top\">";

		while( $obj_page = $obj_pagearray->get() ){
			$page_id=$obj_page->page_id;

			$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $page_id, "name");
			$name = $obj_content->context;
			//$language=$obj_page->language;
			//$lang=$obj_page->lang;
			//$image_path=$obj_page->image_path;
			echo "
			<p class=\"topmenu\"><a href=\"".basename($PHP_SELF)."?pageid=".$page_id."\">$name</p>";
		}

		while( $obj_language = $obj_languagearray->get() ){
			$language_id=$obj_language->language_id;
			$language=$obj_language->language;
			$lang=$obj_language->lang;
			$image_path=$obj_language->image_path;
			echo "
			<a href=\"".basename($PHP_SELF)."?lang=$lang\">
				<img class=\"flags\" src=\"$image_path\" alt=\"$language\" width=25 height=15 border=0>
			</a>";
		}
		echo "
		</div>
		</td></tr>

		<tr>
		<td class=\"document\" align=\"left\" valign=\"top\">
		";
	}

	//*****************************************************************************
	//*****************************************************************************
	function html_body_end($message){
		echo "
		</td>
		</tr>
		<tr>
			<td class=\"indocument\" align=\"center\" style=\"font-size: 10px;\">
				$message
				<br />
				<a href=\"".PROJECT_WEB."\" title=\"".PROJECT_NAME."\" style=\"font-size: 10px;\" target=\"_blank\"><strong>".PROJECT_NAME.PROJECT_COPYRIGHT."</strong></a>
				<br />Ver : ".PROJECT_VERSION."<br />
			</td>
		</tr>

		</table>
		</div>
		";
	}

	//*****************************************************************************
	//*****************************************************************************
	function html_logo_bar(){
		echo "
		<div id=\"head\">
		<table width=\"100%\">
		<tr>
			<td align=\"left\" valign=\"middle\">";
				if ($this->logoname!="")
					echo "<a href=\"index.php\" title=\"$this->textlogo\"><img src=\"./siteimages/$this->logoname\" border=\"0\" alt=\"$this->textlogo\" /></a>";
				else
					echo "<br />
					&nbsp; &nbsp;
					<a href=\"".basename($PHP_SELF)."\" title=\"$this->textlogo\">$this->textlogo</a>
					<br /><br />
					";
				echo "
			</td>
		</tr>
		</table>
		</div>
		</td>
		</tr>
		<tr>
		<td class=\"indocument\" valign=\"top\" align=\"left\"> 
		";
	}

	//*****************************************************************************
	/* Main menu - reads out from the DB the main sections of the document */
	//*****************************************************************************
	function html_main_menu(){
	
		$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_content = new CContent();
		$obj_contentarray = new CContentArray();
		$obj_contentengine = new CContentEngine();
	
		/* Read out the top-level sections from the DB */
		$obj_pagearray = $obj_pageengine->GetParentMenuItems(1);
	
		/* Begin the menu */
		echo "
			<div id=\"mainContainer\" align=\"left\">
			<div id=\"leftContainer\">
				<!--- START MENU HTML -->
				<div id=\"dhtmlgoodies_menu\">
				<ul>
				";
	
				/* Create the menu dynamically */
				while( $obj_page = $obj_pagearray->get() ){
					$thispageid = $obj_page->page_id;
	
					$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $thispageid, "name");
					$name = $obj_content->context;
	
					echo "<li><a href=\"".basename($PHP_SELF)."?pageid=$thispageid\"\">$name</a>";
	
					$obj_subpagearray = $obj_pageengine->GetChildMenuItems($thispageid, 1);
					$sub_num_rows = $obj_pagearray->count();
					
					if ($sub_num_rows!=0){
						echo "<ul>";
						while( $obj_subpage = $obj_subpagearray->get() ){
							$thissubpageid = $obj_subpage->page_id;
							$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $thissubpageid, "name");
							$subname = $obj_content->context;
						echo "<li><a href=\"".basename($PHP_SELF)."?pageid=$thissubpageid\"\">$subname</a></li>";
						}
						echo "</ul>";
					}
					echo "</li>";
				}
				echo "
				</ul>
				</div>
				<!-- END MENU HTML-->
			</div>	
		</div>
		";
	}
	//*****************************************************************************
	/* Permissions of Admin menu options*/
	//*****************************************************************************
	function permission_of($permission){
		$obj_tempdbarray = new CTempDBArray();
		$obj_tempdbengine = new CTempDBEngine();

		$obj_tempdb2array = new CTempDBArray();
		$obj_tempdb2engine = new CTempDBEngine();

		$SQL = "SELECT * FROM permissions ";
		$SQL .= "WHERE active='1' ";
		$SQL .= "AND permission_tag='".strtolower($permission)."' ";
		$row = $obj_tempdbengine->GetRow($SQL);
		if ($row!=null){
			$permission_id = $row['permission_id'];
			$SQL2 = "SELECT * FROM group_permissions ";
			$SQL2 .= "WHERE group_id='".intval($_SESSION['gid'])."' ";
			$SQL2 .= "AND permission_id='".intval($permission_id)."' ";
			$row2 = $obj_tempdb2engine->GetRow($SQL2);
			if ($row2!=null)
				return true;
			else
				return false;
		}
		else
			return false;
	}

	//*****************************************************************************
	function html_login_screen(){
		echo "
		<br />
		<center>
		<form action=\"./modules/login/login.php\" method=\"post\">
		<fieldset>
		<legend>"._CP_FORM_LOGIN_."</legend>
			<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
			<tr>
				<td><label for=\"username\">"._CMN_EMAIL_."</label></td>
			</tr>
			<tr>
				<td><input type=\"text\" name=\"username\" value=\"$username\" size=\"18\" maxlength=\"64\" /></td>
			</tr>
			<tr>
				<td><label for=\"password\">"._CMN_PASSWORD_."</label></td>
			</tr>
			<tr>
				<td><input type=\"password\" name=\"password\" value=\"$password\" size=\"18\" maxlength=\"16\"/></td>
			</tr>
			</table>
			<input type=\"image\" class=\"submitimage\" src=\"images/icon24/login.png\" height=\"24\" width=\"24\" border=\"0\" alt=\"Submit\">
			<br /><br />";
			if ($GLOBALS['user_signup'])
				echo "<a href=".basename($PHP_SELF)."?f=signup>"._CMN_SIGN_UP_."</a><br />";
			if ($GLOBALS['user_getpassword'])
				echo "<a href=".basename($PHP_SELF)."?f=getpassword>"._CMN_FORGOTTEN_PASSWORD_."</a><br />";

		if (($this->action==1) | ($this->action==2)){
			echo "<i>"._CP_LOGIN_ERROR_."</i>";
		}
		if ($this->action==3){
			echo "<i>"._CP_DO_LOGIN_."</i>";
		}
		echo "
		</fieldset>
		<input type=hidden name=\"home\" value=\"true\"/>
		</form>
		</center>";
		//<input type=\"submit\" name=\"submit\" value=\""._CP_LOGIN_."\" style=\"float:center;\"/>
	}

	//*****************************************************************************
	//*****************************************************************************
	function html_user_screen(){
		echo "
		<center>
		<br />
		<fieldset>
		<legend>"._CP_FORM_LOGIN_."</legend>";
			$username = $_SESSION['uname'];
			if (strlen($username)>12)
				$username = substr($_SESSION['uname'],0,12)."~";
			echo "<strong>".$username."</strong><br />";
			if ($_SESSION['mode']=="admin")
				echo "<a href=\"".basename($PHP_SELF)."?mode=user\"><img src=\"images/icon/home.png\" width=\"24\" height=\"24\" border=\"0\" /></a>";
			else
				echo "<a href=\"".basename($PHP_SELF)."?mode=admin\"><img src=\"images/icon/setup.png\" width=\"24\" height=\"24\" border=\"0\" /></a>";
			echo "	
			<a href=\"".basename($PHP_SELF)."?f=logout\"><img src=\"images/icon/logout.png\" width=\"24\" height=\"24\" border=\"0\" /></a>
		</fieldset>
		<br />
		</center>";
	}

	//*****************************************************************************
	//*****************************************************************************
	function html_search_screen($q){
		echo "
		<form action=\"".basename($PHP_SELF)."?f=search\" method=\"post\">
		<fieldset>
		<legend>"._CMN_FROM_SEARCH_."</legend>
			<input type=\"text\" name=\"q\" value=\"$q\" size=\"8\" maxlength=\"16\"/>
			<input type=\"image\" class=\"submitimage\"src=\"images/icon24/search.png\" height=\"24\" width=\"24\" border=\"0\" alt=\"Submit\"><br /><br />
		</fieldset>
		</form>
		<br />";
		//<input type=\"submit\" name=\"submit\" value=\""._CMN_SEARCH_."\" style=\"float:center;\"/>
	}

	//*****************************************************************************
	//*****************************************************************************
	function html_donation(){
		if ($_SERVER['SERVER_PORT']=='80') {
			echo "<a target=\"_blank\" href=\"http://www.chicomas.com\"><img border=\"0\" alt=\"ChiCoMaS\" title=\"ChiCoMaS\" src=\"http://www.chicomas.com/images/logo/chicomas_120x60.jpg\"/></a>
			<br />
			";
	
			echo "<a target=\"_blank\" href=\"http://www.spreadfirefox.com/?q=affiliates&amp;id=187901&amp;t=195\"><img border=\"0\" alt=\"Upgrade to Firefox 1.5!\" title=\"Upgrade to Firefox 1.5!\" src=\"http://sfx-images.mozilla.org/affiliates/Buttons/120x60/trust.gif\"/></a>
			<br />
			";
		}
	}

	//*****************************************************************************
	//*****************************************************************************
	function html_document($content, $request, $user_modules){
		$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();

		$f = $request['f'];
		//$sf = $request['sf'];
		$q = $request['q'];

		if ($this->page_id!="-1"){
			$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $this->page_id, "name");
			$name = $obj_content->context;
	
			$obj_page = $obj_pageengine->GetPage($this->page_id);
			$refid = $obj_page->ref_id;
			$pagetypeid = $obj_page->page_type_id;
			$active = $obj_page->active;

			if (!IsLogin()){
				$_SESSION['mode']="user";
			}

			if ($_SESSION['mode']=="user"){
				if (!$user_modules){
					$obj_content = $obj_contentengine->GetContent(ActiveLanguage(), $this->page_id, "content");
					if (($obj_content!=null) && ($active)){
						$content = $obj_content->context;
						//echo "CONTENT OK : $content<br />";
						//Hit Counter for User mode
						$hitcounter = $obj_content->hit_counter;
						$hitcounter++;
						$obj_content->hit_counter = $hitcounter;
						if (!$obj_contentengine->UpdateContent(ActiveLanguage(), $obj_content, "content"))
							echo "ERROR on hitcounter:$hitcounter UPDATE<br />";
					}
					else{
						$content .= _NO_CONTENT_FOUND_;
					}
				}
			}
		}

		echo "
		<table width=\"100%\">
		<tr>";
			if ($_SESSION['mode']=="user"){
				echo "
				<td width=\"200px\" align=\"center\" valign=\"top\">";
					$this->html_main_menu();

					if (!IsLogin())
						$this->html_login_screen($action);
					else
						$this->html_user_screen();

					$this->html_search_screen($q);
					$this->html_donation();

				echo "
				</td>";
			}

			echo "
			<td width=\"100%\" align=\"center\" valign=\"top\">

				<table width=\"95%\">
				<tr>
					<td valign=\"top\" align=\"left\">";
						if ($_SESSION['mode']=="user"){
							if ($this->page_id!="-1"){
								$obj_pagetype = $obj_pagetypeengine->GetPageType($pagetypeid);
								if (($obj_pagetype!=null) && ($active)){
									$pagefile = $obj_pagetype->page_file;
									if (!file_exists($pagefile)){
										//Content is here...
										$obj_pagetype = $obj_pagetypeengine->GetPageType($pagetypeid);
										echo $this->html_sub_pages($this->page_id);
										echo $content;
									}
									else
										if ($user_modules)
											echo $content;
										else
											require($pagefile);
								}
								else
									echo _NO_PAGE_FOUND_;
							}
						}
						else
							echo $content;
						echo "
						<br/>
					</td>
				</tr>
				</table>
			</td>
		</tr>
		</table>";
	}

	//*****************************************************************************
	//*****************************************************************************
	function html_footer(){
		echo "
		</body>
		</html>
		";
	}

}

/*********************************************************/
class CPageArray{
	var $pages=array();
	var $top=0;
	var $count=0;
	
	function get(){
		if ($this->top <= $this->count){
			$this->top++;			
			return $this->users[$this->top-1];
		}
		else 
			return false;
	}

	function add($CPage) {
		$this->users[$this->count] = $CPage;
		$this->count++;				
		return true;
	}
	
	function count() {
		return ($this->count);
	}
}

/*********************************************************/
class CPageEngine {
	function GetPage($page_id){
		$o_dataaccess = new CDataAccess();
		return $o_dataaccess->GetPage($page_id);
	}

	function GetParentPages($active){
		$o_dataaccess = new CDataAccess();
		return $o_dataaccess->GetParentPages($active);
	}

	function GetChildPages($parent_page_id, $active){
		$o_dataaccess = new CDataAccess();
		return $o_dataaccess->GetChildPages($parent_page_id, $active);
	}

	function GetChildPagesCount($active){
		$o_dataaccess = new CDataAccess();
		return $o_dataaccess->GetChildPagesCount($active);
	}

	function GetParentMenuItems(){
		$o_dataaccess = new CDataAccess();
		return $o_dataaccess->GetParentMenuItems();
	}

	function GetChildMenuItems($parent_page_id){
		$o_dataaccess = new CDataAccess();
		return $o_dataaccess->GetChildMenuItems($parent_page_id);
	}

	function GetTopMenuItems(){
		$o_dataaccess = new CDataAccess();
		return $o_dataaccess->GetTopMenuItems();
	}

	function GetPagesByPageType($pagetypeid) {
		$o_dataaccess = new CDataAccess();
		return $o_dataaccess->GetPagesByPageType($pagetypeid);
	}

	function InsertPage($CPage){
		$o_dataaccess = new CDataAccess();
		return $o_dataaccess->InsertPage($CPage);
	}

	function UpdatePage($CPage){
		$o_dataaccess = new CDataAccess();
		return $o_dataaccess->UpdatePage($CPage);
	}

	function DeletePage($page_id){
		$o_dataaccess = new CDataAccess();
		return $o_dataaccess->DeletePage($page_id);
	}

	function DeletePageByRef($page_id){
		$o_dataaccess = new CDataAccess();
		return $o_dataaccess->DeletePageByRef($page_id);
	}

}
?>
 
Return current item: ChiCoMaS - Chilek CMS