Example #1
0
        $location = $_POST['location'] or die('ubicació no informada');
        $observations = isset($_POST['observations']) ? $_POST['observations'] : '';
        $comments = isset($_POST['comments']) ? $_POST['comments'] : '';
        $group = array('id' => $id, 'name' => $name, 'age' => $age, 'date_start' => $date_start, 'date_end' => $date_end, 'location' => $location, 'comments' => $comments, 'observations' => $observations);
}
/*
echo 'action: '.$action;
echo '$group';
print_r($group);
*/
$c = new Connection();
$conn = $c->getConnection();
$groupDAO = new GroupDAO($conn);
switch ($action) {
    case 'new':
        $insert_id = $groupDAO->create($group);
        break;
    case 'update':
        $groupDAO->update($group);
        break;
    case 'delete':
        //echo 'delete dao'.$id; exit;
        $groupDAO->delete($id);
        break;
}
if ($isAjax) {
    echo json_encode($response);
    exit;
} else {
    header("Location: " . $siteUrl . "/group_list.php?r=" . mt_rand(0, 9999999));
}
Example #2
0
    echo json_encode($groupDAO->selectById($id), JSON_NUMERIC_CHECK);
    exit;
});
$app->get('/group/:groupname/?', authorize(), function ($groupname) use($groupDAO) {
    header("Content-Type: application/json");
    echo json_encode($groupDAO->selectByGroupName($groupname), JSON_NUMERIC_CHECK);
    exit;
});
$app->post('/group/?', function () use($app, $groupDAO) {
    header("Content-Type: application/json");
    $post = $app->request->post();
    if (empty($post)) {
        $post = (array) json_decode($app->request()->getBody());
    }
    echo json_encode($groupDAO->insert($post), JSON_NUMERIC_CHECK);
    exit;
});
$app->delete('/group/:id/?', authorize(), function () use($groupDAO) {
    header("Content-Type: application/json");
    echo json_encode($groupDAO->delete());
    exit;
});
$app->put('/group/:id/?', authorize(), function ($id) use($app, $groupDAO) {
    header("Content-Type: application/json");
    $post = $app->request->post();
    if (empty($post)) {
        $post = (array) json_decode($app->request()->getBody());
    }
    echo json_encode($groupDAO->updateGroup($id, $post), JSON_NUMERIC_CHECK);
    exit;
});