Check();
$User->check_dossier($gDossier);
include_once ("user_menu.php");
echo '
';
/* Analyse ce qui est demandé */
/* Effacement d'une ligne */
if (isset ($_GET['action']))
{
//-----------------------------------------------------
// Action == remove a line
if ( $_GET['action']=="del" )
{
if ( isset ($_GET['l']) )
{
/* Ligne a enfant*/
$R=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val_parent=$1",array($_GET['l']));
if ( Database::num_row($R) != 0 )
{
alert("Ne peut pas effacer le poste: d'autres postes en dépendent");
}
else
{
/* Vérifier que le poste n'est pas utilisé qq part dans les journaux */
$Res=$cn->exec_sql("select * from jrnx where j_poste=$1",array($_GET['l']));
if ( Database::num_row($Res) != 0 )
{
alert("Ne peut pas effacer le poste: il est utilisé dans les journaux");
}
else
{
$Del=$cn->exec_sql("delete from tmp_pcmn where pcm_val=$1",array($_GET['l']));
} // if Database::num_row
} // if Database::num_row
} // isset ($l)
} //$action == del
} // isset action
//----------------------------------------------------------------------
// Modification
//----------------------------------------------------------------------
if ( isset ($_POST['update']))
{
$p_val=trim($_POST["p_valu"]);
$p_lib=trim($_POST["p_libu"]);
$p_parent=trim($_POST["p_parentu"]);
$old_line=trim($_POST["p_oldu"]);
$p_type=htmlentities($_POST['p_typeu']);
$acc=new Acc_Account($cn);
$acc->set_parameter('libelle',$p_lib);
$acc->set_parameter('value',$p_val);
$acc->set_parameter('parent',$p_parent);
$acc->set_parameter('type',$p_type);
// Check if the data are correct
try
{
$acc->check() ;
}
catch (Exception $e)
{
$message="Valeurs invalides, pas de changement \n ".
$e->getMessage();
echo '';
}
if ( strlen ($p_val) != 0 && strlen ($p_lib) != 0 && strlen($old_line)!=0 )
{
if (strlen ($p_val) == 1 )
{
$p_parent=0;
}
else
{
if ( strlen($p_parent)==0 )
{
$p_parent=substr($p_val,0,strlen($p_val)-1);
}
}
/* Parent existe */
$Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1",array($p_parent));
if ( ($p_parent != 0 && Database::num_row($Ret) == 0) || $p_parent==$old_line )
{
echo '';
}
else
{
try
{
$acc->update($old_line);
}
catch(Exception $e)
{
alert($e->getMessage());
}
}
}
else
{
echo '';
}
}
//-----------------------------------------------------
/* Ajout d'une ligne */
if ( isset ( $_POST["Ajout"] ) )
{
extract ($_POST);
$p_val=trim($p_val);
$p_parent=trim($p_parent);
if ( isset ( $p_val) && isset ( $p_lib ) )
{
$p_val=$cn->get_value('select format_account($1)',array($p_val));
$p_parent=$cn->get_value('select format_account($1)',array($_POST["p_parent"]));
if ( strlen ($p_val) != 0 && strlen ($p_lib) != 0 )
{
if (strlen ($p_val) == 1 )
{
$p_parent=0;
}
else
{
if ( strlen(trim($p_parent))==0 &&
(string) $p_parent != (string)(int) $p_parent)
{
$p_parent=substr($p_val,0,strlen($p_val)-1);
}
}
/* Parent existe */
$Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1",array($p_parent));
if ( $p_parent != 0 && Database::num_row($Ret) == 0 )
{
alert(" Ne peut pas modifier; aucun poste parent");
}
else
{
// Check if the account already exists
$Count=$cn->get_value("select count(*) from tmp_pcmn where pcm_val=$1",array($p_val));
if ( $Count != 0 )
{
// Alert message account already exists
alert(" Ce poste existe déjà ");
}
else
{
$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_lib,$p_parent,$p_type));
}
}
}
else
{
echo '
Valeurs invalides ';
}
}
}
$Ret=$cn->exec_sql("select pcm_val,pcm_lib,pcm_val_parent,pcm_type from tmp_pcmn where substr(pcm_val::text,1,1)='".$_SESSION['g_start']."' order by pcm_val::text");
$MaxRow=Database::num_row($Ret);
?>
";
echo "
";
html_page_stop();
?>