<?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 _mm_bcc, _mm_body, _mm_cc, _mm_fld, _mm_from, _mm_own, _mm_rec_date, _mm_snd_time, _mm_subj, _mm_to varchar;
 declare _mm_id varchar;
   declare _user_name, _login_ok varchar;

 declare _login_ok varchar;
  declare _sid, _action, _to, _msg, _subj, _msg_id, _from, _msg1, _to_do, _folder, _old_folder_name varchar;
  declare _err long varchar;
  declare _counter1, _list integer;
  declare _random1 integer;

  _random1 := rnd(9999999);
  _sid := '';
  _sid := get_keyword('SESS', params);
   _to_do := get_keyword('TO_DO', params);
   _old_folder_name := get_keyword ('OLD_FOLDER_NAME', params, '');
   _login_ok := 'NO';

 _folder := (select _sess_folder from wapsession where sid = _sid);
 _list := (select _sess_list from wapsession where sid = _sid);


 if (_sid   <> '')
 {
  for select * from wapsession where sid = _sid  do
  {
   _login_ok := 'YES';
   _user_name := _username;
   _folder := _sess_folder;
   _list := _sess_list;
   _msg_id := _sess_msg_id;
   update wapsession set _time_last_active = datestring ( now() ) where  sid = _sid;
  }
  }else{
    _login_ok := 'NO';
  }

if (_login_ok = 'YES' and _to_do = 'LIST')
{ 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="List" title="Folder List" >
   <do type="options" label="Options">
    <go href="#opt"/>
   </do>
   <p> Folder  No.Msgs</p>
      <?vsp
      _counter1 := 0;
          for select count (*) as _counter1 from MAIL_MESSAGE where MM_OWN = _user_name and MM_FLD = 'Inbox' do
          {
           http(sprintf('<p mode="nowrap"><a href="checkmail.vsp?SESS=%s&amp;OPEN=%s&amp;REF=%d" title="Goto">%s -%d msg</a></p>\n',
               _sid, 'Inbox', _random1,'Inbox', _counter1));
          }

          _counter1 := 0;
          for select count (*) as _counter1 from MAIL_MESSAGE where MM_OWN = _user_name and MM_FLD = 'Draft' do
          {
           http(sprintf('<p mode="nowrap"><a href="checkmail.vsp?SESS=%s&amp;OPEN=%s&amp;REF=%d" title="Goto">%s -%d msg</a></p>\n',
               _sid, 'Draft', _random1,'Draft', _counter1));
          }

          _counter1 := 0;
          for select * from wapfolders where wap_username = _user_name and wap_folder <> 'Inbox' and wap_folder <> 'Draft' and wap_active = 1 do
          {
   for select count (*) as _counter1 from MAIL_MESSAGE where MM_OWN = _user_name and MM_FLD = wap_folder do
   {
            http(sprintf('<p mode="nowrap"><a href="checkmail.vsp?SESS=%s&amp;OPEN=%s&amp;REF=%d" title="Goto">%s -%d msg</a></p>\n',
               _sid, wap_folder, _random1,wap_folder, _counter1));
            _counter1 := 0;
   }
          }
     ?>
   </card>

   <card id="opt">
    <do type="options" label ="Exit">
     <go href="#List"/>
    </do>
    <p><a href="#add">Add a Folder</a></p>
    <p><a href="folders.vsp?SESS=<?=_sid?>&amp;TO_DO=ERASE&amp;REF=<?vsp http(sprintf('%d',_random1)); ?>">Delete a Folder</a></p>
    <p><a href="folders.vsp?SESS=<?=_sid?>&amp;TO_DO=MODIFY1&amp;REF=<?vsp http(sprintf('%d',_random1)); ?>">Rename a Folder</a></p>
    <p><a href="checkmail.vsp?SESS=<?=_sid?>&amp;REF=<?vsp http(sprintf('%d',_random1)); ?>">Mail Menu</a></p>
    <p><a href="#List">Exit</a></p>
   </card>

<card id="add">
   <onevent type="onenterforward">
          <refresh>
   <setvar name="addressnew1" value=""/>
   <setvar name="addressold1" value=""/>
          </refresh>
   </onevent>
 <do type="options" label="Options">
  <go href="#opt"/>
 </do>

      <p>New Folder Name:</p>
      <p><input name="new_folder1" value="" maxlength="30" /></p>
      <p>Add Folder Now?</p>
  <p><a href="folder_add.vsp?SESS=<?=_sid?>&amp;TO_DO=ADD&amp;NEWFOLDER=$(new_folder1:e)" title="Yes">Yes</a></p>
  <p><a href="#List" title="Cancel">Cancel</a></p>
</card>
</wml>
<?vsp
}

if (_login_ok = 'YES' and _to_do = 'ERASE')
{ 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="delete">
    <do type="options" label ="Options">
     <go href="#opt"/>
    </do>
    <?vsp
     if(exists(select * from wapfolders where wap_username = _user_name and wap_folder <> 'Inbox' and wap_folder <> 'Draft' and wap_active = 1))
     {
      http(sprintf('<p>Delete a folder:</p>'));

    for select * from wapfolders where wap_username = _user_name and wap_folder <> 'Inbox' and wap_folder <> 'Draft' and wap_active = 1 do
    {
     http(sprintf('<p><a href="folder.vsp?SESS=%s&amp;TO_DO=DELETE&amp;OLD_FOLDER_NAME=%s" title="Delete">%s</a></p>', _sid, wap_folder, wap_folder));
                  }
                }else{
                 http(sprintf('<p>There is no folder avaliable for deletion</p>'));
                }
     ?>
 </card>
   <card id="opt">
    <do type="options" label ="Exit">
     <go href="#delete"/>
    </do>
    <p><a href="#add">Add a Folder</a></p>
    <p><a href="folders.vsp?SESS=<?=_sid?>&amp;TO_DO=ERASE&amp;REF=<?vsp http(sprintf('%d',_random1)); ?>">Delete a Folder</a></p>
    <p><a href="folders.vsp?SESS=<?=_sid?>&amp;TO_DO=MODIFY&amp;REF=<?vsp http(sprintf('%d',_random1)); ?>">Rename a Folder</a></p>
    <p><a href="checkmail.vsp?SESS=<?=_sid?>&amp;REF=<?vsp http(sprintf('%d',_random1)); ?>">Mail Menu</a></p>
    <p><a href="#delete">Exit</a></p>
   </card>

 <card id="add">
  <do type="accept" label="Add">
   <go href="folder_add.vsp?SESS=<?=_sid?>&amp;TO_DO=ADD&amp;NEWFOLDER=$(new_folder1:e)"/>
  </do>
    <do type="options" label ="Optionst">
     <go href="#opt"/>
    </do>
      <p>New Folder Name:</p>
      <p><input name="new_folder1" value="" maxlength="30" /></p>
      <p>Add Folder Now?</p>
  <p><a href="folder_add.vsp?SESS=<?=_sid?>&amp;TO_DO=ADD&amp;NEWFOLDER=$(new_folder1:e)" title="Yes">Yes</a></p>
  <p><a href="#delete" title="Cancel">Cancel</a></p>
 </card>

</wml>
<?vsp
}

if (_login_ok = 'YES' and _to_do = 'MODIFY1')
{ 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="modify">
    <do type="options" label ="Options">
     <go href="#opt"/>
    </do>
    <?vsp
     if(exists(select * from wapfolders where wap_username = _user_name and wap_folder <> 'Inbox' and wap_folder <> 'Draft' and wap_active = 1))
     {
      http(sprintf('<p>Rename a folder:</p>'));

    for select * from wapfolders where wap_username = _user_name and wap_folder <> 'Inbox' and wap_folder <> 'Draft' and wap_active = 1 do
    {
     http(sprintf('<p><a href="folders.vsp?SESS=%s&amp;TO_DO=MODIFY2&amp;OLD_FOLDER_NAME=%s" title="Rename">%s</a></p>', _sid, wap_folder, wap_folder));
                  }
                }else{
                 http(sprintf('<p>There is no folder avaliable for deletion</p>'));
                }
     ?>
 </card>
   <card id="opt">
    <do type="options" label ="Exit">
     <go href="#List"/>
    </do>
    <p><a href="#add">Add a Folder</a></p>
    <p><a href="folders.vsp?SESS=<?=_sid?>&amp;TO_DO=ERASE&amp;REF=<?vsp http(sprintf('%d',_random1)); ?>">Delete a Folder</a></p>
    <p><a href="folders.vsp?SESS=<?=_sid?>&amp;TO_DO=MODIFY&amp;REF=<?vsp http(sprintf('%d',_random1)); ?>">Rename a Folder</a></p>
    <p><a href="checkmail.vsp?SESS=<?=_sid?>&amp;REF=<?vsp http(sprintf('%d',_random1)); ?>">Mail Menu</a></p>
    <p><a href="#modify">Exit</a></p>
   </card>

 <card id="add">
  <do type="accept" label="Add">
   <go href="folder_add.vsp?SESS=<?=_sid?>&amp;TO_DO=ADD&amp;NEWFOLDER=$(new_folder1:e)"/>
  </do>
    <do type="options" label ="Optionst">
     <go href="#opt"/>
    </do>
      <p>New Folder Name:</p>
      <p><input name="new_folder1" value="" maxlength="30" /></p>
      <p>Add Folder Now?</p>
  <p><a href="folder_add.vsp?SESS=<?=_sid?>&amp;TO_DO=ADD&amp;NEWFOLDER=$(new_folder1:e)" title="Yes">Yes</a></p>
  <p><a href="#modify" title="Cancel">Cancel</a></p>
 </card>

</wml>
<?vsp
}

if (_login_ok = 'YES' and _to_do = 'MODIFY2')
{ 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="modify">
  <do type="accept" label="OK">
   <go href="folder.vsp?SESS=<?=_sid?>&amp;TO_DO=RENAME&amp;OLD_FOLDER_NAME=<?=_old_folder_name?>&amp;NEW_FOLDER_NAME=$(new_folder1)"/>
      </do>
    <do type="options" label ="Optionst">
     <go href="#opt"/>
    </do>
   <p> Rename <?=_old_folder_name?> to:</p>
   <p><input name="new_folder1" value="" maxlength="30" /></p>
   <p>Update Now ?</p>
  <p><a href="folder.vsp?SESS=<?=_sid?>&amp;TO_DO=RENAME&amp;OLD_FOLDER_NAME=<?=_old_folder_name?>&amp;NEW_FOLDER_NAME=$(new_folder1)" title="Yes">Yes</a></p>
  <p><a href="checkmail.vsp?SESS=<?=_sid?>&amp;REF=<?vsp http(sprintf('%d',_random1)); ?>" title="Cancel">Cancel</a></p>
 </card>

   <card id="opt">
    <do type="options" label ="Back">
   <prev/>
    </do>
    <p><a href="#add">Add a Folder</a></p>
    <p><a href="folders.vsp?SESS=<?=_sid?>&amp;TO_DO=ERASE&amp;REF=<?vsp http(sprintf('%d',_random1)); ?>">Delete a Folder</a></p>
    <p><a href="folders.vsp?SESS=<?=_sid?>&amp;TO_DO=MODIFY&amp;REF=<?vsp http(sprintf('%d',_random1)); ?>">Rename a Folder</a></p>
    <p><a href="checkmail.vsp?SESS=<?=_sid?>&amp;REF=<?vsp http(sprintf('%d',_random1)); ?>">Mail Menu</a></p>
    <p><a href="#modify">Exit</a></p>
   </card>
 <card id="add">
  <do type="accept" label="Add">
   <go href="folder_add.vsp?SESS=<?=_sid?>&amp;TO_DO=ADD&amp;NEWFOLDER=$(new_folder1:e)"/>
  </do>
    <do type="options" label ="Optionst">
     <go href="#opt"/>
    </do>
      <p>New Folder Name:<input name="new_folder1" value="" maxlength="30" /></p>
      <p>Add Folder Now?</p>
  <p><a href="folder_add.vsp?SESS=<?=_sid?>&amp;TO_DO=ADD&amp;NEWFOLDER=$(new_folder1:e)" title="Yes">Yes</a></p>
  <p><a href="#modify" title="Cancel">Cancel</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 mode="nowrap">
   Wrong Login
    </p>
  </card>
</wml>
<?vsp
}
?>
