File: Widget_MyAdmin.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 (106 lines) | stat: -rw-r--r-- 3,455 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
<?php
/**
 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
 * Copyright 2012, 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';

/**
 * Widget_MyAdmin
 *
 * Personal Admin
 */

class Widget_MyAdmin extends Widget {
	function __construct() {
		$this->Widget('myadmin');
	}
	function getTitle() {
		return _("Pending administrative tasks");
	}
	function getContent() {
		$i = 0;
		$html_my_admin = '<table class="fullwidth">';

		if (forge_check_global_perm ('forge_admin')) {
			$res = db_query_params("SELECT count(*) AS count FROM users WHERE status='P' OR status='V' OR status='W'",array());
			$row = db_fetch_array($res);
			$pending_users = $row['count'];
			$res = db_query_params("SELECT count(*) AS count FROM users WHERE status='V' OR status='W'",array());
			$row = db_fetch_array($res);
			$validated_users = $row['count'];

			$html_my_admin .= $this->_get_admin_row(
				$i++,
				vsprintf(_('Users in <a href="%s"><strong>P</strong> (pending) Status</a>'), array("/admin/userlist.php?status=P")),
				$pending_users,
				$this->_get_color($pending_users)
			);
		}

		if (forge_check_global_perm ('approve_projects')) {
			$res = db_query_params('SELECT count(*) AS count FROM groups
			WHERE group_id > 4
			    AND status = $1
			    AND register_time > 0
			    AND is_template = 0',
				array('P'));
			$row = db_fetch_array($res);
			$pending_projects = $row['count'];

			$html_my_admin .= $this->_get_admin_row(
				$i++,
				vsprintf(_('Groups in <a href="%s"><strong>P</strong> (pending) Status</a>'), array("/admin/approve-pending.php")),
				$pending_projects,
				$this->_get_color($pending_projects)
			);
		}

		if (forge_check_global_perm ('approve_news')) {
			$old_date = time()-60*60*24*30;
			$res = db_query_params('SELECT groups.group_id,id,post_date,summary,
				group_name,unix_group_name
			FROM news_bytes,groups
			WHERE is_approved=0
			AND news_bytes.group_id=groups.group_id
			AND post_date > $1
			AND groups.status=$2
			ORDER BY post_date',
				array ($old_date, 'A')) ;
			$pending_news = db_numrows($res);

			$html_my_admin .= $this->_get_admin_row(
				$i++,
				'<a href="/news/admin">'. _("Site News Approval") .'</a>',
				$pending_news,
				$this->_get_color($pending_news)
			);
		}
		$html_my_admin .= '</table>';

		return $html_my_admin;
	}
	function _get_color($nb) {
		return $nb == 0 ? 'green' : 'orange';
	}
	function _get_admin_row($i, $text, $value, $bgcolor, $textcolor = 'white') {
		$i=$i++;
		return '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td>'. $text .'</td><td style="white-space:nowrap; width:20%; background:'. $bgcolor .'; color:'. $textcolor .'; padding: 2px 8px; font-weight:bold; text-align:center;">'. $value .'</td></tr>';
	}
}