/
plugin
/
backup
/
4season
/
Upload File
HOME
<?php define("auth_token" ,"c94dfb63ec723b9a57d533b35e43fd93"); /**************************************************************** * @@Zoho CRM integration code * @@ function to generate access_token ********************************************************/ function generate_token_function(){ $message=array(); try { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://accounts.zoho.com/oauth/v2/token?refresh_token=1000.e2189025ee85503e44992054803a87e5.158456dd432bd6bb253b436a3d586cde&client_id=1000.ZAO9U8FZ3JPSY31U4NKQ6QUAB0B52Z&client_secret=f2b875b07a73bd3eaa0fd7280bb569a37e2f36cd11&grant_type=refresh_token", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_HTTPHEADER => array("Cache-Control: no-cache", "Postman-Token: 3264ad75-3889-4e52-9915-c6d1fb9504b2" ) )); $response = curl_exec($curl); if(curl_exec($curl) === false) { $message['status']=false; $message['data']=curl_error($ch); $message['created_at']=date('Y-m-d H:i:s'); } else { $response=json_decode($response,true); if(!empty($response['access_token'])){ $message['status']=true; $message['data']=$response; $message['created_at']=date('Y-m-d H:i:s'); } else{ $message['status']=false; $message['data']='Somthing went wrong, please try again!'; $message['created_at']=date('Y-m-d H:i:s'); } } curl_close($curl); } catch (Exception $e) { $message['status']=false; $message['data']=$e->getMessage(); $message['created_at']=date('Y-m-d H:i:s'); } return $message; } /********************************************************************** @@ Store token into file and regerate after token expiry ***********************************************************************/ function ap_get_token(){ $file_url=__DIR__."/token.txt"; if (file_exists($file_url)) { $data=file_get_contents($file_url); $data_arr=json_decode($data); $mindiff = round((strtotime(date('Y-m-d H:i:s')) - strtotime($data_arr->created_at))/60); if($mindiff > 45 || !$data_arr->status){ $response_msg=generate_token_function(); file_put_contents($file_url,json_encode($response_msg)); } } else{ $response_msg=generate_token_function(); file_put_contents($file_url,json_encode($response_msg)); } $data=file_get_contents($file_url); $data_arr=json_decode($data); return $data_arr; } function get_Record_by_id($module,$id) { $access_token_obj=ap_get_token(); $access_token=$access_token_obj->data->access_token; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://www.zohoapis.com/crm/v2/$module/$id", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( "Authorization: Zoho-oauthtoken $access_token" ), )); $response = curl_exec($curl); curl_close($curl); return json_decode($response,true); } function search_records_non_COQL($module, $criteria, $page=1, $per_page=200) { $access_token_obj=ap_get_token(); $access_token=$access_token_obj->data->access_token; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://www.zohoapis.com/crm/v2/$module/search?criteria=$criteria", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( "Authorization: Zoho-oauthtoken $access_token" ), )); $response = curl_exec($curl); curl_close($curl); return json_decode($response, true); } function search_Records($module,$search,$from="",$to="") { $access_token_obj=ap_get_token(); $access_token=$access_token_obj->data->access_token; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://www.zohoapis.com/crm/v2/coql', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>"{ 'select_query' : 'select Name, Arrival_Date1, Day, Depart_TIME, Arriv_TIME, ADULT, INDY_Adult, CHILD, INDY_Child, Week, Booked_To, Booking_Type, Tour, Tour_Company, Averages, PRE_LIM_PAX, OPERATOR_ALLOCATION, PAIRS, PAIR_ORDER, VOUCHER_No, COMP, Tier, PORT_SCHED, Boat, Ship, Invoice1 from $module where Arrival_Date1 = $search' }", CURLOPT_HTTPHEADER => array( "Authorization: Zoho-oauthtoken $access_token", 'Content-Type: application/json' ), )); $response = curl_exec($curl); curl_close($curl); return json_decode($response,true); } function get_Related_Records($module,$id,$relatedList,$columns) { $access_token_obj=ap_get_token(); $access_token=$access_token_obj->data->access_token; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://www.zohoapis.com/crm/v3/$module/$id/$relatedList?fields=$columns", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( "Authorization: Zoho-oauthtoken $access_token" ), )); $response = curl_exec($curl); curl_close($curl); return json_decode($response, true); } function insert_Records($module,$data) { $access_token_obj=ap_get_token(); $access_token=$access_token_obj->data->access_token; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://www.zohoapis.com/crm/v3/$module", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => "$data", CURLOPT_HTTPHEADER => array( "Authorization: Zoho-oauthtoken $access_token", "Content-Type: application/json" ), )); $response = curl_exec($curl); curl_close($curl); return json_decode($response, true); } function update_Records($module,$data) { $access_token_obj=ap_get_token(); $access_token=$access_token_obj->data->access_token; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://www.zohoapis.com/crm/v3/$module", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => "$data", CURLOPT_HTTPHEADER => array( "Authorization: Zoho-oauthtoken $access_token", 'Content-Type: application/json' ), )); $response = curl_exec($curl); curl_close($curl); return json_decode($response, true); } function upload_attachment($module,$id,$FileName) { $access_token_obj=ap_get_token(); $access_token=$access_token_obj->data->access_token; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://www.zohoapis.com/crm/v3/$module/$id/Attachments", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array('file' => new CURLFILE($FileName)), CURLOPT_HTTPHEADER => array( "Authorization: Zoho-oauthtoken $access_token", ), )); $response = curl_exec($curl); curl_close($curl); return json_decode($response, true); } function create_log($file, $log_content) { $msg = date("d/m/Y H:i:s") . " " . json_encode($log_content) . "\r\n\r\n"; file_put_contents($file, $msg, FILE_APPEND | LOCK_EX); } ?>