3 * Project Admin: Module of common functions
5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2002-2004 (c) GForge Team
7 * Copyright 2011, Franck Villaume - Capgemini
8 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
9 * http://fusionforge.org/
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 Standard header to be used on all /project/admin/* pages
31 function project_admin_header($params) {
32 global $group_id, $feedback, $HTML;
34 $params['toptab'] = 'admin';
35 $params['group'] = $group_id;
37 session_require_perm('project_admin', $group_id);
39 $project = group_get_object($group_id);
40 if (!$project || !is_object($project)) {
48 $labels[] = _('Project Information');
49 $attr_r[] = array('class' => 'tabtitle', 'title' => _('General information about project. Tag, trove list, description.'));
50 $links[] = '/project/admin/?group_id='.$group_id;
52 $labels[] = _('Users and permissions');
53 $attr_r[] = array('class' => 'tabtitle', 'title' => _('Permissions management. Edit / Create roles. Assign new permissions to user. Add / Remove member.'));
54 $links[] = '/project/admin/users.php?group_id='.$group_id;
56 $labels[] = _('Tools');
57 $attr_r[] = array('class' => 'tabtitle', 'title' => _('Activate / Desactivate extensions like docman, forums, plugins.'));
58 $links[] = '/project/admin/tools.php?group_id='.$group_id;
60 $labels[] = _('Project History');
61 $attr_r[] = array('class' => 'tabtitle', 'title' => _('Show the significant change of your project.'));
62 $links[] = '/project/admin/history.php?group_id='.$group_id;
64 if(forge_get_config('use_people')) {
65 $labels[] = _('Post Jobs');
66 $attr_r[] = array('class' => 'tabtitle', 'title' => _('Hiring new people. Describe the job'));
67 $links[] = '/people/createjob.php?group_id='.$group_id;
68 $labels[] = _('Edit Jobs');
69 $attr_r[] = array('class' => 'tabtitle', 'title' => _('Edit already created available position in your project.'));
70 $links[] = '/people/?group_id='.$group_id;
73 if(forge_get_config('use_project_multimedia')) {
74 $labels[] = _('Edit Multimedia Data');
75 //TODO: set the title.
76 $attr_r[] = array('class' => 'tabtitle', 'title' => '');
77 $links[] = '/project/admin/editimages.php?group_id='.$group_id;
79 if(forge_get_config('use_project_vhost')) {
80 $labels[] = _('VHOSTs');
81 //TODO: set the title.
82 $attr_r[] = array('class' => 'tabtitle', 'title' => '');
83 $links[] = '/project/admin/vhost.php?group_id='.$group_id;
85 if(forge_get_config('use_project_database')) {
86 $labels[] = _('Database Admin');
87 //TODO: set the title.
88 $attr_r[] = array('class' => 'tabtitle', 'title' => '');
89 $links[] = '/project/admin/database.php?group_id='.$group_id;
91 if ($project->usesStats()) {
92 $labels[] = _('Stats');
93 //TODO: set the title.
94 $attr_r[] = array('class' => 'tabtitle', 'title' => '');
95 $links[] = '/project/stats/?group_id='.$group_id;
98 $params['labels'] =& $labels;
99 $params['links'] =& $links;
100 $params['attr_r'] =& $attr_r;
101 plugin_hook("groupadminmenu", $params);
102 $params['submenu'] = $HTML->subMenu($params['labels'], $params['links'], $params['attr_r']);
103 site_project_header($params);
108 Standard footer to be used on all /project/admin/* pages
112 function project_admin_footer($params=array()) {
113 site_project_footer($params);
118 The following three functions are for group
121 When changes like adduser/rmuser/change status
122 are made to a group, a row is added to audit trail
123 using group_add_history()
127 function group_get_history ($group_id=false) {
128 return db_query_params("SELECT group_history.field_name,group_history.old_value,group_history.adddate,users.user_name
129 FROM group_history,users
130 WHERE group_history.mod_by=users.user_id
131 AND group_id=$1 ORDER BY group_history.adddate DESC", array($group_id));
134 function group_add_history ($field_name,$old_value,$group_id) {
135 $group=group_get_object($group_id);
136 $group->addHistory($field_name,$old_value);
141 Nicely html-formatted output of this group's audit trail
145 function show_grouphistory ($group_id) {
147 show the group_history rows that are relevant to
151 $result=group_get_history($group_id);
152 $rows=db_numrows($result);
156 echo '<p>'._('This log will show who made significant changes to your project and when').'</p>';
159 $title_arr[]=_('Field');
160 $title_arr[]=_('Old Value');
161 $title_arr[]=_('Date');
162 $title_arr[]=_('By');
164 echo $GLOBALS['HTML']->listTableTop ($title_arr);
165 for ($i=0; $i < $rows; $i++) {
166 $field=db_result($result, $i, 'field_name');
168 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'><td>'.$field.'</td><td>';
170 if (is_numeric(db_result($result, $i, 'old_value'))) {
171 if (preg_match("/[Uu]ser/i", $field)) {
172 echo user_getname(db_result($result, $i, 'old_value'));
174 echo db_result($result, $i, 'old_value');
177 echo db_result($result, $i, 'old_value');
180 '<td>'.date(_('Y-m-d H:i'),db_result($result, $i, 'adddate')).'</td>'.
181 '<td>'.db_result($result, $i, 'user_name').'</td></tr>';
184 echo $GLOBALS['HTML']->listTableBottom();
187 echo '<p>'._('No changes').'</p>';
192 prdb_namespace_seek - check that a projects' potential db name hasn't
193 already been used. If it has - add a 1..20 to the end of it. If it
194 iterates through twenty times and still fails - namespace depletion -
198 function prdb_namespace_seek($namecheck) {
200 $query = 'SELECT * FROM prdb_dbs WHERE dbname=$1';
202 $res_dbl = db_query_params($query, array($namecheck));
204 if (db_numrows($res_dbl) > 0) {
205 //crap, we're going to have issues
208 while ((db_numrows($res_dbl) > 0) && ($curr_num < 20)) {
211 $namecheck .= $namecheck.$curr_num;
213 $res_dbl = db_query_params($query, array($namecheck));
216 // if we reached 20, then the namespace is depleted - eject eject
217 if ($curr_num == 20) {
218 exit_error(_('Failed to find namespace for database'),'home');
224 } //end prdb_namespace_seek()
226 function random_pwgen() {
227 return (substr(strtr(base64_encode(util_randbytes(9)), '+', '.'),
231 function permissions_blurb() {
232 return _('<strong>NOTE:</strong><dl><dt><strong>Project Admins (bold)</strong></dt><dd>can access this page and other project administration pages</dd><dt><strong>Release Technicians</strong></dt><dd>can make the file releases (any project admin also a release technician)</dd><dt><strong>Tool Technicians (T)</strong></dt><dd>can be assigned Bugs/Tasks/Patches</dd><dt><strong>Tool Admins (A)</strong></dt><dd>can make changes to Bugs/Tasks/Patches as well as use the /toolname/admin/ pages</dd><dt><strong>Tool No Permission (N/A)</strong></dt><dd>Developer doesn\'t have specific permission (currently equivalent to \'-\')</dd><dt><strong>Moderators</strong> (forums)</dt><dd>can delete messages from the project forums</dd><dt><strong>Editors</strong> (doc. manager)</dt><dd>can update/edit/remove documentation from the project.</dd></dl>');
237 // c-file-style: "bsd"