/**
  * 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;
 }
Пример #2
0
 if ($_GET['limit_reached']) {
     $form->setDefaults(array('message_subject' => _IWANTTOSIGNUPBUTMAXIMUMUSERSLIMITREACHED, 'message_body' => _IWANTTOSIGNUPBUTMAXIMUMUSERSLIMITREACHEDBODY));
 }
 if ($_SESSION['s_login']) {
     $form->setDefaults(array('email' => $currentUser->user['email']));
 }
 if ($form->isSubmitted()) {
     $fields_insert = array('users_LOGIN' => 'visitor', 'timestamp' => time(), 'action' => 'forms', 'comments' => 'contact', 'session_ip' => eF_encodeIP(eF_getRemoteAddress()));
     eF_insertTableData("logs", $fields_insert);
     if ($form->validate()) {
         $to = $form->exportValue("email");
         $subject = $form->exportValue("message_subject");
         $body = $form->exportValue("message_body") . "\r\n\r\n(" . $subject . " [" . _FROM . ": " . $to . "])";
         if (eF_mail($to, $GLOBALS['configuration']['system_email'], $subject . " [" . _FROM . ": " . $to . "]", $body, false, true)) {
             $copied_body = _THANKYOUFORCONTACTINGUSBODY . "<br/><hr/><br/>" . $form->exportValue("message_body");
             eF_mail($GLOBALS['configuration']['system_email'], $to, _THANKYOUFORCONTACTINGUS, $copied_body, false, false);
             $message = _SENDSUCCESS;
             $message_type = 'success';
             eF_redirect(basename($_SERVER['PHP_SELF']) . '?message=' . urlencode($message) . '&message_type=' . $message_type);
         } else {
             $message = _SENDFAILURE;
             $message_type = 'failure';
         }
     }
 }
 $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
 $renderer->setRequiredTemplate('{$html}{if $required}
         &nbsp;<span class = "formRequired">*</span>
     {/if}');
 $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
 $form->setRequiredNote(_REQUIREDNOTE);
 /**
  * Send a personal message
  *
  * This function is used to send the personal message. If $email is specified,
  * the message is also emailed to the recipients
  * <br/>Example:
  * <code>
  * $pm = new eF_PersonalMessage("professor", array("professor", "student", "admin"), 'Test subject', 'Test personal message body');
  * $pm -> send();
  * </code>
  *
  * @param boolean If true, the personal message will be send as an email as well
  * @return true on success, false on error
  * @since 1.0
  * @access public
  */
 public function send($email = false)
 {
     if (sizeof($this->recipients) == 0) {
         $this->errorMessage = _INVALIDRECIPIENT;
         return false;
     }
     $timestamp = time();
     if ($email) {
         //Check if the messag should be sent as an email also. This will be sent no matter the user quotas
         $recipientsMail = array();
         foreach ($this->recipients as $recipient) {
             if ($this->userData[$recipient]['email'] != "") {
                 $recipientsMail[] = $this->userData[$recipient]['email'];
             } else {
                 $this->errorMessage .= $this->userData[$recipient]['login'] . ' ' . _HASNOTANEMAILADDRESS . '<br/>';
             }
         }
         $recipientsList = implode(",", $recipientsMail);
         $this->body = _THISISAPMFROMSITE . " <a href=" . G_SERVERNAME . ">" . G_SERVERNAME . "</a><br />" . $this->body;
         $emailBody = str_replace('##EFRONTINNERLINK##', 'student', $this->body);
         if (($result = eF_mail($this->userData[$this->sender]['email'], $recipientsList, $this->subject, $emailBody, $this->attachments, false, $this->bcc)) !== true) {
             $this->errorMessage .= _THEMESSAGEWASNOTSENTASEMAIL . '<br/>';
         }
     }
     foreach ($this->recipients as $recipient) {
         $fields_insert = array("users_LOGIN" => $recipient, "recipient" => implode(", ", $this->recipients), "sender" => $this->sender, "timestamp" => $timestamp, "title" => $this->subject, "body" => $this->body, "bcc" => $this->bcc ? 1 : 0, "f_folders_ID" => $this->userData[$recipient]['folders']['Incoming'], "viewed" => 0);
         //It is not viewed yet
         if (!empty($this->attachments) && $this->attachments[0]) {
             if ($this->checkUserQuota($recipient)) {
                 $attachment = new EfrontFile($this->sender_attachment_fileId);
                 $recipient_dir = G_UPLOADPATH . $recipient . '/message_attachments/Incoming/' . $timestamp . '/';
                 mkdir($recipient_dir, 0755);
                 $newFile = $attachment->copy($recipient_dir, false, true);
                 $fields_insert["attachments"] = $newFile['id'];
             } else {
                 $fields_insert["body"] .= '<br /><span class="failure">' . _THEREWASATTACHMENTCUTBECAUSEOFQUOTA . '</span>';
             }
         }
         $id = eF_insertTableData("f_personal_messages", $fields_insert);
         EfrontSearch::insertText($fields_insert['body'], $id, "f_personal_messages", "data");
         EfrontSearch::insertText($fields_insert['title'], $id, "f_personal_messages", "title");
     }
     //it should not come here if sender has reached maximum space limit
     //if ($this -> checkUserQuota($this -> sender)) {
     $fields_insert = array("users_LOGIN" => $this->sender, "recipient" => implode(", ", $this->recipients), "sender" => $this->sender, "timestamp" => $timestamp, "title" => $this->subject, "body" => $this->body, "bcc" => $this->bcc ? 1 : 0, "f_folders_ID" => $this->userData[$this->sender]['folders']['Sent'], "viewed" => 0);
     if (!empty($this->attachments) && $this->attachments[0]) {
         $attachment = new EfrontFile($this->sender_attachment_fileId);
         $fields_insert["attachments"] = $this->sender_attachment_fileId;
     }
     $id = eF_insertTableData("f_personal_messages", $fields_insert);
     EfrontSearch::insertText($fields_insert['body'], $id, "f_personal_messages", "data");
     EfrontSearch::insertText($fields_insert['title'], $id, "f_personal_messages", "title");
     //} else {
     //    $this -> errorMessage .= _COULDNOTBECOPIEDTOYOURSENTBOX.' '._BECAUSEYOURMESSAGEBOXISFULL.'<br />';
     //}
     if ($this->errorMessage) {
         return false;
     } else {
         return true;
     }
 }
 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;
     }
 }
Пример #5
0
        $message = $e->getMessage() . ' (' . $e->getCode() . ') &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>';
    }
} else {
    if (isset($_GET['sent_notification_id']) && eF_checkParameter($_GET['sent_notification_id'], 'id')) {
        $sent_notification = eF_getTableData("sent_notifications", "*", "id = " . $_GET['sent_notification_id']);
        if (!empty($sent_notification)) {
            $notification = $sent_notification[0];
            // Get recipient's email
            $recipient = substr($notification['recipient'], 0, strpos($notification['recipient'], " "));
            // Check the format of the email
            if (substr($notification['body'], 0, 6) == "<html>") {
                $onlyText = false;
            } else {
                $onlyText = true;
            }
            if (eF_mail($GLOBALS['configuration']['system_email'], $recipient, $notification['subject'], $notification['body'], false, $onlyText)) {
                $sent_messages = 1;
            } else {
                $sent_messages = 0;
            }
        }
    } else {
        //debug();
        if (!$GLOBALS['configuration']['notifications_lock'] || time() - $GLOBALS['configuration']['notifications_lock'] > 600) {
            //10 minutes maximum lock time
            EFrontConfiguration::setValue('notifications_lock', time());
            $sent_messages = EfrontNotification::sendNextNotifications($GLOBALS['configuration']['notifications_messages_per_time']);
            EFrontConfiguration::setValue('notifications_lock', 0);
        } else {
            chdir($dir);
            echo "locked";
Пример #6
0
                $result = eF_getTableDataFlat("users JOIN users_to_groups ON users.login = users_to_groups.users_LOGIN", "distinct login, email", "users_to_groups.groups_ID = '" . $form->exportValue('group_recipients') . "'");
                break;
            default:
                break;
        }
        foreach ($result['email'] as $key => $value) {
            if (!eF_checkParameter($value, 'email')) {
                $message .= 'Notice: ' . _USER . ' ' . $result['login'][$key] . ' ' . _HASINVALIDEMAILADDRESS . ': ' . $value . '<br />';
                unset($result['email'][$key]);
            }
        }
        if (sizeof($result['email']) > 0) {
            $recipient = implode(", ", $result['email']);
            // Debug:
            //pr($result);
            $newresult = eF_mail($GLOBALS['configuration']['system_email'], $recipient, $form->exportValue('subject'), $form->exportValue('body'));
            if ($newresult == true) {
                $message .= _EMAILSENDAT . sizeof($result['email']) . ' ' . _USERS;
                $message_type = 'success';
            } else {
                //    $message     .= _EMAILCOULDNOTBESENDBECAUSE.': '.mb_substr($result -> getMessage(), 0, mb_strpos($result -> getMessage(), ':'));
                $message_type = 'failure';
            }
        }
    }
}
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
$form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
$form->setRequiredNote(_REQUIREDNOTE);
$form->accept($renderer);
$smarty->assign('T_EMAIL_FORM', $renderer->toArray());