cacic_common.class.php
10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
/**
* @version $Id: cacic_common.class.php,v 1.1.1.1 2012/09/14 16:01:08 d302112 Exp $
* @package CACIC-Admin
* @subpackage AdminSetup
* @author Adriano dos Santos Vieira <harpiain at gmail.com>
* @copyright Copyright (C) 2008 Adriano dos Santos Vieira. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* CACIC is free software and parts of it may contain or be derived from the
* GNU General Public License or other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// direct access is denied
defined( 'CACIC' ) or die( 'Acesso restrito (Restricted access)!' );
/*
* Classe de templates
*/
if( ! @include("pat/patErrorManager.php") )
{
die('Erro na inclusão da biblioteca patTemplate! (patTemplate include error!).');
}
if( ! @include("pat/patError.php") )
{
die('Erro na inclusão da biblioteca patTemplate! (patTemplate include error!).');
}
if( ! @include("pat/patTemplate.php") )
{
die('Erro na inclusão da biblioteca patTemplate! (patTemplate include error!).');
}
/*
* Uma classe para implementar segurança em transações
*/
define( 'SECURITY', 1 );
require_once('security/security.php');
/**
* Dados de configuração para o CACIC
*/
unset($cacic_common);
define(DISABLED, 'disabled');
/**
* Classe para definições de configurações
*/
class Cacic_Common extends patTemplate {
var $setup_type;
/**
* Componente (objeto) para traduções
*/
var $oTranslator;
/**
* Componente (objeto) para acesso a banco de dados
*/
var $db_link;
/**
* Itens por página em paginação
*/
var $pagination_items = 20;
/**
* Conterá a página apresentada (corrente)
*/
var $pagination_current_page;
/**
* Conterá a quantidade total de itens a serem mostrados
*/
var $pagination_total_items;
function Cacic_Common() {
global $oTranslator, $ip_servidor, $usuario_bd, $senha_usuario_bd, $nome_bd;
$this->db_link = mysql_connect( $ip_servidor, $usuario_bd, $senha_usuario_bd);
mysql_select_db($nome_bd,$this->db_link);
parent::patTemplate();
$this->oTranslator = $oTranslator;
/*
* Inicializa template
*/
$this->setNamespace('cacicCommon');
$this->setRoot(dirname(__FILE__));
$this->readTemplatesFromInput('cacic_common_01.tmpl.php');
$this->addVar('CacicCommon_head', 'CACIC_TITLE', $this->oTranslator->_('Configuracao Basica') );
$this->addVar('CacicCommon_head', 'CACIC_LANG', CACIC_LANGUAGE );
$this->addVar('CacicCommon_head', 'CACIC_LANG_CHARSET', CACIC_LANG_CHARSET );
$this->addVar('CacicCommon_head', 'CACIC_THEME', CACIC_THEME );
$this->addVar('CacicCommon_head', 'CACIC_URL', CACIC_URL );
$this->addVar('CacicCommon_messages', 'MESSAGES', $this->oTranslator->_('Mensagens') );
// Monta paginação
$this->addVar('CacicCommon_pagination', 'PAGE_TITLE', $this->oTranslator->_('Paginacao') );
$this->addVar('CacicCommon_pagination_first', 'PAGE_TEXT', $this->oTranslator->_('Primeira') );
$this->addVar('CacicCommon_pagination_first', 'PAGE_TEXT_TITLE', $this->oTranslator->_('Primeira pagina') );
$this->addVar('CacicCommon_pagination_back', 'PAGE_TEXT', $this->oTranslator->_('Anterior') );
$this->addVar('CacicCommon_pagination_back', 'PAGE_TEXT_TITLE', $this->oTranslator->_('Pagina anterior') );
$this->addVar('CacicCommon_pagination_next', 'PAGE_TEXT', $this->oTranslator->_('Proxima') );
$this->addVar('CacicCommon_pagination_next', 'PAGE_TEXT_TITLE', $this->oTranslator->_('Proxima pagina') );
$this->addVar('CacicCommon_pagination_last', 'PAGE_TEXT', $this->oTranslator->_('Ultima') );
$this->addVar('CacicCommon_pagination_last', 'PAGE_TEXT_TITLE', $this->oTranslator->_('Ultima pagina') );
}
/**
* Armazena na "sessao" os dados de configuração comuns
* @access protected
*/
function setup() {
global $cacic_common;
$cacic_common['common'] = 'Declaracoes comuns ao sistema';
}
/**
* Atribui título da página
* @param string $_title Título a ser atríbuido à pagina
* @access protected
*/
function setPageTitle($_title) {
$this->clearVar('CacicCommon_head', 'CACIC_TITLE');
$this->addVar('CacicCommon_head', 'CACIC_TITLE', $_title );
}
/**
* Verifica se é usuário administrador
* @access protected
*/
function isAdminUser() {
$is_admin_user = false;
$is_admin_user = ($_SESSION['cs_nivel_administracao']==1);
return $is_admin_user;
}
/**
* Atribui o tipo de configuração a ser processada
* @access protected
* @param string $msg A mensagem a ser mostrada
* @param boolean $js Mostra mensagem usando recurso de javascript
*/
function setMessageText($_msg, $_js=false) {
$this->clearVar('CacicCommon_messages_cond', 'MESSAGE');
if($_js)
$this->addVar('CacicCommon_messages_cond', 'msgtype', 'js' );
$this->addVar('CacicCommon_messages_cond', 'MESSAGE', $_msg );
}
/**
* Lança execeção se ocorrer erro
* @access protected
*/
function throwError($_msg) {
throw new Exception($_msg);
}
/**
* Obtem e preenche dados de paginacao
* @access private
* @param string $btn_salvar Se botao para salvar foi acionado
*/
function fillPagination($_total_items) {
// Monta paginação
$_page_to_show = Security::getInt('page');
if(!$_page_to_show)
$_page_to_show = 1;
$this->setPageCurrent($_page_to_show);
if($_total_items)
$this->setPageTotalItems($_total_items);
$this->addVar('CacicCommon_pagination', 'PAGE_CURRENT', $_page_to_show );
$show = (($this->getPageCurrent()==1 or $this->getPageCurrent()==0)?DISABLED:true);
$this->addVar('CacicCommon_pagination_first', 'SHOW', $show ); // SHOW: true, false, DISABLED
$this->addVar('CacicCommon_pagination_first', 'PAGE_NUMBER', 1 );
$this->addVar('CacicCommon_pagination_back', 'SHOW', $show );
$this->addVar('CacicCommon_pagination_back', 'PAGE_NUMBER', $this->getPageBack() );
$this->addRows('CacicCommon_pages_list_cond', $this->pages2Show($_page_to_show, 10) );
$show = (($this->getPageNext()==$this->getPageLast())?DISABLED:true);
$this->addVar('CacicCommon_pagination_next', 'SHOW', $show );
$this->addVar('CacicCommon_pagination_next', 'PAGE_NUMBER', $this->getPageNext() );
$show = (($this->getPageLast()==$this->getPageCurrent())?DISABLED:true);
$this->addVar('CacicCommon_pagination_last', 'SHOW', $show );
$this->addVar('CacicCommon_pagination_last', 'PAGE_NUMBER', $this->getPageLast() );
return $_page_to_show;
}
/**
* Atribui número de itens por página
*/
function setPageItems($_page_items) {
$this->pagination_items = $_page_items;
}
/**
* Atribui número total de itens a paginar
*/
function setPageTotalItems($_total_items) {
$this->pagination_total_items = $_total_items;
}
/**
* Obtem número de itens por página
*/
function getPageItems() {
return $this->pagination_items;
}
/**
* Obtem número da página anterior
*/
function getPageBack() {
$page_back = ($this->pagination_current_page-1)<=0?1:$this->pagination_current_page-1;
return $page_back;
}
/**
* Obtem número da próxima página
*/
function getPageNext() {
$page_next = ($this->pagination_current_page+1)>$this->getPageLast()?$this->getPageLast():$this->pagination_current_page+1;
return $page_next;
}
/**
* Obtem número da última página
*/
function getPageLast() {
$page_last = (int)($this->pagination_total_items / $this->pagination_items);
return $page_last;
}
/**
* Atribui número da página atual (corrente)
*/
function setPageCurrent($_page_current) {
$_page_current = ($_page_current?$_page_current:Security::getInt('page'));
$this->pagination_current_page = $_page_current;
}
/**
* Obtem número da página atual (corrente)
*/
function getPageCurrent() {
return $this->pagination_current_page;
}
/**
* Obtem número de itens por página (corrente ou de uma dada)
*/
function getPageFristItem($_page) {
$ret = ($this->pagination_current_page - 1) * $this->pagination_items;
if($_page)
$ret = ($_page - 1) * $this->pagination_items;
$ret = ($ret<=0?0:$ret);
return $ret;
}
/**
* Prepara dados de paginacao
* @access private
* @param string $btn_salvar Se botao para salvar foi acionado
*/
function pages2Show( $_pages_to_show, $_count) {
if($_pages_to_show<=0) {
$_current_page = 1;
$_pages_to_show = 1;
}
else
$_current_page = $_pages_to_show;
$count = 0;
$_pages_to_show = $_pages_to_show - (int)( $_count / 2);
$_pages_to_show = $_pages_to_show<=0?$_current_page:$_pages_to_show;
$pages_show = array();
while ($count < $_count) {
$count++;
$class_current_page = ($_pages_to_show==$_current_page?'currentpage':'');
$pages = array( array( 'PAGE_TEXT' => $this->oTranslator->_($_pages_to_show),
'PAGE_NUMBER'=> $_pages_to_show,
'DISABLED'=>($class_current_page?DISABLED:false),
'CLASS_CURRENT_PAGE'=>$class_current_page
)
);
$pages_show = array_merge($pages_show, $pages);
$_pages_to_show++;
}
return $pages_show;
}
/**
* Dump de variaceis
* @access protected
*/
function varDump($_var) {
echo "<pre>";
var_dump($_var);
echo "</pre>";
}
}
?>