Skip to content

Instantly share code, notes, and snippets.

@tleilax
Created January 6, 2012 16:03
Show Gist options
  • Save tleilax/1571196 to your computer and use it in GitHub Desktop.
Save tleilax/1571196 to your computer and use it in GitHub Desktop.
Stud.IP: Fix profile tabs' creation
Index: lib/navigation/ProfileNavigation.php
===================================================================
--- lib/navigation/ProfileNavigation.php (Revision 21829)
+++ lib/navigation/ProfileNavigation.php (Arbeitskopie)
@@ -92,6 +92,10 @@
$navigation = new Navigation(_('Profil'), 'about.php');
$this->addSubNavigation('view', $navigation);
+ if (!$this->show_tabs($username)) {
+ return;
+ }
+
// avatar
$navigation = new Navigation(_('Bild'), 'edit_about.php', array('view' => 'Bild'));
$this->addSubNavigation('avatar', $navigation);
@@ -121,4 +125,57 @@
$navigation = new Navigation(_('Kategorien'), 'edit_about.php', array('view' => 'Sonstiges'));
$this->addSubNavigation('sections', $navigation);
}
+
+ /**
+ * Decides whether to display the profile's tab or not
+ *
+ * @param String $username The username of the selected profile's user
+ * @return bool Display profile's tabs if true
+ */
+ private function show_tabs($username) {
+ $user = User::findByUsername($username);
+
+ // User's own homepage
+ if ($user->user_id === $GLOBALS['user']->id and $GLOBALS['perm']->have_perm('autor')) {
+ return true;
+ }
+ // As an assigned deputy
+ if (isDeputyEditAboutActivated() and isDeputy($GLOBALS['user']->id, $user->user_id, true)) {
+ return true;
+ }
+
+ // Respect root's authority
+ if ($GLOBALS['perm']->have_perm('root')) {
+ return true;
+ }
+
+ // If user is no admin
+ if ($GLOBALS['perm']->have_perm('admin') === false) {
+ return false;
+ }
+
+ //Bin ich ein Inst_admin, und ist der user in meinem Inst Tutor oder Dozent?
+ $sth = $db->prepare("SELECT b.inst_perms FROM user_inst AS a ".
+ "LEFT JOIN user_inst AS b USING (Institut_id) ".
+ "WHERE (b.user_id = ?) AND ".
+ "(b.inst_perms = 'autor' OR b.inst_perms = 'tutor' OR ".
+ "b.inst_perms = 'dozent') AND (a.user_id = ?) AND ".
+ "(a.inst_perms = 'admin')");
+ $sth->execute(array($user->user_id, $GLOBALS['user']->id));
+ if ($sth->fetchColumn()) {
+ return true;
+ }
+
+ if (!$GLOBALS['perm']->is_fak_admin()) {
+ return false;
+ }
+
+ $sth = $db->prepare("SELECT c.user_id FROM user_inst a " .
+ "LEFT JOIN Institute b ON(a.Institut_id=b.fakultaets_id) " .
+ "LEFT JOIN user_inst c ON(b.Institut_id=c.Institut_id) " .
+ "WHERE c.inst_perms <> 'user'" .
+ "AND c.user_id=? AND a.inst_perms='admin' AND a.user_id=?");
+ $sth->execute(array($user->user_id, $GLOBALS['user']->id));
+ return (bool)$sth->fetchColumn();
+ }
}
Index: public/about.php
===================================================================
--- public/about.php (Revision 21829)
+++ public/about.php (Arbeitskopie)
@@ -188,36 +188,6 @@
$current_user->store();
}
- //Bin ich ein Inst_admin, und ist der user in meinem Inst Tutor oder Dozent?
- $admin_darf = FALSE;
- if ($perm->have_perm("root")) {
- $admin_darf = TRUE;
- } elseif ($perm->have_perm("admin")) {
- $sth = $db->prepare("SELECT b.inst_perms FROM user_inst AS a ".
- "LEFT JOIN user_inst AS b USING (Institut_id) ".
- "WHERE (b.user_id = ?) AND ".
- "(b.inst_perms = 'autor' OR b.inst_perms = 'tutor' OR ".
- "b.inst_perms = 'dozent') AND (a.user_id = ?) AND ".
- "(a.inst_perms = 'admin')");
- $sth->execute(array($user_id,$user->id));
- if ($sth->fetch()) {
- $admin_darf = TRUE;
- }
- if ($perm->is_fak_admin()) {
- $sth = $db->prepare("SELECT c.user_id FROM user_inst a " .
- "LEFT JOIN Institute b ON(a.Institut_id=b.fakultaets_id) " .
- "LEFT JOIN user_inst c ON(b.Institut_id=c.Institut_id) " .
- "WHERE c.inst_perms <> 'user'" .
- "AND c.user_id=? AND a.inst_perms='admin' AND a.user_id=?");
- $sth->execute(array($user_id,$user->id));
- if ($sth->fetch()) {
- $admin_darf = TRUE;
- }
- }
- }
-
-
-
// generische Datenfelder aufsammeln
$short_datafields = array();
$long_datafields = array();
@@ -233,23 +203,6 @@
}
}
-
-
- $show_tabs = ($user_id == $user->id && $perm->have_perm("autor"))
- || (isDeputyEditAboutActivated()
- && isDeputy($user->id, $user_id, true))
- || $perm->have_perm("root")
- || $admin_darf;
-
- // FIXME these tabs should not have been added anyway
- if (!$show_tabs) {
- foreach (Navigation::getItem('/profile') as $key => $nav) {
- if ($key != 'view') {
- Navigation::removeItem('/profile/'.$key);
- }
- }
- }
-
Navigation::activateItem('/profile/view');
// TODO this can be removed when page output is moved to a template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment