2 /*******************************************************************************
3 * Copyright (C) 2007 Easter-eggs
4 * http://ldapsaisie.labs.libre-entreprise.org
6 * Author: See AUTHORS file in top-level directory.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ******************************************************************************/
25 * Element texte d'un formulaire pour LdapSaisie
27 * Cette classe définis les éléments textes des formulaires.
28 * Elle étant la classe basic LSformElement.
30 * @author Benjamin Renard <brenard@easter-eggs.com>
33 class LSformElement_image extends LSformElement {
35 var $postImage = NULL;
36 var $tmp_file = array();
37 var $fieldTemplate = 'LSformElement_image_field.tpl';
40 * Retourne les infos d'affichage de l'élément
42 * Cette méthode retourne les informations d'affichage de l'élement
46 function getDisplay(){
47 LSsession :: addCssFile('LSformElement_image.css');
49 if (!$this -> isFreeze()) {
50 LSsession :: addHelpInfos(
53 'zoom' => _('Click to enlarge.'),
54 'delete' => _('Click to delete the picture.')
57 $id=$this -> name.'_'.rand();
58 $return = $this -> getLabelInfos();
59 $return['html'] = $this -> fetchTemplate(NULL,array('id' => 'LSformElement_image_input_'.$id));
60 $this -> form -> setMaxFileSize(MAX_SEND_FILE_SIZE);
63 if (!empty($this -> values[0])) {
64 $img_path = LSsession :: getTmpFile($this -> values[0]);
65 $GLOBALS['Smarty'] -> assign('LSformElement_image',array(
69 if (!$this -> isFreeze()) {
70 $GLOBALS['Smarty'] -> assign('LSformElement_image_actions','delete');
73 if ($this -> form -> definedError($this -> name)) {
74 $GLOBALS['Smarty'] -> assign('LSformElement_image_errors',true);
76 if (LSsession :: loadLSclass('LSsmoothbox')) {
77 LSsmoothbox :: loadDependenciesDisplay();
79 LSsession :: addJSscript('LSformElement_image.js');
85 * Recupère la valeur de l'élement passée en POST
87 * Cette méthode vérifie la présence en POST de la valeur de l'élément et la récupère
88 * pour la mettre dans le tableau passer en paramètre avec en clef le nom de l'élément
90 * @param[] array Pointeur sur le tableau qui recupèrera la valeur.
92 * @retval boolean true si la valeur est présente en POST, false sinon
94 function getPostData(&$return) {
95 if($this -> isFreeze()) {
99 if (is_uploaded_file($_FILES[$this -> name]['tmp_name'])) {
100 $fp = fopen($_FILES[$this -> name]['tmp_name'], "r");
101 $buf = fread($fp, filesize($_FILES[$this -> name]['tmp_name']));
103 $tmp_file = LS_TMP_DIR.$this -> name.'_'.rand().'.tmp';
104 if (move_uploaded_file($_FILES[$this -> name]['tmp_name'],$tmp_file)) {
105 LSsession :: addTmpFile($buf,$tmp_file);
107 $return[$this -> name][0] = $buf;
110 if (isset($_POST[$this -> name.'_delete'])) {
111 $return[$this -> name][0]='';