Voilà la pge ou je crée les fonctions
<?php
function login($user,$pwd,$host,$sn,$clnt) {
// créer l'instance SAPRFC.
$sap = new saprfc(array(
"logindata"=>array(
"ASHOST"=>$host
,"SYSNR"=>$sn // system number
,"CLIENT"=>$clnt // client
,"USER"=>$user // user
,"PASSWD"=>$pwd // password
)
,"show_errors"=>false // let class printout errors
,"debug"=>false)) ; // detailed debugging information
return $sap;
}
function logoff($sap) {
// Logoff/Fermer SAPRFC connection LL/2001-08
$sap->logoff();
}
function UserList($sap,$log,$rows) {
// appel fonction
$result=$sap->callFunction("SO_USER_LIST_READ",
array( array("IMPORT","USER_GENERIC_NAME","*"),
array("TABLE","USER_DISPLAY_TAB",array())
));
// appel réussi
if ($sap->getStatus() == SAPRFC_OK) {
// si oui, afficher la liste des users
foreach ($result["USER_DISPLAY_TAB"] as $user) {
$user_status = GetStatus($sap,$user["SAPNAM"]);
$i = 0;
//S$listing = "<tr onMouseOver=\"this.className='highlight'\" onMouseOut=\"this.className='normal'\"><td class=\"tb-data\"><a href=\"index.php?log=".$log."&rows=".$rows."&user=".$user["SAPNAM"]."\">".$user["SAPNAM"]."</a></td><td class=\"tb-data\">".$user_status."</td><td class=\"tb-data\">".$user_valid."</td></tr>";
$listing = "<tr onMouseOver=\"this.className='highlight'\" onMouseOut=\"this.className='normal'\"><td class=\"tb-data\"><a href=\"utilisateur.php?log=".$log."&rows=".$rows."&user=".$user["SAPNAM"]."\">".$user["SAPNAM"]."</a></td><td class=\"tb-data\">".$user_status."</td></td></td></tr>";
//echo "<tr><td>", $user["USRNAM"], "</td><td>";
echo $listing;
$i++;
}
} else {
// sinon afficher la liste des erreurs
$sap->printStatus();
}
}
function ShowActionLog() {
$filename = "action.log";
$fp = fopen($filename, "r");
$contents = fread($fp, filesize($filename));
fclose($fp);
// maintenant remplacer les étiquettes <br>
$contents = str_replace("<br>", "\n", $contents);
return $contents;
}
function PrintActionLog() {
$filename = "action.log";
$fp = fopen($filename, "r");
$contents = fread($fp, filesize($filename));
fclose($fp);
return $contents;
}
function WriteActionLog($line) {
$filename = "action.log";
$fp = fopen($filename, "a");
$string = date('l dS \of F Y h:i:s A')." - ".$line."<br>";
$write = fputs($fp, $string);
fclose($fp);
}
function DeleteActionLog($l_user) {
// D'abord, faire une sauvegarde du fichier
$backup = PrintActionLog();
$backup .= date('l dS \of F Y h:i:s A')." - Log cleared by ".$l_user."<br>";
$filename = "action.log.".time();
$fp = fopen($filename, "w");
$write = fputs($fp, $backup);
fclose($fp);
$filename = "action.log";
$fp = fopen($filename, "w");
$string = date('l dS \of F Y h:i:s A')." - Log cleared by ".$l_user."<br>";
$write = fputs($fp, $string);
fclose($fp);
}
function ULUser($sap,$uid,$action,$l_user) {
$value = "";
$uid = strtoupper($uid);
switch ($action) {
case "lock":
$result=$sap->callFunction("BAPI_USER_LOCK",
array( array("IMPORT","USERNAME",$uid),
array("TABLE","RETURN",array())
));
// appel réussi
if ($sap->getStatus() == SAPRFC_OK) {
// si oui , donner la valeur
$value = $uid." a été bloqué par ".$l_user;
} else {
// sinon afficher la liste des erreurs
$sap->printStatus();
}
break;
case "unlock":
$result=$sap->callFunction("BAPI_USER_UNLOCK",
array( array("IMPORT","USERNAME",$uid),
array("TABLE","RETURN",array())
));
// / appel réussi
if ($sap->getStatus() == SAPRFC_OK) {
// si oui , donner la valeur
$value = $uid." a été debloqué par ".$l_user;
} else {
// sinon afficher la liste des erreurs
$sap->printStatus();
}
break;
}
// Remettre la transaction
$result=$sap->callFunction("BAPI_TRANSACTION_COMMIT");
WriteActionLog($value);
}
function GetStatusValue($sap,$uid) {
$value = "";
$uid = strtoupper($uid);
$result=$sap->callFunction("Z_GET_LOCKSTATUS",
array( array("IMPORT","USERNAME",$uid),
array("EXPORT","STATUS",array())
));
// appel réussi
if ($sap->getStatus() == SAPRFC_OK) {
// si oui , donner la valeur
if ($result["STATUS"] == "0" ) {
$value = "unlocked";
} else {
$value = "locked";
}
} else {
// sinon afficher la liste des erreurs
$sap->printStatus();
}
return $value;
}
function GetStatus($sap,$uid) {
$value = "";
$input = GetStatusValue($sap,$uid);
if ($input == "unlocked" ) {
$value = "<img src=\"images/s_S_LOOP.gif\" align=\"middle\" border=\"0\" alt=\"".$input."\">";
} else {
$value = "<img src=\"images/s_S_LOCL.gif\" border=\"0\" alt=\"".$input."\">";
}
return $value;
}
function GetValid($sap,$uid) {
$value = "";
$result = GetUserLogonDetails($sap,$uid);
$input = $result["GLTGB"];
// si oui , donner la valeur
if ( strtotime("now") < strtotime($input) or $input == "00000000" ) {
$value = "<img src=\"images/s_S_OKAY.gif\" border=\"0\" alt=\"".$input."\">";
} else {
$value = "<img src=\"images/s_S_NONO.gif\" border=\"0\" alt=\"".$input."\">";
}
return $value;
}
function GetUserAddressDetails($sap,$uid) {
$value = "";
$uid = strtoupper($uid);
$result=$sap->callFunction("BAPI_USER_GET_DETAIL",
array( array("IMPORT","USERNAME",$uid),
array("EXPORT","ADDRESS",array())
));
// Call successful?
if ($sap->getStatus() == SAPRFC_OK) {
// Yes, then get value
$value = $result["ADDRESS"];
} else {
// No, print long version of last error
$sap->printStatus();
}
return $value;;
}
function GetUserLogonDetails($sap,$uid) {
$value = "";
$uid = strtoupper($uid);
$result=$sap->callFunction("BAPI_USER_GET_DETAIL",
array( array("IMPORT","USERNAME",$uid),
array("EXPORT","LOGONDATA",array())
));
// appel réussi
if ($sap->getStatus() == SAPRFC_OK) {
// / appel réussi
$value = $result["LOGONDATA"];
} else {
//sinon afficher la liste des erreurs
$sap->printStatus();
}
return $value;
}
function SaveUser($sap,$uid,$gltgb,$l_user) {
$value = "";
$uid = strtoupper($uid);
$logondata["GLTGB"] = $gltgb;
$logondatax["GLTGB"] = "X";
$result=$sap->callFunction("BAPI_USER_CHANGE",
array( array("IMPORT","USERNAME",$uid),
array("IMPORT","LOGONDATA",$logondata),
array("IMPORT","LOGONDATAX",$logondatax)
));
// appel réussi
if ($sap->getStatus() == SAPRFC_OK) {
// / appel réussi
$value = $uid." a été changé par ".$l_user;
} else {
// sinon afficher la liste des erreurs
$sap->printStatus();
}
// remettre la transaction
$result=$sap->callFunction("BAPI_TRANSACTION_COMMIT");
WriteActionLog($value);
}
?>
el voilà ou j'appelle la fonction
<?php
// Session init
session_start();
// La bibliothèque SAPRFC et la bibliothèque personnalisée(SU01
include("saprfc.php");
include("su01.php");
// vérifier si l'action est créée dans l'URL
if (array_key_exists("action",$_GET)) {
$action = $_GET["action"];
// vérifier si l'utilisateur a choisit de se déconnecter
if ( $action == "quitter" ) {
session_unset();
session_destroy();
}
}
// vérifier si les variables sont affectés.
if(!isset($_SESSION["l_user"]) || !isset($_SESSION["l_pwd"])) {
unset($_SESSION["l_user"]);
unset($_SESSION["l_pwd"]);
header("Location: login.php");
} else {
// Initialiser log variable
$log = "sl";
if (array_key_exists("log",$_GET)) {
$log = $_GET["log"];
} else if (array_key_exists("log",$_POST)) {
$log = $_POST["log"];
}
$i = 0;
$rows = $i;
if (array_key_exists("rows",$_GET)) {
$rows = $_GET["rows"];
} else if (array_key_exists("rows",$_POST)) {
$rows = $_POST["rows"];
$i++;
}
}
// manitenant se loguer sur SAP system
$sap = login($_SESSION["l_user"],$_SESSION["l_pwd"],$_SESSION["l_ashost"],$_SESSION["l_sysnr"],$_SESSION["l_client"]);
// vérifier si l'action vérifier si l'action est rapprochée
// si( $action == "id" ) {
// DeleteActionLog($_SESSION["l_user"]);
// }
// vérifier si le nom d'utilisateur a été cliqué et récupérer ensuite des détails d'utilisateur
$userid = "";
$useraddress = "";
$userlogon = "";
// Vérifier pour l'URL visible et ensuite pour les variables
if (array_key_exists("user",$_GET)) {
$userid = $_GET["user"];
} else if (array_key_exists("user",$_POST)) {
$userid = $_POST["user"];
}
if ($userid != "") {
//Vérifiez si l'action a été cliquée
$action = "";
// Vérifiez pour l'URL visible, ensuite pour les variables
if (array_key_exists("action",$_GET)) {
$action = $_GET["action"];
} else if (array_key_exists("action",$_POST)) {
$action = $_POST["action"];
}
if ($action != "") {
if ( $action == "lock" or $action == "unlock" ) {
ULUser($sap,$userid,$action,$_SESSION["l_user"]);
}
if ( $action == "sauvegarder" ) {
SaveUser($sap,$userid,$_POST["u_gltgb"],$_SESSION["l_user"]);
}
}
// Obtenir maintenant des données d'utilisateur
$useraddress = GetUserAddressDetails($sap,$userid);
$userlogon = GetUserLogonDetails($sap,$userid);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>SU01 Transaction</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="Mot de Passe" content="su01,user administration,user,administration" />
<meta name="Description" content="SAP su01 transaction support in PHP" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<link rel="stylesheet" type="text/css" href="styles/su01.css" />
<script language="JavaScript1.2" type="text/javascript">
function SaveUser() {
userdetails.action.value = "save";
// Uncomment, remove the // from the next line to see how to debug JavaScript
//alert("User:" + userdetails.user.value);
userdetails.submit();
}
function ChangeRows(rows) {
userdetails.rows.value = rows;
userdetails.submit();
}
function LockUnlockUser(whatAction) {
userdetails.action.value = whatAction;
userdetails.submit();
}
</script>
</head>
<body onLoad="goforit()">
<table border="0" cellSpacing="2" cellPadding="2">
<tr>
<td width="340px">
<div class="userBody">
<span id="menu">
<a href="index.php"><img src="images/s_B_REFR.gif" border="0">Actualiser</a>    
<img src="images/s_POSITI.gif" border="0"><?php echo $_SESSION["l_user"]; ?>    
<a href="index.php?action=quitter"><img src="images/s_F_CANC.gif" border="0">se déconnecter</a>
</span>
</div>
</td>
<td width="500px">
<div class="userBody">
<span id="clock"></span>
</div>
</td>
</tr><tr>
<td valign="top" width="500px">
<table>
<tr><td align="center" class="tb-header">ID</td>
<td align="center" class="tb-header">status</td>
<td align="center" class="tb-header">Valid</td>
</tr>
<?php echo UserList($sap,$log,$rows); ?>
</table>
</td>
<td valign="top" width="500px">
<div class="userDetail">
<form id="userdetails" name="userdetails" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
</td>
</tr>
</table>
</form>
</div>
</td>
</tr>
<
<?php
logoff($sap);
?>
</body>
</html>