Created
April 23, 2012 17:57
-
-
Save jpetto/2472710 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('../app/app.db.php'); | |
require_once('../lib/class.db.php'); | |
// array to hold results | |
$results = array(); | |
// make sure we have an action | |
if (array_key_exists('action', $_REQUEST)) : | |
$actions = explode('|', strtolower($_REQUEST['action'])); | |
$type = strtolower($_SERVER['REQUEST_METHOD']); | |
if (count($actions) > 0) : | |
// route based on action, then on request type | |
if (in_array('jumbo', $actions)) : | |
if ($type == 'get') : | |
$sql = "SELECT jumbo_ipad_id, jumbo_company_id FROM pritzker"; | |
$q = new DB($sql); | |
$results['jumbo'] = $q->get_row(); | |
elseif ($type == 'post') : | |
$jumbo_ipad_id = $_POST['jumbo_ipad_id']; | |
$jumbo_company_id = $_POST['jumbo_company_id']; | |
$sql = " | |
UPDATE pritzker | |
SET | |
jumbo_company_id = '" . DB::sanitize($jumbo_company_id) . "', | |
jumbo_ipad_id = '" . DB::sanitize($jumbo_ipad_id) . "'"; | |
$q = new DB($sql); | |
$results['jumbo'] = array('updated' => $q->affected_rows); | |
endif; | |
endif; | |
if (in_array('ipad_state', $actions)) : | |
if ($type == 'get') : | |
$sql = "SELECT ipad_state FROM pritzker"; | |
$q = new DB($sql); | |
$results['ipad_state'] = $q->get_row(); | |
elseif ($type == 'post') : | |
$ipad_state = $_POST['ipad_state']; | |
$sql = " | |
UPDATE pritzker | |
SET | |
ipad_state = '" . DB::sanitize($ipad_state) . "'"; | |
$q = new DB($sql); | |
$results['ipad_state'] = array('updated' => $q->affected_rows); | |
endif; | |
endif; | |
if (in_array('face_detected', $actions)) : | |
if ($type == 'get') : | |
$sql = " | |
SELECT | |
face_detected_1, | |
face_detected_2, | |
face_detected_3, | |
face_detected_4, | |
face_detected_5, | |
face_detected_6, | |
face_detected_7, | |
face_detected_8, | |
face_detected_9, | |
face_detected_10, | |
face_detected_11, | |
face_detected_12, | |
face_detected_13, | |
face_detected_14, | |
face_detected_15, | |
face_detected_16, | |
face_detected_17, | |
face_detected_18, | |
face_detected_19, | |
face_detected_20 | |
FROM pritzker"; | |
$q = new DB($sql); | |
$row = $q->get_row(); | |
$results['face_detected'] = array(); | |
foreach ($row as $key => $val) : | |
$results['face_detected'][] = $val; | |
endforeach; | |
elseif ($type == 'post') : | |
$face_detected = $_POST['face_detected']; | |
$ipad_id = $_POST['ipad_id']; | |
$sql = " | |
UPDATE pritzker | |
SET | |
face_detected_" . $ipad_id . " = '" . DB::sanitize($face_detected) . "'"; | |
$q = new DB($sql); | |
$results['face_detected'] = array('updated' => $q->affected_rows); | |
endif; | |
endif; | |
if (in_array('user_interacted', $actions)) : | |
if ($type == 'get') : | |
$sql = " | |
SELECT | |
user_interacted_1, | |
user_interacted_2, | |
user_interacted_3, | |
user_interacted_4, | |
user_interacted_5, | |
user_interacted_6, | |
user_interacted_7, | |
user_interacted_8, | |
user_interacted_9, | |
user_interacted_10, | |
user_interacted_11, | |
user_interacted_12, | |
user_interacted_13, | |
user_interacted_14, | |
user_interacted_15, | |
user_interacted_16, | |
user_interacted_17, | |
user_interacted_18, | |
user_interacted_19, | |
user_interacted_20 | |
FROM pritzker"; | |
$q = new DB($sql); | |
$row = $q->get_row(); | |
$results['user_interacted'] = array(); | |
foreach ($row as $key => $val) : | |
$results['user_interacted'][] = $val; | |
endforeach; | |
elseif ($type == 'post') : | |
$user_interacted = $_POST['user_interacted']; | |
$ipad_id = $_POST['ipad_id']; | |
$sql = " | |
UPDATE pritzker | |
SET | |
user_interacted_" . $ipad_id . " = '" . DB::sanitize($user_interacted) . "'"; | |
$q = new DB($sql); | |
$results['user_interacted'] = array('updated' => $q->affected_rows); | |
endif; | |
endif; | |
if (in_array('update_ipad', $actions)) : | |
if ($type == 'get') : | |
if (array_key_exists('ipad_id', $_REQUEST) && $_REQUEST['ipad_id'] != '') : | |
$ipad_id = $_REQUEST['ipad_id']; | |
$sql = "SELECT update_ipad_" . $ipad_id . " FROM pritzker"; | |
else : | |
$sql = " | |
SELECT | |
update_ipad_1, | |
update_ipad_2, | |
update_ipad_3, | |
update_ipad_4, | |
update_ipad_5, | |
update_ipad_6, | |
update_ipad_7, | |
update_ipad_8, | |
update_ipad_9, | |
update_ipad_10, | |
update_ipad_11, | |
update_ipad_12, | |
update_ipad_13, | |
update_ipad_14, | |
update_ipad_15, | |
update_ipad_16, | |
update_ipad_17, | |
update_ipad_18, | |
update_ipad_19, | |
update_ipad_20 | |
FROM pritzker"; | |
endif; | |
$q = new DB($sql); | |
$results['update_ipad'] = $q->get_row(); | |
elseif ($type == 'post') : | |
$update_ipad = $_POST['update_ipad']; | |
if (array_key_exists('ipad_id', $_POST) && $_POST['ipad_id'] != '') : | |
$ipad_id = $_POST['ipad_id']; | |
$sql = " | |
UPDATE pritzker | |
SET | |
update_ipad_" . $ipad_id . " = '" . DB::sanitize($update_ipad) . "'"; | |
else : | |
$sql = " | |
UPDATE pritzker | |
SET | |
update_ipad_1 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_2 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_3 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_4 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_5 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_6 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_7 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_8 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_9 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_10 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_11 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_12 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_13 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_14 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_15 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_16 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_17 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_18 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_19 = '" . DB::sanitize($update_ipad) . "', | |
update_ipad_20 = '" . DB::sanitize($update_ipad) . "'"; | |
endif; | |
$q = new DB($sql); | |
$results['update_ipad'] = array('updated' => $q->affected_rows); | |
endif; | |
endif; | |
endif; // make sure we have actions | |
endif; // make sure action exists in $_REQUEST | |
// print out json formatted data | |
echo json_encode($results); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment