noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
ajax_account_update.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  *   This file is part of PhpCompta.
00005  *
00006  *   PhpCompta is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   PhpCompta is distributed in the hope that it will be useful,
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 PhpCompta; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 // Copyright (2014) Author Dany De Bontridder <dany@alchimerys.be>
00021 
00022 if (!defined('ALLOWED'))    die('Appel direct ne sont pas permis');
00023 
00024 /**
00025  * @file
00026  * @brief delete insert or update data from account_update (need right CFGPCMN)
00027  * called from ajax_misc.php
00028  * @param array
00029  * @code
00030  *   'op' => string 'account_update' (length=14)
00031   'gDossier' => string '44' (length=2)
00032   'action' => string 'update' (length=6)
00033   'p_oldu' => string '4124' (length=4)
00034   'p_valu' => string '4124' (length=4)
00035   'p_libu' => string 'Impôt belge sur le résultat' (length=29)
00036   'p_parentu' => string '412' (length=3)
00037   'acc_delete' => string '0' (length=1)
00038   'p_typeu' => string '0' (length=1)
00039  * @endcode
00040  */
00041 if ($g_user->check_module('CFGPCMN') == 0)
00042                         exit();
00043 
00044 $var=array('action', 'p_oldu', 'p_valu', 'p_libu', 'p_parentu', 'acc_delete', 'p_typeu');
00045 for ($i=0; $i<count($var); $i++)
00046 {
00047     $name=$var[$i];
00048     if (!isset($$name))
00049         throw new Exception($name." is not set");
00050 }
00051 $ctl='ok';
00052 extract($_GET);
00053 //----------------------------------------------------------------------
00054 // Modification
00055 //----------------------------------------------------------------------
00056 $message=_("opération réussie");
00057 
00058 if ($action=="update" &&$acc_delete==0)
00059 {
00060     // Check if the data are correct
00061     try
00062     {
00063         $p_val=trim($p_valu);
00064         $p_lib=trim($p_libu);
00065         $p_parent=trim($p_parentu);
00066         $old_line=trim($p_oldu);
00067         $p_type=htmlentities($p_typeu);
00068         $acc=new Acc_Account($cn);
00069         $acc->set_parameter('libelle', $p_lib);
00070         $acc->set_parameter('value', $p_val);
00071         $acc->set_parameter('parent', $p_parent);
00072         $acc->set_parameter('type', $p_type);
00073         $acc->check();
00074     }
00075     catch (Exception $e)
00076     {
00077         $message=_("Valeurs invalides, pas de changement")." \n ".
00078                 $e->getMessage();
00079         $ctl='nok';
00080     }
00081     if (strlen($p_val)!=0&&strlen($p_lib)!=0&&strlen($old_line)!=0)
00082     {
00083         if (strlen($p_val)==1)
00084         {
00085             $p_parent=0;
00086         }
00087         else
00088         {
00089             if (strlen($p_parent)==0)
00090             {
00091                 $p_parent=substr($p_val, 0, strlen($p_val)-1);
00092             }
00093         }
00094         /* Parent existe */
00095         $Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1", array($p_parent));
00096         if (($p_parent!=0&&Database::num_row($Ret)==0)||$p_parent==$old_line)
00097         {
00098             $message=_("Ne peut pas modifier; aucun poste parent");
00099             $ctl='nok';
00100         }
00101         else
00102         {
00103             try
00104             {
00105                 $acc->update($old_line);
00106             }
00107             catch (Exception $e)
00108             {
00109                 $message=$e->getMessage();
00110                 $ctl='nok';
00111             }
00112         }
00113     }
00114     else
00115     {
00116         $message=_('Update Valeurs invalides');
00117         $ctl='nok';
00118     }
00119 }
00120 //-----------------------------------------------------
00121 /* Ajout d'une ligne */
00122 if ($action=="new")
00123 {
00124     $p_val=trim($p_valu);
00125     $p_parent=trim($p_parentu);
00126 
00127     if (isset($p_valu)&&isset($p_libu))
00128     {
00129         $p_val=trim($p_valu);
00130 
00131         if (strlen($p_valu)!=0&&strlen($p_libu)!=0)
00132         {
00133             if (strlen($p_valu)==1)
00134             {
00135                 $p_parentu=0;
00136             }
00137             else
00138             {
00139                 if (strlen(trim($p_parentu))==0&&
00140                         (string) $p_parentu!=(string) (int) $p_parentu)
00141                 {
00142                     $p_parentu=substr($p_val, 0, strlen($p_valu)-1);
00143                 }
00144             }
00145             /* Parent existe */
00146             $Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1", array($p_parentu));
00147             if ($p_parent!=0&&Database::num_row($Ret)==0)
00148             {
00149                 $message=_(" Ne peut pas modifier; aucun poste parent");
00150                 $ctl='nok';
00151             }
00152             else
00153             {
00154                 // Check if the account already exists
00155 
00156                 $Count=$cn->get_value("select count(*) from tmp_pcmn where pcm_val=$1", array($p_val));
00157                 if ($Count!=0)
00158                 {
00159                     // Alert message account already exists
00160                     $message=_("Ce poste existe déjà ");
00161                     $ctl='nok';
00162                 }
00163                 else
00164                 {
00165                     $Ret=$cn->exec_sql("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values ($1,$2,$3,$4)", array($p_val, $p_libu, $p_parent, $p_typeu));
00166                 }
00167             }
00168         }
00169         else
00170         {
00171             $message=_("Valeurs invalides ");
00172             $ctl='nok';
00173         }
00174     }
00175 }
00176 
00177 //-----------------------------------------------------
00178 // Action == remove a line
00179 if ($action=="update"&&$acc_delete==1)
00180 {
00181     /* Ligne a enfant */
00182     $R=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val_parent=$1", array($p_valu));
00183     if (Database::num_row($R)!=0)
00184     {
00185         $message=_("Ne peut pas effacer le poste: d'autres postes en dépendent");
00186         $ctl='nok';
00187     }
00188     else
00189     {
00190         /* Vérifier que le poste n'est pas utilisé qq part dans les journaux */
00191         $Res=$cn->exec_sql("select * from jrnx where j_poste=$1", array($p_valu));
00192         if (Database::num_row($Res)!=0)
00193         {
00194             $message=_("Ne peut pas effacer le poste: il est utilisé dans les journaux");
00195             $ctl='nok';
00196         }
00197         else
00198         {
00199             $Del=$cn->exec_sql("delete from tmp_pcmn where pcm_val=$1", array($p_valu));
00200         } // if Database::num_row
00201     } // if Database::num_row
00202 } //$action == del
00203 $message=escape_xml($message);
00204  if ( ! headers_sent()) {     header('Content-type: text/xml; charset=UTF-8');} else { echo "HTML".unescape_xml($html);}
00205  
00206  echo <<<EOF
00207 <?xml version="1.0" encoding="UTF-8"?>
00208 <data>
00209 <ctl>$ctl</ctl>
00210 <code>$message</code>
00211 </data>
00212 EOF;
00213 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations