[Fusionforge-commits] r8587 - in trunk/gforge/plugins/contribtracker: common lib www

Roland Mas lolando at libremir.placard.fr.eu.org
Fri Dec 18 18:42:03 CET 2009


Author: lolando
Date: 2009-12-18 18:42:03 +0100 (Fri, 18 Dec 2009)
New Revision: 8587

Added:
   trunk/gforge/plugins/contribtracker/www/actor_logo.php
Modified:
   trunk/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php
   trunk/gforge/plugins/contribtracker/lib/contribtracker-init.sql
   trunk/gforge/plugins/contribtracker/www/global_admin.php
   trunk/gforge/plugins/contribtracker/www/index.php
Log:
UI+code?\194?\160to create, manage and display logos for actors

Modified: trunk/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php
===================================================================
--- trunk/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php	2009-12-18 17:41:53 UTC (rev 8586)
+++ trunk/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php	2009-12-18 17:42:03 UTC (rev 8587)
@@ -116,7 +116,7 @@
 				usort ($contribs, array ($this, "ContribComparator")) ;
 
 				if (count ($contribs) == 0) {
-					echo '<tr><td colspan="5"><strong>'._('This Project Has Not Released Any Files').'</strong></td></tr>';
+					echo '<tr><td colspan="5"><strong>'._('No contributions have been recorded for this project yet.').'</strong></td></tr>';
 				} else {
 					$max_displayed_contribs = 3 ;
 					$i = 1 ;
@@ -136,6 +136,9 @@
 								util_make_link ('/plugins/'.$this->name.'/?actor_id='.$p->getActor()->getId (),
 										htmlspecialchars ($p->getActor()->getName())),
 								htmlspecialchars ($p->getActor()->getLegalStructure()->getName())) ;
+							if ($p->getActor()->getLogo() != '') {
+								print ' <img type="image/png" src="'.util_make_url ('/plugins/'.$this->name.'/actor_logo.php?actor_id='.$p->getActor()->getId ()).'" />' ;
+							}
 							echo '</li>' ;
 						}
 						echo '</ul></td></tr>' ;
@@ -475,18 +478,19 @@
 		return true ;
 	}
 
-	function create ($name, $address, $email, $description, $structure) {
+	function create ($name, $address, $email, $description, $logo, $structure) {
 		if ($this->getId ()) {
 			$this->setError(_('Object already exists')) ;
 			return false ;
 		}
 
 		db_begin () ;
-		$res = db_query_params ('INSERT INTO plugin_contribtracker_actor (name,address,email,description,struct_id) VALUES ($1,$2,$3,$4,$5)',
+		$res = db_query_params ('INSERT INTO plugin_contribtracker_actor (name,address,email,description,logo,struct_id) VALUES ($1,$2,$3,$4,$5,$6)',
 					array ($name,
 					       $address,
 					       $email,
 					       $description,
+					       base64_encode ($logo),
 					       $structure->getID())) ;
 		if (!$res || db_affected_rows ($res) < 1) {
 			$this->setError (sprintf(_('Could not create object in database: %s'),
@@ -507,7 +511,7 @@
 		return $this->fetchData ($id) ;
 	}
 
-	function update ($name, $address, $email, $description, $structure) {
+	function update ($name, $address, $email, $description, $logo, $structure) {
 		if (! $this->getId ()) {
 			$this->setError(_('Object does not exist')) ;
 			return false ;
@@ -516,11 +520,12 @@
 		$id = $this->getId () ;
 
 		db_begin () ;
-		$res = db_query_params ('UPDATE plugin_contribtracker_actor SET (name,address,email,description,struct_id) = ($1,$2,$3,$4,$5) WHERE actor_id = $6',
+		$res = db_query_params ('UPDATE plugin_contribtracker_actor SET (name,address,email,description,logo,struct_id) = ($1,$2,$3,$4,$5,$6) WHERE actor_id = $7',
 					array ($name,
 					       $address,
 					       $email,
 					       $description,
+					       base64_encode ($logo),
 					       $structure->getID(),
 					       $id)) ;
 		if (!$res || db_affected_rows ($res) < 1) {
@@ -568,6 +573,7 @@
 	function getLegalStructure () {
 		return new ContribTrackerLegalStructure ($this->data_array['struct_id']) ;
 	}
+	function getLogo () { return base64_decode ($this->data_array['logo']) ; }
 
 	function getParticipations () {
 		$res = db_query_params ('SELECT participation_id FROM plugin_contribtracker_participation WHERE actor_id = $1',

Modified: trunk/gforge/plugins/contribtracker/lib/contribtracker-init.sql
===================================================================
--- trunk/gforge/plugins/contribtracker/lib/contribtracker-init.sql	2009-12-18 17:41:53 UTC (rev 8586)
+++ trunk/gforge/plugins/contribtracker/lib/contribtracker-init.sql	2009-12-18 17:42:03 UTC (rev 8587)
@@ -18,6 +18,7 @@
        address text DEFAULT '' NOT NULL,
        email text DEFAULT '' NOT NULL,
        description text DEFAULT '' NOT NULL,
+       logo text DEFAULT '' NOT NULL,
        struct_id integer NOT NULL REFERENCES plugin_contribtracker_legal_structure
 ) ;
 

Added: trunk/gforge/plugins/contribtracker/www/actor_logo.php
===================================================================
--- trunk/gforge/plugins/contribtracker/www/actor_logo.php	                        (rev 0)
+++ trunk/gforge/plugins/contribtracker/www/actor_logo.php	2009-12-18 17:42:03 UTC (rev 8587)
@@ -0,0 +1,34 @@
+<?php
+
+/*
+ * ContribTracker plugin
+ *
+ * Copyright 2009, Roland Mas
+ *
+ */
+
+require_once('../../env.inc.php');
+require_once $gfwww.'include/pre.php';
+$plugin = plugin_get_object ('contribtracker') ;
+
+$actor_id = getIntFromRequest ('actor_id') ;
+
+if ($actor_id) {
+	$actor = new ContribTrackerActor ($actor_id) ;
+	if (!is_object ($actor) || $actor->isError()) {
+		exit_error (_('Invalid actor'),
+			    _('Invalid actor specified')) ;
+	}
+	Header ("Content-type: image/png");
+	echo $actor->getLogo();
+} else {
+		exit_error (_('Invalid actor'),
+			    _('Invalid actor specified')) ;
+}	
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
+?>

Modified: trunk/gforge/plugins/contribtracker/www/global_admin.php
===================================================================
--- trunk/gforge/plugins/contribtracker/www/global_admin.php	2009-12-18 17:41:53 UTC (rev 8586)
+++ trunk/gforge/plugins/contribtracker/www/global_admin.php	2009-12-18 17:42:03 UTC (rev 8587)
@@ -52,7 +52,25 @@
 		exit_permission_denied () ;
 	}
 }
-	
+function check_logo ($arr, $a_id=false) {
+	if ($a_id) {
+		$actor = new ContribTrackerActor ($a_id) ;
+		$default = $actor->getLogo() ;
+	} else {
+		$default = '' ;
+	}
+	if ($arr['tmp_name'] == '') {
+		$logo = $default ;
+	} else {
+		if ($arr['size'] > 10240) {
+			$logo = $default ;
+		} else {
+			$logo = file_get_contents ($arr['tmp_name'], 0, NULL, -1, 10240) ;
+		}
+		unlink ($arr['tmp_name']) ;
+	}
+	return $logo ;
+}	
 
 // Get and validate parameters, error if tampered with
 switch ($action) {
@@ -102,6 +120,8 @@
 	$address = getStringFromRequest ('actor_address') ;
 	$email = getStringFromRequest ('actor_email') ;
 	$desc = getStringFromRequest ('actor_desc') ;
+	$logoarr = getUploadedFile ('actor_logo') ;
+	$logo = check_logo ($logoarr) ;
 	$structure_id = getIntFromRequest ('structure_id') ;
 	check_structure_id ($structure_id) ;
 	break ;
@@ -117,6 +137,8 @@
 	$address = getStringFromRequest ('actor_address') ;
 	$email = getStringFromRequest ('actor_email') ;
 	$desc = getStringFromRequest ('actor_desc') ;
+	$logoarr = getUploadedFile ('actor_logo') ;
+	$logo = check_logo ($logoarr, $actor_id) ;
 	$structure_id = getIntFromRequest ('structure_id') ;
 	check_structure_id ($structure_id) ;
 	break ;	
@@ -167,7 +189,7 @@
 case 'post_add_actor':
 	$actor = new ContribTrackerActor () ;
 	$structure = new ContribTrackerLegalStructure ($structure_id) ;
-	if (!$actor->create ($name, $address, $email, $desc, $structure)) {
+	if (!$actor->create ($name, $address, $email, $desc, $logo, $structure)) {
 		exit_error ($actor->getErrorMessage()) ;
 	}
 	$actor_id = $actor->getId() ;
@@ -181,7 +203,7 @@
 case 'post_edit_actor':
 	$actor = new ContribTrackerActor ($actor_id) ;
 	$structure = new ContribTrackerLegalStructure ($structure_id) ;
-	$actor->update ($name, $address, $email, $desc, $structure) ;
+	$actor->update ($name, $address, $email, $desc, $logo, $structure) ;
 	$action = 'display' ;
 	break ;
 }
@@ -198,6 +220,7 @@
 		print '<td><strong>'._('Postal address').'</strong></td>' ;
 		print '<td><strong>'._('Email').'</strong></td>' ;
 		print '<td><strong>'._('Description').'</strong></td>' ;
+		print '<td><strong>'._('Logo').'</strong></td>' ;
 		print '<td><strong>'._('Legal structure').'</strong></td>' ;
 		print '<td><strong>'._('Actions').'</strong></td>' ;
 		print '</tr></thead><tbody>' ;
@@ -207,6 +230,11 @@
 			print '<td>'.htmlspecialchars($a->getAddress()).'</td>' ;
 			print '<td>'.htmlspecialchars($a->getEmail()).'</td>' ;
 			print '<td>'.htmlspecialchars($a->getDescription()).'</td>' ;
+			print '<td>' ;
+			if ($a->getLogo() != '') {
+				print '<img type="image/png" src="'.util_make_url ('/plugins/'.$plugin->name.'/actor_logo.php?actor_id='.$a->getId ()).'" />' ;
+			}
+			print '</td>' ;
 			print '<td>'.htmlspecialchars($a->getLegalStructure()->getName()).'</td>' ;
 			?>
 				<td>
@@ -378,13 +406,14 @@
 case 'add_actor':
 	print '<h1>'._('Register a new actor').'</h1>' ;
 	?>
-		<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+		<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post" enctype="multipart/form-data">
 			 <input type="hidden" name="action" value="post_add_actor" />
 			 <?php echo _('Actor name:') ?> <input type="text" name="actor_name" size="20" /><br />
 			 <?php echo _('Actor address:') ?> <input type="text" name="actor_address" size="20" /><br />
 			 <?php echo _('Actor email:') ?> <input type="text" name="actor_email" size="20" /><br />
 			 <?php echo _('Actor description:') ?><br />
 			 <textarea name="actor_desc" rows="20" cols="80"></textarea><br />
+			 <?php echo _('Actor logo (PNG, 10 kB max.):') ?> <input type="file" name="actor_logo" /><br />
 			 <?php
 			 echo _('Legal structure:') ?>
 			 <select name="structure_id">
@@ -406,7 +435,7 @@
 	$actor = new ContribTrackerActor ($actor_id) ;
 	
 	?>
-		<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post">
+		<form action="<?php echo util_make_url ('/plugins/'.$plugin->name.'/global_admin.php') ?>" method="post" enctype="multipart/form-data">
 			 <input type="hidden" name="action" value="post_edit_actor" />
 			 <input type="hidden" name="actor_id" value="<?php echo $actor->getId() ?>" />
 			 <?php echo _('Actor name:') ?> <input type="text" name="actor_name" size="20" value="<?php echo htmlspecialchars ($actor->getName()) ?>" /><br />
@@ -414,7 +443,12 @@
 			 <?php echo _('Actor email:') ?> <input type="text" name="actor_email" size="20" value="<?php echo htmlspecialchars ($actor->getEmail()) ?>" /><br />
 			 <?php echo _('Actor description:') ?><br />
 			 <textarea name="actor_desc" rows="20" cols="80"><?php echo htmlspecialchars ($actor->getDescription()) ?></textarea><br />
+			 <?php echo _('Actor logo (PNG, 10 kB max.):') ?> <input type="file" name="actor_logo" />
 			 <?php
+			 if ($actor->getLogo() != '') {
+				 print '<img type="image/png" src="'.util_make_url ('/plugins/'.$plugin->name.'/actor_logo.php?actor_id='.$actor->getId ()).'" />' ;
+			 }
+	print '<br />' ;
 			 echo _('Legal structure:') ?>
 			 <select name="structure_id">
 			 <?php

Modified: trunk/gforge/plugins/contribtracker/www/index.php
===================================================================
--- trunk/gforge/plugins/contribtracker/www/index.php	2009-12-18 17:41:53 UTC (rev 8586)
+++ trunk/gforge/plugins/contribtracker/www/index.php	2009-12-18 17:42:03 UTC (rev 8587)
@@ -43,6 +43,9 @@
 			util_make_link ('/plugins/'.$plugin->name.'/?actor_id='.$p->getActor()->getId (),
 					htmlspecialchars ($p->getActor()->getName())),
 			htmlspecialchars ($p->getActor()->getLegalStructure()->getName())) ;
+		if ($p->getActor()->getLogo() != '') {
+			print ' <img type="image/png" src="'.util_make_url ('/plugins/'.$plugin->name.'/actor_logo.php?actor_id='.$p->getActor()->getId ()).'" />' ;
+		}
 		print '</li>' ;
 	}
 	print '</ul>' ;
@@ -124,6 +127,9 @@
 	print '<li><strong>'._('Legal structure:').'</strong> '.htmlspecialchars($actor->getLegalStructure()->getName()).'</li>' ;
 	print '<li><strong>'._('Description:').'</strong> '.htmlspecialchars($actor->getDescription()).'</li>' ;
 	print '</ul>' ;
+	if ($actor->getLogo() != '') {
+		print '<img type="image/png" src="'.util_make_url ('/plugins/'.$plugin->name.'/actor_logo.php?actor_id='.$actor->getId ()).'" />' ;
+	}
 	
 	$participations = $actor->getParticipations () ;
 	




More information about the Fusionforge-commits mailing list