source: trunk/workflow/inc/class.ui_userinterface.inc.php @ 1227

Revision 1227, 6.8 KB checked in by viani, 15 years ago (diff)

Ticket #593 - Verificação de ambiente na entrada do workflow.

  • Property svn:executable set to *
Line 
1<?php
2/**************************************************************************\
3* eGroupWare                                                               *
4* http://www.egroupware.org                                                *
5* --------------------------------------------                             *
6*  This program is free software; you can redistribute it and/or modify it *
7*  under the terms of the GNU General Public License as published by the   *
8*  Free Software Foundation; either version 2 of the License, or (at your  *
9*  option) any later version.                                              *
10\**************************************************************************/
11
12require_once(dirname(__FILE__) . SEP . 'class.ui_ajaxinterface.inc.php');
13/**
14 * @package Workflow
15 * @license http://www.gnu.org/copyleft/gpl.html GPL
16 * @author Mauricio Luiz Viani - viani@celepar.pr.gov.br
17 * @author Sidnei Augusto Drovetto Jr. - drovetto@gmail.com
18 */
19class ui_userinterface extends ui_ajaxinterface
20{
21        /**
22         * @var array public_functions
23         * @access public
24         */
25        var $public_functions = array(
26                'draw'  => true,
27                'printArea' => true
28        );
29
30        /**
31         * Constructor
32         * @access public
33         * @return object
34         */
35        function ui_userinterface() {
36
37        }
38
39        /**
40         * Draw the user interface
41         * @param int $tabIndex
42         */
43        function draw($tabIndex = null)
44        {
45                $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['workflow']['title'];
46                $GLOBALS['phpgw_info']['flags'] = array('noheader' => false, 'nonavbar' => false, 'currentapp' => 'workflow');
47                $smarty = CreateObject('workflow.workflow_smarty');
48
49                // Check if workflow config is ok
50                if (count($errors = $this->_checkWorkflowConfig()))
51                {
52                        $smarty->assign('header', $smarty->expressoHeader);
53                        $smarty->assign('footer', $smarty->expressoFooter);
54                        $smarty->assign('errors', $errors);
55                        $smarty->display('notworking.tpl');
56                        return false;
57                }
58
59                $this->set_wf_session();
60
61                if (is_null($tabIndex))
62                        $tabIndex = 1;
63
64                $javaScripts = $this->get_common_js();
65                $javaScripts .= $this->get_js_link('workflow','scriptaculous', 'prototype');
66                $javaScripts .= $this->get_js_link('workflow','userinterface', 'main');
67                $javaScripts .= $this->get_js_link('workflow','jscode', 'tigra_menu');
68                $javaScripts .= $this->get_js_link('workflow','userinterface', 'common_functions');
69                $javaScripts .= $this->get_js_link('workflow','userinterface', 'inbox');
70                $javaScripts .= $this->get_js_link('workflow','userinterface', 'inbox_group');
71                $javaScripts .= $this->get_js_link('workflow','userinterface', 'inbox_actions');
72                $javaScripts .= $this->get_js_link('workflow','userinterface', 'processes');
73                $javaScripts .= $this->get_js_link('workflow','userinterface', 'instances');
74                $javaScripts .= $this->get_js_link('workflow','userinterface', 'instances_group');
75                $javaScripts .= $this->get_js_link('workflow','userinterface', 'externals');
76                $javaScripts .= $this->get_js_link('workflow','userinterface', 'orgchart');
77                $javaScripts .= $this->get_js_link('workflow','scriptaculous', 'scriptaculous', 'load=effects');
78                $javaScripts .= $this->get_js_link('workflow','experience', 'experience');
79                $javaScripts .= $this->get_js_link('workflow','experience', 'experience.panorama');
80
81                $css = $this->get_common_css();
82                $css .= $this->get_css_link('userinterface');
83                $css .= $this->get_css_link('orgchart');
84                $css .= $this->get_css_link('experience.panorama');
85
86                $tabs = array(
87                        'Tarefas Pendentes',
88                        'Processos',
89                        'Acompanhamento',
90                        'Aplicações Externas',
91                        'Organograma'
92                );
93
94                $smarty->assign('header', $smarty->expressoHeader);
95                $smarty->assign('footer', $smarty->expressoFooter);
96                $smarty->assign('txt_loading', lang("loading"));
97                $smarty->assign('javaScripts', $javaScripts);
98                $smarty->assign('css', $css);
99                $smarty->assign('tabs', $tabs);
100                $smarty->assign('startTab', $tabIndex);
101
102                $smarty->display('userinterface.tpl');
103        }
104
105        /**
106         * Check if workflow config is ok
107         * @param void
108         * @access private
109         * @return array Errors that were found
110         */
111        private function _checkWorkflowConfig()
112        {
113                $errors = array();
114
115                // Get a connection to db workflow and galaxia (module)
116                if ($GLOBALS['workflow']['workflowObjects']->getDBWorkflow()->Error)
117                        $errors[] = 'Unable to connect to database Workflow';
118
119                if ($errormsg = $GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Error)
120                        $errors[] = 'Unable to connect to database Galaxia';
121
122                return $errors;
123        }
124
125        function printArea()
126        {
127                /* set some session variables */
128                $this->set_wf_session();
129
130                /* create some objects */
131                require_once 'class.so_userinterface.inc.php';
132                $so = new so_userinterface();
133                $smarty = CreateObject('workflow.workflow_smarty');
134
135                /* get the user's organization */
136                $organizationInfo = $so->getUserOrganization($_SESSION['phpgw_info']['workflow']['account_id']);
137                if ($organizationInfo === false)
138                        return false;
139
140                $organizationID = $organizationInfo['organizacao_id'];
141                $areaID = (int) $_REQUEST['areaID'];
142
143                /* load the entire orgchart */
144                $areaStack = $so->getHierarchicalArea($organizationID, null, 0);
145
146                /* if requested, load only one area */
147                if ($areaID !== 0)
148                {
149                        $selectedArea = null;
150                        while (($currentArea = array_pop($areaStack)) !== null)
151                        {
152                                if ($currentArea['area_id'] == $areaID)
153                                {
154                                        $selectedArea = $currentArea;
155                                        break;
156                                }
157
158                                foreach ($currentArea['children'] as &$child)
159                                        $areaStack[] = $child;
160                        }
161
162                        if (is_null($selectedArea))
163                                return false;
164
165                        $areaStack = array(&$selectedArea);
166                }
167                else
168                {
169                        $areaStack = array_reverse($areaStack);
170                        $smarty->assign('organizationName', $organizationInfo['descricao']);
171                }
172
173                /* make the array flat (for a simpler handling) */
174                $flatAreas = array();
175                while (count($areaStack) > 0)
176                {
177                        $currentArea = &$areaStack[count($areaStack) - 1];
178                        unset($areaStack[count($areaStack) - 1]);
179
180                        $currentArea['children'] = array_reverse($currentArea['children']);
181                        foreach ($currentArea['children'] as &$item)
182                        {
183                                $item['orgchartPath'] = $currentArea['orgchartPath'] . $currentArea['sigla'] . ' &rarr; ';
184                                $areaStack[count($areaStack)] = &$item;
185                        }
186                        unset($currentArea['children']);
187
188                        $employees = $so->getAreaEmployees($currentArea['area_id'], $organizationID);
189                        if (is_array($employees))
190                                $currentArea['employees'] = $employees['employees'];
191                        else
192                                $currentArea['employees'] = array();
193                        $flatAreas[] = $currentArea;
194                }
195
196                /* get the CSS and JS links */
197                $javaScripts = $this->get_js_link('workflow', 'jquery', 'jquery-1.2.6');
198                $javaScripts .= $this->get_js_link('workflow', 'userinterface', 'orgchartPrint');
199
200                $css = $this->get_css_link('orgchartPrint', 'print');
201                $css .= $this->get_css_link('orgchartPrintPreview');
202
203                /* pass variables to smarty */
204                $smarty->assign('areasInfo', $flatAreas);
205                $smarty->assign('javaScripts', $javaScripts);
206                $smarty->assign('css', $css);
207
208                /* render the page */
209                $smarty->display('orgchartPrint.tpl');
210        }
211}
212?>
Note: See TracBrowser for help on using the repository browser.