<?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, _user_pass1, _first_name, _family_name, _email, _signup_ok varchar;
   declare _name_length, _pass_length integer;
   declare _err_msg varchar;
   declare _sid varchar;
   _err_msg := '';

   _user_name := lcase(get_keyword('USERNAME', params, ''));
   _user_pass := lcase(get_keyword('POPPASS', params, ''));
   _user_pass1 := lcase(get_keyword('POPPASS1', params, ''));
   _first_name := get_keyword('FIRSTNAME', params, '');
   _email := get_keyword('EMAIL', params, '');

   _name_length := length(get_keyword('USERNAME', params));
   _pass_length := length(get_keyword('POPPASS', params));

   _err_msg := '';

   if(neq(_user_pass1, _user_pass)){
       _err_msg := 'Password can not be confirmed!!!';
   }

   --if( _name_length < 6 or _pass_length < 6){
   -- _err_msg := concat(_err_msg, 'User Name, Password must be at least 6 characters long.<br/> ');
   --}

   if ( matches_like (_email, '%@%') = 0 )
   {
      _err_msg := concat ( _err_msg, 'Return email address is not valid.<br/> ' );
   }

   if (exists (select 1 from mailpwd where _username = _user_name)){
    _err_msg := concat(_err_msg, '<i>', _user_name, '</i>', ' already exists. Please choose another User Name.');
   }

   if (_err_msg = '')
   {
    _signup_ok := 'YES';
   _sid := md5(concat (datestring(now()), _user_name));
   delete from wapsession where _username = _user_name;
  insert into wapsession (sid, _username, _userpass, _time) values(_sid, _user_name, _user_pass, datestring(now()));

    insert into mailpwd (_username, _userpass) values (_user_name, _user_pass);
    insert into wapfolders (wap_username, wap_folder, wap_active) values (_user_name, 'Inbox', 1);
    insert into wapfolders (wap_username, wap_folder, wap_active) values (_user_name, 'Draft', 1);
    insert into wapsetting (_username, _lname, _fname, _sign_up_date, _return_email) values (_user_name, _first_name, _first_name, now(), _email);
   }else{
    _signup_ok := 'NO';
   }

if(_signup_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>
<head>
<meta http-equiv="Cache-Control" content="no-cache" />
</head>
<card id="Welcome" title="OpenLink">
 <do type="accept" label="Back">
  <go href="index.vsp"/>
 </do>
 <p>
  Warning: <br/>
  <?vsp http(sprintf('%s', _err_msg));?>
     </p>
  </card>
</wml>
<?vsp
}
else
{ 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="Welcome" title="OpenLink">
 <do type="accept" label="Login">
  <go href="login.vsp?SESS=<?=_sid?>&amp;LIST=1&amp;FOLDER=Inbox">
   <setvar name="username1" value=""/>
   <setvar name="poppass1" value=""/>
   <setvar name="poppass2" value=""/>
   <setvar name="firstname" value=""/>
   <setvar name="familyname" value=""/>
  </go>
 </do>
 <do type="options" label="Exit">
  <go href="index.vsp"/>
 </do>
 <p>
  Congratulations<br/><?vsp http(sprintf('%s',_first_name));?><br/>
  Sign up Successful.<br/>
  Your User Name is <?=_user_name?>
  <?= _err_msg?>
     </p>
  </card>
</wml>
<?vsp
}
?>


