<?vsp 
--  
--  $Id: handler.vsp,v 1.2.2.1 2012/03/08 12:55:12 source Exp $
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2012 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
--  
--  
?>
<HTML>
 <head>
   <title>Table manipulations calling CLR functions</title>
 </head>
<body>
   <H2>Table manipulations calling CLR functions</H2>
<?vsp
   {
     declare _ClientSerialNo, _SMSKey, _Recepient varchar;
     _ClientSerialNo := registry_get ('ho_s_3.Redcoal.ClientSerialNo');
     _SMSKey := registry_get ('ho_s_3.Redcoal.SMSKey');
     _recepient := registry_get ('ho_s_3.MGRPhone');

     if (isstring (_ClientSerialNo) and isstring (_SMSKey) and isstring (_recepient) and
	  length (_ClientSerialNo) > 0 and length (_SMSKey) > 0 and length (_recepient) > 0)
       {
?>
       <p><i>SMS Sending <a href="setup_sms.vsp">on</a></i></p>
<?vsp
    } else {
?>
       <p><i>SMS Sending <a href="setup_sms.vsp">off</a></i></p>
<?vsp
    }
   }

  declare _add_it, _delete_it integer;
  declare _supplier_id varchar;

  declare exit handler for sqlstate '*' {
?>
    <hr/>
    <table>
      <tr>
        <td>SQL State</td>
        <td><?= __SQL_STATE ?></td>
      </tr>
      <tr>
        <td>SQL Message</td>
        <td><?= __SQL_MESSAGE ?></td>
      </tr>
     </table>
     <hr/>
<?vsp
     goto page_start;
  };

      _supplier_id := trim (get_keyword ('supplier_id', params, ''));
      _add_it := trim (get_keyword ('add_it', params, ''));
      _delete_it := trim (get_keyword ('delete_it', params, ''));

      if (_add_it <> '')
        {
	  insert soft CLR..Suppliers (SupplierID) values (cast (_supplier_id as integer));
?>
    <hr/>
    <p>Added : SupplierID <b><?= cast (_supplier_id as integer) ?></b>.</p>
    <hr/>
<?vsp
	}
      else if (_delete_it <> '')
        {
	  delete from CLR..Suppliers where SupplierID = cast (_supplier_id as integer);
?>
    <hr/>
    <p>Deleted : SupplierID <b><?= cast (_supplier_id as integer) ?></b>.</p>
    <hr/>
<?vsp
	}
page_start:
?>
   <form action="handler.vsp">
   <table>
     <tr>
       <td>
         SupplierID
       </td>
       <td>
         <select name="supplier_id" value="<?= _supplier_id ?>">
<?vsp
            for select SupplierID as supp_id from CLR..Suppliers do {
?>
            <option label="<?= supp_id ?>" value="<?= supp_id ?>"><?= supp_id ?></option>
<?vsp       }
?>
         </select>
       </td>
       <td><input type="submit" name="delete_it" value="Delete"></td>
      </tr>
     </table>
     </form>
     <hr/>
   <form action="handler.vsp">
   <table>
     <tr>
       <td>
         New SupplierID
       </td>
       <td>
         <input type="text" name="supplier_id" value="<?= _supplier_id ?>">
       </td>
       <td><input type="submit" name="add_it" value="Add"></td>
      </tr>
     </table>
     </form>
</body>
</html>
