function getUserLanguageLangFileName()
{
    global $db;
    $results = mysql_query("SELECT lang_file_name FROM languages WHERE id='" . getUserLanguage() . "'", $db);
    if (mysql_num_rows($results) > 0) {
        $result = mysql_fetch_array($results);
        $lang_file_name = $result['lang_file_name'];
        return $lang_file_name;
    }
}
Example #2
0
<?php

require_once "../app/actions/constantes.php";
require_once "../app/actions/funciones.php";
if (!isset($_SESSION['idioma'])) {
    $_SESSION['idioma'] = getUserLanguage();
}
require_once "resumeData_" . $_SESSION['idioma'] . ".php";
/**
 * Send pending notifications.
 *
 * @param string $max_delayhours; default null for all.
 *
 */
function ct_sendPendingNotifications($max_delayhours = null)
{
    $res = churchcore_getTableData("cc_notificationtype", "delay_hours", $max_delayhours != null ? "delay_hours<={$max_delayhours}" : "");
    foreach ($res as $n) {
        // Check if there is a pending notifications for a person and domain_type
        $personANDtypes = db_query('SELECT n.person_id, n.domain_type FROM {cc_notification} n
          WHERE n.notificationtype_id=:nt_id AND (lastsenddate IS NULL OR
          (TIME_TO_SEC(TIMEDIFF(NOW(), lastsenddate)) / 3600)>:delay_hours)
          GROUP BY n.person_id, n.domain_type', array(':nt_id' => $n->id, ':delay_hours' => $n->delay_hours));
        // Collect all notifications in this type for each person and domain_type
        foreach ($personANDtypes as $personANDtype) {
            $notis = db_query('SELECT * FROM {cc_notification} n
                         WHERE n.person_id=:person_id and n.notificationtype_id=:nt_id and n.domain_type=:dt_id', array(':person_id' => $personANDtype->person_id, ':nt_id' => $n->id, ':dt_id' => $personANDtype->domain_type));
            // Get all logs for each notification after? each lastsenddate
            foreach ($notis as $noti) {
                $logs = db_query("SELECT l.txt AS text, DATE_FORMAT(datum, '%e.%c.%Y %H:%i') date FROM {cdb_log} l\n                          WHERE domain_type=:domain_type AND domain_id=:domain_id\n                            AND (:lastsenddate IS NULL OR TIME_TO_SEC(TIMEDIFF(datum, :lastsenddate))>0)\n                          ORDER BY datum DESC", array(":domain_type" => $personANDtype->domain_type, ":domain_id" => $noti->domain_id, ":lastsenddate" => $noti->lastsenddate));
                $messages = array();
                foreach ($logs as $log) {
                    $messages[] = $log;
                }
            }
            if (count($messages)) {
                $p = churchcore_getUserById($personANDtype->person_id);
                if ($p && $p->email) {
                    $data = array('surname' => $p->vorname, 'name' => $p->name, 'nickname' => $p->spitzname ? $p->spitzname : $p->vorname, 'notifyName' => t($personANDtype->domain_type), 'notifyType' => $n->bezeichnung, 'messages' => $messages);
                    $lang = getUserLanguage($personANDtype->person_id);
                    $content = getTemplateContent("email/notification", 'churchcore', $data, null, $lang);
                    churchcore_systemmail($p->email, "[" . getConf('site_name') . "] " . t2($lang, 'news.for.abo.x', t($personANDtype->domain_type)), $content, true);
                }
            }
            // update send date for notification
            $notis = db_query('UPDATE {cc_notification} n SET lastsenddate=NOW()
                         WHERE n.person_id=:person_id AND n.notificationtype_id=:nt_id AND n.domain_type=:dt_id', array(':person_id' => $personANDtype->person_id, ':nt_id' => $n->id, ':dt_id' => $personANDtype->domain_type));
        }
    }
}
Example #4
0
function displayHTMLhead($pageTitle, $metaRobots, $metaDescription, $additionalMeta, $includeJavaScript, $includeJavaScriptFile, $viewType, $rssURLArray)
{
    global $officialDatabaseName;
    // these variables are defined in 'ini.inc.php'
    global $contentTypeCharset;
    global $defaultStyleSheet;
    global $printStyleSheet;
    global $mobileStyleSheet;
    global $useVisualEffects;
    global $databaseBaseURL;
    global $databaseKeywords;
    global $defaultFeedFormat;
    ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
		"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head profile="http://a9.com/-/spec/opensearch/1.1/">
	<title><?php 
    echo $pageTitle;
    ?>
</title>
	<meta name="date" content="<?php 
    echo date('d-M-y');
    ?>
">
	<meta name="robots" content="<?php 
    echo $metaRobots;
    ?>
">
	<meta name="description" lang="en" content="<?php 
    echo $metaDescription;
    ?>
">
	<meta name="keywords" lang="en" content="<?php 
    echo $databaseKeywords;
    ?>
"><?php 
    if (!empty($additionalMeta)) {
        echo $additionalMeta;
    }
    ?>

	<meta http-equiv="content-language" content="<?php 
    echo getUserLanguage();
    ?>
">
	<meta http-equiv="content-type" content="text/html; charset=<?php 
    echo $contentTypeCharset;
    ?>
">
	<meta http-equiv="Content-Style-Type" content="text/css">

    <link rel="stylesheet" href="css/foundation/normalize.css" type="text/css" title="CSS Definition">
    <link rel="stylesheet" href="css/foundation/foundation.min.css" type="text/css" title="CSS Definition">
    <link rel="stylesheet" href="css/font/css/font-awesome.min.css" type="text/css" title="CSS Definition">
    <?php 
    if (preg_match("/^Print\$/i", $viewType)) {
        ?>
        <link rel="stylesheet" href="<?php 
        echo $printStyleSheet;
        ?>
" type="text/css" title="CSS Definition">
    <?php 
    } elseif (preg_match("/^Mobile\$/i", $viewType)) {
        ?>
        <link rel="stylesheet" href="<?php 
        echo $mobileStyleSheet;
        ?>
" type="text/css" title="CSS Definition">
    <?php 
    } else {
        ?>
        <link rel="stylesheet" href="<?php 
        echo $defaultStyleSheet;
        ?>
" type="text/css" title="CSS Definition">
    <?php 
    }
    ?>

        <?php 
    if (!empty($rssURLArray) and isset($_SESSION['user_permissions']) and preg_match("/allow_rss_feeds/", $_SESSION['user_permissions'])) {
        foreach ($rssURLArray as $rssURL) {
            if ($defaultFeedFormat == "Atom XML") {
                $feedContentType = "application/atom+xml";
            } else {
                // RSS XML
                $feedContentType = "application/rss+xml";
            }
            // ...include a link tag pointing to a dynamic RSS feed for the current query:
            ?>

	<link rel="alternate" type="<?php 
            echo $feedContentType;
            ?>
" href="<?php 
            echo $databaseBaseURL . $rssURL['href'];
            ?>
" title="<?php 
            echo $rssURL['title'];
            ?>
"><?php 
        }
    }
    ?>

	<link rel="unapi-server" type="application/xml" title="unAPI" href="<?php 
    echo $databaseBaseURL;
    ?>
unapi.php">
	<link rel="search" type="application/opensearchdescription+xml" title="<?php 
    echo encodeHTML($officialDatabaseName);
    ?>
" href="<?php 
    echo $databaseBaseURL;
    ?>
opensearch.php?operation=explain"><?php 
    if ($includeJavaScript or isset($_SESSION['userAutoCompletions']) and $_SESSION['userAutoCompletions'] == "yes" or $useVisualEffects == "yes") {
        // ...include common refbase JavaScript functions:
        ?>

	<script language="JavaScript" type="text/javascript" src="javascript/common.js"></script><?php 
    }
    if (isset($_SESSION['userAutoCompletions']) and $_SESSION['userAutoCompletions'] == "yes" or $useVisualEffects == "yes") {
        // ...include the Prototype & script.aculo.us JavaScript frameworks:
        ?>

	<script language="JavaScript" type="text/javascript" src="javascript/prototype.js"></script>
	<script language="JavaScript" type="text/javascript" src="javascript/scriptaculous.js?load=effects,controls"></script><?php 
    }
    if (!empty($includeJavaScriptFile)) {
        // ...include additional JavaScript functions:
        ?>

	<script language="JavaScript" type="text/javascript" src="<?php 
        echo $includeJavaScriptFile;
        ?>
"></script><?php 
    }
    ?>

</head>
<body><?php 
}
Example #5
0
<?php

define('DS', DIRECTORY_SEPARATOR);
define('APP_FOLDER', '/');
define('MANGAS_FOLDER', 'mangas');
$ADMIN_IDs = array(2807710899.0);
$languageCode = getUserLanguage();
define('READER_LANGUAGE_CODE', $languageCode);
$phrases = getPhrases($languageCode);
$requestScheme = filter_input(INPUT_SERVER, "REQUEST_SCHEME");
$httpHost = filter_input(INPUT_SERVER, "HTTP_HOST");
$config = array("base_url" => $requestScheme . "://" . $httpHost . APP_FOLDER . "phplib/hybridauth/index.php", "providers" => array("Twitter" => array("enabled" => true, "keys" => array("key" => "uwFVJG4r4STZg8kgI13JDXZTO", "secret" => "dJvMmCwomGUbp19nwCTfVBJz3nAdCnt342mjuWwMpjg1BDdlsB"))), "debug_mode" => false, "debug_file" => "debug.log");
function getPhrases($language)
{
    $fileName = dirname(__DIR__) . DS . "assets" . DS . "locales" . DS . "locale." . $language . ".json";
    if (!file_exists($fileName)) {
        $fileName = dirname(__DIR__) . DS . "assets" . DS . "locales" . DS . "locale.en.json";
    }
    return json_decode(file_get_contents($fileName), true);
}
function getFirstManga($dir)
{
    foreach (new DirectoryIterator($dir . DS . MANGAS_FOLDER) as $dirInfo) {
        if ($dirInfo->isDot()) {
            continue;
        }
        if (!$dirInfo->isDir()) {
            continue;
        }
        return $dirInfo->getFilename();
    }
/**
 * inform leader about open event services
 * TODO: no idea if this could be improved - lots of sql requests and loops
 * @return boolean
 */
function churchservice_inform_leader()
{
    global $base_url;
    include_once "churchservice_db.php";
    // get all group ids from services
    $res = db_query("SELECT cdb_gruppen_ids FROM {cs_service}\n                   WHERE cdb_gruppen_ids!='' AND cdb_gruppen_ids IS NOT NULL");
    // TODO: use WHERE cdb_gruppen_ids > '' ?
    //                   WHERE cdb_gruppen_ids>''); // TODO: works too
    $arr = array();
    foreach ($res as $g) {
        $arr[] = $g->cdb_gruppen_ids;
    }
    if (!count($arr)) {
        return false;
    }
    // get persons being (co)leader of one of this service groups
    $res = db_query("SELECT p.id AS person_id, gpg.gruppe_id, p.email, p.vorname, p.name, p.spitzname, p.cmsuserid\n                   FROM {cdb_person} p, {cdb_gemeindeperson_gruppe} gpg, {cdb_gemeindeperson} gp\n                   WHERE gpg.gemeindeperson_id = gp.id AND p.id = gp.person_id AND status_no >= 1 AND status_no <= 2\n                     AND gpg.gruppe_id IN (" . db_implode($arr) . ")");
    // Aggregiere nach Person_Id P1[G1,G2,G3],P2[G3]
    $persons = array();
    foreach ($res as $p) {
        $data = churchcore_getUserSettings("churchservice", $p->person_id);
        // if person has rights and has not deselected info emails
        $auth = getUserAuthorization($p->person_id);
        if (isset($auth["churchservice"]["view"]) && (!isset($data["informLeader"]) || $data["informLeader"])) {
            if (!isset($data["informLeader"])) {
                $data["informLeader"] = 1;
                churchcore_saveUserSetting("churchservice", $p->person_id, "informLeader", "1");
            }
            if (empty($persons[$p->person_id])) {
                $persons[$p->person_id] = array("group" => array(), "service" => array(), "person" => $p);
            }
            $persons[$p->person_id]["group"][] = $p->gruppe_id;
        }
    }
    // who should get an email?
    foreach ($persons as $person_id => $p) {
        if (!ct_checkUserMail($person_id, "informLeaderService", -1, 6 * 24)) {
            $persons[$person_id] = null;
            // unset($persons[$person_id])?
        }
    }
    // get matching services
    // TODO: nearly the same request as above (additonal bezeichnung, id service_id)
    $res = db_query("SELECT cdb_gruppen_ids, bezeichnung, id AS service_id\n                   FROM {cs_service}\n                   WHERE cdb_gruppen_ids is not null");
    foreach ($res as $d) {
        $group_ids = explode(",", $d->cdb_gruppen_ids);
        foreach ($persons as $key => $person) {
            if ($person) {
                foreach ($person["group"] as $person_group) {
                    if (in_array($person_group, $group_ids)) {
                        $persons[$key]["service"][] = $d->service_id;
                    }
                }
            }
        }
    }
    // get events for each person
    // TODO: add DAYS_TO_INFORM_LEADER_ABOUT_OPEN_SERVICES to $conf?
    foreach ($persons as $person_id => $person) {
        if ($person) {
            $res = db_query("SELECT es.id, c.bezeichnung AS event,\n                       DATE_FORMAT(e.startdate, '%d.%m.%Y %H:%i') AS datum, es.name, s.bezeichnung AS service\n                     FROM {cs_event} e, {cs_eventservice} es, {cs_service} s, {cc_cal} c\n                     WHERE e.valid_yn=1 AND c.id=e.cc_cal_id AND es.service_id in (" . db_implode($person["service"]) . ")\n                       AND es.event_id = e.id AND es.service_id = s.id AND es.valid_yn = 1 AND zugesagt_yn = 0\n                       AND e.startdate > current_date AND DATEDIFF(e.startdate,CURRENT_DATE) <= " . DAYS_TO_INFORM_LEADER_ABOUT_OPEN_SERVICES . "\n                     ORDER BY e.startdate");
            $openServices = array();
            foreach ($res as $s) {
                $openServices[] = $s;
            }
            if (count($openServices)) {
                $data = array('moreInfoUrl' => "{$base_url}?q=churchservice", 'settingsUrl' => "{$base_url}?q=churchservice#SettingsView", 'openServices' => $openServices, 'surname' => $person["person"]->vorname, 'nickname' => $person["person"]->spitzname ? $person["person"]->spitzname : $person["person"]->vorname, 'name' => $person["person"]->name);
                $lang = getUserLanguage($person["person"]->person_id);
                $content = getTemplateContent('email/openServicesLeaderInfo', 'churchservice', $data, null, $lang);
                churchservice_send_mail("[" . getConf('site_name') . "] " . t2($lang, 'open.services'), $content, $person["person"]->email);
            }
        }
    }
}
/**
 * Delete CS-Event, inform people about deleted event and delete calendar entry
 *
 * @param $params["id"] id of Event
 * @param $params["informDeleteEvent"] 1=inform people. Default=0
 * @param $params["deleteCalEntry"] 1=delete Calender entry. Default=0
 * @throws CTException if Event or Calender Entry could not be found
 * @throws CTNoPermission
 */
function churchservice_deleteEvent($params)
{
    global $user;
    if (!user_access("edit events", "churchservice")) {
        throw new CTNoPermission("edit events", "churchservice");
    }
    ct_log("[ChurchService] " . t('remove.event'), 2, $params["id"], "service");
    $db_event = db_query("SELECT e.*, DATE_FORMAT(e.startdate, '%d.%m.%Y %H:%i') AS date_de\n                        FROM {cs_event} e\n                        WHERE id=:event_id", array(":event_id" => $params["id"]))->fetch();
    if (!$db_event) {
        if ($params["id"]) {
            throw new CTException("deleteEvent(" . $params["id"] . "): " . t('x.not.found', t('event')));
        } else {
            return;
        }
    }
    // Inform people about the deleted event
    if (getVar("informDeleteEvent", false, $params)) {
        $db_cal = db_query("SELECT * FROM {cc_cal}\n                        WHERE id=:cal_id AND DATEDIFF(startdate, now())>=0", array(":cal_id" => $db_event->cc_cal_id))->fetch();
        if ($db_cal != false) {
            $db = db_query("SELECT p.id p_id, p.vorname, p.name, IF(p.spitzname, p.spitzname, p.vorname) AS nickname, p.email FROM {cs_eventservice} es, {cdb_person} p\n                      WHERE event_id = :event_id AND valid_yn = 1 AND p.id = es.cdb_person_id\n                        AND es.cdb_person_id IS NOT NULL AND p.email != ''", array(":event_id" => $params["id"]));
            foreach ($db as $p) {
                $lang = getUserLanguage($p->p_id);
                $subject = "[" . getConf('site_name') . "] " . t2($lang, 'cancelation.of.event.date', $db_cal->bezeichnung, $db_event->date_de);
                $data = array('person' => $p, 'eventTitle' => $db_cal->bezeichnung, 'eventDate' => $db_event->date_de);
                // Deine Dienstanfrage wurde entsprechend entfernt.'
                $content = getTemplateContent('email/eventDeleted', 'churchservice', $data, null, $lang);
                churchservice_send_mail($subject, $content, $p->email);
            }
        }
    }
    if (getVar("deleteCalEntry", 1, $params) == 1) {
        db_query("DELETE FROM {cs_eventservice}\n              WHERE event_id=:event_id", array(":event_id" => $params["id"]), false);
        db_query("DELETE FROM {cs_event}\n              WHERE id=:event_id", array(":event_id" => $params["id"]), false);
    } else {
        db_query("UPDATE {cs_event} SET valid_yn=0\n              WHERE id=:id", array(":id" => $params["id"]));
    }
}
/**
 * inform leader about new or changed group member and sends an additional text if available
 *
 * @param int $group_id, group ID
 * @param int $p_id, person ID
 * @param string $add_text, additional text
 */
function informLeaderAboutMembershipChange($groupId, $pId, $changeType, $additionalText = false)
{
    global $base_url, $user;
    $mt = getGroupMemberTypes();
    // Get involved person (pId) and all Leaders in Group
    $res = db_query("\n      SELECT p.name, p.vorname, p.spitzname, p.email, p.id p_id, p.lastlogin, gp.id gp_id, gpg.status_no, g.bezeichnung,\n        DATE_FORMAT(gpg.letzteaenderung, '%d.%m.%Y') letzteaenderung, cmsuserid, gpg.comment\n      FROM {cdb_person} p, {cdb_gemeindeperson} gp, {cdb_gemeindeperson_gruppe} gpg, {cdb_gruppe} g\n      WHERE p.id=gp.person_id AND gp.id=gpg.gemeindeperson_id AND g.id=gpg.gruppe_id\n        AND gpg.gruppe_id=:groupId AND\n        (p.id = :pId OR (NOT ISNULL(p.lastlogin) AND gpg.status_no BETWEEN 1 AND 3 AND p.email > ''))", array(':pId' => $pId, ':groupId' => $groupId));
    foreach ($res as $p) {
        $persons[$p->p_id] = $p;
    }
    foreach ($persons as $p) {
        // if person had logged in in the past and is one of leader(1), coleader(2) or supervisor(3)
        // and it was not changed by current user
        // and if delete a person, the person himselves should not be informed about his deletion!
        if (!empty($p->lastlogin) && $p->status_no >= 1 && $p->status_no <= 3 && $p->p_id != $user->id && ($changeType != "delete" || $p->p_id != $pId)) {
            $data = array('title' => $mt[$p->status_no]["bezeichnung"], 'userIsSupervisor' => $p->status_no == 3, 'groupName' => $p->bezeichnung, 'memberType' => $mt[$persons[$pId]->status_no]["bezeichnung"], 'member' => $persons[$pId], 'changeType' => $changeType, 'additionalText' => $additionalText, 'gotoMemberUrl' => $base_url . '?q=churchdb#PersonView/searchEntry:' . $pId);
            $lang = getUserLanguage($pId);
            $content = getTemplateContent('email/groupMemberChange', 'churchdb', $data, null, $lang);
            churchdb_send_mail("[" . getConf('site_name') . "] " . t2($lang, 'change.in.group.x', $p->bezeichnung), $content, $p->email);
        }
    }
}
Example #9
0
/**
 * view external map (ajax)
 */
function externmapview__ajax()
{
    global $user;
    $func = getVar("func");
    $groupId = getVar("g_id");
    $surname = getVar("Vorname");
    $name = getVar("Nachname");
    $groupId = getVar("g_id");
    $email = getVar("E-Mail-Adresse");
    $fon = getVar("Telefon");
    $comment = getVar("Kommentar");
    if ($func == 'loadMasterData') {
        $res["home_lat"] = getConf('churchdb_home_lat', '53.568537');
        $res["home_lng"] = getConf('churchdb_home_lng', '10.03656');
        $res["districts"] = churchcore_getTableData("cdb_distrikt", "bezeichnung");
        $res["groups"] = getExternalGroupData();
        $res["modulespath"] = CHURCHDB;
        $res["user_pid"] = $user->id;
        $res["vorname"] = $user->vorname;
        $res = jsend()->success($res);
    } else {
        if ($func == 'addPersonGroupRelation') {
            include_once CHURCHDB . '/churchdb_ajax.php';
            $res = churchdb_addPersonGroupRelation($user->id, $groupId, -2, null, null, null, t("request.by.external.mapview"));
            sendConfirmationMail($user->email, $user->vorname, $groupId);
            $res = jsend()->success($res);
        } else {
            if ($func == 'editPersonGroupRelation') {
                include_once CHURCHDB . '/churchdb_ajax.php';
                $res = _churchdb_editPersonGroupRelation($user->id, $groupId, -2, null, "null", t("request.changed.by.external.mapview"));
                sendConfirmationMail($user->email, $user->vorname, $groupId);
                $res = jsend()->success($res);
            } else {
                if ($func == 'sendEMail') {
                    $db = db_query('SELECT * FROM {cdb_person}
                    WHERE UPPER(email) LIKE UPPER(:email) AND UPPER(vorname) LIKE UPPER(:vorname) AND UPPER(name) LIKE UPPER(:name)', array(':email' => $email, ':vorname' => $surname, ':name' => $name))->fetch();
                    $txt = "";
                    if ($db) {
                        include_once CHURCHDB . '/churchdb_ajax.php';
                        churchdb_addPersonGroupRelation($db->id, $groupId, -2, null, null, null, t("request.by.external.mapview") . ": {$comment}");
                        sendConfirmationMail($email, $surname, $groupId);
                        $txt = t("person.found.and.request.sent");
                    } else {
                        $res = db_query("SELECT vorname, p.id id, g.bezeichnung\n                       FROM {cdb_gemeindeperson_gruppe} gpg, {cdb_gemeindeperson} gp, {cdb_person} p, {cdb_gruppe} g\n                       WHERE gpg.gemeindeperson_id = gp.id AND gp.person_id = p.id AND g.id = :gruppe_id\n                         AND gpg.gruppe_id = g.id AND email!='' AND gpg.status_no BETWEEN 1 AND 3 ", array(":gruppe_id" => $groupId));
                        $rec = array();
                        foreach ($res as $p) {
                            $rec[] = $p->vorname;
                            $data = array('title' => t('request.to.group', $p->bezeichnung), 'request' => array('surname' => $surname, 'name' => $name, 'email' => $email, 'phone' => $fon, 'comment' => $comment));
                            $lang = getUserLanguage($p->id);
                            $content = getTemplateContent('email/groupRequest', 'churchdb', $data, null, $lang);
                            $res = churchcore_sendEMailToPersonIDs($p->id, "[" . getConf('site_name') . "] " . t2($lang, 'form.request.to.group', $p->bezeichnung), $content, getConf('site_mail'), true, true);
                        }
                        if (!count($rec)) {
                            $txt = t("could.not.find.group.leader.please.try.other.ways");
                        } else {
                            $txt = t2($lang, "email.send.to", implode($rec, ", "));
                            sendConfirmationMail($email, $surname, $groupId);
                        }
                    }
                    $res = jsend()->success($txt);
                } else {
                    $res = jsend()->fail(t("unknown.call", $func));
                }
            }
        }
    }
    drupal_json_output($res);
}
Example #10
0
function churchcal_saveSplittedEvent($params)
{
    global $user;
    $res = new stdClass();
    // if no splitDate given it is a new event without impact
    if (!isset($params["splitDate"])) {
        throw new CTException("saveSplittedEvent: splitDate not given!");
    }
    $splitDate = new DateTime($params["splitDate"]);
    $untilEnd_yn = $params["untilEnd_yn"];
    $pastEventId = $params["pastEvent"]["id"];
    // Get originEvent out of Database
    $dummy = churchcal_getCalPerCategory(array("category_ids" => array(0 => $params["pastEvent"]["category_id"])));
    $originEvent = (array) $dummy[$params["pastEvent"]["category_id"]][$params["newEvent"]["old_id"]];
    // Copy all entries from past to new event, cause CR und CS does not have all infos and doesn't need it :)
    $pastEventDB = db_query("SELECT bezeichnung, ort, notizen, link, intern_yn, category_id  " . "FROM {cc_cal} WHERE id = :id ", array(":id" => $pastEventId))->fetch();
    if ($pastEventDB != false) {
        foreach ($pastEventDB as $key => $entry) {
            if (empty($params["pastEvent"][$key])) {
                $params["pastEvent"][$key] = $entry;
            }
            if (empty($params["newEvent"][$key])) {
                $params["newEvent"][$key] = $entry;
            }
        }
    }
    // Save new Event without impact on CS and CR ...
    $res = churchcal_createEvent($params["newEvent"], false, true);
    // ... and now bind related bookings and services to the new event
    $newEventId = $res["id"];
    $params["newEvent"]["id"] = $newEventId;
    if (churchcore_isModuleActivated("churchservice")) {
        include_once './' . CHURCHSERVICE . '/churchservice_db.php';
        churchservice_rebindServicesToNewEvent($pastEventId, $newEventId, $splitDate, $untilEnd_yn);
        $params["newEvent"]["cal_id"] = $newEventId;
        $startdate = new Datetime($params["newEvent"]["startdate"]);
        if ($splitDate->format("Y-m-d H:i") != $startdate->format("Y-m-d H:i")) {
            $params["newEvent"]["old_startdate"] = $splitDate;
        }
        churchservice_operateEventFromChurchCal($params["newEvent"]);
    }
    // Save old Event
    churchcal_updateEvent($params["pastEvent"], false, true);
    if (getVar("informCreator", "true", $params["newEvent"]) == "true" && $originEvent["modified_pid"] != $user->id) {
        $data = (array) churchcal_getEventChangeImpact(array("newEvent" => $params["newEvent"], "originEvent" => $originEvent, "pastEvent" => $params["pastEvent"]));
        $data["caption"] = $params["newEvent"]["bezeichnung"];
        $data["startdate"] = churchcore_stringToDateDe($params["newEvent"]["startdate"]);
        $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("id" => $newEventId, "bookingIds" => $res["bookingIds"]);
}
Example #11
0
        $userLang = $_COOKIE['storedlang'];
    } else {
        if (!empty($_COOKIE['storedsesslang'])) {
            $userLang = $_COOKIE['storedsesslang'];
        }
    }
}
// Load available languages
require 'languages/languages.php';
// Get the default language as defined as the default by config.php
$defaultLang = $config->getDefaultLanguage();
if (!isset($languages[$defaultLang])) {
    $defaultLang = 'en';
}
// Negotiate language
$userLang = getUserLanguage($languages, $defaultLang, $userLang);
$file = $languages[$userLang][0];
// Define the language array
$lang = array();
// XXX: this shouldn't be necessary
// ^ i.e. just require english.php, then the desired language
// Reload english to get untranslated strings
require 'languages/english.php';
// Reload the default language
require 'languages/' . $file . '.php';
$vars['language_code'] = $userLang;
$url = '?' . buildQuery($_GET + $_POST);
$vars['language_form'] = '<form action="' . $url . '" method="post" id="langform">';
$vars['language_select'] = '<select name="langchoice" onchange="javascript:this.form.submit();">';
foreach ($languages as $code => $names) {
    $sel = $code == $userLang ? '" selected="selected' : '';
/**
 * update event service
 *
 * @param array $params
 * @throws CTNoPermission
 * @return array
 */
function churchservice_updateEventService($params)
{
    global $user, $base_url;
    $id = $params["id"];
    $name = isset($params["name"]) ? $params["name"] : null;
    $cdb_person_id = isset($params["cdb_person_id"]) ? $params["cdb_person_id"] : null;
    $reason = isset($params["reason"]) ? $params["reason"] : null;
    $zugesagt_yn = $params["zugesagt_yn"];
    include_once CHURCHSERVICE . "/churchservice_db.php";
    $res = array();
    if ($name == "null") {
        $name = null;
    }
    if ($cdb_person_id == "null") {
        $cdb_person_id = null;
    }
    // look if event is still valid
    $arr = db_query("SELECT * FROM {cs_eventservice}\n                   WHERE id=:id", array(":id" => $id))->fetch();
    if (!$arr) {
        return "Eintrag nicht gefunden, id nicht g�ltig!";
    }
    if ($arr->valid_yn != 1 && !isset($params["valid_yn"])) {
        return "Eintrag konnte nicht angepasst werden, da veraltet. Bitte neu laden!";
    }
    // check auth
    $auth = churchservice_getAuthorization();
    // Es ist trotzdem erlaubt, wenn die PersonId eingetragen ist, dann wurde er ja angefragt
    if (!isset($auth["editservice"][$arr->service_id]) && !isset($auth["memberservice"][$arr->service_id]) && !churchService_adminOfEvent($arr->event_id) && $arr->cdb_person_id != $user->id) {
        throw new CTNoPermission("editservice", "churchservice");
    }
    // Wenn die neue �nderung vom gleichen User kommt und noch kein Cron gelaufen ist,
    // Oder wenn valid_yn valide ist, denn dann soll es upgedates werden!
    // brauchen wir kein neuen Insert, sondern machen nur ein Update.
    // Denn wahrscheinlich war es vorher nur ein Versehen.
    // TODO: translation correct?
    // if changing user is the same as last time and cron had not yet run
    // or if valid_yn is valide (update wished), we dont need an insert, only an update,
    // because the last edit probably was a mistake
    $dt = new datetime();
    if ($arr->modified_pid == $user->id && $arr->mailsenddate == null || isset($params["valid_yn"])) {
        $valid_yn = getVar("valid_yn", 1, $params);
        db_update("cs_eventservice")->fields(array("name" => $name, "cdb_person_id" => $cdb_person_id, "valid_yn" => $valid_yn, "zugesagt_yn" => $zugesagt_yn, "reason" => $reason, "mailsenddate" => null, "modified_date" => $dt->format('Y-m-d H:i:s'), "modified_pid" => $user->id))->condition("id", $id, "=")->execute();
        $new_id = $id;
    } else {
        // new entry for edit
        $new_id = db_insert("cs_eventservice")->fields(array("event_id" => $arr->event_id, "service_id" => $arr->service_id, "valid_yn" => 1, "counter" => $arr->counter, "name" => $name, "cdb_person_id" => $cdb_person_id, "zugesagt_yn" => $zugesagt_yn, "reason" => $reason, "modified_date" => $dt->format('Y-m-d H:i:s'), "modified_pid" => $user->id))->execute();
        //if all ok set existing entry to old
        db_update("cs_eventservice")->fields(array("valid_yn" => 0))->condition("id", $id, "=")->execute();
    }
    include_once CHURCHCORE . "/churchcore_db.php";
    $leader = churchcore_getPersonById($arr->modified_pid);
    $event = db_query("SELECT e.startdate datum, c.bezeichnung FROM {cs_event} e, {cc_cal} c\n                     WHERE e.cc_cal_id=c.id and e.id=:event_id", array(":event_id" => $arr->event_id))->fetch();
    $service = churchcore_getTableData("cs_service", "", "id=" . $arr->service_id);
    if ($event && $service) {
        $subject = "[" . getConf('site_name', "ChurchTools") . "] ";
        $txt = 'nothing defined';
        // for worst case only ;-)
        $service = $service[$arr->service_id];
        $data = array('leader' => $leader, 'user' => $user, 'service' => $service, 'event' => $event, 'reason' => $reason, 'eventUrl' => $base_url . '?q=churchservice&id=' . $arr->event_id);
        if ($zugesagt_yn) {
            $data['approved'] = true;
            $subject .= t("surname.name.has.confirmed.request", $user->vorname, $user->name);
            $txt = t("surname.name.has.confirmed.service.x.on.date.event", $user->vorname, $user->name, $service->bezeichnung, $event->datum, $event->bezeichnung);
        } else {
            if ($name) {
                $data['approved'] = true;
                $subject .= t("surname.name.has.proposed.someone", $user->vorname, $user->name);
                $txt = t("surname.name.has.proposed.x.for.service.y.on.date.event", $user->vorname, $user->name, $name, $service->bezeichnung, $event->datum, $event->bezeichnung);
                $subject .= t("surname.name.has.proposed.someone", $user->vorname, $user->name);
            } else {
                $data['approved'] = true;
                $subject .= t("surname.name.has.canceled.request", $user->vorname, $user->name);
                $txt = t("surname.name.has.canceled.service.x.on.date.event", $user->vorname, $user->name, $service->bezeichnung, $event->datum, $event->bezeichnung);
            }
        }
        ct_notify("service", $arr->service_id, $txt);
        // TODO: what does leader really mean? seems not to be a groupleader but the current user? rename?
        if ($leader) {
            // send mail, if another then the inquirer himself confirmed or canceled
            //TODO: maybe use asker, better to understand for nonenglish programmers
            //TODO: test email template
            if (!empty($leader->email) && $user && $leader->id != $user->id) {
                $setting = churchcore_getUserSettings("churchservice", $leader->id);
                if (isset($setting["informInquirer"]) && $setting["informInquirer"] == 1) {
                    $txt = $base_url . '?q=churchservice&id=' . $arr->event_id;
                    $lang = getUserLanguage($leader->id);
                    $content = getTemplateContent('email/serviceRequest', 'churchservice', $data, null, $lang);
                    churchservice_send_mail($subject, $content, $leader->email);
                }
            }
            if (!isset($setting["informInquirer"])) {
                churchcore_saveUserSetting("churchservice", $leader->id, "informInquirer", 0);
            }
        }
    }
    $arr = db_query("SELECT es.*, concat(p.vorname,' ',p.name) as modifieduser FROM {cs_eventservice} es, {cdb_person} p\n                    WHERE p.id=es.modified_pid and es.id=:id", array(":id" => $new_id))->fetch();
    $res["eventservice"] = churchservice_extractEventServiceData($arr);
    $res["result"] = true;
    return $res;
}
/**
 * TODO: too much code in churchresource_updateBooking, split it up
 * FIXME: the changes for using email template are breaking logging in case no email is send
 * otherwise logging of complete mails dont seems useful => only log important things in a short text?
 *
 * @param array $params
 * @return multitype:multitype:unknown
 */
function churchresource_updateBooking($params, $sendEMails = true)
{
    global $base_url, $user;
    $oldBooking = getBooking($params["id"]);
    $bUser = churchcore_getPersonById($oldBooking->person_id);
    $ressources = churchcore_getTableData("cr_resource", "resourcetype_id,sortkey,bezeichnung");
    $i = new CTInterface();
    $i->setParam("resource_id");
    $i->setParam("status_id");
    $i->addTypicalDateFields();
    $i->setParam("text", false);
    $i->setParam("location", false);
    $i->setParam("note", false);
    if (empty($params["text"])) {
        $res = db_query('SELECT text FROM {cr_booking}
                     WHERE id=:id', array(":id" => $params["id"]))->fetch();
        $params["text"] = $res->text;
    }
    $i->setParam("person_id", false);
    $id = db_update("cr_booking")->fields($i->getDBInsertArrayFromParams($params))->condition("id", $params["id"], "=")->execute(false);
    $changes = null;
    $exceptions = churchcore_getTableData("cr_exception", null, "booking_id=" . $params["id"]);
    // look which exceptions are already saved in DB.
    if (isset($params["exceptions"])) {
        foreach ($params["exceptions"] as $exception) {
            $current_exc = null;
            // It is not possible to search exceptions by id, because ChurchCal Exc have other IDs
            if ($exceptions) {
                foreach ($exceptions as $e) {
                    if (churchcore_isSameDay($e->except_date_start, $exception["except_date_start"]) && churchcore_isSameDay($e->except_date_end, $exception["except_date_end"])) {
                        $current_exc = $e;
                    }
                }
            }
            if ($current_exc) {
                $exceptions[$current_exc->id]->exists = true;
            } else {
                $changes["add_exception"][] = $exception;
            }
        }
    }
    // delete removed exceptions from DB.
    if ($exceptions) {
        foreach ($exceptions as $e) {
            if (!isset($e->exists)) {
                $changes["del_exception"][] = (array) $e;
            }
        }
    }
    // get all additions
    $additions = churchcore_getTableData("cr_addition", null, "booking_id=" . $params["id"]);
    // look which additions are already saved in DB.
    if (isset($params["additions"])) {
        foreach ($params["additions"] as $addition) {
            $current_add = null;
            // It is not possible to search additions by id, because ChurchCal adds have other IDs
            if ($additions) {
                foreach ($additions as $a) {
                    if (churchcore_isSameDay($a->add_date, $addition["add_date"]) && $a->with_repeat_yn == $addition["with_repeat_yn"]) {
                        $current_add = $a;
                    }
                }
            }
            if ($current_add) {
                $additions[$current_add->id]->exists = true;
            } else {
                $changes["add_addition"][] = $addition;
            }
        }
    }
    // delete removed additions from DB.
    if ($additions) {
        foreach ($additions as $a) {
            // churchresource_delAddition($a->id);
            if (!isset($a->exists)) {
                $changes["del_addition"][] = (array) $a;
            }
        }
    }
    // save new exceptions
    $res_exceptions = array();
    $res_additions = array();
    $days = array();
    $resources = churchcore_getTableData("cr_resource");
    //TODO: only get needed resource_id
    if ($changes) {
        if (isset($changes["add_exception"])) {
            foreach ($changes["add_exception"] as $exc) {
                // Check, if exception not alreay in DB (only possible when coming from Cal)
                $db = db_query("SELECT id FROM {cr_exception}\n                        WHERE booking_id=:booking_id AND except_date_start=:start", array(":booking_id" => $params["id"], ":start" => $exc["except_date_start"]))->fetch();
                if (!$db) {
                    $id = addException($params["id"], $exc["except_date_start"], $exc["except_date_end"], $user->id);
                    if (isset($exc["id"])) {
                        $res_exceptions[$exc["id"]] = $id;
                    }
                    $days[] = $exc["except_date_start"];
                }
            }
            if ($sendEMails && getConf("churchresource_send_emails", true) && count($days) && $bUser) {
                $data = array('canceled' => true, 'surname' => $bUser->vorname, 'name' => $bUser->name, 'nickname' => $bUser->spitzname ? $bUser->spitzname : $bUser->vorname, 'user' => $user, 'resource' => $resources[$params["resource_id"]]->bezeichnung, 'booking' => $booking, 'days' => implode(", ", $days), 'person' => $bUser, 'contact' => getConf('site_mail'));
                $lang = getUserLanguage($oldBooking->person_id);
                $content = getTemplateContent('email/bookingRequest', 'churchresource', $data, null, $lang);
                churchresource_send_mail("[" . getConf('site_name') . "] " . t2($lang, 'updated.booking.request') . ": " . $params["text"], $content, $bUser->email);
            }
        }
        if (isset($changes["del_exception"])) {
            foreach ($changes["del_exception"] as $exc) {
                $db = db_query("SELECT id FROM {cr_exception}\n                        WHERE booking_id=:booking_id AND except_date_start=:start", array(":booking_id" => $params["id"], ":start" => $exc["except_date_start"]))->fetch();
                if ($db) {
                    churchresource_delException(array("id" => $db->id));
                }
            }
        }
        if (isset($changes["add_addition"])) {
            foreach ($changes["add_addition"] as $add) {
                $db = db_query("SELECT id FROM {cr_addition}\n                      WHERE booking_id=:booking_id AND add_date=:date", array(":booking_id" => $params["id"], ":date" => $add["add_date"]))->fetch();
                if (!$db) {
                    $id = addAddition($params["id"], $add["add_date"], $add["with_repeat_yn"], $user->id);
                    if (isset($add["id"])) {
                        $res_additions[$add["id"]] = $id;
                    }
                }
            }
        }
        if (isset($changes["del_addition"])) {
            foreach ($changes["del_addition"] as $add) {
                $db = db_query("SELECT id FROM {cr_addition}\n                      WHERE booking_id=:booking_id AND add_date=:date", array(":booking_id" => $params["id"], ":date" => $add["add_date"]))->fetch();
                if ($db != false) {
                    churchresource_delAddition($db->id);
                }
            }
        }
    }
    // FIXME: check logic for correct function; i am not sure what should happen exactly in which cases
    // TODO: maybe use $params as data and add further values
    $booking = getBooking($params["id"]);
    $changedFields = churchcore_getFieldChanges(getBookingFields(), $oldBooking, $booking, false);
    $data = array('enddate' => churchcore_stringToDateDe($params["enddate"]), 'startdate' => churchcore_stringToDateDe($params["startdate"]), 'resource' => $resources[$params["resource_id"]]->bezeichnung, 'changes' => str_replace("\n", "<br>", $changedFields), 'booking' => $booking, 'bookingUrl' => $base_url . "?q=churchresource&id=" . $params["id"], 'text' => $params['text'], 'note' => isset($params['location']) ? $params['location'] : "", 'pending' => $params["status_id"] == CR_PENDING, 'approved' => $params["status_id"] == CR_APPROVED && ($oldBooking->status_id != CR_APPROVED || $changedFields != null), 'canceled' => $params["status_id"] == CR_CANCELED, 'deleted' => $params["status_id"] == CR_DELETED, 'contact' => getConf('site_mail'));
    $logInfo = ' :: ' . t('bookingX.for.resource.on.datetime', $params["text"], $resources[$params["resource_id"]]->bezeichnung, $params["startdate"], isset($params['location']) ? $params['location'] : "");
    $subject = t('booking.request.updated');
    if ($data['pending']) {
        $logInfo = t('booking.updated') . $logInfo;
    } elseif ($data['approved']) {
        $logInfo = t('booking.approved') . $logInfo;
    } elseif ($data['canceled']) {
        $logInfo = t('booking.canceled') . $logInfo;
    } elseif ($data['deleted']) {
        $logInfo = t('booking.deleted') . $logInfo;
    }
    if ($sendEMails && getConf("churchresource_send_emails", true)) {
        if (($params["status_id"] != $oldBooking->status_id || $changedFields != null) && $bUser) {
            $adminmails = explode(",", $resources[$params["resource_id"]]->admin_person_ids);
            // if current user is not resource admin OR is not the booking creating user
            if (!in_array($user->id, $adminmails) || $user->id != $bUser->id) {
                $content = getTemplateContent('email/bookingUpdated', 'churchresource', $data);
                churchresource_send_mail("[" . getConf('site_name') . "] {$subject}: " . $params["text"], $content, $bUser->email);
            }
        }
    }
    if ($changedFields) {
        cr_log("UPDATE BOOKING\n" . $logInfo, 3, $booking->id);
    }
    return array("exceptions" => $res_exceptions, "additions" => $res_additions);
}
Example #14
0
<?php

// Project:    Web Reference Database (refbase) <http://www.refbase.net>
// Copyright:  Matthias Steffens <mailto:refbase@extracts.de> and the file's
//             original author(s).
//
//             This code is distributed in the hope that it will be useful,
//             but WITHOUT ANY WARRANTY. Please see the GNU General Public
//             License for more details.
//
// File:       ./includes/locales.inc.php
// Repository: $HeadURL: http://svn.code.sf.net/p/refbase/code/trunk/includes/locales.inc.php $
// Author(s):  Jochen Wendebaum <mailto:wendebaum@users.sourceforge.net>
//
// Created:    12-Oct-04, 12:00
// Modified:   $Date: 2008-09-29 14:51:06 -0700 (Mon, 29 Sep 2008) $
//             $Author: msteffens $
//             $Revision: 1252 $
// This is the locales include file.
// It will read the locales depending on the personal settings of the currently
// logged in user or the default language, if no personal information can be found.
$locale = getUserLanguage();
// function 'getUserLanguage()' is defined in 'include.inc.php'
include 'locales/core.php';
// include the locales
Example #15
0
/**
* switch i18n to different language
*
* This function switches i18n system to a different language.
* Should be called before writing strings to other users into database.
* Use restoreLanguage() to switch back.
*
* @access   public
* @param        string  the user_id of the recipient (function will try to get preferred language from database)
* @param        string  explicit temporary language (set $uid to FALSE to switch to this language)
*/
function setTempLanguage ($uid = FALSE, $temp_language = "") {
    global $_language_domain, $DEFAULT_LANGUAGE;

    if ($uid) {
        $temp_language = getUserLanguage($uid);
    }

    if ($temp_language == "") {
        // we got no arguments, best we can do is to set system default
        $temp_language = $DEFAULT_LANGUAGE;
    }

    setLocaleEnv($temp_language, $_language_domain);
}