Пример #1
0
function operatorSubmitted()
{
    $operator = Operator::getInstance()->GetLoggedOperator();
    $TML = new SmartyClass();
    setOperator($TML);
    $TML->assign('mode', 'profile');
    $toCheck = array('login' => 'form.field.login', 'fullname' => 'form.field.agent_name', 'email' => 'form.field.agent_email');
    foreach ($toCheck as $field => $res) {
        if (empty($_REQUEST[$field])) {
            $errors[] = Resources::Get("errors.required", array(Resources::Get($res)));
        }
    }
    if (empty($errors) && !preg_match("/^[\\w_]+\$/", $_REQUEST['login'])) {
        $errors[] = Resources::Get("page_agent.error.wrong_login");
    }
    if ($_REQUEST['password'] != $_REQUEST['password_confirm']) {
        $errors[] = Resources::Get('my_settings.error.password_match');
    }
    if (!empty($_REQUEST['password']) && md5($_REQUEST['password_existing']) != $operator['password']) {
        $errors[] = Resources::Get('my_settings.error.password_existing');
    }
    $hash = array();
    $requestFile = $_FILES['avatarFile'];
    if (empty($errors) && isset($requestFile) && !empty($requestFile['name']) && $requestFile['size'] > 0 && $requestFile['error'] == 0) {
        $res = Operator::getInstance()->UploadOperatorAvatar($operator['operatorid'], $requestFile);
        if (isset($res)) {
            $errors[] = $res;
        }
        if (empty($errors)) {
            $hash['avatar'] = Operator::getInstance()->getAvatarURL($operator['operatorid'], $requestFile['name']);
        }
    }
    if (empty($errors)) {
        $hash['login'] = $_REQUEST['login'];
        $hash['email'] = $_REQUEST['email'];
        $hash['fullname'] = $_REQUEST['fullname'];
        if (!empty($_REQUEST['password'])) {
            $hash['password'] = md5($_REQUEST['password']);
        }
        Operator::getInstance()->UpdateOperator($operator['operatorid'], $hash);
        Operator::getInstance()->RefreshSessionOperator();
        header("Location: " . WEBIM_ROOT . "/operator/profile.php");
        exit;
    }
    foreach (array('login', 'email', 'fullname') as $f) {
        $TML->assign($f, $_REQUEST[$f]);
    }
    $TML->assign('errors', $errors);
    $TML->display('../templates/operator.tpl');
    exit;
}
Пример #2
0
function operatorSubmitted()
{
    global $TML, $isNew;
    $valid_types = array("gif", "jpg", "png", "jpeg");
    $operator = Operator::getInstance()->GetLoggedOperator(false);
    setOperator();
    $toCheck = array('login' => 'form.field.login', 'fullname' => 'form.field.agent_name', 'email' => 'form.field.agent_email');
    if ($isNew) {
        $toCheck['password'] = '******';
    }
    foreach ($toCheck as $field => $res) {
        if (empty($_REQUEST[$field])) {
            $errors[] = Resources::Get("errors.required", array(Resources::Get($res)));
        }
    }
    if (empty($errors) && !preg_match("/^[\\w_\\.]+\$/", $_REQUEST['login'])) {
        $errors[] = Resources::Get("page_agent.error.wrong_login");
    }
    if ($_REQUEST['password'] != $_REQUEST['password_confirm']) {
        $errors[] = Resources::Get('my_settings.error.password_match');
    }
    if (empty($errors)) {
        $existingOperator = MapperFactory::getMapper("Operator")->getByLogin($_REQUEST['login']);
        $exists = !empty($existingOperator);
        if ($exists) {
            if ($isNew || !$isNew && $_REQUEST['operatorid'] != $existingOperator['operatorid']) {
                $errors[] = Resources::Get('page_agent.error.duplicate_login');
            }
        }
    }
    if (empty($errors) && !is_valid_email($_REQUEST['email'])) {
        $errors[] = Resources::Get('errors.email.format', array(Resources::Get('form.field.agent_email')));
    }
    $departments = array();
    foreach ($_REQUEST as $key => $value) {
        if (!preg_match("/^departments::(.+)\$/", $key, $matches)) {
            continue;
        }
        if (isset($_REQUEST[$key]) && $_REQUEST[$key] == 'on') {
            $departments[] = $matches[1];
        }
    }
    $locales = array();
    foreach ($_REQUEST as $key => $value) {
        if (!preg_match("/^locales::([a-z]{2})\$/", $key, $matches)) {
            continue;
        }
        if (isset($_REQUEST[$key]) && $_REQUEST[$key] == 'on') {
            $locales[] = $matches[1];
        }
    }
    // restore departments on the page
    $operator = Operator::getInstance()->GetLoggedOperator(false);
    $orig = MapperFactory::getMapper("OperatorDepartment")->enumDepartmentsWithOperator($operator['operatorid'], Resources::getCurrentLocale());
    $toAssign = array();
    foreach ($orig as $d) {
        $d['isindepartment'] = in_array($d['departmentid'], $departments);
        $toAssign[] = $d;
    }
    $TML->assign('departments', $toAssign);
    $orig_locales = getAvailableLocalesForChat();
    $to_assign_locales = array();
    foreach ($orig_locales as $d) {
        $d['ishaslocale'] = in_array($d['localeid'], $locales);
        $to_assign_locales[] = $d;
    }
    $TML->assign('locales', $to_assign_locales);
    $hash = array();
    if (empty($errors)) {
        $hash['login'] = $_REQUEST['login'];
        $hash['email'] = $_REQUEST['email'];
        $hash['fullname'] = $_REQUEST['fullname'];
        $hash['role'] = empty($_REQUEST['is_admin']) ? 'operator' : 'admin';
        $op_data_hash['locales'] = implode(",", $locales);
        $op_data_hash['locales'] = empty($op_data_hash['locales']) ? null : $op_data_hash['locales'];
        //Force mapper to set null for column in DB;
        if (!empty($_REQUEST['password'])) {
            $hash['password'] = md5($_REQUEST['password']);
        }
        $operatorToUpdateId = null;
        if ($isNew) {
            $operatorToUpdateId = MapperFactory::getMapper("Operator")->save($hash);
            MapperFactory::getMapper("Operator")->insertOperatorTime($operatorToUpdateId);
        } else {
            $operatorToUpdateId = $_REQUEST['operatorid'];
            $hash['operatorid'] = $operatorToUpdateId;
            MapperFactory::getMapper("Operator")->save($hash);
        }
        $op_data_hash['operatorid'] = $operatorToUpdateId;
        MapperFactory::getMapper("OperatorLastAccess")->save($op_data_hash);
        Operator::getInstance()->setOperatorDepartments($operatorToUpdateId, $departments);
        $requestFile = $_FILES['avatarFile'];
        if (empty($errors) && isset($requestFile) && !empty($requestFile['name']) && $requestFile['size'] > 0 && $requestFile['error'] == 0) {
            $res = Operator::getInstance()->UploadOperatorAvatar($operatorToUpdateId, $requestFile);
            if (!empty($res)) {
                $errors[] = $res;
            }
            if (empty($errors)) {
                $hash = array();
                $hash['avatar'] = Operator::getInstance()->getAvatarURL($operatorToUpdateId, $requestFile['name']);
                Operator::getInstance()->UpdateOperator($operatorToUpdateId, $hash);
            }
        }
        if (empty($errors)) {
            if ($operatorToUpdateId == $operator['operatorid']) {
                Operator::getInstance()->RefreshSessionOperator();
            }
            header("Location: " . AdminURL::getInstance()->getURL('operators'));
            exit;
        }
    }
    foreach (array('login', 'email', 'fullname', 'is_admin') as $f) {
        if (!empty($_REQUEST[$f])) {
            $TML->assign($f, $_REQUEST[$f]);
        }
    }
    $TML->assign('errors', $errors);
    $TML->display('operator.tpl');
    exit;
}
 function CreateAutoForward()
 {
     global $INTLIST, $CONFIG;
     $this->LoadForward(false, false);
     if (!($this->Forward != null && !$this->Forward->Processed)) {
         $allForwards = $this->GetForwards();
         $targets = array();
         setOperator();
         if (count($INTLIST) >= 2) {
             $forwardedToCount = array();
             foreach ($INTLIST as $opsysId => $ccount) {
                 $lastForwardToTime = $ccount;
                 foreach ($allForwards as $forward) {
                     if ($forward->TargetSessId == $opsysId) {
                         $lastForwardToTime = max($forward->Created, $lastForwardToTime);
                         if (!isset($forwardedToCount[$opsysId])) {
                             $forwardedToCount[$opsysId] = 0;
                         }
                         $forwardedToCount[$opsysId]++;
                     }
                 }
                 $targets[$opsysId] = $lastForwardToTime;
             }
             if (count($forwardedToCount) > 0) {
                 $forwardedToCount = min($forwardedToCount);
             } else {
                 $forwardedToCount = 0;
             }
             if (!empty($CONFIG["gl_mcfc"]) && is_numeric($CONFIG["gl_mcfc"])) {
                 if ($CONFIG["gl_mcfc"] <= $forwardedToCount) {
                     return false;
                 }
             }
             if (!empty($targets)) {
                 asort($targets);
                 foreach ($targets as $targetsysid => $time) {
                     if ($targetsysid != $this->DesiredChatPartner) {
                         $forward = new Forward($this->ChatId, $this->DesiredChatPartner);
                         $forward->InitiatorSystemId = $this->DesiredChatPartner;
                         $forward->ReceiverUserId = $this->UserId;
                         $forward->ReceiverBrowserId = $this->BrowserId;
                         $forward->TargetSessId = $targetsysid;
                         $forward->TargetGroupId = $this->DesiredChatGroup;
                         $forward->Invite = false;
                         $forward->Auto = true;
                         $forward->Save();
                         Chat::Destroy($this->ChatId);
                         return true;
                     }
                 }
             }
         } else {
             if (!empty($CONFIG["gl_mcfc"])) {
                 return false;
             }
         }
     }
     return true;
 }
function listen($_user, $init = false)
{
    global $CONFIG, $GROUPS, $INTERNAL, $USER, $INTLIST, $INTBUSY, $VOUCHER, $DEFAULT_BROWSER_LANGUAGE;
    $USER = $_user;
    if (!IS_FILTERED) {
        if (!empty($_POST["p_tid"])) {
            $VOUCHER = VisitorChat::GetMatchingVoucher(base64UrlDecode($_POST[POST_EXTERN_USER_GROUP]), base64UrlDecode($_POST["p_tid"]));
            if ($VOUCHER != null) {
                $USER->Browsers[0]->ChatVoucherId = $VOUCHER->Id;
            }
        }
        if (empty($USER->Browsers[0]->ChatId)) {
            $result = queryDB(true, "SELECT `visit_id` FROM `" . DB_PREFIX . DATABASE_VISITOR_BROWSERS . "` WHERE `visitor_id`='" . DBManager::RealEscape($USER->Browsers[0]->UserId) . "' AND `id`='" . DBManager::RealEscape($USER->Browsers[0]->BrowserId) . "' LIMIT 1;");
            if ($result && ($row = DBManager::FetchArray($result)) && $row["visit_id"] != $USER->Browsers[0]->VisitId && !empty($USER->Browsers[0]->VisitId)) {
                $USER->Browsers[0]->CloseChat(2);
                $USER->AddFunctionCall("lz_chat_set_status(lz_chat_data.STATUS_STOPPED);", false);
                $USER->AddFunctionCall("lz_chat_add_system_text(99,'" . base64_encode("Your browser session has expired (" . $row["visit_id"] . "-" . $USER->Browsers[0]->VisitId . "). Please close this browser instance and try again.") . "');", false);
                $USER->AddFunctionCall("lz_chat_stop_system();", false);
                return $USER;
            }
            $USER->Browsers[0]->SetChatId();
            $init = true;
        }
        if ($USER->Browsers[0]->Status == CHAT_STATUS_OPEN) {
            initData(array("INTERNAL"));
            if (!empty($_POST[POST_EXTERN_USER_GROUP]) && (empty($USER->Browsers[0]->DesiredChatGroup) || $init)) {
                $USER->Browsers[0]->DesiredChatGroup = base64UrlDecode($_POST[POST_EXTERN_USER_GROUP]);
            }
            $USER->Browsers[0]->SetCookieGroup();
            if (!setOperator() && $INTBUSY == 0) {
                $USER->AddFunctionCall("lz_chat_add_system_text(8,null);", false);
                $USER->AddFunctionCall("lz_chat_stop_system();", false);
            } else {
                if (count($INTLIST) + $INTBUSY > 0) {
                    $USER->AddFunctionCall("lz_chat_set_id('" . $USER->Browsers[0]->ChatId . "');", false);
                    $chatPosition = getQueuePosition($USER->UserId, $USER->Browsers[0]->DesiredChatGroup);
                    $chatWaitingTime = getQueueWaitingTime($chatPosition, $INTBUSY);
                    login();
                    $USER->Browsers[0]->SetWaiting(!($chatPosition == 1 && count($INTLIST) > 0 && !(!empty($USER->Browsers[0]->DesiredChatPartner) && $INTERNAL[$USER->Browsers[0]->DesiredChatPartner]->Status == USER_STATUS_BUSY)));
                    if (!$USER->Browsers[0]->Waiting) {
                        $USER->AddFunctionCall("lz_chat_show_connected();", false);
                        $USER->AddFunctionCall("lz_chat_set_status(lz_chat_data.STATUS_ALLOCATED);", false);
                        if ($CONFIG["gl_alloc_mode"] != ALLOCATION_MODE_ALL || !empty($USER->Browsers[0]->DesiredChatPartner)) {
                            $USER->Browsers[0]->CreateChat($INTERNAL[$USER->Browsers[0]->DesiredChatPartner], $USER, true);
                        } else {
                            $run = 0;
                            foreach ($INTLIST as $intid => $am) {
                                $USER->Browsers[0]->CreateChat($INTERNAL[$intid], $USER, false, "", "", true, $run++ == 0);
                            }
                        }
                    } else {
                        if (!empty($_GET["acid"])) {
                            $USER->AddFunctionCall("lz_chat_show_connected();", false);
                            $pchatid = base64UrlDecode($_GET["acid"]);
                            $result = queryDB(true, "SELECT * FROM `" . DB_PREFIX . DATABASE_VISITOR_CHATS . "` WHERE `visitor_id`='" . DBManager::RealEscape($USER->Browsers[0]->UserId) . "' AND `chat_id`='" . DBManager::RealEscape($pchatid) . "' AND (`exit` > " . (time() - 30) . " OR `exit`=0) LIMIT 1;");
                            if ($result && DBManager::GetRowCount($result) == 1) {
                                $row = DBManager::FetchArray($result);
                                if (!empty($row["waiting"])) {
                                    $posts = unserialize($row["queue_posts"]);
                                    foreach ($posts as $post) {
                                        $USER->AddFunctionCall("lz_chat_repost_from_queue('" . $post[0] . "');", false);
                                    }
                                    $USER->AddFunctionCall("lz_chat_data.QueuePostsAdded = true;", false);
                                }
                            }
                        }
                        if ($USER->Browsers[0]->IsMaxWaitingTime(true)) {
                            displayDeclined();
                            return $USER;
                        }
                        $pdm = getPredefinedMessage($GROUPS[$USER->Browsers[0]->DesiredChatGroup]->PredefinedMessages, $USER != null ? $USER->Language : "");
                        if ($pdm != null && !empty($pdm->QueueMessage) && time() - $USER->Browsers[0]->FirstActive > $pdm->QueueMessageTime && !$USER->Browsers[0]->QueueMessageShown) {
                            $USER->Browsers[0]->QueueMessageShown = true;
                            if (empty($_GET["acid"])) {
                                $USER->AddFunctionCall("lz_chat_add_system_text(99,'" . base64_encode($pdm->QueueMessage) . "');", false);
                            }
                        }
                        if (empty($_GET["acid"])) {
                            $USER->AddFunctionCall("lz_chat_show_queue_position(" . $chatPosition . "," . min($chatWaitingTime, 30) . ");", false);
                        }
                        $USER->Browsers[0]->CreateArchiveEntry(null, $USER);
                    }
                }
            }
        } else {
            $action = $USER->Browsers[0]->GetMaxWaitingTimeAction(false);
            if ($action == "MESSAGE" || $action == "FORWARD" && !$USER->Browsers[0]->CreateAutoForward()) {
                $USER->Browsers[0]->InternalDecline($USER->Browsers[0]->InternalUser->SystemId);
                displayDeclined();
            } else {
                if (!$USER->Browsers[0]->ArchiveCreated && !empty($USER->Browsers[0]->DesiredChatPartner)) {
                    $USER->Browsers[0]->CreateChat($INTERNAL[$USER->Browsers[0]->DesiredChatPartner], $USER, true);
                }
                activeListen();
            }
        }
        if ($USER->Browsers[0]->Status <= CHAT_STATUS_WAITING && empty($_POST["p_wls"])) {
            $USER->AddFunctionCall("lz_chat_show_waiting_links('" . base64_encode($wl = $GROUPS[$USER->Browsers[0]->DesiredChatGroup]->GetWaitingLinks($USER->Browsers[0]->Question, $DEFAULT_BROWSER_LANGUAGE)) . "');", false);
        }
    } else {
        displayFiltered();
    }
    return $USER;
}
Пример #5
0
function initChat()
{
    global $INTERNAL, $USER, $INTLIST, $INTBUSY, $CONFIG, $BOTMODE, $GROUPS;
    if (empty($USER->Browsers[0]->ChatId)) {
        $USER->Browsers[0]->SetChatId();
        $USER->AddFunctionCall("lz_closed=false;lz_chat_id='" . $USER->Browsers[0]->ChatId . "';", false);
    }
    if ($USER->Browsers[0]->Status == CHAT_STATUS_OPEN) {
        if (!empty($USER->Browsers[0]->InitChatWith)) {
            $USER->Browsers[0]->DesiredChatPartner = $USER->Browsers[0]->InitChatWith;
            $USER->AddFunctionCall("lz_chat_input_bot_state(false,false);", false);
        }
        if (!empty($USER->Browsers[0]->DesiredChatPartner) && $INTERNAL[$USER->Browsers[0]->DesiredChatPartner]->IsBot && !$BOTMODE) {
            $USER->Browsers[0]->DesiredChatPartner = null;
        }
        setOperator(0, null, true, $BOTMODE, $BOTMODE);
        if (count($INTLIST) + $INTBUSY > 0) {
            $chatPosition = getQueuePosition($USER->UserId, $USER->Browsers[0]->DesiredChatGroup);
            $USER->Browsers[0]->SetWaiting(!$BOTMODE && !($chatPosition == 1 && count($INTLIST) > 0 && !(!empty($USER->Browsers[0]->InternalUser) && $USER->Browsers[0]->InternalUser->Status == USER_STATUS_BUSY)));
            if (!$USER->Browsers[0]->Waiting) {
                if ($CONFIG["gl_alloc_mode"] != ALLOCATION_MODE_ALL || !empty($USER->Browsers[0]->DesiredChatPartner)) {
                    $USER->Browsers[0]->CreateChat($INTERNAL[$USER->Browsers[0]->DesiredChatPartner], $USER, true, "", "", false);
                } else {
                    foreach ($INTLIST as $intid => $am) {
                        $USER->Browsers[0]->CreateChat($INTERNAL[$intid], $USER, false, "", "", false);
                    }
                }
                $USER->Browsers[0]->LoadMembers();
                if (!empty($GROUPS[$USER->Browsers[0]->DesiredChatGroup]->PostHTML)) {
                    $USER->AddFunctionCall("lz_chat_add_html_element('" . base64_encode($GROUPS[$USER->Browsers[0]->DesiredChatGroup]->PostHTML) . "',null,null,null,null,null,null);", false);
                }
            } else {
                if ($USER->Browsers[0]->IsMaxWaitingTime(true)) {
                    $USER->AddFunctionCall("lz_chat_set_talk_to_human(false,false);lz_leave_message_required=true;", false);
                    $USER->Browsers[0]->UpdateUserStatus(false, false, true, false, false);
                }
                $USER->Browsers[0]->CreateArchiveEntry(null, $USER);
            }
        }
    } else {
        if (!$USER->Browsers[0]->ArchiveCreated && !empty($USER->Browsers[0]->DesiredChatPartner)) {
            $USER->Browsers[0]->CreateChat($INTERNAL[$USER->Browsers[0]->DesiredChatPartner], $USER, true);
        }
    }
}