[Fusionforge-commits] r15080 - in trunk/src: common/docman common/docman/include common/docman/views plugins/projects-hierarchy/common

Franck VILLAUME nerville at fusionforge.org
Sun Feb 26 21:51:39 CET 2012


Author: nerville
Date: 2012-02-26 21:51:38 +0100 (Sun, 26 Feb 2012)
New Revision: 15080

Removed:
   trunk/src/common/docman/include/vtemplate.class.php
   trunk/src/common/docman/templates/
Modified:
   trunk/src/common/docman/include/utils.php
   trunk/src/common/docman/views/search.php
   trunk/src/plugins/projects-hierarchy/common/projects-hierarchyPlugin.class.php
Log:
implement search in child projects

Modified: trunk/src/common/docman/include/utils.php
===================================================================
--- trunk/src/common/docman/include/utils.php	2012-02-26 16:02:03 UTC (rev 15079)
+++ trunk/src/common/docman/include/utils.php	2012-02-26 20:51:38 UTC (rev 15080)
@@ -7,6 +7,7 @@
  * Copyright 2002-2004, GForge Team
  * Copyright 2010-2011, Franck Villaume - Capgemini
  * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
+ * Copyright 2012, Franck Villaume - TrivialDev
  * http://fusionforge.org
  *
  * This file is part of FusionForge. FusionForge is free software;
@@ -84,4 +85,36 @@
 	}
 }
 
+function get_path_document($groupsarr, $doc_group, $group_id) {
+	$rep = "";
+	foreach ($groupsarr as $group) {
+		if ($group["doc_group"] == $doc_group) {
+			if ($group["parent_doc_group"] == 0) {
+				$href = util_make_uri("docman/?group_id=$group_id&view=listfile&dirid=$group[doc_group]");
+				$rep .= "<a href=\"$href\" style=\"color:#00610A;\">$group[groupname]</a>";
+				break;
+			}
+			$s = get_path_document($groupsarr, $group["parent_doc_group"], $group_id);
+			$href = util_make_uri("docman/?group_id=$group_id&view=listfile&dirid=$group[doc_group]");
+			$rep .= "$s / <a href=\"$href\" style=\"color:#00610A;\">$group[groupname]</a>";
+			break;
+		}
+	}
+	return $rep;
+}
+
+function prepare_search_text($text) {
+	$rep = $text;
+	$rep = utf8_decode($rep);
+	$rep = preg_replace("/é/", "/e/", $rep);
+	$rep = preg_replace("/è/", "/e/", $rep);
+	$rep = preg_replace("/ê/", "/e/", $rep);
+	$rep = preg_replace("/à/", "/a/", $rep);
+	$rep = preg_replace("/ù/", "/u/", $rep);
+	$rep = preg_replace("/ç/", "/c/", $rep);
+	$rep = preg_replace("/é/", "/e/", $rep);
+	$rep = strtolower($rep);
+	return $rep;
+}
+
 ?>

Deleted: trunk/src/common/docman/include/vtemplate.class.php
===================================================================
--- trunk/src/common/docman/include/vtemplate.class.php	2012-02-26 16:02:03 UTC (rev 15079)
+++ trunk/src/common/docman/include/vtemplate.class.php	2012-02-26 20:51:38 UTC (rev 15080)
@@ -1,604 +0,0 @@
-<?php
-/*****************************************************************
- *			VIRTUAL-TEMPLATE
- *
- * Version : 1.3.3 Base Edition ( Octobre 2004 ) 
- *
- * Address : http://vtemplate.sourceforge.net
- * 
- * Authors: 
- *   + THIEBAUT Jean-Baptiste(J.Baptiste at leweby.com)  -  http://www.leweby.com .
- *   + CAMPANA François (grem at concept-w.net).
- * Licence: GPL.
- *
- * 
- *
- *  
- *****************************************************************/ 
-
-if ( !isset($DEFINE_VTEMPLATE) ){
-define("ALL",1);
-define("VARTAG","{#"); // Tag d'ouverture des variables : vous pouvez changer ce paramètre.
-define("VTEMPLATE_VERSION","1.3.3");
-define("VTEMPLATE_TYPE","BA");
-define("VTEMPLATE_BUILD","1");
-
-
-class Err {
-var $msg;
-var $titre;
-
-function error($errno,$arg="",$code=0,$disp=0){
-// Gestion des erreurs
-switch($errno){
-  case 1:
-    $this->titre="Erreur de session n° $code";
-    $this->msg = "La zone $arg est déjà ouverte.Avant d'ajouter une session sur cette zone, vous devez la fermer à l'aide de la fonction closeSession().<br>"	;
-  break;
-  case 2:
-    $this->titre="Erreur de session n° $code";
-    $this->msg = "Vous tentez de fermer une session de la zone $arg alors qu'aucune session pour cette zone n'existe.Pour ouvrir une session, utilisez la fonction addSession().<br>";
-  break;
-  case 3:
-    $this->titre="Erreur de session n° $code";
-	$var = $arg[1];
-	$zone = $arg[0];
-    $this->msg = "Vous essayez de valoriser la variable $var sans avoir créer de session de la zone $zone.Utilisez la fonction addSession() pour créer une session, puis setvar pour valoriser une variable.<br>";
-  break;
-  case 4:
-    $this->titre="Erreur de session n° $code";
-	$var = $arg[1];
-	$zone = $arg[0];
-    $this->msg = "La variable $var que vous souhaitez valoriser n'existe pas dans la zone $zone.<br>";
-  break;
-  case 5:
-    $this->titre="Erreur de parsing n° $code";
-    $this->msg = "Vous utilisez des caractère non autorisés pour déclarer vos zones.Vous pouvez utiliser tous les caractères à l'exception de \'{\' , \'#\' \'}\' et \'|\'.<br>";
-  break;
-  case 6:
-    $this->titre="Erreur de parsing n° $code";
-    $this->msg = "Vous ne pouvez pas utiliser le même nom ($arg)de zone plusieurs fois.<br>";
-  break;
-  case 7:
-    $this->titre="Erreur de parsing n° $code";
-    $this->msg = "Vous avez oublié de fermer la zone $arg.<br>";
-  break;
-  case 8:
-    $this->titre="Erreur de traitement n° $code";
-    $this->msg = "Le fichier template $arg est introuvable.<br>";
-  break;
-  case 9:
-    $this->titre="Erreur de traitement n° $code";
-    $this->msg = "Impossible d'ouvrir le fichier $arg.Vérifiez les droits de ce fichier.<br>";
-  break;
-  case 10:
-    $this->titre="Erreur de traitement n° $code";
-    $this->msg = "Impossible de lire le fichier template $arg.<br>";
-  break;
-  case 11:
-    $this->titre="Erreur de traitement n° $code";
-    $this->msg = "La zone $arg est introuvable.Vérifiez la syntaxe de cette zone.<br>";
-  break;
-  case 12:
-    $this->titre="Erreur de traitement n° $code";
-    $this->msg = "La variable $arg est introuvable .Vérifiez la syntaxe de la variable.<br>";
-  break;
-  case 13:
-    $this->titre="Erreur de traitement n° $code";
-    $this->msg = "L'identifiant de fichier spécifié n'existe pas.Vérifiez les fonctions Open() de votre script.<br>";
-  break;
-  case 14:
-    $this->titre="Erreur de traitement n° $code";
-	$var = $arg[1];
-	$file = $arg[0];
-    $this->msg = "La variable $var dans le fichier $file est introuvable.Vérifiez la syntaxe de la variable.<br>";
-  break;
-  case 15:
-    $this->titre="Erreur de traitement n° $code";
-	$var = $arg[2];
-	$zone = $arg[1];
-	$fichier = $arg[0];
-    $this->msg = "La variable $var dans la zone $zone du fichier $fichier est introuvable.Vérifiez la syntaxe de la variable et du nom de la zone.<br>";
-  break;
-  default:
-	 $this->titre = "Erreur inconnue $code";	 
-     $this->msg = "Veuillez le rapporter aux auteurs de la classe.";
-}
-$this->titre .= ": <br>";
-if ($disp){
-	$web = "Pour plus d'informations, consultez la <a href=\"http://www.virtual-solution.net/vtemplate/docs/debug-mod.php?version=".VTEMPLATE_VERSION."&build=".VTEMPLATE_BUILD."&type=".VTEMPLATE_TYPE."&error=$code\" target=\"_blank\">doc en ligne</a>";
-	echo "<font face=verdana size=2 color=red><u>$this->titre</u><i>$this->msg</i>$web<br><br></font>";
-}
-return -1;
-}
-// Fin classe
-}
-
-class Session extends err{
-
-var $name;		// Name of the session
-var $globalvar = array();  // List of global variable of the session
-var $varlist = array();  // List of vars in this session
-var $subzone = array(); // list of sub-zone
-var $temp; // Generated code for the current session
-var $generated = NULL; // The final code
-var $source; // Source code
-var $used=0; // Indicates if the session contain used variable
-var $stored; // Give the filename were is stored the session
-
-function Session($name,$source,$stored){
- $this->name = $name;
- $this->source = $source;
- $this->stored = $stored;
- $this->parseVar();
-}
-
-function parseVar(){
- // Récupération des noms des variables
- $regle = "|".VARTAG."(.*)}|sU"; 
- preg_match_all ($regle,$this->source,$var1);
- // Création du tableau de variable  à partir de la liste parsée.
- $this->varlist=array_merge($this->varlist,$var1[1]);
-return 1;
-} 
-
-function init(){
-if($this->used) return $this->error(1,array($this->stored,$this->name),"SESSION1",1);
-// Reset generated code
-$this->temp = $this->source;
-$this->used = 1;
-}
-function closeSession(){
-// Check if the zone has been used.    
-if(!$this->used) return $this->error(2,array($this->stored,$this->name),"SESSION2",1);
-// Set Globals vars.
-$this->generateCode();
-$this->used=0;
-return 1;
-}
-
-function reset(){
-$this->used = 0;
-$this->generated = NULL;
-return 1;
-}
-
-function addSubZone(&$subzone){
-$this->subzone[$subzone->name] = &$subzone;
-return 1;
-}
-
-function setVar($varname,$value){
-if (!$this->used) return $this->error(3,array($this->stored,$this->name,$varname),"SESSION3",1);
-if (!in_array($varname,$this->varlist)) return $this->error(4,array($this->name,$varname),"SESSION4",1);
-$regle = "(\\".VARTAG."$varname\})";
-$this->temp = preg_replace($regle,$value,$this->temp);
-return 1;
-}
-
-function dispVar(){
- echo "Liste variables de $this->name:<br>";
- foreach ( $this->varlist as $vars )
-    echo "$vars <br>";
-}
-
-function setGlobalVar($varname,$value){
-$set = 0;
-if (in_array($varname,$this->varlist)){
-  // Replace the var into this session 
-  $this->globalvar[$varname]=$value;   
-  $set = 1;
-}
-  // Replace the var into sub zones
-  foreach(array_keys($this->subzone) as $subzone){
-      $set = $this->subzone[$subzone]->setGlobalVar($varname,$value) || $set;
-  }
-  return $set;
-}
-
-function replaceGlobalVar(){
-if ( count($this->globalvar) )
-foreach($this->globalvar as $varname => $value){
-  $regle = "(\\".VARTAG."$varname\})";
-  $this->temp = preg_replace($regle,$value,$this->temp);
-}
-}
-
-
-function generateCode(){
-    if ($this->used == 0) return $this->generated;
-    // Replace global var.
-	if ( count($this->globalvar) ) $this->replaceGlobalVar();
-	// Replace all unused variable by ""
-    $regle = "|\\".VARTAG."([^}]*)\}|";
-	$this->temp = preg_replace($regle,"",$this->temp);
-	// Generate the subzone(s) code
-	if(count($this->subzone)){
-	  foreach(array_keys($this->subzone) as $subzone){
-		$text = ($this->subzone[$subzone]->used) ? $this->subzone[$subzone]->generateCode() : $this->subzone[$subzone]->generated;
-		$this->temp = preg_replace("(\|$subzone\|)",$text,$this->temp); 	
-		$this->subzone[$subzone]->reset();
-	  }
-    }
-$this->generated .= $this->temp;
-return $this->generated;
-}
-
-function inVarList($varname){
-return in_array($varname,$this->varlist);
-}
-
-// Fin classe
-}
-
-class VTemplate_Private extends Err{
-/****************************************
-*	   Private Class.		*
-* ***************************************/
-
-var $sources=array(); // Sources des zones issues de la premiere partie du parsing.
-var $sessions=array(); // Tableau de sessions
-var $v_global=array(); // Globla var array.
-
-/****************************************************************
-	    Parsing Functions for Template files.  ( PF 1.0 )
- ****************************************************************/
-
-function getNom($code){
-// Retourne le premier nom de zone qu'il trouve dans le code
-
-   preg_match("(<!--VTP_([^()]+)-->)sU",$code,$reg);
-   
-   // Tester la présence des caratère invalides dans le nom ( | et {});
-   if (@count(explode("|",$reg[1]))>1 || @count(explode("{",$reg[1]))>1 || @count(explode("}",$reg[1]))>1) exit($this->error(5,$reg[1],"PARSE1",1));
-   
-   return @$reg[1];
-}
-
-function endTag($code,$nom){
-// Renvoie TRUE(1) si le tag de fermeture est présent.
-
-   preg_match("(<!--/VTP_$nom-->)sU",$code,$reg);
-
-return ($reg[0]!="<!--/VTP_$nom-->") ? 0 : 1;
-}
-
-function getSource($code,$nom,$type=0){
-// Retourne le source de la zone de nom $nom
-
-   preg_match_all ("(<!--VTP_$nom-->(.*)<!--/VTP_$nom-->)sU",$code,$reg);
-
-return $reg[$type][0];
-}
-
-function parseZone($code_source,$nom_zone="|root|"){
-// Fonction récursive de parsing du fichier template
-   // Vérification que la zone n'existe pas
-   if (isset($this->sources[$nom_zone])) exit($this->error(6,$nom_zone,"PARSE2",1));
-
-   // Enregistrement du code source
-   $this->sources[$nom_zone]["source"]=$code_source;
-
-   // Rappel de la fonction pour chaque fils.
-   while($nom_fils=$this->getNom($this->sources[$nom_zone]["source"])){
-
-     // Vérification que le tag de fin est présent.
-     if (!$this->endTag($code_source,$nom_fils)) exit($this->error(7,$nom_fils,"PARSE3",1));
-
-     // Parse le fils
-     $this->parseZone($this->getSource($this->sources[$nom_zone]["source"],$nom_fils,1),$nom_fils);
-
-     // Enregistre le nom du fils dans la liste des fils
-     $this->sources[$nom_zone]["fils"][]=$nom_fils;
-
-     // Remplace le code du fils dans le source du père
-     $this->sources[$nom_zone]["source"]=str_replace(
-				     $this->getSource($this->sources[$nom_zone]["source"],$nom_fils,0),
-				     "|$nom_fils|",
-				     $this->sources[$nom_zone]["source"]
-				     );
-     // Teste si la zone $nom_fils n'existe pas plusieurs fois dans la zone $nom_zone
-     if (count(explode("|$nom_fils|",$this->sources[$nom_zone]["source"]))>2) exit($this->error(6,$nom_fils,"PARSE4",1));
-   }// fin While
-
-return 1;
-}
-
-/****************************************************************
-	    Session Management functions ( SMF 1.0 )
- ****************************************************************/
-
-function createSession($handle,$zone = "|root|"){
-// Create a new session of the zone
-$this->sessions[$handle][$zone] = new Session($zone,$this->sources[$zone]["source"],$this->file_name[$handle]);
-
-// Create sub-zone
-if (@count($this->sources[$zone]["fils"])){
-   foreach($this->sources[$zone]["fils"] as $subzone){	  
-    $this->createSession($handle,$subzone);
-    $this->sessions[$handle][$zone]->addSubZone($this->sessions[$handle][$subzone]);
-   }
-}
-				  
-//end createSession
-}
-
-
-/****************************************************************
-	    Global Variable Management Functions ( GVMF 1.0 )
- ****************************************************************/
-
- function setGZone($handle,$zone,$var,$value){
- // Define Global var for $zone and its sub-zone.
-   // Set global value to $zone vars.
-  return $this->sessions[$handle][$zone]->setGlobalVar($var,$value);
-}
-
-function setGFile($handle,$var,$value) {
-  return $this->sessions[$handle]["|root|"]->setGlobalVar($var,$value);
-}
-
-function setGAll($var,$value){
-$declare = 0;
-$this->v_global[$var]=$value;
-if (is_array($this->sessions)){
-    foreach($this->sessions as $handle => $v){
-		$declare = $this->setGFile($handle,$var,$value) || $declare;
-		}	
-  } 
-return $declare;
-}
-
-function setGOpened($handle){
-// Set Global var into the opened file
-foreach($this->v_global as $name => $val){
-  $this->setGFile($handle,$name,$val);
-}
-return 1;
-}
- 
-// Fin VTemplate_Private
-}
-
-
-class VTemplate extends VTemplate_Private{
-/****************************************
-*	   var Class.		*
-* ***************************************/
-
-
-/****************************************************************
-	    Core Functions 
-*****************************************************************/
-
-
-function Open($nomfichier){
-// Ouverture d'un fichier source et retourne le handle de ce fichier
-// Création du handle:
-$handle =  "{".count($this->sessions)."}" ;
-
-
-// Récupération du source à parser
-if (!@file_exists($nomfichier)) return $this->error(8,$nomfichier,"TTT1",1);
-if (!$f_id=@fopen($nomfichier,"r")) return $this->error(9,$nomfichier,"TTT2",1);
-if (!$source=@fread($f_id, filesize($nomfichier))) return $this->error(10,$nomfichier,"TTT3",1);
-clearstatcache();
-fclose($f_id);
-
-// Store the filename
-$this->file_name[$handle]=$nomfichier;
-
-// Parse les zones
-$this->parseZone($source);
-
-// Création du tableau de session
-$this->createSession($handle);
-
-//Nettoyage des variables temporaires
-$this->sources=NULL;
-
-// Set global var.
-$this->setGOpened($handle);
-
-$this->addSession($handle);
-return $handle;
-}
-
-function newSession($handle="{0}", $nom_zone = "|root|"){
-	if ( $this->sessions[$handle][$nom_zone]->used ) $this->closeSession($handle,$nom_zone);
-	$this->addSession($handle,$nom_zone);
-	return 1;
-}
-
-function addSession($handle="{0}",$nom_zone = "|root|"){
-	// Does the zone exist ?
-   if(!isset($this->sessions[$handle][$nom_zone])) return $this->error(11,array($nom_zone,$this->file_name[$handle]),"TTT4",1);   
-   $this->sessions[$handle][$nom_zone]->init();
-   return 1;
-}
-
-function closeSession($handle="{0}",$nom_zone = "|root|"){ 
-// Close the current session and all his sub-session
-	  // Check if the zone exists.
-	if(!isset($this->sessions[$handle][$nom_zone])) return $this->error(11,array($nom_zone,$this->file_name[$handle]),"TTT5",1);
-     // Closing sub-zone
-     $this->sessions[$handle][$nom_zone]->closeSession();	
-   return 1;
-}
-
-function setGlobalVar($arg1,$arg2,$arg3){
-if ($arg1 == 1){
-  if (!$this->setGAll($arg2,$arg3)) return $this->error(12,$arg2,"TTT6",1);
-  return 1; 
-}
-if (!isset($this->sessions[$arg1])) return $this->error(13,$arg1,"TTT7",1);
- $tab=explode(".",$arg2);
- if (count($tab)==1){
-    if (!$this->setGFile($arg1,$arg2,$arg3)) return $this->error(14,array($this->file_name[$arg1],$arg2),"TTT8",1);
- }
- else if (count($tab==2)){
-    if (!isset($this->sessions[$arg1][$tab[0]])) return $this->error(11,array($tab[0],$this->file_name[$arg1],"TTT9",1));
-    if (!$this->setGZone($arg1,$tab[0],$tab[1],$arg3)) return $this->error(15,array($this->file_name[$arg1],$tab[0],$tab[1]),"TTT10",1);
- }
-return 1;
-}
-
-function setVar($handle,$zone_var,$val){
- // Fill the variable
-$tab=explode(".",$zone_var);
- if(count($tab)==2){
-   $zone=$tab[0];
-   $var=$tab[1];
- }
- else
- {
-  $zone="|root|";
-  $var=$tab[0];
- }
-
- // Teste l'existence de la zone dans la liste
- if (!isset($this->sessions[$handle][$zone])) return $this->error(11,array($this->file_name[$handle],$zone),"TTT11",1);
-
- //Enregistre la variable
- return $this->sessions[$handle][$zone]->setVar($var,$val);
-}
-
-function Parse($handle_dest,$zone_var_dest,$handle_source,$zone_source="|root|"){
-	if($this->sessions[$handle_source][$zone_source]->used == 1) $this->closeSession($handle_source,$zone_source);
-	  $this->setVar($handle_dest,$zone_var_dest, $this->sessions[$handle_source][$zone_source]->generated);
-}
-
-function setVarF($handle,$zone_var,$file){
-// Fonction qui ouvre le fichier file et copie ce qu'il y a dedans dans une variable.
-$tab=explode(".",$zone_var);
-
-// Récupération nom de la zone et de la variable.
- if(count($tab)==2){
-   $zone=$tab[0];
-   $var=$tab[1];
- }
- else
- {
-  $zone="|root|";
-  $var=$tab[0];
- }
-// Teste l'existence de la zone dans la liste
- if (!is_object($this->sessions[$handle][$zone])) return $this->error(11,array($handle,$zone),"TTT12",1);
-
- // Récupération du source à lire
-if (!@file_exists($file)) return $this->error(8,$file,"TTT13",1);
-if (!$f_id=@fopen($file,"r")) return $this->error(9,$file,"TTT14",1);
-if (!$val=@fread($f_id, filesize($file))) return $this->error(10,$file,"TTT15",1);
-clearstatcache();
-fclose($f_id);
-
-//Enregistre la variable
-return $this->sessions[$handle][$zone]->setVar($var,$val);
-}
-
-
-
-
-
-function isZone($handle, $zone="|root|") 
-{ 
-return isset($this->sessions[$handle][$zone]) ; 
-} 
-
-function Display($handle="{0}",$display=1,$zone="|root|"){
-	$this->closeSession($handle,$zone);
-	$c_genere = $this->sessions[$handle][$zone]->generated; 
-	
-	if ($display) echo $c_genere; else return ($c_genere);
-}
-//fonction complementaire version BETA
-
-/*
-* 
-On peut l'utiliser : 
-- SetVarTab($array): tout les couples clef/valeur sont valorisées 
-- SetVarTab($array,$index) seuls les couples clef/valeur dont la clef est dans le tableau index ou dont la valeur == $index (si pas tableau) 
-Si $index contient ou est une clef de type zone.clef, la clef sera extraite du texte est servira d'index pour $array 
-
-Vincent 
-*/
-
-function setVarTab($handle,$zones,$index = array()){ 
-	if (is_array($index)) 
-	{ 
-		if (count($index)>0) 
-		{ 
-			reset($index); 
-			while (list (, $key) = each ($index)) 
-			{ 
-				$tab=explode(".",$key); 
-				if(count($tab)==2){ 
-					$var=$tab[1]; 
-				} 
-				else 
-				{ 
-					$var=$tab[0]; 
-				} 
-				setVar($handle,$key,$zones[$var]); 
-			} 
-		} 
-		else 
-		{ 
-			reset($zones); 
-			while (list ($key, $val) = each ($zones)) 
-			{ 
-				setVar($handle,$key,$val); 
-			} 
-		} 
-	} 
-	else 
-	{ 
-		setVar($handle,$index,$zones[$index]); 
-	} 
-} 
-
-function setGlobalVarTab($handle,$zones,$index = array()){ 
-
-	if (is_array($index)) 
-	{ 
-		if (count($index)>0) 
-		{ 
-			reset($index); 
-			while (list (, $key) = each ($index)) 
-			{ 
-				$tab=explode(".",$key); 
-				if(count($tab)==2){ 
-					$var=$tab[1]; 
-				} 
-				else 
-				{ 
-					$var=$tab[0]; 
-				} 
-				setGlobalVar($handle,$key,$zones[$var]); 
-			} 
-		} 
-		else 
-		{ 
-			reset($zones); 
-			while (list ($key, $val) = each ($zones)) 
-			{
-				GlobalVar($handle,$key,$val); 
-			} 
-		} 
-	} 
-	else 
-	{ 
-		setBlobalVar($handle,$index,$zones[$index]); 
-	} 
-} 
-
-
-
-
-
-
-// End VTemplate
-}
-$DEFINE_VTEMPLATE = 1;
-}
-?>

Modified: trunk/src/common/docman/views/search.php
===================================================================
--- trunk/src/common/docman/views/search.php	2012-02-26 16:02:03 UTC (rev 15079)
+++ trunk/src/common/docman/views/search.php	2012-02-26 20:51:38 UTC (rev 15080)
@@ -7,6 +7,7 @@
  * Copyright 2005, Fabio Bertagnin
  * Copyright 2010-2011, Franck Villaume - Capgemini
  * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
+ * Copyright 2012, Franck Villaume - TrivialDev
  * http://fusionforge.org
  *
  * This file is part of FusionForge. FusionForge is free software;
@@ -34,47 +35,62 @@
 	session_redirect('/docman/?group_id='.$group_id.'&warning_msg='.urlencode($return_msg));
 }
 
-/* NEED A REAL REWRITE */
-require_once $gfcommon.'docman/include/vtemplate.class.php';
-
 $is_editor = forge_check_perm('docman', $g->getID(), 'approve');
-
-$vtp = new VTemplate;
-if (empty($gfcommon)) {
-	$templates_dir = '../../common';
+$searchString = trim(getStringFromPost("textsearch"));
+$subprojectsIncluded = getStringFromPost('includesubprojects');
+$insideDocuments = getStringFromPost('insideDocuments');
+$allchecked = "";
+$onechecked = "";
+$includesubprojects = "";
+$insideDocumentsCheckbox = "";
+if (getStringFromPost('search_type') == "one") {
+	$onechecked = 'checked="checked"';
 } else {
-	$templates_dir = $gfcommon;
+	$allchecked = 'checked="checked"';
 }
-$handle = $vtp->Open($templates_dir."/docman/templates/search.tpl.html");
-$vtp->NewSession($handle,"MAIN");
 
-$allchecked = "";
-$onechecked = "";
-if (getStringFromPost('search_type') == "one") {$onechecked = 'checked="checked"';}
-else {$allchecked = 'checked="checked"';}
-$vtp->AddSession($handle,"FORMSEARCH");
-$vtp->SetVar($handle,"FORMSEARCH.TITLE",_('Search in documents'));
-$vtp->SetVar($handle,"FORMSEARCH.GROUP_ID",$_GET["group_id"]);
-$vtp->SetVar($handle,"FORMSEARCH.TEXTSEARCH",getStringFromPost("textsearch"));
-$vtp->SetVar($handle,"FORMSEARCH.ALLCHECKED",$allchecked);
-$vtp->SetVar($handle,"FORMSEARCH.ONECHECKED",$onechecked);
-$vtp->SetVar($handle,"FORMSEARCH.SUBMIT_PROMPT",_('Search'));
-$vtp->SetVar($handle,"FORMSEARCH.SEARCH_ALL_WORDS",_('With all the words'));
-$vtp->SetVar($handle,"FORMSEARCH.SEARCH_ONE_WORD",_('With at least one of words'));
-$vtp->CloseSession($handle,"FORMSEARCH");
+if ($subprojectsIncluded)
+	$includesubprojects = 'checked="checked"';
 
-if ((getStringFromPost('cmd') == "search") && trim(getStringFromPost("textsearch"))) {
+if ($insideDocuments)
+	$insideDocumentsCheckbox = 'checked="checked"';
+
+echo '<div class="docmanDivIncluded">';
+echo '<form method="post" action="?group_id='.$group_id.'&view=search" >';
+echo '<table width="98%" cellpadding="2" cellspacing="0" border="0">';
+echo '<tr><td><b>'._('Query: ').'</b>';
+echo '<input type="text" name="textsearch" id="textsearch" size="48" value="'.$searchString.'" />';
+echo '<input type="submit" value="'._('Search').'" />';
+echo '</td></tr><tr><td>';
+echo '<input type="radio" name="search_type" value="all" '.$allchecked.' class="tabtitle-nw" title="'._('All searched words are mandatory').'" />'._('With all the words');
+echo '<input type="radio" name="search_type" value="one" '.$onechecked.' class="tabtitle" title="'._('At least one word must be found').'" />'._('With at least one of words');
+if ($g->useDocmanSearch()) {
+	echo '<input type="checkbox" name="insideDocuments" value="1" '.$insideDocumentsCheckbox.' class="tabtitle" title="'._('Filename and contents are used to match searched words').'" />'._('Inside documents');
+}
+if ($g->usesPlugin('projects-hierarchy')) {
+	$projectsHierarchy = plugin_get_object('projects-hierarchy');
+	$projectIDsArray = $projectsHierarchy->getFamily($group_id, 'child', true, 'validated');
+}
+if (isset($projectIDsArray) && is_array($projectIDsArray))
+	echo '<input type="checkbox" name="includesubprojects" value="1" '.$includesubprojects.' class="tabtitle" title="'._('search into childs following project hierarchy').'" />'._('Include child projects');
+
+echo '</td></tr>';
+echo '</table>';
+echo '</form>';
+if ($searchString) {
 	$textsearch = trim(getStringFromPost("textsearch"));
-	$textsearch = prepare_search_text($textsearch);
+	//$textsearch = prepare_search_text($textsearch);
 	$mots = preg_split("/[\s,]+/",$textsearch);
-	$qpa = db_construct_qpa(false, 'SELECT filename, filetype, docid, doc_data.stateid as stateid, doc_states.name as statename, title, description, createdate, updatedate, doc_group, group_id FROM doc_data JOIN doc_states ON doc_data.stateid = doc_states.stateid') ;
+	$qpa = db_construct_qpa(false, 'SELECT filename, filetype, docid, doc_data.stateid as stateid, doc_states.name as statename, title, description, createdate, updatedate, doc_group, group_id FROM doc_data, doc_states WHERE doc_data.stateid = doc_states.stateid');
 	if (getStringFromPost('search_type') == "one") {
 		if (count($mots) > 0) {
 			$qpa = db_construct_qpa($qpa, ' AND (FALSE');
 			foreach ($mots as $mot) {
 				$mot = strtolower($mot);
-				$qpa = db_construct_qpa($qpa, ' OR title LIKE $1 OR description LIKE $1 OR data_words LIKE $1',
+				$qpa = db_construct_qpa($qpa, ' OR title LIKE $1 OR description LIKE $1 ',
 							 array("%$mot%"));
+				if ($insideDocuments)
+					$qpa = db_construct_qpa($qpa, ' OR data_words LIKE $1 ', array("%$mot%"));
 			}
 			$qpa = db_construct_qpa($qpa, ')');
 		}
@@ -84,8 +100,11 @@
 			$qpa = db_construct_qpa($qpa, ' AND (TRUE');
 			foreach ($mots as $mot) {
 				$mot = strtolower($mot);
-				$qpa = db_construct_qpa($qpa, ' AND (title LIKE $1 OR description LIKE $1 OR data_words LIKE $1)',
+				$qpa = db_construct_qpa($qpa, ' AND (title LIKE $1 OR description LIKE $1 ',
 							array("%$mot%"));
+				if ($insideDocuments)
+					$qpa = db_construct_qpa($qpa, ' OR data_words LIKE $1 ', array("%$mot%"));
+				$qpa = db_construct_qpa($qpa, ' ) ', array());
 			}
 			$qpa = db_construct_qpa($qpa, ')');
 		}
@@ -97,106 +116,56 @@
 		$qpa = db_construct_qpa($qpa, ' AND doc_data.stateid != 2');
 	}
 
-	$qpa = db_construct_qpa($qpa, ' AND group_id = $1', array($group_id));
+	$qpa = db_construct_qpa($qpa, ' AND ( group_id = $1', array($group_id));
 	$params['group_id'] = $group_id;
-	$params['qpa'] = $qpa;
+	$params['qpa'] = &$qpa;
+	$params['includesubprojects'] = $subprojectsIncluded;
 	plugin_hook('docmansearch_has_hierarchy', $params);
-
-	$qpa = db_construct_qpa($qpa, 'ORDER BY updatedate, createdate');
-	$resarr = array();
+	$qpa = db_construct_qpa($qpa, ' ) ', array());
+	$qpa = db_construct_qpa($qpa, ' ORDER BY updatedate, createdate');
 	$result = db_query_qpa($qpa);
 	if (!$result) {
-		$vtp->AddSession($handle, "MESSAGE");
-		$vtp->SetVar($handle, "MESSAGE.TEXT", _('Database query error'));
-		$vtp->CloseSession($handle, "MESSAGE");
+		echo '<p class="error">'._('Database query error').'</p>';
+		db_free_result($result);
 	} elseif (db_numrows($result) < 1) {
-		$vtp->AddSession($handle, "MESSAGE");
-		$vtp->SetVar($handle, "MESSAGE.TEXT", _('Your search did not match any documents'));
-		$vtp->CloseSession($handle, "MESSAGE");
+		echo '<p class="warning_msg">'._('Your search did not match any documents').'</p>';
+		db_free_result($result);
 	} else {
+		$resarr = array();
 		while ($arr = db_fetch_array($result)) {
 			$resarr[] = $arr;
 		}
-	}
-	db_free_result($result);
- 	// print_debug ($sql);
-	// need groups infos
-	$groupsarr = array();
-	$result = db_query_params('SELECT doc_group, groupname, parent_doc_group FROM doc_groups WHERE group_id=$1',
-					array(getIntFromRequest('group_id')));
-	if ($result && db_numrows($result) > 0) {
-		while ($arr = db_fetch_array($result)) {
-			$groupsarr[] = $arr;
+		db_free_result($result);
+		// need groups infos
+		$groupsarr = array();
+		$qpa = db_construct_qpa(false, 'SELECT doc_group, groupname, parent_doc_group FROM doc_groups WHERE group_id=$1', array($group_id));
+		$params['group_id'] = $group_id;
+		$params['qpa'] = &$qpa;
+		$params['includesubprojects'] = $subprojectsIncluded;
+		plugin_hook('docmansearch_has_hierarchy', $params);
+		$result = db_query_qpa($qpa);
+		if ($result && db_numrows($result) > 0) {
+			while ($arr = db_fetch_array($result)) {
+				$groupsarr[] = $arr;
+			}
 		}
-	}
-	db_free_result($result);
-
-	$vtp->AddSession($handle, "RESULTSEARCH");
-	$count = 0;
-	foreach ($resarr as $item) {
-		$count++;
-		$vtp->AddSession($handle, "RESULT");
-		$vtp->SetVar($handle, "RESULT.N", $count);
-		$vtp->SetVar($handle, "RESULT.SEARCHTITLE", $item["title"]);
-		$vtp->SetVar($handle, "RESULT.SEARCHCOMMENT", $item["description"]);
-		$s = get_path_document($groupsarr, $item["doc_group"], "$_GET[group_id]");
-		$vtp->SetVar($handle, "RESULT.SEARCHPATH", $s);
-		if ($item['filetype'] == 'URL') {
-			$vtp->SetVar($handle, "RESULT.FILE_NAME", $item["filename"]);
-		} else {
-			$vtp->SetVar($handle, "RESULT.FILE_NAME", '/docman/view.php/'.$_GET["group_id"].'/'.$item["docid"].'/'.urlencode($item["filename"]));
-		}
-		if ($is_editor) $vtp->SetVar($handle, "RESULT.STATE", $item["statename"]);
-		$vtp->CloseSession($handle, "RESULT");
-	}
-	$vtp->CloseSession($handle, "RESULTSEARCH");
-}
-
-$vtp->CloseSession($handle, "MAIN");
-$vtp->Display();
-
-// print_debug (print_r($_POST,true));
-// print_debug (print_r($groupsarr,true));
-
-function print_debug($text) {
-	echo "<pre>$text</pre>";
-}
-
-function get_path_document($groupsarr, $doc_group, $group_id) {
-	$rep = "";
-	foreach ($groupsarr as $group) {
-		if ($group["doc_group"] == $doc_group) {
-			if ($group["parent_doc_group"] == 0) {
-				$href = util_make_uri("docman/?group_id=$group_id&view=listfile&dirid=$group[doc_group]");
-				$rep .= "<a href=\"$href\" style=\"color:#00610A;\">$group[groupname]</a>";
-				break;
+		db_free_result($result);
+		$count = 0;
+		echo '<table width="98%" cellpadding="0" cellspacing="0" border="0">';
+		foreach ($resarr as $item) {
+			$count++;
+			if ($item['filetype'] == 'URL') {
+				$fileurl = $item["filename"];
+			} else {
+				$fileurl = '/docman/view.php/'.$item["group_id"].'/'.$item["docid"].'/'.urlencode($item["filename"]);
 			}
-			$s = get_path_document($groupsarr, $group["parent_doc_group"], $group_id);
-			$href = util_make_uri("docman/?group_id=$group_id&view=listfile&dirid=$group[doc_group]");
-			$rep .= "$s / <a href=\"$href\" style=\"color:#00610A;\">$group[groupname]</a>";
-			break;
+			echo '<tr><td width="20px" align="right"><b>'.$count.'.</b></td><td><b>'.$item["title"].'</b> (<a href="'.$fileurl.'">'.$item["filename"].'</a>)</td></tr>';
+			echo '<tr><td colspan="2">'.$item["description"].'</td></tr>';
+			echo '<tr><td colspan="2"><b>'.$item["statename"].'</b>  <i>'.get_path_document($groupsarr, $item["doc_group"], "$item[group_id]").'</i></td></tr>';
+			echo '<tr><td colspan="2"> </td></tr>';
 		}
+		echo '</table>';
 	}
-	return $rep;
 }
-
-function prepare_search_text($text) {
-	$rep = $text;
-	$rep = utf8_decode($rep);
-	$rep = preg_replace("/é/", "/e/", $rep);
-	$rep = preg_replace("/è/", "/e/", $rep);
-	$rep = preg_replace("/ê/", "/e/", $rep);
-	$rep = preg_replace("/à/", "/a/", $rep);
-	$rep = preg_replace("/ù/", "/u/", $rep);
-	$rep = preg_replace("/ç/", "/c/", $rep);
-	$rep = preg_replace("/é/", "/e/", $rep);
-	$rep = strtolower($rep);
-	return $rep;
-}
-
-// Local Variables:
-// mode: php
-// c-file-style: "bsd"
-// End:
-
+echo '</div>';
 ?>

Modified: trunk/src/plugins/projects-hierarchy/common/projects-hierarchyPlugin.class.php
===================================================================
--- trunk/src/plugins/projects-hierarchy/common/projects-hierarchyPlugin.class.php	2012-02-26 16:02:03 UTC (rev 15079)
+++ trunk/src/plugins/projects-hierarchy/common/projects-hierarchyPlugin.class.php	2012-02-26 20:51:38 UTC (rev 15080)
@@ -125,10 +125,15 @@
 				break;
 			}
 			case "docmansearch_has_hierarchy": {
-				$group_id = $params['group_id'];
-				$group = group_get_object($group_id);
-				if ($group->usesPlugin($this->name)) {
-					$qpa = $params['qpa'];
+				if ($params['includesubprojects']) {
+					$group_id = $params['group_id'];
+					$group = group_get_object($group_id);
+					if ($group->usesPlugin($this->name)) {
+						$arrayChilds= $this->getFamily($group_id, 'child', true, 'validated');
+						foreach ( $arrayChilds as $childId ) {
+							$params['qpa'] = db_construct_qpa($params['qpa'], ' OR group_id = $1', array($childId));
+						}
+					}
 				}
 				$returned = true;
 				break;




More information about the Fusionforge-commits mailing list