示例#1
0
 function Set_sendMails($nf, $v, $arFields)
 {
     $I_Email = null;
     $U_Email = null;
     if (!$v->isNew) {
         $U_Email = "Y";
     } else {
         $I_Email = "Y";
     }
     IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/support/classes/general/messages.php", $v->arrSite["LANGUAGE_ID"]);
     $mf = self::GetCSupportTableFields("EventFields");
     $mf->ADMIN_EDIT_URL = "/bitrix/admin/ticket_edit.php";
     $mf->LANGUAGE = $v->arrSite["LANGUAGE_ID"];
     $mf->LANGUAGE_ID = $v->arrSite["LANGUAGE_ID"];
     $arrSet = array("ID" => "ID", "DATE_CREATE" => "DATE_CREATE", "TIMESTAMP" => "TIMESTAMP_X", "DATE_CLOSE" => "DATE_CLOSE", "TITLE" => "TITLE", "CATEGORY" => "CATEGORY_NAME", "CRITICALITY" => "CRITICALITY_NAME", "DIFFICULTY" => "DIFFICULTY_NAME", "STATUS" => "STATUS_NAME", "SLA" => "SLA_NAME", "OWNER_USER_ID" => "OWNER_USER_ID", "OWNER_GUEST_ID" => "OWNER_GUEST_ID", "OWNER_SID" => "OWNER_SID", "OWNER_USER_NAME" => "OWNER_NAME", "OWNER_USER_LOGIN" => "OWNER_LOGIN", "OWNER_USER_EMAIL" => "OWNER_EMAIL", "RESPONSIBLE_USER_ID" => "RESPONSIBLE_USER_ID", "RESPONSIBLE_USER_NAME" => "RESPONSIBLE_NAME", "RESPONSIBLE_USER_LOGIN" => "RESPONSIBLE_LOGIN", "RESPONSIBLE_USER_EMAIL" => "RESPONSIBLE_EMAIL", "CREATED_USER_ID" => "CREATED_USER_ID", "CREATED_GUEST_ID" => "CREATED_GUEST_ID", "CREATED_USER_LOGIN" => "CREATED_LOGIN", "CREATED_USER_EMAIL" => "CREATED_EMAIL", "CREATED_USER_NAME" => "CREATED_NAME");
     if (!$v->isNew) {
         $arrSet["MODIFIED_USER_ID"] = "MODIFIED_USER_ID";
         $arrSet["MODIFIED_GUEST_ID"] = "MODIFIED_GUEST_ID";
         $arrSet["MODIFIED_USER_LOGIN"] = "******";
         $arrSet["MODIFIED_USER_EMAIL"] = "MODIFIED_EMAIL";
         $arrSet["MODIFIED_USER_NAME"] = "MODIFIED_NAME";
         $arrSet["RATE"] = "MARK_NAME";
         $arrSet["MESSAGES_AMOUNT"] = "MESSAGES";
     }
     $mf->FromArray((array) $nf, $arrSet);
     $arUserIDs = array($mf->OWNER_USER_ID, $mf->CREATED_USER_ID, $mf->MODIFIED_USER_ID, $mf->RESPONSIBLE_USER_ID);
     $arGuestIDs = array($mf->OWNER_GUEST_ID, $mf->CREATED_GUEST_ID, $mf->MODIFIED_GUEST_ID);
     $arStrUsers = CTicket::GetUsersPropertiesArray($arUserIDs, $arGuestIDs);
     // set name, login, email
     $userCategories = array('OWNER', 'RESPONSIBLE', 'CREATED');
     if (!$v->isNew) {
         $userCategories[] = 'MODIFIED';
     }
     foreach ($userCategories as $userCategory) {
         $propertyId = $userCategory . '_USER_ID';
         if ($mf->{$propertyId} > 0 && isset($arStrUsers['arUsers'][$mf->{$propertyId}])) {
             $name = CUser::FormatName(CSite::GetNameFormat(), $arStrUsers['arUsers'][$mf->{$propertyId}], true, true);
             $propertyName = $userCategory . '_USER_NAME';
             $mf->{$propertyName} = $name;
             $propertyLogin = $userCategory . '_USER_LOGIN';
             $mf->{$propertyLogin} = $arStrUsers['arUsers'][$mf->{$propertyId}]['LOGIN'];
             $propertyEmail = $userCategory . '_USER_EMAIL';
             $mf->{$propertyEmail} = $arStrUsers['arUsers'][$mf->{$propertyId}]['EMAIL'];
         }
     }
     $mf->FILES_LINKS = self::Set_getFilesLinks($v->arrFILES, $v->arrSite["LANGUAGE_ID"]);
     $mf->IMAGE_LINK = $mf->FILES_LINKS;
     $mf->MESSAGE_BODY = PrepareTxtForEmail($arFields["MESSAGE"], $v->arrSite["LANGUAGE_ID"], false, false);
     // сформируем email автора
     // Событие: "TICKET_CHANGE_BY_AUTHOR_FOR_AUTHOR"	- #DEFAULT_EMAIL_FROM# -> #OWNER_EMAIL# (Обращение изменено автором (для автора))
     // Событие: "TICKET_CHANGE_BY_SUPPORT_FOR_AUTHOR"	- #DEFAULT_EMAIL_FROM# -> #OWNER_EMAIL# (Обращение изменено сотрудником техподдержки (для автора))
     // Событие: "TICKET_NEW_FOR_AUTHOR"					- #DEFAULT_EMAIL_FROM# -> #OWNER_EMAIL# (Новое обращение (для автора))
     $ownerEmail = "";
     if ($mf->OWNER_USER_ID > 0 && isset($arStrUsers["arUsers"][$mf->OWNER_USER_ID])) {
         $ownerEmail = $arStrUsers["arUsers"][$mf->OWNER_USER_ID]["EMAIL"];
     } elseif ($mf->OWNER_GUEST_ID > 0 && isset($arStrUsers["arGuests"][$mf->OWNER_GUEST_ID])) {
         $ownerEmail = $arStrUsers["arGuests"][$mf->OWNER_GUEST_ID]["EMAIL"];
     }
     $arrOwnerEmails = self::EmailsFromStringToArray($mf->OWNER_SID, array($ownerEmail));
     if (intval($mf->OWNER_USER_ID) > 0) {
         $rs = CTicket::GetResponsibleList($mf->OWNER_USER_ID, $I_Email, $U_Email);
         while ($arr0 = $rs->Fetch()) {
             if (strlen($arr0['EMAIL']) > 0) {
                 $arrOwnerEmails[] = $arr0['EMAIL'];
             }
         }
     }
     $mf->OWNER_EMAIL = implode(", ", array_unique($arrOwnerEmails));
     // выбираем административные email'ы
     $arrAdminEMails = CTicket::GetAdminEmails();
     if (!is_array($arrAdminEMails)) {
         $arrAdminEMails = array();
     }
     TrimArr($arrAdminEMails);
     // сформируем email техподдержки
     // Событие: "TICKET_OVERDUE_REMINDER"				- #DEFAULT_EMAIL_FROM# -> #SUPPORT_EMAIL# (Напоминание о необходимости ответа (для техподдержки))
     // Событие: "TICKET_CHANGE_FOR_TECHSUPPORT"			- #DEFAULT_EMAIL_FROM# -> #SUPPORT_EMAIL# (Изменения в обращении (для техподдержки))
     // Событие: "TICKET_NEW_FOR_TECHSUPPORT"			- #DEFAULT_EMAIL_FROM# -> #SUPPORT_EMAIL# (Новое обращение (для техподдержки))
     $arrSupportEmails = array();
     if ($mf->RESPONSIBLE_USER_ID > 0 && isset($arStrUsers["arUsers"][$mf->RESPONSIBLE_USER_ID])) {
         $arrSupportEmails[] = $arStrUsers["arUsers"][$mf->RESPONSIBLE_USER_ID]["EMAIL"];
         // из группы ответсвенного, выбираем всех пользователей кто имеет доступ к рассылке
         $rs = CTicket::GetResponsibleList($mf->RESPONSIBLE_USER_ID, $I_Email, $U_Email, "Y");
         while ($arr0 = $rs->Fetch()) {
             if (strlen($arr0['EMAIL']) > 0) {
                 $arrSupportEmails[] = $arr0['EMAIL'];
             }
         }
     }
     if (count($arrSupportEmails) <= 0) {
         $arrSupportEmails = $arrAdminEMails;
     }
     if (count($arrSupportEmails) <= 0) {
         $se = COption::GetOptionString("main", "email_from", "");
         if (strlen($se) > 0) {
             $arrSupportEmails[] = $se;
         }
     }
     TrimArr($arrSupportEmails);
     $mf->SUPPORT_EMAIL = count($arrSupportEmails) > 0 ? TrimEx(implode(",", array_unique($arrSupportEmails)), ",") : "";
     // удалим продублированные адреса из макроса #SUPPORT_ADMIN_EMAIL#
     if (count($arrSupportEmails) > 0) {
         foreach ($arrSupportEmails as $e) {
             unset($arrAdminEMails[$e]);
         }
     }
     $mf->SUPPORT_ADMIN_EMAIL = count($arrAdminEMails) > 0 ? TrimEx(implode(",", $arrAdminEMails), ",") : "";
     if (array_key_exists('PUBLIC_EDIT_URL', $arFields) && strlen($arFields['PUBLIC_EDIT_URL']) > 0) {
         $mf->PUBLIC_EDIT_URL = $arFields['PUBLIC_EDIT_URL'];
     } else {
         $peurl = COption::GetOptionString("support", "SUPPORT_DIR");
         $peurl = str_replace("#LANG_DIR#", $v->arrSite["DIR"], $peurl);
         // совместимость
         $peurl = str_replace("#SITE_DIR#", $v->arrSite["DIR"], $peurl);
         $peurl = str_replace("\\", "/", $peurl);
         $peurl = str_replace("//", "/", $peurl);
         $peurl = TrimEx($peurl, "/");
         $mf->PUBLIC_EDIT_URL = "/" . $peurl . "/" . COption::GetOptionString("support", "SUPPORT_EDIT");
     }
     $mf->SUPPORT_COMMENTS = PrepareTxtForEmail($arFields["SUPPORT_COMMENTS"], $v->arrSite["LANGUAGE_ID"]);
     if (strlen($mf->SUPPORT_COMMENTS) > 0) {
         $mf->SUPPORT_COMMENTS = "\n\n" . $mf->SUPPORT_COMMENTS . "\n";
     }
     $mf->SOURCE = strlen($nf->SOURCE_NAME) <= 0 ? "" : "[" . $nf->SOURCE_NAME . "] ";
     $oUID = intval($mf->OWNER_USER_ID);
     $oGID = intval($mf->OWNER_GUEST_ID);
     if ($oGID > 0) {
         $mf->OWNER_TEXT = $arStrUsers["arGuests"][$oGID]["HTML_NAME_S"];
         if ($oUID > 0) {
             $mf->OWNER_TEXT .= self::addSupportText($oUID);
         }
     } elseif ($oUID > 0) {
         $mf->OWNER_TEXT = $arStrUsers["arUsers"][$oUID]["HTML_NAME_S"];
         $mf->OWNER_TEXT .= self::addSupportText($oUID);
     }
     if (strlen(trim($mf->OWNER_SID)) > 0 && $mf->OWNER_SID != null) {
         $mf->OWNER_TEXT = " / " . $mf->OWNER_TEXT;
     }
     if ($nf->CREATED_MODULE_NAME == "support" || strlen($nf->CREATED_MODULE_NAME) <= 0) {
         $cUID = intval($mf->CREATED_USER_ID);
         $cGID = intval($mf->CREATED_GUEST_ID);
         if ($cGID > 0) {
             $mf->CREATED_TEXT = $arStrUsers["arGuests"][$cGID]["HTML_NAME_S"];
         } elseif ($cUID > 0) {
             $mf->CREATED_TEXT = $arStrUsers["arUsers"][$cUID]["HTML_NAME_S"];
         }
     } else {
         $mf->CREATED_MODULE_NAME = "[" . $nf->CREATED_MODULE_NAME . "]";
     }
     $rUID = intval($mf->RESPONSIBLE_USER_ID);
     if ($rUID > 0) {
         $mf->RESPONSIBLE_TEXT = $arStrUsers["arUsers"][$rUID]["HTML_NAME_S"];
         $mf->RESPONSIBLE_TEXT .= self::addSupportText($rUID);
     }
     /*
     if($mf->OWNER_USER_ID > 0 || strlen(trim($mf->OWNER_USER_LOGIN)) > 0)
     {
     	$mf->OWNER_TEXT = "[" . $mf->OWNER_USER_ID . "] (" . $mf->OWNER_USER_LOGIN . ") " . $mf->OWNER_USER_NAME;
     	if(strlen(trim($mf->OWNER_SID)) > 0 && $mf->OWNER_SID != null) $mf->OWNER_TEXT = " / " . $mf->OWNER_TEXT;
     	$mf->OWNER_TEXT .= self::addSupportText($mf->OWNER_USER_ID);
     }
     
     if($nf->CREATED_MODULE_NAME == "support")
     {
     	$mf->CREATED_MODULE_NAME = "";
     	if($mf->CREATED_USER_ID > 0)
     	{
     		$mf->CREATED_TEXT = "[" . $mf->CREATED_USER_ID . "] (" . $mf->CREATED_USER_LOGIN . ") " . $mf->CREATED_USER_NAME . self::addSupportText($mf->CREATED_USER_ID);
     	}
     }
     else
     {
     	$mf->CREATED_MODULE_NAME = "[" . $nf->CREATED_MODULE_NAME . "]";
     }
     
     if($mf->RESPONSIBLE_USER_ID > 0)
     {
     	$mf->RESPONSIBLE_TEXT = "[" . $mf->RESPONSIBLE_USER_ID . "] (" . $nf->RESPONSIBLE_LOGIN . ") " . $nf->RESPONSIBLE_NAME;
     	$mf->RESPONSIBLE_TEXT .= self::addSupportText($mf->RESPONSIBLE_USER_ID);
     }
     */
     if (!$v->isNew) {
         /*
         if($nf->MODIFIED_MODULE_NAME == "support" && strlen($nf->MODIFIED_MODULE_NAME) > 0)
         {
         	$mf->MODIFIED_MODULE_NAME = "";
         	if($mf->MODIFIED_USER_ID > 0)
         	{
         		$mf->MODIFIED_TEXT = "[" . $mf->MODIFIED_USER_ID . "] (" . $mf->MODIFIED_USER_LOGIN . ") " . $mf->MODIFIED_USER_NAME;
         		$mf->MODIFIED_TEXT .= self::addSupportText($mf->MODIFIED_USER_ID);
         	}
         }
         else $mf->MODIFIED_MODULE_NAME = "[" . $nf->MODIFIED_MODULE_NAME . "]";
         */
         if ($nf->MODIFIED_MODULE_NAME == "support" || strlen($nf->MODIFIED_MODULE_NAME) <= 0) {
             $rUID = intval($mf->MODIFIED_USER_ID);
             $rGID = intval($mf->MODIFIED_GUEST_ID);
             if ($rGID > 0) {
                 $mf->MODIFIED_TEXT = $arStrUsers["arGuests"][$rGID]["HTML_NAME_S"];
                 if ($rUID > 0) {
                     $mf->MODIFIED_TEXT .= self::addSupportText($rUID);
                 }
             } elseif ($rUID > 0) {
                 $mf->MODIFIED_TEXT = $arStrUsers["arUsers"][$rUID]["HTML_NAME_S"];
                 $mf->MODIFIED_TEXT .= self::addSupportText($rUID);
             }
         } else {
             $mf->MODIFIED_MODULE_NAME = "[" . $nf->MODIFIED_MODULE_NAME . "]";
         }
         $mf->MESSAGE_SOURCE = "";
         if ($rsSource = CTicketDictionary::GetByID($arFields["MESSAGE_SOURCE_ID"])) {
             $arSource = $rsSource->Fetch();
             $mf->MESSAGE_SOURCE = array_key_exists("NAME", $arSource) && strlen($arSource["NAME"]) > 0 ? "[" . $arSource["NAME"] . "] " : "";
         }
         if ((strlen(trim($arFields["MESSAGE_AUTHOR_SID"])) > 0 || intval($arFields["MESSAGE_AUTHOR_USER_ID"]) > 0) && $v->bSupportTeam) {
             $mf->MESSAGE_AUTHOR_USER_ID = $arFields["MESSAGE_AUTHOR_USER_ID"];
             $mf->MESSAGE_AUTHOR_SID = $arFields["MESSAGE_AUTHOR_SID"];
         } else {
             $mf->MESSAGE_AUTHOR_USER_ID = $v->uid;
         }
         $arMA = array();
         if ($rsMA = CUser::GetByID($mf->MESSAGE_AUTHOR_USER_ID)) {
             $arMA = $rsMA->Fetch();
         }
         if ($mf->MESSAGE_AUTHOR_USER_ID > 0 || strlen(trim($arMA["LOGIN"])) > 0) {
             $mf->MESSAGE_AUTHOR_TEXT = "[" . $mf->MESSAGE_AUTHOR_USER_ID . "] (" . $arMA["LOGIN"] . ") " . $arMA["NAME"] . " " . $arMA["LAST_NAME"];
             if (strlen(trim($arFields["MESSAGE_AUTHOR_SID"])) > 0) {
                 $mf->MESSAGE_AUTHOR_TEXT = " / " . $mf->MESSAGE_AUTHOR_TEXT;
             }
             if ($mf->MESSAGE_AUTHOR_USER_ID > 0) {
                 $mf->MESSAGE_AUTHOR_TEXT .= self::addSupportText($mf->MESSAGE_AUTHOR_USER_ID);
             }
         }
         if (strlen(trim($arMA["NAME"])) > 0 || strlen(trim($arMA["LAST_NAME"])) > 0) {
             $mf->MESSAGE_AUTHOR_USER_NAME = trim($arMA["NAME"]) . " " . trim($arMA["LAST_NAME"]);
         }
         if (strlen(trim($arMA["LOGIN"])) > 0) {
             $mf->MESSAGE_AUTHOR_USER_LOGIN = $arMA["LOGIN"];
         }
         if (strlen(trim($arMA["EMAIL"])) > 0) {
             $mf->MESSAGE_AUTHOR_USER_EMAIL = $arMA["EMAIL"];
         }
         $mf->MESSAGE_HEADER = str_repeat("=", 23) . " " . GetMessage("SUP_MAIL_MESSAGE") . " " . str_repeat("=", 34);
     }
     $mf->SPAM_MARK = "";
     if (strlen($nf->IS_SPAM) > 0) {
         if ($nf->IS_SPAM == "Y") {
             $mf->SPAM_MARK = "\n" . GetMessage("SUP_EXACTLY_SPAM") . "\n";
         } else {
             $mf->SPAM_MARK = "\n" . GetMessage("SUP_POSSIBLE_SPAM") . "\n";
         }
     }
     self::Set_WriteLog($nf, $v, $mf);
     //$v  +change, +change_hidden
     if (!$v->isNew) {
         $mf->MESSAGE_FOOTER = str_repeat("=", strlen($mf->MESSAGE_HEADER));
     }
     if ($v->isNew && $v->bActiveCoupon) {
         $mf->COUPON = $v->V_COUPON;
     }
     $arEventFields_author = $mf->ToArray(CSupportTableFields::ALL);
     //, array(CSupportTableFields::NOT_NULL)
     $arEventFields_support = $arEventFields_author;
     // отсылаем письмо автору
     if ($v->SEND_EMAIL_TO_AUTHOR == "Y" && ($v->isNew || strlen($v->change) > 0)) {
         $EventType = "TICKET_NEW_FOR_AUTHOR";
         if (!$v->isNew) {
             // HIDDEN
             if ($arFields["HIDDEN"] == "Y") {
                 $arrUnsetHidden = array("MESSAGE_BODY", "IMAGE_LINK");
                 foreach ($arrUnsetHidden as $value) {
                     $arEventFields_author[$value] = "";
                 }
             }
             $EventType = "TICKET_CHANGE_BY_AUTHOR_FOR_AUTHOR";
             if (CTicket::IsSupportTeam($mf->MESSAGE_AUTHOR_USER_ID) || CTicket::IsAdmin($mf->MESSAGE_AUTHOR_USER_ID)) {
                 $EventType = "TICKET_CHANGE_BY_SUPPORT_FOR_AUTHOR";
             }
         }
         $arEventFields_author = CTicket::ExecuteEvents('OnBeforeSendMailToAuthor', $arEventFields_author, $v->isNew, $EventType);
         if ($arEventFields_author) {
             CEvent::Send($EventType, $v->arrSite["ID"], $arEventFields_author);
         }
     }
     // отсылаем письмо техподдержке
     if ($v->SEND_EMAIL_TO_TECHSUPPORT == "Y" && ($v->isNew || strlen($v->change) > 0 || strlen($v->change_hidden) > 0)) {
         $EventType = "TICKET_NEW_FOR_TECHSUPPORT";
         if (!$v->isNew) {
             $arEventFields_support["WHAT_CHANGE"] .= $v->change_hidden;
             $EventType = "TICKET_CHANGE_FOR_TECHSUPPORT";
         }
         $arEventFields_support = CTicket::ExecuteEvents('OnBeforeSendMailToSupport', $arEventFields_support, $v->isNew);
         if ($arEventFields_support) {
             CEvent::Send($EventType, $v->arrSite["ID"], $arEventFields_support);
         }
     }
 }
示例#2
0
				//"WARNING"=>"Y",
				"ACTION"=>"if(confirm('".GetMessage('SUP_DELETE_TICKET_CONF')."')) ".$lAdmin->ActionDoGroup($f_ID, "delete"),
				);
		}
	}


	$row->AddActions($arActions);

	$arRows[] = $arRow;
}

//$arUsersPref = array("RESPONSIBLE", "OWNER", "CREATED", "MODIFIED");
//$arGuestsPref = array("OWNER", "CREATED", "MODIFIED");

$arStrUsersM = CTicket::GetUsersPropertiesArray($aUserIDs,$arGuestIDs);
foreach($arRows as $k => $v)
{
	$rUserID = intval($v["arFields"]["RESPONSIBLE_USER_ID"]);
	$info2Html = '';
	$postFixS = ($bADS ? "" : "_S");
	if($bADS && $rUserID > 0)
	{
		$info2Html .= $arStrUsersM["arUsers"][$rUserID]["HTML_NAME"] . "<br>";
	}
	$v["objRow"]->AddViewField("RESPONSIBLE_USER_ID", $info2Html);


	$dateCreateHtml = $v["arFields"]["t_DATE_CREATE_HTML"];
	$oUserID = intval($v["arFields"]["OWNER_USER_ID"]);
	$oGuestID = intval($v["arFields"]["OWNER_GUEST_ID"]);