ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBackgroundImageInputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
32 {
33  protected $value;
34 
41  function __construct($a_title = "", $a_postvar = "")
42  {
43  parent::__construct($a_title, $a_postvar);
44  $this->setType("background_image");
45  }
46 
52  function setValue($a_value)
53  {
54  $this->value = $a_value;
55  }
56 
62  function getValue()
63  {
64  return $this->value;
65  }
66 
72  function setImages($a_images)
73  {
74  $this->images = $a_images;
75  }
76 
82  function getImages()
83  {
84  return $this->images;
85  }
86 
92  function checkInput()
93  {
94  global $lng;
95 
96  $type = $_POST[$this->getPostVar()]["type"] =
97  ilUtil::stripSlashes($_POST[$this->getPostVar()]["type"]);
98  $int_value = $_POST[$this->getPostVar()]["int_value"] =
99  ilUtil::stripSlashes($_POST[$this->getPostVar()]["int_value"]);
100  $ext_value = $_POST[$this->getPostVar()]["ext_value"] =
101  ilUtil::stripSlashes($_POST[$this->getPostVar()]["ext_value"]);
102 
103  if ($this->getRequired() && $type == "ext" && trim($ext_value) == "")
104  {
105  $this->setAlert($lng->txt("msg_input_is_required"));
106 
107  return false;
108  }
109 
110  if ($type == "external")
111  {
112  $this->setValue($ext_value);
113  }
114  else
115  {
116  $this->setValue($int_value);
117  }
118 
119  return true;
120  }
121 
125  function insert(&$a_tpl)
126  {
127  $tpl = new ilTemplate("tpl.prop_background_image.html", true, true, "Services/Style");
128 
129  $tpl->setVariable("POSTVAR", $this->getPostVar());
130 
131  $int_options = array_merge(array("" => ""), $this->getImages());
132 
133  $value = trim($this->getValue());
134 
135  if (is_int(strpos($value, "/")))
136  {
137  $current_type = "ext";
138  $tpl->setVariable("EXTERNAL_SELECTED", 'checked="checked"');
139  $tpl->setVariable("VAL_EXT", ilUtil::prepareFormOutput($value));
140  }
141  else
142  {
143  $current_type = "int";
144  $tpl->setVariable("INTERNAL_SELECTED", 'checked="checked"');
145  }
146 
147  foreach ($int_options as $option)
148  {
149  $tpl->setCurrentBlock("int_option");
150  $tpl->setVariable("VAL_INT", $option);
151  $tpl->setVariable("TXT_INT", $option);
152 
153  if ($current_type == "int" && $value == $option)
154  {
155  $tpl->setVariable("INT_SELECTED", 'selected="selected"');
156  }
157  $tpl->parseCurrentBlock();
158  }
159 
160  $a_tpl->setCurrentBlock("prop_generic");
161  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
162  $a_tpl->parseCurrentBlock();
163  }
164 
170  function setValueByArray($a_values)
171  {
172  global $ilUser;
173 
174  if ($a_values[$this->getPostVar()]["type"] == "internal")
175  {
176  $this->setValue($a_values[$this->getPostVar()]["int_value"]);
177  }
178  else
179  {
180  $this->setValue($a_values[$this->getPostVar()]["ext_value"]);
181  }
182  }
183 }