Roxen.git / server / etc / modules / Variable.pmod / module.pmod

version» Context lines:

Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1: - // $Id: module.pmod,v 1.64 2001/08/24 14:44:26 nilsson Exp $ + // $Id: module.pmod,v 1.65 2001/08/28 04:42:42 nilsson Exp $      #include <module.h>   #include <roxen.h>      // Locale macros   //<locale-token project="roxen_config"> LOCALE </locale-token>      #define LOCALE(X,Y) \    ([string](mixed)Locale.translate("roxen_config",roxenp()->locale->get(),X,Y))   
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:504:    //! Returns 1 if the variable was changed, otherwise 0.    //!    //! Other side effects: Might create warnings to be shown to the    //! user (see get_warnings)    //!    //! Calls verify_set_from_form and verify_set    {    mixed val;    if( sizeof( val = get_form_vars(id)) && val[""])    { +  set_warning(0);    val = transform_from_form( val[""], val );    if( !force && val == query() )    return 0;    array b;    mixed q = catch( b = verify_set_from_form( val ) );    if( q || sizeof( b ) != 2 )    {    if( q )    add_warning( q );    else    add_warning( "Internal error: Illegal sized array "    "from verify_set_from_form\n" );    return 0;    }    if( b )    { -  set_warning( b[0] ); +  add_warning( b[0] );    set( b[1] );    return 1;    }    }    }       string path()    //! A unique identifier for this variable.    //! Should be used to prefix form variable names.    //!
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:655:    }    else if( new_value < _min && _min < _max)    {    warn = sprintf(LOCALE(329,"Value is less than %s, adjusted"),    _format(_min) );    new_value = _min;    }    return ({ warn, new_value });    }    -  float transform_from_form( string what ) +  float transform_from_form( mixed what )    { -  +  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));    return (float)what;    }       string render_view( RequestID id )    {    return Roxen.html_encode_string( _format(query()) );    }       string render_form( RequestID id, void|mapping additional_args )    {
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:725:    {    warn = sprintf(LOCALE(329,"Value is less than %s, adjusted"),    (string)_min );    new_value = _min;    }    return ({ warn, new_value });    }       int transform_from_form( mixed what )    { -  sscanf( what, "%d", what ); +  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));    return what;    }       string render_form( RequestID id, void|mapping additional_args )    {    int size = 10;    if( _min != _max )    size = max( strlen((string)_max), strlen((string)_min) )+2;    return input(path(), (string)query(), size, additional_args);    }
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1223:    static int _current_count = time()*100+(gethrtime()/10000);    int(0..1) set_from_form(RequestID id)    {    int rn, do_goto;    array l = query();    mapping vl = get_form_vars(id);    // first do the assign...    if( (int)vl[".count"] != _current_count )    return 0;    _current_count++; +  set_warning(0);       foreach( indices( vl ), string vv )    if( sscanf( vv, ".set.%d", rn ) && (vv == ".set."+rn) )    {    m_delete( id->variables, path()+vv );    l[rn] = transform_from_form( vl[vv], vl );    m_delete( vl, vv );    }    // then the move...    foreach( indices(vl), string vv )
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1268:    do_goto = 1;    m_delete( id->variables, path()+vv );    l = l[..rn-1] + l[rn+1..];    }       array b;    mixed q = catch( b = verify_set_from_form( l ) );    if( q || sizeof( b ) != 2 )    {    if( q ) -  set_warning( q ); +  add_warning( q );    else -  set_warning( "Internal error: Illegal sized array " +  add_warning( "Internal error: Illegal sized array "    "from verify_set_from_form\n" );    return 0;    }       int ret;    if( b )    { -  set_warning( b[0] ); +  add_warning( b[0] );    set( b[1] );    ret = 1;    }       if( do_goto && !id->misc->do_not_goto )    {    RequestID nid = id;    while( nid->misc->orig )    nid = id->misc->orig;