<?php
/*
- * HelloWorld plugin
+ * ContribTracker plugin
*
- * Daniel Perez <danielperez.arg@gmail.com>
+ * Copyright 2009, Roland Mas
*
- * This is an example to watch things in action. You can obviously modify things and logic as you see fit
*/
require_once('../../env.inc.php');
require_once $gfwww.'include/pre.php';
-require_once $gfconfig.'plugins/helloworld/config.php';
-
-// the header that displays for the user portion of the plugin
-function helloworld_Project_Header($params) {
- global $DOCUMENT_ROOT,$HTML,$id;
- $params['toptab']='helloworld';
- $params['group']=$id;
- /*
- Show horizontal links
- */
- site_project_header($params);
-}
+$plugin = plugin_get_object ('contribtracker') ;
+
+function display_contribution ($c, $show_groups = false) {
+ global $plugin ;
+ print '<h2>'.$c->getName().'</h2>' ;
+ if ($show_groups) {
+ print '<strong>'._('Project:').'</strong> ' ;
+ print util_make_link_g ($c->getGroup()->getUnixName(),
+ $c->getGroup()->getId(),
+ htmlspecialchars ($c->getGroup()->getPublicName())) ;
+ print '<br />' ;
+ }
-// the header that displays for the project portion of the plugin
-function helloworld_User_Header($params) {
- global $DOCUMENT_ROOT,$HTML,$user_id;
- $params['toptab']='helloworld';
- $params['user']=$user_id;
- /*
- Show horizontal links
- */
- site_user_header($params);
+ print '<strong>'._('Date:').'</strong> ' ;
+ print strftime (_('%Y-%m-%d'), $c->getDate ()) ;
+ print '<br />' ;
+
+ print '<strong>'._('Description:').'</strong> ' ;
+ print htmlspecialchars ($c->getDescription ()) ;
+ print '<br />' ;
+
+ $parts = $c->getParticipations () ;
+ print '<strong>'.ngettext('Participant:',
+ 'Participants:',
+ count ($parts)).'</strong> ' ;
+ print '<br />' ;
+ print '<ul>' ;
+ foreach ($parts as $p) {
+ print '<li>' ;
+ printf (_('%s: %s (%s)'),
+ htmlspecialchars ($p->getRole()->getName()),
+ util_make_link ('/plugins/'.$plugin->name.'/?actor_id='.$p->getActor()->getId (),
+ htmlspecialchars ($p->getActor()->getName())),
+ htmlspecialchars ($p->getActor()->getLegalStructure()->getName())) ;
+ if ($p->getActor()->getLogo() != '') {
+ print ' ';
+ print util_make_link ('/plugins/'.$plugin->name.'/?actor_id='.$p->getActor()->getId (),
+ '<img type="image/png" src="'.util_make_url ('/plugins/'.$plugin->name.'/actor_logo.php?actor_id='.$p->getActor()->getId ()).'" />') ;
+ }
+ print '</li>' ;
+ }
+ print '</ul>' ;
}
+
+$group_id = getIntFromRequest ('group_id') ;
+$actor_id = getIntFromRequest ('actor_id') ;
+if ($group_id) {
+ $group = group_get_object ($group_id) ;
+ if(!$group || !is_object ($group)) {
+ exit_no_group () ;
+ }
+ if (!$group->isPublic()) {
+ $perm =& $group->getPermission(session_get_user());
+
+ if (!$perm || !is_object($perm) || !$perm->isMember()) {
+ exit_no_group () ;
+ }
+ }
+ $contrib_id = getIntFromRequest ('contrib_id') ;
+ if ($contrib_id) { // List only one particular contribution
+ $contrib = new ContribTrackerContribution ($contrib_id) ;
+ if (!$contrib || !is_object ($contrib)
+ || $contrib->getGroup()->getId() != $group_id) {
+ exit_permission_denied () ;
+ }
+
+ $params = array () ;
+ $params['toptab'] = 'contribtracker' ;
+ $params['group'] = $group_id ;
+ $params['title'] = _('Contribution details') ;
+ $params['pagename'] = 'contribtracker' ;
+ $params['sectionvals'] = array($group->getPublicName());
+
+ site_project_header ($params) ;
+
+ display_contribution ($contrib) ;
+ } else { // List all contributions relevant to a group
+ $params = array () ;
+ $params['toptab'] = 'contribtracker' ;
+ $params['group'] = $group_id ;
+ $params['title'] = sprintf (_('Contributions for project %s'),
+ htmlspecialchars ($group->getPublicName()));
+ $params['pagename'] = 'contribtracker' ;
+ $params['sectionvals'] = array($group->getPublicName());
+
+ site_project_header ($params) ;
- $user = session_get_user(); // get the session user
+ $contribs = $plugin->getContributionsByGroup ($group) ;
- if (!$user || !is_object($user) || $user->isError() || !$user->isActive()) {
- exit_error("Invalid User", "Cannot Process your request for this user.");
+ if (count ($contribs) == 0) {
+ print '<h1>'._('No contributions').'</h1>' ;
+ print _('No contributions have been recorded for this project yet.') ;
+ } else {
+ print '<h1>'.sprintf (_('Contributions for project %s'),
+ htmlspecialchars ($group->getPublicName())).'</h1>' ;
+
+ foreach ($contribs as $c) {
+ display_contribution ($c) ;
+ print '<hr />' ;
+ }
+ }
+ }
+} elseif ($actor_id) {
+ $actor = new ContribTrackerActor ($actor_id) ;
+ if (!is_object ($actor) || $actor->isError()) {
+ exit_error (_('Invalid actor'),
+ _('Invalid actor specified.')) ;
}
- $type = getStringFromRequest('type');
- $id = getStringFromRequest('id');
- $pluginname = getStringFromRequest('pluginname');
+ $HTML->header(array('title'=>_('Actor details'),'pagename'=>'contribtracker'));
- if (!$type) {
- exit_error("Cannot Process your request","No TYPE specified"); // you can create items in Base.tab and customize this messages
- } elseif (!$id) {
- exit_error("Cannot Process your request","No ID specified");
+ print '<h1>'.sprintf(_('Actor details for %s'),
+ htmlspecialchars($actor->getName())).'</h1>' ;
+ print '<ul>' ;
+ print '<li><strong>'._('Name:').'</strong> '.htmlspecialchars($actor->getName()).'</li>' ;
+ print '<li><strong>'._('URL:').'</strong> ' ;
+ if ($actor->getUrl() != '') {
+ print '<a href="'.htmlspecialchars($actor->getUrl()).'">'.htmlspecialchars($actor->getUrl()).'</a>';
+ }
+ print '</li>' ;
+ print '<li><strong>'._('Email:').'</strong> '.htmlspecialchars($actor->getEmail()).'</li>' ;
+ print '<li><strong>'._('Legal structure:').'</strong> '.htmlspecialchars($actor->getLegalStructure()->getName()).'</li>' ;
+ print '<li><strong>'._('Description:').'</strong> '.htmlspecialchars($actor->getDescription()).'</li>' ;
+ print '</ul>' ;
+ if ($actor->getLogo() != '') {
+ if ($actor->getUrl() != '') {
+ print '<a href="'.htmlspecialchars($actor->getUrl()).'"><img type="image/png" src="'.util_make_url ('/plugins/'.$plugin->name.'/actor_logo.php?actor_id='.$actor->getId ()).'" /></a>' ;
+ } else {
+ print '<img type="image/png" src="'.util_make_url ('/plugins/'.$plugin->name.'/actor_logo.php?actor_id='.$actor->getId ()).'" />' ;
+ }
+ }
+
+ $participations = $actor->getParticipations () ;
+
+ if (count ($participations) == 0) {
+ printf (_("%s hasn't been involved in any contributions yet"),
+ htmlspecialchars($actor->getName())) ;
} else {
- if ($type == 'group') {
- $group = group_get_object($id);
- if ( !$group) {
- exit_error("Invalid Project", "Inexistent Project");
- }
- if ( ! ($group->usesPlugin ( $pluginname )) ) {//check if the group has the HelloWorld plugin active
- exit_error("Error", "First activate the $pluginname plugin through the Project's Admin Interface");
- }
- $userperm = $group->getPermission($user);//we'll check if the user belongs to the group (optional)
- if ( !$userperm->IsMember()) {
- exit_error("Access Denied", "You are not a member of this project");
- }
- // other perms checks here...
- helloworld_Project_Header(array('title'=>$pluginname . ' Project Plugin!','pagename'=>"$pluginname",'sectionvals'=>array(group_getname($id))));
- // DO THE STUFF FOR THE PROJECT PART HERE
- echo "We are in the Project HelloWorld plugin <br>";
- echo "Greetings from planet " . $world; // $world comes from the config file in /etc
- } elseif ($type == 'user') {
- $realuser = user_get_object($id);//
- if (!($realuser) || !($realuser->usesPlugin($pluginname))) {
- exit_error("Error", "First activate the User's $pluginname plugin through Account Manteinance Page");
- }
- if ( (!$user) || ($user->getID() != $id)) { // if someone else tried to access the private HelloWorld part of this user
- exit_error("Access Denied", "You cannot access other user's personal $pluginname");
- }
- helloworld_User_Header(array('title'=>'My '.$pluginname,'pagename'=>"$pluginname",'sectionvals'=>array($realuser->getUnixName())));
- // DO THE STUFF FOR THE USER PART HERE
- echo "We are in the User HelloWorld plugin <br>";
- echo "Greetings from planet " . $world; // $world comes from the config file in /etc
- } elseif ($type == 'admin') {
- $group = group_get_object($id);
- if ( !$group) {
- exit_error("Invalid Project", "Inexistent Project");
- }
- if ( ! ($group->usesPlugin ( $pluginname )) ) {//check if the group has the HelloWorld plugin active
- exit_error("Error", "First activate the $pluginname plugin through the Project's Admin Interface");
- }
- $userperm = $group->getPermission($user);//we'll check if the user belongs to the group
- if ( !$userperm->IsMember()) {
- exit_error("Access Denied", "You are not a member of this project");
- }
- //only project admin can access here
- if ( $userperm->isAdmin() ) {
- helloworld_Project_Header(array('title'=>$pluginname . ' Project Plugin!','pagename'=>"$pluginname",'sectionvals'=>array(group_getname($id))));
- // DO THE STUFF FOR THE PROJECT ADMINISTRATION PART HERE
- echo "We are in the Project HelloWorld plugin <font color=\"#ff0000\">ADMINISTRATION</font> <br>";
- echo "Greetings from planet " . $world; // $world comes from the config file in /etc
- } else {
- exit_error("Access Denied", "You are not a project Admin");
- }
+ print '<h1>'.sprintf(ngettext('Contribution by %s',
+ 'Contributions by %s',
+ count($participations)),
+ htmlspecialchars($actor->getName())).'</h1>' ;
+
+ foreach ($participations as $p) {
+ $c = $p->getContribution () ;
+ print '<h2>' . util_make_link ('/plugins/'.$plugin->name.'/?group_id='.$c->getGroup()->getId().'&contrib_id='.$c->getId (),
+ htmlspecialchars ($c->getName())) . '</h2>' ;
+ print '<strong>'._('Project:').'</strong> ' ;
+ print util_make_link_g ($c->getGroup()->getUnixName(),
+ $c->getGroup()->getId(),
+ $c->getGroup()->getPublicName()) ;
+ print '<br /><strong>'._('Role:').'</strong> ' ;
+ print htmlspecialchars ($p->getRole()->getName()) ;
+ print '<hr />' ;
}
- }
+ }
+} else { // Latest contributions, globally
+ $HTML->header(array('title'=>_('Contributions'),'pagename'=>'contribtracker'));
- site_project_footer(array());
+ $contribs = $plugin->getContributions () ;
+
+ if (count ($contribs) == 0) {
+ print '<h1>'._('No contributions').'</h1>' ;
+ print _('No contributions have been recorded yet.') ;
+ } else {
+ print '<h1>'._('Latest contributions').'</h1>' ;
+
+ $i = 1 ;
+ foreach ($contribs as $c) {
+ display_contribution ($c, true) ;
+ print '<hr />' ;
+ $i++ ;
+ if ($i > 20) {
+ break ;
+ }
+ }
+ }
+}
+
+site_project_footer(array());
// Local Variables:
// mode: php