D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
grandhou
/
public_html
/
classes
/
Filename :
general.class.php
back
Copy
<?php ##################################################### # | Page Info. | # ##################################################### /* CREATOR : SUMESH T G DATE : 02/04/2009 PAGE : general.class.php DESC : Class contains functions based on insrt,update,select,delete opertions. */ ##################################################### include_once "database.class.php"; class general { function __construct() { $this->now = date("Y-m-d"); $this->date = date("Y-m-d H:i:s"); $this->db = new database(); if(!$this->db->dbConnect()) die("Error Connection".$this->db->ErrorInfo); } function __destruct() { $this->db->dbClose(); } function get_insetId() { return $this->db->getInsertId(); } function extfind($filename) { $filename = strtolower($filename) ; $exts = @split("[/\\.]", $filename) ; $n = count($exts)-1; //$exts = substr($exts[$n-1],0,15).".".$exts[$n]; $exts = date("YmdHis").".".$exts[$n]; return $exts; } # Fetch One Row function get_Onerow($table,$where,$col='*',$html=false) { $sql = "SELECT $col FROM $table WHERE 1=1 $where"; //echo $sql; $res = $this->db->readValue($sql); return $res; } function get_MAxVal($table,$col,$as,$where="") { $sql = "SELECT max($col) AS $as FROM $table"; if($where!="") { $sql .= " WHERE $where"; } //echo $sql; $res = $this->db->readValue($sql); return $res; } function get_MinVal($table,$col,$as,$col2,$where="") { $sql = "SELECT min($col) AS $as, $col2 FROM $table"; if($where!="") { $sql .= " WHERE $where"; } //echo $sql; $res = $this->db->readValue($sql); return $res; } function get_MAxVal2($table,$col,$where="") { $sql = "SELECT $col FROM $table"; if($where!="") { $sql .= " WHERE $where"; } //echo $sql; $res = $this->db->readValue($sql); return $res; } # Fetch One Rows Count function get_AllRowscnt($table,$where="",$group_by="",$col='*') { $sql = "SELECT $col FROM $table WHERE 1=1"; if($where!="") $sql .= " $where"; if($group_by!="") $sql .= " GROUP BY $group_by"; //echo $sql; $res = $this->db->numberOfRecords($sql); return $res; } # Fetch One Rows function get_AllRows($table,$limit=0,$count=10,$order="",$where="",$group_by="",$col='*',$html=false) { $sql = "SELECT $col FROM $table WHERE 1=1"; if($where!="") $sql .= " $where"; if($group_by!="") $sql .= " GROUP BY $group_by"; if($order!="") $sql .= " ORDER BY $order"; $sql .= " LIMIT $limit,$count"; //echo $sql; $res = $this->db->readValues($sql); /* $new_res = array(); foreach($res as $ky=>$val) { foreach($val as $ky1=>$val1) { if($html==false) $new_res[$ky][$ky1] = htmlentities(stripslashes($val1)); else $new_res[$ky][$ky1] = stripslashes($val1); } } return $new_res;*/ return $res; } # Fetch One Rows Count function get_AllRowscnt_qry($sql) { //echo $sql; $res = $this->db->numberOfRecords($sql); return $res; } # Fetch One Rows function get_AllRows_qry($sql) { // echo $sql; $res = $this->db->readValues($sql); return $res; } # Delete Row function del_Row($table,$where="") { $sql = "DELETE FROM $table"; if($where!="") $sql .= " WHERE $where"; //echo $sql; $res = $this->db->setQuery($sql); if($res) { return ""; } else return "Sorry !.Error occured .Please try Again!."; } # Insert Row function ins_Row($table,$colums,$values) { $sql = "INSERT INTO $table ($colums) VALUES ($values)"; $res = $this->db->setQuery($sql); //echo $sql; if($res) { return ""; } else return "Sorry !.Error occured .Please try Again!."; } # Update Row function upd_Row($table,$set,$where) { $sql = "UPDATE $table SET $set WHERE $where"; $res = $this->db->setQuery($sql); //echo $sql;exit; if($res) { return ""; } else return "Sorry !.Error occured .Please try Again!."; } # Check Exist function chk_Ext($table,$where,$col='*') { $sql = "SELECT $col FROM $table WHERE $where"; //echo $sql; $res = $this->db->numberOfRecords($sql); return $res; } function chk_morethan($username,$password) { $sql2 = "SELECT email FROM ma_users WHERE email='".addslashes($username)."' and password='".addslashes($password)."'"; $res2 = $this->db->numberOfRecords($sql2); return $res2; } # Check Login function chk_Login($table,$username,$password,$page,$ses_id='user_id',$ses_name='username',$ses_pass="password",$status="",$admin=0,$col='*') { $sql = "SELECT $col FROM $table WHERE $ses_name='".addslashes($username)."' and $ses_pass='".addslashes($password)."'"; //echo $sql; if($status!="") $sql .= " AND status='$status'"; $res = $this->db->readValue($sql); if($res) { session_start(); if($admin==0) { $_SESSION['ma_log_id'] = $res[$ses_id]; $_SESSION['ma_usr_name'] = $res[$ses_name]; $_SESSION['ma_name'] = $res['full_name']; } else { $_SESSION['MYPR_adm_id'] = $res[$ses_id]; $_SESSION['MYPR_adm_username'] = $res[$ses_name]; $_SESSION['MYPR_adm_type'] = $res['user_type']; } return ""; } else if($res && $status!="" && $res['status']!=$status) { return "Sorry!.Your Account is Inactive Now."; } else { return "Invalid Username/Password"; } } function chng_password($table,$col_pass,$POST,$col_id,$id) { $password = trim(addslashes($POST['new_pwd'])); $old_password = trim(addslashes($POST['old_pwd'])); $sql1 = "SELECT $col_pass FROM $table WHERE $col_pass='$old_password' AND $col_id=$id"; $res1 = $this->db->numberOfRecords($sql1); if($res1==0) { return "Inavlid Old Password."; } else { $sql = "Update $table SET $col_pass='$password' where $col_id=$id"; $res = $this->db->setQuery($sql); if($res) { return ""; } else return "Sorry !.Error occured .Please try Again!."; } } # Check Password function match_Pass($pass,$conf_pass,$min="",$max="") { if($pass!=$conf_pass) { return "Confirm password Didn't Match"; } else if($min!="" && $max!="") { if($pass>$max || $pass<$min) return "Password Must Contains $min - $max char."; else return ""; } else if($min!="") { if($pass<$min) return "Password Must Contains Min. $min char."; else return ""; } else if($min!="") { if($pass>$max) return "Password Must Contains Min. $min char."; else return ""; } else { return ""; } } # Make Date Time function make_DateTime($date) { $date = explode(" ",$date); $time_exp = explode(":",$date[1]); $date_exp = explode("-",$date[0]); if($date[0]==$this->now) { $date = "<font color='blue'><b>Today</b></font>".date(" g:i A", mktime($time_exp[0],$time_exp[1],$time_exp[2],$date_exp[1],$date_exp[2],$date_exp[0])); } else { $date = date("jS, M Y g:i A", mktime($time_exp[0],$time_exp[1],$time_exp[2],$date_exp[1],$date_exp[2],$date_exp[0])); } return $date; } # Make Date Time function make_Date($date) { $date_exp = explode("-",$date); $date = date("jS, M Y [ l ]", mktime(0,0,0,$date_exp[1],$date_exp[2],$date_exp[0])); return $date; } # Remove Stripslashes Array function DetermineAgeFromDOB ($YYYYMMDD_In) { // Parse Birthday Input Into Local Variables // Assumes Input In Form: YYYYMMDD $yIn=substr($YYYYMMDD_In, 0, 4); $mIn=substr($YYYYMMDD_In, 4, 2); $dIn=substr($YYYYMMDD_In, 6, 2); // Calculate Differences Between Birthday And Now // By Subtracting Birthday From Current Date $ddiff = date("d") - $dIn; $mdiff = date("m") - $mIn; $ydiff = date("Y") - $yIn; // Check If Birthday Month Has Been Reached if ($mdiff < 0) { // Birthday Month Not Reached // Subtract 1 Year From Age $ydiff--; } elseif ($mdiff==0) { // Birthday Month Currently // Check If BirthdayDay Passed if ($ddiff < 0) { //Birthday Not Reached // Subtract 1 Year From Age $ydiff--; } } return $ydiff; } function get_time_difference( $start, $end ) { $uts['start'] = strtotime( $start ); $uts['end'] = strtotime( $end ); if( $uts['start']!==-1 && $uts['end']!==-1 ) { if( $uts['end'] >= $uts['start'] ) { $diff = $uts['end'] - $uts['start']; if( $days=intval((floor($diff/86400))) ) $diff = $diff % 86400; if( $hours=intval((floor($diff/3600))) ) $diff = $diff % 3600; if( $minutes=intval((floor($diff/60))) ) $diff = $diff % 60; $diff = intval( $diff ); return( array('days'=>$days, 'hours'=>$hours, 'minutes'=>$minutes, 'seconds'=>$diff) ); } else { trigger_error( "Ending date/time is earlier than the start date/time", E_USER_WARNING ); } } else { trigger_error( "Invalid date/time data detected", E_USER_WARNING ); } return( false ); } function currnt_page() { $currentFile = $_SERVER['REQUEST_URI']; $parts = Explode('/', $currentFile); return $parts[count($parts) - 1]; } //Simple mail function with HTML header function sendmail($to, $subject, $message, $from) { $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= 'From: ' . $from . "\r\n"; $result = mail($to,$subject,$message,$headers); if ($result) return 1; else return 0; } } ?>