Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This one of my code work:
- <?php
- class toy{
- //Constructor for the class toy.
- function __construct(){
- }
- function getToysInfo($toy_id = ""){
- global $objDB;
- if(!empty($toy_id)){
- $sql="select * from toys where toy_id='".$toy_id."'";
- }else{
- $sql="select * from toys";
- }
- $res=$objDB->select($sql);
- return $res;
- }
- //Following function gets the count of total records from the table for paging.
- function getToysCount($extraPara=""){
- global $objDB;
- $sql = "SELECT count(*) as tot FROM toys WHERE 1=1 ".$extraPara;
- $res = $objDB->select($sql);
- return $res[0]['tot'];
- }
- //Following function gets the records from the table for listing.
- function getToysData($extraPara=""){
- global $objDB;
- $sql = "SELECT * FROM toys WHERE 1=1 ".$extraPara;
- $res = $objDB->select($sql);
- return $res;
- }
- //Following function gets the records from the table for for perticular record, required for edit mode auto fill up.
- function getToyById($pkid){
- global $objDB;
- $sql = "SELECT * FROM toys WHERE toy_id= ".$pkid;
- $res = $objDB->select($sql);
- if(count($res) > 0){
- return $res;
- }
- }
- //Following function makes entry to the table. Argument passed is POST Array.
- function addToy(){
- global $objDB;
- $sql = "INSERT INTO `toys` SET
- `toy_name` = '".addslashes($_REQUEST['toy_name'])."',
- `toy_desc` = '".addslashes($_REQUEST['toy_desc'])."',
- `toy_price` = '".$_REQUEST['toy_price']."',
- `brand_id` = '".$_REQUEST['brand_id']."',
- `age_range` = '".$_REQUEST['age_range']."',
- `createdOn` = '".date('Y-m-d H:i:s')."',
- `status` = '".$_REQUEST['status']."'";
- $ins = $objDB->insert($sql);
- if($ins){
- $this->addToyCategories($ins);
- $this->addToyImages($ins,'add');
- $this->addToyStocks($ins,$_REQUEST['stock']);
- return $ins;
- }else{
- return false;
- }
- }
- function addToyCategories($toy_id){
- global $objDB;
- $catArr = $_REQUEST['cat_id'];
- if(is_array($catArr) && count($catArr) > 0 ){
- foreach($catArr as $x){
- $sql = "insert into toy_category_map(`toy_id`,`cat_id`) values('".$toy_id."','".$x."')";
- $objDB->insert($sql);
- }
- }
- return true;
- }
- function deleteToyCategories($toy_id){
- global $objDB;
- if($ids != ""){
- $sql = "DELETE FROM toy_category_map WHERE toy_id = '".$toy_id."'";
- $res = $objDB->sql_query($sql);
- return true;
- }else{
- return false;
- }
- }
- function getToyCategories($toy_id){
- global $objDB;
- $sql="select cat.* from toy_category_map as map
- left join toy_categories as cat on cat.cat_id = map.cat_id
- where map.toy_id='".$toy_id."'";
- //echo $sql;
- $res=$objDB->select($sql);
- return $res;
- }
- function addToyImages($toy_id,$opt){
- global $objDB;
- $is_default_exist = $this->isDefaultImageExist($toy_id);
- $files = $_FILES['toy_images'];
- if(is_array($files) && count($files) > 0){
- foreach($files['name'] as $key => $x){
- if(!empty($x)){
- $file_name = pathinfo($x,PATHINFO_FILENAME);
- $file_ext = pathinfo($x,PATHINFO_EXTENSION);
- $image_name = sanitize($file_name);
- $image_name = $image_name.".".$file_ext;
- $new_file_path = APP_BASE_PATH.TOY_IMAGES_PATH.$image_name;
- if(move_uploaded_file($files['tmp_name'][$key],$new_file_path)){
- $is_default = ($_REQUEST['is_default'] == ($key+1)?'Yes':'No');
- if(!$is_default_exist){
- $sql = "insert into toy_images(`image_name`,`is_default`,`toy_id`) values( "
- ." '".$image_name."','".$is_default."','".$toy_id."')";
- }else{
- $sql = "insert into toy_images(`image_name`,`toy_id`) values( "
- ." '".$image_name."','".$toy_id."')";
- }
- $ins = $objDB->insert($sql);
- $this->addSliderImage($key,$ins);
- }
- }
- }
- }
- return true;
- }
- function addSliderImage($id,$image_id){
- global $objDB;
- // STORING SLIDER IMAGES
- $slider_file = $_FILES['toy_slider_images'];
- if(isset($slider_file['name'][$id])){
- $x = $slider_file['name'][$id];
- $file_name = pathinfo($x,PATHINFO_FILENAME);
- $file_ext = pathinfo($x,PATHINFO_EXTENSION);
- $image_name = sanitize($file_name);
- $image_name = "slider-".$image_name.".".$file_ext;
- $new_file_path = APP_BASE_PATH.TOY_IMAGES_PATH.$image_name;
- if(move_uploaded_file($slider_file['tmp_name'][$id],$new_file_path)){
- $sql = "update toy_images set `slider_image` = '".$image_name."' where image_id = '".$image_id."'";
- $objDB->edit($sql);
- }
- }
- }
- function isDefaultImageExist($toy_id){
- global $objDB;
- $sql="SELECT * FROM toy_images WHERE is_default = 'Yes' AND toy_id = '".$toy_id."'";
- $res=$objDB->select($sql);
- if(is_array($res) && count($res) > 0){
- return true;
- }
- return false;
- }
- //Following function updates record to the table. Argument passed is POST Array and record unique ID.
- function editToy(){
- global $objDB;
- $sql = "UPDATE `toys` SET
- `toy_name` = '".addslashes($_REQUEST['toy_name'])."',
- `toy_desc` = '".addslashes($_REQUEST['toy_desc'])."',
- `toy_price` = '".$_REQUEST['toy_price']."',
- `brand_id` = '".$_REQUEST['brand_id']."',
- `age_range` = '".$_REQUEST['age_range']."',
- `status` = '".$_REQUEST['status']."'
- where toy_id = '".$_REQUEST['toy_id']."'";
- $rs = $objDB->edit($sql);
- $this->deleteToyCategories($_REQUEST['toy_id']);
- $this->addToyCategories($_REQUEST['toy_id']);
- $this->addToyImages($_REQUEST['toy_id'],'edit');
- $this->addToyStocks($_REQUEST['toy_id'],$_REQUEST['stock']);
- return true;
- }
- function getToyImages($toy_id){
- global $objDB;
- $sql="select * from toy_images where toy_id='".$toy_id."'";
- $res=$objDB->select($sql);
- return $res;
- }
- function deleteToyImage($image_id){
- global $objDB;
- $sql = "DELETE FROM toy_images WHERE image_id = '".$image_id."'";
- $res = $objDB->sql_query($sql);
- }
- function checkToyname($username){
- global $objDB;
- $sql = "SELECT count(*) as tot FROM toys WHERE username='".$username."'";
- $res = $objDB->select($sql);
- ($res);
- if($res){
- $cnt=$res[0]['tot'];
- return $cnt;
- }else{
- return false;
- }
- }
- //Following functon check for toys table and finds out if email already exists or not
- function checkToyEmail($email,$id=""){
- global $objDB;
- $idCond ="";
- if($id != ""){
- $idCond = " and toy_id !='".$id."'";
- }
- $sql="select toy_id from toys where email='".$email."' ".$idCond;
- $res=$objDB->select($sql);
- if(count($res) > 0){
- return '_DUPLICATE_';
- }else{
- return '_UNIQUE_';
- }
- }
- //Following function deletes all the records specyfied by the argument (comma seperated).
- function deleteToys($ids){
- global $objDB;
- if($ids != ""){
- $sql = "DELETE FROM toys WHERE toy_id in ('".$ids."')";
- $res = $objDB->sql_query($sql);
- return true;
- }else{
- return false;
- }
- }
- //Following function marks all the records as Active specyfied by the argument (comma seperated).
- function markActive($ids){
- global $objDB;
- if($ids != ""){
- $sql = "UPDATE toys SET status = 'Active' WHERE toy_id in ('".$ids."')";
- $res = $objDB->edit($sql);
- return true;
- }else{
- return false;
- }
- }
- //Following function marks all the records as Inactive specyfied by the argument (comma seperated).
- function markInActive($ids){
- global $objDB;
- if($ids != ""){
- $sql = "UPDATE toys SET status = 'InActive' WHERE toy_id in ('".$ids."')";
- $res = $objDB->edit($sql);
- return true;
- }else{
- return false;
- }
- }
- //checks wether the old password provided is corrct or not
- function validPass($aid){
- global $objDB;
- $query="SELECT `password`
- FROM `toys`
- WHERE `toy_id`='".$aid."'";
- $password= $objDB->select($query);
- if($password[0]["password"]==$_POST["old_password"])
- {
- return true;
- }
- else{
- return false;
- }
- }
- //change password
- function changePassword($aid){
- global $objDB;
- $query="UPDATE `toys`
- SET `password` = '".$_POST["password"]."'
- WHERE `toy_id` = '".$aid."'";
- $objDB->edit($query);
- return true;
- }
- //function to get toys details
- function getToyDetail($email){
- Global $objDB;
- $sql = "SELECT *
- FROM toys
- WHERE email='" . $email . "'";
- return $objDB->select($sql);
- }
- //function to send password
- function sendPassword($email){
- Global $objDB, $cfg;
- //the given email address for the forget password request is valid now let us send the email with the forget password to the user
- //Let us do some preparation before sending an email
- //Let us assign few variable which are require in the template that is going to be send in email
- $customer=$this->getToyDetail($email);
- $objDB->assign('username',$customer[0]['email']);
- $objDB->assign('vPassword',$customer[0]['password']);
- $objDB->assign('AppTitle',$objDB->AppName);
- $objDB->assign('SupportEmail',$objDB->AppSupportEmail);
- $objDB->assign('Cusotmer',stripslashes($customer[0]['first_name'])." ".stripslashes($customer[0]['last_name']));
- //Following method sets From Email addres for Email
- $objDB->From=$objDB->getValueFromTable("setting", "varname", "ADMIN_MAIL", "value");
- //Following method sets From Name for Email
- $objDB->FromName=$objDB->getValueFromTable("setting", "varname", "ADMIN_NAME", "value");
- //$template_detail = $objDB->getTemplateDetail("FORGET_PASSWORD");
- }
- function addToyStocks($toy_id,$stock){
- global $objDB;
- if($stock == 0) return;
- $sql = "INSERT INTO `toy_stocks` SET
- `toy_id` = '".$toy_id."',
- `stock` = '".$stock."',
- `createdOn` = '".date('Y-m-d H:i:s')."'";
- $ins = $objDB->insert($sql);
- return true;
- }
- function getToyStocks($toy_id){
- global $objDB;
- $tot_stock = 0;
- $sql = "select sum(stock) as tot from toy_stocks where toy_id='".$toy_id."' group by toy_id";
- $res = $objDB->select($sql);
- if(is_array($res) && count($res) > 0){
- $tot_stock = $res[0]['tot'];
- //$tot_ordered_stock = $this->getOrderedToyCounts($toy_id);
- return $tot_stock;
- }
- return 0;
- }
- function getOrderedToyCounts($toy_id){
- global $objDB;
- $sql = "SELECT sum(qty) AS tot FROM order_detail WHERE toy_id='".$toy_id."' AND `status` in ('delivered') GROUP BY toy_id";
- $res = $objDB->select($sql);
- if(is_array($res) && count($res) > 0){
- return $res[0]['tot'];
- }
- return 0;
- }
- function getReturnToysReqCount(){
- global $objDB;
- $sql = "SELECT count(*) as tot FROM toy_returns";
- $res = $objDB->select($sql);
- return $res[0]['tot'];
- }
- function getReturnToyReqData($return_id = "",$extraParam = ""){
- global $objDB;
- $sql = "SELECT * FROM toy_returns where 1=1";
- if(!empty($return_id)) $sql.= " and return_id='".$return_id."'";
- $sql.=" order by return_id desc";
- $sql.=$extraParam;
- $res = $objDB->select($sql);
- return $res;
- }
- function updateToyBoxReturnStatus($return_id,$toyboxids){
- global $objDB,$queueObj;
- $arr = explode("\n",$toyboxids);
- $cnt = 0;
- if(is_array($arr) && count($arr) > 0){
- foreach($arr as $x){
- $sql = "update toy_queue set `status` = 'returned' where queue_id = '".$x."' and `status` in ('delivered','investigation')";
- if($objDB->edit($sql)){
- $cnt++;
- }
- }
- if($cnt > 0){
- $sql = "update toy_returns set `is_processed` = 'Yes' where return_id = '".$return_id."'";
- $objDB->edit($sql);
- $boxInfo = $this->getToyBoxInfo($x);
- if($boxInfo){
- //SEND RETURN BOX EMAIL
- $subject = "Toy Box Returned";
- $tpl = file_get_contents(APP_BASE_PATH."templates/pickup-toy-email.html");
- $body=str_replace( array('{NAME}','{BOXID}','{TOYNAME}','{RETURNEDON}','{SITE_NAME}','{SITE_URL}'), array($boxInfo['first_name']." ".$boxInfo['last_name'],$x,stripslashes($boxInfo['toy_name']),getFormattedDate(date("Y-m-d")),APP_NAME,APP_URL),$tpl);
- sendEmail($boxInfo['email'],_APP_EMAIL,APP_EMAIL_FROM,$subject,$body);
- }
- }
- }else{
- $sql = "update toy_queue set `status` = 'returned' where queue_id = '".$toyboxids."' and `status` in ('delivered','investigation')";
- $objDB->edit($sql);
- $sql = "update toy_returns set `is_processed` = 'Yes' where return_id = '".$return_id."'";
- $objDB->edit($sql);
- $boxInfo = $this->getToyBoxInfo($x);
- if($boxInfo){
- //SEND RETURN BOX EMAIL
- $subject = "Toy Box Returned";
- $tpl = file_get_contents(APP_BASE_PATH."templates/pickup-toy-email.html");
- $body=str_replace( array('{NAME}','{BOXID}','{TOYNAME}','{RETURNEDON}','{SITE_NAME}','{SITE_URL}'), array($boxInfo['first_name']." ".$boxInfo['last_name'],$toyboxids,stripslashes($boxInfo['toy_name']),getFormattedDate(date("Y-m-d")),APP_NAME,APP_URL),$tpl);
- sendEmail($boxInfo['email'],_APP_EMAIL,APP_EMAIL_FROM,$subject,$body);
- }
- }
- }
- function getToyBoxInfo($queue_id){
- global $objDB;
- $sql = "SELECT tq.*,u.first_name,u.last_name,t.toy_name,u.email FROM toy_queue AS tq
- LEFT JOIN toys AS t ON t.toy_id = tq.toy_id
- LEFT JOIN users AS u ON u.user_id = tq.user_id
- WHERE queue_id='".$queue_id."'";
- $rs = $objDB->select($sql);
- if(is_array($rs) && count($rs) > 0){
- return $rs[0];
- }
- return false;
- }
- } //end class
- ?>
Add Comment
Please, Sign In to add comment