53bf48 | 2000-12-30 | Martin Nilsson | |
|
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 | |
static int unique_vid;
|
edbf2d | 2000-09-19 | Per Hedbor | |
|
d1de94 | 2000-08-19 | Martin Nilsson | | static mapping(int:mixed) changed_values = ([]);
static mapping(int:function(object:void)) changed_callbacks = ([]);
static mapping(int:int) all_flags = ([]);
static mapping(int:string) all_warnings = ([]);
static mapping(int:function(RequestID,object:int))
invisibility_callbacks = set_weak_flag( ([]), 1 );
class Variable
{
constant is_variable = 1;
constant type = "Basic";
|
b9bf91 | 2000-11-18 | Per Hedbor | | int _id = unique_vid++;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
static mixed _initial;
|
0a92fe | 2000-12-12 | Per Hedbor | | static string _path = sprintf("v%x",_id);
|
79ca87 | 2000-11-24 | Per Hedbor | | static LocaleString __name, __doc;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
void destroy()
{
m_delete( all_flags, _id );
m_delete( all_warnings, _id );
m_delete( invisibility_callbacks, _id );
m_delete( changed_values, _id );
}
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 || "";
}
|
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 | | }
|
79ca87 | 2000-11-24 | Per Hedbor | | LocaleString type_hint( )
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
}
mixed default_value()
{
return _initial;
}
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 )
{
string err, e2;
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() )
catch( get_changed_callback()( this_object() ) );
return 1;
}
else
{
m_delete( changed_values, _id );
if( get_changed_callback() )
catch( get_changed_callback()( this_object() ) );
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;
}
mixed transform_from_form( string what )
{
return what;
}
void set_from_form( RequestID id )
|
b8fd5c | 2000-09-28 | Per Hedbor | |
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
b8fd5c | 2000-09-28 | Per Hedbor | | mixed val;
|
d1de94 | 2000-08-19 | Martin Nilsson | | if( sizeof( val = get_form_vars(id)) && val[""] &&
|
b8fd5c | 2000-09-28 | Per Hedbor | | (val = transform_from_form( val[""] )) != query() )
{
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" );
|
b8fd5c | 2000-09-28 | Per Hedbor | | return;
}
|
a882cd | 2000-09-28 | Per Hedbor | | if( b )
{
set_warning( b[0] );
set( b[1] );
}
|
b8fd5c | 2000-09-28 | Per Hedbor | | }
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
string path()
{
return _path;
}
void set_path( string to )
{
_path = to;
}
|
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 | | }
static string _sprintf( int i )
{
if( i == 'O' )
|
8fec79 | 2000-09-04 | Per Hedbor | | return sprintf( "Variable.%s(%s)",type,(string)name());
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
|
a96834 | 2000-08-25 | Martin Nilsson | | static void create(mixed default_value, void|int flags,
|
79ca87 | 2000-11-24 | Per Hedbor | | 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;
}
}
class Float
{
inherit Variable;
constant type = "Float";
static float _max, _min;
|
a96834 | 2000-08-25 | Martin Nilsson | | static int _prec = 2;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
static string _format( float m )
{
if( !_prec )
return sprintf( "%d", (int)m );
return sprintf( "%1."+_prec+"f", m );
}
void set_range(float minimum, float maximum )
{
_max = maximum;
_min = minimum;
}
void set_precision( int prec )
{
_prec = prec;
}
array(string|float) verify_set( float new_value )
{
string warn;
|
a96834 | 2000-08-25 | Martin Nilsson | | if( new_value > _max && _max > _min)
|
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;
}
else if( new_value < _min && _min < _max)
{
|
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 });
}
float transform_from_form( string what )
{
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;
|
84a73d | 2000-09-18 | Per Hedbor | | if( _max != _min )
|
d1de94 | 2000-08-19 | Martin Nilsson | | size = max( strlen(_format(_max)), strlen(_format(_min)) )+2;
|
53bf48 | 2000-12-30 | Martin Nilsson | | return input(path(), (query()==""?"":_format(query())), size, additional_args);
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
}
class Int
{
inherit Variable;
constant type = "Int";
|
a96834 | 2000-08-25 | Martin Nilsson | | static int _max, _min;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
void set_range(int minimum, int maximum )
{
_max = maximum;
_min = minimum;
}
|
6fd683 | 2000-11-27 | Per Hedbor | | array(string|int) verify_set( mixed 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() });
|
a96834 | 2000-08-25 | Martin Nilsson | | if( new_value > _max && _max > _min )
|
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;
}
else if( new_value < _min && _min < _max)
{
|
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 | | {
|
6fd683 | 2000-11-27 | Per Hedbor | | sscanf( what, "%d", what );
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;
|
84a73d | 2000-09-18 | Per Hedbor | | if( _min != _max )
|
d1de94 | 2000-08-19 | Martin Nilsson | | size = max( strlen((string)_max), strlen((string)_min) )+2;
|
a96834 | 2000-08-25 | Martin Nilsson | | return input(path(), (string)query(), size, additional_args);
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
}
class String
{
inherit Variable;
constant type = "String";
constant width = 40;
|
613baf | 2000-09-28 | Per Hedbor | |
array(string) verify_set_from_form( string new )
{
return ({ 0, new-"\r" });
}
|
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 | | return input(path(), (string)query(), width, additional_args);
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
}
class Text
{
inherit String;
constant type = "Text";
constant cols = 60;
constant rows = 10;
|
a96834 | 2000-08-25 | Martin Nilsson | | string render_form( RequestID id, void|mapping additional_args )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
return "<textarea cols='"+cols+"' rows='"+rows+"' name='"+path()+"'>"
+ Roxen.html_encode_string( query() || "" ) +
"</textarea>";
}
}
class Password
{
inherit String;
constant width = 20;
constant type = "Password";
void set_from_form( RequestID id )
{
mapping val;
if( sizeof( val = get_form_vars(id)) &&
val[""] && strlen(val[""]) )
set( crypt( val[""] ) );
}
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";
constant width = 50;
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";
constant 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";
constant width = 50;
|
b8fd5c | 2000-09-28 | Per Hedbor | | array verify_set_from_form( string new_value )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
return verify_port( new_value, 1 );
}
}
class Directory
{
inherit String;
constant type = "Directory";
constant width = 50;
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;
static array _list = ({});
static mapping _table = ([]);
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;
}
static string _name( mixed what )
{
return (string)what;
}
static string _title( mixed what )
{
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 | | {
string res = "<select name='"+path()+"'>\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 (
|
9f9797 | 2000-11-20 | Per Hedbor | | "option", (["value":_name(current), "selected": "selected"]),
|
55a866 | 2000-11-20 | Per Hedbor | | sprintf(LOCALE(332,"(keep stale value %s)"),_name(current)));
|
d1de94 | 2000-08-19 | Martin Nilsson | | return res + "</select>";
}
static void create( mixed default_value, array|mapping choices,
|
79ca87 | 2000-11-24 | Per Hedbor | | int _flags, LocaleString std_name,
LocaleString std_doc )
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
::create( default_value, _flags, std_name, std_doc );
if( mappingp( choices ) ) {
set_translation_table( choices );
set_choice_list( indices(choices) );
} 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";
static int _prec = 3;
void set_precision( int prec )
{
_prec = prec;
}
static string _title( mixed what )
{
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();
}
static void create(mixed default_value,int flags,
|
79ca87 | 2000-11-24 | Per Hedbor | | LocaleString std_name,LocaleString std_doc)
|
d1de94 | 2000-08-19 | Martin Nilsson | |
{
::create( default_value, 0, flags,std_name, std_doc );
}
}
class List
{
|
0a1915 | 2000-11-11 | Per Hedbor | | inherit Variable;
|
d1de94 | 2000-08-19 | Martin Nilsson | | constant type="List";
constant width = 40;
string transform_to_form( mixed what )
{
return (string)what;
}
mixed transform_from_form( string what )
{
return what;
}
static int _current_count = time()*100+(gethrtime()/10000);
void set_from_form(RequestID id)
{
|
f63757 | 2000-08-22 | Per Hedbor | | int rn, do_goto;
|
d1de94 | 2000-08-19 | Martin Nilsson | | array l = query();
mapping vl = get_form_vars(id);
if( (int)vl[".count"] != _current_count )
return;
_current_count++;
foreach( indices( vl ), string vv )
if( sscanf( vv, ".set.%d", rn ) )
{
m_delete( id->variables, path()+vv );
l[rn] = transform_from_form( vl[vv] );
m_delete( vl, vv );
}
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" );
l += ({ transform_from_form( "" ) });
}
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..];
}
|
f63757 | 2000-08-22 | Per Hedbor | | if( do_goto )
{
|
6b8177 | 2000-08-30 | Per Hedbor | | if( !id->misc->do_not_goto )
{
id->misc->moreheads = ([
|
edbf2d | 2000-09-19 | Per Hedbor | | "Location":Roxen.http_encode_string(id->raw_url+"?random="+
random(4949494)+
"§ion="+
id->variables->section+
"#"+path()),
|
6b8177 | 2000-08-30 | Per Hedbor | | ]);
if( id->misc->defines )
id->misc->defines[ " _error" ] = 302;
}
|
f63757 | 2000-08-22 | Per Hedbor | | }
|
0a1915 | 2000-11-11 | Per Hedbor | |
array b;
mixed q = catch( b = verify_set_from_form( l ) );
if( q || sizeof( b ) != 2 )
{
if( q )
set_warning( q );
else
|
cd87a2 | 2000-11-27 | Martin Nilsson | | set_warning( "Internal error: Illegal sized array "
"from verify_set_from_form\n" );
|
0a1915 | 2000-11-11 | Per Hedbor | | return;
}
if( b )
{
set_warning( b[0] );
set( b[1] );
}
|
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 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 | |
foreach( map(query(), transform_to_form), string val )
{
|
f63757 | 2000-08-22 | Per Hedbor | | res += "<tr>\n<td><font size='-1'>"+ input( 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>")
|
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
|
f63757 | 2000-08-22 | Per Hedbor | | res += "\n<td></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
|
f63757 | 2000-08-22 | Per Hedbor | | res += "\n<td></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";
constant width=20;
string transform_to_form(int what) { return (string)what; }
int transform_from_form(string what) { return (int)what; }
}
class FloatList
{
inherit List;
|
a96834 | 2000-08-25 | Martin Nilsson | | constant type="DirectoryList";
|
d1de94 | 2000-08-19 | Martin Nilsson | | constant width=20;
static int _prec = 3;
void set_precision( int prec )
{
_prec = prec;
}
string transform_to_form(int what)
{
return sprintf("%1."+_prec+"f", what);
}
float transform_from_form(string what) { return (float)what; }
}
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;
[tmp1,tmp2] = verify_port( vv, 1 );
if( tmp1 )
warn += tmp1;
res += ({ tmp2 });
}
if( !strlen( warn ) )
warn = 0;
return ({ warn, res });
}
}
class PortList
{
inherit List;
constant type="PortList";
|
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;
[tmp1,tmp2] = verify_port( vv, 0 );
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__
array verify_set( array(string) value )
{
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>";
}
}
|
a96834 | 2000-08-25 | Martin Nilsson | | static array(string) verify_port( string port, int nofhttp )
|
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 | |
|
bb6d6c | 2000-11-02 | Per Hedbor | | if( path == "" || path[-1] != '/' )
|
d1de94 | 2000-08-19 | Martin Nilsson | | {
|
55a866 | 2000-11-20 | Per Hedbor | | warning += sprintf(LOCALE(336,"Added / to the end of %s")+"\n",port);
|
bb6d6c | 2000-11-02 | Per Hedbor | | path += "/";
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
if( nofhttp && protocol == "fhttp" )
{
|
55a866 | 2000-11-20 | Per Hedbor | | warning += sprintf(LOCALE(337,"Changed %s to http")+"\n",protocol);
|
d1de94 | 2000-08-19 | Martin Nilsson | | protocol = "http";
}
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 );
}
if(!nofhttp)
{
|
c50bf6 | 2000-09-28 | Per Hedbor | | #if constant(SSL.sslfile)
|
edbf2d | 2000-09-19 | Per Hedbor | |
#else
if( (protocol == "https" || protocol == "ftps") )
|
9f9797 | 2000-11-20 | Per Hedbor | | warning +=
|
55a866 | 2000-11-20 | Per Hedbor | | LOCALE(339,"SSL support not available in this Pike version.")+"\n"+
sprintf(LOCALE(340,"Please use %s instead."),
|
9f9797 | 2000-11-20 | Per Hedbor | | protocol[..strlen(protocol)-2])+"\n";
|
edbf2d | 2000-09-19 | Per Hedbor | | #endif
|
d1de94 | 2000-08-19 | Martin Nilsson | | }
|
9f2312 | 2000-09-21 | Per Hedbor | | int pno;
if( sscanf( host, "%s:%d", host, pno ) == 2)
if( roxenp()->protocols[ lower_case( protocol ) ]
&& (pno == roxenp()->protocols[ lower_case( protocol ) ]->default_port ))
|
55a866 | 2000-11-20 | Per Hedbor | | warning += sprintf(LOCALE(341,"Removed the default port number "
|
9f9797 | 2000-11-20 | Per Hedbor | | "(%d) from %s"),pno,port)+"\n";
|
9f2312 | 2000-09-21 | Per Hedbor | | else
host = host+":"+pno;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
edbf2d | 2000-09-19 | Per Hedbor | | port = protocol+"://"+host+path;
|
d1de94 | 2000-08-19 | Martin Nilsson | |
|
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]+"'";
else render+="\""+replace(args[attr], "'", "'")+"\"";
}
if(noxml) return render+">";
return render+" />";
}
|