source: branches/2.2/workflow/inc/class.ui_userinterface.inc.php @ 3167

Revision 3167, 6.8 KB checked in by viani, 14 years ago (diff)

Ticket #1135 - Merged r1990:3166 from /trunk/workflow into /branches/2.2/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 = Factory::getInstance('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 (Factory::getInstance('WorkflowObjects')->getDBWorkflow()->Error)
117                        $errors[] = 'Unable to connect to database Workflow';
118
119                if ($errormsg = Factory::getInstance('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                $so = &Factory::getInstance('so_userinterface');
132                $smarty = &Factory::getInstance('workflow_smarty');
133
134                /* get the user's organization */
135                $organizationInfo = $so->getUserOrganization($_SESSION['phpgw_info']['workflow']['account_id']);
136                if ($organizationInfo === false)
137                        return false;
138
139                $organizationID = $organizationInfo['organizacao_id'];
140                $areaID = (int) $_REQUEST['areaID'];
141
142                /* load the entire orgchart */
143                $areaStack = $so->getHierarchicalArea($organizationID, null, 0);
144
145                /* if requested, load only one area */
146                if ($areaID !== 0)
147                {
148                        $selectedArea = null;
149                        while (($currentArea = array_pop($areaStack)) !== null)
150                        {
151                                if ($currentArea['area_id'] == $areaID)
152                                {
153                                        $selectedArea = $currentArea;
154                                        break;
155                                }
156
157                                foreach ($currentArea['children'] as &$child)
158                                        $areaStack[] = $child;
159                        }
160
161                        if (is_null($selectedArea))
162                                return false;
163
164                        $areaStack = array(&$selectedArea);
165                }
166                else
167                {
168                        $areaStack = array_reverse($areaStack);
169                        $smarty->assign('organizationName', $organizationInfo['descricao']);
170                }
171
172                /* make the array flat (for a simpler handling) */
173                $flatAreas = array();
174                while (count($areaStack) > 0)
175                {
176                        $currentArea = &$areaStack[count($areaStack) - 1];
177                        unset($areaStack[count($areaStack) - 1]);
178
179                        $currentArea['children'] = array_reverse($currentArea['children']);
180                        foreach ($currentArea['children'] as &$item)
181                        {
182                                $item['orgchartPath'] = $currentArea['orgchartPath'] . $currentArea['sigla'] . ' &rarr; ';
183                                $areaStack[count($areaStack)] = &$item;
184                        }
185                        unset($currentArea['children']);
186
187                        $employees = $so->getAreaEmployees($currentArea['area_id'], $organizationID);
188                        if (is_array($employees))
189                                $currentArea['employees'] = $employees['employees'];
190                        else
191                                $currentArea['employees'] = array();
192                        $flatAreas[] = $currentArea;
193                }
194
195                /* get the CSS and JS links */
196                $javaScripts = $this->get_js_link('workflow', 'jquery', 'jquery-1.2.6');
197                $javaScripts .= $this->get_js_link('workflow', 'userinterface', 'orgchartPrint');
198
199                $css = $this->get_css_link('orgchartPrint', 'print');
200                $css .= $this->get_css_link('orgchartPrintPreview');
201
202                /* pass variables to smarty */
203                $smarty->assign('areasJson', json_encode($flatAreas));
204                $smarty->assign('javaScripts', $javaScripts);
205                $smarty->assign('css', $css);
206
207                /* render the page */
208                $smarty->display('orgchartPrint.tpl');
209        }
210}
211?>
Note: See TracBrowser for help on using the repository browser.