ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilFileInputGUI Class Reference

This class represents a file property in a property form. More...

+ Inheritance diagram for ilFileInputGUI:
+ Collaboration diagram for ilFileInputGUI:

Public Member Functions

 __construct ($a_title="", $a_postvar="")
 Constructor.
 setValueByArray ($a_values)
 Set value by array.
 setValue ($a_value)
 Set Value.
 getValue ()
 Get Value.
 setSize ($a_size)
 Set Size.
 getSize ()
 Get Size.
 setFilename ($a_val)
 Set filename value (if filename selection is enabled)
 getFilename ()
 Get Value.
 setSuffixes ($a_suffixes)
 Set Accepted Suffixes.
 getSuffixes ()
 Get Accepted Suffixes.
 enableFileNameSelection ($a_post_var)
 If enabled, users get the possibility to enter a filename for the uploaded file.
 isFileNameSelectionEnabled ()
 Check if filename selection is enabled.
 getFileNamePostVar ()
 Get file name post var.
 checkInput ()
 Check input, strip slashes etc.
 render ($a_mode="")
 Render html.
 insert (&$a_tpl)
 Insert property html.
 getToolbarHTML ()
 Get HTML for toolbar.
- Public Member Functions inherited from ilSubEnabledFormPropertyGUI
 addSubItem ($a_item)
 Add Subitem.
 getSubItems ()
 Get Subitems.
 checkSubItemsInput ()
 Check SubItems.
 getSubForm ()
 Get sub form html.
 getItemByPostVar ($a_post_var)
 Get item by post var.
- Public Member Functions inherited from ilFormPropertyGUI
executeCommand ()
 Execute command.
 getType ()
 Get Type.
 setTitle ($a_title)
 Set Title.
 getTitle ()
 Get Title.
 setPostVar ($a_postvar)
 Set Post Variable.
 getPostVar ()
 Get Post Variable.
 getFieldId ()
 Get Post Variable.
 setInfo ($a_info)
 Set Information Text.
 getInfo ()
 Get Information Text.
 setAlert ($a_alert)
 Set Alert Text.
 getAlert ()
 Get Alert Text.
 setRequired ($a_required)
 Set Required.
 getRequired ()
 Get Required.
 setDisabled ($a_disabled)
 Set Disabled.
 getDisabled ()
 Get Disabled.
 setParentForm ($a_parentform)
 Set Parent Form.
 getParentForm ()
 Get Parent Form.
 setParent ($a_val)
 Set Parent GUI object.
 getParent ()
 Get Parent GUI object.
 hideSubForm ()
 Sub form hidden on init?
 setHiddenTitle ($a_val)
 Set hidden title (for screenreaders)
 getHiddenTitle ()
 Get hidden title.
 serializeData ()
 serialize data
 unserializeData ($a_data)
 unserialize data
 writeToSession ()
 Write to session.
 clearFromSession ()
 Clear session value.
 readFromSession ()
 Read from session.
 getHiddenTag ($a_post_var, $a_value)
 Get hidden tag (used for disabled properties)

Protected Member Functions

 outputSuffixes ($a_tpl, $a_block="allowed_suffixes")
 getMaxFileSizeString ()

Protected Attributes

 $size = 40
- Protected Attributes inherited from ilSubEnabledFormPropertyGUI
 $sub_items = array()
- Protected Attributes inherited from ilFormPropertyGUI
 $type
 $title
 $postvar
 $info
 $alert
 $required = false
 $parentgui
 $parentform
 $hidden_title = ""

Private Attributes

 $filename
 $filename_post

Detailed Description

This class represents a file property in a property form.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 14 of file class.ilFileInputGUI.php.

Constructor & Destructor Documentation

ilFileInputGUI::__construct (   $a_title = "",
  $a_postvar = "" 
)

Constructor.

Parameters
string$a_titleTitle
string$a_postvarPost Variable

Reimplemented from ilFormPropertyGUI.

Reimplemented in ilFileWizardInputGUI, ilImagemapFileInputGUI, ilFlashFileInputGUI, and ilImageFileInputGUI.

Definition at line 26 of file class.ilFileInputGUI.php.

References $lng, ilFormPropertyGUI\setHiddenTitle(), and ilFormPropertyGUI\setType().

{
global $lng;
parent::__construct($a_title, $a_postvar);
$this->setType("file");
$this->setHiddenTitle("(".$lng->txt("form_file_input").")");
}

+ Here is the call graph for this function:

Member Function Documentation

ilFileInputGUI::checkInput ( )

Check input, strip slashes etc.

set alert, if input is not ok.

Returns
boolean Input ok, true/false

Reimplemented from ilFormPropertyGUI.

Reimplemented in ilFileWizardInputGUI, ilImagemapFileInputGUI, and ilFlashFileInputGUI.

Definition at line 172 of file class.ilFileInputGUI.php.

References $_POST, $error, $filename, $lng, ilFormPropertyGUI\getPostVar(), ilFormPropertyGUI\getRequired(), getSuffixes(), getValue(), ilFormPropertyGUI\setAlert(), and ilUtil\virusHandling().

{
global $lng;
// remove trailing '/'
while (substr($_FILES[$this->getPostVar()]["name"],-1) == '/')
{
$_FILES[$this->getPostVar()]["name"] = substr($_FILES[$this->getPostVar()]["name"],0,-1);
}
$filename = $_FILES[$this->getPostVar()]["name"];
$filename_arr = pathinfo($_FILES[$this->getPostVar()]["name"]);
$suffix = $filename_arr["extension"];
$mimetype = $_FILES[$this->getPostVar()]["type"];
$size_bytes = $_FILES[$this->getPostVar()]["size"];
$temp_name = $_FILES[$this->getPostVar()]["tmp_name"];
$error = $_FILES[$this->getPostVar()]["error"];
$_POST[$this->getPostVar()] = $_FILES[$this->getPostVar()];
// error handling
if ($error > 0)
{
switch ($error)
{
case UPLOAD_ERR_INI_SIZE:
$this->setAlert($lng->txt("form_msg_file_size_exceeds"));
return false;
break;
case UPLOAD_ERR_FORM_SIZE:
$this->setAlert($lng->txt("form_msg_file_size_exceeds"));
return false;
break;
case UPLOAD_ERR_PARTIAL:
$this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
return false;
break;
case UPLOAD_ERR_NO_FILE:
if ($this->getRequired())
{
if (!strlen($this->getValue()))
{
$this->setAlert($lng->txt("form_msg_file_no_upload"));
return false;
}
}
break;
case UPLOAD_ERR_NO_TMP_DIR:
$this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
return false;
break;
case UPLOAD_ERR_CANT_WRITE:
$this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
return false;
break;
case UPLOAD_ERR_EXTENSION:
$this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
return false;
break;
}
}
// check suffixes
if ($_FILES[$this->getPostVar()]["tmp_name"] != "" &&
is_array($this->getSuffixes()))
{
if (!in_array(strtolower($suffix), $this->getSuffixes()))
{
$this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
return false;
}
}
// virus handling
if ($_FILES[$this->getPostVar()]["tmp_name"] != "")
{
$vir = ilUtil::virusHandling($temp_name, $filename);
if ($vir[0] == false)
{
$this->setAlert($lng->txt("form_msg_file_virus_found")."<br />".$vir[1]);
return false;
}
}
return true;
}

+ Here is the call graph for this function:

ilFileInputGUI::enableFileNameSelection (   $a_post_var)

If enabled, users get the possibility to enter a filename for the uploaded file.

public

Parameters
stringpost variable

Definition at line 138 of file class.ilFileInputGUI.php.

{
$this->filename_selection = true;
$this->filename_post = $a_post_var;
}
ilFileInputGUI::getFilename ( )

Get Value.

Returns
string Value

Definition at line 104 of file class.ilFileInputGUI.php.

References $filename.

Referenced by render().

{
}

+ Here is the caller graph for this function:

ilFileInputGUI::getFileNamePostVar ( )

Get file name post var.

public

Parameters
stringfile name post var

Definition at line 162 of file class.ilFileInputGUI.php.

References $filename_post.

Referenced by render(), and setValueByArray().

{
}

+ Here is the caller graph for this function:

ilFileInputGUI::getMaxFileSizeString ( )
protected

Definition at line 345 of file class.ilFileInputGUI.php.

Referenced by ilImageFileInputGUI\insert(), ilFileWizardInputGUI\insert(), ilImagemapFileInputGUI\insert(), ilFlashFileInputGUI\insert(), and render().

{
// get the value for the maximal uploadable filesize from the php.ini (if available)
$umf = ini_get("upload_max_filesize");
// get the value for the maximal post data from the php.ini (if available)
$pms = ini_get("post_max_size");
//convert from short-string representation to "real" bytes
$multiplier_a=array("K"=>1024, "M"=>1024*1024, "G"=>1024*1024*1024);
$umf_parts=preg_split("/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$pms_parts=preg_split("/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
if (count($umf_parts) == 2) { $umf = $umf_parts[0]*$multiplier_a[$umf_parts[1]]; }
if (count($pms_parts) == 2) { $pms = $pms_parts[0]*$multiplier_a[$pms_parts[1]]; }
// use the smaller one as limit
$max_filesize = min($umf, $pms);
if (!$max_filesize) $max_filesize=max($umf, $pms);
//format for display in mega-bytes
$max_filesize = sprintf("%.1f MB",$max_filesize/1024/1024);
return $max_filesize;
}

+ Here is the caller graph for this function:

ilFileInputGUI::getSize ( )

Get Size.

Returns
int Size

Definition at line 84 of file class.ilFileInputGUI.php.

References $size.

Referenced by render().

{
return $this->size;
}

+ Here is the caller graph for this function:

ilFileInputGUI::getSuffixes ( )

Get Accepted Suffixes.

Returns
array Accepted Suffixes

Definition at line 126 of file class.ilFileInputGUI.php.

Referenced by ilFlashFileInputGUI\checkInput(), ilImagemapFileInputGUI\checkInput(), ilFileWizardInputGUI\checkInput(), checkInput(), and outputSuffixes().

{
return $this->suffixes;
}

+ Here is the caller graph for this function:

ilFileInputGUI::getToolbarHTML ( )

Get HTML for toolbar.

Implements ilToolbarItem.

Definition at line 375 of file class.ilFileInputGUI.php.

References render().

{
$html = $this->render("toolbar");
return $html;
}

+ Here is the call graph for this function:

ilFileInputGUI::getValue ( )

Get Value.

Returns
string Value

Reimplemented in ilFlashFileInputGUI.

Definition at line 64 of file class.ilFileInputGUI.php.

Referenced by ilImagemapFileInputGUI\checkInput(), checkInput(), ilImageFileInputGUI\insert(), ilImagemapFileInputGUI\insert(), and render().

{
return $this->value;
}

+ Here is the caller graph for this function:

ilFileInputGUI::insert ( $a_tpl)

Insert property html.

Returns
int Size

Reimplemented in ilFlashFileInputGUI, ilImagemapFileInputGUI, ilFileWizardInputGUI, and ilImageFileInputGUI.

Definition at line 316 of file class.ilFileInputGUI.php.

References render().

{
$html = $this->render();
$a_tpl->setCurrentBlock("prop_generic");
$a_tpl->setVariable("PROP_GENERIC", $html);
$a_tpl->parseCurrentBlock();
}

+ Here is the call graph for this function:

ilFileInputGUI::isFileNameSelectionEnabled ( )

Check if filename selection is enabled.

public

Returns
bool enabled/disabled

Definition at line 150 of file class.ilFileInputGUI.php.

Referenced by render().

{
return $this->filename_selection ? true : false;
}

+ Here is the caller graph for this function:

ilFileInputGUI::outputSuffixes (   $a_tpl,
  $a_block = "allowed_suffixes" 
)
protected

Definition at line 326 of file class.ilFileInputGUI.php.

References $lng, and getSuffixes().

Referenced by ilImageFileInputGUI\insert(), ilFileWizardInputGUI\insert(), ilImagemapFileInputGUI\insert(), ilFlashFileInputGUI\insert(), and render().

{
global $lng;
if (is_array($this->getSuffixes()))
{
$suff_str = $delim = "";
foreach($this->getSuffixes() as $suffix)
{
$suff_str.= $delim.".".$suffix;
$delim = ", ";
}
$a_tpl->setCurrentBlock($a_block);
$a_tpl->setVariable("TXT_ALLOWED_SUFFIXES",
$lng->txt("file_allowed_suffixes")." ".$suff_str);
$a_tpl->parseCurrentBlock();
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilFileInputGUI::render (   $a_mode = "")

Render html.

Definition at line 267 of file class.ilFileInputGUI.php.

References $lng, ilFormPropertyGUI\getFieldId(), getFilename(), getFileNamePostVar(), getMaxFileSizeString(), ilFormPropertyGUI\getPostVar(), getSize(), getValue(), isFileNameSelectionEnabled(), and outputSuffixes().

Referenced by getToolbarHTML(), and insert().

{
global $lng;
$f_tpl = new ilTemplate("tpl.prop_file.html", true, true, "Services/Form");
// show filename selection if enabled
{
$f_tpl->setCurrentBlock('filename');
$f_tpl->setVariable('POST_FILENAME',$this->getFileNamePostVar());
$f_tpl->setVariable('VAL_FILENAME',$this->getFilename());
$f_tpl->setVariable('FILENAME_ID',$this->getFieldId());
$f_tpl->setVAriable('TXT_FILENAME_HINT',$lng->txt('if_no_title_then_filename'));
$f_tpl->parseCurrentBlock();
}
else
{
if (trim($this->getValue() != ""))
{
$f_tpl->setCurrentBlock('prop_file_propval');
$f_tpl->setVariable('FILE_VAL', $this->getValue());
$f_tpl->parseCurrentBlock();
}
}
if ($a_mode != "toolbar")
{
$this->outputSuffixes($f_tpl);
$f_tpl->setCurrentBlock("max_size");
$f_tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice")." ".
$f_tpl->parseCurrentBlock();
}
$f_tpl->setVariable("POST_VAR", $this->getPostVar());
$f_tpl->setVariable("ID", $this->getFieldId());
$f_tpl->setVariable("SIZE", $this->getSize());
return $f_tpl->get();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilFileInputGUI::setFilename (   $a_val)

Set filename value (if filename selection is enabled)

Parameters
string$a_val

Definition at line 94 of file class.ilFileInputGUI.php.

Referenced by setValueByArray().

{
$this->filename = $a_val;
}

+ Here is the caller graph for this function:

ilFileInputGUI::setSize (   $a_size)

Set Size.

Parameters
int$a_sizeSize

Definition at line 74 of file class.ilFileInputGUI.php.

Referenced by ilFileSystemGUI\listFiles().

{
$this->size = $a_size;
}

+ Here is the caller graph for this function:

ilFileInputGUI::setValue (   $a_value)

Set Value.

(used for displaying file title of existing file below input field)

Parameters
string$a_valueValue

Reimplemented in ilImagemapFileInputGUI, and ilFlashFileInputGUI.

Definition at line 54 of file class.ilFileInputGUI.php.

Referenced by setValueByArray().

{
$this->value = $a_value;
}

+ Here is the caller graph for this function:

ilFileInputGUI::setValueByArray (   $a_values)

Set value by array.

Parameters
array$a_valuesvalue array

Reimplemented in ilImagemapFileInputGUI, and ilFlashFileInputGUI.

Definition at line 40 of file class.ilFileInputGUI.php.

References getFileNamePostVar(), ilFormPropertyGUI\getPostVar(), setFilename(), and setValue().

{
if (!is_array($a_values[$this->getPostVar()]))
{
$this->setValue($a_values[$this->getPostVar()]);
}
$this->setFilename($a_values[$this->getFileNamePostVar()]);
}

+ Here is the call graph for this function:

Field Documentation

ilFileInputGUI::$filename_post
private

Definition at line 17 of file class.ilFileInputGUI.php.

Referenced by getFileNamePostVar().

ilFileInputGUI::$size = 40
protected

Definition at line 18 of file class.ilFileInputGUI.php.

Referenced by getSize().


The documentation for this class was generated from the following file: