function churchcal_deleteEvent($params, $source = null)
{
    $id = $params["id"];
    if (!churchcal_isAllowedToEditEvent($id)) {
        throw new CTNoPermission("AllowToEditEvent", "churchcal");
    }
    // BENACHRICHTIGE ANDERE MODULE
    if ($source == null || $source != "churchresource") {
        include_once CHURCHRESOURCE . '/churchresource_db.php';
        if ($source == null) {
            $source = "churchcal";
        }
        $params["cal_id"] = $params["id"];
        churchresource_deleteResourcesFromChurchCal($params, $source);
    }
    if ($source == null || $source != "churchservice") {
        include_once CHURCHSERVICE . '/churchservice_db.php';
        $cs_params = array_merge(array(), $params);
        $cs_params["cal_id"] = $params["id"];
        $cs_params["informDeleteEvent"] = 1;
        $cs_params["deleteCalEntry"] = 1;
        if ($source == null) {
            $source = "churchcal";
        }
        $db = db_query("select * from {cs_event} where cc_cal_id=:cal_id", array(":cal_id" => $cs_params["cal_id"]));
        foreach ($db as $cs) {
            $cs_params["id"] = $cs->id;
            churchservice_deleteEvent($cs_params, $source);
        }
    }
    db_query("delete from {cc_cal_except} where cal_id=:id", array(":id" => $id));
    db_query("delete from {cc_cal_add} where cal_id=:id", array(":id" => $id));
    db_query("delete from {cc_cal} where id=:id", array(":id" => $id));
}
 public function deleteEvent($params)
 {
     $this->checkPerm("edit events");
     return churchservice_deleteEvent($params);
 }
/**
 * Update existing event
 * if eventTemplate is given in $params get data from there, else use services
 *
 * @param array $params
 * @throws CTException
 */
function churchservice_updateEvent($params, $csevent)
{
    global $user;
    include_once CHURCHCAL . '/churchcal_db.php';
    // Delete action, e.g. when adding Exceptions to CalEvent
    if (isset($csevent["action"]) && $csevent["action"] == "delete") {
        churchservice_deleteEvent($csevent);
        return;
    }
    // update/insert cs_event
    $fields = array();
    if (isset($csevent["startdate"])) {
        $fields["startdate"] = $csevent["startdate"];
    }
    if (isset($csevent["valid_yn"])) {
        $fields["valid_yn"] = $csevent["valid_yn"];
    }
    if (isset($csevent["special"])) {
        $fields["special"] = $csevent["special"];
    }
    if (isset($csevent["admin"])) {
        $fields["admin"] = $csevent["admin"];
    }
    $event_id = $csevent["id"];
    db_update("cs_event")->fields($fields)->condition('id', $event_id, "=")->execute();
    if (!empty($params["services"])) {
        // update/insert eventservices
        $rm_services = array();
        $new_services = array();
        $dt = new datetime();
        $fields = array("event_id" => $event_id, "valid_yn" => 1, "modified_date" => $dt->format('Y-m-d H:i:s'), "modified_pid" => $user->id);
        foreach ($params["services"] as $key => $val) {
            $fields["service_id"] = $key;
            $fields["counter"] = null;
            $i = $val;
            while ($i > 0) {
                $fields["counter"] = $i--;
                db_insert("cs_eventservice")->fields($fields)->execute();
            }
        }
    }
}
示例#4
0
/**
 * delete cal event
 * @param array $params
 * @param string $source; default: null
 * @throws CTNoPermission
 */
function churchcal_deleteEvent($params, $source = null)
{
    global $user;
    $id = $params["id"];
    $logger = db_query("SELECT * FROM {cc_cal} WHERE id=:id", array(":id" => $params["id"]))->fetch();
    if (!$logger) {
        return;
    }
    if (!churchcal_isAllowedToEditEvent($id)) {
        throw new CTNoPermission("AllowToEditEvent", "churchcal");
    }
    // inform other modules
    if (!$source || $source != "churchresource") {
        include_once CHURCHRESOURCE . '/churchresource_db.php';
        if (!$source) {
            $source = "churchcal";
        }
        $params["cal_id"] = $params["id"];
        churchresource_deleteResourcesFromChurchCal($params, $source);
    }
    if (!$source || $source != "churchservice") {
        include_once CHURCHSERVICE . '/churchservice_db.php';
        $cs_params = array_merge(array(), $params);
        $cs_params["cal_id"] = $params["id"];
        $cs_params["informDeleteEvent"] = 1;
        $cs_params["deleteCalEntry"] = 1;
        if (!$source) {
            $source = "churchcal";
        }
        $db = db_query("SELECT * FROM {cs_event}\n                    WHERE cc_cal_id=:cal_id", array(":cal_id" => $cs_params["cal_id"]));
        foreach ($db as $cs) {
            $cs_params["id"] = $cs->id;
            churchservice_deleteEvent($cs_params, $source);
        }
    }
    db_query("DELETE FROM {cc_meetingrequest} WHERE cal_id=:id", array(":id" => $id));
    db_query("DELETE FROM {cc_cal_except} WHERE cal_id=:id", array(":id" => $id));
    db_query("DELETE FROM {cc_cal_add}    WHERE cal_id=:id", array(":id" => $id));
    db_query("DELETE FROM {cc_cal}        WHERE id=:id", array(":id" => $id));
    $data = db_query("select * from {cc_calcategory} where id=:id", array(":id" => $logger->category_id))->fetch();
    $txt = $user->vorname . " " . $user->name . " hat in Kalender ";
    if ($data != false) {
        $txt .= $data->bezeichnung;
    } else {
        $txt .= $logger->category_id;
    }
    $txt .= " einen Termin gel&ouml;scht: <br>";
    $txt .= churchcore_CCEventData2String($logger);
    ct_notify("category", $logger->category_id, $txt);
}
function churchservice_updateEventFromChurchCal($params, $source = null)
{
    $diff = null;
    // When $params["old_startdate"] is set, first the events are moved
    // to the diff of startdate-old_startdate
    if (isset($params["old_startdate"])) {
        $startdate = new DateTime($params["startdate"]);
        $old_startdate = new DateTime($params["old_startdate"]);
        $diff = $startdate->format("U") - $old_startdate->format("U");
        $db = db_query("select id, startdate from {cs_event} e where e.cc_cal_id=:cal_id", array(":cal_id" => $params["cal_id"]));
        foreach ($db as $e) {
            $sd = new DateTime($e->startdate);
            $sd->modify("+{$diff} seconds");
            db_update("cs_event")->fields(array("startdate" => $sd->format('Y-m-d H:i:s')))->condition('id', $e->id, "=")->execute();
        }
    }
    // When repeat_id is not given, this is only a time shift. So we can end the processing here.
    if (!isset($params["repeat_id"])) {
        return;
    }
    // Collect events in one array to collect the info which has to be created/deleted/updated
    $events = array();
    // Get all mapped events from DB
    $db = db_query("select id, startdate from {cs_event} e where e.cc_cal_id=:cal_id", array(":cal_id" => $params["cal_id"]));
    foreach ($db as $e) {
        $sd = new DateTime($e->startdate);
        $events[$sd->format('Y-m-d')] = array("status" => "delete", "id" => $e->id);
    }
    $o = _convertCTDateTimeToObjects($params);
    foreach (getAllDatesWithRepeats($o, -1000, +1000) as $d) {
        $sd = $d->format('Y-m-d');
        if (isset($events[$sd])) {
            // Event was already moved above through old_startdate
            $events[$sd]["status"] = "ok";
        } else {
            $events[$sd] = array("status" => "create");
        }
        $events[$sd]["startdate"] = $d->format('Y-m-d H:i:s');
    }
    $template = null;
    if (isset($params["eventTemplate"])) {
        $template = $params["eventTemplate"];
    }
    foreach ($events as $key => $do) {
        if ($do["status"] == "delete") {
            $params["id"] = $do["id"];
            $params["informDeleteEvent"] = 1;
            $params["deleteCalEntry"] = 0;
            churchservice_deleteEvent($params, $source);
        } else {
            if ($do["status"] == "create" && $template != null) {
                $params["id"] = null;
                $params["startdate"] = $do["startdate"];
                $params["eventTemplate"] = $template;
                churchservice_saveEvent($params, $source);
            }
        }
    }
}