noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
fid.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  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*!\file
00023  * \brief Fid for the ajax request for cards
00024  * \see fiche_search.php
00025  * Valid parameter GET are
00026  * - d type = cred, deb, all or filter or any sql where clause if the d starts with [sql]
00027  * - j is the legdger
00028  * - l field for the label
00029  * - t field for the tva_id
00030  * - p field for the price (sale)
00031  * - b field for the price (purchase)
00032  * - FID is the QuickCode
00033    *\note if the j is -1 then all the card are shown
00034  */
00035 require_once '../include/constant.php';
00036 require_once('class_own.php');
00037 require_once  ("constant.php");
00038 require_once('class_database.php');
00039 require_once ("user_common.php");
00040 require_once('class_dossier.php');
00041 $gDossier=dossier::id();
00042 
00043 require_once('class_user.php');
00044 
00045 $cn=new Database(dossier::id());
00046 global $g_user;
00047 $g_user=new User($cn);
00048 $g_user->check();
00049 $g_user->check_dossier(dossier::id());
00050 
00051 $fLabel=(isset($_REQUEST['l']))?$_REQUEST['l']:'none';
00052 $fTva_id=(isset($_REQUEST['t']))?$_REQUEST['t']:'none';
00053 $fPrice_sale=(isset($_REQUEST['p']))?$_REQUEST['p']:'none';
00054 $fPrice_purchase=(isset($_REQUEST['b']))?$_REQUEST['b']:'none';
00055 
00056 
00057 
00058 if ( isset($_SESSION['isValid']) && $_SESSION['isValid'] == 1)
00059 {
00060     $jrn=sql_string($_GET['j']);
00061     $d=sql_string($_GET['d']);
00062 
00063     if ( $jrn == -1 )
00064         $d='all';
00065     if ( strpos($d,'sql') == false )
00066     {
00067 
00068         switch ($d)
00069         {
00070         case 'cred':
00071             $filter_jrn=$cn->make_list("select jrn_def_fiche_cred from jrn_def where jrn_def_id=$1",array($jrn));
00072             $filter_card=($filter_jrn != "")?" and fd_id in ($filter_jrn)":' and false ';
00073 
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 'all':
00080             $filter_card="";
00081             break;
00082         case 'filter':
00083                          $get_cred='jrn_def_fiche_cred';
00084         $get_deb='jrn_def_fiche_deb';
00085                 $deb=$cn->get_value("select $get_deb from jrn_def where jrn_def_id=$1",array($jrn));
00086                 $cred=$cn->get_value("select $get_cred from jrn_def where jrn_def_id=$1",array($jrn));
00087 
00088                 $filter_jrn="";
00089 
00090                 if ($deb!=='' && $cred!='')
00091                         $filter_jrn     =$deb.','.$cred;
00092                 elseif($deb != '')
00093                         $filter_jrn=$deb;
00094                 elseif($cred != '')
00095                         $filter_jrn=$cred;
00096 
00097                 $filter_card=($filter_jrn != "")?" and fd_id in ($filter_jrn)":' and false ';
00098             break;
00099         case 'all':
00100             $filter_card='';
00101             break;
00102 
00103         default:
00104             $filter_card="and fd_id in ($d)";
00105         }
00106     }
00107     else
00108     {
00109         $filter_card=$d;
00110         $filter_card=str_replace('[sql]','',$d);
00111     }
00112     $sql="select vw_name,vw_addr,vw_cp,vw_buy,vw_sell,tva_id
00113          from vw_fiche_attr
00114          where quick_code=upper($1)". $filter_card;
00115 
00116     $array=$cn->get_array($sql,  array($_REQUEST['FID']));
00117 
00118     if ( empty($array))
00119     {
00120         echo '{"answer":"nok","flabel":"'.$fLabel.'"}';
00121         exit;
00122     }
00123 
00124 
00125     $name=$array[0]['vw_name'];
00126     $sell=$array[0]['vw_sell'] ;
00127     $buy=$array[0]['vw_buy'];
00128     $tva_id=$array[0]['tva_id'];
00129 
00130     // Check null
00131     $name=($name==null)?" ":str_replace('"','',$name);
00132     $sell=($sell==null)?" ":str_replace('"','',$sell);
00133     $buy=($buy==null)?" ":str_replace('"','',$buy);
00134     $tva_id=($tva_id==null)?" ":str_replace('"','',$tva_id);
00135     /* store the answer in an array and transform it later into a JSON object */
00136     $tmp=array();
00137     $tmp[]=array('flabel',$fLabel);
00138     $tmp[]=array('name',$name);
00139     $tmp[]=array('ftva_id',$fTva_id);
00140     $tmp[]=array('tva_id',$tva_id);
00141     $tmp[]=array('fPrice_sale',$fPrice_sale);
00142     $tmp[]=array('sell',$sell);
00143     $tmp[]=array('fPrice_purchase',$fPrice_purchase);
00144     $tmp[]=array('buy',$buy);
00145     $a='{"answer":"ok"';
00146     for ($o=0;$o < count($tmp);$o++)
00147     {
00148         $a.=sprintf(',"%s":"%s"',$tmp[$o][0],$tmp[$o][1]);
00149     }
00150     $a.='}';
00151 }
00152 else
00153     $a='{"answer":"unauthorized"}';
00154 header("Content-type: text/html; charset: utf8",true);
00155 print $a;
00156 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations