Can change the photo in validation form
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Wed, 27 Sep 2006 19:27:37 +0000 (19:27 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Wed, 27 Sep 2006 19:27:37 +0000 (19:27 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@923 839d8a87-29fc-0310-9880-83ba4fa771e5

include/validations/photos.inc.php
templates/admin/valider.tpl
templates/include/form.valid.edit-photo.tpl [new file with mode: 0644]

index efc6224..6d8fcc3 100644 (file)
@@ -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()
index 15ecd4d..5a56ea1 100644 (file)
@@ -53,7 +53,7 @@
   {if $valid->editor()}
   <tr>
     <td colspan="2" class="center">
-      <form action="admin/validate" method="post">
+      <form enctype="multipart/form-data" action="admin/validate" method="post">
         <div>
           {include file=$valid->editor()}
           <input type="hidden" name="uid"    value="{$valid->uid}" />
diff --git a/templates/include/form.valid.edit-photo.tpl b/templates/include/form.valid.edit-photo.tpl
new file mode 100644 (file)
index 0000000..3b1b607
--- /dev/null
@@ -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               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<input name="userfile" type="file" size="20" maxlength="150" />
+
+{* vim:set et sw=2 sts=2 sws=2: *}