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 $address = getStringFromRequest ('actor_address') ;
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 $address = getStringFromRequest ('actor_address') ;
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, $address, $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, $address, $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>'._('Short name').'</strong></td>' ;
224 print '<td><strong>'._('Postal address').'</strong></td>' ;
225 print '<td><strong>'._('Email').'</strong></td>' ;
226 print '<td><strong>'._('Description').'</strong></td>' ;
227 print '<td><strong>'._('Logo').'</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) {
233 print '<td>'.htmlspecialchars($a->getName()).'</td>' ;
234 print '<td>'.htmlspecialchars($a->getAddress()).'</td>' ;
235 print '<td>'.htmlspecialchars($a->getEmail()).'</td>' ;
236 print '<td>'.htmlspecialchars($a->getDescription()).'</td>' ;
238 if ($a->getLogo() != '') {
239 print '<img type="image/png" src="'.util_make_url ('/plugins/'.$plugin->name.'/actor_logo.php?actor_id='.$a->getId ()).'" />' ;
242 print '<td>'.htmlspecialchars($a->getLegalStructure()->getName()).'</td>' ;
245 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
246 <input type="hidden" name="action" value="edit_actor" />
247 <input type="hidden" name="actor_id" value="<?php echo $a->getId () ?>" />
248 <input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
250 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
251 <input type="hidden" name="action" value="del_actor" />
252 <input type="hidden" name="actor_id" value="<?php echo $a->getId () ?>" />
253 <input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
259 print '</tbody></table>' ;
261 print _('No legal structures currently defined.') ;
263 $structs = $plugin->getLegalStructures () ;
264 if (count ($structs)) {
266 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
267 <input type="hidden" name="action" value="add_actor" />
268 <input type="submit" name="submit" value="<?php echo _('Register new actor') ?>" />
273 print _("No legal structures yet, can't define actors without them.") ;
276 print '<h1>'._('Existing legal structures').'</h1>' ;
277 $structs = $plugin->getLegalStructures () ;
278 if (count ($structs)) {
279 print '<table><thead><tr>' ;
280 print '<td><strong>'._('Short name').'</strong></td>' ;
281 print '<td><strong>'._('Actions').'</strong></td>' ;
282 print '</tr></thead><tbody>' ;
283 foreach ($structs as $s) {
285 print '<td>'.htmlspecialchars($s->getName()).'</td>' ;
288 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
289 <input type="hidden" name="action" value="edit_structure" />
290 <input type="hidden" name="structure_id" value="<?php echo $s->getId () ?>" />
291 <input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
293 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
294 <input type="hidden" name="action" value="del_structure" />
295 <input type="hidden" name="structure_id" value="<?php echo $s->getId () ?>" />
296 <input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
302 print '</tbody></table>' ;
304 print _('No legal structures currently defined.') ;
307 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
308 <input type="hidden" name="action" value="add_structure" />
309 <input type="submit" name="submit" value="<?php echo _('Register new legal structure') ?>" />
313 print '<h1>'._('Existing roles').'</h1>' ;
314 $roles = $plugin->getRoles () ;
315 if (count ($roles)) {
316 print '<table><thead><tr>' ;
317 print '<td><strong>'._('Short name').'</strong></td>' ;
318 print '<td><strong>'._('Description').'</strong></td>' ;
319 print '<td><strong>'._('Actions').'</strong></td>' ;
320 print '</tr></thead><tbody>' ;
321 foreach ($roles as $r) {
323 print '<td>'.htmlspecialchars($r->getName()).'</td>' ;
324 print '<td>'.htmlspecialchars($r->getDescription()).'</td>' ;
327 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
328 <input type="hidden" name="action" value="edit_role" />
329 <input type="hidden" name="role_id" value="<?php echo $r->getId () ?>" />
330 <input type="submit" name="submit" value="<?php echo _('Edit') ?>" />
332 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
333 <input type="hidden" name="action" value="del_role" />
334 <input type="hidden" name="role_id" value="<?php echo $r->getId () ?>" />
335 <input type="submit" name="submit" value="<?php echo _('Delete') ?>" />
341 print '</tbody></table>' ;
343 print _('No roles currently defined.') ;
346 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
347 <input type="hidden" name="action" value="add_role" />
348 <input type="submit" name="submit" value="<?php echo _('Register new role') ?>" />
355 print '<h1>'._('Register a new role').'</h1>' ;
357 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
358 <input type="hidden" name="action" value="post_add_role" />
359 <?php echo _('Role name:') ?> <input type="text" name="role_name" size="20" /><br />
360 <?php echo _('Role description:') ?><br />
361 <textarea name="role_desc" rows="20" cols="80"></textarea><br />
362 <input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
369 print '<h1>'._('Edit a role').'</h1>' ;
370 $role = new ContribTrackerRole ($role_id) ;
373 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
374 <input type="hidden" name="action" value="post_edit_role" />
375 <input type="hidden" name="role_id" value="<?php echo $role->getId() ?>" />
376 <?php echo _('Role name:') ?> <input type="text" name="role_name" size="20" value="<?php echo htmlspecialchars ($role->getName()) ?>" /><br />
377 <?php echo _('Role description:') ?><br />
378 <textarea name="role_desc" rows="20" cols="80"><?php echo htmlspecialchars ($role->getDescription()) ?></textarea><br />
379 <input type="submit" name="submit" value="<?php echo _('Save') ?>" />
384 case 'add_structure':
385 print '<h1>'._('Register a new legal structure').'</h1>' ;
387 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
388 <input type="hidden" name="action" value="post_add_structure" />
389 <?php echo _('Structure name:') ?> <input type="text" name="structure_name" size="20" /><br />
390 <input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
396 case 'edit_structure':
397 print '<h1>'._('Edit a legal structure').'</h1>' ;
398 $structure = new ContribTrackerLegalStructure ($structure_id) ;
401 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
402 <input type="hidden" name="action" value="post_edit_structure" />
403 <input type="hidden" name="structure_id" value="<?php echo $structure->getId() ?>" />
404 <?php echo _('Structure name:') ?> <input type="text" name="structure_name" size="20" value="<?php echo htmlspecialchars ($structure->getName()) ?>" /><br />
405 <input type="submit" name="submit" value="<?php echo _('Save') ?>" />
411 print '<h1>'._('Register a new actor').'</h1>' ;
413 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post" enctype="multipart/form-data">
414 <input type="hidden" name="action" value="post_add_actor" />
415 <?php echo _('Actor name:') ?> <input type="text" name="actor_name" size="20" /><br />
416 <?php echo _('Actor address:') ?> <input type="text" name="actor_address" size="20" /><br />
417 <?php echo _('Actor email:') ?> <input type="text" name="actor_email" size="20" /><br />
418 <?php echo _('Actor description:') ?><br />
419 <textarea name="actor_desc" rows="20" cols="80"></textarea><br />
420 <?php printf (_('Actor logo (PNG, %d kB max):'), $max_logo_size) ?> <input type="file" name="actor_logo" /><br />
422 echo _('Legal structure:') ?>
423 <select name="structure_id">
425 $structs = $plugin->getLegalStructures () ;
426 foreach ($structs as $s) {
427 print '<option value="'.$s->getId().'">'.htmlspecialchars($s->getName()).'</option>' ;
431 <input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
438 print '<h1>'._('Edit an actor').'</h1>' ;
439 $actor = new ContribTrackerActor ($actor_id) ;
442 <form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post" enctype="multipart/form-data">
443 <input type="hidden" name="action" value="post_edit_actor" />
444 <input type="hidden" name="actor_id" value="<?php echo $actor->getId() ?>" />
445 <?php echo _('Actor name:') ?> <input type="text" name="actor_name" size="20" value="<?php echo htmlspecialchars ($actor->getName()) ?>" /><br />
446 <?php echo _('Actor address:') ?> <input type="text" name="actor_address" size="20" value="<?php echo htmlspecialchars ($actor->getAddress()) ?>" /><br />
447 <?php echo _('Actor email:') ?> <input type="text" name="actor_email" size="20" value="<?php echo htmlspecialchars ($actor->getEmail()) ?>" /><br />
448 <?php echo _('Actor description:') ?><br />
449 <textarea name="actor_desc" rows="20" cols="80"><?php echo htmlspecialchars ($actor->getDescription()) ?></textarea><br />
450 <?php printf (_('Actor logo (PNG, %d kB max):'), $max_logo_size) ?> <input type="file" name="actor_logo" /><br />
452 if ($actor->getLogo() != '') {
453 print '<img type="image/png" src="'.util_make_url ('/plugins/'.$plugin->name.'/actor_logo.php?actor_id='.$actor->getId ()).'" />' ;
456 echo _('Legal structure:') ?>
457 <select name="structure_id">
459 $structs = $plugin->getLegalStructures () ;
460 foreach ($structs as $s) {
461 print '<option value="'.$s->getId().'".' ;
462 if ($s->getId() == $actor->getLegalStructure()->getId()) {
465 print '>'.htmlspecialchars($s->getName()).'</option>' ;
469 <input type="submit" name="submit" value="<?php echo _('Save') ?>" />
476 site_project_footer(array());
480 // c-file-style: "bsd"