ILIAS  Release_3_10_x_branch Revision 61812
 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.
 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.
 insert (&$a_tpl)
 Insert property html.
- Public Member Functions inherited from ilSubEnabledFormPropertyGUI
 addSubItem ($a_item)
 Add Subitem.
 getSubItems ()
 Get Subitems.
 setSubformMode ($a_subformmode)
 Set Subform Mode.
 getSubformMode ()
 Get Subform Mode.
 checkSubItemsInput ()
 Check SubItems.
 getSubForm ()
 Get sub form html.
- Public Member Functions inherited from ilFormPropertyGUI
 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.

Protected Member Functions

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

Private Attributes

 $filename
 $filename_post

Additional Inherited Members

- Protected Attributes inherited from ilSubEnabledFormPropertyGUI
 $sub_items = array()
 $subformmode = "bottom"

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 31 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 ilFlashFileInputGUI, and ilImageFileInputGUI.

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

References ilFormPropertyGUI\setType().

{
parent::__construct($a_title, $a_postvar);
$this->setType("file");
}

+ 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.

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

References $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 129 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 95 of file class.ilFileInputGUI.php.

References $filename.

Referenced by ilFlashFileInputGUI\getApplet(), and insert().

{
}

+ Here is the caller graph for this function:

ilFileInputGUI::getFileNamePostVar ( )

Get file name post var.

public

Parameters
stringfile name post var

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

References $filename_post.

Referenced by insert(), and setValueByArray().

{
}

+ Here is the caller graph for this function:

ilFileInputGUI::getMaxFileSizeString ( )
protected

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

Referenced by ilImageFileInputGUI\insert(), ilFlashFileInputGUI\insert(), and insert().

{
// 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::getSuffixes ( )

Get Accepted Suffixes.

Returns
array Accepted Suffixes

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

Referenced by checkInput(), and outputSuffixes().

{
return $this->suffixes;
}

+ Here is the caller graph for this function:

ilFileInputGUI::getValue ( )

Get Value.

Returns
string Value

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

Referenced by checkInput().

{
return $this->value;
}

+ Here is the caller graph for this function:

ilFileInputGUI::insert ( $a_tpl)

Insert property html.

Reimplemented in ilFlashFileInputGUI, and ilImageFileInputGUI.

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

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

{
global $lng;
// show filename selection if enabled
{
$a_tpl->setCurrentBlock('filename');
$a_tpl->setVariable('POST_FILENAME',$this->getFileNamePostVar());
$a_tpl->setVariable('VAL_FILENAME',$this->getFilename());
$a_tpl->setVariable('FILENAME_ID',$this->getFieldId());
$a_tpl->setVAriable('TXT_FILENAME_HINT',$lng->txt('if_no_title_then_filename'));
$a_tpl->parseCurrentBlock();
}
$this->outputSuffixes($a_tpl);
$a_tpl->setCurrentBlock("prop_file");
$a_tpl->setVariable("POST_VAR", $this->getPostVar());
$a_tpl->setVariable("ID", $this->getFieldId());
$a_tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice")." ".
$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 141 of file class.ilFileInputGUI.php.

Referenced by insert().

{
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 283 of file class.ilFileInputGUI.php.

References $lng, and getSuffixes().

Referenced by ilImageFileInputGUI\insert(), and insert().

{
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::setFilename (   $a_val)

Set filename value (if filename selection is enabled)

Parameters
string$a_val

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

Referenced by ilFlashFileInputGUI\setApplet(), and setValueByArray().

{
$this->filename = $a_val;
}

+ Here is the caller graph for this function:

ilFileInputGUI::setSuffixes (   $a_suffixes)

Set Accepted Suffixes.

Parameters
array$a_suffixesAccepted Suffixes

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

Referenced by ilImageFileInputGUI\__construct(), and ilFlashFileInputGUI\__construct().

{
$this->suffixes = $a_suffixes;
}

+ 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

Definition at line 65 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

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

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

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

+ Here is the call graph for this function:

Field Documentation

ilFileInputGUI::$filename
private

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

Referenced by checkInput(), and getFilename().

ilFileInputGUI::$filename_post
private

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

Referenced by getFileNamePostVar().


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