Ejemplo n.º 1
0
 /**
  * execute the controller. Compile and output view if there are any.
  *
  * @return void
  */
 public function execute()
 {
     try {
         require sprintf("%s/%s/crud/%s.php", SERVICE, $this->service, $this->action);
         if (!$this->whenDone) {
             if (AJAX_MODE) {
                 die('OK');
             } else {
                 require LIBRARY . '/view/queryOK.phtml';
             }
         } else {
             http_response($this->whenDone[0], $this->whenDone[1]);
         }
     } catch (CRUDException $e) {
         throw $e;
     }
 }
Ejemplo n.º 2
0
function addItem()
{
    // Get information.
    $title = $_POST['title'];
    $description = $_POST['description'];
    $genre = $_POST['genre'];
    $publisher = $_POST['publisher'];
    $publish_month = $_POST['publish_month'];
    $publish_year = $_POST['publish_year'];
    $image_url = $_POST['image_url'];
    $price = $_POST['price'];
    echo $price;
    // If valid, continue.
    if (true) {
        $item_id = _addItem($title, $description, $genre, $publisher, $publish_month, $publish_year, $image_url, $price);
        if ($item_id > 0) {
            echo $item_id;
            http_response(200);
        } else {
            http_response(210);
        }
    }
}
Ejemplo n.º 3
0
function _changePassword($id, $password)
{
    $dbh = ConnectToDB();
    $sql = "UPDATE login_info SET password = ? WHERE id = ?";
    $stmt = $dbh->prepare($sql);
    $stmt->execute(array($password, $id));
    http_response(200);
    return;
}
Ejemplo n.º 4
0
function getUrlRespHtml_fsockopen($url)
{
    printAutoNewline("input url=" . $url);
    $respHtml = "";
    //resource fsockopen ( string $hostname [, int $port = -1 [, int &$errno [, string &$errstr [, float $timeout = ini_get("default_socket_timeout") ]]]] )
    // $testHostname = "www.yell.com";
    // $fp = fsockopen($testHostname, 80, $errno, $errstr, 30);
    // if (!$fp) {
    // echo "$errstr ($errno)<br />\n";
    // } else {
    // $getRequest = "GET / HTTP/1.1\r\n";
    // $getRequest .= "Host: ".$testHostname."\r\n";
    // $getRequest .= "Connection: Close\r\n\r\n";
    // fwrite($fp, $getRequest);
    // while (!feof($fp)) {
    // $curRespHtml = fgets($fp, 128);
    // printAutoNewline($curRespHtml);
    // $respHtml += $curRespHtml;
    // }
    // fclose($fp);
    // }
    //printAutoNewline($respHtml);
    http_response($url, '200', 3);
    // returns true if the response takes less than 3 seconds and the response code is 200
    return $respHtml;
}
Ejemplo n.º 5
0
function addCreditCardCheckout()
{
    $id = isset($_POST['id']) ? $_POST['id'] : -1;
    $password = isset($_POST['password']) ? $_POST['password'] : '******';
    $card_first_name = $_POST['card_first_name'];
    $card_middle_initial = $_POST['card_middle_initial'];
    $card_last_name = $_POST['card_last_name'];
    $card_type = $_POST['card_type'];
    $card_number = $_POST['card_number'];
    $card_expr_month = $_POST['card_expr_month'];
    $card_expr_year = $_POST['card_expr_year'];
    $card_sec_code = $_POST['card_sec_code'];
    if (verifyAccount($id, $password)) {
        // new address
        _addCreditCard($card_first_name, $card_middle_initial, $card_last_name, $card_type, $card_number, $card_expr_month, $card_expr_year, $card_sec_code);
        _addCustomerCard($id, $card_number);
        $card = _getCreditCard($card_number);
        echo json_encode($card);
        http_response(200);
    } else {
        http_response(200);
        _addCreditCard($card_first_name, $card_middle_initial, $card_last_name, $card_type, $card_number, $card_expr_month, $card_expr_year, $card_sec_code);
        $card = _getCreditCard($card_number);
        echo json_encode($card);
    }
}
Ejemplo n.º 6
0
function http_error400($body)
{
    return http_response(400, 'Bad request', "ERROR: {$body}");
}
Ejemplo n.º 7
0
function addAddress()
{
    $id = isset($_POST['id']) ? $_POST['id'] : -1;
    $password = isset($_POST['password']) ? $_POST['password'] : '******';
    $street = $_POST['addr_street'];
    $city = $_POST['addr_city'];
    $state = $_POST['addr_state'];
    $country = $_POST['addr_country'];
    $zip = $_POST['addr_zip_code'];
    $addr_id = $_POST['addr_id'];
    if (verifyAccount($id, $password)) {
        // new address
        if ($addr_id == -1) {
            $addr_id = _addAddress($street, $city, $state, $country, $zip);
            //echo $addr_id;
            _addCustomerAddress($id, $addr_id);
        } else {
            _editAddress($addr_id, $street, $city, $state, $country, $zip);
        }
        $address = _getAddress($addr_id);
        if (is_array($address)) {
            $address["id"] = $addr_id;
        }
        echo json_encode($address);
        http_response(200);
    } else {
        http_response(200);
        $addr_id = _addAddress($street, $city, $state, $country, $zip);
        $address = _getAddress($addr_id);
        if (is_array($address)) {
            $address["id"] = $addr_id;
        }
        echo json_encode($address);
    }
}