DataObjects/core.sql
[Pman.Core] / DataObjects / Person.php
index 8124d39..48bab37 100644 (file)
@@ -41,9 +41,14 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
     ###END_AUTOCODE
     /**
      *
-     * @param {String} $templateFile  (mail/XXXXXXX.txt) exclude the mail and .txt bit.
-     * @param {Array|Object} $args   data to send out..
-     * @return {Array|PEAR_Error} array of $recipents, $header, $body 
+     *
+     *
+     *
+     *  FIXME !!!! -- USE Pman_Core_Mailer !!!!!
+     *
+     *
+     *
+     *  
      */
     function buildMail($templateFile, $args)
     {
@@ -105,16 +110,15 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         /* use variables from this object to ouput data. */
         $mailtext = $template->bufferedOutputObject($content);
         
+        $htmlbody = false;
         // if a html file with the same name exists, use that as the body
         // I've no idea where this code went, it was here before..
         if (false !== $template->resolvePath ( "mail/$templateFile.html" )) {
             $tops['nonHTML'] = false;
             $template = new HTML_Template_Flexy( $tops );
             $template->compile("mail/$templateFile.html");
-       
             $htmlbody = $template->bufferedOutputObject($content);
             
-            
         }
         
         
@@ -127,6 +131,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         
         $decoder = new Mail_mimeDecode($mailtext);
         $parts = $decoder->getSendArray();
+        
         if (PEAR::isError($parts)) {
             return $parts;
             //echo "PROBLEM: {$parts->message}";
@@ -139,6 +144,20 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         }
         $headers['Date'] = date('r');
         
+        if ($htmlbody !== false) {
+            require_once 'Mail/mime.php';
+            $mime = new Mail_mime(array('eol' => "\n"));
+            $mime->setTXTBody($body);
+            $mime->setHTMLBody($htmlbody);
+            // I think there might be code in mediaoutreach toEmail somewhere
+            // h embeds images here..
+            $body = $mime->get();
+            $headers = $mime->headers($headers);
+            
+        }
+        
+         
+        
         return array(
             'recipients' => $recipents,
             'headers'    => $headers,
@@ -290,6 +309,12 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         $u = DB_DataObject::factory('Person');
         $u->whereAdd(' LENGTH(passwd) > 0');
         if (!$u->count()){
+            
+            // fake person - open system..
+            $ce = DB_DataObject::factory('core_enum');
+            $ce->initEnums();
+            
+            
             $u = DB_DataObject::factory('Person');
             $u->id = -1;
             return $u;
@@ -506,6 +531,8 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         
     }
     
+    
+    
     function hasPerm($name, $lvl) 
     {
         static $pcache = array();
@@ -660,13 +687,13 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             
         }
         
-        
         if (!empty($q['query']['search'])) {
             $s = $this->escape($q['query']['search']);
                     $this->whereAdd("
                         $tn_p.name LIKE '%$s%'  OR
                         $tn_p.email LIKE '%$s%'  OR
                         $tn_p.role LIKE '%$s%'  OR
+                        $tn_p.phone LIKE '%$s%' OR
                         $tn_p.remarks LIKE '%$s%' 
                         
                     ");
@@ -782,9 +809,14 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
     }
     function onInsert($req, $roo)  
     {
-        
-        if ($roo->authUser->id < 0) {
+         
+        $p = DB_DataObject::factory('person');
+        if ($roo->authUser->id < 0 && $p->count() == 1) {
+            // this seems a bit risky...
+            
             $g = DB_DataObject::factory('Groups');
+            $g->initGroups();
+            
             $g->type = 0;
             $g->get('name', 'Administrators');