fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [7968] catch: update notify on import


From: Sigurd Nes
Subject: [Fmsystem-commits] [7968] catch: update notify on import
Date: Sat, 29 Oct 2011 21:29:13 +0000

Revision: 7968
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=7968
Author:   sigurdne
Date:     2011-10-29 21:29:13 +0000 (Sat, 29 Oct 2011)
Log Message:
-----------
catch: update notify on import

Modified Paths:
--------------
    trunk/catch/inc/custom/default/notify_by_email.php

Modified: trunk/catch/inc/custom/default/notify_by_email.php
===================================================================
--- trunk/catch/inc/custom/default/notify_by_email.php  2011-10-29 12:21:34 UTC 
(rev 7967)
+++ trunk/catch/inc/custom/default/notify_by_email.php  2011-10-29 21:29:13 UTC 
(rev 7968)
@@ -1,134 +1,132 @@
 <?php
-
        $validator = CreateObject('phpgwapi.EmailAddressValidator');
 
-       if(!isset($config_data['notify_email']) || 
!$config_data['notify_email'])
+       if(isset($config_data['notify_email']) && $config_data['notify_email'])
        {
-               throw new Exception("notify_accounting_by_email: missing 
'notify_email' in config for this catch schema:{$schema_text}");
-       }
+               $to_array = array();
+               $_to_array = explode(',', $config_data['notify_email']);
+               if (isset($config_data['notify_rule']) && 
$config_data['notify_rule'])
+               {
+                       $notify_rule = explode(',', 
$config_data['notify_rule']);
+                       foreach($notify_rule as $_rule )
+                       {
+                               $__rule = explode('=&gt;', $_rule);
+                               if($__rule)
+                               {
+                                       $_condition = explode('=', $__rule[0]);
+                                       if($_condition)
+                                       {
+                                               $this->db->query("SELECT * FROM 
$target_table WHERE id = {$id} AND " . trim($_condition[0]) . "='" . 
trim($_condition[1]) . "'",__LINE__,__FILE__);
+                                               if($this->db->next_record() && 
isset($_to_array[($__rule[1]-1)]))
+                                               {
+                                                       $to_array[] =  
$_to_array[($__rule[1]-1)];
+                                               }
+                                       }
+                               }
+                       }
+               }
+               else
+               {
+                       $to_array = $_to_array;
+               }
+//_debug_array($to_array);
 
-       $to_array = explode(',', $config_data['notify_email']);
+               $socommon               = CreateObject('property.socommon');
+               $prefs = $socommon->create_preferences('property',$user_id);
 
-//_debug_array($to_array);
-/*
-       foreach($to_array as $_to)
-       {
-               if( !$validator->check_email_address($_to) )
+               if ($validator->check_email_address($prefs['email']))
                {
-                       throw new Exception("notify_accounting_by_email: an 
unvalid 'notify_email': {$_to} in config for schema:{$schema_text}");
+                       $account_name = 
$GLOBALS['phpgw']->accounts->id2name($user_id);
+                       // avoid problems with the delimiter in the send class
+                       if(strpos($account_name,','))
+                       {
+                               $_account_name = explode(',', $account_name);
+                               $account_name = ltrim($_account_name[1]) . ' ' 
. $_account_name[0];
+                       }
+                       $from_email = "{$account_name}<{$prefs['email']}>";
+
+                       $to_array[] = $from_email;
                }
-       }
-*/                                     
-       $socommon               = CreateObject('property.socommon');
-       $prefs = $socommon->create_preferences('property',$user_id);
-//_debug_array($prefs);
-       if ($validator->check_email_address($prefs['email']))
-       {
-               $account_name = $GLOBALS['phpgw']->accounts->id2name($user_id);
-               // avoid problems with the delimiter in the send class
-               if(strpos($account_name,','))
+
+               if (!is_object($GLOBALS['phpgw']->send))
                {
-                       $_account_name = explode(',', $account_name);
-                       $account_name = ltrim($_account_name[1]) . ' ' . 
$_account_name[0];
+                       $GLOBALS['phpgw']->send = CreateObject('phpgwapi.send');
                }
-               $from_email = "{$account_name}<{$prefs['email']}>";
 
-               $to_array[] = $from_email;
-       }
+               $_to = implode(';',$to_array);
 
-       if (!is_object($GLOBALS['phpgw']->send))
-       {
-               $GLOBALS['phpgw']->send = CreateObject('phpgwapi.send');
-       }
+               $from_name = 'noreply';
+               $from_email = isset($from_email) && $from_email ? $from_email : 
"{$from_name}<address@hidden>";
+               $cc = '';
+               $bcc ='';
+               $subject = "{$schema_text}::{$id}";
 
-       $_to = implode(';',$to_array);
+               unset($_link_to_item);
 
-       $from_name = 'noreply';
-       $from_email = isset($from_email) && $from_email ? $from_email : 
"{$from_name}<address@hidden>";
-       $cc = '';
-       $bcc ='';
-       $subject = "{$schema_text}::{$id}";
-       
-       /*
-       $_link_to_item = 'http://'. 
$GLOBALS['phpgw_info']['server']['hostname'] . 
$GLOBALS['phpgw']->link('/index.php',array
-                                               (
-                                                       'menuaction'    => 
'property.uientity.view',
-                                                       'type'                  
=> 'catch',
-                                                       'entity_id'             
=> $entity_id,
-                                                       'cat_id'                
=> $cat_id,
-                                                       'id'                    
=> $id
-                                               ));
-       */
-       //$body = "<a href='{$_link_to_item}'>{$subject}</a>";
-       unset($_link_to_item);
+               if(isset($config_data['email_message']) && 
$config_data['email_message'])
+               {
+                       $body = str_replace(array('[', ']'), array('<', '>'), 
$config_data['email_message']);
+               }
+               else
+               {
+                       $body ="<H2>Det er registrert ny post i 
{$schema_text}</H2>";
+               }
 
-       if(isset($config_data['email_message']) && 
$config_data['email_message'])
-       {
-               $body = str_replace(array('[', ']'), array('<', '>'), 
$config_data['email_message']);
-       }
-       else
-       {
-               $body ="<H2>Det er registrert ny post i {$schema_text}</H2>";
-       }
+               $jasper_id = isset($config_data['jasper_id']) && 
$config_data['jasper_id'] ? $config_data['jasper_id'] : 0;
 
-       $jasper_id = isset($config_data['jasper_id']) && 
$config_data['jasper_id'] ? $config_data['jasper_id'] : 0;
+               $attachments = array();
 
-       $attachments = array(); 
+               if(!$jasper_id)
+               {
+                       
$this->receipt['error'][]=array('msg'=>lang('notify_by_email: missing 
"jasper_id" in config for catch %1 schema', $schema_text));
+               }
+               else
+               {
+                       $jasper_parameters = '';
+                       $_parameters = array();
 
-       if(!$jasper_id)
-       {
-               $this->receipt['error'][]=array('msg'=>lang('notify_by_email: 
missing "jasper_id" in config for catch %1 schema', $schema_text));
-       }
-       else
-       {
-               $jasper_parameters = '';
-               $_parameters = array();
+                       $_parameters[] =  "ID|{$id}";
+                       $jasper_parameters = '"' . implode(';', $_parameters) . 
'"';
 
-               $_parameters[] =  "ID|{$id}";
-               $jasper_parameters = '"' . implode(';', $_parameters) . '"';
+                       unset($_parameters);
 
-               unset($_parameters);
+                       $output_type            = 'PDF';
+                       $values_jasper          = 
execMethod('property.bojasper.read_single', $jasper_id);
+                       $report_source          = 
"{$GLOBALS['phpgw_info']['server']['files_dir']}/property/jasper/{$jasper_id}/{$values_jasper['file_name']}";
+                       $jasper_wrapper         = 
CreateObject('phpgwapi.jasper_wrapper');
 
-               $output_type            = 'PDF';
-               $values_jasper          = 
execMethod('property.bojasper.read_single', $jasper_id);
-               $report_source          = 
"{$GLOBALS['phpgw_info']['server']['files_dir']}/property/jasper/{$jasper_id}/{$values_jasper['file_name']}";
-               $jasper_wrapper         = 
CreateObject('phpgwapi.jasper_wrapper');
+                       try
+                       {
+                               $report = 
$jasper_wrapper->execute($jasper_parameters, $output_type, $report_source, 
true);
+                       }
+                       catch(Exception $e)
+                       {
+                               $error = $e->getMessage();
+                               echo "<H1>{$error}</H1>";
+                       }
 
-       //_debug_array($jasper_parameters);
-       //_debug_array($output_type);
-       //_debug_array($report_source);die();
+                       $jasper_fname = 
tempnam($GLOBALS['phpgw_info']['server']['temp_dir'], 'PDF_') . '.pdf';
+                       file_put_contents($jasper_fname, $report['content'], 
LOCK_EX);
 
-               try
-               {
-                       $report = $jasper_wrapper->execute($jasper_parameters, 
$output_type, $report_source, true);
+                       $attachments[] = array
+                       (
+                               'file' => $jasper_fname,
+                               'name' => $report['filename'],
+                               'type' => $report['mime']
+                       );
+
+                       if($attachments)
+                       {
+                               $body .= "</br>Se vedlegg";
+                       }
                }
-               catch(Exception $e)
+
+               if ($_to && $GLOBALS['phpgw']->send->msg('email', $_to, 
$subject, stripslashes($body), '', $cc, $bcc, $from_email, $from_name, 'html', 
'', $attachments , true))
                {
-                       $error = $e->getMessage();
-                       echo "<H1>{$error}</H1>";
+                       $this->receipt['message'][]=array('msg'=> "email 
notification sent to: {$_to}");
                }
-
-               $jasper_fname = 
tempnam($GLOBALS['phpgw_info']['server']['temp_dir'], 'PDF_') . '.pdf';
-               file_put_contents($jasper_fname, $report['content'], LOCK_EX);
-
-               $attachments[] = array
-               (
-                       'file' => $jasper_fname,
-                       'name' => $report['filename'],
-                       'type' => $report['mime']
-               );
-               
-               if($attachments)
+               if( isset($jasper_fname) && is_file($jasper_fname) )
                {
-                       $body .= "</br>Se vedlegg";
+                       unlink($jasper_fname);
                }
        }
-
-       if ($GLOBALS['phpgw']->send->msg('email', $_to, $subject, 
stripslashes($body), '', $cc, $bcc, $from_email, $from_name, 'html', '', 
$attachments , true))
-       {
-               $this->receipt['message'][]=array('msg'=> "email notification 
sent to: {$_to}");        
-       }
-       if( isset($jasper_fname) && is_file($jasper_fname) )
-       {
-               unlink($jasper_fname);
-       }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]