phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] [20904] New feature : email notification for transiti


From: Pascal Vilarem
Subject: [Phpgroupware-cvs] [20904] New feature : email notification for transitions
Date: Mon, 04 Jan 2010 15:58:20 +0000

Revision: 20904
          
http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=20904
Author:   maat
Date:     2010-01-04 15:58:18 +0000 (Mon, 04 Jan 2010)
Log Message:
-----------
New feature : email notification for transitions

Modified Paths:
--------------
    modules/ged/trunk/inc/class.flows.inc.php
    modules/ged/trunk/inc/class.soflows.inc.php
    modules/ged/trunk/inc/hook_preferences.inc.php

Added Paths:
-----------
    modules/ged/trunk/inc/class.ged_pref.inc.php
    modules/ged/trunk/templates/base/import_project.tpl
    modules/ged/trunk/templates/base/mailing.tpl

Modified: modules/ged/trunk/inc/class.flows.inc.php
===================================================================
--- modules/ged/trunk/inc/class.flows.inc.php   2010-01-04 15:50:20 UTC (rev 
20903)
+++ modules/ged/trunk/inc/class.flows.inc.php   2010-01-04 15:58:18 UTC (rev 
20904)
@@ -368,6 +368,12 @@
                                                //TODO : Check triggers results
                                        }
 
+                                       
if(!isset($transition_context['custom_fields']['mail_notification']) || 
$transition_context['custom_fields']['mail_notification'] != 'no')
+                                       {
+                                               $transitions = 
$this->soflows->list_transitions_notification($transition);
+                                               if(count($transitions) != 0)
+                                                       
$this->send_transition_notification($object,$transitions);
+                                       }
                                        $transition_result=$method_result;
                                }
                                elseif ($method_result['status'] == 
'processing' )
@@ -410,9 +416,75 @@
                * @param   array    $context          TODO
                * @return                             error status
                */
-               public function 
send_status_notification($object,$status,$context=null)
+               public function 
send_transition_notification($object,$transitions)
                {
-                       // TODO
+                       
+                       if($object['project_root'] != 0)
+                       {
+                               
$all_users=$this->soflows->send_transition_notification($transitions,$object);
+                               if(count($all_users) != 0)
+                               {
+                                       
$users=$this->app_flow_client->notification_filter($all_users,$object);
+                                       
+                                       $msg = 
$this->app_flow_client->custom_message($object);
+                                       
+                                       
+                                       /*
+                                        * HTML message : 
+                                        */
+                                       $message_html="<html>
+                               <head>
+                                       
<title>".$GLOBALS['phpgw_info']['server']['site_title']."</title>
+                               </head>
+                               <body>
+                                       <div id=\"header\">
+                                                       <H3>STERIA Isis, 
notifies you to :</H3><br/>
+                               </div>
+                                       ".$msg['html']."
+                                       <div id=\"footer\">
+                                                       <font color=\"\">
+                                                                               
Powered by
+                                                                               
<a style=\"color:#505E7A; text-decoration:none;\" 
href=\"http://www.phpgroupware.org\";>phpGroupWare</a>
+                                                                               
version ".$GLOBALS['phpgw_info']['server']['versions']['phpgwapi']."
+                                                               </font>
+                               </div>
+                                       </body>
+                               </html>"; 
+                                       $sujet = 'Isis notification';
+                                       if(isset($msg['sujet']))
+                                       {
+                                               $sujet .= " : ".$msg['sujet'];
+                                       }
+                                       $border = '-----=' . 
md5(uniqid(mt_rand())); 
+                                       $headers = 'From: 
<address@hidden>'."\n";
+                                       $headers .= "Reply-To: 
<address@hidden>\n";
+                                       $headers .= "Bcc: 
".implode(';',$users)."\n";
+                       $headers .= "MIME-Version: 1.0\n";
+                                       $headers .= "Content-Type: 
multipart/alternative; boundary=\"$border\"\n";
+                       
+                       //-----------------------------------------------
+                       //MESSAGE texte
+                       //-----------------------------------------------
+                       $message = 'This is a multi-part message in MIME 
format.'."\n\n"; 
+                       $message .= "--$border\n";
+                                       $message .= "Content-Type: text/plain; 
charset=UTF-8\n";
+                                       $message .= "Content-Transfer-Encoding: 
8bit\n\n";
+                       $message .= $msg['texte']."\n\n";
+               
+                       //-----------------------------------------------
+                       //MESSAGE HTML
+                       //-----------------------------------------------
+                       
+                       $message .= "--$border\n";
+                                       $message .= "Content-Type: text/html; 
charset=UTF-8\n";
+                                       $message .= "Content-Transfer-Encoding: 
8bit\n\n";
+                       $message .= $message_html."\n\n";
+                       $message .= '--'.$border.'--'."\n";
+                         
+                                       mail(null, $sujet , $message,$headers); 
+                               }
+                       }
+                       
                }
 
                /**

Added: modules/ged/trunk/inc/class.ged_pref.inc.php
===================================================================
--- modules/ged/trunk/inc/class.ged_pref.inc.php                                
(rev 0)
+++ modules/ged/trunk/inc/class.ged_pref.inc.php        2010-01-04 15:58:18 UTC 
(rev 20904)
@@ -0,0 +1,160 @@
+<?php
+       
/**************************************************************************
+       * phpGroupWare - ged
+       * http://www.phpgroupware.org
+       * Written by Pascal Vilarem <address@hidden>
+       *
+       * 
--------------------------------------------------------------------------
+       *  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
+       
***************************************************************************/
+
+include_once ( 'ged_common_functions.inc.php');
+
+class ged_pref
+{
+       
+       var $public_functions=array(
+               'mailing'=>true
+       );
+
+       function ged_pref()
+       {               
+               $this->ged_dm=CreateObject('ged.ged_dm', True);
+               /*
+                *  Get sure that the user is a ged admin
+                * else eject the looser
+                */
+/*             if ( ! $this->ged_dm->pref )
+               {
+                       $link_data=null;
+                       $GLOBALS['phpgw']->redirect_link('/index.php', 
$link_data);
+               }
+*/
+               $this->t = clone ($GLOBALS['phpgw']->template);
+               define('GED_TPL', 
ExecMethod('phpgwapi.phpgw.common.get_tpl_dir', 'ged'));
+               $this->t->set_root(GED_TPL);
+
+               if(address@hidden($GLOBALS['phpgw']->css))
+               {
+                       $GLOBALS['phpgw']->css = createObject('phpgwapi.css');
+               }
+               $GLOBALS['phpgw']->css->validate_file('default','ged');
+       }
+
+       // wrapper to use new phpgw::get_var if it exists
+       // and old get_var otherwise
+       function get_var($varname,$method=null,$default=null)
+       {
+               return ged_get_var($varname,$method, $default);
+       }
+       
+       function display_app_header()
+       {
+               $GLOBALS['phpgw']->common->phpgw_header();
+               echo parse_navbar();
+       }
+
+       function mailing()
+       {
+               
+               $project_choice=$this->get_var('project_choice',array('POST'));
+               $action_choice=$this->get_var('action_choice',array('POST'));
+               $tmp_array=$this->get_var('rm_reject', array('POST', 'GET'));
+               if(is_array($tmp_array))
+               {
+                       $key=array_keys($tmp_array);
+                       $rm_reject=$key[0];
+               }
+               else
+                       $rm_reject = null;
+               if(isset($project_choice) && !isset($rm_reject))
+                       
$this->ged_dm->add_reject($project_choice,$action_choice);
+               if(isset($rm_reject))
+                       $this->ged_dm->remove_reject($rm_reject);
+
+
+               $this->t->set_file(array('mailing_tpl'=>'mailing.tpl'));
+               
+               /*
+                * recovery projects
+                */
+               
+               $list_projects= $this->ged_dm->list_wanted_projects();
+               $this->t->set_block('mailing_tpl', 'projects_block', 
'projects_block_handle');
+
+               $this->t->set_var('project_name', lang("All"));
+               $this->t->set_var('project_id', 0);
+               $this->t->fp('projects_block_handle', 'projects_block', True);
+               foreach($list_projects as $key => $project)
+               {
+                       
+                       $this->t->set_var('project_name', $project);
+                       $this->t->set_var('project_id', $key);
+                       $this->t->fp('projects_block_handle', 'projects_block', 
True);
+               }
+               
+               /*
+                * recovery actions
+                */
+               
+               $list_actions= $this->ged_dm->list_ged_action();
+               $this->t->set_block('mailing_tpl', 'actions_block', 
'actions_block_handle');
+
+               foreach($list_actions as $action)
+               {
+                       
+                       $this->t->set_var('action_name', $action);
+                       $this->t->set_var('action_id', $action);
+                       $this->t->fp('actions_block_handle', 'actions_block', 
True);
+               }
+               
+               /*
+                * recovery rejects
+                */
+               
+               $list_rejects=$this->ged_dm->list_ged_reject();
+               $this->t->set_block('mailing_tpl', 'rejects_block', 
'rejects_block_handle');
+               if(isset($list_rejects))
+               {
+                       foreach($list_rejects as $key => $reject)
+                       {
+                               if($reject['project'] == 0)
+                               {
+                                       $this->t->set_var('reject_name', "ALL 
".$reject['action']);
+                                       $this->t->set_var('reject_id', $key);
+                               $this->t->fp('rejects_block_handle', 
'rejects_block', True);
+                               }
+                               else
+                               {
+                                       $info = 
$this->ged_dm->get_element_info($reject['project']);
+                                       if(is_array($info))
+                                       {
+                                               
$this->t->set_var('reject_name', $info['name']." ".$reject['action']);
+                                               $this->t->set_var('reject_id', 
$key);
+                                               
$this->t->fp('rejects_block_handle', 'rejects_block', True);
+                                       }
+                               }
+                               
+                       }
+               }
+               $this->t->set_var('msg1', lang("by default, you will receive a 
notification when an action was carried out under two conditions:<BR/> - Follow 
the project.<BR/> - the performed action permits you to perform an action on 
the doc."));
+               $this->t->set_var('msg2', lang("if you receive notifications 
that do not interest you, you can choose not to receive mail.<BR/>For this, 
choose a project (or all) and an action, then click "));
+               $this->t->set_var('add-image', 
$GLOBALS['phpgw']->common->image('ged', "add-16"));
+               $this->t->set_var('remove-image', 
$GLOBALS['phpgw']->common->image('ged', "remove-16"));
+               $this->t->set_var('rejected list', lang("notification list 
rejected"));
+               
+               
+               $this->display_app_header();
+               
+               $this->t->pfp('out', 'mailing_tpl');
+       }
+       
+       
+       
+       
+       
+}
+       
\ No newline at end of file


Property changes on: modules/ged/trunk/inc/class.ged_pref.inc.php
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: modules/ged/trunk/inc/class.soflows.inc.php
===================================================================
--- modules/ged/trunk/inc/class.soflows.inc.php 2010-01-04 15:50:20 UTC (rev 
20903)
+++ modules/ged/trunk/inc/class.soflows.inc.php 2010-01-04 15:58:18 UTC (rev 
20904)
@@ -340,6 +340,23 @@
                function get_transition_roles($transition,$object)
                {
                        
+                       if(is_array($transition))
+                               $tran = implode(",", $transition);      
+                       else
+                               $tran = $transition;
+                               
+                       $sql="SELECT distinct account_id FROM phpgw_flows_roles 
where transition in (".$tran.")";
+               
+                       $this->db->query($sql, __LINE__, __FILE__);
+                       
+                       $cpt=0;
+                       $roles=array();
+                       while ($this->db->next_record())
+                       {
+                               $roles[$cpt++]=$this->db->f('account_id');
+                       }
+       
+                       return($roles);
                }
                
                /**
@@ -473,11 +490,39 @@
                * @param   TODO
                * @return  TODO                   list of phpgw accounts
                */
-               function send_status_notification($flow,$status,$context=null)
+               public function 
send_transition_notification($transitions,$object)
                {
+                       
$users=$this->get_transition_roles($transitions,$object);
+                       $final_users=array();
+                       foreach($users as $user)
+               {
+                               
$user_data=$GLOBALS['phpgw']->accounts->get_account_data($user);
                        
+                               if(isset($user_data[$user]))
+                               {
+                                       
+                                       
$data=$GLOBALS['phpgw']->accounts->member($user);//return false, if $user is 
not a group,else, return an array with members
+                                       if(!$data)
+                                       {
+                                               $final_users[$user]=true;
+                                       }
+                                       else
+                                       {
+                                               foreach($data as $group_user)
+                                               {
+                                                       
if($group_user['account_name'] )
+                                                       {
+                                                               
$final_users[$group_user['account_id']]=true;
+                                                       }
+                                               }
+                                       }
+                               }
                }
 
+                       return(array_keys($final_users));
+               }
+
+               
                function grant_role($transition,$object=null,$account_id=null)
                {
                        if ( ! is_null($object))
@@ -580,6 +625,22 @@
                        return ($result);
                }
 
+               function list_transitions_notification($transition)
+               {
+                       $sql="SELECT transition FROM phpgw_flows_transitions 
WHERE from_status = (SELECT to_status FROM phpgw_flows_transitions WHERE 
transition ='".$transition."')";
+
+                       $this->db->query($sql, __LINE__, __FILE__);
+                       
+                       $transitions=array();
+                       $cpt=0;
+                       while ($this->db->next_record())
+                       {
+                               $transitions[$cpt++]= 
$this->db->f('transition');
+                       }
+
+                       return($transitions);   
+               }
+
        }
 
 ?>
\ No newline at end of file

Modified: modules/ged/trunk/inc/hook_preferences.inc.php
===================================================================
--- modules/ged/trunk/inc/hook_preferences.inc.php      2010-01-04 15:50:20 UTC 
(rev 20903)
+++ modules/ged/trunk/inc/hook_preferences.inc.php      2010-01-04 15:58:18 UTC 
(rev 20904)
@@ -31,6 +31,7 @@
                $file=Array
                (
                        
'Preferences'=>$GLOBALS['phpgw']->link('/preferences/preferences.php',array('appname'=>$appname)),
+                       'Mailing service' => 
$GLOBALS['phpgw']->link('/index.php', array('menuaction' => 
'ged.ged_pref.mailing', 'appname' => 'ged') ),
                );
 
 //Do not modify below this line


Property changes on: modules/ged/trunk/templates/base/import_project.tpl
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: modules/ged/trunk/templates/base/mailing.tpl
===================================================================
--- modules/ged/trunk/templates/base/mailing.tpl                                
(rev 0)
+++ modules/ged/trunk/templates/base/mailing.tpl        2010-01-04 15:58:18 UTC 
(rev 20904)
@@ -0,0 +1,42 @@
+<div align=center >
+<H1>{rejected list}</H1>
+<table>
+<tr><td height = 100>
+{msg1}
+<BR/>
+</td></tr><tr><td height = 100>
+{msg2}
+<BR/>
+</td></tr>
+</table>
+<form enctype="multipart/form-data" action="" method="post">
+<table id="ged_mailing_pref" cellspacing="0" cellpadding"0">
+<!-- BEGIN rejects_block -->
+  <tr>
+<td>{reject_name}</td><td style="width: 16px;"><input type="image" 
src="{remove-image}" name="rm_reject[{reject_id}]" ></td>
+       </tr>
+<!-- END rejects_block -->
+
+<tr><td>
+<table>
+<tr>
+       <td>
+               <SELECT name="project_choice">Project
+<!-- BEGIN projects_block -->
+  <OPTION value="{project_id}">{project_name}</OPTION>
+<!-- END projects_block -->
+ </td>
+ <td>
+       <SELECT name="action_choice">Action
+ <!-- BEGIN actions_block -->
+  <OPTION value="{action_id}">{action_name}</OPTION>
+<!-- END actions_block -->
+       </td>
+</tr>
+</table>
+</td>
+<td style="width: 16px;"><input type="image" src="{add-image}"></td>
+</tr>
+</table>
+</form>
+</div>
\ No newline at end of file


Property changes on: modules/ged/trunk/templates/base/mailing.tpl
___________________________________________________________________
Added: svn:mime-type
   + text/plain





reply via email to

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