[1349] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare Workflow - Agents 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 | |
---|
| 11 | |
---|
| 12 | /** |
---|
| 13 | * Agents abstraction library. interface layer. |
---|
| 14 | * This allows the Workflow Engine to connect to various agents |
---|
| 15 | * Agents are external elements for the workflow. It could be |
---|
| 16 | * email systems, filesystems, calendars, what you want. |
---|
| 17 | * Use this class to make childrens like, for example in the |
---|
| 18 | * class.ui_agent_mail_smtp.inc.php for the mail_smtp susbsytem |
---|
| 19 | * |
---|
| 20 | * @package Workflow |
---|
| 21 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 22 | * @author regis.leroy@glconseil.com |
---|
| 23 | */ |
---|
| 24 | require_once(dirname(__FILE__) . SEP . 'class.WorkflowUtils.inc.php'); |
---|
| 25 | |
---|
| 26 | class ui_agent extends WorkflowUtils |
---|
| 27 | { |
---|
| 28 | /** |
---|
| 29 | * @var array $error Local error storage |
---|
| 30 | * @access public |
---|
| 31 | */ |
---|
| 32 | var $error=Array(); |
---|
| 33 | /** |
---|
| 34 | * @var array $agent_values store the POST or GET content concerning the agent |
---|
| 35 | * @access public |
---|
| 36 | */ |
---|
| 37 | var $agent_values = Array(); |
---|
| 38 | /** |
---|
| 39 | * @var bool $interactivity for runtime mode |
---|
| 40 | * @access public |
---|
| 41 | */ |
---|
| 42 | var $interactivity = false; |
---|
| 43 | |
---|
| 44 | // concerning Child classes constructors --------------------------------------------- |
---|
| 45 | /** |
---|
| 46 | * @var object bo_agent object which have to be set in your child class to the right bo_agent child |
---|
| 47 | * @access public |
---|
| 48 | */ |
---|
| 49 | var $bo_agent = null; |
---|
| 50 | /** |
---|
| 51 | * @var string $agent_type The type of the agent, on agent of this type for one activity, no more |
---|
| 52 | * @access public |
---|
| 53 | */ |
---|
| 54 | var $agent_type = ''; |
---|
| 55 | // ----------------------------------------------------------------------------------- |
---|
| 56 | |
---|
| 57 | /** |
---|
| 58 | * Constructor |
---|
| 59 | * @access public |
---|
| 60 | * @return object |
---|
| 61 | */ |
---|
| 62 | function ui_agent() |
---|
| 63 | { |
---|
| 64 | parent::WorkflowUtils(); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | /** |
---|
| 68 | * Function which must be called (internally) at runtime .The agent MUST know if he is runned in an interactive activity or not. |
---|
| 69 | * For example on non-interactive activities the agents musn't scan the POST content |
---|
| 70 | * @param bool $bool true interactive false non-interactive |
---|
| 71 | * @return void |
---|
| 72 | * @access public |
---|
| 73 | */ |
---|
| 74 | function setInteractivity($bool) |
---|
| 75 | { |
---|
| 76 | $this->interactivity = $bool; |
---|
| 77 | } |
---|
| 78 | /** |
---|
| 79 | * Return errors recorded by this object |
---|
| 80 | * You should always call this function after failed operations on a workflow object to obtain messages |
---|
| 81 | * @param array $as_array if true the result will be send as an array of errors or an empty array. Else, if you do not give any parameter |
---|
| 82 | * or give a false parameter you will obtain a single string which can be empty or will contain error messages with <br /> html tags. |
---|
| 83 | * @access public |
---|
| 84 | * @return array errors |
---|
| 85 | */ |
---|
| 86 | function get_error($as_array=false) |
---|
| 87 | { |
---|
| 88 | $this->error[] = $this->bo_agent->get_error(); |
---|
| 89 | if ($as_array) |
---|
| 90 | { |
---|
| 91 | return $this->error; |
---|
| 92 | } |
---|
| 93 | $result_str = implode('<br />',$this->error); |
---|
| 94 | $this->error= Array(); |
---|
| 95 | return $result_str; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | /** |
---|
| 99 | * Factory: load the agent values stored somewhere via the agent bo object |
---|
| 100 | * @param int $agent_id is the agent id |
---|
| 101 | * @return bool false if the agent cannot be loaded, true else |
---|
| 102 | * @access public |
---|
| 103 | */ |
---|
| 104 | function load($agent_id) |
---|
| 105 | { |
---|
| 106 | return ( (isset($this->bo_agent)) && ($this->bo_agent->load($agent_id))); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | /** |
---|
| 110 | * Save the agent values somewhere via the agent bo object |
---|
| 111 | * @param array $datas is an array containing comlumns => value pairs |
---|
| 112 | * @return bool false if the agent was not previously loaded or if the save fail, true else |
---|
| 113 | * @access public |
---|
| 114 | */ |
---|
| 115 | function save(&$datas) |
---|
| 116 | { |
---|
| 117 | if (!(isset($this->bo_agent))) |
---|
| 118 | { |
---|
| 119 | return false; |
---|
| 120 | } |
---|
| 121 | else |
---|
| 122 | { |
---|
| 123 | $ok = $this->bo_agent->set($datas); |
---|
| 124 | if ($ok) $ok = $this->bo_agent->save(); |
---|
| 125 | return $ok; |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | /** |
---|
| 130 | * Function called at runtime to permit associtaion with the instance and the activity |
---|
| 131 | * we store references to theses objects and we tell the ui object if we are in interactive |
---|
| 132 | * mode or not. |
---|
| 133 | * @param array $instance |
---|
| 134 | * @param object $activity activity |
---|
| 135 | * @return void |
---|
| 136 | * @access public |
---|
| 137 | */ |
---|
| 138 | function runtime(&$instance, &$activity) |
---|
| 139 | { |
---|
| 140 | $this->bo_agent->runtime($instance,$activity); |
---|
| 141 | $this->setInteractivity($activity->isInteractive()); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | /** |
---|
| 145 | * This function show the shared part of all agents when showing configuration in the admin activity form |
---|
| 146 | * do not forget to call parent::showAdminActivityOptions ($template_block_name) in the child if you want to display this shared part |
---|
| 147 | * @param string $template_block_name |
---|
| 148 | * @return void |
---|
| 149 | * @access public |
---|
| 150 | */ |
---|
| 151 | function showAdminActivityOptions ($template_block_name) |
---|
| 152 | { |
---|
| 153 | $admin_name = 'admin_agent_shared'; |
---|
| 154 | $this->t->set_file($admin_name, $admin_name . '.tpl'); |
---|
| 155 | $this->t->set_var(array( |
---|
| 156 | 'agent_description' => $this->bo_agent->getDescription(), |
---|
| 157 | 'agent_title' => $this->bo_agent->getTitle(), |
---|
| 158 | 'agent_help' => $this->bo_agent->getHelp(), |
---|
| 159 | )); |
---|
| 160 | $this->translate_template($admin_name); |
---|
| 161 | $this->t->parse($template_block_name, $admin_name); |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | /** |
---|
| 165 | * Function called by the running object (run_activity) after the activity_pre code |
---|
| 166 | * |
---|
| 167 | * and before the user code. This code is runned only if the $GLOBALS['workflow']['__leave_activity'] |
---|
| 168 | * IS NOT set (i.e.: the user is not cancelling his form in case of interactive activity) |
---|
| 169 | * WARNING : on interactive queries the user code is parsed several times and this function is called |
---|
| 170 | * each time you reach the begining of the code, this means at least the first time when you show the form |
---|
| 171 | * and every time you loop on the form + the last time when you complete the code (if the user did not cancel). |
---|
| 172 | * @return bool true or false, if false the $this->error array should contains error messages |
---|
| 173 | * @access public |
---|
| 174 | */ |
---|
| 175 | function run_activity_pre() |
---|
| 176 | { |
---|
| 177 | return true; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | /** |
---|
| 181 | * Function called by the running object (run_activity) after the activity_pre code |
---|
| 182 | * |
---|
| 183 | * and before the user code. This code is runned only if the $GLOBALS['workflow']['__leave_activity'] |
---|
| 184 | * IS set (i.e.: the user is cancelling his form in case of interactive activity) |
---|
| 185 | * @return bool true or false, if false the $this->error array should contains error messages |
---|
| 186 | * @access public |
---|
| 187 | */ |
---|
| 188 | function run_leaving_activity_pre() |
---|
| 189 | { |
---|
| 190 | return true; |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | /** |
---|
| 194 | * Function called by the running object (run_activity) after the user code |
---|
| 195 | * |
---|
| 196 | * and after the activity_pos code. This code is runned only if the $GLOBALS['__activity_completed'] |
---|
| 197 | * IS NOT set (i.e.: the user is not yet completing the activity) |
---|
| 198 | * WARNING : on automatic (non-interactive) activities this code is NEVER called. Non-interactive |
---|
| 199 | * activities are completed after the end of the user code and there is no way to re-parse this |
---|
| 200 | * user code after completion. |
---|
| 201 | * @return bool true or false, if false the $this->error array should contains error messages |
---|
| 202 | * @access public |
---|
| 203 | */ |
---|
| 204 | function run_activity_completed_pos() |
---|
| 205 | { |
---|
| 206 | return true; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | /** |
---|
| 210 | * Function called by the running object (run_activity) after the user code |
---|
| 211 | * |
---|
| 212 | * and after the activity_pos code. This code is runned only if the $GLOBALS['__activity_completed'] |
---|
| 213 | * IS set (i.e.: the user has completing the activity) |
---|
| 214 | * WARNING : on interactive queries the user code is parsed several times and this function is called |
---|
| 215 | * each time you reach the end of the code without completing, this means at least the first time |
---|
| 216 | * and every time you loop on the form. |
---|
| 217 | * @return bool true or false, if false the $this->error array should contains error messages |
---|
| 218 | * @access public |
---|
| 219 | */ |
---|
| 220 | function run_activity_pos() |
---|
| 221 | { |
---|
| 222 | return true; |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | /** |
---|
| 226 | * Retrieve infos set by the user in interactive forms ans store it with the bo_agent object |
---|
| 227 | * @return void |
---|
| 228 | * @access public |
---|
| 229 | */ |
---|
| 230 | function retrieve_form_settings() |
---|
| 231 | { |
---|
| 232 | if ($this->interactivity) |
---|
| 233 | { |
---|
| 234 | $res = Array(); |
---|
| 235 | $this->agent_values = get_var('wf_agent_'.$this->agent_type, array('POST','GET'),$value); |
---|
| 236 | foreach ($this->bo_agent->get(2) as $name => $value) |
---|
| 237 | { |
---|
| 238 | $res[$name] = (isset($this->agents_values[$name]))? $this->agents_values[$name] : $value; |
---|
| 239 | } |
---|
| 240 | //store theses values in the bo_object(without saving the values) |
---|
| 241 | //htmlentites will be made by the bo's set function |
---|
| 242 | $this->bo_agent->set($res); |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | } |
---|
| 247 | ?> |
---|