noalyss Version-9
noalyss_appearance.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 * NOALYSS is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * NOALYSS is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with NOALYSS; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Copyright Author Dany De Bontridder danydb@noalyss.eu
19 *
20 */
21
22/**
23 * @file
24 * @brief Contains some parameters to change appearance of noalyss
25 */
26
27/**
28 * @class
29 * @brief Contains some parameters to change appearance of noalyss, the colors are saved
30 * into the table parm_appearance
31 */
33{
34 static private $aCSSColor = ['H2' => '#9fbcd6',
35 'MENU1' => '#000074',
36 'BODY' => '#ffffff',
37 'MENU2' => '#3d3d87',
38 'MENU1-SELECTED' => '#506cb8',
39 'TR-ODD'=>'#DCE7F5',
40 'TR-EVEN'=>'#ffffff',
41 'INNER-BOX'=>'#DCE1EF',
42 'INNER-BOX-TITLE'=>'#023575',
43 'FONT-MENU1' => '#ffffff',
44 'FONT-MENU2' => '#ffffff',
45 'FONT-TABLE' => '#222bd0',
46 'FONT-DEFAULT' => '#000074',
47 'FOLDER' => '#ffffff',
48 'FONT-TABLE-HEADER' =>'#0C106D',
49 'FONT-FOLDER' => '#000074'];
50 static private $aCSSColorName = array();
51 private $aColor;
52
53 function __construct()
54 {
55 self::$aCSSColorName = ['H2' => _("Titre"),
56 'MENU1' => _("Fond"),
57 'BODY' => _("Fond"),
58 'MENU2' => _("Fond"),
59 'MENU1-SELECTED' => _("Fond item choisi"),
60 'TR-ODD'=>_("Ligne impaire"),
61 'TR-EVEN'=>_("Ligne paire"),
62 'INNER-BOX'=>_("Fond Boîte dialogue"),
63 'INNER-BOX-TITLE'=>_("Fond titre dialogue"),
64 'FOLDER' => _("Fond "),
65 'FONT-MENU1' => _("Caractère"),
66 'FONT-MENU2' => _("Caractère"),
67 'FONT-TABLE' => _("Caractère"),
68 'FONT-DEFAULT' => _("Caractère par défaut"),
69 'FONT-TABLE-HEADER' => _("Caractère en-tête"),
70 'FONT-FOLDER' => _("Caractère")];
71 $this->aColor=self::$aCSSColor;
72 }
73
74 function load():void
75 {
77 $aColor = $cn->get_array("select a_code,a_value from parm_appearance");
78 foreach ($aColor as $key => $value) {
79 $this->aColor[$value['a_code']] = $value['a_value'];
80 }
81
82 }
83
84 function save()
85 {
87 foreach ($this->aColor as $key => $value) {
88 $cn->exec_sql("insert into parm_appearance values ($1,$2)
89 on conflict (a_code) do update set a_value =excluded.a_value", [$key, $value]);
90 }
91 }
92
93 /**
94 * @param string[] $aColor
95 */
96 public function get_color($p_code)
97 {
98 if (isset($this->aColor[$p_code])) {
99 return $this->aColor[$p_code];
100 }
101 throw new Exception('NAP100: INVALID CODE');
102 }
103 function set_color($p_code, $p_value)
104 {
105 $aKey = array_keys($this->aColor);
106 if (!in_array($p_code, $aKey)) {
107 throw new \Exception("NA63: Code invalide ");
108 }
109 if (!preg_match('/^#[a-f0-9]{6}$/i', $p_value)) //hex color is valid
110 {
111 throw new \Exception("NA67: Couleur invalide ");
112 }
113 $this->aColor[$p_code] = $p_value;
114 }
115
116 function print_css()
117 {
118 $this->load();
119 $body = $this->aColor['BODY'];
120 $h2 = $this->aColor['H2'];
121 $menu1 = $this->aColor['MENU1'];
122 $menu2 = $this->aColor['MENU2'];
123 $menu1_selected = $this->aColor['MENU1-SELECTED'];
124 $menu1_font = $this->aColor['FONT-MENU1'];
125 $menu2_font = $this->aColor['FONT-MENU2'];
126 $font_table = $this->aColor['FONT-TABLE'];
127 $font_default = $this->aColor['FONT-DEFAULT'];
128 $font_table_header = $this->aColor['FONT-TABLE-HEADER'];
129 $folder_font = $this->aColor['FONT-FOLDER'];
130 $folder = $this->aColor['FOLDER'];
131 $tr_odd=$this->aColor['TR-ODD'];
132 $tr_even=$this->aColor['TR-EVEN'];
133 $inner_box=$this->aColor['INNER-BOX'];
134 $inner_box_title=$this->aColor['INNER-BOX-TITLE'];
135
136 echo <<<EOF
137 <style>
138#top {
139 color:{$folder_font};
140 background-color: transparent;
141 }
142 #dossier,#module {
143 color:{$folder_font};
144 background-color: {$folder};
145 }
146 body {
147 background-color: {$body} !important;
148 color:{$font_default} !important;
149 }
150 h2 , hr {
151 background-color: {$h2} ;
152 }
153 h2.title {
154 background-color: {$inner_box_title} ;
155 }
156 .nav-fill .nav-item {
157 background: {$menu1};
158 color: {$menu1_font};
159 }
160 .nav-level2 {
161 background-color: {$menu2};
162 color:{$menu2_font};
163 }
164 .nav-pills .nav-link.active {
165 background-color: {$menu1_selected} !important;
166 }
167 table.sortable, table.table_large, table.result ,table.resultfooter {
168 color:{$font_table} !important;
169 }
170 table.sortable th, table.table_large th, table.result th ,table.resultfooter th {
171 color:{$font_table_header};
172 }
173 tr.odd,div.inner_box tr.odd,div.box tr.odd {
174 background-color: {$tr_odd};
175 }
176 #calc1 , div.inner_box , div.box, #add_todo_list , div.add_todo_list,body.op_detail_frame, div.op_detail_frame {
177 background-color:{$inner_box};
178 }
179 tr.even {
180 background-color: {$tr_even} ;
181 }
182 </style>
183
184EOF;
185
186 }
187
188 function input_reset()
189 {
190 $r="";
191 $label=_("Cocher pour remettre les couleurs d'origine");
192 $chk=new ICheckBox("reset_color",1);
193
194 $str_reset=$chk->input();
195 $r.=<<<EOF
196<div class="form-group">
197 <label for="reset_color">
198 {$label}
199</label>
200 {$str_reset}
201</div>
202EOF;
203 return $r;
204
205 }
206
207 /**
208 * Build a html string for each color
209 * @param $p_key string key of $this->aCSSColor
210 * @return string
211 */
212 private function build_input_row(string $p_key):string
213 {
214 $value = $this->aColor[$p_key];
215 $icolor = new IColor($p_key, $value);
216 $label = self::$aCSSColorName[$p_key];
217 $str_icolor = $icolor->input();
218 $str="";
219 $str .= <<<EOF
220<div class="form-group">
221 <label for="{$p_key}">
222 {$label}
223</label>
224 {$str_icolor}
225</div>
226EOF;
227 return $str;
228 }
229 private function title($p_string)
230 {
231 return '<h3 class="">'.h($p_string).'</h3>';
232 }
233 /**
234 * Build the HTML string for inputing the color
235 * @return string
236 */
237 function input_form()
238 {
239 $str = "";
240 $str.=$this->title(_("(1) Général"));
241 $str .= $this->build_input_row('BODY');
242 $str .= $this->build_input_row('FONT-DEFAULT');
243
244 $str.=$this->title(_("(2) En-tête dossier"));
245 $str .= $this->build_input_row('FOLDER');
246 $str .= $this->build_input_row('FONT-FOLDER');
247
248 $str.=$this->title('(3)'._("Titre"));
249 $str .= $this->build_input_row('H2');
250
251 $str.=$this->title('(4)'._("Menu principal"));
252 $str .= $this->build_input_row('MENU1');
253 $str .= $this->build_input_row('FONT-MENU1');
254 $str .= $this->build_input_row('MENU1-SELECTED');
255
256 $str.=$this->title('(5)'._("Sous-Menu"));
257 $str .= $this->build_input_row('MENU2');
258 $str .= $this->build_input_row('FONT-MENU2');
259
260 $str.=$this->title('(6)'._("Tableau"));
261 $str .= $this->build_input_row('FONT-TABLE');
262 $str .= $this->build_input_row('TR-ODD');
263 $str .= $this->build_input_row('TR-EVEN');
264 $str .= $this->build_input_row('FONT-TABLE-HEADER');
265
266
267 $str.=$this->title('(7)'._("Boîte de dialogue"));
268 $str .= $this->build_input_row('INNER-BOX');
269 $str .= $this->build_input_row('INNER-BOX-TITLE');
270
271 $str.=$this->input_reset();
272 return $str;
273 }
274
275 /**
276 * @return string[]
277 */
278 public static function getACSSColor(): array
279 {
280 return self::$aCSSColor;
281 }
282
283 /**
284 * @param string[] $aCSSColor
285 */
286 public static function setACSSColor(array $aCSSColor): void
287 {
288 self::$aCSSColor = $aCSSColor;
289 }
290
291 /**
292 * @return array
293 */
294 public static function getACSSColorName(): array
295 {
296 return self::$aCSSColorName;
297 }
298
299 /**
300 * @param array $aCSSColorName
301 */
302 public static function setACSSColorName(array $aCSSColorName): void
303 {
304 self::$aCSSColorName = $aCSSColorName;
305 }
306
307 function reset()
308 {
309 $this->aColor=self::$aCSSColor ;
310 }
311 /**
312 *@brief retrieve data from POST and returns true, if nothing is retrieved , returns false
313 */
314 function from_post()
315 {
316 $http=new \HttpInput();
317 if ( $http->post("reset_color","number",0) == 1 ) {
318 $this->reset();
319 return true;
320 }
321 foreach (self::$aCSSColorName as $key=>$value) {
322 $color=$http->post($key,'string',"");
323 if (empty($color) ) { return false;}
324 $this->set_color($key,$color);
325 }
326
327 return true;
328 }
329}
330
331
332
h2($p_string, $p_class="", $raw="")
Definition: ac_common.php:68
th($p_string, $p_extra='', $raw='')
Definition: ac_common.php:58
tr($p_string, $p_extra='')
Definition: ac_common.php:88
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$ret label
$opd_description style
static connect()
Html Input.
set_color($p_code, $p_value)
static setACSSColor(array $aCSSColor)
build_input_row(string $p_key)
Build a html string for each color.
from_post()
retrieve data from POST and returns true, if nothing is retrieved , returns false
static setACSSColorName(array $aCSSColorName)
input_form()
Build the HTML string for inputing the color.
$all table
$anc_filter title
$str
Definition: fiche.inc.php:91
$chk