source: sandbox/workflow/branches/609/inc/class.ui_userinterface.inc.php @ 2223

Revision 2223, 6.9 KB checked in by pedroerp, 14 years ago (diff)

Ticket #609 - Iniciando a migração do workflow para a nova factory.

  • 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                $smarty = Factory::getInstance('workflow_smarty');
49
50                // Check if workflow config is ok
51                if (count($errors = $this->_checkWorkflowConfig()))
52                {
53                        $smarty->assign('header', $smarty->expressoHeader);
54                        $smarty->assign('footer', $smarty->expressoFooter);
55                        $smarty->assign('errors', $errors);
56                        $smarty->display('notworking.tpl');
57                        return false;
58                }
59
60                $this->set_wf_session();
61
62                if (is_null($tabIndex))
63                        $tabIndex = 1;
64
65                $javaScripts = $this->get_common_js();
66                $javaScripts .= $this->get_js_link('workflow','scriptaculous', 'prototype');
67                $javaScripts .= $this->get_js_link('workflow','userinterface', 'main');
68                $javaScripts .= $this->get_js_link('workflow','jscode', 'tigra_menu');
69                $javaScripts .= $this->get_js_link('workflow','userinterface', 'common_functions');
70                $javaScripts .= $this->get_js_link('workflow','userinterface', 'inbox');
71                $javaScripts .= $this->get_js_link('workflow','userinterface', 'inbox_group');
72                $javaScripts .= $this->get_js_link('workflow','userinterface', 'inbox_actions');
73                $javaScripts .= $this->get_js_link('workflow','userinterface', 'processes');
74                $javaScripts .= $this->get_js_link('workflow','userinterface', 'instances');
75                $javaScripts .= $this->get_js_link('workflow','userinterface', 'instances_group');
76                $javaScripts .= $this->get_js_link('workflow','userinterface', 'externals');
77                $javaScripts .= $this->get_js_link('workflow','userinterface', 'orgchart');
78                $javaScripts .= $this->get_js_link('workflow','scriptaculous', 'scriptaculous', 'load=effects');
79                $javaScripts .= $this->get_js_link('workflow','experience', 'experience');
80                $javaScripts .= $this->get_js_link('workflow','experience', 'experience.panorama');
81
82                $css = $this->get_common_css();
83                $css .= $this->get_css_link('userinterface');
84                $css .= $this->get_css_link('orgchart');
85                $css .= $this->get_css_link('experience.panorama');
86
87                $tabs = array(
88                        'Tarefas Pendentes',
89                        'Processos',
90                        'Acompanhamento',
91                        'Aplicações Externas',
92                        'Organograma'
93                );
94
95                $smarty->assign('header', $smarty->expressoHeader);
96                $smarty->assign('footer', $smarty->expressoFooter);
97                $smarty->assign('txt_loading', lang("loading"));
98                $smarty->assign('javaScripts', $javaScripts);
99                $smarty->assign('css', $css);
100                $smarty->assign('tabs', $tabs);
101                $smarty->assign('startTab', $tabIndex);
102
103                $smarty->display('userinterface.tpl');
104        }
105
106        /**
107         * Check if workflow config is ok
108         * @param void
109         * @access private
110         * @return array Errors that were found
111         */
112        private function _checkWorkflowConfig()
113        {
114                $errors = array();
115
116                // Get a connection to db workflow and galaxia (module)
117                if ($GLOBALS['workflow']['workflowObjects']->getDBWorkflow()->Error)
118                        $errors[] = 'Unable to connect to database Workflow';
119
120                if ($errormsg = $GLOBALS['workflow']['workflowObjects']->getDBGalaxia()->Error)
121                        $errors[] = 'Unable to connect to database Galaxia';
122
123                return $errors;
124        }
125
126        function printArea()
127        {
128                /* set some session variables */
129                $this->set_wf_session();
130
131                /* create some objects */
132                require_once 'class.so_userinterface.inc.php';
133                $so = new so_userinterface();
134                $smarty = CreateObject('workflow.workflow_smarty');
135
136                /* get the user's organization */
137                $organizationInfo = $so->getUserOrganization($_SESSION['phpgw_info']['workflow']['account_id']);
138                if ($organizationInfo === false)
139                        return false;
140
141                $organizationID = $organizationInfo['organizacao_id'];
142                $areaID = (int) $_REQUEST['areaID'];
143
144                /* load the entire orgchart */
145                $areaStack = $so->getHierarchicalArea($organizationID, null, 0);
146
147                /* if requested, load only one area */
148                if ($areaID !== 0)
149                {
150                        $selectedArea = null;
151                        while (($currentArea = array_pop($areaStack)) !== null)
152                        {
153                                if ($currentArea['area_id'] == $areaID)
154                                {
155                                        $selectedArea = $currentArea;
156                                        break;
157                                }
158
159                                foreach ($currentArea['children'] as &$child)
160                                        $areaStack[] = $child;
161                        }
162
163                        if (is_null($selectedArea))
164                                return false;
165
166                        $areaStack = array(&$selectedArea);
167                }
168                else
169                {
170                        $areaStack = array_reverse($areaStack);
171                        $smarty->assign('organizationName', $organizationInfo['descricao']);
172                }
173
174                /* make the array flat (for a simpler handling) */
175                $flatAreas = array();
176                while (count($areaStack) > 0)
177                {
178                        $currentArea = &$areaStack[count($areaStack) - 1];
179                        unset($areaStack[count($areaStack) - 1]);
180
181                        $currentArea['children'] = array_reverse($currentArea['children']);
182                        foreach ($currentArea['children'] as &$item)
183                        {
184                                $item['orgchartPath'] = $currentArea['orgchartPath'] . $currentArea['sigla'] . ' &rarr; ';
185                                $areaStack[count($areaStack)] = &$item;
186                        }
187                        unset($currentArea['children']);
188
189                        $employees = $so->getAreaEmployees($currentArea['area_id'], $organizationID);
190                        if (is_array($employees))
191                                $currentArea['employees'] = $employees['employees'];
192                        else
193                                $currentArea['employees'] = array();
194                        $flatAreas[] = $currentArea;
195                }
196
197                /* get the CSS and JS links */
198                $javaScripts = $this->get_js_link('workflow', 'jquery', 'jquery-1.2.6');
199                $javaScripts .= $this->get_js_link('workflow', 'userinterface', 'orgchartPrint');
200
201                $css = $this->get_css_link('orgchartPrint', 'print');
202                $css .= $this->get_css_link('orgchartPrintPreview');
203
204                /* pass variables to smarty */
205                $smarty->assign('areasJson', json_encode($flatAreas));
206                $smarty->assign('javaScripts', $javaScripts);
207                $smarty->assign('css', $css);
208
209                /* render the page */
210                $smarty->display('orgchartPrint.tpl');
211        }
212}
213?>
Note: See TracBrowser for help on using the repository browser.