Location: PHPKode > projects > ChiCoMaS - Chilek CMS > chicomas/modules/contact/contact_us.php
<?
defined( '_VALID_DA_' ) or die( 'Direct Access to this location is not allowed.' );

function Begin_Script($request){

	$content = "

	<div id=\"navcontainer\">
	<ul id=\"navlist\">";

	$pageid = $request['pageid'];
	$sf = $request['sf'];
	$messages = $request['messages'];
	if (!isset($messages))
		$messages=0;

	$current = "id=\"current\"";
	$active = "id=\"active\"";

	switch ($sf){
	default:
		if (!$messages){
			$content .= "<li $active><a href=\"".basename($PHP_SELF)."?pageid=".$pageid."\" $current>"._CP_CA_SEND_MESSAGE_."</a></li>";
	
			$content .= "<li><a href=\"".basename($PHP_SELF)."?pageid=".$pageid."&messages=1\">"._CP_CA_READ_MESSAGES_."</a></li>";
		}
		else{
			$content .= "<li><a href=\"".basename($PHP_SELF)."?pageid=".$pageid."\">"._CP_CA_SEND_MESSAGE_."</a></li>";
		
			$content .= "<li $active><a href=\"".basename($PHP_SELF)."?pageid=".$pageid."&messages=1\" $current>"._CP_CA_READ_MESSAGES_."</a></li>";
		}
	break;
	}


	$content .= "
	</ul>
	</div>";

	return $content;

};

//***********************************************
function Run_Module($request){

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

	if ($messages)
		$operation = "messages";

	$content = Begin_Script($request);

	switch ($operation){
	default:
	case "contactus":

		$content .= "
		<center>
		<form action='".basename($PHP_SELF)."' method='post'>
		<input type=\"hidden\" name=\"operation\" value=\"save\" />
		<input type=\"hidden\" name=\"pageid\" value=\"$pageid\" />
		<fieldset>
		<img style=\"float:right;\" src=\"./images/icon48/contacts.png\" width=\"48\" height=\"48\" border=\"0\">
		<legend>"._UP_CONTACT_US_."</legend>
			"._UP_CONTACT_US_MSG_."<br><br>
			<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\">
			<tr>
				<td><label for=\"postname\">"._UP_CU_NAME_SURNAME_."</label></td>
				<td><input type=\"text\" name=\"postname\" value=\"$postname\" style=\"float:left;\" size=\"32\" maxlength=\"64\"/></td>
			</tr>

			<tr>
				<td><label for=\"postemail\">"._UP_CU_EMAIL_."</label></td>
				<td><input type=\"text\" name=\"postemail\" value=\"$postemail\" style=\"float:left;\" size=\"32\" maxlength=\"64\"/></td>
			</tr>

			<tr>
				<td><label for=\"postheader\">"._UP_CU_HEADER_."</label></td>
				<td><input type=\"text\" name=\"postheader\" value=\"$postheader\" style=\"float:left;\" size=\"40\" maxlength=\"64\"/></td>
			</tr>

			<tr>
				<td><label for=\"postcontent\">"._UP_CU_MESSAGE_."</label></td>
				<td><textarea name=\"postcontent\" cols=40 rows=15 wrap=soft style=\"float:left;\">".$postcontent."</textarea></td>
			</tr>

			<tr>
				<td colspan=\"2\" align=\"center\">
					<br>";
					$content .= "<input type=\"submit\" value=\""._UP_CU_SUBMIT_BUTTON_."\" style=\"float:center;\"/>";
					$content .= go_back();
					$content .= "
				</td>
			</tr>
			</table>
			<br>
		</fieldset>
		</form>
		</center>";
	break;
	
	case "save":
		$my_validator = new validator();
	
		$obj_contactus = new CContactUs();
		$obj_contactusarray = new CContactUsArray();
		$obj_contactusengine = new CContactUsEngine();
	
		if (!$my_validator->validate_fields("postname"))
			$failed_postname = true;
		if (!$my_validator->validate_fields("postemail"))
			$failed_postemail = true;
		if (!$my_validator->validate_fields("postheader"))
			$failed_postheader = true;
		if (!$my_validator->validate_fields("postcontent"))
			$failed_postcontent = true;
	
		$content .= "
		<center>";
	
		if ((!$failed_postname) && (!$failed_postemail) && (!$failed_postheader) && (!$failed_postcontent)){
			$obj_contactus->active = 1;
			$obj_contactus->read = 0;
			$obj_contactus->post_name = $request['postname'];
			$obj_contactus->post_email = $request['postemail'];
			$obj_contactus->post_header = $request['postheader'];
			$obj_contactus->post_content = $request['postcontent'];
			$obj_contactus->post_date = get_datetime();
	
			$contactusid = $obj_contactusengine->InsertContactUsMessage($obj_contactus);
	
			//echo "contactusid:$contactusid<br>";
			$content .= "
			<div class=note>
				<h3>"._CMN_NOTE_."</h3>
				<p>";
					$content .= _UP_CU_COMPLETED_;
					$content .= "<br><br>";
					//$content .= go_back();
				$content .= "
				</p>
			</div>";
		}
		else{
			$content .= "
			<div class=note>
				<h3>"._CMN_NOTE_."</h3>
				<p>";
					$content .= _UP_CU_FORM_ERROR_."<br>";
					$content .= "<ul>";
					if ($failed_postname)
						$content .= "<li>"._UP_CU_NAME_SURNAME_;
					if ($failed_postemail)
						$content .= "<li>"._UP_CU_EMAIL_;
					if ($failed_postheader)
						$content .= "<li>"._UP_CU_HEADER_;
					if ($failed_postcontent)
						$content .= "<li>"._UP_CU_MESSAGE_;
					$content .= "</ul>";
					$content .= go_back();
				$content .= "
				</p>
			</div>";
		}
	
		$content .= "
		</center>
		<br>
		";
	break;
	case "messages":
		$obj_tempdbarray = new CTempDBArray();
		$obj_tempdbengine = new CTempDBEngine();
		
		//Toplam gosterilecek kayit sayisi
		$record = 20;
	
		$all = $request['all'];
		if (!isset($all))
			$all=0;
	
		$desc = $request['desc'];
		$orderby = $request['orderby'];
		//Sayfa Numarasi
		$page = $request['page'];
		if ($page<=0)
			$page = 1;

		$SQL = "SELECT * FROM contact_us ";
		$SQL .= "WHERE active=1 ";
		$SQL .= "AND published=1 ";
	
		$obj_tempdbarray = $obj_tempdbengine->GetRows($SQL);
	
		$total_record = $obj_tempdbarray->count();
		$max_page = ceil($total_record / $record);
	
		//$content .= "";
	
		if ($total_record>0){
	
			switch ($orderby){
			default:
					$SQL .= "ORDER BY contact_us_id DESC ";
			break;
			}
			
			$start = ($page-1)*$record;
			$SQL .= "LIMIT $start ,$record";
			
			//echo "SQL:$SQL<br>";
			$obj_tempdbarray = $obj_tempdbengine->GetRows($SQL);

			while( $row = $obj_tempdbarray->get() ){
				$postname = $row['post_name'];
				$postemail = $row['post_email'];
				$postheader = $row['post_header'];
				$postdate = $row['post_date'];
				$postcontent = $row['post_content'];

				$content .= "
				<p>
					<u>$postheader</u><br><br>
					<i>$postcontent</i><br><br>
					<font size=\"-1\" style=\"float:right\">$postname (<em>$postdate</em>)</font><br>
				</p>
				<hr>
				";
			}

			$content .= "<center>";
	
			if ($max_page>1){
				$fpage = 1;
				$lpage = $max_page;
				if ($page>1)
					$ppage = $page-1;
				else
					$ppage = 1;
			
				if ($page>=$max_page)
					$npage = $max_page;
				else
					$npage = $page+1;
			
				//Sayfa gosterimi
				$content .= "
				<a href=".basename($PHP_SELF)."?pageid=".$pageid."&messages=$messages&orderby=".$orderby."&desc=".intval($desc)."&page=".$fpage.">
					<img src=\"./images/icon16/left2.png\" width=\"16\" height=\"16\" border=\"0\">
				</a>
			
				<a href=".basename($PHP_SELF)."?pageid=".$pageid."&messages=$messages&orderby=".$orderby."&desc=".intval($desc)."&page=".$ppage.">
					<img src=\"./images/icon16/left.png\" width=\"16\" height=\"16\" border=\"0\">
				</a>
			
				<a href=".basename($PHP_SELF)."?pageid=".$pageid."&messages=$messages&orderby=".$orderby."&desc=".intval($desc)."&page=".$npage.">
					<img src=\"./images/icon16/right.png\" width=\"16\" height=\"16\" border=\"0\">
				</a>
			
				<a href=".basename($PHP_SELF)."?pageid=".$pageid."&messages=$messages&orderby=".$orderby."&desc=".intval($desc)."&page=".$lpage.">
					<img src=\"./images/icon16/right2.png\" width=\"16\" height=\"16\" border=\"0\">
				</a>
			
				<br><br>";
			}
			
			$content .= "<font size=\"-1\" style=\"float:none;\" >";
			$content .= _CMN_TOTAL_RECORD_.$total_record."<br>";
			$content .= _CMN_PAGE_.$page." / ".$max_page."<br>";
			$content .= "</center><br>";
		}
	}

	return $content;
}

$request = $_REQUEST;

echo Run_Module($request);


//***********************************************
?>
Return current item: ChiCoMaS - Chilek CMS