noalyss Version-9
action.common.inc.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * NOALYSS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with NOALYSS; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21// Copyright Author Dany De Bontridder danydb@aevalys.eu
22
23/**
24 * \file
25 * \brief this file is common to suivi client, suivi fournisseur, suivi
26 * administration.
27 * The needed variables are
28 * - $cn for the database connection
29 * - $sub_action sa from suivi courrier but sc from Suivi client, fournisseur...
30 *
31 */
32if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
35if (isset($_REQUEST['sc']))
36 $supl_hidden.=HtmlInput::hidden('sc', $http->request("sc"));
37if (isset($_REQUEST['f_id']))
38 $supl_hidden.=HtmlInput::hidden('f_id', $http->request("f_id","number"));
39if (isset($_REQUEST['sb']))
40 $supl_hidden.=HtmlInput::hidden('sb', $http->request("sb"));
41$supl_hidden.=HtmlInput::hidden('ac', $http->request("ac"));
43/**
44 * if no group available , then stop
45 */
46global $g_user;
47
48if ( empty ($g_user->get_readable_profile() ) ) {
49 echo '<span class="warning">'. _("Aucun profil disponible").'</span>';
50 return;
51}
52
55
56/*-----------------------------------------------------------------------------*/
57/* For other action */
58/*-----------------------------------------------------------------------------*/
59if ( isset ($_POST['other_action_bt'])) {
60 /**
61 * The action id are in the array mag_id
62 * the tag to remove are vin the array remtag
63 * the tag to add are in the array addtag
64 * the state in ag_state
65 */
66 if ( isset ($_POST['mag_id'])) {
67 switch ($_POST['othact']) {
68 case 'IMP':
69 //Impression
71 return;
72 break;
73 case 'ST':
74 // Etat
76 break;
77 case 'ETIREM':
78 //tag
80 break;
81 case 'ETIADD':
83 break;
84 case 'ETICLEAR':
86 break;
87 case 'DOCREM':
89 break;
90 }
91 }
92}
93
94/* --------------------------------------------------------------------------- */
95/* We ask to generate the document */
96/* --------------------------------------------------------------------------- */
97if (isset($_POST['generate']))
98{
99 $act = new Follow_Up($cn);
100 $act->fromArray($_POST);
101 if ($act->ag_id == 0)
102 {
103 $act->save();
104 $ag_id = $act->ag_id;
105 }
106 else
107 {
108 $act->update();
109 }
110 $doc_mod=$http->post('doc_mod',"number");
111 $act->generate_document($doc_mod, $_POST);
112 $sub_action = 'detail';
113}
114/* for delete */
115if (isset($_POST['delete']) && $_POST['delete'] == "1")
116 $sub_action = 'delete';
117if ($sub_action == "")
118 $sub_action = "list";
119
120// if correction is asked go to directly to add_action
121if (isset($_POST['corr']))
122{
123 $ag_comment = urldecode($_POST['ag_comment']);
124 $sub_action = "add_action";
125}
126// if this page is called from another menu (customer, supplier,...)
127// a button back is added
128//----------------------------------------------------------------------
129// update the detail
130// Add a new action related to this one or update
131//----------------------------------------------------------------------
132if ($sub_action == "update")
133{
134 // update the modification
135 if (isset($_POST['save']))
136 {
137 $act2 = new Follow_Up($cn);
138 $act2->fromArray($_POST);
139 if ($g_user->can_write_action($act2->ag_id) == FALSE )
140 {
141 echo '<div class="redcontent">';
142 echo '<h2 class="error">'._('Cette action ne vous est pas autorisée Contactez votre responsable').'</h2>';
143 echo '</div>';
144 return;
145 }
146 $sub_action = "detail";
147 put_global(array(array('key' => "sa", "value" => "detail")));
148 try {
149 $act2->verify() ;
150 $act2->update() ;
151 }
152 catch (Exception $e)
153 {
154 echo '<span class="notice">';
155 echo _("Erreur")." ".$e->getMessage();
156 echo '</span>';
157 $sub_action="detail";
158 $correction = 1;
159 $act = clone $act2;
160 $act->get();
161 $act->fromArray($_POST);
162 $error_id=$e->getCode();
163 record_log($e);
164 }
165 }
166 //----------------------------------------------------------------------
167 // Add a related action
168 //----------------------------------------------------------------------
169 if (isset($_GET['add_action_here']))
170 {
171 $ag_id=$http->get('ag_id',"number");
172 $act = new Follow_Up($cn,$ag_id);
173 if ($g_user->can_write_action($act->ag_id) == FALSE )
174 {
175 echo '<div class="redcontent">';
176 echo '<h2 class="error">'._('Cette action ne vous est pas autorisée Contactez votre responsable').'</h2>';
177 echo '</div>';
178 return;
179 }
180 //----------------------------------------
181 // puis comme ajout normal (copier / coller )
182 $act->ag_id = 0;
183 $act->d_id = 0;
184 $act->action = $ag_id;
185 $act->ag_timestamp=date('d.m.Y');
186 $act->ag_dest=$g_user->get_profile();
187 $act->ag_hour="";
188 $act->ag_title="";
189 $act->ag_remind_date="";
190 $act->dt_id = $http->request("action_type","number");
191 $act->d_id = 0;
192 $act->ag_comment = "";
193 $act->qcode_dest="";
194 if (isset($_REQUEST['qcode'])){
195 $act->qcode_dest = $http->request ('qcode');
196 } else {
197 // Retrieve recipient of previous followup-action
198 $act->qcode_dest=$cn->get_value("select ad_value from action_gestion ag join fiche_detail fd
199 on (fd.f_id=ag.f_id_dest) where ag_id=$1 and ad_id=$2",
201 }
202 $act->f_id_dest=$act->qcode_dest;
203 $act->save();
204
205 // Add hidden tag
206 echo '<form enctype="multipart/form-data" style="display:inline" action="do.php" method="post"">';
207
208
209
210 echo $act->Display('NEW', false, $base, $retour);
211
212 echo '<input type="hidden" name="ac" value="' . $http->request('ac') . '">';
213 echo '<input type="hidden" name="sa" value="save_action_st2">';
214 echo '<input type="submit" class="button" name="save_action_st2" value="' . _('Enregistrer') . '">';
215 echo $supl_hidden;
216 echo '</form>';
217 return;
218 }
219}
220//--------------------------------------------------------------------------------
221// Show the detail of an action
222// permit the update
223//--------------------------------------------------------------------------------
224if ($sub_action == 'detail')
225{
226 echo '<div class="content" style="padding:1rem">';
227 if ( $correction == 0 )
228 {
229 $act = new Follow_Up($cn);
230 $act->ag_id = $ag_id;
231 echo $act->get();
232 }
233
234
235 if ($g_user->can_write_action($ag_id) == true)
236 {
237
238 printf( '<form enctype="multipart/form-data" id="action_common_frm" class="print" action="do.php"
239method="post" style="display:inline" onsubmit="return check_file_size(this,%s)">',MAX_FILE_SIZE);
240 echo $supl_hidden;
241 echo HtmlInput::hidden('ac', $http->request('ac'));
242 echo dossier::hidden();
243 echo $act->Display('UPD', false, $base, $retour);
244 echo '<input type="hidden" name="sa" value="update">';
245 echo '<input type="hidden" id="delete" name="delete" value="0">';
246 echo HtmlInput::submit("save", "Sauve",' onclick="$(\'delete\').value=0"');
247
248
249
250
251 //
252 if ($g_user->can_delete_action($ag_id))
253 {
254 echo HtmlInput::submit("delete_bt", _("Efface cet événement "),
255 ' onclick="$(\'delete\').value=1;return confirm_box(\'action_common_frm\',\''. _("Vous confirmez l\'effacement") . '\')" ');
256 }
257 echo $retour;
258 echo '</form>';
259 // Create select box for new Action
260 Follow_Up::show_action_add(["sa"=>"update","add_action_here"=>1,"ag_id"=>$ag_id]);
261 }
262 else if ($g_user->can_read_action($ag_id) == true || $act->ag_dest == -1)
263 {
264 echo $act->Display('READ', false, $base, $retour);
265 }
266 else
267 {
268 echo h2info(_("Ce document n'est pas accessible"));
269 return;
270 }
271
272
273 echo '</div>';
274}
275//-------------------------------------------------------------------------------
276// Delete an action
277//-------------------------------------------------------------------------------
278if ($sub_action == 'delete')
279{
280 // confirmed
281 $cn->start();
282 $act = new Follow_Up($cn);
283 $act->ag_id =$http->request("ag_id","number") ;
284 $act->get();
285 if ($g_user->can_delete_action($act->ag_id)==true) $act->remove();
286 $sub_action = "list";
287 $cn->commit();
288 Follow_Up::show_action_list($cn, $base);
289 if (isset($act->ag_ref))
290 echo hb(_('Action ') . $act->ag_ref . _(' effacée'));
291 return;
292}
293
294//--------------------------------------------------------------------------------
295// Show a list of the action
296//--------------------------------------------------------------------------------
297if ($sub_action == "list")
298{
299 // Add a button to export to Csv
300 echo '<form method="GET" style="display:inline;" ACTION="export.php">';
301 echo HtmlInput::request_to_hidden(array("closed_action","remind_date_end","remind_date","sag_ref", "remind_date","only_internal", "state", "gDossier", "qcode", "start_date", "end_date", "ag_id", "ag_dest_query",
302 "tdoc", "action_query","date_start","date_end","hsstate","searchtag"));
303 echo HtmlInput::hidden("act", "CSV:ActionGestion");
304 echo HtmlInput::hidden("export_type", "simple");
305 echo HtmlInput::submit("follow_up_csv", _("Export CSV"),'','smallbutton');
306 echo "</form>";
307 // Add a button to export complete to Csv
308 echo '<form method="GET" style="display:inline;" ACTION="export.php">';
309 echo HtmlInput::request_to_hidden(array("closed_action","remind_date_end","remind_date","sag_ref", "remind_date","only_internal", "state", "gDossier", "qcode", "start_date", "end_date", "ag_id", "ag_dest_query",
310 "tdoc", "action_query","date_start","date_end","hsstate","searchtag"));
311 echo HtmlInput::hidden("act", "CSV:ActionGestion");
312 echo HtmlInput::hidden("export_type", "detail");
313 echo HtmlInput::submit("follow_up_csv", _("Export CSV détaillé"),'','smallbutton');
314 echo "</form>";
315 //if filter_name exists then we save the $_GET into the DB as a JSON object
316 $filter_name=$http->get("filter_name","string",null);
317 if ( noalyss_trim($filter_name) != "" ) {
318 // save filter
319 // $follow_up_filter=new Follow_Up_Filter($cn);
320 $a_content=json_encode($_GET);
321 $action_gestion_filter=new Follow_Up_Filter($filter_name,$a_content);
322 $action_gestion_filter->save();
323 }
324 // si filtered on charge la DB
325 Follow_Up::show_action_list($cn, $base);
326}
327//--------------------------------------------------------------------------------
328// Save Follow_Up
329// Stage 2 : Save a NEW action + Files and generate a document
330//--------------------------------------------------------------------------------
331if ($sub_action == "save_action_st2")
332{
333 $act = new Follow_Up($cn);
334 $act->fromArray($_POST);
335 try {
336 $act->d_id = 0;
337 $act->ag_id = $http->request("ag_id", "number");
338 $act->md_id = $http->post('gen_doc', 'number', 0);
339
340 $act->verify();
341 $sup_parameter = HtmlInput::array_to_string(["sc", "sb", "f_id", "qcode"], $_REQUEST, "&amp;");
342 // insert into action_gestion
343 $act->update();
344
345 $url = "?sa=detail&ag_id=" . $act->ag_id . '&' . dossier::get() . "&ac=" . $http->request("ac") .
346 $sup_parameter;
347 echo '<p><a class="mtitle" href="' . $url . '">' . hb(_('Action Sauvée') . ' : ' . $act->ag_ref) . '</a></p>';
348
349 Follow_Up::show_action_list($cn, $base);
350 $url = "?sa=detail&ag_id=" . $act->ag_id . '&' . dossier::get() . "&ac=" . $http->request("ac") .
351 $sup_parameter;
352 echo '<p><a class="mtitle" href="' . $url . '">' . hb(_('Action Sauvée') . ' : ' . $act->ag_ref) . '</a></p>';
353 } catch (Exception $e) {
354 echo '<span class="notice">';
355 echo _("Erreur") . " " . $e->getMessage();
356 echo '</span>';
357 $sub_action = "add_action";
358 $error_id = $e->getCode();
359 record_log($e);
360 }
361}
362//--------------------------------------------------------------------------------
363// Add an action
364if ($sub_action == "add_action" && ! empty($g_user->get_writable_profile() ) )
365{
366 $act = new Follow_Up($cn);
367 $act->fromArray($_POST);
368 $act->dt_id = $http->request("action_type","number");
369 $act->d_id = 0;
370 $f_id_dest=$http->request("f_id","number",null);
371 if ( $f_id_dest != NULL ) {
372 $act->qcode_dest=$cn->get_value("select ad_value from fiche_detail where ad_id=$1 and f_id=$2",
373 [ATTR_DEF_QUICKCODE,$f_id_dest]);
374 }
375 $act->save();
376
377 echo '<div class="content">';
378 // Add hidden tag
379 echo '<form method="post" action="do.php" name="form_add" id="form_add" enctype="multipart/form-data" >';
380 echo $supl_hidden;
381 echo dossier::hidden();
382
383
384 $act->ag_comment =Decode($http->post("ag_comment","string",""));
385 if (isset($_REQUEST['qcode']))
386 $act->qcode_dest = $http->request('qcode');
387 echo $act->Display('NEW', false, $base, $retour);
388
389 echo '<input type="hidden" name="ac" value="' . $http->request("ac") . '">';
390 echo '<input type="hidden" name="sa" value="save_action_st2">';
391 echo '<input type="hidden" name="save_action_st2" value="save_action_st2">';
392 echo '<input type="submit" class="button" name="save_action_st2" value="' . _('Enregistrer') . '">';
393 echo '</form>';
394
395 echo '</div>';
396
397}
398if ( $error_id != 0 ){
399 $error[10]='dt_id';
400 $error[20]='ag_timestamp';
401 $error[30]='ag_remind_date';
402 $div=$error[$error_id];
403 $js=<<<EOF
404 <script>$('$div').style.borderColor="red";
405 $('info_div').innerHTML='erreur';
406 </script>
407
408EOF;
409 echo $js;
410 }
411?>
412
put_global($array)
Put in superglobal (get,post,request) the value contained in the parameter field (me_parameter)
Definition: ac_common.php:1233
span($p_string, $p_extra='')
Definition: ac_common.php:43
p($p_string)
Definition: ac_common.php:39
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
if(empty($g_user->get_readable_profile())) $correction
$supl_hidden
global $g_user
if no group available , then stop
$ag_id
Definition: action.inc.php:54
$sub_action
Show the list of action, this code should be common to several webpage. But for the moment we keep li...
Definition: action.inc.php:50
$retour
Definition: action.inc.php:27
$base
Definition: action.inc.php:56
$div
$opd_description style
$_REQUEST['ac']
$fl ag_id
$from_poste name
$input_from type
Definition: balance.inc.php:65
$_GET['qcode']
static action_tag_remove($cn, $p_array)
static action_remove($cn, $p_array)
static action_set_state($cn, $p_array)
static action_tag_clear($cn, $p_array)
static action_print($cn, $p_array)
static action_tag_add($cn, $p_array)
static hidden($p_name, $p_value, $p_id="")
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
manage the http input (get , post, request) and extract from an array
static echo_file($msg, $print=true)
display the file
Definition: dbg.php:88
const ATTR_DEF_QUICKCODE
Definition: constant.php:237
const ACTION
Definition: constant.php:196
$_POST['ac']
Definition: do.php:310
vous n
Definition: modele.inc.php:398