ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public function __construct($a_title = "", $a_postvar = "")
22  {
23  global $DIC;
24 
25  $this->lng = $DIC->language();
26  $lng = $DIC->language();
27 
28  parent::__construct($a_title, $a_postvar);
29  $this->setType("image_file");
30  $this->setAllowDeletion(true);
31  $this->setSuffixes(array("jpg", "jpeg", "png", "gif"));
32  $this->setHiddenTitle("(" . $lng->txt("form_image_file_input") . ")");
33  $this->cache = true;
34  }
35 
41  public function setALlowDeletion($a_val)
42  {
43  $this->allow_deletion = $a_val;
44  }
45 
51  public function getALlowDeletion()
52  {
53  return $this->allow_deletion;
54  }
61  public function setUseCache($a_cache)
62  {
63  $this->cache = ($a_cache) ? true : false;
64  }
65 
71  public function getUseCache()
72  {
73  return $this->cache;
74  }
75 
81  public function setImage($a_image)
82  {
83  $this->image = $a_image;
84  }
85 
91  public function getImage()
92  {
93  return $this->image;
94  }
95 
101  public function setAlt($a_alt)
102  {
103  $this->alt = $a_alt;
104  }
105 
111  public function getAlt()
112  {
113  return $this->alt;
114  }
115 
119  public function insert($a_tpl)
120  {
121  $lng = $this->lng;
122 
123  $quota_exceeded = $quota_legend = false;
124  if (self::$check_wsp_quota) {
125  include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
127  $lng->loadLanguageModule("file");
128  $quota_exceeded = $lng->txt("personal_workspace_quota_exceeded_warning");
129  } else {
130  $quota_legend = ilDiskQuotaHandler::getStatusLegend();
131  if ($quota_legend) {
132  $quota_legend = "<br />" . $quota_legend;
133  }
134  }
135  }
136 
137  $i_tpl = new ilTemplate("tpl.prop_image_file.html", true, true, "Services/Form");
138 
139  if ($this->getImage() != "") {
140  if (!$this->getDisabled() && $this->getALlowDeletion()) {
141  $i_tpl->setCurrentBlock("delete_bl");
142  $i_tpl->setVariable("POST_VAR_D", $this->getPostVar());
143  $i_tpl->setVariable(
144  "TXT_DELETE_EXISTING",
145  $lng->txt("delete_existing_file")
146  );
147  $i_tpl->parseCurrentBlock();
148  }
149 
150  if (strlen($this->getValue())) {
151  $i_tpl->setCurrentBlock("has_value");
152  $i_tpl->setVariable("TEXT_IMAGE_NAME", $this->getValue());
153  $i_tpl->parseCurrentBlock();
154  }
155  $i_tpl->setCurrentBlock("image");
156  if (!$this->getUseCache()) {
157  $pos = strpos($this->getImage(), '?');
158  if ($pos !== false) {
159  $i_tpl->setVariable("SRC_IMAGE", $this->getImage() . "&amp;time=" . time());
160  } else {
161  $i_tpl->setVariable("SRC_IMAGE", $this->getImage() . "?time=" . time());
162  }
163  } else {
164  $i_tpl->setVariable("SRC_IMAGE", $this->getImage());
165  }
166  $i_tpl->setVariable("ALT_IMAGE", $this->getAlt());
167  $i_tpl->parseCurrentBlock();
168  }
169 
170  $pending = $this->getPending();
171  if ($pending) {
172  $i_tpl->setCurrentBlock("pending");
173  $i_tpl->setVariable("TXT_PENDING", $lng->txt("file_upload_pending") .
174  ": " . $pending);
175  $i_tpl->parseCurrentBlock();
176  }
177 
178  $i_tpl->setVariable("POST_VAR", $this->getPostVar());
179  $i_tpl->setVariable("ID", $this->getFieldId());
180 
181 
182  /* experimental: bootstrap'ed file upload */
183  $i_tpl->setVariable("TXT_BROWSE", $lng->txt("select_file"));
184 
185 
186  if (!$quota_exceeded) {
187  $i_tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice") . " " .
188  $this->getMaxFileSizeString() . $quota_legend);
189 
190  $this->outputSuffixes($i_tpl, "allowed_image_suffixes");
191  } else {
192  $i_tpl->setVariable("TXT_MAX_SIZE", $quota_exceeded);
193  }
194 
195  if ($this->getDisabled() || $quota_exceeded) {
196  $i_tpl->setVariable(
197  "DISABLED",
198  " disabled=\"disabled\""
199  );
200  }
201 
202  $a_tpl->setCurrentBlock("prop_generic");
203  $a_tpl->setVariable("PROP_GENERIC", $i_tpl->get());
204  $a_tpl->parseCurrentBlock();
205  }
206 
210  public function getDeletionFlag()
211  {
212  if ($_POST[$this->getPostVar() . "_delete"]) {
213  return true;
214  }
215  return false;
216  }
217 }
setALlowDeletion($a_val)
Set allow deletion.
getAlt()
Get Alternative Text.
global $DIC
Definition: saml.php:7
getPostVar()
Get Post Variable.
setAlt($a_alt)
Set Alternative Text.
This class represents a file property in a property form.
getPending()
Get pending filename.
getALlowDeletion()
Get allow deletion.
setUseCache($a_cache)
Set cache.
setType($a_type)
Set Type.
insert($a_tpl)
Insert property html.
setImage($a_image)
Set Image.
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
static isUploadPossible($a_additional_size=null)
setHiddenTitle($a_val)
Set hidden title (for screenreaders)
outputSuffixes($a_tpl, $a_block="allowed_suffixes")
getDeletionFlag()
Get deletion flag.
This class represents an image file property in a property form.
__construct($a_title="", $a_postvar="")
Constructor.
setSuffixes($a_suffixes)
Set Accepted Suffixes.
$_POST["username"]