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 CreateAutoForward($_user)
 {
     $this->LoadForward(false, false);
     if (!($this->Forward != null && !$this->Forward->Processed)) {
         $allForwards = $this->GetForwards();
         $targets = array();
         $this->FindOperator(VisitorChat::$Router, $_user, false, false, array($this->DesiredChatPartner => $this->DesiredChatPartner), false);
         $isTargetAvailable = count(VisitorChat::$Router->OperatorsAvailable) >= 2 || count(VisitorChat::$Router->OperatorsAvailable) == 1 && !empty($this->DesiredChatPartner) && !isset(VisitorChat::$Router->OperatorsAvailable[$this->DesiredChatPartner]);
         if ($isTargetAvailable) {
             $forwardedToCount = array();
             foreach (VisitorChat::$Router->OperatorsAvailable 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(Server::$Configuration->File["gl_mcfc"]) && is_numeric(Server::$Configuration->File["gl_mcfc"])) {
                 if (Server::$Configuration->File["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();
                         $this->ArchiveCreated = 2;
                         Chat::Destroy($this->ChatId);
                         return true;
                     }
                 }
             }
         }
     }
     return true;
 }