Ejemplo n.º 1
0
 public static function paczkomatUżytkownika($login)
 {
     $res = inpost_find_customer($login);
     if (isset($res['preferedBoxMachineName']) && $res['preferedBoxMachineName'] != "") {
         $ret = array("result" => "ok", "glowny" => "", "alternatywny" => "");
         $ret['glowny'] = $res['preferedBoxMachineName'];
         if (isset($res['alternativeBoxMachineName']) && $res['alternativeBoxMachineName'] != "") {
             $ret['alternatywny'] = $res['alternativeBoxMachineName'];
         }
         return $ret;
     } else {
         return array("result" => "error", "message" => $res['error']['message']);
     }
 }
Ejemplo n.º 2
0
function inpost_machines_dropdown($param)
{
    global $inpost_api_url;
    $machines_all = inpost_get_machine_list();
    $machines_with_names_as_keys = array();
    if (!isset($param['paymentavailable'])) {
        $param['paymentavailable'] = 0;
    }
    if (count($machines_all)) {
        foreach ($machines_all as $id => $machine) {
            if ($param['paymentavailable'] && $machine['paymentavailable'] || !$param['paymentavailable']) {
                $machines = $machines_with_names_as_keys[$machine['name']] = $machine;
            }
        }
    }
    if (isset($param['email'])) {
        $client = inpost_find_customer($param['email']);
        if (isset($client['error'])) {
            return -1;
        }
    }
    $result = "";
    $result .= "<select ";
    if (isset($param['class'])) {
        $result .= " class=\"" . $param['class'] . "\"";
    }
    if (isset($param['name'])) {
        $result .= " name=\"" . $param['name'] . "\"";
    }
    $result .= ">";
    if (isset($param['email'])) {
        // paczkomat domyślny
        if (isset($client['preferedBoxMachineName']) && array_key_exists($client['preferedBoxMachineName'], $machines_with_names_as_keys)) {
            $result .= "<option disabled>Paczkomat domyślny</option>";
            $result .= "<option value=\"" . $client['preferedBoxMachineName'] . "\"";
            if (isset($param['email']) and !isset($param['selected'])) {
                $result .= " selected=\"selected\"";
                unset($param['selected']);
            }
            $result .= ">" . $machines_with_names_as_keys[$client['preferedBoxMachineName']]['name'] . " " . $machines_with_names_as_keys[$client['preferedBoxMachineName']]['street'] . " " . $machines_with_names_as_keys[$client['preferedBoxMachineName']]['buildingnumber'] . ", " . $machines_with_names_as_keys[$client['preferedBoxMachineName']]['postcode'] . " " . $machines_with_names_as_keys[$client['preferedBoxMachineName']]['town'];
            if (isset($param['paymentavailable_suffix'])) {
                $result .= $param['paymentavailable_suffix'];
            }
            $result .= "</option>";
        }
        //paczkomat alternatywny
        if ($client['alternativeBoxMachineName'] && array_key_exists($client['alternativeBoxMachineName'], $machines_with_names_as_keys)) {
            $result .= "<option disabled>Paczkomat alternatywny</option>";
            $result .= "<option value=\"" . $client['alternativeBoxMachineName'] . "\"";
            if (isset($param['selected']) and $param['selected'] == $client['alternativeBoxMachineName']) {
                $result .= " selected=\"selected\"";
                unset($param['selected']);
            }
            $result .= ">" . $machines_with_names_as_keys[$client['alternativeBoxMachineName']]['name'] . " " . $machines_with_names_as_keys[$client['alternativeBoxMachineName']]['street'] . " " . $machines_with_names_as_keys[$client['alternativeBoxMachineName']]['buildingnumber'] . ", " . $machines_with_names_as_keys[$client['alternativeBoxMachineName']]['postcode'] . " " . $machines_with_names_as_keys[$client['alternativeBoxMachineName']]['town'] . "</option>";
        }
    }
    //paczkomaty w pobliżu kodu
    if (isset($param['postcode'])) {
        if (!isset($paymentavailable)) {
            $paymentavailable = '';
        }
        $machines = inpost_find_nearest_machines($param['postcode'], $paymentavailable ? 't' : '');
        if (!empty($machines)) {
            $result .= "<option disabled>Paczkomaty najbliżej kodu " . $param['postcode'] . "</option>";
            foreach ($machines as $machine) {
                $result .= "<option value=\"" . $machine['name'] . "\"";
                if (isset($param['selected'])) {
                    if ($param['selected'] == $machine['name']) {
                        $result .= " selected=\"selected\"";
                        unset($param['selected']);
                    }
                }
                $result .= ">" . $machine['name'] . " " . $machine['street'] . " " . $machine['buildingnumber'] . ", " . $machine['postcode'] . " " . $machine['town'] . "</option>";
            }
        }
    }
    //wszystkie paczkomaty
    if (!empty($machines_with_names_as_keys)) {
        $result .= "<option disabled>Wszytkie paczkomaty</option>";
        foreach ($machines_with_names_as_keys as $machine) {
            $result .= "<option value=\"" . $machine['name'] . "\"";
            if (isset($param['selected'])) {
                if ($param['selected'] == $machine['name']) {
                    $result .= " selected=\"selected\"";
                    unset($param['selected']);
                }
            }
            $result .= ">" . $machine['name'] . " " . $machine['street'] . " " . $machine['buildingnumber'] . ", " . $machine['postcode'] . " " . $machine['town'] . "</option>";
        }
    }
    $result .= "</select>";
    return $result;
}