Esempio n. 1
0
 function getInstitutInformations()
 {
     $institutes = UserModel::getUserInstitute($this->current_user->user_id);
     foreach ($institutes as $id => $inst_result) {
         if ($inst_result['visible'] == 1) {
             $entries = DataFieldEntry::getDataFieldEntries(array($this->current_user->user_id, $inst_result['Institut_id']));
             if (!empty($entries)) {
                 foreach ($entries as $entry) {
                     $view = $entry->isVisible(null, false);
                     $show_star = false;
                     if (!$view && $entry->isVisible()) {
                         $view = true;
                         $show_star = true;
                     }
                     if (trim($entry->getValue()) && $view) {
                         $institutes[$id]['datafield'][] = array('name' => $entry->getName(), 'value' => $entry->getDisplayValue(), 'show_star' => $show_star);
                     }
                 }
             }
             $institutes[$id]['role'] = Statusgruppen::getUserRoles($inst_result['Institut_id'], $this->current_user->user_id);
         } else {
             unset($institutes[$id]);
         }
     }
     return $institutes;
 }
    private function getContent ($args = NULL, $raw = FALSE) {
        $instituts_id = $this->config->range_id;
        $username = $args['username'];
        $sem_id = $args['seminar_id'];

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

        $row = false;
        $global_view = false;
        $dbv = new DbView();
        if (in_array(get_object_type($this->config->range_id), array('fak', 'global'))) {
            $global_view = true;
            $selected_item_ids = $this->config->getValue('SelectInstitutes', 'institutesselected');
            // at least one institute has to be selected in the configuration
            if (!is_array($selected_item_ids)) {
                return array();
            }
            // is user lecturer ?
            if ($this->config->getValue('Main', 'onlylecturers')) {
                $current_semester = get_sem_num(time());
                $stm = DBManager::get()->prepare(sprintf(
                    "SELECT aum.user_id "
                    . "FROM auth_user_md5 aum "
                    . "LEFT JOIN seminar_user su USING(user_id) "
                    . "LEFT JOIN seminare s USING (seminar_id) "
                    . "LEFT JOIN user_inst ui ON aum.user_id = ui.user_id "
                    . "WHERE aum.username = ? "
                    . "AND su.status = 'dozent' "
                    . "AND s.visible = 1 "
                    . "AND ((%s) = %s OR ((%s) <= %s  AND ((%s) >= %s OR (%s) = -1))) "
                    . "AND ui.Institut_id IN ('%s') "
                    . "AND ui.inst_perms = 'dozent' "
                    . "AND ui.externdefault = 1 "
                    . "AND %s",
                    $dbv->sem_number_sql,
                    $current_semester,
                    $dbv->sem_number_sql,
                    $current_semester,
                    $dbv->sem_number_end_sql,
                    $current_semester,
                    $dbv->sem_number_end_sql,
                    implode("','", $selected_item_ids),
                    get_ext_vis_query()));
                $stm->execute(array($username));
                // user is not a lecturer
                if (!$row = $stm->fetch()) {
                    return array();
                }
            } else {
                // have user the status dozent at an institute in the list of accepted institutes
                $stm = DBManager::get()->prepare(sprintf(
                    "SELECT aum.user_id "
                    . "FROM auth_user_md5 aum "
                    . "LEFT JOIN user_inst ui USING(user_id) "
                    . "WHERE aum.username = ? "
                    . "AND ui.Institut_id IN ('%s') "
                    . "AND ui.externdefault = 1 "
                    . "AND %s",
                    implode("','", $selected_item_ids), get_ext_vis_query()));
                $stm->execute(array($username));
                // user is not dozent at an institute that is in the list of accepted institutes
                if (!$row = $stm->fetch()) {
                    return array();
                }
            }
        }

        $row = false;

        // Mitarbeiter/in am Institut
        $stm_inst = DBManager::get()->prepare(
            "SELECT i.Institut_id "
            . "FROM Institute i "
            . "LEFT JOIN user_inst ui USING(Institut_id) "
            . "LEFT JOIN auth_user_md5 aum USING(user_id) "
            . "WHERE i.Institut_id = ? "
            . "AND aum.username = ? AND ui.inst_perms IN ('autor','tutor','dozent') AND " . get_ext_vis_query());
        $stm_inst->execute(array($instituts_id, $username));

        // Mitarbeiter/in am Heimatinstitut des Seminars
        if (!$row = $stm_inst->fetch(PDO::FETCH_ASSOC) && $sem_id) {
            $stm_inst = DBManager::get()->prepare(
                "SELECT s.Institut_id "
                . "FROM seminare s "
                . "LEFT JOIN user_inst ui USING(Institut_id) "
                . "LEFT JOIN auth_user_md5 aum USING(user_id) "
                . "WHERE s.Seminar_id = ? "
                . "AND aum.username = ? AND ui.inst_perms = 'dozent' AND " . get_ext_vis_query());
            $stm_inst->execute(array($sem_id, $username));
            if ($row = $stm_inst->fetch(PDO::FETCH_ASSOC)) {
                $instituts_id = $row['Institut_id'];
            }
        }

        // an beteiligtem Institut Dozent(in)
        if (!$row && $sem_id) {
            $stm_inst = DBManager::get()->prepare(
                "SELECT si.institut_id "
                . "FROM seminare s "
                . "LEFT JOIN seminar_inst si ON(s.Seminar_id = si.seminar_id) "
                . "LEFT JOIN user_inst ui ON(si.institut_id = ui.Institut_id) "
                . "LEFT JOIN auth_user_md5 aum USING(user_id) "
                . "WHERE s.Seminar_id = ? "
                . "AND si.institut_id != ? AND ui.inst_perms = 'dozent' AND aum.username = ? AND " . get_ext_vis_query());
            $stm_inst->execute(array($sem_id, $intituts_id, $username));
            if ($row = $stm_inst->fetch(PDO::FETCH_ASSOC)) {
                $instituts_id = $row['institut_id'];
            }
        }

        // ist zwar global Dozent, aber an keinem Institut eingetragen
        if (!$row && $sem_id) {
            $stm = DBManager::get()->prepare(sprintf(
                "SELECT aum.*, %s AS fullname "
                . "FROM auth_user_md5 aum "
                . "LEFT JOIN user_info USING(user_id) "
                . "LEFT JOIN seminar_user su "
                . "WHERE username = ? "
                . "AND perms = 'dozent' AND su.seminar_id = ? AND su.status = 'dozent' AND %s"
                , $GLOBALS['_fullname_sql'][$nameformat], get_ext_vis_query()));
            $stm->execute(array($username, $sem_id));
            $row = $stm->fetch(PDO::FETCH_ASSOC);
        } elseif ($global_view || $this->config->getValue('Main', 'defaultaddr')) {
            $stm = DBManager::get()->prepare(sprintf(
                "SELECT i.Institut_id, i.Name, i.Strasse, i.Plz, i.url, ui.*, aum.*, "
                . "%s AS fullname, uin.user_id, uin.lebenslauf, uin.publi, uin.schwerp, "
                . "uin.Home, uin.title_front, uin.title_rear "
                . "FROM Institute i "
                . "LEFT JOIN user_inst ui USING(Institut_id) "
                . "LEFT JOIN auth_user_md5 aum USING(user_id) "
                . "LEFT JOIN user_info uin USING (user_id) "
                . "WHERE ui.inst_perms IN ('autor','tutor','dozent') "
                . "AND aum.username = ? AND ui.externdefault = 1 AND %s"
                , $GLOBALS['_fullname_sql'][$nameformat], get_ext_vis_query()));
            $stm->execute(array($username));
            $row = $stm->fetch(PDO::FETCH_ASSOC);
            if (!$row) {
                $stm = DBManager::get()->prepare(sprintf(
                    "SELECT i.Institut_id, i.Name, i.Strasse, i.Plz, i.url, ui.*, aum.*, "
                    . "%s AS fullname, uin.user_id, uin.lebenslauf, uin.publi, uin.schwerp, "
                    . "uin.Home, uin.title_front, uin.title_rear "
                    . "FROM Institute i "
                    . "LEFT JOIN user_inst ui USING(Institut_id) "
                    . "LEFT JOIN auth_user_md5 aum USING(user_id) "
                    . "LEFT JOIN user_info uin USING (user_id) "
                    . "WHERE ui.inst_perms IN ('autor','tutor','dozent') "
                    . "AND aum.username = ? AND i.Institut_id = ? AND %s"
                    , $GLOBALS['_fullname_sql'][$nameformat], get_ext_vis_query()));
                $stm->execute(array($username, $instituts_id));
                $row = $stm->fetch(PDO::FETCH_ASSOC);
            }
        } else {
            $stm = DBManager::get()->prepare(sprintf(
                "SELECT i.Institut_id, i.Name, i.Strasse, i.Plz, i.url, ui.*, aum.*, "
                . "%s AS fullname, uin.user_id, uin.lebenslauf, uin.publi, uin.schwerp, "
                . "uin.Home, uin.title_front, uin.title_rear "
                . "FROM Institute i "
                . "LEFT JOIN user_inst ui USING(Institut_id) "
                . "LEFT JOIN auth_user_md5 aum USING(user_id) "
                . "LEFT JOIN user_info uin USING (user_id) "
                . "WHERE ui.inst_perms IN ('autor','tutor','dozent') "
                . "AND aum.username = ? AND i.Institut_id = ? AND %s"
                , $GLOBALS['_fullname_sql'][$nameformat], get_ext_vis_query()));
            $stm->execute(array($username, $instituts_id));
            $row = $stm->fetch(PDO::FETCH_ASSOC);
        }

        // the user with the given username does not fulfill the conditions above
        if (!$row) {
            return array();
        }

        // Alle Einrichtungen hohlen
        $stm = DBManager::get()->prepare(sprintf(
                "SELECT i.Institut_id, i.Name, i.Strasse, i.Plz, i.url, ui.*, aum.*, "
                . "%s AS fullname, uin.user_id, uin.lebenslauf, uin.publi, uin.schwerp, "
                . "uin.Home, uin.title_front, uin.title_rear "
                . "FROM Institute i "
                . "LEFT JOIN user_inst ui USING(Institut_id) "
                . "LEFT JOIN auth_user_md5 aum USING(user_id) "
                . "LEFT JOIN user_info uin USING (user_id) "
                . "WHERE ui.inst_perms IN ('autor','tutor','dozent') "
                . "AND aum.username = ?"
                , $GLOBALS['_fullname_sql'][$nameformat]));
        $stm->execute(array($username));
        $allRows = $stm->fetchAll();
        
        $this->user_id = $row['user_id'];

        $this->user_perm = $visibilities['perms'];

        $content['__GLOBAL__']['STUDIP-EDIT-HREF'] = "{$GLOBALS['ABSOLUTE_URI_STUDIP']}dispatch.php/settings/account?username=$username&login=yes";

        $content['PERSONDETAILS']['FULLNAME'] = ExternModule::ExtHtmlReady($row['fullname']);
        $content['PERSONDETAILS']['LASTNAME'] = ExternModule::ExtHtmlReady($row['Nachname']);
        $content['PERSONDETAILS']['FIRSTNAME'] = ExternModule::ExtHtmlReady($row['Vorname']);
        $content['PERSONDETAILS']['TITLEFRONT'] = ExternModule::ExtHtmlReady($row['title_front']);
        $content['PERSONDETAILS']['TITLEREAR'] = ExternModule::ExtHtmlReady($row['title_rear']);
        if ($statusgroups = Statusgruppen::getUserRoles($instituts_id, $this->user_id)) {
            $content['PERSONDETAILS']['STATUSGROUPS'] = ExternModule::ExtHtmlReady(join(', ', array_values($statusgroups)));
        }
        $content['PERSONDETAILS']['USERNAME'] = $row['username'];
        
        $content['PERSONDETAILS']['IMAGE-HREF'] = Avatar::getAvatar($this->user_id)->getURL(Avatar::NORMAL);

        $gruppen = GetRoleNames(GetAllStatusgruppen($this->config->range_id, $row['user_id']));
        for ($i = 0; $i < sizeof($gruppen); $i++) {
            $content['PERSONDETAILS']['GROUPS'][$i]['GROUP'] = ExternModule::ExtHtmlReady($gruppen[$i]);
        }

        $content['PERSONDETAILS']['INST-NAME'] = ExternModule::ExtHtmlReady($row['Name']);
        $content['PERSONDETAILS']['INST-HREF'] = ExternModule::ExtHtmlReady(trim($row['url']));
        $content['PERSONDETAILS']['STREET'] = ExternModule::ExtHtmlReady($row['Strasse']);
        $content['PERSONDETAILS']['ZIPCODE'] = ExternModule::ExtHtmlReady($row['Plz']);
        $email = get_visible_email($this->user_id);
        $content['PERSONDETAILS']['EMAIL'] = ExternModule::ExtHtmlReady($email);
        $content['PERSONDETAILS']['EMAIL-LOCAL'] = array_shift(explode('@', $content['PERSONDETAILS']['EMAIL']));
        $content['PERSONDETAILS']['EMAIL-DOMAIN'] = array_pop(explode('@', $content['PERSONDETAILS']['EMAIL']));
        $content['PERSONDETAILS']['ROOM'] = ExternModule::ExtHtmlReady($row['raum']);
        $content['PERSONDETAILS']['PHONE'] = ExternModule::ExtHtmlReady($row['Telefon']);
        $content['PERSONDETAILS']['FAX'] = ExternModule::ExtHtmlReady($row['Fax']);
        if (Visibility::verify('homepage', $this->user_id)) {
            $content['PERSONDETAILS']['HOMEPAGE-HREF'] = ExternModule::ExtHtmlReady(trim($row['Home']));
        }
        $content['PERSONDETAILS']['OFFICE-HOURS'] = ExternModule::ExtHtmlReady($row['sprechzeiten']);

        $j = 0;
        foreach($allRows as $curRow)
        {
            $content['PERSONDETAILS']['ALL-INST']['SINGLE-INST'][$j]['SINGLE-INST-NAME'] = ExternModule::ExtHtmlReady($curRow['Name']);
            $content['PERSONDETAILS']['ALL-INST']['SINGLE-INST'][$j]['SINGLE-INST-HREF'] = ExternModule::ExtHtmlReady(trim($curRow['url']));
            $content['PERSONDETAILS']['ALL-INST']['SINGLE-INST'][$j]['SINGLE-INST-STREET'] = ExternModule::ExtHtmlReady($curRow['Strasse']);
            $content['PERSONDETAILS']['ALL-INST']['SINGLE-INST'][$j]['SINGLE-INST-ZIPCODE'] = ExternModule::ExtHtmlReady($curRow['Plz']);
            $content['PERSONDETAILS']['ALL-INST']['SINGLE-INST'][$j]['SINGLE-INST-EMAIL'] = ExternModule::ExtHtmlReady($curRow['Email']);
            $content['PERSONDETAILS']['ALL-INST']['SINGLE-INST'][$j]['SINGLE-INST-EMAIL-LOCAL'] = array_shift(explode('@', $content['PERSONDETAILS']['ALL-INST']['SINGLE-INST'][$j]['SINGLE-INST-EMAIL']));
            $content['PERSONDETAILS']['ALL-INST']['SINGLE-INST'][$j]['SINGLE-INST-EMAIL-DOMAIN'] = array_pop(explode('@', $content['PERSONDETAILS']['ALL-INST']['SINGLE-INST'][$j]['SINGLE-INST-EMAIL']));
            $content['PERSONDETAILS']['ALL-INST']['SINGLE-INST'][$j]['SINGLE-INST-ROOM'] = ExternModule::ExtHtmlReady($curRow['raum']);
            $content['PERSONDETAILS']['ALL-INST']['SINGLE-INST'][$j]['SINGLE-INST-PHONE'] = ExternModule::ExtHtmlReady($curRow['Telefon']);
            $content['PERSONDETAILS']['ALL-INST']['SINGLE-INST'][$j]['SINGLE-INST-FAX'] = ExternModule::ExtHtmlReady($curRow['Fax']);
            $content['PERSONDETAILS']['ALL-INST']['SINGLE-INST'][$j]['SINGLE-INST-HOMEPAGE-HREF'] = ExternModule::ExtHtmlReady(trim($curRow['Home']));
            $content['PERSONDETAILS']['ALL-INST']['SINGLE-INST'][$j]['SINGLE-INST-OFFICE-HOURS'] = ExternModule::ExtHtmlReady($curRow['sprechzeiten']);
            $j++;
        }
        
        // generic data fields
        if ($generic_datafields = $this->config->getValue('Main', 'genericdatafields')) {
            $localEntries = DataFieldEntry::getDataFieldEntries($this->user_id, 'user');
            $k = 1;
            foreach ($generic_datafields as $datafield) {
                if (isset($localEntries[$datafield]) &&
                        is_object($localEntries[$datafield]) &&
                        Visibility::verify($localEntries[$datafield]->getId(), $this->user_id)) {
                    if ($localEntries[$datafield]->getType() == 'link') {
                        $localEntry = ExternModule::extHtmlReady($localEntries[$datafield]->getValue());
                    } else {
                        $localEntry = $localEntries[$datafield]->getDisplayValue();
                    }
                    if ($localEntry) {
                        $content['PERSONDETAILS']["DATAFIELD_$k"] = $localEntry;
                    }
                }
                $k++;
            }
        }

        // homepage plugins
        $plugins = PluginEngine::getPlugins('HomepagePlugin');

        foreach ($plugins as $plugin) {
            $template = $plugin->getHomepageTemplate($this->user_id);

            if ($template) {
                $keyname = 'PLUGIN_' . strtoupper($plugin->getPluginName());
                $content['PERSONDETAILS'][$keyname] = $template->render();
            }
        }

        if (Visibility::verify('lebenslauf', $this->user_id)) {
            $content['PERSONDETAILS']['CV'] = ExternModule::ExtFormatReady($row['lebenslauf']);
        }
        if (Visibility::verify('schwerp', $this->user_id)) {
            $content['PERSONDETAILS']['RESEARCH-INTERESTS'] = ExternModule::ExtFormatReady($row['schwerp']);
        }
        if (Visibility::verify('publi', $this->user_id)) {
            $content['PERSONDETAILS']['PUBLICATIONS'] = ExternModule::ExtFormatReady($row['publi']);
        }

        $content['PERSONDETAILS']['LECTURES'] = $this->elements['TemplateLectures']->toString(array('content' => $this->getContentLectures(), 'subpart' => 'LECTURES'));
        if (Visibility::verify('news', $this->user_id)) {
            $content['PERSONDETAILS']['NEWS'] = $this->elements['TemplateNews']->toString(array('content' => $this->getContentNews(), 'subpart' => 'NEWS'));
        }
        if (Visibility::verify('dates', $this->user_id)) {
            $content['PERSONDETAILS']['APPOINTMENTS'] = $this->elements['TemplateAppointments']->toString(array('content' => $this->getContentAppointments(), 'subpart' => 'APPOINTMENTS'));
        }
        if (Visibility::verify('literature', $this->user_id)) {
            $content['PERSONDETAILS']['LITERATURE'] = $this->elements['TemplateLitList']->toString(array('content' => $this->elements['LitList']->getContent(array('user_id' => $this->user_id)), 'subpart' => 'LITLISTS'));
        }
        $content['PERSONDETAILS']['OWNCATEGORIES'] = $this->elements['TemplateOwnCategories']->toString(array('content' => $this->getContentOwnCategories(), 'subpart' => 'OWNCATEGORIES'));

        return $content;
    }