Rev 609 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php// +--------------------------------------------------------------------------------+// | annuaire_moteur_fonction.php |// +--------------------------------------------------------------------------------+// | Copyright (c) 2000 - 2003 Tela Botanica |// +--------------------------------------------------------------------------------+// | Les fonctions de annuaire_moteur.php |// +--------------------------------------------------------------------------------+// | Auteur : Alexandre Granier <alexandre@tela-botanica.org> |// +--------------------------------------------------------------------------------+//// $Id: annuaire_moteur_fonction.php,v 1.1 2005/03/24 08:47:31 alex Exp $include_once PAP_CHEMIN_API_PEAR.'HTML/QuickForm.php';include_once PAP_CHEMIN_API_PEAR.'HTML/QuickForm/select.php';/** function mkengine ()**** @return*/function mkengine(){global $label_bbota;global $nbr_total;global $bouton, $HTTP_POST_VARS ;$mes_vars = array ("recherche", "nom", "ville", "mail" ,"dept", "prenom", "cotisant", "pays", "sort", "T_REPONSE", "lettre","statut") ;// Deux cas , soit on a cliqué sur rechercher, soit on a cliqué sur un lienforeach ($mes_vars as $key=>$value) {if (!$bouton) { // on a cliqué sur un lienif (empty($HTTP_POST_VARS[$value])) {}} else {// Si on clique sur le bouton rechercherif (empty ($HTTP_POST_VARS[$value])) {$$value = "" ;} else {$$value = $HTTP_POST_VARS[$value] ;}}}// Comptage du nombre total de données dans la table (hors CACHER = 1)$query = "select count(*) as CPT from ".ANN_ANNUAIRE;$result = $GLOBALS['ann_db']->query($query) ;if (DB::isError($result)) {return $result->getMessage().'<br />'.$result->getDebugInfo();}if ($result->numRows() == 1) {$tmp_nb = $result->fetchRow(DB_FETCHMODE_OBJECT);$nbr_total = $tmp_nb->CPT;if ($nbr_total > 0) $chaine = "parmi $nbr_total données";else die("<B>Erreur</B> lors du comptage des structures ($nbr_total trouvées) : $query");} else die("<B>Erreur</B> lors du comptage des structures : $query");$result->free();// fin comptage$ret = '<h1>'.AM_L_TITRE.'</h1>'."\n";$ret .= '<h2>'.AM_L_TITRE.' '.$chaine.'</h2>'."\n";// construction du moteur de str$formulaire = new HTML_QuickForm('formulaire_recherche', 'post', str_replace('&', '&', $GLOBALS['ann_url']->getURL()));$squelette =& $formulaire->defaultRenderer();$squelette->setFormTemplate("\n".'<div id="annuaire_zone_recherche"><table id="annuaire_recherche"><form{attributes}>'."\n".'{content}'."\n".'</form></table></div>'."\n");$squelette->setElementTemplate( '<tr>'."\n".'<td class="champ">{label}</td>'."\n".'<td class="valeur">{element}'.'<!-- BEGIN required --><span class="symbole_obligatoire">'.ADME_LG_FORM_SYMBOLE_CHP_OBLIGATOIRE.'</span><!-- END required -->'.'<!-- BEGIN error --><span class="erreur">{error}</span><!-- END error -->'.'</td>'."\n".'</tr>'."\n");$formulaire->addElement('text', 'recherche', AM_L_RECHERCHER);$requete = 'select GC_ID, GC_NAME from gen_COUNTRY where GC_LOCALE="fr"';$pays = &$GLOBALS['ann_db']->getAssoc ($requete);$pays = array_merge (array('tous' => 'Tous les pays'), $pays);if (DB::isError($pays)) {return $pays->getMessage().'<br />'.$pays->getDebugInfo();}$select = new HTML_QuickForm_select ('pays', AM_L_PAYS, $pays, array ('class' => 'projet_asso')) ;$formulaire->addElement($select) ;$formulaire->addElement('text', 'nom', AM_L_NOM);$formulaire->addElement('text', 'prenom', AM_L_PRENOM);$formulaire->addElement('text', 'ville', AM_L_VILLE);$departement['tous'] = 'Tous';$resultat = & $GLOBALS['ann_db']->query('select GFD_ID, CONCAT(GFD_ID,\' - \',GFD_NAME) as GFD_NAME from gen_FRENCH_DPT');while ($ligne = $resultat->fetchRow(DB_FETCHMODE_OBJECT)) $departement[$ligne->GFD_ID] = $ligne->GFD_NAME;$select_dpt = new HTML_QuickForm_select ('departement', AM_L_DEPARTEMENT, $departement, array ('class' => 'projet_asso')) ;$formulaire->addElement($select_dpt);$formulaire->addElement('text', 'mail', AM_L_MAIL);$cotisant = array (1 => 'Tous', 2 => 'Cotisants', 3 => 'Non cotisants');$select_cotisant = new HTML_QuickForm_select ('cotisant', AM_L_COTISANTS, $cotisant, array ('class' => 'projet_asso')) ;$formulaire->addElement($select_cotisant);$requete = 'select distinct(YEAR(IC_DATE)) as annees from annuaire_COTISATION';$resultat_annee_cotisation = &$GLOBALS['ann_db']->query ($requete);if (DB::isError($resultat_annee_cotisation)) {return $resultat_annee_cotisation->getMessage().'<br />'.$resultat_annee_cotisation->getDebugInfo();}$tableau_annee_cotisation['Toutes'] = 'Toutes';while ($ligne_annee_cotisation = $resultat_annee_cotisation->fetchRow(DB_FETCHMODE_OBJECT)) {$tableau_annee_cotisation[$ligne_annee_cotisation->annees] = $ligne_annee_cotisation->annees;}$select_annee = new HTML_QuickForm_select ('annee_cotisation', 'Année', $tableau_annee_cotisation, array ('class' => 'projet_asso')) ;$formulaire->addElement($select_annee);$grp = array(20 => 20, 50 => 50, 100 => 100) ;$select_grp = new HTML_QuickForm_select ('T_REPONSE', 'Résultat par', $grp, array ('class' => 'projet_asso')) ;$formulaire->addElement($select_grp);$formulaire->addElement('submit', 'bouton', AM_L_RECHERCHER);foreach ($mes_vars as $key=>$value) {if (isset($_POST[$value])) {$default[$value] = $_POST[$value] ;}}$formulaire->setDefaults($_POST);$ret .= '<br />'.$formulaire->toHTML();return $ret;}function mkquery(){// définition des variables globalesglobal $lettre ;global $bouton ;// Requete sur l'annuaire pour extraire le nom, prénom, ville, nom du département (jointure),// l'état de la cotisation (jointure)// le tableau suivant contient tous les champs de la table annuaire_tela sur lesquels on peut effectuer une recherche$fields_annu = array('departement' => 'U_FRENCH_DPT', "pays" => ANN_CHAMPS_PAYS ) ;$mes_vars = array ("recherche", "nom", "ville", "mail" ,"departement","prenom", "cotisant", "pays", "sort", "T_REPONSE","lettre","statut", "annee_cotisation") ;foreach ($mes_vars as $key=>$value) {if (!$bouton) {} else {$lettre = "" ;if (empty ($_REQUEST[$value])) {$$value = "" ;} else {$$value = $_REQUEST[$value] ;}}}$queries = 'select '.ANN_CHAMPS_ID.','.ANN_CHAMPS_NOM.', '.ANN_CHAMPS_PRENOM.', '.ANN_CHAMPS_PAYS.','.ANN_CHAMPS_MAIL.', '.ANN_CHAMPS_VILLE ;$queries .= ", ".ANN_TABLE_PAYS.".GC_NAME ";$queries .= "from ";$queries .= ANN_TABLE_PAYS.','.ANN_ANNUAIRE ;// Construction en fonction des champs saisies// juste le champs "rechercher", on regarde partout$queries .= " where 1 " ;if ($lettre == "") {if ($_REQUEST['recherche'] != '') {$queries .= ' and ('.ANN_CHAMPS_NOM.' like "%'.$_REQUEST['recherche'].'%"' ; // le premierforeach($fields_annu as $key=>$value) {if ($key == "nom") continue ;$queries .= ($key == "pays" ?$pays == "tous" ? ")" :") and $value = '$pays'" : " or $value like '%$recherche%'") ; // les autres}//$queries .= ' and ' ;} else {// si un ou plusieurs autres champs ont été indiqué, on les rajoute ici$or_flag = false ;foreach($fields_annu as $key=>$valeur) {if ($key != "") {if ($key == "pays" && ($$key != 'tous' && $$key != '')) {if ($$key != "tous") $queries .= " and $valeur like \"%".$$key."%\"" ;} else {if ($key == "departement") {if (isset ($_REQUEST[$key]) && $_REQUEST[$key] != "tous") {$queries .= ' and U_FRENCH_DPT="'.$_REQUEST[$key].'"' ;if ($fields_annu["pays"] != "fr") $queries .= ' and '.ANN_CHAMPS_PAYS.'="fr"' ;}} else {if ($$key != '' && $key != 'pays') {$queries .= ' and '.$valeur.' like "%'.$$key.'%"' ;}}}$or_flag = true ;}}// ici le cas ou rien n'a été saisie du tout, on affiche toutif (!$or_flag) {$queries .= ANN_CHAMPS_NOM.' like "%")' ;}}} else {if ($lettre == "tous") $lettre = "" ;$queries .= 'and '.ANN_CHAMPS_NOM.' like "'.$lettre.'%" ' ;}$queries .= "" ;// jointure entre annuaire et table des pays annuaire_tela et gen_COUNTRY$queries .= " and ".ANN_ANNUAIRE.".".ANN_CHAMPS_PAYS."=".ANN_TABLE_PAYS.".GC_ID" ;if (isset($nom) && $nom != "") $queries .= " and ".ANN_CHAMPS_NOM." like \"%$nom%\"" ;if (isset($prenom) && $prenom != "") $queries .= " and ".ANN_CHAMPS_PRENOM." like \"%$prenom%\"" ;if (isset($ville) && $ville != "") $queries .= " and ".ANN_CHAMPS_VILLE." like \"%$ville%\"" ;if (isset($mail) && $mail != "") $queries .= " and ".ANN_CHAMPS_MAIL." like \"%$mail%\"" ;if (isset($_REQUEST['sort']) && $_REQUEST['sort'] != '') $queries .= ' order by '.$_REQUEST['sort'] ;// traitement de l etat de cotisationif (isset($cotisant) && $cotisant != 1) {$queries .= ' and U_ID IN (select IC_ANNU_ID from annuaire_COTISATION where ';if (isset($annee_cotisation) && $annee_cotisation != 0) {$queries .= ' year(IC_DATE)='.$annee_cotisation ;} else {$queries .= 'year(IC_DATE)='.date('Y') ;}$queries .= ')';}return $queries;}function mkresu() {$requete = mkquery() ;// Requete sans le limit pour le nombre de resultat$resultat_nbr = $GLOBALS['ann_db']->query($requete) ;if (DB::isError($resultat_nbr)) {return $resultat_nbr->getMessage().'<br />'.$resultat_nbr->getDebugInfo().'<br />'.$requete ;}$nbr_final = $resultat_nbr->numRows() ;$resultat_nbr->free();$_SESSION['requete_mail_tous'] = $requete ;if (!isset($_REQUEST['T_REPONSE'])) $_REQUEST['T_REPONSE'] = 20 ;$debut = $_REQUEST['pageID'] * $_REQUEST['T_REPONSE'];$requete .= ' limit '.$debut.','.$_REQUEST['T_REPONSE'];// Requetes avec les résultats affichés$resultat = $GLOBALS['ann_db']->query($requete) ;if (DB::isError($resultat)) {return $resultat->getMessage().'<br />'.$resultat->getDebugInfo().'<br />'.$requete ;}$variables_a_supprimer = array ('username', 'password', 'connexion');foreach ($variables_a_supprimer as $var) if (isset($_POST[$var])) unset ($_POST[$var]) ;$variables = array_merge ($_POST, $_GET);foreach ($variables as $key => $var) if ($variables[$key] != '') $GLOBALS['ann_url']->addQueryString($key, $variables[$key]);$ret = "<table id=\"recherche_alphabetique\"><tr>" ;for ($i = 65 ; $i <91 ; $i++) {$ret .= "\t<td><a href=\"".$GLOBALS['ann_url']->getURL()."&lettre=";$ret .= chr($i)."\">";$ret .= chr($i) ;$ret .= "</a></td>\n";}$GLOBALS['ann_url']->addQueryString('lettre', 'tous');$ret .= '<td> <a href="'.$GLOBALS['ann_url']->getURL().'">'.AM_L_TOUS."</a></td>\n" ;$ret .= "<tr></table>\n" ;include_once 'api/pear/Pager/Pager.php';$params = array('mode' => 'Jumping','perPage' => $_REQUEST['T_REPONSE'],'delta' => 12,'httpMethod' => 'GET','extraVars' => array_merge($_POST, $_GET),'altNext' => 'Suivant','altPrev' => 'Précédent','nextImg' => 'Suivant','prevImg' => 'Précedent','totalItems' => $nbr_final);$pager = & Pager::factory($params);$data = $pager->getPageData();$links = $pager->getLinks();$range = $pager->getOffsetByPageId();$ret .= '<h2>'.$range[0].' - '.$range[1].' parmi '.$nbr_final.'</h2>';$ret .= '<div class="bazar_numero">'.$pager->links.'</div>'."\n";include_once 'api/pear/HTML/Table.php';$table = new HTML_Table(array("class" => "table_cadre"));$table->addRow(array("<a href=\"".$GLOBALS['ann_url']->getURL()."&sort=".ANN_CHAMPS_NOM."\">Identité</a>","<a href=\"".$GLOBALS['ann_url']->getURL()."&sort=".ANN_CHAMPS_MAIL."\">Adresse mail</a>","<a href=\"".$GLOBALS['ann_url']->getURL()."&sort=".ANN_CHAMPS_VILLE."\">".AM_L_VILLE, "Pays ou Dpt (fr)","<a href=\"".$GLOBALS['ann_url']->getURL()."&sort=U_COT\">Cotisant en ".date(Y)),'', 'TH') ;while ($valeur = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {$ligne_tableau = array();$montant = 0;// Le nom de l inscrit avec un lien dessus pour voir les details$GLOBALS['ann_url']->addQueryString('u_id', $valeur[ANN_CHAMPS_ID]);array_push ($ligne_tableau, '<a href="'.$GLOBALS['ann_url']->getURL().'">'.$valeur[ANN_CHAMPS_NOM].' '.$valeur[ANN_CHAMPS_PRENOM].'</a>');// l emailarray_push ($ligne_tableau, '<a href="mailto:'.$valeur[ANN_CHAMPS_MAIL].'">'.$valeur[ANN_CHAMPS_MAIL].'</a>');// La villearray_push ($ligne_tableau, $valeur[ANN_CHAMPS_VILLE]);// Le pays ou le departement si francaisif ($valeur['U_COUNTRY'] != 'fr') {array_push ($ligne_tableau, $valeur['GC_NAME']) ;} else {$req_dpt = 'select GFD_NAME from '.ANN_TABLE_DEPARTEMENT.','.ANN_ANNUAIRE.' where '.ANN_ANNUAIRE.'.'.ANN_CHAMPS_ID.'='.$valeur[ANN_CHAMPS_ID] ;$req_dpt .= " and ".ANN_ANNUAIRE.".U_FRENCH_DPT=".ANN_TABLE_DEPARTEMENT.".GFD_ID" ;$resultat_dpt = $GLOBALS['ann_db']->query($req_dpt) ;if (DB::isError($resultat_dpt)) {return $resultat_dpt->getMessage().'<br />'.$resultat_dpt->getDebugInfo().'<br />'.$req_dpt ;}$ligne_dpt = $resultat_dpt->fetchRow(DB_FETCHMODE_OBJECT) ;array_push ($ligne_tableau, $ligne_dpt->GFD_NAME) ;}// Si cotisantif ($valeur->IC_MONTANT != NULL) $montant = $valeur->IC_MONTANT.' €';array_push ($ligne_tableau, $montant);$table->addRow($ligne_tableau);}$table->altRowAttributes(1, array("class" => "ligne_paire"), array("class" => "ligne_impaire"), true);$ret .= $table->toHTML();$GLOBALS['ann_url']->removeQueryString('u_id');$ret .= '<div class="bazar_numero">'.$pager->links.'</div>'."\n";$GLOBALS['ann_url']->addQueryString(ANN_VARIABLE_ACTION, ANN_ACTION_MAIL_TOUS);$ret .= "<div id=\"envoyer_selection\"><a href=\"".$GLOBALS['ann_url']->getURL()."\">".AM_L_MAIL_SELECTION."</a></div>\n" ;$ret .= '<pre id="debogage">'.$requete.'</pre>';return $ret;}function resume_cotisation() {$res = '<h1>Etat des cotisations</h1>'."\n";$requete = 'select distinct(YEAR(IC_DATE)) as annees from annuaire_COTISATION';$tableau_annee_cotisation = &$GLOBALS['ann_db']->getCol ($requete);if (DB::isError($tableau_annee_cotisation)) {return $tableau_annee_cotisation->getMessage().'<br />'.$tableau_annee_cotisation->getDebugInfo();}$requete = 'select MC_ID,MC_LABEL from MODE_COTISATION order by MC_ID' ;$tableau_mode_cotisation = & $GLOBALS['ann_db']->getAssoc($requete);if (DB::isError($tableau_annee_cotisation)) {return $tableau_mode_cotisation->getMessage().'<br />'.$tableau_mode_cotisation->getDebugInfo();}// Initialisation de la tableinclude_once 'api/pear/HTML/Table.php';$table = new HTML_Table(array('class' => 'table_cadre'));$table->addRow(array_merge (array('Année'), $tableau_mode_cotisation,array('Total', 'Nb cotisant', 'Nb inscrit', 'Ratio')), '', 'TH');foreach ($tableau_annee_cotisation as $annee) {// recherche du nombre d adherent de l annee$requete_nb_cotisant = 'select count(*) as nbr from annuaire_tela where U_DATE < "'.$annee.'-12-31" union'.' select count(*) as nbr from annuaire_COTISATION where year(IC_DATE)='.$annee;// La requete union renvoie une colonne appele nbr avec 2 lignes le nbre inscrit a tela et le nbre de cotisant// pour une année donnee$resultat = $GLOBALS['ann_db']->query($requete_nb_cotisant);if (DB::isError($resultat)) {return $resultat->getMessage().'<br />'.$rseultat->getDebugInfo();}$nb_inscrit_annee = $resultat->fetchRow(DB_FETCHMODE_OBJECT);$nb_cotisant_annee = $resultat->fetchRow(DB_FETCHMODE_OBJECT);$ratio = $nb_cotisant_annee->nbr / $nb_inscrit_annee->nbr * 100;$ligne_table = array();// On insere une premiere colone pour les anneesarray_push ($ligne_table, $annee);$somme_annee = 0;foreach ($tableau_mode_cotisation as $mode_id => $mode_label) {$requete = 'select sum(IC_MONTANT) as montant from annuaire_COTISATION where IC_MC_ID='.$mode_id.' and year(IC_DATE)='.$annee;$montant = $GLOBALS['ann_db']->getOne($requete);if (DB::isError($montant)) {return $montant->getMessage().'<br />'.$montant->getDebugInfo();}array_push ($ligne_table, $montant);$somme_annee += $montant;}array_push ($ligne_table, $somme_annee, $nb_cotisant_annee->nbr, $nb_inscrit_annee->nbr,substr((string)$ratio, 0, 5).' %');$table->addRow($ligne_table);}$res .= $table->toHTML();return $res;}/* +--Fin du code ----------------------------------------------------------------------------------------+** $Log:$* * +-- Fin du code ----------------------------------------------------------------------------------------+*/?>