File: Widget_MyProjects.class.php

package info (click to toggle)
fusionforge 5.3.2%2B20141104-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 60,472 kB
  • sloc: php: 271,846; sql: 36,817; python: 14,575; perl: 6,406; sh: 5,980; xml: 4,294; pascal: 1,411; makefile: 911; cpp: 52; awk: 27
file content (158 lines) | stat: -rw-r--r-- 4,836 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
 * Copyright 2010, Franck Villaume - Capgemini
 * Copyright 2013, French Ministry of National Education
 * Copyright 2013-2014, Franck Villaume - TrivialDev
 *
 * This file is a part of Fusionforge.
 *
 * Fusionforge is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Fusionforge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Fusionforge. If not, see <http://www.gnu.org/licenses/>.
 */

require_once 'Widget.class.php';
require_once 'common/rss/RSS.class.php';

/**
 * Widget_MyProjects
 *
 * PROJECT LIST
 */

class Widget_MyProjects extends Widget {
	function __construct() {
		$this->Widget('myprojects');
	}
	function getTitle() {
		return _("My Projects");
	}

	function getContent() {
		global $HTML;
		$html_my_projects = '';

		$user = session_get_user();
		$groups = $user->getGroups();
		sortProjectList($groups);
		$roles = RBACEngine::getInstance()->getAvailableRolesForUser($user);
		sortRoleList ($roles) ;

		if (count ($groups) < 1) {
			$html_my_projects .= '<div class="warning">'. _("You're not a member of any project") .'</div>';
		} else {
			$html_my_projects .= '<table style="width:100%">';
			$i = 0;
			$ra = RoleAnonymous::getInstance();
			foreach ($groups as $g) {
				$i++;
				$html_my_projects .= '
				<tr '. $HTML->boxGetAltRowStyle($i) .'><td style="width:99%">'.
					'<a href="/projects/'. $g->getUnixName() .'/">'.
					$g->getPublicName().'</a>';

				$isadmin = false;
				$role_names = array();
				foreach ($roles as $r) {
					if ($r instanceof RoleExplicit
						&& $r->getHomeProject() != NULL
						&& $r->getHomeProject()->getID() == $g->getID()) {
						$role_names[] = $r->getName();
						if ($r->hasPermission('project_admin', $g->getID())) {
							$isadmin = true;
						}
					}
				}
				if ($isadmin) {
					$html_my_projects .= ' <small><a href="/project/admin/?group_id='.$g->getID().'">['._("Admin").']</a></small>';
				}
				$html_my_projects .= ' <small>('.htmlspecialchars (implode (', ', $role_names)).')</small>';
				if (!$ra->hasPermission('project_read', $g->getID())) {
					$html_my_projects .= ' (*)';
					$private_shown = true;
				}
				if (!$isadmin) {
					$html_my_projects .= '</td>'.
						'<td><a href="rmproject.php?group_id='. $g->getID().
						'" onClick="return confirm(\''._("Quit this project?").'\')">'.
						'<img src="'.$GLOBALS['HTML']->imgroot.'ic/trash.png" alt="'._('Leave project').'" height="16" width="16" /></a></td></tr>';
				} else {
					$html_my_projects .= '</td><td>&nbsp;</td></tr>';
				}
			}
			$html_my_projects .= '</table>';
			if (isset($private_shown) && $private_shown) {
				$html_my_projects .= '
					<span>(*)&nbsp;<em>'._("Private project").'</em></span>';
			}

		}
		return $html_my_projects;
	}

	function hasRss() {
		return true;
	}

	function displayRss() {
		$rss = new RSS(array(
				'title'       => forge_get_config('forge_name').' - '. _('MyProjects'),
				'description' => _('My projects'),
				'link'        => get_server_url(),
				'language'    => 'en-us',
				'copyright'   => 'Copyright Xerox',
				'pubDate'     => gmdate('D, d M Y G:i:s',time()).' GMT',
			));
		$projects = UserManager::instance()->getCurrentUser()->getGroups();
		sortProjectList($projects);

		if (!$projects || count($projects) < 1) {
			$rss->addItem(array(
					  'title'       => forge_get_config('forge_name'),
					  'description' => _("You're not a member of any project") . db_error(),
					  'link'        => util_make_url()
				  ));
		}

		foreach ($projects as $project) {
			$pid = $project->getID();
			$title = $project->getPublicName();
			$url = util_make_url('/projects/' . $project->getUnixName());

			if ( !RoleAnonymous::getInstance()->hasPermission('project_read',$pid)) {
				$title .= ' (*)';
			}

			$desc = "Project: $url\n";
			if (forge_check_perm ('project_admin', $pid)) {
				$desc .= '<br />Admin: '. util_make_url('/project/admin/?group_id='.$pid);
			}

			$rss->addItem(array(
						'title'       => $title,
						'description' => $desc,
						'link'        => $url)
					);
		}
		$rss->display();
	}

	function getDescription() {
		return _("List the projects you belong to. Selecting any of these projects brings you to the corresponding Project Summary page.");
	}
}

// Local Variables:
// mode: php
// c-file-style: "bsd"
// End: