noalyss Version-9
forecast.inc.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/**
23 * \file
24 * \brief display, add, delete and modify forecast
25 */
26if (!defined('ALLOWED'))
27 die('Appel direct ne sont pas permis');
28
29require_once NOALYSS_INCLUDE."/database/forecast_sql.class.php";
30require_once NOALYSS_INCLUDE."/database/forecast_item_sql.class.php";
31require_once NOALYSS_INCLUDE."/database/forecast_category_sql.class.php";
32
33
34global $http;
35
36$action=$http->get("action", "string", "");
37$ac=$http->request("ac");
38$forecast_id=$http->request('f_id', 'number',-1);
39
40echo '<div class="content">';
41$sa=$http->request("sa", "string", "list");
42/* * ********************************************************************
43 * Remove a anticipation
44 *
45 *
46 * ******************************************************************** */
47if ($action=='del')
48{
49 $f_id=$http->get("f_id", "number");
51 $forecast->delete();
52}
53/* * *******************************************************************
54 * Cloning
55 * ******************************************************************* */
56if ($action=='clone')
57{
58 echo "<h2> cloning</h2>";
59 /*
60 * We need to clone the forecast
61 */
62 $f_id=$http->get("f_id", "number");
63 $anti=new Anticipation($cn, $f_id);
64 $forecast_id=$anti->object_clone();
65 $action="mod_view";
66}
67
68/* * ********************************************************************
69 * Save first the data for new
70 *
71 *
72 * ******************************************************************** */
73if ($sa=='new')
74{
75 try
76 {
77 $f_name=$http->post("f_name");
78 $p_start=$http->post("p_start","number");
79 $p_end=$http->post("p_end","number");
80 if ( $f_name == "") {
81 throw new Exception(_("Le nom ne peut pas être vide"));
82 }
84 $forecast_sql->setp("f_name",$f_name);
85 $forecast_sql->setp("f_start_date",$p_start);
86 $forecast_sql->setp("f_end_date",$p_end);
87 $forecast_sql->save();
88 $action="mod_item";
89 $forecast_id=$forecast_sql->getp("f_id");
90
91 }
92 catch (Exception $exc)
93 {
94 echo_warning($exc->getMessage());
95 $sa="list";
96 }
97}
98
99/* * ********************************************************************
100 * If we request to modify the items
101 *
102 *
103 * ******************************************************************** */
104if ($action=='mod_item')
105{
106
107 /* Propose a form for the items
108 */
109 $anticipation=new Anticipation($cn, $forecast_id);
110 $anticipation->input_form();
111
112
113
114 return;
115}
116/* * ********************************************************************
117 * if a forecast is asked we display the result
118 *
119 *
120 * ******************************************************************** */
121if ($sa=="vw")
122{
123 echo '<div class="content">';
125
126
127 $forecast->setForecastId($forecast_id);
128 try
129 {
130 echo $forecast->display();
131 echo '<div class="noprint">';
132 echo '<form id="forecast_frm" method="get">';
133 echo dossier::hidden();
134 echo HtmlInput::hidden('action', '');
135 echo HtmlInput::hidden('f_id', $forecast_id);
136 echo HtmlInput::submit('mod_item_bt', _('Modifier éléments'), 'onclick="$(\'action\').value=\'mod_item\';"');
137 //echo HtmlInput::submit('cvs',_('Export CVS'));
138
139 echo HtmlInput::hidden('ac', $ac);
140 $href=http_build_query(array('ac'=>$ac, 'gDossier'=>Dossier::id()));
141 echo '<a style="display:inline-block" class="smallbutton" href="do.php?'.$href.'">'._('Retour').'</a>';
142 echo '</form>';
143 echo '</div>';
144 echo '</div>';
145 return;
146 }
147 catch (Exception $e)
148 {
149 echo "<div class=\"error\"><p>"._("Erreur")." : ".$e->getMessage().
150 '</p><p>'._('Vous devez corriger').'</p></div>';
152 echo '<div class="content">';
153 /* display a blank form for name and category */
154 echo '<form method="post" action="?">';
155 echo dossier::hidden();
156 echo HtmlInput::hidden('sa', 'mod');
157 echo HtmlInput::hidden('ac', $ac);
158 echo $anc->form_cat();
159 echo HtmlInput::submit('mod_cat_save', _('Sauver'));
160 echo '</form>';
161 echo '</div>';
162 }
163}
164/* * ********************************************************************
165 * Display menu
166 *
167 *
168 * ******************************************************************** */
169// display button add and list of forecast to display
170if ($sa=='list')
171{
172
173
174 $aForecast=Forecast::load_all($cn);
175 $menu=array();
176 $get_dossier=dossier::get();
177 require_once NOALYSS_TEMPLATE."/forecast-new.php";
178
179 echo '<div class="content">';
180 echo _('Filtre')." ".HtmlInput::filter_table("forecast_table_id", '0', 1);
181 echo '<TABLE id="forecast_table_id" class="vert_mtitle">';
182 $href="?ac=".$ac."&sa=new&".$get_dossier;
183 echo '<TR><TD class="first"><A HREF="#" onclick="document.getElementById(\'forecast_new_div\').show()">'._("Ajout d'une prévision").'</A></TD></TR>';
184 $forecast_id=$http->request('f_id', 'number', -1);
185
186 for ($i=0; $i<count($aForecast); $i++)
187 {
188 $href="?ac=".$ac."&sa=vw&".$get_dossier.'&f_id='.$aForecast[$i]['f_id'];
189 $name=h($aForecast[$i]['f_name']);
190 $menu[]=array($href, $name, $name, $aForecast[$i]['f_id']);
191 echo '<TR><TD><A HREF="'.$href.'">'.h($name).'</A></TD></TR>';
192 }
193
194 echo "</TABLE>";
195 echo '</div>';
196 return;
197}
198?>
199</div>
echo_warning($p_string)
warns
Definition: ac_common.php:589
$href
Definition: adm.inc.php:31
h( $row[ 'oa_description'])
static id()
return the 'gDossier' value after a check
ORM abstract of the table public.forecast.
static load_all($p_cn)
load all the existing forecast
static filter_table($p_table_id, $p_col, $start_row)
filter the rows in a table and keep the colored row in alternance
static hidden($p_name, $p_value, $p_id="")
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
$p_end
$p_start
global $http
$forecast_id
$ac
$sa
$action