public static function subject($type, $data)
 {
     require_once 'subject.class.php';
     $class = new Subject();
     $status = false;
     $class->setData($data);
     switch ($type) {
         case 'add':
             $status = $class->add();
             break;
         case 'update':
             $status = $class->update();
             break;
         case 'delete':
             $status = $class->delete();
             break;
         case 'getsingle':
             $status = $class->getsingle();
             break;
         case 'getpage':
             $status = $class->getpage();
             break;
         case 'search':
             $status = $class->search();
             break;
         default:
             break;
     }
     if ($status) {
         wp_send_json_success($status);
     } else {
         wp_send_json_error($class->error);
     }
 }
Пример #2
0
function showSubject()
{
    global $connector;
    $subject = new Subject();
    $subject->setConnector($connector);
    if (isset($_POST['operation'])) {
        list($operation, $params) = explode("#", $_POST['operation']);
        switch ($operation) {
            case 'saveChanges':
                $subject->storeFormValues($_POST);
                $error_msg = $subject->insert();
                if ($error_msg) {
                    $result['edit'] = $subject;
                }
                break;
            case 'delete':
                $error_msg = $subject->delete($params);
                break;
            case 'edit':
                $result['edit'] = $subject->getById($params);
                break;
            case 'editChanges':
                $subject->storeFormValues($_POST);
                $error_msg = $subject->update();
                break;
            default:
                $error_msg = "Operazione non valida";
        }
        if ($error_msg != "") {
            $result["errorMessage"] = $error_msg;
        } elseif ($operation != 'edit') {
            $result["statusMessage"] = "Operazione completata!";
        }
    }
    if (isset($_POST['search'])) {
        $result["subjects"] = $subject->search($_POST['search']);
    } else {
        $result["subjects"] = $subject->getList();
    }
    $page = "subject.php";
    include_once BASE_PATH . "template.php";
}