Anda di halaman 1dari 13

Compatible php con SAP http://www.sdn.sap.com/irj/scn/weblogs?

blog=/pub/wlg/3916 Introduction This weblog provides a simple implementation that uses SAPRFC , PHPRFC extension and PHP script to view the details of Mobile Devices(Details of Users , Installed Application Details and the Device Profile) attached to the particular MI Server. This blog would be helpful to those non-SAP users(PHP programmers) who are willing to use the simple functionalities provided by SAP MI. The sample scripts implement RFC calls to the function modules MEMGMT_DEVICE_GETLIST(for getting the list of all devices attached to the MI Server) and MEMGMT_DEVICE_GETDETAIL(for getting the details of a particular mobile device). Prerequisites 1. System must be configured properly to support the PHPRFC(This provides an RFC interface to SAP function modules in PHP). 2. The MI server user , used to login , must have the appropriate authorizations to execute the MI related RFC enabled function modules. Versions Used I used the Apache Server 2.0.58 , PHP 5.1.4 and the SAPRFC 1.4.1-5.1.1 as subject installations. Source Code This initial.php file is to provide a generic user interface to login into the MI Server. <html> <head> <title>Mobile Infrastructure Login Page</title> </head> <body bgcolor="#ededed"> <h3>MI Server Login Details</h3> <form action="login.php" action="post"> <table border=1 bgcolor="#dedede"> <tr><td>Server Name</td><td><input type="text" name="serverName"></td></tr> <tr><td>System Number</td><td><input type="text" name="sysNumber" size="3" maxlength=2></td></tr> <tr><td>Client</td><td><input type="text" name="sapClient" size="3" maxlength=3></td></tr> <tr><td>User</td><td><input type="text" name="sapUser"></td></tr> <tr><td>Password</td><td><input type="password" name="userPassword"></td></tr> <tr><td align="right"><input type="submit" value="Login"></td><td><input type="reset" value="Clear"></td></tr> </table> </form> </body> </html> The login page will look like this when you access the page through browser.In this screen you have to enter the MI Server login parameters.

This login.php file contains the PHP scripts to display the list of mobile devices attached to the MI Server.I have used a little bit of style sheet and java script codes to format the output while viewing through the browser. <html> <head> <title>List of Mobile Devices</title> </head> <body bgcolor="#ededed"> <?php $serverName = $_GET['serverName']; $sysNumber = $_GET['sysNumber']; $sapClient = $_GET['sapClient']; $sapUser = $_GET['sapUser']; $userPassword = $_GET['userPassword']; require_once("saprfc.php"); $sap = new saprfc(array( "logindata"=>array( "ASHOST"=> $serverName // application server ,"SYSNR"=> $sysNumber // system number ,"CLIENT"=> $sapClient // client ,"USER"=> $sapUser // user ,"PASSWD"=> $userPassword // password ) ,"show_errors"=>false // let class printout errors ,"debug"=>false)) ; // detailed debugging information // Call-Function - For getting the list of installed mobile devices

$result=$sap->callFunction("MEMGMT_DEVICE_GETLIST", array( array("TABLE","DEVICE_LIST",array()))); // Call successfull? if ($sap->getStatus() == SAPRFC_OK) { // Yes, print out the LIst of devices ?> <h4>List of All Mobile Devices</h4> <?php // This is to find out the total number of installed mobile devices. $iCount = 0; foreach ($result["DEVICE_LIST"] as $user) { if($user["DEPLID"]!='') { $iCount = $iCount + 1; } } ?> <table><tr><td><b>Total Number of Mobile Devices </b></td><td><b><?= $iCount ? ></b></td></tr></table> <table width=100%> <tr class=miHeader><td class="1stCellHeader">Device ID</td><td class="1stCellHeader">User Name</td><td class="1stCellHeader">Device Name</td><td class="1stCellHeader">Changed Date</td><td class="1stCellHeader">Changed Time</td></tr> <?php foreach ($result["DEVICE_LIST"] as $user) { if($user["DEPLID"]!='') { // formatting the date and time for display $chDate = $user["CHANGEDAT"]; $year = substr($chDate,0,4); $month = substr($chDate,4,2); $day = substr($chDate,6,2); $arrayDate = array($day,$month,$year); $formDate = implode("-",$arrayDate); $chTime = $user["CHANGETIM"]; $hours = substr($chTime,0,2);

$minutes = substr($chTime,2,2); $seconds = substr($chTime,4,2); $arrayTime = array($hours,$minutes,$seconds); $formTime = implode(":",$arrayTime); echo "<tr class=miBody><td class=1stCellBody><a href=javascript:popDeviceDetails('", $user["DEPLID"],"')>" , $user["DEPLID"] , "</a></td><td class=nextCellBody>",$user["USERNAME"],"</td><td class=nextCellBody>",$user["DEVICE_NAME"],"</td><td class=nextCellBody>", $formDate ,"</td><td class=nextCellBody>",$formTime ,"</td></tr>"; } } } else { // No, print long Version of last Error $sap->printStatus(); // or print your own error-message with the strings received from // $sap->getStatusText() or $sap->getStatusTextLong() } // Logoff/Close saprfc-connection LL/2001-08 $sap->logoff(); ?> </table> <table width="100%"> <tr> <td align="middle"> <input type="button" class="test" value="Home" name="_event_gotoMenu" onclick="javascript:history.back();"> </td> </td> </tr> </table> </body> <!-- Style sheet to format the dispaly. --> <style> tr.miHeader { background-color: #9caece;

color: black; font-family: "Arial, sans-serif"; font-size: 8pt; font-style: normal; font-weight: bold; } <!-- Style for table body --> tr.miBody { color: black; font-family: "Arial, sans-serif"; font-size: 8pt; font-style: normal; font-weight: normal; } td { color: black; font-family: "Arial, sans-serif"; font-size: 8pt; font-style: normal; } td.1stCellHeader { border-bottom: black 1px solid; border-left: black 1px solid; border-right: black 1px solid; border-top: black 1px solid; } td.nextCellHeader { border-bottom: black 1px solid; border-left: black 0px solid; border-right: black 1px solid; border-top: black 1px solid; } <!-- Style for first cell in table body --> td.1stCellBody {

border-bottom: black 1px solid; border-left: black 1px solid; border-right: black 1px solid; border-top: black 0px solid; } <!-- Style for next cell in table body --> td.nextCellBody { border-bottom: black 1px solid; border-left: black 0px solid; border-right: black 1px solid; border-top: black 0px solid; } input.test { background-color: #ededed; font-family: "Arial, sans-serif"; font-size: 8pt; font-style: normal; font-weight: normal; border : 1px solid black ; padding : 0; margin : 0; } </style> <!-- This java script function is to call the pop-up screen for displaying the particular device details. --> <script language="javascript"> function popDeviceDetails(deviceID) { var w =900 ; var h =500; var t = (screen.availHeight-h)/2 ; var l = (screen.availwidth-w)/2 ; var url ="popDeviceDetails.php?deviceID="+deviceID + "&serverName=<?= $_GET['serverName'] ?>" + "&sysNumber=<?= $_GET['sysNumber'] ?>" + "&sapClient=<?= $_GET['sapClient'] ?>" + "&sapUser=<?= $_GET['sapUser'] ?>" + "&userPassword=<?= $_GET['userPassword'] ?>"; var prop = "scrollbars=yes, resizable=no, menubar=no, location=no, status=no, directories=no, toolbar=no, height=" + h + ",width=" + w + ",top=" + t + ",left=" + l;

var win = window.open(url, deviceID , prop ); win.focus(); } </script> </html> You can see the list of Mobile Devices in this screen.From this you will have to click on the particular device id to view its details.

The popDeviceDetails.php file contains the script to display the details of the selected mobile device. <html> <head> <title>Device Details</title> </head> <body bgcolor="#ededed"> <?php require_once("saprfc.php"); // collect the particular device id selected. $deviceID = $_GET["deviceID"]; $sap = new saprfc(array( "logindata"=>array( "ASHOST"=> $_GET['serverName'] // application server ,"SYSNR"=> $_GET['sysNumber'] // system number ,"CLIENT"=> $_GET['sapClient'] // client ,"USER"=> $_GET['sapUser'] // user ,"PASSWD"=> $_GET['userPassword'] // password ) ,"show_errors"=>false // let class printout errors ,"debug"=>false)) ; //detailed debugging information // Call-Function for getting the details of the selected device. $result=$sap->callFunction("MEMGMT_DEVICE_GETDETAIL",

array( array("IMPORT","I_DEVICE_ID",$deviceID), // setting the import parameter array("TABLE","E_USERS",array()), // users on the client device array("TABLE","E_APPLICATIONS",array()), // details of applications installed on the device for all users. array("TABLE","E_CLIENTPROFILE",array()))); // Client device details. // Call successfull? if ($sap->getStatus() == SAPRFC_OK) { // Yes, print out the Userlist ?> <table width=100%> <tr align=center><td><h4>Device Details</h4></td></tr> </table> <!-- To display the users --> <h5>Users</h5> <table width=100%> <tr class=miHeader><td class="1stCellHeader">Device ID</td><td class="1stCellHeader">User Name</td></tr> <?php foreach ($result["E_USERS"] as $users) { echo "<tr class=miBody><td class=1stCellBody>",$deviceID ,"</td><td class=nextCellBody>",$users["USERNAME"],"</td></tr>"; } ?> </table> <!-- To display the installed applications details --> <h5>Installed Application Details</h5> <table width=100%>

<tr class=miHeader><td class="1stCellHeader">User Name</td><td class="1stCellHeader">Application Name</td><td class="1stCellHeader">Version</td></tr> <?php foreach ($result["E_APPLICATIONS"] as $applications) { echo "<tr class=miBody><td class=1stCellBody>", $applications["USERNAME"] ,"</td><td class=nextCellBody>", $applications["APPLNAME"],"</td><td class=nextCellBody>", $applications["VERSION"],"</td></tr>"; } ?> </table> <!-- To display the selected device's profile details --> <h5>Device Profile Details</h5> <table width=100%> <tr class=miHeader><td class="1stCellHeader">Attribute Name</td><td class="1stCellHeader">Attribute Value</td></tr> <?php foreach ($result["E_CLIENTPROFILE"] as $clientprofile) { echo "<tr class=miBody><td class=1stCellBody>", $clientprofile["ATTRIBUTE_NAME"] ,"</td><td class=nextCellBody>", $clientprofile["ATTRIBUTE_VALUE"],"</td></tr>"; } ?> </table> <?php } else { // No, print long Version of last Error

$sap->printStatus(); // or print your own error-message with the strings received from // $sap->getStatusText() or $sap->getStatusTextLong() } // Logoff/Close saprfc-connection LL/2001-08 $sap->logoff(); ?> <table width="100%"> <tr align="middle"> <td> <input class="test" type="button" value="Close" class="test" onClick="onExit();"> </td> </tr> </table> </form> </body> <!-- Style sheet to format the display --> <style> tr.miHeader { background-color: #9caece; color: black; font-family: "Arial, sans-serif"; font-size: 8pt; font-style: normal; font-weight: bold; } <!-- Style for table body --> tr.miBody { color: black; font-family: "Arial, sans-serif"; font-size: 8pt; font-style: normal;

font-weight: normal; } td { color: black; font-family: "Arial, sans-serif"; font-size: 8pt; font-style: normal; } td.1stCellHeader { border-bottom: black 1px solid; border-left: black 1px solid; border-right: black 1px solid; border-top: black 1px solid; } td.nextCellHeader { border-bottom: black 1px solid; border-left: black 0px solid; border-right: black 1px solid; border-top: black 1px solid; } <!-- Style for first cell in table body --> td.1stCellBody { border-bottom: black 1px solid; border-left: black 1px solid; border-right: black 1px solid; border-top: black 0px solid; } <!-- Style for next cell in table body --> td.nextCellBody { border-bottom: black 1px solid; border-left: black 0px solid; border-right: black 1px solid; border-top: black 0px solid; }

input.test { background-color: #ededed; font-family: "Arial, sans-serif"; font-size: 8pt; font-style: normal; font-weight: normal; border : 1px solid black ; padding : 0; margin : 0; } </style> <!-- java script code used to close the pop-up window --> <script language="javascript"> function onExit() { self.close(); } </script> </html> In this screen , you can see the , Users , Installed Applications and the device profile parameters such as OS used, Main Memory details, size of the data folder , JVM details , Client Users .etc .

Useful links

How to setup your system for SAPRFC? Apache HTTP Server PHP version 4 or 5 SAPRFC for PHP List of SAP / PHP Blogs

Summary
Hope you have enjoyed the Mix of PHP and SAP MI.

Author's Note
You will have to copy these initial.php , login.php and the popDeviceDetails.php files into the htdocs(by default all the php files and html files are stored in this directory) directory of the Apache HTTP Server installation. You can create your own folders to store these php files.But you have to properly change the value of DocumentRoot "(changed document path)" in the httpd.conf file located in the conf directory of Apache home folder. Kishor Gopinathan is an Enterprise Portal Consultant working for SAP Global Delivery, Bangalore.

Anda mungkin juga menyukai