external_path.'/pd_reports/'.$pdid : $CI->external_path.'/sales_pd/'.$pdid; // echo $path_to_check;die(); $geo_location = null; $pdmas = array(); $logger = $pd_type == 1 ? MYLOG::logFunction(null,$pdid) : MYLOG::logSalesPD($pdid); $model_to_load = ($pd_type == 1 || $pd_type == 3) ? 'PD_Model' : 'Sales_PD_Model'; //print_r($logger);die(); if(!file_exists($path_to_check)) { mkdir($path_to_check,0777); } $google_map_static_api_key = GOOGLE_STATIC_MAP_API_KEY; if($pd_type == 1 || $pd_type == 3) { $pdmas = $CI->PD_Model->getPDMasterDetails($pdid); $geo_location = $pdmas[0]['start_location']; // $satellite_script_from_db = $CI->$model_to_load->selectCustomRecords(array('*'),array('script_name' => SATELLITE_IMAGE_LOCATION),SCRIPTS); // $satellite_script = $satellite_script_from_db[0]['script_content']; //Replacing Place holders // $satellite_script = str_replace('{{APPPATH}}',$path_to_check,$satellite_script); // $satellite_script = str_replace('{{ADDRESS}}',$geo_location,$satellite_script); // $satellite_script = str_replace('{{GEOLOCATION}}',$geo_location,$satellite_script); // $satellite_script = str_replace('{{API_KEY}}',$google_map_static_api_key,$satellite_script); // //echo $satellite_script;die(); // file_put_contents(APPPATH.'/views/js/phantomsatellite.js',$satellite_script); // //call& execute phantom script // $str = 'phantomjs '.APPPATH.'/views/js/phantomsatellite.js'; // exec($str,$ou); // exec('phantom.exit();'); } else if($pd_type == 2) { $pdmas = $CI->Sales_PD_Model->selectCustomRecords(array('geo_location'),array('sales_pd_id' => $pdid),SALES_PD_DATA); $geo_location = $pdmas[0]['geo_location']; } $geo_location = preg_replace('/\s+/', '', $geo_location); $url = "https://maps.googleapis.com/maps/api/staticmap?center=".$geo_location."&zoom=14&markers=color:red|".$geo_location."&size=800x300&maptype=roadmap&key=".$google_map_static_api_key; //echo $url; $ou = file_put_contents($path_to_check.'/satellite.png', file_get_contents($url)); $satellite_script = $url; //echo $url; // //convert as base 64 image. $satellite_image_png_path = $path_to_check.'/satellite.png'; //echo 'all done'; //die(); if($pd_type == 1 ) { $bucketname = LENDER_BUCKET_NAME_PREFIX.$pdmas[0]['fk_lender_id']; $key = 'pd'.$pdid.'/'.'satellite.png'; $bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$CI->external_path.'/pd_reports/'.$pdid.'/satellite.png'); $s3result= $CI->aws_s3->uploadFileToS3Bucket($bucket_data); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { $CI->PD_Model->updateRecords(array('isactive' => 0),PDDOCUMENTS,array('pd_document_title' => 'satellite','fk_pd_id' => $pd_id)); $record_data = array('fk_pd_id' => $pdid,'pd_document_title'=>'satellite','pd_document_name'=>'satellite.png','fk_form_id'=>null,'rental_count_id' => null,'location' => null); $id = $CI->PD_Model->saveRecords($record_data,PDDOCUMENTS); $api_return = $id; $custom_log_info = '###CUSTOM DEBUG SATELLITE IMAGE STORED IN S3 DONE - '. $id; log_message('ERROR',$custom_log_info); } } else if($pd_type == 2) //save satellite img as base64 in sale pd doc table { $satellite_base64 = base64_encode(file_get_contents($satellite_image_png_path)); $CI->Sales_PD_Model->updateRecords(array('isactive' => 0),SALEPD_DOCS,array('img_name' => 'satellite','fk_sales_pd_id' => $pd_id)); $CI->Sales_PD_Model->saveRecords(array('img' => $satellite_base64,'img_name' => 'satellite','fk_sales_pd_id' => $pdid),SALEPD_DOCS); } else if($pd_type == 3) { //echo 'updae'; $satellite_base64 = base64_encode(file_get_contents($satellite_image_png_path)); $CI->PD_Model->updateRecords(array('isactive' => 0),SMC_CREDIT_PD_DOCS,array('img_name' => 'satellite','fk_smc_credit_pd_id' => $pd_id)); $CI->PD_Model->saveRecords(array('img' => $satellite_base64,'img_name' => 'satellite','fk_smc_credit_pd_id' => $pd_id),SMC_CREDIT_PD_DOCS); } //generate log $logger->info("Generate Satellite Called in (".ENVIRONMENT.")",array('script' => $satellite_script,'script_output' => $ou)); //return $base64_pdscore_chart_url; if($api) { return $api_return; } } } ?>