[795] | 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 | |
---|
| 12 | require_once('class.bo_ajaxinterface.inc.php'); |
---|
| 13 | |
---|
| 14 | /** |
---|
| 15 | * @package Workflow |
---|
| 16 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 17 | * @author Mauricio Luiz Viani - viani@celepar.pr.gov.br |
---|
| 18 | * @author Sidnei Augusto Drovetto - drovetto@gmail.com |
---|
| 19 | */ |
---|
| 20 | class bo_userinterface extends bo_ajaxinterface |
---|
| 21 | { |
---|
| 22 | /** |
---|
| 23 | * @var object Acesso à camada Model |
---|
| 24 | * @access public |
---|
| 25 | */ |
---|
| 26 | var $so; |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * @var array Informações sobre a organização do usuário |
---|
| 30 | * @access private |
---|
| 31 | */ |
---|
| 32 | private $organizationInfo; |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * Construtor da classe bo_userinterface |
---|
| 36 | * @access public |
---|
| 37 | * @return object |
---|
| 38 | */ |
---|
| 39 | function bo_userinterface() |
---|
| 40 | { |
---|
[3167] | 41 | parent::bo_ajaxinterface(); |
---|
| 42 | $this->so = &Factory::getInstance('so_userinterface'); |
---|
| 43 | $GLOBALS['ajax']->gui = &Factory::newInstance('GUI'); |
---|
[795] | 44 | } |
---|
| 45 | |
---|
| 46 | /** |
---|
| 47 | * Retorna os processos do usuário |
---|
| 48 | * @access public |
---|
| 49 | * @return mixed retorna uma string com uma mensagem de erro ou um array com dados dos processos |
---|
| 50 | */ |
---|
| 51 | function processes() |
---|
| 52 | { |
---|
| 53 | $account_id = $_SESSION['phpgw_info']['workflow']['account_id']; |
---|
| 54 | $result = $GLOBALS['ajax']->gui->gui_list_user_activities($account_id, '0', '-1', "wf_menu_path__ASC, ga.wf_name__ASC", '', '', '', true, true, true, ''); |
---|
| 55 | |
---|
| 56 | $errorMessage = $GLOBALS['ajax']->gui->get_error(false); |
---|
| 57 | if (!empty($errorMessage)) |
---|
| 58 | { |
---|
| 59 | $this->disconnect_all(); |
---|
| 60 | return array('error' => $errorMessage); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | $recset = array(); |
---|
| 64 | $webserver_url = $_SESSION['phpgw_info']['workflow']['server']['webserver_url']; |
---|
| 65 | |
---|
[3167] | 66 | $templateServer =& Factory::getInstance('TemplateServer'); |
---|
[795] | 67 | foreach ($result['data'] as $line) |
---|
| 68 | { |
---|
| 69 | /* don't include activities whose menu_path is equal to ! */ |
---|
| 70 | if ($line['wf_menu_path'] === '!') |
---|
| 71 | continue; |
---|
| 72 | |
---|
| 73 | if (file_exists(GALAXIA_PROCESSES . '/' . $line['wf_normalized_name'] . '/resources/icon.png')) |
---|
| 74 | $iconweb = $webserver_url . '/workflow/redirect.php?pid=' . $line['wf_p_id'] . '&file=/icon.png'; |
---|
| 75 | else |
---|
| 76 | $iconweb = $templateServer->generateImageLink('navbar.png'); |
---|
| 77 | $procname_ver = $line['wf_normalized_name']; |
---|
| 78 | if (!isset($recset[$procname_ver])) |
---|
| 79 | { |
---|
| 80 | $recset[$procname_ver]['wf_p_id'] = $line['wf_p_id']; |
---|
| 81 | $recset[$procname_ver]['wf_procname'] = $line['wf_procname']; |
---|
| 82 | $recset[$procname_ver]['wf_version'] = $line['wf_version']; |
---|
| 83 | $recset[$procname_ver]['wf_is_active'] = $line['wf_is_active']; |
---|
| 84 | $recset[$procname_ver]['wf_iconfile'] = $iconweb; |
---|
| 85 | if ($_SESSION['phpgw_info']['workflow']['server']['use_https'] > 0) |
---|
| 86 | { |
---|
| 87 | $GLOBALS['ajax']->gui->wf_security->loadConfigValues($line['wf_p_id']); |
---|
| 88 | $recset[$procname_ver]['useHTTPS'] = $GLOBALS['ajax']->gui->wf_security->processesConfig[$line['wf_p_id']]['execute_activities_using_secure_connection']; |
---|
| 89 | } |
---|
| 90 | else |
---|
| 91 | $recset[$procname_ver]['useHTTPS'] = 0; |
---|
| 92 | } |
---|
[3167] | 93 | if (!is_dir(GALAXIA_PROCESSES . '/' . $line['wf_normalized_name'])) |
---|
| 94 | { |
---|
| 95 | $recset[$procname_ver]['wf_iconfile'] = $templateServer->generateImageLink('navbar_nocode.png'); |
---|
| 96 | } |
---|
| 97 | else |
---|
| 98 | { |
---|
| 99 | $recset[$procname_ver][] = array('wf_activity_id' => $line['wf_activity_id'], |
---|
| 100 | 'wf_name' => $line['wf_name'], |
---|
| 101 | 'wf_menu_path' => $line['wf_menu_path'], |
---|
| 102 | 'wf_type' => $line['wf_type'], |
---|
| 103 | 'wf_is_autorouted' => $line['wf_is_autorouted'], |
---|
| 104 | 'wf_is_interactive' => $line['wf_is_interactive']); |
---|
| 105 | } |
---|
[795] | 106 | } |
---|
| 107 | |
---|
| 108 | $recset = array_values($recset); |
---|
| 109 | usort($recset, create_function('$a,$b', 'return strcasecmp($a[\'wf_procname\'] . $a[\'wf_version\'],$b[\'wf_procname\'] . $b[\'wf_version\']);')); |
---|
| 110 | |
---|
| 111 | $this->disconnect_all(); |
---|
| 112 | return $recset; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | /** |
---|
| 116 | * Informacoes sobre o processo |
---|
| 117 | * @param $params parametros |
---|
| 118 | * @return array |
---|
| 119 | * @access public |
---|
| 120 | */ |
---|
| 121 | function process_about($params) |
---|
| 122 | { |
---|
| 123 | $pid = $params['pid']; |
---|
| 124 | $result = array(); |
---|
[3167] | 125 | |
---|
| 126 | $process = &Factory::newInstance('Process'); |
---|
[795] | 127 | $process->getProcess($pid); |
---|
| 128 | $result['wf_procname'] = $process->name; |
---|
| 129 | $result['wf_version'] = $process->version; |
---|
| 130 | $result['wf_description'] = $process->description; |
---|
[3167] | 131 | |
---|
| 132 | $activ_manager = &Factory::newInstance('ActivityManager'); |
---|
[795] | 133 | $result['wf_activities'] = $activ_manager->get_process_activities($pid); |
---|
[3167] | 134 | |
---|
[795] | 135 | $this->disconnect_all(); |
---|
[3167] | 136 | |
---|
| 137 | return $result; |
---|
[795] | 138 | } |
---|
| 139 | |
---|
| 140 | /** |
---|
| 141 | * Fornece os dados para a contrução da interface de Tarefas Pendentes |
---|
| 142 | * @param $params Parâmetros advindos da chamada Ajax |
---|
| 143 | * @return array Contendo os dados para construção da interface ou uma mensagem de erro |
---|
| 144 | * @access public |
---|
| 145 | */ |
---|
| 146 | function inbox($params) |
---|
| 147 | { |
---|
| 148 | $preferences = $_SESSION['phpgw_info']['workflow']['user']['preferences']; |
---|
| 149 | |
---|
| 150 | /* initialize Paging Class */ |
---|
| 151 | $itemsPerPage = isset($preferences['ui_items_per_page']) ? $preferences['ui_items_per_page'] : 15; |
---|
| 152 | $lightVersion = ((isset($preferences['use_light_interface']) ? $preferences['use_light_interface'] : 0) == 1); |
---|
[3167] | 153 | $paging = Factory::newInstance('Paging', $itemsPerPage, $_POST); |
---|
[795] | 154 | |
---|
| 155 | /* define the sorting */ |
---|
| 156 | $sort = 'wf_act_started__DESC'; |
---|
| 157 | if ($params['sort']) |
---|
| 158 | $sort = $params['sort']; |
---|
| 159 | else |
---|
| 160 | if (isset($preferences['inbox_sort'])) |
---|
| 161 | $sort = $preferences['inbox_sort']; |
---|
| 162 | |
---|
| 163 | /* make sure that the sorting parameter is one of the expected values */ |
---|
| 164 | $sortFields = explode('__', strtolower($sort)); |
---|
| 165 | if (count($sortFields) != 2) |
---|
| 166 | $sort = 'wf_act_started__DESC'; |
---|
| 167 | else |
---|
| 168 | if (!(in_array($sortFields[0], array('wf_act_started', 'wf_procname', 'wf_name', 'insname', 'wf_priority')) && in_array($sortFields[1], array('desc', 'asc')))) |
---|
| 169 | $sort = 'wf_act_started__DESC'; |
---|
| 170 | elseif(strpos($sort, 'wf_act_started') === false){ |
---|
| 171 | $sort = $sort.', wf_act_started__ASC'; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | $params['sort'] = $sort; |
---|
| 175 | |
---|
| 176 | /* get other parameters */ |
---|
| 177 | $pid = (int) $params['pid']; |
---|
| 178 | $search_term = $params['search_term']; |
---|
| 179 | $account_id = $_SESSION['phpgw_info']['workflow']['account_id']; |
---|
| 180 | $result = $GLOBALS['ajax']->gui->gui_list_user_instances($account_id, 0, -1, $sort, $search_term, "ga.wf_is_interactive = 'y'", false, $pid, true, false, true, false, false, false); |
---|
| 181 | |
---|
| 182 | $errorMessage = $GLOBALS['ajax']->gui->get_error(false); |
---|
| 183 | if (!empty($errorMessage)) |
---|
| 184 | { |
---|
| 185 | $this->disconnect_all(); |
---|
| 186 | return array('error' => $errorMessage); |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | $output = array(); |
---|
| 190 | $output['sort_param'] = str_replace(', wf_act_started__ASC', '', $sort); |
---|
| 191 | $output['instances'] = array(); |
---|
| 192 | $output['processes'] = array(); |
---|
| 193 | $list_process = array(); |
---|
| 194 | $actionKeys = array( |
---|
| 195 | 'run', |
---|
| 196 | 'viewrun', |
---|
| 197 | 'view', |
---|
| 198 | 'send', |
---|
| 199 | 'release', |
---|
| 200 | 'grab', |
---|
| 201 | 'exception', |
---|
| 202 | 'resume', |
---|
| 203 | 'abort', |
---|
| 204 | 'monitor'); |
---|
| 205 | |
---|
| 206 | foreach ($result['data'] as $row) |
---|
| 207 | { |
---|
| 208 | /* don't show the instance if the user can't run it */ |
---|
| 209 | if (($row['wf_user'] != $account_id) && ($row['wf_user'] != '*')) |
---|
| 210 | continue; |
---|
| 211 | if (($row['wf_status'] == 'active') || ($row['wf_status'] == 'exception')) |
---|
| 212 | { |
---|
| 213 | $availableActions = $GLOBALS['ajax']->gui->getUserActions( |
---|
| 214 | $account_id, |
---|
| 215 | $row['wf_instance_id'], |
---|
| 216 | $row['wf_activity_id'], |
---|
| 217 | $row['wf_readonly'], |
---|
| 218 | $row['wf_p_id'], |
---|
| 219 | $row['wf_type'], |
---|
| 220 | $row['wf_is_interactive'], |
---|
| 221 | $row['wf_is_autorouted'], |
---|
| 222 | $row['wf_act_status'], |
---|
| 223 | $row['wf_owner'], |
---|
| 224 | $row['wf_status'], |
---|
| 225 | $row['wf_user']); |
---|
| 226 | |
---|
| 227 | $row['viewRunAction'] = false; |
---|
| 228 | if (isset($availableActions['viewrun'])) |
---|
| 229 | $row['viewRunAction'] = array('viewActivityID' => $availableActions['viewrun']['link'], 'height' => $availableActions['viewrun']['iframe_height']); |
---|
| 230 | |
---|
| 231 | foreach ($actionKeys as $key) |
---|
| 232 | $availableActions[$key] = (isset($availableActions[$key])); |
---|
| 233 | |
---|
| 234 | if ($GLOBALS['ajax']->gui->wf_security->processesConfig[$row['wf_p_id']]['disable_advanced_actions'] == 1) |
---|
| 235 | { |
---|
| 236 | $availableActions['release'] = false; |
---|
| 237 | $availableActions['grab'] = false; |
---|
| 238 | $availableActions['exception'] = false; |
---|
| 239 | $availableActions['resume'] = false; |
---|
| 240 | $availableActions['abort'] = false; |
---|
| 241 | $availableActions['monitor'] = false; |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | /* define the advanced actions for javascript usage */ |
---|
| 245 | $actionsArray = array(); |
---|
| 246 | $actionsArray[] = array('name' => 'run', 'value' => $availableActions['run'], 'text' => 'Executar'); |
---|
| 247 | $actionsArray[] = array('name' => 'view', 'value' => $availableActions['view'], 'text' => 'Visualizar'); |
---|
| 248 | $actionsArray[] = array('name' => 'send', 'value' => $availableActions['send'], 'text' => 'Enviar'); |
---|
| 249 | $actionsArray[] = array('name' => 'viewrun', 'value' => $availableActions['viewrun'], 'text' => ''); |
---|
| 250 | $actionsArray[] = ($row['wf_user'] == '*') ? |
---|
| 251 | array('name' => 'grab', 'value' => $availableActions['grab'], 'text' => 'Capturar') : |
---|
| 252 | array('name' => 'release', 'value' => $availableActions['release'], 'text' => 'Liberar Acesso'); |
---|
| 253 | $actionsArray[] = ($row['wf_status'] == 'active') ? |
---|
| 254 | array('name' => 'exception', 'value' => $availableActions['exception'], 'text' => 'Colocar em Exceção') : |
---|
| 255 | array('name' => 'resume', 'value' => $availableActions['resume'], 'text' => 'Retirar de Exceção'); |
---|
| 256 | $actionsArray[] = array('name' => 'abort', 'value' => $availableActions['abort'], 'text' => 'Abortar'); |
---|
| 257 | |
---|
| 258 | $row['wf_actions'] = $actionsArray; |
---|
| 259 | |
---|
| 260 | $row['wf_started'] = date('d/m/Y H:i', $row['wf_started']); |
---|
| 261 | $row['wf_act_started'] = date('d/m/Y H:i', $row['wf_act_started']); |
---|
| 262 | |
---|
| 263 | $row['wf_user_fullname'] = ''; |
---|
| 264 | if ($row['wf_user'] == '*') |
---|
| 265 | $row['wf_user_fullname'] = '*'; |
---|
| 266 | else |
---|
| 267 | if ($row['wf_user'] != '') |
---|
[3167] | 268 | $row['wf_user_fullname'] = Factory::getInstance('WorkflowLDAP')->getName($row['wf_user']); |
---|
[795] | 269 | |
---|
| 270 | /* unset unneeded information */ |
---|
| 271 | unset($row['wf_ended'], $row['wf_owner'], $row['wf_category'], $row['wf_act_status'], $row['wf_started'], $row['wf_type'], $row['wf_is_interactive'], $row['wf_is_autorouted'], $row['wf_normalized_name'], $row['wf_readonly']); |
---|
| 272 | $output['instances'][] = $row; |
---|
| 273 | } |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | /* paginate the results */ |
---|
| 277 | $output['instances'] = $paging->restrictItems($output['instances']); |
---|
| 278 | $output['paging_links'] = $paging->commonLinks(); |
---|
| 279 | |
---|
| 280 | /* only save different actions set */ |
---|
| 281 | $actions = array_values(array_map(create_function('$a', 'return unserialize($a);'), array_unique(array_map(create_function('$a', 'return serialize($a[\'wf_actions\']);'), $output['instances'])))); |
---|
| 282 | |
---|
| 283 | $actionsArray = array(); |
---|
| 284 | $userNames = array(); |
---|
| 285 | $processesInfo = array(); |
---|
| 286 | $activityNames = array(); |
---|
| 287 | foreach ($output['instances'] as $key => $value) |
---|
| 288 | { |
---|
| 289 | $userNames[$value['wf_user']] = $value['wf_user_fullname']; |
---|
| 290 | unset($output['instances'][$key]['wf_user_fullname']); |
---|
| 291 | |
---|
| 292 | $processesInfo[$value['wf_p_id']] = array( |
---|
| 293 | 'name' => $value['wf_procname'] . ' (v' . $value['wf_version'] . ')', |
---|
| 294 | 'useHTTPS' => (($_SESSION['phpgw_info']['workflow']['server']['use_https'] > 0) ? $GLOBALS['ajax']->gui->wf_security->processesConfig[$value['wf_p_id']]['execute_activities_using_secure_connection'] : 0) |
---|
| 295 | ); |
---|
| 296 | unset($output['instances'][$key]['wf_procname']); |
---|
| 297 | unset($output['instances'][$key]['wf_version']); |
---|
| 298 | |
---|
| 299 | $activityNames[$value['wf_activity_id']] = $value['wf_name']; |
---|
| 300 | unset($output['instances'][$key]['wf_name']); |
---|
| 301 | |
---|
| 302 | $output['instances'][$key]['wf_actions'] = array_search($value['wf_actions'], $actions); |
---|
| 303 | if (is_null($value['insname'])) |
---|
| 304 | $output['instances'][$key]['insname'] = ''; |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | $output['userNames'] = $userNames; |
---|
| 308 | $output['processesInfo'] = $processesInfo; |
---|
| 309 | $output['activityNames'] = $activityNames; |
---|
| 310 | $output['actions'] = $actions; |
---|
| 311 | |
---|
| 312 | /* load all the activities that have at least one instance */ |
---|
| 313 | $allActivities = $GLOBALS['ajax']->gui->gui_list_user_activities($account_id, 0, -1, "ga.wf_name__ASC", '', "gia.wf_user = '$account_id' OR gia.wf_user = '*'", true); |
---|
| 314 | foreach ($allActivities['data'] as $activity) |
---|
| 315 | $list_process[$activity['wf_procname'] . " (v" . $activity['wf_version'] . ")"] = $activity['wf_p_id']; |
---|
| 316 | |
---|
| 317 | $this->disconnect_all(); |
---|
| 318 | |
---|
| 319 | foreach ($list_process as $processName => $processId) |
---|
| 320 | $output['processes'][] = array('name' => $processName, 'pid' => $processId); |
---|
| 321 | |
---|
| 322 | /* some extra params */ |
---|
| 323 | $output['params'] = $params; |
---|
| 324 | $output['light'] = $lightVersion; |
---|
| 325 | $output['instancesDigest'] = md5(serialize($output['instances'])); |
---|
| 326 | |
---|
| 327 | return $output; |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | /** |
---|
| 331 | * Fornece os dados para a contrução da interface de Tarefas Pendentes (quando os dados estão agrupados) |
---|
| 332 | * @return array Contendo os dados para construção da interface ou uma mensagem de erro |
---|
| 333 | * @access public |
---|
| 334 | */ |
---|
| 335 | function inbox_group() |
---|
| 336 | { |
---|
| 337 | $account_id = $_SESSION['phpgw_info']['workflow']['account_id']; |
---|
| 338 | $result = $GLOBALS['ajax']->gui->gui_list_user_instances($account_id, 0, -1, 'wf_procname__ASC,wf_name__ASC', '', "ga.wf_is_interactive = 'y'", false, 0, true, false, true, false, false, false); |
---|
| 339 | |
---|
| 340 | $output = array(); |
---|
| 341 | foreach ($result['data'] as $data) |
---|
| 342 | { |
---|
| 343 | if (($data['wf_user'] != $account_id) && ($data['wf_user'] != "*")) |
---|
| 344 | continue; |
---|
| 345 | if (isset($output[$data['wf_activity_id']])) |
---|
| 346 | $output[$data['wf_activity_id']]['wf_instances']++; |
---|
| 347 | else |
---|
| 348 | $output[$data['wf_activity_id']] = array('wf_p_id' => $data['wf_p_id'], 'wf_procname' => $data['wf_procname'], 'wf_version' => $data['wf_version'], 'wf_name' => $data['wf_name'], 'wf_instances' => 1); |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | $errorMessage = $GLOBALS['ajax']->gui->get_error(false); |
---|
| 352 | if (!empty($errorMessage)) |
---|
| 353 | { |
---|
| 354 | $this->disconnect_all(); |
---|
| 355 | return array('error' => $errorMessage); |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | $this->disconnect_all(); |
---|
| 359 | return array_values($output); |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | /** |
---|
| 363 | * Envia uma instância para próxima atividade |
---|
| 364 | * @param $params Parâmetros advindos da chamada Ajax |
---|
| 365 | * @return mixed Array contendo uma mensagem de erro ou um booleano (true) informando que a ação foi feita com sucesso |
---|
| 366 | * @access public |
---|
| 367 | */ |
---|
| 368 | function inboxActionSend($params) |
---|
| 369 | { |
---|
| 370 | $instanceID = (int) $params['instanceID']; |
---|
| 371 | $activityID = (int) $params['activityID']; |
---|
| 372 | $result = true; |
---|
| 373 | |
---|
| 374 | if (!$GLOBALS['ajax']->gui->gui_send_instance($activityID, $instanceID)) |
---|
| 375 | $result = array('error' => $GLOBALS['ajax']->gui->get_error(false) . "<br />Você não está autorizado a enviar esta instância."); |
---|
| 376 | |
---|
| 377 | $this->disconnect_all(); |
---|
| 378 | |
---|
| 379 | return $result; |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | /** |
---|
| 383 | * Libera uma instância (atribui a instância para *) |
---|
| 384 | * @param $params Parâmetros advindos da chamada Ajax |
---|
| 385 | * @return mixed Array contendo uma mensagem de erro ou um booleano (true) informando que a ação foi feita com sucesso |
---|
| 386 | * @access public |
---|
| 387 | */ |
---|
| 388 | function inboxActionRelease($params) |
---|
| 389 | { |
---|
| 390 | $instanceID = (int) $params['instanceID']; |
---|
| 391 | $activityID = (int) $params['activityID']; |
---|
| 392 | $result = true; |
---|
| 393 | |
---|
| 394 | if (!$GLOBALS['ajax']->gui->gui_release_instance($activityID, $instanceID)) |
---|
| 395 | $result = array('error' => $GLOBALS['ajax']->gui->get_error(false) . "<br />Você não está autorizado a liberar esta instância."); |
---|
| 396 | |
---|
| 397 | $this->disconnect_all(); |
---|
| 398 | |
---|
| 399 | return $result; |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | /** |
---|
| 403 | * Captura uma instância (atribui a instância para o usuário atual) |
---|
| 404 | * @param $params Parâmetros advindos da chamada Ajax |
---|
| 405 | * @return mixed Array contendo uma mensagem de erro ou um booleano (true) informando que a ação foi feita com sucesso |
---|
| 406 | * @access public |
---|
| 407 | */ |
---|
| 408 | function inboxActionGrab($params) |
---|
| 409 | { |
---|
| 410 | $instanceID = (int) $params['instanceID']; |
---|
| 411 | $activityID = (int) $params['activityID']; |
---|
| 412 | $result = true; |
---|
| 413 | |
---|
| 414 | if (!$GLOBALS['ajax']->gui->gui_grab_instance($activityID, $instanceID)) |
---|
| 415 | $result = array('error' => $GLOBALS['ajax']->gui->get_error(false) . "<br />Você não tem permissão para capturar esta instância."); |
---|
| 416 | |
---|
| 417 | $this->disconnect_all(); |
---|
| 418 | |
---|
| 419 | return $result; |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | /** |
---|
| 423 | * Transforma a instância em exceção |
---|
| 424 | * @param $params Parâmetros advindos da chamada Ajax |
---|
| 425 | * @return mixed Array contendo uma mensagem de erro ou um booleano (true) informando que a ação foi feita com sucesso |
---|
| 426 | * @access public |
---|
| 427 | */ |
---|
| 428 | function inboxActionException($params) |
---|
| 429 | { |
---|
| 430 | $instanceID = (int) $params['instanceID']; |
---|
| 431 | $activityID = (int) $params['activityID']; |
---|
| 432 | $result = true; |
---|
| 433 | |
---|
| 434 | if (!$GLOBALS['ajax']->gui->gui_exception_instance($activityID, $instanceID)) |
---|
| 435 | $result = array('error' => $GLOBALS['ajax']->gui->get_error(false) . "<br />Você não tem permissão para transformar esta instância em exceção."); |
---|
| 436 | |
---|
| 437 | $this->disconnect_all(); |
---|
| 438 | |
---|
| 439 | return $result; |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | /** |
---|
| 443 | * Retira uma instância em exceção |
---|
| 444 | * @param $params Parâmetros advindos da chamada Ajax |
---|
| 445 | * @return mixed Array contendo uma mensagem de erro ou um booleano (true) informando que a ação foi feita com sucesso |
---|
| 446 | * @access public |
---|
| 447 | */ |
---|
| 448 | function inboxActionResume($params) |
---|
| 449 | { |
---|
| 450 | $instanceID = (int) $params['instanceID']; |
---|
| 451 | $activityID = (int) $params['activityID']; |
---|
| 452 | $result = true; |
---|
| 453 | |
---|
| 454 | if (!$GLOBALS['ajax']->gui->gui_resume_instance($activityID, $instanceID)) |
---|
| 455 | $result = array('error' => $GLOBALS['ajax']->gui->get_error(false) . "<br />Você não tem permissão para retirar de exceção esta instância."); |
---|
| 456 | |
---|
| 457 | $this->disconnect_all(); |
---|
| 458 | |
---|
| 459 | return $result; |
---|
| 460 | } |
---|
| 461 | |
---|
| 462 | /** |
---|
| 463 | * Aborta uma instância |
---|
| 464 | * @param $params Parâmetros advindos da chamada Ajax |
---|
| 465 | * @return mixed Array contendo uma mensagem de erro ou um booleano (true) informando que a ação foi feita com sucesso |
---|
| 466 | * @access public |
---|
| 467 | */ |
---|
| 468 | function inboxActionAbort($params) |
---|
| 469 | { |
---|
| 470 | $instanceID = (int) $params['instanceID']; |
---|
| 471 | $activityID = (int) $params['activityID']; |
---|
| 472 | $result = true; |
---|
| 473 | |
---|
| 474 | if (!$GLOBALS['ajax']->gui->gui_abort_instance($activityID, $instanceID)) |
---|
| 475 | $result = array('error' => $GLOBALS['ajax']->gui->get_error(false) . "<br />Você não tem permissão para abortar esta instância."); |
---|
| 476 | |
---|
| 477 | $this->disconnect_all(); |
---|
| 478 | |
---|
| 479 | return $result; |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | /** |
---|
| 483 | * Visualiza dados de uma instância |
---|
| 484 | * @param $params Parâmetros advindos da chamada Ajax |
---|
| 485 | * @return mixed Array contendo uma mensagem de erro ou um booleano (true) informando que a ação foi feita com sucesso |
---|
| 486 | * @access public |
---|
| 487 | */ |
---|
| 488 | function inboxActionView($params) |
---|
| 489 | { |
---|
| 490 | $instanceID = $params['instanceID']; |
---|
| 491 | $result = $GLOBALS['ajax']->gui->wf_security->checkUserAction(0, $instanceID, 'view'); |
---|
| 492 | |
---|
| 493 | $errorMessage = $GLOBALS['ajax']->gui->get_error(false); |
---|
| 494 | if (!empty($errorMessage)) |
---|
| 495 | { |
---|
| 496 | $this->disconnect_all(); |
---|
| 497 | return array('error' => $errorMessage); |
---|
| 498 | } |
---|
| 499 | |
---|
[3167] | 500 | $instance = &Factory::newInstance('Instance'); |
---|
[795] | 501 | $instance->getInstance($instanceID); |
---|
| 502 | |
---|
[3167] | 503 | $process = &Factory::newInstance('Process'); |
---|
[795] | 504 | $process->getProcess($instance->pId); |
---|
| 505 | |
---|
| 506 | $result = array( |
---|
| 507 | 'wf_status' => $instance->status, |
---|
| 508 | 'wf_p_id' => $instance->pId, |
---|
| 509 | 'wf_procname' => $process->name, |
---|
| 510 | 'wf_version' => $process->version, |
---|
| 511 | 'wf_instance_id' => $instance->instanceId, |
---|
| 512 | 'wf_priority' => $instance->priority, |
---|
[3167] | 513 | 'wf_owner' => Factory::getInstance('WorkflowLDAP')->getName($instance->owner), |
---|
[795] | 514 | 'wf_next_activity' => $instance->nextActivity, |
---|
[3167] | 515 | 'wf_next_user' => Factory::getInstance('WorkflowLDAP')->getName($instance->nextUser), |
---|
[795] | 516 | 'wf_name' => $instance->name, |
---|
| 517 | 'wf_category' => $instance->category, |
---|
| 518 | 'wf_started' => date('d/m/Y H:i', $instance->started) |
---|
| 519 | ); |
---|
| 520 | |
---|
| 521 | $viewActivityID = $GLOBALS['ajax']->gui->gui_get_process_view_activity($instance->pId); |
---|
| 522 | if ($viewActivityID !== false) |
---|
| 523 | if ($GLOBALS['ajax']->gui->wf_security->checkUserAction($viewActivityID, $instanceID, 'viewrun')) |
---|
| 524 | $result['viewRunAction'] = array('viewActivityID' => $viewActivityID, 'height' => $GLOBALS['ajax']->gui->wf_security->processesConfig[$instance->pId]['iframe_view_height'], 'useHTTPS' => (($_SESSION['phpgw_info']['workflow']['server']['use_https'] > 0) ? $GLOBALS['ajax']->gui->wf_security->processesConfig[$instance->pId]['execute_activities_using_secure_connection'] : 0)); |
---|
| 525 | |
---|
| 526 | if ($instance->ended > 0) |
---|
| 527 | $result['wf_ended'] = date('d/m/Y H:i', $instance->ended); |
---|
| 528 | else |
---|
| 529 | $result['wf_ended'] = ""; |
---|
| 530 | |
---|
[3167] | 531 | $ldap = &Factory::getInstance('WorkflowLDAP'); |
---|
[795] | 532 | foreach ($instance->workitems as $line) |
---|
| 533 | { |
---|
| 534 | $line['wf_duration'] = $this->time_diff($line['wf_ended']-$line['wf_started']); |
---|
| 535 | $line['wf_started'] = date('d/m/Y H:i', $line['wf_started']); |
---|
| 536 | $line['wf_ended'] = date('d/m/Y H:i', $line['wf_ended']); |
---|
| 537 | $line['wf_user'] = $ldap->getName($line['wf_user']); |
---|
| 538 | $result['wf_workitems'][] = $line; |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | foreach ($instance->activities as $line) |
---|
| 542 | { |
---|
| 543 | $line['wf_started'] = date('d/m/Y H:i', $line['wf_started']); |
---|
| 544 | if ($line['wf_ended'] > 0) |
---|
| 545 | $line['wf_ended'] = date('d/m/Y H:i', $line['wf_ended']); |
---|
| 546 | else |
---|
| 547 | $line['wf_ended'] = ""; |
---|
| 548 | $line['wf_user'] = $ldap->getName($line['wf_user']); |
---|
| 549 | $result['wf_activities'][] = $line; |
---|
| 550 | } |
---|
| 551 | |
---|
| 552 | $show_properties = false; |
---|
| 553 | |
---|
| 554 | $current_user_id = $_SESSION['phpgw_info']['workflow']['account_id']; |
---|
| 555 | |
---|
| 556 | /* check if the current user is a process admin */ |
---|
| 557 | $is_admin_process = $GLOBALS['ajax']->acl->check_process_access($current_user_id, $instance->pId); |
---|
| 558 | $is_admin_workflow = $_SESSION['phpgw_info']['workflow']['user_is_admin']; |
---|
| 559 | $show_properties = ($is_admin_process || $is_admin_workflow); |
---|
| 560 | |
---|
| 561 | if($show_properties) |
---|
| 562 | { |
---|
| 563 | foreach ($instance->properties as $key => $value) |
---|
| 564 | { |
---|
| 565 | $result['wf_properties']['keys'][] = $key; |
---|
| 566 | $result['wf_properties']['values'][] = wordwrap(htmlspecialchars($value), 80, "<br>", 1); |
---|
| 567 | } |
---|
| 568 | } |
---|
| 569 | |
---|
| 570 | $this->disconnect_all(); |
---|
| 571 | return $result; |
---|
| 572 | } |
---|
| 573 | |
---|
| 574 | /** |
---|
| 575 | * Retorna os idiomas |
---|
| 576 | * @return array |
---|
| 577 | * @access public |
---|
| 578 | */ |
---|
| 579 | function getLang(){ |
---|
| 580 | |
---|
| 581 | $keys = array(); |
---|
| 582 | $values = array(); |
---|
| 583 | $langs = array(); |
---|
| 584 | foreach($_SESSION['phpgw_info']['workflow']['lang'] as $key => $value) { |
---|
| 585 | $keys[] = $key; |
---|
| 586 | $values[] = $value; |
---|
| 587 | } |
---|
| 588 | array_push($langs,$keys,$values); |
---|
| 589 | return $langs; |
---|
| 590 | } |
---|
| 591 | |
---|
| 592 | /** |
---|
| 593 | * Return a given duration in human readable form, usefull for workitems duration |
---|
| 594 | * |
---|
| 595 | * @param $to |
---|
| 596 | * @return string a given duration in human readable form, usefull for workitems duration |
---|
| 597 | */ |
---|
| 598 | function time_diff($to) { |
---|
| 599 | $days = (int)($to/(24*3600)); |
---|
| 600 | $to = $to - ($days*(24*3600)); |
---|
| 601 | $hours = (int)($to/3600); |
---|
| 602 | $to = $to - ($hours*3600); |
---|
| 603 | $min = date("i", $to); |
---|
| 604 | $to = $to - ($min*60); |
---|
| 605 | $sec = date("s", $to); |
---|
| 606 | |
---|
| 607 | return tra('%1 days, %2:%3:%4',$days,$hours,$min,$sec); |
---|
| 608 | } |
---|
| 609 | |
---|
| 610 | /** |
---|
| 611 | * Instances |
---|
| 612 | * @param $params |
---|
| 613 | * @return string a given duration in human readable form, usefull for workitems duration |
---|
| 614 | * @access public |
---|
| 615 | */ |
---|
| 616 | function instances($params) |
---|
| 617 | { |
---|
| 618 | $preferences = $_SESSION['phpgw_info']['workflow']['user']['preferences']; |
---|
| 619 | |
---|
| 620 | $lightVersion = ((isset($preferences['use_light_interface']) ? $preferences['use_light_interface'] : 0) == 1); |
---|
| 621 | |
---|
| 622 | /* get some parameters */ |
---|
| 623 | $userID = $_SESSION['phpgw_info']['workflow']['account_id']; |
---|
| 624 | $pid = (int) $params['pid']; |
---|
| 625 | $active = ($params['active'] == 1); |
---|
| 626 | |
---|
| 627 | $defaultSorting = ($active ? 'wf_act_started__DESC' : 'wf_started__DESC'); |
---|
| 628 | $availableSortings = $active ? |
---|
| 629 | array('wf_act_started', 'wf_procname', 'wf_name', 'insname') : |
---|
| 630 | array('wf_started', 'wf_ended', 'wf_procname', 'insname'); |
---|
| 631 | |
---|
| 632 | /* define the sorting */ |
---|
| 633 | $sort = $defaultSorting; |
---|
| 634 | if ($params['sort']) |
---|
| 635 | $sort = $params['sort']; |
---|
| 636 | /* make sure that the sorting parameter is one of the expected values */ |
---|
| 637 | $sortFields = explode('__', strtolower($sort)); |
---|
| 638 | if (count($sortFields) != 2) |
---|
| 639 | $sort = $defaultSorting; |
---|
| 640 | else |
---|
| 641 | if (!(in_array($sortFields[0], $availableSortings) && in_array($sortFields[1], array('desc', 'asc')))) |
---|
| 642 | $sort = $defaultSorting; |
---|
| 643 | $params['sort'] = $sort; |
---|
| 644 | |
---|
| 645 | |
---|
| 646 | /* retrieve the results */ |
---|
| 647 | $result = $GLOBALS['ajax']->gui->gui_list_instances_by_owner($userID, 0, -1, $sort, '', '', false, 0, $active, !$active, $active, !$active); |
---|
| 648 | |
---|
| 649 | $errorMessage = $GLOBALS['ajax']->gui->get_error(false); |
---|
| 650 | if (!empty($errorMessage)) |
---|
| 651 | { |
---|
| 652 | $this->disconnect_all(); |
---|
| 653 | return array('error' => $errorMessage); |
---|
| 654 | } |
---|
| 655 | |
---|
| 656 | $output['params'] = $params; |
---|
| 657 | $output['instances'] = array(); |
---|
| 658 | $output['processes'] = array(); |
---|
| 659 | $list_process = array(); |
---|
| 660 | $cod_process = array(); |
---|
| 661 | |
---|
[3167] | 662 | $ldap = &Factory::getInstance('WorkflowLDAP'); |
---|
[795] | 663 | $viewActivitiesID = array(); |
---|
| 664 | foreach ($result['data'] as $row) |
---|
| 665 | { |
---|
| 666 | if (($pid == 0) || ($row['wf_p_id'] == $pid)) |
---|
| 667 | { |
---|
| 668 | $row['wf_started'] = date('d/m/Y H:i', $row['wf_started']); |
---|
| 669 | if ($row['wf_ended']) |
---|
| 670 | $row['wf_ended'] = date('d/m/Y H:i', $row['wf_ended']); |
---|
| 671 | |
---|
| 672 | if ($row['wf_act_started']) |
---|
| 673 | $row['wf_act_started'] = date('d/m/Y H:i', $row['wf_act_started']); |
---|
| 674 | |
---|
| 675 | $row['wf_user_fullname'] = ''; |
---|
| 676 | if ($row['wf_user'] != '*' && $row['wf_user'] != '') |
---|
| 677 | $row['wf_user_fullname'] = $ldap->getName($row['wf_user']); |
---|
| 678 | |
---|
| 679 | /* load information about the view activity */ |
---|
| 680 | if (!isset($viewActivitiesID[$row['wf_p_id']])) |
---|
| 681 | $viewActivitiesID[$row['wf_p_id']] = $GLOBALS['ajax']->gui->gui_get_process_view_activity($row['wf_p_id']); |
---|
| 682 | if ($viewActivitiesID[$row['wf_p_id']] !== false) |
---|
| 683 | if ($GLOBALS['ajax']->gui->wf_security->checkUserAction($viewActivitiesID[$row['wf_p_id']], $row['wf_instance_id'], 'viewrun')) |
---|
| 684 | $row['viewRunAction'] = array('viewActivityID' => $viewActivitiesID[$row['wf_p_id']], 'height' => $GLOBALS['ajax']->gui->wf_security->processesConfig[$instance->pId]['iframe_view_height']); |
---|
| 685 | |
---|
| 686 | $output['instances'][] = $row; |
---|
| 687 | } |
---|
| 688 | $processNameAndVersion = $row['wf_procname'] . " (v" . $row['wf_version'] . ")"; |
---|
| 689 | if (!isset($list_process[$processNameAndVersion])) |
---|
| 690 | $list_process[$processNameAndVersion] = array('total' => 1, 'pid' => $row['wf_p_id'], 'name' => $processNameAndVersion); |
---|
| 691 | else |
---|
| 692 | $list_process[$processNameAndVersion]['total']++; |
---|
| 693 | } |
---|
| 694 | |
---|
| 695 | ksort($list_process); |
---|
| 696 | $output['processes'] = array_values($list_process); |
---|
| 697 | |
---|
| 698 | $userNames = array(); |
---|
| 699 | $processesInfo = array(); |
---|
| 700 | $activityNames = array(); |
---|
| 701 | foreach ($output['instances'] as $key => $value) |
---|
| 702 | { |
---|
| 703 | $userNames[$value['wf_user']] = $value['wf_user_fullname']; |
---|
| 704 | unset($output['instances'][$key]['wf_user_fullname']); |
---|
| 705 | |
---|
| 706 | $processesInfo[$value['wf_p_id']] = array( |
---|
| 707 | 'name' => $value['wf_procname'] . ' (v' . $value['wf_version'] . ')', |
---|
| 708 | 'useHTTPS' => (($_SESSION['phpgw_info']['workflow']['server']['use_https'] > 0) ? $GLOBALS['ajax']->gui->wf_security->processesConfig[$value['wf_p_id']]['execute_activities_using_secure_connection'] : 0) |
---|
| 709 | ); |
---|
| 710 | |
---|
| 711 | if ($active) |
---|
| 712 | { |
---|
| 713 | $activityNames[$value['wf_activity_id']] = $value['wf_name']; |
---|
| 714 | unset($output['instances'][$key]['wf_name']); |
---|
| 715 | } |
---|
| 716 | |
---|
| 717 | if (is_null($value['insname'])) |
---|
| 718 | $output['instances'][$key]['insname'] = ''; |
---|
| 719 | } |
---|
| 720 | |
---|
| 721 | $output['userNames'] = $userNames; |
---|
| 722 | $output['processesInfo'] = $processesInfo; |
---|
| 723 | $output['activityNames'] = $activityNames; |
---|
| 724 | |
---|
| 725 | $output['light'] = $lightVersion; |
---|
| 726 | |
---|
| 727 | if (!isset($params['group_instances'])) |
---|
| 728 | { |
---|
| 729 | /* paginate the result */ |
---|
| 730 | $itemsPerPage = isset($_SESSION['phpgw_info']['workflow']['user']['preferences']['ui_items_per_page']) ? $_SESSION['phpgw_info']['workflow']['user']['preferences']['ui_items_per_page'] : 15; |
---|
[3167] | 731 | $paging = Factory::newInstance('Paging', $itemsPerPage, $_POST); |
---|
[795] | 732 | $output['instances'] = $paging->restrictItems($output['instances']); |
---|
| 733 | $output['paging_links'] = $paging->commonLinks(); |
---|
| 734 | } |
---|
| 735 | else |
---|
| 736 | unset($output['instances']); |
---|
| 737 | |
---|
| 738 | $this->disconnect_all(); |
---|
| 739 | |
---|
| 740 | return $output; |
---|
| 741 | } |
---|
| 742 | |
---|
| 743 | /** |
---|
| 744 | * Aplicacoes externas do usuario |
---|
[3167] | 745 | * @return array |
---|
[795] | 746 | * @access public |
---|
| 747 | */ |
---|
| 748 | function externals() |
---|
| 749 | { |
---|
| 750 | $webserver_url = $_SESSION['phpgw_info']['workflow']['server']['webserver_url']; |
---|
[3167] | 751 | $templateServer = &Factory::getInstance('TemplateServer'); |
---|
[795] | 752 | |
---|
| 753 | /* load the sites that the user can access */ |
---|
| 754 | $allowedSites = $this->so->getExternalApplications(); |
---|
| 755 | |
---|
| 756 | /* prepare the data for the javascript */ |
---|
| 757 | $output = array(); |
---|
| 758 | foreach ($allowedSites as $row) |
---|
| 759 | { |
---|
| 760 | if ($row['image'] == "") |
---|
| 761 | $row['image'] = $templateServer->generateImageLink('navbar.png'); |
---|
| 762 | else |
---|
| 763 | $row['image'] = $webserver_url . '/workflow/redirect.php?file=/external_applications/' . $row['image']; |
---|
| 764 | |
---|
| 765 | if ($row['authentication'] == 1) |
---|
| 766 | $row['wf_ext_link'] = (($_SESSION['phpgw_info']['workflow']['server']['use_https'] > 0) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . "$webserver_url/index.php?menuaction=workflow.external_bridge.render&site=" . $row['external_application_id']; |
---|
| 767 | else |
---|
| 768 | $row['wf_ext_link'] = $row['address']; |
---|
| 769 | |
---|
| 770 | $output[] = $row; |
---|
| 771 | } |
---|
| 772 | |
---|
| 773 | return $output; |
---|
| 774 | } |
---|
| 775 | |
---|
| 776 | /** |
---|
| 777 | * Verifica se o usuário tem acesso ao Organograma (e se o mesmo está ativo) |
---|
| 778 | * @return mixed true em caso de sucesso ou uma array contendo mensagens sobre o problema (não cadastrado ou organograma não ativo) |
---|
| 779 | * @access private |
---|
| 780 | */ |
---|
| 781 | private function checkOrgchartAccess() |
---|
| 782 | { |
---|
| 783 | $this->organizationInfo = $this->so->getUserOrganization($_SESSION['phpgw_info']['workflow']['account_id']); |
---|
| 784 | if ($this->organizationInfo === false) |
---|
| 785 | return array('warning' => 'Você não está cadastrado em nenhuma organização'); |
---|
| 786 | |
---|
| 787 | if ($this->organizationInfo['ativa'] == 'N') |
---|
| 788 | return array('warning' => 'Organograma indisponível'); |
---|
| 789 | |
---|
| 790 | return true; |
---|
| 791 | } |
---|
| 792 | |
---|
| 793 | /** |
---|
| 794 | * Organograma |
---|
| 795 | * @return array com as areas da organizacao |
---|
| 796 | * @access public |
---|
| 797 | */ |
---|
| 798 | function orgchart() |
---|
| 799 | { |
---|
| 800 | /* check for access */ |
---|
| 801 | if (($checkWarnings = $this->checkOrgchartAccess()) !== true) |
---|
| 802 | return $checkWarnings; |
---|
| 803 | |
---|
| 804 | $this->organizationInfo['areas'] = $this->getHierarchicalArea(); |
---|
| 805 | return $this->organizationInfo; |
---|
| 806 | } |
---|
| 807 | |
---|
| 808 | /** |
---|
| 809 | * Retorna a lista de centros de custo |
---|
| 810 | * @return array Lista de centros de custo |
---|
| 811 | * @access public |
---|
| 812 | */ |
---|
| 813 | function getCostCenters() |
---|
| 814 | { |
---|
| 815 | /* check for access */ |
---|
| 816 | if (($checkWarnings = $this->checkOrgchartAccess()) !== true) |
---|
| 817 | return $checkWarnings; |
---|
| 818 | |
---|
| 819 | return $this->so->getCostCenters($this->organizationInfo['organizacao_id']); |
---|
| 820 | } |
---|
| 821 | |
---|
| 822 | /** |
---|
| 823 | * Get the hierarchical Area |
---|
| 824 | * @return array |
---|
| 825 | * @access public |
---|
| 826 | */ |
---|
| 827 | function getHierarchicalArea() |
---|
| 828 | { |
---|
| 829 | /* check for access */ |
---|
| 830 | if (($checkWarnings = $this->checkOrgchartAccess()) !== true) |
---|
| 831 | return $checkWarnings; |
---|
| 832 | |
---|
| 833 | return $this->so->getHierarchicalArea($this->organizationInfo['organizacao_id']); |
---|
| 834 | } |
---|
| 835 | |
---|
| 836 | /** |
---|
| 837 | * Retorna a lista de areas |
---|
| 838 | * @return array lista de areas |
---|
| 839 | * @access public |
---|
| 840 | */ |
---|
| 841 | function getAreaList() |
---|
| 842 | { |
---|
| 843 | /* check for access */ |
---|
| 844 | if (($checkWarnings = $this->checkOrgchartAccess()) !== true) |
---|
| 845 | return $checkWarnings; |
---|
| 846 | |
---|
| 847 | $areas = $this->so->getAreaList($this->organizationInfo['organizacao_id']); |
---|
| 848 | for ($i = 0; $i < count($areas); $i++) |
---|
| 849 | { |
---|
| 850 | $areas[$i]['children'] = false; |
---|
| 851 | $areas[$i]['depth'] = 1; |
---|
| 852 | } |
---|
| 853 | |
---|
| 854 | return $areas; |
---|
| 855 | } |
---|
| 856 | |
---|
| 857 | /** |
---|
| 858 | * Retorna a lista de categorias |
---|
| 859 | * @return array lista de categorias |
---|
| 860 | * @access public |
---|
| 861 | */ |
---|
| 862 | function getCategoriesList() |
---|
| 863 | { |
---|
| 864 | /* check for access */ |
---|
| 865 | if (($checkWarnings = $this->checkOrgchartAccess()) !== true) |
---|
| 866 | return $checkWarnings; |
---|
| 867 | |
---|
| 868 | return $this->so->getCategoriesList($this->organizationInfo['organizacao_id']); |
---|
| 869 | } |
---|
| 870 | |
---|
| 871 | |
---|
| 872 | /** |
---|
| 873 | * Return the area of employee |
---|
| 874 | * @param $params parameters |
---|
| 875 | * @access public |
---|
| 876 | * @return array array of employees |
---|
| 877 | */ |
---|
| 878 | function getAreaEmployees($params) |
---|
| 879 | { |
---|
| 880 | /* check for access */ |
---|
| 881 | if (($checkWarnings = $this->checkOrgchartAccess()) !== true) |
---|
| 882 | return $checkWarnings; |
---|
| 883 | |
---|
| 884 | $employees = $this->so->getAreaEmployees((int) $params['areaID'], $this->organizationInfo['organizacao_id']); |
---|
| 885 | |
---|
| 886 | if ($employees === false) |
---|
| 887 | return array('error' => 'Área não encontrada.'); |
---|
| 888 | |
---|
| 889 | return $employees; |
---|
| 890 | } |
---|
| 891 | |
---|
| 892 | /** |
---|
| 893 | * Return the area of employee |
---|
| 894 | * @param $params parameters |
---|
| 895 | * @access public |
---|
| 896 | * @return array array of employees |
---|
| 897 | */ |
---|
| 898 | function getCategoryEmployees($params) |
---|
| 899 | { |
---|
| 900 | /* check for access */ |
---|
| 901 | if (($checkWarnings = $this->checkOrgchartAccess()) !== true) |
---|
| 902 | return $checkWarnings; |
---|
| 903 | |
---|
| 904 | $employees = $this->so->getCategoryEmployees((int) $params['categoryID'], $this->organizationInfo['organizacao_id']); |
---|
| 905 | |
---|
| 906 | if ($employees === false) |
---|
| 907 | return array('error' => 'Categoria não encontrada.'); |
---|
| 908 | |
---|
| 909 | usort($employees['employees'], create_function('$a,$b', 'return strcasecmp($a[\'cn\'],$b[\'cn\']);')); |
---|
| 910 | |
---|
| 911 | return $employees; |
---|
| 912 | } |
---|
| 913 | |
---|
| 914 | /** |
---|
| 915 | * Search Employee |
---|
| 916 | * @param $params |
---|
| 917 | * @access public |
---|
| 918 | * @return array search result |
---|
| 919 | */ |
---|
| 920 | function searchEmployee($params) |
---|
| 921 | { |
---|
[1470] | 922 | if (!ereg('^([[:alnum:] -]+)$', $params['searchTerm'])) |
---|
[795] | 923 | return array('error' => 'Parâmetro de busca inválido'); |
---|
| 924 | |
---|
| 925 | if (strlen(str_replace(' ', '', $params['searchTerm'])) < 2) |
---|
| 926 | return array('error' => 'Utilize ao menos duas letras em sua busca'); |
---|
| 927 | |
---|
| 928 | /* check for access */ |
---|
| 929 | if (($checkWarnings = $this->checkOrgchartAccess()) !== true) |
---|
| 930 | return $checkWarnings; |
---|
| 931 | |
---|
[3167] | 932 | $result = array(); |
---|
| 933 | |
---|
| 934 | /* do the search */ |
---|
| 935 | $result['bytelephone'] = $this->so->searchEmployeeByTelephone($params['searchTerm'], $this->organizationInfo['organizacao_id']); |
---|
| 936 | $result['employees'] = $this->so->searchEmployeeByName($params['searchTerm'], $this->organizationInfo['organizacao_id']); |
---|
| 937 | $result['bygroup'] = $this->so->searchEmployeeByArea($params['searchTerm'], $this->organizationInfo['organizacao_id']); |
---|
| 938 | |
---|
[795] | 939 | $this->disconnect_all(); |
---|
| 940 | |
---|
[3167] | 941 | /* if all searches returned false */ |
---|
| 942 | if (!is_array($result['employees']) and |
---|
| 943 | !is_array($result['bygroup']) and |
---|
| 944 | !is_array($result['bytelephone'])) |
---|
[795] | 945 | return array('error' => 'O sistema de busca não pode ser utilizado para sua organização'); |
---|
| 946 | |
---|
| 947 | return $result; |
---|
| 948 | } |
---|
| 949 | |
---|
| 950 | /** |
---|
| 951 | * Busca informações sobre um funcionário. |
---|
| 952 | * @param array $params Uma array contendo o ID do funcionário cujas informações serão extraídas. |
---|
| 953 | * @return array Informações sobre o funcionário. |
---|
| 954 | * @access public |
---|
| 955 | */ |
---|
| 956 | function getEmployeeInfo($params) |
---|
| 957 | { |
---|
| 958 | /* check for access */ |
---|
| 959 | if (($checkWarnings = $this->checkOrgchartAccess()) !== true) |
---|
| 960 | return $checkWarnings; |
---|
| 961 | |
---|
| 962 | $result = $this->so->getEmployeeInfo((int) $params['funcionario_id'], $this->organizationInfo['organizacao_id']); |
---|
| 963 | if (is_array($result['info'])) |
---|
| 964 | { |
---|
| 965 | foreach ($result['info'] as $key => $value) |
---|
| 966 | { |
---|
[1277] | 967 | if ( $value['name'] == 'UIDNumber' ) |
---|
[795] | 968 | { |
---|
| 969 | unset($result['info'][$key]); |
---|
| 970 | } |
---|
| 971 | } |
---|
| 972 | $result['info'] = array_values($result['info']); |
---|
| 973 | } |
---|
| 974 | return $result; |
---|
| 975 | } |
---|
| 976 | |
---|
| 977 | /** |
---|
| 978 | * Busca informações sobre uma área. |
---|
| 979 | * @param array $params Uma array contendo o ID da área cujas informações serão extraídas. |
---|
| 980 | * @return array Informações sobre a área. |
---|
| 981 | * @access public |
---|
| 982 | */ |
---|
| 983 | function getAreaInfo($params) |
---|
| 984 | { |
---|
| 985 | /* check for access */ |
---|
| 986 | if (($checkWarnings = $this->checkOrgchartAccess()) !== true) |
---|
| 987 | return $checkWarnings; |
---|
| 988 | |
---|
| 989 | return $this->so->getAreaInfo((int) $params['area_id'], $this->organizationInfo['organizacao_id']); |
---|
| 990 | } |
---|
[1245] | 991 | |
---|
| 992 | /** |
---|
| 993 | * Retorna a lista de telefones úteis da organização |
---|
| 994 | * @return array Lista de telefones |
---|
| 995 | * @access public |
---|
| 996 | */ |
---|
| 997 | function getUsefulPhones( ) |
---|
| 998 | { |
---|
| 999 | /* check for access */ |
---|
| 1000 | if ( ($checkWarnings = $this->checkOrgchartAccess( ) ) !== true ) |
---|
| 1001 | return $checkWarnings; |
---|
| 1002 | |
---|
| 1003 | return $this -> so -> getUsefulPhones( $this -> organizationInfo[ 'organizacao_id' ] ); |
---|
| 1004 | } |
---|
| 1005 | |
---|
| 1006 | /** |
---|
| 1007 | * Retorna a lista as áreas com substituição de chefia |
---|
| 1008 | * @return array Lista das áreas com substituição de chefia |
---|
| 1009 | * @access public |
---|
| 1010 | */ |
---|
| 1011 | function getAreaWithSubtituteBoss( ) |
---|
| 1012 | { |
---|
| 1013 | /* check for access */ |
---|
| 1014 | if ( ($checkWarnings = $this->checkOrgchartAccess( ) ) !== true ) |
---|
| 1015 | return $checkWarnings; |
---|
| 1016 | |
---|
| 1017 | return $this -> so -> getAreaWithSubtituteBoss( $this -> organizationInfo[ 'organizacao_id' ] ); |
---|
| 1018 | } |
---|
[1266] | 1019 | |
---|
| 1020 | /** |
---|
| 1021 | * Retorna a lista de localidades |
---|
| 1022 | * @return array lista de localidades |
---|
| 1023 | * @access public |
---|
| 1024 | */ |
---|
| 1025 | function getManning( ) |
---|
| 1026 | { |
---|
| 1027 | /* check for access */ |
---|
| 1028 | if ( ( $checkWarnings = $this->checkOrgchartAccess( ) ) !== true ) |
---|
| 1029 | return $checkWarnings; |
---|
| 1030 | |
---|
| 1031 | return $this -> so -> getManning( $this -> organizationInfo[ 'organizacao_id' ] ); |
---|
| 1032 | } |
---|
| 1033 | |
---|
| 1034 | /** |
---|
| 1035 | * Return the employees of a manning |
---|
| 1036 | * @param $params parameters |
---|
| 1037 | * @access public |
---|
| 1038 | * @return array array of employees |
---|
| 1039 | */ |
---|
| 1040 | function getManningEmployees( $params ) |
---|
| 1041 | { |
---|
| 1042 | /* check for access */ |
---|
| 1043 | if ( ( $checkWarnings = $this -> checkOrgchartAccess( ) ) !== true ) |
---|
| 1044 | return $checkWarnings; |
---|
| 1045 | |
---|
| 1046 | $employees = $this -> so -> getManningEmployees( ( int ) $params[ 'locationID' ], $this -> organizationInfo[ 'organizacao_id' ] ); |
---|
| 1047 | |
---|
| 1048 | if ( $employees === false ) |
---|
| 1049 | return array( 'error' => 'Localidade não encontrada.' ); |
---|
| 1050 | |
---|
[1269] | 1051 | return $employees; |
---|
| 1052 | } |
---|
[1266] | 1053 | |
---|
[1269] | 1054 | /** |
---|
| 1055 | * Return the list of employees in alphabetical order |
---|
| 1056 | * @access public |
---|
| 1057 | * @return array array of employees |
---|
| 1058 | */ |
---|
| 1059 | function getAlphabeticalEmployees( ) |
---|
| 1060 | { |
---|
| 1061 | /* check for access */ |
---|
| 1062 | if ( ( $checkWarnings = $this -> checkOrgchartAccess( ) ) !== true ) |
---|
| 1063 | return $checkWarnings; |
---|
| 1064 | |
---|
| 1065 | $employees = $this -> so -> getAlphabeticalEmployees( $this -> organizationInfo[ 'organizacao_id' ] ); |
---|
| 1066 | |
---|
| 1067 | if ( $employees === false ) |
---|
| 1068 | return array( 'error' => 'Localidade não encontrada.' ); |
---|
| 1069 | |
---|
[1266] | 1070 | return $employees; |
---|
| 1071 | } |
---|
[1446] | 1072 | |
---|
| 1073 | function callVoipConnect($params) |
---|
| 1074 | { |
---|
[3167] | 1075 | $cachedLDAP = Factory::newInstance('CachedLDAP'); |
---|
[1446] | 1076 | $cachedLDAP->setOperationMode($cachedLDAP->OPERATION_MODE_LDAP); |
---|
| 1077 | |
---|
| 1078 | $entry = $cachedLDAP->getEntryByID( $_SESSION['phpgw_info']['workflow']['account_id'] ); |
---|
| 1079 | if ( $entry && ! is_null($entry['telephonenumber']) ) |
---|
| 1080 | $fromNumber = $entry['telephonenumber']; |
---|
| 1081 | |
---|
| 1082 | if ( $fromNumber == false ) |
---|
| 1083 | return false; |
---|
| 1084 | |
---|
| 1085 | $toNumber = $params['to']; |
---|
| 1086 | |
---|
| 1087 | $voipServer = $_SESSION['phpgw_info']['workflow']['server']['voip_server']; |
---|
| 1088 | $voipUrl = $_SESSION['phpgw_info']['workflow']['server']['voip_url']; |
---|
| 1089 | $voipPort = $_SESSION['phpgw_info']['workflow']['server']['voip_port']; |
---|
| 1090 | |
---|
| 1091 | if(!$voipServer || !$voipUrl || !$voipPort) |
---|
| 1092 | return false; |
---|
| 1093 | |
---|
| 1094 | $url = "http://".$voipServer.":".$voipPort.$voipUrl."?magic=1333&acao=liga&ramal=".$fromNumber."&numero=".$toNumber; |
---|
| 1095 | $sMethod = 'GET '; |
---|
| 1096 | $crlf = "\r\n"; |
---|
| 1097 | $sRequest = " HTTP/1.1" . $crlf; |
---|
| 1098 | $sRequest .= "Host: localhost" . $crlf; |
---|
| 1099 | $sRequest .= "Accept: */* " . $crlf; |
---|
| 1100 | $sRequest .= "Connection: Close" . $crlf . $crlf; |
---|
| 1101 | $sRequest = $sMethod . $url . $sRequest; |
---|
| 1102 | $sockHttp = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); |
---|
| 1103 | if (!$sockHttp) { |
---|
| 1104 | return false; |
---|
| 1105 | } |
---|
| 1106 | $resSocketConnect = socket_connect($sockHttp, $voipServer, $voipPort); |
---|
| 1107 | if (!$resSocketConnect) { |
---|
| 1108 | return false; |
---|
| 1109 | } |
---|
| 1110 | $resSocketWrite = socket_write($sockHttp, $sRequest, strlen($sRequest)); |
---|
| 1111 | if (!$resSocketWrite) { |
---|
| 1112 | return false; |
---|
| 1113 | } |
---|
| 1114 | $sResponse = ''; |
---|
| 1115 | while ($sRead = socket_read($sockHttp, 512)) { |
---|
| 1116 | $sResponse .= $sRead; |
---|
| 1117 | } |
---|
| 1118 | |
---|
| 1119 | socket_close($sockHttp); |
---|
| 1120 | $pos = strpos($sResponse, $crlf . $crlf); |
---|
| 1121 | return substr($sResponse, $pos + 2 * strlen($crlf)); |
---|
| 1122 | } |
---|
[1451] | 1123 | |
---|
| 1124 | function isVoipEnabled( ) |
---|
| 1125 | { |
---|
| 1126 | $voip_enabled = false; |
---|
| 1127 | $voip_groups = array(); |
---|
[1452] | 1128 | if ( $_SESSION['phpgw_info']['workflow']['voip_groups'] ) |
---|
[1451] | 1129 | { |
---|
[1452] | 1130 | foreach ( explode(",",$_SESSION['phpgw_info']['workflow']['voip_groups']) as $i => $voip_group ) |
---|
[1451] | 1131 | { |
---|
| 1132 | $a_voip = explode(";",$voip_group); |
---|
| 1133 | $voip_groups[] = $a_voip[1]; |
---|
| 1134 | } |
---|
| 1135 | |
---|
[1452] | 1136 | foreach($_SESSION['phpgw_info']['workflow']['user_groups'] as $idx => $group) |
---|
[1451] | 1137 | { |
---|
[1452] | 1138 | if(array_search($group,$voip_groups) !== FALSE) |
---|
[1451] | 1139 | { |
---|
| 1140 | $voip_enabled = true; |
---|
| 1141 | break; |
---|
| 1142 | } |
---|
| 1143 | } |
---|
| 1144 | } |
---|
| 1145 | |
---|
| 1146 | return ( $voip_enabled ) ? 'VoipIsEnabled' : 'VoipIsDisabled'; |
---|
| 1147 | } |
---|
[795] | 1148 | } |
---|
| 1149 | ?> |
---|