ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilImageFileInputGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  protected $cache;
14 
21  function __construct($a_title = "", $a_postvar = "")
22  {
23  global $lng;
24 
25  parent::__construct($a_title, $a_postvar);
26  $this->setType("image_file");
27  $this->setSuffixes(array("jpg", "jpeg", "png", "gif"));
28  $this->setHiddenTitle("(".$lng->txt("form_image_file_input").")");
29  $this->cache = true;
30  }
31 
38  public function setUseCache($a_cache)
39  {
40  $this->cache = ($a_cache) ? true : false;
41  }
42 
48  public function getUseCache()
49  {
50  return $this->cache;
51  }
52 
58  function setImage($a_image)
59  {
60  $this->image = $a_image;
61  }
62 
68  function getImage()
69  {
70  return $this->image;
71  }
72 
78  function setAlt($a_alt)
79  {
80  $this->alt = $a_alt;
81  }
82 
88  function getAlt()
89  {
90  return $this->alt;
91  }
92 
96  function insert(&$a_tpl)
97  {
98  global $lng;
99 
100  $i_tpl = new ilTemplate("tpl.prop_image_file.html", true, true, "Services/Form");
101 
102  $this->outputSuffixes($i_tpl, "allowed_image_suffixes");
103 
104  if ($this->getImage() != "")
105  {
106  if (!$this->getDisabled())
107  {
108  $i_tpl->setCurrentBlock("delete_bl");
109  $i_tpl->setVariable("POST_VAR_D", $this->getPostVar());
110  $i_tpl->setVariable("TXT_DELETE_EXISTING",
111  $lng->txt("delete_existing_file"));
112  $i_tpl->parseCurrentBlock();
113  }
114 
115  if (strlen($this->getValue()))
116  {
117  $i_tpl->setCurrentBlock("has_value");
118  $i_tpl->setVariable("TEXT_IMAGE_NAME", $this->getValue());
119  $i_tpl->parseCurrentBlock();
120  }
121  $i_tpl->setCurrentBlock("image");
122  if (!$this->getUseCache())
123  {
124  $pos = strpos($this->getImage(), '?');
125  if ($pos !== false)
126  {
127  $i_tpl->setVariable("SRC_IMAGE", $this->getImage() . "&amp;time=" . time());
128  }
129  else
130  {
131  $i_tpl->setVariable("SRC_IMAGE", $this->getImage() . "?time=" . time());
132  }
133  }
134  else
135  {
136  $i_tpl->setVariable("SRC_IMAGE", $this->getImage());
137  }
138  $i_tpl->setVariable("ALT_IMAGE", $this->getAlt());
139  $i_tpl->parseCurrentBlock();
140  }
141 
142  $i_tpl->setVariable("POST_VAR", $this->getPostVar());
143  $i_tpl->setVariable("ID", $this->getFieldId());
144  $i_tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice")." ".
145  $this->getMaxFileSizeString());
146 
147  if ($this->getDisabled())
148  {
149  $i_tpl->setVariable("DISABLED",
150  " disabled=\"disabled\"");
151  }
152 
153  $a_tpl->setCurrentBlock("prop_generic");
154  $a_tpl->setVariable("PROP_GENERIC", $i_tpl->get());
155  $a_tpl->parseCurrentBlock();
156  }
157 
161  function getDeletionFlag()
162  {
163  if ($_POST[$this->getPostVar()."_delete"])
164  {
165  return true;
166  }
167  return false;
168  }
169 
170 }