1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5/**
6* This class represents a border style with all/top/right/bottom/left in a property form.
7*
8* @author Alex Killing <alex.killing@gmx.de>
9* @version $Id$
10* @ingroup	ServicesForm
11*/
12class ilTRBLBorderStyleInputGUI extends ilFormPropertyGUI
13{
14    /**
15     * @var ilObjUser
16     */
17    protected $user;
18
19    protected $value;
20
21    /**
22    * Constructor
23    *
24    * @param	string	$a_title	Title
25    * @param	string	$a_postvar	Post Variable
26    */
27    public function __construct($a_title = "", $a_postvar = "")
28    {
29        global $DIC;
30
31        $this->lng = $DIC->language();
32        $this->user = $DIC->user();
33        parent::__construct($a_title, $a_postvar);
34        $this->setType("border_style");
35        $this->dirs = array("all", "top", "bottom", "left", "right");
36    }
37
38    /**
39    * Set All Value.
40    *
41    * @param	string	$a_allvalue	All Value
42    */
43    public function setAllValue($a_allvalue)
44    {
45        $this->allvalue = $a_allvalue;
46    }
47
48    /**
49    * Get All Value.
50    *
51    * @return	string	All Value
52    */
53    public function getAllValue()
54    {
55        return $this->allvalue;
56    }
57
58    /**
59    * Set Top Value.
60    *
61    * @param	string	$a_topvalue	Top Value
62    */
63    public function setTopValue($a_topvalue)
64    {
65        $this->topvalue = $a_topvalue;
66    }
67
68    /**
69    * Get Top Value.
70    *
71    * @return	string	Top Value
72    */
73    public function getTopValue()
74    {
75        return $this->topvalue;
76    }
77
78    /**
79    * Set Bottom Value.
80    *
81    * @param	string	$a_bottomvalue	Bottom Value
82    */
83    public function setBottomValue($a_bottomvalue)
84    {
85        $this->bottomvalue = $a_bottomvalue;
86    }
87
88    /**
89    * Get Bottom Value.
90    *
91    * @return	string	Bottom Value
92    */
93    public function getBottomValue()
94    {
95        return $this->bottomvalue;
96    }
97
98    /**
99    * Set Left Value.
100    *
101    * @param	string	$a_leftvalue	Left Value
102    */
103    public function setLeftValue($a_leftvalue)
104    {
105        $this->leftvalue = $a_leftvalue;
106    }
107
108    /**
109    * Get Left Value.
110    *
111    * @return	string	Left Value
112    */
113    public function getLeftValue()
114    {
115        return $this->leftvalue;
116    }
117
118    /**
119    * Set Right Value.
120    *
121    * @param	string	$a_rightvalue	Right Value
122    */
123    public function setRightValue($a_rightvalue)
124    {
125        $this->rightvalue = $a_rightvalue;
126    }
127
128    /**
129    * Get Right Value.
130    *
131    * @return	string	Right Value
132    */
133    public function getRightValue()
134    {
135        return $this->rightvalue;
136    }
137
138    /**
139    * Check input, strip slashes etc. set alert, if input is not ok.
140    *
141    * @return	boolean		Input ok, true/false
142    */
143    public function checkInput()
144    {
145        $lng = $this->lng;
146
147        foreach ($this->dirs as $dir) {
148            $pre_value = $_POST[$this->getPostVar()][$dir]["pre_value"] =
149                ilUtil::stripSlashes($_POST[$this->getPostVar()][$dir]["pre_value"]);
150
151            /*
152            if ($this->getRequired() && trim($num_value) == "")
153            {
154                $this->setAlert($lng->txt("msg_input_is_required"));
155
156                return false;
157            }*/
158
159            $value = $pre_value;
160
161            if (trim($value) != "") {
162                switch ($dir) {
163                    case "all": $this->setAllValue($value); break;
164                    case "top": $this->setTopValue($value); break;
165                    case "bottom": $this->setBottomValue($value); break;
166                    case "left": $this->setLeftValue($value); break;
167                    case "right": $this->setRightValue($value); break;
168                }
169            }
170        }
171
172        return true;
173    }
174
175    /**
176    * Insert property html
177    */
178    public function insert(&$a_tpl)
179    {
180        $lng = $this->lng;
181
182        $layout_tpl = new ilTemplate("tpl.prop_trbl_layout.html", true, true, "Services/Style/Content");
183
184        foreach ($this->dirs as $dir) {
185            $tpl = new ilTemplate("tpl.prop_trbl_select.html", true, true, "Services/Style/Content");
186            $pre_options = array_merge(
187                array("" => ""),
188                ilObjStyleSheet::_getStyleParameterValues("border-style")
189            );
190
191            switch ($dir) {
192                case "all": $value = strtolower(trim($this->getAllValue())); break;
193                case "top": $value = strtolower(trim($this->getTopValue())); break;
194                case "bottom": $value = strtolower(trim($this->getBottomValue())); break;
195                case "left": $value = strtolower(trim($this->getLeftValue())); break;
196                case "right": $value = strtolower(trim($this->getRightValue())); break;
197            }
198
199            foreach ($pre_options as $option) {
200                $tpl->setCurrentBlock("pre_option");
201                $tpl->setVariable("VAL_PRE", $option);
202                $tpl->setVariable("TXT_PRE", $option);
203                if ($value == $option) {
204                    $tpl->setVariable("PRE_SELECTED", 'selected="selected"');
205                }
206                $tpl->parseCurrentBlock();
207            }
208
209            $tpl->setVariable("POSTVAR", $this->getPostVar());
210            $tpl->setVariable("TXT_DIR", $lng->txt("sty_$dir"));
211            $tpl->setVariable("DIR", $dir);
212
213            $layout_tpl->setVariable(strtoupper($dir), $tpl->get());
214        }
215
216        $a_tpl->setCurrentBlock("prop_generic");
217        $a_tpl->setVariable("PROP_GENERIC", $layout_tpl->get());
218        $a_tpl->parseCurrentBlock();
219    }
220
221    /**
222    * Set value by array
223    *
224    * @param	array	$a_values	value array
225    */
226    public function setValueByArray($a_values)
227    {
228        $ilUser = $this->user;
229
230        $this->setAllValue($a_values[$this->getPostVar()]["all"]["pre_value"]);
231        $this->setBottomValue($a_values[$this->getPostVar()]["bottom"]["pre_value"]);
232        $this->setTopValue($a_values[$this->getPostVar()]["top"]["pre_value"]);
233        $this->setLeftValue($a_values[$this->getPostVar()]["left"]["pre_value"]);
234        $this->setRightValue($a_values[$this->getPostVar()]["right"]["pre_value"]);
235    }
236}
237