0917d3 | 2013-03-04 | Anders Johansson | |
|
149437 | 2003-07-31 | Anders Johansson | |
|
0a2948 | 2001-08-22 | Per Hedbor | | inherit Variable.Variable;
|
5004d1 | 2001-08-22 | Martin Nilsson | |
|
0a2948 | 2001-08-22 | Per Hedbor | |
#define LOCALE(X,Y) \
([string](mixed)Locale.translate("roxen_config",roxenp()->locale->get(),X,Y))
|
5004d1 | 2001-08-22 | Martin Nilsson | |
|
0a2948 | 2001-08-22 | Per Hedbor | |
|
97c832 | 2002-04-23 | Henrik Grubbström (Grubba) | |
|
5004d1 | 2001-08-22 | Martin Nilsson | |
|
0a2948 | 2001-08-22 | Per Hedbor | |
|
97c832 | 2002-04-23 | Henrik Grubbström (Grubba) | |
|
5004d1 | 2001-08-22 | Martin Nilsson | |
|
0a2948 | 2001-08-22 | Per Hedbor | |
|
d8816e | 2002-10-22 | Jonas Wallden | |
|
97c832 | 2002-04-23 | Henrik Grubbström (Grubba) | |
|
0a2948 | 2001-08-22 | Per Hedbor | |
|
e7c340 | 2002-10-03 | Anders Johansson | | array transform_from_form( string what, mapping vl )
|
0a2948 | 2001-08-22 | Per Hedbor | | {
array res = query() + ({});
if(sizeof(res)!=5)
res = ({ 0, 2, 1, 6, 3 });
res[0] = (int)what;
for(int i=1; i<5; i++) {
res[i] = (int)vl[(string)i];
res[i] = max( ({ 0, 1, 1, 0, 0 })[i], res[i] );
res[i] = min( ({ 2, 23, 9, 7, 23 })[i], res[i] );
}
return res;
}
private string checked( int pos, int alt )
{
if(alt==query()[pos])
return " checked='checked'";
return "";
}
|
e7c340 | 2002-10-03 | Anders Johansson | | private mapping next_or_same_day(mapping from, int day, int hour)
|
0a2948 | 2001-08-22 | Per Hedbor | | {
|
e7c340 | 2002-10-03 | Anders Johansson | | if(from->wday==day && from->hour<hour)
return from;
|
0a2948 | 2001-08-22 | Per Hedbor | | return next_day(from, day);
}
private mapping next_day(mapping from, int day)
{
|
795b95 | 2020-03-27 | Henrik Grubbström (Grubba) | | int num_days = ((6 + day - from->wday) % 7) + 1;
from->hour = 12;
mapping m = localtime(mktime(from) + num_days * 3600 * 24);
m->hour = from->hour = 0;
return m;
|
0a2948 | 2001-08-22 | Per Hedbor | | }
private mapping next_or_same_time(mapping from, int hour, void|int delta)
{
if(from->hour==hour) return from;
return next_time(from, hour, delta);
}
private mapping next_time(mapping from, int hour, void|int delta)
{
if(from->hour<hour) {
from->hour = hour;
return from;
}
|
4dbfcf | 2002-04-25 | Anders Johansson | | return localtime(mktime(from) + (24 - from->hour + hour)*3600 + delta);
|
0a2948 | 2001-08-22 | Per Hedbor | | }
int get_next( int last )
|
5004d1 | 2001-08-22 | Martin Nilsson | |
|
97c832 | 2002-04-23 | Henrik Grubbström (Grubba) | |
|
0a2948 | 2001-08-22 | Per Hedbor | | {
array vals = query();
if( !vals[0] )
return -1;
|
e7c340 | 2002-10-03 | Anders Johansson | |
|
0a2948 | 2001-08-22 | Per Hedbor | | if( vals[0] == 1 )
if( !last )
return time(1);
else
return last + 3600 * vals[1];
mapping m = localtime( last || time(1) );
m->min = m->sec = 0;
|
4dbfcf | 2002-04-25 | Anders Johansson | | if( !vals[3] ) {
|
075731 | 2002-10-09 | Anders Johansson | |
if (!last)
{
for(int i; i<vals[2]; i++)
m = next_or_same_time( m, vals[4] );
return mktime(m);
}
else
{
for(int i; i<vals[2]; i++)
m = next_time( m, vals[4] );
return mktime(m);
}
}
if (!last)
{
|
4dbfcf | 2002-04-25 | Anders Johansson | | for(int i; i<vals[2]; i++)
|
075731 | 2002-10-09 | Anders Johansson | | {
m = next_or_same_time( next_or_same_day( m, vals[3]-1, vals[4]+1 ),
vals[4], 6*24*3600 );
}
|
0a2948 | 2001-08-22 | Per Hedbor | | }
|
075731 | 2002-10-09 | Anders Johansson | | else
|
4dbfcf | 2002-04-25 | Anders Johansson | | {
|
075731 | 2002-10-09 | Anders Johansson | | for(int i; i<vals[2]; i++)
{
m = next_or_same_time( next_or_same_day( m, vals[3]-1, vals[4] ),
vals[4], 6*24*3600 );
}
|
4dbfcf | 2002-04-25 | Anders Johansson | | }
return mktime(m);
|
0a2948 | 2001-08-22 | Per Hedbor | | }
string render_form( RequestID id, void|mapping additional_args )
{
string res, inp1, inp2, inp3;
res = "<table>"
"<tr valign='top'><td><input name='" + path() + "' value='0' type='radio' " +
|
9fa11d | 2001-08-24 | Martin Nilsson | | checked(0,0) + " /></td><td>" + LOCALE(482, "Never") + "</td></tr>\n";
|
0a2948 | 2001-08-22 | Per Hedbor | |
|
3931ad | 2003-07-25 | Anders Johansson | | inp1 = HTML.select(path()+"1", "123456789"/1 + "1011121314151617181920212223"/2, (string)query()[1]);
|
0a2948 | 2001-08-22 | Per Hedbor | |
res += "<tr valign='top'><td><input name='" + path() + "' value='1' type='radio' " +
|
9fa11d | 2001-08-24 | Martin Nilsson | | checked(0,1) + " /></td><td>" + sprintf( LOCALE(483, "Every %s hour(s)."), inp1) +
|
0a2948 | 2001-08-22 | Per Hedbor | | "</td></tr>\n";
|
3931ad | 2003-07-25 | Anders Johansson | | inp1 = HTML.select(path()+"2", "123456789"/1, (string)query()[2]);
inp2 = HTML.select(path()+"3", ({
|
9fa11d | 2001-08-24 | Martin Nilsson | | ({ "0", LOCALE(484, "Day") }),
({ "1", LOCALE(485, "Sunday") }),
({ "2", LOCALE(486, "Monday") }),
({ "3", LOCALE(487, "Tuesday") }),
({ "4", LOCALE(488, "Wednesday") }),
({ "5", LOCALE(489, "Thursday") }),
({ "6", LOCALE(490, "Friday") }),
({ "7", LOCALE(491, "Saturday") }) }), (string)query()[3]);
|
3931ad | 2003-07-25 | Anders Johansson | | inp3 = HTML.select(path()+"4", "000102030405060708091011121314151617181920212223"/2,
|
0a2948 | 2001-08-22 | Per Hedbor | | sprintf("%02d", query()[4]));
res += "<tr valign='top'><td><input name='" + path() + "' value='2' type='radio' " +
checked(0,2) + " /></td>\n<td>" +
|
9fa11d | 2001-08-24 | Martin Nilsson | | sprintf(LOCALE(492, "Every %s %s at %s o'clock."), inp1, inp2, inp3) +
|
0a2948 | 2001-08-22 | Per Hedbor | | "</td></tr>\n</table>";
return res;
}
string render_view( RequestID id, void|mapping additional_args )
{
array res = query();
switch(res[0]) {
case 0:
|
9fa11d | 2001-08-24 | Martin Nilsson | | return LOCALE(482, "Never");
|
0a2948 | 2001-08-22 | Per Hedbor | | case 1:
|
9fa11d | 2001-08-24 | Martin Nilsson | | return sprintf(LOCALE(493, "Every %d hour."), res[1]);
|
0a2948 | 2001-08-22 | Per Hedbor | | case 2:
string period = ({
|
9fa11d | 2001-08-24 | Martin Nilsson | | LOCALE(484, "Day"),
|
e7c340 | 2002-10-03 | Anders Johansson | | LOCALE(485, "Sunday"),
|
9fa11d | 2001-08-24 | Martin Nilsson | | LOCALE(486, "Monday"),
LOCALE(487, "Tuesday"),
LOCALE(488, "Wednesday"),
LOCALE(489, "Thursday"),
LOCALE(490, "Friday"),
|
e7c340 | 2002-10-03 | Anders Johansson | | LOCALE(491, "Saturday")
|
0a2948 | 2001-08-22 | Per Hedbor | | })[query()[3]];
|
9fa11d | 2001-08-24 | Martin Nilsson | | return sprintf(LOCALE(494, "Every %d %s at %02d:00"), res[2], period, res[4]);
|
0a2948 | 2001-08-22 | Per Hedbor | | default:
|
9fa11d | 2001-08-24 | Martin Nilsson | | return LOCALE(495, "Error in stored value.");
|
0a2948 | 2001-08-22 | Per Hedbor | | }
}
|