/**
  *
  * @param array $params
  * @return array with persons
  */
 public function getAllowedPeopleForCalender($params)
 {
     include_once './' . CHURCHDB . '/churchdb_db.php';
     $db = db_query("SELECT * FROM {cc_domain_auth}\n                    WHERE daten_id=:daten_id AND (auth_id=403 || auth_id=404)", array(":daten_id" => $params["category_id"]));
     $res = array();
     foreach ($db as $d) {
         if ($d->domain_type == "gruppe") {
             $g = array();
             $ids = churchdb_getAllPeopleIdsFromGroups(array($d->domain_id));
             if ($ids) {
                 foreach ($ids as $id) {
                     $p = churchdb_getPersonDetails($id);
                     if ($p != "no access") {
                         $g[] = $p;
                     }
                 }
             }
             if (count($g)) {
                 $gr = churchcore_getTableData("cdb_gruppe", null, "id=" . $d->domain_id);
                 if ($gr) {
                     $res[] = array("type" => "gruppe", "data" => $g, "bezeichnung" => $gr[$d->domain_id]->bezeichnung);
                 }
             }
         } else {
             if ($d->domain_type == "person") {
                 $p = churchdb_getPersonDetails($d->domain_id);
                 if ($p != "no access") {
                     $res[] = array("type" => "person", "data" => $p);
                 }
             }
         }
     }
     return $res;
 }
 /**
  *
  * @param array $params
  * @throws CTException
  */
 public function sendEMail($params)
 {
     global $user;
     include_once './' . CHURCHDB . '/churchdb_db.php';
     $groups = churchdb_getMyGroups($user->id, true, false);
     if (empty($groups[$params["groupid"]])) {
         throw new CTException("Group is not allowed!");
     }
     $ids = churchdb_getAllPeopleIdsFromGroups(array($params["groupid"]));
     churchcore_sendEMailToPersonIDs(implode(",", $ids), "[" . getConf('site_name') . "] " . t('message.from.x', "{$user->vorname}  {$user->name}"), $params["message"], null, true);
 }
Пример #3
0
/**
 * Wen group_id>0 dann nur die Gruppe, ansonsten hole aus allen meinen Gruppen die Daten
 * @param unknown_type $group_id
 * @return string|Ambigous <unknown, multitype:>
 */
function churchcal_getAbsents($params)
{
    global $user;
    include_once CHURCHDB . '/churchdb_db.php';
    $persons = array();
    if (isset($params["cal_ids"])) {
        $cal_ids = $params["cal_ids"];
        // Wer hat explizit Freigaben f�r den Kalender?
        $db = db_query("select * from  {cc_domain_auth} d where d.auth_id=403 and d.daten_id in (" . implode(",", $cal_ids) . ")");
        if ($db != false) {
            foreach ($db as $auth) {
                if ($auth->domain_type == "person") {
                    $persons[$auth->domain_id] = $auth->domain_id;
                } else {
                    if ($auth->domain_type == "gruppe") {
                        $allPersonIds = churchdb_getAllPeopleIdsFromGroups(array($auth->domain_id));
                        if ($allPersonIds != false) {
                            foreach ($allPersonIds as $id) {
                                $persons[$id] = $id;
                            }
                        }
                    }
                }
            }
        }
    }
    if (isset($params["person_id"])) {
        $persons[$params["person_id"]] = $params["person_id"];
    }
    $arrs = array();
    if (count($persons) > 0) {
        // Hole nun die Abwesenheit dazu
        $res = db_query("select p.id p_id, a.startdate, a.enddate, p.vorname, p.name, absent_reason_id reason_id\n             from {cs_absent} a, {cdb_person} p \n               where p.id in (" . implode(',', $persons) . ") and a.person_id=p.id");
        foreach ($res as $a) {
            $arrs[] = $a;
        }
    }
    return $arrs;
}
Пример #4
0
/**
 * get absent times
 * @param string $year
 * @return string
 */
function churchservice_getAbsents($year = null)
{
    $txt = '';
    if (user_access("view", "churchdb")) {
        $user = $_SESSION["user"];
        include_once CHURCHDB . '/churchdb_db.php';
        $groups = churchdb_getMyGroups($user->id, true, true);
        $allPersonIds = churchdb_getAllPeopleIdsFromGroups($groups);
        if (count($groups) > 0 && count($allPersonIds) > 0) {
            $sql = "SELECT p.id p_id, p.name, p.vorname, DATE_FORMAT(a.startdate, '%d.%m.') AS startdate_short,\n                DATE_FORMAT(a.startdate, '%d.%m.%Y') AS startdate, DATE_FORMAT(a.enddate, '%d.%m.%Y') AS enddate,\n                a.bezeichnung, ar.bezeichnung reason\n              FROM {cdb_person} p, {cs_absent} a, {cs_absent_reason} ar\n              WHERE a.absent_reason_id=ar.id AND p.id=a.person_id\n              AND p.id in (" . db_implode($allPersonIds) . ") ";
            if ($year == null) {
                $sql .= "AND DATEDIFF(a.startdate,NOW())>=-1 AND DATEDIFF(a.startdate,NOW())<=31";
            } else {
                $sql .= "AND (DATE_FORMAT(a.startdate, '%Y')={$year} OR DATE_FORMAT(a.enddate, '%Y')={$year})";
            }
            $sql .= "\n              ORDER BY a.startdate";
            $db = db_query($sql);
            $people = array();
            foreach ($db as $a) {
                if (!isset($people[$a->p_id])) {
                    $people[$a->p_id] = array();
                }
                $people[$a->p_id][] = $a;
            }
            if (count($people)) {
                $txt = '<ul>';
                foreach ($people as $p) {
                    $txt .= '<li>' . $p[0]->vorname . " " . $p[0]->name . ": <p>";
                    foreach ($p as $abwesend) {
                        $reason = $abwesend->bezeichnung ? $abwesend->bezeichnung . " ({$abwesend->reason})" : $abwesend->reason;
                        if ($abwesend->startdate == $abwesend->enddate) {
                            $txt .= "<small>{$abwesend->startdate} {$reason}</small><br/>";
                        } else {
                            $txt .= "<small>{$abwesend->startdate_short} - {$abwesend->enddate} {$reason}</small><br/>";
                        }
                    }
                }
                $txt .= '</ul>';
            }
        }
    }
    return $txt;
}
Пример #5
0
/**
 * if group_id is given then get only this group, else all groups user is member of
 *
 * @param $params
 * @return array
 */
function churchcal_getAbsents($params)
{
    global $user;
    include_once CHURCHDB . '/churchdb_db.php';
    $persons = array();
    // Get absents when cal_ids is given
    if ($cal_ids = getVar("cal_ids", false, $params)) {
        // who has rights for this calendar?
        $res = db_query("SELECT *\n                     FROM  {cc_domain_auth} d\n                     WHERE d.auth_id=403 AND d.daten_id IN (" . db_implode($cal_ids) . ")");
        if ($res) {
            foreach ($res as $auth) {
                if ($auth->domain_type == "person") {
                    $persons[$auth->domain_id] = $auth->domain_id;
                } else {
                    if ($auth->domain_type == "gruppe") {
                        $allPersonIds = churchdb_getAllPeopleIdsFromGroups(array($auth->domain_id));
                        if ($allPersonIds) {
                            foreach ($allPersonIds as $id) {
                                $persons[$id] = $id;
                            }
                        }
                    }
                }
            }
        }
    }
    // Get Absents when person_id is given
    if ($pid = getVar("person_id", false, $params)) {
        if ($pid == $user->id || user_access("manage absent", "churchservice") || churchdb_isPersonLeaderOfPerson($user->id, $pid)) {
            $persons[$pid] = $pid;
        } else {
            throw new CTNoPermission("manage absent");
        }
    }
    $arrs = array();
    if (count($persons)) {
        // get absences
        $res = db_query("SELECT p.id AS p_id, a.id, a.startdate, a.enddate, p.vorname, p.name, absent_reason_id AS reason_id\n                     FROM {cs_absent} a, {cdb_person} p\n                     WHERE p.id IN (" . db_implode($persons) . ") AND a.person_id=p.id");
        foreach ($res as $a) {
            $arrs[] = $a;
        }
    }
    return $arrs;
}
function churchservice_getAbsents($year = null)
{
    $txt = '';
    if (user_access("view", "churchdb")) {
        $user = $_SESSION["user"];
        include_once CHURCHDB . '/churchdb_db.php';
        $groups = churchdb_getMyGroups($user->id, true, true);
        $allPersonIds = churchdb_getAllPeopleIdsFromGroups($groups);
        if (count($groups) > 0 && count($allPersonIds) > 0) {
            $sql = "SELECT p.id p_id, p.name, p.vorname, DATE_FORMAT(a.startdate, '%d.%m.') startdate_short, DATE_FORMAT(a.startdate, '%d.%m.%Y') startdate, DATE_FORMAT(a.enddate, '%d.%m.%Y') enddate, a.bezeichnung, ar.bezeichnung reason \n                FROM {cdb_person} p, {cs_absent} a, {cs_absent_reason} ar \n              where a.absent_reason_id=ar.id and p.id=a.person_id and p.id in (" . implode(",", $allPersonIds) . ") ";
            if ($year == null) {
                $sql .= "and datediff(a.enddate,now())>=-1 and datediff(a.enddate,now())<=31";
            } else {
                $sql .= "and (DATE_FORMAT(a.startdate, '%Y')={$year} or DATE_FORMAT(a.enddate, '%Y')={$year})";
            }
            $sql .= " order by a.startdate";
            $db = db_query($sql);
            $people = array();
            foreach ($db as $a) {
                if (isset($people[$a->p_id])) {
                    $absent = $people[$a->p_id];
                } else {
                    $absent = array();
                }
                $absent[] = $a;
                $people[$a->p_id] = $absent;
            }
            if (count($people) > 0) {
                $txt = '<ul>';
                foreach ($people as $p) {
                    $txt .= '<li>' . $p[0]->vorname . " " . $p[0]->name . ": <p>";
                    foreach ($p as $abwesend) {
                        $reason = $abwesend->reason;
                        if ($abwesend->bezeichnung != null) {
                            $reason = $abwesend->bezeichnung . " ({$reason})";
                        }
                        if ($abwesend->startdate == $abwesend->enddate) {
                            $txt .= '<small>' . $abwesend->startdate . " {$reason}</small><br/>";
                        } else {
                            $txt .= '<small>' . $abwesend->startdate_short . "-" . $abwesend->enddate . " {$reason}</small><br/>";
                        }
                    }
                }
                $txt .= '</ul>';
            }
            if ($year == null && user_access("view", "churchcal")) {
                $txt .= '<p style="line-height:100%" align="right"><a href="?q=churchcal&viewname=yearView">' . t("more") . '</a></p>';
            }
        }
    }
    return $txt;
}