ce script php (SM21.php ) permet d'utiliser un navigateur pour consulter les logs SAP

 

<html>
<head>
<title>SM21 Controle des logs </title>
</head>
<body>

<?


if (trim($datedebut)=="")
{
?>

<form action="SM21.php" method="post">
<table align=center width="75%">
<tr><td>Date de début</td><td>:</td><td><input type="text" name="datedebut" value="<?
$currentdate = getdate(time()-86400);
$mois=$currentdate["mon"];
if ($mois<10)
{
$mois="0".$mois;

}
printf("%d%s%d",$currentdate["year"],$mois,$currentdate["mday"]);
?>"> </td></tr>
<tr><td>Heure de début</td><td>:</td><td><input type="text" name="heuredebut" value="000000" ></td></tr>
<tr><td>Date de fin</td><td>:</td><td><input type="text" name="datefin" value="<? print date("Ymd") ?>"></td></tr>
<tr><td>Heure de fin</td><td>:</td><td><input type="text" name="heurefin" value="<? print date("Hi")."00" ?>"></td></tr>
<tr><td><input name="" type="submit" value="Envoyer"> </td><td></td><td align=center><input name="" type="reset" value="vider"></td></tr>
</table>
</form>
<?
}
else
{
require_once("saprfc.php");

// Create saprfc-instance
$sap = new saprfc(array(
"logindata"=>array(
"ASHOST"=>"monserveur" // application server
,"SYSNR"=>"00" // system number
,"CLIENT"=>"007" // client
,"USER"=>"rfcuser" // user
,"PASSWD"=>"password" // password
,"LANG"=>"FR"
)
,"show_errors"=>false // let class printout errors
,"debug"=>false)) ; // detailed debugging information

if ($sap->getStatus() == SAPRFC_OK) {
$result=$sap->callFunction("SXMI_LOGON",
array(
array("IMPORT","EXTCOMPANY","mycompany"), // ce nom peut être n'importe quelle chaine
array("IMPORT","EXTPRODUCT","PHP"), // ce nom peut être n'importe quelle chaine
array("IMPORT","INTERFACE","XMB"),
array("IMPORT","VERSION","0.1"),
array("EXPORT","SESSIONID"),
array("EXPORT","RETURN")
)
);


if ($sap->getStatus() != SAPRFC_OK) {
$sap->printStatus();
echo "Erreur";
exit;
}

//FUNCTION SXMI_XMB_SYSLOG_READ.
//----------------------------------------------------------------------
////Lokale Schnittstelle:
// IMPORTING
// VALUE(SERVER_NAME) LIKE TBTCJOB-EXECSERVER DEFAULT SPACE
// VALUE(EXTERNAL_USER_NAME) LIKE TXMILOGRAW-EXTUSER
// VALUE(FROM_DATE) LIKE SY-DATUM DEFAULT SPACE
// VALUE(FROM_TIME) LIKE SY-UZEIT DEFAULT SPACE
// VALUE(TO_DATE) LIKE SY-DATUM DEFAULT SPACE
// VALUE(TO_TIME) LIKE SY-UZEIT DEFAULT SPACE
// VALUE(LIMIT_PAGES) TYPE I DEFAULT 3
// TABLES
// SYSLOG_TBL STRUCTURE BTCSYSLOG
// EXCEPTIONS
// NOT_LOGGED_ON
// EXTERNAL_USER_NAME_MISSING
// INVALID_DATE_TIME
// INVALID_SERVER_NAME
// CANT_LOG_ACTION
// PROBLEM_DETECTED
// INVALID_PAGES
//----------------------------------------------------------------------


$result=$sap->callFunction("SXMI_XMB_SYSLOG_READ",
array(
array("IMPORT","EXTERNAL_USER_NAME","BORCHERS"),
array("IMPORT","SERVER_NAME",""),
array("IMPORT","LIMIT_PAGES","999"),
array("IMPORT","FROM_DATE",$datedebut),
array("IMPORT","FROM_TIME",$heuredebut),
array("IMPORT","TO_DATE",$datefin),
array("IMPORT","TO_TIME",$heurefin),
array("TABLE","SYSLOG_TBL",array())
)
);

if ($sap->getStatus() == SAPRFC_OK) {
// Yes, print out the Userlist
print "Nombre de ligne : ".count($result["SYSLOG_TBL"])."<BR><br>";

echo "<table width=\"75%\" border=2>";

foreach ($result["SYSLOG_TBL"] as $log) {
$ligne=$log["LINE"];
$champs = explode("|",$ligne);
if (count($champs)==1)
{
$syslog= $champs[0];
if ($syslog==''){$syslog="&nbsp;";}
print "<tr><td colspan=\"6\">$syslog</td></tr>\n";
}
else
{

$heure= $champs[1];
if (trim($heure)==""){$heure="&nbsp;";}
$utilisateur= $champs[2];
if (trim($utilisateur)==''){$utilisateur="&nbsp;";}
$transaction= $champs[3];
if (trim($transaction)==''){$transaction="&nbsp;";}
$message= $champs[4];
if (trim($message)==''){$message="&nbsp;";}
$texte= $champs[5];
if (trim($texte)==''){$texte="&nbsp;";}
$date= $champs[6];
if (trim($date)==''){$date="&nbsp;";}

echo "<tr><td>$heure</td><td>$utilisateur</td><td>$transaction</td><td>$message</td><td>$texte</td><td>$date</td></tr>\n";
}

}

}
echo "</table>";
} else {
// No, print long Version of last Error
$sap->printStatus();
echo "Erreur";

}

$result=$sap->callFunction("SXMI_LOGOFF",array(array("IMPORT","INTERFACE","XMB")));
$sap->logoff();
}
?>
</body>
</html>