Пример #1
0
 function flash()
 {
     $html = '<div id="flash-message">';
     $flash = api_session::get_flash();
     if (isset($flash['error'])) {
         $html .= "<div id='error'><ul>";
         foreach ($flash['error'] as $msg) {
             $html .= "<li>{$msg}</li>";
         }
         $html .= "</ul></div>";
     }
     if (isset($flash['warning'])) {
         $html .= "<div id='warning'><ul>";
         foreach ($flash['warning'] as $msg) {
             $html .= "<li>{$msg}</li>";
         }
         $html .= "</ul></div>";
     }
     if (isset($flash['info'])) {
         $html .= "<div id='info'><ul>";
         foreach ($flash['info'] as $msg) {
             $html .= "<li>{$msg}</li>";
         }
         $html .= "</ul></div>";
     }
     return $html . '</div>';
 }
Пример #2
0
 static function getInstance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Пример #3
0
 /**
  * Internal method for posting the invocation to the Intacct XML Gateway
  *
  * @param String      $xml        the XML request document
  * @param api_session $session    an api_session instance with an active connection
  * @param string      $dtdVersion Either "2.1" or "3.0".  Defaults to "3.0"
  * @param boolean     $multiFunc  whether or not this invocation calls multiple methods.  Default is false
  *
  * @throws Exception
  * @return String the XML response document
  */
 private static function post($xml, api_session $session, $dtdVersion = "3.0", $multiFunc = false)
 {
     $sessionId = $session->sessionId;
     $endPoint = $session->endPoint;
     $senderId = $session->senderId;
     $senderPassword = $session->senderPassword;
     $transaction = $session->transaction ? 'true' : 'false';
     $templateHead = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<request>\n    <control>\n        <senderid>{$senderId}</senderid>\n        <password>{$senderPassword}</password>\n        <controlid>foobar</controlid>\n        <uniqueid>false</uniqueid>\n        <dtdversion>{$dtdVersion}</dtdversion>\n        {%validate}\n        <includewhitespace>false</includewhitespace>\n    </control>\n    <operation transaction='{$transaction}'>\n        <authentication>\n            <sessionid>{$sessionId}</sessionid>\n        </authentication>";
     $contentHead = "<content>\n            <function controlid=\"foobar\">";
     $contentFoot = "</function>\n        </content>";
     $templateFoot = "</operation>\n</request>";
     if (is_null($session->getResponseValidation())) {
         $templateHead = str_replace("{%validate}", '', $templateHead);
     } else {
         $templateHead = str_replace("{%validate}", '<validate>' . $session->getResponseValidation() . '</validate>', $templateHead);
     }
     if ($multiFunc) {
         $xml = $templateHead . $xml . $templateFoot;
     } else {
         $xml = $templateHead . $contentHead . $xml . $contentFoot . $templateFoot;
     }
     if (self::$dryRun == true) {
         self::$lastRequest = $xml;
         return null;
     }
     $count = 0;
     // retry five times on too many operations
     $res = "";
     while (true) {
         try {
             $res = api_post::execute($xml, $endPoint);
             api_post::validateResponse($res);
             break;
         } catch (Exception $ex) {
             if (strpos($ex->getMessage(), "too many operations") !== false || strpos($ex->getMessage(), "HTTP Response Code not 200") !== false) {
                 $count++;
                 if ($count >= 5) {
                     throw new Exception($ex);
                 }
             } else {
                 throw new Exception($ex);
             }
         }
     }
     return $res;
 }
Пример #4
0
 public function checkAuth()
 {
     //if (!empty($_SESSION[$this->config->appname]['user']['id'])) {
     if (api_session::get('user')) {
         //api_log::log(api_log::INFO, 'Session exists');
         //echo "Session exists";
         return true;
     }
     return false;
 }
Пример #5
0
 public static function start($base_path = null)
 {
     if (self::$initialized) {
         return;
     }
     /* project root
      ********************/
     //define( 'PROJECT_DIR', dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR);
     define('PROJECT_DIR', $base_path);
     define('API_DIR', PROJECT_DIR . 'inc' . DIRECTORY_SEPARATOR);
     define('APP_DIR', PROJECT_DIR . 'app' . DIRECTORY_SEPARATOR);
     define('VENDOR_DIR', PROJECT_DIR . 'vendor');
     define('SF_EVENT_DIR', VENDOR_DIR . DIRECTORY_SEPARATOR . 'sfEvent' . DIRECTORY_SEPARATOR);
     define('LOCAL_API_DIR', PROJECT_DIR . 'localinc' . DIRECTORY_SEPARATOR);
     $root = dirname(dirname(__FILE__));
     set_include_path(API_DIR . PATH_SEPARATOR . APP_DIR . PATH_SEPARATOR . VENDOR_DIR . PATH_SEPARATOR . SF_EVENT_DIR . PATH_SEPARATOR . LOCAL_API_DIR . PATH_SEPARATOR . get_include_path());
     include 'autoload.php';
     // Start sessions
     $sessions = api_session::getInstance();
     // Construct URL for Web home (root of current host)
     $hostname = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
     $hostinfo = self::getHostConfig($hostname);
     $schema = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https' : 'http';
     $reqHostPath = '/';
     if ($hostname != '') {
         $reqHostPath = $schema . '://' . $hostname;
         if (is_null($hostinfo)) {
             $reqHostPath .= '/';
         } else {
             $reqHostPath .= $hostinfo['path'];
         }
     }
     define('API_HOST', $schema . '://' . $hostname . '/');
     define('API_WEBROOT', $reqHostPath);
     define('API_MOUNTPATH', $hostinfo['path']);
     require_once PROJECT_DIR . "config/commandmap.php";
     if (!function_exists('e')) {
         /**
          * This function is dynamically redefinable.
          * @see $GLOBALS['_global_function_callback_e']
          */
         function e($args)
         {
             $args = func_get_args();
             return call_user_func_array($GLOBALS['_global_function_callback_e'], $args);
         }
         if (!isset($GLOBALS['_global_function_callback_e'])) {
             $GLOBALS['_global_function_callback_e'] = NULL;
         }
     }
     if (!function_exists('__')) {
         /**
          * This function is dynamically redefinable.
          * @see $GLOBALS['_global_function_callback___']
          */
         function __($args)
         {
             $args = func_get_args();
             return call_user_func_array($GLOBALS['_global_function_callback___'], $args);
         }
         if (!isset($GLOBALS['_global_function_callback___'])) {
             $GLOBALS['_global_function_callback___'] = NULL;
         }
     }
     if (!function_exists('t')) {
         /**
          * This function is dynamically redefinable.
          * @see $GLOBALS['_global_function_callback_t']
          */
         function t($args)
         {
             $args = func_get_args();
             return call_user_func_array($GLOBALS['_global_function_callback_t'], $args);
         }
         if (!isset($GLOBALS['_global_function_callback_t'])) {
             $GLOBALS['_global_function_callback_t'] = NULL;
         }
     }
     if (!function_exists('url')) {
         /**
          * This function is dynamically redefinable.
          * @see $GLOBALS['_global_function_callback_url']
          */
         function url($args)
         {
             $args = func_get_args();
             return call_user_func_array($GLOBALS['_global_function_callback_url'], $args);
         }
         if (!isset($GLOBALS['_global_function_callback_url'])) {
             $GLOBALS['_global_function_callback_url'] = NULL;
         }
     }
     self::$initialized = true;
 }
Пример #6
0
 /**
  * Generate an authentication response
  *
  * @param 
  */
 function openid_provider_authentication_response($request)
 {
     //global $user;
     // If the user is not yet logged in, redirect to the login page before continuing.
     $user = api_session::get('user');
     if (!$user) {
         //$_SESSION['openid_provider']['request'] = $request;
         // Set in endpoint method
         // api_session::set('openid_request', $request);
         $this->openid_redirect_http('/login');
     }
     // Determine the realm (openid.trust_root in 1.x)
     $realm = empty($request['openid.realm']) ? $request['openid.trust_root'] : $request['openid.realm'];
     // Check if realm is OK?
     if (!$this->check_realm($realm)) {
         throw new Exception("Realm not ok");
         $this->openid_redirect_http('/error');
     }
     // Check for a directed identity request.
     if ($request['openid.identity'] == 'http://specs.openid.net/auth/2.0/identifier_select') {
         //$identity = url(openid_provider_user_url($user->uid), array('absolute' => TRUE));
         $identity = 'http://local.openid_provider/user/' . $user['id'] . '/identity';
     } else {
         $identity = $request['openid.identity'];
         if ($identity != url(openid_provider_user_url($user['id']), array('absolute' => TRUE))) {
             $response = openid_provider_authentication_error($request['openid.mode']);
             openid_redirect($request['openid.return_to'], $response);
         }
     }
     $response = array('openid.ns' => OPENID_NS_2_0, 'openid.mode' => 'id_res', 'openid.op_endpoint' => 'http://local.openid_provider/openid/provider', 'openid.identity' => $identity, 'openid.claimed_id' => $identity, 'openid.return_to' => $request['openid.return_to'], 'openid.response_nonce' => $this->openid_provider_nonce(), 'openid.assoc_handle' => $request['openid.assoc_handle'], 'openid.sreg.nickname' => $user['username'], 'openid.sreg.email' => $user['email']);
     // Is the RP requesting Immediate or Indirect mode?
     if ($request['openid.mode'] == 'checkid_immediate') {
         // TODO
     }
     $parts = parse_url($request['openid.return_to']);
     if (isset($parts['query'])) {
         $query = $parts['query'];
         $q = $this->openid_get_params($query);
         foreach ($q as $key => $val) {
             $response[$key] = $val;
         }
     }
     // calling hook_openid so we can do response parsing and send any pertinent data back to the user
     // TODO ???? //$response = array_merge($response, module_invoke_all('openid_provider', 'response', $response, $request));
     // Skipping trust step, if the realm is ok then its trusted.
     $rp = $this->openid_provider_rp_load($user['id'], $realm);
     if (empty($rp)) {
         echo "Create rp";
         $this->openid_provider_rp_save($user['id'], $realm, TRUE);
     }
     $rp = $this->openid_provider_rp_load($user['id'], $realm);
     echo "\nrp: ";
     print_r($rp);
     echo "\n";
     if ($rp) {
         //$rp->auto_release) {
         $response = $this->openid_provider_sign($response);
         //$this->openid_provider_rp_save($user['id'], $realm, TRUE);
         return $this->openid_redirect_http($response['openid.return_to'], $response);
     } else {
         // Unset global post variable, otherwise FAPI will assume it has been
         // submitted against openid_provider_form.
         unset($_POST);
         //return drupal_get_form('openid_provider_form', $response, $realm);
         //$this->openid_redirect_http('/trust');
         throw new Exception("Association error");
     }
 }