canReopen() public static method

public static canReopen ( erLhcoreClassModelChat $chat, $skipStatusCheck = false )
$chat erLhcoreClassModelChat
Beispiel #1
0
    } catch (Exception $e) {
    }
} else {
    $defaultTheme = erLhcoreClassModelChatConfig::fetch('default_theme_id')->current_value;
    if ($defaultTheme > 0) {
        try {
            $theme = erLhAbstractModelWidgetTheme::fetch($defaultTheme);
            $Result['theme'] = $theme;
            $modeAppendTheme = '/(theme)/' . $theme->id;
        } catch (Exception $e) {
        }
    }
}
try {
    $chat = erLhcoreClassChat::getSession()->load('erLhcoreClassModelChat', $Params['user_parameters']['chat_id']);
    if ($chat->hash == $Params['user_parameters']['hash'] && erLhcoreClassChat::canReopen($chat, true)) {
        // Is IP blocked directly?
        if (erLhcoreClassModelChatBlockedUser::getCount(array('filter' => array('ip' => erLhcoreClassIPDetect::getIP()))) > 0) {
            header('Location: ' . $_SERVER['HTTP_REFERER']);
            exit;
        }
        /**
         * is IP range blocked
         * */
        $ignorable_ip = erLhcoreClassModelChatConfig::fetch('banned_ip_range')->current_value;
        if ($ignorable_ip != '' && erLhcoreClassIPDetect::isIgnored(erLhcoreClassIPDetect::getIP(), explode(',', $ignorable_ip))) {
            header('Location: ' . $_SERVER['HTTP_REFERER']);
            exit;
        }
        if ($chat->status != erLhcoreClassModelChat::STATUS_ACTIVE_CHAT && $chat->status != erLhcoreClassModelChat::STATUS_PENDING_CHAT) {
            if (erLhcoreClassModelChatConfig::fetch('reopen_as_new')->current_value == 1 || $chat->user_id == 0) {
    ?>
</h4>
		<?php 
} else {
    ?>
			<h4><?php 
    echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chat', 'Pending confirm');
    ?>
</h4>
		<?php 
}
?>
		</div>
				
		<?php 
if (erLhcoreClassModelChatConfig::fetch('reopen_chat_enabled')->current_value == 1 && erLhcoreClassModelChatConfig::fetch('allow_reopen_closed')->current_value == 1 && erLhcoreClassChat::canReopen($chat)) {
    ?>
			<a href="<?php 
    echo erLhcoreClassDesign::baseurl('chat/reopen');
    ?>
/<?php 
    echo $chat->id;
    ?>
/<?php 
    echo $chat->hash;
    if (isset($chat_widget_mode) && $chat_widget_mode == true) {
        ?>
/(mode)/widget<?php 
    }
    if (isset($chat_embed_mode) && $chat_embed_mode == true) {
        ?>
<?php

/**
 * Override
 * */
try {
    $chat = erLhcoreClassChat::getSession()->load('erLhcoreClassModelChat', $Params['user_parameters']['chat_id']);
} catch (Exception $e) {
    $chat = false;
}
if ((int) erLhcoreClassModelChatConfig::fetch('disable_send')->current_value == 1) {
    exit;
}
if (is_object($chat) && $chat->hash == $Params['user_parameters']['hash'] && ($chat->status == erLhcoreClassModelChat::STATUS_ACTIVE_CHAT || erLhcoreClassChat::canReopen($chat, true))) {
    if (ezcInputForm::hasPostData()) {
        $definition = array('email' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'validate_email'));
        $form = new ezcInputForm(INPUT_POST, $definition);
        $Errors = array();
        if (!$form->hasValidData('email')) {
            $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('user/edit', 'Wrong email address');
        }
        if (!isset($_SERVER['HTTP_X_CSRFTOKEN']) || !isset($_POST['csfr_token']) || $_POST['csfr_token'] != $_SERVER['HTTP_X_CSRFTOKEN']) {
            $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('user/edit', 'Invalid CSRF token!');
        }
        if (empty($Errors)) {
            $tpl = erLhcoreClassTemplate::getInstance('lhchat/sendmail.tpl.php');
            $mailTemplate = erLhAbstractModelEmailTemplate::fetch(3);
            erLhcoreClassChatMail::prepareSendMail($mailTemplate);
            $mailTemplate->recipient = $form->email;
            $messages = array_reverse(erLhcoreClassModelmsg::getList(array('customfilter' => array('user_id != -1'), 'limit' => 500, 'sort' => 'id DESC', 'filter' => array('chat_id' => $chat->id))));
            // Fetch chat messages
<?php

$tpl = erLhcoreClassTemplate::getInstance('lhchat/chatpreview.tpl.php');
try {
    $chat = erLhcoreClassChat::getSession()->load('erLhcoreClassModelChat', $Params['user_parameters']['chat_id']);
    if ($chat->hash == $Params['user_parameters']['hash'] && ($chat->status == erLhcoreClassModelChat::STATUS_ACTIVE_CHAT || erLhcoreClassChat::canReopen($chat, true) || $chat->status == erLhcoreClassModelChat::STATUS_CLOSED_CHAT && $chat->time > time() - 1800)) {
        erLhcoreClassChat::setTimeZoneByChat($chat);
        $tpl->set('chat', $chat);
    } else {
        $tpl->setFile('lhchat/errors/chatnotexists.tpl.php');
    }
} catch (Exception $e) {
    $tpl->setFile('lhchat/errors/chatnotexists.tpl.php');
}
echo $tpl->fetch();
exit;