Location: PHPKode > projects > Akasha > includes/functions.inc
<?

function findMaxMboxID() 
{
   global $dbname;

  $query = "select max(mbox_id) from tblMailBoxes";
  $result = mysql_db_query("$dbname",$query);
  	if($result) {
		while ($r = mysql_fetch_array($result)) {
			$max_mbox_id = $r["max(mbox_id)"];
		}
	}

	return $max_mbox_id;
}

function findUserByHash($ID) 
{
   global $dbname;

  $query = "select user_id from tblLoggedUsers where hash = '$ID'";
  $result = mysql_db_query("$dbname",$query);
  	if($result) {
		while ($r = mysql_fetch_array($result)) {
			$user_id = $r["user_id"];
		}
	}
	return $user_id;
}

function getUsername($ID) 
{
	global $dbname;

  $query = "select username from tblLoggedUsers where hash = '$ID'";
  $result = mysql_db_query("$dbname", $query);
  	if($result) {
		while ($r = mysql_fetch_array($result)) {
			$username = $r["username"];
		}
	}
	
	return $username;
}

function getPassword($ID) 
{
	global $dbname;

  $query = "select password from tblLoggedUsers where hash = '$ID'";
  $result = mysql_db_query("$dbname",$query);
  	if($result) {
		while ($r = mysql_fetch_array($result)) {
			$password = $r["password"];
		}
	}
	return $password;
}

function findUser($username) 
{
	global $dbname;

	$username = trim($username);
	$user_id=0;
  $query = "select user_id from tblUsers where username = '$username'";
  $result = mysql_db_query("$dbname",$query);
  	if($result) {
		while ($r = mysql_fetch_array($result)) {
			$user_id = $r["user_id"];
		}
	}

	return $user_id;
}

function findMaxUserID() 
{
	global $dbname;

  $query = "select max(user_id) from tblUsers";
  $result = mysql_db_query("$dbname",$query);
  	if($result) {
		while ($r = mysql_fetch_array($result)) {
			$max_user_id = $r["max(user_id)"];
		}
	}

	return $max_user_id;
}

function getUserMailAdress($ID) 
{
	global $dbname;

	$user_id = findUserByHash($ID);
  $query = "select username,domain_id from tblUsers where user_id = $user_id";
  $result = mysql_db_query("$dbname",$query);
 	if($result) {
		while ($r = mysql_fetch_array($result)) {
			$username = $r["username"];
			$domain_id = $r["domain_id"];

      $query1 = "select domain from tblDomains where domain_id = $domain_id";
      $result1 = mysql_db_query("$dbname",$query1);
     	if($result1) {
    		while ($r = mysql_fetch_array($result1)) {
    			$domain = $r["domain"];
				}
			}
		}
	}

	$mailadress = "$username@$domain";

	return $mailadress;
}

function addUserToDB($txtusername,$txtpassword,$ip) 
{
	global $dbname;
	$max_user_id = findMaxUserID();	
	$domain_id = 1;
	$query = "select domain_id from tblUserDomains where username='$txtusername'";
	$result = mysql_db_query("$dbname",$query);
  	if($result) {
		while ($r = mysql_fetch_array($result)) {
			$domain_id = $r["domain_id"];
		}
	}

	$user_id = $max_user_id + 1;
	$date = date('Y-m-d');
	$query = "insert into tblUsers values($user_id,'$txtusername','$txtpassword','',$domain_id,'$date','$ip',1)";
	$result = mysql_db_query("$dbname",$query);
	$max_mbox_id = findMaxMboxID();
	$txt_outbox = "Sent Mail";
	$txt_trash = "Trash";


  $query = "insert into tblMailBoxes values(NULL,$user_id,'$txt_outbox',1)";
  $result = mysql_db_query("$dbname",$query);
  $query = "insert into tblMailBoxes values(NULL,$user_id,'$txt_trash',2)";
  $result = mysql_db_query("$dbname",$query);
	return $user_id;
}


function decode_mime_string ($string) {
   if (eregi("=?([A-Z,0-9,-]+)?([A-Z,0-9,-]+)?([A-Z,0-9,-,=,_]+)?=", $string)) {
      $coded_strings = explode('=?', $string);
      $counter = 1;
      $string = $coded_strings[0]; 
      while ($counter < sizeof($coded_strings)) {
         $elements = explode('?', $coded_strings[$counter]); 
         if (eregi("Q", $elements[1])) {
            $elements[2] = str_replace('_', ' ', $elements[2]);
            $elements[2] = eregi_replace("=([A-F,0-9]{2})", "%\\1", $elements[2]);
            $string .= urldecode($elements[2]);
         } else { 
            $elements[2] = str_replace('=', '', $elements[2]);
            if ($elements[2]) { $string .= base64_decode($elements[2]); }
         }
         if (isset($elements[3]) && $elements[3] != '') {
            $elements[3] = ereg_replace("^=", '', $elements[3]);
            $string .= $elements[3];
         }
				 $string .= " ";
         $counter++;
      }
   }
   return $string;
}

function findMimeType($extension) {
	$dosyatipi="application/octet-stream";
	$mime=fopen("../mime.types","r");
	while ( !feof($mime) ) {
		$mytype=fgets($mime,1000);
		$mimeparts=explode("	",$mytype);	
		$mimeuzanti = trim(strtolower($mimeparts[1]));
		
		if ($mimeuzanti == $extension) {
			$dosyatipi=$mimeparts[0];
		}	
	}
	fclose($mime);

	return $dosyatipi;
}

function htmlisle($body)  {

	$tmpbody = stristr ($body,"<html>");
	if ($tmpbody) {
		$body = substr ($tmpbody, 7);
	}
	$tmpbody = stristr ($body,"<body");
	if ($tmpbody) {
		$body = substr ($tmpbody, 7);
		$tmpbody2 = stristr ($body,">");
		$body = substr ($tmpbody2, 1);	
	}
  	return $body;
}

function bodyIsle($body)  {

	global $ID,$qp;

  	if ( strlen($body) <= 0 ) { 
			$body= "Mesaj içeriði boþ..."; 
		}
 
	if ($qp == 1) {
 		$xbody=imap_qprint($body);
  		$mylen=strlen($xbody);
  		if ( $mylen > 10 )  {
  			$body=$xbody;
  		}
	}

  	$htmlbody	=($body);
  	$htmlbody	=htmlspecialchars($htmlbody);
 	
	$htmlbody=ereg_replace("([A-Za-z0-9_]+\@[[:alnum:].]+[a-zA-Z]+)","<a href=\"new_message.php?ID=$ID&to=\\1\">\\1</a>",$htmlbody);
  	$htmlbody = eregi_replace("(http|https|ftp)://([[:alnum:]/\n+-=&%:_.~?]+[#[:alnum:]+]*)","<a href=\"\\1://\\2\" target='yeni'>\\1://\\2</a>",	$htmlbody);

  	return $htmlbody;
}

function calculateHowManyPages($messagecount) {
	global $seperator;

	$tmp_page = floor($messagecount / $seperator);
	$total_page = $tmp_page * $seperator;
	if ($messagecount != $total_page) {
		$how_many = $tmp_page + 1;
	} else {
		$how_many = $tmp_page;
	}	
	return $how_many;
}

function getMboxTip($mbox_id) 
{
	global $dbname;

  $query = "select mbox_tip from tblMailBoxes where mbox_id = $mbox_id";
  $result = mysql_db_query("$dbname",$query);
  if($result) {
		while ($r = mysql_fetch_array($result)) {
			$mbox_tip = $r["mbox_tip"];
		}
	}

	return $mbox_tip;
}

function getMboxName($mbox_id) {
	global $dbname;

  $query = "select mboxname from tblMailBoxes where mbox_id = $mbox_id";
  $result = mysql_db_query("$dbname",$query);
  if($result) {
		while ($r = mysql_fetch_array($result)) {
			$mboxname = $r["mboxname"];
		}
	}

	return $mboxname;
}

// ------------------------------------------------------------
// check if mailbox is owned by user
// ------------------------------------------------------------
function getUserIDMbox($mbox_id) 
{
   global $dbname;

   $query = "select user_id from tblMailBoxes where mbox_id = $mbox_id";
   $result = mysql_db_query("$dbname",$query);
   if( $result ) {
      $user_id = @mysql_result( $result, 0, "user_id" );
   } else {
      $user_id = 0;
   }
   return $user_id;
}

function findGidenKutusu($user_id) {
	global $dbname;

  $query = "select mbox_id from tblMailBoxes where user_id = $user_id and mbox_tip = 1";
  $result = mysql_db_query("$dbname",$query);
  if($result) {
		while ($r = mysql_fetch_array($result)) {
			$mbox_id = $r["mbox_id"];
		}
	}

	return $mbox_id;
}

function findUserMessageCount($mbox_id,$user_id) {
	global $dbname;

  $query = "select count(message_id) from tblMessages where user_id = $user_id and mbox_id=$mbox_id";
  $result = mysql_db_query("$dbname",$query);
  if($result) {
		while ($r = mysql_fetch_array($result)) {
			$messagecount = $r["count(message_id)"];
		}
	}

	return $messagecount;
}

function findMboxMessageCount($mbox_id) {
	global $dbname;

  $query = "select count(*) from tblMessages where mbox_id = $mbox_id";
  $result = mysql_db_query("$dbname",$query);
  if($result) {
		while ($r = mysql_fetch_array($result)) {
			$messagecount = $r["count(*)"];
		}
	}

	return $messagecount;
}

?>
Return current item: Akasha