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  */
24 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
25 
26 
27 global $g_user;
28 
29 $g_user=new User($cn);
32 $action=$http->post("action","string","display_form");
33 
34 if (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 //----------------------------------------------------------------------------------------------
60 if ( $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" nohistory>
88  <input type="password" value="" class="input_text" name="pass_2" nohistory>
89  </td>
90  </tr>
91 
92  <tr>
93  <td>
94  <?php echo _('Thème');?>
95  </td>
96  <td>
97  <?php echo $style->input();?>
98  </td>
99  </tr>
100 
101  <?php
102  if ($inside_dossier)
103  {
104  $l_user_per = $g_user->get_periode();
105  if ($l_user_per == "")
106  $l_user_per = $cn->get_value("select min(p_id) from parm_periode where p_closed='f'");
107 
108  // if periode is closed then warns the users
109  $period = new Periode($cn, $l_user_per);
110 
111  $period->p_id = $l_user_per;
112  $period->jrn_def_id = 0;
113  $selected_exercice=$period->get_exercice();
114  $js=sprintf('onchange="updatePeriodePreference(%d);"',Dossier::id());
115  $exercice=new Exercice($cn);
116 
117  if ($period->is_closed($l_user_per) == 1)
118  {
119  $msg = _('Attention cette période est fermée, vous ne pourrez rien modifier dans le module comptable');
120  $msg = '<h2 class="notice">' . $msg . '</h2>';
121  }
122 
123  $iperiod = new IPeriod("period");
124  $iperiod->id="setting_period";
125  $iperiod->user = $g_user;
126  $iperiod->cn = $cn;
127  $iperiod->filter_year = true;
128  $iperiod->exercice=$selected_exercice;
129  $iperiod->value = $l_user_per;
130  $iperiod->type = ALL;
131  $l_form_per = $iperiod->input();
132  ?>
133  <tr>
134  <td>
135  <?=_("Exercice")?>
136  </td>
137  <td>
138  <?=$exercice->select("exercice_setting",$selected_exercice,$js)->input();?>
139  </td>
140  </tr>
141  <tr>
142  <td>
143  <?=_("Premier jour semaine")?>
144  </td>
145  <td>
146  <?php
147  $aFirstDay=array(
148  ["label"=>_("Lundi"),"value"=>1],
149  ["label"=>_("Mardi"),"value"=>2],
150  ["label"=>_("Mercredi"),"value"=>3],
151  ["label"=>_("Jeudi"),"value"=>4],
152  ["label"=>_("Vendredi"),"value"=>5],
153  ["label"=>_("Samedi"),"value"=>6],
154  ["label"=>_("Dimanche"),"value"=>0],
155  );
156  $selFirstDay=new ISelect("selFirstDay");
157  $selFirstDay->value=$aFirstDay;
158  $selFirstDay->selected=$g_user->get_first_week_day();
159  echo $selFirstDay->input();
160  ?>
161 
162  </td>
163  </tr>
164  <tr>
165 
166  <td><?php echo _('Période');?></td>
167  <td>
168  <?php printf(' %s ', $l_form_per);?>
169  </td>
170  <td> <?php echo $msg;?></td>
171  <tr>
172  <td><?php echo _('Taille des pages');?></td>
173  <td>
174  <SELECT NAME="p_size">
175  <option value="15">15
176  <option value="25">25
177  <option value="50">50
178  <option value="100">100
179  <option value="150">150
180  <option value="200">200
181  <option value="-1"><?php echo _('Illimité');?>
182  <?php
183  $label = ($_SESSION[SESSION_KEY.'g_pagesize'] == -1) ? _('Illimité') : $_SESSION[SESSION_KEY.'g_pagesize'];
184  echo '<option value="' . $_SESSION[SESSION_KEY.'g_pagesize'] . '" selected>' . $label;
185  ?>
186  </SELECT>
187 
188  </td>
189  </tr>
190  <?php
191  }
192  ?>
193  </table>
194  </fieldset>
195  <fieldset>
196  <legend><?=_("Format Export CSV")?></legend>
197  <p>
198  <?php
199  if ( $_SESSION[SESSION_KEY.'csv_fieldsep']==1 && $_SESSION[SESSION_KEY.'csv_decimal']==1)
200  {
201  echo_warning(_("N'utilisez pas le même séparateur pour les champs et les décimales"));
202  }
203  ?>
204  </p>
205  <table>
206  <tr>
207  <td>
208  <?=_("Séparateur de champs")?>
209  </td>
210  <td>
211  <?php
212  $csv_fieldsep=new ISelect('csv_fieldsep');
213  $csv_fieldsep->value=[
214  ["label"=>_("Point-virgule"),"value"=>0],
215  ["label"=>_("virgule"),"value"=>1]
216  ];
217  $csv_fieldsep->selected=$_SESSION[SESSION_KEY.'csv_fieldsep'];
218  echo $csv_fieldsep->input();
219  ?>
220  </td>
221  </tr>
222  <tr>
223  <td>
224  <?=_("Séparateur Décimale")?>
225  </td>
226  <td>
227  <?php
228  $csv_decimal=new ISelect('csv_decimal');
229  $csv_decimal->value=[
230  ["label"=>_("point"),"value"=>0],
231  ["label"=>_("virgule"),"value"=>1]
232  ];
233  $csv_decimal->selected=$_SESSION[SESSION_KEY.'csv_decimal'];
234  echo $csv_decimal->input();
235  ?>
236  </td>
237  </tr>
238  <tr>
239  <td>
240  <?=_("Encodage")?>
241  </td>
242  <td>
243  <?php
244  $csv_encoding=new ISelect('csv_encoding');
245  $csv_encoding->value=[
246  ["label"=>_("utf8"),"value"=>'utf8'],
247  ["label"=>_("latin1"),"value"=>'latin1']
248  ];
249  $csv_encoding->selected=$_SESSION[SESSION_KEY.'csv_encoding'];
250  echo $csv_encoding->input();
251  ?>
252  </td>
253  </tr>
254  </table>
255 
256  </fieldset>
257  <?php
258  if ($inside_dossier)
259  {
260  /* Pref for welcome page */
261  echo '<fieldset style="margin: 1%">';
262  echo '<legend>' . _('Options pour la page d\'accueil') . '</legend>';
263  echo _('Mini-Rapport : ');
264  $rapport = new Acc_Report($cn);
265  $aRapport = $rapport->make_array();
266  $aRapport[] = array("value" => 0, "label" => _('Aucun mini rapport'));
267  $wRapport = new ISelect();
268  $wRapport->name = "minirap";
269  $wRapport->selected = $g_user->get_mini_report();
270  $wRapport->value = $aRapport;
271  echo $wRapport->input();
272  echo '<span class="notice">' . _('Le mini rapport est un rapport qui s\'affiche sur votre page d\'accueil') . '</span>';
273  echo '</fieldset>';
274  }
275 
276  echo '<fieldset style="margin: 1%">';
277  echo '<legend>' . _('Langue') . '</legend>';
278  echo _('Selectionnez votre langue');
279  $aLang = array(array(_('Français'), 'fr_FR.utf8'),
280  array(_('Anglais'), 'en_US.utf8'),
281  array(_('Néerlandais'), 'nl_NL.utf8'),
282  );
283  echo '<select name="lang" id="l">';
284  for ($i = 0; $i < count($aLang); $i++)
285  {
286  $sel = "";
287  if ($aLang[$i][1] == $_SESSION[SESSION_KEY.'g_lang'])
288  $sel = " selected ";
289  printf('<option value="%s" %s>%s</option>', $aLang[$i][1], $sel, $aLang[$i][0]);
290  }
291  echo '</select>';
292  echo '</fieldset>';
293 
294  if ($inside_dossier){
295  echo Dossier::hidden();
296  }
297  echo '<p style="text-align:center">';
298  echo HtmlInput::button_close('preference_div');
299  echo HtmlInput::submit("set_preference", _("Valider"));
300  echo '</p>';
301  echo '</form>';
302 
303  echo "</DIV>";
304  ?>
305 <?php
306 }
307 //---------------------------------------------------------------------------------------------------------------------
308 // Save the form
309 //---------------------------------------------------------------------------------------------------------------------
310 if ($action == 'save')
311 {
312  //// Save value
313  $style_user=$http->post("style_user","string","Classique");
314  $lang=$http->post("lang","string","fr_FR.utf8");
315  $p_size=$http->post("p_size","number",50);
316  $pass_1=$http->post("pass_1","string","");
317  $pass_2=$http->post("pass_2","string","");
318  $p_email=$http->post("p_email","string","");
319  $csv_fieldsep=$http->post("csv_fieldsep","number");
320  $csv_decimal=$http->post("csv_decimal","number");
321  $csv_encoding=$http->post("csv_encoding");
322  $firstday=$http->post("selFirstDay","number");
323 
324  if (strlen(trim($pass_1)) != 0 && strlen(trim($pass_2)) != 0)
325  {
326  $g_user->save_password($pass_1,$pass_2);
327 
328  }
329  if ( $inside_dossier)
330  {
331  $minirap=$http->post("minirap","number","0");
332  $period=$http->post("period","number");
333  $g_user->set_periode($period);
334  $g_user->set_mini_report($minirap);
335  }
336  $g_user->save_global_preference('THEME', $style_user);
337  $g_user->save_global_preference('LANG', $lang);
338  $g_user->save_global_preference('PAGESIZE', $p_size);
339  $g_user->save_global_preference('csv_fieldsep', $csv_fieldsep);
340  $g_user->save_global_preference('csv_decimal', $csv_decimal);
341  $g_user->save_global_preference('csv_encoding', $csv_encoding);
342  $g_user->save_global_preference('first_week_day', $firstday);
343  $g_user->save_email($p_email);
344 
345  $_SESSION[SESSION_KEY.'g_theme']=$style_user;
346  $_SESSION[SESSION_KEY.'g_pagesize']=$p_size;
347  $_SESSION[SESSION_KEY.'g_lang']=$lang;
348 
349  // find the right CSS theme
350  $style= $repo->get_value("select the_filestyle from theme
351  where the_name=$1" ,[$style_user]);
352  if ($style == "")
353  {
354  $style = "style-classic7.css";
355  }
356  json_response(["style"=>$style]);
357 
358 }
$sel
$sel
Definition: lettering.account.inc.php:90
Periode
For the periode tables parm_periode and jrn_periode.
Definition: periode.class.php:32
style
$opd_description style
Definition: ajax_mod_predf_op.php:52
IPeriod
Generate the form for the periode Data Members.
Definition: iperiod.class.php:34
Acc_Report
Class rapport Create, view, modify and parse report.
Definition: acc_report.class.php:32
Dossier\hidden
static hidden()
return a string to set gDossier into a FORM
Definition: dossier.class.php:190
$rapport
$rapport
Definition: dashboard.php:143
ALL
const ALL
Definition: constant.php:194
$exercice
catch(Exception $e) $exercice
Definition: ajax_display_letter.php:45
HtmlInput\button_close
static button_close($div_name)
close button for the HTML popup
Definition: html_input.class.php:430
HttpInput
manage the http input (get , post, request) and extract from an array
Definition: http_input.class.php:37
echo_warning
echo_warning($p_string)
warns
Definition: ac_common.php:582
p
p($p_string)
Definition: ac_common.php:39
tr
tr($p_string, $p_extra='')
Definition: ac_common.php:88
$g_user
global $g_user
Definition: ajax_preference.php:27
HtmlInput\title_box
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".
Definition: html_input.class.php:838
$msg
$msg
Definition: ajax_create_menu.php:10
Dossier\connect
static connect()
Definition: dossier.class.php:282
$action
$action
Definition: ajax_preference.php:32
name
$from_poste name
Definition: balance.inc.php:159
$i
$i
Definition: action_document_type_mtable_input.php:83
$label
$label
Definition: impress_jrn.inc.php:115
type
$input_from type
Definition: balance.inc.php:65
HtmlInput\submit
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
Definition: html_input.class.php:199
$_REQUEST
$_REQUEST['ac']
Definition: ajax_search_action.php:26
$cn
$cn
Definition: ajax_anc_accounting.php:30
json_response
json_response($p_answer)
Send header and json object.
Definition: function_javascript.php:2794
User
Data & function about connected users.
Definition: user.class.php:33
Dossier\id
static id()
return the $_REQUEST['gDossier'] after a check
Definition: dossier.class.php:55
Database
contains the class for connecting to Noalyss
Definition: database.class.php:32
table
$all table
Definition: company.inc.php:138
$repo
if(isset($_REQUEST['gDossier']) && $http->request("gDossier","number", 0) !=0) $repo
Definition: ajax_preference.php:47
$inside_dossier
$inside_dossier
Definition: ajax_preference.php:30
$style
$style
Definition: ajax_preference.php:51
$http
$http
Definition: ajax_preference.php:31
td
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
$style_user
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:77
$res
$res
Definition: ajax_preference.php:49
value
$style value
Definition: ajax_preference.php:52
Exercice
about the accountancy period (usually 1 year starting in January until december) = exercice
Definition: exercice.class.php:30
ISelect
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Definition: iselect.class.php:39
$js
$js
Definition: ajax_tag_list.php:32