4 * ContribTracker plugin
6 * Copyright 2009, Roland Mas
10 require_once('../../env.inc.php');
11 require_once $gfwww.'include/pre.php';
12 require_once $gfwww.'admin/admin_utils.php';
13 $plugin = plugin_get_object ('contribtracker') ;
15 $max_logo_size = 50 ; // In kibibytes
17 session_require(array('group'=>'1','admin_flags'=>'A'));
19 site_admin_header (array ('title' => _('Contribution tracker administration'))) ;
21 $action = getStringFromRequest ('action') ;
22 $action = util_ensure_value_in_set ($action, array ('display',
34 'post_edit_structure',
39 function check_role_id ($r_id) {
40 $role = new ContribTrackerRole ($r_id) ;
41 if (!$role || !is_object ($role)) {
42 exit_permission_denied () ;
45 function check_actor_id ($a_id) {
46 $actor = new ContribTrackerActor ($a_id) ;
47 if (!$actor || !is_object ($actor)) {
48 exit_permission_denied () ;
51 function check_structure_id ($s_id) {
52 $structure = new ContribTrackerLegalStructure ($s_id) ;
53 if (!$structure || !is_object ($structure)) {
54 exit_permission_denied () ;
57 function check_logo ($arr, $a_id=false) {
58 global $max_logo_size ;
61 $actor = new ContribTrackerActor ($a_id) ;
62 $default = $actor->getLogo() ;
66 if ($arr['tmp_name'] == '') {
69 if ($arr['size'] > 1024 * $max_logo_size) {
72 $logo = file_get_contents ($arr['tmp_name'], 0, NULL, -1, 1024 * $max_logo_size) ;
74 unlink ($arr['tmp_name']) ;
79 // Get and validate parameters, error if tampered with
87 $name = getStringFromRequest ('role_name') ;
88 $desc = getStringFromRequest ('role_desc') ;
92 $role_id = getIntFromRequest ('role_id') ;
93 check_role_id ($role_id) ;
95 case 'post_edit_role':
96 $role_id = getIntFromRequest ('role_id') ;
97 check_role_id ($role_id) ;
98 $name = getStringFromRequest ('role_name') ;
99 $desc = getStringFromRequest ('role_desc') ;
102 case 'add_structure':
104 case 'post_add_structure':
105 $name = getStringFromRequest ('structure_name') ;
106 $desc = getStringFromRequest ('structure_desc') ;
108 case 'edit_structure':
109 case 'del_structure':
110 $structure_id = getIntFromRequest ('structure_id') ;
111 check_structure_id ($structure_id) ;
113 case 'post_edit_structure':
114 $structure_id = getIntFromRequest ('structure_id') ;
115 check_structure_id ($structure_id) ;
116 $name = getStringFromRequest ('structure_name') ;
117 $desc = getStringFromRequest ('structure_desc') ;
122 case 'post_add_actor':
123 $name = getStringFromRequest ('actor_name') ;
124 $url = getStringFromRequest ('actor_url') ;
125 $email = getStringFromRequest ('actor_email') ;
126 $desc = getStringFromRequest ('actor_desc') ;
127 $logoarr = getUploadedFile ('actor_logo') ;
128 $logo = check_logo ($logoarr) ;
129 $structure_id = getIntFromRequest ('structure_id') ;
130 check_structure_id ($structure_id) ;
134 $actor_id = getIntFromRequest ('actor_id') ;
135 check_actor_id ($actor_id) ;
137 case 'post_edit_actor':
138 $actor_id = getIntFromRequest ('actor_id') ;
139 check_actor_id ($actor_id) ;
140 $name = getStringFromRequest ('actor_name') ;
141 $url = getStringFromRequest ('actor_url') ;
142 $email = getStringFromRequest ('actor_email') ;
143 $desc = getStringFromRequest ('actor_desc') ;
144 $logoarr = getUploadedFile ('actor_logo') ;
145 $logo = check_logo ($logoarr, $actor_id) ;
146 $structure_id = getIntFromRequest ('structure_id') ;
147 check_structure_id ($structure_id) ;
152 // Do the required action
155 case 'post_add_role':
156 $role = new ContribTrackerRole () ;
157 if (!$role->create ($name, $desc)) {
158 exit_error ($role->getErrorMessage()) ;
160 $role_id = $role->getId() ;
161 $action = 'display' ;
164 $role = new ContribTrackerRole ($role_id) ;
166 $action = 'display' ;
168 case 'post_edit_role':
169 $role = new ContribTrackerRole ($role_id) ;
170 $role->update ($name, $desc) ;
171 $action = 'display' ;
174 case 'post_add_structure':
175 $structure = new ContribTrackerLegalStructure () ;
176 if (!$structure->create ($name, $desc)) {
177 exit_error ($structure->getErrorMessage()) ;
179 $structure_id = $structure->getId() ;
180 $action = 'display' ;
182 case 'del_structure':
183 $structure = new ContribTrackerLegalStructure ($structure_id) ;
184 $structure->delete () ;
185 $action = 'display' ;
187 case 'post_edit_structure':
188 $structure = new ContribTrackerLegalStructure ($structure_id) ;
189 $structure->update ($name, $desc) ;
190 $action = 'display' ;
193 case 'post_add_actor':
194 $actor = new ContribTrackerActor () ;
195 $structure = new ContribTrackerLegalStructure ($structure_id) ;
196 if (!$actor->create ($name, $url, $email, $desc, $logo, $structure)) {
197 exit_error ($actor->getErrorMessage()) ;
199 $actor_id = $actor->getId() ;
200 $action = 'display' ;
203 $actor = new ContribTrackerActor ($actor_id) ;
205 $action = 'display' ;
207 case 'post_edit_actor':
208 $actor = new ContribTrackerActor ($actor_id) ;
209 $structure = new ContribTrackerLegalStructure ($structure_id) ;
210 $actor->update ($name, $url, $email, $desc, $logo, $structure) ;
211 $action = 'display' ;
215 // Display appropriate forms
219 print '<h1>'._('Existing actors').'</h1>' ;
220 $actors = $plugin->getActors () ;
221 if (count ($actors)) {
222 print '<table><thead><tr>' ;
223 print '<td><strong>'._('Logo').'</strong></td>' ;
224 print '<td><strong>'._('Short name').'</strong></td>' ;
225 print '<td><strong>'._('URL').'</strong></td>' ;
226 print '<td><strong>'._('Email').'</strong></td>' ;
227 print '<td><strong>'._('Description').'</strong></td>' ;
228 print '<td><strong>'._('Legal structure').'</strong></td>' ;
229 print '<td><strong>'._('Actions').'</strong></td>' ;
230 print '</tr></thead><tbody>' ;
231 foreach ($actors as $a) {
234 if ($a->getLogo() != '') {
235 print '<img type="image/png" src="'.util_make_url ('/plugins/'.$plugin->name.'/actor_logo.php?actor_id='.$a->getId ()).'" />' ;
238 print '<td>'.htmlspecialchars($a->getName()).'</td>' ;
240 if ($actor->getUrl() != '') {
241 print '<a href="'.htmlspecialchars($actor->getUrl()).'">'.htmlspecialchars($actor->getUrl()).'</a>';
244 print '<td>'.htmlspecialchars($a->getEmail()).'</td>' ;
245 print '<td>'.htmlspecialchars($a->getDescription()).'</td>' ;
246 print '<td>'.htmlspecialchars($a->getLegalStructure()->getName()).'</td>' ;
249 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
250 <input type="hidden" name="action" value="edit_actor" />
251 <input type="hidden" name="actor_id" value="<?php echo $a->getId () ?>" />
252 <input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
254 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
255 <input type="hidden" name="action" value="del_actor" />
256 <input type="hidden" name="actor_id" value="<?php echo $a->getId () ?>" />
257 <input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
263 print '</tbody></table>' ;
265 print _('No legal structures currently defined.') ;
267 $structs = $plugin->getLegalStructures () ;
268 if (count ($structs)) {
270 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
271 <input type="hidden" name="action" value="add_actor" />
272 <input type="submit" name="submit" value="<?php echo _('Register new actor') ?>" />
277 print _("No legal structures yet, can't define actors without them.") ;
280 print '<h1>'._('Existing legal structures').'</h1>' ;
281 $structs = $plugin->getLegalStructures () ;
282 if (count ($structs)) {
283 print '<table><thead><tr>' ;
284 print '<td><strong>'._('Short name').'</strong></td>' ;
285 print '<td><strong>'._('Actions').'</strong></td>' ;
286 print '</tr></thead><tbody>' ;
287 foreach ($structs as $s) {
289 print '<td>'.htmlspecialchars($s->getName()).'</td>' ;
292 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
293 <input type="hidden" name="action" value="edit_structure" />
294 <input type="hidden" name="structure_id" value="<?php echo $s->getId () ?>" />
295 <input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
297 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
298 <input type="hidden" name="action" value="del_structure" />
299 <input type="hidden" name="structure_id" value="<?php echo $s->getId () ?>" />
300 <input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
306 print '</tbody></table>' ;
308 print _('No legal structures currently defined.') ;
311 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
312 <input type="hidden" name="action" value="add_structure" />
313 <input type="submit" name="submit" value="<?php echo _('Register new legal structure') ?>" />
317 print '<h1>'._('Existing roles').'</h1>' ;
318 $roles = $plugin->getRoles () ;
319 if (count ($roles)) {
320 print '<table><thead><tr>' ;
321 print '<td><strong>'._('Short name').'</strong></td>' ;
322 print '<td><strong>'._('Description').'</strong></td>' ;
323 print '<td><strong>'._('Actions').'</strong></td>' ;
324 print '</tr></thead><tbody>' ;
325 foreach ($roles as $r) {
327 print '<td>'.htmlspecialchars($r->getName()).'</td>' ;
328 print '<td>'.htmlspecialchars($r->getDescription()).'</td>' ;
331 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
332 <input type="hidden" name="action" value="edit_role" />
333 <input type="hidden" name="role_id" value="<?php echo $r->getId () ?>" />
334 <input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
336 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
337 <input type="hidden" name="action" value="del_role" />
338 <input type="hidden" name="role_id" value="<?php echo $r->getId () ?>" />
339 <input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
345 print '</tbody></table>' ;
347 print _('No roles currently defined.') ;
350 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
351 <input type="hidden" name="action" value="add_role" />
352 <input type="submit" name="submit" value="<?php echo _('Register new role') ?>" />
359 print '<h1>'._('Register a new role').'</h1>' ;
361 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
362 <input type="hidden" name="action" value="post_add_role" />
363 <?php echo _('Role name:') ?> <input type="text" name="role_name" size="20" /><br />
364 <?php echo _('Role description:') ?><br />
365 <textarea name="role_desc" rows="20" cols="80"></textarea><br />
366 <input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
373 print '<h1>'._('Edit a role').'</h1>' ;
374 $role = new ContribTrackerRole ($role_id) ;
377 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
378 <input type="hidden" name="action" value="post_edit_role" />
379 <input type="hidden" name="role_id" value="<?php echo $role->getId() ?>" />
380 <?php echo _('Role name:') ?> <input type="text" name="role_name" size="20" value="<?php echo htmlspecialchars ($role->getName()) ?>" /><br />
381 <?php echo _('Role description:') ?><br />
382 <textarea name="role_desc" rows="20" cols="80"><?php echo htmlspecialchars ($role->getDescription()) ?></textarea><br />
383 <input type="submit" name="submit" value="<?php echo _('Save') ?>" />
388 case 'add_structure':
389 print '<h1>'._('Register a new legal structure').'</h1>' ;
391 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
392 <input type="hidden" name="action" value="post_add_structure" />
393 <?php echo _('Structure name:') ?> <input type="text" name="structure_name" size="20" /><br />
394 <input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
400 case 'edit_structure':
401 print '<h1>'._('Edit a legal structure').'</h1>' ;
402 $structure = new ContribTrackerLegalStructure ($structure_id) ;
405 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
406 <input type="hidden" name="action" value="post_edit_structure" />
407 <input type="hidden" name="structure_id" value="<?php echo $structure->getId() ?>" />
408 <?php echo _('Structure name:') ?> <input type="text" name="structure_name" size="20" value="<?php echo htmlspecialchars ($structure->getName()) ?>" /><br />
409 <input type="submit" name="submit" value="<?php echo _('Save') ?>" />
415 print '<h1>'._('Register a new actor').'</h1>' ;
417 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post" enctype="multipart/form-data">
418 <input type="hidden" name="action" value="post_add_actor" />
419 <?php echo _('Actor name:') ?> <input type="text" name="actor_name" size="20" /><br />
420 <?php echo _('Actor URL:') ?> <input type="text" name="actor_url" size="20" /><br />
421 <?php echo _('Actor email:') ?> <input type="text" name="actor_email" size="20" /><br />
422 <?php echo _('Actor description:') ?><br />
423 <textarea name="actor_desc" rows="20" cols="80"></textarea><br />
424 <?php printf (_('Actor logo (PNG, %d kB max):'), $max_logo_size) ?> <input type="file" name="actor_logo" /><br />
426 echo _('Legal structure:') ?>
427 <select name="structure_id">
429 $structs = $plugin->getLegalStructures () ;
430 foreach ($structs as $s) {
431 print '<option value="'.$s->getId().'">'.htmlspecialchars($s->getName()).'</option>' ;
435 <input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
442 print '<h1>'._('Edit an actor').'</h1>' ;
443 $actor = new ContribTrackerActor ($actor_id) ;
446 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post" enctype="multipart/form-data">
447 <input type="hidden" name="action" value="post_edit_actor" />
448 <input type="hidden" name="actor_id" value="<?php echo $actor->getId() ?>" />
449 <?php echo _('Actor name:') ?> <input type="text" name="actor_name" size="20" value="<?php echo htmlspecialchars ($actor->getName()) ?>" /><br />
450 <?php echo _('Actor URL:') ?> <input type="text" name="actor_url" size="20" value="<?php echo htmlspecialchars ($actor->getUrl()) ?>" /><br />
451 <?php echo _('Actor email:') ?> <input type="text" name="actor_email" size="20" value="<?php echo htmlspecialchars ($actor->getEmail()) ?>" /><br />
452 <?php echo _('Actor description:') ?><br />
453 <textarea name="actor_desc" rows="20" cols="80"><?php echo htmlspecialchars ($actor->getDescription()) ?></textarea><br />
454 <?php printf (_('Actor logo (PNG, %d kB max):'), $max_logo_size) ?> <input type="file" name="actor_logo" /><br />
456 if ($actor->getLogo() != '') {
457 print '<img type="image/png" src="'.util_make_url ('/plugins/'.$plugin->name.'/actor_logo.php?actor_id='.$actor->getId ()).'" />' ;
460 echo _('Legal structure:') ?>
461 <select name="structure_id">
463 $structs = $plugin->getLegalStructures () ;
464 foreach ($structs as $s) {
465 print '<option value="'.$s->getId().'".' ;
466 if ($s->getId() == $actor->getLegalStructure()->getId()) {
469 print '>'.htmlspecialchars($s->getName()).'</option>' ;
473 <input type="submit" name="submit" value="<?php echo _('Save') ?>" />
480 site_project_footer(array());
484 // c-file-style: "bsd"