Code

Replaced in_array calls with in_array_strict
[gosa.git] / gosa-plugins / goto / admin / ConfigManagement / class_TemplateWidget_fixedList.inc
1 <?php
3 class TemplateWidget_fixedList extends TemplateWidget
4 {
5     protected $value = array();
6     
7     function __construct(&$config, $name, $value, $description,$syntax,$required,$type,$display,$values)
8     {
9         parent:: __construct($config, $name, $value, $description,$syntax,$required,$type,$display,$values);
11         $this->listWidget= new sortableListing($this->value);
12         $this->listWidget->setEditable(false);
13         $this->listWidget->setDeleteable(true);
14         $this->listWidget->setColspecs(array('*'));
15         $this->listWidget->setWidth("100%");
16         $this->listWidget->setHeight("70px");
17         $this->listWidget->setAcl("rwcdm");
18     }
20     function getAvailableOptions()
21     {
22         $tmp = array();
23         foreach($this->values as $key => $name){
24             if(!in_array_strict($key, $this->value)){
25                 $tmp[$key]=$name;
26             }
27         }
28         return($tmp);
29     }
31     function render()
32     {
33         $str = "";
35         // Build up list data
36         $data = $this->value;
37         foreach($this->value as $key => $name){
38             $lData[$key] = array('data' => array($this->values[$name]));
39         }
40         $this->listWidget->setListData($data, $lData);
41         $this->listWidget->update();
42         $str .= $this->listWidget->render();
43         $str .= "<select size='1' name='{$this->postName}_Input'>";
44         foreach($this->getAvailableOptions() as $name => $value){
45             $str .= "<option value=\"{$name}\">{$value}</option>\n";
46         }
47         $str .= "</select>";
48         $str .= "<button name='{$this->postName}_Add'>".msgPool::addButton()."</button>";
49         return($str);
50     }
52     function save_object()
53     {
54         $this->listWidget->save_object();
55         $action = $this->listWidget->getAction();
56         if($action['action'] == 'delete'){
57             $id = $this->listWidget->getKey($action['targets'][0]);
58             unset($this->value[$id]);
59             $this->value = array_values($this->value);
60         }
62         if(isset($_POST["{$this->postName}_Add"]) && isset($_POST["{$this->postName}_Input"])){
63             $input = get_post("{$this->postName}_Input");
65             if(!empty($input) && !empty($this->syntax) && !preg_match("/".$this->syntax."/", $input)){
66                 msg_dialog::displayChecks(array(msgPool::invalid($this->display, $input, "/".$this->syntax."/")));
67             }elseif(!empty($input)){
68                 $this->value[] = $input;
69             }
70         }
71     }
73     /*! \brief  Check the value entry using the provieded syntax.
74      * @return  Array   Returns a list of errors
75      */
76     function check()
77     {
78         if($this->required && empty($this->value)){
79             return(array(msgPool::required($this->display)));
80         }
81         return(array());
82     }
83 }
86 ?>