-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiments-anonynote-build.php
200 lines (194 loc) · 6.55 KB
/
experiments-anonynote-build.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
<?php
$colors[1] = array('name' => 'White', 'hex' => 'ffffff');
$colors[2] = array('name' => 'Gray', 'hex' => 'f3f3f3');
$colors[3] = array('name' => 'Red', 'hex' => 'ffdddd');
$colors[4] = array('name' => 'Orange', 'hex' => 'fff6dd');
$colors[5] = array('name' => 'Yellow', 'hex' => 'feffdd');
$colors[6] = array('name' => 'Green', 'hex' => 'dfffdd');
$colors[7] = array('name' => 'Cyan', 'hex' => 'ddffff');
$colors[8] = array('name' => 'Blue', 'hex' => 'dde2ff');
$colors[9] = array('name' => 'Purple', 'hex' => 'f4ddff');
$method = $_GET['method'];
$db = new mysqli(HOSTNAME, USERNAME, DBPASSWORD, DBNAMEEXP);
if ($db->connect_errno) {
echo '<p>Database error. <a href="/experiments/anonynote">Maybe reload</a>?</p>';
} else {
switch ($method) {
case "buildNotepad":
$pad = addslashes($_GET['notepad']);
echo '<a href="#" class="home-link" onclick="buildOpenDialog();"><i class="fa fa-long-arrow-left"></i> Create or edit another notepad</a>
<h2>Notepad: “' . stripslashes($pad) . '”</h2>
<span id="this-notepad" class="hidden">' . stripslashes($pad) . '</span>
<button type="button" class="btn btn-primary" onclick="buildEdit(\'' . $pad . '\');">
<i class="fa fa-plus"></i> Add note
</button>
';
$sql="SELECT * FROM `notes` WHERE notepad='" . $pad . "' ORDER BY `notes`.`org` DESC";
$result = $db->query($sql);
if (mysqli_num_rows($result) > 0) {
echo '<div class="spacer20"></div>
<table id="notes-table" class="table table-bordered table-condensed">
<thead>
<tr>
<th class="col-one">Actions</th>
<th class="col-two">Note</th>
</tr>
</thead>
<tbody id="sortable">
';
while ($row = $result->fetch_assoc()) {
$note = $noteFull = htmlspecialchars($row["text"]);
if (strlen($note) > 150) {
// truncate string
$noteCut = substr($note, 0, 150);
// make sure it ends in a word
$note = substr($noteCut, 0, strrpos($noteCut, ' ')).'... <a href="#" title="Read more" onclick="readMore(' . $row["id"] . ');"><span class="ital">read more</span></a>';
}
echo '<tr id="id-' . $row["id"] . '" class="color-' . $row["color"] . '" style="background-color: #' . $row["color"] . '">
<td class="action-btns">
<a href="#" class="sort-handle" title="Drag to re-order">
<span class="fa-stack">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-arrows-v fa-stack-1x fa-inverse"></i>
</span>
</a>
<a href="#" title="Edit" onclick="buildEdit(\'' . $pad . '\', ' . $row["id"] . ');">
<span class="fa-stack">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-pencil fa-stack-1x fa-inverse"></i>
</span>
</a>
<a href="#" title="Delete" onclick="deleteNote(' . $row["id"] . ');">
<span class="fa-stack">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-times fa-stack-1x fa-inverse"></i>
</span>
</a>
</td>
<td class="note-display break-word">
<span class="note-short">' . nl2br($note) . '</span>
<span class="note-full hidden">' . nl2br($noteFull) . '</span>
</td>
</tr>
';
}
echo '</tbody>
</table>';
}
break;
case "buildEdit":
$pad = addslashes($_GET['notepad']);
$id = $_GET['noteid'];
if ($id != "") {
$sql="SELECT * FROM `notes` WHERE id='" . $id . "' LIMIT 1";
$result = $db->query($sql);
while ($row = $result->fetch_assoc()) {
$i = $row["id"];
$n = $row["notepad"];
$o = $row["org"];
$c = $row["color"];
$t = $row["text"];
}
}
echo '<span class="bold">Pick a color: </span>
<div style="display: inline-block;">
<select id="colorselector">';
foreach ($colors as $arr) {
if ($arr["hex"] != $c) {
echo '<option value="' . $arr["hex"] . '" data-color="#' . $arr["hex"] . '">' . $arr["name"] . '</option>';
} else {
echo '<option value="' . $arr["hex"] . '" data-color="#' . $arr["hex"] . '" selected="selected">' . $arr["name"] . '</option>';
}
}
if (!isset($c)) {
$c = 'ffffff';
}
echo '
</select>
</div>
<div class="spacer10"></div>
<form>
<div class="form-group">
<label for="note-text" class="sr-only">Note</label>
<textarea class="form-control" rows="10" id="note-text" name="note-text" placeholder="Enter your note here." style="background-color: #' . $c . '">';
if (isset($t)) {
echo $t;
}
echo '</textarea>
<p class="text-danger note-error"></p>
</div>';
$param = "'" . $pad . "'";
if (isset($i)) {
$param .= ", " . $i;
}
echo '<button type="button" class="btn btn-success" onclick="saveNote(' . $param . ');">
<i class="fa fa-check"></i> Save note
</button>
<button type="button" class="btn btn-danger" onclick="buildNotepad(\'' . $pad . '\', \'fade\');">
<i class="fa fa-times"></i> Cancel
</button>
</form>
';
break;
case "saveNote":
$pad = addslashes($_GET['notepad']);
$text = addslashes(urldecode($_GET['notetext']));
$color = $_GET['notecolor'];
if ($_GET['noteid'] == "") {
$sql1="SELECT MAX(`org`) FROM `notes` WHERE notepad='" . $pad . "'";
if ($result = $db->query($sql1)) {
while ($row = $result->fetch_assoc()) {
$org = $row['MAX(`org`)'] + 1;
}
} else {
$org = 1;
}
$sql2="INSERT INTO `" . DBNAMEEXP . "`.`notes` (`id`, `notepad`, `org`, `color`, `text`) VALUES (NULL, '" . $pad . "', '" . $org . "', '" . $color . "', '" . $text . "')";
if ($result = $db->query($sql2)) {
echo "1";
} else {
echo "0";
}
} else {
$id = $_GET['noteid'];
$sql="UPDATE `" . DBNAMEEXP . "`.`notes` SET `color`='" . $color . "', `text`='" . $text . "' WHERE `notes`.`id`=" . $id . "";
if ($result = $db->query($sql)) {
echo "1";
} else {
echo "0";
}
}
break;
case "deleteNote":
$id = $_GET['noteid'];
$sql="DELETE FROM `notes` WHERE id='" . $id . "'";
if ($result = $db->query($sql)) {
echo "1";
} else {
echo "0";
}
break;
case "reorderEntry":
$pad = addslashes($_GET['notepad']);
$orderStr = $_GET['noteorder'];
$err = 0;
foreach ($orderStr as $idKey => $idValue) {
$i = str_replace("id-", "", $idValue);
$o = count($orderStr) - $idKey;
$sql="UPDATE `" . DBNAMEEXP . "`.`notes` SET `org`='" . $o . "' WHERE `notes`.`id`=" . $i . "";
if ($result = $db->query($sql)) {
//
} else {
$err++;
}
}
if ($err != 0) {
echo "2";
} else {
echo "1";
}
break;
}
}
$db->close();
?>