Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
4d138184
Commit
4d138184
authored
Mar 23, 2010
by
Richard Mansfield
Browse files
Add pieform element for multiple files
Signed-off-by:
Richard Mansfield
<
richardm@catalyst.net.nz
>
parent
8030c135
Changes
2
Hide whitespace changes
Inline
Side-by-side
htdocs/lib/form/elements/files.php
0 → 100644
View file @
4d138184
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage form-element
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined
(
'INTERNAL'
)
||
die
();
/**
* Multiple file elements
*
* @param array $element The element to render
* @param Pieform $form The form to render the element for
* @return string The HTML for the element
*/
function
pieform_element_files
(
Pieform
$form
,
$element
)
{
$smarty
=
smarty_core
();
$smarty
->
left_delimiter
=
'{{'
;
$smarty
->
right_delimiter
=
'}}'
;
$value
=
$form
->
get_value
(
$element
);
if
(
!
is_array
(
$value
)
&&
isset
(
$element
[
'defaultvalue'
])
&&
is_array
(
$element
[
'defaultvalue'
]))
{
$value
=
$element
[
'defaultvalue'
];
}
$smarty
->
assign
(
'name'
,
$form
->
get_name
()
.
'_'
.
$element
[
'name'
]);
return
$smarty
->
fetch
(
'form/files.tpl'
);
}
function
pieform_element_files_get_value
(
Pieform
$form
,
$element
)
{
$name
=
$form
->
get_name
()
.
'_'
.
$element
[
'name'
];
$value
=
array
();
foreach
(
$_FILES
as
$k
=>
$v
)
{
if
(
preg_match
(
'/^'
.
$name
.
'_files_\d+$/'
,
$k
)
&&
!
empty
(
$v
[
'name'
]))
{
$value
[]
=
$v
;
}
}
return
$value
;
}
function
pieform_element_files_set_attributes
(
$element
)
{
/*{{{*/
$element
[
'needsmultipart'
]
=
true
;
return
$element
;
}
/*}}}*/
htdocs/theme/raw/templates/form/files.tpl
0 → 100644
View file @
4d138184
<script
type=
"text/javascript"
>
var
{
{
$name
}
}
_current
=
0
;
var
{
{
$name
}
}
_newrefinput
;
var
{
{
$name
}
}
_newref
;
function
{
{
$name
}
}
_new
()
{
{
{
$name
}
}
_current
++
;
{
{
$name
}
}
_newrefinput
=
INPUT
(
{
'type'
:
'file'
,
'name'
:
'{{$name}}_files_'
+
{{
$name
}}
_current
}
);
var
{
{
$name
}
}
_newref
=
DIV
(
null
,{
{
$name
}
}
_newrefinput
);
appendChildNodes
(
'
{
{
$name
}
}_list
'
,
{
{
$name
}
}
_newref
);
{
{
$name
}
}
_newrefinput
.
focus
();
}
</script>
<div
id=
"{
{
$name
}
}_list"
>
<input
type=
"file"
name=
"{
{
$name
}
}_files_0"
/>
</div>
<a
href=
""
onclick=
"{
{
$name
}
}_new(); return false;"
>
[+]
</a>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment