コード例 #1
0
ファイル: churchcal.php プロジェクト: toXel/churchtools_basic
/**
 * 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);
}
コード例 #2
0
/**
 * Store all Exception and Addition changes for communication to other modules
 *
 * @param array $params
 * @param string $sourc; controls cooperation between modules if event comes from another modulee
 * @param boolean $withoutPerm If permission will be checked.
 */
function churchcal_updateEvent($params, $callCS = true, $withoutPerm = false)
{
    global $user, $base_url;
    $changes = array();
    if (!$withoutPerm && !churchcal_isAllowedToEditCategory($params["category_id"])) {
        throw new CTNoPermission("AllowedToEditCategory[" . $params["category_id"] . "] (newCat)", "churchcal");
    }
    $old_cal = db_query("SELECT *\n                       FROM {cc_cal}\n                       WHERE id=:id", array(":id" => $params["id"]))->fetch();
    // can user edit old event category?
    if (!$withoutPerm && !churchcal_isAllowedToEditCategory($old_cal->category_id)) {
        throw new CTNoPermission("AllowedToEditCategory[" . $old_cal->category_id . "] (oldCat)", "churchcal");
    }
    // When empty, load originEvent for later sending Change protocol
    $dummy = churchcal_getCalPerCategory(array("category_ids" => array(0 => $old_cal->category_id)));
    $originEvent = (array) $dummy[$old_cal->category_id][$params["id"]];
    if (isset($params["notizen"])) {
        $params["notizen"] = str_replace('\\"', '"', $params["notizen"]);
    }
    $i = new CTInterface();
    $i->setParam("startdate", false);
    $i->setParam("enddate", false);
    $i->setParam("bezeichnung", false);
    $i->setParam("category_id", false);
    $i->setParam("ort", false);
    $i->setParam("notizen", false);
    $i->setParam("intern_yn", false);
    $i->setParam("link", false);
    $i->setParam("repeat_id", false);
    $i->setParam("repeat_until", false);
    $i->setParam("repeat_frequence", false);
    $i->setParam("repeat_option_id", false);
    if (isset($params["modified_pid"])) {
        $i->setParam("modified_pid");
    }
    // not with ", false" cause this cause an update
    $f = $i->getDBInsertArrayFromParams($params);
    if (count($f)) {
        db_update("cc_cal")->fields($f)->condition("id", $params["id"], "=")->execute();
    }
    // get all exceptions for event
    $exc = churchcore_getTableData("cc_cal_except", null, "cal_id=" . $params["id"]);
    // look which are already in DB
    if (!empty($params["exceptions"])) {
        foreach ($params["exceptions"] as $exception) {
            if ($exception["id"] > 0) {
                $exc[$exception["id"]]->vorhanden = true;
            } else {
                $add_exc = array("cal_id" => $params["id"], "except_date_start" => $exception["except_date_start"], "except_date_end" => $exception["except_date_end"]);
                churchcal_addException($add_exc);
                $changes["add_exception"][] = $add_exc;
            }
        }
    }
    // delete removed exceptions from DB
    if ($exc) {
        foreach ($exc as $e) {
            if (!isset($e->vorhanden)) {
                $del_exc = array("id" => $e->id, "except_date_start" => $e->except_date_start, "except_date_end" => $e->except_date_end);
                churchcal_delException($del_exc);
                $changes["del_exception"][] = $del_exc;
            }
        }
    }
    // get all additions
    $add = churchcore_getTableData("cc_cal_add", null, "cal_id=" . $params["id"]);
    // look which are already in DB.
    if (!empty($params["additions"])) {
        foreach ($params["additions"] as $addition) {
            if ($addition["id"] > 0) {
                $add[$addition["id"]]->vorhanden = true;
            } else {
                $add_add = array("cal_id" => $params["id"], "add_date" => $addition["add_date"], "with_repeat_yn" => $addition["with_repeat_yn"]);
                churchcal_addAddition($add_add);
                $changes["add_addition"][] = $add_add;
            }
        }
    }
    // delete from DB which are deleted.
    if ($add) {
        foreach ($add as $a) {
            if (!isset($a->vorhanden)) {
                $del_add = array("id" => $a->id, "add_date" => $a->add_date);
                churchcal_delAddition($del_add);
                $changes["del_addition"][] = $del_add;
            }
        }
    }
    // meeting request
    if (isset($params["meetingRequest"])) {
        churchcal_handleMeetingRequest($params["id"], $params);
    }
    // Call other modules
    $newBookingIds = null;
    if (churchcore_isModuleActivated("churchresource")) {
        include_once CHURCHRESOURCE . '/churchresource_db.php';
        $newBookingIds = churchresource_operateResourcesFromChurchCal($params);
    }
    $newCSIds = null;
    if ($callCS) {
        if (churchcore_isModuleActivated("churchservice")) {
            include_once CHURCHSERVICE . '/churchservice_db.php';
            $newCSIds = churchservice_operateEventFromChurchCal($params);
        }
    }
    // Notification
    $data = db_query("select * from {cc_calcategory} where id=:id", array(":id" => $params["category_id"]))->fetch();
    $txt = $user->vorname . " " . $user->name . " hat einen Termin angepasst im Kalender ";
    if ($data != false) {
        $txt .= $data->bezeichnung;
    } else {
        $txt .= $params["category_id"];
    }
    $txt .= " auf:<br>";
    $txt .= churchcore_CCEventData2String($params);
    ct_notify("category", $params["category_id"], $txt);
    // Inform creator when I am allowed and when it is not me!
    if ($callCS && getVar("informCreator", "true") == "true" && $originEvent["modified_pid"] != $user->id) {
        $data = (array) churchcal_getEventChangeImpact(array("newEvent" => $params, "originEvent" => $originEvent, "pastEvent" => null));
        if (!empty($data["bookings"]) || !empty($data["cal"])) {
            $data["new"] = false;
            $data["caption"] = $params["bezeichnung"];
            $data["startdate"] = churchcore_stringToDateDe($params["startdate"]);
            $data["eventUrl"] = $base_url . "?q=churchcal&category_id=" . $params["category_id"] . "&id=" . $params["id"];
            $p = db_query("SELECT name, vorname, IF(spitzname, spitzname, vorname) AS nickname\n                      FROM {cdb_person}\n                      WHERE id=:id", array(":id" => $originEvent["modified_pid"]))->fetch();
            $data["p"] = $p;
            // get populated template and send email
            $lang = getUserLanguage($params["modified_pid"]);
            $content = getTemplateContent('email/informCreator', 'churchcal', $data, null, $lang);
            churchcore_sendEMailToPersonIDs($originEvent["modified_pid"], "[" . getConf('site_name') . "] " . t2($lang, 'information.for.your.event'), $content, null, true);
        }
    }
    return array("cseventIds" => $newCSIds, "bookingIds" => $newBookingIds);
}