source: branches/1.2/workflow/inc/class.ui_agent_mail_smtp.inc.php @ 1349

Revision 1349, 8.7 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

  • Property svn:executable set to *
Line 
1<?php
2        /**************************************************************************\
3* eGroupWare Workflow - Mail SMTP Agent Connector - interface layer        *
4* ------------------------------------------------------------------------ *
5* This program is free software; you can redistribute it and/or modify it  *
6* under the terms of the GNU General Public License as published           *
7* by the Free Software Foundation; either version 2 of the License, or     *
8* any later version.                                                       *
9\**************************************************************************/
10
11require_once(dirname(__FILE__) . SEP . 'class.ui_agent.inc.php');
12/**
13 * Mail-SMTP Agent : interface layer.
14 * This class connects the workflow agents calls to the mail_smtp agent business layer
15 *
16 * @package Workflow
17 * @license http://www.gnu.org/copyleft/gpl.html GPL
18 * @author regis.leroy@glconseil.com
19 */             
20class ui_agent_mail_smtp extends ui_agent
21{
22        /**
23         * Constructor
24         * @access public
25         * @return object
26         */     
27        function ui_agent_mail_smtp()
28        {
29                parent::ui_agent();
30                $this->agent_type = 'mail_smtp';
31                $this->bo_agent = CreateObject('workflow.bo_agent_mail_smtp');
32        }
33
34        /**
35         * Show Admin Activity Options
36         * @param string $template_block_name
37         * @access public
38         * @return void 
39         */
40        function showAdminActivityOptions ($template_block_name)
41        {
42                $admin_name = 'admin_agent_'.$this->agent_type;
43                $this->t->set_file($admin_name, $admin_name . '.tpl');
44                $this->t->set_block($admin_name, 'block_ag_config_option_input', 'ag_option_input');
45                $this->t->set_block($admin_name, 'block_ag_config_option_textarea', 'ag_option_textarea');
46                $this->t->set_block($admin_name, 'block_ag_config_option_select_option', 'ag_option_select_option');
47                $this->t->set_block($admin_name, 'block_ag_config_option_select', 'ag_option_select');
48                $options =& $this->bo_agent->getAdminActivityOptions();
49                foreach ($options as $option_name => $option_conf)
50                {
51                        if ($option_conf['type'] == 'text')
52                        {
53                                $size = $option_conf['size'];
54                                if ( (!($size)) || ($size > 80)) $size = 80;
55                                $this->t->set_var(array(
56                                        'ag_config_name_i'      => "wf_agent[".$this->agent_type."][".$option_name."]",
57                                        'ag_config_label_i'     => $option_conf['label'],
58                                        'ag_config_value_i'     => $option_conf['value'],
59                                        'ag_config_size_i'      => 'size="'.$size.'"',
60                                ));
61                                $this->t->parse('ag_option_input','block_ag_config_option_input',true);
62                        }
63                        if ($option_conf['type'] == 'textarea')
64                        {
65                                $this->t->set_var(array(
66                                        'ag_config_name_t'      => "wf_agent[".$this->agent_type."][".$option_name."]",
67                                        'ag_config_label_t'     => $option_conf['label'],
68                                        'ag_config_value_t'     => $option_conf['value'],
69                                ));
70                                $this->t->parse('ag_option_textarea','block_ag_config_option_textarea',true);
71                        }
72                        if ($option_conf['type'] == 'select')
73                        {       
74                                $this->t->set_var(array(
75                                        'ag_config_name_s'      => "wf_agent[".$this->agent_type."][".$option_name."]",
76                                        'ag_config_label_s'     => $option_conf['label'],
77                                ));
78                                foreach($option_conf['values'] as $key => $value)
79                                {
80                                        $this->t->set_var(array(
81                                                'ag_config_value_s_key'         => $key,
82                                                'ag_config_value_s_value'       => $value,
83                                                'ag_config_value_s_selected'    => ($option_conf['value']==$key)? 'selected': '',
84                                        ));
85                                        $this->t->parse('ag_option_select_option','block_ag_config_option_select_option',true);
86                                }
87                                $this->t->parse('ag_option_select','block_ag_config_option_select',true);
88                        }
89                }
90                //show the shared part handled by parent object
91                parent::showAdminActivityOptions('shared_part');
92                $this->translate_template($admin_name);
93                $this->t->parse($template_block_name, $admin_name);
94        }
95       
96        /**
97         * Function called by the running object (run_activity) after the activity_pre code
98         * and before the user code. This code is runned only if the $GLOBALS['workflow']['__leave_activity']
99         * IS NOT set (i.e.: the user is not cancelling his form in case of interactive activity)
100         * WARNING : on interactive queries the user code is parsed several times and this function is called
101         * each time you reach the begining of the code, this means at least the first time when you show the form
102         * and every time you loop on the form + the last time when you complete the code (if the user did not cancel).
103         * @return bool true or false, if false the $this->error array should contains error messages
104         * @access public
105         */
106        function run_activity_pre()
107        {
108                //load agent data from database
109                $this->bo_agent->init();
110               
111                //this will send an email only if the configuration says to do so
112                if (!($this->bo_agent->send_start()))
113                {
114                        $this->error[] = lang('Smtp Agent has detected some errors when sending email at the beginning of the activity');
115                        $ok = false;
116                }
117                else
118                {
119                        $ok = true;
120                }
121                $this->error[] = $this->bo_agent->get_error();
122                if ($this->bo_agent->debugmode) echo '<br />START: Mail agent in DEBUG mode:'.implode('<br />',$this->error);
123                return $ok;
124        }
125       
126        /**
127         * Function called by the running object (run_activity) after the activity_pre code
128         * and before the user code. This code is runned only if the $GLOBALS['workflow']['__leave_activity']
129         * IS set (i.e.: the user is cancelling his form in case of interactive activity)
130         * @return bool true or false, if false the $this->error array should contains error messages
131         * @access public
132         */
133        function run_leaving_activity_pre()
134        {
135                //actually we never send emails when cancelling
136                return true;
137        }
138       
139        /**
140         * Function called by the running object (run_activity) after the user code
141         * and after the activity_pos code. This code is runned only if the $GLOBALS['__activity_completed']
142         * IS set (i.e.: the user has completing the activity)
143         * @return bool true or false, if false the $this->error array should contains error messages
144         * @access public
145         */
146        function run_activity_completed_pos()
147        {
148                //this will send an email only if the configuration says to do so
149                if (!($this->bo_agent->send_completed()))
150                {
151                        $this->error[] = lang('Smtp Agent has detected some errors when sending email after completion of the activity');
152                        $ok = false;
153                }
154                else
155                {
156                        $ok = true;
157                }
158                $this->error[] = $this->bo_agent->get_error();
159                if ($this->bo_agent->debugmode) echo '<br />COMPLETED: Mail agent in DEBUG mode:'.implode('<br />',$this->error);
160                return $ok;
161        }
162       
163        /**
164         * Function called by the running object (run_activity) after the user code
165         * and after the activity_pos code. This code is runned only if the $GLOBALS['__activity_completed']
166         * IS NOT set (i.e.: the user is not yet completing the activity)
167         * WARNING : on interactive queries the user code is parsed several times and this function is called
168         * each time you reach the end of the code without completing, this means at least the first time
169         * and every time you loop on the form.
170         * This function can call two types of mail sending
171         * * sending email on POST queries (usefull for interactive forms), retrieving POSTed values
172         * * sending email at each reach of the end of the code (usefull for automatic activities which
173         * completes only after execution of user code (sending after completion is not possible). And we
174         * musn't retrieve POSTed values in this case because it can concerns previous non-automatic activities
175         * @return bool true or false, if false the $this->error array should contains error messages
176         * @access public
177         */
178        function run_activity_pos()
179        {
180                if ($this->bo_agent->sendOnPosted())
181                {//First case, POSTed emails, we will try to see if there are some POSTed infos
182                        //form settings POSTED with wf_agent_mail_smtp['xxx'] values
183                        $this->retrieve_form_settings();
184                        if (!(isset($this->agent_values['submit_send'])))
185                        {
186                                return true;
187                        }
188                        else
189                        {
190                                //erase agent data with the POSTed values
191                                $this->bo_agent->set($this->agent_values);
192                               
193                                //this will send an email only if the configuration says to do so
194                                if (!($this->bo_agent->send_post()))
195                                {
196                                        $this->error[] = lang('Smtp Agent has detected some errors when sending email on demand whith this activity');
197                                        $ok = false;
198                                }
199                                else
200                                {
201                                        $ok = true;
202                                }
203                                $this->error[] = $this->bo_agent->get_error();
204                                if ($this->bo_agent->debugmode) echo '<br />POST: Mail agent in DEBUG mode:'.implode('<br />',$this->error);
205                                return $ok;
206                        }
207                }
208                else
209                {//Second case , not about POSTed values, the bo_agent will see himself he he need
210                // to do something on end of the user code
211                        //this will send an email only if the configuration says to do so
212                        if (!($this->bo_agent->send_end()))
213                        {
214                                $this->error[] = lang('Smtp Agent has detected some errors when sending email at the end of this activity');
215                                $ok = false;
216                        }
217                        else
218                        {
219                                $ok = true;
220                        }
221                        $this->error[] = $this->bo_agent->get_error();
222                        if ($this->bo_agent->debugmode) echo '<br />END: Mail agent in DEBUG mode:'.implode('<br />',$this->error);
223                                return $ok;
224                        }
225                }
226               
227        }
228?>
Note: See TracBrowser for help on using the repository browser.