4 * ContribTracker plugin
6 * Copyright 2009, Roland Mas
10 require_once '../../env.inc.php';
11 require_once $gfcommon.'include/pre.php';
12 $plugin = plugin_get_object('contribtracker') ;
14 $group_id = getIntFromRequest('group_id') ;
15 session_require_perm('project_admin', $group_id) ;
16 $group = group_get_object($group_id) ;
19 $params['toptab'] = 'contribtracker' ;
20 $params['group'] = $group_id ;
21 $params['title'] = sprintf (_('Contribution tracker for project %s'),
22 htmlspecialchars ($group->getPublicName()));
23 $params['pagename'] = 'contribtracker' ;
24 $params['sectionvals'] = array($group->getPublicName());
26 $date_format = _('%Y-%m-%d') ;
28 site_project_header ($params) ;
30 $action = getStringFromRequest ('action') ;
31 $action = util_ensure_value_in_set ($action, array ('display',
41 function check_contrib_id ($c_id, $g_id) {
42 $contrib = new ContribTrackerContribution ($c_id) ;
43 if (!$contrib || !is_object ($contrib)
44 || $contrib->getGroup()->getId() != $g_id) {
45 exit_permission_denied () ;
48 function check_part_id ($p_id, $c_id) {
49 $part = new ContribTrackerParticipation ($p_id) ;
50 if (!$part || !is_object ($part)
51 || $part->getContribution()->getId() != $c_id) {
52 exit_permission_denied () ;
55 function check_date () {
57 $r_date = getStringFromRequest ('date') ;
58 $tmp = strptime ($r_date, $date_format) ;
62 $date = mktime (0,0,0,$tmp['tm_mon']+1,$tmp['tm_mday'],$tmp['tm_year']+1900);
66 function check_updown () {
67 $up = getStringFromRequest ('up') ;
68 $down = getStringFromRequest ('down') ;
71 } elseif ($down != '') {
78 // Get and validate parameters, error if tampered with
84 case 'post_add_contrib':
85 $date = check_date () ;
86 $name = getStringFromRequest ('contrib_name') ;
87 $desc = getStringFromRequest ('contrib_desc') ;
91 $contrib_id = getIntFromRequest ('contrib_id') ;
92 check_contrib_id ($contrib_id, $group_id) ;
94 case 'post_edit_contrib':
95 $contrib_id = getIntFromRequest ('contrib_id') ;
96 check_contrib_id ($contrib_id, $group_id) ;
97 $date = check_date () ;
98 $name = getStringFromRequest ('contrib_name') ;
99 $desc = getStringFromRequest ('contrib_desc') ;
102 $contrib_id = getIntFromRequest ('contrib_id') ;
103 check_contrib_id ($contrib_id, $group_id) ;
104 $part_id = getIntFromRequest ('part_id') ;
105 check_part_id ($part_id, $contrib_id) ;
108 $contrib_id = getIntFromRequest ('contrib_id') ;
109 check_contrib_id ($contrib_id, $group_id) ;
110 $part_id = getIntFromRequest ('part_id') ;
111 check_part_id ($part_id, $contrib_id) ;
112 $updown = check_updown () ;
115 $contrib_id = getIntFromRequest ('contrib_id') ;
116 check_contrib_id ($contrib_id, $group_id) ;
117 $actor_id = getIntFromRequest ('actor_id') ;
118 $actor = new ContribTrackerActor ($actor_id) ;
119 if (!$actor || !is_object ($actor)) {
120 exit_permission_denied () ;
122 $role_id = getIntFromRequest ('role_id') ;
123 $role = new ContribTrackerRole ($role_id) ;
124 if (!$role || !is_object ($role)) {
125 exit_permission_denied () ;
130 // Do the required action
133 case 'post_add_contrib':
134 $contrib = new ContribTrackerContribution () ;
135 if (!$contrib->create ($name, $date, $desc, $group)) {
136 $error_msg = $contrib->getErrorMessage() ;
139 $contrib_id = $contrib->getId() ;
140 $action = 'edit_contrib' ;
144 $contrib = new ContribTrackerContribution ($contrib_id) ;
145 $contrib->delete () ;
146 $action = 'display' ;
148 case 'post_edit_contrib':
149 $contrib = new ContribTrackerContribution ($contrib_id) ;
150 $contrib->update ($name, $date, $desc, $group) ;
151 $action = 'display' ;
154 $part = new ContribTrackerParticipation ($part_id) ;
156 $action = 'edit_contrib' ;
159 $part = new ContribTrackerParticipation ($part_id) ;
162 } elseif ($updown < 0) {
165 $action = 'edit_contrib' ;
168 $contrib = new ContribTrackerContribution ($contrib_id) ;
169 $actor = new ContribTrackerActor ($actor_id) ;
170 $role = new ContribTrackerRole ($role_id) ;
171 $part = new ContribTrackerParticipation () ;
172 $part->create ($contrib, $actor, $role) ;
173 $action = 'edit_contrib' ;
177 // Display appropriate forms
179 if(isset($error_msg) && !empty($error_msg)) {
180 echo "<div class='error'>".$error_msg."</div>";
184 print '<h1>'._('Register a new contribution').'</h1>' ;
186 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/project_admin.php') ?>" method="post">
187 <input type="hidden" name="action" value="post_add_contrib" />
188 <input type="hidden" name="group_id" value="<?php echo $group_id ?>" />
189 <?php echo _('Contribution name')._(':') ?> <input type="text" name="contrib_name" size="20" /><br />
190 <?php echo _('Contribution date')._(':') ?> <input type="text" name="date" value="<?php echo strftime($date_format,time()) ?>" /><br />
191 <?php echo _('Contribution description')._(':') ?><br />
192 <textarea name="contrib_desc" rows="20" cols="80"></textarea><br />
193 <input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
199 print '<h1>'._('Edit a contribution').'</h1>' ;
201 $contrib = new ContribTrackerContribution ($contrib_id) ;
203 print '<h3>'._('Contribution details').'</h3>' ;
206 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/project_admin.php') ?>" method="post">
207 <input type="hidden" name="action" value="post_edit_contrib" />
208 <input type="hidden" name="group_id" value="<?php echo $group_id ?>" />
209 <input type="hidden" name="contrib_id" value="<?php echo $contrib->getId() ?>" />
210 <?php echo _('Contribution name')._(':') ?> <input type="text" name="contrib_name" size="20" value="<?php echo htmlspecialchars ($contrib->getName()) ?>" /><br />
211 <?php echo _('Contribution date')._(':') ?> <input type="text" name="date" value="<?php echo strftime($date_format,time()) ?>" /><br />
212 <?php echo _('Contribution description')._(':') ?><br />
213 <textarea name="contrib_desc" rows="20" cols="80"><?php echo htmlspecialchars ($contrib->getDescription()) ?></textarea><br />
214 <input type="submit" name="submit" value="<?php echo _('Save') ?>" />
218 print '<h3>'._('Current participants').'</h3>' ;
220 $parts = $contrib->getParticipations () ;
221 print '<strong>'.ngettext('Participant:',
223 count ($parts)).'</strong> ' ;
226 foreach ($parts as $p) {
228 printf (_('%s: %s (%s)'),
229 htmlspecialchars ($p->getRole()->getName()),
230 util_make_link ('/plugins/'.$plugin->name.'/?actor_id='.$p->getActor()->getId (),
231 htmlspecialchars ($p->getActor()->getName())),
232 htmlspecialchars ($p->getActor()->getLegalStructure()->getName())) ;
234 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/project_admin.php') ?>" method="post">
235 <input type="hidden" name="action" value="del_part" />
236 <input type="hidden" name="group_id" value="<?php echo $group_id ?>" />
237 <input type="hidden" name="contrib_id" value="<?php echo $contrib->getId() ?>" />
238 <input type="hidden" name="part_id" value="<?php echo $p->getId() ?>" />
239 <input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
241 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/project_admin.php') ?>" method="post">
242 <input type="hidden" name="action" value="move_part" />
243 <input type="hidden" name="group_id" value="<?php echo $group_id ?>" />
244 <input type="hidden" name="contrib_id" value="<?php echo $contrib->getId() ?>" />
245 <input type="hidden" name="part_id" value="<?php echo $p->getId() ?>" />
246 <input type="submit" name="down" value="<?php echo _('Move participant down') ?>" />
247 <input type="submit" name="up" value="<?php echo _('Move participant up') ?>" />
254 print '<h3>'._('Add a participant').'</h3>' ;
257 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/project_admin.php') ?>" method="post">
258 <input type="hidden" name="action" value="add_part" />
259 <input type="hidden" name="group_id" value="<?php echo $group_id ?>" />
260 <input type="hidden" name="contrib_id" value="<?php echo $contrib->getId() ?>" />
261 <select name="actor_id">
263 $actors = $plugin->getActors () ;
264 foreach ($actors as $a) {
265 print '<option value="'.$a->getId().'">'.htmlspecialchars($a->getName()).'</option>' ;
269 <select name="role_id">
271 $roles = $plugin->getRoles () ;
272 foreach ($roles as $r) {
273 print '<option value="'.$r->getId().'">'.htmlspecialchars($r->getName()).'</option>' ;
277 <input type="submit" name="submit" value="<?php echo _('Add participant') ?>" />
283 $contribs = $plugin->getContributionsByGroup ($group) ;
284 if (count ($contribs) != 0) {
285 print '<h1>'._('Existing contributions').'</h1>' ;
287 foreach ($contribs as $c) {
288 print '<h3>'.$c->getName().'</h3>' ;
289 print '<strong>'._('Date')._(':').'</strong> ' ;
290 print strftime (_('%Y-%m-%d'), $c->getDate ()) ;
293 print '<strong>'._('Description')._(':').'</strong> ' ;
294 print htmlspecialchars ($c->getDescription ()) ;
297 $parts = $c->getParticipations () ;
298 print '<strong>'.ngettext('Participant:',
300 count ($parts)).'</strong> ' ;
303 foreach ($parts as $p) {
305 printf (_('%s: %s (%s)'),
306 htmlspecialchars ($p->getRole()->getName()),
307 util_make_link ('/plugins/'.$plugin->name.'/?actor_id='.$p->getActor()->getId (),
308 htmlspecialchars ($p->getActor()->getName())),
309 htmlspecialchars ($p->getActor()->getLegalStructure()->getName())) ;
314 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/project_admin.php') ?>" method="post">
315 <input type="hidden" name="action" value="edit_contrib" />
316 <input type="hidden" name="group_id" value="<?php echo $group_id ?>" />
317 <input type="hidden" name="contrib_id" value="<?php echo $c->getId() ?>" />
318 <input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
320 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/project_admin.php') ?>" method="post">
321 <input type="hidden" name="action" value="del_contrib" />
322 <input type="hidden" name="group_id" value="<?php echo $group_id ?>" />
323 <input type="hidden" name="contrib_id" value="<?php echo $c->getId() ?>" />
324 <input type="submit" name="submit" value="<?php echo _('Delete'); ?>" />
330 print '<h1>'._('No contributions for this project yet.').'</h1>' ;
333 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/project_admin.php') ?>" method="post">
334 <input type="hidden" name="action" value="add_contrib" />
335 <input type="hidden" name="group_id" value="<?php echo $group_id ?>" />
336 <input type="submit" name="submit" value="<?php echo _('Add new contribution') ?>" />
342 site_project_footer(array());
346 // c-file-style: "bsd"