source: trunk/workflow/inc/class.ui_orgchart.inc.php @ 795

Revision 795, 6.7 KB checked in by viani, 15 years ago (diff)

Ticket #488 - Inclusão do módulo workflow no ramo trunk do repositório Expresso.

  • Property svn:executable set to *
Line 
1<?php
2
3        /**************************************************************************\
4* eGroupWare                                                 *
5* http://www.egroupware.org                                                *
6* --------------------------------------------                             *
7*  This program is free software; you can redistribute it and/or modify it *
8*  under the terms of the GNU General Public License as published by the   *
9*  Free Software Foundation; either version 2 of the License, or (at your  *
10*  option) any later version.                                              *
11\**************************************************************************/
12
13require_once(dirname(__FILE__) . SEP . 'class.ui_ajaxinterface.inc.php');
14require_once(dirname(__FILE__) . SEP . 'class.workflow_acl.inc.php');
15/**
16 * @package Workflow
17 * @license http://www.gnu.org/copyleft/gpl.html GPL
18 * @author Mauricio Luiz Viani - viani@celepar.pr.gov.br
19 */
20class ui_orgchart extends ui_ajaxinterface
21{
22        /**
23         * @var array $public_functions
24         * @access public
25         */
26        var $public_functions = array(
27                'draw'  => true,
28                'graph' => true
29        );
30        /**
31         * @var array $workflow_acl
32         * @access public
33         */
34        var $workflow_acl;
35        /**
36         * Construtor
37         * @access public
38         */
39        function ui_orgchart()
40        {
41        }
42        /**
43         * Draw the orgchart admin interface
44         * @return void
45         * @access public
46         */
47        function draw($tab_index = "")
48        {
49                $this->workflow_acl = CreateObject('workflow.workflow_acl');
50
51                $isAdmin = $this->workflow_acl->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']);
52                $isOrgchartManager = $this->workflow_acl->checkUserGroupAccessToType('ORG', $GLOBALS['phpgw_info']['user']['account_id']);
53
54                if (!($isAdmin || $isOrgchartManager))
55                {
56                        $GLOBALS['phpgw']->common->phpgw_header();
57                        echo parse_navbar();
58                        echo lang('access not permitted');
59                        $GLOBALS['phpgw']->log->message('F-Abort, Unauthorized access to workflow.ui_orgchart');
60                        $GLOBALS['phpgw']->log->commit();
61                        $GLOBALS['phpgw']->common->phpgw_exit();
62                }
63
64                $GLOBALS['phpgw_info']['flags'] = array('noheader' => false, 'nonavbar' => false, 'currentapp' => 'workflow');
65                $smarty = CreateObject('workflow.workflow_smarty');
66
67                $this->set_wf_session();
68
69                $javaScripts = $this->get_common_js();
70                $javaScripts .= $this->get_js_link('workflow','scriptaculous', 'prototype');
71                $javaScripts .= $this->get_js_link('workflow','orgchart', 'main');
72                $javaScripts .= $this->get_js_link('workflow','orgchart', 'utils');
73                $javaScripts .= $this->get_js_link('workflow','orgchart', 'organization');
74                $javaScripts .= $this->get_js_link('workflow','orgchart', 'organizations');
75                $javaScripts .= $this->get_js_link('workflow','scriptaculous', 'lightbox');
76                $javaScripts .= $this->get_js_link('workflow','jscode', 'participants');
77
78                $css = $this->get_common_css();
79                $css .= $this->get_css_link('orgchart');
80                $css .= $this->get_css_link('lightbox');
81
82                $smarty->assign('header', $smarty->expressoHeader);
83                $smarty->assign('footer', $smarty->expressoFooter);
84                $smarty->assign('txt_loading', lang('loading'));
85                $smarty->assign('javaScripts', $javaScripts);
86                $smarty->assign('tabIndex', $tab_index);
87                $smarty->assign('css', $css);
88                $smarty->display('orgchart.tpl');
89        }
90
91        /**
92         * Show the graph
93         * @access public
94         * @return void
95         */
96        function graph()
97        {
98                if (!isset($_GET['organizationID']))
99                        die();
100                $organizationID = $_GET['organizationID'];
101                if (is_numeric($organizationID))
102                        $organizationID = (int) $organizationID;
103                else
104                        die();
105
106                require_once(dirname(__FILE__) . SEP . 'engine' . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'GraphViz.php');
107
108                $config_values = CreateObject('phpgwapi.config','workflow');
109                $config_values->read_repository();
110                $conf_db = $config_values->config_data;
111                $db = CreateObject('phpgwapi.db');
112                $db->connect(
113                        $conf_db['database_name'],
114                        $conf_db['database_host'],
115                        $conf_db['database_port'],
116                        $conf_db['database_admin_user'],
117                        $conf_db['database_admin_password'],
118                        $conf_db['database_type']
119                );
120                $db = $db->Link_ID;
121                $attributes = array();
122                $attributes['ranksep'] = '1.5 equally';
123                $attributes['rankdir'] = 'LR';
124                $graph = new Process_GraphViz(true, $attributes);
125
126
127                /**
128                 * Get Hierarchical Area
129                 * @param organizationID
130                 * @param $parent
131                 * @param $depth
132                 * @param $db
133                 * @param $graph
134                 * @return
135                 */
136                function getHierarchicalArea($organizationID, $parent, $depth, $db, $graph)
137                {
138                        /* orgchart graph configuration */
139                        $color='black';
140                        $fillcolor='lightblue2'; //blue TLS values
141                        $fontsize = '10';
142                        $color = '0.25,1,0.28'; #dark green in TLS values
143                        $arrowsize = 0.8;
144
145                        if (is_null($parent))
146                                $result = $db->query("SELECT area_id, sigla, titular_funcionario_id FROM area WHERE (superior_area_id IS NULL) AND (organizacao_id = ?) AND (ativa = 'S') ORDER BY sigla", array($organizationID));
147                        else
148                                $result = $db->query("SELECT area_id, sigla, titular_funcionario_id FROM area WHERE (superior_area_id = ?) AND (ativa = 'S') ORDER BY sigla", array($parent));
149
150                        $output = $result->GetArray(-1);
151
152                        if (is_null($parent) && (count($output) == 0))
153                                return false;
154
155                        $ldap = &$GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP');
156                        for ($i = 0; $i < count($output); $i++)
157                        {
158                                for ($j = 0; $j < $result->_numOfFields; $j++)
159                                        unset($output[$i][$j]);
160                                if ($output[$i]['titular_funcionario_id'] != '')
161                                {
162                                        $supervisor = $ldap->getName($output[$i]['titular_funcionario_id']);
163                                        $supervisor = str_replace(array(" da ", " de ", " do ", " das ", " dos "), " ", $supervisor);
164                                        $supervisorArray = explode(' ', $supervisor);
165                                        $supervisorName = '';
166                                        for ($j = 0; $j < count($supervisorArray); $j++)
167                                                $supervisorName .= (($j == 0) || ($j == count($supervisorArray) - 1)) ? $supervisorArray[$j] . ' ' : $supervisorArray[$j][0] . '. ';
168                                        $supervisorName = trim(str_replace("Junior", "Jr", $supervisorName));
169                                }
170                                else
171                                        $supervisorName = '';
172                                /* add the area box */
173                                $graph->addNode($output[$i]['area_id'],array(
174                                        'URL'           => $output[$i]['area_id'],
175                                        'label'         => $output[$i]['sigla'] . '\n' . $supervisorName,
176                                        'shape'         => 'box',
177                                        'color'         => $color,
178                                        'fillcolor'     => $fillcolor,
179                                        'style'         => 'filled',
180                                        'fontsize'      => $fontsize,
181                                        'fontname'      => 'serif'
182                                        )
183                                );
184
185                                /* add the conection between areas */
186                                if (!is_null($parent))
187                                        $graph->addEdge(array($parent => $output[$i]['area_id']), array('color'=>$color,arrowsize=>$arrowsize));
188                                $output[$i]['children'] = getHierarchicalArea($organizationID, $output[$i]['area_id'], $depth + 1, $db, $graph);
189                                $output[$i]['depth'] = $depth;
190                        }
191
192                        return $output;
193                }
194
195
196                $result = getHierarchicalArea($organizationID, null, 0, $db, $graph);
197                if ($result !== false)
198                        $graph->image('png', '/tmp/grafico');
199                        else
200                                die();
201        }
202}
203?>
Note: See TracBrowser for help on using the repository browser.