-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathindexes.php
73 lines (63 loc) · 2.09 KB
/
indexes.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
<?php
/**
* This file is a part of MyWebSQL package
*
* @file: modules/indexes.php
* @author Samnan ur Rehman
* @copyright (c) 2008-2014 Samnan ur Rehman
* @web http://mywebsql.net
* @license http://mywebsql.net/license
*/
function processRequest(&$db) {
$action = v($_REQUEST["id"]);
include(BASE_PATH . "/lib/tableeditor.php");
$editor = new tableEditor($db);
$editor->setName(v($_REQUEST["name"]));
$editor->loadTable(true, true, false);
if ($action == "alter")
{
$result = alterTableIndexes($db, v($_REQUEST["query"]), $editor);
$formatted_query = preg_replace("/[\\n|\\r]?[\\n]+/", "<br>", htmlspecialchars($editor->getSql()));
if ($result)
print
'<div id="result">1</div><div id="message">'
.'<div class="message ui-state-default">The command executed successfully.</div>'
.'<div class="sql-text ui-state-default">'.$formatted_query.'</div>'
.'</div>';
else
print
'<div id="result">0</div><div id="message">'
.'<div class="message ui-state-error">Error occured while executing the query:</div>'
.'<div class="sql-text ui-state-error">'.$formatted_query.'</div>'
.'<div class="message ui-state-highlight">'.htmlspecialchars($db->getError()).'</div>'
.'</div>';
}
else
displayIndexesForm($db, $editor);
}
function displayIndexesForm(&$db, &$editor)
{
$indexes = $editor->getIndexes();
$fields = $editor->getFields();
$replace = array(
'ID' => v($_REQUEST["id"]) ? htmlspecialchars($_REQUEST["id"]) : '',
'MESSAGE' => __('Changes are not saved until you press [Save All Changes]'),
'INDEXES' => count($indexes) > 0 ? json_encode($indexes) : '{}',
'FIELDS' => json_encode($fields),
'TABLE_NAME' => htmlspecialchars($editor->getName())
);
echo view('indexes', $replace);
}
function alterTableIndexes(&$db, $info, &$editor)
{
$info = json_decode($info);
if (!is_object($info))
return false;
if (v($info->indexes))
$editor->setIndexes($info->indexes);
$sql = $editor->getAlterIndexStatement();
if (!$db->query($sql))
return false;
return true;
}
?>