Esempio n. 1
1
function login()
{
    if ($username == null) {
        echo "E-Mail is a required field.";
    } else {
        if ($password == null) {
            echo "Password is a required field.";
        } else {
            ProgressIndicator::Show();
            $url = "http://demo.kikapptools.com/Gastos/crud/Login.php";
            $httpClient_post = new httpClient();
            $inputMetodo = new InputText();
            $inputMetodo->setValue("login");
            $httpClient_post->addVariable('username', $username);
            $httpClient_post->addVariable('password', $password);
            $result = $httpClient_post->Execute('POST', $url);
            $id_user = new InputText();
            $struct = array("response" => DataType::Character(50));
            Data::FromJson($struct, $result);
            $id_user = $struct['response'];
            ProgressIndicator::Hide();
            if ($id_user != "0") {
                StorageAPI::Set("token", $id_user);
                AndroidAction::GoHome();
            } else {
                echo "Wrong user or password";
            }
        }
    }
}
Esempio n. 2
0
function save()
{
    if ($username == null) {
        echo "E-Mail is a required field.";
    } else {
        if ($password == null) {
            echo "Password is a required field.";
        } else {
            if ($password != $password2) {
                echo "Please make sure your passwords match.";
            } else {
                ProgressIndicator::Show();
                $url = "http://demo.kikapptools.com/Gastos/crud/updateUser.php";
                $httpClient_post = new httpClient();
                $inputMetodo = new InputText();
                $inputMetodo->setValue("login");
                $httpClient_post->addVariable('username', $username);
                $httpClient_post->addVariable('password', $password);
                $httpClient_post->addVariable('id', $token);
                $result = $httpClient_post->Execute('POST', $url);
                $id_user = new InputText();
                $struct = array("response" => DataType::Character(50));
                Data::FromJson($struct, $result);
                $id_user = $struct['response'];
                ProgressIndicator::Hide();
                AndroidAction::GoHome();
            }
        }
    }
}
Esempio n. 3
0
function save()
{
    if ($email == null) {
        echo "EMail is a required field.";
    } else {
        if ($password == null) {
            echo "Password is a required field.";
        } else {
            if ($password != $password_2) {
                echo "Please make sure your passwords match.";
            } else {
                ProgressIndicator::Show();
                $url = "http://demo.kikapptools.com/Gastos/crud/Register.php";
                $http = new httpClient();
                $http->addVariable('username', $email);
                $http->addVariable('passcode', $password);
                //lo de pasar la clave a md5 lo hace el Register.php
                $result = $http->Execute('POST', $url);
                $struct = array("id_usuario" => DataType::Character(101));
                Data::FromJson($struct, $result);
                $id_user = new InputText(100);
                $id_user = $struct['id_usuario'];
                if ($id_user == "0") {
                    echo "User already signed up";
                } else {
                    echo "Signed up succesfully.";
                    StorageAPI::Set("token", $id_user);
                    AndroidAction::GoHome();
                }
            }
        }
    }
}
Esempio n. 4
0
function login()
{
    if ($email == null) {
        echo "E-Mail is a required field.";
    } else {
        if ($pass == null) {
            echo "Password is a required field.";
        } else {
            ProgressIndicator::Show();
            $url = "http://demo.kikapptools.com/magento/apiKikApp/api.php?metodo=login";
            $httpClient_post = new httpClient();
            $httpClient_post->addVariable('email', $email);
            $httpClient_post->addVariable('password', $pass);
            $result = $httpClient_post->Execute('POST', $url);
            $customerToken = new InputText();
            $userName = new InputText();
            $response = array("customerToken" => DataType::Character(150), "userName" => DataType::Character(150));
            Data::FromJson($response, $result);
            $customerToken = $response['customerToken'];
            $userName = $response['userName'];
            ProgressIndicator::Hide();
            if ($customerToken != "") {
                StorageAPI::Set("token", $customerToken);
                StorageAPI::Set("userName", $userName);
                AndroidAction::GoHome();
            } else {
                echo "Invalid user";
            }
        }
    }
}
Esempio n. 5
0
function load_data()
{
    $url = "http://www.devxtend.com/Gecko/samples/3_2/rest/main_load_data";
    $hc = new httpClient();
    $rs = $hc->Execute("GET", $url);
    $struct = array(array("id" => DataType::Character(6), "name" => DataType::Character(100)));
    Data::FromJson($struct, $rs);
}
Esempio n. 6
0
function loadCity()
{
    $url = "http://demo.kikapptools.com/HttpClientEjemplo/crud/getCity.php";
    $httpClient = new httpClient();
    $result = $httpClient->Execute('GET', $url);
    $struct = array("nombreCiudad" => DataType::Character(150));
    Data::FromJson($struct, $result);
    $city = $product['nombreCiudad'];
}
Esempio n. 7
0
function clientStart()
{
    $token = StorageAPI::Get("token");
    $url = "http://demo.kikapptools.com/Gastos/crud/getAccount.php";
    $httpClient = new httpClient();
    $httpClient->addVariable("id", $token);
    $result = $httpClient->Execute('POST', $url);
    $struct = array("money" => DataType::Numeric(11));
    Data::FromJson($struct, $result);
    $input = $struct['money'];
}
Esempio n. 8
0
function confirm()
{
    $token = StorageAPI::Get("token");
    ProgressIndicator::ShowWithTitle("Adding budget...");
    $httpUpdate = new httpClient();
    $httpUpdate->addVariable('money', $money_value);
    $httpUpdate->addVariable('dates', $input_date);
    $httpUpdate->addVariable("id", $token);
    $httpUpdate->Execute('POST', "http://demo.kikapptools.com/Gastos/crud/updateAccount.php");
    ProgressIndicator::Hide();
    AndroidAction::GoHome();
}
Esempio n. 9
0
function load_image()
{
    $url = "http://demo.kikapptools.com/magento/apiKikApp/ProductImages.php?pId=" . $id;
    $httpClient = new httpClient();
    echo $id;
    $result = $httpClient->Execute('GET', $url);
    $str_images = array(array("url" => DataType::Character(350)));
    Data::FromJson($str_images, $result);
    foreach ($str_images as $img) {
        $image = $img['url'];
    }
}
Esempio n. 10
0
function load_grid()
{
    $url = "http://demo.kikapptools.com/magento/apiKikApp/Categories.php?cId=" . $cat;
    $httpClient = new httpClient();
    $result = $httpClient->Execute('GET', $url);
    $struct = array(array("id" => DataType::Numeric(6), "name" => DataType::Character(150)));
    Data::FromJson($struct, $result);
    foreach ($struct as $product) {
        $id = $product['id'];
        $name = $product['name'];
    }
}
Esempio n. 11
0
function delete()
{
    $isOk = new InputBoolean();
    $isOk = Interop::Confirm("Do you want to delete company ?");
    if ($isOk == true) {
        ProgressIndicator::Show();
        $httpC = new httpClient();
        $httpC->addVariable("CompanyId", $id);
        $httpC->Execute('POST', "http://demo.kikapptools.com/CRMManager/crud/deleteCompany.php");
        ProgressIndicator::Hide();
        return;
    }
}
Esempio n. 12
0
function load_images()
{
    $url = "http://demo.kikapptools.com/magento/apiGecko/productos.php?cId=0";
    $httpClient = new httpClient();
    $result = $httpClient->Execute('GET', $url);
    $struct = array(array("id" => DataType::Numeric(6), "name" => DataType::Character(150), "description" => DataType::Character(300), "pirce" => DataType::Character(10), "thumb" => DataType::Character(200)));
    Data::FromJson($struct, $result);
    foreach ($struct as $product) {
        $id = $product['id'];
        $title = $product['name'];
        $desc = $product['description'];
        $image = $product['thumb'];
    }
}
Esempio n. 13
0
function load_companies()
{
    $url = "http://demo.kikapptools.com/CRMManager/crud/getCompanies.php";
    $httpClient = new httpClient();
    $result = $httpClient->Execute('GET', $url);
    $struct = array(array("CompanyId" => DataType::Numeric(8), "CompanyName" => DataType::Character(100), "CompanyImage" => DataType::Character(200), "CompanyAddress" => DataType::Character(200)));
    Data::FromJson($struct, $result);
    $id = new InputNumeric();
    foreach ($struct as $company) {
        $id = $company['CompanyId'];
        $image = $company['CompanyImage'];
        $name = $company['CompanyName'];
        $address = $company['CompanyAddress'];
    }
}
Esempio n. 14
0
function grid_load()
{
    $url = "http://demo.kikapptools.com/magento/apiKikApp/Products.php?cId=" . $cat;
    $httpClient = new httpClient();
    $result = $httpClient->Execute('GET', $url);
    $struct = array(array("id" => DataType::Numeric(6), "name" => DataType::Character(150), "description" => DataType::Character(300), "pirce" => DataType::Character(10), "thumb" => DataType::Character(200), "stock" => DataType::Character(50), "href" => DataType::Character(300)));
    Data::FromJson($struct, $result);
    $prodUrl = new InputText();
    $id = new InputNumeric();
    $stock = new InputText();
    foreach ($struct as $product) {
        $id = $product['id'];
        $title = $product['name'];
        $desc = $product['description'];
        $image = $product['thumb'];
        $price = $product['pirce'];
        $stock = $product['stock'];
        $prodUrl = $product['href'];
    }
}
Esempio n. 15
0
function grid_load_products()
{
    $url_prod = "http://www.demo.kikapptools.com/magento/apiGecko/productos.php?cId=0";
    //the server url
    //Remember to configurate your server url on the Manifest.xml on <services>
    $httpClient_prod = new httpClient();
    $result_prod = $httpClient_prod->Execute('GET', $url_prod);
    //you get a JSON
    //it's a list so you have an array of an array
    $struct_prod = array(array("id" => DataType::Numeric(6), "name" => DataType::Character(150), "description" => DataType::Character(300), "pirce" => DataType::Character(10), "thumb" => DataType::Character(200)));
    Data::FromJson($struct_prod, $result_prod);
    //does a merge of the structure you made and the json you got
    foreach ($struct_prod as $product) {
        $id_prod = $product['id'];
        $title_prod = $product['name'];
        $desc_prod = $product['description'];
        $image_prod = $product['thumb'];
        $price_prod = $product['pirce'];
    }
    $id_prod = new InputNumeric();
}
Esempio n. 16
0
function confirm()
{
    $token = StorageAPI::Get("token");
    ProgressIndicator::ShowWithTitle("Inserting movement...");
    $httpUpdate = new httpClient();
    $httpUpdate->addVariable('value', $input_value);
    $httpUpdate->addVariable('moveType', $moveType);
    $httpUpdate->addVariable('description', $input_desc);
    $httpUpdate->addVariable("id", $token);
    $httpUpdate->addVariable('idCat', $dc_cat);
    $httpUpdate->addVariable('dates', $input_date);
    $httpUpdate->Execute('POST', "http://demo.kikapptools.com/Gastos/crud/insertMovements.php");
    ProgressIndicator::Hide();
    AndroidAction::GoHome();
}
Esempio n. 17
0
function save()
{
    ProgressIndicator::Show();
    $httpUpdate = new httpClient();
    $httpUpdate->addVariable('id', $id);
    $httpUpdate->addVariable('name', $name);
    $httpUpdate->addVariable('address', $address);
    $httpUpdate->addVariable('phone', $phone);
    $httpUpdate->addVariable('image', $image);
    $httpUpdate->Execute('POST', "http://demo.kikapptools.com/CRMManager/crud/updateCompany.php");
    ProgressIndicator::Hide();
    return;
}
Esempio n. 18
0
function save()
{
    ProgressIndicator::Show();
    $request = new httpClient();
    $request->addVariable('taskID', $id);
    $request->addVariable('status', $status);
    $request->addVariable('task', $name);
    $request->addVariable('imagen', $imagen);
    $result = $request->Execute('POST', "http://52.34.247.215/frameWorkExamples/taskManager/crud/updateTask.php");
    $sdtError = array("response" => type::Character(100));
    Data::FromJson($sdtError, $result);
    $rsValue = new InputText(100);
    $rsValue = $sdtError['response'];
    ProgressIndicator::Hide();
    $win->Open("main");
}
Esempio n. 19
0
 public static function getFullPy($word)
 {
     $RET = '';
     if ($word) {
         $word = SearchUtil::EscapeKeyword($word);
         // 分词
         $url = sprintf('http://360xun.sinaapp.com/api/segment?words=%s', urlencode($word));
         $segWord = httpClient::curlRequset($url);
         // 中文单字
         $singleWordArr = self::SplitSingleChinese($word);
         $singleWord = implode(' ', $singleWordArr);
         // 中文拼音前缀
         $preWordArr = self::SplitChinese($word);
         $preWord = implode(' ', $preWordArr);
         $pySegWord = Pinyin::str2py($segWord);
         $pySingleWord = Pinyin::str2py($singleWord);
         $pyPreWord = Pinyin::str2py($preWord);
         $segArr = explode(' ', $segWord);
         $engArr = array();
         if ($segArr) {
             foreach ($segArr as $s) {
                 if (preg_match('/^[a-zA-Z]+$/is', $s)) {
                     if ($engs = self::SplitEnglish($s, 3)) {
                         $engArr = array_merge($engArr, $engs);
                     }
                 }
             }
         }
         $RET = $pySegWord . ' ' . $pySingleWord . ' ' . $pyPreWord;
         if ($engArr) {
             $RET = implode(' ', $engArr) . ' ' . $RET;
         }
         $RET_ARR = array_unique(explode(' ', $RET));
         $RET = implode(' ', $RET_ARR);
         $RET = trim($RET);
     }
     return $RET;
 }
Esempio n. 20
0
function save()
{
    if ($name == null) {
        echo "Name is a required field.";
    } else {
        if ($lastname == null) {
            echo "Last name is a required field.";
        } else {
            if ($email == null) {
                echo "E-Mail is a required field.";
            } else {
                if ($password == null) {
                    echo "Password is a required field.";
                } else {
                    if ($password != $password_2) {
                        echo "Please make sure your passwords match.";
                    } else {
                        ProgressIndicator::Show();
                        $url = "http://demo.kikapptools.com/magento/apiKikApp/api.php?metodo=createUser";
                        $http = new httpClient();
                        $http->addVariable('name', $name);
                        $http->addVariable('lastname', $lastname);
                        $http->addVariable('email', $email);
                        $http->addVariable('password', $password);
                        $rs = $http->Execute("POST", $url);
                        $sdt_rs = array("error" => DataType::Character(300));
                        Data::FromJson($sdtError, $rs);
                        $rs = new InputText(300);
                        $rs = $sdt_rs['error'];
                        ProgressIndicator::Hide();
                        if ($rs == "0") {
                            echo "User created successfully!";
                            $win->Open("Login");
                        } else {
                            echo $rs;
                        }
                    }
                }
            }
        }
    }
}
Esempio n. 21
0
function save()
{
    ProgressIndicator::Show();
    $url = "http://demo.kikapptools.com/magento/apiKikApp/api.php?metodo=updateUser";
    $hc = new httpClient();
    $hc->addVariable("name", $name);
    $hc->addVariable("lastname", $last_name);
    $hc->addVariable("email", $email);
    $hc->addVariable("customerToken", $token);
    $rs = $hc->Execute("POST", $url);
    $sdt_rs = array("error" => DataType::Character(300));
    Data::FromJson($sdtError, $rs);
    $rs = new InputText(300);
    $rs = $sdt_rs['error'];
    ProgressIndicator::Hide();
    if ($rs == "0") {
        echo "User updated successfully!";
        $win->Refresh();
    } else {
        echo $rs;
    }
}
Esempio n. 22
0
function save()
{
    //Check form values
    if ($name == null) {
        echo "Name is a required field.";
    } else {
        $compareDefaultDate = new InputDate();
        if ($date == $compareDefaultDate) {
            echo "Date is a required field.";
        } else {
            if ($description == null) {
                echo "Please provide a description";
            } else {
                ProgressIndicator::Show();
                //Make JSON request with variables
                $request = new httpClient();
                $request->addVariable('task', $name);
                $request->addVariable('taskID', $id);
                $request->addVariable('created_at', $date);
                $request->addVariable('description', $description);
                $url = "http://demo.kikapptools.com/taskManager/crud/addTask.php";
                $result = $request->Execute("POST", $url);
                //Cast response data type
                $sdtError = array("response" => DataType::Character(100));
                Data::FromJson($sdtError, $result);
                $rsValue = new InputText(100);
                $rsValue = $sdtError['response'];
                if ($addToCalendar) {
                    Calendar::Schedule($name, $date, $date, "10:00:00", "11:00:00", $name);
                }
                ProgressIndicator::Hide();
                //returns to the app home page.
                AndroidAction::GoHome();
            }
        }
    }
}
Esempio n. 23
0
 function _upsGetQuote()
 {
     if (!isset($this->_upsActionCode)) {
         $this->_upsActionCode = '4';
     }
     $request = join('&', array('accept_UPS_license_agreement=yes', '10_action=' . $this->_upsActionCode, '13_product=' . $this->_upsProductCode, '14_origCountry=' . $this->_upsOriginCountryCode, '15_origPostal=' . $this->_upsOriginPostalCode, '19_destPostal=' . $this->_upsDestPostalCode, '22_destCountry=' . $this->_upsDestCountryCode, '23_weight=' . $this->_upsPackageWeight, '47_rate_chart=' . $this->_upsRateCode, '48_container=' . $this->_upsContainerCode, '49_residential=' . $this->_upsResComCode));
     $http = new httpClient();
     if ($http->Connect('www.ups.com', 80)) {
         $http->addHeader('Host', 'www.ups.com');
         $http->addHeader('User-Agent', 'osCommerce');
         $http->addHeader('Connection', 'Close');
         if ($http->Get('/using/services/rave/qcostcgi.cgi?' . $request)) {
             $body = $http->getBody();
         }
         $http->Disconnect();
     } else {
         return 'error';
     }
     /*
         mail('*****@*****.**','UPS response',$body,'From: <*****@*****.**>');
     */
     $body_array = explode("\n", $body);
     $returnval = array();
     $errorret = 'error';
     // only return error if NO rates returned
     $n = sizeof($body_array);
     for ($i = 0; $i < $n; $i++) {
         $result = explode('%', $body_array[$i]);
         $errcode = substr($result[0], -1);
         switch ($errcode) {
             case 3:
                 if (is_array($returnval)) {
                     $returnval[] = array($result[1] => $result[8]);
                 }
                 break;
             case 4:
                 if (is_array($returnval)) {
                     $returnval[] = array($result[1] => $result[8]);
                 }
                 break;
             case 5:
                 $errorret = $result[1];
                 break;
             case 6:
                 if (is_array($returnval)) {
                     $returnval[] = array($result[3] => $result[10]);
                 }
                 break;
         }
     }
     if (empty($returnval)) {
         $returnval = $errorret;
     }
     return $returnval;
 }
Esempio n. 24
0
 function _getQuote()
 {
     global $order;
     if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
         $request = '<RateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="******">';
         $services_count = 0;
         if (isset($this->service)) {
             $this->types = array($this->service => $this->types[$this->service]);
         }
         $dest_zip = str_replace(' ', '', $order->delivery['postcode']);
         if ($order->delivery['country']['iso_code_2'] == 'US') {
             $dest_zip = substr($dest_zip, 0, 5);
         }
         reset($this->types);
         while (list($key, $value) = each($this->types)) {
             $request .= '<Package ID="' . $services_count . '">' . '<Service>' . $key . '</Service>' . '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' . '<ZipDestination>' . $dest_zip . '</ZipDestination>' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<Container>' . $this->container . '</Container>' . '<Size>' . $this->size . '</Size>' . '<Machinable>' . $this->machinable . '</Machinable>' . '</Package>';
             $services_count++;
         }
         $request .= '</RateRequest>';
         $request = 'API=Rate&XML=' . urlencode($request);
     } else {
         $request = '<IntlRateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="******">' . '<Package ID="0">' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<MailType>Package</MailType>' . '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' . '</Package>' . '</IntlRateRequest>';
         $request = 'API=IntlRate&XML=' . urlencode($request);
     }
     switch (MODULE_SHIPPING_USPS_SERVER) {
         case 'production':
             $usps_server = 'production.shippingapis.com';
             $api_dll = 'shippingapi.dll';
             break;
         case 'test':
         default:
             $usps_server = 'testing.shippingapis.com';
             $api_dll = 'ShippingAPITest.dll';
             break;
     }
     $body = '';
     $http = new httpClient();
     if ($http->Connect($usps_server, 80)) {
         $http->addHeader('Host', $usps_server);
         $http->addHeader('User-Agent', 'osCommerce');
         $http->addHeader('Connection', 'Close');
         if ($http->Get('/' . $api_dll . '?' . $request)) {
             $body = $http->getBody();
         }
         $http->Disconnect();
     } else {
         return false;
     }
     $response = array();
     while (true) {
         if ($start = strpos($body, '<Package ID=')) {
             $body = substr($body, $start);
             $end = strpos($body, '</Package>');
             $response[] = substr($body, 0, $end + 10);
             $body = substr($body, $end + 9);
         } else {
             break;
         }
     }
     $rates = array();
     if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
         if (sizeof($response) == '1') {
             if (ereg('<Error>', $response[0])) {
                 $number = ereg('<Number>(.*)</Number>', $response[0], $regs);
                 $number = $regs[1];
                 $description = ereg('<Description>(.*)</Description>', $response[0], $regs);
                 $description = $regs[1];
                 return array('error' => $number . ' - ' . $description);
             }
         }
         $n = sizeof($response);
         for ($i = 0; $i < $n; $i++) {
             if (strpos($response[$i], '<Postage>')) {
                 $service = ereg('<Service>(.*)</Service>', $response[$i], $regs);
                 $service = $regs[1];
                 $postage = ereg('<Postage>(.*)</Postage>', $response[$i], $regs);
                 $postage = $regs[1];
                 $rates[] = array($service => $postage);
             }
         }
     } else {
         if (ereg('<Error>', $response[0])) {
             $number = ereg('<Number>(.*)</Number>', $response[0], $regs);
             $number = $regs[1];
             $description = ereg('<Description>(.*)</Description>', $response[0], $regs);
             $description = $regs[1];
             return array('error' => $number . ' - ' . $description);
         } else {
             $body = $response[0];
             $services = array();
             while (true) {
                 if ($start = strpos($body, '<Service ID=')) {
                     $body = substr($body, $start);
                     $end = strpos($body, '</Service>');
                     $services[] = substr($body, 0, $end + 10);
                     $body = substr($body, $end + 9);
                 } else {
                     break;
                 }
             }
             $size = sizeof($services);
             for ($i = 0, $n = $size; $i < $n; $i++) {
                 if (strpos($services[$i], '<Postage>')) {
                     $service = ereg('<SvcDescription>(.*)</SvcDescription>', $services[$i], $regs);
                     $service = $regs[1];
                     $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs);
                     $postage = $regs[1];
                     if (isset($this->service) && $service != $this->service) {
                         continue;
                     }
                     $rates[] = array($service => $postage);
                 }
             }
         }
     }
     return sizeof($rates) > 0 ? $rates : false;
 }
Esempio n. 25
0
 /**
  * Sent request for quote to UPS via older HTML method
  *
  * @return array
  */
 function _upsGetQuote()
 {
     if (!isset($this->_upsActionCode)) {
         $this->_upsActionCode = '4';
     }
     $request = join('&', array('accept_UPS_license_agreement=yes', '10_action=' . $this->_upsActionCode, '13_product=' . $this->_upsProductCode, '14_origCountry=' . $this->_upsOriginCountryCode, '15_origPostal=' . $this->_upsOriginPostalCode, '19_destPostal=' . $this->_upsDestPostalCode, '22_destCountry=' . $this->_upsDestCountryCode, '23_weight=' . $this->_upsPackageWeight, '47_rate_chart=' . $this->_upsRateCode, '48_container=' . $this->_upsContainerCode, '49_residential=' . $this->_upsResComCode));
     $http = new httpClient();
     if ($http->Connect('www.ups.com', 80)) {
         $http->addHeader('Host', 'www.ups.com');
         $http->addHeader('User-Agent', 'Zen Cart');
         $http->addHeader('Connection', 'Close');
         if ($http->Get('/using/services/rave/qcostcgi.cgi?' . $request)) {
             $body = $http->getBody();
         }
         $http->Disconnect();
     } else {
         return 'error';
     }
     // BOF: UPS USPS
     /*
     TEST by checking out in the catalog; try a variety of shipping destinations to be sure
     your customers will be properly served.  If you are not getting any quotes, try enabling
     more alternatives in admin. Make sure your store's postal code is set in Admin ->
     Configuration -> Shipping/Packaging, since you won't get any quotes unless there is
     a origin that UPS recognizes.
     
     If you STILL don't get any quotes, here is a way to find out exactly what UPS is sending
     back in response to rate quote request, you can uncomment the following mail() line and 
     then check your email after visiting the shipping page in checkout ...
     */
     //mail(STORE_OWNER_EMAIL_ADDRESS, 'UPS response', $body, 'From: <'.STORE_OWNER_EMAIL_ADDRESS.'>');
     // EOF: UPS USPS
     $body_array = explode("\n", $body);
     /* //DEBUG ONLY
         $n = sizeof($body_array);
         for ($i=0; $i<$n; $i++) {
           $result = explode('%', $body_array[$i]);
           print_r($result);
         }
         die('END');
     */
     $returnval = array();
     $errorret = 'error';
     // only return 'error' if NO rates returned
     $n = sizeof($body_array);
     for ($i = 0; $i < $n; $i++) {
         $result = explode('%', $body_array[$i]);
         $errcode = substr($result[0], -1);
         switch ($errcode) {
             case 3:
                 if (is_array($returnval)) {
                     $returnval[] = array($result[1] => $result[10]);
                 }
                 break;
             case 4:
                 if (is_array($returnval)) {
                     $returnval[] = array($result[1] => $result[10]);
                 }
                 break;
             case 5:
                 $errorret = $result[1];
                 break;
             case 6:
                 if (is_array($returnval)) {
                     $returnval[] = array($result[3] => $result[10]);
                 }
                 break;
         }
     }
     if (empty($returnval)) {
         $returnval = $errorret;
     }
     return $returnval;
 }
Esempio n. 26
0
 function _getQuote()
 {
     global $order, $transittime;
     if (in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) {
         $transit = TRUE;
     }
     if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
         $request = '<RateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="******">';
         $services_count = 0;
         if (isset($this->service)) {
             $this->types = array($this->service => $this->types[$this->service]);
         }
         $dest_zip = str_replace(' ', '', $order->delivery['postcode']);
         if ($order->delivery['country']['iso_code_2'] == 'US') {
             $dest_zip = substr($dest_zip, 0, 5);
         }
         reset($this->types);
         $allowed_types = explode(", ", MODULE_SHIPPING_USPS_TYPES);
         while (list($key, $value) = each($this->types)) {
             if (!in_array($key, $allowed_types)) {
                 continue;
             }
             $request .= '<Package ID="' . $services_count . '">' . '<Service>' . $key . '</Service>' . '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' . '<ZipDestination>' . $dest_zip . '</ZipDestination>' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<Container>' . $this->container . '</Container>' . '<Size>' . $this->size . '</Size>' . '<Machinable>' . $this->machinable . '</Machinable>' . '</Package>';
             if ($transit) {
                 $transitreq = 'USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="******">' . '<OriginZip>' . STORE_ORIGIN_ZIP . '</OriginZip>' . '<DestinationZip>' . $dest_zip . '</DestinationZip>';
                 switch ($key) {
                     case 'Express':
                         $transreq[$key] = 'API=ExpressMail&XML=' . urlencode('<ExpressMailRequest ' . $transitreq . '</ExpressMailRequest>');
                         break;
                     case 'Priority':
                         $transreq[$key] = 'API=PriorityMail&XML=' . urlencode('<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>');
                         break;
                     case 'Parcel':
                         $transreq[$key] = 'API=StandardB&XML=' . urlencode('<StandardBRequest ' . $transitreq . '</StandardBRequest>');
                         break;
                     default:
                         $transreq[$key] = '';
                         break;
                 }
             }
             $services_count++;
         }
         $request .= '</RateRequest>';
         $request = 'API=Rate&XML=' . urlencode($request);
     } else {
         $request = '<IntlRateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '" PASSWORD="******">' . '<Package ID="0">' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<MailType>Package</MailType>' . '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' . '</Package>' . '</IntlRateRequest>';
         $request = 'API=IntlRate&XML=' . urlencode($request);
     }
     switch (MODULE_SHIPPING_USPS_SERVER) {
         case 'production':
             $usps_server = 'production.shippingapis.com';
             $api_dll = 'ShippingAPI.dll';
             break;
         case 'test':
         default:
             $usps_server = 'stg-production.shippingapis.com';
             $api_dll = 'shippingapi.dll';
             break;
     }
     $body = '';
     $http = new httpClient();
     if ($http->Connect($usps_server, 80)) {
         $http->addHeader('Host', $usps_server);
         $http->addHeader('User-Agent', 'osCommerce');
         $http->addHeader('Connection', 'Close');
         if ($http->Get('/' . $api_dll . '?' . $request)) {
             $body = $http->getBody();
         }
         //  mail('*****@*****.**','USPS rate quote response',$body,'From: <*****@*****.**>');
         if ($transit && is_array($transreq) && $order->delivery['country']['id'] == STORE_COUNTRY) {
             while (list($key, $value) = each($transreq)) {
                 if ($http->Get('/' . $api_dll . '?' . $value)) {
                     $transresp[$key] = $http->getBody();
                 }
             }
         }
         $http->Disconnect();
     } else {
         return false;
     }
     $response = array();
     while (true) {
         if ($start = strpos($body, '<Package ID=')) {
             $body = substr($body, $start);
             $end = strpos($body, '</Package>');
             $response[] = substr($body, 0, $end + 10);
             $body = substr($body, $end + 9);
         } else {
             break;
         }
     }
     $rates = array();
     if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
         if (sizeof($response) == '1') {
             if (ereg('<Error>', $response[0])) {
                 $number = ereg('<Number>(.*)</Number>', $response[0], $regs);
                 $number = $regs[1];
                 $description = ereg('<Description>(.*)</Description>', $response[0], $regs);
                 $description = $regs[1];
                 return array('error' => $number . ' - ' . $description);
             }
         }
         $n = sizeof($response);
         for ($i = 0; $i < $n; $i++) {
             if (strpos($response[$i], '<Postage>')) {
                 $service = ereg('<Service>(.*)</Service>', $response[$i], $regs);
                 $service = $regs[1];
                 $postage = ereg('<Postage>(.*)</Postage>', $response[$i], $regs);
                 $postage = $regs[1];
                 $rates[] = array($service => $postage);
                 if ($transit) {
                     switch ($service) {
                         case 'Express':
                             $time = ereg('<MonFriCommitment>(.*)</MonFriCommitment>', $transresp[$service], $tregs);
                             $time = $tregs[1];
                             if ($time == '' || $time == 'No Data') {
                                 $time = '1 - 2 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
                             } else {
                                 $time = 'Tomorrow by ' . $time;
                             }
                             break;
                         case 'Priority':
                             $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);
                             $time = $tregs[1];
                             if ($time == '' || $time == 'No Data') {
                                 $time = '2 - 3 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
                             } elseif ($time == '1') {
                                 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY;
                             } else {
                                 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
                             }
                             break;
                         case 'Parcel':
                             $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs);
                             $time = $tregs[1];
                             if ($time == '' || $time == 'No Data') {
                                 $time = '4 - 7 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
                             } elseif ($time == '1') {
                                 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY;
                             } else {
                                 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
                             }
                             break;
                         case 'First Class':
                             $time = '2 - 5 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
                             break;
                         default:
                             $time = '';
                             break;
                     }
                     if ($time != '') {
                         $transittime[$service] = ' (' . $time . ')';
                     }
                 }
             }
         }
     } else {
         if (ereg('<Error>', $response[0])) {
             $number = ereg('<Number>(.*)</Number>', $response[0], $regs);
             $number = $regs[1];
             $description = ereg('<Description>(.*)</Description>', $response[0], $regs);
             $description = $regs[1];
             return array('error' => $number . ' - ' . $description);
         } else {
             $body = $response[0];
             $services = array();
             while (true) {
                 if ($start = strpos($body, '<Service ID=')) {
                     $body = substr($body, $start);
                     $end = strpos($body, '</Service>');
                     $services[] = substr($body, 0, $end + 10);
                     $body = substr($body, $end + 9);
                 } else {
                     break;
                 }
             }
             $allowed_types = array();
             foreach (explode(", ", MODULE_SHIPPING_USPS_TYPES_INTL) as $value) {
                 $allowed_types[$value] = $this->intl_types[$value];
             }
             $size = sizeof($services);
             for ($i = 0, $n = $size; $i < $n; $i++) {
                 if (strpos($services[$i], '<Postage>')) {
                     $service = ereg('<SvcDescription>(.*)</SvcDescription>', $services[$i], $regs);
                     $service = $regs[1];
                     $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs);
                     $postage = $regs[1];
                     $time = ereg('<SvcCommitments>(.*)</SvcCommitments>', $services[$i], $tregs);
                     $time = $tregs[1];
                     $time = preg_replace('/Weeks$/', MODULE_SHIPPING_USPS_TEXT_WEEKS, $time);
                     $time = preg_replace('/Days$/', MODULE_SHIPPING_USPS_TEXT_DAYS, $time);
                     $time = preg_replace('/Day$/', MODULE_SHIPPING_USPS_TEXT_DAY, $time);
                     if (!in_array($service, $allowed_types)) {
                         continue;
                     }
                     if (isset($this->service) && $service != $this->service) {
                         continue;
                     }
                     $rates[] = array($service => $postage);
                     if ($time != '') {
                         $transittime[$service] = ' (' . $time . ')';
                     }
                 }
             }
         }
     }
     return sizeof($rates) > 0 ? $rates : false;
 }
Esempio n. 27
0
 /**
  * Get actual quote from USPS
  *
  * @return array of results or boolean false if no results
  */
 function _getQuote()
 {
     // BOF: UPS USPS
     global $order, $transittime;
     if (in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) {
         $transit = TRUE;
     }
     // EOF: UPS USPS
     // translate for US Territories
     //    if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
     if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY || SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US') {
         $request = '<RateV3Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">';
         $services_count = 0;
         if (isset($this->service)) {
             $this->types = array($this->service => $this->types[$this->service]);
         }
         $dest_zip = str_replace(' ', '', $order->delivery['postcode']);
         // translate for US Territories
         if ($order->delivery['country']['iso_code_2'] == 'US' || SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US') {
             $dest_zip = substr($dest_zip, 0, 5);
         }
         reset($this->types);
         // BOF: UPS USPS
         $allowed_types = explode(", ", MODULE_SHIPPING_USPS_TYPES);
         while (list($key, $value) = each($this->types)) {
             // BOF: UPS USPS
             if (!in_array($key, $allowed_types)) {
                 continue;
             }
             //For Options list, go to page 6 of document: http://www.usps.com/webtools/_pdf/Rate-Calculators-v1-2.pdf
             //FIRST CLASS MAIL OPTIONS
             if ($key == 'FIRST CLASS') {
                 $this->FirstClassMailType = '<FirstClassMailType>LETTER</FirstClassMailType>';
             } else {
                 $this->FirstClassMailType = '';
             }
             //PRIORITY MAIL OPTIONS
             if ($key == 'PRIORITY') {
                 $this->container = '';
                 // Blank, Flate Rate Envelope, or Flat Rate Box // Sm Flat Rate Box, Md Flat Rate Box and Lg Flat Rate Box
             }
             //EXPRESS MAIL OPTIONS
             if ($key == 'EXPRESS') {
                 $this->container = '';
                 // Blank, or Flate Rate Envelope
             }
             //PARCEL POST OPTIONS
             if ($key == 'PARCEL') {
                 $this->container = 'Regular';
                 $this->machinable = 'true';
             }
             //BPM OPTIONS
             //MEDIA MAIL OPTIONS
             //LIBRARY MAIL OPTIONS
             $request .= '<Package ID="' . $services_count . '">' . '<Service>' . $key . '</Service>' . '<FirstClassMailType>' . $this->fctype . '</FirstClassMailType>' . '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' . '<ZipDestination>' . $dest_zip . '</ZipDestination>' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<Container>' . $this->container . '</Container>' . '<Size>' . $this->size . '</Size>' . '<Machinable>' . $this->machinable . '</Machinable>' . '</Package>';
             // BOF: UPS USPS
             if ($transit) {
                 $transitreq = 'USERID="' . MODULE_SHIPPING_USPS_USERID . '">' . '<OriginZip>' . STORE_ORIGIN_ZIP . '</OriginZip>' . '<DestinationZip>' . $dest_zip . '</DestinationZip>';
                 switch ($key) {
                     case 'EXPRESS':
                         $transreq[$key] = 'API=ExpressMail&XML=' . urlencode('<ExpressMailRequest ' . $transitreq . '</ExpressMailRequest>');
                         break;
                     case 'PRIORITY':
                         $transreq[$key] = 'API=PriorityMail&XML=' . urlencode('<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>');
                         break;
                     case 'PARCEL':
                         $transreq[$key] = 'API=StandardB&XML=' . urlencode('<StandardBRequest ' . $transitreq . '</StandardBRequest>');
                         break;
                     default:
                         $transreq[$key] = '';
                         break;
                 }
             }
             // EOF: UPS USPS
             $services_count++;
         }
         $request .= '</RateV3Request>';
         $request = 'API=RateV3&XML=' . urlencode($request);
     } else {
         $request = '<IntlRateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '">' . '<Package ID="0">' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<MailType>Package</MailType>' . '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' . '</Package>' . '</IntlRateRequest>';
         $request = 'API=IntlRate&XML=' . urlencode($request);
     }
     switch (MODULE_SHIPPING_USPS_SERVER) {
         case 'production':
             $usps_server = 'production.shippingapis.com';
             $api_dll = 'shippingapi.dll';
             break;
         case 'test':
         default:
             $usps_server = 'testing.shippingapis.com';
             $api_dll = 'ShippingAPI.dll';
             break;
     }
     $body = '';
     $http = new httpClient();
     $http->timeout = 5;
     if ($http->Connect($usps_server, 80)) {
         $http->addHeader('Host', $usps_server);
         $http->addHeader('User-Agent', 'Zen Cart');
         $http->addHeader('Connection', 'Close');
         if ($http->Get('/' . $api_dll . '?' . $request)) {
             $body = $http->getBody();
         }
         if (MODULE_SHIPPING_USPS_DEBUG_MODE == 'Email') {
             mail(STORE_OWNER_EMAIL_ADDRESS, 'Debug: USPS rate quote response', '(You can turn off this debug email by editing your USPS module settings in the admin area of your store.) ' . "\n\n" . $body, 'From: <' . EMAIL_FROM . '>');
         }
         // BOF: UPS USPS
         // translate for US Territories
         //      if ($transit && is_array($transreq) && ($order->delivery['country']['id'] == STORE_COUNTRY)) {
         if ($transit && is_array($transreq) && ($order->delivery['country']['id'] == STORE_COUNTRY || SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US')) {
             while (list($key, $value) = each($transreq)) {
                 if ($http->Get('/' . $api_dll . '?' . $value)) {
                     $transresp[$key] = $http->getBody();
                 }
             }
         }
         // EOF: UPS USPS
         $http->Disconnect();
     } else {
         return -1;
     }
     $response = array();
     while (true) {
         if ($start = strpos($body, '<Package ID=')) {
             $body = substr($body, $start);
             $end = strpos($body, '</Package>');
             $response[] = substr($body, 0, $end + 10);
             $body = substr($body, $end + 9);
         } else {
             break;
         }
     }
     $rates = array();
     // translate for US Territories
     //    if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
     if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY || SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US') {
         if (sizeof($response) == '1') {
             if (preg_match('/<Error>/i', $response[0])) {
                 $number = preg_match('/<Number>(.*)<\\/Number>/msi', $response[0], $regs);
                 $number = $regs[1];
                 $description = preg_match('/<Description>(.*)<\\/Description>/msi', $response[0], $regs);
                 $description = $regs[1];
                 return array('error' => $number . ' - ' . $description);
             }
         }
         $n = sizeof($response);
         for ($i = 0; $i < $n; $i++) {
             if (strpos($response[$i], '<Rate>')) {
                 $service = preg_match('/<MailService>(.*)<\\/MailService>/msi', $response[$i], $regs);
                 $service = $regs[1];
                 if (preg_match('/Express/i', $service)) {
                     $service = 'EXPRESS';
                 }
                 if (preg_match('/Priority/i', $service)) {
                     $service = 'PRIORITY';
                 }
                 if (preg_match('/First-Class Mail/i', $service)) {
                     $service = 'FIRST CLASS';
                 }
                 if (preg_match('/Parcel/i', $service)) {
                     $service = 'PARCEL';
                 }
                 if (preg_match('/Media/i', $service)) {
                     $service = 'MEDIA';
                 }
                 if (preg_match('/Bound Printed/i', $service)) {
                     $service = 'BPM';
                 }
                 if (preg_match('/Library/i', $service)) {
                     $service = 'LIBRARY';
                 }
                 $postage = preg_match('/<Rate>(.*)<\\/Rate>/msi', $response[$i], $regs);
                 $postage = $regs[1];
                 $rates[] = array($service => $postage);
                 // BOF: UPS USPS
                 if ($transit) {
                     switch ($service) {
                         case 'EXPRESS':
                             $time = preg_match('/<MonFriCommitment>(.*)<\\/MonFriCommitment>/msi', $transresp[$service], $tregs);
                             $time = $tregs[1];
                             if ($time == '' || $time == 'No Data') {
                                 $time = '1 - 2 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
                             } else {
                                 $time = 'Tomorrow by ' . $time;
                             }
                             break;
                         case 'PRIORITY':
                             $time = preg_match('/<Days>(.*)<\\/Days>/msi', $transresp[$service], $tregs);
                             $time = $tregs[1];
                             if ($time == '' || $time == 'No Data') {
                                 $time = '2 - 3 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
                             } elseif ($time == '1') {
                                 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY;
                             } else {
                                 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
                             }
                             break;
                         case 'PARCEL':
                             $time = preg_match('/<Days>(.*)<\\/Days>/msi', $transresp[$service], $tregs);
                             $time = $tregs[1];
                             if ($time == '' || $time == 'No Data') {
                                 $time = '4 - 7 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
                             } elseif ($time == '1') {
                                 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAY;
                             } else {
                                 $time .= ' ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
                             }
                             break;
                         case 'FIRST CLASS':
                             $time = '2 - 5 ' . MODULE_SHIPPING_USPS_TEXT_DAYS;
                             break;
                         default:
                             $time = '';
                             break;
                     }
                     if ($time != '') {
                         $transittime[$service] = ' (' . $time . ')';
                     }
                 }
                 // EOF: UPS USPS
             }
         }
     } else {
         if (preg_match('/<Error>/i', $response[0])) {
             $number = preg_match('/<Number>(.*)<\\/Number>/msi', $response[0], $regs);
             $number = $regs[1];
             $description = preg_match('/<Description>(.*)<\\/Description>/msi', $response[0], $regs);
             $description = $regs[1];
             return array('error' => $number . ' - ' . $description);
         } else {
             $body = $response[0];
             $services = array();
             while (true) {
                 if ($start = strpos($body, '<Service ID=')) {
                     $body = substr($body, $start);
                     $end = strpos($body, '</Service>');
                     $services[] = substr($body, 0, $end + 10);
                     $body = substr($body, $end + 9);
                 } else {
                     break;
                 }
             }
             // BOF: UPS USPS
             $allowed_types = array();
             foreach (explode(", ", MODULE_SHIPPING_USPS_TYPES_INTL) as $value) {
                 $allowed_types[$value] = $this->intl_types[$value];
             }
             // EOF: UPS USPS
             $size = sizeof($services);
             for ($i = 0, $n = $size; $i < $n; $i++) {
                 if (strpos($services[$i], '<Postage>')) {
                     $service = preg_match('/<SvcDescription>(.*)<\\/SvcDescription>/msi', $services[$i], $regs);
                     $service = $regs[1];
                     $postage = preg_match('/<Postage>(.*)<\\/Postage>/i', $services[$i], $regs);
                     $postage = $regs[1];
                     // BOF: UPS USPS
                     $time = preg_match('/<SvcCommitments>(.*)<\\/SvcCommitments>/msi', $services[$i], $tregs);
                     $time = $tregs[1];
                     $time = preg_replace('/Weeks$/', MODULE_SHIPPING_USPS_TEXT_WEEKS, $time);
                     $time = preg_replace('/Days$/', MODULE_SHIPPING_USPS_TEXT_DAYS, $time);
                     $time = preg_replace('/Day$/', MODULE_SHIPPING_USPS_TEXT_DAY, $time);
                     if (!in_array($service, $allowed_types)) {
                         continue;
                     }
                     if ($_SESSION['cart']->total > 400 && strstr($services[$i], 'Priority Mail International Flat Rate Envelope')) {
                         continue;
                     }
                     // skip value > $400 Priority Mail International Flat Rate Envelope
                     // EOF: UPS USPS
                     if (isset($this->service) && $service != $this->service) {
                         continue;
                     }
                     $rates[] = array($service => $postage);
                     // BOF: UPS USPS
                     if ($time != '') {
                         $transittime[$service] = ' (' . $time . ')';
                     }
                     // EOF: UPS USPS
                 }
             }
         }
     }
     //echo 'RATE RESPONSE: ' . "\n" . print_r($rates);
     return sizeof($rates) > 0 ? $rates : false;
 }
Esempio n. 28
0
function refresh()
{
    $url = "http://demo.kikapptools.com/Gastos/crud/getIncome.php?id=" . $token;
    $httpClient = new httpClient();
    $result = $httpClient->Execute('GET', $url);
    $struct = array("account" => DataType::Numeric(11), "value_income" => DataType::Numeric(11), "value_outcome" => DataType::Numeric(11), "value_income_month" => DataType::Numeric(11), "value_outcome_month" => DataType::Numeric(11), "label_actual_month" => DataType::Character(20));
    Data::FromJson($struct, $result);
    $input_account = $struct['account'];
    $input_income = $struct['value_income'];
    $input_outcome = $struct['value_outcome'];
    $input1 = $struct['value_income_month'];
    $input2 = $struct['value_outcome_month'];
    $label_title = $struct['label_actual_month'];
}
 function _getQuote()
 {
     global $order;
     if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
         $dest_zip = str_replace(' ', '', $order->delivery['postcode']);
         if ($order->delivery['country']['iso_code_2'] == 'US') {
             $dest_zip = substr($dest_zip, 0, 5);
         }
         $request = '<RateV3Request USERID="' . MODULE_SHIPPING_USPS_USERID . '">' . '<Package ID="0">' . '<Service>' . 'ALL' . '</Service>' . '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' . '<ZipDestination>' . $dest_zip . '</ZipDestination>' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<Container/><Size>Regular</Size><Machinable>True</Machinable>' . '</Package></RateV3Request>';
         $request = 'API=RateV3&XML=' . urlencode($request);
     } else {
         $request = '<IntlRateRequest USERID="' . MODULE_SHIPPING_USPS_USERID . '">' . '<Package ID="0">' . '<Pounds>' . $this->pounds . '</Pounds>' . '<Ounces>' . $this->ounces . '</Ounces>' . '<MailType>Package</MailType>' . '<GXG>' . '<Length>12</Length><Width>12</Width><Height>12</Height>' . '<POBoxFlag>N</POBoxFlag><GiftFlag>N</GiftFlag>' . '</GXG>' . '<ValueOfContents>50</ValueOfContents>' . '<Country>' . $this->countries[$order->delivery['country']['iso_code_2']] . '</Country>' . '</Package>' . '</IntlRateRequest>';
         $request = 'API=IntlRate&XML=' . urlencode($request);
     }
     $body = '';
     if (!class_exists('httpClient')) {
         include 'includes/classes/http_client.php';
     }
     $http = new httpClient();
     if ($http->Connect('production.shippingapis.com', 80)) {
         $http->addHeader('Host', 'production.shippingapis.com');
         $http->addHeader('User-Agent', 'osCommerce');
         $http->addHeader('Connection', 'Close');
         if ($http->Get('/shippingapi.dll?' . $request)) {
             $body = $http->getBody();
         }
         $http->Disconnect();
     } else {
         return false;
     }
     $response = array();
     while (true) {
         if ($start = strpos($body, '<Package ID=')) {
             $body = substr($body, $start);
             $end = strpos($body, '</Package>');
             $response[] = substr($body, 0, $end + 10);
             $body = substr($body, $end + 9);
         } else {
             break;
         }
     }
     $rates = array();
     if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
         if (sizeof($response) == '1') {
             if (preg_match('/<Error>/', $response[0])) {
                 $number = preg_match('/<Number>(.*)<\\/Number>/', $response[0], $regs);
                 $number = $regs[1];
                 $description = preg_match('/<Description>(.*)<\\/Description>/', $response[0], $regs);
                 $description = $regs[1];
                 return array('error' => $number . ' - ' . $description);
             }
         }
         $n = sizeof($response);
         for ($i = 0; $i < $n; $i++) {
             $resp = $response[$i];
             $pos = 0;
             while (1) {
                 $pos = strpos($response[$i], '<Postage', $pos);
                 if ($pos === FALSE) {
                     break;
                 }
                 $end = strpos($response[$i], '</Postage>', $pos);
                 if ($end === FALSE) {
                     break;
                 }
                 $resp = substr($response[$i], $pos, $end - $pos);
                 $service = preg_match('/<MailService>(.*)<\\/MailService>/', $resp, $regs);
                 $service = $regs[1];
                 $postage = preg_match('/<Rate>(.*)<\\/Rate>/', $resp, $regs);
                 $postage = $regs[1];
                 $pos = $end;
                 $rates[] = array($service => $postage);
             }
         }
     } else {
         if (preg_match('/<Error>/', $response[0])) {
             $number = preg_match('/<Number>(.*)<\\/Number>/', $response[0], $regs);
             $number = $regs[1];
             $description = preg_match('/<Description>(.*)<\\/Description>/', $response[0], $regs);
             $description = $regs[1];
             return array('error' => $number . ' - ' . $description);
         } else {
             $body = $response[0];
             $services = array();
             while (true) {
                 if ($start = strpos($body, '<Service ID=')) {
                     $body = substr($body, $start);
                     $end = strpos($body, '</Service>');
                     $services[] = substr($body, 0, $end + 10);
                     $body = substr($body, $end + 9);
                 } else {
                     break;
                 }
             }
             $size = sizeof($services);
             for ($i = 0, $n = $size; $i < $n; $i++) {
                 if (strpos($services[$i], '<Postage>')) {
                     $service = preg_match('/<SvcDescription>(.*)<\\/SvcDescription>/', $services[$i], $regs);
                     $service = $regs[1];
                     $postage = preg_match('/<Postage>(.*)<\\/Postage>/', $services[$i], $regs);
                     $postage = $regs[1];
                     if (isset($this->service) && $service != $this->service) {
                         continue;
                     }
                     $rates[] = array($service => $postage);
                 }
             }
         }
     }
     return sizeof($rates) > 0 ? $rates : false;
 }
Esempio n. 30
0
function removeTask()
{
    $isOk = new InputBoolean();
    $isOk = Interop::Confirm("Do you want to delete this task ?");
    if ($isOk == true) {
        //Make JSON request
        $urlDelete = "http://demo.kikapptools.com/taskManager/crud/deleteTask.php?action=delete&taskID=" . $id;
        $httpClient = new httpClient();
        $result = $httpClient->Execute('GET', $urlDelete);
        //Cast response data type
        $sdtError = array("response" => DataType::Character(100));
        Data::FromJson($sdtError, $result);
        $rsValue = new InputText(100);
        $rsValue = $sdtError['response'];
        //returns to the app home page.
        AndroidAction::GoHome();
    }
}