-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocess_list.php
executable file
·160 lines (132 loc) · 4.92 KB
/
process_list.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
<?php
/**
* process_list.php
*
* This script inserts, updates, and deletes Concept Lists to mcl.concept_list.
* This script takes to url parameters:
* s (required) - case insensitive type of submission: update, create new, delete
* name - must be unique
* source - db name of the concept dictionary source
* list - the concept_list_id (ignored if submit type is 'create new')
* concepts - comma-separated list of
* admin - set to 1 to allow editing of restricted lists
*/
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
session_start();
require_once('LocalSettings.inc.php');
require_once('ConceptListFactory.inc.php');
require_once('ConceptList.inc.php');
require_once('search_common.inc.php');
// Set debug status
$debug = false;
if (isset($_POST['debug']) && $_POST['debug']) {
$debug = true;
echo '<pre>', var_dump($_POST), '</pre>';
}
// Make sure the form submit post parameter was passed
if (!isset($_POST['s']) || !$_POST['s']) {
trigger_error('<strong>s</strong> is a required form post parameter.', E_USER_ERROR);
}
// Determine submission type
$submit = strtolower($_POST['s']);
if ($submit != 'update' && $submit != 'create new' && $submit != 'delete') {
trigger_error("Allowed values for <strong>s</strong> are 'update', " .
"'create new', and 'delete'.", E_USER_ERROR);
}
// Get the form variables
$name = $_POST['name'];
$source = $_POST['source'];
$list_id = null;
if (isset($_POST['list'])) $list_id = $_POST['list'];
$concepts = null;
if (isset($_POST['concepts'])) $concepts = $_POST['concepts'];
// Connect to db
$cxn = mysql_connect($mcl_db_host, $mcl_db_uid, $mcl_db_pwd);
if (!$cxn) {
die('Could not connect to database: ' . mysql_error());
}
mysql_select_db($mcl_default_concept_dict_db, $cxn);
$clf = new ConceptListFactory();
$clf->setConnection($cxn);
$clf->debug = $debug;
// Determine if this is a restricted list
// NOTE: right now, this only applies to the MCL Core. Can override with 'admin' parameter.
$restrict_editing = false;
if ($list_id == 1) {
if (!isset($_POST['admin'])) $restrict_editing = true;
}
/****************************************************************************
** Process Delete
****************************************************************************/
if ($submit == 'delete')
{
// Make the sure the right parameters are set
if (!$list_id) {
trigger_error('<strong>list</strong> is a required form post parameter ' .
"for submit type 'delete'.", E_USER_ERROR);
}
// Throw error if deleting one of the restricted lists
if ($restrict_editing) {
trigger_error("Cannot delete restricted lists without admin privileges", E_USER_ERROR);
}
// Delete the list
if (!$clf->deleteConceptList($list_id)) {
trigger_error("Cannot delete concept_list_id: " . $list_id, E_USER_ERROR);
}
// Set the redirect url
$url = 'list.php';
}
/****************************************************************************
** Process Delete
****************************************************************************/
elseif ($submit == 'create new')
{
// Make sure the right parameters are set
// NOTE: 'concepts' is an optional parameter
if (!$name || !$source) {
trigger_error('<strong>name</strong> and <strong>source</strong> are ' .
"required form post parameters for submit type 'create new'.", E_USER_ERROR);
}
// Add the list
$new_concept_list_id = $clf->addConceptList($name, $source, $concepts);
// Set the redirect url
if ($new_concept_list_id) {
$url = 'list.php?list=' . $new_concept_list_id;
} else {
// todo: need to pass error message to user
$url = 'list.php';
}
}
/****************************************************************************
** Update Concept List (for updates or new lists)
****************************************************************************/
elseif ($submit == 'update')
{
// Make sure the right parameters are set
if (!$list_id) {
trigger_error('<strong>list</strong> is a required form post parameter ' .
"for submit type 'update'.", E_USER_ERROR);
}
// Throw error if updating one of the restricted lists
if ($restrict_editing) {
trigger_error("Cannot update restricted lists without administrative privileges", E_USER_ERROR);
}
// Update the list
if (!$clf->updateConceptList($list_id, $name, $source, $concepts)) {
trigger_error('Unable to update concept list: ' . $list_id, E_USER_ERROR);
}
// Set the redirect url
$url = 'list.php?list=' . $list_id;
}
/****************************************************************************
** Redirect back to list.php
****************************************************************************/
// Get back to list.php
if ($debug) {
echo '<p>Redirect to: <a href="' . $url . '">' . $url . '</a></p>';
} else {
header('Location:' . $url);
}
exit();
?>