-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathini.php
322 lines (279 loc) · 12 KB
/
ini.php
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
320
321
322
<?php
require_once('Zend/Cache.php');
if (!isset($_SESSION)) session_start();
$con = mysql_connect("localhost", "miguel", "miguel");
mysql_select_db("PED", $con);
/**
* Este tipo de ligação é necessário para se coneguir realizar transações
*/
$link = mysqli_connect("localhost", "miguel", "miguel", "PED");
// variavel que indica o caminho onde os indices do Zend_Search_Lucene estao
basename(getcwd()) == 'PED-Project'?$indexPath = 'data/docindex':$indexPath='../data/docindex';
/* * ****************
* CONSTANTES *
* **************** */
// Listagem
$num_proj = 10;
$num_sup = 5;
// Megaprocessos
$adm = "Administracao";
$dis = "Disseminacao";
$ing = "Ingestao";
// Interface de Administracao
$ins = "Insercao";
$alt = "Alteracao";
$rem = "Remocao";
$lis = "Listagem";
$exp = "Exportacao";
// Dados
$uti = "Utilizador";
$pro = "Projeto";
$aut = "Autor";
$sup = "Supervisor";
$sip = "SIP";
// Hash que contem todas as accoes e respectivas descricoes que podem ser escritas no log
$log_msg = array(
"lis_uti" => array("act" => "$adm:$lis:$uti", "desc" => "Tarefa de $adm: $lis de $uti"."es"),
"ins_uti" => array("act" => "$adm:$ins:$uti", "desc" => "Tarefa de $adm: $ins do $uti"),
"alt_uti" => array("act" => "$adm:$alt:$uti", "desc" => "Tarefa de $adm: $alt do $uti"),
"rem_uti" => array("act" => "$adm:$rem:$uti", "desc" => "Tarefa de $adm: $rem do $uti"),
"lis_as" => array("act" => "$adm:$lis:$aut$sup", "desc" => "Tarefa de $adm: $lis de $aut"."es e $sup"."es"),
"ins_aut" => array("act" => "$adm:$ins:$aut", "desc" => "Tarefa de $adm: $ins do $aut"),
"alt_aut" => array("act" => "$adm:$alt:$aut", "desc" => "Tarefa de $adm: $alt do $aut"),
"rem_aut" => array("act" => "$adm:$rem:$aut", "desc" => "Tarefa de $adm: $rem do $aut"),
"ins_sup" => array("act" => "$adm:$ins:$sup", "desc" => "Tarefa de $adm: $ins do $sup"),
"alt_sup" => array("act" => "$adm:$alt:$sup", "desc" => "Tarefa de $adm: $alt do $sup"),
"rem_sup" => array("act" => "$adm:$rem:$sup", "desc" => "Tarefa de $adm: $rem do $sup"),
"lis_aut" => array("act" => "$adm:$lis:$aut", "desc" => "Tarefa de $adm: $lis do $aut"),
"lis_sup" => array("act" => "$adm:$lis:$sup", "desc" => "Tarefa de $adm: $lis do $sup"),
"lis_pros" => array("act" => "$adm:$lis:$pro"."s", "desc" => "Tarefa de $adm: $lis de $pro"."s"),
"lis_pro" => array("act" => "$adm:$lis:$pro", "desc" => "Tarefa de $adm: $lis do $pro"),
"lis_dis_as" => array("act" => "$dis:$lis:$aut$sup", "desc" => "Tarefa de $dis: $lis de $aut"."es e $sup"."es"),
"lis_dis_aut" => array("act" => "$dis:$lis:$aut", "desc" => "Tarefa de $dis: $lis do $aut"),
"lis_dis_sup" => array("act" => "$dis:$lis:$sup", "desc" => "Tarefa de $dis: $lis do $sup"),
"lis_dis_pros" => array("act" => "$dis:$lis:$pro"."s", "desc" => "Tarefa de $dis: $lis de $pro"."s"),
"lis_dis_pro" => array("act" => "$dis:$lis:$pro", "desc" => "Tarefa de $dis: $lis do $pro"),
"lis_dis_uti" => array("act" => "$dis:$lis:$uti", "desc" => "Tarefa de $dis: $lis de $uti"."es"),
"login" => array("act" => "Login", "desc" => "Login no sistema pelo $uti"),
"ing_sip" => array("act" => "$ing:$sip", "desc" => "Tarefa de $ing de um $sip no sistema pelo $uti"),
"dis_exp" => array("act" => "$dis:$exp", "desc" => "Tarefa de $dis: $exp do projeto"),
"dis_exp_tot" => array("act" => "$dis:$exp:Total", "desc" => "Tarefa de $dis: $exp do repositório"),
"rem_pro" => array("act" => "$adm:$rem:$pro", "desc" => "Tarefa de $adm: $rem do $pro"));
/* * ****************
* MINHAS FUNÇÕES *
* **************** */
function go_back() {
echo "<span class=\"go_back\"><A HREF=\"javascript:javascript:history.go(-1)\">Voltar</A></span>";
}
// Funcao que devolve a hora atual
function agora() {
date_default_timezone_set("Europe/Lisbon");
return date("Y-m-d\TH:i:s");
}
/* -------------------------------------------------------------------------------------------------- */
/* ------------------------------------------ Logs -------------------------------------------------- */
/* -------------------------------------------------------------------------------------------------- */
// Ordena os logs por ordem decrescente de insercao
function log_reverse() {
$doc = new DOMDocument(); // DOM xml
$doc->load('logs.xml');
$xslt = new XSLTProcessor();
$XSL = new DOMDocument();
$XSL->load('logs_sort.xsl', LIBXML_NOCDATA);
$xslt->importStylesheet($XSL);
$fh = fopen("logs_sorted.xml", 'w') or die("can't open file");
fwrite($fh, $xslt->transformToXML($doc));
fclose($fh);
}
// verifica se o ficheiro de logs existe no sistema de ficheiros
function log_exists($l) {
if (!file_exists($l)) {
$fh = fopen($l, 'w') or die("can't open file");
fwrite($fh, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><logs></logs>");
fclose($fh);
}
}
// insere no final do ficheiro de logs
function log_insert($username, $name, $date, $action, $description) {
log_exists("../logs/logs.xml");
$logs = simplexml_load_file("../logs/logs.xml");
$log = $logs->addChild('log');
$log->addChild('username', utf8_decode($username)); //TODO:caracteres estranhos sao subsituidos por '?'
$log->addChild('name', utf8_decode($name));
$log->addChild('date', utf8_decode($date));
$log->addChild('action', utf8_decode($action));
$log->addChild('description', utf8_decode($description));
$logs->asXML("../logs/logs.xml");
}
/** Retorna os logs correspondentes a uma página **/
function log_page($start, $per_page) {
$log_file = "../logs/logs_sorted.xml";
log_exists($log_file);
$logs = simplexml_load_file($log_file);
$str="<table class=\"user\"><tr class=\"user\"><th class=\"user\">Username</th><th class=\"user\">Nome</th><th class=\"user\">Data</th><th class=\"user\">Acao</th><th class=\"user\">Descricao</th></tr>";
for ($i = 0; $i < $start + $per_page and $logs->log[$i] != null; $i++) {
if ($i >= $start) {
$log = $logs->log[$i];
$str .= "<tr class=\"user\"><td class=\"user\">" . $log->username . " </td><td class=\"user\">" . utf8_decode($log->name) . " </td><td class=\"user\">" . $log->date . " </td><td class=\"user\">" . $log->action . "</td><td class=\"user\">" . $log->description . "</td></tr>";
}
}
$str .= "</table>";
return $str;
}
// lista $limit logs comecando no nodo numero $eu
function log_list($eu, $limit) {
log_exists("logs_sorted.xml");
$logs = simplexml_load_file("logs_sorted.xml");
$str = "{ \"data\" : [";
for ($i = 0; $i < $eu + $limit and $logs->log[$i] != null; $i++) {
if ($i >= $eu) {
$log = $logs->log[$i];
$str = $str . "{\"username\" : \"$log->username\", \"name\" : \"$log->name\", \"date\" : \"$log->date\", \"action\" : \"$log->action\", \"description\" : \"$log->description\"},";
}
}
if (log_count() != 0)
$str = substr($str, 0, (strLen($str) - 1));
return $str;
}
// conta o numero de nodos
function log_count() {
$log_file = "../logs/logs_sorted.xml";
log_exists($log_file);
return simplexml_load_file($log_file)->count();
}
/* -------------------------------------------------------------------------------------------------- */
/* ------------------------------------------ XML --------------------------------------------------- */
/* -------------------------------------------------------------------------------------------------- */
// validação de um xml
function libxml_display_error($error) {
$return = "<br/>\n";
switch ($error->level) {
case LIBXML_ERR_WARNING:
$return .= "<b>Warning $error->code</b>: ";
break;
case LIBXML_ERR_ERROR:
$return .= "<b>Error $error->code</b>: ";
break;
case LIBXML_ERR_FATAL:
$return .= "<b>Fatal Error $error->code</b>: ";
break;
}
$return .= trim($error->message);
if ($error->file) {
$return .= " in <b>$error->file</b>";
}
$return .= " on line <b>$error->line</b>\n";
return $return;
}
function libxml_display_errors() {
$errors = libxml_get_errors();
foreach ($errors as $error) {
print libxml_display_error($error);
}
libxml_clear_errors();
}
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir . "/" . $object) == "dir")
rrmdir($dir . "/" . $object); else
unlink($dir . "/" . $object);
}
}
reset($objects);
rmdir($dir);
}
}
/**
* Passar um objeto para a linha da tabela de listagem
* @param type $titulo
* @param type $res
*/
function obj_to_table($type, $res) {
switch ($type) {
case '1':
$titulo = "Projetos";
$head = "<tr><th class=\"user\">Codigo</th><th class=\"user\">Keyname</th><th class=\"user\">Title</th></tr>";
$data = "";
while ($reg = mysql_fetch_array($res)) {
$data .= "<tr>";
$data .= "<td class=\"user\"><a href=\"../gerirU/gerirS_Show.php?projcode=".$reg["projcode"]."\">" . $reg["projcode"] . "</a></td>";
$data .= "<td class=\"user\">" . $reg["keyname"] . "</td>";
$data .= "<td class=\"user\">" . $reg["title"] . "</td>";
$data .= "</tr>";
}
break;
case '2':
$titulo = "Cursos";
$head = "<tr><th class=\"user\">Codigo</th><th class=\"user\">Curso</th></tr>";
$data = "";
while ($reg = mysql_fetch_array($res)) {
$data .= "<tr>";
$data .= "<td class=\"user\">" . $reg["coursecode"] . "</td>";
$data .= "<td class=\"user\">" . $reg["coursedescription"] . "</td>";
$data .= "</tr>";
}
break;
case '3':
$titulo = "Autores";
$head = "<tr><th class=\"user\">ID</th><th class=\"user\">Name</th><th class=\"user\">Email</th></tr>";
$data = "";
while ($reg = mysql_fetch_array($res)) {
$data .= "<tr>";
$data .= "<td class=\"user\"><a href=\"../gerirU/gerirAS_Show_author.php?authorcode=".$reg["authorcode"]."\">" . $reg["id"] . "</a></td>";
$data .= "<td class=\"user\">" . $reg["name"] . "</td>";
$data .= "<td class=\"user\">" . $reg["email"] . "</td>";
$data .= "</tr>";
}
break;
case '4':
$titulo = "Supervisores";
$head = "<tr><th class=\"user\">Codigo</th><th class=\"user\">Name</th><th class=\"user\">Email</th></tr>";
$data = "";
while ($reg = mysql_fetch_array($res)) {
$data .= "<tr>";
$data .= "<td class=\"user\"><a href=\"../gerirU/gerirAS_Show_supervisor.php?supcode=".$reg["supcode"]."&page_p=1\">" . $reg["supcode"] . "</a></td>";
$data .= "<td class=\"user\">" . $reg["name"] . "</td>";
$data .= "<td class=\"user\">" . $reg["email"] . "</td>";
$data .= "</tr>";
}
break;
default: break;
}
echo "<h3 class=\"user\">" . $titulo . "</h3>";
echo "<div id=\"containt_main_users_column_label\">";
echo "<table class=\"user\">";
echo $head;
echo $data;
echo "</table>";
echo "</div>";
}
function Zip($source, $destination) {
if (!extension_loaded('zip') || !file_exists($source)) {
return false;
}
$zip = new ZipArchive();
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
return false;
}
$source = str_replace('\\', '/', realpath($source));
//echo "<br/>Source = $source<br/>";
//echo "<br/>Destino = $destination<br/>";
if (is_dir($source) === true) {
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
$file = str_replace('\\', '/', realpath($file));
if (is_dir($file) === true) {
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
} else if (is_file($file) === true) {
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
}
}
} else if (is_file($source) === true) {
$zip->addFromString(basename($source), file_get_contents($source));
}
return $zip->close();
}
?>