[gosa.git] / gosa-plugins / goto-ng / admin / newConfigManagement / TemplateEngine / class_TemplateWidget_fixedList.inc
1 <?php
3 class TemplateWidget_fixedList extends TemplateWidget
4 {
5 protected $value = array();
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($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 $this->listWidget->setDeleteable($this->enabled);
37 $disabled = (!$this->enabled || !$this->writeable)? "disabled" : "";
38 $name = (!$this->enabled || !$this->writeable)? "dummy".rand(0,10000) : $this->postName;
40 $data = $this->value;
41 foreach($this->value as $key => $name){
42 $lData[$key] = array('data' => array($this->values[$name]));
43 }
44 $this->listWidget->setListData($data, $lData);
45 $this->listWidget->update();
46 $str .= $this->listWidget->render();
47 $str .= "<select size='1' name='{$name}_Input' {$disabled}>";
48 foreach($this->getAvailableOptions() as $name => $value){
49 $str .= "<option value=\"{$name}\">{$value}</option>\n";
50 }
51 $str .= "</select>";
52 $str .= "<button name='{$name}_Add' {$disabled}>".msgPool::addButton()."</button>";
53 return($str);
54 }
56 function save_object()
57 {
58 $this->listWidget->save_object();
59 $action = $this->listWidget->getAction();
60 if($action['action'] == 'delete'){
61 $id = $this->listWidget->getKey($action['targets'][0]);
62 unset($this->value[$id]);
63 $this->value = array_values($this->value);
64 }
66 if(isset($_POST["{$this->postName}_Add"]) && isset($_POST["{$this->postName}_Input"])){
67 $input = get_post("{$this->postName}_Input");
69 if(!empty($input) && !empty($this->syntax) && !preg_match("/".$this->syntax."/", $input)){
70 msg_dialog::displayChecks(array(msgPool::invalid($this->display, $input, "/".$this->syntax."/")));
71 }elseif(!empty($input)){
72 $this->value[] = $input;
73 }
74 }
75 }
77 /*! \brief Check the value entry using the provieded syntax.
78 * @return Array Returns a list of errors
79 */
80 function check()
81 {
82 if($this->required && empty($this->value)){
83 return(array(msgPool::required($this->display)));
84 }
85 return(array());
86 }
87 }
90 ?>