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 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 switch($op)
00098 {
00099
00100
00101
00102 case 'rmfa':
00103 if ($g_user->check_action(FICCAT)==0)exit();
00104 ob_start();
00105 if( ! isset($_GET['ad_id']) || isNumber($_GET['ad_id']) ==0)
00106 throw new Exception ( _("Parametre ad_id est invalide"),11);
00107 $ad_id= $_GET['ad_id'];
00108 try
00109 {
00110 $cn->start();
00111 $fa=new Fiche_Attr($cn,$ad_id);
00112 $fa->delete();
00113 $cn->commit();
00114 }
00115 catch (Exception $e)
00116 {
00117 $cn->rollback();
00118 echo $e->getMessage();
00119 }
00120 $html=ob_get_contents();
00121 ob_end_clean();
00122 break;
00123
00124
00125
00126
00127 case 'dc':
00128 $f=new Fiche($cn);
00129
00130 $html=HtmlInput::title_box(_("Détail fiche"), $ctl);
00131 if ( $qcode != '')
00132 {
00133 $f->get_by_qcode($qcode);
00134 $can_modify=$g_user->check_action(FIC);
00135 if ( isset($ro) )
00136 {
00137 $can_modify=0;
00138 }
00139 if ( $can_modify==1)
00140 $card=$f->Display(false);
00141 else
00142 $card=$f->Display(true);
00143 if ( $card == 'FNT' )
00144 {
00145 $html.='<h2 class="error">'._('Fiche non trouvée').'</h2>';
00146 }
00147 else
00148 {
00149
00150 if ($can_modify==1)
00151 {
00152 $html.='<form id="form_'.$ctl.'"method="get" onsubmit="update_card(this);return false;">';
00153 $html.=dossier::hidden();
00154 $html.=HtmlInput::hidden('f_id',$f->id);
00155 $html.=HtmlInput::hidden('ctl',$ctl);
00156 }
00157 $html.=$card;
00158 if ( $can_modify==1)
00159 {
00160 $html.=HtmlInput::submit('save',_('Sauver'));
00161 }
00162 $html.=HtmlInput::button('close_'.$ctl,'Fermer',"onclick=\"removeDiv('$ctl')\"");
00163 if ( ! isset ($nohistory))$html.=HtmlInput::history_card_button($f->id,_('Historique'));
00164 if ($can_modify==1)
00165 {
00166 $html.='</form>';
00167 }
00168 }
00169 }
00170 else
00171 {
00172 $html.='<h2 class="error">'._('Aucune fiche demandée').'</h2>';
00173 $html.=HtmlInput::button('close_'.$ctl,_('Fermer'),"onclick=\"removeDiv('$ctl')\"");
00174 }
00175 break;
00176
00177
00178
00179 case 'bc':
00180 if ( $g_user->check_action(FICADD)==1 )
00181 {
00182 $r=HtmlInput::title_box(_("Nouvelle fiche"), $ctl);
00183
00184 $cat_name=$cn->get_value('select fd_label from fiche_def where fd_id=$1',
00185 array($fd_id));
00186 $f=new Fiche($cn);
00187 $r.='<form id="save_card" method="POST" onsubmit="this.ipopup=\''.$ctl.'\';save_card(this);return false;" >';
00188 $r.=dossier::hidden();
00189 $r.=(isset($ref))?HtmlInput::hidden('ref',1):'';
00190 $r.=HtmlInput::hidden('fd_id',$fd_id);
00191 $r.=HtmlInput::hidden('ctl',$ctl);
00192 $r.=$f->blank($fd_id);
00193 $r.=HtmlInput::submit('sc',_('Sauve'));
00194 $r.='</form>';
00195 $html=$r;
00196 }
00197 else
00198 {
00199 $html=alert(_('Action interdite'),true);
00200 }
00201 break;
00202 /* ------------------------------------------------------------ */
00203 /* Show Type */
00204 /* Before inserting a new card, the type must be selected */
00205 /* ------------------------------------------------------------ */
00206 case 'st':
00207 $sql="select fd_id,fd_label from fiche_def";
00208 /* if we filter thanks the ledger*/
00209 if ( $ledger != -1 )
00210 {
00211 /* we want the card for deb or cred or both of this ledger */
00212 switch( $fil )
00213 {
00214 case -1:
00215 $l=new Acc_Ledger($cn,$ledger);
00216 $where=' where fd_id in ('.$l->get_all_fiche_def().')';
00217 break;
00218 case 'cred':
00219 $l=new Acc_Ledger($cn,$ledger);
00220 $prop=$l->get_propertie();
00221 if ( $prop['jrn_def_fiche_cred']=='')$prop=-1;
00222 $where=' where fd_id in ('.$prop['jrn_def_fiche_cred'].')';
00223 break;
00224 case 'deb':
00225 $l=new Acc_Ledger($cn,$ledger);
00226 $prop=$l->get_propertie();
00227 if ( $prop=='')$prop=-1;
00228 $where=' where fd_id in ('.$prop['jrn_def_fiche_deb'].')';
00229 break;
00230 }
00231 }
00232 else
00233 {
00234 /* we filter thanks a given model of card */
00235 if ( isset($cat))
00236 {
00237 $where=sprintf(' where frd_id in ('.sql_string ($cat).')');
00238 }
00239 else
00240 /* we filter thanks a given list of category of card
00241 */
00242 if ( isset($fil) && strlen(trim($fil)) > 0 )
00243 {
00244 $where=sprintf(" where fd_id in (%s)",
00245 sql_string($fil));
00246 }
00247 }
00248 if ( strpos($where," in ()") != 0)
00249 {
00250 $html=HtmlInput::anchor_close('select_card_div');
00251 $html.=h2info(_('Choix de la catégorie'));
00252 $html.='<h3 class="notice">';
00253 $html.=_("Aucune catégorie de fiche ne correspond à".
00254 " votre demande, le journal pourrait n'avoir accès à aucune fiche");
00255 $html.='</h3>';
00256 break;
00257 }
00258 $sql.=" ".$where." order by fd_label";
00259
00260 $array=$cn->make_array($sql);
00261 $html=HtmlInput::title_box(_("Choix de la catégorie"), $ctl);
00262
00263 if ( empty($array))
00264 {
00265 $html.=_("Aucune catégorie de fiche ne correspond à".
00266 " votre demande");
00267 if ( DEBUG ) $html.=$sql;
00268 }
00269 else
00270 {
00271 $r='';
00272 $r.='<p class="notice" style="padding-left:2em">';
00273 $r.=_("Choississez la catégorie de fiche à laquelle vous aimeriez ajouter une fiche").'</p>';
00274 $isel=new ISelect('fd_id');
00275 $isel->value=$array;
00276 $r.='<div style="text-align:center">';
00277 $r.='<form id="sel_type" method="GET" onsubmit="this.ipopup='.$ctl.';dis_blank_card(this);return false;" >';
00278 $r.=dossier::hidden();
00279 $r.=(isset($ref))?HtmlInput::hidden('ref',1):'';
00280
00281 $r.=$isel->input();
00282 $r.='<p>';
00283 $r.=HtmlInput::submit('st','choix');
00284 $r.=HtmlInput::button('Annuler',_('Annuler')," onclick=\"removeDiv('$ctl')\" ");
00285 $r.='</p>';
00286 $r.='</form>';
00287 $r.='</div>';
00288 $html.=$r;
00289
00290 }
00291 break;
00292 /*----------------------------------------------------------------------
00293 * SC save card
00294 * save the new card (insert)
00295 *
00296 ----------------------------------------------------------------------*/
00297 case 'sc':
00298 $html=HtmlInput::title_box(_("Choix de la catégorie"), $ctl);
00299 if ( $g_user->check_action(FICADD)==1 )
00300 {
00301 $f=new Fiche($cn);
00302 $f->insert($fd_id,$_POST);
00303 $f->Get();
00304 $html.='<h2 class="notice">'._('Fiche sauvée').'</h2>';
00305 $html.=$f->Display(true);
00306 $js="";
00307 if ( isset( $_POST['ref'])) $js=create_script(' window.location.reload()');
00308 $html.=$js;
00309 }
00310 else
00311 {
00312 $html.=alert(_('Action interdite'),true);
00313 }
00314 $html.=HtmlInput::button('fermer',_('Fermer')," onclick=\"removeDiv('$ctl')\";");
00315 break;
00316 /*----------------------------------------------------------------------
00317 * Search a card
00318 *
00319 *----------------------------------------------------------------------*/
00320 case 'fs':
00321 require_once('class_acc_ledger.php');
00322 $r=HtmlInput::title_box(_("Détail fiche"), 'search_card');
00323 $r.='<form method="GET" onsubmit="this.ctl=\'ipop_card\';search_get_card(this);return false;">';
00324 $q=new IText('query');
00325 $q->value=(isset($query))?$query:'';
00326 $r.='<span style="margin-left:50px">';
00327 $r.=_('Fiche contenant').HtmlInput::infobulle(19);
00328 $r.=$q->input();
00329 $r.=HtmlInput::submit('fs',_('Recherche'),"","smallbutton");
00330 $r.='</span>';
00331 $r.=dossier::hidden().HtmlInput::hidden('op','fs');
00332 $array=array();
00333 foreach (array('query','inp','jrn','label','typecard','price','tvaid') as $i)
00334 {
00335 if (isset(${$i}) )
00336 {
00337 $r.=HtmlInput::hidden($i,${$i});
00338 $sql_array[$i]=${$i};
00339 }
00340 }
00341 /* what is the type of the ledger */
00342 $type="GL";
00343 if (isset($jrn) && $jrn > 1)
00344 {
00345 $ledger=new Acc_Ledger($cn,$jrn);
00346 $type=$ledger->get_type();
00347 }
00348 $fiche=new Fiche($cn);
00349 /* Build the SQL and show result */
00350 $sql=$fiche->build_sql($sql_array);
00351
00352 if ( strpos($sql," in ()") != 0)
00353 {
00354 $html=HtmlInput::anchor_close('search_card');
00355 $html.='<div> '.h2info(_('Recherche de fiche')).'</div>';
00356 $html.='<h3 class="notice">';
00357 $html.=_("Aucune catégorie de fiche ne correspond à".
00358 " votre demande, le journal pourrait n'avoir accès à aucune fiche");
00359 $html.='</h3>';
00360 break;
00361 }
00362 /* We limit the search to MAX_SEARCH_CARD records */
00363 $sql=$sql.' order by vw_name limit '.MAX_SEARCH_CARD;
00364 $a=$cn->get_array($sql);
00365 for($i=0;$i<count($a);$i++)
00366 {
00367 $array[$i]['quick_code']=$a[$i]['quick_code'];
00368 $array[$i]['name']=h($a[$i]['vw_name']);
00369 $array[$i]['first_name']=h($a[$i]['vw_first_name']);
00370 $array[$i]['description']=h($a[$i]['vw_description']);
00371 $array[$i]['javascript']=sprintf("set_value('%s','%s');",
00372 $inp,$array[$i]['quick_code']);
00373 $array[$i]['javascript'].=sprintf("set_value('%s','%s');",
00374 $label,j(h(strip_tags($a[$i]['vw_name']))));
00375
00376 /* if it is a ledger of sales we use vw_buy
00377 if it is a ledger of purchase we use vw_sell*/
00378 if ( $type=="ACH" )
00379 $array[$i]['javascript'].=sprintf("set_value('%s','%s');",
00380 $price,$a[$i]['vw_buy']);
00381 if ( $type=="VEN" )
00382 $array[$i]['javascript'].=sprintf("set_value('%s','%s');",
00383 $price,$a[$i]['vw_sell']);
00384 $array[$i]['javascript'].=sprintf("set_value('%s','%s');",
00385 $tvaid,$a[$i]['tva_id']);
00386 $array[$i]['javascript'].="removeDiv('search_card');";
00387
00388 }//foreach
00389
00390 ob_start();
00391 require_once('template/card_result.php');
00392 $r.=ob_get_contents();
00393 ob_end_clean();
00394 $ctl=$ctl.'_content';
00395 $html=$r;
00396 break;
00397 case 'ac':
00398 if ( $g_user->check_action(FICCAT)==1 )
00399 {
00400
00401 /*----------------------------------------------------------------------
00402 * Add a category, display first the form
00403 *
00404 *----------------------------------------------------------------------*/
00405 $ipopup=str_replace('_content','',$ctl);
00406 switch($cat)
00407 {
00408 case FICHE_TYPE_CLIENT:
00409 $msg=_(' de clients');
00410 $base=$cn->get_value("select p_value from parm_code where p_code='CUSTOMER'");
00411 break;
00412 case FICHE_TYPE_FOURNISSEUR:
00413 $msg=_(' de fournisseurs');
00414 $base=$cn->get_value("select p_value from parm_code where p_code='SUPPLIER'");
00415 break;
00416 case FICHE_TYPE_ADM_TAX:
00417 $msg=_(' d\'administration');
00418 $base='';
00419 break;
00420 case FICHE_TYPE_CONTACT:
00421 $msg=_(' de contacts');
00422 $base='';
00423 }
00424
00425 $html='';
00426 /* show the form */
00427
00428 $search=new IPoste("class_base");
00429 $search->size=40;
00430 $search->value=$base;
00431 $search->label=_("Recherche poste");
00432 $search->set_attribute('gDossier',dossier::id());
00433 $search->set_attribute('account',$search->name);
00434 $search->set_attribute('ipopup','ipop_account');
00435
00436 $nom_mod=new IText("nom_mod");
00437 $str_poste=$search->input();
00438 $submit=HtmlInput::submit('save',_('Sauve'));
00439 ob_start();
00440 require('template/category_of_card.php');
00441 $html.=ob_get_contents();
00442 ob_end_clean();
00443
00444 }
00445 else
00446 {
00447 $html=alert(_('Action interdite'),true);
00448 }
00449 break;
00450 case 'scc':
00451 /*----------------------------------------------------------------------
00452 * Save card Category into the database and return a ok message
00453 *
00454 *----------------------------------------------------------------------*/
00455 $html='';
00456 if ( $g_user->check_action(FICCAT) == 1 )
00457 {
00458 $script=create_script("removeDiv('$ctl')");
00459 $html.=$script;
00460 if ( strlen(trim($_GET['nom_mod'])) != 0 &&
00461 strlen(trim($_GET['class_base'])) != 0 )
00462 {
00463 $array=array("FICHE_REF"=>$cat,
00464 "nom_mod"=>$_GET['nom_mod'],
00465 "class_base"=>$_GET['class_base']);
00466 if ( isset ($_POST['create'])) $array['create']=1;
00467 $catcard=new Fiche_Def($cn);
00468 if ( $catcard->Add($array) == -1)
00469 $script="alert('"._('Catégorie existe déjà')."')";
00470 else
00471 $script="alert('"._('Catégorie sauvée')."')";
00472 $html.=create_script($script);
00473 }
00474 else
00475 {
00476 $script="alert('"._("Le nom et la classe base ne peuvent être vide")."')";
00477 $html.=create_script($script);
00478
00479 $invalid=1;
00480 }
00481 }
00482 else
00483 {
00484 $html=alert(_('Action interdite'),true);
00485 }
00486 break;
00487 case 'upc':
00488 $html=HtmlInput::title_box("Détail fiche", $ctl);
00489
00490 if ( $g_user->check_action(FICADD)==0 )
00491 {
00492 $html.=alert(_('Action interdite'),true);
00493 }
00494 else
00495 {
00496 if ($cn->get_value('select count(*) from fiche where f_id=$1',array($_GET['f_id'])) == '0' )
00497 {
00498 $html.=alert(_('Fiche non valide'),true);
00499 }
00500
00501 else
00502 {
00503 $html=HtmlInput::anchor_close($ctl);
00504 $html.=h2info(_('Détail fiche (sauvée)'));
00505
00506 $f=new Fiche($cn,$_GET['f_id']);
00507 ob_start();
00508 $f->update($_GET);
00509 $html.=ob_get_contents();
00510 ob_end_clean();
00511 $html.=$f->Display(true);
00512 $html.=HtmlInput::button('close_'.$ctl,'Fermer',"onclick=\"removeDiv('$ctl')\"");
00513 }
00514 }
00515 }
00516 $html=escape_xml($html);
00517
00518 header('Content-type: text/xml; charset=UTF-8');
00519 echo <<<EOF
00520 <?xml version="1.0" encoding="UTF-8"?>
00521 <data>
00522 <ctl>$ctl</ctl>
00523 <code>$html</code>
00524 </data>
00525 EOF;