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
14 * This file is part of GForge.
16 * GForge is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * GForge is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with GForge; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 require_once('../../env.inc.php');
33 require_once $gfwww.'include/pre.php';
34 require_once $gfwww.'project/admin/project_admin_utils.php';
36 if (!$sys_use_project_database) {
40 $group_id = getIntFromRequest('group_id');
41 session_require(array('group'=>$group_id,'admin_flags'=>'A'));
43 $group =& group_get_object($group_id);
44 if (!$group || !is_object($group)) {
45 exit_error(_('Error'), _('Error creating group'));
46 } else if ($group->isError()) {
47 exit_error(_('Error'), $group->getErrorMessage());
50 if (getStringFromRequest('createdb')) {
51 $newdbtypeid = getIntFromRequest('newdbtypeid');
53 //mysql takes issue with database names that have dashes in them - so strip the dashes, replace with ""
54 //e.g. free-mysql becomes freemysql (it's a workaround)
55 //if there is a dash in the groupname
56 $dbname = str_replace("-", "", $group->getUnixName());
58 //check there is no name double up - if there is - add an incrementing to the number to the end
60 $dbname = prdb_namespace_seek($dbname);
61 $randompw = random_pwgen();
63 $sql = "INSERT INTO prdb_dbs(group_id,dbname,dbusername,dbuserpass,requestdate,dbtype,created_by,state)
64 VALUES($1, $2, $2, $3, $4, $5, $6 ,2)";
65 $res = db_query_params($sql, array($group_id, $dbname, $randompw, time(), $newdbtypeid, $LUSER->getID()));
67 if (!$res || db_affected_rows($res) < 1) {
68 $feedback .= _('Cannot add database entry').': '.db_error();
71 $feedback .= _('Database scheduled for creation');
72 group_add_history('Created database '.$dbname.' type '.$row_db['dbsoftware'].' ','',$group_id);
78 if (getStringFromRequest('updatedbrec')) {
79 $dbid = getIntFromRequest('dbid');
80 $pw = getStringFromRequest('pw');
81 $pwconfirm = getStringFromRequest('pwconfirm');
82 $newdbtypeid = getIntFromRequest('newdbtypeid');
84 if ($pw == $pwconfirm) {
86 //sync new password, and flag it as 'pending (an) update'
88 $res = db_query_params ('
100 if (!$res || db_affected_rows($res) < 1) {
101 $feedback .= "Update failure - ".db_error()."";
103 $res = db_query_params ('
108 array($newdbtypeid));
109 $row_db = db_fetch_array($res);
110 group_add_history('Updated database - (type: '.$row_db['dbsoftware'].')','',$group_id);
114 $feedback .= "Operation failed. Password and Password Confirm are not the same";
120 if (getStringFromRequest('deletedbconfirm')) {
121 $dbid = getIntFromRequest('dbid');
123 //schedule for deletion
125 $res = db_query_params ('
134 if (!$res || db_affected_rows($res) < 1) {
135 $feedback .= 'Cannot delete database: '.db_error();
137 $feedback .= "Database scheduled for deletion";
142 project_admin_header(array('title'=>_('Database Information').'','group'=>$group_id));
144 // XXX ogi: where's deletedb defined?
145 if ($deletedb == 1) {
147 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 />";
151 $res_db = db_query_params ('
154 WHERE dbsoftware NOT IN (
156 FROM prdb_dbs,prdb_types
157 WHERE dbtypeid=dbtype
164 if (db_numrows($res_db) > 0) {
168 <p><strong><span style="text-decoration:underline">'._('Add New Database').'</span></strong></p>
169 <p><em>'._('Clicking on "create" will schedule the creation of the database, and email the details to the project administrators').'</em></p>
171 <p><strong>'._('Database Type').':</strong></p>
172 <p><form action="'.getStringFromServer('PHP_SELF').'" method="post">
173 <input type="hidden" name="createdb" value="1" />
174 <input type="hidden" name="group_id" value="'.$group_id.'" />
175 <select name="newdbtypeid">
179 while ($res_row = db_fetch_array($res_db)) {
181 print "<option value=\"".$res_row['dbtypeid']."\">".$res_row['dbsoftware']."</option>";
187 <input type="submit" name="Create" value="'._('Create').'" />
193 <?php echo _('Maximum number of databases of all types have been allocated') ?>
201 FROM prdb_dbs,prdb_states,prdb_types
206 $res_db = db_query_params($sql, array($group_id));
208 if (db_numrows($res_db) > 0) {
211 $title[]=_('DB Type');
213 $title[]=_('New Password');
214 $title[]=_('Confirm New');
215 $title[]=_('Operations');
217 echo $GLOBALS['HTML']->listTableTop($title);
219 while ($row_db = db_fetch_array($res_db)) {
222 <tr '.$GLOBALS['HTML']->boxGetAltRowStyle($i++).'>
224 <td>'.$row_db['dbsoftware'].'</td>
225 <td>'.$row_db['statename'].'</td>
228 //if database is active or pending update allow the record to be deleted or password changed
230 if (($row_db['state'] == 1) || ($row_db['state'] == 4) || ($row_db['state'] == 2)) {
232 print '<form name="dbupdate" method="post" action="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'">
233 <input type="hidden" name="dbid" value="'.$row_db['dbid'].'" />
234 <input type="hidden" name="updatedbrec" value="1" />
235 <td><input type="text" name="pw" size="8" maxlength="16" /></td>
236 <td><input type="text" name="pwconfirm" size="8" maxlength="16" /></td>
238 <input type="submit" name="submit" value="'._('Update').'" />
255 echo $GLOBALS['HTML']->listTableBottom();
259 print '<strong><span style="text-decoration:underline">'._('Current Databases').'</span></strong><p>'._('There are no databases currently allocated to this group').'</p>';
263 project_admin_footer(array());