-
Notifications
You must be signed in to change notification settings - Fork 0
/
liveagenda_msg.php
319 lines (231 loc) · 7.65 KB
/
liveagenda_msg.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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
require_once( 'db_cfg.php' );
require_once( 'config.php' );
// disable caching, we want the users to update from the server every time
header( 'Expires: 0' );
header( 'Cache-Control: must-revalidate, proxy-revalidate, no-cache, no-store, max-age=0, s-maxage=0' );
$db = db_connect();
$broadcasterid = PFS_BROADCASTERID;
function delItem( $mediaid )
{
global $db;
global $broadcasterid;
if( !isset( $mediaid ) )
return;
if( !isset( $_REQUEST['textid'] ) )
return;
$textid = htmlspecialchars( trim( $_REQUEST['textid'] ) );
$textid_db = $db->quoteSmart( $textid );
$sql = "UPDATE agenda_items SET deleted=1 WHERE id=$textid_db AND broadcasterid=$broadcasterid;";
$result = $db->query( $sql );
if( PEAR::isError( $result ) )
{
error_log( 'Chat::msg: ' . $result->GetMessage() );
}
return getAllItems( $mediaid );
}
function addItem( $mediaid )
{
global $db;
global $broadcasterid;
if( !isset( $mediaid ) )
return;
if( !isset( $_REQUEST['text'] ) )
return getAllItems( $mediaid );
$text = trim( $_REQUEST['text'] );
if( empty( $text ) )
return getAllItems( $mediaid );
$text = htmlspecialchars( $text );
$text_db = $db->quoteSmart( $text );
$sql = "INSERT INTO agenda_items SET mediaid=$mediaid, broadcasterid=$broadcasterid, name=$text_db;";
$result = $db->query( $sql );
if( PEAR::isError( $result ) )
{
error_log( 'Chat::msg: ' . $result->GetMessage() );
}
return getAllItems( $mediaid );
}
function mrkItem( $mediaid )
{
global $db;
global $broadcasterid;
if( !isset( $mediaid ) )
return;
if( !isset( $_REQUEST['textid'] ) )
return;
$textid = htmlspecialchars( trim( $_REQUEST['textid'] ) );
$textid_db = $db->quoteSmart( $textid );
$sql = "UPDATE agenda_items SET posted=1, date=CURRENT_TIMESTAMP WHERE id=$textid_db AND broadcasterid=$broadcasterid;";
$result = $db->query( $sql );
if( PEAR::isError( $result ) )
{
error_log( 'Chat::msg: ' . $result->GetMessage() );
}
return getAllItems( $mediaid );
}
function ediItemMark( $mediaid )
{
global $db;
global $broadcasterid;
if( !isset( $mediaid ) )
return;
if( !isset( $_REQUEST['textid'] ) )
return;
$textid = htmlspecialchars( trim( $_REQUEST['textid'] ) );
$textid_db = $db->quoteSmart( $textid );
if( !isset( $_REQUEST['offset'] ) )
return;
$offset = htmlspecialchars( trim( $_REQUEST['offset'] ) );
$offset_db = $db->quoteSmart( $offset );
$sql = "UPDATE agenda_items SET posted=1, offset=$offset_db, date=CURRENT_TIMESTAMP WHERE id=$textid_db AND broadcasterid=$broadcasterid;";
$result = $db->query( $sql );
if( PEAR::isError( $result ) )
{
error_log( 'Chat::msg: ' . $result->GetMessage() );
}
return getAllItems( $mediaid );
}
function ediItemMark2( $mediaid )
{
global $db;
global $broadcasterid;
if( !isset( $mediaid ) )
return;
if( !isset( $_REQUEST['textid'] ) )
return;
$textid = htmlspecialchars( trim( $_REQUEST['textid'] ) );
$textid_db = $db->quoteSmart( $textid );
if( !isset( $_REQUEST['position'] ) )
return;
$offset = htmlspecialchars( trim( $_REQUEST['position'] ) );
$offset_db = $db->quoteSmart( $offset );
$sql = "UPDATE agenda_items SET posted=1, offset=$offset_db, date=CURRENT_TIMESTAMP WHERE id=$textid_db AND broadcasterid=$broadcasterid;";
error_log( $sql );
$result = $db->query( $sql );
if( PEAR::isError( $result ) )
{
error_log( 'Chat::msg: ' . $result->GetMessage() );
}
}
function getPlyItems( $mediaid )
{
global $db;
global $broadcasterid;
$mediaid_db = $db->quoteSmart( $mediaid );
if( isset( $_REQUEST['position'] ) )
$offset = $db->quoteSmart( $_REQUEST['position'] );
else
$offset = 9999999;
$sql = "SELECT name FROM agenda_items WHERE mediaid=$mediaid_db AND broadcasterid=$broadcasterid AND posted AND NOT deleted AND offset <= $offset ORDER BY date DESC LIMIT 1;";
$result = $db->getAll( $sql, array(), DB_FETCHMODE_ASSOC );
if( PEAR::isError( $result ) )
{
error_log( "Chat::all: " . $result->GetMessage() );
exit;
}
$allItems = '';
foreach( $result as $item )
{
$allItems .= "<br><br><span class=\"txt\">$item[name]</span><br>\n";
}
return $allItems;
}
function getAllItems2( $mediaid )
{
global $db;
global $broadcasterid;
$edit_mode = false;
if( isset( $_REQUEST['edit'] ) )
$edit_mode = true;
$mediaid_db = $db->quoteSmart( $mediaid );
$sql = "SELECT id, offset, name FROM agenda_items WHERE mediaid=$mediaid_db AND broadcasterid=$broadcasterid AND posted AND NOT deleted ORDER BY offset;";
$result = $db->getAll( $sql, array(), DB_FETCHMODE_ASSOC );
if( PEAR::isError( $result ) )
{
error_log( "Chat::all: " . $result->GetMessage() );
exit;
}
$html_section_head = "<table>";
$html_chapters = "";
foreach( $result as $chapter )
{
$html_chapters .= "<tr>";
$html_chapters .= "<td class=\"pfs_item\"><div id=\"agendalist_$chapter[id]\">";
if( $edit_mode ) $html_chapters .= "<button onclick=\"markItem($chapter[id]);\" >Mark</button>";
$html_chapters .= "<a href=\"#\" onclick=\"gotoIndex($chapter[offset], '$chapter[name]');\" ><img src=\"images/play.gif\" alt=\"Play Video\" width=\"24\" height=\"17\"></a> ";
$html_chapters .= "<a href=\"#\" onclick=\"gotoIndex($chapter[offset], '$chapter[name]');\" >$chapter[name]</a>";
$html_chapters .= "</div></td>";
$html_chapters .= "</tr>\n";
// $html_chapters .= "<tr><td style=\"border-bottom: .5px solid #cccccc; line-height: 1em; padding-bottom:2px; \"><a href=\"".$chapter['url']."\" class=\"rollover\"></a><a href=\"".$chapter['url']."\" >".$chapter['name']."</a></td></tr>";
}
$html_section_footer = "</table>";
$html_allitems = '<table>' . $html_chapters . '</table>';
return $html_allitems;
}
function getAllItems( $mediaid )
{
global $db;
global $broadcasterid;
$mediaid_db = $db->quoteSmart( $mediaid );
$sql = '';
$sql .= "( SELECT id, name, posted FROM agenda_items WHERE mediaid=$mediaid AND broadcasterid=$broadcasterid AND posted AND NOT deleted ORDER BY date DESC )";
$sql .= " UNION ";
$sql .= "( SELECT id, name, posted FROM agenda_items WHERE mediaid=$mediaid AND broadcasterid=$broadcasterid AND NOT posted AND NOT deleted ORDER BY id )";
$sql .= ";";
$result = $db->getAll( $sql, array(), DB_FETCHMODE_ASSOC );
if( PEAR::isError( $result ) )
{
error_log( "Chat::all: " . $result->GetMessage() );
exit;
}
$allItems = '';
foreach( $result as $item )
{
$item_html = "<li class=\"section_break\"><h3><div id=\"agendaitem_$item[id]\" >$item[name]</div></h3>";
if( !$item['posted'] )
$item_html .= "<button onclick=\"doMarkItem($item[id]);\" >Mark</button> <button onclick=\"doEdiItem($item[id],'$item[name]');\" >Edit</button> <button onclick=\"doDelItem($item[id]);\" >Delete</button>";
$item_html .= "<p></p></li>";
$allItems .= $item_html . "\n";
}
return $allItems;
}
$mediaid = 0;
if( isset( $_REQUEST['mediaid'] ) )
{
$mediaid = $_REQUEST['mediaid'];
}
if( isset( $_REQUEST['cmd'] ) )
{
switch( $_REQUEST['cmd'] )
{
case 'add':
$result = addItem( $mediaid );
break;
case 'del':
$result = delItem( $mediaid );
break;
case 'mrk':
$result = mrkItem( $mediaid );
break;
case 'mk2':
$result = ediItemMark( $mediaid );
break;
case 'get':
$result = getAllItems( $mediaid );
break;
case 'ply':
$result = getPlyItems( $mediaid );
break;
case 'pre':
break;
case 'lst':
$result = getAllItems2( $mediaid );
break;
case 'mk3':
$result = ediItemMark2( $mediaid );
break;
}
if( isset( $result ) )
echo $result;
}
?>