00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 if ( ! defined('ALLOWED')) define ('ALLOWED',1);
00057
00058 require_once '../include/constant.php';
00059 require_once('class_database.php');
00060 require_once ('class_fiche.php');
00061 require_once('class_iradio.php');
00062 require_once('function_javascript.php');
00063 require_once('ac_common.php');
00064 require_once ('class_user.php');
00065 require_once ('class_fiche_attr.php');
00066 mb_internal_encoding("UTF-8");
00067
00068 $var=array('gDossier','op','ctl');
00069 $cont=0;
00070
00071 foreach ($var as $v)
00072 {
00073 if ( ! isset ($_REQUEST [$v] ) )
00074 {
00075 echo "$v._(' is not set ')";
00076 $cont=1;
00077 }
00078 }
00079 extract($_REQUEST );
00080
00081 ajax_disconnected($ctl);
00082
00083 if ( $cont != 0 ) exit();
00084
00085 set_language();
00086
00087
00088
00089 ajax_disconnected($_REQUEST['ctl']);
00090
00091 $cn=new Database($gDossier);
00092 global $g_user;
00093 $g_user=new User($cn);
00094 $g_user->check(true);
00095 $g_user->check_dossier($gDossier,true);
00096 $html=var_export($_REQUEST,true);
00097 if ( LOGINPUT)
00098 {
00099 $file_loginput=fopen($_ENV['TMP'].'/scenario-'.$_SERVER['REQUEST_TIME'].'.php','a+');
00100 fwrite ($file_loginput,"<?php \n");
00101 fwrite ($file_loginput,'//@description:'.$op."\n");
00102 fwrite($file_loginput, '$_GET='.var_export($_GET,true));
00103 fwrite($file_loginput,";\n");
00104 fwrite($file_loginput, '$_POST='.var_export($_POST,true));
00105 fwrite($file_loginput,";\n");
00106 fwrite($file_loginput, '$_POST[\'gDossier\']=$gDossierLogInput;');
00107 fwrite($file_loginput,"\n");
00108 fwrite($file_loginput, '$_GET[\'gDossier\']=$gDossierLogInput;');
00109 fwrite($file_loginput,"\n");
00110 fwrite($file_loginput,' $_REQUEST=array_merge($_GET,$_POST);');
00111 fwrite($file_loginput,"\n");
00112 fwrite($file_loginput,"include '".basename(__FILE__)."';\n");
00113 fclose($file_loginput);
00114 }
00115 switch($op)
00116 {
00117
00118
00119
00120 case 'rmfa':
00121 if ($g_user->check_action(FICCAT)==0)exit();
00122 ob_start();
00123 if( ! isset($_GET['ad_id']) || isNumber($_GET['ad_id']) ==0)
00124 throw new Exception ( _("Parametre ad_id est invalide"),11);
00125 $ad_id= $_GET['ad_id'];
00126 try
00127 {
00128 $cn->start();
00129 $fa=new Fiche_Attr($cn,$ad_id);
00130 $fa->delete();
00131 $cn->commit();
00132 }
00133 catch (Exception $e)
00134 {
00135 $cn->rollback();
00136 echo $e->getMessage();
00137 }
00138 $html=ob_get_contents();
00139 ob_end_clean();
00140 break;
00141
00142
00143
00144
00145 case 'dc':
00146 $f=new Fiche($cn);
00147
00148 $html=HtmlInput::title_box(_("Détail fiche"), $ctl);
00149 if ( $qcode != '')
00150 {
00151 $f->get_by_qcode($qcode);
00152 $can_modify=$g_user->check_action(FIC);
00153 if ( isset($ro) )
00154 {
00155 $can_modify=0;
00156 }
00157 if ( $can_modify==1)
00158 $card=$f->Display(false);
00159 else
00160 $card=$f->Display(true);
00161 if ( $card == 'FNT' )
00162 {
00163 $html.='<h2 class="error">'._('Fiche non trouvée').'</h2>';
00164 }
00165 else
00166 {
00167
00168 if ($can_modify==1)
00169 {
00170 $html.='<form id="form_'.$ctl.'"method="get" onsubmit="update_card(this);return false;">';
00171 $html.=dossier::hidden();
00172 $html.=HtmlInput::hidden('f_id',$f->id);
00173 $html.=HtmlInput::hidden('ctl',$ctl);
00174 }
00175 $html.=$card;
00176 if ( $can_modify==1)
00177 {
00178 $html.=HtmlInput::submit('save',_('Sauver'));
00179 }
00180 $html.=HtmlInput::button('close_'.$ctl,'Fermer',"onclick=\"removeDiv('$ctl')\"");
00181 if ( ! isset ($nohistory))$html.=HtmlInput::history_card_button($f->id,_('Historique'));
00182 if ($can_modify==1)
00183 {
00184 $html.='</form>';
00185 }
00186 }
00187 }
00188 else
00189 {
00190 $html.='<h2 class="error">'._('Aucune fiche demandée').'</h2>';
00191 $html.=HtmlInput::button('close_'.$ctl,_('Fermer'),"onclick=\"removeDiv('$ctl')\"");
00192 }
00193 break;
00194
00195
00196
00197 case 'bc':
00198 if ( $g_user->check_action(FICADD)==1 )
00199 {
00200 $r=HtmlInput::title_box(_("Nouvelle fiche"), $ctl);
00201
00202 $cat_name=$cn->get_value('select fd_label from fiche_def where fd_id=$1',
00203 array($fd_id));
00204 $f=new Fiche($cn);
00205 $r.='<form id="save_card" method="POST" onsubmit="this.ipopup=\''.$ctl.'\';save_card(this);return false;" >';
00206 $r.=dossier::hidden();
00207 $r.=(isset($ref))?HtmlInput::hidden('ref',1):'';
00208 $r.=HtmlInput::hidden('fd_id',$fd_id);
00209 $r.=HtmlInput::hidden('ctl',$ctl);
00210 $r.=$f->blank($fd_id);
00211 $r.=HtmlInput::submit('sc',_('Sauve'));
00212 $r.='</form>';
00213 $html=$r;
00214 }
00215 else
00216 {
00217 $html=alert(_('Action interdite'),true);
00218 }
00219 break;
00220 /* ------------------------------------------------------------ */
00221 /* Show Type */
00222 /* Before inserting a new card, the type must be selected */
00223 /* ------------------------------------------------------------ */
00224 case 'st':
00225 $sql="select fd_id,fd_label,fd_description from fiche_def";
00226 /* if we filter thanks the ledger*/
00227 if ( $ledger != -1 )
00228 {
00229 /* we want the card for deb or cred or both of this ledger */
00230 switch( $fil )
00231 {
00232 case -1:
00233 $l=new Acc_Ledger($cn,$ledger);
00234 $where=' where fd_id in ('.$l->get_all_fiche_def().')';
00235 break;
00236 case 'cred':
00237 $l=new Acc_Ledger($cn,$ledger);
00238 $prop=$l->get_propertie();
00239 if ( $prop['jrn_def_fiche_cred']=='')$prop=-1;
00240 $where=' where fd_id in ('.$prop['jrn_def_fiche_cred'].')';
00241 break;
00242 case 'deb':
00243 $l=new Acc_Ledger($cn,$ledger);
00244 $prop=$l->get_propertie();
00245 if ( $prop=='')$prop=-1;
00246 $where=' where fd_id in ('.$prop['jrn_def_fiche_deb'].')';
00247 break;
00248 }
00249 }
00250 else
00251 {
00252 /* we filter thanks a given model of card */
00253 if ( isset($cat))
00254 {
00255 $where=sprintf(' where frd_id in ('.sql_string ($cat).')');
00256 }
00257 else
00258 /* we filter thanks a given list of category of card
00259 */
00260 if ( isset($fil) && strlen(trim($fil)) > 0 )
00261 {
00262 $where=sprintf(" where fd_id in (%s)",
00263 sql_string($fil));
00264 }
00265 }
00266 if ( strpos($where," in ()") != 0)
00267 {
00268 $html=HtmlInput::anchor_close('select_card_div');
00269 $html.=h2info(_('Choix de la catégorie'));
00270 $html.='<h3 class="notice">';
00271 $html.=_("Aucune catégorie de fiche ne correspond à".
00272 " votre demande, le journal pourrait n'avoir accès à aucune fiche");
00273 $html.='</h3>';
00274 break;
00275 }
00276 $sql.=" ".$where." order by fd_label";
00277
00278 $array=$cn->get_array($sql);
00279 $html=HtmlInput::title_box(_("Choix de la catégorie"), $ctl);
00280
00281 if ( empty($array))
00282 {
00283 $html.=_("Aucune catégorie de fiche ne correspond à".
00284 " votre demande");
00285 if ( DEBUG ) $html.=$sql;
00286 }
00287 else
00288 {
00289 $r='';
00290 $r.='<p style="padding-left:2em">';
00291 $r.=_("Choisissez la catégorie de fiche à laquelle vous aimeriez ajouter une fiche").'</p>';
00292
00293 $r.='<div style="text-align:center">';
00294
00295 $msg=_('Choisissez une catégorie svp');
00296 $r.='<form id="sel_type" method="GET" onsubmit="this.ipopup='.$ctl.";if ($('fd_id').value != 0 ) {dis_blank_card(this);return false;} else "
00297 . "{ $('error_cat').innerHTML='".$msg."'; return false;}\">" ;
00298 $r.='<span id="error_cat" class="notice"></span>';
00299 $r.=dossier::hidden();
00300 $r.=(isset($ref))?HtmlInput::hidden('ref',1):'';
00301 $r.=_('Filtrer').' '.HtmlInput::filter_table("cat_card_table", '0,1', 0);
00302 $r.='<table id="cat_card_table" class="result">';
00303 for ($i=0;$i<count($array);$i++)
00304 {
00305 $class=($i%2==0)?' class="even" ':' class="odd" ';
00306 $r.='<tr '.$class.' id="select_cat_row_'.$array[$i]['fd_id'].'">';
00307 $r.='<td >';
00308 $r.='<a href="javascript:void(0)" onclick="select_cat(\''.$array[$i]['fd_id'].'\')">'.h($array[$i]['fd_label']).'</a>';
00309 $r.='</td>';
00310 $r.='<td>';
00311 $r.='<a href="javascript:void(0)" onclick="select_cat(\''.$array[$i]['fd_id'].'\')">'.h($array[$i]['fd_description']).'</a>';
00312 $r.='</td>';
00313
00314 $r.="</tr>";
00315 }
00316 $r.='</table>';
00317 $r.=HtmlInput::hidden('fd_id',0);
00318 $r.='<p>';
00319 $r.=HtmlInput::submit('st','choix');
00320 $r.=HtmlInput::button('Annuler',_('Annuler')," onclick=\"removeDiv('$ctl')\" ");
00321 $r.='</p>';
00322 $r.='</form>';
00323 $r.='</div>';
00324 $html.=$r;
00325
00326 }
00327 break;
00328
00329
00330
00331
00332
00333 case 'sc':
00334 $html=HtmlInput::title_box(_("Choix de la catégorie"), $ctl);
00335 if ( $g_user->check_action(FICADD)==1 )
00336 {
00337 $f=new Fiche($cn);
00338 $f->insert($fd_id,$_POST);
00339 $f->Get();
00340 $html.='<h2 class="notice">'._('Fiche sauvée').'</h2>';
00341 $html.=$f->Display(true);
00342 $js="";
00343 if ( isset( $_POST['ref'])) $js=create_script(' window.location.reload()');
00344 $html.=$js;
00345 }
00346 else
00347 {
00348 $html.=alert(_('Action interdite'),true);
00349 }
00350 $html.=HtmlInput::button('fermer',_('Fermer')," onclick=\"removeDiv('$ctl')\";");
00351 break;
00352
00353
00354
00355
00356 case 'fs':
00357 require_once('class_acc_ledger.php');
00358 $r=HtmlInput::title_box(_("Détail fiche"), 'search_card');
00359 $r.='<form method="GET" onsubmit="this.ctl=\'ipop_card\';search_get_card(this);return false;">';
00360 $q=new IText('query');
00361 $q->value=(isset($query))?$query:'';
00362 $r.='<span style="margin-left:50px">';
00363 $r.=_('Fiche contenant').HtmlInput::infobulle(19);
00364 $r.=$q->input();
00365 $r.=HtmlInput::submit('fs',_('Recherche'),"","smallbutton");
00366 $r.='</span>';
00367 $r.=dossier::hidden().HtmlInput::hidden('op','fs');
00368 $array=array();
00369 foreach (array('query','inp','jrn','label','typecard','price','tvaid') as $i)
00370 {
00371 if (isset(${$i}) )
00372 {
00373 $r.=HtmlInput::hidden($i,${$i});
00374 $sql_array[$i]=${$i};
00375 }
00376 }
00377
00378 $type="GL";
00379 if (isset($jrn) && $jrn > 1)
00380 {
00381 $ledger=new Acc_Ledger($cn,$jrn);
00382 $type=$ledger->get_type();
00383 }
00384 $fiche=new Fiche($cn);
00385
00386 $sql=$fiche->build_sql($sql_array);
00387
00388 if ( strpos($sql," in ()") != 0)
00389 {
00390 $html=HtmlInput::anchor_close('search_card');
00391 $html.='<div> '.h2info(_('Recherche de fiche')).'</div>';
00392 $html.='<h3 class="notice">';
00393 $html.=_("Aucune catégorie de fiche ne correspond à".
00394 " votre demande, le journal pourrait n'avoir accès à aucune fiche");
00395 $html.='</h3>';
00396 break;
00397 }
00398
00399 $sql=$sql.' order by vw_name limit '.MAX_SEARCH_CARD;
00400 $a=$cn->get_array($sql);
00401 for($i=0;$i<count($a);$i++)
00402 {
00403 $array[$i]['quick_code']=$a[$i]['quick_code'];
00404 $array[$i]['name']=h($a[$i]['vw_name']);
00405 $array[$i]['accounting']=$a[$i]['accounting'];
00406 $array[$i]['first_name']=h($a[$i]['vw_first_name']);
00407 $array[$i]['description']=h($a[$i]['vw_description']);
00408 $array[$i]['javascript']=sprintf("set_value('%s','%s');",
00409 $inp,$array[$i]['quick_code']);
00410 $array[$i]['javascript'].=sprintf("set_value('%s','%s');",
00411 $label,j(h(strip_tags($a[$i]['vw_name']))));
00412
00413
00414
00415 if ( $type=="ACH" )
00416 $array[$i]['javascript'].=sprintf("set_value('%s','%s');",
00417 $price,$a[$i]['vw_buy']);
00418 if ( $type=="VEN" )
00419 $array[$i]['javascript'].=sprintf("set_value('%s','%s');",
00420 $price,$a[$i]['vw_sell']);
00421 $array[$i]['javascript'].=sprintf("set_value('%s','%s');",
00422 $tvaid,$a[$i]['tva_id']);
00423 $array[$i]['javascript'].="removeDiv('search_card');";
00424
00425 }
00426
00427 ob_start();
00428 require_once('template/card_result.php');
00429 $r.=ob_get_contents();
00430 ob_end_clean();
00431 $ctl=$ctl.'_content';
00432 $html=$r;
00433 break;
00434 case 'action_add_concerned_card':
00435 require_once 'ajax_add_concerned_card.php';
00436 return;
00437 break;
00438 case 'action_save_concerned':
00439 require 'ajax_action_save_concerned.php';
00440 return;
00441 case 'action_remove_concerned':
00442 require 'ajax_action_remove_concerned.php';
00443 return;
00444 case 'ac':
00445 if ( $g_user->check_action(FICCAT)==1 )
00446 {
00447
00448
00449
00450
00451
00452 $ipopup=str_replace('_content','',$ctl);
00453 $msg="";$base="";
00454 switch($cat)
00455 {
00456 case FICHE_TYPE_CLIENT:
00457 $msg=_(' de clients');
00458 $base=$cn->get_value("select p_value from parm_code where p_code='CUSTOMER'");
00459 break;
00460 case FICHE_TYPE_FOURNISSEUR:
00461 $msg=_(' de fournisseurs');
00462 $base=$cn->get_value("select p_value from parm_code where p_code='SUPPLIER'");
00463 break;
00464 case FICHE_TYPE_ADM_TAX:
00465 $msg=_(' d\'administration');
00466 $base='';
00467 break;
00468 case FICHE_TYPE_CONTACT:
00469 $msg=_(' de contacts');
00470 $base='';
00471 case FICHE_TYPE_FIN:
00472 $msg=_(' Banque');
00473 $base=$cn->get_value("select p_value from parm_code where p_code='BANQUE'");
00474
00475 }
00476
00477 $html='';
00478
00479
00480 $search=new IPoste("class_base");
00481 $search->size=40;
00482 $search->value=$base;
00483 $search->label=_("Recherche poste");
00484 $search->set_attribute('gDossier',dossier::id());
00485 $search->set_attribute('account',$search->name);
00486 $search->set_attribute('ipopup','ipop_account');
00487
00488 $nom_mod=new IText("nom_mod");
00489 $str_poste=$search->input();
00490 $submit=HtmlInput::submit('save',_('Sauve'));
00491 ob_start();
00492 require('template/category_of_card.php');
00493 $html.=ob_get_contents();
00494 ob_end_clean();
00495
00496 }
00497 else
00498 {
00499 $html=alert(_('Action interdite'),true);
00500 }
00501 break;
00502 case 'scc':
00503
00504
00505
00506
00507 $html='';
00508 if ( $g_user->check_action(FICCAT) == 1 )
00509 {
00510 $script=create_script("removeDiv('$ctl')");
00511 $html.=$script;
00512 if ( strlen(trim($_GET['nom_mod'])) != 0 &&
00513 strlen(trim($_GET['class_base'])) != 0 )
00514 {
00515 $array=array("FICHE_REF"=>$cat,
00516 "nom_mod"=>$_GET['nom_mod'],
00517 "class_base"=>$_GET['class_base']);
00518 if ( isset ($_POST['create'])) $array['create']=1;
00519 $catcard=new Fiche_Def($cn);
00520 if ( $catcard->Add($array) == -1)
00521 $script="alert('"._('Catégorie existe déjà')."')";
00522 else
00523 $script="alert('"._('Catégorie sauvée')."')";
00524 $html.=create_script($script);
00525 }
00526 else
00527 {
00528 $script="alert('"._("Le nom et la classe base ne peuvent être vide")."')";
00529 $html.=create_script($script);
00530
00531 $invalid=1;
00532 }
00533 }
00534 else
00535 {
00536 $html=alert(_('Action interdite'),true);
00537 }
00538 break;
00539 case 'upc':
00540 $html=HtmlInput::title_box("Détail fiche", $ctl);
00541
00542 if ( $g_user->check_action(FICADD)==0 )
00543 {
00544 $html.=alert(_('Action interdite'),true);
00545 }
00546 else
00547 {
00548 if ($cn->get_value('select count(*) from fiche where f_id=$1',array($_GET['f_id'])) == '0' )
00549 {
00550 $html.=alert(_('Fiche non valide'),true);
00551 }
00552
00553 else
00554 {
00555 $html=HtmlInput::title_box(_('Détail fiche (sauvée)'),$ctl);
00556
00557 $f=new Fiche($cn,$_GET['f_id']);
00558 ob_start();
00559 $f->update($_GET);
00560 $html.=ob_get_contents();
00561 ob_end_clean();
00562 $html.=$f->Display(true);
00563 $html.=HtmlInput::button('close_'.$ctl,'Fermer',"onclick=\"removeDiv('$ctl')\"");
00564 }
00565 }
00566 }
00567 $xml=escape_xml($html);
00568 if (DEBUG && headers_sent()) {
00569 echo $html;return;
00570 }
00571 header('Content-type: text/xml; charset=UTF-8');
00572 echo <<<EOF
00573 <?xml version="1.0" encoding="UTF-8"?>
00574 <data>
00575 <ctl>$ctl</ctl>
00576 <code>$xml</code>
00577 </data>
00578 EOF;