Location: PHPKode > scripts > Ramui web hosting directory script > Ramui web hosting directory script/gb/admin/include/clsmail.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 clsmail extends clsmain
{
private function show_inbox($page,$sortColumn,$sortDirection)
{
        $search='';
        $sortDir=((empty($sortDirection))? 'Desc' : 'Asc');
		$sort_arr=array('date','email');
        $sortCol=$sort_arr[$sortColumn];
        if(!empty($_GET['SearchFileString'])){$search=htmlspecialchars(fw_strip_slashes($_GET['SearchFileString']));}
        $this->build_head("Message list", "");
		$query="SELECT id FROM ".$this->prefix."inbox WHERE subject LIKE '%%%s%%' OR message LIKE '%%%s%%' OR email LIKE '%%%s%%'";
        $result = @mysql_query(sprintf($query,mysql_real_escape_string($search),mysql_real_escape_string($search),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 id, subject, email, new, date FROM ".$this->prefix."inbox WHERE subject LIKE '%%%s%%' OR message LIKE '%%%s%%' OR email LIKE '%%%s%%'";
		$query.="ORDER BY $sortCol $sortDir LIMIT ".$start_count.", ".$this->list_perpage;
		$query=sprintf($query,mysql_real_escape_string($search),mysql_real_escape_string($search),mysql_real_escape_string($search));
        echo '<table id="list"><tr><td width="66%" class="heading" style="border-left:1px solid #888888;">Subject</td>';
		echo '<td width="20%" class="heading" style="border-right:#888888;">';
		echo '<a href="index.php?qur=4M6M1M1M1"><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=4M6M1M1M0"><img src="images/dsc.gif" onmouseover="this.src=\'images/dsc-h.gif\'" onmouseout="this.src=\'images/dsc.gif\'" /></a>From</td>';
		echo '<td width="14%" class="heading" style="border-right:#888888;">';
		echo '<a href="index.php?qur=4M6M1M0M1"><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=4M6M1M0M0"><img src="images/dsc.gif" onmouseover="this.src=\'images/dsc-h.gif\'" onmouseout="this.src=\'images/dsc.gif\'" /></a>Date</td></tr>';
		echo '<tr><td colspan="3"><a title="Remove filter" href="index.php?qur=4M">Message list:</a></td></tr>';
        $result = @mysql_query($query);
        while($row = @mysql_fetch_array($result, MYSQL_ASSOC))
        {
            echo '<tr onMouseOver="this.className=\'highlight\'" onMouseOut="this.className=\'normal\'">';
			$src='<img title= "Read" src="images/mailread.gif" alt="R" />';$class='approved';
			if($row['new']){$src='<img title="Unread" src="images/mailunread.gif" alt="U" />';$class='pending';}
            echo '<td>'.$src.'<a class="'.$class.'" href="index.php?qur=4M1M'.$row['id'].'">'.$row['subject'].'</a></td>';
			echo '<td>'.$row['email'].'</td>';
            echo '<td>'.date("M d, H:i", $row['date']).'</td></tr>';
        }
        echo '<tr><td colspan="3"><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=4M6M'.($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=4M6M'.$p.'M'.$sortColumn.'M'.$sortDirection.'&SearchFileString='.$search.'">'.$p.'</a>]&nbsp;';}
        }
        echo(($page<$totalpage)? '<a href="index.php?qur=4M6M'.($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="3" style="background:#e0e0e0; padding-bottom:0;">';
        echo '<form name="frmSearchList" style="float:right; margin:0; color:#000000;" onSubmit="return fw_search(\'index.php?qur=4M6M1M0M0\');">';
        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=4M6M1M0M0\');"></form></td></tr></table>';
        echo '</div>';
        $this->build_footer();
}
private function show_message($id)
{
        @mysql_query(sprintf("UPDATE ".$this->prefix."inbox SET new = 0 WHERE id = %d",$id));
		$query=sprintf("SELECT* FROM ".$this->prefix."inbox WHERE id = %d",$id);
        $result= @mysql_query($query);
        $row = @mysql_fetch_array($result, MYSQL_ASSOC);
		$message=nl2br(htmlentities($row['message']));
		$this->build_head("Inbox: ".$id,'<script type="text/javascript" src="script/mailreport.js"></script>');
        include 'include/showmail.php';
        $this->build_footer();
}
private function delete_message($id)
{
		@mysql_query(sprintf("DELETE FROM ".$this->prefix."inbox WHERE id = %d",$id));
		@header("Location: index.php?qur=4M");exit;
}
private function download_message($id)
{
        $query=sprintf("SELECT* FROM ".$this->prefix."inbox WHERE id = %d",$id);
        $result= @mysql_query($query);
        $row = @mysql_fetch_array($result, MYSQL_ASSOC);
		$s="Message from: ".(empty($row['name'])? "Unknown sender" : $row['name'])." (".$row['email'].")\r\n";
		$s.="Subject: ".$row['subject']."\r\nDate: ".gmdate("M d, H:i", $row['date'])."\r\n------------------------------------------------------------\r\n\r\n";
		$s.=$row['message'];
		$f='message'.$row['id'].'.rtf';
        @header("Content-type: application/text");
        @header("Content-Disposition: attachment; filename=$f");
        echo $s;
        exit;
}
private function save_settings()
{
		$defaultfrom = trim(fw_strip_slashes(rawurldecode($_POST["defaultfrom"])));
		$replyto = trim(fw_strip_slashes(rawurldecode($_POST["defaultto"])));
		$response = trim(fw_strip_slashes(rawurldecode($_POST["responsetext"])));
		$messagesize = trim($_POST["messagesize"]);
		$autoresponder=(isset($_POST["autoresponder"])? 1 : 0);
		$query="UPDATE ".$this->prefix."mailsettings SET messagesize = %u, defaultfrom = '%s', replyto = '%s', response = '%s', autoresponder = $autoresponder";
		$query=sprintf($query,$messagesize,mysql_real_escape_string($defaultfrom),mysql_real_escape_string($replyto),mysql_real_escape_string($response));
		if(@mysql_query($query)){echo 's';}
		else{echo mysql_error();}exit;
}
private function send_mail()
{
		$subject = trim(fw_strip_slashes(rawurldecode($_POST["subject"])));
		$from = trim(fw_strip_slashes(rawurldecode($_POST["from"])));
		$message = trim(fw_strip_slashes(rawurldecode($_POST["message"])));
		$replyto=trim(fw_strip_slashes(rawurldecode($_POST["message"])));
		$email = trim(fw_strip_slashes(rawurldecode($_POST["email"])));
		$sendcopy=isset($_POST["sendcopy"]);
		$headers="From: ".$from."\r\n";
		if(!(empty($replyto))){$headers.="Reply-To: ".$replyto."\r\n";}
		if($sendcopy){
			$result=@mysql_query("SELECT email FROM ".$this->prefix."admin LIMIT 0,1");
			$row = @mysql_fetch_array($result, MYSQL_ASSOC);
			if(!empty($row['email'])){$headers.="Bcc: ".$row['email']."\r\n";}}
		if(@mail($email,$subject, $message, $headers)){echo '<span style="color:green">Message has been successfully sent.</span>';}
		else{echo '<span style="margin:10px;color:red">Error! unable to send message</span>';}
		exit;
}
public function get_query($query)
{
if ($this->validate_user()){
      switch ($query[1]) {
          case "1":
              $this->show_message($query[2]);
          break;
          case "2":
              $this->delete_message($query[2]);
          break;
          case "3":
              $this->download_message($query[2]);
          break;
          case "4":
              $this->save_settings();
          break;
          case "5":
              $this->log_out();
          break;
          case "6":
              $this->show_inbox($query[2],$query[3],$query[4]);
          break;
          case "7":
              $this->send_mail();
          break;
          default :
              $this->show_inbox(1,0,0);
      }
}
else {if(($query[1]==6)||($query[1]==1)||empty($query[1])){$this->log_in();}}
}
}
?>
Return current item: Ramui web hosting directory script