Esempio n. 1
0
<?php

include_once '../Model/exercise.php';
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
$method = $_SERVER['REQUEST_METHOD'];
$format = isset($_REQUEST['format']) ? $_REQUEST['format'] : 'web';
$view = null;
switch ($action . '_' . $method) {
    case 'create_GET':
        $model = Exercise::Blank();
        $view = "exercise/edit.php";
        break;
    case 'save_POST':
        $sub_action = empty($_REQUEST['Exercise_id']) ? 'Created_at' : 'Updated_at';
        $errors = Exercise::Validate($_REQUEST);
        if (!$errors) {
            $errors = Exercise::Save($_REQUEST);
        }
        if (!$errors) {
            if ($format == 'json') {
                header("Location: ?action=edit&format=json&id={$_REQUEST['Exercise_id']}");
            } else {
                header("Location: ?sub_action={$sub_action}&id={$_REQUEST['Exercise_id']}");
            }
            die;
        } else {
            //my_print($errors);
            $model = $_REQUEST;
            $view = "exercise/edit.php";
        }
        break;
Esempio n. 2
0
<?php

include_once '../Model/exercise.php';
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
$method = $_SERVER['REQUEST_METHOD'];
$format = isset($_REQUEST['format']) ? $_REQUEST['format'] : 'web';
$view = null;
switch ($action . '_' . $method) {
    case 'create_GET':
        $exercises = Exercise::Blank();
        $view = "exercises/edit.php";
        break;
    case 'save_POST':
        $sub_action = empty($_REQUEST['id']) ? 'created' : 'updated';
        $errors = Exercise::Validate($_REQUEST);
        if (!$errors) {
            $errors = Exercise::Save($_REQUEST);
        }
        if (!$errors) {
            if ($format == 'json') {
                header("Location: ?action=edit&format=json&id={$_REQUEST['id']}");
            } else {
                header("Location: ?sub_action={$sub_action}&id={$_REQUEST['id']}");
            }
            die;
        } else {
            $exercises = $_REQUEST;
            $view = "exercises/edit.php";
        }
        break;
    case 'edit_GET':