ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
SAP.php
Go to the documentation of this file.
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3 
31 require_once 'Auth/Container.php';
35 require_once 'PEAR.php';
36 
55 
56  // {{{ properties
57 
61  var $options = array(
62  'CLIENT' => '000',
63  'LANG' => 'EN',
64  'GETSSO2' => true,
65  );
66 
67  // }}}
68  // {{{ Auth_Container_SAP()
69 
95  {
96  $saprfc_loaded = PEAR::loadExtension('saprfc');
97  if (!$saprfc_loaded) {
98  return PEAR::raiseError('Cannot use SAP authentication, '
99  .'SAPRFC extension not loaded!');
100  }
101  if (empty($options['R3NAME']) && empty($options['ASHOST'])) {
102  return PEAR::raiseError('R3NAME or ASHOST required for authentication');
103  }
104  $this->options = array_merge($this->options, $options);
105  }
106 
107  // }}}
108  // {{{ fetchData()
109 
117  function fetchData($username, $password)
118  {
119  $this->log('Auth_Container_SAP::fetchData() called.', AUTH_LOG_DEBUG);
120  $connection_options = $this->options;
121  $connection_options['USER'] = $username;
122  $connection_options['PASSWD'] = $password;
123  $rfc = saprfc_open($connection_options);
124  if (!$rfc) {
125  $message = "Couldn't connect to the SAP system.";
126  $error = $this->getError();
127  if ($error['message']) {
128  $message .= ': ' . $error['message'];
129  }
130  PEAR::raiseError($message, null, null, null, @$erorr['all']);
131  return false;
132  } else {
133  if (!empty($this->options['GETSSO2'])) {
134  $this->log('Attempting to retrieve SSO2 ticket.', AUTH_LOG_DEBUG);
135  if ($ticket = @saprfc_get_ticket($rfc)) {
136  $this->options['MYSAPSSO2'] = $ticket;
137  unset($this->options['GETSSO2']);
138  $this->_auth_obj->setAuthData('sap', $this->options);
139  } else {
140  PEAR::raiseError("SSO ticket retrieval failed");
141  }
142  }
143  @saprfc_close($rfc);
144  return true;
145  }
146 
147  }
148 
149  // }}}
150  // {{{ getError()
151 
158  function getError()
159  {
160 
161  $error = array();
162  $sap_error = saprfc_error();
163  if (empty($err)) {
164  return $error;
165  }
166  $err = explode("n", $sap_error);
167  foreach ($err AS $line) {
168  $item = split(':', $line);
169  $error[strtolower(trim($item[0]))] = trim($item[1]);
170  }
171  $error['all'] = $sap_error;
172  return $error;
173  }
174 
175  // }}}
176 
177 }
178 
179 ?>