示例#1
1
 /**
  * Open RFC client connection to SAP R/3 System
  *
  * @param [client]        Client number
  * @param [user]          User name
  * @param [passwd]        Password
  * @param [language]      Language (empty = default)
  *
  * @return SAPRFC_OK on success, <> SAPRFC_OK on failure
  */
 function Open($client = "", $user = "", $passwd = "", $lang = "")
 {
     if ($this->rfc) {
         return $this->SetStatus(SAPRFC_ERROR, "SAPConnection::Open: Connection is " . "already opened, close it first.");
     }
     switch ($this->connType) {
         case SAPRFC_CONN_NONE:
             return $this->SetStatus(SAPRFC_ERROR, "SAPConnection::Open: Connection is " . "is not defined.");
         case SAPRFC_CONN_APPSERVER:
             $connect_data[ASHOST] = $this->appServer;
             $connect_data[SYSNR] = $this->systemNumber;
             break;
         case SAPRFC_CONN_LOGONGROUP:
             $connect_data[MSHOST] = $this->messageServer;
             $connect_data[R3NAME] = $this->R3SystemName;
             $connect_data[GROUP] = $this->logonGroup;
             break;
         case SAPRFC_CONN_USERDEFINED:
             $connect_data = $this->userLogonData;
             break;
         default:
             return $this->SetStatus(SAPRFC_ERROR, "SAPConnection::Open: Unsupported connection type");
     }
     if (!empty($client)) {
         $connect_data[CLIENT] = $client;
     }
     if (!empty($user)) {
         $connect_data[USER] = $user;
     }
     if (!empty($passwd)) {
         $connect_data[PASSWD] = $passwd;
     }
     if (!empty($lang)) {
         $connect_data[LANG] = $lang;
     }
     $this->rfc = @saprfc_open($connect_data);
     if ($this->rfc == false) {
         return $this->SetStatus(SAPRFC_ERROR, @saprfc_error());
     }
     if ($this->trace) {
         $this->EnableTrace();
     } else {
         $this->DisableTrace();
     }
     if (!empty($this->codePage)) {
         $this->SetCodePage($this->codePage);
     }
     return $this->SetStatus(SAPRFC_OK, "");
 }
示例#2
1
//----------------------------------------------------------------------


$REPORT = "RSUSR000";                            // Set name of the report

$LOGIN = array (                                 // Set login data to R/3
			"ASHOST"=>"garfield",                // application server host name
			"SYSNR"=>"30",                       // system number
			"CLIENT"=>"900",                     // client
			"USER"=>"rfctest",                   // user
			"PASSWD"=>"*****",                   // password
			"CODEPAGE"=>"1404");                 // codepage
   
// ----------------------------------------------------------------------------

   $rfc = saprfc_open ($LOGIN);
   if (! $rfc )
   {
       echo "RFC connection failed with error:".saprfc_error();
       exit;
   }

   $fce = saprfc_function_discover($rfc, "RFC_READ_REPORT");
   if (! $fce )
   {
       echo "Discovering interface of function module RFC_READ_REPORT failed";
       exit;
   }

   saprfc_import ($fce,"PROGRAM",$REPORT);
   saprfc_table_init ($fce,"QTAB");
示例#3
1
        if (isset($GWHOST))             $l["GWHOST"] = $GWHOST;
        if (isset($GWSERV))             $l["GWSERV"] = $GWSERV;
        if (isset($MSHOST))             $l["MSHOST"] = $MSHOST;
        if (isset($R3NAME))             $l["R3NAME"] = $R3NAME;
        if (isset($GROUP))              $l["GROUP"] = $GROUP;
        if (isset($LANG))               $l["LANG"] = $LANG;
        if (isset($TRACE))              $l["TRACE"] = $TRACE;
        if (isset($LCHECK))             $l["LCHECK"] = $LCHECK;
        if (isset($CODEPAGE))           $l["CODEPAGE"] = $CODEPAGE;
        $SAPRFC_LOGON = serialize ($l);       // set cookie variable
        $p = "select";                        // switch to selection of function module
    }
}

// login data avaible, can open connection to SAP R/3
$rfc = @saprfc_open ($l);

if (! $rfc )                    // if login failed, show error message
{
   if (isset ($l["use_load_balancing"]))
      print_error_message ( "Login error",
                            "Can't login to client ".$l["CLIENT"]." of the system ".$l["R3NAME"]." (Host: ".$l["MSHOST"].", Group: ".$l["GROUP"].") as user ".$l["USER"].". <a href=\"saprfc_test.php?p=newlogin\">New login</a>",
                            saprfc_error()
                          );
   else
      print_error_message ( "Login error",
                            "Can't login to client ".$l["CLIENT"]." and host ".$l["ASHOST"]." (System number: ".$l["SYSNR"].") as user ".$l["USER"].". <a href=\"saprfc_test.php?p=newlogin\">New login</a>",
                            saprfc_error()
                          );
   exit;
}
示例#4
0
文件: SAP.php 项目: wilaheng/wila
 public function connect($func, $CDSA)
 {
     $conn = inf()->sap->conn;
     $conn["USER"] = $_SESSION["SAP_USERNAME"];
     $conn["PASSWD"] = $_SESSION["SAP_PASSWORD"];
     $this->user = $conn["USER"];
     $this->conn = saprfc_open($conn);
     if (!$this->conn) {
         throw new Exception("SAPRFC CONNECTION FAILED");
     }
     $this->func = saprfc_function_discover($this->conn, $func);
     if (!$this->func) {
         throw new Exception(sprintf("DISCOVERING INTERFACE OF FUNCTION %s MODULE FAILED", $func));
     }
     $this->conf = inf()->sap->conf;
     $rs = DB::lookup("vfs")->executeQuery("SELECT * FROM sap_conf WHERE AREA_SUB='%s'", $CDSA);
     if ($rs->next()) {
         $this->conf["BUS_AREA"] = $rs->get("BUS_AREA");
         $this->VR = $rs->get("VENDOR");
         $this->VC = $rs->get("VENDOR_CO");
         $this->CC = $rs->get("COST_CENTER");
         $this->PC = $rs->get("PROFIT_CENTER");
     } else {
         throw new Exception(sprintf("LOADING SAP CONFIG FOR FUNCTION %s MODULE FAILED", $func));
     }
 }
示例#5
-1
 public function open()
 {
     $rfc = saprfc_open($sap_config);
     if (!$rfc) {
         echo 'An error occured: <pre>';
         print_r(saprfc_error());
         exit;
     }
     return $rfc;
 }
示例#6
-1
	function login() {
	   	if (!$this->rfc_conn)
	   	{
		   	$this->rfc_conn=@saprfc_open($this->logindata);
			if (!$this->rfc_conn) {
				return $this->setStatus(SAPRFC_ERROR,"saprfc::login()\nOpen RFC connection with saprfc_open() failed with error:\n".@saprfc_error());
			}
		}
		return SAPRFC_OK;
	}
示例#7
-1
 function bapiCall($bapiName)
 {
     global $rfc, $fce;
     $login = $_SESSION['sap_login'];
     $rfc = saprfc_open($login);
     $fce = saprfc_function_discover($rfc, $bapiName);
     if (!$fce) {
         echo "Discovering interface of function module failed";
         exit;
     }
 }
示例#8
-1
 /**
  * @return null
  * @throws Exception
  * @author Manuel Will
  * @since 2013
  */
 private function getConnectionResource()
 {
     if (null === self::$connectionResource) {
         $this->checkSapIsConnectAble();
         $connection = saprfc_open($this->arrCredentials);
         if (!$connection) {
             $arrCredentials = $this->arrCredentials;
             $message = sprintf('The SAP-Connection failed. %s@%s ', $arrCredentials['ASHOST'], $arrCredentials['USER']);
             throw new SAP_Exception($message);
         }
         self::$connectionResource = $connection;
     }
     return self::$connectionResource;
 }
示例#9
-1
 /**
  * Performs username and password check
  *
  * @param string Username
  * @param string Password
  * @return boolean TRUE on success (valid user), FALSE otherwise
  */
 function fetchData($username, $password)
 {
     $this->log('Auth_Container_SAP::fetchData() called.', AUTH_LOG_DEBUG);
     $connection_options = $this->options;
     $connection_options['USER'] = $username;
     $connection_options['PASSWD'] = $password;
     $rfc = saprfc_open($connection_options);
     if (!$rfc) {
         $message = "Couldn't connect to the SAP system.";
         $error = $this->getError();
         if ($error['message']) {
             $message .= ': ' . $error['message'];
         }
         PEAR::raiseError($message, null, null, null, @$erorr['all']);
         return false;
     } else {
         if (!empty($this->options['GETSSO2'])) {
             $this->log('Attempting to retrieve SSO2 ticket.', AUTH_LOG_DEBUG);
             if ($ticket = @saprfc_get_ticket($rfc)) {
                 $this->options['MYSAPSSO2'] = $ticket;
                 unset($this->options['GETSSO2']);
                 $this->_auth_obj->setAuthData('sap', $this->options);
             } else {
                 PEAR::raiseError("SSO ticket retrieval failed");
             }
         }
         @saprfc_close($rfc);
         return true;
     }
 }
示例#10
-1
 /**
  * sapLogn
  *
  * @param string $conn - Connection string "Test","Production","Production_wm"
  * @return boolean
  * @access private
  */
 public function saplogin($conn = null)
 {
     switch ($conn) {
         case "Test":
             $this->sapRfc = @saprfc_open($this->sap_login_test);
             break;
         case "Production":
             $this->sapRfc = @saprfc_open($this->sap_login_production);
             break;
         case "Production_wm":
             $this->sapRfc = @saprfc_open($this->sap_login_wm_production);
             break;
         default:
             $this->sapRfc = @saprfc_open($this->sap_login_test);
             break;
     }
     if (!$this->sapRfc) {
         return false;
     }
     return true;
 }
示例#11
-1
# Prerequisite:
#    Profile parameters: login/create_sso2_ticket = 1
#                        login/accept_sso2_ticket = 1
#    Transaction SSO2 - Administration logon ticket
#
# The first logon to SAP using username and password, request for ticket GETOSS2 = 1
# Please change logon parameters for your system
$login = array("ASHOST" => "<hostname>", "SYSNR" => "00", "CLIENT" => "<client>", "USER" => "<username>", "PASSWD" => "<password>", "GETSSO2" => "1");
$rfc = saprfc_open($login);
if (!$rfc) {
    echo "RFC connection failed";
    exit;
}
# Get SSO ticket
$ticket = saprfc_get_ticket($rfc);
saprfc_close($rfc);
if ($ticket) {
    echo "SSO2 ticket = " . $ticket . "<br>";
}
# The second logon to SAP using SSO2 ticket
unset($login["PASSWD"]);
unset($login["USER"]);
unset($login["GETSS02"]);
$login["MYSAPSSO2"] = $ticket;
$rfc = saprfc_open($login);
if (!$rfc) {
    echo "SSO2 RFC connection failed";
    exit;
}
echo "SSO2 OK<br>";
saprfc_close($rfc);
示例#12
-2
文件: Gateway.php 项目: cti/saprfc
 /**
  * @param $config
  * @throws Exception
  */
 function __construct($config)
 {
     if (!function_exists('saprfc_open')) {
         throw new Exception('no saprfc extension');
     }
     $this->connection = saprfc_open($config);
     if (!$this->connection) {
         throw new Exception($this->decodeString(saprfc_error()));
     }
     $this->errors = array(SAPRFC_FAILURE => 'Error occurred', SAPRFC_EXCEPTION => 'Exception raised', SAPRFC_SYS_EXCEPTION => 'System exception raised, connection closed', SAPRFC_CALL => 'Call received', SAPRFC_INTERNAL_COM => 'Internal communication, repeat (internal use only)', SAPRFC_CLOSED => 'Connection closed by the other side', SAPRFC_RETRY => 'No data yet', SAPRFC_NO_TID => 'No Transaction ID available', SAPRFC_EXECUTED => 'Function already executed', SAPRFC_SYNCHRONIZE => 'Synchronous Call in Progress', SAPRFC_MEMORY_INSUFFICIENT => 'Memory insufficient', SAPRFC_VERSION_MISMATCH => 'Version mismatch', SAPRFC_NOT_FOUND => 'Function not found (internal use only)', SAPRFC_CALL_NOT_SUPPORTED => 'This call is not supported', SAPRFC_NOT_OWNER => 'Caller does not own the specified handle', SAPRFC_NOT_INITIALIZED => 'RFC not yet initialized.', SAPRFC_SYSTEM_CALLED => 'A system call such as RFC_PING for connectiontest is executed', SAPRFC_INVALID_HANDLE => 'An invalid handle was passed to an API call.', SAPRFC_INVALID_PARAMETER => 'An invalid parameter was passed to an API call.', SAPRFC_CANCELED => 'Internal use only');
 }