Index: /extensions/ConcoursPhoto/CHANGELOG
===================================================================
--- /extensions/ConcoursPhoto/CHANGELOG	(revision 3905)
+++ /extensions/ConcoursPhoto/CHANGELOG	(revision 3905)
@@ -0,0 +1,10 @@
+TODO for next versions : 
+- 
+
+
+Version 0.0.x
+-------------
+0.0.1 --> Initial version
+
+
+_______________
Index: /extensions/ConcoursPhoto/admin/add_concours.php
===================================================================
--- /extensions/ConcoursPhoto/admin/add_concours.php	(revision 3905)
+++ /extensions/ConcoursPhoto/admin/add_concours.php	(revision 3905)
@@ -0,0 +1,338 @@
+<?php
+
+// To add a concours, 2 steps  are needed:
+// Step 1 : action=new
+//	initialize a concours and store it to database (with elements on piwigo_concours table)
+//	After storage on database, step 2 is called (action=new_crit)
+// Step 2 : action=new_crit  &  concours_id=XX
+
+// add_concours with action=view is called only to list informations about a concours id
+// add_concours with action=modify is called to modify informations about a concours.  Like creation, 2 steps are needed
+//	Step 1 : action=modify &  concours_id=XX
+//		List informations about concours id and modify it to store to piwifo_concours table
+//		Go to Step 2 (if needed by client choice ==> 2 buttons) with action=modify_crit
+//	Ste 2 : action=modify_crit &  concours_id=XX
+//		List informations about criterias and modify them
+//		Warning : different cases are possible : 
+//			- delete criteria ou sub criteria
+//			- modify criteria ou sub criteria (
+//			- add criteria ou sub criteria
+//		For all theses actions, the command is sent by _GET method
+
+
+
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+global $template;
+
+include_once(CONCOURS_PATH . 'admin/functions.inc.php');
+load_language('plugin.lang', CONCOURS_PATH);
+
+
+	
+// test for _GET informations needed
+if (!isset($_GET['action']))
+  die('Wrong parameters...1');
+else
+  $action = $_GET['action'];
+
+
+// concours initialize
+if ($action != "new")
+{
+	if (!isset($_GET['concours']))
+	  die('Wrong parameters...2');
+
+	$concours_id = $_GET['concours'];
+	// Get informations from base for concours_id
+	$concours = new Concours($concours_id);
+}
+else	// creation
+{
+	$concours = new Concours();
+	$query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
+				FROM ' . CONCOURS_TABLE . ' ;';
+	list($next_element_id) = mysql_fetch_array(pwg_query($query));
+	$concours_id = $next_element_id;
+}
+
+ 
+// Add criteria
+if (isset($_POST['add']))
+	redirect( PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&amp;id_concours=' . $concours_id.'&amp;action=add');
+
+  
+if (isset($_POST['submit']))
+{
+	if ($action == "modify_crit")
+		redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php');
+
+	if ($action == "edit")
+		redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php');
+
+// Step 1 : action = modify
+// Step 2 : action = modify_crit
+	
+	// Verify date format.		
+//	echo "DATE=".$_POST['concours_begin_date'];
+	if (!preg_match(
+	"/^([2][0]\d{2})\-([0]\d|[1][0-2])\-([0-2]\d|[3][0-1])\s([0-1]\d|[2][0-3])\:[0-5]\d\:[0-5]\d$/"
+	, $_POST['concours_begin_date']))
+	{
+		$_POST['concours_begin_date'] = date("Y-m-d H:m:s");
+//		redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php&amp;tab=add_concours&amp;action='.$action.'&amp;concours=' . $concours_id);
+	}
+
+	
+	
+	// Get information from form
+	$concours->concours_id = $concours_id;
+	$concours->concours_infos['id'] = $concours_id;
+	$concours->concours_infos['name'] = $_POST['concours_name'];
+	$concours->concours_infos['descr'] = $_POST['concours_descr'];
+	$concours->concours_infos['begin_date'] = $_POST['concours_begin_date'];
+
+	$concours->concours_infos['end_date'] = AjoutJours($concours->concours_infos['begin_date'],$_POST['concours_end_date'] );
+
+//echo $_POST['concours_end_date'].' : '.$concours->concours_infos['end_date'];
+
+	$concours->concours_infos['groups'] = (!empty($_POST['groups']) ? '"' . implode(',', $_POST['groups']) . '"' : 'NULL');
+	$concours->concours_infos['category'] = $_POST['cat_selection'];
+	
+	switch($action)	
+	{
+		case "edit" :
+			redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php');
+			break;
+		case "new" :
+			
+			$concours->save_concours();
+			$concours->get_default_criterias();
+if ($concours->debug)	sleep(5);
+			// Redirect to admin
+			redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php&amp;tab=add_concours&amp;action=modify_crit&amp;concours=' . $concours_id);
+
+			break;
+		case "modify" :
+			$concours->update_concours();
+			redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php&amp;tab=add_concours&amp;action=modify_crit&amp;concours=' . $concours_id);
+
+			break;
+		case "modify_crit" :
+			redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php');
+			break;
+	}
+	  
+		
+}		
+	
+	
+	
+switch($action)	
+{
+// Download the file
+	case "file" :
+		// TODO generate csv file
+		$file = $concours->generate_csv();
+		// Get the existing filename or the new one if doesnt exist
+		$filename = $concours->save_file($file);
+
+		redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php');
+		break;
+
+// Geneate result
+	case "result" :
+		// Generate result and save it to DB
+		$concours->create_result();
+		// Generate csv file
+		// 1. Simple  csv file
+//		$file = $concours->generate_csv();
+		// 2.  Complete csv file.
+		$file = $concours->generate_detail_csv();
+		// Save file to directory
+		$filename = $concours->save_file($file);
+		
+		redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php');
+		break;
+
+	case "del" : 
+	// Suppress concours and all parameters
+		$concours->delete_concours();
+		redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php');
+		break;
+		
+	case "new" :
+		$concours->concours_infos['groups'] = array();
+		$concours->concours_infos['category'] = '';
+		$template->assign( 'CONCOURS', array(
+				'ID'	=> $concours_id,
+				'BEGIN_DATE'	=> date("Y-m-d H:m:s"),
+				'END_DATE'	=> 15
+				));
+
+		break;
+	case "modify" :
+
+/*		$info_concours['groups']
+				`create_date` datetime NOT NULL,
+				`name` text NOT NULL,
+				`descr` varchar(255) default NULL,
+				`begin_date` datetime NOT NULL,
+				`end_date` datetime NOT NULL,
+				`category` smallint(5) default NULL,
+				`groups` varchar(255) default NULL,
+*/		
+		// Format group list
+		$concours->concours_infos['groups'] = explode(',', $concours->concours_infos['groups']);
+		
+		$template->assign( 'CONCOURS', array(
+				'ID'	=> $concours->concours_infos['id'],
+				'NAME'	=> $concours->concours_infos['name'],
+				'DESCR'	=> $concours->concours_infos['descr'],
+				'BEGIN_DATE'	=> $concours->concours_infos['begin_date'],
+				'END_DATE'	=> NbJours($concours->concours_infos['begin_date'], $concours->concours_infos['end_date'])
+				));
+
+		break;
+	case "modify_crit" :
+	case "edit" :
+		$concours->concours_infos['groups'] = explode(',', $concours->concours_infos['groups']);
+		
+		$template->assign( 'CONCOURS', array(
+				'ID'	=> $concours->concours_infos['id'],
+				'NAME'	=> $concours->concours_infos['name'],
+				'DESCR'	=> $concours->concours_infos['descr'],
+				'BEGIN_DATE'	=> $concours->concours_infos['begin_date'],
+				'END_DATE'	=> NbJours($concours->concours_infos['begin_date'], $concours->concours_infos['end_date'])
+				));
+		
+		$firstcriterias = $concours->get_firstlevel_criterias();
+		foreach ($firstcriterias as $criteria)
+		{
+		if ($concours->debug)					echo "criteriaID=".$criteria['criteria_id']."\n";
+			// First without sub criterias
+			if (!$concours->is_criterias_contains_sub($criteria['criteria_id'] ))
+			{
+				$template->append( 'concours_criteria', array(
+						'nosub'	=> true,
+						'level'	=> 1,
+						'id' 	=> $criteria['criteria_id'],				// id du critere
+						'name' 	=> $criteria['name'],				// id du critere
+						'lib'	=> $criteria['descr'], //.'(min='$criteria['min_value'].';max='.$criteria['min_value'].')',			// libelle du critrer
+						'min' 	=> $criteria['min_value'],				// min
+						'max' 	=> $criteria['max_value'],				// max
+						'pond' 	=> $criteria['ponderation'],			// ponderation
+						'U_EDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&amp;id_concours=' . $concours->concours_id.'&amp;action=modify&amp;id='.$criteria['id'],
+						'U_DELETE' => !is_adviser() ? PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&amp;id_concours=' . $concours->concours_id.'&amp;action=delete&amp;id='.$criteria['id'] : '',
+						'U_ADD' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&amp;id_concours=' . $concours->concours_id.'&amp;action=add&amp;upcriteria='.$criteria['criteria_id'],
+					));
+			}
+			else
+			{
+				$template->append( 'concours_criteria', array(
+						'nosub'	=> false,
+						'level'	=> 1,
+						'id' 	=> $criteria['criteria_id'],				// id du critere
+						'name' 	=> $criteria['name'],				// id du critere
+						'lib'	=> $criteria['descr'],
+						'U_ADD' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&amp;id_concours=' . $concours->concours_id.'&amp;action=add&amp;upcriteria='.$criteria['criteria_id'],
+					));
+				$secondcriterias = $concours->get_subcriterias($criteria['criteria_id'] );
+				foreach ($secondcriterias as $subcriteria)
+				{
+		if ($concours->debug)							echo "subcriteriaID=".$criteria['criteria_id']."\n";
+					$template->append( 'concours_criteria', array(
+							'nosub'	=> true,
+							'level'	=> 2,
+							'id' 	=> $subcriteria['criteria_id'],				// id du critere
+							'name' 	=> $subcriteria['name'],				// id du critere
+							'lib'	=> $subcriteria['descr'], //.'(min='$criteria['min_value'].';max='.$criteria['min_value'].')',			// libelle du critrer
+							'min' 	=> $subcriteria['min_value'],				// min
+							'max' 	=> $subcriteria['max_value'],				// max
+							'pond' 	=> $subcriteria['ponderation'],			// ponderation
+							'U_EDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&amp;id_concours=' . $concours->concours_id.'&amp;action=modify&amp;id='.$subcriteria['id'],
+							'U_DELETE' => !is_adviser() ? PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&amp;id_concours=' . $concours->concours_id.'&amp;action=delete&amp;id='.$subcriteria['id'] : '',
+						));
+					
+				}
+			}
+
+		}
+		
+		break;
+}
+	
+	
+	
+$template->assign( 'action', $action);
+$template->assign('IMG_URL', CONCOURS_IMG_PATH);
+	
+
+
+
+// Groups selection
+$groups = get_all_groups();
+if (!empty($groups))
+{
+  $template->assign('group_perm', array('GROUPSELECTION' => get_html_groups_selection($groups, 'groups', (isset($concours->concours_infos['groups']) ? $concours->concours_infos['groups'] : array()))));
+}
+
+// Category selection
+$query = '
+  SELECT id, name, uppercats, global_rank
+  FROM '.CATEGORIES_TABLE.';';
+
+  $result = pwg_query($query);
+  $categories = array();
+if (!empty($result))
+{
+	while ($row = mysql_fetch_assoc($result))
+		array_push($categories, $row);
+}
+usort($categories, 'global_rank_compare');
+
+if (!empty($result))
+{
+		foreach ($categories as $cat)
+			$template->append('category_selection',
+				array(	'ID' => $cat['id'],
+						'NAME' => get_cat_display_name_cache($cat['uppercats'],null,false),
+						'SELECTED' => ($concours->concours_infos['category'] == $cat['id'] ? 'selected' : '')
+					));
+}
+
+
+
+$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/add_concours.tpl'));
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
+
+// NB of days between 2 dates "AAAA-MM-JJ HH:hh:ss"
+function NbJours($debut, $fin) {
+
+  $tDeb = explode("-", substr($debut,0,strpos($debut, ' ')));
+  $tFin = explode("-", substr($fin,0,strpos($fin, ' ')));
+
+  $diff = mktime(0, 0, 0, $tFin[1], $tFin[2], $tFin[0]) - 
+          mktime(0, 0, 0, $tDeb[1], $tDeb[2], $tDeb[0]);
+  
+  return(($diff / 86400));
+
+}
+function AjoutJours($debut, $jours) {
+  $tDeb = explode("-", substr($debut,0,strpos($debut, ' ')));
+  $tDebH = explode(":", substr($debut,strpos($debut, ' ')+1));
+  $tFin = "";
+
+	$nb_ans = (int)(($jours)/365);
+	$nb_mois = (int)(( ($jours)%365) / 31);
+	$nb_jours = (int)(( ($jours)%365) % 31);		
+
+$tFin = date("Y-m-d H:m:s", mktime($tDebH[0], $tDebH[1], $tDebH[2], $tDeb[1] + $nb_mois, $tDeb[2] + $nb_jours, $tDeb[0] + $nb_ans));
+  
+  return($tFin);
+
+}
+
+
+?>
Index: /extensions/ConcoursPhoto/admin/admin.php
===================================================================
--- /extensions/ConcoursPhoto/admin/admin.php	(revision 3905)
+++ /extensions/ConcoursPhoto/admin/admin.php	(revision 3905)
@@ -0,0 +1,44 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+global $template, $conf, $user;
+
+load_language('plugin.lang', CONCOURS_PATH);
+include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
+include_once(CONCOURS_PATH . 'admin/functions.inc.php');
+$my_base_url = get_admin_plugin_menu_link(__FILE__);
+
+// +-----------------------------------------------------------------------+
+// |                            Tabsheet
+// +-----------------------------------------------------------------------+
+if (!isset($_GET['tab']))
+    $page['tab'] = 'manage';
+else
+    $page['tab'] = $_GET['tab'];
+
+$tabsheet = new tabsheet();
+$tabsheet->add('manage',
+               l10n('concours_management'),
+               $my_base_url.'&amp;tab=manage');
+
+$tabsheet->add('add_concours',
+               l10n('concours_add'),
+               $my_base_url.'&amp;tab=add_concours&amp;action=new');
+
+$tabsheet->add('config',
+               l10n('concours_config'),
+               $my_base_url.'&amp;tab=config');
+
+$tabsheet->add('params',
+               l10n('concours_params'),
+               $my_base_url.'&amp;tab=params');
+
+$tabsheet->select($page['tab']);
+$tabsheet->assign();
+
+
+// Include file
+include(CONCOURS_PATH.'admin/'.$page['tab'].'.php');
+
+?>
Index: /extensions/ConcoursPhoto/admin/config.php
===================================================================
--- /extensions/ConcoursPhoto/admin/config.php	(revision 3905)
+++ /extensions/ConcoursPhoto/admin/config.php	(revision 3905)
@@ -0,0 +1,98 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+global $template;
+
+// Show default criterias (concours id=0)
+// Available actions : 
+// add (action=add)
+// modify(action=modify)
+// delete(action=delete)
+
+$defaultconcours = new Concours(0);
+
+
+if (isset($_POST['add']))	// Add new criteria
+{
+	redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&amp;action=add&amp;concours_id=' . $id_concours);
+}
+
+if (isset($_GET['action']))
+{
+	if (isset($_GET['id']))
+		$criteria_id = $_GET['id'];
+	switch($_GET['action'])
+	{
+		case "delete" :
+			if (isset($criteria_id))
+				$defaultconcours->delete_criteria($criteria_id);
+			else
+				die ("Wrong parameters...");
+			break;
+		case "modify" : 
+			break;
+	}
+}
+
+
+$firstcriterias = $defaultconcours->get_firstlevel_criterias();
+foreach ($firstcriterias as $criteria)
+{
+if ($defaultconcours->debug)					echo "criteriaID=".$criteria['criteria_id']."\n";
+	// First without sub criterias
+	if (!$defaultconcours->is_criterias_contains_sub($criteria['criteria_id'] ))
+	{
+		$template->append( 'concours_criteria', array(
+				'nosub'	=> true,
+				'level'	=> 1,
+				'id' 	=> $criteria['criteria_id'],				// id du critere
+				'name' 	=> $criteria['name'],				// id du critere
+				'lib'	=> $criteria['descr'], //.'(min='$criteria['min_value'].';max='.$criteria['min_value'].')',			// libelle du critrer
+				'min' 	=> $criteria['min_value'],				// min
+				'max' 	=> $criteria['max_value'],				// max
+				'pond' 	=> $criteria['ponderation'],			// ponderation
+				'U_EDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&amp;concours_id=' . $defaultconcours->concours_id.'&amp;action=modify&amp;id='.$criteria['id'],
+				'U_DELETE' => !is_adviser() ? PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&amp;concours_id=' . $defaultconcours->concours_id.'&amp;action=delete&amp;id='.$criteria['id'] : '',
+				'U_ADD' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&amp;concours_id=' . $defaultconcours->concours_id.'&amp;action=add&amp;upcriteria='.$criteria['criteria_id'],
+			));
+	}
+	else
+	{
+		$template->append( 'concours_criteria', array(
+				'nosub'	=> false,
+				'level'	=> 1,
+				'id' 	=> $criteria['criteria_id'],				// id du critere
+				'name' 	=> $criteria['name'],				// id du critere
+				'lib'	=> $criteria['descr'],
+				'U_ADD' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&amp;concours_id=' . $defaultconcours->concours_id.'&amp;action=add&amp;upcriteria='.$criteria['criteria_id'],
+			));
+		$secondcriterias = $defaultconcours->get_subcriterias($criteria['criteria_id'] );
+		foreach ($secondcriterias as $subcriteria)
+		{
+if ($defaultconcours->debug)							echo "subcriteriaID=".$criteria['criteria_id']."\n";
+			$template->append( 'concours_criteria', array(
+					'nosub'	=> true,
+					'level'	=> 2,
+					'id' 	=> $subcriteria['criteria_id'],				// id du critere
+					'name' 	=> $subcriteria['name'],				// id du critere
+					'lib'	=> $subcriteria['descr'], //.'(min='$criteria['min_value'].';max='.$criteria['min_value'].')',			// libelle du critrer
+					'min' 	=> $subcriteria['min_value'],				// min
+					'max' 	=> $subcriteria['max_value'],				// max
+					'pond' 	=> $subcriteria['ponderation'],			// ponderation
+					'U_EDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&amp;concours_id=' . $defaultconcours->concours_id.'&amp;action=modify&amp;id='.$subcriteria['id'],
+					'U_DELETE' => !is_adviser() ? PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fcriteria.php&amp;concours_id=' . $defaultconcours->concours_id.'&amp;action=delete&amp;id='.$subcriteria['id'] : '',
+				));
+			
+		}
+	}
+
+}
+
+$template->assign('IMG_URL', CONCOURS_IMG_PATH);
+
+
+$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/config.tpl');
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
+
+?>
Index: /extensions/ConcoursPhoto/admin/criteria.php
===================================================================
--- /extensions/ConcoursPhoto/admin/criteria.php	(revision 3905)
+++ /extensions/ConcoursPhoto/admin/criteria.php	(revision 3905)
@@ -0,0 +1,117 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+global $template;
+
+// Add or modify new criteria
+// if previous page is "config" ==> id_concours=0. After submit, redirect to config page
+// if previous page is add_concours with action modify_crit and id_concours !=0, redirect to add_concours page with correct params.
+
+// action = modify/add/edit
+
+$id_concours = (isset($_GET['id_concours']) ? $_GET['id_concours'] : 0);
+	
+$concours = new Concours($id_concours);
+
+if (!isset($_GET['action']))
+	$_GET['action'] = "edit";
+
+
+if (isset($_POST['submit'])) // validation
+{
+	$datas = array();
+
+	$datas['id'] = isset($_GET['id']) ? $_GET['id'] : null;
+	$datas['name'] = $_POST['criteria_name'];
+	$datas['descr'] = $_POST['criteria_lib'];
+	$datas['min_value'] = $_POST['criteria_min'];
+	$datas['max_value'] = $_POST['criteria_max'];
+	$datas['ponderation'] = $_POST['criteria_pond'];
+	$datas['uppercriteria'] = isset($_GET['upcriteria']) ? $_GET['upcriteria'] : false;
+	// if action = add
+	if ($_GET['action'] == "add")
+	{
+		$concours->add_criteria($datas);
+	}
+	// if action = modify
+	elseif ($_GET['action'] == "modify" )
+	{
+		$concours->update_criteria($datas);
+	}
+
+	if ($id_concours == 0)
+		redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php&amp;tab=config');
+	else
+		redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php&amp;tab=add_concours&amp;action=modify_crit&amp;concours=' . $id_concours);
+} 
+
+
+switch ($_GET['action'])
+{
+
+	case "delete" :
+		if (!isset($_GET['id']))
+			die ("Wrong parameters...");
+		else
+		{	
+if ($concours->debug)		echo "ID=".$_GET['id'];
+			$concours->delete_criteria_by_id($_GET['id']);
+
+			if ($id_concours == 0)
+				redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php&amp;tab=config');
+			else
+				redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php&amp;tab=add_concours&amp;action=modify_crit&amp;concours=' . $id_concours);
+			
+		}
+		break;
+		
+	case "modify" :
+		if (!isset($_GET['id']))
+			die ("Wrong parameters...");
+		else
+		{	
+			$criteria = $concours->get_criteria_by_id($_GET['id']);
+			if (!$criteria == array()) // Not found
+			{
+				$template->assign( array(
+						'criteria_id' 		=> $criteria['criteria_id'],				// id du critere
+						'criteria_name' 	=> $criteria['name'],				// id du critere
+						'criteria_lib'		=> $criteria['descr'], //.'(min='$criteria['min_value'].';max='.$criteria['min_value'].')',			// libelle du critrer
+						'criteria_min' 		=> $criteria['min_value'],				// min
+						'criteria_max' 		=> $criteria['max_value'],				// max
+						'criteria_pond' 	=> $criteria['ponderation'],			// ponderation
+						'action'			=> $_GET['action']
+					));
+			
+			}
+			
+		}
+		break;
+		
+	case "add" :
+		$query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
+					FROM ' . CONCOURS_DETAIL_TABLE . ' ;';
+		list($next_element_id) = mysql_fetch_array(pwg_query($query));
+		$query = 'SELECT IF(MAX(criteria_id)+1 IS NULL, 1, MAX(criteria_id)+1) AS next_criteria_id
+					FROM ' . CONCOURS_DETAIL_TABLE . '
+				  WHERE id_concours = '.$concours->concours_id  . ' ;';
+		list($next_criteria_id) = mysql_fetch_array(pwg_query($query));
+
+		$template->assign( array(
+				'criteria_id' 		=> $next_criteria_id,				// id du critere
+				'action'			=> $_GET['action']
+			));
+		break;
+	default : 
+		break;
+}
+
+$template->assign( array('EDIT'=>(isset($_GET['edit']) ? true : false)));
+
+
+
+$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/criteria.tpl');
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
+
+?>
Index: /extensions/ConcoursPhoto/admin/file.php
===================================================================
--- /extensions/ConcoursPhoto/admin/file.php	(revision 3905)
+++ /extensions/ConcoursPhoto/admin/file.php	(revision 3905)
@@ -0,0 +1,18 @@
+<?php
+
+
+
+$filename = $_GET['file'];
+
+$dirpath = "../result/";
+		
+$size = filesize($dirpath. $filename);
+
+header('Content-Type: application/octet-stream');
+header('Content-Length: '.$size);
+header('Content-Disposition: attachment; filename='.$filename);
+header('Content-Transfer-Encoding: binary');
+
+readfile($dirpath. $filename);
+
+?>
Index: /extensions/ConcoursPhoto/admin/functions.inc.php
===================================================================
--- /extensions/ConcoursPhoto/admin/functions.inc.php	(revision 3905)
+++ /extensions/ConcoursPhoto/admin/functions.inc.php	(revision 3905)
@@ -0,0 +1,212 @@
+<?php
+
+// Get all generated csv files stored on RESULT directory
+function get_csvfile_result()
+{
+	$csvfile = array();
+    if (is_dir(CONCOURS_RESULT_FOLDER) )
+	{
+		$dir = opendir(CONCOURS_RESULT_FOLDER);
+		while ($file = readdir($dir)) 
+		{
+            // only csv file
+			if ($file != '.' and $file != '..' and preg_match("/.csv/", $file)) 
+            {
+				$path = CONCOURS_RESULT_FOLDER . $file;
+				if (!is_dir($path) and !is_link($path)) 
+				{
+					$concours_info = get_info_concours_from_csvfile($file);
+					$csvfile[$file] = array(
+						'name' => $file,
+						'link' => $path,
+						'conc_id' => (isset($concours_info['conc_id']) ? $concours_info['conc_id'] : "0"),
+						'conc_name' => (isset($concours_info['conc_name']) ? $concours_info['conc_name'] : "N/A"),
+						'conc_descr' => (isset($concours_info['conc_descr']) ? $concours_info['conc_descr'] : "N/A")
+						);
+
+	// Try to search on database if the concours is already present to recover name ans description					
+				}
+			}
+		}
+		closedir($dir);
+		uasort($csvfile, 'name_compare');
+	}
+	return $csvfile;
+}
+
+// Get name and description of a concours with resulte file name
+function get_info_concours_from_csvfile($csvfile = "")
+{
+
+	$query = 'SELECT id_concours as conc_id, CONC.name as conc_name, CONC.descr as conc_descr'
+	.' FROM ' .CONCOURS_RESULT_TABLE
+	.' INNER JOIN '.CONCOURS_TABLE.' AS CONC ON CONC.id = id_concours'
+	.' WHERE file_name = "'.$csvfile .'"'
+	.';';
+
+	$result = pwg_query($query);
+	if ($result)
+		return mysql_fetch_assoc($result);
+	else
+		return false;
+	
+}
+
+
+// check if a result is already present in the database
+function has_result($concours_id)
+{
+	// recover all img_id from the category
+	$query = 'SELECT DISTINCT(id_concours)'
+	.' FROM ' .CONCOURS_RESULT_TABLE
+	.' WHERE id_concours = '.$concours_id .';';
+	
+	$result = pwg_query($query);
+	// For each images
+	if (mysql_fetch_assoc($result))
+		return true;
+	else
+		return false;
+
+}
+// check if a file is already generated and return the link
+function has_file($concours_id)
+{
+	// recover all img_id from the category
+	$query = 'SELECT DISTINCT(file_name)'
+	.' FROM ' .CONCOURS_RESULT_TABLE
+	.' WHERE id_concours = '.$concours_id .';';
+	
+	$result = pwg_query($query);
+	// For each images
+	if ($row = mysql_fetch_assoc($result))
+		return $row['file_name'];
+	else
+		return false;
+
+}
+
+
+// Get list of inactive concours
+// return array with concours id
+function get_inactive_concours()
+{
+	$concours_list=array();
+	$query = '
+		SELECT *
+		FROM ' . CONCOURS_TABLE .' 
+		WHERE time_to_sec(TIMEDIFF(begin_date, now())) > 0
+		;';
+
+	$result = pwg_query($query);
+//echo $query;
+	while ($row = mysql_fetch_assoc($result))
+	{
+		array_push($concours_list, $row);
+	}
+	return $concours_list;
+}
+
+// Get list of active concours
+// return array with concours id
+function get_active_concours()
+{
+	$concours_list=array();
+	$query = '
+		SELECT *
+		FROM ' . CONCOURS_TABLE .' 
+		WHERE time_to_sec(TIMEDIFF(begin_date, now())) < 0
+		AND time_to_sec(TIMEDIFF(now(), end_date)) < 0
+		;';
+
+	$result = pwg_query($query);
+//echo $query;
+	while ($row = mysql_fetch_assoc($result))
+	{
+		array_push($concours_list, $row);
+	}
+	return $concours_list;
+}
+
+// Get list of closed concours
+// return array with concours id
+function get_closed_concours()
+{
+	$concours_list=array();
+	$query = '
+		SELECT *
+		FROM ' . CONCOURS_TABLE .' 
+		WHERE time_to_sec(TIMEDIFF(now(), end_date)) > 0 '
+//		.'AND id != 0'
+		.';';
+
+	$result = pwg_query($query);
+//echo $query;
+	while ($row = mysql_fetch_assoc($result))
+	{
+		array_push($concours_list, $row);
+	}
+	return $concours_list;
+}
+
+
+function get_html_groups_selection(
+  $groups,
+  $fieldname,
+  $selecteds = array()
+  )
+{
+  global $conf;
+  if (count ($groups) == 0 )
+  {
+    return '';
+  }
+  $output = '<div id="'.$fieldname.'">';
+  $id = 1;
+  foreach ($groups as $group)
+  {
+    $output.=
+
+      '<input type="checkbox" name="'.$fieldname.'[]"'
+      .' id="group_'.$id++.'"'
+      .' value="'.$group['id'].'"'
+      ;
+
+    if (in_array($group['id'], $selecteds))
+    {
+      $output.= ' checked="checked"';
+    }
+
+    $output.=
+      '><label>'
+      .'&nbsp;'. $group['name']
+      .'</label>'
+      ."\n"
+      ;
+  }
+  $output.= '</div>';
+
+  return $output;
+}
+
+
+function get_all_groups()
+{
+$query = '
+SELECT id, name
+  FROM '.GROUPS_TABLE.'
+  ORDER BY name ASC
+;';
+$result = pwg_query($query);
+
+$groups = array();
+  while ($row = mysql_fetch_assoc($result))
+  {
+    array_push($groups, $row);
+  }
+
+  uasort($groups, 'name_compare');
+  return $groups;
+}
+
+?>
Index: /extensions/ConcoursPhoto/admin/index.php
===================================================================
--- /extensions/ConcoursPhoto/admin/index.php	(revision 3905)
+++ /extensions/ConcoursPhoto/admin/index.php	(revision 3905)
@@ -0,0 +1,33 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery                           |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | file          : $Id: index.php 1912 2007-03-16 06:30:07Z rub $
+// | last update   : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $
+// | last modifier : $Author: rub $
+// | revision      : $Revision: 1912 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/ConcoursPhoto/admin/manage.php
===================================================================
--- /extensions/ConcoursPhoto/admin/manage.php	(revision 3905)
+++ /extensions/ConcoursPhoto/admin/manage.php	(revision 3905)
@@ -0,0 +1,80 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+global $template;
+
+// Show concours list in 3 cases :
+// 1-> prepared concours (not actived)
+// 2-> active concours
+// 3-> closed concours
+
+$prepared_concours = get_inactive_concours();
+$active_concours = get_active_concours();
+$closed_concours = get_closed_concours();
+
+// 1 prepared concours
+foreach ($prepared_concours as $concours)
+{
+  $template->append('prepared_concours', array(
+    'ID' => $concours['id'],
+	'CREATE_DATE'	=> $concours['create_date'],
+    'NAME' => $concours['name'],
+    'DESC' => $concours['descr'],
+	'BEGIN_DATE'	=> $concours['begin_date'],
+	'END_DATE'	=> $concours['end_date'],
+
+    'U_EDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;concours=' . $concours['id'].'&amp;action=modify',
+    'U_DELETE' => !is_adviser() ? PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;concours=' . $concours['id'].'&amp;action=del' : '',
+  ));
+
+}
+// 2 active concours
+foreach ($active_concours as $concours)
+{
+  $template->append('active_concours', array(
+    'ID' => $concours['id'],
+	'CREATE_DATE'	=> $concours['create_date'],
+    'NAME' => $concours['name'],
+    'DESC' => $concours['descr'],
+	'BEGIN_DATE'	=> $concours['begin_date'],
+	'END_DATE'	=> $concours['end_date'],
+
+    'U_EDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;concours=' . $concours['id'].'&amp;action=modify',
+    'U_DELETE' => !is_adviser() ? PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;concours=' . $concours['id'].'&amp;action=del': '',
+  ));
+
+}
+// 3 closed concours
+foreach ($closed_concours as $concours)
+{
+	if ($concours['id'] != 0)	// Default are not display
+	{
+		$filename = has_file($concours['id']);
+	  $template->append('closed_concours', array(
+		'ID' => $concours['id'],
+		'CREATE_DATE'	=> $concours['create_date'],
+		'NAME' => $concours['name'],
+		'DESC' => $concours['descr'],
+		'BEGIN_DATE'	=> $concours['begin_date'],
+		'END_DATE'	=> $concours['end_date'],
+
+		'U_EDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;concours=' . $concours['id'].'&amp;action=edit',
+		'U_DELETE' => !is_adviser() ? PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;concours=' . $concours['id'].'&amp;action=del' : '',
+		'U_RESULT' => (!is_adviser() and !has_result($concours['id']) )? PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;concours=' . $concours['id'].'&amp;action=result' : '',
+		'U_FILE' => !is_adviser() 
+						? ($filename ? CONCOURS_ADMIN_PATH . 'file.php?file=' . $filename
+																: (has_result($concours['id']) ? PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;concours=' . $concours['id'].'&amp;action=file' : ''))
+						: '',
+	  ));
+	}
+}
+
+$template->assign('IMG_URL', CONCOURS_IMG_PATH);
+
+
+
+$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/manage.tpl');
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
+
+?>
Index: /extensions/ConcoursPhoto/admin/params.php
===================================================================
--- /extensions/ConcoursPhoto/admin/params.php	(revision 3905)
+++ /extensions/ConcoursPhoto/admin/params.php	(revision 3905)
@@ -0,0 +1,45 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+include_once(CONCOURS_PATH . 'admin/functions.inc.php');
+
+global $template;
+
+// General parameters for the concours
+$concours = new Concours();
+
+if (isset($_POST['submit'])) { 
+  $concours->my_config['active_menubar'] = isset($_POST['active_menubar']);
+  $concours->my_config['nbconcours_menubar'] = $_POST['nbconcours_menubar'];
+
+  $concours->save_config();
+  array_push($page['infos'], l10n('concours_saveOK'));
+}
+
+for($jj=0; $jj < 10; $jj++)
+{
+	$template->append('NBCONCOURS',array('ID' => $jj,'NAME' => $jj,'SELECTED' => ($concours->my_config['nbconcours_menubar'] == $jj ? 'selected' : '')));
+	$i++;	
+}
+
+$template->assign(array(
+	'SHOW_MENUBAR' 			=> ($concours->my_config['active_menubar'] ? 'checked="checked"' : '')
+			));
+
+$result = array();
+$result = get_csvfile_result();		
+$o=0;
+foreach($result as $file)
+{
+	$template->append('FILE',array('NAME' => $file['name'],
+								   'LINK' => $file['link'],
+								   'CONC_ID' => $file['conc_id'],
+								   'CONC_NAME' => $file['conc_name'],
+								   'CONC_DESCR' => $file['conc_descr']
+					));
+}
+
+$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/params.tpl');
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
+
+?>
Index: /extensions/ConcoursPhoto/admin/template/add_concours.tpl
===================================================================
--- /extensions/ConcoursPhoto/admin/template/add_concours.tpl	(revision 3905)
+++ /extensions/ConcoursPhoto/admin/template/add_concours.tpl	(revision 3905)
@@ -0,0 +1,149 @@
+{include file='include/autosize.inc.tpl'}
+
+<div class="titrePage">
+  <h2>Concours</h2>
+</div>
+
+<form method="post" action="" class="properties"  ENCTYPE="multipart/form-data">
+
+<fieldset>
+	<legend>{'concours_add'|@translate}</legend>
+	<table>
+
+		<tr><td colspan="3"><br></td></tr>
+
+		<tr>
+			<td><b>{'concours_id'|@translate}&nbsp;&nbsp;</b></td>
+			<td colspan="2">{$CONCOURS.ID}</td>
+		</tr>
+{if (isset($action) && ($action == 'modify_crit' || $action == 'edit'))}
+		<tr>
+			<td><b>{'concours_name'|@translate}&nbsp;&nbsp;</b></td>
+			<td colspan="2">{$CONCOURS.NAME}</td>
+		</tr>
+
+		<tr>
+			<td><b>{'concours_descr'|@translate}&nbsp;&nbsp;</b></td>
+			<td colspan="2">{$CONCOURS.DESCR}</td>
+		</tr>
+
+		<tr>
+			<td><b>{'concours_begin_date'|@translate}</b></td>
+			<td colspan="2">{$CONCOURS.BEGIN_DATE}
+			 {'concours_nb_jours'|@translate} {$CONCOURS.END_DATE} {'jours'|@translate}</td>
+        </tr>
+		<tr>
+			<td colspan="3">
+			<b>{'concours_category_select'|@translate}</b>
+			<select  name="cat_selection" disabled="disabled">
+			 {foreach from=$category_selection item=category_selection}
+			  <option value="{$category_selection.ID}" {$category_selection.SELECTED}>{$category_selection.NAME}</option>
+			{/foreach}
+			</select>
+			</td>
+        </tr>
+{else}
+		<tr>
+			<td><b>{'concours_name'|@translate}&nbsp;&nbsp;</b></td>
+			<td colspan="2"><input  type="text" size="50" maxlength="50" value="{$CONCOURS.NAME}" name="concours_name"/></td>
+		</tr>
+
+		<tr><td colspan="3"><br></td></tr>
+
+		<tr>
+			<td><b>{'concours_descr'|@translate}&nbsp;&nbsp;</b></td>
+			<td colspan="2"><input  type="text" size="65" maxlength="255" value="{$CONCOURS.DESCR}" name="concours_descr"/></td>
+		</tr>
+
+		<tr><td colspan="3"><br></td></tr>
+
+		{if isset($group_perm)}
+		<tr><td colspan="3"><br></td></tr>
+		<tr>
+			<td><b>{'concours_authorized_group'|@translate} &nbsp;&nbsp;</b></td>
+			<td colspan="2">{$group_perm.GROUPSELECTION}</td>
+        </tr>
+		{/if}
+		<tr>
+			<td>&nbsp;</td>
+			<td>{'concours_begin_date'|@translate} (AAAA-MM-JJ HH:MM:SS)</td>
+			<td>{'concours_nb_jours'|@translate}</td>
+        </tr>
+		<tr>
+			<td><b>{'concours_activation_date'|@translate}</b></td>
+			<td><input  type="text" size="19" maxlength="19" value="{$CONCOURS.BEGIN_DATE}" name="concours_begin_date"/></td>
+			<td><input  type="text" size="5" maxlength="5" value="{$CONCOURS.END_DATE}" name="concours_end_date"/> {'jours'|@translate}</td>
+        </tr>
+        <tr><td colspan="3"><br></td></tr>
+		<tr>
+			<td colspan="3">
+			<b>{'concours_category_select'|@translate}</b>
+			<select  name="cat_selection">
+			 {foreach from=$category_selection item=category_selection}
+			  <option value="{$category_selection.ID}" {$category_selection.SELECTED}>{$category_selection.NAME}</option>
+			{/foreach}
+			</select>
+			</td>
+        </tr>
+{/if}
+		</table>
+</fieldset>
+{if (isset($action) && ($action == 'modify_crit' || $action == 'edit'))}
+<fieldset>
+	<legend>{'concours_criterias'|@translate}</legend>
+	 <table border="1">
+		<tr>
+			<td><b>{'concours_id'|@translate}</b></td>
+			<td><b>{'concours_name'|@translate}</b></td>
+			<td width="50%"><b>{'concours_descr'|@translate}</b></td>
+			<td><b>{'concours_min_value'|@translate}</b></td>
+			<td><b>{'concours_max_value'|@translate}</b></td>
+			<td><b>{'concours_coef'|@translate}</b></td>
+			{if $action != 'edit'}
+			<td width="10%"><b>{'concours_actions'|@translate}</b></td>
+			{/if}
+		</tr>
+	 {foreach from=$concours_criteria item=concours_criteria}
+		<tr>
+			<td>{$concours_criteria.id}</td>		
+			<td>
+				{if $concours_criteria.level == 1}
+					<b>{$concours_criteria.name}</b>
+				{else}
+					&nbsp;&nbsp;<i>{$concours_criteria.name}</i>
+				{/if}
+			</td>		
+			<td>{$concours_criteria.lib}</td>		
+			{if !$concours_criteria.nosub}
+				<td colspan="3">&nbsp;</td>		
+			{else}
+				<td>{$concours_criteria.min}</td>		
+				<td>{$concours_criteria.max}</td>		
+				<td>{$concours_criteria.pond}</td>		
+			{/if}
+			{if $action != 'edit'}
+			<td>
+				{if isset($concours_criteria.U_EDIT)}
+					<a href="{$concours_criteria.U_EDIT}" title="{'criteria_edit'|@translate}"><img src="{$themeconf.admin_icon_dir}/category_edit.png" class="button" alt="{'criteria_edit'|@translate}"/></a>
+					&nbsp;
+				{/if}
+				{if isset($concours_criteria.U_DELETE)}
+					<a href="{$concours_criteria.U_DELETE}" title="{'criteria_delete'|@translate}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');"><img src="{$themeconf.admin_icon_dir}/delete.png" class="button" alt="{'criteria_delete'|@translate}" /></a>
+				{/if}
+				{if $concours_criteria.level == 1}
+					<a href="{$concours_criteria.U_ADD}" title="{'subcriteria_add'|@translate}" ><img src="{$IMG_URL}add.png" class="button" alt="{'subcriteria_add'|@translate}" /></a>
+				{/if}
+			</td>
+			{/if}
+		</tr>
+	{/foreach}
+	</table>
+	{if $action != 'edit'}
+	<p><input type="submit" name="add" value="{'concours_add_criteria'|@translate}" />
+	{/if}
+
+
+</fieldset>
+{/if}
+<p><input class="submit" type="submit" value="{'Submit'|@translate}" name="submit" /></p>
+</form>
Index: /extensions/ConcoursPhoto/admin/template/config.tpl
===================================================================
--- /extensions/ConcoursPhoto/admin/template/config.tpl	(revision 3905)
+++ /extensions/ConcoursPhoto/admin/template/config.tpl	(revision 3905)
@@ -0,0 +1,57 @@
+<div class="titrePage">
+  <h2>Concours</h2>
+</div>
+<p>
+{'concours_admin_title'|@translate}
+</p>
+<form method="post" action="" class="properties"  ENCTYPE="multipart/form-data">
+<fieldset>
+	<legend>{'default_criteria'|@translate}</legend>
+
+	 <table border="1">
+		<tr>
+			<td><b>{'concours_id'|@translate}</b></td>
+			<td><b>{'concours_name'|@translate}</b></td>
+			<td width="50%"><b>{'concours_descr'|@translate}</b></td>
+			<td><b>{'concours_min_value'|@translate}</b></td>
+			<td><b>{'concours_max_value'|@translate}</b></td>
+			<td><b>{'concours_coef'|@translate}</b></td>
+			<td width="10%"><b>{'concours_actions'|@translate}</b></td>
+		</tr>
+	 {foreach from=$concours_criteria item=concours_criteria}
+		<tr>
+			<td>{$concours_criteria.id}</td>		
+			<td>
+				{if $concours_criteria.level == 1}
+					<b>{$concours_criteria.name}</b>
+				{else}
+					&nbsp;&nbsp;<i>{$concours_criteria.name}</i>
+				{/if}
+			</td>		
+			<td>{$concours_criteria.lib}</td>		
+			{if !$concours_criteria.nosub}
+				<td colspan="3">&nbsp;</td>		
+			{else}
+				<td>{$concours_criteria.min}</td>		
+				<td>{$concours_criteria.max}</td>		
+				<td>{$concours_criteria.pond}</td>		
+			{/if}
+			<td>
+			{if isset($concours_criteria.U_EDIT)}
+				<a href="{$concours_criteria.U_EDIT}" title="{'criteria_edit'|@translate}"><img src="{$themeconf.admin_icon_dir}/category_edit.png" class="button" alt="{'criteria_edit'|@translate}"/></a>
+				&nbsp;
+			{/if}
+			{if isset($concours_criteria.U_DELETE)}
+				<a href="{$concours_criteria.U_DELETE}" title="{'criteria_delete'|@translate}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');"><img src="{$themeconf.admin_icon_dir}/delete.png" class="button" alt="{'criteria_delete'|@translate}" /></a>
+			{/if}
+			{if $concours_criteria.level == 1}
+				<a href="{$concours_criteria.U_ADD}" title="{'subcriteria_add'|@translate}" ><img src="{$IMG_URL}add.png" class="button" alt="{'subcriteria_add'|@translate}" /></a>
+			{/if}
+			</td>
+		</tr>
+	{/foreach}
+	</table>
+	<p><input type="submit" name="add" value="{'concours_add_criteria'|@translate}" />
+		
+</fieldset>
+</form>
Index: /extensions/ConcoursPhoto/admin/template/criteria.tpl
===================================================================
--- /extensions/ConcoursPhoto/admin/template/criteria.tpl	(revision 3905)
+++ /extensions/ConcoursPhoto/admin/template/criteria.tpl	(revision 3905)
@@ -0,0 +1,53 @@
+<div class="titrePage">
+  <h2>Concours</h2>
+</div>
+<p>
+{'concours_admin_title'|@translate}
+</p>
+<form method="post" action="" class="properties"  ENCTYPE="multipart/form-data">
+<fieldset>
+	<legend>{'manage_criteria'|@translate}</legend>
+	 <table border="1">
+		<tr>
+			<td><b>{'concours_id'|@translate}</b></td>
+			<td>{$criteria_id}</td>
+		</tr>
+
+		<tr>
+			<td><b>{'concours_name'|@translate}</b></td>
+			<td width="50">{if $action != "edit"} 
+				<input type="text" size="50" maxlength="50" value="{$criteria_name}" name="criteria_name"/></td>
+				{else}{$criteria_name}{/if}
+			</td>
+		</tr>
+		<tr>
+			<td><b>{'concours_descr'|@translate}</b></td>
+			<td width="255">{if $action != "edit"} 
+				<input type="text" size="65" maxlength="255" value="{$criteria_lib}" name="criteria_lib"/></td>
+				{else}{$criteria_lib}{/if}
+			</td>
+		</tr>
+			<td><b>{'concours_min_value'|@translate}</b></td>
+			<td>{if $action != "edit"} 
+				<input type="text" size="5" maxlength="5" value="{$criteria_min}" name="criteria_min"/></td>
+				{else}{$criteria_min}{/if}
+			</td>
+		</tr>
+			<td><b>{'concours_max_value'|@translate}</b></td>
+			<td>{if $action != "edit"} 
+				<input type="text" size="5" maxlength="5" value="{$criteria_max}" name="criteria_max"/></td>
+				{else}{$criteria_max}{/if}
+			</td>
+		</tr>
+			<td><b>{'concours_coef'|@translate}</b></td>
+			<td>{if $action != "edit"} 
+				<input type="text" size="5" maxlength="5" value="{$criteria_pond}" name="criteria_pond"/></td>
+				{else}{$criteria_pond}{/if}
+			</td>
+		</tr>
+	</table>
+
+	<p><input type="submit" name="submit" value="{'concours_criteria_submit'|@translate}" />
+		
+</fieldset>
+</form>
Index: /extensions/ConcoursPhoto/admin/template/manage.tpl
===================================================================
--- /extensions/ConcoursPhoto/admin/template/manage.tpl	(revision 3905)
+++ /extensions/ConcoursPhoto/admin/template/manage.tpl	(revision 3905)
@@ -0,0 +1,99 @@
+<div class="titrePage">
+  <h2>Concours</h2>
+</div>
+<p>
+{'concours_admin_title'|@translate}
+</p>
+<form method="post" action="" class="properties"  ENCTYPE="multipart/form-data">
+<fieldset>
+	<legend>{'manage_concours'|@translate}</legend>
+
+	<fieldset>
+		<legend>{'prepared_concours'|@translate}</legend>
+		 <table border="1">
+			<tr>
+				<th><b>{'concours_id'|@translate}</b></th>
+				<th><b>{'concours_name'|@translate}</b></th>
+				<th><b>{'concours_create_date'|@translate}</b></th>
+				<th width="50%"><b>{'concours_descr'|@translate}</b></th>
+				<th><b>{'concours_begin_date'|@translate}</b></th>
+				<th><b>{'concours_end_date'|@translate}</b></th>
+				<th width="10%"><b>{'concours_actions'|@translate}</b></th>
+			</tr>
+		 {foreach from=$prepared_concours item=prepared_concours}
+			<tr>
+				<td>{$prepared_concours.ID}</td>		
+				<td>{$prepared_concours.NAME}</td>		
+				<td>{$prepared_concours.CREATE_DATE}</td>		
+				<td>{$prepared_concours.DESC}</td>		
+				<td>{$prepared_concours.BEGIN_DATE}</td>		
+				<td>{$prepared_concours.END_DATE}</td>		
+				<td><a href="{$prepared_concours.U_EDIT}" title="{'concours_edit'|@translate}"><img src="{$themeconf.admin_icon_dir}/category_edit.png" class="button" alt="{'concours_edit'|@translate}"/></a>
+				&nbsp;<a href="{$prepared_concours.U_DELETE}" title="{'concours_delete'|@translate}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');"><img src="{$themeconf.admin_icon_dir}/category_delete.png" class="button" alt="{'concours_delete'|@translate}" /></a>
+				</td>
+			</tr>
+		{/foreach}
+		</table>
+	</fieldset>
+	
+	<fieldset>
+		<legend>{'active_concours'|@translate}</legend>
+		 <table border="1">
+			<tr>
+				<th><b>{'concours_id'|@translate}</b></th>
+				<th><b>{'concours_name'|@translate}</b></th>
+				<th><b>{'concours_create_date'|@translate}</b></th>
+				<th width="50%"><b>{'concours_descr'|@translate}</b></th>
+				<th><b>{'concours_begin_date'|@translate}</b></th>
+				<th><b>{'concours_end_date'|@translate}</b></th>
+				<th width="10%"><b>{'concours_actions'|@translate}</b></th>
+			</tr>
+		 {foreach from=$active_concours item=active_concours}
+			<tr>
+				<td>{$active_concours.ID}</td>		
+				<td>{$active_concours.NAME}</td>		
+				<td>{$active_concours.CREATE_DATE}</td>		
+				<td>{$active_concours.DESC}</td>		
+				<td>{$active_concours.BEGIN_DATE}</td>		
+				<td>{$active_concours.END_DATE}</td>		
+				<td><a href="{$active_concours.U_EDIT}" title="{'concours_edit'|@translate}"><img src="{$themeconf.admin_icon_dir}/category_edit.png" class="button" alt="{'concours_edit'|@translate}"/></a>
+				&nbsp;<a href="{$active_concours.U_DELETE}" title="{'concours_delete'|@translate}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');"><img src="{$themeconf.admin_icon_dir}/category_delete.png" class="button" alt="{'concours_delete'|@translate}" /></a>
+				</td>
+			</tr>
+		{/foreach}
+		</table>
+	</fieldset>
+
+	<fieldset>
+		<legend>{'closed_concours'|@translate}</legend>
+		 <table border="1">
+			<tr>
+				<th><b>{'concours_id'|@translate}</b></th>
+				<th><b>{'concours_name'|@translate}</b></th>
+				<th><b>{'concours_create_date'|@translate}</b></th>
+				<th width="50%"><b>{'concours_descr'|@translate}</b></th>
+				<th><b>{'concours_begin_date'|@translate}</b></th>
+				<th><b>{'concours_end_date'|@translate}</b></th>
+				<th><b>{'concours_actions'|@translate}</b></th>
+			</tr>
+		 {foreach from=$closed_concours item=closed_concours}
+			<tr>
+				<td>{$closed_concours.ID}</td>		
+				<td>{$closed_concours.NAME}</td>		
+				<td>{$closed_concours.CREATE_DATE}</td>		
+				<td>{$closed_concours.DESC}</td>		
+				<td>{$closed_concours.BEGIN_DATE}</td>		
+				<td>{$closed_concours.END_DATE}</td>		
+				<td><a href="{$closed_concours.U_EDIT}" title="{'concours_edit'|@translate}"><img src="{$themeconf.admin_icon_dir}/category_edit.png" class="button" alt="{'concours_edit'|@translate}"/></a>
+				&nbsp;<a href="{$closed_concours.U_DELETE}" title="{'concours_delete'|@translate}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');"><img src="{$themeconf.admin_icon_dir}/category_delete.png" class="button" alt="{'concours_delete'|@translate}" /></a>
+				{if $closed_concours.U_RESULT != ''}&nbsp;<a href="{$closed_concours.U_RESULT}" title="{'concours_result'|@translate}"><img src="{$IMG_URL}generate.png" class="button" alt="{'concours_result'|@translate}" /></a>{/if}
+				{if $closed_concours.U_FILE != ''}&nbsp;<a href="{$closed_concours.U_FILE}" title="{'concours_file'|@translate}"><img src="{$IMG_URL}file.png" class="button" alt="{'concours_file'|@translate}" /></a>{/if}
+				
+				</td>
+			</tr>
+		{/foreach}
+		</table>
+	</fieldset>
+	
+</fieldset>
+</form>
Index: /extensions/ConcoursPhoto/admin/template/params.tpl
===================================================================
--- /extensions/ConcoursPhoto/admin/template/params.tpl	(revision 3905)
+++ /extensions/ConcoursPhoto/admin/template/params.tpl	(revision 3905)
@@ -0,0 +1,67 @@
+<div class="titrePage">
+  <h2>Concours</h2>
+</div>
+<p>
+{'concours_admin_title'|@translate}
+</p>
+<form method="post" action="" class="general">
+<fieldset>
+	<legend>{'concours_params'|@translate}</legend>
+<TABLE border="0" CELLPADDING="2" ALIGN="LEFT">
+
+	<TR>
+		<TD colspan="2">
+		    <input type="checkbox" name="active_menubar" {$SHOW_MENUBAR}/> {'concours_show_menubar'|@translate} 
+		    <br/>
+		</TD>
+	</TR>
+	<TR>
+		<TD colspan="2">
+		  {'concours_nb_concours_menubar'|@translate}
+		  <select id="nbconcours_menubar" name="nbconcours_menubar">
+			 {foreach from=$NBCONCOURS item=NBCONCOURS}
+			  <option value="{$NBCONCOURS.ID}" {$NBCONCOURS.SELECTED}>{$NBCONCOURS.NAME}</option>
+			{/foreach}
+		  </select>
+
+	     </TD>
+	</TR>
+ </table>
+<br/>
+</fieldset>
+ 
+<p><input type="submit" name="submit" value="{'concours_submit'|@translate}" />
+</p>
+</form>
+
+
+<fieldset>
+	<legend>{'concours_result_files'|@translate}</legend>
+</br>
+<table align="left">
+	<tr>
+		<td colspan="2"  align="left">
+		{'concours_result_file_list'|@translate}
+		</td>
+	</tr>
+	{if count($FILE)}
+	 {foreach from=$FILE item=FILE}
+		<tr align="left">
+			<td>
+				<a href="{$FILE.LINK}">{$FILE.NAME}</a>
+			</td>
+			<td>
+				Concours <b>{$FILE.CONC_NAME}</b> {if $FILE.CONC_ID != 0}({$FILE.CONC_ID}){/if} : <i>{$FILE.CONC_DESCR}</i>
+			</td>
+		</tr>
+	  {/foreach}
+	 {else}
+		<tr>
+		<td colspan="2" align="left">
+			<b>{'concours_no_result_file'|@translate}</b>
+			</td>
+		</tr>
+			
+	 {/if}
+</table>
+</fieldset>
Index: /extensions/ConcoursPhoto/img/index.php
===================================================================
--- /extensions/ConcoursPhoto/img/index.php	(revision 3905)
+++ /extensions/ConcoursPhoto/img/index.php	(revision 3905)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/ConcoursPhoto/include/Concours.class.php
===================================================================
--- /extensions/ConcoursPhoto/include/Concours.class.php	(revision 3905)
+++ /extensions/ConcoursPhoto/include/Concours.class.php	(revision 3905)
@@ -0,0 +1,1540 @@
+<?php
+/*
+ * Plugin Name: ConcoursPhoto
+ * File :  Concours.class.php  
+ */
+ 
+global $user;
+
+class Concours
+{
+	var $concours_id = null;
+	var $concours_infos = array();
+	
+/*	var $create_date = null;
+	var $name = null;
+	var $descr = null;
+	var $begin_date = null;
+	var $end_date = null;
+	var $category = null;
+	var $groups = null;
+*/	
+
+	// General configuration parameters
+	var $my_config = array();
+/*
+	active_menubar
+	nbconcours_menubar
+*/
+	var $user_groups = array();
+	var $debug = false;
+	
+	// Class constructor with concours id. Return NULL if not existing or create it
+	function Concours($concours_id = null, $force_creation = NULL)
+	{
+//	    $this->get_user_groups();
+		if ($concours_id !== null)
+		{		
+			$this->concours_id = (int)$concours_id;
+			$this->get_concours($concours_id);
+		}
+		// Load general parameters
+		$this->load_config();
+	}
+
+	
+	// Load general configuration from config_database
+	function load_config() 
+	{
+
+		$query = '
+		  SELECT value
+		  FROM '.CONFIG_TABLE.'
+		  WHERE param = \'concoursphoto\'
+		;';
+
+		$result = pwg_query($query);
+
+	    if($result) 
+		{
+		     $row = mysql_fetch_row($result);
+		     if(is_string($row[0])) 
+			 {
+		        $this->my_config = unserialize(($row[0]));
+		     }
+	    }
+		$this->load_default_config();
+	}
+	
+	// Initialize default values of params
+	private function load_default_config()
+	{
+	    include CONCOURS_INC_PATH.'default_values.inc.php';
+	    foreach ($concours_default_values as $key => $value) 
+		{
+		    if (!isset($this->my_config[$key]))		$this->my_config[$key] = $value;
+		}
+	}
+
+	// Save  general configuration to config_database
+	function save_config()
+	{
+		$query = '
+		  REPLACE INTO '.CONFIG_TABLE.'
+		  VALUES(
+			\'concoursphoto\',
+			\''.serialize($this->my_config).'\',
+			\'Configuration Concours Photo\')
+		;';
+
+		$result = pwg_query($query);
+
+		if($result) 
+		  return true;
+		else
+		  return false;
+	}
+	
+	
+	// Retrieve user groups 
+	function get_user_groups()
+	{
+		global $user;
+if ($this->debug)
+foreach ($user as $id=>$val)
+{
+	if (is_array($val))
+		foreach ($val as $id2=>$val2)
+			echo "user[".$id."][".$id2."]=".$val2."\n";
+	else
+		echo "user[".$id."]=".$val."\n";
+}
+
+		$query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id = ' . $user['id'] . ';';
+if ($this->debug)		echo $query."\n";
+		$result = pwg_query($query);
+		while ($row = mysql_fetch_assoc($result))
+		{
+		  array_push($this->user_groups, $row['group_id']);
+		}
+		
+if ($this->debug)
+foreach ($this->user_groups as $gr)
+	echo "Group=".$gr."\n";
+
+	}
+
+	// create a concours and store it to db.
+	// return id for concours.
+	function create_concours()
+	{}
+
+	// Get informations array for  a concours id
+	function get_concours($concours_id = null)
+	{
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+			$query = '
+				SELECT *
+				FROM ' . CONCOURS_TABLE .' 
+				WHERE id =' . ($concours_id !== NULL ? $concours_id : $this->concours_id) . '
+				LIMIT 1
+			';
+
+			$result = pwg_query($query);
+			if ($result)
+				$this->concours_infos = mysql_fetch_assoc($result);
+		}
+
+	}
+
+	// save informations on database for a concours_id
+	function save_concours($concours_id = null)
+	{
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+							
+			$query = "INSERT INTO " . CONCOURS_TABLE . "
+						( `id`,
+						`create_date`, 
+						`name`, 
+						`descr`, 
+						`begin_date`, 
+						`end_date`, 
+						`category`, 
+						`groups`)
+					VALUES (".($concours_id !== NULL ? $concours_id : $this->concours_id).", now(), 
+							\"".$this->concours_infos['name']."\", \"".$this->concours_infos['descr']."\",
+							\"".$this->concours_infos['begin_date']."\", \"".$this->concours_infos['end_date']."\", 
+							".$this->concours_infos['category'].", ".$this->concours_infos['groups'].");";
+			if (pwg_query($query) != null)
+				return true;
+			else
+				return false;
+		}
+		else		
+			return false;
+	}
+
+	// update informations on database for a concours_id
+	function update_concours($concours_id = null)
+	{
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+
+			$query = "UPDATE " . CONCOURS_TABLE . "
+						SET 
+						create_date = now(), 
+						name = \"".$this->concours_infos['name']."\", 
+						descr = \"".$this->concours_infos['descr']."\", 
+						begin_date = \"".$this->concours_infos['begin_date']."\", 
+						end_date = \"".$this->concours_infos['end_date']."\", 
+						category = ".$this->concours_infos['category'].", 
+						groups = ".$this->concours_infos['groups']."
+						WHERE id = ".($concours_id !== NULL ? $concours_id : $this->concours_id)."
+						;";
+			pwg_query($query);
+			if (pwg_query($query) != null)
+				return true;
+			else
+				return false;
+		}
+		else		
+			return false;
+	
+	}
+	
+	// delete concours from db (and all sub informations such as details, vote and result
+	function delete_concours($concours_id = null)
+	{
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+		
+			$query = '
+				DELETE
+				FROM ' . CONCOURS_TABLE .' 
+				WHERE id =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . '
+				';
+			pwg_query($query);
+			$query = '
+				DELETE
+				FROM ' . CONCOURS_DETAIL_TABLE .' 
+				WHERE id_concours =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . '
+				';
+			pwg_query($query);
+			$query = '
+				DELETE
+				FROM ' . CONCOURS_DATA_TABLE .' 
+				WHERE id_concours =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . '
+				';
+			pwg_query($query);
+			$query = '
+				DELETE
+				FROM ' . CONCOURS_RESULT_TABLE .' 
+				WHERE id_concours =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . '
+				';
+			pwg_query($query);
+		}
+		else
+			return false;
+		
+	}
+
+			
+	// today's date is between open and close date of concours?
+	function is_active($concours_id = NULL)
+	{
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+			$query = '
+				SELECT id
+				FROM ' . CONCOURS_TABLE .' 
+				WHERE id =' . ($concours_id !== NULL ? $concours_id : $this->concours_id) . '
+				AND time_to_sec(TIMEDIFF(begin_date,now())) < 0
+				AND time_to_sec(TIMEDIFF(now(), end_date)) < 0
+				';
+
+			$result = pwg_query($query);
+if ($this->debug) echo $query."\n";
+			if ($result != NULL)
+				return true;
+			else
+				return false;
+		}
+		else
+			return NULL;
+	}
+
+	// today's date is not between open and close date of concours?
+	function is_closed($concours_id = NULL)
+	{
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+			$query = '
+				SELECT id
+				FROM ' . CONCOURS_TABLE .' 
+				WHERE id =' . ($concours_id !== NULL ? $concours_id : $this->concours_id) . '
+				AND time_to_sec(TIMEDIFF(now(), end_date)) > 0
+				';
+
+			$result = pwg_query($query);
+if ($this->debug) echo $query."\n";
+			if ($result != NULL)
+				return true;
+			else
+				return false;
+		}
+		else
+			return NULL;
+	}
+
+
+	// Get criterias that are stored on db for default mode (concours_id = 0)
+	function get_default_criterias()
+	{
+		$criterias = $this->get_criterias_list(0);
+		$query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
+					FROM ' . CONCOURS_DETAIL_TABLE . ' ;';
+		list($next_element_id) = mysql_fetch_array(pwg_query($query));
+
+		foreach ($criterias as $criteria)
+		{		
+if ($this->debug)			echo "NEXT =".$next_element_id."\n";
+			$query = 'INSERT INTO '.CONCOURS_DETAIL_TABLE.'
+						(id, id_concours, criteria_id, name, descr, min_value, max_value, ponderation, uppercriteria)'
+						.'VALUES ('.$next_element_id.', '.$this->concours_id.', '
+						.$criteria['criteria_id'].', "'.$criteria['name'].'", "'
+						.$criteria['descr'].'", '.$criteria['min_value'].', '
+						.$criteria['max_value'].', '.$criteria['ponderation'].', '
+						.($criteria['uppercriteria'] ? $criteria['uppercriteria'] : 'NULL').')
+						;';
+			
+				$result = pwg_query($query);
+if ($this->debug)	echo $query;			
+			$next_element_id = $next_element_id +1;
+		}
+	}
+
+	// Get criterias from a concours
+	function get_criterias_list($concours_id = NULL)
+	{
+		$criteria_list = array();
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+			$query = '
+				SELECT *
+				FROM ' . CONCOURS_DETAIL_TABLE .' 
+				WHERE id_concours =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . '
+				ORDER BY criteria_id
+				';
+			$result = pwg_query($query);
+if ($this->debug) echo $query."\n";
+			while ($row = mysql_fetch_assoc($result))
+			{
+				array_push($criteria_list, $row);
+			}
+			return $criteria_list;
+		}
+		else
+			return $criteria_list;
+	}
+
+	// Get list of the fist level criterias
+	function get_firstlevel_criterias($concours_id = NULL)
+	{
+		$criteria_list = array();
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+			$query = '
+				SELECT *
+				FROM ' . CONCOURS_DETAIL_TABLE .' 
+				WHERE id_concours =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . '
+				AND uppercriteria IS NULL
+				ORDER BY criteria_id
+				';
+			$result = pwg_query($query);
+if ($this->debug) echo $query."\n";
+			while ($row = mysql_fetch_assoc($result))
+			{
+if ($this->debug)			echo "criteria_id=".$row['criteria_id']."\n";
+				array_push($criteria_list, $row);
+			}
+			return $criteria_list;
+		}
+		else
+			return $criteria_list;
+	}
+
+	// check if a criteria contains subcriterias
+	function is_criterias_contains_sub($criteria_id, $concours_id = NULL)
+	{
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+			$query = '
+				SELECT criteria_id
+				FROM ' . CONCOURS_DETAIL_TABLE .' 
+				WHERE id_concours =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . '
+				AND uppercriteria = '.$criteria_id.'
+				';
+			$result = pwg_query($query);
+if ($this->debug) echo $query."\n";
+			// mini 1 line 
+			if(mysql_fetch_assoc($result))
+				return true;
+			else
+				return false;
+		}
+		return NULL;
+	}
+	
+	
+	// Get list of subcriterias from a criteria_id
+	function get_subcriterias($criteria_id, $concours_id = NULL)
+	{
+		$criteria_list = array();
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+			$query = '
+				SELECT *
+				FROM ' . CONCOURS_DETAIL_TABLE .' 
+				WHERE id_concours =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . '
+				AND uppercriteria = '.$criteria_id.'
+				ORDER BY criteria_id
+				';
+			$result = pwg_query($query);
+if ($this->debug) echo $query."\n";
+			while ($row = mysql_fetch_assoc($result))
+			{
+				array_push($criteria_list, $row);
+			}
+			return $criteria_list;
+		}
+		else
+			return $criteria_list;
+	}
+	
+	// Get a detail from a criteria 
+	function get_criteria($criteria_id, $concours_id = NULL)
+	{
+		$criteria = array();
+
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+			$query = '
+				SELECT *
+				FROM ' . CONCOURS_DETAIL_TABLE .' 
+				WHERE id_concours = '. ($concours_id !== null ? $concours_id : $this->concours_id ) . '
+				AND criteria_id =' . $criteria_id . '
+				';
+			$result = pwg_query($query);
+	if ($this->debug) echo $query."\n";
+	$criteria = mysql_fetch_assoc($result);
+	/*		while ($row = mysql_fetch_assoc($result))
+			{
+				array_push($criteria, $row);
+			}
+*/		
+		}
+		return $criteria;
+	
+	}
+
+	// Get a detail from a criteria 
+	function get_criteria_by_id($id)
+	{
+		$criteria = array();
+
+		$query = '
+			SELECT *
+			FROM ' . CONCOURS_DETAIL_TABLE .' 
+			WHERE id =' . $id . '
+			';
+		$result = pwg_query($query);
+if ($this->debug) echo $query."\n";
+$criteria = mysql_fetch_assoc($result);
+/*		while ($row = mysql_fetch_assoc($result))
+		{
+			array_push($criteria, $row);
+		}
+*/		
+	return $criteria;
+	
+	}
+
+	// Add a criteria to a concours
+	// Datas is an array and contains all infos.
+	// Return the criteria id
+	function add_criteria($datas, $concours_id = NULL)
+	{
+		// determines the criteria_id 
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+			$query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id
+						FROM ' . CONCOURS_DETAIL_TABLE . ' ;';
+			list($next_element_id) = mysql_fetch_array(pwg_query($query));
+			$query = 'SELECT IF(MAX(criteria_id)+1 IS NULL, 1, MAX(criteria_id)+1) AS next_criteria_id
+						FROM ' . CONCOURS_DETAIL_TABLE . '
+					  WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id ) . ' ;';
+			list($next_criteria_id) = mysql_fetch_array(pwg_query($query));
+			
+			$query = '
+			INSERT INTO ' . CONCOURS_DETAIL_TABLE .'
+				(`id`,
+				`id_concours`,
+				`criteria_id`,
+				`name`,
+				`descr`,
+				`min_value`,
+				`max_value`,
+				`ponderation`,
+				`uppercriteria`)
+				VALUES (
+				'.$next_element_id.', '.($concours_id !== null ? $concours_id : $this->concours_id ).',
+				'.$next_criteria_id.', "'.$datas['name'].'", "'.$datas['descr'].'", '.$datas['min_value'].'
+				, '.$datas['max_value'].', '.$datas['ponderation'].'
+				, '.($datas['uppercriteria'] ? $datas['uppercriteria'] : 'NULL').'
+				);';
+
+			pwg_query($query);
+			if ($this->debug) echo $query."\n";
+	
+		}
+	}
+	
+	// Update a criteria to a concours
+	// Datas is an array and contains all infos.
+	function update_criteria($datas, $concours_id = NULL)
+	{
+		// determines the criteria_id 
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+			$query = '
+				UPDATE ' . CONCOURS_DETAIL_TABLE .'
+				SET 
+				name = "'.$datas['name'].'",
+				descr = "'.$datas['descr'].'",
+				min_value = '.$datas['min_value'].',
+				max_value = '.$datas['max_value'].',
+				ponderation = '.$datas['ponderation'].',
+				uppercriteria = '.($datas['uppercriteria'] ? $datas['uppercriteria'] : 'NULL').'
+				WHERE id = '.$datas['id'].';';
+
+			pwg_query($query);
+
+			if ($this->debug) echo $query."\n";
+
+		}		
+	}
+	
+
+	// Delete a criteria from a concours
+	function delete_criteria($criteria_id, $concours_id = NULL)
+	{
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+		
+			$query = '
+				DELETE
+				FROM ' . CONCOURS_DETAIL_TABLE .' 
+				WHERE id_concours =' . ($concours_id !== null ? $concours_id : $this->concours_id ) . '
+				AND criteria_id = '.$criteria_id.'
+				';
+			$result = pwg_query($query);
+	if ($this->debug) echo $query."\n";
+			if($result)
+				return true;
+			else
+				return false;
+		}
+		else
+			return null;
+
+	}
+	
+	// Delete a criteria (with id) from a concours
+	function delete_criteria_by_id($id)
+	{
+	
+		$query = '
+			DELETE
+			FROM ' . CONCOURS_DETAIL_TABLE .' 
+			WHERE id =' . $id . '
+			';
+		$result = pwg_query($query);
+if ($this->debug) echo $query."\n";
+
+	}	
+
+	// check if a result is already present in the database
+	function is_result_present($concours_id = null)
+	{
+		// recover all img_id from the category
+		$query = 'SELECT DISTINCT(id_concours)'
+		.' FROM ' .CONCOURS_RESULT_TABLE
+		.' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id ).';';
+		
+		$result = pwg_query($query);
+		// For each images
+		if (mysql_fetch_assoc($result))
+			return true;
+		else
+			return false;
+	
+	}
+	
+	
+	// After concours is completed (closed date is passed), generate the result and store it to DB
+	function create_result($concours_id = NULL)
+	{
+		// var which contains id=img_id and val =global note
+		$global_note = array();
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+			// only for closed concours and not already result generated
+			if ($this->is_closed($concours_id) AND ! $this->is_result_present($concours_id))
+			{
+				$user_id = array();
+				// vars not initialized
+				if ($this->concours_infos == array())
+					$this->get_concours();
+				$category = $this->concours_infos['category'];
+
+if ($this->debug)
+	echo "CAT=".$category;
+				// Get all user_id from a concours
+				$query = 'SELECT DISTINCT(user_id)'
+				.' FROM ' .CONCOURS_DATA_TABLE
+				.' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id )
+				.';';
+				$result = pwg_query($query);
+if ($this->debug)
+echo $query;
+				while ($row = mysql_fetch_assoc($result))
+				{
+					array_push($user_id, $row['user_id']);
+				}
+
+if ($this->debug)
+	foreach ($user_id as $userid)
+			echo "USER = ".$userid;
+				
+				
+				
+				// recover all img_id from the category
+				$query = 'SELECT DISTINCT(image_id)'
+				.' FROM ' .IMAGE_CATEGORY_TABLE
+				.' WHERE category_id = '.$category.';';
+				
+				$result = pwg_query($query);
+				// For each images
+				while ($row = mysql_fetch_assoc($result))
+				{
+		if ($this->debug)	echo "IMG_ID=".$row['image_id']."\n";
+					foreach ($user_id as $i => $userid)
+					{
+						if (!isset($global_note[$row['image_id']]))
+							$global_note[$row['image_id']] = 0;
+						$global_note[$row['image_id']] +=  $this->get_img_globalnote_user($row['image_id'], null, $userid );			
+					}
+				}
+				if ($this->debug)
+				{
+					foreach ($global_note as $id => $val)
+						echo "Note img ( ".$id.") = ".$val."\n";
+				}
+				
+				// update database and store result into RESULT table
+				// note = global note
+				foreach ($global_note as $id => $val)
+				{
+					$query = 'INSERT INTO  ' . CONCOURS_RESULT_TABLE .'(`id_concours`, `img_id`, `date` , `note` )
+							VALUES ('.($concours_id !== null ? $concours_id : $this->concours_id )
+									 .', '.$id 
+									 .', now() '
+									 .', '.$val
+									 .');';
+				$result = pwg_query($query);
+						 
+					
+				}
+				
+
+				
+			}
+			else
+				return false;
+		}
+		else
+			return false;
+	}
+	
+
+	// Check if an image's author is the same as the actual user 
+	function check_img_user($img_id)
+	{
+		global $user;
+		$query = '
+			SELECT author
+			FROM ' . IMAGES_TABLE .' 
+			WHERE id =' . $img_id . '
+			';
+
+		$result = pwg_query($query);
+if ($this->debug) echo $query."\n";
+		if ($result)
+		{
+			$row = mysql_fetch_assoc($result);
+			$authorid = get_userid($row['author']);
+			if ($authorid and ($authorid == $user['id']))
+				return true;
+			else
+				return false;
+		}
+		return false;
+	
+	}
+	
+
+	// Add tpl to picture.php page to display concours informations and vote
+	function display_concours_to_picture()
+	{
+		// Step1 : concours is defined to this category AND concours is open AND user is authorized to access to this category (thru group)
+		// Step1 bis : dont show concours if img_author = user_id
+		// Step 2 : Recover stored informations in db for this user
+		// Step 3 : Complete tpl information
+		// Step 4 : concat tpl
+		
+		global $page, $user, $template;
+
+		// Get user group.
+		$this->get_user_groups();
+
+		$concours = array();
+
+		
+// DEBUG
+if ($this->debug)
+foreach ($page as $id=>$val)
+{
+	if (is_array($val))
+		foreach ($val as $id2=>$val2)
+			echo "page[".$id."][".$id2."]=".$val2."\n";
+	else
+		echo "page[".$id."]=".$val."\n";
+}
+//  END DEBUG
+		if (($page['section']) == 'categories' AND !empty($page['category']))
+		{
+if ($this->debug)	echo "STEP1\n";
+			//------------
+			// Step 1
+			$query = '
+				SELECT *
+				FROM ' . CONCOURS_TABLE .' 
+				WHERE category =' . $page['category']['id'] . '
+				AND time_to_sec(TIMEDIFF(begin_date,now())) < 0
+				AND time_to_sec(TIMEDIFF(now(), end_date)) < 0
+				';
+
+			$result = pwg_query($query);
+if ($this->debug) echo $query."\n";
+			while ($row = mysql_fetch_assoc($result))
+			{
+				
+				if (!empty($row['groups']))
+				{
+if ($this->debug)	echo "GROUPS=".$row['groups'];				
+					$authorized_groups = explode(',', $row['groups']);
+					if (array_intersect($this->user_groups, $authorized_groups) == array()) 
+					{
+if ($this->debug)	echo "ERROR GROUPS";
+						continue;
+					}
+					$concours = $row;
+				}
+
+			}
+
+if ($this->debug)	echo "STEP1 bis\n";
+			//------------
+			// Step 1 bis
+			// Actual user is  the author of the picture ==>end
+			if ($this->check_img_user($page['current_item']))
+				return;
+			
+
+if ($this->debug)	echo "STEP2\n";
+			//------------
+			// Step 2
+			if ($concours != array())
+			{
+				// If user validate the notation
+				if (isset($_POST['concours_submit']))
+				{
+					$user_note = "";
+		if ($this->debug)			echo "SUBMIT";
+				// concat all the notes to save on db
+				
+					$firstcriterias = $this->get_firstlevel_criterias($concours['id']);
+					foreach ($firstcriterias as $criteria)
+					{
+						
+						// First without sub criterias
+						if (!$this->is_criterias_contains_sub($criteria['criteria_id'],$concours['id'] ))
+						{
+							// Check value 
+							$value = str_replace(",",".",$_POST[$criteria['criteria_id']]);
+							$value = str_replace(" ","",$value);
+							$value = floatval($value);
+							if ($value < floatval($criteria['min_value']))
+								$value = floatval($criteria['min_value']);
+							if ($value > floatval($criteria['max_value']))
+								$value = floatval($criteria['max_value']);
+
+							$user_note .= (strlen($user_note) != 0 ? ";" : "").$criteria['criteria_id']."=".$value;
+						}
+						else
+						{
+							$secondcriterias = $this->get_subcriterias($criteria['criteria_id'], $concours['id'] );
+							foreach ($secondcriterias as $subcriteria)
+							{
+								// Check value 
+								$value = str_replace(",",".",$_POST[$subcriteria['criteria_id']]);
+								$value = str_replace(" ","",$value);
+								$value = floatval($value);
+								if ($value < floatval($subcriteria['min_value']))
+									$value = floatval($subcriteria['min_value']);
+								if ($value > floatval($subcriteria['max_value']))
+									$value = floatval($subcriteria['max_value']);
+							
+								$user_note .= (strlen($user_note) != 0 ? ";" : "").$subcriteria['criteria_id']."=".$value;
+							}
+						}
+					}
+				
+//				$datas = "0=0";
+					$this->store_img_note_user($page['current_item'], $user_note, $concours['id']);
+if ($this->debug)	echo "COMMENT=".$_POST['CONCOURS_COMMENT'];
+					$this->store_img_comment_user($page['current_item'], $_POST['concours_comment'], $concours['id']);
+				}
+
+				// If user want to erase notes
+				if (isset($_POST['concours_raz']))
+				{
+if ($this->debug)			echo "RAZ";				
+					$this->RAZ_img_note_user($page['current_item'], $concours['id']);
+				}
+				else
+				{
+					// Recover previous note in DB (if exists)
+					$user_notes = $this->get_img_note_user($page['current_item'], $concours['id']);
+				}
+				
+				// Comment is not RAZ, always restore				
+				$comment = $this->get_img_comment_user($page['current_item'], $concours['id']);
+
+if ($this->debug)	echo "STEP3\n";
+				//------------
+				// Step 3
+				// Recover all 1st level criterias
+				$firstcriterias = $this->get_firstlevel_criterias($concours['id']);
+				foreach ($firstcriterias as $criteria)
+				{
+if ($this->debug)					echo "criteriaID=".$criteria['criteria_id']."\n";
+					// First without sub criterias
+					if (!$this->is_criterias_contains_sub($criteria['criteria_id'],$concours['id'] ))
+					{
+						$template->append( 'concours_criteria', array(
+								'nosub'	=> true,
+								'level'	=> 1,
+								'id' 	=> $criteria['criteria_id'],				// id du critere
+								'name' 	=> $criteria['name'],				// id du critere
+								'lib'	=> $criteria['descr'], //.'(min='$criteria['min_value'].';max='.$criteria['min_value'].')',			// libelle du critrer
+								'val'	=> (isset($user_notes[$criteria['criteria_id']])?$user_notes[$criteria['criteria_id']] : $criteria['min_value']),		//  valeur du critere
+								'min' 	=> $criteria['min_value'],				// min
+								'max' 	=> $criteria['max_value']				// max
+							));
+					}
+					else
+					{
+						$template->append( 'concours_criteria', array(
+								'nosub'	=> false,
+								'level'	=> 1,
+								'id' 	=> $criteria['criteria_id'],				// id du critere
+								'name' 	=> $criteria['name'],				// id du critere
+								'lib'	=> $criteria['descr']
+							));
+						$secondcriterias = $this->get_subcriterias($criteria['criteria_id'], $concours['id'] );
+						foreach ($secondcriterias as $subcriteria)
+						{
+if ($this->debug)							echo "subcriteriaID=".$criteria['criteria_id']."\n";
+							$template->append( 'concours_criteria', array(
+									'nosub'	=> true,
+									'level'	=> 2,
+									'id' 	=> $subcriteria['criteria_id'],				// id du critere
+									'name' 	=> $subcriteria['name'],				// id du critere
+									'lib'	=> $subcriteria['descr'], //.'(min='$criteria['min_value'].';max='.$criteria['min_value'].')',			// libelle du critrer
+									'val'	=> (isset($user_notes[$subcriteria['criteria_id']])?$user_notes[$subcriteria['criteria_id']] : $subcriteria['min_value']),
+									'min' 	=> $subcriteria['min_value'],				// min
+									'max' 	=> $subcriteria['max_value']				// max
+								));
+							
+						}
+					}
+
+				}
+				// Add the comment
+				$template->assign( 'CONCOURS_COMMENT', $comment);
+				
+				// Add concours informations on template
+				$template->assign( 'concours_infos', array(
+							'name'	=> $concours['name'],
+							'descr'	=> $concours['descr']
+								));
+				
+			
+				$template->set_filenames(array('concours' =>  CONCOURS_ROOT.'/template/concours.tpl'));
+//				$template->concat('PLUGIN_PICTURE_AFTER', $template->parse('concours', true));
+				$template->concat('COMMENT_IMG', $template->parse('concours', true));
+
+				// 
+				$template->assign('INFO_AUTHOR',l10n('concours_img_author'));
+			}
+		}
+	}
+
+	// RAZ notation from user to db
+	// fill criterias notes to 0 in DB
+	// return false if error
+	function RAZ_img_note_user($img_id, $concours_id = NULL)
+	{
+		$user_note = "";
+		if ($concours_id === null)
+			if ($this->concours_id !== null)
+				$concours_id = $this->concours_id;
+			else
+				return false;
+				
+		$firstcriterias = $this->get_firstlevel_criterias($concours_id);
+		foreach ($firstcriterias as $criteria)
+		{
+if ($this->debug)					echo "ID=".$criteria['criteria_id']."\n";
+			// First without sub criterias
+			if (!$this->is_criterias_contains_sub($criteria['criteria_id'],$concours_id ))
+			{
+				$user_note .= (strlen($user_note) != 0 ? ";" : "").$criteria['criteria_id']."=".$criteria['min_value'];
+			}
+			else
+			{
+				$secondcriterias = $this->get_subcriterias($criteria['criteria_id'], $concours_id );
+				foreach ($secondcriterias as $subcriteria)
+				{
+if ($this->debug)							echo "ID=".$criteria['criteria_id']."\n";
+					$user_note .= (strlen($user_note) != 0 ? ";" : "").$subcriteria['criteria_id']."=".$subcriteria['min_value'];
+				}
+			}
+		}
+if ($this->debug)	echo "RAZ=>".$user_note."\n";
+		if (strlen($user_note) != 0)
+		{
+			$this->store_img_note_user($img_id, $user_note, $concours_id);
+			return true;
+		}
+		else
+			return false;
+				
+
+	}
+
+	// Store notation from user to db
+	// save with format "criteria_id=note;criteria_id=note..." for data	
+	function store_img_note_user($img_id, $datas, $concours_id = NULL)
+	{
+		global $user;
+		if ($this->get_img_note_user( $img_id, $concours_id) == array())
+		{
+			$query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id  FROM ' . CONCOURS_DATA_TABLE . ' ;';
+			list($next_element_id) = mysql_fetch_array(pwg_query($query));
+if ($this->debug)	echo "Next_element=".$next_element_id."\n";
+			$query = '
+			INSERT INTO ' . CONCOURS_DATA_TABLE .'
+				(`id`,
+				`id_concours` ,
+				`user_id` ,
+				`create_date` ,
+				`img_id` ,
+				`datas` )
+			VALUES ( '.$next_element_id.','
+			.($concours_id !== null ? $concours_id : $this->concours_id ) .'
+			, '. $user['id'] .', now(), '.$img_id.', "'.$datas.'");';
+		}
+		else
+		{
+			$query = '
+			UPDATE ' . CONCOURS_DATA_TABLE .'
+			SET datas = "'.$datas.'", create_date = now()
+			WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id ).'
+			AND user_id = '.$user['id'].' 
+			AND img_id = '.$img_id.';';
+		}
+if ($this->debug) 			echo $query."\n";
+			pwg_query($query);
+	
+	}
+	
+	// get notation's user from db
+	// Return an array with :
+	// Criteria_id ==> value
+	// Note : criterias with subcriterias are not saved and not restored. They are calculated for global result
+	function get_img_note_user($img_id, $concours_id = NULL, $user_id = null)
+	{
+		global $user;
+		$img_note = array();
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+			$query = '
+			SELECT datas
+			FROM ' . CONCOURS_DATA_TABLE .' 
+			WHERE id_concours =' . ($concours_id !== NULL ? $concours_id : $this->concours_id) . '
+			AND user_id = '. ($user_id !== null ? $user_id : $user['id']).'
+			AND img_id = '. $img_id .'
+			';
+if ($this->debug) 			echo $query."\n";
+			$result = pwg_query($query);
+			
+			while ($row = mysql_fetch_assoc($result))
+			{
+if ($this->debug)				echo "row[data]=".$row['datas']."\n";
+				$datas = explode(";",$row['datas']);
+				foreach ($datas as $val)
+				{
+					if (strpos($val, '=') !== FALSE)
+						$img_note[substr($val, 0, strpos($val, '='))]=substr($val, strpos($val, '=')+1);
+				}
+			}
+// DEBUG
+if ($this->debug)
+foreach ($img_note as $id=>$val)
+{
+	if (is_array($val))
+		foreach ($val as $id2=>$val2)
+			echo "img_note[".$id."][".$id2."]=".$val2."\n";
+	else
+		echo "img_note[".$id."]=".$val."\n";
+}
+//  END DEBUG
+			
+			return $img_note;
+		}
+		else
+			return array();
+		
+		
+	}
+
+	
+	// get notation's user from db
+	// Return the global note for a picture id from a user
+	function get_img_globalnote_user($img_id, $concours_id = NULL, $user_id = null)
+	{
+		global $user;
+		$img_note = array();
+		$global_user_note = 0;
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+			$query = '
+			SELECT datas
+			FROM ' . CONCOURS_DATA_TABLE .' 
+			WHERE id_concours =' . ($concours_id !== NULL ? $concours_id : $this->concours_id) . '
+			AND user_id = '. ($user_id !== null ? $user_id : $user['id']).'
+			AND img_id = '. $img_id .'
+			';
+			$result = pwg_query($query);
+			
+			while ($row = mysql_fetch_assoc($result))
+			{
+				$datas = explode(";",$row['datas']);
+				foreach ($datas as $val)
+				{
+					if (strpos($val, '=') !== FALSE)
+						$img_note[substr($val, 0, strpos($val, '='))]=substr($val, strpos($val, '=')+1);
+				}
+			}
+			
+			$firstcriterias = $this->get_firstlevel_criterias($concours_id);
+			foreach ($firstcriterias as $criteria)
+			{
+if ($this->debug)					echo "criteriaID=".$criteria['criteria_id']."\n";
+				// First without sub criterias
+				if (!$this->is_criterias_contains_sub($criteria['criteria_id'],$concours_id ))
+				{
+					if (isset($img_note[$criteria['criteria_id']]))
+						$global_user_note += (int)$criteria['ponderation'] * (float)$img_note[$criteria['criteria_id']];
+				}
+				else
+				{
+
+					$secondcriterias = $this->get_subcriterias($criteria['criteria_id'], $concours_id );
+					foreach ($secondcriterias as $subcriteria)
+					{
+if ($this->debug)							echo "subcriteriaID=".$subcriteria['criteria_id']."\n";
+						if (isset($img_note[$subcriteria['criteria_id']]))
+						$global_user_note += (int)$subcriteria['ponderation'] * (float)$img_note[$subcriteria['criteria_id']];
+					}
+				}
+
+			}
+			
+			return $global_user_note;
+		}
+		else
+			return array();
+		
+		
+	}
+
+	// Store comment from user to db
+	function store_img_comment_user($img_id, $datas, $concours_id = NULL)
+	{
+		global $user;
+		if (($comment = $this->get_img_note_user( $img_id, $concours_id)) == false)
+		{
+			$query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id  FROM ' . CONCOURS_DATA_TABLE . ' ;';
+			list($next_element_id) = mysql_fetch_array(pwg_query($query));
+if ($this->debug)	echo "Next_element=".$next_element_id."\n";
+			$query = '
+			INSERT INTO ' . CONCOURS_DATA_TABLE .'
+				(`id`,
+				`id_concours` ,
+				`user_id` ,
+				`create_date` ,
+				`img_id` ,
+				`comment`)
+			VALUES ( '.$next_element_id.','
+			.($concours_id !== null ? $concours_id : $this->concours_id ) .'
+			, '. $user['id'] .', now(), '.$img_id.', "'.$datas.'");';
+		}
+		else
+		{
+			$query = '
+			UPDATE ' . CONCOURS_DATA_TABLE .'
+			SET comment = "'.$datas.'", create_date = now()
+			WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id ).'
+			AND user_id = '.$user['id'].' 
+			AND img_id = '.$img_id.';';
+		}
+if ($this->debug) 			echo $query."\n";
+			pwg_query($query);
+	
+	}
+	
+	
+	// Get comment on an image for a user
+	function get_img_comment_user($img_id, $concours_id = NULL, $user_id = null)
+	{
+		global $user;
+		$datas = false;
+		if ($concours_id!== null or $this->concours_id !== null)
+		{
+			$query = '
+			SELECT comment
+			FROM ' . CONCOURS_DATA_TABLE .' 
+			WHERE id_concours =' . ($concours_id !== NULL ? $concours_id : $this->concours_id) . '
+			AND user_id = '. ($user_id !== null ? $user_id : $user['id']).'
+			AND img_id = '. $img_id .'
+			';
+if ($this->debug) 			echo $query."\n";
+			$result = pwg_query($query);
+			
+			while ($row = mysql_fetch_assoc($result))
+			{
+if ($this->debug)				echo "row[comment]=".$row['comment']."\n";
+				$datas = $row['comment'];
+			}
+		}
+		return $datas;
+	}
+	
+	
+	// Generate csv file for a closed concours with result generated
+	function generate_csv($concours_id = NULL)
+	{
+		$file = "rang, id_concours, img_id, img_name, img_file, date, note, datas\r\n";
+
+		// recover all img_id from the category
+		$query = 'SELECT id_concours, img_id, IMG.name, IMG.file, date, note, datas'
+		.' FROM ' .CONCOURS_RESULT_TABLE
+		.' INNER JOIN ' . IMAGES_TABLE.' AS IMG on IMG.id = img_id'
+		.' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id )
+		.' ORDER BY note DESC'
+		.';';
+		
+		$result = pwg_query($query);
+		// For each images
+		$rang = 1;
+		while ($row = mysql_fetch_assoc($result))
+		{
+			$file .= $rang.', '
+					.$row['id_concours'].', '
+					.$row['img_id'].', '
+					.$row['name'].', '
+					.$row['file'].', '
+					.$row['date'].', '
+					.$row['note'].', '
+					.($row['datas'] != null ? $row['datas'] : '')
+					."\r\n";
+			$rang ++;
+		}
+				
+		return $file;
+	
+		
+	}
+
+	// Generate csv file for a closed concours with result generated and all users informations 
+	function generate_detail_csv($concours_id = NULL)
+	{
+		if ($concours_id === null)
+			$concours_id = $this->concours_id;
+		// Prepare the list of criteria
+		$criteria_list = "";
+		$firstcriterias = $this->get_firstlevel_criterias($concours_id);
+		$ident1 = 1;
+		foreach ($firstcriterias as $criteria)
+		{
+			// format (id:name)
+			$criteria_list .= (strlen($criteria_list) ? "," : "")
+								.$ident1.":".$criteria['name']
+								."(id=".$criteria['criteria_id'].")";
+			// First wit sub criterias
+			if ($this->is_criterias_contains_sub($criteria['criteria_id'],$concours_id ))
+			{
+				$ident2 = 1;
+				$secondcriterias = $this->get_subcriterias($criteria['criteria_id'], $concours_id );
+				foreach ($secondcriterias as $subcriteria)
+				{
+					// format (id:name)
+					$criteria_list .= (strlen($criteria_list) ? "," : "")
+									  .$ident1.".".$ident2
+									  .":".$subcriteria['name']."(id=".$subcriteria['criteria_id'].")";
+					$ident2 ++;
+				}
+			}
+			$ident1++;
+		}
+if ($this->debug)	echo "CRITERIA_LIST=".$criteria_list."\n";	
+		$user_list = array();
+		$users_criteria = "";
+		// Get all the users who have notes for the concours
+		$query = 'SELECT distinct(user_id), USER.username'
+		.' FROM ' .CONCOURS_DATA_TABLE
+		.' INNER JOIN ' . USERS_TABLE.' AS USER on USER.id = user_id'
+		.' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id )
+		.' ORDER BY username ASC'
+		.';';
+		$result = pwg_query($query);
+		// For each user
+		while ($row = mysql_fetch_assoc($result))
+		{
+			array_push($user_list, $row);
+			$users_criteria .= (strlen($users_criteria) ? "," : "")."user, user_global_note, comment, ".$criteria_list;
+			
+		}
+
+if ($this->debug)	echo "users_criteria=".$users_criteria."\n";	
+		
+		// All informations in csv format
+		$file = "rang, id_concours, nom_concours, date_debut, date_fin, date_export, img_id, img_name, img_file, img_author, note, nbvotant, datas,"
+		.$users_criteria 
+		."\r\n";
+
+		// nb of users who vote for each image
+		$query = 'SELECT img_id, COUNT(DISTINCT user_id) AS NBVOTE FROM ' . CONCOURS_DATA_TABLE 
+		.' GROUP BY img_id '
+		.';';
+				
+		$result = pwg_query($query);
+//		echo $query;
+		$nbvotes = array();
+		while ($row = mysql_fetch_assoc($result))
+		{
+			$nbvotes[$row['img_id']] = $row['NBVOTE'];
+		}
+/*		
+		foreach ($nbvotes as $id=>$val)
+		{
+			echo "Vote img(".$id.")=".$val."\n";
+		}
+*/		
+		// recover all img_id from the category
+		$query = 'SELECT id_concours, img_id, IMG.name, IMG.file, IMG.author, date, note, datas, comment'
+		.' FROM ' .CONCOURS_RESULT_TABLE
+		.' INNER JOIN ' . IMAGES_TABLE.' AS IMG on IMG.id = img_id'
+		.' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id )
+		.' ORDER BY note DESC'
+		.';';
+		
+		$result = pwg_query($query);
+//		echo $query;
+		// For each images
+		$rang = 1;
+		while ($row = mysql_fetch_assoc($result))
+		{
+			$file .= $rang.', '
+					.$row['id_concours'].', '
+					.str_replace(",", "",$this->concours_infos['name']).', '
+					.$this->concours_infos['begin_date'].', '
+					.$this->concours_infos['end_date'].', '
+					.$row['date'].', '
+
+					.$row['img_id'].', '
+					.str_replace(",", "",$row['name']).', '
+					.$row['file'].', '
+					.$row['author'].', '
+					.$row['note'].', '
+					.(isset($nbvotes[$row['img_id']]) ? $nbvotes[$row['img_id']] : 0).', '
+					.($row['datas'] != null ? $row['datas'] : '')
+					;
+			foreach ($user_list as $uuser)
+			{
+				
+				$user_note = $this->get_img_note_user($row['img_id'], $concours_id, $uuser['user_id']);
+				
+				$file .= ', '.$uuser['username'].', '.$this->get_img_globalnote_user($row['img_id'], $concours_id, $uuser['user_id'])
+						.', '.($row['comment'] != null ? str_replace(",", "",$row['comment']) : '')
+						.', '
+						;
+
+				$user_note_by_crit = "";
+				foreach ($firstcriterias as $criteria)
+				{
+					// First without sub criterias
+					if (!$this->is_criterias_contains_sub($criteria['criteria_id'],$concours_id ))
+					{
+						$user_note_by_crit .= (strlen($user_note_by_crit) ? "," : "").(isset($user_note[$criteria['criteria_id']]) ? $user_note[$criteria['criteria_id']] : ' ');
+					}
+					else
+					{
+						$user_note_by_subcrit = "";
+						$subcrit_note = 0;
+						$user_has_vote = false;
+						$secondcriterias = $this->get_subcriterias($criteria['criteria_id'], $concours_id );
+						foreach ($secondcriterias as $subcriteria)
+						{
+							if (isset($user_note[$subcriteria['criteria_id']]))		$user_has_vote = true;
+							$user_note_by_subcrit .= (strlen($user_note_by_subcrit) ? "," : "").(isset($user_note[$subcriteria['criteria_id']]) ? $user_note[$subcriteria['criteria_id']] : ' ');
+							$subcrit_note += (int)$subcriteria['ponderation'] * (float)(isset($user_note[$subcriteria['criteria_id']]) ? $user_note[$subcriteria['criteria_id']] : 0);
+
+						}
+						$user_note_by_crit .= (strlen($user_note_by_crit) ? "," : "").($user_has_vote ? $subcrit_note : ' ').",".$user_note_by_subcrit;
+					}
+				}
+				$file .= $user_note_by_crit;
+
+			}
+
+			$file .="\r\n";
+			$rang ++;
+		}
+//		echo $file;
+		return $file;
+	
+		
+	}
+	
+	
+	
+	// Save csv datas to physical file
+	function save_file($file,$concours_id = NULL)
+	{
+		// check if already saved file
+		if ($filename = $this->get_file_name($concours_id))
+			return $filename;
+		else
+		{
+			$dirpath = CONCOURS_RESULT_FOLDER;
+
+			$filename = date('Ymd')."_concours".($concours_id !== null ? $concours_id : $this->concours_id ).".csv";
+			if (!is_dir($dirpath)) 
+				@mkdir($dirpath);
+			if (file_exists($dirpath. $filename))
+				unlink($dirpath. $filename);
+
+			$fh = fopen($dirpath. $filename, 'w') or die("can't open file");
+			fwrite($fh, $file);
+			fclose($fh);
+
+			//update result database with filename
+			$query = "UPDATE " . CONCOURS_RESULT_TABLE . "
+						SET 
+						file_name = \"".$filename."\"
+						WHERE id_concours= ".($concours_id !== NULL ? $concours_id : $this->concours_id)."
+						;";
+			pwg_query($query);
+	//		echo $query;
+			
+			return $filename;
+		}
+	}		
+
+	// Get result file name from db
+	function get_file_name($concours_id = NULL)
+	{
+		$query = 'SELECT distinct(file_name)'
+		.' FROM ' .CONCOURS_RESULT_TABLE
+		.' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id )
+		.';';
+		$row = mysql_fetch_assoc(pwg_query($query));
+		if ($row)
+			return $row['file_name'];
+		else
+			return false;
+	
+	}
+
+	// Get csv datas from a saved file
+	function get_file($concours_id = NULL)
+	{
+		$filename = CONCOURS_RESULT_FOLDER.
+		$size = filesize($filename);
+		header('Content-Type: application/octet-stream');
+		header('Content-Length: '.$size);
+		header('Content-Disposition: attachment; filename='.$filename);
+		header('Content-Transfer-Encoding: binary');
+
+		$file = @fopen($filename, ‘rb’);
+		if ($file) {
+			// stream the file and exit the script when complete
+			fpassthru($file);
+		}
+	
+	}
+	
+	// Activation page administration
+	function concours_admin_menu($menu)
+	{
+	    array_push($menu,
+	       array(
+	            'NAME' => CONCOURS_NAME,
+	            'URL' => get_admin_plugin_menu_link(CONCOURS_ADMIN_PATH.'admin.php')
+	        ) 
+	    );
+	    return $menu;
+	}
+	
+	// register Concours Menubar
+	public function register_blocks( $menu_ref_arr )
+	{
+	$menu = & $menu_ref_arr[0];
+	if ($menu->get_id() != 'menubar' OR $this->my_config['active_menubar'] == false)
+	  return;
+	$menu->register_block( new RegisteredBlock( 'CONCOURS_menu', 'Polls', 'MYPOLLS'));
+	}
+
+  /*
+    initialise menubar's menu
+    called by menubar object when making menu
+  */
+	public function blockmanager_apply( $menu_ref_arr )
+	{
+  
+		global $user, $template;
+		$menu = & $menu_ref_arr[0];
+
+		if ($this->user_groups == array())
+			$this->get_user_groups();
+		
+		if ( ($block = $menu->get_block( 'CONCOURS_menu' ) ) != null )
+		{
+		  if($user['id']==2)
+		  {
+			$vote_id = $_SERVER['REMOTE_ADDR'];
+		  }
+		  else
+		  {
+			$vote_id = $user['id'];
+		  }
+
+	//      $polls_list=$this->get_polls_list($vote_id, is_admin(), $user['language']);
+		  $menu_list=array();
+
+		  if(is_admin())
+		  {
+			array_push($menu_list,
+			  array(
+				'nfo' => "",
+				'text' => l10n('concours_admin_add'),
+				'link' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;action=new',
+				'edit' => ""
+			  )
+			);
+		  }
+
+			// recover all img_id from the category
+			$query = 'SELECT distinct(id_concours), groups, CONC.name'
+			.' FROM ' .CONCOURS_RESULT_TABLE
+			.' INNER JOIN '.CONCOURS_TABLE. ' AS CONC ON CONC.id = id_concours'
+			.' ORDER BY date DESC'
+			.';';
+			
+			$result = pwg_query($query);
+			$nb_concours = 1;
+			// For each concours
+			while ($row = mysql_fetch_assoc($result))
+			{
+				
+				if ($nb_concours > $this->my_config['nbconcours_menubar'])
+					break;
+					
+				if (!empty($row['groups']))
+				{
+					$authorized_groups = explode(',', $row['groups']);
+					if (array_intersect($this->user_groups, $authorized_groups) == array()) 
+					{
+						continue;
+					}
+					$nb_concours ++;
+					array_push($menu_list,
+					  array(
+						'nfo' => "",
+						'text' => $row['name'],
+	//					'link' => CONCOURS_PATH.'publish.php?id='.$row['id_concours'],
+						'link' => './index.php?/concours/'.$row['id_concours'],
+						'edit' => (is_admin()? PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;concours=' . $row['id_concours'].'&amp;action=modify':"")
+					  )
+					);
+				}
+			}
+
+		  if (count($menu_list))
+		  {
+
+			  $block->set_title("Concours Photo");
+			  $block->template = CONCOURS_ROOT.'/template/concours_menu.tpl';
+			  $block->data = $menu_list;
+		  }
+		}
+	}
+
+	
+	function section_init_concours()
+	{
+		global $tokens, $page;
+		if ($tokens[0] == 'concours')
+		  $page['section'] = 'concours';
+	}
+	
+	function index_concours()
+	{
+		global $page;
+		
+		if (isset($page['section']) and $page['section'] == 'concours')
+		{
+			include(CONCOURS_PATH . 'publish.php');
+		}
+	}
+
+	
+}
+
+?>
Index: /extensions/ConcoursPhoto/include/default_values.inc.php
===================================================================
--- /extensions/ConcoursPhoto/include/default_values.inc.php	(revision 3905)
+++ /extensions/ConcoursPhoto/include/default_values.inc.php	(revision 3905)
@@ -0,0 +1,10 @@
+<?php
+/*
+ * Plugin Name: ConcoursPhoto
+ * File :  default_values.inc.php  
+ */
+
+$concours_default_values['active_menubar'] = true; // Activate menubar view
+$concours_default_values['nbconcours_menubar'] = 3;	// Nb of last published concours show on concours menubar
+
+?>
Index: /extensions/ConcoursPhoto/include/index.php
===================================================================
--- /extensions/ConcoursPhoto/include/index.php	(revision 3905)
+++ /extensions/ConcoursPhoto/include/index.php	(revision 3905)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/ConcoursPhoto/index.php
===================================================================
--- /extensions/ConcoursPhoto/index.php	(revision 3905)
+++ /extensions/ConcoursPhoto/index.php	(revision 3905)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/ConcoursPhoto/language/en_UK/description.txt
===================================================================
--- /extensions/ConcoursPhoto/language/en_UK/description.txt	(revision 3905)
+++ /extensions/ConcoursPhoto/language/en_UK/description.txt	(revision 3905)
@@ -0,0 +1,1 @@
+Create photo competition with specifics criterias on Piwigo gallery
Index: /extensions/ConcoursPhoto/language/en_UK/index.php
===================================================================
--- /extensions/ConcoursPhoto/language/en_UK/index.php	(revision 3905)
+++ /extensions/ConcoursPhoto/language/en_UK/index.php	(revision 3905)
@@ -0,0 +1,33 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery                           |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | file          : $Id: index.php 1912 2007-03-16 06:30:07Z rub $
+// | last update   : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $
+// | last modifier : $Author: rub $
+// | revision      : $Revision: 1912 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/ConcoursPhoto/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/ConcoursPhoto/language/en_UK/plugin.lang.php	(revision 3905)
+++ /extensions/ConcoursPhoto/language/en_UK/plugin.lang.php	(revision 3905)
@@ -0,0 +1,11 @@
+<?php
+/*
+ * Plugin Name: ConcoursPhoto
+ * File :  plugin.lang.php
+* Lang : EN 
+ */
+
+// Piclenslite button
+//$lang['']	 				= '';
+
+?>
Index: /extensions/ConcoursPhoto/language/fr_FR/description.txt
===================================================================
--- /extensions/ConcoursPhoto/language/fr_FR/description.txt	(revision 3905)
+++ /extensions/ConcoursPhoto/language/fr_FR/description.txt	(revision 3905)
@@ -0,0 +1,1 @@
+Création de concours photos avec critères sur les catégories de la galerie Piwigo
Index: /extensions/ConcoursPhoto/language/fr_FR/index.php
===================================================================
--- /extensions/ConcoursPhoto/language/fr_FR/index.php	(revision 3905)
+++ /extensions/ConcoursPhoto/language/fr_FR/index.php	(revision 3905)
@@ -0,0 +1,33 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery                           |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | file          : $Id: index.php 1912 2007-03-16 06:30:07Z rub $
+// | last update   : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $
+// | last modifier : $Author: rub $
+// | revision      : $Revision: 1912 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/ConcoursPhoto/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/ConcoursPhoto/language/fr_FR/plugin.lang.php	(revision 3905)
+++ /extensions/ConcoursPhoto/language/fr_FR/plugin.lang.php	(revision 3905)
@@ -0,0 +1,65 @@
+<?php
+/*
+ * Plugin Name: ConcoursPhoto
+ * File :  plugin.lang.php
+* Lang : FR 
+ */
+
+
+$lang['concours_save']	 				= 'Sauvegarder';
+$lang['concours_RAZ']	 				= 'Réinitialiser';
+$lang['concours_admin_edit']	 				= 'Edit';
+$lang['concours_result']	 				= 'Résultat du concours';
+$lang['concours_add']	 				= 'Ajouter un concours';
+$lang['concours_id']	 				= 'Identifiant';
+$lang['concours_name']	 				= 'Nom';
+$lang['concours_descr']	 				= 'Description';
+$lang['concours_activation_date']	 				= 'Période du concours';
+$lang['concours_nb_jours']	 				= 'Pendant';
+$lang['jours']	 				= 'Jours';
+$lang['concours_category_select']	 				= 'Catégorie sélectionnée';
+$lang['concours_authorized_group']	 				= 'Groupes authorisés';
+$lang['concours_begin_date']	 				= 'Date de début';
+$lang['concours_end_date']	 				= 'Date de fin';
+$lang['concours_criterias']	 				= 'Critères du concours';
+$lang['concours_min_value']	 				= 'Valeur minimale';
+$lang['concours_max_value']	 				= 'Valeur maximale';
+$lang['concours_coef']	 				= 'Coefficient';
+$lang['criteria_edit']	 				= 'Editer le critère';
+$lang['criteria_delete']	 				= 'Supprimer le critère';
+$lang['criteria_add']	 				= 'Ajouter un critère';
+$lang['subcriteria_add']	 				= 'Ajouter un sous-critère';
+$lang['concours_actions']	 				= 'Actions';
+$lang['concours_admin_title']	 				= 'Administration du plugin Concours Photo';
+$lang['default_criteria']	 				= 'Gestion des critères par défaut';
+$lang['concours_add_criteria']	 				= 'Ajouter un nouveau critère';
+$lang['concours_criteria_submit']	 				= 'Valider le critère';
+$lang['manage_concours']	 				= 'Gestion des concours';
+$lang['prepared_concours']	 				= 'Concours préparés non actifs';
+$lang['active_concours']	 				= 'Concours actifs en cours';
+$lang['closed_concours']	 				= 'Concours terminés';
+$lang['concours_result']	 				= 'Générer le résultat';
+$lang['concours_file']	 				= 'Télécharger le fichier résultat';
+$lang['concours_create_date']	 				= 'Date de création';
+$lang['concours_management']	 				= 'Gérer les concours';
+$lang['concours_edit']	 				= 'Editer le concours';
+$lang['concours_delete']	 				= 'Supprimer le concours';
+$lang['concours_add']	 				= 'Ajouter un  concours';
+$lang['concours_config']	 				= 'Critères par défaut';
+$lang['concours_admin_add'] = $lang['concours_add'];
+$lang['concours_comment']			= 'Appréciation/Commentaire/Remarque sur la photo';
+$lang['concours_result_page']		= 'Résultat du concours';
+$lang['concours_img_author']		= 'Masqué pour le concours';
+$lang['concours_1st']				= 'er';
+$lang['concours_2nd']				= 'ème';
+$lang['concours_3rd']				= 'ème';
+$lang['concours_4th']				= 'ème';
+$lang['concours_submit']			= 'Valider';
+$lang['concours_params']			= 'Paramètres généraux';
+$lang['concours_show_menubar']			= 'Affichage du menu "Résultat des concours"';
+$lang['concours_nb_concours_menubar']			= 'Nombre de résultats à afficher';
+$lang['concours_result_files']			= 'Fichiers générés de résultat';
+$lang['concours_result_file_list']			= 'Liste des fichiers de résultat pouvant être téléchargés (même si le concours a été supprimé)';
+$lang['concours_no_result_file']			= 'Aucun fichier généré présent';
+
+?>
Index: /extensions/ConcoursPhoto/language/index.php
===================================================================
--- /extensions/ConcoursPhoto/language/index.php	(revision 3905)
+++ /extensions/ConcoursPhoto/language/index.php	(revision 3905)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/ConcoursPhoto/main.inc.php
===================================================================
--- /extensions/ConcoursPhoto/main.inc.php	(revision 3905)
+++ /extensions/ConcoursPhoto/main.inc.php	(revision 3905)
@@ -0,0 +1,63 @@
+<?php
+/*
+ * Plugin Name: ConcoursPhoto
+ * Version: 0.0.1
+ * Description: Concours de photo : notation sur critères
+ * Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
+ * Author: Tiico
+ * Author URI: 
+ * */
+/********* Fichier main.inc.php  *********/
+
+/* See CHANGELOG for release informations */
+
+ 
+if (!defined('PHPWG_ROOT_PATH'))  die('Hacking attempt!');
+
+global $prefixeTable;
+
+define('CONCOURS_NAME', 'Concours Photo');
+define('CONCOURS_ROOT', dirname(__FILE__));
+define('CONCOURS_DIR' , basename(dirname(__FILE__)));
+define('CONCOURS_CFG_FILE' , CONCOURS_ROOT.'/'.CONCOURS_DIR.'.dat');
+define('CONCOURS_CFG_FILE1' , PHPWG_PLUGINS_PATH.CONCOURS_DIR.'.dat');
+define('CONCOURS_CFG_DB' , CONCOURS_DIR);
+define('CONCOURS_PATH' , PHPWG_PLUGINS_PATH . CONCOURS_DIR . '/');
+define('CONCOURS_INC_PATH' , PHPWG_PLUGINS_PATH . CONCOURS_DIR . '/include/');
+define('CONCOURS_IMG_PATH' , PHPWG_PLUGINS_PATH . CONCOURS_DIR . '/img/');
+define('CONCOURS_ADMIN_PATH' , PHPWG_PLUGINS_PATH . CONCOURS_DIR . '/admin/');
+define('CONCOURS_RESULT_FOLDER' , PHPWG_PLUGINS_PATH . CONCOURS_DIR . '/result/');
+
+
+define('CONCOURS_TABLE' , $prefixeTable . 'concours');
+define('CONCOURS_DETAIL_TABLE' , $prefixeTable . 'concours_detail');
+define('CONCOURS_DATA_TABLE' , $prefixeTable . 'concours_data');
+define('CONCOURS_RESULT_TABLE' , $prefixeTable . 'concours_result');
+
+
+
+load_language('plugin.lang', CONCOURS_PATH);
+
+include_once CONCOURS_INC_PATH.'Concours.class.php';
+global $page, $template;
+
+
+$concours = new Concours();
+
+// Add concours to picture page
+add_event_handler('loc_end_picture', array(&$concours, 'display_concours_to_picture')); 
+// Add admin page
+add_event_handler('get_admin_plugin_menu_links', array(&$concours, 'concours_admin_menu') );
+
+// MenuBar 
+add_event_handler('blockmanager_register_blocks', array(&$concours, 'register_blocks') );
+add_event_handler('blockmanager_apply', array(&$concours, 'blockmanager_apply') );
+
+add_event_handler('loc_end_section_init', array(&$concours, 'section_init_concours'));
+
+add_event_handler('loc_end_index', array(&$concours, 'index_concours'));
+
+
+set_plugin_data($plugin['id'], $concours)
+
+?>
Index: /extensions/ConcoursPhoto/maintain.inc.php
===================================================================
--- /extensions/ConcoursPhoto/maintain.inc.php	(revision 3905)
+++ /extensions/ConcoursPhoto/maintain.inc.php	(revision 3905)
@@ -0,0 +1,207 @@
+<?php
+/*
+ * Plugin Name: ConcoursPhoto
+ * File :  maintain.inc.php  
+ */
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+
+function plugin_install()
+{
+	global $prefixeTable, $conf;
+
+	$query = 'SHOW TABLES LIKE "' . $prefixeTable . 'concours"';
+	$result = pwg_query($query);
+	if (!mysql_fetch_row($result))
+	{
+	// Concours description
+		$q = 'CREATE TABLE `' . $prefixeTable . 'concours` (
+				`id` smallint(5) NOT NULL,
+				`create_date` datetime NOT NULL,
+				`name` text NOT NULL,
+				`descr` varchar(255) default NULL,
+				`begin_date` datetime NOT NULL,
+				`end_date` datetime NOT NULL,
+				`category` smallint(5) default NULL,
+				`groups` varchar(255) default NULL,
+				
+				PRIMARY KEY  (`id`)
+				) DEFAULT CHARSET=utf8;';
+		pwg_query($q);
+
+	// Concours description detail (criterias)
+		$q = 'CREATE TABLE `' . $prefixeTable . 'concours_detail` (
+				`id` smallint(5) NOT NULL,
+				`id_concours` smallint(5) NOT NULL,
+				`criteria_id` smallint(5) NOT NULL,
+				`name` text NOT NULL,
+				`descr` varchar(255) default NULL,
+				`min_value` int default 0,
+				`max_value` int default 0,
+				`ponderation` int default 1,
+				`uppercriteria` smallint(5) default NULL,
+				
+				PRIMARY KEY  (`id`),
+				FOREIGN KEY (`id_concours`) REFERENCES ' . $prefixeTable . 'concours(id)
+				) DEFAULT CHARSET=utf8;';
+		pwg_query($q);
+
+
+	// Concours notation (by users)
+		$q = 'CREATE TABLE `' . $prefixeTable . 'concours_data` (
+				`id` smallint(5) NOT NULL,
+				`id_concours` smallint(5) NOT NULL,
+				`user_id` smallint(5) NOT NULL,
+				`create_date` datetime NOT NULL,
+				`img_id` smallint(5) NOT NULL,
+				`datas` longtext default NULL,
+				`comment` longtext default NULL,				
+				PRIMARY KEY  (`id`)
+				) DEFAULT CHARSET=utf8;';
+		pwg_query($q);
+		
+	// Concours result (synthesis)
+		$q = 'CREATE TABLE `' . $prefixeTable . 'concours_result` (
+				`id_concours` smallint(5) NOT NULL,
+				`img_id` smallint(5) NOT NULL,
+				`date` datetime NOT NULL,
+				`note` float default 0,
+				`datas` longtext default NULL,
+				`file_name` longtext default NULL,
+				PRIMARY KEY  (`img_id`),
+				FOREIGN KEY (`id_concours`) REFERENCES ' . $prefixeTable . 'concours(id)				
+				) DEFAULT CHARSET=utf8;';
+		pwg_query($q);
+		
+	// Default values  insertion
+    $q = "INSERT INTO `" . $prefixeTable . "concours` 
+				( `id`,
+				`create_date`, 
+				`name`, 
+				`descr`, 
+				`begin_date`, 
+				`end_date`, 
+				`category`, 
+				`groups`)
+			VALUES (0, now(), 'Default', 'default values', now(), now(), NULL, NULL);";
+    pwg_query($q);
+
+    // Default values for criterias (concours_id=0)
+    $q = "INSERT INTO `" . $prefixeTable . "concours_detail` 
+				(`id`,
+				`id_concours` , 
+				`criteria_id` , 
+				`name`, 
+				`descr`, 
+				`min_value`, 
+				`max_value`, 
+				`ponderation` ,
+				`uppercriteria`)
+			VALUES (1, 0, 1, 'Artistique', 'Artistique', 0, 10, 1, NULL),
+			 (2, 0, 2, 'Respect du sujet', 'Sujet en rapport avec le theme', 0, 1, 1, 1),
+			 (3, 0, 3, 'Sujet bien identifié', 'Sans ambiguite', 0, 2, 1, 1),
+			 (4, 0, 4, 'Traitement du sujet', 'Expression/Attitude/mouvement', 0, 2, 1, 1),
+			 (5, 0, 5, 'Mise en valeur du sujet', 'Cadrage/Harmonie de la composition/Esthetique de l\'image/Choix de l\'eclairage', 0, 5, 1, 1),
+
+			 (6, 0, 6, 'Technique', 'Technique', 0, 6, 1, NULL),
+			 (7, 0, 7, 'Nettete de l\'image', 'Etagement des plans/Pique de l\'image', 0, 3, 1, 6),
+			 (8, 0, 8, 'Rendu des couleurs (ou gris)', 'Teintes/Staurations', 0, 1, 1, 6),
+			 (9, 0, 9, 'Exposition', 'Equilibre hautes/basses lumieres', 0, 2, 1, 6),
+
+			 (10, 0, 10, 'Coup de coeur', 'coup de coeur', 0, 4, 1, NULL),
+			 (11, 0, 11, 'Emotion spontanee', 'emotion spontanee', 0, 2, 1, 10),
+			 (12, 0, 12, 'Adhesion au choix artistique', 'Adhesion au choix artistique', 0, 2, 1, 10);";
+			 
+    pwg_query($q);
+
+    $q = '
+    INSERT INTO '.CONFIG_TABLE.' (param,value,comment)
+    VALUES ("concoursphoto","","Configuration Concours Photo")
+    ;';
+
+    pwg_query($q);
+    
+    
+/*	
+	// TEST INSERTION INTO DB (Goupe test =1)
+    $q = "INSERT INTO `" . $prefixeTable . "concours` 
+				( `id`,
+				`create_date`, 
+				`name`, 
+				`descr`, 
+				`begin_date`, 
+				`end_date`, 
+				`category`, 
+				`groups`)
+			VALUES (1, now(), 'Test', 'Test Concours', now(), '2019-09-02 18:08:00', 2, 1);";
+    pwg_query($q);
+	
+    $q = "INSERT INTO `" . $prefixeTable . "concours_data` 
+				(`id` ,
+				`id_concours` ,
+				`user_id` ,
+				`create_date` ,
+				`img_id` ,
+				`datas` )
+			VALUES (1, 1, 3, now(), 54, \"2=1;3=1;4=2;5=3;7=1;8=0;9=0,5;11=1,5;12=2\");";
+    pwg_query($q);
+    $q = "INSERT INTO `" . $prefixeTable . "concours_detail` 
+				(`id`,
+				`id_concours` , 
+				`criteria_id` , 
+				`name`, 
+				`descr`, 
+				`min_value`, 
+				`max_value`, 
+				`ponderation` ,
+				`uppercriteria`)
+			VALUES (13, 1, 1, 'Artistique', 'Artistique', 0, 10, 1, NULL),
+			 (14, 1, 2, 'Respect du sujet', 'Sujet en rapport avec le theme', 0, 1, 1, 1),
+			 (15, 1, 3, 'Sujet bien identifié', 'Sans ambiguite', 0, 2, 1, 1),
+			 (16, 1, 4, 'Traitement du sujet', 'Expression/Attitude/mouvement', 0, 2, 1, 1),
+			 (17, 1, 5, 'Mise en valeur du sujet', 'Cadrage/Harmonie de la composition/Esthetique de l\'image/Choix de l\'eclairage', 0, 5, 1, 1),
+
+			 (18, 1, 6, 'Technique', 'Technique', 0, 6, 1, NULL),
+			 (19, 1, 7, 'Nettete de l\'image', 'Etagement des plans/Pique de l\'image', 0, 3, 1, 6),
+			 (20, 1, 8, 'Rendu des couleurs (ou gris)', 'Teintes/Staurations', 0, 1, 1, 6),
+			 (21, 1, 9, 'Exposition', 'Equilibre hautes/basses lumieres', 0, 2, 1, 6),
+
+			 (22, 1, 10, 'Coup de coeur', 'coup de coeur', 0, 4, 1, NULL),
+			 (23, 1, 11, 'Emotion spontanee', 'emotion spontanee', 0, 2, 1, 10),
+			 (24, 1, 12, 'Adhesion au choix artistique', 'Adhesion au choix artistique', 0, 2, 1, 10);";
+			 
+    pwg_query($q);
+	// END TEST INSERTION 
+*/
+	
+	}
+
+}
+
+function plugin_activate()
+{
+  global $prefixeTable;
+
+}
+
+function plugin_uninstall()
+{
+    global $prefixeTable;
+
+	$q = 'DROP TABLE ' . $prefixeTable . 'concours, 
+	' . $prefixeTable . 'concours_detail, 
+	' . $prefixeTable . 'concours_data,
+	' . $prefixeTable . 'concours_result	;';
+    pwg_query($q);
+
+    $q = '
+      DELETE FROM '.CONFIG_TABLE.'
+      WHERE param="concoursphoto" LIMIT 1
+    ;';
+    pwg_query($q);
+
+}
+
+
+?>
Index: /extensions/ConcoursPhoto/publish.php
===================================================================
--- /extensions/ConcoursPhoto/publish.php	(revision 3905)
+++ /extensions/ConcoursPhoto/publish.php	(revision 3905)
@@ -0,0 +1,92 @@
+<?php
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+global $template;
+
+// Publish the result on a global page.
+// Mode global ==> simply display global result
+// Mode full ==> display global result and user notations
+
+$ap_id = explode('concours/' , $_SERVER['REQUEST_URI']);
+$id_concours = $ap_id[1];
+
+$concours = new Concours($id_concours);
+
+$category = $concours->concours_infos['category'];
+
+$query = 'SELECT DISTINCT(img.id), img.name, img.file, img.path, img.tn_ext, 
+		  ic.category_id, cat.name AS catname, conc.note'
+		.' FROM ' . IMAGES_TABLE.' AS img'
+		.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON img.id = ic.image_id'
+		.' INNER JOIN '.CATEGORIES_TABLE.' AS cat ON ic.category_id = cat.id'
+		.' INNER JOIN '.CONCOURS_RESULT_TABLE.' AS conc ON conc.img_id = img.id'
+		.' WHERE ic.category_id = '.$concours->concours_infos['category']
+		.' ORDER by note DESC;';
+$result = pwg_query($query);
+$rang = 1;
+while ($row = mysql_fetch_assoc($result))
+{
+	// link on picture.php page
+	set_make_full_url();
+	if ( isset($row['category_id']) & isset($row['catname']) ) 
+	{
+		$url = duplicate_picture_url(
+		array(
+		'image_id' => $row['id'],
+		'image_file' => $row['file'],
+		'category' => array(
+						'id' => $row['category_id'],
+						'name' => $row['catname'],
+						'permalink' => ''
+					  )
+		),
+		array('start')
+		);
+	}
+	else
+	{
+		$url = duplicate_picture_url(
+		  array(
+			'image_id' => $row['id'],
+			'image_file' => $row['file']
+		  ),
+		  array('start')
+		);
+	}	
+	unset_make_full_url();
+
+	$template->append( 'concours_note', array(
+			'img_id' => $row['id'],
+			'name'	=> $row['name'],
+			'file'	=> $row['file'],
+			'rang'	=> $rang,
+			'thumb'	=> get_thumbnail_url($row),
+			'url'	=> $url,
+			'note' 	=> ($row['note'] == 0 ? 'N/A' :$row['note'])
+		));
+	$rang ++;
+
+}
+// Envoi de la page
+$template->assign(array(
+  'TITLE' => "Concours : ".$concours->concours_infos['name']));
+
+$template->assign('IMG_URL', CONCOURS_IMG_PATH);
+
+$template->set_filenames(array('concours_result' =>  CONCOURS_ROOT.'/template/result.tpl'));
+$template->concat('PLUGIN_INDEX_CONTENT_BEGIN', $template->parse('concours_result', true));
+  
+  
+  $template->assign('PLUGIN_INDEX_ACTIONS' , '
+    <li><a href="' . make_index_url() . '" title="' . l10n('return to homepage') . '">
+      <img src="' . $template->get_themeconf('icon_dir') . '/home.png" class="button" alt="' . l10n('home') . '"/></a>
+    </li>');
+
+if (is_admin())
+{
+  $template->assign('U_EDIT', PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;concours=' . $id_concours.'&amp;action=edit');
+}
+
+$template->clear_assign(array('U_MODE_POSTED', 'U_MODE_CREATED'));
+
+?>
Index: /extensions/ConcoursPhoto/result/index.php
===================================================================
--- /extensions/ConcoursPhoto/result/index.php	(revision 3905)
+++ /extensions/ConcoursPhoto/result/index.php	(revision 3905)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/ConcoursPhoto/template/concours.tpl
===================================================================
--- /extensions/ConcoursPhoto/template/concours.tpl	(revision 3905)
+++ /extensions/ConcoursPhoto/template/concours.tpl	(revision 3905)
@@ -0,0 +1,50 @@
+<div class="concours">
+	<form  method="post" action="{$CONCOURS_F_ACTIONS}" class="concours"> 
+	<fieldset> 
+		<legend>Concours Photo</legend> 
+	<table>
+		<tr>
+			<td align="left" colspan="5"><b>Concours : {$concours_infos.name}&nbsp;</b>
+			<i>({$concours_infos.descr})</i>&nbsp;
+			<td>
+		</tr>
+		<tr><td colspan="5"><br></td></tr>
+		 {foreach from=$concours_criteria item=concours_criteria}
+			<tr>
+			{if $concours_criteria.level == 1}
+				<td align="left" colspan="2"><b><u>{$concours_criteria.name}</u></b>&nbsp;
+					(<b><i>{$concours_criteria.lib}</i></b>)&nbsp;&nbsp;</td>		
+			{else}
+				<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>		
+				<td><i>{$concours_criteria.name}&nbsp;&nbsp;</i></td>
+			{/if}
+			{if $concours_criteria.level == 1}
+				<td align="left" >&nbsp;</td>
+			{else}
+				<td><i>{$concours_criteria.lib}&nbsp;&nbsp;</i></td>
+			{/if}
+			{if $concours_criteria.nosub}
+			<td><input type="text" size="4" maxlength="4" value="{$concours_criteria.val}" name="{$concours_criteria.id}" /></td>
+			<td><i>(Min={$concours_criteria.min}&nbsp;;Max={$concours_criteria.max})&nbsp;</i></td>
+			{else}
+				<td colspan="2">&nbsp;</td>		
+			{/if}
+			</tr>
+		{/foreach}
+		<tr><td colspan="5"><br></td></tr>
+		<tr>
+			<td colspan="2">{'concours_comment'|@translate}&nbsp;</td>
+			<td colspan="3">
+			<textarea cols="50" rows="4" name="concours_comment" id="concours_comment">{$CONCOURS_COMMENT}</textarea>
+			</td>
+		</tr>		
+
+	</table>
+	<p>
+	<input type="submit" name="concours_submit" value="{'concours_save'|@translate}" />
+	<input type="submit" name="concours_raz" value="{'concours_RAZ'|@translate}" onclick="return confirm('{'Are you sure?'|@translate|@escape:'javascript'}');">
+	</p>	
+	</fieldset> 
+	</form> 
+
+</div>
Index: /extensions/ConcoursPhoto/template/concours_menu.tpl
===================================================================
--- /extensions/ConcoursPhoto/template/concours_menu.tpl	(revision 3905)
+++ /extensions/ConcoursPhoto/template/concours_menu.tpl	(revision 3905)
@@ -0,0 +1,18 @@
+
+{if isset($block->data) and count($block->data)}
+  <!-- Concours menu bar -->
+  {if $block->get_title() !="" }
+    <dt>{$block->get_title()}</dt>
+  {/if}
+  <dd>
+    <ul>
+      {foreach from=$block->data key=name item=link}
+        <li>
+          {$link.nfo}<a href="{$link.link}">{$link.text}</a>
+          {if $link.edit!=""} [<a href="{$link.edit}">{"concours_admin_edit"|@translate}</a>]
+          {/if}
+        </li>
+      {/foreach}
+    </ul>
+  </dd>
+{/if}
Index: /extensions/ConcoursPhoto/template/index.php
===================================================================
--- /extensions/ConcoursPhoto/template/index.php	(revision 3905)
+++ /extensions/ConcoursPhoto/template/index.php	(revision 3905)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/ConcoursPhoto/template/result.tpl
===================================================================
--- /extensions/ConcoursPhoto/template/result.tpl	(revision 3905)
+++ /extensions/ConcoursPhoto/template/result.tpl	(revision 3905)
@@ -0,0 +1,31 @@
+<div class="concours">
+	<fieldset> 
+		<legend>{'concours_result_page'|@translate}</legend> 
+	<table>
+		<tr><td colspan="5"><br></td></tr>
+		 {foreach from=$concours_note item=concours_note}
+			<tr>
+				<td><b><i> ({$concours_note.rang}{if $concours_note.rang == 1}{'concours_1st'|@translate}
+												 {elseif $concours_note.rang == 2}{'concours_2nd'|@translate}
+												 {elseif $concours_note.rang == 3}{'concours_3rd'|@translate}
+												 {else}{'concours_4th'|@translate}{/if}
+							)&nbsp;&nbsp;</i></b></td>
+				<td><b>Photo {$concours_note.img_id}&nbsp;&nbsp;</b></td>		
+				<td>
+					<a href="{$concours_note.url}"> 
+					<img class="thumbnail" src="{$concours_note.thumb}" alt="{$concours_note.name}" title="{$concours_note.name}"/> 
+					</a>
+				</td>
+				<td><i>Note : {$concours_note.note}&nbsp;&nbsp;</i></td>
+				{if $concours_note.rang > 3}
+				<td>&nbsp;</td>
+				{else}
+				<td><img src="{$IMG_URL}trophee-{$concours_note.rang}.png" width="75" height="75"></td>
+				{/if}
+			</tr>
+		{/foreach}
+
+	</table>
+	</fieldset> 
+
+</div>
