forked from hypercities/hypercities
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateMapMeta.php
More file actions
89 lines (77 loc) · 2.01 KB
/
updateMapMeta.php
File metadata and controls
89 lines (77 loc) · 2.01 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
<?php
include_once('includes/database.inc');
include_once('includes/dbUtil.inc');
include_once('includes/util.inc');
include_once("includes/serverSession.inc");
//session_start();
cServerSession::start();
HC_checkReferer();
$HC_POST = HC_cleanInput($_POST,
array('id'=>'int',
'date_from'=>'dtime',
'date_to'=>'dtime',
'publication_date'=>'dtime',
'title'=>'str',
'title_en'=>'str',
'creator'=>'str',
'publisher'=>'str',
'copyright_notice'=>'str',
'caption'=>'str',
'caption_en'=>'str',
'collection_source'=>'str',
'call_number'=>'str',
'map_size'=>'str',
'scale'=>'str',
'description'=>'str'),
array('id'),
array('date_from',
'date_to',
'publication_date',
'title',
'title_en',
'creator',
'publisher',
'copyright_notice',
'caption',
'caption_en',
'collection_source',
'call_number',
'map_size',
'scale',
'description')
);
$userId = cServerSession::getUserId();
$mapId = $HC_POST['id'];
//HC_debugLog(var_dump($HC_POST, false));
$db = database::getInstance();
$params = array('type'=>'');
$query_str = "UPDATE `maps` SET ";
$totalUpdates = 0;
foreach ($HC_POST as $key => &$value) {
if ( $key != "id" && $value !== NULL ) {
if ( is_string($value) && strlen($value) == 0 ) {
$query_str .= "`". $key . "` = NULL, ";
$totalUpdates++;
} else {
$query_str .= "`". $key . "` = ?, ";
$params['type'] .= "s";
$params[] = &$value;
$totalUpdates++;
}
}
}
$query_str .= "`updated_at` = NOW() WHERE `id` = ?";
$params['type'] .= "i";
$params[] = &$mapId;
//HC_debugLog(var_dump($params, false));
//HC_debugLog($query_str);
// If we need to change something. do it.
if ($totalUpdates > 0) {
$result = $db->preparedQuery($query_str, $params);
if (!$result) {
HC_errorLog("Fail to update map $mapId : " . $db->getError());
HC_reportError("Database Error : Unable to update Map.");
}
}
HC_reportSuccess();
?>