source: sandbox/workflow/branches/993/inc/class.ui_orgchart.inc.php @ 2418

Revision 2418, 6.2 KB checked in by pedroerp, 14 years ago (diff)

Ticket #993 - Versão inicial da classe 'Settings' e substituicao de chamadas 'read_repository'.

  • 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');
14
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        public function ui_orgchart()
40        {
41        }
42        /**
43         * Draw the orgchart admin interface
44         * @return void
45         * @access public
46         */
47        public function draw($tab_index = "")
48        {
49                $this->workflow_acl = Factory::getInstance('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 = Factory::getInstance('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        public 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                $db = &Factory::getInstance('WorkflowObjects')->getDBWorkflow()->Link_ID;
107
108                $attributes = array();
109                $attributes['ranksep'] = '1.5 equally';
110                $attributes['rankdir'] = 'LR';
111                $graph = &Factory::getInstance('Process_GraphViz', true, $attributes);
112
113                $result = $this->getHierarchicalArea($organizationID, null, 0, $db, $graph);
114                if ($result !== false)
115                        $graph->image('png', '/tmp/grafico');
116                        else
117                                die();
118        }
119
120
121        /**
122         * Get Hierarchical Area
123         * @param organizationID
124         * @param $parent
125         * @param $depth
126         * @param $db
127         * @param $graph
128         * @return
129         */
130        private function getHierarchicalArea($organizationID, $parent, $depth, $db, $graph)
131        {
132                /* orgchart graph configuration */
133                $color='black';
134                $fillcolor='lightblue2'; //blue TLS values
135                $fontsize = '10';
136                $color = '0.25,1,0.28'; #dark green in TLS values
137                $arrowsize = 0.8;
138
139                if (is_null($parent))
140                        $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));
141                else
142                        $result = $db->query("SELECT area_id, sigla, titular_funcionario_id FROM area WHERE (superior_area_id = ?) AND (ativa = 'S') ORDER BY sigla", array($parent));
143
144                $output = $result->GetArray(-1);
145
146                if (is_null($parent) && (count($output) == 0))
147                        return false;
148
149                $ldap = &Factory::getInstance('WorkflowLDAP');
150                for ($i = 0; $i < count($output); $i++)
151                {
152                        for ($j = 0; $j < $result->_numOfFields; $j++)
153                                unset($output[$i][$j]);
154                        if ($output[$i]['titular_funcionario_id'] != '')
155                        {
156                                $supervisor = $ldap->getName($output[$i]['titular_funcionario_id']);
157                                $supervisor = str_replace(array(" da ", " de ", " do ", " das ", " dos "), " ", $supervisor);
158                                $supervisorArray = explode(' ', $supervisor);
159                                $supervisorName = '';
160                                for ($j = 0; $j < count($supervisorArray); $j++)
161                                        $supervisorName .= (($j == 0) || ($j == count($supervisorArray) - 1)) ? $supervisorArray[$j] . ' ' : $supervisorArray[$j][0] . '. ';
162                                $supervisorName = trim(str_replace("Junior", "Jr", $supervisorName));
163                        }
164                        else
165                                $supervisorName = '';
166
167                        /* add the area box */
168                        $graph->addNode($output[$i]['area_id'],array(
169                                'URL'           => $output[$i]['area_id'],
170                                'label'         => $output[$i]['sigla'] . '\n' . $supervisorName,
171                                'shape'         => 'box',
172                                'color'         => $color,
173                                'fillcolor'     => $fillcolor,
174                                'style'         => 'filled',
175                                'fontsize'      => $fontsize,
176                                'fontname'      => 'serif'
177                                )
178                        );
179
180                        /* add the conection between areas */
181                        if (!is_null($parent))
182                                $graph->addEdge(array($parent => $output[$i]['area_id']), array('color'=>$color,'arrowsize'=>$arrowsize));
183                        $output[$i]['children'] = $this->getHierarchicalArea($organizationID, $output[$i]['area_id'], $depth + 1, $db, $graph);
184                        $output[$i]['depth'] = $depth;
185                }
186
187                return $output;
188        }
189}
190?>
Note: See TracBrowser for help on using the repository browser.