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 24/** 25* This class represents a background image property in a property form. 26* 27* @author Alex Killing <alex.killing@gmx.de> 28* @version $Id$ 29* @ingroup ServicesForm 30*/ 31class ilBackgroundImageInputGUI extends ilFormPropertyGUI 32{ 33 /** 34 * @var ilObjUser 35 */ 36 protected $user; 37 38 protected $value; 39 40 /** 41 * Constructor 42 * 43 * @param string $a_title Title 44 * @param string $a_postvar Post Variable 45 */ 46 public function __construct($a_title = "", $a_postvar = "") 47 { 48 global $DIC; 49 50 $this->lng = $DIC->language(); 51 $this->user = $DIC->user(); 52 parent::__construct($a_title, $a_postvar); 53 $this->setType("background_image"); 54 } 55 56 /** 57 * Set Value. 58 * 59 * @param string $a_value Value 60 */ 61 public function setValue($a_value) 62 { 63 $this->value = $a_value; 64 } 65 66 /** 67 * Get Value. 68 * 69 * @return string Value 70 */ 71 public function getValue() 72 { 73 return $this->value; 74 } 75 76 /** 77 * Set Images. 78 * 79 * @param array $a_images Images 80 */ 81 public function setImages($a_images) 82 { 83 $this->images = $a_images; 84 } 85 86 /** 87 * Get Images. 88 * 89 * @return array Images 90 */ 91 public function getImages() 92 { 93 return $this->images; 94 } 95 96 /** 97 * Check input, strip slashes etc. set alert, if input is not ok. 98 * 99 * @return boolean Input ok, true/false 100 */ 101 public function checkInput() 102 { 103 $lng = $this->lng; 104 105 $type = $_POST[$this->getPostVar()]["type"] = 106 ilUtil::stripSlashes($_POST[$this->getPostVar()]["type"]); 107 $int_value = $_POST[$this->getPostVar()]["int_value"] = 108 ilUtil::stripSlashes($_POST[$this->getPostVar()]["int_value"]); 109 $ext_value = $_POST[$this->getPostVar()]["ext_value"] = 110 ilUtil::stripSlashes($_POST[$this->getPostVar()]["ext_value"]); 111 112 if ($this->getRequired() && $type == "ext" && trim($ext_value) == "") { 113 $this->setAlert($lng->txt("msg_input_is_required")); 114 115 return false; 116 } 117 118 if ($type == "external") { 119 $this->setValue($ext_value); 120 } else { 121 $this->setValue($int_value); 122 } 123 124 return true; 125 } 126 127 /** 128 * Insert property html 129 */ 130 public function insert(&$a_tpl) 131 { 132 $tpl = new ilTemplate("tpl.prop_background_image.html", true, true, "Services/Style/Content"); 133 134 $tpl->setVariable("POSTVAR", $this->getPostVar()); 135 136 $int_options = array_merge(array("" => ""), $this->getImages()); 137 138 $value = trim($this->getValue()); 139 140 if (is_int(strpos($value, "/"))) { 141 $current_type = "ext"; 142 $tpl->setVariable("EXTERNAL_SELECTED", 'checked="checked"'); 143 $tpl->setVariable("VAL_EXT", ilUtil::prepareFormOutput($value)); 144 } else { 145 $current_type = "int"; 146 $tpl->setVariable("INTERNAL_SELECTED", 'checked="checked"'); 147 } 148 149 foreach ($int_options as $option) { 150 $tpl->setCurrentBlock("int_option"); 151 $tpl->setVariable("VAL_INT", $option); 152 $tpl->setVariable("TXT_INT", $option); 153 154 if ($current_type == "int" && $value == $option) { 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 165 /** 166 * Set value by array 167 * 168 * @param array $a_values value array 169 */ 170 public function setValueByArray($a_values) 171 { 172 $ilUser = $this->user; 173 174 if ($a_values[$this->getPostVar()]["type"] == "internal") { 175 $this->setValue($a_values[$this->getPostVar()]["int_value"]); 176 } else { 177 $this->setValue($a_values[$this->getPostVar()]["ext_value"]); 178 } 179 } 180} 181