noalyss Version-9
input_switch.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * * Copyright (C) 2019 Dany De Bontridder <dany@alchimerys.be>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program 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 this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Aut
20 *
21 */
22
23// Copyright Author Dany De Bontridder danydb@noalyss.eu
24
25/**
26 * @file
27 * @brief show a switch, when you click on it an hidden field is changed, the value is 1 or 0
28 */
29/**
30 * @class InputSwitch
31 * @brief show a switch, when you click on it an hidden field is changed, the value is 1 or 0
32 */
33
35{
36
37 var $icon;
39 var $value;
40
41 function __construct($name='', $value='', $p_id="")
42 {
43 $this->name=$name;
44 $this->value_container=uniqid();
45 $this->value=$value;
46 $this->icon=$p_id;
47 $this->javascript="";
48 }
49
50 function input($p_name=NULL, $p_value=NULL)
51 {
52 $r="";
53 if ($p_name!=NULL)
54 $this->name=$p_name;
55 if ($p_value!=NULL)
56 $this->value=$p_value;
57
58 if ( $this->icon=="") $this->icon=uniqid ("inputSwitch");
59
60 if ( trim($this->value_container) ==="" || trim($this->value) === "") {
61 throw new Exception(_("Valeur invalide"),1);
62 }
63 if ($this->readOnly == TRUE) {
64 return $this->display();
65 }
66 $r.= HtmlInput::hidden($this->name, $this->value,$this->value_container);
67
68 $this->javascript=sprintf('toggle_onoff(\'%s\',\'%s\');%s;',$this->icon,$this->value_container,$this->javascript);
69
70 if ($this->value=='1') {
71 $r.=Icon_Action::iconon($this->icon, $this->javascript);
72 } else {
73 $r.=Icon_Action::iconoff($this->icon, $this->javascript);
74 }
75 return $r;
76 }
77 function display()
78 {
79 if ($this->value=='1') {
80 return Icon_Action::iconon($this->icon, "");
81 } else {
82 return Icon_Action::iconoff($this->icon, "");
83 }
84 }
85
86}
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$ret javascript
$from_poste name
class widget This class is used to create all the HTML INPUT TYPE and some specials which works with ...
static hidden($p_name, $p_value, $p_id="")
static iconoff($p_id, $p_javascript, $p_style="")
Display a icon OFF.
static iconon($p_id, $p_javascript, $p_style="")
Display a icon ON.
show a switch, when you click on it an hidden field is changed, the value is 1 or 0
__construct($name='', $value='', $p_id="")
input($p_name=NULL, $p_value=NULL)
$icard readOnly