/**
  * get MasterData
  *
  * @return array with objects
  *
  */
 public function getMasterData()
 {
     global $config;
     $res = array();
     $res["auth_table_plain"] = getAuthTable();
     foreach ($res["auth_table_plain"] as $auth) {
         if ($auth->datenfeld && !isset($res[$auth->datenfeld])) {
             $res[$auth->datenfeld] = churchcore_getTableData($auth->datenfeld);
         }
     }
     $res["modules"] = churchcore_getModulesSorted(true, false);
     $res["person"] = churchcore_getTableData("cdb_person", "name, vorname", null, "id, concat(name, ', ', vorname) as bezeichnung");
     $res["person"][-1] = new stdClass();
     $res["person"][-1]->id = -1;
     $res["person"][-1]->bezeichnung = "- " . t("public.user") . " -";
     $res["publiccalendar_name"] = getConf("churchcal_maincalname", "Church Calendar");
     $res["gruppe"] = churchcore_getTableData("cdb_gruppe", null, null, "id, bezeichnung");
     $res["status"] = churchcore_getTableData("cdb_status");
     $res["category"] = churchcore_getTableData("cc_calcategory", null, null, "id, bezeichnung, privat_yn, oeffentlich_yn");
     $res["modulename"] = "churchcore";
     $res["admins"] = $config["admin_ids"];
     $auths = churchcore_getTableData("cc_domain_auth");
     if ($auths) {
         foreach ($auths as $auth) {
             $domaintype = array();
             // initalize $res[domain_tye]
             if (isset($res[$auth->domain_type])) {
                 $domaintype = $res[$auth->domain_type];
             }
             $object = new stdClass();
             if (isset($domaintype[$auth->domain_id])) {
                 $object = $domaintype[$auth->domain_id];
             } else {
                 $object->id = $auth->domain_id;
                 if (isset($db[$auth->domain_type][$auth->domain_id])) {
                     $object->bezeichnung = $db[$auth->domain_type][$auth->domain_id]->bezeichnung;
                 } else {
                     $object->bezeichnung = t("non.existent");
                 }
             }
             if ($auth->daten_id == null) {
                 $object->auth[$auth->auth_id] = $auth->auth_id;
             } else {
                 if (!isset($object->auth[$auth->auth_id])) {
                     $object->auth[$auth->auth_id] = array();
                 }
                 $object->auth[$auth->auth_id][$auth->daten_id] = $auth->daten_id;
             }
             $domaintype[$auth->domain_id] = $object;
             $res[$auth->domain_type] = $domaintype;
         }
     }
     foreach (churchcore_getModulesSorted() as $name) {
         if (isset($config[$name . "_name"])) {
             $res["names"][$name] = $config[$name . "_name"];
         }
     }
     return $res;
 }
Exemplo n.º 2
0
/**
 *
 * @param int $user_id
 * @return auth
 */
function getUserAuthorization($user_id)
{
    global $config;
    $auth = null;
    if ($user_id == null) {
        return null;
    }
    $auth_table = getAuthTable();
    $IamAdmin = false;
    if (in_array($user_id, $config["admin_ids"])) {
        $IamAdmin = true;
    }
    // Wenn ich in den Admin-Mails bin, dann schuster ich mir alle Rechte zu, die der Admin sehen darf
    if ($IamAdmin) {
        foreach ($auth_table as $entry) {
            if ($entry->admindarfsehen_yn == 1) {
                if ($entry->datenfeld == null) {
                    $auth[$entry->modulename][$entry->auth] = true;
                } else {
                    $res2 = db_query("SELECT id FROM {" . $entry->datenfeld . "}");
                    $auth2 = null;
                    foreach ($res2 as $entry2) {
                        $auth2[$entry2->id] = $entry2->id;
                    }
                    $auth[$entry->modulename][$entry->auth] = $auth2;
                }
                $auth[$entry->modulename]["view"] = true;
            }
        }
    }
    // F�r normale Benutzer und bei Admins nach Where nur die, wo es nicht f�r Admin alles gibt.
    // Autorisierung �ber direkte Personenzuordnung
    $res = db_query("SELECT daten_id, auth_id\n                   FROM {cc_domain_auth} pa\n                   WHERE pa.domain_type='person' AND pa.domain_id=:id", array(':id' => $user_id));
    $auth = _implantAuth($auth_table, $IamAdmin, $res, $auth);
    // Autorisierung �ber Status
    $res = db_query("SELECT daten_id, auth_id\n                   FROM {cdb_gemeindeperson} gp, {cc_domain_auth} da\n                   WHERE da.domain_type='status' AND da.domain_id=gp.status_id AND gp.person_id=:id", array(':id' => $user_id));
    $auth = _implantAuth($auth_table, $IamAdmin, $res, $auth);
    // Autorisierung �ber Gruppen
    $res = db_query("SELECT daten_id, auth_id\n                   FROM {cdb_gemeindeperson} gp, {cdb_gemeindeperson_gruppe} gpg, {cc_domain_auth} da\n                   WHERE da.domain_type='gruppe' and gpg.gemeindeperson_id=gp.id and gpg.status_no>=0\n                     AND da.domain_id=gpg.gruppe_id and gp.person_id=:id", array(':id' => $user_id));
    $auth = _implantAuth($auth_table, $IamAdmin, $res, $auth);
    // Wenn es kein Anonymous ist
    if ($user_id > 0) {
        $auth["home"]["view"] = true;
        $auth["logout"]["view"] = true;
        $auth["login"]["view"] = true;
        $auth["profile"]["view"] = true;
        $auth["help"]["view"] = true;
        $auth["cron"]["view"] = true;
        $auth["ical"]["view"] = true;
        $auth["churchauth"]["view"] = true;
        if (isset($auth["churchcore"]) && isset($auth["churchcore"]["administer persons"])) {
            $auth["simulate"]["view"] = true;
        }
        if (isset($auth["churchcore"]) && isset($auth["churchcore"]["administer settings"])) {
            $auth["admin"]["view"] = true;
        }
        if (isset($auth["churchcore"]) && isset($auth["churchcore"]["view logfile"])) {
            $auth["churchcore"]["view"] = true;
        }
        if (isset($_SESSION["simulate"])) {
            $auth["simulate"]["view"] = true;
        }
    }
    return $auth;
}
/**
 * get auth table
 * @return array
 */
function churchdb_getAuthTable()
{
    $res = getAuthTable();
    $auth = null;
    foreach ($res as $entry) {
        $auth[$entry->modulename][$entry->auth] = $entry;
    }
    return $auth;
}