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