A voir également:
- Pb php lié au système SAP
- Restauration systeme - Guide
- Easy php - Télécharger - Divers Web & Internet
- Comment refaire le système d'un ordinateur - Guide
- Cloner disque systeme - Guide
- L'administrateur système a configuré la politique de votre système pour interdire cette installation ✓ - Forum Logiciels
3 réponses
voilà mon code
<?php
function login($user,$pwd,$host,$sn,$clnt) {
// créer l'instance SAPRFC.
$sap = new saprfc(array(
"logindata"=>array(
"ASHOST"=>$host // application server
,"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"]);
$user_valid = GetValid($sap,$user["SAPNAM"]);
$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>";
echo $listing;
}
} 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\" 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);
}
?>
<?php
function login($user,$pwd,$host,$sn,$clnt) {
// créer l'instance SAPRFC.
$sap = new saprfc(array(
"logindata"=>array(
"ASHOST"=>$host // application server
,"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"]);
$user_valid = GetValid($sap,$user["SAPNAM"]);
$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>";
echo $listing;
}
} 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\" 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);
}
?>