//Service : Add Remove Favorite Package

$mainframe = JFactory::getApplication();
$option = JRequest::getVar('option','com_jewebservices','','string');
//$post = JRequest::get ('post');  
$uri = JURI::getInstance();
$url= $uri->root();
global $HTTP_RAW_POST_DATA;
 
$post = json_decode($HTTP_RAW_POST_DATA, true);

//$post['package_id'] = 474;
//$post['user_id'] = 747;

//$post['add_remove'] = 1;

if($post['user_id']){

if($post['add_remove']==1){

 $query = "INSERT INTO #__jetour_favoritepackage (`user_id`,`package_id`) VALUES ('".$post['user_id']."','".$post['package_id']."')"; 
 $db->setQuery($query);
 $db->Query();
 
 $arr = array('success' => 1, 'message' => "Package added to favorite list");
 echo json_encode($arr);exit;
}else if($post['add_remove']==2){
 $query = "DELETE FROM #__jetour_favoritepackage WHERE `user_id`=".$post['user_id']." AND `package_id`=".$post['package_id']; 
 $db->setQuery($query);
 $db->Query();
 
 $arr = array('success' => 1, 'message' => "Package Deleted from favorite list");
 echo json_encode($arr);exit;
}else{
 $arr = array('success' => 0, 'message' => "Something went Wrong in adding to favorite" ); 
 echo json_encode($arr);exit;
}
}else{
 $arr = array('success' => 0, 'message' => "Please Login First" ); 
 echo json_encode($arr);exit;
}