Exemplo n.º 1
0
if (Request::get('visible_groups')) {
    $group_ids = explode(',', Request::get('visible_groups'));
} else {
    $group_ids = $this->config->getValue('Main', 'groupsvisible');
}
if (!$group_ids) {
    die($GLOBALS['EXTERN_ERROR_MESSAGE']);
} else {
    $group_ids = array_intersect($all_groups, $group_ids);
}

if (!is_array($group_ids)) {
    die($GLOBALS['EXTERN_ERROR_MESSAGE']);
}

if (!$visible_groups = get_statusgruppen_by_id($range_id, $group_ids)) {
    die($GLOBALS['EXTERN_ERROR_MESSAGE']);
}

$aliases_groups = $this->config->getValue('Main', 'groupsalias');
$order          = $this->config->getValue('Main', 'order');
$sort           = $this->config->getValue('Main', 'sort');

$query_order = array();
foreach ($sort as $key => $position) {
    if ($position > 0) {
        $query_order[$position] = $this->data_fields[$key];
    }
}
if (count($query_order) > 0) {
    ksort($query_order, SORT_NUMERIC);
    function getContent ($args = NULL, $raw = FALSE) {
        if ($raw) {
            $this->setRawOutput();
        }

        if (!$all_groups = get_all_statusgruppen($this->config->range_id)) {
            die($GLOBALS["EXTERN_ERROR_MESSAGE"]);
        } else {
            $all_groups = array_keys($all_groups);
        }

        if (!$group_ids = $this->config->getValue('Main', 'groupsvisible')) {
            die($GLOBALS["EXTERN_ERROR_MESSAGE"]);
        } else {
            $group_ids = array_intersect($all_groups, $group_ids);
        }

        if (!is_array($group_ids)) {
            die($GLOBALS["EXTERN_ERROR_MESSAGE"]);
        }

        if (!$visible_groups = get_statusgruppen_by_id($this->config->range_id, $group_ids)) {
            die($GLOBALS["EXTERN_ERROR_MESSAGE"]);
        }

        $sort = $this->config->getValue('Main', 'sort');
        $query_order = '';
        foreach ($sort as $key => $position) {
            if ($position > 0) {
                $query_order[$position] = $this->data_fields[$key];
            }
        }
        if ($query_order) {
            ksort($query_order, SORT_NUMERIC);
            $query_order = ' ORDER BY ' . implode(',', $query_order);
        }

        $grouping = $this->config->getValue("Main", "grouping");
        if (!$nameformat = $this->config->getValue('Main', 'nameformat')) {
            $nameformat = 'full_rev';
        }

        if(!$grouping) {
            $query = "SELECT DISTINCT ui.raum, ui.sprechzeiten, ui.Telefon, inst_perms, Email, aum.user_id, ";
            $query .= 'username, aum.Vorname, title_front, title_rear, ';
            $query .= $GLOBALS['_fullname_sql'][$nameformat] . " AS fullname, aum.Nachname ";
            if ($query_order != '') {
                $query .= "FROM statusgruppe_user LEFT JOIN auth_user_md5 aum USING(user_id) ";
                $query .= "LEFT JOIN user_info USING(user_id) LEFT JOIN user_inst ui USING(user_id) ";
                $query .= "WHERE statusgruppe_id IN (?) AND Institut_id = ? AND ".get_ext_vis_query()."$query_order";
            } else {
                $query .= "FROM statusgruppen s LEFT JOIN statusgruppe_user su USING(statusgruppe_id) ";
                $query .= "LEFT JOIN auth_user_md5 aum USING(user_id) ";
                $query .= "LEFT JOIN user_info USING(user_id) LEFT JOIN user_inst ui USING(user_id) ";
                $query .= "WHERE su.statusgruppe_id IN (?) AND Institut_id = ? ";
                $query .= "' AND ".get_ext_vis_query()." ORDER BY ";
                $query .= "s.position ASC, su.position ASC";
            }
            $parameters = array($this->config->getValue('Main', 'groupsvisible'), $this->config->range_id);
            $statement = DBManager::get()->prepare($query);
            $statement->execute($parameters);
            $row = $statement->fetch(PDO::FETCH_ASSOC);
            $visible_groups = array('');
        }

        // generic data fields
        $generic_datafields = $this->config->getValue('TemplateGeneric', 'genericdatafields');

        $data['data_fields'] = $this->data_fields;
        $defaultaddress = $this->config->getValue('Main', 'defaultadr');
        if (! $defaultaddress) {
           $db_out =& $row;
        }

        $content = null;
        $i = 0;
        $aliases_groups = $this->config->getValue('Main', 'groupsalias');
        foreach ($visible_groups as $group_id => $group) {
            if ($grouping) {
                if ($query_order == '') {
                    $query_order = ' ORDER BY su.position';
                }
                $query = 'SELECT ui.raum, ui.sprechzeiten, ui.Telefon, inst_perms, Email, aum.user_id, ';
                $query .= 'username, aum.Vorname, title_front, title_rear, ';
                $query .= $GLOBALS['_fullname_sql'][$nameformat] . " AS fullname, aum.Nachname ";
                $query .= 'FROM statusgruppe_user su LEFT JOIN auth_user_md5 aum USING(user_id) ';
                $query .= 'LEFT JOIN user_info USING(user_id) LEFT JOIN user_inst ui USING(user_id) ';
                $query .= "WHERE su.statusgruppe_id = ? AND ".get_ext_vis_query()." AND Institut_id = ? $query_order";

                $parameters = array($group_id, $this->config->range_id );
                $statement = DBManager::get()->prepare($query);
                $statement->execute($parameters);
                $row = $statement->fetch(PDO::FETCH_ASSOC);

                if($aliases_groups[$group_id]) {
                    $group = $aliases_groups[$group_id];
                }
            }


            if ($row !== false) {
                if($aliases_groups[$group_id]) {
                    $content['PERSONS']['GROUP'][$i]['GROUPTITLE-SUBSTITUTE'] = ExternModule::ExtHtmlReady($aliases_groups[$group_id]);
                }
                $content['PERSONS']['GROUP'][$i]['GROUPTITLE'] = ExternModule::ExtHtmlReady($group);
                $content['PERSONS']['GROUP'][$i]['GROUP-NO'] = $i + 1;

                $j = 0;
                do{
                    $visibilities = get_local_visibility_by_id($row['user_id'], 'homepage', true);
                    $user_perm = $visibilities['perms'];
                    $visibilities = json_decode($visibilities['homepage'], true);

                    if ($defaultaddress) {
                        $query = 'SELECT ui.raum, ui.sprechzeiten, ui.Telefon, inst_perms,  Email, ';
                        $query .= 'title_front, title_rear, ';
                        $query .= 'aum.user_id, username, ' . $GLOBALS['_fullname_sql'][$nameformat];
                        $query .= ' AS fullname, aum.Nachname, aum.Vorname FROM auth_user_md5 aum LEFT JOIN ';
                        $query .= 'user_info USING(user_id) LEFT JOIN ';
                        $query .= "user_inst ui USING(user_id) WHERE aum.user_id = '" . $row['user_id'];
                        $query .= "' AND ".get_ext_vis_query().' AND externdefault = 1';

                        $statement2 = DBManager::get()->prepare($query);
                        $statement2->execute();
                        $db_out = $statement2->fetch(PDO::FETCH_ASSOC);
                        //no default
                        if ($db_out === false) {
                            $query = 'SELECT ui.raum, ui.sprechzeiten, ui.Telefon, inst_perms,  Email, ';
                            $query .= 'title_front, title_rear, ';
                            $query .= 'aum.user_id, username, ' . $GLOBALS['_fullname_sql'][$nameformat];
                            $query .= ' AS fullname, aum.Nachname, aum.Vorname FROM auth_user_md5 aum LEFT JOIN ';
                            $query .= 'user_info USING(user_id) LEFT JOIN ';
                            $query .= "user_inst ui USING(user_id) WHERE aum.user_id = '" . $row['user_id'];
                            $query .= "' AND ".get_ext_vis_query()." AND Institut_id = ? " ;
                            $statement2 = DBManager::get()->prepare($query);
                            $params = array($this->config->range_id);
                            $statement2->execute($params);
                            $db_out = $statement2->fetch(PDO::FETCH_ASSOC);
                        }
                    }
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['FULLNAME'] = ExternModule::ExtHtmlReady($db_out['fullname']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['LASTNAME'] = ExternModule::ExtHtmlReady($db_out['Nachname']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['FIRSTNAME'] = ExternModule::ExtHtmlReady($db_out['Vorname']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['TITLEFRONT'] = ExternModule::ExtHtmlReady($db_out['title_front']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['TITLEREAR'] = ExternModule::ExtHtmlReady($db_out['title_rear']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['PERSONDETAIL-HREF'] = $this->elements['LinkInternTemplate']->createUrl(array('link_args' => 'username='******'username']));
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['USERNAME'] = $db_out['username'];

                    if (is_element_visible_externally( $row['user_id'], $user_perm, 'picture', $visibilities['picture'])) {
                        $avatar = Avatar::getAvatar($db_out['user_id']);
                    } else {
                        $avatar = Avatar::getNobody();
                    }
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['IMAGE-URL-SMALL'] = $avatar->getURL(Avatar::SMALL);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['IMAGE-URL-MEDIUM'] = $avatar->getURL(Avatar::MEDIUM);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['IMAGE-URL-NORMAL'] = $avatar->getURL(Avatar::NORMAL);

                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['PHONE'] = ExternModule::ExtHtmlReady($db_out['Telefon']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['ROOM'] = ExternModule::ExtHtmlReady($db_out['raum']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['EMAIL'] = get_visible_email($row['user_id']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['EMAIL-LOCAL'] = array_shift(explode('@', $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['EMAIL']));
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['EMAIL-DOMAIN'] = array_pop(explode('@', $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['EMAIL']));
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['OFFICEHOURS'] = ExternModule::ExtHtmlReady($db_out['sprechzeiten']);
                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['PERSON-NO'] = $j + 1;

                    // generic data fields
                    if (is_array($generic_datafields)) {
                        $localEntries = DataFieldEntry::getDataFieldEntries($db_out['user_id'], 'user');
                        #$datafields = $datafields_obj->getLocalFields($db_out->f('user_id'));
                        $k = 1;
                        foreach ($generic_datafields as $datafield) {
                            if (isset($localEntries[$datafield]) &&
                                    is_object($localEntries[$datafield] &&
                                    is_element_visible_externally($db_out['user_id'],
                                        $user_perm, $localEntries[$datafield]->getId(),
                                        $visibilities[$localEntries[$datafield]->getId()]))) {
                                if ($localEntries[$datafield]->getType() == 'link') {
                                    $localEntry = ExternModule::extHtmlReady($localEntries[$datafield]->getValue());
                                } else {
                                    $localEntry = $localEntries[$datafield]->getDisplayValue();
                                }
                                if ($localEntry) {
                                    $content['PERSONS']['GROUP'][$i]['PERSON'][$j]['DATAFIELD_' . $k] = $localEntry;
                                }
                            }
                            $k++;
                        }
                    }
                    $j++;
                }while ($row = $statement->fetch(PDO::FETCH_ASSOC));
            }
            $i++;
        }

        return $content;
    }