forked from ademcan/canSnippet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowse.php
83 lines (75 loc) · 2.76 KB
/
browse.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
<?php
/*
@author: Ademcan ([email protected])
@name: browse.php
@description: browse page allow users to choose a language and a corresponding snippet
*/
session_start();
include "config.php";
include 'includes/menu.php';
$mytable ="snippets";
$base=new SQLite3($config["dbname"]);
?>
<h1>Browse snippets</h1>
<div id="browseLeftPane">
<div id="languagePanel">
Choose a language<br><br>
<select id="selectLanguage" name="selectLanguage" class="box" >
<?php
// get list of languages
if(isset($_SESSION['valid']) && $_SESSION['valid']){
$query_language = "SELECT DISTINCT language FROM $mytable";
}
else {
$query_language = "SELECT DISTINCT language FROM $mytable WHERE private != 'on' ";
}
$results_language = $base->query($query_language);
echo '<option value="default" selected> Choose a language </option>';
while($row = $results_language->fetchArray())
{
$language = $row['language'];
echo '<option value="'.$language.'" >'.$language;
}
?>
</select>
</div>
<!--returns the selected language-->
<script>
//var selectCode = document.getElementById("selectCode");
document.getElementById("selectLanguage").onchange = function(){
selectedLanguage = document.getElementById("selectLanguage").value ;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
document.getElementById("namePanel").innerHTML = xhr.responseText;
}
};
xhr.open("POST", "action.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
if(selectedLanguage=="c++")
selectedLanguage="c%2b%2b";
xhr.send("language="+selectedLanguage+"&action=getname");
};
</script>
<div id="namePanel">
</div>
</div>
<script>
document.getElementById("namePanel").onchange = function(){
selectedName = document.getElementById("selectCode").value ;
var xhr2 = new XMLHttpRequest();
xhr2.onreadystatechange = function() {
if (xhr2.readyState == 4 && (xhr2.status == 200 || xhr2.status == 0)) {
document.getElementById("codePanel").innerHTML = xhr2.responseText;
Prism.highlightAll();
}
};
xhr2.open("POST", "action.php", true);
xhr2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr2.send("id="+selectedName+"&action=getcode");
};
</script>
<div id="codePanel">
</div>
</div>
</body></html>