Esempio n. 1
0
function churchcal_deleteCategory($params)
{
    global $user;
    $id = $params["id"];
    $data = db_query("select * from {cc_calcategory} where id=:id", array(":id" => $id))->fetch();
    if ($data == false) {
        return CTException("Kategorie nicht vorhanden");
    }
    $auth = user_access("edit category", "churchcal");
    if ($data->modified_pid != $user->id && ($auth == null || !isset($auth[$id]))) {
        throw new CTNoPermission("Edit Category", "churchcal");
    }
    $c = db_query("select count(*) c from {cs_event} e, {cc_cal} cal where cal.id=e.cc_cal_id and cal.category_id=:id", array(":id" => $id))->fetch();
    if ($c->c > 0) {
        throw new CTFail("Es sind noch Dienste zu dem Kalender verbunden. Kann ihn deshalb nicht entfernen!");
    }
    db_query("delete from {cc_cal} where category_id=:id", array(":id" => $id));
    db_query("delete from {cc_calcategory} where id=:id", array(":id" => $id));
    db_query("delete from {cc_domain_auth} where auth_id in (403, 404) and daten_id={$id}");
}
Esempio n. 2
0
function churchcal_deleteCategory($params)
{
    global $user;
    $id = getVar('id', false, $params);
    $data = db_query("SELECT * FROM {cc_calcategory}\n                    WHERE id=:id", array(":id" => $id))->fetch();
    if (!$data) {
        return CTException(t('category.does.not.exist'));
    }
    $auth = user_access("edit category", "churchcal");
    if ($data->modified_pid != $user->id && (!$auth || !isset($auth[$id]))) {
        throw new CTNoPermission("Edit Category", "churchcal");
    }
    $c = db_query("SELECT COUNT(*) c\n                 FROM {cs_event} e, {cc_cal} cal, {cs_eventservice} es\n                 WHERE cal.id=e.cc_cal_id AND cal.category_id=:id\n                 AND es.event_id=e.id AND zugesagt_yn=1 AND es.valid_yn=1\n                 AND DATEDIFF(cal.startdate, now())>=0", array(":id" => $id))->fetch();
    if ($c->c > 0) {
        throw new CTFail(t('deleting.failed.because.of.remaining.services'));
    }
    $db = db_query("SELECT c.id FROM {cs_event} e, {cc_cal} c WHERE c.category_id=:category_id AND e.cc_cal_id = c.id", array(":category_id" => $id));
    foreach ($db as $cal) {
        churchcal_deleteEvent(array("id" => $cal->id));
    }
    db_query("DELETE FROM {cc_cal}         WHERE category_id=:id", array(":id" => $id));
    db_query("DELETE FROM {cc_calcategory} WHERE id=:id", array(":id" => $id));
    db_query("DELETE FROM {cc_domain_auth} WHERE auth_id in (403, 404) and daten_id=:id", array(":id" => $id));
}