77bdaf | 2008-12-11 | Jonas Wallden | |
|
ef40dc | 2000-09-01 | Martin Stjernholm | |
|
d1de94 | 2000-08-19 | Martin Nilsson | | #include <module.h>
#include <roxen.h>
|
2f02b1 | 2000-10-12 | Martin Nilsson | | #define LOCALE(X,Y) \
([string](mixed)Locale.translate("roxen_config",roxenp()->locale->get(),X,Y))
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
23f13c | 2002-05-13 | Jonas Wallden | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected int unique_vid;
protected string unique_prefix = (string) getpid();
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
edbf2d | 2000-09-19 | Per Hedbor | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected mapping(string:mixed) changed_values = ([]);
protected mapping(string:function(object:void)) changed_callbacks = ([]);
protected mapping(string:int) all_flags = ([]);
protected mapping(string:string) all_warnings = ([]);
protected mapping(string:function(RequestID,object:int))
|
d1de94 | 2000-08-19 | Martin Nilsson | | invisibility_callbacks = set_weak_flag( ([]), 1 );
|
a7defb | 2001-08-01 | Per Hedbor | | mapping(string:Variable) all_variables = set_weak_flag( ([]), 1 );
mapping get_all_variables()
{
return all_variables;
}
Variable get_variables( string v )
{
return all_variables[v];
}
|
67aeb1 | 2001-08-17 | Per Hedbor | | string get_diff_def_html( Variable v,
string button_tag,
string def_url,
string diff_url,
int page )
{
if( page )
return v->diff( 2 );
if( v->is_defaulted() || (v->get_flags() & VAR_NO_DEFAULT) )
return "";
string oneliner = v->diff( 0 ), diff_button="";
mapping m;
if( !oneliner )
{
if( v->diff( 1 ) )
{
m = ([ "href":diff_url,"target":"_new", ]);
diff_button =
Roxen.make_container( "a",m,
Roxen.make_container(
button_tag,
([]),
|
9fa11d | 2001-08-24 | Martin Nilsson | | LOCALE(474,"Show changes")
|
67aeb1 | 2001-08-17 | Per Hedbor | | ) );
}
}
m = ([ "href":def_url, ]);
return diff_button + " " +
Roxen.make_container( "a",m,
Roxen.make_container( button_tag, ([]),
|
9fa11d | 2001-08-24 | Martin Nilsson | | LOCALE(475, "Restore default value" )+
|
67aeb1 | 2001-08-17 | Per Hedbor | | (oneliner||"") ) );
}
|
a7defb | 2001-08-01 | Per Hedbor | | class Diff
{
|
fc4039 | 2008-08-15 | Martin Stjernholm | | private array(string) diff;
|
a7defb | 2001-08-01 | Per Hedbor | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | private
|
a7defb | 2001-08-01 | Per Hedbor | | array(string) print_row(array(string) diff_old, array(string) diff_new,
int line, int|void start, int|void end)
{
if(!sizeof(diff_old) && sizeof(diff_new))
return Array.map(diff_new, lambda(string s) {return "+ " + s;} );
if(sizeof(diff_old) && !sizeof(diff_new))
return Array.map(diff_old, lambda(string s) {return "- " + s;} );
if(diff_old != diff_new)
return Array.map(diff_old, lambda(string s) {return "- " + s;} )
+ Array.map(diff_new, lambda(string s) {return "+ " + s;} );
if(start + end < sizeof(diff_old) && (start || end))
{
if(start && !end)
diff_old = diff_old[.. start - 1];
else
{
diff_old = diff_old[.. start - 1] +
({ line + sizeof(diff_old) - end }) +
diff_old[sizeof(diff_old) - end ..];
}
}
return Array.map(diff_old, lambda(string|int s)
{ if(intp(s)) return "Line "+s+":";
return " " + s; } );
}
string html(void|int hide_header)
{
string r = "";
int added, deleted;
if(sizeof(diff) && diff[-1] == " ")
diff = diff[..sizeof(diff)-2];
foreach(diff, string row)
{
row = Roxen.html_encode_string(row);
row = replace(row, "\t", " ");
row = replace(row, " ", " ");
switch(row[0])
{
case '&': r += "<tt>"+row+"</tt><br>\n";
break;
case '+': r += "<tt><font color='darkgreen'>"+row+"</font></tt><br>\n";
added++;
break;
case '-': r += "<tt><font color='darkred'>"+row+"</font></tt><br>\n";
deleted++;
break;
case 'L': r += "<i>"+row+"</i><br>\n";
break;
}
}
if (!hide_header)
r =
|
9fa11d | 2001-08-24 | Martin Nilsson | | "<b>" + LOCALE(476, "Change in content") + "</b><br />\n"+
"<i>"+(added==1? LOCALE(477, "1 line added."):
sprintf(LOCALE(478, "%d lines added."), added)) + " " +
(deleted==1? LOCALE(479, "1 line deleted."):
sprintf(LOCALE(480, "%d lines deleted."), deleted)) +
|
a7defb | 2001-08-01 | Per Hedbor | | "</i><p>\n"+
r;
return r;
}
array get()
{
return diff;
}
void create(array(string) new, array(string) old, int context)
{
array(array(string)) diff_old, diff_new;
[diff_old, diff_new] = Array.diff(old, new);
int line = 1;
int diffp = 0;
diff = ({ });
for(int i = 0; i < sizeof(diff_old); i++)
{
if(diff_old[i] != diff_new[i])
{
diff += print_row(diff_old[i], diff_new[i], line);
diffp = 1;
}
else if(sizeof(diff_old) > 1)
{
diff += print_row(diff_old[i], diff_new[i], line,
diffp?context:0,
sizeof(diff_old) - 1 > i?context:0 );
diffp = 0;
}
line += sizeof(diff_old[i] - ({ }));
}
}
}
|
d1de94 | 2000-08-19 | Martin Nilsson | | class Variable
{
constant is_variable = 1;
constant type = "Basic";
|
23f13c | 2002-05-13 | Jonas Wallden | | string _id = unique_prefix + "_" + (string) unique_vid++;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected mixed _initial;
protected string _path = sprintf("v%s",_id);
protected LocaleString __name, __doc;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
a7defb | 2001-08-01 | Per Hedbor | | string diff( int render )
|
67aeb1 | 2001-08-17 | Per Hedbor | |
|
a7defb | 2001-08-01 | Per Hedbor | |
{
return 0;
}
|
d1de94 | 2000-08-19 | Martin Nilsson | | void destroy()
{
|
dd9148 | 2004-02-17 | Martin Stjernholm | | if (global::this) {
m_delete( all_flags, _id );
m_delete( all_warnings, _id );
m_delete( invisibility_callbacks, _id );
m_delete( changed_values, _id );
}
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
string get_warnings()
{
return all_warnings[ _id ];
}
int get_flags()
{
return all_flags[_id];
}
void set_flags( int flags )
|
65025e | 2000-10-19 | Per Hedbor | |
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
if(!flags )
m_delete( all_flags, _id );
else
all_flags[_id] = flags;
}
int check_visibility( RequestID id,
int more_mode,
int expert_mode,
int devel_mode,
|
82f9da | 2000-09-16 | Per Hedbor | | int initial,
int|void variable_in_cfif )
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
82f9da | 2000-09-16 | Per Hedbor | |
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
int flags = get_flags();
function cb;
|
e51c7b | 2000-12-08 | Martin Nilsson | | if( flags & VAR_INVISIBLE ) return 0;
|
82f9da | 2000-09-16 | Per Hedbor | | if( initial && !(flags & VAR_INITIAL) ) return 0;
if( (flags & VAR_EXPERT) && !expert_mode ) return 0;
if( (flags & VAR_MORE) && !more_mode ) return 0;
if( (flags & VAR_DEVELOPER) && !devel_mode ) return 0;
if( (flags & VAR_NOT_CFIF) && variable_in_cfif ) return 0;
|
d1de94 | 2000-08-19 | Martin Nilsson | | if( (cb = get_invisibility_check_callback() ) &&
cb( id, this_object() ) )
return 0;
return 1;
}
void set_invisibility_check_callback( function(RequestID,Variable:int) cb )
{
if( functionp( cb ) )
invisibility_callbacks[ _id ] = cb;
else
m_delete( invisibility_callbacks, _id );
}
function(Variable:void) get_changed_callback( )
{
return changed_callbacks[ _id ];
}
void set_changed_callback( function(Variable:void) cb )
{
if( functionp( cb ) )
changed_callbacks[ _id ] = cb;
else
m_delete( changed_callbacks, _id );
}
|
c6fd2e | 2000-09-03 | Per Hedbor | | void add_changed_callback( function(Variable:void) cb )
{
mixed oc = get_changed_callback( );
if( arrayp( oc ) )
oc += ({ cb });
else
oc = ({ oc, cb }) - ({ 0 });
changed_callbacks[ _id ] = oc;
}
|
d1de94 | 2000-08-19 | Martin Nilsson | | function(RequestID,Variable:int) get_invisibility_check_callback()
{
return invisibility_callbacks[_id];
}
|
79ca87 | 2000-11-24 | Per Hedbor | | LocaleString doc( )
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
return __doc || "";
}
|
d32160 | 2005-02-04 | Martin Stjernholm | |
void set_doc (LocaleString doc)
{
__doc = doc;
}
|
79ca87 | 2000-11-24 | Per Hedbor | | LocaleString name( )
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
|
55a866 | 2000-11-20 | Per Hedbor | | return __name || LOCALE(326,"unnamed")+" "+_id;
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
|
d32160 | 2005-02-04 | Martin Stjernholm | | void set_name (LocaleString name)
{
__name = name;
}
|
79ca87 | 2000-11-24 | Per Hedbor | | LocaleString type_hint( )
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
}
mixed default_value()
{
return _initial;
}
|
bbaf61 | 2005-02-04 | Martin Stjernholm | | void set_default_value (mixed to)
{
_initial = to;
}
|
d1de94 | 2000-08-19 | Martin Nilsson | | void set_warning( string to )
{
if( to && strlen(to) )
all_warnings[ _id ] = to;
else
m_delete( all_warnings, _id );
}
|
b8fd5c | 2000-09-28 | Per Hedbor | | void add_warning( string to )
{
|
a882cd | 2000-09-28 | Per Hedbor | | if(to) set_warning( (get_warnings()||"") + to );
|
b8fd5c | 2000-09-28 | Per Hedbor | | }
|
d1de94 | 2000-08-19 | Martin Nilsson | | int set( mixed to )
|
397653 | 2001-06-13 | Martin Stjernholm | |
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
|
67b85e | 2001-11-12 | Martin Stjernholm | | string err;
mixed e2;
|
d1de94 | 2000-08-19 | Martin Nilsson | | if( e2 = catch( [err,to] = verify_set( to )) )
{
if( stringp( e2 ) )
{
|
b8fd5c | 2000-09-28 | Per Hedbor | | add_warning( e2 );
|
d1de94 | 2000-08-19 | Martin Nilsson | | return ([])[0];
}
throw( e2 );
}
|
b8fd5c | 2000-09-28 | Per Hedbor | | add_warning( err );
|
d1de94 | 2000-08-19 | Martin Nilsson | | return low_set( to );
}
int low_set( mixed to )
{
if( equal( to, query() ) )
return 0;
if( !equal(to, default_value() ) )
{
changed_values[ _id ] = to;
if( get_changed_callback() )
|
5d8bab | 2002-01-29 | Martin Stjernholm | | get_changed_callback()( this_object() );
|
d1de94 | 2000-08-19 | Martin Nilsson | | return 1;
}
else
{
m_delete( changed_values, _id );
if( get_changed_callback() )
|
5d8bab | 2002-01-29 | Martin Stjernholm | | get_changed_callback()( this_object() );
|
d1de94 | 2000-08-19 | Martin Nilsson | | return -1;
}
}
mixed query()
{
mixed v;
if( !zero_type( v = changed_values[ _id ] ) )
return v;
return default_value();
}
int is_defaulted()
{
return zero_type( changed_values[ _id ] ) ||
equal(changed_values[ _id ], default_value());
}
|
b8fd5c | 2000-09-28 | Per Hedbor | | array(string|mixed) verify_set_from_form( mixed new_value )
{
return ({ 0, new_value });
}
|
d1de94 | 2000-08-19 | Martin Nilsson | | array(string|mixed) verify_set( mixed new_value )
{
return ({ 0, new_value });
}
mapping(string:string) get_form_vars( RequestID id )
{
string p = path();
array names = glob( p+"*", indices(id->variables) );
mapping res = ([ ]);
foreach( sort(names), string n )
res[ n[strlen(p).. ] ] = id->variables[ n ];
return res;
}
|
39adcf | 2001-06-27 | Martin Nilsson | | mixed transform_from_form( string what, mapping|void v )
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
return what;
}
|
bacec9 | 2001-06-13 | Martin Nilsson | | int(0..1) set_from_form( RequestID id, void|int(0..1) force )
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
d9ab8c | 2001-05-22 | Martin Nilsson | |
|
bacec9 | 2001-06-13 | Martin Nilsson | |
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
b8fd5c | 2000-09-28 | Per Hedbor | |
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
b8fd5c | 2000-09-28 | Per Hedbor | | mixed val;
|
d9ab8c | 2001-05-22 | Martin Nilsson | | if( sizeof( val = get_form_vars(id)) && val[""])
|
b8fd5c | 2000-09-28 | Per Hedbor | | {
|
e8668d | 2001-08-28 | Martin Nilsson | | set_warning(0);
|
39adcf | 2001-06-27 | Martin Nilsson | | val = transform_from_form( val[""], val );
|
cc3171 | 2001-05-24 | Martin Nilsson | | if( !force && val == query() )
|
bacec9 | 2001-06-13 | Martin Nilsson | | return 0;
|
b8fd5c | 2000-09-28 | Per Hedbor | | array b;
mixed q = catch( b = verify_set_from_form( val ) );
if( q || sizeof( b ) != 2 )
{
if( q )
add_warning( q );
else
|
cd87a2 | 2000-11-27 | Martin Nilsson | | add_warning( "Internal error: Illegal sized array "
"from verify_set_from_form\n" );
|
bacec9 | 2001-06-13 | Martin Nilsson | | return 0;
|
b8fd5c | 2000-09-28 | Per Hedbor | | }
|
a882cd | 2000-09-28 | Per Hedbor | | if( b )
{
|
e8668d | 2001-08-28 | Martin Nilsson | | add_warning( b[0] );
|
a882cd | 2000-09-28 | Per Hedbor | | set( b[1] );
|
bacec9 | 2001-06-13 | Martin Nilsson | | return 1;
|
a882cd | 2000-09-28 | Per Hedbor | | }
|
b8fd5c | 2000-09-28 | Per Hedbor | | }
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
string path()
{
return _path;
}
void set_path( string to )
{
|
a7defb | 2001-08-01 | Per Hedbor | | m_delete( all_variables, _path );
|
d1de94 | 2000-08-19 | Martin Nilsson | | _path = to;
|
a7defb | 2001-08-01 | Per Hedbor | | all_variables[ to ] = this_object();
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
|
a96834 | 2000-08-25 | Martin Nilsson | | string render_form( RequestID id, void|mapping additional_args );
|
d1de94 | 2000-08-19 | Martin Nilsson | |
string render_view( RequestID id )
{
|
88c867 | 2000-09-19 | Per Hedbor | | mixed v = query();
if( arrayp(v) ) v = map(v,lambda(mixed v){return(string)v;})*", " ;
return Roxen.html_encode_string( (string)v );
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string _sprintf( int i )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
if( i == 'O' )
|
8fec79 | 2000-09-04 | Per Hedbor | | return sprintf( "Variable.%s(%s)",type,(string)name());
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create(mixed default_value, void|int flags,
void|LocaleString std_name, void|LocaleString std_doc)
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
set_flags( flags );
_initial = default_value;
__name = std_name;
__doc = std_doc;
|
a7defb | 2001-08-01 | Per Hedbor | | all_variables[ path() ] = this_object();
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
}
|
2c7616 | 2004-10-20 | Martin Stjernholm | | class NoLimit
{
string _sprintf (int flag)
{
switch (flag) {
case 's': return "n/a";
case 'O': return this == no_limit ? "no_limit" : "<bogus no_limit clone>";
default: return 0;
}
}
}
NoLimit no_limit = NoLimit();
|
d1de94 | 2000-08-19 | Martin Nilsson | |
class Float
{
inherit Variable;
constant type = "Float";
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected float|NoLimit _max = no_limit, _min = no_limit;
protected int _prec = 2;
protected int _may_be_empty = 0;
protected int(0..1) _is_empty = 0;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string _format( float|NoLimit m )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
2c7616 | 2004-10-20 | Martin Stjernholm | | if (m == no_limit)
return "n/a";
|
d1de94 | 2000-08-19 | Martin Nilsson | | if( !_prec )
return sprintf( "%d", (int)m );
return sprintf( "%1."+_prec+"f", m );
}
|
a7defb | 2001-08-01 | Per Hedbor | | string diff( int render )
{
if(!render)
return "("+_format(default_value())+")";
}
|
2c7616 | 2004-10-20 | Martin Stjernholm | | void set_range(float|NoLimit minimum, float|NoLimit maximum )
{
|
4e9896 | 2006-02-17 | Martin Stjernholm | | if (maximum != no_limit && minimum != no_limit && maximum < minimum)
|
2c7616 | 2004-10-20 | Martin Stjernholm | | _max = _min = no_limit;
else {
_max = maximum;
_min = minimum;
}
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
void set_precision( int prec )
{
_prec = prec;
}
array(string|float) verify_set( float new_value )
{
|
b03a3b | 2007-01-12 | Erik Dahl | | if (new_value == (float)0 && _is_empty)
return ({ 0, new_value });
|
d1de94 | 2000-08-19 | Martin Nilsson | | string warn;
|
2c7616 | 2004-10-20 | Martin Stjernholm | | if(_max != no_limit && new_value > _max)
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
55a866 | 2000-11-20 | Per Hedbor | | warn = sprintf(LOCALE(328,"Value is bigger than %s, adjusted"),
|
9f9797 | 2000-11-20 | Per Hedbor | | _format(_max) );
|
a96834 | 2000-08-25 | Martin Nilsson | | new_value = _max;
}
|
2c7616 | 2004-10-20 | Martin Stjernholm | | else if(_min != no_limit && new_value < _min)
|
a96834 | 2000-08-25 | Martin Nilsson | | {
|
55a866 | 2000-11-20 | Per Hedbor | | warn = sprintf(LOCALE(329,"Value is less than %s, adjusted"),
|
9f9797 | 2000-11-20 | Per Hedbor | | _format(_min) );
|
a96834 | 2000-08-25 | Martin Nilsson | | new_value = _min;
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
return ({ warn, new_value });
}
|
e8668d | 2001-08-28 | Martin Nilsson | | float transform_from_form( mixed what )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
b03a3b | 2007-01-12 | Erik Dahl | | if (!sizeof(what) && _may_be_empty) {
_is_empty = 1;
return (float)0;
}
|
e8668d | 2001-08-28 | Martin Nilsson | | string junk;
if(!sizeof(what)) {
add_warning(LOCALE(80, "No data entered.\n"));
return _min;
}
sscanf(what, "%f%s", what, junk);
if(!junk) {
add_warning(LOCALE(81, "Data is not a float.\n"));
return _min;
}
if(sizeof(junk))
add_warning(sprintf(LOCALE(82, "Found the string %O trailing after the float.\n"), junk));
|
d1de94 | 2000-08-19 | Martin Nilsson | | return (float)what;
}
string render_view( RequestID id )
{
return Roxen.html_encode_string( _format(query()) );
}
|
a96834 | 2000-08-25 | Martin Nilsson | | string render_form( RequestID id, void|mapping additional_args )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
int size = 15;
|
2c7616 | 2004-10-20 | Martin Stjernholm | | if( _max != no_limit && _min != no_limit )
|
d1de94 | 2000-08-19 | Martin Nilsson | | size = max( strlen(_format(_max)), strlen(_format(_min)) )+2;
|
b03a3b | 2007-01-12 | Erik Dahl | | string value;
if (_may_be_empty && (float)query() == (float)0)
value = "";
else
value = query()==""? "" : _format( (float)query() );
|
fc1a0c | 2008-01-29 | Mathias Södermark | |
additional_args = additional_args || ([]);
additional_args->type="text";
|
b03a3b | 2007-01-12 | Erik Dahl | |
return input(path(), value, size, additional_args);
}
void may_be_empty(int(0..1) state)
{
_may_be_empty = state;
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
}
class Int
{
inherit Variable;
constant type = "Int";
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected int|NoLimit _max = no_limit, _min = no_limit;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected int(0..1) _may_be_empty = 0;
protected int(0..1) _is_empty = 0;
|
b03a3b | 2007-01-12 | Erik Dahl | |
|
2c7616 | 2004-10-20 | Martin Stjernholm | | void set_range(int|NoLimit minimum, int|NoLimit maximum )
{
|
4e9896 | 2006-02-17 | Martin Stjernholm | | if (maximum != no_limit && minimum != no_limit && maximum < minimum)
|
2c7616 | 2004-10-20 | Martin Stjernholm | | _max = _min = no_limit;
else {
_max = maximum;
_min = minimum;
}
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
|
a7defb | 2001-08-01 | Per Hedbor | | string diff( int render )
{
if(!render)
return "("+default_value()+")";
}
|
6fd683 | 2000-11-27 | Per Hedbor | | array(string|int) verify_set( mixed new_value )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
b03a3b | 2007-01-12 | Erik Dahl | | if (new_value == 0 && _is_empty)
return ({ 0, new_value });
|
d1de94 | 2000-08-19 | Martin Nilsson | | string warn;
|
6fd683 | 2000-11-27 | Per Hedbor | | if(!intp( new_value ) )
|
e05d53 | 2000-11-27 | Martin Nilsson | | return ({ sprintf(LOCALE(152,"%O is not an integer"),new_value),
|
6fd683 | 2000-11-27 | Per Hedbor | | query() });
|
2c7616 | 2004-10-20 | Martin Stjernholm | | if( _max != no_limit && new_value > _max)
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
55a866 | 2000-11-20 | Per Hedbor | | warn = sprintf(LOCALE(328,"Value is bigger than %s, adjusted"),
|
9f9797 | 2000-11-20 | Per Hedbor | | (string)_max );
|
a96834 | 2000-08-25 | Martin Nilsson | | new_value = _max;
}
|
2c7616 | 2004-10-20 | Martin Stjernholm | | else if( _min != no_limit && new_value < _min)
|
a96834 | 2000-08-25 | Martin Nilsson | | {
|
55a866 | 2000-11-20 | Per Hedbor | | warn = sprintf(LOCALE(329,"Value is less than %s, adjusted"),
|
9f9797 | 2000-11-20 | Per Hedbor | | (string)_min );
|
a96834 | 2000-08-25 | Martin Nilsson | | new_value = _min;
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
return ({ warn, new_value });
}
|
6fd683 | 2000-11-27 | Per Hedbor | | int transform_from_form( mixed what )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
b03a3b | 2007-01-12 | Erik Dahl | | if (!sizeof(what) && _may_be_empty) {
_is_empty = 1;
return 0;
}
|
e8668d | 2001-08-28 | Martin Nilsson | | string junk;
if(!sizeof(what)) {
add_warning(LOCALE(80, "No data entered.\n"));
return _min;
}
sscanf( what, "%d%s", what, junk );
if(!junk) {
add_warning(LOCALE(83, "Data is not an integer\n"));
return _min;
}
if(sizeof(junk))
add_warning(sprintf(LOCALE(84, "Found the string %O trailing after the integer.\n"), junk));
|
6fd683 | 2000-11-27 | Per Hedbor | | return what;
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
|
a96834 | 2000-08-25 | Martin Nilsson | | string render_form( RequestID id, void|mapping additional_args )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
int size = 10;
|
2c7616 | 2004-10-20 | Martin Stjernholm | | if( _min != no_limit && _max != no_limit )
|
d1de94 | 2000-08-19 | Martin Nilsson | | size = max( strlen((string)_max), strlen((string)_min) )+2;
|
b03a3b | 2007-01-12 | Erik Dahl | | string value = (query() == 0 && _is_empty)? "" : (string)query();
|
fc1a0c | 2008-01-29 | Mathias Södermark | |
additional_args = additional_args || ([]);
additional_args->type="text";
|
b03a3b | 2007-01-12 | Erik Dahl | | return input(path(), value, size, additional_args);
}
void may_be_empty(int(0..1) state)
{
_may_be_empty = state;
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
}
|
d0876c | 2008-09-25 | Martin Stjernholm | | class TmpInt
{
inherit Int;
void save() {}
}
|
d1de94 | 2000-08-19 | Martin Nilsson | |
class String
{
inherit Variable;
constant type = "String";
|
c85b8f | 2001-06-14 | Johan Schön | | int width = 40;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
613baf | 2000-09-28 | Per Hedbor | |
|
a7defb | 2001-08-01 | Per Hedbor | | string diff( int render )
{
if(!render)
return "("+Roxen.html_encode_string( default_value() )+")";
}
|
bacec9 | 2001-06-13 | Martin Nilsson | | array(string) verify_set_from_form( mixed new )
|
613baf | 2000-09-28 | Per Hedbor | | {
|
bacec9 | 2001-06-13 | Martin Nilsson | | return ({ 0, [string]new-"\r" });
|
613baf | 2000-09-28 | Per Hedbor | | }
|
a96834 | 2000-08-25 | Martin Nilsson | | string render_form( RequestID id, void|mapping additional_args )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
0167ce | 2007-10-17 | Jonas Wallden | | additional_args = additional_args || ([]);
|
546008 | 2007-10-17 | Mathias Södermark | | additional_args->type="text";
|
a96834 | 2000-08-25 | Martin Nilsson | | return input(path(), (string)query(), width, additional_args);
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
}
class Text
{
inherit String;
constant type = "Text";
|
7263fd | 2001-08-09 | Martin Nilsson | |
|
61d55c | 2008-09-26 | Martin Stjernholm | | int cols = 56;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
7263fd | 2001-08-09 | Martin Nilsson | |
|
c85b8f | 2001-06-14 | Johan Schön | | int rows = 10;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
a7defb | 2001-08-01 | Per Hedbor | |
string diff( int render )
{
switch( render )
{
case 0: return 0;
case 1: return "";
case 2:
array lines_orig = default_value()/"\n";
array lines_new = query()/"\n";
Diff diff = Diff( lines_new, lines_orig, 2 );
if( sizeof(diff->get()) )
return diff->html();
else
|
9fa11d | 2001-08-24 | Martin Nilsson | | return "<i>"+LOCALE(481,"No difference\n" )+"</i>";
|
a7defb | 2001-08-01 | Per Hedbor | | }
}
array(string) verify_set_from_form( mixed new )
{
return ({ 0, [string]new-"\r" });
}
|
a96834 | 2000-08-25 | Martin Nilsson | | string render_form( RequestID id, void|mapping additional_args )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
ec6f24 | 2006-05-05 | Marcus Wellhardh | | return "<textarea cols='"+cols+"' rows='"+rows+"' name='"+path()+"' wrap='off'>"
|
d1de94 | 2000-08-19 | Martin Nilsson | | + Roxen.html_encode_string( query() || "" ) +
"</textarea>";
}
|
a7defb | 2001-08-01 | Per Hedbor | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create(mixed default_value, void|int flags,
void|LocaleString std_name, void|LocaleString std_doc)
|
a7defb | 2001-08-01 | Per Hedbor | |
{
if( strlen( default_value ) && default_value[0] == '\n' )
default_value = default_value[1..];
::create( default_value, flags, std_name, std_doc );
}
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
class Password
{
inherit String;
|
c85b8f | 2001-06-14 | Johan Schön | | int width = 20;
|
d1de94 | 2000-08-19 | Martin Nilsson | | constant type = "Password";
|
42fb35 | 2001-06-14 | Martin Nilsson | | int(0..1) set_from_form( RequestID id )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
mapping val;
if( sizeof( val = get_form_vars(id)) &&
|
42fb35 | 2001-06-14 | Martin Nilsson | | val[""] && strlen(val[""]) ) {
|
d1de94 | 2000-08-19 | Martin Nilsson | | set( crypt( val[""] ) );
|
42fb35 | 2001-06-14 | Martin Nilsson | | return 1;
}
return 0;
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
string render_view( RequestID id )
{
return "******";
}
|
a96834 | 2000-08-25 | Martin Nilsson | | string render_form( RequestID id, void|mapping additional_args )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
a96834 | 2000-08-25 | Martin Nilsson | | additional_args = additional_args || ([]);
additional_args->type="password";
|
2ffb48 | 2000-11-19 | Stefan Wallström | | return input(path(), "", 30, additional_args);
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
}
class File
{
inherit String;
constant type = "File";
|
c85b8f | 2001-06-14 | Johan Schön | | int width = 50;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
string read( )
{
return Stdio.read_bytes( query() );
}
|
1f4a6c | 2000-08-28 | Per Hedbor | | Stat stat()
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
return file_stat( query() );
}
|
be3631 | 2000-08-23 | Per Hedbor | |
#ifdef __NT__
array verify_set( string value )
{
return ::verify_set( replace( value, "\\", "/" ) );
}
#endif
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
class Location
{
inherit String;
constant type = "Location";
|
c85b8f | 2001-06-14 | Johan Schön | | int width = 50;
|
81251c | 2000-11-20 | Per Hedbor | |
array verify_set( string value )
{
if( !strlen( value ) || !((<'~','/'>)[value[-1]]) )
return ({
|
55a866 | 2000-11-20 | Per Hedbor | | LOCALE(330,"You most likely want an ending '/' on this variable"),
|
81251c | 2000-11-20 | Per Hedbor | | value
});
return ::verify_set( value );
}
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
class URL
{
inherit String;
constant type = "URL";
|
c85b8f | 2001-06-14 | Johan Schön | | int width = 50;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
b8fd5c | 2000-09-28 | Per Hedbor | | array verify_set_from_form( string new_value )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
bc0dec | 2001-08-05 | Martin Nilsson | | return verify_port( new_value );
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
}
class Directory
{
inherit String;
constant type = "Directory";
|
c85b8f | 2001-06-14 | Johan Schön | | int width = 50;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
array verify_set( string value )
{
|
be3631 | 2000-08-23 | Per Hedbor | | #ifdef __NT__
value = replace( value, "\\", "/" );
#endif
if( strlen(value) && value[-1] != '/' )
value += "/";
|
f63757 | 2000-08-22 | Per Hedbor | | if( !strlen( value ) )
return ::verify_set( value );
|
d1de94 | 2000-08-19 | Martin Nilsson | | if( !(r_file_stat( value ) && (r_file_stat( value )[ ST_SIZE ] == -2 )))
|
55a866 | 2000-11-20 | Per Hedbor | | return ({sprintf(LOCALE(331,"%s is not a directory"),value)+"\n",value});
|
d1de94 | 2000-08-19 | Martin Nilsson | | return ::verify_set( value );
}
|
1f4a6c | 2000-08-28 | Per Hedbor | | Stat stat()
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
return file_stat( query() );
}
array get( )
{
return get_dir( query() );
}
}
class MultipleChoice
{
inherit Variable;
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected array _list = ({});
protected mapping _table = ([]);
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
a7defb | 2001-08-01 | Per Hedbor | | string diff( int render )
{
if(!render)
return "("+_title( default_value() )+")";
}
|
d1de94 | 2000-08-19 | Martin Nilsson | | void set_choice_list( array to )
{
_list = to;
}
array get_choice_list( )
{
return _list;
}
void set_translation_table( mapping to )
{
_table = to;
}
mapping get_translation_table( )
{
return _table;
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string _name( mixed what )
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
return (string)what;
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string _title( mixed what )
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
if( mapping tt = get_translation_table() )
return tt[ what ] || (string)what;
return (string)what;
}
|
a96834 | 2000-08-25 | Martin Nilsson | | string render_form( RequestID id, void|mapping additional_args )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
134f6f | 2002-02-26 | Marcus Wellhardh | | string autosubmit = "";
if(additional_args && additional_args->autosubmit)
autosubmit = " autosubmit='autosubmit' onChange='javascript:submit();'";
string res = "<select name='"+path()+"'"+autosubmit+">\n";
|
ef40dc | 2000-09-01 | Martin Stjernholm | | string current = _name (query());
int selected = 0;
|
d1de94 | 2000-08-19 | Martin Nilsson | | foreach( get_choice_list(), mixed elem )
{
mapping m = ([]);
m->value = _name( elem );
|
ef40dc | 2000-09-01 | Martin Stjernholm | | if( equal( m->value, current ) ) {
|
d1de94 | 2000-08-19 | Martin Nilsson | | m->selected="selected";
|
ef40dc | 2000-09-01 | Martin Stjernholm | | selected = 1;
}
|
d1de94 | 2000-08-19 | Martin Nilsson | | res += " "+Roxen.make_container( "option", m, _title( elem ) )+"\n";
}
|
ef40dc | 2000-09-01 | Martin Stjernholm | | if (!selected)
|
c6fd2e | 2000-09-03 | Per Hedbor | | res += " " + Roxen.make_container (
|
62b1c5 | 2007-10-05 | Martin Jonsson | | "option", (["value":current, "selected": "selected"]),
sprintf(LOCALE(332,"(keep stale value %s)"),current));
|
d1de94 | 2000-08-19 | Martin Nilsson | | return res + "</select>";
}
|
7263fd | 2001-08-09 | Martin Nilsson | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create( mixed default_value, array|mapping choices,
void|int _flags, void|LocaleString std_name,
void|LocaleString std_doc )
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
::create( default_value, _flags, std_name, std_doc );
if( mappingp( choices ) ) {
set_translation_table( choices );
|
b0e7e2 | 2005-12-17 | Jonas Wallden | | set_choice_list( sort(indices(choices)) );
|
d1de94 | 2000-08-19 | Martin Nilsson | | } else
set_choice_list( choices );
}
}
class StringChoice
{
inherit MultipleChoice;
constant type = "StringChoice";
}
class IntChoice
{
inherit MultipleChoice;
constant type = "IntChoice";
int transform_from_form( string what )
{
return (int)what;
}
}
class FloatChoice
{
inherit MultipleChoice;
constant type = "FloatChoice";
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected int _prec = 3;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
void set_precision( int prec )
{
_prec = prec;
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string _title( mixed what )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
if( !_prec )
return sprintf( "%d", (int)what );
return sprintf( "%1."+_prec+"f", what );
}
int transform_from_form( string what )
{
array q = get_choice_list();
mapping a = mkmapping( map( q, _name ), q );
return a[what] || (float)what;
}
}
class FontChoice
{
inherit StringChoice;
constant type = "FontChoice";
void set_choice_list()
{
}
array get_choice_list()
{
return roxenp()->fonts->available_fonts();
}
|
7263fd | 2001-08-09 | Martin Nilsson | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create(mixed default_value, void|int flags,
void|LocaleString std_name, void|LocaleString std_doc)
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
::create( default_value, 0, flags,std_name, std_doc );
}
}
|
2ef68b | 2001-10-04 | Per Hedbor | | class TableChoice
{
inherit StringChoice;
constant type = "TableChoice";
Variable db;
array(string) get_choice_list( )
{
return sort(DBManager.db_tables( db->query() ));
}
void create( string default_value,
void|int flags,
void|LocaleString std_name,
void|LocaleString std_doc,
Variable _dbchoice )
{
::create( default_value, ({}), flags, std_name, std_doc );
db = _dbchoice;
}
}
|
5bfe94 | 2001-06-16 | Martin Nilsson | | class DatabaseChoice
{
inherit StringChoice;
constant type = "DatabaseChoice";
|
630b48 | 2001-08-01 | Per Hedbor | | function(void:void|object) config = lambda() { return 0; };
|
5bfe94 | 2001-06-16 | Martin Nilsson | |
DatabaseChoice set_configuration_pointer( function(void:object) configuration )
|
dd03b2 | 2006-04-20 | Henrik Grubbström (Grubba) | |
|
5bfe94 | 2001-06-16 | Martin Nilsson | | {
config = configuration;
return this_object();
}
array get_choice_list( )
{
return ({ " none" }) + sort(DBManager.list( config() ));
}
|
110a25 | 2001-06-18 | Martin Nilsson | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create(string default_value, void|int flags,
void|LocaleString std_name, void|LocaleString std_doc)
|
110a25 | 2001-06-18 | Martin Nilsson | | {
::create( default_value, ({}), flags, std_name, std_doc );
}
|
5bfe94 | 2001-06-16 | Martin Nilsson | | }
|
983677 | 2001-09-21 | Per Hedbor | | class AuthMethodChoice
{
inherit StringChoice;
constant type = "AuthMethodChoice";
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected Configuration config;
|
983677 | 2001-09-21 | Per Hedbor | |
array get_choice_list( )
{
return ({ " all" }) + sort( config->auth_modules()->name );
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create( string default_value, int flags,
string std_name, string std_doc,
Configuration c )
|
983677 | 2001-09-21 | Per Hedbor | | {
config = c;
::create( default_value, ({}), flags, std_name, std_doc );
}
}
class UserDBChoice
{
inherit StringChoice;
constant type = "UserDBChoice";
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected Configuration config;
|
983677 | 2001-09-21 | Per Hedbor | |
array get_choice_list( )
{
return ({ " all" }) + sort( config->user_databases()->name );
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create( string default_value, int flags,
string std_name, string std_doc,
Configuration c )
|
983677 | 2001-09-21 | Per Hedbor | | {
config = c;
::create( default_value, ({}), flags, std_name, std_doc );
}
}
|
ec7ab1 | 2006-11-30 | Henrik Grubbström (Grubba) | |
class ProviderChoice
{
inherit StringChoice;
constant type = "ProviderChoice";
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected Configuration conf;
protected string provides;
protected string default_id;
protected string local_id = "";
protected int isset;
|
ec7ab1 | 2006-11-30 | Henrik Grubbström (Grubba) | |
int low_set(RoxenModule to)
{
|
ee8d50 | 2007-01-22 | Henrik Grubbström (Grubba) | | RoxenModule old = changed_values[_id];
if (to == old) return 0;
if (!old) {
if (local_id != "") {
old = transform_from_form(local_id);
}
if (!old) {
old = default_value();
if (old) local_id = _name(old);
}
changed_values[_id] = to;
if (to == old) return 0;
}
changed_values[_id] = to;
|
ec7ab1 | 2006-11-30 | Henrik Grubbström (Grubba) | | local_id = _name(to);
|
ee8d50 | 2007-01-22 | Henrik Grubbström (Grubba) | | if( get_changed_callback() )
get_changed_callback()( this_object() );
return 1;
|
ec7ab1 | 2006-11-30 | Henrik Grubbström (Grubba) | | }
|
151c84 | 2007-01-10 | Henrik Grubbström (Grubba) | |
int set(string|RoxenModule to)
{
if (stringp(to)) {
local_id = to;
to = transform_from_form(to);
|
62b1c5 | 2007-10-05 | Martin Jonsson | | isset = 1;
|
151c84 | 2007-01-10 | Henrik Grubbström (Grubba) | | }
return ::set(to);
}
|
ec7ab1 | 2006-11-30 | Henrik Grubbström (Grubba) | | RoxenModule query()
{
|
62b1c5 | 2007-10-05 | Martin Jonsson | | RoxenModule res = changed_values[_id];
|
2df07b | 2006-12-06 | Henrik Grubbström (Grubba) | | if (!res) {
|
7ae70c | 2006-12-06 | Henrik Grubbström (Grubba) | | if (local_id != "") {
|
2df07b | 2006-12-06 | Henrik Grubbström (Grubba) | |
res = transform_from_form(local_id);
|
7ae70c | 2006-12-06 | Henrik Grubbström (Grubba) | | if (res) low_set(res);
|
62b1c5 | 2007-10-05 | Martin Jonsson | | } else if(!isset) {
res = default_value();
if(res) {
set(res);
}
|
2df07b | 2006-12-06 | Henrik Grubbström (Grubba) | | }
|
ec7ab1 | 2006-11-30 | Henrik Grubbström (Grubba) | | }
return res;
}
array get_choice_list()
{
|
ee8d50 | 2007-01-22 | Henrik Grubbström (Grubba) | | array res = conf->get_providers(provides);
sort(map(res, _title), res);
return res;
|
ec7ab1 | 2006-11-30 | Henrik Grubbström (Grubba) | | }
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string _name(RoxenModule val)
|
ec7ab1 | 2006-11-30 | Henrik Grubbström (Grubba) | | {
return val?val->module_local_id():"";
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string _title(RoxenModule val)
|
ec7ab1 | 2006-11-30 | Henrik Grubbström (Grubba) | | {
|
7ae70c | 2006-12-06 | Henrik Grubbström (Grubba) | | return val?val->module_name:"";
|
ec7ab1 | 2006-11-30 | Henrik Grubbström (Grubba) | | }
RoxenModule transform_from_form(string local_id, mapping|void v)
{
return conf->find_module(local_id);
}
RoxenModule default_value()
{
if (default_id) {
return transform_from_form(default_id);
} else {
|
62b1c5 | 2007-10-05 | Martin Jonsson | | array(RoxenModule) providers = conf->get_providers(provides);
|
ec7ab1 | 2006-11-30 | Henrik Grubbström (Grubba) | | if (sizeof(providers)) {
return providers[0];
}
|
2df07b | 2006-12-06 | Henrik Grubbström (Grubba) | | return UNDEFINED;
|
ec7ab1 | 2006-11-30 | Henrik Grubbström (Grubba) | | }
}
|
da85d7 | 2006-12-07 | Henrik Grubbström (Grubba) | | array(string|mixed) verify_set( mixed new_value )
{
|
5fe867 | 2007-01-22 | Henrik Grubbström (Grubba) | | if (!new_value) {
new_value = query();
}
|
da85d7 | 2006-12-07 | Henrik Grubbström (Grubba) | | if (!new_value) {
return ({ "Not configured", 0 });
}
return ({ 0, new_value });
}
|
ec7ab1 | 2006-11-30 | Henrik Grubbström (Grubba) | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create(string default_id, int flags,
string std_name, string std_doc,
string provides, Configuration conf)
|
ec7ab1 | 2006-11-30 | Henrik Grubbström (Grubba) | | {
this_program::provides = provides;
this_program::default_id = default_id;
this_program::conf = conf;
::create(0, ({}), flags, std_name, std_doc);
}
}
|
d1de94 | 2000-08-19 | Martin Nilsson | |
class List
{
|
0a1915 | 2000-11-11 | Per Hedbor | | inherit Variable;
|
d1de94 | 2000-08-19 | Martin Nilsson | | constant type="List";
|
c85b8f | 2001-06-14 | Johan Schön | | int width = 40;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
5f7016 | 2001-11-01 | Henrik Grubbström (Grubba) | | array(string|array(string)) verify_set(mixed to)
{
if (stringp(to)) {
return ({ "Compatibility: "
"Converted from TYPE_STRING to TYPE_STRING_LIST.\n",
(to-" ")/"," });
}
return ::verify_set(to);
}
|
d1de94 | 2000-08-19 | Martin Nilsson | | string transform_to_form( mixed what )
{
return (string)what;
}
|
d21c1f | 2001-02-02 | Per Hedbor | | mixed transform_from_form( string what,mapping v )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
return what;
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected int _current_count = time()*100+(gethrtime()/10000);
|
42fb35 | 2001-06-14 | Martin Nilsson | | int(0..1) set_from_form(RequestID id)
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
f63757 | 2000-08-22 | Per Hedbor | | int rn, do_goto;
|
98ab17 | 2003-03-05 | Mattias Andersson | | array l = copy_value(query());
|
d1de94 | 2000-08-19 | Martin Nilsson | | mapping vl = get_form_vars(id);
if( (int)vl[".count"] != _current_count )
|
42fb35 | 2001-06-14 | Martin Nilsson | | return 0;
|
d1de94 | 2000-08-19 | Martin Nilsson | | _current_count++;
|
e8668d | 2001-08-28 | Martin Nilsson | | set_warning(0);
|
d1de94 | 2000-08-19 | Martin Nilsson | |
foreach( indices( vl ), string vv )
|
d21c1f | 2001-02-02 | Per Hedbor | | if( sscanf( vv, ".set.%d", rn ) && (vv == ".set."+rn) )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
74dd85 | 2004-06-09 | Henrik Grubbström (Grubba) | | if ((rn >= 0) && (rn < sizeof(l))) {
m_delete( id->variables, path()+vv );
l[rn] = transform_from_form( vl[vv], vl );
m_delete( vl, vv );
} else {
report_debug("set_from_form(%O): vv:%O sizeof(l):%d\n",
id, vv, sizeof(l));
}
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
foreach( indices(vl), string vv )
if( sscanf( vv, ".up.%d.x%*s", rn ) == 2 )
{
|
f63757 | 2000-08-22 | Per Hedbor | | do_goto = 1;
|
d1de94 | 2000-08-19 | Martin Nilsson | | m_delete( id->variables, path()+vv );
m_delete( vl, vv );
l = l[..rn-2] + l[rn..rn] + l[rn-1..rn-1] + l[rn+1..];
}
else if( sscanf( vv, ".down.%d.x%*s", rn )==2 )
{
|
f63757 | 2000-08-22 | Per Hedbor | | do_goto = 1;
|
d1de94 | 2000-08-19 | Martin Nilsson | | m_delete( id->variables, path()+vv );
l = l[..rn-1] + l[rn+1..rn+1] + l[rn..rn] + l[rn+2..];
}
if( vl[".new.x"] )
{
|
f63757 | 2000-08-22 | Per Hedbor | | do_goto = 1;
|
d1de94 | 2000-08-19 | Martin Nilsson | | m_delete( id->variables, path()+".new.x" );
|
d21c1f | 2001-02-02 | Per Hedbor | | l += ({ transform_from_form( "",vl ) });
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
foreach( indices(vl), string vv )
if( sscanf( vv, ".delete.%d.x%*s", rn )==2 )
{
|
f63757 | 2000-08-22 | Per Hedbor | | do_goto = 1;
|
d1de94 | 2000-08-19 | Martin Nilsson | | m_delete( id->variables, path()+vv );
l = l[..rn-1] + l[rn+1..];
}
|
0a1915 | 2000-11-11 | Per Hedbor | |
array b;
mixed q = catch( b = verify_set_from_form( l ) );
if( q || sizeof( b ) != 2 )
{
if( q )
|
e8668d | 2001-08-28 | Martin Nilsson | | add_warning( q );
|
0a1915 | 2000-11-11 | Per Hedbor | | else
|
e8668d | 2001-08-28 | Martin Nilsson | | add_warning( "Internal error: Illegal sized array "
|
cd87a2 | 2000-11-27 | Martin Nilsson | | "from verify_set_from_form\n" );
|
42fb35 | 2001-06-14 | Martin Nilsson | | return 0;
|
0a1915 | 2000-11-11 | Per Hedbor | | }
|
42fb35 | 2001-06-14 | Martin Nilsson | |
int ret;
|
0a1915 | 2000-11-11 | Per Hedbor | | if( b )
{
|
e8668d | 2001-08-28 | Martin Nilsson | | add_warning( b[0] );
|
0a1915 | 2000-11-11 | Per Hedbor | | set( b[1] );
|
42fb35 | 2001-06-14 | Martin Nilsson | | ret = 1;
|
0a1915 | 2000-11-11 | Per Hedbor | | }
|
42fb35 | 2001-06-14 | Martin Nilsson | |
|
4329da | 2001-01-29 | Per Hedbor | | if( do_goto && !id->misc->do_not_goto )
{
RequestID nid = id;
while( nid->misc->orig )
nid = id->misc->orig;
string section = RXML.get_var("section", "var");
string query = nid->query;
if( !query )
query = "";
else
query += "&";
|
552cd9 | 2003-10-23 | Jonas Wallden | |
query +=
(section ? ("section=" + section + "&") : "") +
"random=" + random(4949494);
|
22f4c2 | 2008-05-09 | Martin Stjernholm | |
string url =
Roxen.http_encode_invalids (nid->not_query +
(nid->misc->path_info || "") +
"?" + query + "#" + path());
nid->set_response_header ("Location", url);
|
4329da | 2001-01-29 | Per Hedbor | | if( nid->misc->defines )
nid->misc->defines[ " _error" ] = 302;
else if( id->misc->defines )
id->misc->defines[ " _error" ] = 302;
}
|
42fb35 | 2001-06-14 | Martin Nilsson | |
return ret;
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
|
d21c1f | 2001-02-02 | Per Hedbor | |
string render_row(string prefix, mixed val, int width)
{
return input( prefix, val, width );
}
|
a96834 | 2000-08-25 | Martin Nilsson | | string render_form( RequestID id, void|mapping additional_args )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
string prefix = path()+".";
int i;
|
f63757 | 2000-08-22 | Per Hedbor | | string res = "<a name='"+path()+"'>\n</a><table>\n"
"<input type='hidden' name='"+prefix+"count' value='"+_current_count+"' />\n";
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
d21c1f | 2001-02-02 | Per Hedbor | | foreach( map(query(), transform_to_form), mixed val )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
d21c1f | 2001-02-02 | Per Hedbor | | res += "<tr>\n<td><font size='-1'>"+ render_row(prefix+"set."+i, val, width)
+ "</font></td>\n";
|
d1de94 | 2000-08-19 | Martin Nilsson | | #define BUTTON(X,Y) ("<submit-gbutton2 name='"+X+"'>"+Y+"</submit-gbutton2>")
|
e69c01 | 2000-08-31 | Martin Nilsson | | #define REORDER(X,Y) ("<submit-gbutton2 name='"+X+"' icon-src='"+Y+"'></submit-gbutton2>")
|
80cd68 | 2003-11-17 | Anders Johansson | | #define DIMBUTTON(X) ("<disabled-gbutton icon-src='"+X+"'></disabled-gbutton>")
|
d1de94 | 2000-08-19 | Martin Nilsson | | if( i )
res += "\n<td>"+
|
e69c01 | 2000-08-31 | Martin Nilsson | | REORDER(prefix+"up."+i, "/internal-roxen-up")+
|
d1de94 | 2000-08-19 | Martin Nilsson | | "</td>";
else
|
80cd68 | 2003-11-17 | Anders Johansson | | res += "\n<td>"+DIMBUTTON("/internal-roxen-up")+"</td>";
|
d1de94 | 2000-08-19 | Martin Nilsson | | if( i != sizeof( query())- 1 )
res += "\n<td>"+
|
e69c01 | 2000-08-31 | Martin Nilsson | | REORDER(prefix+"down."+i, "/internal-roxen-down")
|
d1de94 | 2000-08-19 | Martin Nilsson | | +"</td>";
else
|
80cd68 | 2003-11-17 | Anders Johansson | | res += "\n<td>"+DIMBUTTON("/internal-roxen-down")+"</td>";
|
d1de94 | 2000-08-19 | Martin Nilsson | | res += "\n<td>"+
|
99a745 | 2000-08-22 | Andreas Lange | | BUTTON(prefix+"delete."+i, LOCALE(227, "Delete") )
|
d1de94 | 2000-08-19 | Martin Nilsson | | +"</td>";
"</tr>";
i++;
}
res +=
|
f63757 | 2000-08-22 | Per Hedbor | | "\n<tr><td colspan='2'>"+
|
99a745 | 2000-08-22 | Andreas Lange | | BUTTON(prefix+"new", LOCALE(297, "New row") )+
|
f63757 | 2000-08-22 | Per Hedbor | | "</td></tr></table>\n\n";
|
d1de94 | 2000-08-19 | Martin Nilsson | |
return res;
}
}
class DirectoryList
{
inherit List;
constant type="DirectoryList";
array verify_set( array(string) value )
{
string warn = "";
|
f63757 | 2000-08-22 | Per Hedbor | | foreach( value, string vi )
{
if(!strlen(vi))
continue;
if( !(r_file_stat( vi ) && (r_file_stat( vi )[ ST_SIZE ] == -2 )))
|
55a866 | 2000-11-20 | Per Hedbor | | warn += sprintf(LOCALE(331,"%s is not a directory"),vi)+"\n";
|
f63757 | 2000-08-22 | Per Hedbor | | if( strlen(vi) && vi[-1] != '/' )
value = replace( value, vi, vi+"/" );
|
843ccc | 2000-08-25 | Per Hedbor | | }
|
be3631 | 2000-08-23 | Per Hedbor | | #ifdef __NT__
|
843ccc | 2000-08-25 | Per Hedbor | | value = map( value, replace, "\\", "/" );
|
be3631 | 2000-08-23 | Per Hedbor | | #endif
|
d1de94 | 2000-08-19 | Martin Nilsson | | if( strlen( warn ) )
return ({ warn, value });
|
f63757 | 2000-08-22 | Per Hedbor | |
|
d1de94 | 2000-08-19 | Martin Nilsson | | return ::verify_set( value );
}
}
class StringList
{
inherit List;
constant type="StringList";
}
class IntList
{
inherit List;
constant type="IntList";
|
c85b8f | 2001-06-14 | Johan Schön | | int width=20;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
string transform_to_form(int what) { return (string)what; }
|
d21c1f | 2001-02-02 | Per Hedbor | | int transform_from_form(string what,mapping v) { return (int)what; }
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
class FloatList
{
inherit List;
|
dd03b2 | 2006-04-20 | Henrik Grubbström (Grubba) | | constant type="FloatList";
|
c85b8f | 2001-06-14 | Johan Schön | | int width=20;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected int _prec = 3;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
void set_precision( int prec )
{
_prec = prec;
}
string transform_to_form(int what)
{
return sprintf("%1."+_prec+"f", what);
}
|
d21c1f | 2001-02-02 | Per Hedbor | | float transform_from_form(string what,mapping v) { return (float)what; }
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
class URLList
{
inherit List;
|
a96834 | 2000-08-25 | Martin Nilsson | | constant type="URLList";
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
b8fd5c | 2000-09-28 | Per Hedbor | | array verify_set_from_form( array(string) new_value )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
string warn = "";
array res = ({});
foreach( new_value, string vv )
{
string tmp1, tmp2;
|
bc0dec | 2001-08-05 | Martin Nilsson | | [tmp1,tmp2] = verify_port( vv );
|
d1de94 | 2000-08-19 | Martin Nilsson | | if( tmp1 )
warn += tmp1;
res += ({ tmp2 });
}
if( !strlen( warn ) )
warn = 0;
return ({ warn, res });
}
}
class PortList
{
inherit List;
constant type="PortList";
|
d21c1f | 2001-02-02 | Per Hedbor | | string render_row( string prefix, mixed val, int width )
{
string res = "<input type=hidden name='"+prefix+"' value='"+prefix+"' />";
|
b98c02 | 2001-07-31 | Per Hedbor | | Standards.URI split = Standards.URI( val );
|
d21c1f | 2001-02-02 | Per Hedbor | |
res += "<select name='"+prefix+"prot'>";
|
71e872 | 2005-02-11 | Martin Stjernholm | | int default_port;
|
d21c1f | 2001-02-02 | Per Hedbor | | foreach( sort(indices( roxenp()->protocols )), string p )
{
|
71e872 | 2005-02-11 | Martin Stjernholm | | if( p == split->scheme ) {
|
d21c1f | 2001-02-02 | Per Hedbor | | res += "<option selected='t'>"+p+"</option>";
|
71e872 | 2005-02-11 | Martin Stjernholm | | default_port = roxenp()->protocols[p]->default_port;
}
|
d21c1f | 2001-02-02 | Per Hedbor | | else
res += "<option>"+p+"</option>";
}
res += "</select>";
|
a497e3 | 2001-11-05 | Ambrose Li | | res += "://<input type=text name='"+prefix+"host' value='"+
|
b98c02 | 2001-07-31 | Per Hedbor | | Roxen.html_encode_string(split->host)+"' />";
|
80cd68 | 2003-11-17 | Anders Johansson | | res += ":<input type=text size=5 name='"+prefix+"port' value='"+
|
71e872 | 2005-02-11 | Martin Stjernholm | | (split->port == default_port ? "" : split->port) +"' />";
|
d21c1f | 2001-02-02 | Per Hedbor | |
|
a497e3 | 2001-11-05 | Ambrose Li | | res += "/<input type=text name='"+prefix+"path' value='"+
|
21182a | 2001-10-05 | Per Hedbor | | Roxen.html_encode_string(split->path[1..])+"' /><br />";
mapping opts = ([]);
string a,b;
foreach( (split->fragment||"")/";", string x )
{
sscanf( x, "%s=%s", a, b );
opts[a]=b;
}
|
a497e3 | 2001-11-05 | Ambrose Li | | res += "IP#: <input size=15 type=text name='"+prefix+"ip' value='"+
|
21182a | 2001-10-05 | Per Hedbor | | Roxen.html_encode_string(opts->ip||"")+"' /> ";
|
9c3df9 | 2001-11-21 | Henrik Grubbström (Grubba) | | res += LOCALE(510,"Bind this port: ");
|
63ef1c | 2002-04-19 | Anders Johansson | | res += "<select name='"+prefix+"nobind'>";
|
21182a | 2001-10-05 | Per Hedbor | | if( (int)opts->nobind )
{
res +=
|
63ef1c | 2002-04-19 | Anders Johansson | | ("<option value='0'>"+LOCALE("yes","Yes")+"</option>"
"<option selected='t' value='1'>"+LOCALE("no","No")+"</option>");
|
21182a | 2001-10-05 | Per Hedbor | | }
else
{
res +=
|
63ef1c | 2002-04-19 | Anders Johansson | | ("<option selected='t' value='0'>"+LOCALE("yes","Yes")+"</option>"
"<option value='1'>"+LOCALE("no","No")+"</option>");
|
21182a | 2001-10-05 | Per Hedbor | | }
res += "</select>";
|
d21c1f | 2001-02-02 | Per Hedbor | | return res;
}
string transform_from_form( string v, mapping va )
{
if( v == "" ) return "http://*/";
v = v[strlen(path())..];
|
21182a | 2001-10-05 | Per Hedbor | | if( strlen( va[v+"path"] ) && va[v+"path"][-1] != '/' )
va[v+"path"]+="/";
|
77bdaf | 2008-12-11 | Jonas Wallden | |
string host = va[v + "host"];
if (has_value(host, ":") && !has_prefix(host, "["))
host = "[" + host + "]";
|
21182a | 2001-10-05 | Per Hedbor | |
|
77bdaf | 2008-12-11 | Jonas Wallden | | return (string)Standards.URI(va[v+"prot"]+"://"+ host +
|
71e872 | 2005-02-11 | Martin Stjernholm | | (va[v+"port"] && sizeof (va[v+"port"]) ?
":"+ va[v+"port"] : "") +"/"+va[v+"path"]+"#"
|
21182a | 2001-10-05 | Per Hedbor | |
"ip="+va[v+"ip"]+";"
"nobind="+va[v+"nobind"]+";"
);
|
d21c1f | 2001-02-02 | Per Hedbor | | }
|
b8fd5c | 2000-09-28 | Per Hedbor | | array verify_set_from_form( array(string) new_value )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
string warn = "";
array res = ({});
foreach( new_value, string vv )
{
string tmp1, tmp2;
|
bc0dec | 2001-08-05 | Martin Nilsson | | [tmp1,tmp2] = verify_port( vv );
|
d1de94 | 2000-08-19 | Martin Nilsson | | if( tmp1 )
warn += tmp1;
res += ({ tmp2 });
}
if( !strlen( warn ) )
warn = "";
return ({ warn, res });
}
}
class FileList
{
inherit List;
constant type="FileList";
|
be3631 | 2000-08-23 | Per Hedbor | |
#ifdef __NT__
|
c6fe1f | 2003-02-17 | Tomas Nilsson | | array(string|array(string)) verify_set(mixed value )
|
be3631 | 2000-08-23 | Per Hedbor | | {
|
c6fe1f | 2003-02-17 | Tomas Nilsson | |
if (stringp(value))
return ::verify_set( replace(value, "\\", "/") );
|
be3631 | 2000-08-23 | Per Hedbor | | return ::verify_set( map( value, replace, "\\", "/" ) );
}
#endif
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
class Flag
{
inherit Variable;
constant type = "Flag";
int transform_from_form( string what )
{
return (int)what;
}
|
a96834 | 2000-08-25 | Martin Nilsson | | string render_form( RequestID id, void|mapping additional_args )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
string res = "<select name=\""+path()+"\"> ";
if(query())
res += "<option value=\"1\" selected=\"selected\">" +
LOCALE("yes", "Yes")+ "</option>\n"
"<option value=\"0\">" +LOCALE("no", "No")+ "</option>\n";
else
res += "<option value=\"1\">" +LOCALE("yes", "Yes")+ "</option>\n"
"<option value=\"0\" selected>" +LOCALE("no", "No")+ "</option>\n";
return res+"</select>";
}
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected array(string) verify_port( string port )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
if(!strlen(port))
return ({ 0, port });
|
9f9797 | 2000-11-20 | Per Hedbor | |
|
d1de94 | 2000-08-19 | Martin Nilsson | | string warning="";
if( (int)port )
{
|
55a866 | 2000-11-20 | Per Hedbor | | warning += sprintf(LOCALE(333,"Assuming http://*:%[0]d/ for %[0]d")+"\n",
|
9f9797 | 2000-11-20 | Per Hedbor | | (int)port);
|
d1de94 | 2000-08-19 | Martin Nilsson | | port = "http://*:"+port+"/";
}
string protocol, host, path;
if(!strlen( port ) )
|
55a866 | 2000-11-20 | Per Hedbor | | return ({ LOCALE(334,"Empty URL field")+"\n", port });
|
d1de94 | 2000-08-19 | Martin Nilsson | |
if(sscanf( port, "%[^:]://%[^/]%s", protocol, host, path ) != 3)
|
55a866 | 2000-11-20 | Per Hedbor | | return ({ sprintf(LOCALE(335,"%s does not conform to URL syntax")+"\n",port),
|
9f9797 | 2000-11-20 | Per Hedbor | | port });
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
21182a | 2001-10-05 | Per Hedbor | |
|
d1de94 | 2000-08-19 | Martin Nilsson | | if( protocol != lower_case( protocol ) )
{
|
55a866 | 2000-11-20 | Per Hedbor | | warning += sprintf(LOCALE(338,"Changed %s to %s"),
|
9f9797 | 2000-11-20 | Per Hedbor | | protocol, lower_case( protocol ))+"\n";
|
edbf2d | 2000-09-19 | Per Hedbor | | protocol = lower_case( protocol );
}
|
c50bf6 | 2000-09-28 | Per Hedbor | | #if constant(SSL.sslfile)
|
bc0dec | 2001-08-05 | Martin Nilsson | |
|
edbf2d | 2000-09-19 | Per Hedbor | | #else
|
bc0dec | 2001-08-05 | Martin Nilsson | | if( (protocol == "https" || protocol == "ftps") )
warning +=
LOCALE(339,"SSL support not available in this Pike version.")+"\n"+
sprintf(LOCALE(340,"Please use %s instead."),
protocol[..strlen(protocol)-2])+"\n";
|
edbf2d | 2000-09-19 | Per Hedbor | | #endif
|
9f2312 | 2000-09-21 | Per Hedbor | | int pno;
|
77bdaf | 2008-12-11 | Jonas Wallden | | int default_pno =
(roxenp()->protocols[lower_case(protocol)] || ([ ]) )->default_port;
if (has_value(host, "[")) {
Standards.URI uri = Standards.URI(port);
pno = uri->port;
port = (string) uri;
} else {
if (sscanf(host, "%s:%d", host, pno) == 2)
if (pno != default_pno)
host = host + ":" + pno;
port = protocol+"://"+host+path;
}
if (default_pno && (pno == default_pno))
warning += sprintf(LOCALE(341, "Removed the default port number "
"(%d) from %s"), pno, port) + "\n";
|
edbf2d | 2000-09-19 | Per Hedbor | | if( !roxenp()->protocols[ protocol ] )
|
55a866 | 2000-11-20 | Per Hedbor | | warning += sprintf(LOCALE(342,"Warning: The protocol %s is not known "
|
9f9797 | 2000-11-20 | Per Hedbor | | "by roxen"),protocol)+"\n";
|
d1de94 | 2000-08-19 | Martin Nilsson | | return ({ (strlen(warning)?warning:0), port });
}
|
a96834 | 2000-08-25 | Martin Nilsson | |
|
ae7023 | 2000-12-02 | Martin Nilsson | | string input(string name, string value, int size,
void|mapping(string:string) args, void|int noxml)
|
a96834 | 2000-08-25 | Martin Nilsson | | {
if(!args)
args=([]);
else
args+=([]);
args->name=name;
|
ae7023 | 2000-12-02 | Martin Nilsson | | if(value)
args->value=value;
if(!args->size && size)
|
f4cf46 | 2000-11-20 | Martin Nilsson | | args->size=(string)size;
|
a96834 | 2000-08-25 | Martin Nilsson | |
string render="<input";
foreach(indices(args), string attr) {
render+=" "+attr+"=";
if(!has_value(args[attr], "\"")) render+="\""+args[attr]+"\"";
else if(!has_value(args[attr], "'")) render+="'"+args[attr]+"'";
|
03f169 | 2002-09-11 | Martin Stjernholm | | else render+="'"+replace(args[attr], "'", "'")+"'";
|
a96834 | 2000-08-25 | Martin Nilsson | | }
if(noxml) return render+">";
return render+" />";
}
|