From 5af85e819a8602f6720dff9e2efa6aa02d257d48 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Wed, 27 Sep 2006 19:27:37 +0000 Subject: [PATCH] Can change the photo in validation form git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@923 839d8a87-29fc-0310-9880-83ba4fa771e5 --- include/validations/photos.inc.php | 46 +++++++++++++++++++++++++---- templates/admin/valider.tpl | 2 +- templates/include/form.valid.edit-photo.tpl | 25 ++++++++++++++++ 3 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 templates/include/form.valid.edit-photo.tpl diff --git a/include/validations/photos.inc.php b/include/validations/photos.inc.php index efc6224..6d8fcc3 100644 --- a/include/validations/photos.inc.php +++ b/include/validations/photos.inc.php @@ -44,9 +44,18 @@ class PhotoReq extends Validate function PhotoReq($_uid, $_data, $_stamp=0) { - global $page; - $this->Validate($_uid, true, 'photo', $_stamp); + if (!$this->_get_image($_data)) { + return ($this = null); + } + } + + // }}} + // {{{ function _get_image() + + function _get_image($_data) + { + global $page; // calcul de la taille de l'image require_once dirname(__FILE__).'/../../classes/VarStream.php'; @@ -56,7 +65,7 @@ class PhotoReq extends Validate if (empty($image_infos)) { $page->trig("Image invalide"); - return ($this = null); + return false; } list($this->x, $this->y, $this->mimetype) = $image_infos; @@ -66,14 +75,14 @@ class PhotoReq extends Validate case 3: $this->mimetype = "png"; break; default: $page->trig("Type d'image invalide"); - return ($this = null); + return false; } if (strlen($_data) > SIZE_MAX) { $img = imagecreatefromstring($_data); if (!$img) { $page->trig("image trop grande et impossible à retailler automatiquement"); - return ($this = null); + return false; } $nx = $x = imagesx($img); @@ -99,6 +108,7 @@ class PhotoReq extends Validate unlink($file); } $this->data = $_data; + return true; } // }}} @@ -116,6 +126,32 @@ class PhotoReq extends Validate { return 'include/form.valid.photos.tpl'; } // }}} + // {{{ function editor() + + function editor() + { + return 'include/form.valid.edit-photo.tpl'; + } + + // }}} + // {{{ function handle_editor() + + function handle_editor() + { + if (isset($_FILES['userfile']['tmp_name'])) { + $file = $_FILES['userfile']['tmp_name']; + if ($data = file_get_contents($file)) { + if ($this->_get_image($data)) { + return true; + } + } else { + $page->trig('Fichier inexistant ou vide'); + } + } + return false; + } + + // }}} // {{{ function _mail_subj function _mail_subj() diff --git a/templates/admin/valider.tpl b/templates/admin/valider.tpl index 15ecd4d..5a56ea1 100644 --- a/templates/admin/valider.tpl +++ b/templates/admin/valider.tpl @@ -53,7 +53,7 @@ {if $valid->editor()} -
+
{include file=$valid->editor()} diff --git a/templates/include/form.valid.edit-photo.tpl b/templates/include/form.valid.edit-photo.tpl new file mode 100644 index 0000000..3b1b607 --- /dev/null +++ b/templates/include/form.valid.edit-photo.tpl @@ -0,0 +1,25 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2006 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* 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 2 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, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + + + +{* vim:set et sw=2 sts=2 sws=2: *} -- 2.1.4