noalyss Version-9
ifile.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief Html Input
24 */
25
26/*!
27 * \class IFile
28 * \brief Html Input for uploading file, must be in a form with enctype="multipart/form-data"
29 */
30class IFile extends HtmlInput
31{
32 // if true , the size is tested and a box is displaid
34 private $multiple ; // false by default, if true allow to select several files
35 function __construct($p_name = "", $p_value = "", $p_id = "")
36 {
37 parent::__construct($p_name, $p_value, $p_id);
38 $this->alert_on_size=false;
39 $this->multiple=false;
40 }
41
42 public function get_multiple(): bool
43 {
44 return $this->multiple;
45 }
46
47 public function set_multiple(bool $multiple): IFile
48 {
49 $this->multiple = $multiple;
50 return $this;
51 }
52
53 /**
54 * @return false
55 */
56 public function getAlertOnSize()
57 {
59 }
60
61 /**
62 * if true , the size is tested and a box is displaid
63 * @param false $alert_on_size
64 */
65 public function setAlertOnSize(bool $alert_on_size)
66 {
67 $this->alert_on_size = $alert_on_size;
68 }
69
70 /*!\brief show the html input of the widget*/
71 public function input($p_name=null,$p_value=null)
72 {
73 $this->name=($p_name==null)?$this->name:$p_name;
74 $this->value=($p_value==null)?$this->value:$p_value;
75 if ( $this->readOnly==true) return $this->display();
76 if ($this->id=="") $this->id=uniqid("file_");
77 $multiple="";
78 if ( $this->multiple) $multiple=" multiple ";
79
80 $r=sprintf('<INPUT class="inp" %s TYPE="file" name="%s" id="%s" value="%s">',
82 $this->name,
83 $this->id,
84 $this->value);
85 if ( $this->alert_on_size)
86 {
87 $max_size=MAX_FILE_SIZE;
88 $max_size_mb=round($max_size / 1024 /1024,2);
89 $too_large=h(_("Fichier trop grand(max = $max_size_mb MB)"));
90
91 $js_check_size=sprintf('
92 document.getElementById("%s").addEventListener("change",function ()
93 {
94 var fFile=document.getElementById("%s");
95 if (fFile.files[0] && fFile.files[0].size>%s) { smoke.alert("%s");fFile.value="";}
96 });',$this->id,$this->id,$max_size,$too_large);
97 $r.=create_script($js_check_size);
98
99 }
100 return $r;
101
102 }
103 /*!\brief print in html the readonly value of the widget*/
104 public function display()
105 {
106
107 }
108 static public function test_me()
109 {
110 }
111}
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
h( $row[ 'oa_description'])
$from_poste name
class widget This class is used to create all the HTML INPUT TYPE and some specials which works with ...
Html Input for uploading file, must be in a form with enctype="multipart/form-data".
Definition: ifile.class.php:31
set_multiple(bool $multiple)
Definition: ifile.class.php:47
getAlertOnSize()
Definition: ifile.class.php:56
input($p_name=null, $p_value=null)
show the html input of the widget
Definition: ifile.class.php:71
$alert_on_size
Definition: ifile.class.php:33
__construct($p_name="", $p_value="", $p_id="")
Definition: ifile.class.php:35
display()
print in html the readonly value of the widget
get_multiple()
Definition: ifile.class.php:42
setAlertOnSize(bool $alert_on_size)
if true , the size is tested and a box is displaid
Definition: ifile.class.php:65
static test_me()
$icard readOnly
create_script($p_string)
create the HTML for adding the script tags around of the script