<?php

class Mat_Admin
{
public $perpage = 20; /*Uploads perpage*/

	public function Users_Count($verified="all") 
	{
      // Base query
       $sql = "SELECT COUNT(DISTINCT uid) AS count FROM  users ";
       // Add condition if called with "verified"
       if ($verified == "verified") {
           $sql .= "WHERE verified = 1 AND status = 1";
        // Add condition if called with "unverified"
      } elseif ($verified == 'unverified') {
         $sql .= "WHERE verified = 0 AND status = 1";
      }
         $query=mysql_query($sql) or die(mysql_error());
         $row = mysql_fetch_array($query);
    return $row['count'];
    }

    public function Users_CountM()
    {
       $query=mysql_query("SELECT uid FROM users")or die(mysql_error());
       return mysql_num_rows($query);
    }
	//Report Count
	public function Report_Count()
    {
       $query=mysql_query("SELECT r_id FROM reported_post")or die(mysql_error());
       return mysql_num_rows($query);
    }
	 //Updates Count
    public function Updates_Count()
    {
       $query=mysql_query( "SELECT msg_id FROM messages")or die(mysql_error());
       return mysql_num_rows($query);
    }
	//Comments Count
    public function Comments_Count()
    {
       $query=mysql_query("SELECT com_id FROM comments")or die(mysql_error());
       return mysql_num_rows($query);
    }
	//Share Count
    public function Share_Count()
    {
       $query=mysql_query("SELECT share_id FROM message_share")or die(mysql_error());
       return mysql_num_rows($query);
    }
	//Like Count
    public function Like_Count()
    {
       $query=mysql_query("SELECT like_id FROM message_like")or die(mysql_error());
       return mysql_num_rows($query);
    }
	//Active Users Count
    public function ActiveUsers_Count()
    {
       $query=mysql_query("SELECT uid FROM users where status='1'")or die(mysql_error());
       return mysql_num_rows($query);
    }
	//Conversations Users Count
    public function Conversations_Count()
    {
       $query=mysql_query("SELECT c_id FROM conversation")or die(mysql_error());
       return mysql_num_rows($query);
    }
	//Conversations Users Count
    public function UserUploads_Count()
    {
       $query=mysql_query("SELECT id FROM user_uploads")or die(mysql_error());
       return mysql_num_rows($query);
    }
    //Conversations Users Count
    public function UserVideoUploads_Count()
    {
       $query=mysql_query("SELECT id FROM user_uploads WHERE vidyo_adi")or die(mysql_error());
       return mysql_num_rows($query);
    }
	//Conversations Users Count
    public function ProfileUploads_Count()
    {
       $query=mysql_query("SELECT id FROM user_profile_images")or die(mysql_error());
       return mysql_num_rows($query);
    }
    public function ProfileCover_Count()
    {
       $query=mysql_query("SELECT id FROM user_cover_images")or die(mysql_error());
       return mysql_num_rows($query);
    }
	 /* User Details*/
    public function Users_Details($start,$per_page)
    {
	   $start=mysql_real_escape_string($start);
	   $per_page=mysql_real_escape_string($per_page);
       $query=mysql_query("SELECT uid,username,email,friend_count,profile_pic,conversation_count,updates_count,
	   profile_pic_status,verified,provider,name  FROM users WHERE status='1' ORDER BY uid DESC LIMIT $start, $per_page")or die(mysql_error());
       while($row=mysql_fetch_array($query)) {
	         $data[]=$row;
	        }
	        if(!empty($data)) {
	    // Store the result into array
	      return $data;
	   } 
    }
    /*Recent Users*/
	public function Recent_Users()
	{
	   $query=mysql_query("SELECT uid,username,email,friend_count,join_date,profile_pic,conversation_count,updates_count,profile_pic_status,verified,provider,name FROM users WHERE status='1' ORDER BY uid DESC LIMIT 10")or die(mysql_error());
	   while($row=mysql_fetch_array($query)) {
		   $data[]=$row;
		   }
		  if(!empty($data)) {
	    // Store the result into array
	      return $data;
	   } 			
	}
	 /* User Details*/
    public function Blocked_Users_Details($start,$per_page)
    {
	   $start=mysql_real_escape_string($start);
	   $per_page=mysql_real_escape_string( $per_page);
       $query=mysql_query("SELECT uid,username,email,friend_count,profile_pic,conversation_count,updates_count,
	                       profile_pic_status,verified,provider,name  FROM users WHERE status='2' ORDER BY uid DESC LIMIT $start, $per_page")or die(mysql_error());
       while($row=mysql_fetch_array($query)) {
	         $data[]=$row;
	   }
	   if(!empty($data)) {
	    // Store the result into array
	      return $data;
	   } 
    }
    /* User Verify*/
    public function User_Verify($uid,$type)
    {
	   $uid=mysql_real_escape_string($uid);
	   $type=mysql_real_escape_string($type);
	   if(strlen($type)) {
	      /* Unverified */
	     $query=mysql_query("UPDATE users SET verified='0' WHERE uid='$uid'")or die(mysql_error());
	   } else {
	     echo "UPDATE users SET verified='1' WHERE uid='$uid'";
	   /* Verified */
       $query=mysql_query("UPDATE users SET verified='1' WHERE uid='$uid'")or die(mysql_error());
     }
     return $query;
    }
	 /* User Verified Details*/
    public function Verified_Users_Details($start,$per_page)
    {
	   $start=mysql_real_escape_string($start);
	   $per_page=mysql_real_escape_string($per_page);
       $query=mysql_query( "SELECT uid,username,email,friend_count,profile_pic,conversation_count,updates_count,
	   profile_pic_status,verified,provider,name  FROM users WHERE status='1' AND verified='1' ORDER BY uid DESC LIMIT $start, $per_page")or die(mysql_error());
       while($row=mysql_fetch_array($query)) {
	        $data[]=$row;
	   }
	  if(!empty($data)) {
	   // Store the result into array
	   return $data;
	 } 
    }
	 /* Comments Details*/
    public function Comments_Details($start,$per_page)
    {
	   $start=mysql_real_escape_string($start);
	   $per_page=mysql_real_escape_string($per_page);
       $query=mysql_query( "SELECT C.com_id,C.comment,U.username,U.name,U.uid  FROM comments C, users U WHERE U.uid=C.uid_fk  ORDER BY com_id DESC LIMIT $start, $per_page")or die(mysql_error());
       while($row=mysql_fetch_array($query)) {
	         $data[]=$row;
	    }
	     if(!empty($data)) {
	   // Store the result into array
	   return $data;
	 }
    }
	/* UserUploads Details*/
    public function UserUploads_Details($start,$per_page)
    {
		$start=mysql_real_escape_string($start);
		$per_page=mysql_real_escape_string($per_page);
		$query=mysql_query("
		SELECT
		G.image_path,
		G.id,
		G.uid_fk,
		U.username,
		U.name,
		U.uid,
		M.comment_count,
		M.like_count
		FROM
		user_uploads G
		INNER JOIN  users U ON U.uid=G.uid_fk
		INNER JOIN messages M ON FIND_IN_SET(G.id, M.uploads)
		ORDER BY id DESC LIMIT $start, $per_page")or die(mysql_error());
		while($row=mysql_fetch_array($query)) {
	          $data[]=$row;
	    }
	    if(!empty($data)) {
	     // Store the result into array
	     return $data;
	 }
    }
	/* Profile Details*/
    public function ProfileUploads_Details($start,$per_page)
    {
	   $start=mysql_real_escape_string($start);
	   $per_page=mysql_real_escape_string($per_page);
       $query=mysql_query( "SELECT G.profile_image_path,G.id,G.uid_fk,U.username,U.name,U.uid  FROM user_profile_images G, users U WHERE U.uid=G.uid_fk ORDER BY id DESC LIMIT $start, $per_page")or die(mysql_error());
       while($row=mysql_fetch_array($query)) {
	         $data[]=$row;
	   }
	   if(!empty($data)) {
	   // Store the result into array
	   return $data;
	 }
    }
    public function User_Profile_Image($uid,$base_url) 
	{
	     $uid=mysql_real_escape_string($uid);
		 $query = mysql_query("SELECT email,profile_pic FROM `users` WHERE uid='$uid'") or die(mysql_error());
		 $row=mysql_fetch_array($query);
		 if(!empty($row['profile_pic'])) {
			 $profile_pic_path=$base_url.'user_profile_uploads/';
			 $data= $profile_pic_path.$row['profile_pic'];
		     return $data;
		 } else {
		   $data=$base_url."mat_icons/default.jpg";
		   return $data;
		 }
	}
	/* User Block*/
    public function User_Block($uid,$type)
    {
	$uid=mysql_real_escape_string($uid);
	$type=mysql_real_escape_string($type);
	if(strlen($type)) {
	   /* Unblock */
	   $query=mysql_query("UPDATE users SET status='1' WHERE uid='$uid'")or die(mysql_error());
	  } else {
	  /* block */
       $query=mysql_query("UPDATE users SET status='2' WHERE uid='$uid'")or die(mysql_error());
     }
	  return $query;
    }
    /* User Delete*/
    public function User_Delete($uid)
    {
	   $uid=mysql_real_escape_string($uid);
       if(strlen($uid)) {
		  mysql_query("DELETE FROM conversation_reply WHERE user_id_fk='$uid'")or die(mysql_error());
		  mysql_query("DELETE FROM conversation WHERE user_one='$uid' OR user_two='$uid'")or die(mysql_error());
		  mysql_query("DELETE FROM user_uploads WHERE uid_fk='$uid'")or die(mysql_error());
		  mysql_query("DELETE FROM comment_like WHERE uid_fk='$uid'")or die(mysql_error());
		  mysql_query("DELETE FROM message_share WHERE uid_fk='$uid'")or die(mysql_error());
		  mysql_query("DELETE FROM message_like WHERE uid_fk='$uid'")or die(mysql_error());
		  mysql_query("DELETE FROM group_users WHERE uid_fk='$uid'")or die(mysql_error());
		  mysql_query("DELETE FROM groups WHERE uid_fk='$uid'")or die(mysql_error());
		  mysql_query("DELETE FROM comments WHERE uid_fk='$uid'")or die(mysql_error());
		  mysql_query("DELETE FROM messages WHERE uid_fk='$uid'")or die(mysql_error());
		  mysql_query("DELETE FROM users WHERE uid='$uid'")or die(mysql_error());
	}
	return $query;
    }
	/* User Delete*/
    public function Message_Delete($msg_id)
    {
	   $msg_id=mysql_real_escape_string($msg_id);
       if(strlen($msg_id)) {
          $query=mysql_query("SELECT com_id  FROM comments WHERE msg_id_fk='$msg_id'")or die(mysql_error());
          while($row=mysql_fetch_array($query)) {
	            $cid=$row['com_id'];
	            mysql_query("DELETE FROM comment_like WHERE com_id_fk='$cid'")or die(mysql_error());
	   }
    mysql_query("DELETE FROM reported_post WHERE report_id='$msg_id'")or die(mysql_error());
	mysql_query("DELETE FROM message_share WHERE uid_fk='$msg_id'")or die(mysql_error());
	mysql_query("DELETE FROM message_like WHERE uid_fk='$msg_id'")or die(mysql_error());
	mysql_query("DELETE FROM comments WHERE msg_id_fk='$msg_id'")or die(mysql_error());
	mysql_query("DELETE FROM messages WHERE msg_id='$msg_id'")or die(mysql_error());

	}
	return $query;
    }
	/* Comment Delete*/
    public function Comment_Delete($com_id)
    {
	   $com_id=mysql_real_escape_string($com_id);
       if(strlen($com_id)) {
	      mysql_query("DELETE FROM comment_like WHERE com_id_fk='$com_id'")or die(mysql_error());
	      mysql_query("DELETE FROM comments WHERE com_id='$com_id'")or die(mysql_error());
	   }
	   return true;
    }
	/*Delete images*/
	public function Delete_Image($pid,$upload_path)
	{
	   $com_id=mysql_real_escape_string($pid);
	   $query=mysql_query("SELECT id,image_path FROM user_uploads U WHERE id='$pid'");
	   $num=mysql_num_rows($query);
       if($num>0) {
	      $data=mysql_fetch_array($query);
	      $final_image="../".$upload_path.$data['image_path'];
	      unlink($final_image);
          $q=mysql_query( "SELECT uploads,msg_id FROM messages WHERE  uploads!=0 AND  uploads LIKE '%$pid%';");
	      $d=mysql_fetch_array($q);
	      $msgid=$d['msg_id'];
	      $str = $d['uploads'];
          $tmp = explode(",", $str);
	      $key = array_search($pid, $tmp);
	      if($key)
	         $tmp[$key] = null;
	         $tmp = array_filter($tmp);
	         $newSet = implode(",",$tmp);
	         $newSet=(string)$newSet;
         if($newSet==$str) {
	        $pattern = '/(\,)?'.$pid.'(\,)?/i';
	        $newSet=preg_replace($pattern, '', $str);
	      }
         if(strlen($newSet)==0)
	        $newSet='0';
            mysql_query("UPDATE messages SET uploads='$newSet' WHERE msg_id='$msgid'") or die(mysql_error());
	       $query = mysql_query("DELETE FROM user_uploads WHERE id='$pid'") or die(mysql_error());
	    return true;
	    }
    }
	/* Configurations*/
	public function Get_Configurations() 
	{
	   $query=mysql_query("SELECT notificationPerPage,uploadImage,profileWidth,friendsWidgetPerPage,adminPerPage,annoncement,scriptName,scriptTitle,scriptLogo FROM configuration WHERE con_id='1'")or die(mysql_error());
       $data=mysql_fetch_array($query);
	   return $data;
	}
    /*User Settings*/
     public function ScriptLogoChange($actual_image_name) 
	 {
	   if($actual_image_name) {
	       mysql_query("UPDATE configuration SET scriptLogo='$actual_image_name' WHERE con_id='1'") or die(mysql_error());	
        }
        return true;
      }
	 
     /* Updates Details*/
    public function Updates_Details($start,$per_page)
    {
	   $start=mysql_real_escape_string($start);
	   $per_page=mysql_real_escape_string($per_page);
       $query=mysql_query("SELECT M.msg_id,M.message,M.video,M.uploads,U.username,U.name,U.uid  FROM messages M, users U WHERE U.uid=M.uid_fk  ORDER BY msg_id DESC LIMIT $start, $per_page")or die(mysql_error());
       while($row=mysql_fetch_array($query)) {
	         $data[]=$row;
	   }
	       if(!empty($data)) {
	    // Store the result into array
	      return $data;
	   } 
    }
	 /* Updates Details*/
    public function Updates_Detailss($start,$per_page)
    {
	   $start=mysql_real_escape_string($start);
	   $per_page=mysql_real_escape_string($per_page);
       $query=mysql_query("SELECT 
	          users.uid,
		      users.username,
		      users.name,
		      user_uploads.uid_fk,
		      user_uploads.id,
		      user_uploads.image_path,
		      messages.msg_id,
		      messages.message,
			  messages.video,
		      messages.uid_fk,
		      messages.uploads,
		      messages.comment_count,
		      messages.like_count 
		      FROM users 
		      INNER JOIN messages
		      ON users.uid  = messages.uid_fk
		      INNER JOIN user_uploads 
		      ON messages.uploads = user_uploads.id
		      ORDER BY msg_id DESC LIMIT $start, $per_page")or die(mysql_error());
              while($row=mysql_fetch_array($query)) {
	          $data[]=$row;
	  }
	  if(!empty($data)) {
	   // Store the result into array
	   return $data;
	 } 
    }
	/*Id Image Upload*/
	public function Get_Upload_Video_Id($id) 
	{	
        $query = mysql_query("select video_name,video_ext from user_uploads where id='$id'") or die(mysql_error());
        $result = mysql_fetch_array($query);
    	return $result;
    }
	/*User Lister*/
	 public function User_Lister($uid,$base_url)
	 {
	     $uid=mysql_real_escape_string($uid);
		 $query = mysql_query("SELECT email,profile_pic FROM `users` WHERE uid='$uid'") or die(mysql_error());
		 $row=mysql_fetch_array($query);
		 if(!empty($row['profile_pic'])) {
		    $profile_pic_path=$base_url.'user_profile_uploads/';
		    $data= $profile_pic_path.$row['profile_pic'];
		    return $data;
		   } else {
		     $data=$base_url."mat_icons/default.jpg";
			 return $data;
		  }
	  }
		/*Id Image Upload*/
	public function Get_Upload_Image_Id($id) 
	{	
        $query = mysql_query("select image_path from user_uploads where id='$id'") or die(mysql_error());
        $result = mysql_fetch_array($query);
    	return $result;
    }
	/*User Full Name*/
	public function UserFullName($username) 
	{
	   $username=mysql_real_escape_string($username);
	   $query = mysql_query("SELECT name FROM `users` WHERE username='$username'") or die(mysql_error());
	   $data=mysql_fetch_array($query);
	   if($data['name']) {
		  $name=$data['name'];
		  $str_length = strlen($name);       
          if($str_length > 25) {
             $name= substr($name, 0, 25) . "..." ;
          }
		    return ucfirst($name);    
	      } else {
		    return $username;
	      }
	
	}
	/* Image Config*/
	public function Image_Config($uploadimage,$banner,$profile,$gravatar)
	{
      $final_uploadimage=$uploadimage*1024;
      mysql_query( "UPDATE configurations SET uploadImage='$final_uploadimage',bannerWidth='$banner',profileWidth='$profile',gravatar='$gravatar'  WHERE con_id='1'")or die(mysql_error());
      return $data;
	}

	/* PerPage Config*/
	public function Perpage_Config($NewsFeedPerPage,$notifications,$friends,$friendsWidget,$photos,$groups,$admin,$forgot)
	{
      mysql_query("UPDATE configurations SET newsfeedPerPage='$NewsFeedPerPage',notificationPerPage='$notifications',friendsPerPage='$friends',photosPerPage='$photos',groupsPerPage='$groups',adminPerPage='$admin',friendsWidgetPerPage='$friendsWidget',forgot='$forgot'  WHERE con_id='1'")or die(mysql_error());
      return $data;
	}
	/*Insert Annoncement*/
	public function Insert_Annoncement($annoncement)
	{
		$annoncement=mysql_real_escape_string($annoncement);// Update is text update
		mysql_query("UPDATE configuration SET annoncement='$annoncement' WHERE con_id='1'") or die(mysql_error());
	    // Insert an image if user selected correct formating image
		mysql_query("UPDATE users SET announcement_readed='1'") or die(mysql_error());	
	}
	/*Change Script Name*/
	public function InsertScriptName($scriptName)
	{
		$scriptName=mysql_real_escape_string($scriptName);// Update is text update
		mysql_query("UPDATE configuration SET scriptName='$scriptName' WHERE con_id='1'") or die(mysql_error());	
	}
	/*Change Script Title*/
	public function InsertScriptTitle($scriptTitle)
	{
		$scriptTitle=mysql_real_escape_string($scriptTitle);// Update is text update
		mysql_query("UPDATE configuration SET scriptTitle='$scriptTitle' WHERE con_id='1'") or die(mysql_error());	
	}
	 /* Comments Details*/
    public function Report_Details($start,$per_page)
    {
	   $start=mysql_real_escape_string($start);
	   $per_page=mysql_real_escape_string($per_page);
       $query=mysql_query("SELECT R.r_id,R.report_id,R.report_type,R.uid_fk,U.username,U.name,U.uid  FROM reported_post R, users U WHERE U.uid=R.uid_fk  ORDER BY r_id DESC LIMIT $start, $per_page")or die(mysql_error());
       while($row=mysql_fetch_array($query)) {
	         $data[]=$row;
	      }
	      if(!empty($data)) {
	       // Store the result into array
	         return $data;
	       }
    }
	/*Recent Complaints*/
	public function Recent_Complaints_Details()
	{
	   	$query=mysql_query("SELECT R.r_id,R.report_id,R.report_type,R.uid_fk,U.username,U.name,U.uid FROM  reported_post R, users U WHERE U.uid=R.uid_fk ORDER BY r_id DESC LIMIT 10") or die(mysql_error());
		 while($row=mysql_fetch_array($query)){
			   $data[]=$row;
			  }
			  if(!empty($data)){
				return $data;
			}
		
    }
	// Show status for reporting
	public function Status_Update($msgid)
	{
		$msgid = mysql_real_escape_string($msgid);
	    // Show the status update details. Like tex, like count , comment count ext.
	     $query = mysql_query("SELECT M.msg_id, M.uid_fk, M.message, M.created,M.like_count,M.comment_count,M.share_count,U.username,M.uploads 
	     FROM messages M, users U  
	     WHERE U.status='1' 
	     AND M.uid_fk=U.uid and M.msg_id='$msgid'") or die(mysql_error());
	     while($row=mysql_fetch_array($query)) {
			   $data[]=$row;
		     }
		     return $data;
	}
	/*Like Validate Check*/
	public function Like_Check($msg_id, $uid)
	{
		$msg_id=mysql_real_escape_string($msg_id);
	    $uid=mysql_real_escape_string($uid);
	    //Check that users Liked the message.
	     $q=mysql_query("SELECT like_id FROM message_like WHERE  uid_fk='$uid' and msg_id_fk='$msg_id'");
	    // Output the result
	    if(mysql_num_rows($q)==0) {
		    return true;
		 } else {
			 return false;
		 }
	}
	/*User Profile Picture */
	public function User_Profilepic($uid, $base_url)
	{
		$uid=mysql_real_escape_string($uid);
	   //This is checking user uploded profile image or not
	    $query = mysql_query("SELECT email,profile_pic,profile_pic_status FROM `users` WHERE uid='$uid'") or die(mysql_error());
	    $row=mysql_fetch_array($query);
		if($row['profile_pic_status']) { // Checking profile image status 1 or 0 
		if(!empty($row['profile_pic'])) {  // If profile image is not empty then show the profile image from user profile image folder
			 $profile_pic_path=$base_url.'user_profile_uploads/';
			 $data= $profile_pic_path.$row['profile_pic'];
			 return $data;
		   } else { 
		      // If user not uploaded an profile image then show default image from mat_icons folder
		      // If you want to change default image for profile image then you can fined it from mat_cions folder in default.jpg
			   $data=$base_url."mat_icons/default.jpg";
			   return $data;
		   }
		   } else { 
		       // If the profile imag status is 0 then show the user gravatar image from the data link
		      /*Gravator Image*/
			   $email=$row['email']; // Gravatar email
			   $lowercase = strtolower($email); // Checking email for gravatar image 
			   $imagecode = md5($lowercase);
			   $data="http://www.gravatar.com/avatar/".$imagecode."?d=mm&s=230"; // Gravatar image link for user profile image
			   return $data;
		   }
	}
	/*Like Users*/
	public function Like_Users($msg_id)
	{
		// This is showing which user liked the updated message
	    $msg_id=mysql_real_escape_string($msg_id); 
	    $q=mysql_query("SELECT like_id FROM message_like WHERE msg_id_fk='$msg_id' ");
	    if(mysql_num_rows($q)>0) { // If any user liked the updated message
		    $query=mysql_query("SELECT U.username FROM message_like M, users U WHERE U.uid=M.uid_fk AND M.msg_id_fk='$msg_id' LIMIT 3"); 
		    // Then showing the username in liked user. Like: abc,def liked this
		    while($row=mysql_fetch_array($query)) {
				 $data[]=$row;
			   }
		   return $data;
		}
	}
	/*Comments*/
	public function Comments($msg_id, $second_count)
	{
		$query='';
	    if($second_count) {
		    // The scond count is showing comment count limited
			 $query="limit $second_count,2";
		 }
		 //The query to select comments
		 $query = mysql_query("SELECT C.com_id, C.uid_fk, C.comment, C.created,C.like_count, U.username FROM comments C, users U WHERE U.status='1' AND C.uid_fk=U.uid and C.msg_id_fk='$msg_id' order by C.com_id asc $query") or die(mysql_error());
		 //Store the result
		 while($row=mysql_fetch_array($query))
		 // Store the result into array
		       $data[]=$row;
			   if(!empty($data)) {
				  // Store the result into array
				  return $data;
				}
	}
	/* Template Update*/
	public function Insert_Advertisment($ads_title,$ads_description,$ads_url,$ads_durl,$ads_img)
	{

	   mysql_query("INSERT INTO s_advertisements(ads_title,ads_description,ads_url,ads_durl,ads_img)VALUES('$ads_title','$ads_description','$ads_url','$ads_durl','$ads_img')")or die(mysql_error());
       $query=mysql_query("SELECT ads_id,ads_title,ads_description,ads_url,ads_durl,ads_img FROM s_advertisements ORDER BY ads_id DESC LIMIT 1")or die(mysql_error());
	   $data=mysql_fetch_array($query);
	   return $data;
	}

	/* Advertisments*/
	public function Advertisments()
	{
      $query=mysql_query( "SELECT ads_id,ads_title,ads_description,ads_url,ads_durl,ads_img,status FROM s_advertisements ORDER BY ads_id DESC")or die(mysql_error(  ));
	   while($row=mysql_fetch_array($query)) {
	        $data[]=$row;
	    }
	    if(!empty($data)) {
		  // Store the result into array
		  return $data;
	    }
	}
	/* Template Update*/
	public function Advertisment_Delete($ads_id)
	{
      $ads_id=mysql_real_escape_string($ads_id);
	  mysql_query("DELETE FROM s_advertisements WHERE ads_id='$ads_id'")or die(mysql_error());
      return true;
	}
}
?>
