ok
Direktori : /home2/selectio/public_html/subamangala/admin/apis/ |
Current File : /home2/selectio/public_html/subamangala/admin/apis/preferance-create-update-api.php |
<?php ob_start(); session_start(); include "../config/config.php"; $session_id = $_SESSION['subamangala_matrimony']['id']; // City Details Create, Update Starts Here if(isset($_POST['type']) && $_POST['type']=='create_update_preferance'){ try{ /* Preferance Insert And Update Starts Here */ if(isset($_POST['setpreference'])) { $profileid=$_POST['ids']; $caste='';$natchatram='';$miny='';$maxy='';$thosam='';$height_cat='';$edu='';$marriage='';$servicedate='';$Total_Count='';$limit=''; $insertstatus=$_POST['insertstatus']; if(!empty($_POST['caste'])){ // Loop to store and display values of individual checked checkbox. foreach($_POST['caste'] as $crop){ $caste=$caste.''.$crop.','; } } else{ $caste=''; } if(!empty($_POST['natchatram'])){ // Loop to store and display values of individual checked checkbox. foreach($_POST['natchatram'] as $nat){ $natchatram=$natchatram.''.$nat.','; } } else{ $natchatram=''; } if(!empty($_POST['miny'])){ // Loop to store and display values of individual checked checkbox. $miny=$_POST['miny']; $maxy=$_POST['maxy']; } else{ $miny='';$maxy=''; } if(!empty($_POST['thosam'])){ // Loop to store and display values of individual checked checkbox. foreach($_POST['thosam'] as $tho){ $thosam=$thosam.''.$tho.','; } } else{ $thosam=''; } if(!empty($_POST['height_cat'])){ // Loop to store and display values of individual checked checkbox. foreach($_POST['height_cat'] as $height){ $height_cat=$height_cat.''.$height.','; } } else{ $height_cat=''; } if(!empty($_POST['edu'])){ // Loop to store and display values of individual checked checkbox. foreach($_POST['edu'] as $ed){ $edu=$edu.''.$ed.','; } } else{ $edu=''; } if(!empty($_POST['marriage'])){ // Loop to store and display values of individual checked checkbox. $marriage=$_POST['marriage']; } else{ $marriage=''; } if(!empty($_POST['date'])){ // Loop to store and display values of individual checked checkbox. $servicedate=$_POST['date']; $servicedate=date('Y-m-d', strtotime($servicedate)); } else{ $servicedate=''; } for($k=0;$k<=count($_POST['upload_image']);$k++){ if(isset($_FILES['upload_image']["name"][$k]) && $_FILES['upload_image']['tmp_name'][$k]!='') { $extensionimage = end(explode(".", $_FILES["upload_image"]["name"][$k])); $image = rand(10,1000000000)."-".$date."-image." . $extensionimage; $upload = move_uploaded_file($_FILES['upload_image']['tmp_name'][$k], '../horoscope-upload/' . $image); $upload_multi_image = 'horoscope-upload/' . $image; } else if(isset($_POST['upload_image'][$k])) { $upload_multi_image=$_POST['upload_image'][$k]; }else{ $upload_multi_image='../horoscope-upload/default-img.png'; } $statement7 = $pdo->prepare("INSERT INTO `upload_img`(`profile_id`, `img`, `status`) VALUES ($profileid,'".$upload_multi_image."','1')"); $result7=$statement7->execute(); } $limit_sta=$_POST['limit_sta']; $limit=$_POST['limit']; $days=$_POST['days']; $login=$_POST['login']; date_default_timezone_set('Asia/Kolkata'); $cur=date('Y-m-d'); if($days=='1') { $curdate=date('Y-m-d'); } elseif($days=='0') { $curdate=''; } else { $statement = $pdo->prepare("select * from preference where Profileid='$profileid' and Pref_Days='$days'"); $statement->execute(); $datas = $statement->fetchAll(PDO::FETCH_ASSOC); $totalData = $statement->rowCount(); if($datas) { $curdate=$datas[0]['Entry_Date']; } else { $dayss='+'.$days.' day'; $curdate=date('Y-m-d', strtotime($dayss, strtotime($cur))); } } //$limit_sta=''; if($insertstatus=='Updatevalue') { if($limit_sta=='Automatic') { $statements = $pdo->prepare("select * from preference where Profileid='$profileid' and Pref_Limit='$limit'"); $statements->execute(); $datass = $statements->fetchAll(PDO::FETCH_ASSOC); $totalDatas = $statements->rowCount(); if($datass) { $Total_Count=$datass[0]['Total_Count']; } else { $Total_Count=$limit; } } $statement2 = $pdo->prepare("UPDATE `preference` SET `Pref_Caste`=?, `Pref_Star`=?, `Pref_Dhosam`=?, `Pref_Edu`=?, `Pref_Height`=?, `Pref_Marriage`=?, `From_Year`=?, `To_Year`=?, `Pref_Limit`=?, `Pref_Days`=?, `Entry_Date`=?, `Limit_Status`=?, `Service_Date`=?, `Total_Count`=? WHERE Profileid=?"); $result2 = $statement2->execute(array($caste, $natchatram, $thosam, $edu, $height_cat, $marriage, $miny, $maxy, $limit, $days, $curdate, $limit_sta, $servicedate, $Total_Count, $profileid)); if($result2) { $cont=gettotalmatches($profileid,$con); //$cont=0; $statement3 = $pdo->prepare("UPDATE `profiles` SET `Total_Matches`=? WHERE `id`= ?"); $result3 = $statement3->execute(array($cont, $profileid)); } } else{ if($limit_sta=='Automatic') { $Total_Count=$limit; //$Days_Count=$days; } else{ $Total_Count=''; } $statement6 = $pdo->prepare("INSERT INTO `admin_preference`(`Pref_Caste`,`Pref_Star`,`Pref_Dhosam`,`Pref_Edu`,`Pref_Height`,`Pref_Marriage`,`From_Year`,`To_Year`,`Profileid`,`Pref_Limit`,`Pref_Days`,`Entry_Date`,`Limit_Status`,`Service_Date`,`Total_Count`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); $result6 = $statement6->execute(array($caste,$natchatram,$thosam,$edu,$height_cat,$marriage,$miny,$maxy,$profileid,$limit,$days,$curdate,$limit_sta,$servicedate,$Total_Count)); if($result6) { $cont=gettotalmatches($profileid,$con); //$cont=0; $statement10 = $pdo->prepare("UPDATE `profiles` SET `Total_Matches`=? WHERE `id`= ?"); $result10 = $statement10->execute(array($cont, $profileid)); } } }if($result2){ $return_arr['message']='Preferance Details Updated Successfully...'; // $return_arr['last_id']=$last_id; $return_arr['status']=200; } else{ $return_arr['message']='Something Went Wrong..'; $return_arr['status']=400; } }catch(PDOException $e){ $return_arr['message']="$e"; $return_arr['status']=500; } echo json_encode($return_arr); } /* Preferance Insert And Update Ends Here*/ function gettotalmatches($profileid,$pdo) { $cont='0'; //echo $query; $statement9 = $pdo->prepare("select count(*) as cont from profiles Ori,preference pref, profiles Mat left outer join rassi r on Mat.rasi=r.id left OUTER join natchatram n on Mat.natchatram=n.id left OUTER join caste c on c.id=Mat.caste left OUTER join subcaste s on s.id=Mat.subcaste WHERE Ori.id='$profileid' and pref.Profileid=Ori.id and Year(STR_TO_DATE(Mat.dob,'%d-%m-%Y')) BETWEEN if(pref.From_Year='',1900,From_Year) and if(pref.To_Year='',year(CURDATE()),To_Year) and Mat.gender<>Ori.gender and c.id like if(pref.Pref_Caste='','%',if(FIND_IN_SET(c.id,pref.Pref_Caste)<>0,c.id,0)) and n.id like if(pref.Pref_star='','%',if(FIND_IN_SET(n.id,pref.Pref_Star)<>0,n.id,0)) and Mat.edu_cat like if(pref.Pref_Edu='','%',FIND_IN_SET(Mat.edu_cat,pref.Pref_Edu)) and Mat.height_cat like if(pref.Pref_Height='','%',FIND_IN_SET(Mat.height_cat,pref.Pref_Height)) and Mat.marriage like if(pref.Pref_Marriage='','%',FIND_IN_SET(Mat.marriage,pref.Pref_Marriage)) and Mat.regnop like if(pref.Pref_Dhosam='','%',FIND_IN_SET(Mat.regnop,pref.Pref_Dhosam)) order by c.id"); $statement9->execute(); $datas9 = $statement9->fetchAll(PDO::FETCH_ASSOC); if($datas9) { $cont=$datas9[0]['cont']; } return $cont; } ?>