//***********************************************************
//					Listener
//***********************************************************
if (isset($_POST['action'])) {
    $action = $_POST['action'];
} else {
    $action = "";
}
if ($action == "getResources") {
    $resources = ct_getResources();
    $courses = db_getAllCourses();
    $response = array("resources" => $resources, "courses" => $courses);
    echo json_encode($response);
} else {
    if ($action == "getCourses") {
        $response = db_getAllCourses();
        echo json_encode($response);
    } else {
        if ($action == "getCreditTypes") {
            $response = ct_getCreditTypes();
            echo json_encode($response);
        } else {
            if ($action == "getCreditType") {
                $id = isset($_POST['id']) ? $_POST['id'] : "";
                $response = ct_getCreditType($id);
                echo json_encode($response);
            } else {
                if ($action == "addCreditType") {
                    $name = isset($_POST['name']) ? $_POST['name'] : "";
                    $resource = isset($_POST['resource']) ? $_POST['resource'] : "";
                    $policyId = isset($_POST['policyId']) ? $_POST['policyId'] : "";
function ct_getCourses()
{
    return db_getAllCourses();
}
     }
 } else {
     if ($action == "getHistoricReportByUserAndCreditType") {
         session_start();
         $userId = $_SESSION["userid"];
         $timeZoneId = db_getUserTimeZone($userId)->data;
         $quotaSummary = null;
         if (isset($_POST['userId']) && isset($_POST['creditTypeId'])) {
             $quotaSummary = rm_getHistoricQuotaSummaryByUserAndCreditType($_POST['userId'], $_POST['creditTypeId'], $timeZoneId);
         } else {
             $quotaSummary = rm_getHistoricQuotaSummaryByUserAndCreditType($_POST['userId'], $_POST['creditTypeId'], $timeZoneId);
         }
         echo json_encode($quotaSummary);
     } else {
         if ($action == "getAllCourses") {
             $courses = db_getAllCourses();
             $response = array("courses" => $courses);
             echo json_encode($response);
         } else {
             if ($action == "getCoursesByUser") {
                 if (isset($_POST['userId'])) {
                     $courses = db_getCoursesByUser($_POST['userId']);
                     $response = array("courses" => $courses);
                     echo json_encode($response);
                 }
             } else {
                 if ($action == "getAllUsers") {
                     $users = db_getAllUsers();
                     $response = array("users" => $users);
                     echo json_encode($response);
                 }