4 * Project Admin page to manage group's databases
6 * This page allows to request, change password of, and delete database.
7 * Group may have single database of each type that provided (e.g., mysql,
10 * Portions Copyright 1999-2001 (c) VA Linux Systems
11 * The rest Copyright 2002-2004 (c) GForge Team
12 * http://fusionforge.org/
14 * This file is part of FusionForge. FusionForge is free software;
15 * you can redistribute it and/or modify it under the terms of the
16 * GNU General Public License as published by the Free Software
17 * Foundation; either version 2 of the Licence, or (at your option)
20 * FusionForge is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License along
26 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 require_once('../../env.inc.php');
32 require_once $gfcommon.'include/pre.php';
33 require_once $gfwww.'project/admin/project_admin_utils.php';
35 if (!forge_get_config('use_project_database')) {
39 $group_id = getIntFromRequest('group_id');
40 session_require_perm ('project_admin', $group_id) ;
42 $group = group_get_object($group_id);
43 if (!$group || !is_object($group)) {
45 } else if ($group->isError()) {
46 exit_error($group->getErrorMessage(),'admin');
49 if (getStringFromRequest('createdb')) {
50 $newdbtypeid = getIntFromRequest('newdbtypeid');
52 //mysql takes issue with database names that have dashes in them - so strip the dashes, replace with ""
53 //e.g. free-mysql becomes freemysql (it's a workaround)
54 //if there is a dash in the groupname
55 $dbname = str_replace("-", "", $group->getUnixName());
57 //check there is no name double up - if there is - add an incrementing to the number to the end
59 $dbname = prdb_namespace_seek($dbname);
60 $randompw = random_pwgen();
62 $res = db_query_params("INSERT INTO prdb_dbs(group_id,dbname,dbusername,dbuserpass,requestdate,dbtype,created_by,state)
63 VALUES($1, $2, $2, $3, $4, $5, $6 ,2)", array($group_id, $dbname, $randompw, time(), $newdbtypeid, $LUSER->getID()));
65 if (!$res || db_affected_rows($res) < 1) {
66 $error_msg .= _('Cannot add database entry').': '.db_error();
69 $feedback .= _('Database scheduled for creation');
70 group_add_history('Created database '.$dbname.' type '.$row_db['dbsoftware'].' ','',$group_id);
75 if (getStringFromRequest('updatedbrec')) {
76 $dbid = getIntFromRequest('dbid');
77 $pw = getStringFromRequest('pw');
78 $pwconfirm = getStringFromRequest('pwconfirm');
79 $newdbtypeid = getIntFromRequest('newdbtypeid');
81 if ($pw == $pwconfirm) {
83 //sync new password, and flag it as 'pending (an) update'
85 $res = db_query_params ('
97 if (!$res || db_affected_rows($res) < 1) {
98 $error_msg .= "Update failure - ".db_error()."";
100 $res = db_query_params ('
105 array($newdbtypeid));
106 $row_db = db_fetch_array($res);
107 group_add_history('Updated database - (type: '.$row_db['dbsoftware'].')','',$group_id);
111 $error_msg .= "Operation failed. Password and Password Confirm are not the same";
117 if (getStringFromRequest('deletedbconfirm')) {
118 $dbid = getIntFromRequest('dbid');
120 //schedule for deletion
122 $res = db_query_params ('
131 if (!$res || db_affected_rows($res) < 1) {
132 $error_msg .= 'Cannot delete database: '.db_error();
134 $feedback .= "Database scheduled for deletion";
139 project_admin_header(array('title'=>_('Database Information').'','group'=>$group_id));
141 // XXX ogi: where's deletedb defined?
142 if ($deletedb == 1) {
144 print "<hr /><strong><div align=\"center\">"._('Click to confirm deletion')."[ <a href=\"".getStringFromServer('PHP_SELF')."?deletedbconfirm=1&group_id=".$group_id."&dbid=$dbid\">'._('CONFIRM DELETE').'</a> ] </div></strong> <hr />";
148 $res_db = db_query_params ('
151 WHERE dbsoftware NOT IN (
153 FROM prdb_dbs,prdb_types
154 WHERE dbtypeid=dbtype
161 if (db_numrows($res_db) > 0) {
165 <p><strong><span style="text-decoration:underline">'._('Add New Database').'</span></strong></p>
166 <p><em>'._('Clicking on "create" will schedule the creation of the database, and email the details to the project administrators').'</em></p>
168 <p><strong>'._('Database Type').':</strong></p>
169 <p><form action="'.getStringFromServer('PHP_SELF').'" method="post">
170 <input type="hidden" name="createdb" value="1" />
171 <input type="hidden" name="group_id" value="'.$group_id.'" />
172 <select name="newdbtypeid">
176 while ($res_row = db_fetch_array($res_db)) {
178 print "<option value=\"".$res_row['dbtypeid']."\">".$res_row['dbsoftware']."</option>";
184 <input type="submit" name="Create" value="'._('Create').'" />
190 <?php echo _('Maximum number of databases of all types have been allocated') ?>
196 $res_db = db_query_params("
198 FROM prdb_dbs,prdb_states,prdb_types
202 ", array($group_id));
204 if (db_numrows($res_db) > 0) {
207 $title[]=_('DB Type');
209 $title[]=_('New Password');
210 $title[]=_('Confirm New');
211 $title[]=_('Operations');
213 echo $GLOBALS['HTML']->listTableTop($title);
215 while ($row_db = db_fetch_array($res_db)) {
218 <tr '.$GLOBALS['HTML']->boxGetAltRowStyle($i++).'>
220 <td>'.$row_db['dbsoftware'].'</td>
221 <td>'.$row_db['statename'].'</td>
224 //if database is active or pending update allow the record to be deleted or password changed
226 if (($row_db['state'] == 1) || ($row_db['state'] == 4) || ($row_db['state'] == 2)) {
228 print '<form name="dbupdate" method="post" action="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'">
229 <input type="hidden" name="dbid" value="'.$row_db['dbid'].'" />
230 <input type="hidden" name="updatedbrec" value="1" />
231 <td><input type="text" name="pw" size="8" maxlength="16" /></td>
232 <td><input type="text" name="pwconfirm" size="8" maxlength="16" /></td>
234 <input type="submit" name="submit" value="'._('Update').'" />
251 echo $GLOBALS['HTML']->listTableBottom();
255 print '<strong><span style="text-decoration:underline">'._('Current Databases').'</span></strong><p>'._('There are no databases currently allocated to this group').'</p>';
259 project_admin_footer(array());