public function sendRequest($method = null, $args = null, $postmethod = 'get', $tryagain = true) { try { $result = parent::sendRequest($method, $args, $postmethod); if ($tryagain && is_null($result)) { $result = parent::sendRequest($method, $args, $postmethod, false); } elseif (is_null($result)) { throw new CMSException("No response", $method, 8888, 'n/a'); } if (is_array($result) && isset($result['error']) && $result['error']) { throw new CMSException($result['error']['message'], $method, $result['error']['code'], $result['error']['field']); } } catch (CMSException $e) { } if (isset($result['response'])) { return $result['response']; } return $result; }
} // Flop the API if needed if (isset($_GET['api']) && $_GET['api'] == 'flop') { $_SESSION['api_mode'] = $_SESSION['api_mode'] == 'dev' ? 'production' : 'dev'; header('location:' . $_SERVER['HTTP_REFERER']); die; } d('MODE', $_SESSION['api_mode']); // Use the right API d('API_KEY', $_SESSION['api_mode'] == 'dev' ? 'bcppxparnj' : 'vnjjhwwtrp'); // i.wayne.edu // Include the API include_once ROOT . '/lib/phpcms/phpcms.php'; include_once ROOT . '/lib/functions.php'; // Initialize the API $c = new Phpcms(API_KEY, MODE); $c->debug = false; //$c->parser = 'raw'; //$c->sendRequest('api/information/version', 'get'); //Pre($c); // If trying to login if (isset($_POST['accessid']) && isset($_POST['password'])) { $login_credentials = array('accessid' => strtolower($_POST['accessid']), 'password' => $_POST['password']); $login_response = $c->sendRequest('api/user/auth', $login_credentials, 'post', true); Pre($login_response); // Store the session ID in the session if (isset($login_response['response']['auth']['sessionid'])) { $_SESSION['sessionid'] = $login_response['response']['auth']['sessionid']; // Get the users information $user_details = $c->sendRequest('api/user/info', array('accessid' => $_POST['accessid'])); // Save the basic information about this user