Location: PHPKode > scripts > Ramui web hosting directory script > Ramui web hosting directory script/gb/admin/include/clsadmin.php
<?php
/*
Copyright (c) 2011 http://ramui.com/. All right reserved.
This product is protected by copyright and distributed under licenses restricting copying, distribution. Permission is granted to the public to download and use this script provided that this Notice and any statement of authorship are reproduced in every page on all copies of the script.
*/
class admin extends clsmain
{
private function key_list($page,$sortColumn,$sortDirection)
{
        $search='';
        $sortDir=((empty($sortDirection))? 'Desc' : 'Asc');
		$sort_arr=array('id','keywords','hit','date');
        $sortCol=$sort_arr[$sortColumn];
        if(!empty($_GET['SearchFileString'])){$search=htmlspecialchars(fw_strip_slashes($_GET['SearchFileString']));}
        $this->build_head("Keyword list", '<script type="text/javascript" src="script/admin.js"></script>');
		$query="SELECT id FROM ".$this->prefix."searchkey WHERE keywords LIKE '%%%s%%'";
        $result = @mysql_query(sprintf($query,mysql_real_escape_string($search)));
        $num_rows = @mysql_num_rows($result);
        $start_count=($page-1)*$this->list_perpage;
        $totalpage=fw_total_page($num_rows, $this->list_perpage);
        $query ="SELECT* FROM ".$this->prefix."searchkey WHERE keywords LIKE '%%%s%%' ORDER BY $sortCol $sortDir LIMIT $start_count, ".$this->list_perpage;
		$query=sprintf($query,mysql_real_escape_string($search));
		echo '<table id="list"><tr><td width="68%" class="heading" style="border-left:1px solid #d0d0d0;">';
		echo '<a href="index.php?qur=6M6M1M1M1"><img src="images/asc.gif" onmouseover="this.src=\'images/asc-h.gif\'" onmouseout="this.src=\'images/asc.gif\'" /></a>';
		echo '<a href="index.php?qur=6M6M1M1M0"><img src="images/dsc.gif" onmouseover="this.src=\'images/dsc-h.gif\'" onmouseout="this.src=\'images/dsc.gif\'" /></a>Search key</td>';
		echo '<td width="10%" class="heading">';
		echo '<a href="index.php?qur=6M6M1M2M1"><img src="images/asc.gif" onmouseover="this.src=\'images/asc-h.gif\'" onmouseout="this.src=\'images/asc.gif\'" /></a>';
		echo '<a href="index.php?qur=6M6M1M2M0"><img src="images/dsc.gif" onmouseover="this.src=\'images/dsc-h.gif\'" onmouseout="this.src=\'images/dsc.gif\'" /></a>Hit</td>';
		echo '<td width="8%" class="heading" style="border-right:none;text-align:center;">&nbsp;</td>';
		echo '<td width="14%" class="heading" style="border-left:none;border-right:#888888;">';
		echo '<a href="index.php?qur=6M6M1M3M1"><img src="images/asc.gif" onmouseover="this.src=\'images/asc-h.gif\'" onmouseout="this.src=\'images/asc.gif\'" /></a>';
		echo '<a href="index.php?qur=6M6M1M3M0"><img src="images/dsc.gif" onmouseover="this.src=\'images/dsc-h.gif\'" onmouseout="this.src=\'images/dsc.gif\'" /></a>Modified</td></tr>';
		echo '<tr><td colspan="4"><a title="Remove filter" href="index.php?qur=6M6M1M0M0">Keyword list:</a></td></tr>';
		echo '<tr><td><input id="newkey" class="newkey" type="text" value="Insert new key..." onclick="fw_cleartext(this,\'Insert new key...\');" /></td><td><input id="newhit" class="newkey" type="text" /></td>';
		echo '<td colspan="2"><input type="button" class="btnnewkey" onclick="javascript:fwInsertNew()" value="Submit" /> <input type="button" class="btnnewkey" onclick="javascript:fwResetNew()" value="Reset" /></td></tr>';
        $result = @mysql_query($query);
        while($row = @mysql_fetch_array($result, MYSQL_ASSOC))
        {
            echo '<tr onMouseOver="this.className=\'highlight\'" onMouseOut="this.className=\'normal\'">';
			echo '<td>'.$row['keywords'].'</td><td style="text-align:center;">'.$row['hit'].'</td><td style="text-align:center;"><a style="color:red;" href="javascript:fwDeleteKey('.$row['id'].')">Delete</a></td><td>'.date("M d, H:i", $row['date']).'</td></tr>';
		}
        echo '<tr><td colspan="4"><b>No. of pages:&nbsp;'.$totalpage.'</b>&nbsp;&nbsp;&nbsp;';
        $start=(($page>10)? $page-10 : 1);
        $end=(($totalpage<=21)? $totalpage : $start+20);
        echo(($page>1)? '<a href="index.php?qur=6M6M'.($page-1).'M'.$sortColumn.'M'.$sortDirection.'&SearchFileString='.$search.'">Back</a>&nbsp;' : '<span style="color:#808080;">Back</span>&nbsp;');
        for($p=$start; $p<=$end; $p++){
             if($p==$page){echo '<span style="color:#808080;">['.$p.']</span>&nbsp;';}
             else{echo '[<a href="index.php?qur=6M6M'.$p.'M'.$sortColumn.'M'.$sortDirection.'&SearchFileString='.$search.'">'.$p.'</a>]&nbsp;';}
        }
        echo(($page<$totalpage)? '<a href="index.php?qur=6M6M'.($page+1).'M'.$sortColumn.'M'.$sortDirection.'&SearchFileString='.$search.'">Next</a>&nbsp;' : '<span style="color:#808080;">Next</span>&nbsp;');
        echo '</td></tr>';
        echo '<tr><td colspan="4" style="background:#e0e0e0; padding-bottom:0;">';
        echo '<form name="frmSearchList" style="float:right; margin:0; color:#000000;" onSubmit="return fw_search(\'index.php?qur=6M6M1M0M0\');">';
        echo 'Search file:&nbsp;<input name="txtSearch" style="padding-left:5px; width:180px; font-size:11px; color:#666666;" type="text" value="';
        echo (($search=='')? 'Type few characters...' : $search);
        echo '" size="20" onclick="fw_cleartext(this,\'Type few characters...\');">&nbsp;<input name="Submit" type="button" style="width:80px; font-size:11px; color:#333333;" value="Search" onClick="fw_search(\'index.php?qur=2M6M1M0M0M0\');"></form></td></tr></table>';
        echo '</div>';
        $this->build_footer();
}
private function show_boardsettings()
{
        $query  = "SELECT* FROM ".$this->prefix."settings";
        $result = @mysql_query($query);
        $row = @mysql_fetch_array($result, MYSQL_ASSOC);
		$list= glob("../templates/*",GLOB_ONLYDIR);
		$option='';
		foreach ($list as $template){
		$template=str_replace("../templates/", "", $template);
		$option.=(($row['defaultstyle']==$template)? '<option selected value="' : '<option value="').$template.'">'.$template.'</option>';}
        $blocksite=(($row['blocksite'])? '<span style="color:#338833;">Unblock this site..</span>' : '<span style="color:#883333;">Block this site..</span>');
		$this->build_head("Site informations:", '<script type="text/javascript" src="script/admin.js"></script>');
        include "include/editsite.php";
        $this->build_footer();
}

private function save_boardsettings()
{
		$sitename=trim(fw_strip_slashes(rawurldecode($_POST["sitename"])));
        $description=trim(fw_strip_slashes(rawurldecode($_POST["description"])));
        $keywords=trim(fw_strip_slashes(rawurldecode($_POST["keywords"])));
		$postsize=trim($_POST["postsize"]);
		$commentsize=trim($_POST["commentsize"]);
		$listcount=trim($_POST["listcount"]);
		$commentcount=trim($_POST["commentcount"]);
		$defaultstyle=trim(fw_strip_slashes(rawurldecode($_POST["defaultstyle"])));
		$approval=((isset($_POST["approval"]))? 'A' : '');
		$nofollow=((isset($_POST["nofollow"]))? (($_POST["nofollow"]==='Y')? 'Y' : 'A') : '');
		$allowemail=((isset($_POST["allowemail"]))? 1 : 0);
		$allowedit=((isset($_POST["allowedit"]))? 1 : 0);
		$afflink=((isset($_POST["afflink"]))? 1 : 0);
		$verify=((isset($_POST["verify"]))? 1 : 0);
		$description=fw_remove_smarttag($description);
		$description=str_replace("\n"," ",str_replace("\r","",$description));
        $query="UPDATE ".$this->prefix."settings SET sitename = '%s', description = '%s', keywords = '%s', defaultstyle = '%s', verifyuser = $verify, postsize = %d, commentsize = %d, commentcount = %d, listcount = %d, allowedit = $allowedit, approval = '$approval', afflink = $afflink, nofollow = '$nofollow', allowemail = $allowemail";
        $query=sprintf($query,mysql_real_escape_string($sitename),mysql_real_escape_string($description),mysql_real_escape_string($keywords),mysql_real_escape_string($defaultstyle),$postsize,$commentsize,$commentcount,$listcount);
		if(!@mysql_query($query)){echo '<span style="color:red">Error! '.mysql_error().'</span>';}
        else{echo '<span style="color:green">Data has been updated.</span>';}
        exit;
}
private function block_site()
{
		$query = "SELECT blocksite FROM ".$this->prefix."settings";
        $result = @mysql_query($query);
        $row = @mysql_fetch_array($result, MYSQL_ASSOC);
		if($row['blocksite']){$blocksite=0; $message='<span style="color:#883333;">Block this site..</span>';}
		else{$blocksite=1; $message='<span style="color:#338833;">Unblock this site..</span>';}
		if(@mysql_query("UPDATE ".$this->prefix."settings SET blocksite = $blocksite")){echo $message;}
		exit;
}
private function delete_key($id)
{
		@mysql_query(sprintf("DELETE FROM ".$this->prefix."searchkey WHERE id = %d",$id));
		@header("Location: index.php?qur=6M6M1M0M0");exit;
}
private function insert_key()
{
		$dt=time();
		$key=trim(fw_strip_slashes(rawurldecode($_POST["key"])));
		$key=mysql_real_escape_string(strtolower($key));
		$hit=trim($_POST["hit"]);
		$query=sprintf("UPDATE ".$this->prefix."searchkey SET hit = hit+(%u), date = $dt WHERE keywords = '%s'",$hit,$key);
		@mysql_query($query);
		if(mysql_affected_rows()==0){@mysql_query(sprintf("INSERT INTO ".$this->prefix."searchkey(keywords, hit, date) VALUES('%s',%u,$dt)",$key,$hit));}
		echo "ok";exit;
}
private function show_adminsettings($message='')
{
		$query="SELECT user, email FROM ".$this->prefix."admin LIMIT 0,1";
        $result = @mysql_query($query);
        $row = @mysql_fetch_array($result, MYSQL_ASSOC);
		$this->build_head("Admin settings:",'<script type="text/javascript" src="script/admin.js"></script>');
		include 'include/editadmin.php';
		$this->build_footer();
}
private function save_adminsettings()
{
		$message='';
		$changepass=false;
		$email=trim(fw_strip_slashes($_POST["email"]));
		$user=trim(fw_strip_slashes($_POST["user"]));
		if(!fw_validate_user($user,$email)){$message='<span style="color:red">Error! Invalid user name and / or email!</span>';}
		$password=md5(trim(fw_strip_slashes($_POST["password"])));
		$newpassword=trim(fw_strip_slashes($_POST["newpassword"]));
		$retypepassword=trim(fw_strip_slashes($_POST["retypepassword"]));
		if((!empty($newpassword))&&(!empty($retypepassword))&&($newpassword===$retypepassword)){
			$newpassword=md5($newpassword);
			$changepass=true;
			$query=sprintf("UPDATE ".$this->prefix."admin SET user = '%s', email = '%s', password = '%s', login = '', session = '' WHERE password = '%s'",mysql_real_escape_string($user),mysql_real_escape_string($email),mysql_real_escape_string($newpassword),mysql_real_escape_string($password));}
		else{
			$newpassword=$password;
			$query=sprintf("UPDATE ".$this->prefix."admin SET user = '%s', email = '%s', password = '%s' WHERE password = '%s'",mysql_real_escape_string($user),mysql_real_escape_string($email),mysql_real_escape_string($newpassword),mysql_real_escape_string($password));}
		if(empty($message)){
			@mysql_query($query);
			if(mysql_affected_rows()===1){
				if($changepass){$message='<span style="color:green;padding:10px;">Data has been updated. Please login again.</span>';$this->log_in($message);exit;}
				$message='<span style="color:green">Data has been updated.</span>';}
			else{$message='<span style="color:red">Sorry! Unable to update data</span>';}}
		$this->show_adminsettings($message);
}
public function get_query($query)
{
if ($this->validate_user()){
      switch ($query[1]) {
          case "1":
              $this->show_boardsettings();
          break;
          case "2":
              $this->save_boardsettings();
          break;
          case "3":
              $this->block_site();
          break;
          case "4":
              $this->insert_key();
          break;
          case "5":
              $this->log_out();
          break;
          case "6":
              $this->key_list($query[2],$query[3],$query[4]);
          break;
          case "7":
              $this->delete_key($query[2]);
          break;
          case "8":
              $this->show_adminsettings();
          break;
          case "9":
              $this->save_adminsettings();
          break;
          default :
              $this->show_boardsettings();
      }
}
else {if(($query[1]==1)||empty($query[1])){$this->log_in();}}
}
}
?>
Return current item: Ramui web hosting directory script