-
Notifications
You must be signed in to change notification settings - Fork 1
/
kora_database_admin.php
executable file
·292 lines (223 loc) · 12.7 KB
/
kora_database_admin.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
<?php
define('KORA_PLUGIN_PATHBASE', plugin_dir_url(__FILE__));
require_once(realpath(dirname(__FILE__) . "/dbconfig.php"));
$url_plugin=$_GET['url'];
?>
<script> var url_plugin = '<?php echo KORA_PLUGIN_PATHBASE;?>'; </script>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script src="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/js/bootstrap-multiselect.js"></script>
<script src="<?php echo plugins_url('kora/remodal_v1.0.6/dist/remodal.min.js'); ?>"></script>
<script src="<?php echo plugins_url('kora/chosen_v1.4.2/chosen.jquery.min.js'); ?>"></script>
<script src="<?php echo plugins_url('kora/chosen_v1.4.2/chosen.proto.min.js'); ?>"></script>
<script src="<?php echo plugins_url('kora/js/connect.js'); ?>"></script>
<link rel="stylesheet" href="http://cdn.rawgit.com/davidstutz/bootstrap-multiselect/master/dist/css/bootstrap-multiselect.css"
type="text/css"/>
<link rel="stylesheet" href="<?php echo plugins_url('kora/remodal_v1.0.6/dist/remodal.css'); ?>" type="text/css"/>
<link rel="stylesheet" href="<?php echo plugins_url('kora/remodal_v1.0.6/dist/remodal-default-theme.css'); ?>"
type="text/css"/>
<link rel="stylesheet" href="<?php echo plugins_url('kora/chosen_v1.4.2/chosen.css'); ?>" type="text/css"/>
<?php
$emptys = array();
$emptyfunc = function ($bool, $name) use (&$emptys) {
if (!$bool) {
$emptys[] = $name;
}
};
if ($_POST['kordat_hidden'] == 'Y') {
///Form data sent
$dbapi = $_POST['kordat_dbapi'];
update_option('kordat_dbapi', $dbapi);
$emptyfunc($dbapi, "URL of KORA Installation");
$dbproj = $_POST['kordat_dbproj'];
update_option('kordat_dbproj', $dbproj);
$emptyfunc($dbproj, "Project ID");
$dbscheme = $_POST['kordat_dbscheme'];
update_option('kordat_dbscheme', $dbscheme);
$emptyfunc($dbscheme, "Scheme ID");
$dbtoken = $_POST['kordat_dbtoken'];
update_option('kordat_dbtoken', $dbtoken);
$emptyfunc($dbtoken, "Token");
if (($dbapi && $dbscheme && $dbtoken)) {
//if ($scheme_proj_token) {
echo " <div class='updated'><p><strong>";
_e('Options saved.');
echo "</strong></p></div>";
} else {
echo "<div class='error'><p><strong>All fields below need to be filled: </strong></p>";
//var_dump($emptys);
if ($dbapi == '') {
echo "<p>* URL of Kora Installation</p>";
}
if ($dbproj[1] === '') {
echo "<p>* Project ID</p>";
}
if ($dbtoken[0] === '') {
echo "<p>* Token</p>";
}
if ($dbscheme[1] == '') {
echo "<p>* Scheme ID</p>";
}
echo "</div>";
}
} else {
///Normal page display
$dbapi = get_option('kordat_dbapi');
$dbproj = get_option('kordat_dbproj');
$dbscheme = get_option('kordat_dbscheme');
$dbtoken = get_option('kordat_dbtoken');
}
//button pos
$edit_pos = KORA_PLUGIN_PATHBASE . 'edit.png';
$add_pos = KORA_PLUGIN_PATHBASE . 'plus.png';
$remove_pos = KORA_PLUGIN_PATHBASE . 'minus.png';
/* connect to database*/
$mysql_hostname = kordat_dbhostname;
$mysql_user = kordat_dbhostuser;
$mysql_database = kordat_dbselectname;
$mysql_password = kordat_dbhostpass;
@$bd = new mysqli($mysql_hostname, $mysql_user, $mysql_password, $mysql_database);
if ($bd->connect_error) {
echo "<p class='error'><strong>";
echo "Please edit config.php.dist (Kora Host Database Settings) first! Save as config.php!";
echo "</strong></p>";
} else {
// Get all project id and name in db.
$projectID_query = "SELECT pid, name, description FROM project;";
$stmt = $bd->prepare($projectID_query) ;
$stmt->execute();
$stmt->bind_result($pid, $pname, $pdesc);
$projectInfo = array();
while($stmt->fetch()){
$projectInfo[] = array('pid' => $pid, 'projectName' => $pname, 'description' => $pdesc);
}
$stmt->close();
// Get all scheme infromation from db.
$query_scheme = "SELECT schemeid, pid, schemeName, description FROM scheme;";
$stmt = $bd->prepare($query_scheme) ;
$stmt->execute();
$stmt->bind_result($sid, $pid, $sname, $sdesc);
$schemeInfo = array();
while($stmt->fetch()){
$schemeInfo[] = array('sid' => $sid, 'pid' => $pid, 'schemeName' => $sname, 'description' => $sdesc);
}
$stmt->close();
}
?>
<div class='wrap'>
<h1>KoraConnect</h1>
<form id='setting_form' name='kordat_form' method='post' action='#'>
<input type='hidden' name='kordat_hidden' value='Y'/>
<h2 id='koraUrlHeader'>URL of Kora Installation</h2>
<input id='koraUrl' type='text' name='kordat_dbapi' value='<?php echo $dbapi; ?>'
placeholder='Enter the URL of your Kora installation here (http://kora.example.org/) then click "Update Connection"'/>
<h2 id="ptsHeader">Projects, Tokens, and Schemes</h2>
<div id="questions">
<span id="projectQuestion">Where do I find the Projects?</span>
<span id="tokenQuestion">Where do I find the Token?</span>
<span id="schemeQuestion">Where do I find the Schemes?</span>
</div>
<div class = "projectBox" id="projectBox">
<?php
if (is_array($dbproj)) {
for ($i = 0; $i < count($dbproj) ; $i++) {
if ((empty($dbproj[$i]) || empty($dbscheme[$i]) || empty($dbtoken[$i]))) {
continue;
}
?>
<div class = "projectBoxItem">
<select class = 'koraProject' id='koraProject' name='kordat_dbproj[]' <?php //if ($dbtoken[0] && $dbproj[0]) { echo "readonly"; } ?>
data-placeholder="Project: Search and select a project" alt='<?php echo $i;?>'>
<option value="default"></option>
<?php
foreach($projectInfo as $p){
echo '<option value = "'.$p['pid'].'"';
if ($p['pid'] == $dbproj[$i]) {echo 'selected="selected"'; }
echo '>'.$p['pid'].'---'.$p['projectName'].'---'.$p['description'].'</option>';
}
?>
</select>
<img class='deleteBox' pid=<?php echo dechex($dbproj[$i]);?> src='<?php echo plugins_url("kora/images/Close.svg"); ?>'
width='19' height='18' alt='Delete Button'/>
<input id='koraToken' type='text' name='kordat_dbtoken[]' value="<?php echo $dbtoken[$i]; ?>"
onchange='<!--this.form.submit()-->' placeholder='Token: Enter token associated with the project'
disabled <?php //if ($dbtoken[0] && $dbproj[0]) { echo "readonly"; } ?> />
<!-- Scheme -->
<select class = 'koraScheme' id='koraScheme' name='kordat_dbscheme[]' data-placeholder="Scheme(s): Search and select by scheme name or ID" alt='<?php echo $i;?>' multiple>
<option value="default"></option>
</select>
</div>
<div class="buttonCont"></div>
<?php
}
} else { ?>
<div class = "projectBoxItem">
<select class = 'koraProject' id='koraProject' name='kordat_dbproj[]' <?php //if ($dbtoken[0] && $dbproj[0]) { echo "readonly"; } ?>
data-placeholder="Project: Search and select a project">
<option value="default"></option>
<?php
foreach($projectInfo as $p){
echo '<option value = "'.$p['pid'].'"';
if ($p['pid'] == $dbproj) {echo 'selected="selected"';}
echo '>'.$p['pid'].'---'.$p['projectName'].'---'.$p['description'].'</option>';
}
?>
</select>
<img class='deleteBox' src='<?php echo plugins_url("kora/images/Close.svg"); ?>'
width='19' height='18' alt='Delete Button'/>
<input id='koraToken' type='text' name='kordat_dbtoken[]' value="<?php echo $dbtoken; ?>"
onchange='<!--this.form.submit()-->' placeholder='Token: Enter token associated with the project'
disabled <?php //if ($dbtoken[0] && $dbproj[0]) { echo "readonly"; } ?> />
<!-- Scheme -->
<select class = 'koraScheme' id='koraScheme' name='kordat_dbscheme[]' data-placeholder="Scheme(s): Search and select by scheme name or ID" multiple>
<option value="default"></option>
</select>
</div>
<div class="buttonCont"></div>
<?php }
?>
</div>
<div id="appendNewProjects"></div>
<input id='addNewButton' type='button' value='Add New Project, Token, & Scheme(s)' disabled />
</form>
</div><!-- end of .wrap -->
<!-- Modals -->
<div class="remodal" id="projectModal" data-remodal-id="projectModal">
<button data-remodal-action="close" class="remodal-close"></button>
<h2>Finding the project</h2>
<p>To find the project you wish to connect, navigate to the project selection page
within your Kora installation. Your various projects will be listed. You may search
via the project name or ID within KoraConnect.
</p>
<img src="<?php echo plugins_url('/kora/images/finding-the-project.svg'); ?>"
width="452" height="73" alt="How to find the project" />
</div>
<div class="remodal" id="tokenModal" data-remodal-id="tokenModal">
<button data-remodal-action="close" class="remodal-close"></button>
<h2>Finding the token</h2>
<p>To find the token, navigate to the Manage Search Tokens within your Kora installation.
Various tokens will be listed for each project. Look for the project you’re connecting to,
and the token key will be in the far left column.
</p>
<img src="<?php echo plugins_url('/kora/images/finding-the-token.svg'); ?>"
width="456" height="120" alt="How to find the token" />
<div id="redCircle"></div>
</div>
<div class="remodal" id="schemeModal" data-remodal-id="schemeModal">
<button data-remodal-action="close" class="remodal-close"></button>
<h2>Finding the scheme</h2>
<p>To find the scheme you wish to connect, navigate to the project that contains the desired
scheme within your Kora installation. The schemes will be listed within the project. You
may search by scheme name or ID within KoraConnect.
</p>
<img src="<?php echo plugins_url('/kora/images/finding-the-scheme.svg'); ?>"
width="452" height="91" alt="How to find the scheme" />
</div>
<div class="remodal" id="deleteModal" data-remodal-id="deleteModal">
<button data-remodal-action="close" class="remodal-close"></button>
<h2>Do you want to remove this project? If you remove the project, all items from this project will be
remove from the library and galleries.</h2>
<button class="remove">Remove</button>
<button class="cancel">Cancel</button>
</div>