コード例 #1
0
/**
 * send emails to persons with given id(s)
 *
 * @param string $ids; comma separated
 * @param string $subject
 * @param string $content
 * @param string $from; default: null (use current users email)
 * @param string $htmlmail; default: false
 * @param string $withtemplate; default: true
 */
function churchcore_sendEMailToPersonIDs($ids, $subject, $content, $from = null, $htmlmail = false, $withtemplate = true)
{
    global $base_url;
    if ($ids == null || $ids == "") {
        ct_log("Konnte Email {$subject} nicht senden, kein Empfänger angegeben!", 1);
        return;
    }
    if (!$from) {
        $user_pid = $_SESSION["user"]->id;
        $res = db_query("SELECT vorname, name, email FROM {cdb_person}\n                     WHERE id={$user_pid}")->fetch();
        $from = "{$res->vorname} {$res->name} <{$res->email}>";
    }
    $persons = db_query("SELECT * FROM {cdb_person} WHERE id IN ({$ids})");
    $error = array();
    foreach ($persons as $p) {
        $mailtxt = $content;
        if (empty($p->email)) {
            $error[] = $p->vorname . " " . $p->name;
        } else {
            $mailtxt = str_replace('\\"', '"', $mailtxt);
            $mailtxt = churchcore_personalizeTemplate($mailtxt, $p);
            churchcore_mail($from, $p->email, $subject, $mailtxt, $htmlmail, $withtemplate);
        }
    }
    if (count($error)) {
        throw new CTFail(t('following.persons.have.no.email.address') . ' ' . implode($error, ", "));
    }
}
コード例 #2
0
function churchcal_getCalPerCategory($params, $withintern = true)
{
    $data = array();
    $res = db_query("select cal.*, concat(p.vorname, ' ',p.name) modified_name, e.id event_id, e.startdate event_startdate, e.created_by_template_id event_template_id, \n                 b.id booking_id, b.startdate booking_startdate, b.enddate booking_enddate, b.resource_id booking_resource_id, b.status_id booking_status_id \n               from {cc_cal} cal\n               left join {cs_event} e on (cal.id=e.cc_cal_id) \n               left join {cr_booking} b on (cal.id=b.cc_cal_id) \n               left join {cdb_person} p on (cal.modified_pid=p.id)\n               where cal.category_id in (" . implode(",", $params["category_ids"]) . ")\n                " . (!$withintern ? " and intern_yn=0" : "") . " \n               order by category_id");
    $data = null;
    // Agreggiere, falls es mehrere Bookings oder Events pro calendareintrag gibt.
    foreach ($res as $arr) {
        if (isset($data[$arr->id])) {
            $elem = $data[$arr->id];
        } else {
            $elem = $arr;
            $req = churchcore_getTableData("cc_meetingrequest", null, "cal_id=" . $arr->id);
            if ($req != false) {
                $elem->meetingRequest = array();
                foreach ($req as $r) {
                    $elem->meetingRequest[$r->person_id] = $r;
                }
            }
        }
        if ($arr->booking_id != null) {
            $elem->bookings[$arr->booking_resource_id] = array("id" => $arr->booking_id, "minpre" => (strtotime($arr->startdate) - strtotime($arr->booking_startdate)) / 60, "minpost" => (strtotime($arr->booking_enddate) - strtotime($arr->enddate)) / 60, "resource_id" => $arr->booking_resource_id, "status_id" => $arr->booking_status_id);
        }
        if ($arr->event_id != null) {
            // Get additional Service text infos, like "Preaching with [Vorname]"
            $service_texts = null;
            $es = db_query("select es.name, s.id, es.cdb_person_id, s.cal_text_template from {cs_service} s, {cs_eventservice} es where es.event_id=:event_id and\n                       es.service_id=s.id and es.valid_yn=1 and es.zugesagt_yn=1 \n                      and s.cal_text_template is not null and s.cal_text_template!=''", array(":event_id" => $arr->event_id));
            foreach ($es as $e) {
                if ($e !== false) {
                    if (strpos($e->cal_text_template, "[") === false) {
                        if ($service_texts == null) {
                            $service_texts = array();
                        }
                        $txt = $e->cal_text_template;
                    }
                    if ($e->cdb_person_id != null) {
                        include_once CHURCHDB . "/churchdb_db.php";
                        $p = db_query("select * from {cdb_person} where id=:id", array(":id" => $e->cdb_person_id))->fetch();
                        if ($p !== false) {
                            if ($service_texts == null) {
                                $service_texts = array();
                            }
                            $txt = churchcore_personalizeTemplate($e->cal_text_template, $p);
                        }
                    }
                    if ($service_texts !== null && array_search($txt, $service_texts) === false) {
                        $service_texts[] = $txt;
                    }
                }
            }
            // Save event info
            $elem->events[$arr->event_id] = array("id" => $arr->event_id, "startdate" => $arr->event_startdate, "service_texts" => $service_texts);
        }
        $data[$arr->id] = $elem;
    }
    if ($data == null) {
        return array();
    }
    $excepts = churchcore_getTableData("cc_cal_except");
    if ($excepts != null) {
        foreach ($excepts as $val) {
            // Kann sein, dass es Exceptions gibt, wo es kein Termin mehr gibt.
            if (isset($data[$val->cal_id])) {
                if (!isset($data[$val->cal_id]->exceptions)) {
                    $a = array();
                } else {
                    $a = $data[$val->cal_id]->exceptions;
                }
                $b = new stdClass();
                $b->id = $val->id;
                $b->except_date_start = $val->except_date_start;
                $b->except_date_end = $val->except_date_end;
                $a[$val->id] = $b;
                $data[$val->cal_id]->exceptions = $a;
            }
        }
    }
    $excepts = churchcore_getTableData("cc_cal_add");
    if ($excepts != null) {
        foreach ($excepts as $val) {
            // Kann sein, dass es Additions gibt, wo es kein Termin mehr gibt.
            if (isset($data[$val->cal_id])) {
                if (!isset($data[$val->cal_id]->additions)) {
                    $a = array();
                } else {
                    $a = $data[$val->cal_id]->additions;
                }
                $b = new stdClass();
                $b->id = $val->id;
                $b->add_date = $val->add_date;
                $b->with_repeat_yn = $val->with_repeat_yn;
                $a[$val->id] = $b;
                $data[$val->cal_id]->additions = $a;
            }
        }
    }
    $ret = array();
    foreach ($params["category_ids"] as $cat) {
        $ret[$cat] = array();
        foreach ($data as $d) {
            if ($d->category_id == $cat) {
                $ret[$cat][$d->id] = $d;
            }
        }
    }
    return $ret;
}
コード例 #3
0
/**
 * send sms
 * TODO: use sms template
 *
 * @param string $ids, comma separated
 * @param string $txt
 * @return array
 */
function churchdb_sendsms($ids, $txt)
{
    global $user;
    $param = array();
    // get cell phone number of user as sender from DB - maybe session contains an outdated one.
    $mobile = db_query("SELECT telefonhandy FROM {cdb_person}\n                      WHERE id=:id", array(":id" => $user->id))->fetch();
    if (!empty($mobile->telefonhandy)) {
        $param["from"] = preg_replace('![^0-9]!', '', $mobile->telefonhandy);
    } else {
        $param["from"] = "ChurchTools";
    }
    $db = db_query("SELECT id, telefonhandy, vorname, name, IF(spitzname != '', spitzname, vorname) AS spitzname\n                  FROM {cdb_person}\n                  WHERE id IN (" . db_implode($ids) . ")");
    $res = array();
    $res["withoutmobilecount"] = 0;
    $res["smscount"] = 0;
    foreach ($db as $p) {
        if (!$p->telefonhandy) {
            $res["withoutmobilecount"]++;
            $res[$p->id] = t("no.sms.sent.person.has.no.mobile.number");
        } else {
            $param["to"] = $p->telefonhandy;
            $param["message"] = churchcore_personalizeTemplate($txt, $p);
            $res[$p->id] = churchdb_smspromote($param);
            $res["smscount"]++;
        }
    }
    return $res;
}
コード例 #4
0
/**
 * send emails to persons with given id(s)
 * 
 * @param string $ids, ids, comma separated
 * @param string $subject
 * @param string $content
 * @param string $from, if empty, current users email 
 */
function churchcore_sendEMailToPersonids($ids, $subject, $content, $from = null, $htmlmail = false, $withtemplate = true)
{
    global $base_url;
    if ($from == null) {
        $user_pid = $_SESSION["user"]->id;
        $res = db_query("select vorname, name, email from {cdb_person} where id={$user_pid}")->fetch();
        $from = "{$res->vorname} {$res->name} <{$res->email}>";
    }
    $arr = db_query("select * from {cdb_person} where id in ({$ids})");
    $error = array();
    foreach ($arr as $p) {
        $mailtxt = $content;
        if (empty($p->email)) {
            $error[] = $p->vorname . " " . $p->name;
        } else {
            $mailtxt = str_replace('\\"', '"', $mailtxt);
            $mailtxt = churchcore_personalizeTemplate($mailtxt, $p);
            //ct_log("[ChurchCore] - Sende Mail an $p->email $mailtxt",2,-1,"mail");
            churchcore_mail($from, $p->email, $subject, $mailtxt, $htmlmail, $withtemplate);
        }
    }
    if (count($error) > 0) {
        throw new CTFail(t('following.persons.have.no.email.address') . ' ' . implode($error, ", "));
    }
}
コード例 #5
0
/**
 *
 * @param unknown $params
 * @param string $withIntern
 * @return multitype:|Ambigous <multitype:multitype: , NULL, object, boolean, db_accessor>
 */
function churchcal_getCalPerCategory($params, $withIntern = null)
{
    global $user;
    if ($withIntern == null) {
        $withIntern = $user == null || $user->id == -1 ? false : true;
    }
    $data = array();
    $from = getConf("churchcal_entries_last_days", 180);
    $res = db_query("\n      SELECT cal.*, CONCAT(p.vorname, ' ',p.name) AS modified_name, e.id AS event_id, e.startdate AS event_startdate,\n        e.created_by_template_id AS event_template_id, b.id AS booking_id, b.startdate AS booking_startdate, b.enddate AS booking_enddate,\n        b.resource_id AS booking_resource_id, b.status_id AS booking_status_id, b.location AS booking_location,\n        b.note AS booking_note\n      FROM {cc_cal} cal\n      LEFT JOIN {cs_event} e ON (cal.id=e.cc_cal_id)\n      LEFT JOIN {cr_booking} b ON (cal.id=b.cc_cal_id)\n      LEFT JOIN {cdb_person} p ON (cal.modified_pid=p.id)\n      WHERE cal.category_id IN (" . db_implode($params["category_ids"]) . ") " . (!$withIntern ? " and intern_yn=0" : "") . " AND(     ( DATEDIFF  ( cal.enddate , NOW() ) > - {$from} )\n                 OR ( cal.repeat_id>0 AND DATEDIFF (cal.repeat_until, NOW() ) > - {$from}) )\n      ");
    $data = null;
    // collect bookings/events if more then one per calendar entry
    foreach ($res as $arr) {
        if (isset($data[$arr->id])) {
            $elem = $data[$arr->id];
        } else {
            $elem = $arr;
            $req = churchcore_getTableData("cc_meetingrequest", null, "cal_id=" . $arr->id);
            if ($req) {
                $elem->meetingRequest = array();
                foreach ($req as $r) {
                    $elem->meetingRequest[$r->person_id] = $r;
                }
            }
        }
        if ($arr->booking_id) {
            $elem->bookings[$arr->booking_id] = array("id" => $arr->booking_id, "minpre" => (strtotime($arr->startdate) - strtotime($arr->booking_startdate)) / 60, "minpost" => (strtotime($arr->booking_enddate) - strtotime($arr->enddate)) / 60, "resource_id" => $arr->booking_resource_id, "status_id" => $arr->booking_status_id, "location" => $arr->booking_location, "note" => $arr->booking_note);
            unset($arr->booking_id);
            unset($arr->booking_startdate);
            unset($arr->booking_enddate);
            unset($arr->booking_resource_id);
            unset($arr->booking_status_id);
            unset($arr->booking_location);
            unset($arr->booking_note);
        }
        if ($arr->event_id) {
            // Get additional Service text infos, like "Preaching with [Vorname]"
            $service_texts = array();
            $es = db_query("\n        SELECT es.name, s.id, es.cdb_person_id, s.cal_text_template from {cs_service} s, {cs_eventservice} es\n        WHERE es.event_id=:event_id AND es.service_id=s.id and es.valid_yn=1 and es.zugesagt_yn=1\n          AND s.cal_text_template IS NOT NULL AND s.cal_text_template!=''", array(":event_id" => $arr->event_id));
            foreach ($es as $e) {
                if ($e) {
                    $txt = false;
                    if (strpos($e->cal_text_template, "[") === false) {
                        $txt = $e->cal_text_template;
                    }
                    $p = null;
                    // First use person_id
                    if ($e->cdb_person_id) {
                        $p = db_query("SELECT * FROM {cdb_person}\n                         WHERE id=:id", array(":id" => $e->cdb_person_id))->fetch();
                    }
                    // When not available use name
                    if (!$p && $e->name) {
                        $p = new stdClass();
                        $p->name = $e->name;
                    }
                    if ($p) {
                        $txt = churchcore_personalizeTemplate($e->cal_text_template, $p);
                    }
                    if (!in_array($txt, $service_texts)) {
                        $service_texts[] = $txt;
                    }
                }
            }
            // Save event info
            $elem->csevents[$arr->event_id] = array("id" => $arr->event_id, "startdate" => $arr->event_startdate, "service_texts" => $service_texts, "eventTemplate" => $arr->event_template_id);
        }
        $data[$arr->id] = $elem;
    }
    $exceptions = churchcore_getTableData("cc_cal_except");
    if ($exceptions) {
        foreach ($exceptions as $e) {
            // there may be exceptions without event
            if (isset($data[$e->cal_id])) {
                if (!isset($data[$e->cal_id]->exceptions)) {
                    $data[$e->cal_id]->exceptions = array();
                }
                $data[$e->cal_id]->exceptions[$e->id] = new stdClass();
                $data[$e->cal_id]->exceptions[$e->id]->id = $e->id;
                $data[$e->cal_id]->exceptions[$e->id]->except_date_start = $e->except_date_start;
                $data[$e->cal_id]->exceptions[$e->id]->except_date_end = $e->except_date_end;
            }
        }
    }
    $additions = churchcore_getTableData("cc_cal_add");
    if ($additions) {
        foreach ($additions as $e) {
            // there may be additions without event
            if (isset($data[$e->cal_id])) {
                if (!isset($data[$e->cal_id]->additions)) {
                    $data[$e->cal_id]->additions = array();
                }
                $data[$e->cal_id]->additions[$e->id] = new stdClass();
                $data[$e->cal_id]->additions[$e->id]->id = $e->id;
                $data[$e->cal_id]->additions[$e->id]->add_date = $e->add_date;
                $data[$e->cal_id]->additions[$e->id]->with_repeat_yn = $e->with_repeat_yn;
            }
        }
    }
    $ret = array();
    foreach ($params["category_ids"] as $cat) {
        $ret[$cat] = array();
        if ($data) {
            foreach ($data as $d) {
                if ($d->category_id == $cat) {
                    $ret[$cat][$d->id] = $d;
                }
            }
        }
    }
    return $ret;
}