noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
fid_card.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011 
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with NOALYSS; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 */
00020 
00021 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00022 
00023 /*!\file
00024  * \brief this file is used by the autocomplete functionnality
00025  *\see ICard
00026  */
00027 
00028 require_once '../include/constant.php';
00029 require_once('class_database.php');
00030 require_once('class_dossier.php');
00031 /*!\brief
00032  *  Received parameters are
00033  *   - j for the ledger
00034  *   - e for extra (typecard)
00035  *   - type is the ledger type (ach, ven, fin, gl or nothing)
00036  *   - FID contains the string the user is typing
00037  *\note the typecard can be
00038  *   - cred card for the debit only if j is set
00039  *   - deb card for the debit only if j is set
00040  *   - filter card for debit and credit only if j OR type is set
00041  *   - list of fd_id
00042  *
00043  */
00044 
00045 $jrn= ( ! isset($_REQUEST['j']))?-1:$_REQUEST['j'];
00046 $filter_card="";
00047 $cn=new Database(dossier::id());
00048 $d=$_REQUEST['e'];
00049 $filter_card='';
00050 
00051 require_once('class_user.php');
00052 global $g_user;
00053 $g_user=new User($cn);
00054 $g_user->check();
00055 $g_user->check_dossier(dossier::id());
00056 
00057 if ( $d == 'all')
00058 {
00059     $filter_card='';
00060 }
00061 else if (strpos($d,'sql]')==true)
00062 {
00063         $filter_card=  str_replace('[sql]', " and ", $d);
00064 } else
00065     $filter_card="and fd_id in ($d)";
00066 
00067 if ( $jrn != -1 )
00068 {
00069     switch ($d)
00070     {
00071     case 'cred':
00072         $filter_jrn=$cn->make_list("select jrn_def_fiche_cred from jrn_def where jrn_def_id=$1",array($jrn));
00073         $filter_card=($filter_jrn != "")?" and fd_id in ($filter_jrn)":' and false ';
00074         break;
00075     case 'deb':
00076         $filter_jrn=$cn->make_list("select jrn_def_fiche_deb from jrn_def where jrn_def_id=$1",array($jrn));
00077         $filter_card=($filter_jrn != "")?" and fd_id in ($filter_jrn)":' and false ';
00078         break;
00079     case 'filter':
00080         $get_cred='jrn_def_fiche_cred';
00081         $get_deb='jrn_def_fiche_deb';
00082                 $deb=$cn->get_value("select $get_deb from jrn_def where jrn_def_id=$1",array($jrn));
00083                 $cred=$cn->get_value("select $get_cred from jrn_def where jrn_def_id=$1",array($jrn));
00084 
00085                 $filter_jrn="";
00086 
00087                 if ($deb!=='' && $cred!='')
00088                         $filter_jrn     =$deb.','.$cred;
00089                 elseif($deb != '')
00090                         $filter_jrn=$deb;
00091                 elseif($cred != '')
00092                         $filter_jrn=$cred;
00093 
00094                 $filter_card=($filter_jrn != "")?" and fd_id in ($filter_jrn)":' and false ';
00095 
00096         break;
00097 
00098     }
00099 }
00100 else
00101 {
00102     if (isset($_REQUEST['type']))
00103     {
00104         if ($_REQUEST['type']=='gl' || $_REQUEST['type']=='') $filter_card='';
00105         else
00106         {
00107             $get_cred='jrn_def_fiche_cred';
00108             $get_deb='jrn_def_fiche_deb';
00109 
00110             $filter_jrn=$cn->make_list("select $get_cred||','||$get_deb as fiche from jrn_def where jrn_def_type=$1",array($_REQUEST['type']));
00111             $filter_card=($filter_jrn != "")?" and fd_id in ($filter_jrn)":' and false ';
00112 
00113         }
00114     }
00115 }
00116 
00117 
00118 /* create a filter based on j */
00119 /*$sql_str="select f_id, vw_name,quick_code,vw_description ".
00120   " from vw_fiche_attr where  ".
00121   " ( vw_name ilike '%'||$1||'%' or quick_code ilike $2||'%' or vw_description ilike '%'||$3||'%')    ".
00122   $filter_card;
00123 */
00124 
00125 $sql_str="select distinct f_id from fiche join fiche_detail using (f_id) where ad_id in (9,1,23) and ad_value ilike '%'||$1||'%' ".$filter_card.' limit 12';
00126 
00127 $sql=$cn->get_array($sql_str                ,array($_REQUEST['FID']));
00128 
00129 if (sizeof($sql) != 0 )
00130 {
00131     echo "<ul>";
00132     $sql_get=$cn->prepare('get_name',"select ad_value from fiche_detail where f_id = $1 and ad_id=$2");
00133 
00134     for ($i =0;$i<12 && $i < count($sql) ;$i++)
00135     {
00136         $name='';
00137         $quick_code='';
00138         $desc='';
00139 
00140         $sql_name=$cn->execute('get_name',array($sql[$i]['f_id'],1));
00141         if ( Database::num_row($sql_name) == 1) $name=Database::fetch_result($sql_name,0,0);
00142 
00143         $sql_name=$cn->execute('get_name',array($sql[$i]['f_id'],9));
00144         if ( Database::num_row($sql_name) == 1) $desc=Database::fetch_result($sql_name,0,0);
00145 
00146         $sql_name=$cn->execute('get_name',array($sql[$i]['f_id'],23));
00147         if (Database::num_row($sql_name) == 1) $quick_code=Database::fetch_result($sql_name,0,0);
00148 
00149 
00150         /* Highlight the found pattern with bold format */
00151         $name=str_ireplace($_REQUEST['FID'],'<em>'.$_REQUEST['FID'].'</em>',h($name));
00152         $qcode=str_ireplace($_REQUEST['FID'],'<em>'.$_REQUEST['FID'].'</em>',h($quick_code));
00153         $desc=str_ireplace($_REQUEST['FID'],'<em>'.$_REQUEST['FID'].'</em>',h($desc));
00154         printf('<li id="%s">%s <span class="informal"> %s %s</span></li>',
00155                $quick_code,
00156                $quick_code,
00157                $name,
00158                $desc
00159               );
00160     }
00161     echo '</ul>';
00162     if (count($sql) > 12)
00163     {
00164         printf ('<i>...'._('Résultat limité à 12').'  ...</i>');
00165     }
00166 }
00167 else
00168 {
00169     echo "<ul><li>"._("Non trouvé")."</li></ul>";
00170 }
00171 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations