Author: chintana
Date: Tue Sep  1 12:09:30 2009
New Revision: 809993

URL: http://svn.apache.org/viewvc?rev=809993&view=rev
Log:
Replacing config service options that was received from the database to the 
values taken from the PHP config service.


Modified:
    incubator/stonehenge/trunk/stocktrader/php/trader_client/config.inc

Modified: incubator/stonehenge/trunk/stocktrader/php/trader_client/config.inc
URL: 
http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/php/trader_client/config.inc?rev=809993&r1=809992&r2=809993&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/php/trader_client/config.inc 
(original)
+++ incubator/stonehenge/trunk/stocktrader/php/trader_client/config.inc Tue Sep 
 1 12:09:30 2009
@@ -1,40 +1,10 @@
 <?php
 
 require_once('MDB2.php');
+require_once('../config_service/class_info.php');
 
 session_start();
 
-// return a database connection, we're using singleton so we'll not be 
creating new objects
-// everytime
-function get_db_conn() {
-       $hspec = '';
-       if ($_SESSION['database'] == "mysql") {
-               $hspec = 'localhost:3306';
-       } else if ($_SESSION['database'] == "mssql") {
-               $hspec = 'localhost,1433';
-       }
-       
-       $dsn = array(
-               'phptype' => $_SESSION['database'],
-               'username' => 'trade',
-               'password' => 'yyy',
-               'hostspec' => $hspec,
-               'database' => 'stocktraderdb',
-       );
-       
-       $options = array(
-               'debug' => 2,
-               'portability' => MDB2_PORTABILITY_ALL,
-       );
-       
-       $db =& MDB2::singleton($dsn, $options);
-       if (PEAR::isError($db)) {
-               die($db->getMessage());
-       }
-       
-       return $db;
-}
-
 function display_db_select_form() {
        $str = <<<EOF
        <tr>
@@ -126,61 +96,56 @@
        echo $str;      
 }
 
-// execute the query, display an error if it fails
-function query_or_error($db, $q) {
-       $res =& $db->query($q);
-       if (PEAR::isError($res)) {
-               die($res->getMessage());
-       }
-       return $res;
+function get_proxy() {
+       global $class_map;
+       
+       $client = new WSClient(array("wsdl" 
=>"../resources/wsdl/config_svc.wsdl",
+                                                        "classmap" => 
$class_map));    
+       $proxy = $client->getProxy();
+       
+       return $proxy;
 }
 
 function display_bs_ops_conf_form() {
-       $db = get_db_conn();
-       
-       $res =& query_or_error($db, "SELECT bs FROM clienttobs WHERE client = 
'PHP_CLIENT'");   
-       $bs = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
-       
-       $res =& query_or_error($db, "SELECT ops FROM bstoops WHERE bs = '" . 
$bs['bs'] . "'");
-       $ops = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
        
-       $res =& query_or_error($db, "SELECT bs, ops FROM bstoops");
-       $bstoops = array();
-       while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
-               $bstoops[$row['bs']] = $row['ops'];
-       }
+       $proxy = get_proxy();
+
+       $input = new GetClientConfig();
+       $input->client = new ClientConfigRequest();
+       $input->client->ClientName = "PHP_CLIENT";
+       $response = $proxy->GetClientConfig($input);    
+       
+       $bs = $response->GetClientConfigResult->BSName;
+       
+       $input = new GetBSConfig();
+       $input->bs = new BSConfigRequest();
+       $input->bs->BSName = $bs;
+       $response = $proxy->GetBSConfig($input);
+                               
+       $ops = $response->GetBSConfigResult->OPSName;
        
        $str = <<<EOF
        <tr>
                <td style="padding: 10px;">Business Service</td>
                <td>
-               <script type="text/javascript">
-               function change_ops(bs) {
-                       var bstoops = new Array()
-                       
-EOF;
-       foreach ($bstoops as $k => $v) {
-               $str .= 'bstoops["' . $k . '"] = "' . $v . '"' . "\n";
-       }
-       $str .= <<<EOF
-                       var ops = document.getElementById("ops");
-                       for( var i = 0; i < ops.options.length; i++ ) {
-                               if ( ops.options[i].value == bstoops[bs.value] )
-                                       ops.options[i].selected = true
-                       }
-               }
-               </script>
-               <select name="bs" onChange="change_ops(this);">
+               <select name="bs">
 EOF;
 
-       $res =& query_or_error($db, "SELECT servicename FROM service WHERE 
servicename LIKE '%_BS'");
-       while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
-               $str .= '<option value="' . $row['servicename'] . '"';
-               if ($row['servicename'] == $bs['bs']) {
-                        $str .= ' selected="selected"';
+       $input = new GetBSLocations();
+       $response = $proxy->GetBSLocations($input);
+       
+       for ($i = 0; $i < 
count($response->GetBSLocationsResult->ServiceLocation); $i++) {
+               $str .= '<option value="' .
+                               
$response->GetBSLocationsResult->ServiceLocation[$i]->ServiceName .
+                               '"';
+               if 
($response->GetBSLocationsResult->ServiceLocation[$i]->ServiceName == $bs) {
+                       $str .= ' selected="selected"';
                }
-               $str .= '>' . $row['servicename'] . '</option>';
+               $str .= '>' .
+                               
$response->GetBSLocationsResult->ServiceLocation[$i]->ServiceName .
+                               '</option>';
        }
+       
        $str .= '</select></td></tr>';
        echo $str;
        
@@ -189,14 +154,20 @@
                <td style="padding: 10px;">Order Processing Service</td>
                <td><select name="ops" id="ops">
 EOF;
-                       
-       $res =& query_or_error($db, "SELECT servicename FROM service WHERE 
servicename LIKE '%_OPS%'");
-       while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
-               $str .= '<option value="' . $row['servicename'] . '"';
-               if ($row['servicename'] == $ops['ops']) {
+
+       $input = new GetOPSLocations();
+       $response = $proxy->GetOPSLocations($input);
+       
+       for ($i = 0; $i < 
count($response->GetOPSLocationsResult->ServiceLocation); $i++) {
+               $str .= '<option value="' .
+                               
$response->GetOPSLocationsResult->ServiceLocation[$i]->ServiceName .
+                               '"';
+               if 
($response->GetOPSLocationsResult->ServiceLocation[$i]->ServiceName == $ops) {
                        $str .= ' selected="selected"';
                }
-               $str .= '>' . $row['servicename'] . '</option>';
+               $str .= '>' .
+                               
$response->GetOPSLocationsResult->ServiceLocation[$i]->ServiceName .
+                               '</option>';
        }
        $str .= '</select></td></tr>';
        echo $str;
@@ -215,56 +186,39 @@
 }
 
 function update_clienttobs($bs) {
-       $db = get_db_conn();
-       $s = "UPDATE clienttobs SET bs = ? WHERE client = 'PHP_CLIENT'";
-       $t = array('text');
-       $stmt = $db->prepare($s, $t, MDB2_PREPARE_MANIP);
-       $data = array($bs);
-       $rows = $stmt->execute($data);
        
-       if (PEAR::isError($rows)) {
-               die($rows->getMessage());
-       }
+       $proxy = get_proxy();
+       
+       $input = new SetClientToBS();
+       $input->clientConfig = new ClientToBS();
+       $input->clientConfig->Bs = $bs;
+       $input->clientConfig->Client = "PHP_CLIENT";
+       
+       $proxy->SetClientToBS($input);
 }
 
 function update_bstoops($ops, $bs) {
-       $db = get_db_conn();
-       $s = "UPDATE bstoops SET ops = ? WHERE bs = ?";
-       $t = array('text', 'text');
-       $stmt = $db->prepare($s, $t, MDB2_PREPARE_MANIP);
-       $data = array($ops, $bs);
-       $rows = $stmt->execute($data);
        
-       if (PEAR::isError($rows)) {
-               die($rows->getMessage());
-       }
+       $proxy = get_proxy();
+       
+       $input = new SetBSToOPS();
+       $input->bsConfig = new BSToOPS();
+       $input->bsConfig->Bs = $bs;
+       $input->bsConfig->Ops = $ops;
+       
+       $proxy->SetBSToOPS($input);
 }
 
 function update_service($name, $url, $sec) {
-       $db = get_db_conn();
-       $s = "UPDATE service SET url = ?, sec = ? WHERE servicename = ?";
-       $t = array('text', 'boolean', 'text');
-       $stmt = $db->prepare($s, $t, MDB2_PREPARE_MANIP);
-       $data = array($url, $sec, $name);
-       $rows = $stmt->execute($data);
+       $proxy = get_proxy();
        
-       if (PEAR::isError($rows)) {             
-               die($rows->getMessage());
-       }
-}
-
-function insert_new_service($service, $url, $sec) {
-       $db = get_db_conn();    
-       $s = "INSERT INTO service VALUES(?, ?, ?)";
-       $t = array('text', 'text', 'boolean');
-       $stmt = $db->prepare($s, $t, MDB2_PREPARE_MANIP);
-       $secval = ($sec == "on") ? 1 : 0;
-       $data = array($service, $url, $secval);
-       $rows = $stmt->execute($data);
+       $input = new SetServiceLocation();
+       $input->location = new ServiceLocation();
+       $input->location->Sec = $sec ? "true" : "false";
+       $input->location->ServiceName = $name;
+       $input->location->ServiceURL = $url;
        
-       if (PEAR::isError($rows)) {
-               die($rows->getMessage());
-       }
+       $proxy->SetServiceLocation($input);
 }
 
 function update_params($post, $type) { 
@@ -280,9 +234,8 @@
                update_service($post['ops_name'], $post['ops_url'], $opssec);   
        
        } else if ($type == "addnew") {
                if (isset($post['service_name']) &&
-                       isset($post['service_url']) &&
-                       isset($post['service_sec']) ) {
-               insert_new_service($post['service_name'], $post['service_url'], 
$post['service_sec']);
+                       isset($post['service_url']) ) {
+               update_service($post['service_name'], $post['service_url'], 
$post['service_sec']);
                        }
        }
 }
@@ -292,29 +245,44 @@
        update_params($post, "basic");
 }
 
-function display_advanced_config_form() {
-       $db = get_db_conn();
+function display_advanced_config_form() {      
        
-       // current BS value
-       $res =& query_or_error($db, "SELECT bs FROM clienttobs WHERE client = 
'PHP_CLIENT'");   
-       $bs = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
-       
-       // current OPS value
-       $res =& query_or_error($db, "SELECT ops FROM bstoops WHERE bs = '" . 
$bs['bs'] . "'");
-       $ops = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
+       $proxy = get_proxy();
+       
+       $input = new GetClientConfig();
+       $input->client = new ClientConfigRequest();
+       $input->client->ClientName = "PHP_CLIENT";
+       $response = $proxy->GetClientConfig($input);
+               
+       $bs = $response->GetClientConfigResult->BSName;
+       
+       $input = new GetBSConfig();
+       $input->bs = new BSConfigRequest();
+       $input->bs->BSName = $bs;
+       $response = $proxy->GetBSConfig($input);
+                               
+       $ops = $response->GetBSConfigResult->OPSName;
+       
+       $input = new GetBSLocations();
+       $response = $proxy->GetBSLocations($input);
        
-       // All OPS into an array
-       $res =& query_or_error($db, "SELECT servicename, url, sec FROM service 
WHERE servicename LIKE '%_OPS%'");
-       $ops_list = array();
-       while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
-               $ops_list[$row['servicename']] = $row['url'] . '##' . 
$row['sec'];
-       }
-
-       // All BS into an array
-       $res =& query_or_error($db, "SELECT servicename, url, sec FROM service 
WHERE servicename LIKE '%_BS'");
        $bs_list = array();
-       while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
-               $bs_list[$row['servicename']] = $row['url'] . '##' . 
$row['sec'];
+       for ($i = 0; $i < 
count($response->GetBSLocationsResult->ServiceLocation); $i++) {
+               
$bs_list[$response->GetBSLocationsResult->ServiceLocation[$i]->ServiceName] =
+                       
$response->GetBSLocationsResult->ServiceLocation[$i]->ServiceURL .
+                       '##' .
+                       
$response->GetBSLocationsResult->ServiceLocation[$i]->Sec;
+       }
+       
+       $input = new GetOPSLocations();
+       $response = $proxy->GetOPSLocations($input);
+       
+       $ops_list = array();
+       for ($i = 0; $i < 
count($response->GetOPSLocationsResult->ServiceLocation); $i++) {
+               
$ops_list[$response->GetOPSLocationsResult->ServiceLocation[$i]->ServiceName] =
+                       
$response->GetOPSLocationsResult->ServiceLocation[$i]->ServiceURL .
+                       '##' .
+                       
$response->GetOPSLocationsResult->ServiceLocation[$i]->Sec;
        }
        
        // business service options
@@ -348,7 +316,7 @@
        
        foreach ($bs_list as $k => $v) {
                $str .= '<option value="' . $k . '"';
-               if ($k == $bs['bs']) {
+               if ($k == $bs) {
                         $str .= ' selected="selected"';
                }
                $str .= '>' . $k . '</option>';
@@ -356,7 +324,7 @@
        $str .= '</select> <a href="config.php?type=BS">Add New</a></td></tr>';
        echo $str;
        
-       $default_url = preg_split("/##/", $bs_list[$bs['bs']]);
+       $default_url = preg_split("/##/", $bs_list[$bs]);
        $str = <<<EOF
        <tr>
                <td>Business Service URL</td>
@@ -366,7 +334,7 @@
                <td>&nbsp;</td>
                <td><input type="checkbox" name="bs_sec" id="bs_sec"
 EOF;
-       if ($default_url[1] == 1) {
+       if ($default_url[1] == "true") {
                $str .= ' checked="checked"';
        }
        $str .= <<<EOF
@@ -410,7 +378,7 @@
 
        foreach($ops_list as $k => $v) {
                $str .= '<option value="' . $k . '"';
-               if ($k == $ops['ops']) {
+               if ($k == $ops) {
                        $str .= ' selected="selected"';
                }
                $str .= '>' . $k . '</option>';                 
@@ -418,7 +386,7 @@
        $str .= '</select> <a href="config.php?type=OPS">Add New</a></td></tr>';
        echo $str;
        
-       $default_url = preg_split("/##/", $ops_list[$ops['ops']]);
+       $default_url = preg_split("/##/", $ops_list[$ops]);
        $str = <<<EOF
        <tr>
                <td>Order Processing Service URL</td>
@@ -428,7 +396,7 @@
                <td>&nbsp;</td>
                <td><input type="checkbox" name="ops_sec" id="ops_sec"
 EOF;
-       if ($default_url[1] == 1) {
+       if ($default_url[1] == "true") {
                $str .= ' checked="checked"';
        }
        $str .= <<<EOF


Reply via email to