[Gbounty-commits] r7 - in trunk: . db include/languages www
www/include www/include/admin
feri at garage.maemo.org
feri at garage.maemo.org
Thu Oct 26 05:37:14 EEST 2006
Author: feri
Date: 2006-10-26 05:37:14 +0300 (Thu, 26 Oct 2006)
New Revision: 7
Added:
trunk/www/include/admin/
trunk/www/include/admin/gbounty_admin_utils.php
Modified:
trunk/ChangeLog
trunk/db/gbounty-init.sql
trunk/include/languages/Base.tab
trunk/www/include/gbounty_dbutils.php
trunk/www/include/gbounty_display.php
trunk/www/index.php
Log:
all admin functionality implemented. testing can begin.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-10-24 03:04:52 UTC (rev 6)
+++ trunk/ChangeLog 2006-10-26 02:37:14 UTC (rev 7)
@@ -1,3 +1,8 @@
+2006-10-26 05:30 feri (ferenc at maemo.org)
+
+ All admin functionality implemented. Styling is not done yet, but
+ functional testing can begin.
+
2006-10-24 06:00 feri (ferenc at maemo.org)
Use $group_id all over instead of $id (AFAIK it is a sort of
Modified: trunk/db/gbounty-init.sql
===================================================================
--- trunk/db/gbounty-init.sql 2006-10-24 03:04:52 UTC (rev 6)
+++ trunk/db/gbounty-init.sql 2006-10-26 02:37:14 UTC (rev 7)
@@ -1,5 +1,5 @@
--
--- let's drop gbounty tables (dangerous)
+-- let's drop gbounty tables and rules (dangerous)
--
DROP TABLE plugin_gbounty_bounties;
DROP TABLE plugin_gbounty_details;
@@ -56,3 +56,15 @@
-- add gbounty to the plugins table
--
INSERT INTO plugins (plugin_name,plugin_desc) VALUES ('gbounty','gbounty plugin');
+
+--
+-- create some clever rules
+--
+CREATE RULE new_bounty AS ON INSERT TO plugin_gbounty_bounties DO INSERT INTO plugin_gbounty_details VALUES (currval('plugin_gbounty_bounties_id_seq'));
+
+
+--
+--only for testing purposes
+--
+--insert into plugin_gbounty_bounties (status, founder, project, category, task, prize, email, currency) values (1, 105, 104, 'test1', 'test1', 111, 'test1', 'USD');
+--insert into plugin_gbounty_bounties (status, founder, project, category, task, prize, email, currency) values (1, 105, 104, 'test2', 'test2', 999, 'test2', 'EUR');
Modified: trunk/include/languages/Base.tab
===================================================================
--- trunk/include/languages/Base.tab 2006-10-24 03:04:52 UTC (rev 6)
+++ trunk/include/languages/Base.tab 2006-10-26 02:37:14 UTC (rev 7)
@@ -6,8 +6,9 @@
# */
user_home view_gbounty Personal Bounties
project_admin gbounty Gbounty Administration
+general admintitle Bounty Administration
general backtobrowse [Back to all bounties]
-error nodata No Data Available
+error nodata The project does not have bounties
list category Category
list task Task Name
list bounty Bounty
@@ -28,3 +29,21 @@
delete question Are you sure you want to delete the bounty above?
delete sure Yes, I am
delete notsure No, I do not want to delete it
+edit header Details of the bounty
+edit save Save
+edit cancel Cancel
+edit status Status
+edit email Email
+edit description Detailed Description
+edit open Open
+edit resolved Resolved
+edit removed Removed
+edit new_ok Bounty is successfuly added
+edit new_nok Bounty could not be added
+edit update_ok Bounty is successfuly updated
+edit update_nok Bounty could not be updated
+edit remove_ok Bounty is marked as removed
+edit remove_nok Bounty could not be marked as removed
+edit reopen_ok Bounty is successfuly reopened
+edit reopen_nok Bounty could not be reopened
+admin addbounty Add New Bounty
Added: trunk/www/include/admin/gbounty_admin_utils.php
===================================================================
--- trunk/www/include/admin/gbounty_admin_utils.php 2006-10-24 03:04:52 UTC (rev 6)
+++ trunk/www/include/admin/gbounty_admin_utils.php 2006-10-26 02:37:14 UTC (rev 7)
@@ -0,0 +1,17 @@
+<?php
+
+
+function admin_menu($Language, $HTML, $baseurl) {
+ $labels = array();
+ $links = array();
+
+ $labels[] = $Language->getText('admin','addbounty');
+ $links[] = $baseurl.'&action=admin&subcmd=add';
+
+ echo ($HTML->beginSubMenu());
+ echo $HTML->printSubMenu($labels, $links);
+ plugin_hook("groupadminmenu", $params) ;
+ echo ($HTML->endSubMenu());
+}
+
+?>
\ No newline at end of file
Modified: trunk/www/include/gbounty_dbutils.php
===================================================================
--- trunk/www/include/gbounty_dbutils.php 2006-10-24 03:04:52 UTC (rev 6)
+++ trunk/www/include/gbounty_dbutils.php 2006-10-26 02:37:14 UTC (rev 7)
@@ -69,8 +69,11 @@
*
*/
function get_solved_bounties($gforge_id, $limit='-1') {
- $qry = "SELECT * FROM plugin_gbounty_bounties b JOIN plugin_gbounty_details d ON (b.id=d.bounty_id) WHERE status='1' AND project='".$gforge_id."';";
+ $qry = "SELECT * FROM plugin_gbounty_bounties b JOIN plugin_gbounty_details d ON (b.id=d.bounty_id) WHERE status='1' AND project='".$gforge_id."' ORDER BY b.id;";
$res = db_query($qry, $limit);
+ if ($res == false) {
+ echo pg_errormessage();
+ }
return return_result($res);
}
@@ -81,16 +84,70 @@
* @return array all matching rows
*/
function get_all_bounties($group_id, $limit='-1') {
- $qry = "SELECT * FROM plugin_gbounty_bounties b JOIN plugin_gbounty_details d ON (b.id=d.bounty_id) WHERE project='".$group_id."';";
+ $qry = "SELECT * FROM plugin_gbounty_bounties b JOIN plugin_gbounty_details d ON (b.id=d.bounty_id) WHERE project='".$group_id."' ORDER BY b.id;";
$res = db_query($qry, $limit);
+ if ($res == false) {
+ echo pg_errormessage();
+ }
return return_result($res);
}
/**
+ * new_bounty() - add a new bounty to the table
*
+ * @param array bounty records
+ * @return boolean true if upidate was OK; false if update failed
*/
-function create_new_bounty() {
+function new_bounty($bounty) {
+# echo "<pre>";
+# echo "new_bounty\n";
+# print_r($bounty);
+# echo "</pre>";
+ extract($bounty);
+ $qry = "INSERT INTO plugin_gbounty_bounties (status, founder, project, category, task, prize, email, currency) VALUES (";
+ $qry .= $bounty_status.",".$bounty_founder.",".$bounty_project.",'".$bounty_category."','";
+ $qry .= $bounty_task."','".$bounty_prize."','".$bounty_email."','".$bounty_currency."');";
+ $res = db_query($qry);
+ if ($res == false) {
+ echo pg_errormessage();
+ }
+ else {
+ //if the previous qry was OK we need to update only the details table, since the rule has created a new record
+ $qry = "UPDATE plugin_gbounty_details SET description='".$bounty_description."',";
+ $qry .= "modules='".$bounty_modules."', howto='".$bounty_howto."', pointers='".$bounty_pointers."' ";
+ $qry .= "WHERE bounty_id=currval('plugin_gbounty_bounties_id_seq');";
+ $res = db_query($qry);
+ if ($res == false) {
+ echo pg_errormessage();
+ }
+ }
+ return $res;
+}
+/**
+ * update_bounty() - updates a bounty
+ *
+ * @param array the bounty records
+ * @return boolean true if upidate was OK; false if update failed
+ *
+ */
+function update_bounty($bounty) {
+# echo "<pre>";
+# echo "update_bounty\n";
+# print_r($bounty);
+# echo "</pre>";
+ extract($bounty);
+ $qry = "UPDATE plugin_gbounty_bounties SET status=".$bounty_status.",";
+ $qry .= "prize='".$bounty_prize."',category='".$bounty_category."',task='".$bounty_task."',";
+ $qry .= "email='".$bounty_email."',currency='".$bounty_currency."' ";
+ $qry .= "WHERE id=".$bounty_id.";";
+ $res = db_query($qry);
+ if ($res == false) {
+ echo pg_errormessage();
+ } else {
+ $res = true;
+ }
+ return $res;
}
@@ -98,39 +155,42 @@
* mark_bounty_open() - marks a bounty open
*
* @param integer the bounty_id
- * @return array
+ * @return boolean
*/
function mark_bounty_open($bounty_id) {
$qry = "UPDATE plugin_gbounty_bounties SET status=0 WHERE id=".$bounty_id.";";
$res = db_query($qry,$limit);
if ($res == false)
- echo "Insert/update failed: " . pg_errormessage();
+ echo pg_errormessage();
+ return $res;
}
/**
* mark_bounty_closed() - marks a bounty as removed
*
* @param integer the bounty_id
- * @return array
+ * @return boolean
*/
function mark_bounty_closed() {
$qry = "UPDATE plugin_gbounty_bounties SET status=1 WHERE id=".$bounty_id.";";
$res = db_query($qry,$limit);
if ($res == false)
- echo "Insert/update failed: " . pg_errormessage();
+ echo pg_errormessage();
+ return $res;
}
/**
* mark_bounty_removed() - marks a bounty as removed
*
* @param integer the bounty_id
- * @return array
+ * @return boolean
*/
function mark_bounty_removed($bounty_id) {
$qry = "UPDATE plugin_gbounty_bounties SET status=2 WHERE id=".$bounty_id.";";
$res = db_query($qry,$limit);
if ($res == false)
- echo "Insert/update failed: " . pg_errormessage();
+ echo pg_errormessage();
+ return $res;
}
?>
\ No newline at end of file
Modified: trunk/www/include/gbounty_display.php
===================================================================
--- trunk/www/include/gbounty_display.php 2006-10-24 03:04:52 UTC (rev 6)
+++ trunk/www/include/gbounty_display.php 2006-10-26 02:37:14 UTC (rev 7)
@@ -154,4 +154,59 @@
echo '</div>'."\n";
}
+
+/**
+ * edit_bounty() - Editing a bounty
+ *
+ * @param array a multidimensional result array that is returned by the return_result() DB helper
+ *
+ */
+function edit_bounty($Language, $HTML, $baseurl, $bounty, $new=false, $founder="", $project="", $email="") {
+ echo '<hr/>';
+ echo '<h2 class="edit_hdr">'.$Language->getText('edit','header')."</h2>\n";
+ echo '<form action="'.$baseurl.'&action=admin" method="post">'."\n";
+ if (! $new) {
+ $founder = $bounty["founder"];
+ $project = $bounty["project"];
+ $status = $bounty["status"];
+ $currency = $bounty["currency"];
+ $email = $bounty["email"];
+ $values = array('0', '1', '2');
+ $texts = array($Language->getText('edit','open'),
+ $Language->getText('edit','resolved'),
+ $Language->getText('edit','removed'));
+ echo '<h3>'.$Language->getText('edit','status').'</h3>'."\n";
+ echo html_build_radio_buttons_from_arrays($values, $texts, "bounty_status", $status, false, 'none', false, 'Any');
+ echo "\n";
+ } else {
+ //TODO: Is there a way to get the location and then the currency based of a Gforge project ??
+ $currency = "EUR";
+ echo '<input type="hidden" name="bounty_status" value="0"/>'."\n";
+ }
+ echo '<h3>'.$Language->getText('list','category').'</h3>'."\n";
+ echo '<input type="text" name="bounty_category" size="50" maxlength="50" value="'.$bounty["category"].'"/>'."\n";
+ echo '<h3>'.$Language->getText('list','task').'</h3>'."\n";
+ echo '<input type="text" name="bounty_task" size="50" maxlength="50" value="'.$bounty["task"].'"/>'."\n";
+ echo '<h3>'.$Language->getText('list','bounty').'</h3>'."\n";
+ echo '<input type="text" name="bounty_prize" size="6" maxlength="6" value="'.$bounty["prize"].'"/>'."\n";
+ echo '<input type="text" name="bounty_currency" size="3" maxlength="3" value="'.$currency.'"/>'."\n";
+ echo '<h3>'.$Language->getText('edit','email').'</h3>'."\n";
+ echo '<input type="text" name="bounty_email" size="40" maxlength="40" value="'.$email.'"/>'."\n";
+ echo '<h3>'.$Language->getText('edit','description').'</h3>'."\n";
+ echo '<textarea name="bounty_description" cols="80" rows="10">'.$bounty["description"].'</textarea>'."\n";
+ echo '<h3>'.$Language->getText('detail','modules').'</h3>'."\n";
+ echo '<textarea name="bounty_modules" cols="80" rows="10">'.$bounty["modules"].'</textarea>'."\n";
+ echo '<h3>'.$Language->getText('detail','howto').'</h3>'."\n";
+ echo '<textarea name="bounty_howto" cols="80" rows="10">'.$bounty["howto"].'</textarea>'."\n";
+ echo '<h3>'.$Language->getText('detail','pointers').'</h3>'."\n";
+ echo '<textarea name="bounty_pointers" cols="50" rows="10">'.$bounty["pointers"].'</textarea>'."\n";
+ echo '<br/><br/>';
+ echo '<input type="submit" name="submit" value="'.$Language->getText('edit','save').'"/>'."\n";
+ echo '<input type="submit" name="submit" value="'.$Language->getText('edit','cancel').'"/>'."\n";
+ echo '<input type="hidden" name="bounty_id" value="'.$bounty["id"].'"/>'."\n";
+ echo '<input type="hidden" name="bounty_founder" value="'.$founder.'"/>'."\n";
+ echo '<input type="hidden" name="bounty_project" value="'.$project.'"/>'."\n";
+ echo '</form>'."\n";
+}
+
?>
\ No newline at end of file
Modified: trunk/www/index.php
===================================================================
--- trunk/www/index.php 2006-10-24 03:04:52 UTC (rev 6)
+++ trunk/www/index.php 2006-10-26 02:37:14 UTC (rev 7)
@@ -9,9 +9,10 @@
*/
require_once('pre.php');
-require_once ('plugins/gbounty/config.php');
-require_once ('include/gbounty_dbutils.php');
-require_once ('include/gbounty_display.php');
+require_once('plugins/gbounty/config.php');
+require_once('include/gbounty_dbutils.php');
+require_once('include/gbounty_display.php');
+require_once('include/admin/gbounty_admin_utils.php');
// the header that displays for the user portion of the plugin
function gbounty_Project_Header($params) {
@@ -149,10 +150,11 @@
//only project admin can access here
if ( $userperm->isAdmin() ) {
gbounty_Project_Header(array('title'=>$pluginname . ' Project Plugin!','pagename'=>"$pluginname",'sectionvals'=>array(group_getname($group_id))));
-
// DO THE STUFF FOR THE PROJECT ADMINISTRATION PART HERE
$baseurl="?type=".$type."&group_id=".$group_id."&pluginname=".$pluginname;
+ admin_menu($Language, $HTML, $baseurl);
+
switch ($action) {
case "getdetail":
$result = get_bounty_details($group_id, $bounty_id);
@@ -163,12 +165,57 @@
}
break;
case "admin":
- echo "<h1>will be ready soon</h1>";
+ echo '<h1>'.$Language->getText('general','admintitle').'</h1>'."\n";
$result = get_all_bounties($group_id);
+ switch ($subcmd) {
+ case "add":
+ edit_bounty($Language, $HTML, $baseurl, "", true, $user->getId(), $group_id, $user->getEmail());
+ break;
+ default:
+ break;
+ }
+ if (is_array($_POST)) {
+ switch ($_POST["submit"]) {
+ case $Language->getText('delete','sure'):
+ if($_POST["bounty_id"]) {
+ $fb = mark_bounty_removed($_POST["bounty_id"]);
+ if ($fb)
+ header ("Location:".$baseurl."&action=admin&feedback=".$Language->getText('edit','remove_ok'));
+ else
+ header ("Location:".$baseurl."&action=admin&feedback=".$Language->getText('edit','remove_nok'));
+ }
+ break;
+ case $Language->getText('delete','notsure'):
+ break;
+ case $Language->getText('edit','save'):
+ if ($_POST["bounty_id"]) {
+ //it was an update
+ $fb = update_bounty($_POST);
+ if ($fb)
+ header ("Location:".$baseurl."&action=admin&feedback=".$Language->getText('edit','update_ok'));
+ else
+ header ("Location:".$baseurl."&action=admin&feedback=".$Language->getText('edit','update_nok'));
+ } else {
+ //it was a new bounty
+ $fb = new_bounty($_POST);
+ if ($fb)
+ header ("Location:".$baseurl."&action=admin&feedback=".$Language->getText('edit','new_ok'));
+ else
+ header ("Location:".$baseurl."&action=admin&feedback=".$Language->getText('edit','new_nok'));
+ }
+ break;
+ case $Language->getText('edit','cancel'):
+ break;
+ default:
+ break;
+ }
+ }
if ($result) {
admin_bounties($Language, $HTML, $result, $baseurl);
switch ($subcmd) {
case "edit":
+ $result = get_bounty_details($group_id, $bounty_id);
+ edit_bounty($Language, $HTML, $baseurl, $result[0], false);
break;
case "delete":
$result = get_bounty_details($group_id, $bounty_id);
@@ -179,26 +226,15 @@
header ("Location:".$baseurl."&action=admin");
break;
case "reopen":
- mark_bounty_open($bounty_id);
- header ("Location:".$baseurl."&action=admin");
+ $fb = mark_bounty_open($bounty_id);
+ if ($fb)
+ header ("Location:".$baseurl."&action=admin&feedback=".$Language->getText('edit','reopen_ok'));
+ else
+ header ("Location:".$baseurl."&action=admin&feedback=".$Language->getText('edit','reopen_nok'));
break;
default:
break;
}
- if ($_POST) {
- switch ($_POST["submit"]) {
- case $Language->getText('delete','sure'):
- if($_POST["bounty_id"]) {
- mark_bounty_removed($_POST["bounty_id"]);
- }
- break;
- case $Language->getText('delete','notsure'):
- break;
- default:
- break;
- }
- header ("Location:".$baseurl."&action=admin");
- }
}else {
echo $Language->gettext('error', 'nodata');
}
More information about the Gbounty-commits
mailing list