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') ;
37 $action = getStringFromRequest ('action') ;
38 $action = util_ensure_value_in_set ($action, array ('display',
50 'post_edit_structure',
55 function check_role_id ($r_id) {
56 $role = new ContribTrackerRole ($r_id) ;
57 if (!$role || !is_object ($role)) {
58 exit_permission_denied ('','home') ;
61 function check_actor_id ($a_id) {
62 $actor = new ContribTrackerActor ($a_id) ;
63 if (!$actor || !is_object ($actor)) {
64 exit_permission_denied ('','home') ;
67 function check_structure_id ($s_id) {
68 $structure = new ContribTrackerLegalStructure ($s_id) ;
69 if (!$structure || !is_object ($structure)) {
70 exit_permission_denied ('','home') ;
73 function check_logo ($arr, $a_id=false) {
74 global $max_logo_size ;
77 $actor = new ContribTrackerActor ($a_id) ;
78 $default = $actor->getLogo() ;
82 if ($arr['tmp_name'] == '') {
85 if ($arr['size'] > 1024 * $max_logo_size) {
88 $logo = file_get_contents ($arr['tmp_name'], 0, NULL, -1, 1024 * $max_logo_size) ;
90 unlink ($arr['tmp_name']) ;
95 // Get and validate parameters, error if tampered with
102 case 'post_add_role':
103 $name = getStringFromRequest ('role_name') ;
104 $desc = getStringFromRequest ('role_desc') ;
108 $role_id = getIntFromRequest ('role_id') ;
109 check_role_id ($role_id) ;
111 case 'post_edit_role':
112 $role_id = getIntFromRequest ('role_id') ;
113 check_role_id ($role_id) ;
114 $name = getStringFromRequest ('role_name') ;
115 $desc = getStringFromRequest ('role_desc') ;
118 case 'add_structure':
120 case 'post_add_structure':
121 $name = getStringFromRequest ('structure_name') ;
122 $desc = getStringFromRequest ('structure_desc') ;
124 case 'edit_structure':
125 case 'del_structure':
126 $structure_id = getIntFromRequest ('structure_id') ;
127 check_structure_id ($structure_id) ;
129 case 'post_edit_structure':
130 $structure_id = getIntFromRequest ('structure_id') ;
131 check_structure_id ($structure_id) ;
132 $name = getStringFromRequest ('structure_name') ;
133 $desc = getStringFromRequest ('structure_desc') ;
138 case 'post_add_actor':
139 $name = getStringFromRequest ('actor_name') ;
140 $url = getStringFromRequest ('actor_url') ;
141 $email = getStringFromRequest ('actor_email') ;
142 $desc = getStringFromRequest ('actor_desc') ;
143 $logoarr = getUploadedFile ('actor_logo') ;
144 $logo = check_logo ($logoarr) ;
145 $structure_id = getIntFromRequest ('structure_id') ;
146 check_structure_id ($structure_id) ;
150 $actor_id = getIntFromRequest ('actor_id') ;
151 check_actor_id ($actor_id) ;
153 case 'post_edit_actor':
154 $actor_id = getIntFromRequest ('actor_id') ;
155 check_actor_id ($actor_id) ;
156 $name = getStringFromRequest ('actor_name') ;
157 $url = getStringFromRequest ('actor_url') ;
158 $email = getStringFromRequest ('actor_email') ;
159 $desc = getStringFromRequest ('actor_desc') ;
160 $logoarr = getUploadedFile ('actor_logo') ;
161 $logo = check_logo ($logoarr, $actor_id) ;
162 $structure_id = getIntFromRequest ('structure_id') ;
163 check_structure_id ($structure_id) ;
168 // Do the required action
171 case 'post_add_role':
172 $role = new ContribTrackerRole () ;
173 if (!$role->create ($name, $desc)) {
174 exit_error ($role->getErrorMessage(),'contribtracker') ;
176 $role_id = $role->getId() ;
177 $action = 'display' ;
180 $role = new ContribTrackerRole ($role_id) ;
182 $action = 'display' ;
184 case 'post_edit_role':
185 $role = new ContribTrackerRole ($role_id) ;
186 $role->update ($name, $desc) ;
187 $action = 'display' ;
190 case 'post_add_structure':
191 $structure = new ContribTrackerLegalStructure () ;
192 if (!$structure->create ($name, $desc)) {
193 exit_error ($structure->getErrorMessage(),'contribtracker') ;
195 $structure_id = $structure->getId() ;
196 $action = 'display' ;
198 case 'del_structure':
199 $structure = new ContribTrackerLegalStructure ($structure_id) ;
200 $structure->delete () ;
201 $action = 'display' ;
203 case 'post_edit_structure':
204 $structure = new ContribTrackerLegalStructure ($structure_id) ;
205 $structure->update ($name, $desc) ;
206 $action = 'display' ;
209 case 'post_add_actor':
210 $actor = new ContribTrackerActor () ;
211 $structure = new ContribTrackerLegalStructure ($structure_id) ;
212 if (!$actor->create ($name, $url, $email, $desc, $logo, $structure)) {
213 exit_error ($actor->getErrorMessage(),'contribtracker') ;
215 $actor_id = $actor->getId() ;
216 $action = 'display' ;
219 $actor = new ContribTrackerActor ($actor_id) ;
221 $action = 'display' ;
223 case 'post_edit_actor':
224 $actor = new ContribTrackerActor ($actor_id) ;
225 $structure = new ContribTrackerLegalStructure ($structure_id) ;
226 $actor->update ($name, $url, $email, $desc, $logo, $structure) ;
227 $action = 'display' ;
231 // Display appropriate forms
232 site_admin_header (array ('title' => _('Contribution tracker administration'))) ;
236 print '<h1>'._('Existing actors').'</h1>' ;
237 $actors = $plugin->getActors () ;
238 if (count ($actors)) {
239 print '<table><thead><tr>' ;
240 print '<td><strong>'._('Logo').'</strong></td>' ;
241 print '<td><strong>'._('Short name').'</strong></td>' ;
242 print '<td><strong>'._('URL').'</strong></td>' ;
243 print '<td><strong>'._('Email').'</strong></td>' ;
244 print '<td><strong>'._('Description').'</strong></td>' ;
245 print '<td><strong>'._('Legal structure').'</strong></td>' ;
246 print '<td><strong>'._('Actions').'</strong></td>' ;
247 print '</tr></thead><tbody>' ;
248 foreach ($actors as $a) {
251 if ($a->getLogo() != '') {
252 print '<img type="image/png" src="'.util_make_url ('/plugins/'.$plugin->name.'/actor_logo.php?actor_id='.$a->getId ()).'" />' ;
255 print '<td>'.htmlspecialchars($a->getName()).'</td>' ;
257 if ($a->getUrl() != '') {
258 print '<a href="'.htmlspecialchars($a->getUrl()).'">'.htmlspecialchars($a->getUrl()).'</a>';
261 print '<td>'.htmlspecialchars($a->getEmail()).'</td>' ;
262 print '<td>'.htmlspecialchars($a->getDescription()).'</td>' ;
263 print '<td>'.htmlspecialchars($a->getLegalStructure()->getName()).'</td>' ;
266 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
267 <input type="hidden" name="action" value="edit_actor" />
268 <input type="hidden" name="actor_id" value="<?php echo $a->getId () ?>" />
269 <input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
271 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
272 <input type="hidden" name="action" value="del_actor" />
273 <input type="hidden" name="actor_id" value="<?php echo $a->getId () ?>" />
274 <input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
280 print '</tbody></table>' ;
282 print _('No legal structures currently defined.') ;
284 $structs = $plugin->getLegalStructures () ;
285 if (count ($structs)) {
287 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
288 <input type="hidden" name="action" value="add_actor" />
289 <input type="submit" name="submit" value="<?php echo _('Register new actor') ?>" />
294 print _("No legal structures yet, can't define actors without them.") ;
297 print '<h1>'._('Existing legal structures').'</h1>' ;
298 $structs = $plugin->getLegalStructures () ;
299 if (count ($structs)) {
300 print '<table><thead><tr>' ;
301 print '<td><strong>'._('Short name').'</strong></td>' ;
302 print '<td><strong>'._('Actions').'</strong></td>' ;
303 print '</tr></thead><tbody>' ;
304 foreach ($structs as $s) {
306 print '<td>'.htmlspecialchars($s->getName()).'</td>' ;
309 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
310 <input type="hidden" name="action" value="edit_structure" />
311 <input type="hidden" name="structure_id" value="<?php echo $s->getId () ?>" />
312 <input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
314 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
315 <input type="hidden" name="action" value="del_structure" />
316 <input type="hidden" name="structure_id" value="<?php echo $s->getId () ?>" />
317 <input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
323 print '</tbody></table>' ;
325 print _('No legal structures currently defined.') ;
328 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
329 <input type="hidden" name="action" value="add_structure" />
330 <input type="submit" name="submit" value="<?php echo _('Register new legal structure') ?>" />
334 print '<h1>'._('Existing roles').'</h1>' ;
335 $roles = $plugin->getRoles () ;
336 if (count ($roles)) {
337 print '<table><thead><tr>' ;
338 print '<td><strong>'._('Short name').'</strong></td>' ;
339 print '<td><strong>'._('Description').'</strong></td>' ;
340 print '<td><strong>'._('Actions').'</strong></td>' ;
341 print '</tr></thead><tbody>' ;
342 foreach ($roles as $r) {
344 print '<td>'.htmlspecialchars($r->getName()).'</td>' ;
345 print '<td>'.htmlspecialchars($r->getDescription()).'</td>' ;
348 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
349 <input type="hidden" name="action" value="edit_role" />
350 <input type="hidden" name="role_id" value="<?php echo $r->getId () ?>" />
351 <input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
353 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
354 <input type="hidden" name="action" value="del_role" />
355 <input type="hidden" name="role_id" value="<?php echo $r->getId () ?>" />
356 <input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
362 print '</tbody></table>' ;
364 print _('No roles currently defined.') ;
367 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
368 <input type="hidden" name="action" value="add_role" />
369 <input type="submit" name="submit" value="<?php echo _('Register new role') ?>" />
376 print '<h1>'._('Register a new role').'</h1>' ;
378 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
379 <input type="hidden" name="action" value="post_add_role" />
380 <?php echo _('Role name')._(':') ?> <input type="text" name="role_name" size="20" /><br />
381 <?php echo _('Role description')._(':') ?><br />
382 <textarea name="role_desc" rows="20" cols="80"></textarea><br />
383 <input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
390 print '<h1>'._('Edit a role').'</h1>' ;
391 $role = new ContribTrackerRole ($role_id) ;
394 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
395 <input type="hidden" name="action" value="post_edit_role" />
396 <input type="hidden" name="role_id" value="<?php echo $role->getId() ?>" />
397 <?php echo _('Role name')._(':') ?> <input type="text" name="role_name" size="20" value="<?php echo htmlspecialchars ($role->getName()) ?>" /><br />
398 <?php echo _('Role description')._(':') ?><br />
399 <textarea name="role_desc" rows="20" cols="80"><?php echo htmlspecialchars ($role->getDescription()) ?></textarea><br />
400 <input type="submit" name="submit" value="<?php echo _('Save') ?>" />
405 case 'add_structure':
406 print '<h1>'._('Register a new legal structure').'</h1>' ;
408 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
409 <input type="hidden" name="action" value="post_add_structure" />
410 <?php echo _('Structure name')._(':') ?> <input type="text" name="structure_name" size="20" /><br />
411 <input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
417 case 'edit_structure':
418 print '<h1>'._('Edit a legal structure').'</h1>' ;
419 $structure = new ContribTrackerLegalStructure ($structure_id) ;
422 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
423 <input type="hidden" name="action" value="post_edit_structure" />
424 <input type="hidden" name="structure_id" value="<?php echo $structure->getId() ?>" />
425 <?php echo _('Structure name')._(':') ?> <input type="text" name="structure_name" size="20" value="<?php echo htmlspecialchars ($structure->getName()) ?>" /><br />
426 <input type="submit" name="submit" value="<?php echo _('Save') ?>" />
432 print '<h1>'._('Register a new actor').'</h1>' ;
434 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post" enctype="multipart/form-data">
435 <input type="hidden" name="action" value="post_add_actor" />
436 <?php echo _('Actor name')._(':') ?> <input type="text" name="actor_name" size="20" /><br />
437 <?php echo _('Actor URL')._(':') ?> <input type="text" name="actor_url" size="20" /><br />
438 <?php echo _('Actor email')._(':') ?> <input type="text" name="actor_email" size="20" /><br />
439 <?php echo _('Actor description')._(':') ?><br />
440 <textarea name="actor_desc" rows="20" cols="80"></textarea><br />
441 <?php printf (_('Actor logo (PNG, %d kB max)')._(':'), $max_logo_size) ?> <input type="file" name="actor_logo" /><br />
443 echo _('Legal structure')._(':') ?>
444 <select name="structure_id">
446 $structs = $plugin->getLegalStructures () ;
447 foreach ($structs as $s) {
448 print '<option value="'.$s->getId().'">'.htmlspecialchars($s->getName()).'</option>' ;
452 <input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
459 print '<h1>'._('Edit an actor').'</h1>' ;
460 $actor = new ContribTrackerActor ($actor_id) ;
463 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post" enctype="multipart/form-data">
464 <input type="hidden" name="action" value="post_edit_actor" />
465 <input type="hidden" name="actor_id" value="<?php echo $actor->getId() ?>" />
466 <?php echo _('Actor name')._(':') ?> <input type="text" name="actor_name" size="20" value="<?php echo htmlspecialchars ($actor->getName()) ?>" /><br />
467 <?php echo _('Actor URL')._(':') ?> <input type="text" name="actor_url" size="20" value="<?php echo htmlspecialchars ($actor->getUrl()) ?>" /><br />
468 <?php echo _('Actor email')._(':') ?> <input type="text" name="actor_email" size="20" value="<?php echo htmlspecialchars ($actor->getEmail()) ?>" /><br />
469 <?php echo _('Actor description')._(':') ?><br />
470 <textarea name="actor_desc" rows="20" cols="80"><?php echo htmlspecialchars ($actor->getDescription()) ?></textarea><br />
471 <?php printf (_('Actor logo (PNG, %d kB max)')._(':'), $max_logo_size) ?> <input type="file" name="actor_logo" /><br />
473 if ($actor->getLogo() != '') {
474 print '<img type="image/png" src="'.util_make_url ('/plugins/'.$plugin->name.'/actor_logo.php?actor_id='.$actor->getId ()).'" />' ;
477 echo _('Legal structure')._(':') ?>
478 <select name="structure_id">
480 $structs = $plugin->getLegalStructures () ;
481 foreach ($structs as $s) {
482 print '<option value="'.$s->getId().'".' ;
483 if ($s->getId() == $actor->getLegalStructure()->getId()) {
486 print '>'.htmlspecialchars($s->getName()).'</option>' ;
490 <input type="submit" name="submit" value="<?php echo _('Save') ?>" />
497 site_project_footer(array());
501 // c-file-style: "bsd"