noalyss Version-9
do_BASE_342368.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
21define('ALLOWED',1);
22/**\file
23 * \brief Main file
24 */
25require_once '../include/constant.php';
26
27require_once NOALYSS_INCLUDE.'/class/database.class.php';
28require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
29require_once NOALYSS_INCLUDE.'/lib/user_common.php';
30require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
31require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
32require_once NOALYSS_INCLUDE.'/constant.security.php';
33require_once NOALYSS_INCLUDE.'/lib/html_input.class.php';
34require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
35require_once NOALYSS_INCLUDE.'/lib/icon_action.class.php';
37
38mb_internal_encoding("UTF-8");
39// if gDossier is not set redirect to form to choose a folder
40if ( ! isset($_REQUEST['gDossier']))
41{
42 redirect('user_login.php');
43 exit();
44}
45if ( ! isset ($_SESSION[SESSION_KEY.'g_user']))
46 {
47 echo "<h2>"._('Vous êtes déconnecté')."</h2>";
48 $backurl=$_SERVER['REQUEST_URI'];
49 $url="index.php?".http_build_query(array('reconnect'=>1,'backurl'=>urlencode($backurl)));
51 exit();
52
53 }
55
57$g_user = new Noalyss_user($cn);
58$http=new HttpInput();
59IDate::set_firstDate($g_user->get_first_week_day());
60
61/*
62 * check that the database is not empty
63 */
64if ( ! $cn->exist_table('version')) {
65 echo '<h2 class="notice">'._('Désolé').'</h2>';
66 echo _('Ce dossier est vide');
67 echo '<p>';
68 echo '<a class="button" href="do.php">'._("Retour à l'accueil").'</a>';
69 echo '</p>';
70 return;
71}
72/**
73 * if access_mode is MOBILE than force it to mobile.php
74 */
75if ($g_user->get_access_mode()=='MOBILE') { require NOALYSS_HOME."/mobile.php"; return;}
76
77$style_user=$http->post("style_user","string",$_SESSION[SESSION_KEY.'g_theme']);
78
80if ( DEBUGNOALYSS > 1 ) {
81/**
82 * Debug Design
83 */
84echo <<<EOF
85<div class="d-none d-sm-block d-md-none d-lg-none d-xl-none " style="background-color:red">Small</div>
86<div class="d-none d-md-block d-lg-none " style="background-color:orangered">Medium</div>
87<div class="d-none d-lg-block d-xl-none " style="background-color:orange">Large</div>
88<div class="d-none d-xl-block " style="background-color:wheat">X Large</div>
89EOF;
90
91 ?>
92<div id="debug_div" style="border:slategray solid 1px;margin-left: 0px;position:absolute;background:white;top:2px;left:25px;z-index:1000;display:none">
93 <h2 style="margin-top:100px"> Memory Usage </h2>
94 <?php echo memory_get_usage()/1024.0 . " kb \n"; ?>
95
96
97 <h2>$_POST</h2>
98 <pre>
99 <?php
100 print_r($_POST);
101 ?>
102
103 </pre>
104 <h2>$_GET</h2>
105 <pre>
106 <?php
107 print_r($_GET);
108 ?>
109 </pre>
110 <h2>$_REQUEST</h2>
111 <pre>
112 <?php
113 print_r($_REQUEST);
114 ?>
115 </pre>
116 <h2>$_SESSION</h2>
117 <pre>
118 <?php
119 print_r($_SESSION);
120 ?>
121 </pre>
122
123 <h2>$GLOBALS</h2>
124 <pre>
125 <?php
126 // Use much of memory
127 print_r($GLOBALS);
128 ?>
129 </pre>
130
131</div>
132<script>
133 function show_debug_request() {
134 var visible=document.getElementById('debug_div').style.display;
135 var new_state="";
136 if ( visible === 'block') { new_state='none';}
137 else
138 if ( visible == 'none') { new_state='block';}
139 else
140 console.log('erreur');
141 document.getElementById('debug_div').style.display=new_state;
142 }
143</script>
144<input type="button" class="tinybutton" style="position:absolute;top:40px;left:50px;margin-left:50px;z-index:1000" value="show request" onclick="show_debug_request()">
145
146<?php
147
148} //<--- if DEBUG
150
151$g_user->Check();
152$g_user->check_dossier(Dossier::id());
154/* Check Browser version if < IE6 then unsupported */
155$browser = $_SERVER['HTTP_USER_AGENT'];
156if (strpos($browser, 'MSIE 6') != false ||
157 strpos($browser, 'MSIE 5') != false)
158{
159
160
161 echo <<<EOF
162 <!--[if lt IE 7]>
163 <div style='border: 1px solid #F7941D; background: #FEEFDA; text-align: center; clear: both; height: 75px; position: relative;'>
164 <div style='position: absolute; right: 3px; top: 3px; font-family: courier new; font-weight: bold;'><a href='#' onclick='javascript:this.parentNode.parentNode.style.display="none"; return false;'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-cornerx.jpg' style='border: none;' alt='Close this notice'/></a></div>
165 <div style='width: 640px; margin: 0 auto; text-align: left; padding: 0; overflow: hidden; color: black;'>
166 <div style='width: 75px; float: left;'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-warning.jpg' alt='Warning!'/></div>
167 <div style='width: 275px; float: left; font-family: Arial, sans-serif;'>
168 <div style='font-size: 14px; font-weight: bold; margin-top: 12px;'>Vous utilisez un navigateur dépassé depuis près de 8 ans!</div>
169 <div style='font-size: 12px; margin-top: 6px; line-height: 12px;'>Pour une meilleure expérience web, prenez le temps de mettre votre navigateur à jour.</div>
170 </div>
171 <div style='width: 75px; float: left;'><a href='http://fr.www.mozilla.com/fr/' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-firefox.jpg' style='border: none;' alt='Get Firefox 3.5'/></a></div>
172 <div style='width: 73px; float: left;'><a href='http://www.apple.com/fr/safari/download/' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-safari.jpg' style='border: none;' alt='Get Safari 4'/></a></div>
173 <div style='float: left;'><a href='http://www.google.com/chrome?hl=fr' target='_blank'><img src='http://www.ie6nomore.com/files/theme/ie6nomore-chrome.jpg' style='border: none;' alt='Get Google Chrome'/></a></div>
174 </div>
175 </div>
176 <![endif]-->
177EOF;
178 exit();
179}
180if ($cn->exist_table('version') == false)
181{
182 echo '<h2 class="error" style="font-size:12px">' . _("Base de donnée invalide") . '</h2>';
183 $base = dirname($_SERVER['REQUEST_URI']);
184 echo HtmlInput::button_anchor('Retour', $base . '/user_login.php');
185 exit();
186}
187if (DBVERSION < dossier::get_version($cn))
188{
189 $a = _("cliquez ici pour mettre à jour ");
190 $base =NOALYSS_URL."/admin-noalyss.php?action=upgrade&sb=application";
191
192 echo '<h2 class="error" style="font-size:12px">' .
193 _("Attention: la version de base de donnée est supérieure à la version du programme, vous devriez mettre à jour") ,
194 '<a class="text-warning line" hreF="' . $base . '">' . $a . '</a></h2>',
195 '</h2>';
196}
197if (DBVERSION > dossier::get_version($cn))
198{
199 echo '<h2 class="error" style="font-size:12px">' . _("Votre base de données n'est pas à jour") . ' ';
200 $a = _("cliquez ici pour appliquer le patch");
201 $base =NOALYSS_URL.'/admin-noalyss.php?action=upgrade&sb=database';
202 echo '<a class="text-warning line" href="' . $base . '">' . $a . '</a></h2>';
203}
204
205/*
206 * Set a correct periode for the user
207 */
208$periode = $g_user->get_periode();
210
211if ($oPeriode->load() == -1)
212{
213 $periode = $cn->get_value('select p_id from parm_periode order by p_start asc limit 1');
214 $g_user->set_periode($periode);
215}
216
218
219?>
220<script>
221/**
222 * All the onload must be here otherwise the other will overwritten
223 * @returns {undefined}
224 */
225window.onload=function ()
226{
227 create_anchor_up();
228 init_scroll();
229 sorttable.init
230}
231</script>
232<?php
233
234/*
235 * if an action is requested
236 */
237if (isset($_REQUEST['ac']))
238{
239 // When debugging save all the input in a file
240 if ( LOGINPUT)
241 {
242 $file_loginput=fopen($_ENV['TMP'].'/scenario-'.$_SERVER['REQUEST_TIME'].'.php','a+');
243 $tmp_ac=explode('/',trim(strtoupper($_REQUEST['ac'])));
244 $last=count($tmp_ac);
245 if ($last > 0) $last--;
246 fwrite ($file_loginput,"<?php \n");
247 fwrite ($file_loginput,'//@description:'.$tmp_ac[$last]."\n");
248 fwrite($file_loginput, '$_GET='.var_export($_GET,true));
249 fwrite($file_loginput,";\n");
250 fwrite($file_loginput, '$_POST='.var_export($_POST,true));
251 fwrite($file_loginput,";\n");
252 fwrite($file_loginput, '$_POST[\'gDossier\']=$gDossierLogInput;');
253 fwrite($file_loginput,"\n");
254 fwrite($file_loginput, '$_GET[\'gDossier\']=$gDossierLogInput;');
255 fwrite($file_loginput,"\n");
256 fwrite($file_loginput,' $_REQUEST=array_merge($_GET,$_POST);');
257 fwrite($file_loginput,"\n");
258 fclose($file_loginput);
259 }
260
261 // Priority to POST , otherwise "duplicate operation" doesn't work
262 $ac_post = trim(strtoupper($http->post("ac","string","")));
263 $ac_get = trim(strtoupper($http->get("ac","string","")));
264
265 $AC=($ac_post == "")?$ac_get:$ac_post;
266 $user_profile=$g_user->get_profile();
267
268
269 $amenu_id=$cn->get_array('select
270 pm_id_v3,pm_id_v2,pm_id_v1
271 from v_menu_profile where code= upper($1) and p_id=$2',
272 array($AC,$user_profile));
273
274 try {
275 if (count($amenu_id) == 0 ) {
276 // if only an Access Direct is asked without the full path
277
278 $aAccess=[];
279 // Find the possible path pm_id_v3 / pm_id_v2 / pm_id_v1
280 $direct_ac=$cn->get_array("select me_file,me_parameter,me_javascript from profile_menu
281 join menu_ref using (me_code)
282 where
283 p_id=$2
284 and me_code=$1", [strtoupper($AC),$user_profile]);
285
286 // if the me_code is available for user, find all the possible path
287 if (!empty($direct_ac)) {
288 $aAccess=$cn->get_array("select code, me_code from v_menu_description where me_code=$1 and p_id=$2",
289 [strtoupper($AC),$user_profile]);
290 }
291
292 if (empty($aAccess)) {
293 throw new Exception(_('Erreur menu'),10);
294 }
295
296 // retrieve the element path
297 $amenu_id=$cn->get_array('select
298 pm_id_v3,pm_id_v2,pm_id_v1
299 from v_menu_profile
300 where code= upper($1) and p_id=$2',
301 array($aAccess[0]['code'],$user_profile));
302
303 }
304 if ( count($amenu_id)> 1) {
305 $tmp=$amenu_id[0];
306 $amenu_id=[];
307 $amenu_id[0]=$tmp;
308 }
309 $amenu_id=complete_default_menu($amenu_id,$user_profile);
310
311 $AC=rebuild_access_code($amenu_id);
312
313 put_global(array(array("key"=>"ac","value"=>$AC)));
314 $module_id=$cn->get_value('select distinct
315 case when pm_id_v3 = 0 then (case when pm_id_v2 = 0 then pm_id_v1 else pm_id_v2 end) else pm_id_v3 end
316 from
317 v_menu_profile
318 where p_id =$1
319 and upper(code)=upper($2)',
320 array($user_profile,$AC));
321 $g_user->audit();
322 // Show module and highligt selected one
323 show_module($module_id);
324
325
326 show_menu( $amenu_id[0]['pm_id_v3']);
327
328 show_menu( $amenu_id[0]['pm_id_v2']);
329
330 show_menu($amenu_id[0]['pm_id_v1']);
331
332
333 } catch (Exception $e) {
334 if ( $e->getCode() == 10 ) {
335 alert(_('Accès menu impossible'));
336 echo '<a class="button" href="do.php?'.Dossier::get().'">';
337 echo _('Retour');
338 echo '</a>';
339 return;
340 }
341 else {
342 alert($e->getMessage());
343 record_log($e->getTraceAsString());
344 throw $e;
345 }
346 }
347}
348else
349{
350 $default = find_default_module();
351 $user_profile=$g_user->get_profile();
352
353 try
354 {
355 if ( $user_profile == "" )
356 throw new Exception (_('Aucun profil utilisateur'));
357
358 $menu_id=$cn->get_value('select
359 case when pm_id_v3 = 0 then
360 (case when pm_id_v2 = 0 then pm_id_v1 else pm_id_v2 end)
361 else pm_id_v3 end
362 from v_menu_profile where code= upper($1) and p_id=$2',
363 array($default,$user_profile));
364 $_GET['ac']=$default;
365 $_POST['ac']=$default;
366 $_REQUEST['ac']=$default;
368 $all[0] = $default;
370 }
371 catch (Exception $exc)
372 {
373 echo $exc->getMessage();
374 record_log("No user profile ");
375 record_log($exc->getMessage());
376 record_log($exc->getTraceAsString());
377 throw $exc;
378 }
379
380}
381
382
h2($p_string, $p_class="", $raw="")
Definition: ac_common.php:68
complete_default_menu($pa_menu)
Check if there is a default menu for this user and add it.
Definition: ac_common.php:1482
put_global($array)
Put in superglobal (get,post,request) the value contained in the parameter field (me_parameter)
Definition: ac_common.php:1233
html_page_start($p_theme="", $p_script="", $p_script2="")
Default page header for each page.
Definition: ac_common.php:275
rebuild_access_code($pan_code)
rebuild the access code
Definition: ac_common.php:1508
find_default_module()
Definition: ac_common.php:991
show_module($selected)
Show the modules.
Definition: ac_common.php:932
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
show_menu($module)
Definition: ac_common.php:1071
alert($p_msg, $buffer=false)
alert in javascript
Definition: ac_common.php:738
$base
Definition: action.inc.php:56
$url
$opd_description style
if(! empty( $error)) for($i=0;$i< count($error);$i++)( $last !=$error[$i]) $last
$input_from type
Definition: balance.inc.php:65
static id()
return the 'gDossier' value after a check
static connect()
static button_anchor($p_label, $p_value, $p_name="", $p_javascript="", $p_class="smallbutton")
create a button with a ref
manage the http input (get , post, request) and extract from an array
static set_firstDate($firstDate)
Class to manage the company parameter (address, name...)
For the periode tables parm_periode and jrn_periode.
const DBVERSION
Definition: constant.php:31
$menu_id
if(strpos( $browser, 'MSIE 6') !=false||strpos( $browser, 'MSIE 5') !=false) if($cn->exist_table('version')==false) if(DBVERSION< dossier::get_version( $cn)) if(DBVERSION > dossier::get_version($cn)) $periode
$_POST['ac']
if(! $cn->exist_table( 'version')) if($g_user->get_access_mode()=='MOBILE') $style_user
if access_mode is MOBILE than force it to mobile.php
$user_profile
if(! isset( $_REQUEST[ 'gDossier'])) if(! isset($_SESSION[SESSION_KEY. 'g_user'])) $cn
$oPeriode
if($oPeriode->load()==-1) $module_selected
global $g_user
$_REQUEST['ac']
$_GET['ac']
global $g_parameter
$browser
$all[0]
for($e=0; $e< count($afiche); $e++) exit
load_all_script()
load all the javascript only one time
redirect($p_string, $p_time=0)