Пример #1
0
require_once 'includes/SI_TaskActivity.php';
log_message("JSON API Called: " . $request->action);
log_message(print_r($params, true));
$action_map = array('authenticate' => array('SureInvoice', 'authenticateUser'), 'getCompanies' => array('SI_Company', 'getActiveCompanies'), 'stayAlive' => array('SureInvoice', 'stayAlive'), 'getUserSetting' => array('SureInvoice', 'getUserSetting'), 'saveUserSetting' => array('SureInvoice', 'saveUserSetting'), 'getRecentTime' => array('SureInvoice', 'getRecentTime'), 'getTimerData' => array('SureInvoice', 'getTimerData'), 'pauseTimer' => array('SureInvoice', 'pauseTimer'), 'startTimer' => array('SureInvoice', 'startTimer'), 'addTimer' => array('SureInvoice', 'addTimer'), 'deleteTimer' => array('SureInvoice', 'deleteTimer'), 'getDefaultItemCode' => array('SI_Task', 'getDefaultItemCode'), 'getActivityDetailHTML' => array('SI_TaskActivity', 'getActivityDetailHTML'), 'importGetUsers' => array('SureInvoice', 'importGetUsers'), 'importGetTasks' => array('SureInvoice', 'importGetTasks'), 'importGetItemCodes' => array('SureInvoice', 'importGetItemCodes'));
if (!isLoggedIn() && $request->action != 'authenticate') {
    echo json_encode(array('error' => 'User is not logged in!'));
    exit;
}
$output = array();
switch ($request->action) {
    case 'findTasks':
        $task = new SI_Task();
        $tasks = array();
        if (!isset($params[0]) || empty($params[0])) {
            if (isset($_GET['query'])) {
                $tasks = $task->findTasks($_GET['query']);
            } else {
                $output['error'] = 'Invalid parameters for findTasks action';
                break;
            }
        } else {
            $tasks = $task->findTasks($params[0]);
        }
        if ($tasks === false) {
            $output['error'] = $task->getLastError();
        } else {
            $output['tasks'] = $tasks;
        }
        break;
    case 'addTaskActivity':
        $project = new SI_Project();