fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [16313] refactor code


From: sigurdne
Subject: [Fmsystem-commits] [16313] refactor code
Date: Wed, 15 Feb 2017 13:09:12 -0500 (EST)

Revision: 16313
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=16313
Author:   sigurdne
Date:     2017-02-15 13:09:12 -0500 (Wed, 15 Feb 2017)
Log Message:
-----------
refactor code

Modified Paths:
--------------
    trunk/bookingfrontend/inc/class.bouser.inc.php
    trunk/bookingfrontend/inc/custom/default/MinId.php
    trunk/eventplannerfrontend/inc/class.bouser.inc.php

Modified: trunk/bookingfrontend/inc/class.bouser.inc.php
===================================================================
--- trunk/bookingfrontend/inc/class.bouser.inc.php      2017-02-15 15:51:32 UTC 
(rev 16312)
+++ trunk/bookingfrontend/inc/class.bouser.inc.php      2017-02-15 18:09:12 UTC 
(rev 16313)
@@ -238,130 +238,45 @@
 
                protected function get_breg_orgs( $fodselsnr )
                {
-                       $breg_conn = pg_connect("host=" . 
$GLOBALS['phpgw_domain']['default']['db_host'] . " port=5432 dbname=breg user=" 
. $GLOBALS['phpgw_domain']['default']['db_user'] . " password=" . 
$GLOBALS['phpgw_domain']['default']['db_pass']) or die('connection failed');
-                       $sql = "SELECT distinct orgnr FROM breg.personcurrent 
WHERE fodselsnr ='" . $fodselsnr . "'";
-                       $results = pg_query($breg_conn, $sql);
-                       $orgs = pg_fetch_all($results);
-                       print_r($sql);
-                       print_r($orgs);
-                       pg_close($breg_conn);
-                       return $orgs;
-               }
+                       $db = createObject('phpgwapi.db', null, null, true);
 
-               protected function get_user_orgnr_from_auth_header()
-               {
-                       $config = CreateObject('phpgwapi.config', 
'bookingfrontend');
-                       $config->read();
-                       if ($config->config_data['authentication_method'] === 
'MinId.php')
+                       $db->Host = 
$GLOBALS['phpgw_domain']['default']['db_host'];
+                       $db->Port = '5432';
+                       $db->Type = 'postgres';
+                       $db->Database = 'breg';
+                       $db->User = 
$GLOBALS['phpgw_domain']['default']['db_user'];
+                       $db->Password = 
$GLOBALS['phpgw_domain']['default']['db_pass'];
+
+                       try
                        {
-                               $ipdp = sha1($_SERVER['HTTP_UID']);
-                               $bregorgs = $this->get_breg_orgs($ipdp);
-                               $myorgnr = array();
-                               if ($bregorgs == array())
-                               {
-                                       $external_user = (object)'ciao';
-                                       $external_user->login = '000000000';
-                               }
-                               else
-                               {
-                                       foreach ($bregorgs as $org)
-                                       {
-                                               $myorgnr[] = $org['orgnr'];
-                                       }
-                                       if (count($myorgnr) > 1)
-                                       {
-                                               $external_user = (object)'ciao';
-                                               $external_user->login = 
$myorgnr[0];
-                                               $orgs = array();
-                                               foreach ($myorgnr as $org)
-                                               {
-                                                       $orgs[] = 
array('orgnumber' => $org, 'orgname' => $this->get_orgname_from_db($org));
-                                               }
-                                               
phpgwapi_cache::session_set($this->get_module(), self::ORGARRAY_SESSION_KEY, 
$orgs);
-                                       }
-                                       elseif (count($myorgnr) > 0)
-                                       {
-                                               
phpgwapi_cache::session_set($this->get_module(), self::ORGARRAY_SESSION_KEY, 
NULL);
-                                               $external_user = (object)'ciao';
-                                               $external_user->login = 
$myorgnr[0];
-                                       }
-                               }
+                               $db->connect();
+                               $this->connected = true;
                        }
-                       else
+                       catch (Exception $e)
                        {
-
-                               $header_key = 
isset($config->config_data['header_key']) && $config->config_data['header_key'] 
? $config->config_data['header_key'] : 'Osso-User-Dn';
-                               $header_regular_expression = 
isset($config->config_data['header_regular_expression']) && 
$config->config_data['header_regular_expression'] ? 
$config->config_data['header_regular_expression'] : '/^cn=(.*),cn=users.*$/';
-
-                               $headers = getallheaders();
-
-                               if (isset($config->config_data['debug']) && 
$config->config_data['debug'])
-                               {
-                                       $this->debug = true;
-                                       echo 'headers:<br>';
-                                       _debug_array($headers);
-                               }
-
-                               if (isset($headers[$header_key]) && 
$headers[$header_key])
-                               {
-                                       $matches = array();
-                                       
preg_match_all($header_regular_expression, $headers[$header_key], $matches);
-                                       $userid = $matches[1][0];
-
-                                       if ($this->debug)
-                                       {
-                                               echo 'matches:<br>';
-                                               _debug_array($matches);
-                                       }
-                               }
-
-                               $options = array();
-                               $options['soap_version'] = SOAP_1_1;
-                               $options['location'] = 
isset($config->config_data['soap_location']) && 
$config->config_data['soap_location'] ? $config->config_data['soap_location'] : 
'';// 'http://soat1a.srv.bergenkom.no:8888/gateway/services/BrukerService-v1';
-                               $options['uri'] = 
isset($config->config_data['soap_uri']) && $config->config_data['soap_uri'] ? 
$config->config_data['soap_uri'] : '';// 'http://soat1a.srv.bergenkom.no';
-                               $options['trace'] = 1;
-
-                               if 
(isset($config->config_data['soap_proxy_host']) && 
$config->config_data['soap_proxy_host'])
-                               {
-                                       $options['proxy_host'] = 
$config->config_data['soap_proxy_host'];
-                               }
-
-                               if 
(isset($config->config_data['soap_proxy_port']) && 
$config->config_data['soap_proxy_port'])
-                               {
-                                       $options['proxy_port'] = 
$config->config_data['soap_proxy_port'];
-                               }
-                               $options['encoding'] = 
isset($config->config_data['soap_encoding']) && 
$config->config_data['soap_encoding'] ? $config->config_data['soap_encoding'] : 
'UTF-8';
-                               $options['login'] = 
isset($config->config_data['soap_login']) && $config->config_data['soap_login'] 
? $config->config_data['soap_login'] : '';
-                               $options['password'] = 
isset($config->config_data['soap_password']) && 
$config->config_data['soap_password'] ? $config->config_data['soap_password'] : 
'';
-
-                               $wsdl = 
isset($config->config_data['soap_wsdl']) && $config->config_data['soap_wsdl'] ? 
$config->config_data['soap_wsdl'] : '';// 
'http://soat1a.srv.bergenkom.no:8888/gateway/services/BrukerService-v1?wsdl';
-
-                               $authentication_method = 
isset($config->config_data['authentication_method']) && 
$config->config_data['authentication_method'] ? 
$config->config_data['authentication_method'] : '';
-
-                               require_once PHPGW_SERVER_ROOT . 
"/bookingfrontend/inc/custom/default/{$authentication_method}";
-
-                               $external_user = new 
booking_external_user($wsdl, $options, $userid, $this->debug);
-                               // test values
-                               //$external_user = (object) 'ciao'; 
$external_user->login = 994239929;
+                               $status = lang('unable_to_connect_to_database');
                        }
 
-                       if ($this->debug)
+                       $sql = "SELECT DISTINCT orgnr FROM personcurrent WHERE 
fodselsnr ='{$fodselsnr}'";
+                       $results = array();
+                       $db = & $GLOBALS['phpgw']->db;
+                       $db->query($sql, __LINE__, __FILE__);
+                       while ($db->next_record())
                        {
-                               echo 'External user:<br>';
-                               _debug_array($external_user);
+                               $results[] = $db->f('orgnr', true);
                        }
-                       try
-                       {
-                               return 
createObject('booking.sfValidatorNorwegianOrganizationNumber')->clean($external_user->login);
-                       }
-                       catch (sfValidatorError $e)
-                       {
-                               if ($this->debug)
-                               {
-                                       echo $e->getMessage();
-                                       die();
-                               }
-                               return null;
-                       }
+                       return $results;
                }
+
+      protected function get_breg_orgs_old($fodselsnr) {
+            $breg_conn = 
pg_connect("host=".$GLOBALS['phpgw_domain']['default']['db_host']." port=5432 
dbname=breg user=".$GLOBALS['phpgw_domain']['default']['db_user']." 
password=".$GLOBALS['phpgw_domain']['default']['db_pass']) or die('connection 
failed');
+            $sql = "SELECT distinct orgnr FROM breg.personcurrent WHERE 
fodselsnr ='".$fodselsnr."'";
+            $results = pg_query($breg_conn, $sql);
+            $orgs = pg_fetch_all($results);
+            print_r($sql);
+            print_r($orgs);
+            pg_close($breg_conn);
+            return $orgs;
+        }
+
        }
\ No newline at end of file

Modified: trunk/bookingfrontend/inc/custom/default/MinId.php
===================================================================
--- trunk/bookingfrontend/inc/custom/default/MinId.php  2017-02-15 15:51:32 UTC 
(rev 16312)
+++ trunk/bookingfrontend/inc/custom/default/MinId.php  2017-02-15 18:09:12 UTC 
(rev 16313)
@@ -36,269 +36,67 @@
        /**
         * START WRAPPER
         */
-       class booking_external_user
+       class bookingfrontend_external_user extends bookingfrontend_bouser
        {
 
-               /**
-                * The resulting external user
-                * @access public
-                * @var string
-                */
-               public $login = 0;
+               public function __construct()
+               {
+                       parent::__construct();
+               }
 
-               /**
-                * Debug for testing
-                * @access public
-                * @var bool
-                */
-               public $debug = false;
-               public $orgs = array();
-
-               public function __construct( $wsdl, $options, $userid, $debug = 
false )
+               protected function get_user_org_id()
                {
-                       if ($debug)
+                       $ipdp = sha1($_SERVER['HTTP_UID']);
+                       $bregorgs = $this->get_breg_orgs($ipdp);
+                       $myorgnr = array();
+                       if ($bregorgs == array())
                        {
-                               $this->debug = true;
+                               $external_user = (object)'ciao';
+                               $external_user->login = '000000000';
                        }
-                       try
+                       else
                        {
-                               $BrukerService = new BrukerService($wsdl, 
$options);
-                       }
-                       catch (Exception $e)
-                       {
-                               if ($this->debug)
+                               foreach ($bregorgs as $org)
                                {
-                                       echo $e->getMessage();
-                                       echo '<br>wsdl: ' . $wsdl;
-                                       echo '<br>options:';
-                                       _debug_array($options);
+                                       $myorgnr[] = $org['orgnr'];
                                }
+                               if (count($myorgnr) > 1)
+                               {
+                                       $external_user = (object)'ciao';
+                                       $external_user->login = $myorgnr[0];
+                                       $orgs = array();
+                                       foreach ($myorgnr as $org)
+                                       {
+                                               $orgs[] = array('orgnumber' => 
$org, 'orgname' => $this->get_orgname_from_db($org));
+                                       }
+                                       
phpgwapi_cache::session_set($this->get_module(), self::ORGARRAY_SESSION_KEY, 
$orgs);
+                               }
+                               elseif (count($myorgnr) > 0)
+                               {
+                                       
phpgwapi_cache::session_set($this->get_module(), self::ORGARRAY_SESSION_KEY, 
NULL);
+                                       $external_user = (object)'ciao';
+                                       $external_user->login = $myorgnr[0];
+                               }
                        }
 
-                       if (isset($BrukerService) && $BrukerService)
+
+                       if ($this->debug)
                        {
-                               $ctx = new UserContext();
-
-                               $ctx->appid = 'portico';
-                               $ctx->onBehalfOfId = $userid;
-                               $ctx->userid = $userid;
-                               $ctx->transactionid = 
$GLOBALS['phpgw_info']['server']['install_id']; // KAN UTELATES. BENYTTES I.F.M 
SUPPORT. LEGG INN EN FOR DEG UNIK ID.
-
-                               $request = new retrieveBruker();
-                               $request->userContext = $ctx;
-                               $request->userid = $userid;
-
-                               $response = 
$BrukerService->retrieveBruker($request);
-                               $Bruker = $response->return;
-                               $this->login = $Bruker->ou; // organisasjons nr
+                               echo 'External user:<br>';
+                               _debug_array($external_user);
                        }
-               }
-       }
-       /**
-        * END WRAPPER - custom code beyond this point
-        */
-       /**
-        * soap client for altinn supported external login service at Bergen 
Kommune
-        * this code is generated by the 
http://code.google.com/p/wsdl2php-interpreter/ 
-        *
-        * @package phpgroupware
-        * @subpackage bookingfrontend
-        */
-
-       /**
-        * Bruker
-        */
-       class Bruker
-       {
-
-               /**
-                * @access public
-                * @var string
-                */
-               public $uid;
-
-               /**
-                * @access public
-                * @var string
-                */
-               public $mail;
-
-               /**
-                * @access public
-                * @var string
-                */
-               public $preferedLocal;
-
-               /**
-                * @access public
-                * @var string
-                */
-               public $givenName;
-
-               /**
-                * @access public
-                * @var string
-                */
-               public $sn;
-
-               /**
-                * @access public
-                * @var string
-                */
-               public $cn;
-
-               /**
-                * @access public
-                * @var string
-                */
-               public $ou;
-
-       }
-
-       /**
-        * UserContext
-        */
-       class UserContext
-       {
-
-               /**
-                * @access public
-                * @var string
-                */
-               public $userid;
-
-               /**
-                * @access public
-                * @var string
-                */
-               public $onBehalfOfId;
-
-               /**
-                * @access public
-                * @var string
-                */
-               public $appid;
-
-               /**
-                * @access public
-                * @var string
-                */
-               public $transactionid;
-
-       }
-
-       /**
-        * retrieveBruker
-        */
-       class retrieveBruker
-       {
-
-               /**
-                * @access public
-                * @var UserContext
-                */
-               public $userContext;
-
-               /**
-                * @access public
-                * @var string
-                */
-               public $userid;
-
-       }
-
-       /**
-        * retrieveBrukerResponse
-        */
-       class retrieveBrukerResponse
-       {
-
-               /**
-                * @access public
-                * @var Bruker
-                */
-               public $return;
-
-       }
-
-       /**
-        * BrukerService
-        * @author WSDLInterpreter
-        */
-       class BrukerService extends SoapClient
-       {
-
-               /**
-                * Default class map for wsdl=>php
-                * @access private
-                * @var array
-                */
-               private static $classmap = array
-                       (
-                       "Bruker" => "Bruker",
-                       "UserContext" => "UserContext",
-                       "retrieveBruker" => "retrieveBruker",
-                       "retrieveBrukerResponse" => "retrieveBrukerResponse",
-               );
-
-               /**
-                * Constructor using wsdl location and options array
-                * @param string $wsdl WSDL location for this service
-                * @param array $options Options for the SoapClient
-                */
-               public function __construct( $wsdl = '', $options = array() )
-               {
-                       foreach (self::$classmap as $wsdlClassName => 
$phpClassName)
+                       try
                        {
-                               if 
(!isset($options['classmap'][$wsdlClassName]))
-                               {
-                                       $options['classmap'][$wsdlClassName] = 
$phpClassName;
-                               }
+                               return 
createObject('booking.sfValidatorNorwegianOrganizationNumber')->clean($external_user->login);
                        }
-                       parent::__construct($wsdl, $options);
-               }
-
-               /**
-                * Checks if an argument list matches against a valid argument 
type list
-                * @param array $arguments The argument list to check
-                * @param array $validParameters A list of valid argument types
-                * @return boolean true if arguments match against 
validParameters
-                * @throws Exception invalid function signature message
-                */
-               public function _checkArguments( $arguments, $validParameters )
-               {
-                       $variables = "";
-                       foreach ($arguments as $arg)
+                       catch (sfValidatorError $e)
                        {
-                               $type = gettype($arg);
-                               if ($type == "object")
+                               if ($this->debug)
                                {
-                                       $type = get_class($arg);
+                                       echo $e->getMessage();
+                                       die();
                                }
-                               $variables .= "(" . $type . ")";
+                               return null;
                        }
-                       if (!in_array($variables, $validParameters))
-                       {
-                               throw new Exception("Invalid parameter types: " 
. str_replace(")(", ", ", $variables));
-                       }
-                       return true;
                }
-
-               /**
-                * Service Call: retrieveBruker
-                * Parameter options:
-                * (retrieveBruker) parameters
-                * @param mixed,... See function description for parameter 
options
-                * @return retrieveBrukerResponse
-                * @throws Exception invalid function signature message
-                */
-               public function retrieveBruker( $mixed = null )
-               {
-                       $validParameters = array(
-                               "(retrieveBruker)",
-                       );
-                       $args = func_get_args();
-                       $this->_checkArguments($args, $validParameters);
-                       return $this->__soapCall("retrieveBruker", $args);
-               }
        }
\ No newline at end of file

Modified: trunk/eventplannerfrontend/inc/class.bouser.inc.php
===================================================================
--- trunk/eventplannerfrontend/inc/class.bouser.inc.php 2017-02-15 15:51:32 UTC 
(rev 16312)
+++ trunk/eventplannerfrontend/inc/class.bouser.inc.php 2017-02-15 18:09:12 UTC 
(rev 16313)
@@ -254,120 +254,4 @@
                        return $results;
                }
 
-               protected function get_user_orgnr_from_auth_header()
-               {
-                       $config = CreateObject('phpgwapi.config', 
'eventplannerfrontend');
-                       $config->read();
-                       if ($config->config_data['authentication_method'] === 
'MinId.php')
-                       {
-                               $ipdp = sha1($_SERVER['HTTP_UID']);
-                               $bregorgs = $this->get_breg_orgs($ipdp);
-                               $myorgnr = array();
-                               if ($bregorgs == array())
-                               {
-                                       $external_user = (object)'ciao';
-                                       $external_user->login = '000000000';
-                               }
-                               else
-                               {
-                                       foreach ($bregorgs as $org)
-                                       {
-                                               $myorgnr[] = $org['orgnr'];
-                                       }
-                                       if (count($myorgnr) > 1)
-                                       {
-                                               $external_user = (object)'ciao';
-                                               $external_user->login = 
$myorgnr[0];
-                                               $orgs = array();
-                                               foreach ($myorgnr as $org)
-                                               {
-                                                       $orgs[] = 
array('orgnumber' => $org, 'orgname' => $this->get_orgname_from_db($org));
-                                               }
-                                               
phpgwapi_cache::session_set($this->get_module(), self::ORGARRAY_SESSION_KEY, 
$orgs);
-                                       }
-                                       elseif (count($myorgnr) > 0)
-                                       {
-                                               
phpgwapi_cache::session_set($this->get_module(), self::ORGARRAY_SESSION_KEY, 
NULL);
-                                               $external_user = (object)'ciao';
-                                               $external_user->login = 
$myorgnr[0];
-                                       }
-                               }
-                       }
-                       else
-                       {
-
-                               $header_key = 
isset($config->config_data['header_key']) && $config->config_data['header_key'] 
? $config->config_data['header_key'] : 'Osso-User-Dn';
-                               $header_regular_expression = 
isset($config->config_data['header_regular_expression']) && 
$config->config_data['header_regular_expression'] ? 
$config->config_data['header_regular_expression'] : '/^cn=(.*),cn=users.*$/';
-
-                               $headers = getallheaders();
-
-                               if (isset($config->config_data['debug']) && 
$config->config_data['debug'])
-                               {
-                                       $this->debug = true;
-                                       echo 'headers:<br>';
-                                       _debug_array($headers);
-                               }
-
-                               if (isset($headers[$header_key]) && 
$headers[$header_key])
-                               {
-                                       $matches = array();
-                                       
preg_match_all($header_regular_expression, $headers[$header_key], $matches);
-                                       $userid = $matches[1][0];
-
-                                       if ($this->debug)
-                                       {
-                                               echo 'matches:<br>';
-                                               _debug_array($matches);
-                                       }
-                               }
-
-                               $options = array();
-                               $options['soap_version'] = SOAP_1_1;
-                               $options['location'] = 
isset($config->config_data['soap_location']) && 
$config->config_data['soap_location'] ? $config->config_data['soap_location'] : 
'';// 'http://soat1a.srv.bergenkom.no:8888/gateway/services/BrukerService-v1';
-                               $options['uri'] = 
isset($config->config_data['soap_uri']) && $config->config_data['soap_uri'] ? 
$config->config_data['soap_uri'] : '';// 'http://soat1a.srv.bergenkom.no';
-                               $options['trace'] = 1;
-
-                               if 
(isset($config->config_data['soap_proxy_host']) && 
$config->config_data['soap_proxy_host'])
-                               {
-                                       $options['proxy_host'] = 
$config->config_data['soap_proxy_host'];
-                               }
-
-                               if 
(isset($config->config_data['soap_proxy_port']) && 
$config->config_data['soap_proxy_port'])
-                               {
-                                       $options['proxy_port'] = 
$config->config_data['soap_proxy_port'];
-                               }
-                               $options['encoding'] = 
isset($config->config_data['soap_encoding']) && 
$config->config_data['soap_encoding'] ? $config->config_data['soap_encoding'] : 
'UTF-8';
-                               $options['login'] = 
isset($config->config_data['soap_login']) && $config->config_data['soap_login'] 
? $config->config_data['soap_login'] : '';
-                               $options['password'] = 
isset($config->config_data['soap_password']) && 
$config->config_data['soap_password'] ? $config->config_data['soap_password'] : 
'';
-
-                               $wsdl = 
isset($config->config_data['soap_wsdl']) && $config->config_data['soap_wsdl'] ? 
$config->config_data['soap_wsdl'] : '';// 
'http://soat1a.srv.bergenkom.no:8888/gateway/services/BrukerService-v1?wsdl';
-
-                               $authentication_method = 
isset($config->config_data['authentication_method']) && 
$config->config_data['authentication_method'] ? 
$config->config_data['authentication_method'] : '';
-
-                               require_once PHPGW_SERVER_ROOT . 
"/eventplannerfrontend/inc/custom/default/{$authentication_method}";
-
-                               $external_user = new 
booking_external_user($wsdl, $options, $userid, $this->debug);
-                               // test values
-                               //$external_user = (object) 'ciao'; 
$external_user->login = 994239929;
-                       }
-
-                       if ($this->debug)
-                       {
-                               echo 'External user:<br>';
-                               _debug_array($external_user);
-                       }
-                       try
-                       {
-                               return 
createObject('booking.sfValidatorNorwegianOrganizationNumber')->clean($external_user->login);
-                       }
-                       catch (sfValidatorError $e)
-                       {
-                               if ($this->debug)
-                               {
-                                       echo $e->getMessage();
-                                       die();
-                               }
-                               return null;
-                       }
-               }
        }
\ No newline at end of file




reply via email to

[Prev in Thread] Current Thread [Next in Thread]