noalyss Version-9
ajax_preference.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// Copyright Author Dany De Bontridder danydb@aevalys.eu
20/**\file
21 * \brief this file is always included and then executed
22 * it permits to change the user preferences
23 */
24if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
25
26
27global $g_user;
28
32$action=$http->post("action","string","display_form");
33
34if (isset($_REQUEST['gDossier']) && $http->request("gDossier","number",0) != 0 )
35{
36 $g_user->load_global_pref();
37 $msg = "";
39 $g_user->cn = $cn;
40 $inside_dossier = true;
41 $local_pref=$g_user->get_preference();
42}
43//////////////////////////////////////////////////////////////////////////
44// Theme
45//////////////////////////////////////////////////////////////////////////
46
47 $repo = new Database();
48// charge tous les styles
49 $res = $repo->exec_sql("select the_name from theme
50 order by the_name");
51 $style = new ISelect('style_user');
52 $style->value = $repo->make_array("select the_name,the_name
53 from theme
54 order by the_name");
55 $style->selected =$_SESSION[SESSION_KEY.'g_theme'];
56
57//----------------------------------------------------------------------------------------------
58// Display the form
59//----------------------------------------------------------------------------------------------
60if ( $action == 'display_form' )
61{
62 echo HtmlInput::title_box(_('Préférence'), 'preference_div');
63 echo '<DIV class="content">';
64 echo '<p class="notice">';
65 echo _("Après validation, recharger pour appliquer les changements");
66 echo '</p>';
67 //----------------------------------------------------------------------
68 //
69?>
70
71<div class="content" >
72
73 <FORM METHOD="POST" onsubmit="updatePreference();return false;" id="preference_frm">
74 <fieldset style="margin: 1%"><legend><?php echo _('Options Générales')?></legend>
75 <table>
76 <tr>
77 <td>
78 <?php echo _('Email')?>
79 </td>
80 <td>
81 <input type="text" name="p_email" value="<?php echo $g_user->email?>" class="input_text">
82 </td>
83 </tr>
84 <tr><td>
85 Mot de passe :
86 </td>
87 <td><input type="password" value="" class="input_text" name="pass_1" id="pass_1" nohistory onkeyup=check_password_strength('pass_1','info_passid',1)>
88 <input type="password" value="" class="input_text" name="pass_2" nohistory>
89 <span id="info_passid"></span>
90 </td>
91 </tr>
92
93 <tr>
94 <td>
95 <?php echo _('Thème');?>
96 </td>
97 <td>
98 <?php echo $style->input();?>
99 </td>
100 </tr>
101
102 <?php
103 if ($inside_dossier)
104 {
105 $l_user_per = $g_user->get_periode();
106 if ($l_user_per == "")
107 $l_user_per = $cn->get_value("select min(p_id) from parm_periode where p_closed='f'");
108
109 // if periode is closed then warns the users
110 $period = new Periode($cn, $l_user_per);
111
112 $period->p_id = $l_user_per;
113 $period->jrn_def_id = 0;
114 $selected_exercice=$period->get_exercice();
115 $js=sprintf('onchange="updatePeriodePreference(%d);"',Dossier::id());
117
118 if ($period->is_closed($l_user_per) == 1)
119 {
120 $msg = _('Attention cette période est fermée, vous ne pourrez rien modifier dans le module comptable');
121 $msg = '<h2 class="notice">' . $msg . '</h2>';
122 }
123
124 $iperiod = new IPeriod("period");
125 $iperiod->id="setting_period";
126 $iperiod->user = $g_user;
127 $iperiod->cn = $cn;
128 $iperiod->filter_year = true;
129 $iperiod->exercice=$selected_exercice;
130 $iperiod->value = $l_user_per;
131 $iperiod->type = ALL;
132 $l_form_per = $iperiod->input();
133 ?>
134 <tr>
135 <td>
136 <?=_("Exercice")?>
137 </td>
138 <td>
139 <?=$exercice->select("exercice_setting",$selected_exercice,$js)->input();?>
140 </td>
141 </tr>
142
143 <tr>
144
145 <td><?php echo _('Période');?></td>
146 <td>
147 <?php printf(' %s ', $l_form_per);?>
148 </td>
149 <td> <?php echo $msg;?></td>
150 <tr>
151 <td><?php echo _('Taille des pages');?></td>
152 <td>
153 <SELECT NAME="p_size">
154 <option value="15">15
155 <option value="25">25
156 <option value="50">50
157 <option value="100">100
158 <option value="150">150
159 <option value="200">200
160 <option value="-1"><?php echo _('Illimité');?>
161 <?php
162 $label = ($_SESSION[SESSION_KEY.'g_pagesize'] == -1) ? _('Illimité') : $_SESSION[SESSION_KEY.'g_pagesize'];
163 echo '<option value="' . $_SESSION[SESSION_KEY.'g_pagesize'] . '" selected>' . $label;
164 ?>
165 </SELECT>
166
167 </td>
168 </tr>
169 <?php
170 }
171 ?>
172 <tr>
173 <td>
174 <?=_("Premier jour semaine")?>
175 </td>
176 <td>
177 <?php
178 $aFirstDay=array(
179 ["label"=>_("Lundi"),"value"=>1],
180 ["label"=>_("Mardi"),"value"=>2],
181 ["label"=>_("Mercredi"),"value"=>3],
182 ["label"=>_("Jeudi"),"value"=>4],
183 ["label"=>_("Vendredi"),"value"=>5],
184 ["label"=>_("Samedi"),"value"=>6],
185 ["label"=>_("Dimanche"),"value"=>0],
186 );
187 $selFirstDay=new ISelect("selFirstDay");
188 $selFirstDay->value=$aFirstDay;
189 $selFirstDay->selected=$g_user->get_first_week_day();
190 echo $selFirstDay->input();
191 ?>
192
193 </td>
194 </tr>
195 </table>
196 </fieldset>
197 <fieldset>
198 <legend><?=_("Format Export CSV")?></legend>
199 <p>
200 <?php
201 if ( $_SESSION[SESSION_KEY.'csv_fieldsep']==1 && $_SESSION[SESSION_KEY.'csv_decimal']==1)
202 {
203 echo_warning(_("N'utilisez pas le même séparateur pour les champs et les décimales"));
204 }
205 ?>
206 </p>
207 <table>
208 <tr>
209 <td>
210 <?=_("Séparateur de champs")?>
211 </td>
212 <td>
213 <?php
214 $csv_fieldsep=new ISelect('csv_fieldsep');
215 $csv_fieldsep->value=[
216 ["label"=>_("Point-virgule"),"value"=>0],
217 ["label"=>_("virgule"),"value"=>1]
218 ];
219 $csv_fieldsep->selected=$_SESSION[SESSION_KEY.'csv_fieldsep'];
220 echo $csv_fieldsep->input();
221 ?>
222 </td>
223 </tr>
224 <tr>
225 <td>
226 <?=_("Séparateur Décimale")?>
227 </td>
228 <td>
229 <?php
230 $csv_decimal=new ISelect('csv_decimal');
231 $csv_decimal->value=[
232 ["label"=>_("point"),"value"=>0],
233 ["label"=>_("virgule"),"value"=>1]
234 ];
235 $csv_decimal->selected=$_SESSION[SESSION_KEY.'csv_decimal'];
236 echo $csv_decimal->input();
237 ?>
238 </td>
239 </tr>
240 <tr>
241 <td>
242 <?=_("Encodage")?>
243 </td>
244 <td>
245 <?php
246 $csv_encoding=new ISelect('csv_encoding');
247 $csv_encoding->value=[
248 ["label"=>_("utf8"),"value"=>'utf8'],
249 ["label"=>_("latin1"),"value"=>'latin1']
250 ];
251 $csv_encoding->selected=$_SESSION[SESSION_KEY.'csv_encoding'];
252 echo $csv_encoding->input();
253 ?>
254 </td>
255 </tr>
256 </table>
257
258 </fieldset>
259 <?php
260 if ($inside_dossier)
261 {
262 /* Pref for welcome page */
263 echo '<fieldset style="margin: 1%">';
264 echo '<legend>' . _('Options pour la page d\'accueil') . '</legend>';
265 echo _('Mini-Rapport : ');
266 $rapport = new Acc_Report($cn);
267 $aRapport = $rapport->make_array();
268 $aRapport[] = array("value" => 0, "label" => _('Aucun mini rapport'));
269 $wRapport = new ISelect();
270 $wRapport->name = "minirap";
271 $wRapport->selected = $g_user->get_mini_report();
272 $wRapport->value = $aRapport;
273 echo $wRapport->input();
274 echo '<span class="notice">' . _('Le mini rapport est un rapport qui s\'affiche sur votre page d\'accueil') . '</span>';
275 echo '</fieldset>';
276 }
277
278 echo '<fieldset style="margin: 1%">';
279 echo '<legend>' . _('Langue') . '</legend>';
280 echo _('Selectionnez votre langue');
281 $aLang = array(array(_('Français'), 'fr_FR.utf8'),
282 array(_('Anglais'), 'en_US.utf8'),
283 array(_('Néerlandais'), 'nl_NL.utf8'),
284 );
285 echo '<select name="lang" id="l">';
286 for ($i = 0; $i < count($aLang); $i++)
287 {
288 $sel = "";
289 if ($aLang[$i][1] == $_SESSION[SESSION_KEY.'g_lang'])
290 $sel = " selected ";
291 printf('<option value="%s" %s>%s</option>', $aLang[$i][1], $sel, $aLang[$i][0]);
292 }
293 echo '</select>';
294 echo '</fieldset>';
295
296 if ($inside_dossier){
297 echo Dossier::hidden();
298 }
299 echo '<p style="text-align:center">';
300 echo HtmlInput::button_close('preference_div');
301 echo HtmlInput::submit("set_preference", _("Valider"));
302 echo '</p>';
303 echo '</form>';
304
305 echo "</DIV>";
306 ?>
307<?php
308}
309//---------------------------------------------------------------------------------------------------------------------
310// Save the form
311//---------------------------------------------------------------------------------------------------------------------
312if ($action == 'save')
313{
314 //// Save value
315 $style_user=$http->post("style_user","string","Classique");
316 $lang=$http->post("lang","string","fr_FR.utf8");
317 $p_size=$http->post("p_size","number",50);
318 $pass_1=$http->post("pass_1","string","");
319 $pass_2=$http->post("pass_2","string","");
320 $p_email=$http->post("p_email","string","");
321 $csv_fieldsep=$http->post("csv_fieldsep","number");
322 $csv_decimal=$http->post("csv_decimal","number");
323 $csv_encoding=$http->post("csv_encoding");
324 $firstday=$http->post("selFirstDay","number");
325 $password="OK";
326 $msg ="";
327 if (noalyss_strlentrim($pass_1) != 0 && noalyss_strlentrim($pass_2) != 0)
328 {
329 if ( $g_user->save_password($_POST['pass_1'],$pass_2) )
330 {
331 $g_user->password_to_session() ;
332
333 } else {
334 /**
335 * password not changed
336 */
337 $password="NOK";
338 $msg="";
339 if ( $_POST['pass_1'] !== $pass_2) {
340 $msg = _("Mot de passe ne correspondent pas");
341 $msg .="<br/>";
342 }
343 $a_pass_error=check_password_strength($_POST['pass_1']);
344 if ( count($a_pass_error['msg']) != 0 ) {
345 foreach($a_pass_error['msg'] as $pass_error) {
346 $msg.=$pass_error."<br/>";
347 }
348 }
349
350 }
351 }
352 if ( $inside_dossier)
353 {
354 $minirap=$http->post("minirap","number","0");
355 $period=$http->post("period","number");
356 $g_user->set_periode($period);
357 $g_user->set_mini_report($minirap);
358 }
359 $g_user->save_global_preference('THEME', $style_user);
360 $g_user->save_global_preference('LANG', $lang);
361 $g_user->save_global_preference('PAGESIZE', $p_size);
362 $g_user->save_global_preference('csv_fieldsep', $csv_fieldsep);
363 $g_user->save_global_preference('csv_decimal', $csv_decimal);
364 $g_user->save_global_preference('csv_encoding', $csv_encoding);
365 $g_user->save_global_preference('first_week_day', $firstday);
366 $g_user->save_email($p_email);
367
368 $_SESSION[SESSION_KEY.'g_theme']=$style_user;
369 $_SESSION[SESSION_KEY.'g_pagesize']=$p_size;
370 $_SESSION[SESSION_KEY.'g_lang']=$lang;
371 $_SESSION[SESSION_KEY.'csv_fieldsep']=$csv_fieldsep;
372 $_SESSION[SESSION_KEY.'csv_decimal']=$csv_decimal;
373 $_SESSION[SESSION_KEY.'csv_encoding']=$csv_encoding;
374
375 // find the right CSS theme
376 $style= $repo->get_value("select the_filestyle from theme
377 where the_name=$1" ,[$style_user]);
378 if ($style == "")
379 {
380 $style = "style-classic7.css";
381 }
382 json_response(["style"=>$style,'psw'=>$password,'msg'=>$msg]);
383
384}
span($p_string, $p_extra='')
Definition: ac_common.php:43
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549
echo_warning($p_string)
warns
Definition: ac_common.php:589
check_password_strength($password)
returns an double array with the error found and code , if the count is 0 then the password is very s...
Definition: ac_common.php:1700
tr($p_string, $p_extra='')
Definition: ac_common.php:88
p($p_string)
Definition: ac_common.php:39
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
catch(Exception $e) $exercice
$opd_description style
$inside_dossier
global $g_user
if(isset($_REQUEST['gDossier']) && $http->request("gDossier","number", 0) !=0) $repo
$style value
$_REQUEST['ac']
$from_poste name
$input_from type
Definition: balance.inc.php:65
Class rapport Create, view, modify and parse report.
contains the class for connecting to Noalyss
static id()
return the 'gDossier' value after a check
static hidden()
return a string to set gDossier into a FORM
static connect()
about the accountancy period (usually 1 year starting in January until december) = exercice
static button_close($div_name, $class='smallbutton')
close button for the HTML popup
static title_box($p_name, $p_div, $p_mod="close", $p_js="", $p_draggable="n", $p_enlarge='n')
Title for boxes, you can customize the symbol thanks symbol with the mode "custom".
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
manage the http input (get , post, request) and extract from an array
Generate the form for the periode Data Members.
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Data & function about connected users.
For the periode tables parm_periode and jrn_periode.
$all table
const ALL
Definition: constant.php:204
$rapport
Definition: dashboard.php:50
$_POST['ac']
Definition: do.php:310
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
Definition: do.php:83
json_response($p_answer)
Send header and json object.