noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
ajax_poste.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 this file answer to the Ajax request from js/accounting_item.js
00024  * - op
00025     - sf  show form of search
00026          - param j : ledger -> php jrn
00027          - param c : control for storing the pcm_val -> javascript account
00028          - param l : control for storing the pcm_lib -> javascript label
00029          - param ctl : the node to update (ipopup)
00030          - param q : the acc_query -> javascript query
00031  * - ctl (to return)
00032  *
00033  *
00034  */
00035 define ('ALLOWED',1);
00036 require_once '../include/constant.php';
00037 require_once  ("ac_common.php");
00038 require_once('class_acc_ledger.php');
00039 require_once ('class_database.php');
00040 require_once('function_javascript.php');
00041 require_once('class_acc_account_ledger.php');
00042 mb_internal_encoding("UTF-8");
00043 
00044 extract($_REQUEST);
00045 $var=array('gDossier','op','ctl');
00046 $cont=0;
00047 /*  check if mandatory parameters are given */
00048 foreach ($var as $v)
00049 {
00050     if ( ! isset ($_REQUEST [$v] ) )
00051     {
00052         echo "$v is not set ";
00053         $cont=1;
00054     }
00055 }
00056 ajax_disconnected($ctl);
00057 
00058 set_language();
00059 
00060 if ( $cont != 0 ) exit();
00061 $cn=new Database(dossier::id());
00062 include_once ("class_user.php");
00063 global $g_user;
00064 $g_user=new User($cn);
00065 $g_user->Check();
00066 if  ($g_user->check_dossier(dossier::id()) == 'X') exit();
00067 $xml="";
00068 
00069 switch ($op)
00070 {
00071     /*----------------------------------------------------------------------
00072      * Show the form and the result
00073      *
00074      ----------------------------------------------------------------------*/
00075 case "sf":
00076         $ipopup=$ctl;
00077     $attr=sprintf('this.ctl=\'%s\';',$ipopup);
00078     $ctl.='_content';
00079     $it=new IText('acc_query');
00080     $it->size=30;
00081     $it->value=(isset($q))?$q:'';
00082     $str_poste=$it->input();
00083     $str_submit=HtmlInput::submit('sf',_('Recherche'),"","smallbutton");
00084     $r='';
00085         $r=HtmlInput::anchor_close('search_account');
00086     $r.='<div> '.h2(_('Poste Comptable'),' class="title"').'</div>';
00087 
00088     $r.='<form id="sp" method="get" onsubmit="'.$attr.'search_get_poste(this);return false;">';
00089     ob_start();
00090     require_once('template/account_search.php');
00091     $r.=ob_get_contents();
00092     ob_end_clean();
00093     $r.=dossier::hidden();
00094     $r.=(isset ($c))?HtmlInput::hidden('account',$c):"";
00095     $r.=(isset ($l))?HtmlInput::hidden('label',$l):"";
00096     $r.=(isset ($j))?HtmlInput::hidden('jrn',$j):"";
00097     $r.=(isset ($nover))?HtmlInput::hidden('nover','1'):"";
00098     $r.=(isset ($nosearch))?HtmlInput::hidden('nosearch','1'):"";
00099     $r.=(isset ($bracket))?HtmlInput::hidden('bracket','1'):"";
00100 
00101 
00102     $r.='</form>';
00103     $sql="
00104                 select pcm_val,pcm_lib,array_to_string(array_agg(j_qcode) , ',') as acode
00105                 from tmp_pcmn left join vw_poste_qcode on (j_poste=pcm_val) ";
00106     $sep=" where ";
00107     /* build the sql stmt */
00108     if ( isset($j) && $j > 0 && isNumber($j))
00109     {
00110         /* create a filter on the ledger */
00111         $ledger=new Acc_Account_Ledger($cn,0);
00112         $fd_id=$ledger->build_sql_account($j);
00113         if ( $fd_id != '' )
00114         {
00115             $sql.=" $sep (".$fd_id.')';
00116             $sep=" and ";
00117         }
00118     }
00119     /* show result */
00120     if ( isset($q) && strlen(trim($q)) > 0)
00121     {
00122         $q= sql_string($q);
00123         $sql.=sprintf(" $sep ( pcm_val::text like '%s%%' or pcm_lib::text ilike '%%%s%%') ",
00124                       $q,$q);
00125     }
00126     $sql.=' group by pcm_val,pcm_lib,pcm_val_parent, pcm_type  order by pcm_val::text limit 50';
00127     if ( isset($q) && strlen(trim($q))> 0 )
00128     {
00129         $array=$cn->get_array($sql);
00130     }
00131     if ( ! isset($q) ) $array=array();
00132     if ( isset($q) && strlen(trim($q))==0) $array=array();
00133 
00134     /*  set the javascript */
00135     for ($i=0;$i<count($array);$i++)
00136     {
00137         $pcm_val=$array[$i]['pcm_val'];
00138         if ( isset($bracket))
00139         {
00140             $pcm_val='['.$pcm_val.']';
00141         }
00142         if (isset($nover))
00143         {
00144             /* no overwrite  */
00145             $str=sprintf("$('%s').value=$('%s').value+' '+'%s';",
00146                          $c,$c,$pcm_val);
00147 
00148         }
00149         else
00150         {
00151             $str=sprintf("$('%s').value='%s';",
00152                          $c,$pcm_val);
00153         }
00154 
00155         if ( isset($l) )
00156         {
00157             $str.=sprintf("set_value('%s',g('%s').innerHTML);",
00158                           $l,"lib$i");
00159 
00160         }
00161         $str.="removeDiv('search_account');";
00162         $array[$i]['javascript']=$str;
00163     }
00164     ob_start();
00165 
00166     require_once('template/account_result.php');
00167     $r.=ob_get_contents();
00168     ob_end_clean();
00169 
00170     $html=$r;
00171     break;
00172 }
00173 $html=escape_xml($html);
00174 header('Content-type: text/xml; charset=UTF-8');
00175 echo <<<EOF
00176 <?xml version="1.0" encoding="UTF-8"?>
00177 <data>
00178 <ctl>$ctl</ctl>
00179 <code>$html</code>
00180 </data>
00181 EOF;
 All Data Structures Namespaces Files Functions Variables Enumerations