DataObjects/Core_watch.php
[Pman.Core] / DataObjects / Person.php
index 40aa9da..ec47f6d 100644 (file)
@@ -41,6 +41,16 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
     ###END_AUTOCODE
     /**
      *
+     * Build an email to sent do user
+     *
+     * key 'args'
+     *
+     * no_auth => disable authentication check on
+     * templateDir => alternative template directory.
+     * HTTP_HOST
+     *
+     * expects mail/TMPLATE.txt (if .html exists, it will be the html body version)
+     * 
      * @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 
@@ -82,21 +92,42 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             (isset($ff->HTTP_HOST) ? $ff->HTTP_HOST : 'localhost');
             
         /* use the regex compiler, as it doesnt parse <tags */
-        require_once 'HTML/Template/Flexy.php';
-        $template = new HTML_Template_Flexy( array(
+        
+        $tops = array(
             'compiler'    => 'Flexy',
             'nonHTML' => true,
             'filters' => array('SimpleTags','Mail'),
             //     'debug'=>1,
-        ));
+        );
+        
+        
+        
+        if (!empty($args['templateDir'])) {
+            $tops['templateDir'] = $args['templateDir'];
+        }
+        
         
-     
-         
         
+        require_once 'HTML/Template/Flexy.php';
+        $template = new HTML_Template_Flexy( $tops );
         $template->compile("mail/$templateFile.txt");
         
         /* 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);
+            
+        }
+        
+        
+        
         //echo "<PRE>";print_R($mailtext);
         //print_R($mailtext);exit;
         /* With the output try and send an email, using a few tricks in Mail_MimeDecode. */
@@ -105,6 +136,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}";
@@ -117,6 +149,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,
@@ -453,7 +499,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         }
         
         // ------ STANDARD PERMISSION HANDLING.
-        
+        $isOwner = $this->company()->comptype == 'OWNER';
         $g = DB_DataObject::Factory('group_members');
         $grps = $g->listGroupMembership($this);
        //var_dump($grps);
@@ -462,7 +508,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         // the load all the perms for those groups, and add them all together..
         // then load all those 
         $g = DB_DataObject::Factory('group_rights');
-        $ret =  $g->listPermsFromGroupIds($grps, $isAdmin);
+        $ret =  $g->listPermsFromGroupIds($grps, $isAdmin, $isOwner);
         //echo '<PRE>';print_r($ret);
         return $ret;