check(true);
$g_user->check_dossier($gDossier,true);
$html=var_export($_REQUEST,true);
// For storing extra information , example the HTML elt id to update
// after creating
$extra="";
$http=new \HttpInput();
switch($op2)
{
case 'attribute':
require_once "ajax/ajax_card_attribute.php";
return ;
/* ------------------------------------------------------------ */
/* Display card detail */
/* ------------------------------------------------------------ */
case 'dc':
$f=new Fiche($cn);
/* add title + close */
$qcode=$http->request("qcode","string",false);
// if there is no qcode then try to find it thanks the card id
if ( $qcode == false ){
$f->id=$http->get("f_id","number","0");
if ( $f->id==0) {
$html=HtmlInput::title_box(_("Fiche"), $ctl,"close","","y");
$html.='
'._('Aucune fiche demandée').'
';
break;
}
$qcode=$f->get_quick_code();
} else {
$f->get_by_qcode($qcode);
}
$title=$f->getLabelCategory();
$html=HtmlInput::title_box($title, $ctl,"close","","y");
// after save , we can either show a card in readonly or update a row
$safter_save=$http->request("after_save","string","1");
switch ($safter_save)
{
case "1":
// show a card it readonly and fade it
$after_save="update_card(this)";
break;
case "2":
// update a row in the table X
$after_save="card_update_row(this)";
break;
default:
break;
}
if ( $qcode != null)
{
$can_modify=$g_user->check_action(FIC);
if ( isset($ro) )
{
$can_modify=0;
}
if ( $can_modify==1)
$card=$f->Display(false,$ctl);
else
$card=$f->Display(true);
if ( $card == 'FNT' )
{
$html.=''._('Fiche non trouvée').'
';
$html.=''.HtmlInput::button_close($ctl).'
';
}
else
{
if ($can_modify==1)
{
$html.='';
}
}
}
else
{
$html.=''._('Aucune fiche demandée').'
';
}
break;
/* ------------------------------------------------------------ */
/* Blank card */
/* ------------------------------------------------------------ */
case 'bc':
if ( $g_user->check_action(FICADD)==1 || $g_user->check_action(FIC)==1)
{
/* get cat. name */
$cat_name=$cn->get_value('select fd_label from fiche_def where fd_id=$1',
array($fd_id));
$r=HtmlInput::title_box($cat_name, $ctl,p_draggable:true);
$f=new Fiche($cn);
$r.='';
$html=$r;
}
else
{
$html=alert(_('Action interdite'),true);
}
break;
/* ------------------------------------------------------------ */
/* Show Type */
/* Before inserting a new card, the type must be selected */
/* ------------------------------------------------------------ */
case 'st':
$sql="select fd_id,fd_label,fd_description from fiche_def";
/* if we filter thanks the ledger*/
if ( $ledger != -1 )
{
/* we want the card for deb or cred or both of this ledger */
switch( $fil )
{
case -1:
$l=new Acc_Ledger($cn,$ledger);
$array=$l->get_all_fiche_def();
$array=(empty($array))?"-1":$array;
$where=' where fd_id in ('.$l->get_all_fiche_def().')';
break;
case 'cred':
$l=new Acc_Ledger($cn,$ledger);
$prop=$l->get_propertie();
if ( empty($prop) || empty($prop['jrn_def_fiche_cred']))
{
$where ="";
}else {
$where=' where fd_id in ('.$prop['jrn_def_fiche_cred'].')';
}
break;
case 'deb':
$l=new Acc_Ledger($cn,$ledger);
$prop=$l->get_propertie();
if ( empty($prop) || empty($prop['jrn_def_fiche_deb']) ) {
$where = "" ;
} else {
$where=' where fd_id in ('.$prop['jrn_def_fiche_deb'].')';
}
break;
}
}
else
{
/* we filter thanks a given model of card */
if ( isset($cat) && ! empty($cat))
{
$where=sprintf(' where frd_id in ('.sql_string ($cat).')');
}
elseif ( isset($fil) && noalyss_strlentrim($fil) > 0 && $fil != -1 )
{
/* we filter thanks a given list of category of card
*/
$where=sprintf(" where fd_id in (%s)",
sql_string($fil));
} else
{
// create any type of cards
$where ="";
}
}
if ( strpos($where," in ()") != 0)
{
$html=_("Aucune catégorie de fiche ne correspond à".
" votre demande, le journal pourrait n'avoir accès à aucune fiche");
break;
}
$sql.=" ".$where." order by fd_label";
$array=$cn->get_array($sql);
$list_fiche="";
if ( empty($array))
{
$html=_("Aucune catégorie de fiche ne correspond à votre demande");
if ( DEBUGNOALYSS > 0 ) $html.=$sql;
}
else
{
$html=HtmlInput::title_box(_("Choix de la catégorie"), $ctl);
$r='';
$r.='';
$r.='
';
$r.=_("Choisissez la catégorie de fiche à laquelle vous aimeriez ajouter une fiche").'
';
if ( ! isset($eltid)) $eltid="";
$msg=_('Choisissez une catégorie svp');
$r.='
';
$r.=dossier::hidden();
$r.=(isset($ref))?HtmlInput::hidden('ref',1):'';
$r.=_('Cherche').' '.HtmlInput::filter_table("cat_card_table", '0,1', 0);
$r.='
';
$r.=HtmlInput::hidden('fd_id',0);
$r.='
';
$r.=HtmlInput::button('Fermer',_('Fermer')," onclick=\"removeDiv('$ctl')\" ");
$r.='
';
$r.='
';
$html.=$r;
}
$xml=escape_xml($html);
if (!defined("TEST_UNIT")) header('Content-type: text/xml; charset=UTF-8');
echo <<
$ctl
$xml
{$list_fiche}
EOF;
return;
break;
/*----------------------------------------------------------------------
* SC save card
* save the new card (insert)
*
----------------------------------------------------------------------*/
case 'sc':
if ( $g_user->check_action(FICADD)==1 )
{
$f=new Fiche($cn);
$status="OK";
try {
$f->insert($fd_id,$_POST);
$f->Get();
$after_save=$http->post("after_save","number",0);
// Action after save = 0, the card is display one second and fade out
//
if ( $after_save == 0 ) {
$html=HtmlInput::title_box(_("Choix de la catégorie"), $ctl);
$html.=''._('Fiche sauvée').'
';
$html.=$f->Display(true);
$js="";
if ( isset( $_POST['ref'])) $js=create_script(' window.location.reload()');
$html.=$js;
if ( isset ($eltid)) {
// after adding a new card, we update some field
$extra="$eltid".
"{$f->get_quick_code ()}";
}
$extra.=$status;
$extra.="0";
}
// Action after save = 1 ; after adding a card the table must be updated
// see fiche.inc.php
//
if ( $after_save == 1 ){
$f_id=$f->id;
ob_start();
$detail=Icon_Action::modify("mod".$f_id, sprintf("modify_card('%s')",$f_id)).
" ".
Icon_Action::trash("del".$f_id, sprintf("delete_card_id('%s')",$f_id));
$html = td($detail);
$html .= $f->display_row();
$html.=ob_get_contents();
ob_clean();
$extra="".$f_id."";
$ctl="row_card".$f_id;
$extra.="1";
}
} catch (Exception $exc) {
$html=""._("Erreur sauvegarde")."
";
$html.=$exc->getMessage();
$status="NOK";
$extra=$status;
}
}
else
{
$html.=alert(_('Action interdite'),true);
$html.=HtmlInput::button_close($ctl);
}
break;
/*----------------------------------------------------------------------
* Search a card
*
*----------------------------------------------------------------------*/
case 'fs':
$r=HtmlInput::title_box(_("Détail fiche"), 'search_card');
$r.='";
$sql_array["query"]=$query;
$sql_array["inactive_card"]=$inactive;
/* what is the type of the ledger */
$type="GL";
if (isset($jrn) && $jrn > 1)
{
$ledger=new Acc_Ledger($cn,$jrn);
$type=$ledger->get_type();
}
// if jrn == -10 , the search is called from the detail operation from an action follow-up
if ( isset($jrn) && $jrn == -10){
$type=$http->request("amount_from_type","string","VEN");
}
$fiche=new Fiche($cn);
/* Build the SQL and show result */
$sql=$fiche->build_sql($sql_array);
if ( strpos($sql," in ()") != 0)
{
$html="";
$html.=HtmlInput::title_box(_('Recherche de fiche'), 'search_card');
$html.='';
$html.=_("Aucune catégorie de fiche ne correspond à".
" votre demande, le journal pourrait n'avoir accès à aucune fiche");
$html.='
';
$html.=HtmlInput::button_close("search_card");
break;
}
/**
* if inactive == 0 , then only active card
*/
if ( $inactive == 0 ) {
$sql.=" and f_enable='1' ";
}
/* We limit the search to MAX_SEARCH_CARD records */
$sql=$sql.' order by vw_name ';
$total_card=$cn->get_value("select count(*) from ($sql) as c");
$record_start=$page_card*MAX_SEARCH_CARD;
$sql.=' limit '.MAX_SEARCH_CARD.' offset '.$record_start;
$aFound=$cn->get_array($sql);
$nb_found=count($aFound);
for($i=0;$i<$nb_found;$i++)
{
$array[$i]['quick_code']=$aFound[$i]['quick_code'];
$array[$i]['name']=h($aFound[$i]['vw_name']);
$array[$i]['accounting']=$aFound[$i]['accounting'];
$array[$i]['first_name']=h($aFound[$i]['vw_first_name']);
$array[$i]['description']=h($aFound[$i]['vw_description']);
$array[$i]['javascript']=sprintf("set_value('%s','%s');",
$inp,$array[$i]['quick_code']);
$array[$i]['javascript'].=sprintf("set_value('%s','%s');",
$label,j(noalyss_strip_tags($aFound[$i]['vw_name'])));
/* if it is a ledger of sales we use vw_buy
if it is a ledger of purchase we use vw_sell*/
if ( $type=="ACH" ){
$amount=(isNumber($aFound[$i]['vw_buy']) == 1 )?$aFound[$i]['vw_buy']:0;
$array[$i]['javascript'].=sprintf("set_value('%s','%s');",
$price,$amount);
}
if ( $type=="VEN" ){
$amount=(isNumber($aFound[$i]['vw_sell']) == 1 )?$aFound[$i]['vw_sell']:0;
$array[$i]['javascript'].=sprintf("set_value('%s','%s');",
$price,$amount);
}
// if there is no TVA_ID in the view, it is possible we have a TVA_CODE
$tva_code=(empty($aFound[$i]['tva_id']))?$aFound[$i]['tva_code']:$aFound[$i]['tva_id'];
$array[$i]['javascript'].=sprintf("set_value('%s','%s');",
$tvaid,$tva_code);
$array[$i]['javascript'].="removeDiv('search_card');";
}//foreach
ob_start();
require_once NOALYSS_TEMPLATE.'/card_result.php';
$r.=ob_get_contents();
$r.=HtmlInput::button_close("search_card");
ob_end_clean();
$ctl=$ctl.'_content';
$html=$r;
break;
case 'action_add_concerned_card':
require_once NOALYSS_INCLUDE.'/ajax/ajax_add_concerned_card.php';
return;
break;
// add several card to an action follow⁻up
case 'link_concerned_card':
require NOALYSS_INCLUDE.'/ajax/ajax_action_save_concerned.php';
return;
// remove card from an action follow⁻up
case 'action_remove_concerned':
require NOALYSS_INCLUDE.'/ajax/ajax_action_remove_concerned.php';
return;
case 'ac':
if ( $g_user->check_action(FICCAT)==1 )
{
/*----------------------------------------------------------------------
* Add a category, display first the form
*
*----------------------------------------------------------------------*/
$ipopup=str_replace('_content','',$ctl);
$msg="";$base="";
switch($cat)
{
case FICHE_TYPE_CLIENT:
$msg=_(' de clients');
$base=$cn->get_value("select p_value from parm_code where p_code='CUSTOMER'");
break;
case FICHE_TYPE_FOURNISSEUR:
$msg=_(' de fournisseurs');
$base=$cn->get_value("select p_value from parm_code where p_code='SUPPLIER'");
break;
case FICHE_TYPE_ADM_TAX:
$msg=_(' d\'administration');
$base='';
break;
case FICHE_TYPE_CONTACT:
$msg=_(' de contacts');
$base='';
break;
case FICHE_TYPE_FIN:
$msg=_(' Banque');
$base=$cn->get_value("select p_value from parm_code where p_code='BANQUE'");
break;
case FICHE_TYPE_EMPL:
$msg=_(' Employé ou administrateur');
$base='';
break;
}
$html='';
/* show the form */
$search=new IPoste("class_base");
$search->size=40;
$search->value=$base;
$search->label=_("Recherche poste");
$search->set_attribute('gDossier',dossier::id());
$search->set_attribute('account',$search->name);
$search->set_attribute('ipopup','ipop_account');
$nom_mod=new IText("nom_mod");
$str_poste=$search->input();
$submit=HtmlInput::submit('save',_('Sauve'));
ob_start();
require(NOALYSS_TEMPLATE.'/category_of_card.php');
$html.=ob_get_contents();
ob_end_clean();
}
else
{
$html=alert(_('Action interdite'),true);
}
break;
case 'scc':
/*----------------------------------------------------------------------
* Save card Category into the database and return a ok message
*
*----------------------------------------------------------------------*/
$html='';
$invalid=0;
if ( $g_user->check_action(FICCAT) == 1 )
{
$html="";
$nom_mod=$http->post("nom_mod");
$class_base=$http->post("class_base");
$fd_description=$http->post("fd_description","string","");
if ( noalyss_strlentrim($nom_mod) != 0 )
{
$array=array("FICHE_REF"=>$cat,
"nom_mod"=>$nom_mod,
"class_base"=>$class_base,
"fd_description"=>$fd_description);
if ( isset ($_POST['create'])) $array['create']="on";
$catcard=new Fiche_Def($cn);
ob_start();
$result=$catcard->Add($array);
$html.=ob_get_contents();
ob_end_clean();
if ( $result == 1)
{
$script="alert_box('"._('Catégorie existe déjà')."')";
$invalid=1;
}
else{
$script="alert_box('"._('Catégorie sauvée')."');removeDiv('$ctl')";
// add code to update the SELECT in include/template/category_of_card.php
$catcard->get();
$extra = ''.
''.$catcard->id.''.
''. escape_xml($catcard->label).''.
'';
}
$html.=create_script($script);
}
else
{
$script="alert_box('"._("Le nom ne peut pas être vide")."')";
$html.=create_script($script);
$invalid=1;
}
}
else
{
$html=alert(_('Action interdite'),true);
$invalid=1;
}
if ($invalid == 1) {
$ctl="info_div";
}
break;
// Update a card and then display the result
// in a readonly box
case 'upc':
$html=HtmlInput::title_box("Détail fiche", $ctl);
if ( $g_user->check_action(FICADD)==0 )
{
$html.=alert(_('Action interdite'),true);
}
else
{
if ($cn->get_value('select count(*) from fiche where f_id=$1',array($_GET['f_id'])) == '0' )
{
$html.=alert(_('Fiche non valide'),true);
}
else
{
$html=HtmlInput::title_box(_('Détail fiche (sauvée)'),$ctl);
$f=new Fiche($cn,$_GET['f_id']);
ob_start();
$f->update($_GET);
$html.=ob_get_contents();
ob_end_clean();
$html.=$f->Display(true);
}
}
$html.=''.HtmlInput::button_close($ctl).'
';
break;
// Update a card and then display the result
// in the table
case 'upr':
$f_id=$http->get("f_id","number");
$html="";
if ( $g_user->check_action(FICADD)==0 )
{
$html.=alert(_('Action interdite'),true);
}
else
{
if ($cn->get_value('select count(*) from fiche where f_id=$1',array($f_id)) == '0' )
{
$html.=alert(_('Fiche non valide'),true);
}
else
{
$f=new Fiche($cn,$f_id );
ob_start();
$f->update($_GET);
$detail=Icon_Action::modify("mod".$f_id, sprintf("modify_card('%s')",$f_id)).
" ".
Icon_Action::trash("del".$f_id, sprintf("delete_card_id('%s')",$f_id));
$html.=td($detail);
$html.=$f->display_row();
$html.=ob_get_contents();
ob_end_clean();
}
}
break;
//------------------------------------------------------------------
// Unlink a card
//------------------------------------------------------------------
case 'rm_card':
$html=HtmlInput::title_box("Détail fiche", $ctl);
if ( $g_user->check_action(FIC)==0 )
{
$html.=alert(_('Action interdite'),true);
}
else
{
if ($cn->get_value('select count(*) from fiche where f_id=$1',array($_GET['f_id'])) == '0' )
{
$html.=alert(_('Fiche non valide'),true);
}
else
{
$f=new Fiche($cn,$_GET['f_id']);
if ( $f->is_used()==0){
$f->delete();
$html="OK";
} else {
$html="";
$html=_("Fiche non effacée");
}
}
}
break;
//---------------------------------------------------------------------------------------------------------------
// Display option of a contact in an action-followup
//---------------------------------------------------------------------------------------------------------------
case 'display_card_option':
require_once NOALYSS_INCLUDE.'/ajax/ajax_display_card_option.php';
return;
break;
//---------------------------------------------------------------------------------------------------------------
// Save option of a contact in an action-followup
//---------------------------------------------------------------------------------------------------------------
case 'save_card_option':
require_once NOALYSS_INCLUDE.'/ajax/ajax_save_card_option.php';
return;
break;
// ----------------------------------------------------------------------------------------------------------------
// Display a list of other card linked to the event / followup
// ----------------------------------------------------------------------------------------------------------------
case 'action_concerned_list':
require_once NOALYSS_INCLUDE.'/ajax/ajax_action_concerned_list.php';
return ;
break;
} // switch
$xml=escape_xml($html);
if (DEBUGNOALYSS > 0 && headers_sent()) {
echo $html;return;
}
header('Content-type: text/xml; charset=UTF-8');
echo <<
$ctl
$xml
$extra
EOF;