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 | |
---|
13 | require_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 | */ |
---|
20 | class 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 = 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 | 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 | $config_values = Factory::getInstance('config', 'workflow'); |
---|
107 | $config_values->read_repository(); |
---|
108 | $conf_db = $config_values->config_data; |
---|
109 | $db = Factory::getInstance('db'); |
---|
110 | $db->connect( |
---|
111 | $conf_db['database_name'], |
---|
112 | $conf_db['database_host'], |
---|
113 | $conf_db['database_port'], |
---|
114 | $conf_db['database_admin_user'], |
---|
115 | $conf_db['database_admin_password'], |
---|
116 | $conf_db['database_type'] |
---|
117 | ); |
---|
118 | $db = $db->Link_ID; |
---|
119 | $attributes = array(); |
---|
120 | $attributes['ranksep'] = '1.5 equally'; |
---|
121 | $attributes['rankdir'] = 'LR'; |
---|
122 | $graph = &Factory::getInstance('Process_GraphViz', true, $attributes); |
---|
123 | |
---|
124 | |
---|
125 | /** |
---|
126 | * Get Hierarchical Area |
---|
127 | * @param organizationID |
---|
128 | * @param $parent |
---|
129 | * @param $depth |
---|
130 | * @param $db |
---|
131 | * @param $graph |
---|
132 | * @return |
---|
133 | */ |
---|
134 | function getHierarchicalArea($organizationID, $parent, $depth, $db, $graph) |
---|
135 | { |
---|
136 | /* orgchart graph configuration */ |
---|
137 | $color='black'; |
---|
138 | $fillcolor='lightblue2'; //blue TLS values |
---|
139 | $fontsize = '10'; |
---|
140 | $color = '0.25,1,0.28'; #dark green in TLS values |
---|
141 | $arrowsize = 0.8; |
---|
142 | |
---|
143 | if (is_null($parent)) |
---|
144 | $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)); |
---|
145 | else |
---|
146 | $result = $db->query("SELECT area_id, sigla, titular_funcionario_id FROM area WHERE (superior_area_id = ?) AND (ativa = 'S') ORDER BY sigla", array($parent)); |
---|
147 | |
---|
148 | $output = $result->GetArray(-1); |
---|
149 | |
---|
150 | if (is_null($parent) && (count($output) == 0)) |
---|
151 | return false; |
---|
152 | |
---|
153 | $ldap = &Factory::getInstance('WorkflowLDAP'); |
---|
154 | for ($i = 0; $i < count($output); $i++) |
---|
155 | { |
---|
156 | for ($j = 0; $j < $result->_numOfFields; $j++) |
---|
157 | unset($output[$i][$j]); |
---|
158 | if ($output[$i]['titular_funcionario_id'] != '') |
---|
159 | { |
---|
160 | $supervisor = $ldap->getName($output[$i]['titular_funcionario_id']); |
---|
161 | $supervisor = str_replace(array(" da ", " de ", " do ", " das ", " dos "), " ", $supervisor); |
---|
162 | $supervisorArray = explode(' ', $supervisor); |
---|
163 | $supervisorName = ''; |
---|
164 | for ($j = 0; $j < count($supervisorArray); $j++) |
---|
165 | $supervisorName .= (($j == 0) || ($j == count($supervisorArray) - 1)) ? $supervisorArray[$j] . ' ' : $supervisorArray[$j][0] . '. '; |
---|
166 | $supervisorName = trim(str_replace("Junior", "Jr", $supervisorName)); |
---|
167 | } |
---|
168 | else |
---|
169 | $supervisorName = ''; |
---|
170 | /* add the area box */ |
---|
171 | $graph->addNode($output[$i]['area_id'],array( |
---|
172 | 'URL' => $output[$i]['area_id'], |
---|
173 | 'label' => $output[$i]['sigla'] . '\n' . $supervisorName, |
---|
174 | 'shape' => 'box', |
---|
175 | 'color' => $color, |
---|
176 | 'fillcolor' => $fillcolor, |
---|
177 | 'style' => 'filled', |
---|
178 | 'fontsize' => $fontsize, |
---|
179 | 'fontname' => 'serif' |
---|
180 | ) |
---|
181 | ); |
---|
182 | |
---|
183 | /* add the conection between areas */ |
---|
184 | if (!is_null($parent)) |
---|
185 | $graph->addEdge(array($parent => $output[$i]['area_id']), array('color'=>$color,arrowsize=>$arrowsize)); |
---|
186 | $output[$i]['children'] = getHierarchicalArea($organizationID, $output[$i]['area_id'], $depth + 1, $db, $graph); |
---|
187 | $output[$i]['depth'] = $depth; |
---|
188 | } |
---|
189 | |
---|
190 | return $output; |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | $result = getHierarchicalArea($organizationID, null, 0, $db, $graph); |
---|
195 | if ($result !== false) |
---|
196 | $graph->image('png', '/tmp/grafico'); |
---|
197 | else |
---|
198 | die(); |
---|
199 | } |
---|
200 | } |
---|
201 | ?> |
---|