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