ajax_misc.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 /* $Revision: 5089 $ */
00021 
00022 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00023 
00024 /* !\file
00025  * \brief this file respond to an ajax request
00026  * The parameters are
00027  * - gDossier
00028  * - $op operation the file has to execute
00029  * Part 1
00030  * dsp_tva fill a ipopup with a choice of possible VAT
00031  *     - if code is set then fill the field code
00032  *     - if compute is set then add event to call clean_tva and compute_ledger
00033   @see Acc_Ledger_Sold::input
00034  * Part 2
00035  * dl : display form to modify, add and delete lettering for a given operation
00036  *
00037  */
00038 require_once('class_database.php');
00039 require_once ('class_fiche.php');
00040 require_once('class_iradio.php');
00041 require_once('function_javascript.php');
00042 require_once('ac_common.php');
00043 require_once ('class_user.php');
00044 mb_internal_encoding("UTF-8");
00045 
00046 $var = array('gDossier', 'op');
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 if ($cont != 0)
00058         exit();
00059 extract($_REQUEST);
00060 set_language();
00061 global $g_user, $cn, $g_parameter;
00062 $cn = new Database($gDossier);
00063 $g_user = new User($cn);
00064 $g_user->check(true);
00065 $g_user->check_dossier($gDossier, true);
00066 $html = var_export($_REQUEST, true);
00067 
00068 switch ($op)
00069 {
00070         case "remove_anc":
00071                 if ($g_user->check_module('ANCODS') == 0)
00072                         exit();
00073                 $cn->exec_sql("delete from operation_analytique where oa_group=$1", array($_GET['oa']));
00074                 break;
00075         case "rm_stock":
00076                 if ($g_user->check_module('STOCK') == 0)
00077                         exit();
00078                 require_once('constant.security.php');
00079                 $cn->exec_sql('delete from stock_goods where sg_id=$1', array($s_id));
00080                 $html = escape_xml($s_id);
00081                 header('Content-type: text/xml; charset=UTF-8');
00082                 printf('{"d_id":"%s"}', $s_id);
00083                 exit();
00084                 break;
00085         //--------------------------------------------------
00086         // get the last date of a ledger
00087         case 'lastdate':
00088                 require_once('class_acc_ledger_fin.php');
00089                 $ledger = new Acc_Ledger_Fin($cn, $_GET['p_jrn']);
00090                 $html = $ledger->get_last_date();
00091                 $html = escape_xml($html);
00092                 header('Content-type: text/xml; charset=UTF-8');
00093                 echo <<<EOF
00094 <?xml version="1.0" encoding="UTF-8"?>
00095 <data>
00096 <code>e_date</code>
00097 <value>$html</value>
00098 </data>
00099 EOF;
00100 
00101                 break;
00102         case 'bkname':
00103                 require_once('class_acc_ledger_fin.php');
00104                 $ledger = new Acc_Ledger_Fin($cn, $_GET['p_jrn']);
00105                 $html = $ledger->get_bank_name();
00106                 $html = escape_xml($html);
00107                 header('Content-type: text/xml; charset=UTF-8');
00108                 echo <<<EOF
00109 <?xml version="1.0" encoding="UTF-8"?>
00110 <data>
00111 <code>bkname</code>
00112 <value>$html</value>
00113 </data>
00114 EOF;
00115                 break;
00116         // display new calendar
00117         case 'cal':
00118                 require_once('class_calendar.php');
00119                 /* others report */
00120                 $cal = new Calendar();
00121                 $cal->set_periode($per);
00122 
00123                 $html = "";
00124                 $html = $cal->display();
00125                 $html = escape_xml($html);
00126                 header('Content-type: text/xml; charset=UTF-8');
00127                 echo <<<EOF
00128 <?xml version="1.0" encoding="UTF-8"?>
00129 <data>
00130 <code>$html</code>
00131 </data>
00132 EOF;
00133                 break;
00134         /* rem a cat of document */
00135         case 'rem_cat_doc':
00136                 require_once('class_document_type.php');
00137                 // if user can not return error message
00138                 if ($g_user->check_action(PARCATDOC) == 0)
00139                 {
00140                         $html = "nok";
00141                         header('Content-type: text/xml; charset=UTF-8');
00142                         echo <<<EOF
00143 <?xml version="1.0" encoding="UTF-8"?>
00144 <data>
00145 <dtid>$html</dtid>
00146 </data>
00147 EOF;
00148                         return;
00149                 }
00150                 // remove the cat if no action
00151                 $count_md = $cn->get_value('select count(*) from document_modele where md_type=$1', array($dt_id));
00152                 $count_a = $cn->get_value('select count(*) from action_gestion where ag_type=$1', array($dt_id));
00153 
00154                 if ($count_md != 0 || $count_a != 0)
00155                 {
00156                         $html = "nok";
00157                         header('Content-type: text/xml; charset=UTF-8');
00158                         echo <<<EOF
00159 <?xml version="1.0" encoding="UTF-8"?>
00160 <data>
00161 <dtid>$html</dtid>
00162 </data>
00163 EOF;
00164                         exit;
00165                 }
00166                 $cn->exec_sql('delete from document_type where dt_id=$1', array($dt_id));
00167                 $html = $dt_id;
00168                 header('Content-type: text/xml; charset=UTF-8');
00169                 echo <<<EOF
00170 <?xml version="1.0" encoding="UTF-8"?>
00171                                  <data>
00172                                  <dtid>$html</dtid>
00173                                  </data>
00174 EOF;
00175                 return;
00176                 break;
00177         case 'mod_cat_doc':
00178                 require_once 'template/document_mod_change.php';
00179                 break;
00180         case 'dsp_tva':
00181                 $cn = new Database($gDossier);
00182                 $Res = $cn->exec_sql("select * from tva_rate order by tva_rate desc");
00183                 $Max = Database::num_row($Res);
00184                 $r = "";
00185                 $r = HtmlInput::anchor_close('tva_select');
00186                 $r.=h2info('Choississez la TVA ');
00187                 $r.='<div >';
00188                 $r.= '<TABLE style="width:100%">';
00189                 $r.=th('');
00190                 $r.=th(_('code'));
00191                 $r.=th(_('Taux'));
00192                 $r.=th(_('Symbole'));
00193                 $r.=th(_('Explication'));
00194 
00195                 for ($i = 0; $i < $Max; $i++)
00196                 {
00197                         $row = Database::fetch_array($Res, $i);
00198                         if (!isset($compute))
00199                         {
00200                                 if (!isset($code))
00201                                 {
00202                                         $script = "onclick=\"$('$ctl').value='" . $row['tva_id'] . "';removeDiv('tva_select');\"";
00203                                 }
00204                                 else
00205                                 {
00206                                         $script = "onclick=\"$('$ctl').value='" . $row['tva_id'] . "';set_value('$code','" . $row['tva_label'] . "');removeDiv('tva_select');\"";
00207                                 }
00208                         }
00209                         else
00210                         {
00211                                 if (!isset($code))
00212                                 {
00213                                         $script = "onclick=\"$('$ctl').value='" . $row['tva_id'] . "';removeDiv('tva_select');clean_tva('$compute');compute_ledger('$compute');\"";
00214                                 }
00215                                 else
00216                                 {
00217                                         $script = "onclick=\"$('$ctl').value='" . $row['tva_id'] . "';set_value('$code','" . $row['tva_label'] . "');removeDiv('tva_select');clean_tva('$compute');compute_ledger('$compute');\"";
00218                                 }
00219                         }
00220                         $set = '<INPUT TYPE="BUTTON" class="button" Value="select" ' . $script . '>';
00221                         $class=($i%2 == 0)?' class="odd" ':' class="even" ';
00222                         $r.='<tr'.$class. '>';
00223                         $r.=td($set);
00224                         $r.=td($row['tva_id']);
00225                         $r.=td($row['tva_rate']);
00226                         $r.=td($row['tva_label']);
00227                         $r.=td($row['tva_comment']);
00228                         $r.='</tr>';
00229                 }
00230                 $r.='</TABLE>';
00231                 $r.='</div>';
00232                 $html = escape_xml($r);
00233 
00234                 header('Content-type: text/xml; charset=UTF-8');
00235                 echo <<<EOF
00236 <?xml version="1.0" encoding="UTF-8"?>
00237 <data>
00238 <code>$html</code>
00239 <popup>$popup</popup>
00240 </data>
00241 EOF;
00242                 break;
00243         case 'label_tva':
00244                 $cn = new Database($gDossier);
00245                 if (isNumber($id) == 0)
00246                         $value = _('tva inconnue');
00247                 else
00248                 {
00249                         $Res = $cn->get_array("select * from tva_rate where tva_id = $1", array($id));
00250                         if (count($Res) == 0)
00251                                 $value = _('tva inconnue');
00252                         else
00253                                 $value = $Res[0]['tva_label'];
00254                 }
00255                 header('Content-type: text/xml; charset=UTF-8');
00256                 echo <<<EOF
00257 <?xml version="1.0" encoding="UTF-8"?>
00258 <data>
00259 <code>$code</code>
00260 <value>$value</value>
00261 </data>
00262 EOF;
00263 
00264                 break;
00265         /**
00266          * display the lettering
00267          */
00268         case 'dl':
00269                 require_once('class_lettering.php');
00270                 $exercice = $g_user->get_exercice();
00271                 if ($g_user->check_module("LETCARD") == 0 && $g_user->check_module("LETACC") == 0)
00272                         exit();
00273                 $periode = new Periode($cn);
00274                 list($first_per, $last_per) = $periode->get_limit($exercice);
00275 
00276                 $ret = new IButton('return');
00277                 $ret->label = _('Retour');
00278                 $ret->javascript = "$('detail').hide();$('list').show();$('search').show();";
00279 
00280                 // retrieve info for the given j_id (date, amount,side and comment)
00281                 $sql = "select j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,J_POSTE,j_qcode,jr_id,
00282          jr_comment,j_montant, j_debit,jr_internal from jrnx join jrn on (j_grpt=jr_grpt_id)
00283          where j_id=$1";
00284                 $arow = $cn->get_array($sql, array($j_id));
00285                 $row = $arow[0];
00286                 $r = '';
00287                 $r.='<fieldset><legend>' . _('Lettrage') . '</legend>';
00288                 $r.='Poste ' . $row['j_poste'] . '  ' . $row['j_qcode'] . '<br>';
00289 
00290                 $detail = "<A class=\"detail\" style=\"display:inline\" HREF=\"javascript:modifyOperation('" . $row['jr_id'] . "'," . $gDossier . ")\" > " . $row['jr_internal'] . "</A>";
00291 
00292                 $r.='Date : ' . $row['j_date_fmt'] . ' ref :' . $detail . ' <br>  ';
00293                 $r.=h($row['jr_comment']) . " montant: " . ($row['j_montant']) . " " . (($row['j_debit'] == 't') ? 'D' : 'C');
00294                 $r.='</fieldset>';
00295                 $r.='<div id="filtre" style="float:left;display:block">';
00296                 $r.='<form method="get" id="search_form" onsubmit="search_letter(this);return false">';
00297                 $r.='<div style="float:left;">';
00298                 // needed hidden var
00299                 $r.=dossier::hidden();
00300                 if (isset($_REQUEST['ac']))
00301                         $r.=HtmlInput::hidden('ac', $_REQUEST['ac']);
00302                 if (isset($_REQUEST['sa']))
00303                         $r.=HtmlInput::hidden('sa', $_REQUEST['sa']);
00304                 if (isset($_REQUEST['acc']))
00305                         $r.=HtmlInput::hidden('acc', $_REQUEST['acc']);
00306                 $r.=HtmlInput::hidden('j_id', $j_id);
00307                 $r.=HtmlInput::hidden('op', $op);
00308                 $r.=HtmlInput::hidden('ot', $ot);
00309 
00310                 $r.='<table>';
00311                 //min amount
00312                 $line = td(_('Montant min. '));
00313                 $min = new INum('min_amount');
00314                 $min->value = (isset($min_amount)) ? $min_amount : $row['j_montant'];
00315                 $min_amount = (isset($min_amount)) ? $min_amount : $row['j_montant'];
00316 
00317                 $line.=td($min->input());
00318                 // max amount
00319                 $line.=td(_('Montant max. '));
00320                 $max = new INum('max_amount');
00321                 $max->value = (isset($max_amount)) ? $max_amount : $row['j_montant'];
00322                 $max_amount = (isset($max_amount)) ? $max_amount : $row['j_montant'];
00323                 $line.=td($max->input());
00324                 $r.=tr($line);
00325 
00326                 // start date
00327                 $start = new IDate('search_start');
00328                 $start->value = (isset($search_start)) ? $search_start : $first_per->first_day();
00329 
00330 
00331                 $line = td('Date Debut') . td($start->input());
00332                 // end date
00333                 $end = new IDate('search_end');
00334                 $end->value = (isset($search_end)) ? $search_end : $last_per->last_day();
00335                 $line.=td('Date Fin') . td($end->input());
00336                 $r.=tr($line);
00337                 // Side
00338                 $line = td('Debit / Credit');
00339                 $iside = new ISelect('side');
00340                 $iside->value = array(
00341                         array('label' => _('Debit'), 'value' => 0),
00342                         array('label' => _('Credit'), 'value' => 1),
00343                         array('label' => _('Les 2'), 'value' => 3)
00344                 );
00345                 /**
00346                  *
00347                  * if $side is not then
00348                  * - if jl_id exist and is > 0 show by default all the operation (=3)
00349                  * - if jl_id does not exist or is < 0 then show by default the opposite
00350                  *  side
00351                  */
00352                 if (!isset($side))
00353                 {
00354                         // find the jl_id of the j_id
00355                         $jl_id = $cn->get_value('select comptaproc.get_letter_jnt($1)', array($j_id));
00356                         if ($jl_id == null)
00357                         {
00358                                 // get the other side
00359                                 $iside->selected = (isset($side)) ? $side : (($row['j_debit'] == 't') ? 1 : 0);
00360                                 $side = (isset($side)) ? $side : (($row['j_debit'] == 't') ? 1 : 0);
00361                         }
00362                         else
00363                         {
00364                                 // show everything
00365                                 $iside->selected = 3;
00366                                 $side = 3;
00367                         }
00368                 }
00369                 else
00370                 {
00371                         $iside->selected = $side;
00372                 }
00373 
00374                 $r.=tr($line . td($iside->input()));
00375                 $r.='</table>';
00376                 $r.='</div>';
00377                 $r.='<div style="float:left;padding-left:100">';
00378                 $r.=HtmlInput::submit('search', 'Rechercher');
00379                 $r.='</div>';
00380                 $r.='</form>';
00381                 $r.='</div>';
00382 
00383                 $form = '<div id="result" style="float:top;clear:both">';
00384 
00385                 $form.='<FORM id="letter_form" METHOD="post">';
00386                 $form.=dossier::hidden();
00387                 if (isset($_REQUEST['p_action']))
00388                         $form.=HtmlInput::hidden('p_action', $_REQUEST['p_action']);
00389                 if (isset($_REQUEST['sa']))
00390                         $form.=HtmlInput::hidden('sa', $_REQUEST['sa']);
00391                 if (isset($_REQUEST['acc']))
00392                         $form.=HtmlInput::hidden('acc', $_REQUEST['acc']);
00393                 if (isset($_REQUEST['sc']))
00394                         $form.=HtmlInput::hidden('sc', $_REQUEST['sc']);
00395                 if (isset($_REQUEST['sb']))
00396                         $form.=HtmlInput::hidden('sb', $_REQUEST['sb']);
00397                 if (isset($_REQUEST['f_id']))
00398                         $form.=HtmlInput::hidden('f_id', $_REQUEST['f_id']);
00399                 /*  check if date are valid */
00400                 if ((isset($search_end) && isDate($search_end) == null) ||
00401                                 (isset($search_start) && isDate($search_start) == null))
00402                 {
00403                         ob_start();
00404                         alert(_('Date malformée, désolé'));
00405                         $html = ob_get_contents();
00406                         ob_clean();
00407 
00408                         $html = escape_xml($html);
00409 
00410                         header('Content-type: text/xml; charset=UTF-8');
00411                         echo <<<EOF
00412 <?xml version="1.0" encoding="UTF-8"?>
00413 <data>
00414 <code>detail</code>
00415 <value>$html</value>
00416 </data>
00417 EOF;
00418                         exit();
00419                 }
00420 
00421                 // display a list of operation from the other side + box button
00422                 if ($ot == 'account')
00423                 {
00424                         $obj = new Lettering_Account($cn, $row['j_poste']);
00425                         if (isset($search_start))
00426                                 $obj->start = $search_start;
00427                         if (isset($search_end))
00428                                 $obj->end = $search_end;
00429                         if (isset($max_amount))
00430                                 $obj->fil_amount_max = $max_amount;
00431                         if (isset($min_amount))
00432                                 $obj->fil_amount_min = $min_amount;
00433                         if (isset($side))
00434                                 $obj->fil_deb = $side;
00435 
00436                         $form.=$obj->show_letter($j_id);
00437                 }
00438                 else if ($ot == 'card')
00439                 {
00440                         $obj = new Lettering_Card($cn, $row['j_qcode']);
00441                         if (isset($search_start))
00442                                 $obj->start = $search_start;
00443                         if (isset($search_end))
00444                                 $obj->end = $search_end;
00445                         if (isset($max_amount))
00446                                 $obj->fil_amount_max = $max_amount;
00447                         if (isset($min_amount))
00448                                 $obj->fil_amount_min = $min_amount;
00449                         if (isset($side))
00450                                 $obj->fil_deb = $side;
00451                         $form.=$obj->show_letter($j_id);
00452                 }
00453                 else
00454                 {
00455                         $form.='Mauvais type objet';
00456                 }
00457 
00458                 $form.=HtmlInput::submit('record', _('Sauver')) . $ret->input();
00459                 $form.='</FORM>';
00460                 $form.='</div>';
00461                 $html = $r . $form;
00462                 //       echo $html;exit;
00463                 $html = escape_xml($html);
00464 
00465                 header('Content-type: text/xml; charset=UTF-8');
00466                 echo <<<EOF
00467 <?xml version="1.0" encoding="UTF-8"?>
00468 <data>
00469 <code>detail</code>
00470 <value>$html</value>
00471 </data>
00472 EOF;
00473                 break;
00474         case 'mod_doc':
00475                 require_once('ajax_mod_document.php');
00476                 break;
00477         case 'input_per':
00478                 require_once('ajax_mod_periode.php');
00479                 break;
00480         case 'save_per':
00481                 require_once('ajax_mod_periode.php');
00482                 break;
00483         case 'mod_predf':
00484                 require_once('ajax_mod_predf_op.php');
00485                 break;
00486         case 'save_predf':
00487                 require_once('ajax_save_predf_op.php');
00488                 break;
00489         case 'search_op':
00490                 require_once 'search.inc.php';
00491                 break;
00492         case 'search_action':
00493                 require_once 'ajax_search_action.php';
00494                 break;
00495         case 'display_profile':
00496                 require_once("ajax_get_profile.php");
00497                 break;
00498         case 'det_menu':
00499                 require_once("ajax_get_menu_detail.php");
00500                 break;
00501         case 'add_menu':
00502                 require_once 'ajax_add_menu.php';
00503                 break;
00504         case 'cardsearch':
00505                 require_once 'ajax_boxcard_search.php';
00506                 break;
00507         case 'add_plugin':
00508                 $me_code = new IText('me_code');
00509                 $me_file = new IText('me_file');
00510                 $me_menu = new IText('me_menu');
00511                 $me_description = new IText("me_description");
00512                 $me_parameter = new IText("me_parameter");
00513                 $new = true;
00514                 require_once 'ajax_plugin_detail.php';
00515                 break;
00516         case 'mod_plugin':
00517                 $m = $cn->get_array("select me_code,me_file,me_menu,me_description,me_parameter
00518                         from menu_ref where me_code=$1", array($me_code));
00519                 if (empty($m))
00520                 {
00521                         echo HtmlInput::title_box("Ce plugin n'existe pas ", $ctl);
00522                         echo "<p>Il y a une erreur, ce plugin n'existe pas";
00523                         exit;
00524                 }
00525                 $me_code = new IText('me_code', $m[0] ['me_code']);
00526                 $me_file = new IText('me_file', $m[0] ['me_file']);
00527                 $me_menu = new IText('me_menu', $m[0] ['me_menu']);
00528                 $me_description = new IText("me_description", $m[0] ['me_description']);
00529                 $me_parameter = new IText("me_parameter", $m[0] ['me_parameter']);
00530                 $new = false;
00531                 require_once 'ajax_plugin_detail.php';
00532                 break;
00533         case 'saldo':
00534                 require_once 'ajax_bank_saldo.php';
00535                 break;
00536         case 'up_predef':
00537                 require_once 'ajax_update_predef.php';
00538                 break;
00539         case 'upd_receipt':
00540                 require_once 'ajax_get_receipt.php';
00541                 break;
00542         case 'up_pay_method':
00543                 require_once 'ajax_update_payment.php';
00544                 break;
00545         case 'openancsearch':
00546         case 'resultancsearch':
00547                 require_once('ajax_anc_search.php');
00548                 break;
00549         case 'autoanc':
00550                 require_once 'ajax_auto_anc_card.php';
00551                 break;
00552         case 'create_menu';
00553                 require_once 'ajax_create_menu.php';
00554                 break;
00555         case 'modify_menu';
00556                 require_once 'ajax_mod_menu.php';
00557                 break;
00558         case 'mod_stock_repo':
00559                 require_once 'ajax_mod_stock_repo.php';
00560                 break;
00561         case 'view_mod_stock':
00562                 require_once 'ajax_view_mod_stock.php';
00563                 break;
00564         case 'fddetail':
00565                 require_once 'ajax_fiche_def_detail.php';
00566                 break;
00567         default:
00568                 var_dump($_GET);
00569 }