Ticket #1166: bo_monitors_diff

File bo_monitors_diff, 12.5 KB (added by adeildosantos, 14 years ago)
Line 
1Index: class.bo_monitors.inc.php
2===================================================================
3--- class.bo_monitors.inc.php   (revisão 795)
4+++ class.bo_monitors.inc.php   (revisão 2591)
5@@ -11,18 +11,14 @@
6 
7 require_once('class.bo_ajaxinterface.inc.php');
8 
9-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'GUI' . SEP . 'GUI.php');
10-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ProcessManager.php');
11-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ActivityManager.php');
12-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'InstanceManager.php');
13-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'RoleManager.php');
14-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessMonitor' . SEP . 'ProcessMonitor.php');
15-require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'API' . SEP . 'Instance.php');
16-require_once('class.workflow_acl.inc.php');
17-require_once('class.bo_adminaccess.inc.php');
18-require_once('class.powergraphic.inc.php');
19 
20 /**
21+ * DO NOT remove this line. Ever. Somehow, monitors interface will stop working..
22+ */
23+require_once(PHPGW_API_INC . SEP . 'common_functions.inc.php');
24+
25+
26+/**
27  * @package Workflow
28  * @license http://www.gnu.org/copyleft/gpl.html GPL
29  * @author Sidnei Augusto Drovetto Jr. - drovetto@gmail.com
30@@ -133,14 +129,14 @@
31        function bo_monitors()
32        {
33                parent::bo_ajaxinterface();
34-               $GLOBALS['ajax']->gui   = new GUI($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
35+               $GLOBALS['ajax']->gui   = &Factory::newInstance('GUI');
36                $this->userID                   = $_SESSION['phpgw_info']['workflow']['account_id'];
37                $this->isWorkflowAdmin  = $GLOBALS['ajax']->acl->checkWorkflowAdmin($this->userID);
38-               $this->processManager   = new ProcessManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
39-               $this->activityManager  = new ActivityManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
40-               $this->instanceManager  = new InstanceManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
41-               $this->roleManager              = new RoleManager($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
42-               $this->processMonitor   = new ProcessMonitor($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
43+               $this->processManager   = &Factory::newInstance('ProcessManager');
44+               $this->activityManager  = &Factory::newInstance('ActivityManager');
45+               $this->instanceManager  = &Factory::newInstance('InstanceManager');
46+               $this->roleManager              = &Factory::newInstance('RoleManager');
47+               $this->processMonitor   = &Factory::newInstance('ProcessMonitor');
48        }
49 
50        /**
51@@ -168,10 +164,9 @@
52         */
53        private function convertFiltersToSQL($filters)
54        {
55-               require_once 'nano/JSON.php';
56 
57                /* desserializa os dados */
58-               $JSON = new Services_JSON();
59+               $JSON = &Factory::newInstance('Services_JSON');
60                /* desserializa a array principal, depois desserializa cada elemento desta array e, por fim, converte os elementos (que estão em forma de objeto) para array associativa */
61                $filters = array_map('get_object_vars', array_map(array($JSON, 'decode'), $JSON->decode($filters)));
62                $sqlFilters = array();
63@@ -334,10 +329,10 @@
64                $filters[] = '(gp.wf_p_id = ' . $params['pid'] . ')';
65                $filters[] = '(gia.wf_user IS NOT NULL)';
66 
67-               $ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
68+               $ldap = &Factory::getInstance('WorkflowLDAP');
69                if (!$completeData)
70                {
71-                       $paging = $GLOBALS['workflow']['factory']->newInstance('Paging', 500, $_POST);
72+                       $paging = Factory::newInstance('Paging', 500, $_POST);
73                        $tmp = $this->processMonitor->monitor_list_instances($paging->nextItem, $paging->itemsPerPage, $order, '', implode(' AND ', $filters));
74                        $output['data'] = $paging->restrictItems(array_values($tmp['data']), $tmp['cant']);
75                        $output['instanceCount'] = $tmp['cant'];
76@@ -352,7 +347,7 @@
77                $userMapping = array('*' => '*');
78                $activityMapping = array();
79                $instanceCount = count($output['data']);
80-               $cachedLDAP = &$GLOBALS['workflow']['factory']->getInstance('CachedLDAP');
81+               $cachedLDAP = &Factory::getInstance('CachedLDAP');
82                for ($i = 0; $i < $instanceCount; $i++)
83                {
84                        /* get the user name */
85@@ -475,10 +470,10 @@
86 
87                /* load the data */
88                $filters[] = '(gp.wf_p_id = ' . $params['pid'] . ')';
89-               $ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
90+               $ldap = &Factory::getInstance('WorkflowLDAP');
91                if (!$completeData)
92                {
93-                       $paging = $GLOBALS['workflow']['factory']->newInstance('Paging', 500, $_POST);
94+                       $paging = Factory::newInstance('Paging', 500, $_POST);
95                        $tmp = $this->processMonitor->monitor_list_completed_instances($paging->nextItem, $paging->itemsPerPage, $order, '', implode(' AND ', $filters));
96                        $output['data'] = $paging->restrictItems(array_values($tmp['data']), $tmp['cant']);
97                        $output['instanceCount'] = $tmp['cant'];
98@@ -490,7 +485,7 @@
99                        $output['data'] = array_values($tmp['data']);
100                }
101 
102-               $cachedLDAP = &$GLOBALS['workflow']['factory']->getInstance('CachedLDAP');
103+               $cachedLDAP = &Factory::getInstance('CachedLDAP');
104                $userMapping = array();
105                $instanceCount = count($output['data']);
106                for ($i = 0; $i < $instanceCount; $i++)
107@@ -626,7 +621,7 @@
108                                $output['fullname'] = 'Perfil: ' . $role['wf_name'];
109                        }
110                        else
111-                               $output['fullname'] = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($user);
112+                               $output['fullname'] = Factory::getInstance('WorkflowLDAP')->getName($user);
113 
114                $this->instanceManager->set_instance_user($params['iid'], $params['aid'], $user);
115 
116@@ -647,7 +642,7 @@
117 
118                if ($params['ns'] == 'aborted')
119                {
120-                       $realInstance = new Instance($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
121+                       $realInstance = &Factory::newInstance('Instance');
122                        $realInstance->getInstance($params['iid']);
123                        if (!empty($realInstance->instanceId))
124                        {
125@@ -683,7 +678,7 @@
126                        return "Você não tem permissão para executar este procedimento!";
127 
128                /* use next user or * for the new instance */
129-               $realInstance = new Instance($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
130+               $realInstance = &Factory::newInstance('Instance');
131                $realInstance->getInstance($params['iid'], false, false);
132                $user = $realInstance->getNextUser($params['aid']);
133                $user = ($user == '') ? '*' : $user;
134@@ -750,7 +745,7 @@
135                        return "Você não tem permissão para executar este procedimento!";
136 
137                $maximumDisplaySize = 100;
138-               $instance = new Instance($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
139+               $instance = &Factory::newInstance('Instance');
140                $instance->getInstance($params['iid']);
141 
142                $output = array();
143@@ -782,7 +777,7 @@
144                if ((!$this->checkAccess($params['pid'], array($this->IP_CHANGE_PROPERTIES))) || ($instanceInfo['wf_p_id'] != $params['pid']))
145                        return "Você não tem permissão para executar este procedimento!";
146 
147-               $instance = new Instance($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
148+               $instance = &Factory::newInstance('Instance');
149                $instance->getInstance($params['iid']);
150                $output = $params;
151                $output['value'] = $instance->properties[$params['name']];
152@@ -803,7 +798,7 @@
153 
154                $maximumDisplaySize = 100;
155 
156-               $instance = new Instance($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
157+               $instance = &Factory::newInstance('Instance');
158                $instance->getInstance($params['iid']);
159                $instance->set($params['name'], $params['value']);
160                $instance->sync();
161@@ -834,7 +829,7 @@
162                if ((!$this->checkAccess($params['pid'], array($this->IP_CHANGE_PROPERTIES))) || ($instanceInfo['wf_p_id'] != $params['pid']))
163                        return "Você não tem permissão para executar este procedimento!";
164 
165-               $instance = new Instance($GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Link_ID);
166+               $instance = &Factory::newInstance('Instance');
167                $instance->getInstance($params['iid']);
168                $instance->clear($params['name']);
169                $instance->sync();
170@@ -857,7 +852,7 @@
171                /* common configuration */
172                $output = array();
173                $urlPrefix = 'workflow/inc/class.powergraphic.inc.php?';
174-               $powergraphic = new powergraphic;
175+               $powergraphic = &Factory::getInstance('powergraphic');
176                $powergraphic->graphic_1 = $params['pid'];
177                $powergraphic->skin = 1;
178                $powergraphic->credits = 0;
179@@ -903,7 +898,7 @@
180                $aux = $this->processMonitor->stats_instances_per_user($params['pid']);
181                /* prepare the data */
182                $aux2 = array();
183-               $ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
184+               $ldap = &Factory::getInstance('WorkflowLDAP');
185                foreach ($aux as $user => $count)
186                        $aux2[] = array(
187                                'user' => $ldap->getName($user) . " ({$count})",
188@@ -983,14 +978,14 @@
189                }
190 
191                /* load LDAP info and sort the result */
192-               $foundUsers = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getNames($users);
193+               $foundUsers = Factory::getInstance('WorkflowLDAP')->getNames($users);
194                usort($foundUsers, create_function('$a,$b', 'return strcasecmp($a[\'name\'],$b[\'name\']);'));
195 
196 
197                /* special treatment for  users not found in LDAP */
198                if (count($users) > count($foundUsers))
199                {
200-                       $cachedLDAP = &$GLOBALS['workflow']['factory']->getInstance('CachedLDAP');
201+                       $cachedLDAP = &Factory::getInstance('CachedLDAP');
202                        $foundUsersID = array_map(create_function('$a', 'return $a[\'id\'];'), $foundUsers);
203                        $missingUsers = array_diff($users, $foundUsersID);
204                        foreach ($missingUsers as $missingUser)
205@@ -1241,7 +1236,7 @@
206                if (count($list) === 0)
207                        return $output;
208 
209-               $BOUserInterface = &$GLOBALS['workflow']['factory']->getInstance('bo_userinterface');
210+               $BOUserInterface = &Factory::getInstance('bo_userinterface');
211 
212                /* initialize some variables */
213                $translationArray = array();
214@@ -1343,7 +1338,7 @@
215                }
216 
217                /* load the recipient e-mail */
218-               $ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
219+               $ldap = &Factory::getInstance('WorkflowLDAP');
220                foreach ($output as $key => $value)
221                {
222                        $userData = $ldap->getUserInfo($value['user']);
223@@ -1395,16 +1390,26 @@
224                        return $emails;
225 
226                /* prepare the environment to load some configuration values from other module */
227-               $GLOBALS['phpgw']->db = &$GLOBALS['workflow']['workflowObjects']->getDBExpresso();
228-               $GLOBALS['phpgw']->common = CreateObject('phpgwapi.common');
229-               $GLOBALS['phpgw']->session = CreateObject('phpgwapi.sessions');
230+               $GLOBALS['phpgw']->db =& Factory::getInstance('WorkflowObjects')->getDBExpresso();
231+               $GLOBALS['phpgw']->common = Factory::getInstance('common');
232+               $GLOBALS['phpgw']->session = Factory::getInstance('sessions');
233                function lang($a){return $a;};
234 
235                /* get the required configuration */
236-               $BOEmailAdmin = $GLOBALS['workflow']['factory']->newForeignInstance('emailadmin', 'bo');
237+               $BOEmailAdmin = Factory::getInstance('bo');
238                $profileList = $BOEmailAdmin->getProfileList();
239                $profile = $BOEmailAdmin->getProfile($profileList[0]['profileID']);
240 
241+               /**
242+                * XXX - XXX
243+                * It's weird.. There are two almost identical PHPMailer classes.
244+                * The class registered in our factory is under 'EGW_INC_ROOT'.
245+                * The class used here has the same name and it's under another
246+                * directory. For now, let's just include it in the old-fashion
247+                * way, but if someone, someday try to use both classes in the
248+                * same access, it could cause us troubles.
249+                */
250+
251                /* configure the PHPMailer class to send the e-mails */
252                require_once '../expressoMail1_2/inc/class.phpmailer.php';
253                $phpMailer = new PHPMailer();
254@@ -1493,8 +1498,8 @@
255        private function getNames($userIDs, $processID)
256        {
257                $output = array();
258-               $cachedLDAP = &$GLOBALS['workflow']['factory']->getInstance('CachedLDAP');
259-               $ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
260+               $cachedLDAP = &Factory::getInstance('CachedLDAP');
261+               $ldap = &Factory::getInstance('WorkflowLDAP');
262                foreach ($userIDs as $userID)
263                {
264                        if (!isset($output[$userID]))
265@@ -1541,7 +1546,7 @@
266                $filters[] = "(gp.wf_p_id = {$processID})";
267                $filters[] = '(gia.wf_user IS NOT NULL)';
268 
269-               $cachedLDAP = &$GLOBALS['workflow']['factory']->newInstance('CachedLDAP');
270+               $cachedLDAP = &Factory::newInstance('CachedLDAP');
271                $cachedLDAP->setOperationMode($cachedLDAP->OPERATION_MODE_LDAP);
272                $output = array();
273                $instanceList = $this->processMonitor->monitor_list_instances(0, -1, 'wf_instance_id__ASC', '', implode(' AND ', $filters));
274@@ -1558,7 +1563,7 @@
275                        $userIDs[$instance['wf_user']] = true;
276                }
277 
278-               $validUsers = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getNames(array_keys($userIDs));
279+               $validUsers = Factory::getInstance('WorkflowLDAP')->getNames(array_keys($userIDs));
280                array_walk($validUsers, create_function('&$a', '$a = $a[\'id\'];'));
281 
282                foreach ($instanceList['data'] as $instance)