-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.php
More file actions
102 lines (84 loc) · 3.21 KB
/
config.php
File metadata and controls
102 lines (84 loc) · 3.21 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
<?php
include "credentials.php";
$link = "";
$year = "";
$debug = false;
$aPathCdS = array(); // Array contenente i link della lista dei corsi di studio di ogni dipartimento;
$aPath_OPIS_Dipartimento = array(); // Array contente i link delle schede opis del Dipartimento
$mysqli = new mysqli($host, $username, $password, $db_name);
if ($mysqli->connect_error)
die('Errore di connessione');
$mysqli->query("DELETE FROM schede_opis");
$mysqli->query("DELETE FROM insegnamento");
$mysqli->query("DELETE FROM corso_di_studi");
$mysqli->query("DELETE FROM dipartimento");
function curl_exec_utf8($ch) {
$data = curl_exec($ch);
if (!is_string($data)) return $data;
unset($charset);
$content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
/* 1: HTTP Content-Type: header */
preg_match( '@([\w/+]+)(;\s*charset=(\S+))?@i', $content_type, $matches );
if ( isset( $matches[3] ) )
$charset = $matches[3];
/* 2: <meta> element in the page */
if (!isset($charset)) {
preg_match( '@<meta\s+http-equiv="Content-Type"\s+content="([\w/]+)(;\s*charset=([^\s"]+))?@i', $data, $matches );
if ( isset( $matches[3] ) ) {
$charset = $matches[3];
/* In case we want do do further processing downstream: */
$data = preg_replace('@(<meta\s+http-equiv="Content-Type"\s+content="[\w/]+\s*;\s*charset=)([^\s"]+)@i', '$1utf-8', $data, 1);
}
}
/* 3: <xml> element in the page */
if (!isset($charset)) {
preg_match( '@<\?xml.+encoding="([^\s"]+)@si', $data, $matches );
if ( isset( $matches[1] ) ) {
$charset = $matches[1];
/* In case we want do do further processing downstream: */
$data = preg_replace('@(<\?xml.+encoding=")([^\s"]+)@si', '$1utf-8', $data, 1);
}
}
/* 4: PHP's heuristic detection */
if (!isset($charset)) {
$encoding = mb_detect_encoding($data);
if ($encoding)
$charset = $encoding;
}
/* 5: Default for HTML */
if (!isset($charset)) {
if (strstr($content_type, "text/html") === 0)
$charset = "ISO 8859-1";
}
/* Convert it if it is anything but UTF-8 */
/* You can change "UTF-8" to "UTF-8//IGNORE" to
ignore conversion errors and still output something reasonable */
if (isset($charset) && strtoupper($charset) != "UTF-8")
$data = iconv($charset, 'UTF-8', $data);
return $data;
}
function getDOM($link)
{
libxml_use_internal_errors(true);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec_utf8($ch);
$html = utf8_encode($html);
$dom = new DOMDocument;
$dom->substituteEntities = false;
$dom->loadHTML('<?xml version="1.0" encoding="utf-8"?>' . $html);
$dom->encoding = 'utf-8';
curl_close($ch);
return $dom;
}
function get_primary_id(int $unict_id, string $table): int {
global $mysqli, $year;
$result = $mysqli->query("SELECT id FROM $table WHERE unict_id = $unict_id AND anno_accademico = '$year'");
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
return $row["id"];
}
echo "\nSELECT id FROM $table WHERE unict_id = $unict_id AND anno_accademico = '$year'";
die("\n\nError getting the primary id of $table");
}
?>