rbs@u2
Home
Php_u2
Html #1
Html #2
Html #3
Html #4
JS #1
JS #2
JS #3
JS #4
JsApi #1
JsApi #2
JsApi #3
JsApi #4
JsApi_u4
all-files
ori-v2
master
user
Logout
dsg
tool css
bootstrtap 5.3
auth
profile
waste
waste_group
venue
vehicle
event
comment
notification
discover
post
scanner
to_delete
const fetch = require('node-fetch'); async function garage(v) { let url=`${v.api}/vehicle/add-vehicle-to-garage/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } async function garage(v) { let url=`${v.api}/vehicle/delete-garage/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } async function garage(v) { let url=`${v.api}/vehicle/get-garage/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } async function garage(v) { let url=`${v.api}/vehicle/get-garage-posts/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } async function garage(v) { let url=`${v.api}/vehicle/get-user-garage/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } async function discover(v) { let url=`${v.api}/vehicle/popular-users-cars/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } async function garage(v) { let url=`${v.api}/vehicle/update-garage/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } const vehicle = { garage, garage, garage, garage, garage, discover, garage, } module.exports = vehicle
Save
ownedFrom!='') { $ef=explode("/",$js->ownedFrom); $own_from=strtotime($ef[2]."-".$ef[1]."-".$ef[0]); } else { $own_from=0; } if($js->ownedTo!='') { $et=explode("/",$js->ownedTo); $own_to=strtotime($et[2]."-".$et[1]."-".$et[0]); } else { $own_to=0; } if(isset($js->user_id)) { $idt=array( 'id'=>$id2, 'allow_tagging'=>$js->allow_tagging, 'colour'=>$js->colour, 'description'=>$js->description, 'make'=>$js->make, 'model'=>$js->model, 'owned_from'=>$own_from, 'owned_to'=>$own_to, 'primary_car'=>$js->primary_car, 'registration'=>$js->registration, 'user_id'=>$js->user_id, 'variant'=>$js->variant, 'vehicle_period'=>$js->vehicle_period, 'create_at'=>time(), ); Insert($db,"garage",$idt,0); if($js->cover_photo) { $data=$js->cover_photo; $image_info = getimagesize($data); $extension = (isset($image_info["mime"]) ? explode('/', $image_info["mime"] )[1]: ""); $dt['type']=$extension; $tmp_file=$ar['img_path']."users/tmp/".$js->user_id.".".$extension; $sub_folder=$ar['img_path']."/users/".$js->user_id; if(!is_dir($sub_folder)){ mkdir($sub_folder, 0755); } $sub_folder_p=$ar['img_path']."/users/".$js->user_id."/g"; if(!is_dir($sub_folder_p)){ mkdir($sub_folder_p, 0755); } $new_file=genRandom(10).".".$extension; $dt['newfile']=$new_file; $data = str_replace('data:image/'.$extension.';base64,', '', $data); $data = str_replace(' ','+',$data); $bin = base64_decode($data); if ($bin === false) { //$dt['info']="convert invalid"; } //tmp file file_put_contents($tmp_file, $bin); ini_set('display_errors', '0'); resize_crop_image(1200,760,$tmp_file,$sub_folder_p."/".$new_file); unlink($tmp_file); $sql="SELECT `seq` from `images` where `modul`='garage' and `item_id`=".$id2." order by `seq` desc limit 1"; $res=mysqli_query($db,$sql); if(mysqli_num_rows($res)==1) { $r = mysqli_fetch_assoc($res); $seq2=$r['seq']+1; } else { $seq2=1; } $sql3="SELECT `id` from `images` order by `id` desc limit 1"; $res3=mysqli_query($db,$sql3); if(mysqli_num_rows($res3)==1) { $r3 = mysqli_fetch_assoc($res3); $id3=$r3['id']+1; } else { $id3=1; } $idt=array( 'id'=>$id2, 'modul'=>'garage', 'item_id'=>$id2, 'seq'=>$seq2, 'create_at'=>time(), 'path'=>$ar['imgurl']."users/".$js->user_id."/g/".$new_file, ); Insert($db,"images",$idt,0); $udt=array( 'cover_photo'=>$ar['imgurl']."users/".$js->user_id."/g/".$new_file, ); Update($db,"garage",$udt,"id=".$id2,0); } $dt['success']=true; $dt['message']="Garage Added successfully"; $dt['id']=$id2; } else { $dt['success']=true; //$dt['message']="Garage Added successfully"; } //$dt['col']=$js; return $dt; } function delete_garage($js){ global $ar,$db; $dt=array(); //{"user_id":67032,"garage_id":"52"} Delete($db,"garage","id=".$js->garage_id,0); $dt['success']=true; $dt['message']="Garage deleted successfully"; return $dt; } function get_garage($js){ global $ar,$db; $dt=array(); $sql2="SELECT allow_tagging,colour,cover_photo,create_at,id,make,model,owned_from,owned_to,user_id,primary_car,registration,description,`status`,variant,update_at from `garage` where id=".$js->garage_id; $res2=mysqli_query($db,$sql2); if(mysqli_num_rows($res2)==1) { $r2 = mysqli_fetch_assoc($res2); $dt=$r2; $dt['create_at']=date("Y-m-d H:i:s",$r2['create_at']); $dt['update_at']=date("Y-m-d H:i:s",$r2['update_at']); $dt['status']=$ar['st_garage'][$r2['status']]; $dt['owner_id']=$r2['user_id']; if($r2['owned_from']>0) { $dt['owned_since']=date("d/m/Y",$r2['owned_from']); } if($r2['owned_to']>0) { $dt['owned_until']=date("d/m/Y",$r2['owned_to']); } else { $dt['owned_until']=""; } //owner $sql3="SELECT email,name,username,first_name,last_name,profile_image from `users` where id=".$r2['user_id']; //echo $sql8."
"; $res3=mysqli_query($db,$sql3); $r3 =mysqli_fetch_assoc($res3); $dt['owner']=$r3; //image $sql4="SELECT `path` from `images` where item_id=".$r2['id']." and modul='garage'"; //echo $sql8."
"; $res4=mysqli_query($db,$sql4); while($r4 =mysqli_fetch_assoc($res4)) { $dt['images'][]=$r4['path']; } } else { $dt['success']=false; $dt['message']="Garage not found"; } //$dt['col']=$js; return $dt; } function get_garage_posts($js){ global $ar,$db; $dt=array(); //{"garage_id":"35","page":1,"limit":10,"tagged":false} $sql="SELECT id,caption,event_id,garage_id,location,has_tags,post_date,update_at, comments_count,likes_count,user_id from `posts` where garage_id=".$js->garage_id; //echo $sql8."
"; //$dt['sql'][0]=$sql; $res=mysqli_query($db,$sql); $total_items=mysqli_num_rows($res); $total_pages=ceil($total_items/$js->limit); $start=($js->page-1)*$js->limit; if(mysqli_num_rows($res)>0) { $sql2 = $sql." order by post_date desc limit ".$start.",".$js->limit; $res2=mysqli_query($db,$sql2); $a=0; while($r2 = mysqli_fetch_assoc($res2)) { $dt['data'][$a]=$r2; $sql3="SELECT * from user_post_liked where user_id=".$user_id." and post_id=".$r2['id']; $res3=mysqli_query($db,$sql3); if(mysqli_num_rows($res3)>0) { $dt['data'][$a]['is_liked']=true; } else { $dt['data'][$a]['is_liked']=false; } $sql4="SELECT * from user_post_bookmarked where user_id=".$user_id." and post_id=".$r2['id']; $res4=mysqli_query($db,$sql4); if(mysqli_num_rows($res4)>0) { $dt['data'][$a]['is_bookmarked']=true; } else { $dt['data'][$a]['is_bookmarked']=false; } $sql5="SELECT * from user_post_liked_old where user_id=".$user_id." and post_id=".$r2['id']; $res5=mysqli_query($db,$sql5); if(mysqli_num_rows($res5)>0) { $dt['data'][$a]['is_liked_and_old']=mysqli_num_rows($res4); } else { $dt['data'][$a]['is_liked_and_old']=0; } $sql6="SELECT `username` from user_name where user_id=".$r2['user_id']; $res6=mysqli_query($db,$sql6); if(mysqli_num_rows($res6)>0) { $r6 = mysqli_fetch_assoc($res6); $dt['data'][$a]['username']=$r6['username']; } else { $dt['data'][$a]['username']=""; } $sql7="SELECT `path` from `images` where `modul`='users' and item_id=".$r2['user_id']." limit 1"; $res7=mysqli_query($db,$sql7); if(mysqli_num_rows($res7)>0) { $r7 = mysqli_fetch_assoc($res7); $dt['data'][$a]['user_profil_image']=$r7['path']; } else { $dt['data'][$a]['user_profil_image']=""; } $sql8="SELECT * from `post_media` where post_id=".$r2['id'].""; $res8=mysqli_query($db,$sql8); $dt['data'][$a]['media']=array(); while($r8 = mysqli_fetch_assoc($res8)) { $dt['data'][$a]['media'][]=$r8; } $a++; } } else { $dt['data']=[]; } $dt['total_items']=$total_items; $dt['total_pages']=$total_pages; $dt['current_page']=$js->page; $dt['limit']=$js->limit; return $dt; } function get_user_garage($js){ global $ar,$db; $dt=array(); $sql2="SELECT id,allow_tagging,cover_photo,make,model,owned_from,owned_to,primary_car,registration,description,`status`,variant,create_at,update_at from `garage` where user_id=".$js->user_id; //$dt['sql']=$sql2; $res2=mysqli_query($db,$sql2); if(mysqli_num_rows($res2)>0) { $c=0; while($r2 = mysqli_fetch_assoc($res2)) { $dt[$c]=$r2; if($r2['owned_from']>0) { $dt[$c]['owned_since']=date("Y-m-d H:i:s",$r2['owned_from']); } else { $dt[$c]['owned_since']=""; } if($r2['owned_to']>0) { $dt[$c]['owned_until']=date("Y-m-d H:i:s",$r2['owned_to']); } else { $dt[$c]['owned_until']=""; } $dt[$c]['create_at']=date("Y-m-d H:i:s",$r2['create_at']); if($r2['update_at']>0) { $dt[$c]['update_at']=date("Y-m-d H:i:s",$r2['update_at']); } $dt[$c]['status']=$ar['st_garage'][$r2['status']]; $c++; } } else { $dt['error']=true; $dt['message']="Garage not found"; } return $dt; } function popular_users_cars($js){ global $ar,$db; $dt=array(); //{"user_id":67032,"page":1,"per_page":10} $page=$js->page; $limit=$js->per_page; $sql="SELECT * from `cars` "; //echo $sql8."
"; $res=mysqli_query($db,$sql); $total_items=mysqli_num_rows($res); $total_pages=ceil($total_items/$limit); $start=($page-1)*$limit; $sql2 = $sql." order by id desc limit ".$start.",".$limit; $res2=mysqli_query($db,$sql2); $a=0; while($r2 = mysqli_fetch_assoc($res2)) { $sql3="SELECT * from car_owners where id=".$r2['owner_id']; $res3=mysqli_query($db,$sql3); $r3 = mysqli_fetch_assoc($res3); $sql4="SELECT `path` from images where modul='car_owners' and item_id=".$r2['owner_id']; $res4=mysqli_query($db,$sql4); $r4 = mysqli_fetch_assoc($res4); $dt['data'][$a]=$r2; $dt['data'][$a]['owner']=$r3; $dt['data'][$a]['owner']['thumbnail']=$r4['path']; $a++; } $dt['total_pages']=$total_pages; $dt['page']=$page; $dt['limit']=$limit; return $dt; } function update_garage($js){ global $ar,$db; $dt=array(); if($js->ownedFrom!='') { $ef=explode("/",$js->ownedFrom); $own_from=strtotime($ef[2]."-".$ef[1]."-".$ef[0]); } else { $own_from=0; } if($js->ownedTo!='') { $et=explode("/",$js->ownedTo); $own_to=strtotime($et[2]."-".$et[1]."-".$et[0]); } else { $own_to=0; } if($js->primary_car!='' && $js->primary_car=='past') { $pc=2; } $udt=array( 'allow_tagging'=>$js->allow_tagging, 'colour'=>$js->colour, 'description'=>$js->description, 'make'=>$js->make, 'model'=>$js->model, 'owned_from'=>$own_from, 'owned_to'=>$own_to, 'primary_car'=>$pc, 'registration'=>$js->registration, 'user_id'=>$js->user_id, 'variant'=>$js->variant, 'vehicle_period'=>$js->vehicle_period, 'update_at'=>time(), ); Update($db,"garage",$udt,"id=".$js->garage_id,0); if($js->cover_photo!='') { $data=$js->cover_photo; $image_info = getimagesize($data); $extension = (isset($image_info["mime"]) ? explode('/', $image_info["mime"] )[1]: ""); $dt['type']=$extension; $tmp_file=$ar['img_path']."users/tmp/".$js->user_id.".".$extension; $sub_folder=$ar['img_path']."/users/".$js->user_id; if(!is_dir($sub_folder)){ mkdir($sub_folder, 0755); } $sub_folder_p=$ar['img_path']."/users/".$js->user_id."/g"; if(!is_dir($sub_folder_p)){ mkdir($sub_folder_p, 0755); } $new_file=genRandom(10).".".$extension; $dt['newfile']=$new_file; $data = str_replace('data:image/'.$extension.';base64,', '', $data); $data = str_replace(' ','+',$data); $bin = base64_decode($data); if ($bin === false) { $dt['info']="convert invalid"; } //tmp file file_put_contents($tmp_file, $bin); ini_set('display_errors', '0'); resize_crop_image(1200,760,$tmp_file,$sub_folder_p."/".$new_file); unlink($tmp_file); $sql="SELECT `seq` from `images` where `modul`='garage' and `item_id`=".$js->garage_id." order by `seq` desc limit 1"; $res=mysqli_query($db,$sql); if(mysqli_num_rows($res)==1) { $r = mysqli_fetch_assoc($res); $seq2=$r['seq']+1; } else { $seq2=1; } $sql2="SELECT `id` from `images` order by `id` desc limit 1"; $res2=mysqli_query($db,$sql2); if(mysqli_num_rows($res2)==1) { $r2 = mysqli_fetch_assoc($res2); $id2=$r2['id']+1; } else { $id2=1; } $idt=array( 'id'=>$id2, 'modul'=>'garage', 'item_id'=>$id2, 'seq'=>$seq2, 'create_at'=>time(), 'path'=>$ar['imgurl']."users/".$js->user_id."/g/".$new_file, ); Insert($db,"images",$idt,0); $udt=array( 'cover_photo'=>$ar['imgurl']."users/".$js->user_id."/g/".$new_file, ); Update($db,"garage",$udt,"id=".$js->garage_id,0); } //$dt['col']=$js; $dt['success']=true; $dt['message']="Garage updated successfully"; return $dt; } ?>
user_id)) { $idt=array( 'id'=>$id2, 'box_dimension'=>$js->box_dimension, 'colour'=>$js->colour, 'noken'=>$js->noken, 'make'=>$js->make, 'model'=>$js->model, 'name'=>$js->name, 'user_id'=>$js->user_id, 'create_at'=>time(), ); Insert($db,"vehicles",$idt,0); if($js->cover_photo) { $data=$js->cover_photo; $image_info = getimagesize($data); $extension = (isset($image_info["mime"]) ? explode('/', $image_info["mime"] )[1]: ""); $dt['type']=$extension; $tmp_file=$ar['img_path']."users/tmp/".$js->user_id.".".$extension; $sub_folder=$ar['img_path']."/users/".$js->user_id; if(!is_dir($sub_folder)){ mkdir($sub_folder, 0755); } $sub_folder_p=$ar['img_path']."/users/".$js->user_id."/veh"; if(!is_dir($sub_folder_p)){ mkdir($sub_folder_p, 0755); } $new_file=genRandom(10).".".$extension; $dt['newfile']=$new_file; $data = str_replace('data:image/'.$extension.';base64,', '', $data); $data = str_replace(' ','+',$data); $bin = base64_decode($data); if ($bin === false) { //$dt['info']="convert invalid"; } //tmp file file_put_contents($tmp_file, $bin); ini_set('display_errors', '0'); resize_crop_image(1200,760,$tmp_file,$sub_folder_p."/".$new_file); unlink($tmp_file); $sql="SELECT `seq` from `images` where `modul`='vehicle' and `item_id`=".$id2." order by `seq` desc limit 1"; $res=mysqli_query($db,$sql); if(mysqli_num_rows($res)==1) { $r = mysqli_fetch_assoc($res); $seq2=$r['seq']+1; } else { $seq2=1; } $sql3="SELECT `id` from `images` order by `id` desc limit 1"; $res3=mysqli_query($db,$sql3); if(mysqli_num_rows($res3)==1) { $r3 = mysqli_fetch_assoc($res3); $id3=$r3['id']+1; } else { $id3=1; } $idt=array( 'id'=>$id3, 'modul'=>'vehicle', 'item_id'=>$id2, 'seq'=>$seq2, 'create_at'=>time(), 'path'=>$ar['imgurl']."users/".$js->user_id."/veh/".$new_file, ); Insert($db,"images",$idt,0); $udt=array( 'cover_photo'=>$ar['imgurl']."users/".$js->user_id."/veh/".$new_file, ); Update($db,"vehicles",$udt,"id=".$id2,0); } $dt['success']=true; $dt['message']="Vehicle Added successfully"; $dt['id']=$id2; } else { $dt['success']=true; //$dt['message']="Vehicle Added successfully"; } //$dt['col']=$js; return $dt; } function delete_vehicle($js){ global $ar,$db; $dt=array(); $sql="SELECT * from `vehicles` where id=".$js->vehicle_id." and user_id=".$js->user_id; //$dt['sql']=$sql; $res=mysqli_query($db,$sql); if(mysqli_num_rows($res)>0) { $r=mysqli_fetch_assoc($res); $udt=array( 'del'=>1, ); Update($db,"vehicles",$udt,"id=".$js->vehicle_id,0); //Delete($db,"waste","id=".$js->waste_id,0); $dt['success']=true; $dt['message']="Vehicle deleted successfully"; } else { $dt['error']=true; $dt['message']="Error delete vehicle"; } return $dt; } function edit_vehicle($js){ global $ar,$db; $dt=array(); $user_id=$js->user_id; $vehicle_id=$js->vehicle_id; if(isset($js->user_id)) { $udt=array( 'user_id'=>$js->user_id, 'box_dimension'=>$js->box_dimension, 'colour'=>$js->colour, 'noken'=>$js->noken, 'make'=>$js->make, 'model'=>$js->model, 'name'=>$js->name, 'update_at'=>time(), ); Update($db,"vehicles",$udt,"id=".$js->vehicle_id,0); if($js->cover_photo) { $data=$js->cover_photo; $image_info = getimagesize($data); $extension = (isset($image_info["mime"]) ? explode('/', $image_info["mime"] )[1]: ""); $dt['type']=$extension; $tmp_file=$ar['img_path']."users/tmp/".$js->user_id.".".$extension; $sub_folder=$ar['img_path']."/users/".$js->user_id; if(!is_dir($sub_folder)){ mkdir($sub_folder, 0755); } $sub_folder_p=$ar['img_path']."/users/".$js->user_id."/veh"; if(!is_dir($sub_folder_p)){ mkdir($sub_folder_p, 0755); } $new_file=genRandom(10).".".$extension; $dt['newfile']=$new_file; $data = str_replace('data:image/'.$extension.';base64,', '', $data); $data = str_replace(' ','+',$data); $bin = base64_decode($data); if ($bin === false) { //$dt['info']="convert invalid"; } //tmp file file_put_contents($tmp_file, $bin); ini_set('display_errors', '0'); resize_crop_image(1200,760,$tmp_file,$sub_folder_p."/".$new_file); unlink($tmp_file); $sql="SELECT `seq` from `images` where `modul`='vehicle' and `item_id`=".$js->vehicle_id." order by `seq` desc limit 1"; $res=mysqli_query($db,$sql); if(mysqli_num_rows($res)==1) { $r = mysqli_fetch_assoc($res); $seq2=$r['seq']+1; } else { $seq2=1; } $sql3="SELECT `id` from `images` order by `id` desc limit 1"; $res3=mysqli_query($db,$sql3); if(mysqli_num_rows($res3)==1) { $r3 = mysqli_fetch_assoc($res3); $id3=$r3['id']+1; } else { $id3=1; } $idt=array( 'id'=>$id3, 'modul'=>'vehicle', 'item_id'=>$js->vehicle_id, 'seq'=>$seq2, 'create_at'=>time(), 'path'=>$ar['imgurl']."users/".$js->user_id."/veh/".$new_file, ); Insert($db,"images",$idt,0); $udt=array( 'cover_photo'=>$ar['imgurl']."users/".$js->user_id."/veh/".$new_file, ); Update($db,"vehicles",$udt,"id=".$js->vehicle_id,0); } $dt['success']=true; $dt['message']="Update vehicle successfully"; //$dt['id']=$id2; } else { $dt['error']=true; $dt['message']="Error update vehicle"; } //$dt['col']=$js; return $dt; } function get_user_vehicle($js){ global $ar,$db; $dt=array(); $sql="SELECT * from `vehicles` where del=0 and user_id=".$js->user_id; //echo $sql8."
"; $res=mysqli_query($db,$sql); $total_items=mysqli_num_rows($res); $total_pages=ceil($total_items/$js->limit); $start=($js->page-1)*$js->limit; $sql2 = $sql." order by create_at desc limit ".$start.",".$js->limit; $res2=mysqli_query($db,$sql2); if(mysqli_num_rows($res)>0) { $c=0; while($r1 = mysqli_fetch_assoc($res2)) { $dt['data'][$c]=$r1; $sql3="SELECT `path` as url from images where `item_id`='".$r1['id']."' and modul='vehicle'"; //echo $sql8."
"; $res3=mysqli_query($db,$sql3); $d=0; while($r3 = mysqli_fetch_assoc($res3)) { $dt['data'][$c]['media'][$d]=$r3; $d++; } $c++; } $dt['success']=true; $dt['page']=$js->page; $dt['limit']=$js->limit; $dt['total_pages']=$total_pages; $dt['total_items']=$total_items; } else { //$dt['error']=true; //$dt['error']="No posts found for the user"; $dt['data']=[]; $dt['message']="No data found for the user"; } return $dt; } function get_vehicle($js){ global $ar,$db; $dt=array(); $sql="SELECT * from `vehicles` where id=".$js->vehicle_id; $res=mysqli_query($db,$sql); if(mysqli_num_rows($res)>0) { $r1 = mysqli_fetch_assoc($res); $dt['data']=$r1; $sql3="SELECT `path` as url from images where `item_id`='".$r1['id']."' and modul='vehicle'"; $res3=mysqli_query($db,$sql3); $d=0; while($r3 = mysqli_fetch_assoc($res3)) { $dt['data']['media'][$d]=$r3; $d++; } $dt['success']=true; } else { $dt['data']=[]; $dt['message']="No data found"; } return $dt; } function get_vehicles($js){ global $ar,$db; $dt=array(); $sql="SELECT * from `vehicles` where del=0"; //echo $sql8."
"; $res=mysqli_query($db,$sql); $total_items=mysqli_num_rows($res); $total_pages=ceil($total_items/$js->limit); $start=($js->page-1)*$js->limit; $sql2 = $sql." order by create_at desc limit ".$start.",".$js->limit; $res2=mysqli_query($db,$sql2); if(mysqli_num_rows($res)>0) { $c=0; while($r1 = mysqli_fetch_assoc($res2)) { $dt['data'][$c]=$r1; $sql3="SELECT `path` as url from images where `item_id`='".$r1['id']."' and modul='vehicle'"; //echo $sql8."
"; $res3=mysqli_query($db,$sql3); $d=0; while($r3 = mysqli_fetch_assoc($res3)) { $dt['data'][$c]['media'][$d]=$r3; $d++; } $c++; } $dt['success']=true; $dt['page']=$js->page; $dt['limit']=$js->limit; $dt['total_pages']=$total_pages; $dt['total_items']=$total_items; } else { //$dt['error']=true; //$dt['error']="No posts found for the user"; $dt['data']=[]; $dt['message']="No data found for the user"; } return $dt; } function like_vehicle($js){ global $ar,$db; $dt=array(); $sql2="SELECT `id` from `user_vehicle_liked` order by `id` desc limit 1"; $res2=mysqli_query($db,$sql2); if(mysqli_num_rows($res2)==1) { $r2 = mysqli_fetch_assoc($res2); $id2=$r2['id']+1; } else { $id2=1; } $sql1="SELECT * from `user_vehicle_liked` where vehicle_id=".$js->vehicle_id." and user_id=".$js->user_id; $res1=mysqli_query($db,$sql1); if(mysqli_num_rows($res1)==1) { Delete($db,"user_vehicle_liked","vehicle_id=".$js->vehicle_id." and user_id=".$js->user_id,0); $dt['success']=true; $dt['message']="Vehicle un-liked"; } else { $idt=array( 'id'=>$id2, 'vehicle_id'=>$js->vehicle_id, 'user_id'=>$js->user_id, ); Insert($db,"user_vehicle_liked",$idt,0); $dt['success']=true; $dt['message']="Vehicle liked"; } return $dt; } function save_vehicle($js){ global $ar,$db; $dt=array(); $sql2="SELECT `id` from `user_vehicle_saved` order by `id` desc limit 1"; $res2=mysqli_query($db,$sql2); if(mysqli_num_rows($res2)==1) { $r2 = mysqli_fetch_assoc($res2); $id2=$r2['id']+1; } else { $id2=1; } $sql1="SELECT * from `user_vehicle_saved` where vehicle_id=".$js->vehicle_id." and user_id=".$js->user_id; $res1=mysqli_query($db,$sql1); if(mysqli_num_rows($res1)==1) { Delete($db,"user_vehicle_saved","vehicle_id=".$js->vehicle_id." and user_id=".$js->user_id,0); $dt['success']=true; $dt['message']="Vehicle un-saved"; } else { $idt=array( 'id'=>$id2, 'vehicle_id'=>$js->vehicle_id, 'user_id'=>$js->user_id, ); Insert($db,"user_vehicle_saved",$idt,0); $dt['success']=true; $dt['message']="Vehicle saved"; } return $dt; } function update_vehicle_cover_photo($js){ global $ar,$db; $dt=array(); $user_id=$js->user_id; $vehicle_id=$js->vehicle_id; $data=$js->cover_photo; if(isset($js->cover_photo) && $js->cover_photo!=''){ $image_info = getimagesize($data); $extension = (isset($image_info["mime"]) ? explode('/', $image_info["mime"] )[1]: ""); //$dt['type']=$extension; $tmp_file=$ar['img_path']."users/tmp/".$user_id.".".$extension; $sub_folder=$ar['img_path']."/users/".$user_id; if(!is_dir($sub_folder)){ mkdir($sub_folder, 0755); } $sub_folder_p=$ar['img_path']."/users/".$user_id."/veh"; if(!is_dir($sub_folder_p)){ mkdir($sub_folder_p, 0755); } $new_file=genRandom(10).".".$extension; //$dt['newfile']=$new_file; $data = str_replace('data:image/'.$extension.';base64,', '', $data); $data = str_replace(' ','+',$data); $bin = base64_decode($data); if ($bin === false) { $dt['info']="convert invalid"; } //tmp file file_put_contents($tmp_file, $bin); ini_set('display_errors', '0'); resize_crop_image(1200,760,$tmp_file,$sub_folder_p."/".$new_file); unlink($tmp_file); $sql="SELECT `seq` from `images` where `modul`='vehicle' and `item_id`=".$js->vehicle_id." order by `seq` desc limit 1"; $res=mysqli_query($db,$sql); if(mysqli_num_rows($res)==1) { $r = mysqli_fetch_assoc($res); $seq2=$r['seq']+1; } else { $seq2=1; } $sql2="SELECT `id` from `images` order by `id` desc limit 1"; $res2=mysqli_query($db,$sql2); if(mysqli_num_rows($res2)==1) { $r2 = mysqli_fetch_assoc($res2); $id3=$r2['id']+1; } else { $id3=1; } $idt=array( 'id'=>$id3, 'modul'=>'vehicle', 'item_id'=>$js->vehicle_id, 'seq'=>$seq2, 'create_at'=>time(), 'path'=>$ar['imgurl']."users/".$user_id."/veh/".$new_file, ); Insert($db,"images",$idt,0); $udt=array( 'cover_photo'=>$ar['imgurl']."users/".$user_id."/veh/".$new_file, ); Update($db,"vehicles",$udt,"id=".$js->vehicle_id,0); //$dt['idt']=$idt; //$dt['udt']=$udt; $dt['success']=true; $dt['message']="Cover photo update"; } else { $dt['error']=true; $dt['message']="Error update cover photo"; } //$dt['image_url']=$ar['imgurl']."users/".$user_id."/w/".$new_file; return $dt; } ?>
Save
export const addVehicleToGarage = async (data) => { const controller = new AbortController() const signal = controller.signal try { const user = await getSessionUser() if (!user) return setTimeout(() => { controller.abort() }, TIMEOUT_MS_HIGH) const response = await fetch(`${API_URL}/wp-json/app/v1/add-vehicle-to-garage`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ ...data, user_id: user.id, }), signal }) const res = await response.json() return res } catch (error) { if (error.name === 'AbortError') { throw { message: "Failed to add your vehicle, your connection timed out", name: "TimeOutError" }; } else { throw error; // Rethrow any other errors } } } export const deleteVehicleFromGarage = async (garageId) => { const controller = new AbortController() const signal = controller.signal try { const user = await getSessionUser() if (!user) return setTimeout(() => { controller.abort() }, TIMEOUT_MS_HIGH) const response = await fetch(`${API_URL}/wp-json/app/v1/delete-garage`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, garage_id: garageId, }), signal }) const res = await response.json() return res } catch (error) { if (error.name === 'AbortError') { throw { message: "Failed to delete your vehicle, your connection timed out", name: "TimeOutError" }; } else { throw error; // Rethrow any other errors } } } export const getGargeById = async (garageId) => { try { const response = await fetch(`${API_URL}/wp-json/app/v1/get-garage`, { method: "POST", cache: "force-cache", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ garage_id: garageId }), }) const data = await response.json() if (response.status !== 200) { throw new Error('Failed to fetch users posts') } return data } catch (error) { console.error(error) return null } } export const getPostsForGarage = async (garageId, page = 1, tagged = false) => { try { const response = await fetch(`${API_URL}/wp-json/app/v1/get-garage-posts`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ garage_id: garageId, page, limit: 10, tagged }), }) const data = await response.json() if (response.status !== 200) { return null } return data } catch (error) { return null } } export const getUserGarage = async (profileId) => { try { const response = await fetch(`${API_URL}/wp-json/app/v1/get-user-garage`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: profileId }), }) const data = await response.json() if (response.status !== 200) { return [] } return data } catch (error) { return [] } } export const fetchTrendingUsers = async (page) => { try { const user = await getSessionUser(); if (!user) { throw new Error('Session user not found'); } const response = await fetch(`${API_URL}/wp-json/app/v1/popular-users-cars`, { method: "POST", cache: "force-cache", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, page, per_page: 10, }), }); const data = await response.json(); return data; } catch (error) { console.error(error); return null; } }; export const updateVehicleInGarage = async (data, garageId) => { const controller = new AbortController() const signal = controller.signal try { const user = await getSessionUser() if (!user) return setTimeout(() => { controller.abort() }, TIMEOUT_MS_HIGH) const response = await fetch(`${API_URL}/wp-json/app/v1/update-garage`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ ...data, user_id: user.id, garage_id: garageId, }), signal }) const res = await response.json() return res } catch (error) { if (error.name === 'AbortError') { throw { message: "Failed to update your vehicle, your connection timed out", name: "TimeOutError" }; } else { throw error; // Rethrow any other errors } } }
import { API_URL, TIMEOUT_MS_HIGHER } from "./consts.js" import { getSessionUser } from "./auth.js"; export const addVehicle = async (data) => { try { const user = await getSessionUser() if (!user) return setTimeout(() => { controller.abort() }, TIMEOUT_MS_HIGH) const response = await fetch(`${API_URL}/vehicle/add-vehicle`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ ...data, user_id: user.id, }) }) const res = await response.json() return res } catch (error) { if (error.name === 'AbortError') { throw { message: "Failed to add your vehicle, your connection timed out", name: "TimeOutError" }; } else { throw error; // Rethrow any other errors } } } export const deleteVehicle = async (vehicleId) => { try { const user = await getSessionUser() if (!user) return setTimeout(() => { controller.abort() }, TIMEOUT_MS_HIGH) const response = await fetch(`${API_URL}/vehicle/delete-vehicle`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, vehicle_id: vehicleId, }) }) const res = await response.json() return res } catch (error) { if (error.name === 'AbortError') { throw { message: "Failed to delete your vehicle, your connection timed out", name: "TimeOutError" }; } else { throw error; // Rethrow any other errors } } } export const editVehicle = async (data) => { try { const user = await getSessionUser() if (!user) return setTimeout(() => { controller.abort() }, TIMEOUT_MS_HIGH) const response = await fetch(`${API_URL}/vehicle/edit-vehicle`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ ...data, user_id: user.id, }) }) const res = await response.json() return res } catch (error) { if (error.name === 'AbortError') { throw { message: "Failed to add your vehicle, your connection timed out", name: "TimeOutError" }; } else { throw error; // Rethrow any other errors } } } export const getUserVehicle = async (userId) => { try { const response = await fetch(`${API_URL}/vehicle/get-user-vehicle`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: userId }), }) const data = await response.json() if (response.status !== 200) { return [] } return data } catch (error) { return [] } } export const getVehicleById = async (vehicleId) => { try { const response = await fetch(`${API_URL}/vehicle/get-vehicle`, { method: "POST", cache: "force-cache", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ vehcile_id: vehicleId }), }) const data = await response.json() if (response.status !== 200) { throw new Error('Failed to fetch users posts') } return data } catch (error) { console.error(error) return null } } export async function getVehicles(page) { const controller = new AbortController() const signal = controller.signal try { const user = await getSessionUser() if (!user) return // setTimeout(() => { // controller.abort() // }, 5) const response = await fetch(`${API_URL}/vehicle/get-vehicles?page=${page}&limit=10`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id }), signal // Abort signal }) const data = await response.json() return data } catch (error) { console.log(error); return {} } } export const LikeVehicle = async (vehicleId) => { const user = await getSessionUser() if (!user) return const response = await fetch(`${API_URL}/vehicle/like-vehicle`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, vehicle_id: vehicleId }), }) const data = await response.json() return data } export const SaveVehicle = async (vehicleId) => { const user = await getSessionUser() if (!user) return const response = await fetch(`${API_URL}/vehicle/save-vehicle`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, vehicle_id: vehicleId }), }) const data = await response.json() return data } export const updateVehicleCoverImage = async (vehicleId, cover_photo) => { try { const user = await getSessionUser(); if (!user) return; setTimeout(() => { controller.abort() }, TIMEOUT_MS_HIGHER) const response = await fetch(`${API_URL}/vehicle/update-vehicle-cover-photo`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user.id, vehicle_id:vehicleId, cover_photo }) }); const data = await response.json(); return data; } catch (error) { if (error.name === 'AbortError') { throw { message: "Failed to update cover photo, your connection timed out", name: "TimeOutError" }; } else { throw error; // Rethrow any other errors } } };
Save
vehicle
-- add-vehicle-to-garage
-- delete-garage
-- get-garage
-- get-garage-posts
-- get-user-garage
-- popular-users-cars
-- update-garage