4 * ContribTracker plugin
6 * Copyright 2009, Roland Mas
7 * Copyright 2010 (c) Franck Villaume
8 * http://fusionforge.org/
10 * This file is part of FusionForge.
12 * FusionForge is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 require_once '../../env.inc.php';
28 require_once $gfcommon.'include/pre.php';
29 require_once $gfwww.'admin/admin_utils.php';
30 $plugin = plugin_get_object ('contribtracker') ;
32 $max_logo_size = 50 ; // In kibibytes
34 session_require_global_perm ('forge_admin') ;
36 $action = getStringFromRequest ('action') ;
37 $action = util_ensure_value_in_set ($action, array ('display',
49 'post_edit_structure',
54 function check_role_id ($r_id) {
55 $role = new ContribTrackerRole ($r_id) ;
56 if (!$role || !is_object ($role)) {
57 exit_permission_denied ('','home') ;
60 function check_actor_id ($a_id) {
61 $actor = new ContribTrackerActor ($a_id) ;
62 if (!$actor || !is_object ($actor)) {
63 exit_permission_denied ('','home') ;
66 function check_structure_id ($s_id) {
67 $structure = new ContribTrackerLegalStructure ($s_id) ;
68 if (!$structure || !is_object ($structure)) {
69 exit_permission_denied ('','home') ;
72 function check_logo ($arr, $a_id=false) {
73 global $max_logo_size ;
76 $actor = new ContribTrackerActor ($a_id) ;
77 $default = $actor->getLogo() ;
81 if ($arr['tmp_name'] == '') {
84 if ($arr['size'] > 1024 * $max_logo_size) {
87 $logo = file_get_contents ($arr['tmp_name'], 0, NULL, -1, 1024 * $max_logo_size) ;
89 unlink ($arr['tmp_name']) ;
94 // Get and validate parameters, error if tampered with
101 case 'post_add_role':
102 $name = getStringFromRequest ('role_name') ;
103 $desc = getStringFromRequest ('role_desc') ;
107 $role_id = getIntFromRequest ('role_id') ;
108 check_role_id ($role_id) ;
110 case 'post_edit_role':
111 $role_id = getIntFromRequest ('role_id') ;
112 check_role_id ($role_id) ;
113 $name = getStringFromRequest ('role_name') ;
114 $desc = getStringFromRequest ('role_desc') ;
117 case 'add_structure':
119 case 'post_add_structure':
120 $name = getStringFromRequest ('structure_name') ;
121 $desc = getStringFromRequest ('structure_desc') ;
123 case 'edit_structure':
124 case 'del_structure':
125 $structure_id = getIntFromRequest ('structure_id') ;
126 check_structure_id ($structure_id) ;
128 case 'post_edit_structure':
129 $structure_id = getIntFromRequest ('structure_id') ;
130 check_structure_id ($structure_id) ;
131 $name = getStringFromRequest ('structure_name') ;
132 $desc = getStringFromRequest ('structure_desc') ;
137 case 'post_add_actor':
138 $name = getStringFromRequest ('actor_name') ;
139 $url = getStringFromRequest ('actor_url') ;
140 $email = getStringFromRequest ('actor_email') ;
141 $desc = getStringFromRequest ('actor_desc') ;
142 $logoarr = getUploadedFile ('actor_logo') ;
143 $logo = check_logo ($logoarr) ;
144 $structure_id = getIntFromRequest ('structure_id') ;
145 check_structure_id ($structure_id) ;
149 $actor_id = getIntFromRequest ('actor_id') ;
150 check_actor_id ($actor_id) ;
152 case 'post_edit_actor':
153 $actor_id = getIntFromRequest ('actor_id') ;
154 check_actor_id ($actor_id) ;
155 $name = getStringFromRequest ('actor_name') ;
156 $url = getStringFromRequest ('actor_url') ;
157 $email = getStringFromRequest ('actor_email') ;
158 $desc = getStringFromRequest ('actor_desc') ;
159 $logoarr = getUploadedFile ('actor_logo') ;
160 $logo = check_logo ($logoarr, $actor_id) ;
161 $structure_id = getIntFromRequest ('structure_id') ;
162 check_structure_id ($structure_id) ;
167 // Do the required action
170 case 'post_add_role':
171 $role = new ContribTrackerRole () ;
172 if (!$role->create ($name, $desc)) {
173 exit_error ($role->getErrorMessage(),'contribtracker') ;
175 $role_id = $role->getId() ;
176 $action = 'display' ;
179 $role = new ContribTrackerRole ($role_id) ;
181 $action = 'display' ;
183 case 'post_edit_role':
184 $role = new ContribTrackerRole ($role_id) ;
185 $role->update ($name, $desc) ;
186 $action = 'display' ;
189 case 'post_add_structure':
190 $structure = new ContribTrackerLegalStructure () ;
191 if (!$structure->create ($name, $desc)) {
192 exit_error ($structure->getErrorMessage(),'contribtracker') ;
194 $structure_id = $structure->getId() ;
195 $action = 'display' ;
197 case 'del_structure':
198 $structure = new ContribTrackerLegalStructure ($structure_id) ;
199 $structure->delete () ;
200 $action = 'display' ;
202 case 'post_edit_structure':
203 $structure = new ContribTrackerLegalStructure ($structure_id) ;
204 $structure->update ($name, $desc) ;
205 $action = 'display' ;
208 case 'post_add_actor':
209 $actor = new ContribTrackerActor () ;
210 $structure = new ContribTrackerLegalStructure ($structure_id) ;
211 if (!$actor->create ($name, $url, $email, $desc, $logo, $structure)) {
212 exit_error ($actor->getErrorMessage(),'contribtracker') ;
214 $actor_id = $actor->getId() ;
215 $action = 'display' ;
218 $actor = new ContribTrackerActor ($actor_id) ;
220 $action = 'display' ;
222 case 'post_edit_actor':
223 $actor = new ContribTrackerActor ($actor_id) ;
224 $structure = new ContribTrackerLegalStructure ($structure_id) ;
225 $actor->update ($name, $url, $email, $desc, $logo, $structure) ;
226 $action = 'display' ;
230 // Display appropriate forms
231 site_admin_header (array ('title' => _('Contribution tracker administration'))) ;
235 print '<h1>'._('Existing actors').'</h1>' ;
236 $actors = $plugin->getActors () ;
237 if (count ($actors)) {
238 print '<table><thead><tr>' ;
239 print '<td><strong>'._('Logo').'</strong></td>' ;
240 print '<td><strong>'._('Short name').'</strong></td>' ;
241 print '<td><strong>'._('URL').'</strong></td>' ;
242 print '<td><strong>'._('Email').'</strong></td>' ;
243 print '<td><strong>'._('Description').'</strong></td>' ;
244 print '<td><strong>'._('Legal structure').'</strong></td>' ;
245 print '<td><strong>'._('Actions').'</strong></td>' ;
246 print '</tr></thead><tbody>' ;
247 foreach ($actors as $a) {
250 if ($a->getLogo() != '') {
251 print '<img type="image/png" src="'.util_make_url ('/plugins/'.$plugin->name.'/actor_logo.php?actor_id='.$a->getId ()).'" />' ;
254 print '<td>'.htmlspecialchars($a->getName()).'</td>' ;
256 if ($a->getUrl() != '') {
257 print '<a href="'.htmlspecialchars($a->getUrl()).'">'.htmlspecialchars($a->getUrl()).'</a>';
260 print '<td>'.htmlspecialchars($a->getEmail()).'</td>' ;
261 print '<td>'.htmlspecialchars($a->getDescription()).'</td>' ;
262 print '<td>'.htmlspecialchars($a->getLegalStructure()->getName()).'</td>' ;
265 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
266 <input type="hidden" name="action" value="edit_actor" />
267 <input type="hidden" name="actor_id" value="<?php echo $a->getId () ?>" />
268 <input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
270 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
271 <input type="hidden" name="action" value="del_actor" />
272 <input type="hidden" name="actor_id" value="<?php echo $a->getId () ?>" />
273 <input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
279 print '</tbody></table>' ;
281 print _('No legal structures currently defined.') ;
283 $structs = $plugin->getLegalStructures () ;
284 if (count ($structs)) {
286 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
287 <input type="hidden" name="action" value="add_actor" />
288 <input type="submit" name="submit" value="<?php echo _('Register new actor') ?>" />
293 print _("No legal structures yet, cannot define actors without them.") ;
296 print '<h1>'._('Existing legal structures').'</h1>' ;
297 $structs = $plugin->getLegalStructures () ;
298 if (count ($structs)) {
299 print '<table><thead><tr>' ;
300 print '<td><strong>'._('Short name').'</strong></td>' ;
301 print '<td><strong>'._('Actions').'</strong></td>' ;
302 print '</tr></thead><tbody>' ;
303 foreach ($structs as $s) {
305 print '<td>'.htmlspecialchars($s->getName()).'</td>' ;
308 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
309 <input type="hidden" name="action" value="edit_structure" />
310 <input type="hidden" name="structure_id" value="<?php echo $s->getId () ?>" />
311 <input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
313 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
314 <input type="hidden" name="action" value="del_structure" />
315 <input type="hidden" name="structure_id" value="<?php echo $s->getId () ?>" />
316 <input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
322 print '</tbody></table>' ;
324 print _('No legal structures currently defined.') ;
327 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
328 <input type="hidden" name="action" value="add_structure" />
329 <input type="submit" name="submit" value="<?php echo _('Register new legal structure') ?>" />
333 print '<h1>'._('Existing roles').'</h1>' ;
334 $roles = $plugin->getRoles () ;
335 if (count ($roles)) {
336 print '<table><thead><tr>' ;
337 print '<td><strong>'._('Short name').'</strong></td>' ;
338 print '<td><strong>'._('Description').'</strong></td>' ;
339 print '<td><strong>'._('Actions').'</strong></td>' ;
340 print '</tr></thead><tbody>' ;
341 foreach ($roles as $r) {
343 print '<td>'.htmlspecialchars($r->getName()).'</td>' ;
344 print '<td>'.htmlspecialchars($r->getDescription()).'</td>' ;
347 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
348 <input type="hidden" name="action" value="edit_role" />
349 <input type="hidden" name="role_id" value="<?php echo $r->getId () ?>" />
350 <input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
352 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
353 <input type="hidden" name="action" value="del_role" />
354 <input type="hidden" name="role_id" value="<?php echo $r->getId () ?>" />
355 <input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
361 print '</tbody></table>' ;
363 print _('No roles currently defined.') ;
366 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
367 <input type="hidden" name="action" value="add_role" />
368 <input type="submit" name="submit" value="<?php echo _('Register new role') ?>" />
375 print '<h1>'._('Register a new role').'</h1>' ;
377 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
378 <input type="hidden" name="action" value="post_add_role" />
379 <?php echo _('Role Name')._(':') ?> <input type="text" name="role_name" size="20" /><br />
380 <?php echo _('Role description')._(':') ?><br />
381 <textarea name="role_desc" rows="20" cols="80"></textarea><br />
382 <input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
389 print '<h1>'._('Edit a role').'</h1>' ;
390 $role = new ContribTrackerRole ($role_id) ;
393 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
394 <input type="hidden" name="action" value="post_edit_role" />
395 <input type="hidden" name="role_id" value="<?php echo $role->getId() ?>" />
396 <?php echo _('Role Name')._(':') ?> <input type="text" name="role_name" size="20" value="<?php echo htmlspecialchars ($role->getName()) ?>" /><br />
397 <?php echo _('Role description')._(':') ?><br />
398 <textarea name="role_desc" rows="20" cols="80"><?php echo htmlspecialchars ($role->getDescription()) ?></textarea><br />
399 <input type="submit" name="submit" value="<?php echo _('Save') ?>" />
404 case 'add_structure':
405 print '<h1>'._('Register a new legal structure').'</h1>' ;
407 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
408 <input type="hidden" name="action" value="post_add_structure" />
409 <?php echo _('Structure name')._(':') ?> <input type="text" name="structure_name" size="20" /><br />
410 <input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
416 case 'edit_structure':
417 print '<h1>'._('Edit a legal structure').'</h1>' ;
418 $structure = new ContribTrackerLegalStructure ($structure_id) ;
421 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
422 <input type="hidden" name="action" value="post_edit_structure" />
423 <input type="hidden" name="structure_id" value="<?php echo $structure->getId() ?>" />
424 <?php echo _('Structure name')._(':') ?> <input type="text" name="structure_name" size="20" value="<?php echo htmlspecialchars ($structure->getName()) ?>" /><br />
425 <input type="submit" name="submit" value="<?php echo _('Save') ?>" />
431 print '<h1>'._('Register a new actor').'</h1>' ;
433 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post" enctype="multipart/form-data">
434 <input type="hidden" name="action" value="post_add_actor" />
435 <?php echo _('Actor name')._(':') ?> <input type="text" name="actor_name" size="20" /><br />
436 <?php echo _('Actor URL')._(':') ?> <input type="text" name="actor_url" size="20" /><br />
437 <?php echo _('Actor email')._(':') ?> <input type="text" name="actor_email" size="20" /><br />
438 <?php echo _('Actor description')._(':') ?><br />
439 <textarea name="actor_desc" rows="20" cols="80"></textarea><br />
440 <?php printf (_('Actor logo (PNG, %d kB max)')._(':'), $max_logo_size) ?> <input type="file" name="actor_logo" /><br />
442 echo _('Legal structure')._(':') ?>
443 <select name="structure_id">
445 $structs = $plugin->getLegalStructures () ;
446 foreach ($structs as $s) {
447 print '<option value="'.$s->getId().'">'.htmlspecialchars($s->getName()).'</option>' ;
451 <input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
458 print '<h1>'._('Edit an actor').'</h1>' ;
459 $actor = new ContribTrackerActor ($actor_id) ;
462 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post" enctype="multipart/form-data">
463 <input type="hidden" name="action" value="post_edit_actor" />
464 <input type="hidden" name="actor_id" value="<?php echo $actor->getId() ?>" />
465 <?php echo _('Actor name')._(':') ?> <input type="text" name="actor_name" size="20" value="<?php echo htmlspecialchars ($actor->getName()) ?>" /><br />
466 <?php echo _('Actor URL')._(':') ?> <input type="text" name="actor_url" size="20" value="<?php echo htmlspecialchars ($actor->getUrl()) ?>" /><br />
467 <?php echo _('Actor email')._(':') ?> <input type="text" name="actor_email" size="20" value="<?php echo htmlspecialchars ($actor->getEmail()) ?>" /><br />
468 <?php echo _('Actor description')._(':') ?><br />
469 <textarea name="actor_desc" rows="20" cols="80"><?php echo htmlspecialchars ($actor->getDescription()) ?></textarea><br />
470 <?php printf (_('Actor logo (PNG, %d kB max)')._(':'), $max_logo_size) ?> <input type="file" name="actor_logo" /><br />
472 if ($actor->getLogo() != '') {
473 print '<img type="image/png" src="'.util_make_url ('/plugins/'.$plugin->name.'/actor_logo.php?actor_id='.$actor->getId ()).'" />' ;
476 echo _('Legal structure')._(':') ?>
477 <select name="structure_id">
479 $structs = $plugin->getLegalStructures () ;
480 foreach ($structs as $s) {
481 print '<option value="'.$s->getId().'".' ;
482 if ($s->getId() == $actor->getLegalStructure()->getId()) {
485 print '>'.htmlspecialchars($s->getName()).'</option>' ;
489 <input type="submit" name="submit" value="<?php echo _('Save') ?>" />
496 site_project_footer(array());
500 // c-file-style: "bsd"