ILIAS  Release_4_2_x_branch Revision 61807
 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->setAllowDeletion(true);
28  $this->setSuffixes(array("jpg", "jpeg", "png", "gif"));
29  $this->setHiddenTitle("(".$lng->txt("form_image_file_input").")");
30  $this->cache = true;
31  }
32 
38  function setALlowDeletion($a_val)
39  {
40  $this->allow_deletion = $a_val;
41  }
42 
48  function getALlowDeletion()
49  {
50  return $this->allow_deletion;
51  }
58  public function setUseCache($a_cache)
59  {
60  $this->cache = ($a_cache) ? true : false;
61  }
62 
68  public function getUseCache()
69  {
70  return $this->cache;
71  }
72 
78  function setImage($a_image)
79  {
80  $this->image = $a_image;
81  }
82 
88  function getImage()
89  {
90  return $this->image;
91  }
92 
98  function setAlt($a_alt)
99  {
100  $this->alt = $a_alt;
101  }
102 
108  function getAlt()
109  {
110  return $this->alt;
111  }
112 
116  function insert(&$a_tpl)
117  {
118  global $lng;
119 
120  $i_tpl = new ilTemplate("tpl.prop_image_file.html", true, true, "Services/Form");
121 
122  $this->outputSuffixes($i_tpl, "allowed_image_suffixes");
123 
124  if ($this->getImage() != "")
125  {
126  if (!$this->getDisabled() && $this->getALlowDeletion())
127  {
128  $i_tpl->setCurrentBlock("delete_bl");
129  $i_tpl->setVariable("POST_VAR_D", $this->getPostVar());
130  $i_tpl->setVariable("TXT_DELETE_EXISTING",
131  $lng->txt("delete_existing_file"));
132  $i_tpl->parseCurrentBlock();
133  }
134 
135  if (strlen($this->getValue()))
136  {
137  $i_tpl->setCurrentBlock("has_value");
138  $i_tpl->setVariable("TEXT_IMAGE_NAME", $this->getValue());
139  $i_tpl->parseCurrentBlock();
140  }
141  $i_tpl->setCurrentBlock("image");
142  if (!$this->getUseCache())
143  {
144  $pos = strpos($this->getImage(), '?');
145  if ($pos !== false)
146  {
147  $i_tpl->setVariable("SRC_IMAGE", $this->getImage() . "&amp;time=" . time());
148  }
149  else
150  {
151  $i_tpl->setVariable("SRC_IMAGE", $this->getImage() . "?time=" . time());
152  }
153  }
154  else
155  {
156  $i_tpl->setVariable("SRC_IMAGE", $this->getImage());
157  }
158  $i_tpl->setVariable("ALT_IMAGE", $this->getAlt());
159  $i_tpl->parseCurrentBlock();
160  }
161 
162  $pending = $this->getPending();
163  if($pending)
164  {
165  $i_tpl->setCurrentBlock("pending");
166  $i_tpl->setVariable("TXT_PENDING", $lng->txt("file_upload_pending").
167  ": ".$pending);
168  $i_tpl->parseCurrentBlock();
169  }
170 
171  $i_tpl->setVariable("POST_VAR", $this->getPostVar());
172  $i_tpl->setVariable("ID", $this->getFieldId());
173  $i_tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice")." ".
174  $this->getMaxFileSizeString());
175 
176  if ($this->getDisabled())
177  {
178  $i_tpl->setVariable("DISABLED",
179  " disabled=\"disabled\"");
180  }
181 
182  $a_tpl->setCurrentBlock("prop_generic");
183  $a_tpl->setVariable("PROP_GENERIC", $i_tpl->get());
184  $a_tpl->parseCurrentBlock();
185  }
186 
190  function getDeletionFlag()
191  {
192  if ($_POST[$this->getPostVar()."_delete"])
193  {
194  return true;
195  }
196  return false;
197  }
198 
199 }