Пример #1
0
 public function process_user($username, $password, $facility_code)
 {
     $curl = new Curl();
     $response = array();
     //Get Supplier
     $supplier = $this->get_supplier($facility_code);
     if ($supplier == "kemsa") {
         //Use nascop url
         $url = $this->default_url;
         $post = array("email" => $username, "password" => $password);
         $url = $this->default_url . 'sync/user';
         $curl->post($url, $post);
     } else {
         //Use escm url
         $curl->setBasicAuthentication($username, $password);
         $curl->setOpt(CURLOPT_RETURNTRANSFER, TRUE);
         $url = $this->default_url . 'user/' . $username;
         $curl->get($url);
     }
     //Handle Response
     if ($curl->error) {
         $response['error'] = TRUE;
         $response['content'] = array($curl->error_code);
     } else {
         $response['error'] = FALSE;
         $response['content'] = json_decode($curl->response, TRUE);
     }
     return json_encode($response);
 }
Пример #2
0
 public function testBasicHttpAuth()
 {
     $data = array();
     $this->curl->get(self::TEST_URL . '/http_basic_auth.php', $data);
     $this->assertEquals('canceled', $this->curl->response);
     $username = '******';
     $password = '******';
     $this->curl->setBasicAuthentication($username, $password);
     $this->curl->get(self::TEST_URL . '/http_basic_auth.php', $data);
     $this->assertEquals('{"username":"******","password":"******"}', $this->curl->response);
 }
Пример #3
0
 public function get_updates($type = 0)
 {
     if ($type != 0) {
         if ($this->session->userdata("update_timer") != "") {
             $to_time = strtotime(date('Y-m-d H:i:s'));
             $from_time = strtotime($this->session->userdata("update_timer"));
             if (round(abs($to_time - $from_time) / 60, 2) <= 10) {
                 $this->session->set_userdata("update_test", false);
                 echo 2;
                 die;
             }
         }
         $this->session->set_userdata("update_timer", date('Y-m-d H:i:s'));
     }
     ini_set("max_execution_time", "1000000");
     $current_month_start = date('Y-m-01');
     $one_current_month_start = date('Y-m-d', strtotime($current_month_start . "-1 month"));
     $two_current_month_start = date('Y-m-d', strtotime($current_month_start . "-2 months"));
     $three_current_month_start = date('Y-m-d', strtotime($current_month_start . "-3 months"));
     $facility_code = $this->session->userdata('facility');
     $api_userID = $this->session->userdata('api_id');
     $facility_list = User_Facilities::getHydratedFacilityList($api_userID);
     $lists = json_decode($facility_list['facility'], TRUE);
     $facility = Facilities::getSupplier($facility_code);
     $supplier = $facility->supplier->name;
     $links = array();
     $curl = new Curl();
     if (strtoupper($supplier) == "KENYA PHARMA") {
         $url = $this->esm_url;
         foreach ($lists as $facility_id) {
             if ($type == 0) {
                 $links[] = "facility/" . $facility_id . "/cdrr";
                 $links[] = "facility/" . $facility_id . "/maps";
             } else {
                 $links[] = "facility/" . $facility_id . "/cdrr/" . $current_month_start;
                 $links[] = "facility/" . $facility_id . "/maps/" . $current_month_start;
                 $links[] = "facility/" . $facility_id . "/cdrr/" . $one_current_month_start;
                 $links[] = "facility/" . $facility_id . "/maps/" . $one_current_month_start;
                 $links[] = "facility/" . $facility_id . "/cdrr/" . $two_current_month_start;
                 $links[] = "facility/" . $facility_id . "/maps/" . $two_current_month_start;
             }
         }
         $username = $this->session->userdata('api_user');
         $password = $this->session->userdata('api_pass');
         $curl->setBasicAuthentication($username, $password);
         $curl->setOpt(CURLOPT_RETURNTRANSFER, TRUE);
     } else {
         $url = $this->nascop_url;
         if (!empty($lists)) {
             $lists = explode(",", $lists[0]);
             foreach ($lists as $facility_id) {
                 if ($type == 0) {
                     $links[] = "sync/facility/" . $facility_id . "/cdrr";
                     $links[] = "sync/facility/" . $facility_id . "/maps";
                 } else {
                     $links[] = "sync/facility/" . $facility_id . "/cdrr/" . $current_month_start;
                     $links[] = "sync/facility/" . $facility_id . "/maps/" . $current_month_start;
                     $links[] = "sync/facility/" . $facility_id . "/cdrr/" . $one_current_month_start;
                     $links[] = "sync/facility/" . $facility_id . "/maps/" . $one_current_month_start;
                     $links[] = "sync/facility/" . $facility_id . "/cdrr/" . $two_current_month_start;
                     $links[] = "sync/facility/" . $facility_id . "/maps/" . $two_current_month_start;
                 }
             }
         }
     }
     //clear orders if its a full sync
     if ($type == 0) {
         $this->clear_orders();
     }
     foreach ($links as $link) {
         $target_url = $url . $link;
         $curl->get($target_url);
         if ($curl->error) {
             $curl->error_code;
             echo "Error: " . $curl->error_code . "<br/>";
         } else {
             $main_array = json_decode($curl->response, TRUE);
             $clean_data = array();
             foreach ($main_array as $main) {
                 if ($main['code'] == "D-CDRR" || $main['code'] == "F-CDRR_units" || $main['code'] == "F-CDRR_packs") {
                     $type = "cdrr";
                 } else {
                     $type = "maps";
                 }
                 if ($type == 0) {
                     if (is_array($main)) {
                         if (!empty($main)) {
                             $id = $this->extract_order($type, array($main), $main['id']);
                         }
                     }
                 } else {
                     if ($main['period_begin'] == $current_month_start || $main['period_begin'] == $one_current_month_start || $main['period_begin'] == $two_current_month_start) {
                         if (is_array($main)) {
                             if (!empty($main)) {
                                 $id = $this->extract_order($type, array($main), $main['id']);
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->session->set_flashdata('order_message', "Sync Complete");
     echo 1;
 }