[795] | 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 'common.inc.php'; |
---|
| 14 | require_once 'engine/class.ajax_config.inc.php'; |
---|
| 15 | require_once 'engine/config.ajax.inc.php'; |
---|
| 16 | /** |
---|
| 17 | * Cria o ambiente de sessão para rodar Ajax e implementa alguns métodos |
---|
| 18 | * básicos para inclusão de JavaScript e CSS |
---|
| 19 | * |
---|
| 20 | * @package Workflow |
---|
| 21 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 22 | * @author Mauricio Luiz Viani - viani@celepar.pr.gov.br |
---|
| 23 | */ |
---|
| 24 | class ui_ajaxinterface |
---|
| 25 | { |
---|
| 26 | /** |
---|
| 27 | * @var int $num_version Identifica a verão dos arquivos JavaScript e CSS. Incremente o valor deste atribuito |
---|
| 28 | * sempre que existirem alterações nos arquivos, para forçar o download pelo browser |
---|
| 29 | * @access public |
---|
| 30 | */ |
---|
| 31 | var $num_version = 213; |
---|
| 32 | |
---|
| 33 | /** |
---|
| 34 | * Construtor |
---|
| 35 | * @access public |
---|
| 36 | * @return object |
---|
| 37 | */ |
---|
| 38 | function ui_ajaxinterface() |
---|
| 39 | { |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | * Coloca na variável de sessão todas as informações que serão necessárias para |
---|
| 44 | * rodar os métodos acionados pelas requisições Ajax. |
---|
| 45 | * |
---|
| 46 | * @return void |
---|
| 47 | * @access public |
---|
| 48 | */ |
---|
| 49 | function set_wf_session() |
---|
| 50 | { |
---|
[3167] | 51 | $acl = Factory::getInstance('workflow_acl'); |
---|
[795] | 52 | $_SESSION['phpgw_info']['workflow']['server_root'] = PHPGW_SERVER_ROOT; |
---|
| 53 | $_SESSION['phpgw_info']['workflow']['phpgw_api_inc'] = PHPGW_API_INC; |
---|
| 54 | $_SESSION['phpgw_info']['workflow']['phpgw_include_root'] = PHPGW_INCLUDE_ROOT; |
---|
| 55 | $vfs = createobject('phpgwapi.vfs'); |
---|
| 56 | $_SESSION['phpgw_info']['workflow']['vfs_basedir'] = $vfs->basedir; |
---|
[3167] | 57 | $_SESSION['phpgw_info']['workflow']['server'] = $GLOBALS['phpgw_info']['server']; |
---|
[795] | 58 | $_SESSION['phpgw_info']['workflow']['lang'] = $GLOBALS['lang']; |
---|
| 59 | $_SESSION['phpgw_info']['workflow']['account_id'] = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
[3167] | 60 | $_SESSION['phpgw_info']['workflow']['user_groups'] = Factory::getInstance('WorkflowLDAP')->getUserGroups($GLOBALS['phpgw_info']['user']['account_id']); |
---|
[795] | 61 | $user_is_admin = $acl->checkWorkflowAdmin($GLOBALS['phpgw_info']['user']['account_id']); |
---|
[3167] | 62 | $_SESSION['phpgw_info']['workflow']['user_is_admin'] = $user_is_admin; |
---|
[795] | 63 | $_SESSION['phpgw_info']['workflow']['user_can_admin_process'] = ($user_is_admin || ($GLOBALS['phpgw']->acl->check('admin_workflow',1,'workflow'))); |
---|
[3167] | 64 | $_SESSION['phpgw_info']['workflow']['user_can_admin_instance'] = ($user_is_admin || ($GLOBALS['phpgw']->acl->check('admin_instance_workflow',1,'workflow'))); |
---|
[795] | 65 | |
---|
| 66 | $can_monitor = $acl->checkUserGroupAccessToType('MON', $GLOBALS['phpgw_info']['user']['account_id']); |
---|
| 67 | $_SESSION['phpgw_info']['workflow']['user_can_monitor'] = ($user_is_admin || $can_monitor); |
---|
| 68 | $_SESSION['phpgw_info']['workflow']['user_can_clean_instances'] = $_SESSION['phpgw_info']['workflow']['user_can_monitor']; |
---|
| 69 | $_SESSION['phpgw_info']['workflow']['user_can_clean_aborted_instances'] = $_SESSION['phpgw_info']['workflow']['user_can_monitor']; |
---|
| 70 | $_SESSION['phpgw_info']['workflow']['user']['preferences'] = $GLOBALS['phpgw_info']['user']['preferences']['workflow']; |
---|
[1452] | 71 | $_SESSION['phpgw_info']['workflow']['voip_groups'] = $GLOBALS['phpgw_info']['server']['voip_groups']; |
---|
[795] | 72 | } |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | * Insere código html para incorporar arquivos JavaScript de uso comum |
---|
| 76 | * |
---|
| 77 | * @return string codigo html para insercao do javascript |
---|
| 78 | * @access public |
---|
| 79 | */ |
---|
| 80 | function get_common_js() |
---|
| 81 | { |
---|
| 82 | $result = "<script language='javascript'>var _web_server_url = '" . $GLOBALS['phpgw_info']['server']['webserver_url'] . "';</script>"; |
---|
| 83 | $result = $result . $this->get_js_link('workflow','jscode', 'globals'); |
---|
| 84 | $result = $result . $this->get_js_link('workflow','jscode', 'common_functions'); |
---|
| 85 | $result = $result . $this->get_js_link('workflow','jscode', 'abas'); |
---|
| 86 | $result = $result . $this->get_js_link('workflow','jscode', 'connector'); |
---|
| 87 | $result = $result . $this->get_js_link('workflow','jscode', 'sniff_browser'); |
---|
| 88 | $result = $result . $this->get_js_link('workflow','jscode', 'wz_dragdrop'); |
---|
| 89 | $result = $result . $this->get_js_link('workflow','jscode', 'dJSWin'); |
---|
| 90 | $result = $result . $this->get_js_link('workflow','jscode', 'doiMenuDOM'); |
---|
| 91 | |
---|
| 92 | return $result; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | /** |
---|
| 96 | * Insere o código html para inclusão do arquivo de estilo common.css |
---|
| 97 | * |
---|
| 98 | * @return string tag html completa para inserção do arquivo common.css |
---|
| 99 | * @access public |
---|
| 100 | */ |
---|
| 101 | function get_common_css() |
---|
| 102 | { |
---|
| 103 | return $this->get_css_link('common'); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | /** |
---|
| 107 | * Insere o código html para inclusão de um arquivo de folha de estilo. Primeiramente |
---|
| 108 | * procura o arquivo no template do usuário. Se não encontrado monta o link para o |
---|
| 109 | * template default. |
---|
| 110 | * |
---|
| 111 | * @param string $CSSName nome do arquivo de folha de estilo. |
---|
| 112 | * @param string $mediaType o tipo de mídia (padrão: all) |
---|
| 113 | * @return string tag html completa para inserção do arquivo solicitado |
---|
| 114 | * @access public |
---|
| 115 | */ |
---|
| 116 | function get_css_link($CSSName, $mediaType = 'all') |
---|
| 117 | { |
---|
| 118 | $CSSName = "css/{$CSSName}.css"; |
---|
[3167] | 119 | $templateServer = &Factory::getInstance('TemplateServer'); |
---|
[795] | 120 | $CSSLink = $templateServer->getWebFile($CSSName); |
---|
| 121 | $CSSFile = $templateServer->getSystemFile($CSSName); |
---|
| 122 | |
---|
| 123 | return '<link href="' . $CSSLink . '?' . (file_exists($CSSFile) ? filesize($CSSFile) : $this->num_version) . '" type="text/css" rel="StyleSheet" media="' . $mediaType . '">'; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | /** |
---|
| 127 | * Insere o código html para inclusão de um arquivo JavaScript. |
---|
| 128 | * |
---|
| 129 | * @param string $module nome do módulo do eGroupware (preferencialmente workflow) |
---|
| 130 | * @param string $js_package nome do grupamento de arquivos javascript |
---|
| 131 | * @param string $js_name nome do arquivo javascript |
---|
| 132 | * @param array $params parametros |
---|
| 133 | * @return string tag html completa para inserção do arquivo solicitado |
---|
| 134 | * @access public |
---|
| 135 | */ |
---|
| 136 | function get_js_link($module, $js_package, $js_name, $params = null) |
---|
| 137 | { |
---|
| 138 | if (is_null($params)) |
---|
| 139 | $params = array(); |
---|
| 140 | else |
---|
| 141 | if (!is_array($params)) |
---|
| 142 | $params = array($params); |
---|
| 143 | |
---|
| 144 | $localFile = $_SESSION['phpgw_info']['workflow']['server_root'] . SEP . $module . SEP . 'js' . SEP . $js_package . SEP . $js_name.'.js'; |
---|
| 145 | if (@file_exists($localFile)) |
---|
| 146 | $params[] = filesize($localFile); |
---|
| 147 | else |
---|
| 148 | $params[] = $this->num_version; |
---|
| 149 | $js_file = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.$module.SEP.'js'.SEP.$js_package.SEP.$js_name.'.js'; |
---|
| 150 | return '<script src="'.$js_file.'?'.implode('&', $params).'" type="text/javascript"></script>'; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | /** |
---|
| 154 | * Executa a função inicial JavaScript que irá montar os dados da interface. |
---|
| 155 | * |
---|
| 156 | * @param string $param nome da função JavaScript |
---|
| 157 | * @return string tag html completa com a chamada da função |
---|
| 158 | * @access public |
---|
| 159 | */ |
---|
| 160 | function run_init_script($param) |
---|
| 161 | { |
---|
| 162 | return '<script language="javascript">' . $param . '</script>'; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | } |
---|
| 166 | ?> |
---|