[Fusionforge-commits] r8585 - in trunk/gforge/plugins/contribtracker: common www

Roland Mas lolando at libremir.placard.fr.eu.org
Fri Dec 18 18:41:44 CET 2009


Author: lolando
Date: 2009-12-18 18:41:44 +0100 (Fri, 18 Dec 2009)
New Revision: 8585

Added:
   trunk/gforge/plugins/contribtracker/www/global_admin.php
Modified:
   trunk/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php
   trunk/gforge/plugins/contribtracker/www/project_admin.php
Log:
UI+code?\194?\160to add/remove/edit roles, structures and actors

Modified: trunk/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php
===================================================================
--- trunk/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php	2009-12-18 17:41:34 UTC (rev 8584)
+++ trunk/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php	2009-12-18 17:41:44 UTC (rev 8585)
@@ -32,6 +32,7 @@
 		$this->hooks[] = "groupisactivecheckboxpost" ; //
 		$this->hooks[] = "project_admin_plugins"; // to show up in the admin page for group
 		$this->hooks[] = "project_before_frs"; // project summary page
+                $this->hooks[] = "site_admin_option_hook"; // to show in the site admin page
 	}
 
 	function CallHook ($hookname, $params) {
@@ -153,6 +154,14 @@
 						      echo $HTML->boxBottom();
 			}
 		}
+                elseif ($hookname == "site_admin_option_hook") {
+                        ?>
+                        <li><?php echo util_make_link ('/plugins/'.$this->name.'/global_admin.php',
+                                                       _('Edit actors and roles for the contribution tracker plugin')
+                                ); ?></li>
+                        <?php
+                } 
+
 	}
 
 	function getActors () {

Added: trunk/gforge/plugins/contribtracker/www/global_admin.php
===================================================================
--- trunk/gforge/plugins/contribtracker/www/global_admin.php	                        (rev 0)
+++ trunk/gforge/plugins/contribtracker/www/global_admin.php	2009-12-18 17:41:44 UTC (rev 8585)
@@ -0,0 +1,423 @@
+<?php
+
+/*
+ * ContribTracker plugin
+ *
+ * Copyright 2009, Roland Mas
+ *
+ */
+
+require_once('../../env.inc.php');
+require_once $gfwww.'include/pre.php';
+require_once $gfwww.'admin/admin_utils.php';
+$plugin = plugin_get_object ('contribtracker') ;
+
+session_require(array('group'=>'1','admin_flags'=>'A'));
+
+site_admin_header (array ('title' => _('Contribution tracker administration'))) ;
+
+$action = getStringFromRequest ('action') ;
+$action = util_ensure_value_in_set ($action, array ('display',
+						    'add_role',
+						    'add_actor',
+						    'add_structure',
+						    'post_add_role',
+						    'post_add_actor',
+						    'post_add_structure',
+						    'edit_role',
+						    'edit_actor',
+						    'edit_structure',
+						    'post_edit_role',
+						    'post_edit_actor',
+						    'post_edit_structure',
+						    'del_role',
+						    'del_actor',
+						    'del_structure')) ;
+
+function check_role_id ($r_id) {
+	$role = new ContribTrackerRole ($r_id) ;
+	if (!$role || !is_object ($role)) {
+		exit_permission_denied () ;
+	}
+}
+function check_actor_id ($a_id) {
+	$actor = new ContribTrackerActor ($a_id) ;
+	if (!$actor || !is_object ($actor)) {
+		exit_permission_denied () ;
+	}
+}
+function check_structure_id ($s_id) {
+	$structure = new ContribTrackerLegalStructure ($s_id) ;
+	if (!$structure || !is_object ($structure)) {
+		exit_permission_denied () ;
+	}
+}
+	
+
+// Get and validate parameters, error if tampered with
+switch ($action) {
+case 'display':
+	break ;
+
+case 'add_role':
+	break ;
+case 'post_add_role':
+	$name = getStringFromRequest ('role_name') ;
+	$desc = getStringFromRequest ('role_desc') ;
+	break ;
+case 'edit_role':
+case 'del_role':
+	$role_id = getIntFromRequest ('role_id') ;
+	check_role_id ($role_id) ;
+	break ;	
+case 'post_edit_role':
+	$role_id = getIntFromRequest ('role_id') ;
+	check_role_id ($role_id) ;
+	$name = getStringFromRequest ('role_name') ;
+	$desc = getStringFromRequest ('role_desc') ;
+	break ;	
+
+case 'add_structure':
+	break ;
+case 'post_add_structure':
+	$name = getStringFromRequest ('structure_name') ;
+	$desc = getStringFromRequest ('structure_desc') ;
+	break ;
+case 'edit_structure':
+case 'del_structure':
+	$structure_id = getIntFromRequest ('structure_id') ;
+	check_structure_id ($structure_id) ;
+	break ;	
+case 'post_edit_structure':
+	$structure_id = getIntFromRequest ('structure_id') ;
+	check_structure_id ($structure_id) ;
+	$name = getStringFromRequest ('structure_name') ;
+	$desc = getStringFromRequest ('structure_desc') ;
+	break ;	
+
+case 'add_actor':
+	break ;
+case 'post_add_actor':
+	$name = getStringFromRequest ('actor_name') ;
+	$address = getStringFromRequest ('actor_address') ;
+	$email = getStringFromRequest ('actor_email') ;
+	$desc = getStringFromRequest ('actor_desc') ;
+	$structure_id = getIntFromRequest ('structure_id') ;
+	check_structure_id ($structure_id) ;
+	break ;
+case 'edit_actor':
+case 'del_actor':
+	$actor_id = getIntFromRequest ('actor_id') ;
+	check_actor_id ($actor_id) ;
+	break ;	
+case 'post_edit_actor':
+	$actor_id = getIntFromRequest ('actor_id') ;
+	check_actor_id ($actor_id) ;
+	$name = getStringFromRequest ('actor_name') ;
+	$address = getStringFromRequest ('actor_address') ;
+	$email = getStringFromRequest ('actor_email') ;
+	$desc = getStringFromRequest ('actor_desc') ;
+	$structure_id = getIntFromRequest ('structure_id') ;
+	check_structure_id ($structure_id) ;
+	break ;	
+
+}
+	
+// Do the required action
+
+switch ($action) {
+case 'post_add_role':
+	$role = new ContribTrackerRole () ;
+	if (!$role->create ($name, $desc)) {
+		exit_error ($role->getErrorMessage()) ;
+	}
+	$role_id = $role->getId() ;
+	$action = 'display' ;
+	break ;
+case 'del_role':
+	$role = new ContribTrackerRole ($role_id) ;
+	$role->delete () ;
+	$action = 'display' ;
+	break ;
+case 'post_edit_role':
+	$role = new ContribTrackerRole ($role_id) ;
+	$role->update ($name, $desc) ;
+	$action = 'display' ;
+	break ;
+
+case 'post_add_structure':
+	$structure = new ContribTrackerLegalStructure () ;
+	if (!$structure->create ($name, $desc)) {
+		exit_error ($structure->getErrorMessage()) ;
+	}
+	$structure_id = $structure->getId() ;
+	$action = 'display' ;
+	break ;
+case 'del_structure':
+	$structure = new ContribTrackerLegalStructure ($structure_id) ;
+	$structure->delete () ;
+	$action = 'display' ;
+	break ;
+case 'post_edit_structure':
+	$structure = new ContribTrackerLegalStructure ($structure_id) ;
+	$structure->update ($name, $desc) ;
+	$action = 'display' ;
+	break ;
+
+case 'post_add_actor':
+	$actor = new ContribTrackerActor () ;
+	$structure = new ContribTrackerLegalStructure ($structure_id) ;
+	if (!$actor->create ($name, $address, $email, $desc, $structure)) {
+		exit_error ($actor->getErrorMessage()) ;
+	}
+	$actor_id = $actor->getId() ;
+	$action = 'display' ;
+	break ;
+case 'del_actor':
+	$actor = new ContribTrackerActor ($actor_id) ;
+	$actor->delete () ;
+	$action = 'display' ;
+	break ;
+case 'post_edit_actor':
+	$actor = new ContribTrackerActor ($actor_id) ;
+	$structure = new ContribTrackerLegalStructure ($structure_id) ;
+	$actor->update ($name, $address, $email, $desc, $structure) ;
+	$action = 'display' ;
+	break ;
+}
+
+// Display appropriate forms
+
+switch ($action) {
+case 'display':
+	print '<h1>'._('Existing actors').'</h1>' ;
+	print '<table><thead><tr>' ;
+	print '<td><strong>'._('Short name').'</strong></td>' ;
+	print '<td><strong>'._('Postal address').'</strong></td>' ;
+	print '<td><strong>'._('Email').'</strong></td>' ;
+	print '<td><strong>'._('Description').'</strong></td>' ;
+	print '<td><strong>'._('Legal structure').'</strong></td>' ;
+	print '<td><strong>'._('Actions').'</strong></td>' ;
+	$actors = $plugin->getActors () ;
+	print '</tr></thead><tbody>' ;
+	foreach ($actors as $a) {
+		print '<tr>';
+		print '<td>'.htmlspecialchars($a->getName()).'</td>' ;
+		print '<td>'.htmlspecialchars($a->getAddress()).'</td>' ;
+		print '<td>'.htmlspecialchars($a->getEmail()).'</td>' ;
+		print '<td>'.htmlspecialchars($a->getDescription()).'</td>' ;
+		print '<td>'.htmlspecialchars($a->getLegalStructure()->getName()).'</td>' ;
+?>
+<td>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="edit_actor" />
+<input type="hidden" name="actor_id" value="<?php echo $a->getId () ?>" />
+<input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
+</form>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="del_actor" />
+<input type="hidden" name="actor_id" value="<?php echo $a->getId () ?>" />
+<input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
+</form>
+</td>
+<?php
+		print '</tr>';
+	}	
+	print '</tbody></table>' ;
+?>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="add_actor" />
+<input type="submit" name="submit" value="<?php echo _('Register new actor') ?>" />
+</form>
+<?php
+
+	print '<h1>'._('Existing legal structures').'</h1>' ;
+	print '<table><thead><tr>' ;
+	print '<td><strong>'._('Short name').'</strong></td>' ;
+	print '<td><strong>'._('Actions').'</strong></td>' ;
+	$structs = $plugin->getLegalStructures () ;
+	print '</tr></thead><tbody>' ;
+	foreach ($structs as $s) {
+		print '<tr>';
+		print '<td>'.htmlspecialchars($s->getName()).'</td>' ;
+?>
+<td>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="edit_structure" />
+<input type="hidden" name="structure_id" value="<?php echo $s->getId () ?>" />
+<input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
+</form>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="del_structure" />
+<input type="hidden" name="structure_id" value="<?php echo $s->getId () ?>" />
+<input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
+</form>
+</td>
+<?php
+		print '</tr>';
+	}	
+	print '</tbody></table>' ;
+?>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="add_structure" />
+<input type="submit" name="submit" value="<?php echo _('Register new legal structure') ?>" />
+</form>
+<?php
+
+	print '<h1>'._('Existing roles').'</h1>' ;
+	print '<table><thead><tr>' ;
+	print '<td><strong>'._('Short name').'</strong></td>' ;
+	print '<td><strong>'._('Description').'</strong></td>' ;
+	print '<td><strong>'._('Actions').'</strong></td>' ;
+	$roles = $plugin->getRoles () ;
+	print '</tr></thead><tbody>' ;
+	foreach ($roles as $r) {
+		print '<tr>';
+		print '<td>'.htmlspecialchars($r->getName()).'</td>' ;
+		print '<td>'.htmlspecialchars($r->getDescription()).'</td>' ;
+?>
+<td>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="edit_role" />
+<input type="hidden" name="role_id" value="<?php echo $r->getId () ?>" />
+<input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
+</form>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="del_role" />
+<input type="hidden" name="role_id" value="<?php echo $r->getId () ?>" />
+<input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
+</form>
+</td>
+<?php
+		print '</tr>';
+	}	
+	print '</tbody></table>' ;
+?>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="add_role" />
+<input type="submit" name="submit" value="<?php echo _('Register new role') ?>" />
+</form>
+<?php
+
+	break ;
+
+case 'add_role':
+	print '<h1>'._('Register a new role').'</h1>' ;
+?>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="post_add_role" />
+<?php echo _('Role name:') ?> <input type="text" name="role_name" size="20" /><br />
+<?php echo _('Role description:') ?><br />
+<textarea name="role_desc" rows="20" cols="80"></textarea>
+<input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
+</form>
+
+<?php
+	 break ;
+
+case 'edit_role':
+	print '<h1>'._('Edit a role').'</h1>' ;
+	$role = new ContribTrackerRole ($role_id) ;
+	
+?>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="post_edit_role" />
+<input type="hidden" name="role_id" value="<?php echo $role->getId() ?>" />
+<?php echo _('Role name:') ?> <input type="text" name="role_name" size="20" value="<?php echo htmlspecialchars ($role->getName()) ?>" /><br />
+<?php echo _('Role description:') ?><br />
+<textarea name="role_desc" rows="20" cols="80"><?php echo htmlspecialchars ($role->getDescription()) ?></textarea>
+<input type="submit" name="submit" value="<?php echo _('Save') ?>" />
+</form>
+<?php
+	 break ;
+
+case 'add_structure':
+	print '<h1>'._('Register a new legal structure').'</h1>' ;
+?>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="post_add_structure" />
+<?php echo _('Structure name:') ?> <input type="text" name="structure_name" size="20" /><br />
+<input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
+</form>
+
+<?php
+	 break ;
+
+case 'edit_structure':
+	print '<h1>'._('Edit a legal structure').'</h1>' ;
+	$structure = new ContribTrackerLegalStructure ($structure_id) ;
+	
+?>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="post_edit_structure" />
+<input type="hidden" name="structure_id" value="<?php echo $structure->getId() ?>" />
+<?php echo _('Structure name:') ?> <input type="text" name="structure_name" size="20" value="<?php echo htmlspecialchars ($structure->getName()) ?>" /><br />
+<input type="submit" name="submit" value="<?php echo _('Save') ?>" />
+</form>
+<?php
+	 break ;
+
+case 'add_actor':
+	print '<h1>'._('Register a new actor').'</h1>' ;
+?>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="post_add_actor" />
+<?php echo _('Actor name:') ?> <input type="text" name="actor_name" size="20" /><br />
+<?php echo _('Actor address:') ?> <input type="text" name="actor_address" size="20" /><br />
+<?php echo _('Actor email:') ?> <input type="text" name="actor_email" size="20" /><br />
+<?php echo _('Actor description:') ?><br />
+<textarea name="actor_desc" rows="20" cols="80"></textarea><br />
+<?php
+	 echo _('Legal structure:') ?>
+<select name="structure_id">
+<?php
+	$structs = $plugin->getLegalStructures () ;
+	foreach ($structs as $s) {
+		print '<option value="'.$s->getId().'">'.htmlspecialchars($s->getName()).'</option>' ;
+	}
+?>
+</select>
+<input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
+</form>
+
+<?php
+	 break ;
+
+case 'edit_actor':
+	print '<h1>'._('Edit an actor').'</h1>' ;
+	$actor = new ContribTrackerActor ($actor_id) ;
+	
+?>
+<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+<input type="hidden" name="action" value="post_edit_actor" />
+<input type="hidden" name="actor_id" value="<?php echo $actor->getId() ?>" />
+<?php echo _('Actor name:') ?> <input type="text" name="actor_name" size="20" value="<?php echo htmlspecialchars ($actor->getName()) ?>" /><br />
+<?php echo _('Actor address:') ?> <input type="text" name="actor_address" size="20" value="<?php echo htmlspecialchars ($actor->getAddress()) ?>" /><br />
+<?php echo _('Actor email:') ?> <input type="text" name="actor_email" size="20" value="<?php echo htmlspecialchars ($actor->getEmail()) ?>" /><br />
+<?php echo _('Actor description:') ?><br />
+<textarea name="actor_desc" rows="20" cols="80"><?php echo htmlspecialchars ($actor->getDescription()) ?></textarea><br />
+<?php
+	 echo _('Legal structure:') ?>
+<select name="structure_id">
+<?php
+	$structs = $plugin->getLegalStructures () ;
+	foreach ($structs as $s) {
+		print '<option value="'.$s->getId().'">'.htmlspecialchars($s->getName()).'</option>' ;
+	}
+?>
+</select>
+<input type="submit" name="submit" value="<?php echo _('Save') ?>" />
+</form>
+<?php
+	 break ;
+
+}
+
+site_project_footer(array());
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
+?>

Modified: trunk/gforge/plugins/contribtracker/www/project_admin.php
===================================================================
--- trunk/gforge/plugins/contribtracker/www/project_admin.php	2009-12-18 17:41:34 UTC (rev 8584)
+++ trunk/gforge/plugins/contribtracker/www/project_admin.php	2009-12-18 17:41:44 UTC (rev 8585)
@@ -296,14 +296,6 @@
 	break ;
 }
 
-
-
-
-
-util_make_link ('/plugins/'.$plugin->name.'/project_admin.php?group_id='.$group->getId ().'&action=foo',
-		_('Blah')) ;
-	
-
 site_project_footer(array());
 
 // Local Variables:




More information about the Fusionforge-commits mailing list