<?vsp 
--  
--  $Id$
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2018 OpenLink Software
--  
--  This project is free software; you can redistribute it and/or modify it
--  under the terms of the GNU General Public License as published by the
--  Free Software Foundation; only version 2 of the License, dated June 1991.
--  
--  This program is distributed in the hope that it will be useful, but
--  WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
--  General Public License for more details.
--  
--  You should have received a copy of the GNU General Public License along
--  with this program; if not, write to the Free Software Foundation, Inc.,
--  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--  
--  
 http_rewrite(); http_header('Content-type: text/vnd.wap.wml\r\n');

   declare _user_name, _user_pass, _login_ok varchar;
  declare _sid varchar;
  declare _random1 integer;

  _random1 := rnd(9999999);
  _sid := '';
  _sid := get_keyword('SESS', params);
  _user_name := get_keyword('USERNAME', params);
   _login_ok := 'NO';

 if (_sid <> '') {
  for select * from wapsession where sid = _sid do
  {
   _login_ok := 'YES';
   _user_name := _username;
  }
  }else{
    _user_pass := get_keyword('POPPASS', params);
    for select * from mailpwd where _username = _user_name and _userpass = {?'POPPASS'} do
  {
    _login_ok := 'YES';
    _sid := md5(concat (datestring(now()), _user_name));
    if (_allow_multiple_session = 0)
    {
     delete from wapsession where _username = _user_name;
    }else{
     delete from wapsession where _username = _user_name and datediff ('hour', stringdate (_time_last_active), now() ) > 23;
    }
     insert into wapsession (sid, _username, _userpass, _time, _time_last_active) values(_sid, _user_name, _user_pass, datestring(now()), datestring(now()) );
     dbg_obj_print ('new sid:', _sid);
    }

  }

   if ( _login_ok = 'YES' ) { http_rewrite(); http_header('Content-type: text/vnd.wap.wml\r\n');
?><?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
  <card id="menu1" title="OpenLink" >
   <onevent type ="onenterforward">
    <refresh>
   <setvar name="sid" value="<?=_sid?>"/>
   <setvar name="username1" value=""/>
   <setvar name="poppass1" value=""/>
  </refresh>
   </onevent>
   <p><b>OpenLink Demo</b></p>
    <p><a href="checkmail.vsp?SESS=<?=_sid?>&amp;OPEN=Inbox&amp;REF=<?=_random1?>" title="Mail">Wap Mail</a></p>
    <p><a href="logout.vsp?SESS=<?=_sid?>&amp;REF=<?=_random1?>" title="Logout">Logout</a></p>
  </card>
</wml>
<?vsp
 }
 if(_login_ok = 'NO'){ http_rewrite(); http_header('Content-type: text/vnd.wap.wml\r\n');
?><?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
  <card id="P1" title="Wrong" >
    <p>
   Wrong Login
    </p>
  </card>
</wml>
<?vsp
 }
?>


