3 require_once('../include/db.php');
5 header('Content-type: application/json');
7 function exit_with_error($status, $details = array()) {
8 $details['status'] = $status;
9 echo json_encode($details);
13 function exit_with_success($details = array()) {
14 $details['status'] = 'OK';
15 echo json_encode($details);
22 exit_with_error('DatabaseConnectionError');
26 function camel_case_words_separated_by_underscore($name) {
27 return implode('', array_map('ucfirst', explode('_', $name)));
30 function require_format($key, $value, $pattern) {
31 if (!preg_match($pattern, $value))
32 exit_with_error('Invalid' . camel_case_words_separated_by_underscore($key), array('value' => $value));
35 function require_existence_of($array, $list_of_arguments, $prefix = '') {
38 foreach ($list_of_arguments as $key => $pattern) {
39 $name = camel_case_words_separated_by_underscore($prefix . $key);
40 if (!array_key_exists($key, $array))
41 exit_with_error($name . 'NotSpecified');
42 require_format($name, $array[$key], $pattern);