cloning
"; /* * We need to clone the forecast */ $f_id=$http->get("f_id","number"); $anti = new Forecast($cn, $f_id); $anti->object_clone(); $sa="list"; } /* * ******************************************************************** * Save the modification mod_cat_save * * * ******************************************************************** */ if (isset($_POST['mod_cat_save'])) { /* * We save the forecast */ $f_id=$http->post("f_id","number"); $an_name=$http->post("an_name"); $start_date=$http->post("start_date"); $end_date=$http->post("end_date"); $anti = new Forecast($cn,$f_id); try { $cn->start(); /* Save forecast */ $anti->set_parameter('name', $an_name); $anti->set_parameter('start_date', $start_date); $anti->set_parameter('end_date', $end_date); $anti->save(); /* add new category */ for ($i = 0; $i < MAX_CAT; $i++) { if (isset($_POST['fr_cat_new' . $i])) { $fr_cat_name=$http->post("fr_cat_new".$i); if (strlen(trim($fr_cat_name)) != 0) { $order=$http->post("fc_order_new".$i); $desc=$http->post('fr_cat_new' . $i); $f_id=$http->post("f_id","number"); $c = new Forecast_Cat($cn); $c->set_parameter('order',$order); $c->set_parameter('desc', $desc); $c->set_parameter('forecast', $f_id); $c->save(); } } } /* update existing cat */ foreach ($_POST as $key => $value) { $var = sscanf($key, 'fr_cat%d'); $idx = sprintf("fr_cat%d", $var[0]); if (isset($_POST[$idx])) { $fc = new Forecast_Cat($cn, $var[0]); if (strlen(trim($_POST[$idx])) == 0) { $fc->delete(); } else { $order=$http->post("fc_order".$var[0]); $desc=$http->post('fr_cat' . $var[0]); $f_id=$http->post("f_id","number"); $fc->set_parameter('order', $order); $fc->set_parameter('desc', $desc); $fc->set_parameter('forecast', $f_id); $fc->save(); } } } $cn->commit(); } catch (Exception $e) { alert($e->getMessage()); $cn->rollback(); } $sa = 'vw'; } /* * ******************************************************************** * Save first the data for new * * * ******************************************************************** */ if ($sa == 'new' || isset($_POST['step3'])) { $correct = 0; if (isset($_POST['step3'])) { /* save all the items */ try { $cn->start(); $nb_row=$http->post("nbrow"); for ($i = 0; $i < $nb_row; $i++) { // Delete if needed if (isset($_POST['fi_id' . $i])) { if (strlen(trim($_POST['an_cat_acc' . $i])) == 0 && strlen(trim($_POST['an_qc' . $i])) == 0) { $e = new Forecast_item($cn); $e->set_parameter("id", $_POST['fi_id' . $i]); $e->delete(); } } if (strlen(trim($_POST['an_cat_acc' . $i])) != 0 || strlen(trim($_POST['an_qc' . $i])) != 0) { /* we save only if there is something */ $e = new Forecast_item($cn); if (isset($_POST['fi_id' . $i])) { $e->set_parameter("id", $_POST['fi_id' . $i]); } $e->set_parameter('text', $_POST['an_label' . $i]); $e->set_parameter('amount', $_POST['an_cat_amount' . $i]); $e->set_parameter('debit', $_POST['an_deb' . $i]); $e->set_parameter('cat_id', $_POST['an_cat' . $i]); $e->set_parameter('account', $_POST['an_cat_acc' . $i]); $e->set_parameter('periode', $_POST['month' . $i]); $f = new Fiche($cn); if ($f->get_by_qcode($_POST['an_qc' . $i], false) == 0) $e->set_parameter('card', $f->id); else $e->set_parameter('card', null); $e->set_parameter('order', $i); $e->save(); } } $cn->commit(); $sa = 'vw'; // to avoid to restart the add of new anticipation } catch (Exception $e) { $cn->rollback(); alert($e->getMessage()); $correct = 1; } } /* Second step : we save the name and category * and propose the items we add the item */ if ($correct == 2 || isset($_POST['step2'])) { try { $cn->start(); /* Save forecast */ $a = new Forecast($cn); $a->set_parameter('name', $_POST['an_name']); $a->set_parameter('start_date', $_POST['start_date']); $a->set_parameter('end_date', $_POST['end_date']); $a->save(); $id = $a->get_parameter("id"); /* save cat */ for ($i = 0; $i < MAX_CAT; $i++) { if (strlen(trim($_POST['fr_cat' . $i])) != 0) { $c = new Forecast_Cat($cn); $c->set_parameter('order', $_POST['fr_order' . $i]); $c->set_parameter('desc', $_POST['fr_cat' . $i]); $c->set_parameter('forecast', $id); $c->save(); } } $cn->commit(); } catch (Exception $e) { alert($e->getMessage()); $correct = 1; unset($_POST['step2']); $cn->rollback(); } } } /* * ******************************************************************** * Ask for a new anticipation (forecast) * * * ******************************************************************** */ if ($sa == 'new') { /* Second step : we save the name and category * and propose the items we add the item */ if ($correct == 2 || isset($_POST['step2'])) { /* Propose a form for the items */ $anticip = new Anticipation($cn, $a->get_parameter("id")); echo '';
echo '';
echo '
';
}
/* First step, the name and the category */
if (!isset($_POST['step2']) || $correct == 1)
{
$anc = new Anticipation($cn);
echo '';
/* display a blank form for name and category */
echo '';
echo '
';
}
}
/* * ********************************************************************
* If we request to modify the category or the name
*
*
* ******************************************************************** */
if ( $action == 'mod_cat')
{
$anc = new Anticipation($cn, $_GET['f_id']);
echo '';
/* display a blank form for name and category */
echo '';
echo '
';
return;
}
/* * ********************************************************************
* If we request to modify the items
*
*
* ******************************************************************** */
if ($action == 'mod_item' )
{
/* Propose a form for the items
*/
$anticip = new Anticipation($cn, $_GET['f_id']);
echo '';
echo '';
echo '
';
return;
}
/* * ********************************************************************
* if a forecast is asked we display the result
*
*
* ******************************************************************** */
if (isset($_REQUEST['f_id']) && $sa == "vw")
{
echo '';
$forecast = new Anticipation($cn);
$forecast->set_parameter("id", $_REQUEST['f_id']);
try
{
echo $forecast->display();
echo '
';
return;
}
catch (Exception $e)
{
echo " ';
echo '" . _("Erreur")." : " . $e->getMessage() . '
' . _('Vous devez corriger') . '
';
/* display a blank form for name and category */
echo '';
echo '
';
}
}
/* * ********************************************************************
* Display menu
*
*
* ******************************************************************** */
// display button add and list of forecast to display
if ($sa=='list')
{
$aForecast=Forecast::load_all($cn);
$menu=array();
$get_dossier=dossier::get();
echo '';
echo _('Filtre')." ".HtmlInput::filter_table("forecast_table_id", '0', 1);
echo '';
$href="?ac=".$_REQUEST['ac']."&sa=new&".$get_dossier;
echo '
";
echo '
';
return;
}
?>
'._("Ajout d'une prévision").' | '.h($name).' | '; } echo "