-
Notifications
You must be signed in to change notification settings - Fork 3
/
admin.php
580 lines (538 loc) · 18.3 KB
/
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
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
<?php
// Event Administration by Poster
// $Id: admin.php,v 1.38 2010/06/27 04:12:30 nobu Exp $
include 'header.php';
include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
include_once 'notify.inc.php';
require 'perm.php';
$eid = param( 'eid' );
$op = param( 'op', $eid ? 'edit' : 'new' );
if ( isset( $_POST['save'] ) ) {
$op = 'save';
} elseif ( isset( $_POST['preview'] ) ) {
$op = 'preview';
} elseif ( isset( $_POST['editdate'] ) ) {
$op = 'date';
} elseif ( empty( $op ) ) {
$op = 'new';
}
// store in database
$adm = $xoopsUser->isAdmin( $xoopsModule->mid() );
$uid = $xoopsUser->getVar( 'uid' );
// set form data
$iargs = array(
'reservation',
'strict',
'autoaccept',
'notify',
'persons',
'style'
); // integer value default '0'
$targs = array( 'title', 'summary', 'body', 'optfield', 'before' );
define( "_EG_OPTDEFS", "redirect=" . _MD_RESERV_REDIRECT . ",text\n" );
$myts = MyTextSanitizer::getInstance();
$xoopsOption['template_main'] = EGPREFIX . '_admin.html';
if ( $op == 'new' ) {
// default value in post form
$data = array(
'lang_event_edit' => _MD_NEWTITLE,
'reservation' => 1, // reservation: 0=disable, 1=enable
'style' => 1, // edit text: 0=html, 1=CRLF, 2=plain
'autoaccept' => 1, // order to: 0=confirm, 1=accepted
'notify' => 1, // notify to poster: 0=nothing, 1=send
'strict' => 1, // order when full: 0=continue, 1=stop
'persons' => $xoopsModuleConfig['default_persons'],
// how many persons/sheet in room
'optfield' => $xoopsModuleConfig['member_only'] ? _MD_RESERV_DEFAULT_MEMBER : _MD_RESERV_DEFAULT_ITEM,
'title' => '', // contents
'summary' => '',
'body' => '',
'counter' => 0,
'reserved' => 0,
'edate' => time() + 3600 * 24, // now + a day
'event' => '',
'expire' => $xoopsModuleConfig['expire_after'] * 60,
'closetime' => $xoopsModuleConfig['close_before'] * 60,
'optvars' => '',
'topicid' => 1
);
} else {
if ( $eid ) {
$result = $xoopsDB->query( 'SELECT * FROM ' . EGTBL . ' e LEFT JOIN ' . OPTBL . ' o ON e.eid=o.eid LEFT JOIN ' . CATBL . " ON topicid=catid WHERE e.eid=$eid" );
$data = $xoopsDB->fetchArray( $result );
$edate = $data['edate'];
} else {
$data = array();
}
$data['lang_event_edit'] = _MD_EDITARTICLE;
if ( $op == 'preview' || $op == 'save' || $op == 'date' ) {
$edate = getDateField( "edate" );
if ( isset( $_POST['expire'] ) ) {
$expire = empty( $_POST['expire'] ) ? time_to_sec( $_POST['expire_text'] ) : (int) $_POST['expire'];
} else {
$expire = getDateField( 'expire' );
}
$data['ldate'] = $data['edate'] = $edate;
$data['expire'] = $expire;
$data['topicid'] = param( 'topicid', 1 );
foreach ( $iargs as $name ) {
$data[ $name ] = param( $name );
}
foreach ( $targs as $name ) {
$data[ $name ] = param( $name, "" );
}
$data['ldate'] = 0;
$data['closetime'] = time_to_sec( $data['before'] );
if ( $adm ) {
$data['status'] = param( 'status' );
}
$data['optvars'] = post_optvars( _EG_OPTDEFS );
}
}
if ( ! isset( $data['status'] ) ) {
$data['status'] = $xoopsModuleConfig['auth'] ? STAT_POST : STAT_NORMAL;
}
$extent_sets = array();
if ( isset( $_POST['extent_sets'] ) ) {
$init = false;
$sets = $_POST['extent_sets'];
} else {
$init = true;
}
$input_extent = '';
if ( $eid ) { // already exists extents
$result = $xoopsDB->query( 'SELECT rvid FROM ' . RVTBL . " WHERE eid=$eid AND exid=0", 1 );
if ( $xoopsDB->getRowsNum( $result ) == 0 ) {
$save = _MD_EDIT_EXTENT . "(" . _MD_SAVE . ")";
$input_extent = "<input type='submit' name='editdate' value='$save'/>
<a href='editdate.php?eid=$eid'>" . _MD_EDIT_EXTENT . "</a>";
}
$result = $xoopsDB->query( 'SELECT * FROM ' . EXTBL . ' WHERE eidref=' . $eid . ' ORDER BY exdate' );
while ( $ext = $xoopsDB->fetchArray( $result ) ) {
$n = $ext['exid'];
$ext['date'] = eventdate( $ext['exdate'] );
$ext['no'] = $n;
$ext['disable'] = true;
$extent_sets[] = $ext;
}
} else {
$extents = param( 'extents', "none" );
$repeat = param( 'repeat', 1 );
$input_extent = select_list( 'extents', $ev_extents, $extents );
$input_extent .= ' ' . _MD_EXTENT_REPEAT . " <input size='2' value='$repeat' name='repeat'/>";
$step = 86400; // sec/day
switch ( $extents ) {
case 'weekly':
$step = $step * 7;
case 'daily':
for ( $n = 0, $i = $edate; $n < $repeat; $n ++, $i += $step ) {
$v = $init ? true : isset( $sets[ $n ] );
$extent_sets[] =
array(
'exdate' => $i,
'no' => $n,
'date' => eventdate( $i ),
'checked' => $v
);
$sets[ $n ] = $v ? $i : 0;
}
break;
case 'monthly':
list( $y, $m, $d, $h, $mi ) = explode( ' ', formatTimestamp( $edate, "Y m j G i" ) );
for ( $n = 0; $n < $repeat; $n ++ ) {
$i = userTimeToServerTime( mktime( $h, $mi, 0, $m + $n, $d, $y ) );
$v = $init ? true : isset( $sets[ $n ] );
$extent_sets[] =
array(
'exdate' => $i,
'no' => $n,
'date' => eventdate( $i ),
'checked' => $v
);
$sets[ $n ] = $v ? $i : 0;
}
default:
break;
}
}
$now = time();
if ( $op == 'save' || $op == 'date' ) {
// database field names
$updated = "";
$fields = array(
'title' => _MD_TITLE,
'edate' => _MD_EVENT_DATE,
'expire' => _MD_EVENT_EXPIRE,
'summary' => _MD_INTROTEXT,
'body' => _MD_EXTEXT,
'style' => _MD_EVENT_STYLE,
'status' => $ev_stats[ STAT_NORMAL ],
'topicid' => _MD_EVENT_CATEGORY
);
if ( $eid ) {
$cond = $adm ? "" : " AND uid=$uid"; // condition update by poster
$result = $xoopsDB->query( 'SELECT * FROM ' . EGTBL . " WHERE eid=$eid" );
$pdata = $xoopsDB->fetchArray( $result );
$buf = "mdate=$now";
foreach ( $fields as $name => $label ) {
if ( $pdata[ $name ] != $data[ $name ] ) {
$buf .= ", $name=" . $xoopsDB->quoteString( $data[ $name ] );
if ( $name == 'edate' ) {
$label .= " " . formatTimestamp( $pdata[ $name ], _MD_POSTED_FMT ) . " -> " . formatTimestamp( $data[ $name ], _MD_POSTED_FMT );
}
$updated .= " " . $label . "\n";
}
}
$xoopsDB->query( 'UPDATE ' . EGTBL . ' SET ' . $buf . " WHERE eid=$eid $cond" );
$delta = $edate - $pdata['edate'];
if ( $delta ) {
$xoopsDB->query( 'UPDATE ' . EXTBL . " SET exdate=exdate+'$delta' WHERE eidref=$eid AND exdate>$now" );
}
} else {
$pdata = array( 'status' => STAT_POST );
$flist = "uid, cdate, mdate";
$buf = "$uid, $now, $now";
foreach ( array_keys( $fields ) as $name ) {
$flist .= ", $name";
$buf .= ', ' . $xoopsDB->quoteString( $data[ $name ] );
}
$xoopsDB->query( 'INSERT INTO ' . EGTBL . "($flist) VALUES($buf)" );
$data['eid'] = $eid = $xoopsDB->getInsertId();
$data['uid'] = $uid;
if ( ! empty( $sets ) ) {
foreach ( $sets as $v ) {
if ( $v ) {
$xoopsDB->query( 'INSERT INTO ' . EXTBL . "(eidref, exdate) VALUES($eid, $v)" );
}
}
}
event_notify( 'new', $data );
}
if ( empty( $eid ) ) {
echo "<div class='error'>Internal Error: eguide/admin.php</div>\n";
exit();
}
if ( $pdata['status'] != $data['status'] ) {
user_notify( $eid );
}
$result = $xoopsDB->query( "SELECT * FROM " . OPTBL . " WHERE eid=$eid" );
$ofields = array(
'reservation' => _MD_RESERV_DESC,
'strict' => _MD_RESERV_STOPFULL,
'autoaccept' => _MD_RESERV_AUTO,
'notify' => _MD_RESERV_NOTIFYPOSTER,
'persons' => _MD_RESERV_PERSONS,
'optfield' => _MD_RESERV_ITEM,
'closetime' => _MD_CLOSEDATE,
'optvars' => _MD_OPTION_VARS
);
if ( $xoopsDB->getRowsNum( $result ) ) {
$pdata = $xoopsDB->fetchArray( $result );
$buf = "";
foreach ( $ofields as $name => $label ) {
if ( $pdata[ $name ] != $data[ $name ] ) {
$buf .= ( empty( $buf ) ? '' : ', ' ) . $name . '=' . $xoopsDB->quoteString( $data[ $name ] );
switch ( $name ) {
case 'persons':
$label .= ' ' . $pdata[ $name ] . ' -> ' . $data[ $name ];
break;
case 'closetime':
$label .= ' ' . time_to_str( $pdata[ $name ] ) . ' -> ' . time_to_str( $data[ $name ] );
case 'reservation':
case 'strict':
case 'autoaccept':
case 'notify':
$label .= ' ' . ( $data[ $name ] ? _YES : _NO );
break;
}
$updated = " " . $label . "\n";
}
}
$xoopsDB->query( 'UPDATE ' . OPTBL . " SET $buf WHERE eid=$eid" );
} else {
$keys = array_keys( $ofields );
$flist = 'eid, ' . implode( ', ', $keys );
$buf = $eid;
foreach ( $keys as $name ) {
$buf .= ', ' . $xoopsDB->quoteString( $data[ $name ] );
}
$xoopsDB->query( "INSERT INTO " . OPTBL . "($flist) VALUES($buf)" );
}
if ( $updated && $data['status'] == STAT_NORMAL ) {
$dirname = basename( __DIR__ );
$tags = array(
'uid' => $data['uid'],
'URL_EVENTS' => $data['title'] . "\n" . XOOPS_URL . "/modules/$dirname/event.php?eid=" . $eid,
'UPDATED' => $updated,
'DO_UNAME' => $xoopsUser->getVar( 'uname' )
);
event_notify( 'update', $tags );
}
if ( $op == 'date' ) {
header( 'Location: ' . EGUIDE_URL . '/editdate.php?eid=' . $eid );
} else {
redirect_header( EGUIDE_URL . "/event.php?eid=$eid", 2, _MD_DBUPDATED );
}
exit;
} elseif ( $op == 'confirm' ) {
if ( $adm ) { // delete by admin
$result = $xoopsDB->query( 'DELETE FROM ' . EGTBL . " WHERE eid=$eid" );
$result = $xoopsDB->query( 'DELETE FROM ' . OPTBL . " WHERE eid=$eid" );
$result = $xoopsDB->query( 'DELETE FROM ' . RVTBL . " WHERE eid=$eid" );
$result = $xoopsDB->query( 'DELETE FROM ' . EXTBL . " WHERE eidref=$eid" );
} else { // delete by poster
$result = $xoopsDB->query( 'UPDATE ' . EGTBL . ' SET status=' . STAT_DELETED . " WHERE eid=$eid AND uid=$uid" );
}
redirect_header( EGUIDE_URL . "/index.php", 2, _MD_DBDELETED );
exit();
}
include( XOOPS_ROOT_PATH . "/header.php" );
assign_module_css();
// DHTML calendar
include_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/calendar.php';
if ( ! empty( $ev_week ) ) {
$xoopsTpl->assign( 'weekname', $ev_week );
}
if ( ! empty( $ev_month ) ) {
$xoopsTpl->assign( 'monthname', $ev_month );
}
$y = formatTimestamp( time(), 'Y' );
$xoopsTpl->assign( 'calrange', array( $y - 10, $y + 10 ) );
$check = array( 'title' => _MD_TITLE, 'summary' => _MD_INTROTEXT );
foreach ( $check as $k => $v ) {
$check[ $k ] = sprintf( _FORM_ENTER, $v );
}
$xoopsTpl->assign( 'check', $check );
$xoopsTpl->assign( 'use_fckeditor', eguide_form_options( 'use_fckeditor', 0 ) );
$xoopsTpl->assign( 'enable_copy', eguide_form_options( 'enable_copy', 0 ) );
$timetable = array();
$tstr = $xoopsModuleConfig['time_defs'];
if ( $tstr ) {
foreach ( explode( ',', $tstr ) as $value ) {
if ( strpos( $value, '=' ) ) {
list( $value, $label ) = explode( '=', $value );
} else {
$label = $value;
}
$timetable[] = array( 'label' => $label, 'value' => $value );
}
}
$xoopsTpl->assign( 'timetable', $timetable );
if ( $eid && $op == 'delete' ) {
$xoopsOption['template_main'] = EGPREFIX . '_event.html';
edit_eventdata( $data );
unset( $data['eid'] ); // disable control link
$xoopsTpl->assign( 'event', $data );
$xoopsTpl->assign( 'message', "<div><form action='admin.php' method='post'>
<input type='hidden' name='op' value='confirm' />
<input type='hidden' name='eid' value='$eid' />
<input type='submit' value='" . _DELETE . "' />
</form><b>" . _MD_EVENT_DEL_DESC . "</b></div>\n" .
( ( $adm ) ? "<div class='evnote'>" . _MD_EVENT_DEL_ADMIN . "</div>\n" : '' ) );
} else {
$expire = $data['expire'] > $data['edate'] ? $data['expire'] - $data['edate'] : $data['expire'];
$str = isset( $expire_set["+$expire"] ) ? "" : htmlspecialchars( time_to_str( $expire ) );
$input_expire = "<input name='expire_text' size='8' value='$str' onchange='document.evform.expire.selectedIndex=0' /> " .
select_list( 'expire', $expire_set, $expire );
$cats = get_eguide_category();
if ( count( $cats ) > 1 ) {
$input_category = select_list( 'topicid', $cats, $data['topicid'] );
} else {
$input_category = '';
}
if ( $op == 'preview' ) {
$views = array(
'edate',
'cdate',
'title',
'summary',
'body',
'persons',
'reserved',
'closetime',
'style',
'uid',
'counter',
'catid',
'catimg',
'catname'
);
$event = array();
if ( empty( $data['cdate'] ) ) {
$data['cdate'] = $now;
$data['reserved'] = 0;
$data['counter'] = 0;
$data['uid'] = $uid;
$data['catid'] = 1;
}
$result = $xoopsDB->query( 'SELECT catname, catimg FROM ' . CATBL . ' WHERE catid=' . $data['topicid'] );
list( $data['catname'], $data['catimg'] ) = $xoopsDB->fetchRow( $result );
foreach ( $views as $name ) {
$event[ $name ] = $data[ $name ];
}
edit_eventdata( $event );
$form = eventform( $data, 0 );
$form['submit_opts'] = 'disabled';
$xoopsTpl->assign( 'form', $form );
$xoopsTpl->assign( 'event', $event );
} else {
$xoopsTpl->assign( 'event', '' );
}
$input_status = $adm ? select_list( 'status', $ev_stats, $data['status'] ) : '';
if ( empty( $data['before'] ) ) {
$data['before'] = time_to_str( $data['closetime'] );
}
edit_eventdata( $data );
$data['optfield'] = htmlspecialchars( $data['optfield'] );
$xoopsTpl->assign( $data );
class myFormDhtmlTextArea extends XoopsFormDhtmlTextArea {
function _renderSmileys() {
} // only disable smileys
}
$summary = isset( $data['summary'] ) ? $data['summary'] : '';
$textarea = new myFormDhtmlTextArea( '', 'summary', $summary, 10, 60 );
$nlab = eguide_form_options( 'label_persons' );
if ( $nlab ) {
$nlab = sprintf( _MD_RESERV_LABEL_DESC, $nlab );
}
$edate = $data['edate'];
$xoopsTpl->assign( array(
'input_edate' => datefield( 'edate', $edate ),
'input_edatetime' => timefield( 'edate', $edate ),
'edatetime' => formatTimestamp( $edate, 'H:i' ),
'input_expire' => $input_expire,
'input_category' => $input_category,
'input_extent' => $input_extent,
'input_status' => $input_status,
'extent_sets' => $extent_sets,
'label_desc' => $nlab,
'summary_textarea' => $textarea->render(),
'input_style' => select_list( 'style', $edit_style, $data['style'] ),
'edata' => $data,
) );
if ( is_string($data['optvars']) ) {
$optvars = !empty($data['optvars'])?unserialize_vars( $data['optvars'] ) : array( 'redirect'=>'' );
$xoopsTpl->assign( 'optvars', $optvars );
foreach ( explode( "\n", _EG_OPTDEFS ) as $item ) {
list( $fname ) = explode( "=", $item );
unset( $optvars[ $fname ] );
}
$others = "";
foreach ( $optvars as $k => $v ) {
$others .= "$k=$v\n";
}
$xoopsTpl->assign( 'opt_others', $others );
}
$xoopsTpl->assign( array(
'input_edate' => datefield( 'edate', $edate ),
'input_edatetime' => timefield( 'edate', $edate ),
'edatetime' => formatTimestamp( $edate, 'H:i' ),
'input_expire' => $input_expire,
'input_category' => $input_category,
'input_extent' => $input_extent,
'input_status' => $input_status,
'extent_sets' => $extent_sets,
'label_desc' => $nlab,
'summary_textarea' => $textarea->render(),
'input_style' => select_list( 'style', $edit_style, $data['style'] ),
) );
}
$paths = array();
if ( $eid ) {
$cid = $data['topicid'];
$paths[ $data['title'] ] = "event.php?eid=$eid";
if ( $op == 'delete' ) {
$paths[ _DELETE ] = "admin.php?op=delete&eid=$eid";
} else {
$paths[ _EDIT ] = "admin.php?eid=$eid";
}
} else {
$cid = 0;
$paths[ _MD_NEWTITLE ] = 'admin.php';
}
set_eguide_breadcrumbs( $cid, $paths );
include( XOOPS_ROOT_PATH . "/footer.php" );
// make to unix time from separate fields.
function getDateField( $p ) {
global $xoopsUser;
if ( empty( $_POST["{$p}ymd"] ) ) {
return 0;
}
list( $y, $m, $d ) = explode( '-', $_POST["{$p}ymd"] );
if ( isset( $_POST["{$p}time"] ) ) { // accept 'HH:mm' format
list( $hour, $min ) = explode( ':', $_POST["{$p}time"] );
} else {
$hour = $_POST["{$p}hour"];
$min = $_POST["{$p}min"];
}
return userTimeToServerTime( mktime( $hour, $min, 0, $m, $d, $y ), $xoopsUser->getVar( "timezone_offset" ) );
}
function datefield( $prefix, $time, $hastime = true ) {
$buf = "<input id='{$prefix}ymd' name='{$prefix}ymd' size='12' value='" . formatTimestamp( $time, "Y-m-d" ) . "'/> ";
$buf .= "<script language='javascript'><!--
document.write('<input type=\"button\" value=\"" . _MD_CAL . "\" onClick=\"showCalendar(\\'{$prefix}ymd\\')\">');
--></script>\n";
return $buf;
}
function timefield( $prefix, $time ) {
list( $h, $i ) = explode( ' ', formatTimestamp( $time, "G i" ) );
$buf = select_value( "%02d", "{$prefix}hour", 0, 23, $h );
$buf .= " : ";
$buf .= select_value( "%02d", "{$prefix}min", 0, 59, $i, 5 );
$buf .= " : 00\n";
return $buf;
}
function select_value( $fmt, $name, $from, $to, $def = 0, $step = 1 ) {
$buf = "<select name='$name' id='$name'>\n";
for ( $i = $from; $i <= $to; $i += $step ) {
$buf .= "<option value='$i'" . ( $i == $def ? " selected='selected'" : "" ) . ">" . sprintf( $fmt, $i ) . "</option>\n";
}
$buf .= "</select>\n";
return $buf;
}
function select_list( $name, $options, $def = 1 ) {
$buf = "<select name='$name'>\n";
foreach ( $options as $i => $v ) {
if ( is_array( $v ) ) {
$v = $v['name'];
}
$buf .= "<option value='$i'" . ( $i == $def ? " selected='selected'" : "" ) . ">$v</option>\n";
}
$buf .= "</select>\n";
return $buf;
}
function time_to_str( $sec ) {
$unit = explode( ',', _MD_TIME_UNIT );
if ( ( abs( $sec ) >= 86400 ) && ( $sec % 86400 ) == 0 ) { // days
return ( $sec / 86400 ) . $unit[0];
} elseif ( ( abs( $sec ) >= 3600 ) && ( $sec % 3600 == 0 ) ) { // hours
return ( $sec / 3600 ) . $unit[1];
}
return (int) ( $sec / 60 ) . $unit[2];
}
function time_to_sec( $str ) {
$unit = explode( ',', _MD_TIME_REG );
$v = (int) $str;
if ( preg_match( '/^-?\d+' . $unit[0] . '$/i', $str ) ) {
return $v * 86400;
} elseif ( preg_match( '/^-?\d+' . $unit[1] . '?$/i', $str ) ) {
return $v * 3600;
}
return $v * 60;
}
function post_optvars( $defs ) {
$vars = array();
foreach ( explode( "\n", $defs ) as $item ) {
list( $fname ) = explode( "=", $item );
$v = param( $fname, '' );
if ( ! empty( $v ) ) {
$vars[ $fname ] = "$fname=$v";
}
}
$fname = 'opt_others';
$v = param( $fname, '' );
if ( ! empty( $v ) ) {
$vars[ $fname ] = $v;
}
return join( "\n", $vars );
}