}
function writeCustomer()
{
    //decode json object into associate array to extract email to use as filename
    $json = file_get_contents("php://input");
    $filedata = json_decode($json, true);
    $filename = '../customers/' . $filedata['email'] . ".json";
    //write json to file
    if (file_put_contents($filename, $json)) {
        http_response_code(200);
    } else {
        http_response_code(400);
    }
    return true;
}
//handle the request based on the method
$requestType = $_SERVER['REQUEST_METHOD'];
switch ($requestType) {
    case 'GET':
        getCustomers();
        break;
    case 'DELETE':
        deleteCustomer();
        break;
    case 'PUT':
        writeCustomer();
        break;
    default:
        echo "Error, request method {$requestType} is not supported";
        break;
}
Beispiel #2
0
<?php

include 'common_functions.php';
echo "All Customers\n";
echo json_encode(getCustomers());
echo PHP_EOL;
echo "Jason Flores\n";
echo json_encode(getOrdersByCustomer(3));
echo PHP_EOL;
echo "Customer SELECT\n";
echo buildCustomerSelect();
echo PHP_EOL;
Beispiel #3
0
<html>
<?php 
require_once './includes/functions.php';
include './includes/config.php';
// Die if id not present
if (!isset($_GET['id'])) {
    die('Missing customer ID');
}
// page meta data
$title = "%s - " . $title;
// Site title
$pageTitle = "%s | %s";
// This page title
// retrieve customers array and the customer id from the GET page params
$customers = getCustomers();
// All customers array
$customerId = htmlspecialchars($_GET['id']);
// Current customer ID
$customer = array();
// Current customer array
// Loop - http://php.net/manual/en/control-structures.foreach.php
// Find matching customer id, assign to $customer variable
// print out first to see the structure of our array - uncomment below
// echo '<pre>'; print_r($customers);
foreach ($customers as $value) {
    if ($value['id'] == $customerId) {
        $customer = $value;
        break;
    }
}
// If $customer variable is empty, die with a propper message
Beispiel #4
0
//first thing before we perform anything is to make sure our user is actually in the database
if (!$userid || $usertoken == "") {
    // no id is bound to this token
    //as a non logged in user, our only tasks can be login and register
    if ($task != "login" && $task != "register" && $task != "resetDo" && $task != "resetInit") {
        $task = "";
        $data = array("success" => false, "message" => "No userid or token");
        echo json_encode($data);
        exit;
    }
}
#######################################################################################################################
#########################################################TASKS#########################################################
#######################################################################################################################
if ($task == "getCustomers") {
    echo getCustomers($userid);
}
//task getCustomers
if ($task == "addCustomer") {
    $customername = $request->customername;
    echo addCustomer($userid, $customername);
}
//task addCustomer
if ($task == "addService") {
    $servicename = $request->servicename;
    $hourlyrate = $request->hourlyrate;
    echo addService($userid, $servicename, $hourlyrate);
}
//task addService
if ($task == "insertNewTime") {
    $customerid = $request->customerid;
Beispiel #5
0
function testPostUpdateCustomer()
{
    echo "Starting test: testPostUpdateCustomer" . "<br />";
    echo "-------------------------------------------------------------------------------------<br />";
    echo "POST update customer in XML format:" . "<br />";
    $xml = getCustomers("xml");
    $customer = $xml->Customer[0];
    $customer->Notes = "Customer updated via xml POST";
    echo "Input data:" . "<br />";
    echo htmlentities($customer->asXML());
    echo "<br />";
    echo "Input id:" . "<br />";
    echo $customer->Guid;
    echo "<br />";
    echo "<br />";
    $xmlPost = postCustomer($customer, "xml", $customer->Guid);
    echo "Output data:" . "<br />";
    echo htmlentities($xmlPost->asXML());
    /*
    echo "-------------------------------------------------------------------------------------<br />";
    echo "POST update customer in JSON format:" . "<br />";
    
    $json = getCustomers("json");
    $customer = $json->Items[0];
    
    $customer->Notes = "Customer updated via json POST";
    echo "Input data:" . "<br />";
    echo json_encode($customer);
    $jsonPost = postCustomer($customer, "json");
    echo "Output data:" . "<br />";
    echo json_encode($jsonPost);
    */
    echo "-------------------------------------------------------------------------------------<br />";
    echo "End of test: testPostUpdateCustomer" . "<br />";
}
 * The purpose of this dude is to save us time when creating test orders
 * The idea is to have random customer data and an order with a number of products in the cart (between 1 and 3).
 *
 * Things I made use of:
 *  - http://inchoo.net/ecommerce/magento/programming-magento/programatically-create-customer-and-order-in-magento-with-full-blown-one-page-checkout-process-under-the-hood/
 *  - http://pravams.com/2011/11/11/magento-create-order-programmatically/
 *  - http://fakester.biz/
 *
 */
// And we're away
require_once "../app/Mage.php";
Mage::app();
// How many orders are we creating
$num_orders = (int) $_GET["orders"];
// Get some random customer information
$customers = getCustomers($num_orders);
// Create a few orders
for ($i = 1; $i <= $num_orders; $i++) {
    // Get random products
    $products = getProducts();
    // Get a customer
    $customer = getCustomer(array_pop($customers));
    // Order some mofo products for some mofo customer
    $order = createOrder($products, $customer);
    printf("Created order %s\n", $order->getIncrementId());
}
/*
 * Get random customer information from fakester.biz
 *
 * @return array
 */
<?php

session_start();
require_once 'Adapter.class.php';
require_once 'functions.inc.php';
$go = $_POST['go'];
switch ($go) {
    case 'login':
        print loginUser($_POST['un'], $_POST['p']);
        break;
    case 'logout':
        print logOutUser();
        break;
    case 'getcustomers':
        print getCustomers($_POST);
        break;
    case 'addcall':
        print addCall($_POST);
        break;
    case 'getcalls':
        print getCalls();
        break;
    case 'addcustomer':
        print addcustomer($_POST);
        break;
}
      <?php 
echo $s_customer_dashboard;
?>
      <button type="button" class="btn btn-info" data-toggle="modal" data-target="#addCustomerModal">
        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
        <?php 
echo $s_add_customer;
?>
      </button>
    </h1>
    <?php 
if (isset($_GET['customersSearch'])) {
    $customersSearch = $_GET['customersSearch'];
    $customers = getCustomers($conn, 'all', $customersSearch);
} else {
    $customers = getCustomers($conn);
}
function makeCustomerEditButton($customer)
{
    $button = "<button type='button' class='btn btn-warning' ";
    $button .= "data-toggle='modal' data-target='#editCustomerModal' ";
    $button .= "data-id='{$customer['id']}' ";
    $button .= "data-firstname='{$customer['firstname']}' ";
    $button .= "data-lastname='{$customer['lastname']}' ";
    $button .= "data-tel='{$customer['tel']}' ";
    $button .= "data-line='{$customer['line_id']}' ";
    $button .= "data-email='{$customer['email']}' ";
    $button .= "data-address='{$customer['address']}' >";
    $button .= "<span class='glyphicon glyphicon-pencil' aria-hidden='true'></span>";
    $button .= "</button>";
    return $button;
Beispiel #9
0
    $sort = 'username';
}
if (isset($_GET['order'])) {
    $order = $_GET['order'];
} else {
    $order = 'ASC';
}
if (isset($_GET['page'])) {
    $page = $_GET['page'];
} else {
    $page = 1;
}
$numrows = 20;
$data = array('sort' => $sort, 'order' => $order, 'start' => ($page - 1) * $numrows, 'limit' => $numrows);
$total_customer = getTotalCustomers();
$customers = getCustomers($data);
$pagination = new Pagination();
$pagination->total = $total_customer;
$pagination->page = $page;
$pagination->limit = $numrows;
$pagination->url = "customer/page{page}.html";
$pagination = $pagination->render();
$url = '';
if ($order == 'ASC') {
    $url .= '/DESC';
} else {
    $url .= '/ASC';
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['selected'])) {
    foreach ($_POST['selected'] as $customer_id) {
        $delete_query = deleteCustomer($customer_id);
Beispiel #10
0
<?php

include 'common_functions.php';
$custId = isset($_GET['custId']) ? (int) $_GET['custId'] : 0;
$orders = getOrdersByCustomer($custId);
$cust = $custId ? getCustomers(['id' => $custId])[0] : array();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Order History</title>
</head>
<body>
	<form action="M8ex4.php" method="get">
	<?php 
echo buildCustomerSelect($custId);
?>
	<input type="submit" />
	</form>
    <?php 
if ($cust) {
    ?>
        <h1><?php 
    echo $cust['firstname'] . ' ' . $cust['lastname'];
    ?>
</h1>
        <table>
            <thead>
                <tr>
                    <th>Date</th>
/**
 * 
 * @param int $custId
 * @return string HTML $output
 */
function buildCustomerSelect($custId = 0)
{
    $list = getCustomers();
    $select = '<select name="custId">';
    foreach ($list as $customer) {
        if ($custId == $customer['id']) {
            $sel = ' selected';
        } else {
            $sel = '';
        }
        $select .= '<option value="' . $customer['id'] . $sel . '">' . $customer['firstname'] . ' ' . $customer['lastname'] . '</option>';
    }
    $select .= '</select>';
    return $select;
}