function sap_controller() { global $mysqli, $session, $route; require "Modules/sap/sap_model.php"; $sap = new Sap($mysqli); if ($route->action == 'save') { $result = false; $data = null; if (isset($_POST['data'])) { $data = $_POST['data']; } if (!isset($_POST['data']) && isset($_GET['data'])) { $data = $_GET['data']; } //echo $data; if ($data && $data != null) { if ($session['write']) { $result = $sap->save($session['userid'], 1, $data); } else { $result = true; $data = preg_replace('/[^\\w\\s-.",:{}\\[\\]]/', '', $data); $_SESSION['sapdata'] = $data; } } } elseif ($route->action == 'get' && $session['write']) { $result = json_decode($sap->get($session['userid'], 1)); } else { if (!$route->action) { $route->action = 1; } $example = false; $datafromsession = false; if ($session['write']) { $data = $sap->get($session['userid'], 1); if (!$data && isset($_SESSION['sapdata'])) { $data = $_SESSION['sapdata']; $sap->save($session['userid'], 1, $data); } } else { if (isset($_SESSION['sapdata'])) { $data = $_SESSION['sapdata']; $datafromsession = true; } else { $example = true; $data = file_get_contents('Modules/sap/example.data'); } } $result = view("Modules/sap/sap_view.php", array('data' => $data, 'page' => $route->action, 'example' => $example, 'datafromsession' => $datafromsession)); } return array('content' => $result, 'fullwidth' => true); }
$obj = new T100Row(); foreach ($row as $field => $value) { $obj->{$field} = $value; } $arr[] = $obj; } return $arr; } public function select($fields, $table, $where = array(), $rowcount = 0, $offset = 0) { return $this->mapToObjects(parent::select($fields, $table, $where, $rowcount, $offset)); } } $sapConfig = (include __DIR__ . DIRECTORY_SEPARATOR . 'sap_config.php'); try { $sap = new Sap($sapConfig); /* * Option 1: Fetch RFC_READ_TABLE function into a previously * instatiated instance of 'MyRfcReadTable' class */ #$myRfcReadTable = new MyRfcReadTable('Argument #1'); #$sap->fetchFunction($myRfcReadTable); /* * Option 2: Fetch RFC_READ_TABLE function, returning a new instance * of 'MyRfcReadTable' class with constructor arguments */ $myRfcReadTable = $sap->fetchFunction('RFC_READ_TABLE', 'MyRfcReadTable', array('Argument #1')); /* Reads the selected fields for the first 5 rows of table 'T100' with constraint SPRSL = 'D' */ $data = $myRfcReadTable->select(array('SPRSL' => 'LANG', 'ARBGB' => 'MSGID', 'MSGNR', 'TEXT'), 'T100', array('SPRSL' => 'D'), 5); } catch (SapException $se) { echo 'SapException ::', $se->getMessageKey(), ':: ', $se->getMessage(), PHP_EOL;
<?php class PartnerRepository extends SapFunction { #My system specific function, don't bother const RFC_FUNCTION_NAME = 'Z_RFC_PARTNER_SELECT'; public function getName() { return self::RFC_FUNCTION_NAME; } public function getPartners($vatnum) { $result = $this->__invoke(array('I_PARS' => array('STCD2' => $vatnum))); return $result['ET_PARTNER_LIST']; } } $sapConfig = (include __DIR__ . DIRECTORY_SEPARATOR . 'sap_config.php'); $sap = new Sap($sapConfig); $partnerRepository = new PartnerRepository(); $sap->fetchFunction($partnerRepository); $partners = $partnerRepository->getPartners('123456789'); print_r($partners);
{ return $this->reason; } } $sapConfig = (include __DIR__ . DIRECTORY_SEPARATOR . 'sap_config.php'); if (isset($argc, $argv) && $argc > 2) { /* get username/password from command line arguments */ $username = $argv[1]; $password = $argv[2]; } else { /* use Sap logon parameters to test this example */ $username = $sapConfig['user']; $password = $sapConfig['passwd']; } try { $sap = new Sap($sapConfig); $loginCheckFunction = $sap->fetchFunction('SUSR_LOGIN_CHECK_RFC', 'SapRfcUserLogin'); } catch (SapException $se) { echo 'System not available (', $se->getMessageKey(), ')', PHP_EOL, $se->getMessage(), PHP_EOL; exit(1); } echo "Authenticating {$username}... "; switch ($loginCheckFunction->authenticate($username, $password)) { case $loginCheckFunction::SUCCESS: echo 'SUCCESS!', PHP_EOL; break; default: switch ($loginCheckFunction->getReason()) { case 'PASSWORD_EXPIRED': /* You could use the SUSR_USER_CHANGE_PASSWORD_RFC function for password change here */ /* You could use the SUSR_USER_CHANGE_PASSWORD_RFC function for password change here */