<?php

 // Copyright 2009-2011 United States Government. 

   //This software is licensed under the GNU General Public License
   //version 2 (see the file LICENSE for details)



function itlens_db_set_active($name) {
    global $user;

    static $isConnectionPrepared = NULL;

    if (isset($isConnectionPrepared[$name]) && $isConnectionPrepared[$name]) {
        db_set_active($name);

        return;
    } else {
        // looking for user agency in Drupal database
        $user_agency = '0';
        if (isset($user->name)) {
            /*db_set_active();
            $sql = "SELECT agency FROM user_agency WHERE name = '%s'";
            $result = db_query($sql, $user->name);

            while($row = mysql_fetch_array($result)) {
                $user_agency = $row['agency'];
            }*/
        }

        // proparaging the user agency to the application database
        /*db_set_active($name);
        try {
            $sql = "CALL set_agency('%s')";
            db_query($sql, $user_agency);
        } catch (Exception $e) {
            db_set_active();
            throw $e;
        }*/

        $isConnectionPrepared[$name] = TRUE;
    }
}
