Location: PHPKode > projects > ChiCoMaS - Chilek CMS > chicomas/modules/contact/contact_operation.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\">";

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

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

	$content .= "<li><a href=\"".basename($PHP_SELF)."?mode=admin\">"._CONTROL_PANEL_."</a></li>";

	switch ($sf){
	default:
	case 'messages':
		if (!$all){
			$content .= "<li $active><a href=\"".basename($PHP_SELF)."?f=contact&sf=messages\" $current>"._CP_CA_NEW_MESSAGES_."</a></li>";
	
			$content .= "<li><a href=\"".basename($PHP_SELF)."?f=contact&sf=messages&all=1\">"._CP_CA_ALL_MESSAGES_."</a></li>";
		}
		else{
			$content .= "<li><a href=\"".basename($PHP_SELF)."?f=contact&sf=messages\">"._CP_CA_NEW_MESSAGES_."</a></li>";
		
			$content .= "<li $active><a href=\"".basename($PHP_SELF)."?f=contact&sf=messages&all=1\" $current>"._CP_CA_ALL_MESSAGES_."</a></li>";
		}
	break;
	}


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

	return $content;

};

function End_Script(){
	$content = "
	</center>";

	return $content;

};

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

	$content = null;

	$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 ";
	if (!$all)
	$SQL .= "AND read_message=0 ";

	$obj_tempdbarray = $obj_tempdbengine->GetRows($SQL);

	$total_record = $obj_tempdbarray->count();
	$max_page = ceil($total_record / $record);

	$content = "<center>";

	if ($total_record>0){

		switch ($orderby){
		default:
				$SQL .= "ORDER BY contact_us_id ";
		break;
		case 'name':
				$SQL .= "ORDER BY post_name ";
		break;
		case 'header':
				$SQL .= "ORDER BY post_header ";
		break;
		case 'date':
				$SQL .= "ORDER BY post_date ";
		break;
		}
		
		$start = ($page-1)*$record;
		$SQL .= "LIMIT $start ,$record";
		
		//echo "SQL:$SQL<br>";
		$obj_tempdbarray = $obj_tempdbengine->GetRows($SQL);
	
		$content .= "
	
		<table width=\"100%\" cellpadding=\"3\" cellspacing=\"3\" border=\"1\">
		<tbody>
			<th><a href=".basename($PHP_SELF)."?f=contact&sf=messages&all=$all&orderby=name&desc=".intval($desc).">"._CP_CA_POST_NAME_."<br>("._CP_CA_POST_EMAIL_.")</a></th>
			<th><a href=".basename($PHP_SELF)."?f=contact&sf=messages&all=$all&orderby=header&desc=".intval($desc).">"._CP_CA_POST_HEADER_."</a></th>
			<th><a href=".basename($PHP_SELF)."?f=contact&sf=messages&all=$all&orderby=date&desc=".intval($desc).">"._CP_CA_POST_DATE_."</a></th>
			<th>"._CP_CA_PUBLISHED_."</th>
			<th>"._CP_CA_READ_."</th>
			<th>"._CP_CA_DELETE_."</th>
		</tbody>";
	
		while( $row = $obj_tempdbarray->get() ){
			$messageid = $row['contact_us_id'];
			$postname = $row['post_name'];
			$postemail = $row['post_email'];
			$postheader = $row['post_header'];
			$postdate = $row['post_date'];
			$published = $row['published'];
			$content .= "
			<tr>
				<td align=\"center\">$postname<br>$postemail</td>
				<td align=\"center\">$postheader</td>
				<td align=\"center\">$postdate</td>
				<td align=\"center\">";
				if ($published)
					$content .= "<img border=0 src=\"images/icon/check.png\">";
				else
					$content .= "<img border=0 src=\"images/icon/disable.png\">";
				$content .= "
				</td>

				<td align=\"center\"><a href=".basename($PHP_SELF)."?f=contact&sf=read&all=$all&messageid=$messageid><img border=0 src=\"images/icon/read.jpg\"></a></td>

				<td align=\"center\"><a href=".basename($PHP_SELF)."?f=contact&sf=delete&all=$all&messageid=$messageid><img border=0 src=\"images/icon/remove.gif\"></a></td>
			</tr>";
		}
		$content .= "</table><br>";
	
		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)."?f=contact&sf=messages&all=$all&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)."?f=contact&sf=messages&all=$all&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)."?f=contact&sf=messages&all=$all&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)."?f=contact&sf=messages&all=$all&orderby=".$orderby."&desc=".intval($desc)."&page=".$lpage.">
				<img src=\"./images/icon16/right.png\" width=\"16\" height=\"16\" border=\"0\">
			</a>
		
			<br><br>";
		}
		
		$content .= _CMN_TOTAL_RECORD_.$total_record."<br>";
		$content .= _CMN_PAGE_.$page." / ".$max_page."<br>";
		$content .= "<br>";
	
	}
	else{
		$content .= "
		<div class=note>
			<h3>"._CMN_NOTE_."</h3>
			<p>";
				$content .= _CP_CA_NO_NEW_MESSAGE_;
				$content .= "<br><br>";
				//$content .= go_back();
			$content .= "
			</p>
		</div>";
	}

	return $content;
}

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

	$content = null;

	$obj_tempdbarray = new CTempDBArray();
	$obj_tempdbengine = new CTempDBEngine();

	$messageid = $request['messageid'];
	$all = $request['all'];

	$SQL  = "UPDATE contact_us ";
	$SQL .= "SET ";
	$SQL .= "read_message = '1', ";
	$SQL .= "read_date = '".get_datetime."' ";
	$SQL .= "WHERE contact_us_id=".intval($messageid);
	
	if (!$obj_tempdbengine->ExecQuery($SQL))
		$content .= "<br>Update Error on ExecQuery<br>";


	$SQL = "SELECT * FROM contact_us ";
	$SQL .= "WHERE contact_us_id='".intval($messageid)."' ";

	$row = $obj_tempdbengine->GetRow($SQL);
	$postname = $row['post_name'];
	$postemail = $row['post_email'];
	$postheader = $row['post_header'];
	$postcontent = $row['post_content'];
	$postdate = $row['post_date'];
	$published = $row['published'];
	if ($published)
		$published = " checked ";

	$content .= "
	<center>
	<form action='".basename($PHP_SELF)."?f=contact&sf=save' method='post'>
	<input type=\"hidden\" name=\"messageid\" value=\"$messageid\" />
	<input type=\"hidden\" name=\"all\" value=\"$all\" />
	<fieldset>
	<img style=\"float:right;\" src=\"./images/icon48/contacts.png\" width=\"48\" height=\"48\" border=\"0\">
	<legend>"._CP_CA_POST_CONTENT_."</legend>
		<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\">
		<tr>
			<td><label for=\"published\">"._CP_CA_PUBLISHED_."</label></td>
			<td><input type=\"checkbox\" name=\"published\" $published style=\"float:left;\"/></td>
		</tr>

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

		<tr>
			<td><label for=\"postemail\">"._CP_CA_POST_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\">"._CP_CA_POST_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\">"._CP_CA_POST_CONTENT_."</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=\""._CMN_SAVE_."\" style=\"float:center;\"/>";
				$content .= go_back();
				$content .= "
			</td>
		</tr>
		</table>
		<br>
	</fieldset>
	</form>
	</center>";

	return $content;
}

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

	$content = null;

	$obj_tempdbarray = new CTempDBArray();
	$obj_tempdbengine = new CTempDBEngine();
	
	$messageid = $request['messageid'];
	$all = $request['all'];

	$published = $request['published'];
	$postname = $request['postname'];
	$postemail = $request['postemail'];
	$postheader = $request['postheader'];
	$postcontent = $request['postcontent'];

	if ($published=="on")
		$published = 1;

	$SQL  = "UPDATE contact_us ";
	$SQL .= "SET ";
	$SQL .= "published = '".$published."', ";
	$SQL .= "post_name = '".$postname."', ";
	$SQL .= "post_email = '".$postemail."', ";
	$SQL .= "post_header = '".$postheader."', ";
	$SQL .= "post_content = '".$postcontent."' ";
	$SQL .= "WHERE contact_us_id=".intval($messageid);
	
	if (!$obj_tempdbengine->ExecQuery($SQL))
		$content .= "<br>Update Error on ExecQuery<br>";

	$content .= "
	<div class=note>
		<h3>"._CMN_NOTE_."</h3>
		<p>";
			$content .= _CP_CA_MESSAGE_IS_SAVED_;
			$content .= "<br><br>";
			//$content .= go_back();
		$content .= "
		</p>
	</div>";

	ReDirection(basename($PHP_SELF)."?f=contact&sf=messages&all=$all");

	return $content;
}


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

	$obj_tempdbarray = new CTempDBArray();
	$obj_tempdbengine = new CTempDBEngine();

	$messageid = $request['messageid'];
	$all = $request['all'];
	$accept = $request['accept'];

	$SQL = "SELECT * FROM contact_us ";
	$SQL .= "WHERE contact_us_id='".intval($messageid)."' ";

	$row = $obj_tempdbengine->GetRow($SQL);
	$postname = $row['post_name'];
	$postemail = $row['post_email'];
	$postheader = $row['post_header'];
	$postcontent = $row['post_content'];
	$postdate = $row['post_date'];
	$published = $row['published'];
	if ($published)
		$published = " checked ";

	if ($accept){


		$SQL  = "UPDATE contact_us ";
		$SQL .= "SET ";
		$SQL .= "active = '0' ";
		$SQL .= "WHERE contact_us_id='".intval($messageid)."'";
		
		if (!$obj_tempdbengine->ExecQuery($SQL))
			$content .= "<br>Update Error on ExecQuery<br>";

		/*
		$SQL = "DELETE FROM contact_us ";
		$SQL .= "WHERE contact_us_id='".intval($messageid)."'";
		//$content .= $SQL;
	
		if (!$obj_tempdbengine->ExecQuery($SQL))
			$content .= "<br>Delete Error on ExecQuery<br>";
		*/

		$content .= "
		<div class=note>
			<h3>"._CMN_NOTE_."</h3>
			<p>";
			$content .= _MDL_DELETE_OK_;
			$content .= "<br><br>";
			ReDirection(basename($PHP_SELF)."?f=contact&sf=list&all=$all");
			$content .= "
			</p>
		</div>
		";
	}
	else{

		$content .= "
		<center>
		<form action='".basename($PHP_SELF)."?f=contact&sf=delete' method='post'>
		<input type=\"hidden\" name=\"messageid\" value=\"$messageid\" />
		<input type=\"hidden\" name=\"all\" value=\"$all\" />
		<input type=\"hidden\" name=\"accept\" value=\"1\" />
		<fieldset>
		<img style=\"float:right;\" src=\"./images/icon48/contacts.png\" width=\"48\" height=\"48\" border=\"0\">
		<legend>"._CP_CA_POST_CONTENT_."</legend>
			<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\">
			<tr>
				<td><label for=\"published\">"._CP_CA_PUBLISHED_."</label></td>
				<td><input type=\"checkbox\" name=\"published\" $published style=\"float:left;\"/></td>
			</tr>
	
			<tr>
				<td><label for=\"postname\">"._CP_CA_POST_NAME_."</label></td>
				<td><input type=\"text\" name=\"postname\" value=\"$postname\" style=\"float:left;\" size=\"32\" maxlength=\"64\"/></td>
			</tr>
	
			<tr>
				<td><label for=\"postemail\">"._CP_CA_POST_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\">"._CP_CA_POST_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\">"._CP_CA_POST_CONTENT_."</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=\""._CP_CA_DELETE_."\" style=\"float:center;\"/>";
					$content .= go_back();
					$content .= "
				</td>
			</tr>
			</table>
			<br>
		</fieldset>
		</form>
		</center>";
	}

	return $content;
}


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

	global $module;
	global $module_path;
	global $process;

	$process = "contact";

	$obj_tempdbarray = new CTempDBArray();
	$obj_tempdbengine = new CTempDBEngine();

	$pageid = $request['pageid'];
	$projectid = $request['projectid'];
	$process = $request['process'];
	$operation = $request['operation'];
	$sf = $request['sf'];

	$content = Begin_Script($request);

	switch ($sf){
	default:
	case 'messages':
		$content .= List_Messages($request);
	break;
	case 'read':
		$content .= Read_Message($request);
	break;
	case 'save':
		$content .= Save_Message($request);
	break;
	case 'delete':
		$content .= Delete_Message($request);
	break;
	}

	$content .= End_Script();

	return $content;
}

?>
Return current item: ChiCoMaS - Chilek CMS