Esempio n. 1
0
 function ValidateEmailHost($email, $hosts = 0)
 {
     if (!$this->ValidateEmailAddress($email)) {
         return 0;
     }
     $user = strtok($email, "@");
     $domain = strtok("");
     if (GetMXRR($domain, &$hosts, &$weights)) {
         $mxhosts = array();
         for ($host = 0; $host < count($hosts); $host++) {
             $mxhosts[$weights[$host]] = $hosts[$host];
         }
         KSort($mxhosts);
         for (Reset($mxhosts), $host = 0; $host < count($mxhosts); Next($mxhosts), $host++) {
             $hosts[$host] = $mxhosts[Key($mxhosts)];
         }
     } else {
         $hosts = array();
         if (strcmp(@gethostbyname($domain), $domain) != 0) {
             $hosts[] = $domain;
         }
     }
     return count($hosts) != 0;
 }
Esempio n. 2
0
 function Connect($domain = "")
 {
     if (strcmp($this->state, "Disconnected")) {
         $this->error = "connection is already established";
         return 0;
     }
     $this->disconnected_error = 0;
     $this->error = $error = "";
     $this->esmtp_host = "";
     $this->esmtp_extensions = array();
     $hosts = array();
     if ($this->direct_delivery) {
         if (strlen($domain) == 0) {
             return 1;
         }
         $hosts = $weights = $mxhosts = array();
         $getmxrr = $this->getmxrr;
         if (function_exists($getmxrr) && $getmxrr($domain, $hosts, $weights)) {
             for ($host = 0; $host < count($hosts); $host++) {
                 $mxhosts[$weights[$host]] = $hosts[$host];
             }
             KSort($mxhosts);
             for (Reset($mxhosts), $host = 0; $host < count($mxhosts); Next($mxhosts), $host++) {
                 $hosts[$host] = $mxhosts[Key($mxhosts)];
             }
         } else {
             if (strcmp(@gethostbyname($domain), $domain) != 0) {
                 $hosts[] = $domain;
             }
         }
     } else {
         if (strlen($this->host_name)) {
             $hosts[] = $this->host_name;
         }
         if (strlen($this->pop3_auth_host)) {
             $user = $this->user;
             if (strlen($user) == 0) {
                 $this->error = "it was not specified the POP3 authentication user";
                 return 0;
             }
             $password = $this->password;
             if (strlen($password) == 0) {
                 $this->error = "it was not specified the POP3 authentication password";
                 return 0;
             }
             $domain = $this->pop3_auth_host;
             $this->error = $this->ConnectToHost($domain, $this->pop3_auth_port, "Resolving POP3 authentication host \"" . $domain . "\"...");
             if (strlen($this->error)) {
                 return 0;
             }
             if (strlen($response = $this->GetLine()) == 0) {
                 return 0;
             }
             if (strcmp($this->Tokenize($response, " "), "+OK")) {
                 $this->error = "POP3 authentication server greeting was not found";
                 return 0;
             }
             if (!$this->PutLine("USER " . $this->user) || strlen($response = $this->GetLine()) == 0) {
                 return 0;
             }
             if (strcmp($this->Tokenize($response, " "), "+OK")) {
                 $this->error = "POP3 authentication user was not accepted: " . $this->Tokenize("\r\n");
                 return 0;
             }
             if (!$this->PutLine("PASS " . $password) || strlen($response = $this->GetLine()) == 0) {
                 return 0;
             }
             if (strcmp($this->Tokenize($response, " "), "+OK")) {
                 $this->error = "POP3 authentication password was not accepted: " . $this->Tokenize("\r\n");
                 return 0;
             }
             fclose($this->connection);
             $this->connection = 0;
         }
     }
     if (count($hosts) == 0) {
         $this->error = "could not determine the SMTP to connect";
         return 0;
     }
     for ($host = 0, $error = "not connected"; strlen($error) && $host < count($hosts); $host++) {
         $domain = $hosts[$host];
         $error = $this->ConnectToHost($domain, $this->host_port, "Resolving SMTP server domain \"{$domain}\"...");
     }
     if (strlen($error)) {
         $this->error = $error;
         return 0;
     }
     $timeout = $this->data_timeout ? $this->data_timeout : $this->timeout;
     if ($timeout && function_exists("socket_set_timeout")) {
         socket_set_timeout($this->connection, $timeout, 0);
     }
     if ($this->debug) {
         $this->OutputDebug("Connected to SMTP server \"" . $domain . "\".");
     }
     if (!strcmp($localhost = $this->localhost, "") && !strcmp($localhost = getenv("SERVER_NAME"), "") && !strcmp($localhost = getenv("HOST"), "")) {
         $localhost = "localhost";
     }
     $success = 0;
     if ($this->VerifyResultLines("220", $responses) > 0) {
         $success = $this->StartSMTP($localhost);
         if ($this->start_tls) {
             if (!isset($this->esmtp_extensions["STARTTLS"])) {
                 $this->error = "server does not support starting TLS";
                 $success = 0;
             } elseif (!function_exists('stream_socket_enable_crypto')) {
                 $this->error = "this PHP installation or version does not support starting TLS";
                 $success = 0;
             } elseif ($success = $this->PutLine('STARTTLS') && $this->VerifyResultLines('220', $responses) > 0) {
                 $this->OutputDebug('Starting TLS cryptograpic protocol');
                 if (!($success = stream_socket_enable_crypto($this->connection, 1, STREAM_CRYPTO_METHOD_TLS_CLIENT))) {
                     $this->error = 'could not start TLS connection encryption protocol';
                 } else {
                     $this->OutputDebug('TLS started');
                     $success = $this->StartSMTP($localhost);
                 }
             }
         }
         if ($success && strlen($this->user) && strlen($this->pop3_auth_host) == 0) {
             if (!isset($this->esmtp_extensions["AUTH"])) {
                 $this->error = "server does not require authentication";
                 if (isset($this->esmtp_extensions["STARTTLS"])) {
                     $this->error .= ', it probably requires starting TLS';
                 }
                 $success = 0;
             } else {
                 if (strlen($this->authentication_mechanism)) {
                     $mechanisms = array($this->authentication_mechanism);
                 } else {
                     $mechanisms = array();
                     for ($authentication = $this->Tokenize($this->esmtp_extensions["AUTH"], " "); strlen($authentication); $authentication = $this->Tokenize(" ")) {
                         $mechanisms[] = $authentication;
                     }
                 }
                 $credentials = array("user" => $this->user, "password" => $this->password);
                 if (strlen($this->realm)) {
                     $credentials["realm"] = $this->realm;
                 }
                 if (strlen($this->workstation)) {
                     $credentials["workstation"] = $this->workstation;
                 }
                 $success = $this->SASLAuthenticate($mechanisms, $credentials, $authenticated, $mechanism);
                 if (!$success && !strcmp($mechanism, "PLAIN")) {
                     /*
                      * Author:  Russell Robinson, 25 May 2003, http://www.tectite.com/
                      * Purpose: Try various AUTH PLAIN authentication methods.
                      */
                     $mechanisms = array("PLAIN");
                     $credentials = array("user" => $this->user, "password" => $this->password);
                     if (strlen($this->realm)) {
                         /*
                          * According to: http://www.sendmail.org/~ca/email/authrealms.html#authpwcheck_method
                          * some sendmails won't accept the realm, so try again without it
                          */
                         $success = $this->SASLAuthenticate($mechanisms, $credentials, $authenticated, $mechanism);
                     }
                     if (!$success) {
                         /*
                          * It was seen an EXIM configuration like this:
                          * user^password^unused
                          */
                         $credentials["mode"] = SASL_PLAIN_EXIM_DOCUMENTATION_MODE;
                         $success = $this->SASLAuthenticate($mechanisms, $credentials, $authenticated, $mechanism);
                     }
                     if (!$success) {
                         /*
                          * ... though: http://exim.work.de/exim-html-3.20/doc/html/spec_36.html
                          * specifies: ^user^password
                          */
                         $credentials["mode"] = SASL_PLAIN_EXIM_MODE;
                         $success = $this->SASLAuthenticate($mechanisms, $credentials, $authenticated, $mechanism);
                     }
                 }
                 if ($success && strlen($mechanism) == 0) {
                     $this->error = "it is not supported any of the authentication mechanisms required by the server";
                     $success = 0;
                 }
             }
         }
     }
     if ($success) {
         $this->state = "Connected";
         $this->connected_domain = $domain;
     } else {
         fclose($this->connection);
         $this->connection = 0;
     }
     return $success;
 }
 function SendAPIRequest($url, $method, $parameters, $oauth, $options, &$response)
 {
     $this->response_status = 0;
     $http = new http_class();
     $http->debug = $this->debug && $this->debug_http;
     $http->log_debug = true;
     $http->sasl_authenticate = 0;
     $http->user_agent = $this->oauth_user_agent;
     if ($this->debug) {
         $this->OutputDebug('Accessing the ' . $options['Resource'] . ' at ' . $url);
     }
     $arguments = array();
     $method = strtoupper($method);
     $authorization = '';
     $type = isset($options['RequestContentType']) ? strtolower(trim(strtok($options['RequestContentType'], ';'))) : 'application/x-www-form-urlencoded';
     if (isset($oauth)) {
         $values = array('oauth_consumer_key' => $this->client_id, 'oauth_nonce' => md5(uniqid(rand(), true)), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_timestamp' => time(), 'oauth_version' => '1.0');
         if ($this->url_parameters && $type === 'application/x-www-form-urlencoded' && count($parameters)) {
             $first = strpos($url, '?') === false;
             foreach ($parameters as $parameter => $value) {
                 $url .= ($first ? '?' : '&') . UrlEncode($parameter) . '=' . UrlEncode($value);
             }
             $parameters = array();
         }
         $value_parameters = $type !== 'application/x-www-form-urlencoded' ? array() : $parameters;
         $values = array_merge($values, $oauth, $value_parameters);
         $uri = strtok($url, '?');
         $sign = $method . '&' . $this->Encode($uri) . '&';
         $first = true;
         $sign_values = $values;
         $u = parse_url($url);
         if (isset($u['query'])) {
             parse_str($u['query'], $q);
             foreach ($q as $parameter => $value) {
                 $sign_values[$parameter] = $value;
             }
         }
         KSort($sign_values);
         foreach ($sign_values as $parameter => $value) {
             $sign .= $this->Encode(($first ? '' : '&') . $parameter . '=' . $this->Encode($value));
             $first = false;
         }
         $key = $this->Encode($this->client_secret) . '&' . $this->Encode($this->access_token_secret);
         $values['oauth_signature'] = base64_encode($this->HMAC('sha1', $sign, $key));
         if ($this->authorization_header) {
             $authorization = 'OAuth';
             $first = true;
             foreach ($values as $parameter => $value) {
                 $authorization .= ($first ? ' ' : ',') . $parameter . '="' . $this->Encode($value) . '"';
                 $first = false;
             }
         } else {
             if ($method === 'GET') {
                 $first = strcspn($url, '?') == strlen($url);
                 foreach ($values as $parameter => $value) {
                     $url .= ($first ? '?' : '&') . $parameter . '=' . $this->Encode($value);
                     $first = false;
                 }
                 $post_values = array();
             } else {
                 $post_values = $values;
             }
         }
     }
     if (strlen($error = $http->GetRequestArguments($url, $arguments))) {
         return $this->SetError('it was not possible to open the ' . $options['Resource'] . ' URL: ' . $error);
     }
     if (strlen($error = $http->Open($arguments))) {
         return $this->SetError('it was not possible to open the ' . $options['Resource'] . ' URL: ' . $error);
     }
     $arguments['RequestMethod'] = $method;
     switch ($type) {
         case 'application/x-www-form-urlencoded':
             if (isset($options['RequestBody'])) {
                 return $this->SetError('the request body is defined automatically from the parameters');
             }
             $arguments['PostValues'] = $parameters;
             break;
         case 'application/json':
             $arguments['Headers']['Content-Type'] = $options['RequestContentType'];
             if (!isset($options['RequestBody'])) {
                 $arguments['Body'] = json_encode($parameters);
                 break;
             }
         default:
             if (!isset($options['RequestBody'])) {
                 return $this->SetError('it was not specified the body value of the of the API call request');
             }
             $arguments['Headers']['Content-Type'] = $options['RequestContentType'];
             $arguments['Body'] = $options['RequestBody'];
             break;
     }
     $arguments['Headers']['Accept'] = isset($options['Accept']) ? $options['Accept'] : '*/*';
     if (strlen($authorization)) {
         $arguments['Headers']['Authorization'] = $authorization;
     }
     if (strlen($error = $http->SendRequest($arguments)) || strlen($error = $http->ReadReplyHeaders($headers))) {
         $http->Close();
         return $this->SetError('it was not possible to retrieve the ' . $options['Resource'] . ': ' . $error);
     }
     $error = $http->ReadWholeReplyBody($data);
     $http->Close();
     if (strlen($error)) {
         return $this->SetError('it was not possible to access the ' . $options['Resource'] . ': ' . $error);
     }
     $this->response_status = intval($http->response_status);
     $content_type = isset($headers['content-type']) ? strtolower(trim(strtok($headers['content-type'], ';'))) : 'unspecified';
     switch ($content_type) {
         case 'text/javascript':
         case 'application/json':
             if (!function_exists('json_decode')) {
                 return $this->SetError('the JSON extension is not available in this PHP setup');
             }
             $object = json_decode($data);
             switch (GetType($object)) {
                 case 'object':
                     if (!isset($options['ConvertObjects']) || !$options['ConvertObjects']) {
                         $response = $object;
                     } else {
                         $response = array();
                         foreach ($object as $property => $value) {
                             $response[$property] = $value;
                         }
                     }
                     break;
                 case 'array':
                     $response = $object;
                     break;
                 default:
                     if (!isset($object)) {
                         return $this->SetError('it was not returned a valid JSON definition of the ' . $options['Resource'] . ' values');
                     }
                     $response = $object;
                     break;
             }
             break;
         case 'application/x-www-form-urlencoded':
         case 'text/plain':
         case 'text/html':
             parse_str($data, $response);
             break;
         default:
             $response = $data;
             break;
     }
     if ($this->response_status >= 200 && $this->response_status < 300) {
         $this->access_token_error = '';
     } else {
         $this->access_token_error = 'it was not possible to access the ' . $options['Resource'] . ': it was returned an unexpected response status ' . $http->response_status . ' Response: ' . $data;
         if ($this->debug) {
             $this->OutputDebug('Could not retrieve the OAuth access. Error: ' . $this->access_token_error);
         }
         if (isset($options['FailOnAccessError']) && $options['FailOnAccessError']) {
             $this->error = $this->access_token_error;
             return false;
         }
     }
     return true;
 }
Esempio n. 4
0
 function ValidateEmailHost($email, &$hosts)
 {
     if (!$this->ValidateEmailAddress($email)) {
         return 0;
     }
     $user = $this->Tokenize($email, "@");
     $domain = $this->Tokenize("");
     $hosts = $weights = array();
     $getmxrr = $this->getmxrr;
     if (function_exists($getmxrr) && $getmxrr($domain, $hosts, $weights)) {
         $mxhosts = array();
         for ($host = 0; $host < count($hosts); $host++) {
             $mxhosts[$weights[$host]] = $hosts[$host];
         }
         KSort($mxhosts);
         for (Reset($mxhosts), $host = 0; $host < count($mxhosts); Next($mxhosts), $host++) {
             $hosts[$host] = $mxhosts[Key($mxhosts)];
         }
     } else {
         if (strcmp($ip = @gethostbyname($domain), $domain) && (strlen($this->exclude_address) == 0 || strcmp(@gethostbyname($this->exclude_address), $ip))) {
             $hosts[] = $domain;
         }
     }
     return count($hosts) != 0;
 }
Esempio n. 5
0
 function Sign(&$url, $method, $parameters, $oauth, $request_content_type, $has_files, $post_values_in_uri, &$authorization, &$post_values)
 {
     $values = array('oauth_consumer_key' => $this->client_id, 'oauth_nonce' => md5(uniqid(rand(), true)), 'oauth_signature_method' => $this->signature_method, 'oauth_timestamp' => time(), 'oauth_version' => '1.0');
     if ($has_files) {
         $value_parameters = array();
     } else {
         if (($this->url_parameters || $method !== 'POST') && $request_content_type === 'application/x-www-form-urlencoded' && count($parameters)) {
             $first = strpos($url, '?') === false;
             foreach ($parameters as $parameter => $value) {
                 $url .= ($first ? '?' : '&') . UrlEncode($parameter) . '=' . UrlEncode($value);
                 $first = false;
             }
             $parameters = array();
         }
         $value_parameters = $request_content_type !== 'application/x-www-form-urlencoded' ? array() : $parameters;
     }
     $header_values = $method === 'GET' ? array_merge($values, $oauth, $value_parameters) : array_merge($values, $oauth);
     $values = array_merge($values, $oauth, $value_parameters);
     $key = $this->Encode($this->client_secret) . '&' . $this->Encode($this->access_token_secret);
     switch ($this->signature_method) {
         case 'PLAINTEXT':
             $values['oauth_signature'] = $key;
             break;
         case 'HMAC-SHA1':
             $uri = strtok($url, '?');
             $sign = $method . '&' . $this->Encode($uri) . '&';
             $first = true;
             $sign_values = $values;
             $u = parse_url($url);
             if (isset($u['query'])) {
                 parse_str($u['query'], $q);
                 foreach ($q as $parameter => $value) {
                     $sign_values[$parameter] = $value;
                 }
             }
             KSort($sign_values);
             foreach ($sign_values as $parameter => $value) {
                 $sign .= $this->Encode(($first ? '' : '&') . $parameter . '=' . $this->Encode($value));
                 $first = false;
             }
             $header_values['oauth_signature'] = $values['oauth_signature'] = base64_encode($this->HMAC('sha1', $sign, $key));
             break;
         default:
             return $this->SetError($this->signature_method . ' signature method is not yet supported');
     }
     if ($this->authorization_header) {
         $authorization = 'OAuth';
         $first = true;
         foreach ($header_values as $parameter => $value) {
             $authorization .= ($first ? ' ' : ',') . $parameter . '="' . $this->Encode($value) . '"';
             $first = false;
         }
         $post_values = $parameters;
     } else {
         if ($method !== 'POST' || $post_values_in_uri) {
             $first = strcspn($url, '?') == strlen($url);
             foreach ($values as $parameter => $value) {
                 $url .= ($first ? '?' : '&') . $parameter . '=' . $this->Encode($value);
                 $first = false;
             }
             $post_values = array();
         } else {
             $post_values = $values;
         }
     }
     return true;
 }
Esempio n. 6
0
 static function UIntersectArrayMerge($Array1, $Array2, $CompareFunction)
 {
     $ResultArray = Array_UIntersect_Assoc($Array1, $Array2, $CompareFunction) + $Array2;
     KSort($ResultArray);
     return $ResultArray;
 }
Esempio n. 7
0
 function Connect($domain = "")
 {
     $this->error = $error = "";
     $this->esmtp_host = "";
     $this->esmtp_extensions = array();
     $hosts = array();
     if ($this->direct_delivery) {
         if (strlen($domain) == 0) {
             return 1;
         }
         $hosts = $weights = $mxhosts = array();
         $getmxrr = $this->getmxrr;
         if (function_exists($getmxrr) && $getmxrr($domain, $hosts, $weights)) {
             for ($host = 0; $host < count($hosts); $host++) {
                 $mxhosts[$weights[$host]] = $hosts[$host];
             }
             KSort($mxhosts);
             for (Reset($mxhosts), $host = 0; $host < count($mxhosts); Next($mxhosts), $host++) {
                 $hosts[$host] = $mxhosts[Key($mxhosts)];
             }
         } else {
             if (strcmp(@gethostbyname($domain), $domain) != 0) {
                 $hosts[] = $domain;
             }
         }
     } else {
         if (strlen($this->host_name)) {
             $hosts[] = $this->host_name;
         }
     }
     if (count($hosts) == 0) {
         $this->error = "could not determine the SMTP to connect";
         return 0;
     }
     if (strcmp($this->state, "Disconnected")) {
         $this->error = "connection is already established";
         return 0;
     }
     for ($host = 0;; $host++) {
         $domain = $hosts[$host];
         if (ereg('^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$', $domain)) {
             $ip = $domain;
         } else {
             if ($this->debug) {
                 $this->OutputDebug("Resolving SMTP server domain \"{$domain}\"...");
             }
             if (!strcmp($ip = @gethostbyname($domain), $domain)) {
                 $ip = "";
             }
         }
         if (strlen($ip) == 0 || strlen($this->exclude_address) && !strcmp(@gethostbyname($this->exclude_address), $ip)) {
             if ($host == count($hosts) - 1) {
                 $this->error = "could not resolve the host domain \"" . $domain . "\"";
                 return 0;
             }
             continue;
         }
         if ($this->debug) {
             $this->OutputDebug("Connecting to SMTP server ip \"{$ip}\"...");
         }
         if ($this->connection = $this->timeout ? fsockopen($ip, $this->host_port, $errno, $error, $this->timeout) : fsockopen($ip, $this->host_port)) {
             break;
         }
         if ($host == count($hosts) - 1) {
             switch ($this->timeout ? strval($error) : "??") {
                 case "-3":
                     $this->error = "-3 socket could not be created";
                     break;
                 case "-4":
                     $this->error = "-4 dns lookup on hostname \"" . $domain . "\" failed";
                     break;
                 case "-5":
                     $this->error = "-5 connection refused or timed out";
                     break;
                 case "-6":
                     $this->error = "-6 fdopen() call failed";
                     break;
                 case "-7":
                     $this->error = "-7 setvbuf() call failed";
                     break;
                 default:
                     $this->error = $error . " could not connect to the host \"" . $this->host_name . "\"";
                     break;
             }
             return 0;
         }
     }
     if ($this->debug) {
         $this->OutputDebug("Connected to SMTP server ip \"{$ip}\".");
     }
     if (!strcmp($localhost = $this->localhost, "") && !strcmp($localhost = getenv("SERVER_NAME"), "") && !strcmp($localhost = getenv("HOST"), "")) {
         $localhost = "localhost";
     }
     $success = 0;
     if ($this->VerifyResultLines("220", $responses) > 0) {
         if ($this->esmtp || strlen($this->user)) {
             if ($this->PutLine("EHLO {$localhost}") && $this->VerifyResultLines("250", $responses) > 0) {
                 $this->esmtp_host = $this->Tokenize($responses[0], " ");
                 for ($response = 1; $response < count($responses); $response++) {
                     $extension = strtoupper($this->Tokenize($responses[$response], " "));
                     $this->esmtp_extensions[$extension] = $this->Tokenize("");
                 }
                 $success = 1;
             }
         }
         if (!$success && strlen($this->user) == 0 && $this->PutLine("HELO {$localhost}") && $this->VerifyResultLines("250", $responses) > 0) {
             $success = 1;
         }
         if ($success && strlen($this->user)) {
             if (!isset($this->esmtp_extensions["AUTH"])) {
                 $this->error = "server does not require authentication";
                 $success = 0;
             } else {
                 for ($authentication = $this->Tokenize($this->esmtp_extensions["AUTH"], " "); strlen($authentication); $authentication = $this->Tokenize(" ")) {
                     switch ($authentication) {
                         case "PLAIN":
                             $success = $this->PutLine("AUTH PLAIN " . base64_encode($this->user . chr(0) . $this->user . (strlen($this->realm) ? "@" . $this->realm : "") . chr(0) . $this->password)) && $this->VerifyResultLines("235", $responses);
                             break 2;
                         case "LOGIN":
                             $success = $this->PutLine("AUTH LOGIN") && $this->VerifyResultLines("334", $responses) && $this->PutLine(base64_encode($this->user . (strlen($this->realm) ? "@" . $this->realm : ""))) && $this->VerifyResultLines("334", $responses) && $this->PutLine(base64_encode($this->password)) && $this->VerifyResultLines("235", $responses);
                             break 2;
                     }
                 }
                 if ($success && strlen($authentication) == 0) {
                     $this->error = "the server does not require a supported authentication method";
                     $success = 0;
                 }
             }
         }
     }
     if ($success) {
         $this->state = "Connected";
         $this->connected_domain = $domain;
     } else {
         fclose($this->connection);
         $this->connection = 0;
     }
     return $success;
 }
Esempio n. 8
0
    $Comp = Comp_Load('Formats/Percent', $WorkComplite['Discont']);
    if (Is_Error($Comp)) {
        return ERROR | @Trigger_Error(500);
    }
    #-------------------------------------------------------------------------------
    $Cost = Comp_Load('Formats/Currency', $WorkComplite['Cost']);
    if (Is_Error($Cost)) {
        return ERROR | @Trigger_Error(500);
    }
    #-------------------------------------------------------------------------------
    $Verifies[$CreateDate] = array('Founding' => SPrintF('%s %s', $WorkComplite['Service'], $WorkComplite['Comment']), 'Measure' => $WorkComplite['Measure'], 'Amount' => (int) $WorkComplite['Amount'], 'Cost' => $Cost, 'Discont' => $Comp, 'Debet' => 0, 'Credit' => $WorkComplite['Summ']);
    #-------------------------------------------------------------------------------
}
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
KSort($Verifies);
#-------------------------------------------------------------------------------
$Table = array(array(new Tag('TD', array('class' => 'Head'), 'Дата'), new Tag('TD', array('class' => 'Head'), 'Основание'), new Tag('TD', array('class' => 'Head'), 'Ед. изм.'), new Tag('TD', array('class' => 'Head'), 'Кол-во'), new Tag('TD', array('class' => 'Head'), 'Цена'), new Tag('TD', array('class' => 'Head'), 'Скидка'), new Tag('TD', array('class' => 'Head'), 'Дебет'), new Tag('TD', array('class' => 'Head'), 'Кредит')));
#-------------------------------------------------------------------------------
$Total = array('Debet' => 0, 'Credit' => 0);
#-------------------------------------------------------------------------------
foreach ($Verifies as $CreateDate => $Verify) {
    #-------------------------------------------------------------------------------
    $Comp = Comp_Load('Formats/Date/Standard', (int) $CreateDate);
    if (Is_Error($Comp)) {
        return ERROR | @Trigger_Error(500);
    }
    #-------------------------------------------------------------------------------
    $Line = array($Comp, $Verify['Founding'], $Verify['Measure'], $Verify['Amount'], $Verify['Cost'], $Verify['Discont']);
    #-------------------------------------------------------------------------------
    $Credit = $Verify['Credit'];
Esempio n. 9
0
function Styles_Menu($Path)
{
    /****************************************************************************/
    $__args_types = array('string');
    #-----------------------------------------------------------------------------
    $__args__ = Func_Get_Args();
    eval(FUNCTION_INIT);
    /****************************************************************************/
    $Result = $Chain = array();
    #-----------------------------------------------------------------------------
    do {
        #---------------------------------------------------------------------------
        $Menu = Styles_XML(SPrintF('Menus/%s.xml', $Path));
        if (Is_Error($Menu)) {
            return ERROR | @Trigger_Error('[Styles_Menu]: не удалось загрузить файл меню');
        }
        #---------------------------------------------------------------------------
        Array_UnShift($Chain, $Menu);
        #---------------------------------------------------------------------------
        $Path = isset($Menu['RootID']) ? $Menu['RootID'] : FALSE;
        #---------------------------------------------------------------------------
    } while ($Path);
    #-----------------------------------------------------------------------------
    foreach ($Chain as $Menu) {
        Array_Union($Result, $Menu);
    }
    #-----------------------------------------------------------------------------
    $Items =& $Result['Items'];
    #-----------------------------------------------------------------------------
    if (isset($Result['Comp'])) {
        #---------------------------------------------------------------------------
        $Comp = Comp_Load($Result['Comp']);
        if (Is_Error($Comp)) {
            return ERROR | @Trigger_Error(500);
        }
        #---------------------------------------------------------------------------
        if (Is_Array($Comp)) {
            Array_Union($Items, $Comp);
        }
    }
    #-----------------------------------------------------------------------------
    foreach (Array_Keys($Items) as $ItemID) {
        #---------------------------------------------------------------------------
        $Item =& $Items[$ItemID];
        #---------------------------------------------------------------------------
        if (!Is_Array($Item)) {
            continue;
        }
        #---------------------------------------------------------------------------
        if (isset($Item['UnActive'])) {
            unset($Items[$ItemID]);
        }
        #---------------------------------------------------------------------------
        $IsActive = FALSE;
        #---------------------------------------------------------------------------
        foreach ($Item['Paths'] as $Path) {
            #-------------------------------------------------------------------------
            $IsActive = Preg_Match(SPrintF('/%s/', $Path), $GLOBALS['__URI']) || Preg_Match(SPrintF('/%s/', $Path), $_SERVER['REQUEST_URI']);
            #-------------------------------------------------------------------------
            if ($IsActive) {
                break;
            }
        }
        #---------------------------------------------------------------------------
        $Item['IsActive'] = $IsActive;
    }
    #-----------------------------------------------------------------------------
    KSort($Items);
    #-----------------------------------------------------------------------------
    return $Result;
}
Esempio n. 10
0
 function SendAPIRequest($url, $method, $parameters, $oauth, $options, &$response)
 {
     $this->response_status = 0;
     $http = new http_class();
     $http->debug = $this->debug && $this->debug_http;
     $http->log_debug = true;
     $http->sasl_authenticate = 0;
     $http->user_agent = $this->oauth_user_agent;
     $http->redirection_limit = isset($options['FollowRedirection']) ? intval($options['FollowRedirection']) : 0;
     $http->follow_redirect = $http->redirection_limit != 0;
     if ($this->debug) {
         $this->OutputDebug('Accessing the ' . $options['Resource'] . ' at ' . $url);
     }
     $post_files = array();
     $method = strtoupper($method);
     $authorization = '';
     $type = isset($options['RequestContentType']) ? strtolower(trim(strtok($options['RequestContentType'], ';'))) : ($method === 'POST' || isset($oauth) ? 'application/x-www-form-urlencoded' : '');
     if (isset($oauth)) {
         $values = array('oauth_consumer_key' => $this->client_id, 'oauth_nonce' => md5(uniqid(rand(), true)), 'oauth_signature_method' => $this->signature_method, 'oauth_timestamp' => time(), 'oauth_version' => '1.0');
         $files = isset($options['Files']) ? $options['Files'] : array();
         if (count($files)) {
             foreach ($files as $name => $value) {
                 if (!isset($parameters[$name])) {
                     return $this->SetError('it was specified an file parameters named ' . $name);
                 }
                 $file = array();
                 switch (isset($value['Type']) ? $value['Type'] : 'FileName') {
                     case 'FileName':
                         $file['FileName'] = $parameters[$name];
                         break;
                     case 'Data':
                         $file['Data'] = $parameters[$name];
                         break;
                     default:
                         return $this->SetError($value['Type'] . ' is not a valid type for file ' . $name);
                 }
                 $file['Content-Type'] = isset($value['ContentType']) ? $value['ContentType'] : 'automatic/name';
                 $post_files[$name] = $file;
             }
             unset($parameters[$name]);
             if ($method !== 'POST') {
                 $this->OutputDebug('For uploading files the method should be POST not ' . $method);
                 $method = 'POST';
             }
             if ($type !== 'multipart/form-data') {
                 if (isset($options['RequestContentType'])) {
                     return $this->SetError('the request content type for uploading files should be multipart/form-data');
                 }
                 $type = 'multipart/form-data';
             }
             $value_parameters = array();
         } else {
             if ($this->url_parameters && $type === 'application/x-www-form-urlencoded' && count($parameters)) {
                 $first = strpos($url, '?') === false;
                 foreach ($parameters as $parameter => $value) {
                     $url .= ($first ? '?' : '&') . UrlEncode($parameter) . '=' . UrlEncode($value);
                     $first = false;
                 }
                 $parameters = array();
             }
             $value_parameters = $type !== 'application/x-www-form-urlencoded' ? array() : $parameters;
         }
         $header_values = $method === 'GET' ? array_merge($values, $oauth, $value_parameters) : array_merge($values, $oauth);
         $values = array_merge($values, $oauth, $value_parameters);
         $key = $this->Encode($this->client_secret) . '&' . $this->Encode($this->access_token_secret);
         switch ($this->signature_method) {
             case 'PLAINTEXT':
                 $values['oauth_signature'] = $key;
                 break;
             case 'HMAC-SHA1':
                 $uri = strtok($url, '?');
                 $sign = $method . '&' . $this->Encode($uri) . '&';
                 $first = true;
                 $sign_values = $values;
                 $u = parse_url($url);
                 if (isset($u['query'])) {
                     parse_str($u['query'], $q);
                     foreach ($q as $parameter => $value) {
                         $sign_values[$parameter] = $value;
                     }
                 }
                 KSort($sign_values);
                 foreach ($sign_values as $parameter => $value) {
                     $sign .= $this->Encode(($first ? '' : '&') . $parameter . '=' . $this->Encode($value));
                     $first = false;
                 }
                 $header_values['oauth_signature'] = $values['oauth_signature'] = base64_encode($this->HMAC('sha1', $sign, $key));
                 break;
             default:
                 return $this->SetError($this->signature_method . ' signature method is not yet supported');
         }
         if ($this->authorization_header) {
             $authorization = 'OAuth';
             $first = true;
             foreach ($header_values as $parameter => $value) {
                 $authorization .= ($first ? ' ' : ',') . $parameter . '="' . $this->Encode($value) . '"';
                 $first = false;
             }
             $post_values = $parameters;
         } else {
             if ($method !== 'POST' || isset($options['PostValuesInURI']) && $options['PostValuesInURI']) {
                 $first = strcspn($url, '?') == strlen($url);
                 foreach ($values as $parameter => $value) {
                     $url .= ($first ? '?' : '&') . $parameter . '=' . $this->Encode($value);
                     $first = false;
                 }
                 $post_values = array();
             } else {
                 $post_values = $values;
             }
         }
     } else {
         $post_values = $parameters;
         if (count($parameters)) {
             switch ($type) {
                 case 'application/x-www-form-urlencoded':
                 case 'multipart/form-data':
                 case 'application/json':
                     break;
                 default:
                     $first = strpos($url, '?') === false;
                     foreach ($parameters as $name => $value) {
                         if (GetType($value) === 'array') {
                             foreach ($value as $index => $value) {
                                 $url .= ($first ? '?' : '&') . $name . '=' . UrlEncode($value);
                                 $first = false;
                             }
                         } else {
                             $url .= ($first ? '?' : '&') . $name . '=' . UrlEncode($value);
                             $first = false;
                         }
                     }
             }
         }
     }
     if (strlen($authorization) === 0 && !strcasecmp($this->access_token_type, 'Bearer')) {
         $authorization = 'Bearer ' . $this->access_token;
     }
     if (strlen($error = $http->GetRequestArguments($url, $arguments))) {
         return $this->SetError('it was not possible to open the ' . $options['Resource'] . ' URL: ' . $error);
     }
     /* @TODO proxy configs
        $arguments['ProxyHostName'] = '127.0.0.1';
        $arguments['ProxyHostPort'] = '3128';
        */
     if (strlen($error = $http->Open($arguments))) {
         return $this->SetError('it was not possible to open the ' . $options['Resource'] . ' URL: ' . $error);
     }
     if (count($post_files)) {
         $arguments['PostFiles'] = $post_files;
     }
     $arguments['RequestMethod'] = $method;
     switch ($type) {
         case 'application/x-www-form-urlencoded':
         case 'multipart/form-data':
             if (isset($options['RequestBody'])) {
                 return $this->SetError('the request body is defined automatically from the parameters');
             }
             $arguments['PostValues'] = $post_values;
             break;
         case 'application/json':
             $arguments['Headers']['Content-Type'] = $options['RequestContentType'];
             $arguments['Body'] = isset($options['RequestBody']) ? $options['RequestBody'] : json_encode($parameters);
             break;
         default:
             if (!isset($options['RequestBody'])) {
                 if (isset($options['RequestContentType'])) {
                     return $this->SetError('it was not specified the body value of the of the API call request');
                 }
                 break;
             }
             $arguments['Headers']['Content-Type'] = $options['RequestContentType'];
             $arguments['Body'] = $options['RequestBody'];
             break;
     }
     $arguments['Headers']['Accept'] = isset($options['Accept']) ? $options['Accept'] : '*/*';
     switch ($authentication = isset($options['AccessTokenAuthentication']) ? strtolower($options['AccessTokenAuthentication']) : '') {
         case 'basic':
             $arguments['Headers']['Authorization'] = 'Basic ' . base64_encode($this->client_id . ':' . ($this->get_token_with_api_key ? $this->api_key : $this->client_secret));
             break;
         case '':
             if (strlen($authorization)) {
                 $arguments['Headers']['Authorization'] = $authorization;
             }
             break;
         default:
             return $this->SetError($authentication . ' is not a supported authentication mechanism to retrieve an access token');
     }
     if (isset($options['RequestHeaders'])) {
         $arguments['Headers'] = array_merge($arguments['Headers'], $options['RequestHeaders']);
     }
     if (strlen($error = $http->SendRequest($arguments)) || strlen($error = $http->ReadReplyHeaders($headers))) {
         $http->Close();
         return $this->SetError('it was not possible to retrieve the ' . $options['Resource'] . ': ' . $error);
     }
     $error = $http->ReadWholeReplyBody($data);
     $http->Close();
     if (strlen($error)) {
         return $this->SetError('it was not possible to access the ' . $options['Resource'] . ': ' . $error);
     }
     $this->response_status = intval($http->response_status);
     $content_type = isset($options['ResponseContentType']) ? $options['ResponseContentType'] : (isset($headers['content-type']) ? strtolower(trim(strtok($headers['content-type'], ';'))) : 'unspecified');
     $content_type = preg_replace('/^(.+\\/).+\\+(.+)$/', '\\1\\2', $content_type);
     switch ($content_type) {
         case 'text/javascript':
         case 'application/json':
             if (!function_exists('json_decode')) {
                 return $this->SetError('the JSON extension is not available in this PHP setup');
             }
             $object = json_decode($data);
             switch (GetType($object)) {
                 case 'object':
                     if (!isset($options['ConvertObjects']) || !$options['ConvertObjects']) {
                         $response = $object;
                     } else {
                         $response = array();
                         foreach ($object as $property => $value) {
                             $response[$property] = $value;
                         }
                     }
                     break;
                 case 'array':
                     $response = $object;
                     break;
                 default:
                     if (!isset($object)) {
                         return $this->SetError('it was not returned a valid JSON definition of the ' . $options['Resource'] . ' values');
                     }
                     $response = $object;
                     break;
             }
             break;
         case 'application/x-www-form-urlencoded':
         case 'text/plain':
         case 'text/html':
             parse_str($data, $response);
             break;
         case 'text/xml':
             if (isset($options['DecodeXMLResponse'])) {
                 switch (strtolower($options['DecodeXMLResponse'])) {
                     case 'simplexml':
                         if ($this->debug) {
                             $this->OutputDebug('Decoding XML response with simplexml');
                         }
                         try {
                             $response = @new SimpleXMLElement($data);
                         } catch (Exception $exception) {
                             return $this->SetError('Could not parse XML response: ' . $exception->getMessage());
                         }
                         break 2;
                     default:
                         return $this->SetError($options['DecodeXML'] . ' is not a supported method to decode XML responses');
                 }
             }
         default:
             $response = $data;
             break;
     }
     if ($this->response_status >= 200 && $this->response_status < 300) {
         $this->access_token_error = '';
     } else {
         $this->access_token_error = 'it was not possible to access the ' . $options['Resource'] . ': it was returned an unexpected response status ' . $http->response_status . ' Response: ' . $data;
         if ($this->debug) {
             $this->OutputDebug('Could not retrieve the OAuth access token. Error: ' . $this->access_token_error);
         }
         if (isset($options['FailOnAccessError']) && $options['FailOnAccessError']) {
             $this->error = $this->access_token_error;
             return false;
         }
     }
     return true;
 }