DataObjects/Images.php
[Pman.Core] / DataObjects / Images.php
index 87688cf..53bfc77 100644 (file)
@@ -30,23 +30,20 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
     
-    function checkPerm($perm, $au)
+    function checkPerm($lvl, $au)
     {
         // default permissons are to
         // allow create / edit / if the user has
         
         if (!$au) {
-            
-          
-            
             return false;
         }
         
         $o = $this->object();
         //print_r($o);
-        if (method_exists($o, 'hasPerm')) {
+        if (method_exists($o, 'checkPerm')) {
             // edit permissions on related object needed...
-            return $o->hasPerm( $perm == 'S' ? 'S' : 'E' , $au);
+            return $o->checkPerm( $lvl == 'S' ? 'S' : 'E' , $au);
             
         }
         
@@ -268,7 +265,7 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
     /// ctrl not used??
     function onUpload($roo)
     {
-//        echo $_FILES['imageUpload']['type'];exit;
+        //print_r($_FILES); echo $_FILES['imageUpload']['type'];exit;
         if (empty($_FILES['imageUpload']['tmp_name']) || 
             empty($_FILES['imageUpload']['name']) || 
             empty($_FILES['imageUpload']['type'])
@@ -658,6 +655,21 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
             return false;
         }
         
+        if (!empty($this->imgtype) && $this->imgtype[0] == '-' && !empty($this->onid)) {
+            // then its an upload 
+            $img  = DB_DataObject::factory('Images');
+            $img->onid = $this->onid;
+            $img->ontable = $this->ontable;
+            $img->imgtype = $this->imgtype;
+            
+            $img->find();
+            while ($img->fetch()) {
+                $img->beforeDelete();
+                $img->delete();
+            }
+            
+        }
+        
         require_once 'File/MimeType.php';
         $y = new File_MimeType();
         
@@ -676,8 +688,9 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
         
         $ext = $y->toExt(trim((string) $this->mimetype ));
         
-        $this->filename = empty($this->filename) ? 
-            ('image-upload-' . date('Y-m-d H:i:s') . '.' . $ext) : ($this->filename .'.'. $ext); 
+        if(array_pop(explode('.', $this->filename)) != $ext){
+            $this->filename = $this->filename .'.'. $ext; 
+        }
         
         if (!$this->createFromData($data)) {
             return false;