Esempio n. 1
0
 *	   Typically, you store transaction IDs in a database so that you know you are only processing unique transactions.
 *	 - Validate that the receiver's email address is registered to you.
 *	   This check provides additional protection against fraud.
 *	 - Verify that the price, item description, and so on, match the transaction on your website.
 *	   This check provides additional protection against fraud.
 * 6. If the verified response passes the checks, take action based on the value of the txn_type variable if it exists; otherwise, take action based on the value of the reason_code variable.
 * 7. If the response is INVALID, save the message for further investigation.
 *
 */
$path = "../libraries/";
require_once $path . "configuration.php";
$GLOBALS['configuration']['paypalmode'] == 'sandbox' ? $paypalUrl = "www.sandbox.paypal.com" : ($paypalUrl = "www.paypal.com");
//Toggle sandbox/normal use
try {
    //Get the directory where the log file will be stored
    $admin = EfrontSystem::getAdministrator();
    $logFolder = $admin->user['directory'] . '/';
    new EfrontDirectory($logFolder);
    //This way if the $logFolder is not a valid directory, we will go to the catch{} block below
} catch (Exception $e) {
    $logFolder = '';
    //Use the current directory for storing the log
}
$logFile = $logFolder . 'ipn.log';
file_put_contents($logFile, "\n======================Start of communication====================\n", FILE_APPEND);
try {
    $result = eF_getTableData("payments", "*");
    $processedPayments = array();
    foreach ($result as $value) {
        if ($value['txn_id']) {
            $processedPayments[$value['txn_id']] = $value['status'];
 /**
  * Get the list of users that are currently online
  *
  * This function is used to get a list of the users that are currently online
  * In addition, it logs out any inactive users, based on global setting
  * <br>Example:
  * <code>
  * $online = EfrontUser :: getUsersOnline();
  * </code>
  *
  * @param boolean $userType Return only users of the basic type $user_type
  * @param int $interval The idle interval above which a user is logged out. If it's not specified, no logging out takes place
  * @return array The list of online users
  * @since 3.5.0
  * @access public
  */
 public static function getUsersOnline($interval = false)
 {
     $usersOnline = array();
     //A user may have multiple active entries on the user_times table, one for system, one for unit etc. Pick the most recent
     $result = eF_getTableData("user_times,users", "users.login, users.name, users.surname, users.user_type, timestamp_now, session_timestamp, session_id", "users.login=user_times.users_LOGIN and session_expired=0", "timestamp_now desc");
     foreach ($result as $value) {
         if (!isset($parsedUsers[$value['login']])) {
             if (time() - $value['timestamp_now'] < $interval || !$interval) {
                 $usersOnline[] = array('login' => $value['login'], 'formattedLogin' => formatLogin($value['login'], $value), 'user_type' => $value['user_type'], 'timestamp_now' => $value['timestamp_now'], 'session_timestamp' => $value['session_timestamp'], 'time' => EfrontTimes::formatTimeForReporting(time() - $value['session_timestamp']));
             } else {
                 //pr($result);
                 //pr("interval: $interval, time: ".time().", timestamp_now:".$value['timestamp_now']);
                 EfrontUserFactory::factory($value['login'])->logout($value['session_id']);
                 //exit;
             }
             $parsedUsers[$value['login']] = true;
         }
     }
     $online_users = sizeof($result);
     if (G_VERSIONTYPE != 'community') {
         #cpp#ifndef COMMUNITY
         if (G_VERSIONTYPE != 'standard') {
             #cpp#ifndef STANDARD
             $threshold = $GLOBALS['configuration']['max_online_users_threshold'];
             if ($threshold > 0 && $online_users > $threshold && time() > $GLOBALS['configuration']['max_online_users_threshold_timestamp'] + 24 * 60 * 60) {
                 $admin = EfrontSystem::getAdministrator();
                 eF_mail($GLOBALS['configuration']['system_email'], $admin->user['email'], _ONLINEUSERSMAIL, str_replace(array('%w', '%x', '%y', '%z'), array($admin->user['name'], $threshold, $GLOBALS['configuration']['site_name'], G_SERVERNAME), _ONLINEUSERSMAILBODY));
                 EfrontConfiguration::setValue('max_online_users_threshold_timestamp', time());
             }
         }
         #cpp#endif
     }
     #cpp#endif
     if ($GLOBALS['configuration']['max_online_users'] < $online_users) {
         EfrontConfiguration::setValue('max_online_users', $online_users);
         EfrontConfiguration::setValue('max_online_users_timestamp', time());
     }
     if (G_VERSIONTYPE == 'enterprise' && defined("G_BRANCH_URL") && G_BRANCH_URL && $_SESSION['s_current_branch']) {
         $branch = new EfrontBranch($_SESSION['s_current_branch']);
         $branchUsers = $branch->getBranchTreeUsers();
         foreach ($usersOnline as $key => $value) {
             if (!isset($branchUsers[$value['login']]) && $value['user_type'] != 'administrator') {
                 unset($usersOnline[$key]);
             }
         }
     }
     return $usersOnline;
 }
 public function sendTo($recipient)
 {
     if (is_array($recipient)) {
         if (isset($recipient['login'])) {
             if (!(isset($recipient['email']) && isset($recipient['name']) && isset($recipient['surname']) && isset($recipient['user_type']))) {
                 $recipient = $recipient['login'];
             } else {
                 $defined = 1;
             }
         } else {
             throw new EfrontNotificationException(_UNKNOWNRECIPIENT, EfrontNotificationException::NORECIPIENTLOGIN_DEFINED);
         }
     }
     if (!$defined) {
         $recipient = eF_getTableData("users", "*", "login = '******'");
         if (!empty($recipient)) {
             $recipient = $recipient[0];
         } else {
             throw new EfrontNotificationException(_UNKNOWNRECIPIENT, EfrontNotificationException::NORECIPIENTLOGIN_DEFINED);
         }
     }
     // create the array of substitutions for this particular user and replace them in the subject/message texts
     $hostname = G_SERVERNAME;
     if ($hostname[strlen($hostname) - 1] == "/") {
         $hostname = substr($hostname, 0, strlen($hostname) - 1);
     }
     $language = eF_getTableData("languages", "translation", "name = '" . $recipient['languages_NAME'] . "'");
     if (!empty($language)) {
         $language = $language[0]['translation'];
     }
     $template_formulations = array("users_name" => $recipient['name'], "users_surname" => $recipient['surname'], "users_login" => $recipient['login'], "users_email" => $recipient['email'], "users_comments" => $recipient['comments'], "users_language" => $language, "date" => formatTimestamp(time()), "date_time" => formatTimestamp(time(), 'time'), "timestamp" => time(), "user_type" => $recipient['user_type'], "host_name" => $hostname, "site_name" => $GLOBALS['configuration']['site_name'], "site_motto" => $GLOBALS['configuration']['site_motto']);
     $header = array('From' => $GLOBALS['configuration']['system_email'], 'To' => $recipient['email'], 'Subject' => eF_formulateTemplateMessage($this->notification['subject'], $template_formulations), 'Content-Transfer-Encoding' => '7bit', 'Date' => date("r"));
     if ($this->notification['html_message'] == 1) {
         $header['Content-type'] = 'text/html;charset="UTF-8"';
         // if content-type is text/html, the message cannot be received by mail clients for Registration content
     } else {
         $header['Content-type'] = 'text/plain;charset="UTF-8"';
     }
     $smtp = Mail::factory('smtp', array('auth' => $GLOBALS['configuration']['smtp_auth'] ? true : false, 'host' => $GLOBALS['configuration']['smtp_host'], 'password' => $GLOBALS['configuration']['smtp_pass'], 'port' => $GLOBALS['configuration']['smtp_port'], 'username' => $GLOBALS['configuration']['smtp_user'], 'timeout' => $GLOBALS['configuration']['smtp_timeout']));
     // force url change for html messages
     $message = eF_getCorrectLanguageMessage($this->notification['message'], $recipient['languages_NAME']);
     // Local paths names should become urls
     if ($this->notification['html_message'] == 1) {
         $message = str_replace('="content', '="###host_name###/content', $message);
         /*
          * //Commented-out Feb 2013 (periklis) because it's no longer needed (probably)        	
         			if ($configuration['math_images']) {
         				$message = "<html><body><script type = \"text/javascript\" src = \"###host_name###/js/ASCIIMath2Tex.js\"> </script>".$message."</body></html>";
         			} else {
         				$message = "<html><body><script type = \"text/javascript\" src = \"###host_name###/js/ASCIIMathML.js\"> </script>".$message."</body></html>";
         			}
         */
     } else {
         $message = str_replace("<br />", "\r\n", $message);
         $message = str_replace("<br>", "\r\n", $message);
         $message = str_replace("<p>", "\r\n", $message);
         $message = str_replace("</p>", "\r\n", $message);
         $message = str_replace("&amp;", "&", $message);
         $message = strip_tags($message);
     }
     $message = eF_formulateTemplateMessage($message, $template_formulations);
     $message = eF_replaceMD5($message);
     if ($GLOBALS['configuration']['notifications_send_mode'] == 0) {
         //email only
         if (!empty($recipient['email'])) {
             $result = $smtp->send($recipient['email'], $header, $message);
         }
     } else {
         if ($GLOBALS['configuration']['notifications_send_mode'] == 1) {
             //pm only
             $pm = new eF_PersonalMessage($recipient['login'], $recipient['login'], $header['Subject'], $message);
             $result = $pm->send();
         } else {
             if ($GLOBALS['configuration']['notifications_send_mode'] == 2) {
                 //email and pm
                 $pm = new eF_PersonalMessage($recipient['login'], $recipient['login'], $header['Subject'], $message);
                 $pm->send();
                 if (!empty($recipient['email'])) {
                     $result = $smtp->send($recipient['email'], $header, $message);
                 }
             }
         }
     }
     if (PEAR::isError($result)) {
         $admin = EfrontSystem::getAdministrator();
         eF_mail($GLOBALS['configuration']['system_email'], $admin->user['email'], _AUTOMATEDEMAILSENTFROM . $admin->user['email'], $result->getMessage());
         throw new EfrontNotificationException($result->getMessage(), EfrontNotificationException::GENERAL_ERROR);
     }
     if ($result === true) {
         // put into sent_notifications table
         eF_insertTableData("sent_notifications", array("timestamp" => time(), "recipient" => $recipient['email'] . " (" . $recipient['name'] . " " . $recipient['surname'] . ")", "subject" => $header['Subject'], "body" => $message, "html_message" => $this->notification['html_message']));
         return true;
     } else {
         return false;
     }
 }