switch ($post['action']) {
     case "create":
         // Create array to pass to function
         $arg = array('title' => $post['title'], 'message' => $post['message'], 'create_date' => date("Y-m-d H:i:s"), 'start_date' => $post['start_date'], 'end_date' => $post['end_date']);
         // Insert record
         $result = addAnnouncement($arg);
         if ($result == FALSE) {
             // Error
             echo 'Database write unsuccessful';
         } else {
             header('Location: /announcements.php');
         }
         break;
     case "update":
         $arg = array('value' => $post['value'], 'title' => $post['title'], 'message' => $post['message'], 'start_date' => $post['start_date'], 'end_date' => $post['end_date']);
         $result = updateAnnouncement($arg);
         if ($result == FALSE) {
             return 'Announcement not updated!';
         } else {
             header('Location: /announcements.php');
         }
         break;
     case "delete":
         $result = deleteAnnouncement($post['value']);
         if ($result == FALSE) {
             return 'Announcement not deleted!';
         } else {
             header('Location: /announcements.php');
         }
         break;
     default:
Пример #2
0
function processAnnouncement($action, $id, $title, $body, $expiration, $active)
{
    if ($action == 'showoption') {
        $announcementOpt = announcementOption($id);
        echo $announcementOpt;
        return;
    }
    if ($action == 'show' || $action == 'add') {
        $announcementDetail = showAnnouncement($action, $id);
        echo json_encode(array('form' => $announcementDetail, 'request' => "showAnnouncement({$action}, {$id})"));
        return;
    }
    $show_id = updateAnnouncement($action, $id, $title, $body, $expiration, $active);
    if ($action == 'update' || $action == 'addnew') {
        $announcementDetail = showAnnouncement('show', $show_id);
        $announcementOpt = announcementOption($show_id);
        $rt = array('form' => $announcementDetail, 'Opt' => $announcementOpt, 'msg' => 'Announcement added/updated');
        echo json_encode($rt);
        return;
    }
    if ($action == 'delete') {
        if (isset($show_id)) {
            $rt['msg'] = $show_id;
            echo json_encode($rt);
            return;
        }
        $announcementOpt = announcementOption(0);
        $rt = array('form' => '', 'Opt' => $announcementOpt, 'msg' => 'Announcement deleted');
        echo json_encode($rt);
        return;
    }
}