function WF_SetMove($NEW_ID, $OLD_ID = 0) { if (CModule::IncludeModule("workflow")) { $err_mess = "FILE: " . __FILE__ . "<br>LINE: "; global $DB, $USER; $USER_ID = is_object($USER) ? intval($USER->GetID()) : 0; $NEW = "Y"; $OLD_ID = intval($OLD_ID); $NEW_ID = intval($NEW_ID); if ($OLD_ID > 0) { $old = $DB->Query("SELECT WF_STATUS_ID FROM b_iblock_element WHERE ID = " . $OLD_ID, false, $err_mess . __LINE__); if ($old_r = $old->Fetch()) { $NEW = "N"; } } CTimeZone::Disable(); $new = CIBlockElement::GetByID($NEW_ID); CTimeZone::Enable(); if ($new_r = $new->Fetch()) { $NEW_STATUS_ID = intval($new_r["WF_STATUS_ID"]); $OLD_STATUS_ID = intval($old_r["WF_STATUS_ID"]); $PARENT_ID = intval($new_r["WF_PARENT_ELEMENT_ID"]); CTimeZone::Disable(); $parent = CIBlockElement::GetByID($PARENT_ID); CTimeZone::Enable(); if ($parent_r = $parent->Fetch()) { $arFields = array("TIMESTAMP_X" => $DB->GetNowFunction(), "IBLOCK_ELEMENT_ID" => $PARENT_ID, "OLD_STATUS_ID" => $OLD_STATUS_ID, "STATUS_ID" => $NEW_STATUS_ID, "USER_ID" => $USER_ID); $DB->Insert("b_workflow_move", $arFields, $err_mess . __LINE__); if ($NEW_STATUS_ID != $OLD_STATUS_ID) { // Get creator Email $strSql = "SELECT EMAIL FROM b_user WHERE ID = " . intval($parent_r["CREATED_BY"]); $rs = $DB->Query($strSql, false, $err_mess . __LINE__); if ($ar = $rs->Fetch()) { $parent_r["CREATED_BY_EMAIL"] = $ar["EMAIL"]; } else { $parent_r["CREATED_BY_EMAIL"] = ""; } // gather email of the workflow admins $WORKFLOW_ADMIN_GROUP_ID = intval(COption::GetOptionString("workflow", "WORKFLOW_ADMIN_GROUP_ID")); $strSql = "\n\t\t\t\t\t\t\tSELECT U.ID, U.EMAIL\n\t\t\t\t\t\t\tFROM b_user U, b_user_group UG\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tUG.GROUP_ID=" . $WORKFLOW_ADMIN_GROUP_ID . "\n\t\t\t\t\t\t\t\tAND U.ID = UG.USER_ID\n\t\t\t\t\t\t\t\tAND U.ACTIVE='Y'\n\t\t\t\t\t\t"; $rs = $DB->Query($strSql, false, $err_mess . __LINE__); $arAdmin = array(); while ($ar = $rs->Fetch()) { $arAdmin[$ar["ID"]] = $ar["EMAIL"]; } // gather email for BCC $arBCC = array(); // gather all who changed doc in its current status $strSql = "\n\t\t\t\t\t\t\tSELECT U.EMAIL\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\tb_workflow_move WM\n\t\t\t\t\t\t\t\tINNER JOIN b_user U on U.ID = WM.USER_ID\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tIBLOCK_ELEMENT_ID = " . $PARENT_ID . "\n\t\t\t\t\t\t\t\tAND OLD_STATUS_ID = " . $NEW_STATUS_ID . "\n\t\t\t\t\t\t"; $rs = $DB->Query($strSql, false, $err_mess . __LINE__); while ($ar = $rs->Fetch()) { $arBCC[$ar["EMAIL"]] = $ar["EMAIL"]; } // gather all editors // in case status have notifier flag //First those who have write permissions on iblock $strSql = "\n\t\t\t\t\t\t\tSELECT U.EMAIL\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\tb_workflow_status S\n\t\t\t\t\t\t\t\tINNER JOIN b_workflow_status2group SG on SG.STATUS_ID = S.ID\n\t\t\t\t\t\t\t\tINNER JOIN b_iblock_group IG on IG.GROUP_ID = SG.GROUP_ID\n\t\t\t\t\t\t\t\tINNER JOIN b_user_group UG on UG.GROUP_ID = IG.GROUP_ID\n\t\t\t\t\t\t\t\tINNER JOIN b_user U on U.ID = UG.USER_ID\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tS.ID = " . $NEW_STATUS_ID . "\n\t\t\t\t\t\t\t\tAND S.NOTIFY = 'Y'\n\t\t\t\t\t\t\t\tAND IG.IBLOCK_ID = " . intval($new_r["IBLOCK_ID"]) . "\n\t\t\t\t\t\t\t\tAND IG.PERMISSION >= 'U'\n\t\t\t\t\t\t\t\tAND SG.PERMISSION_TYPE = '2'\n\t\t\t\t\t\t\t\tAND U.ACTIVE = 'Y'\n\t\t\t\t\t\t"; $rs = $DB->Query($strSql, false, $err_mess . __LINE__); while ($ar = $rs->Fetch()) { $arBCC[$ar["EMAIL"]] = $ar["EMAIL"]; } //Second admins if they in PERMISSION_TYPE = 2 list //because they have all the rights $strSql = "\n\t\t\t\t\t\t\tSELECT U.EMAIL\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\tb_workflow_status S\n\t\t\t\t\t\t\t\tINNER JOIN b_workflow_status2group SG on SG.STATUS_ID = S.ID\n\t\t\t\t\t\t\t\tINNER JOIN b_user_group UG on UG.GROUP_ID = SG.GROUP_ID\n\t\t\t\t\t\t\t\tINNER JOIN b_user U on U.ID = UG.USER_ID\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tS.ID = " . $NEW_STATUS_ID . "\n\t\t\t\t\t\t\t\tAND S.NOTIFY = 'Y'\n\t\t\t\t\t\t\t\tAND SG.GROUP_ID = 1\n\t\t\t\t\t\t\t\tAND SG.PERMISSION_TYPE = '2'\n\t\t\t\t\t\t\t\tAND U.ACTIVE = 'Y'\n\t\t\t\t\t\t"; $rs = $DB->Query($strSql, false, $err_mess . __LINE__); while ($ar = $rs->Fetch()) { $arBCC[$ar["EMAIL"]] = $ar["EMAIL"]; } $iblock_r = CIBlock::GetArrayByID($new_r["IBLOCK_ID"]); $iblock_r["LID"] = array(); $rsIBlockSite = $DB->Query("SELECT SITE_ID FROM b_iblock_site WHERE IBLOCK_ID= " . intval($new_r["IBLOCK_ID"])); while ($arIBlockSite = $rsIBlockSite->Fetch()) { $iblock_r["LID"][] = $arIBlockSite["SITE_ID"]; } if (array_key_exists($new_r["MODIFIED_BY"], $arAdmin)) { $new_r["USER_NAME"] .= " (Admin)"; } // it is not new doc if ($NEW != "Y") { if (array_key_exists($parent_r["CREATED_BY"], $arAdmin)) { $parent_r["CREATED_USER_NAME"] .= " (Admin)"; } // send change notification $arEventFields = array("ID" => $PARENT_ID, "IBLOCK_ID" => $new_r["IBLOCK_ID"], "IBLOCK_TYPE" => $iblock_r["IBLOCK_TYPE_ID"], "ADMIN_EMAIL" => implode(",", $arAdmin), "BCC" => implode(",", $arBCC), "PREV_STATUS_ID" => $OLD_STATUS_ID, "PREV_STATUS_TITLE" => CIblockElement::WF_GetStatusTitle($OLD_STATUS_ID), "STATUS_ID" => $NEW_STATUS_ID, "STATUS_TITLE" => CIblockElement::WF_GetStatusTitle($NEW_STATUS_ID), "DATE_CREATE" => $parent_r["DATE_CREATE"], "CREATED_BY_ID" => $parent_r["CREATED_BY"], "CREATED_BY_NAME" => $parent_r["CREATED_USER_NAME"], "CREATED_BY_EMAIL" => $parent_r["CREATED_BY_EMAIL"], "DATE_MODIFY" => $new_r["TIMESTAMP_X"], "MODIFIED_BY_ID" => $new_r["MODIFIED_BY"], "MODIFIED_BY_NAME" => $new_r["USER_NAME"], "NAME" => $new_r["NAME"], "SECTION_ID" => $new_r["IBLOCK_SECTION_ID"], "PREVIEW_HTML" => $new_r["PREVIEW_TEXT_TYPE"] == "html" ? $new_r["PREVIEW_TEXT"] : TxtToHtml($new_r["PREVIEW_TEXT"]), "PREVIEW_TEXT" => $new_r["PREVIEW_TEXT_TYPE"] == "text" ? $new_r["PREVIEW_TEXT"] : HtmlToTxt($new_r["PREVIEW_TEXT"]), "PREVIEW" => $new_r["PREVIEW_TEXT"], "PREVIEW_TYPE" => $new_r["PREVIEW_TEXT_TYPE"], "DETAIL_HTML" => $new_r["DETAIL_TEXT_TYPE"] == "html" ? $new_r["DETAIL_TEXT"] : TxtToHtml($new_r["DETAIL_TEXT"]), "DETAIL_TEXT" => $new_r["DETAIL_TEXT_TYPE"] == "text" ? $new_r["DETAIL_TEXT"] : HtmlToTxt($new_r["DETAIL_TEXT"]), "DETAIL" => $new_r["DETAIL_TEXT"], "DETAIL_TYPE" => $new_r["DETAIL_TEXT_TYPE"], "COMMENTS" => $new_r["WF_COMMENTS"]); CEvent::Send("WF_IBLOCK_STATUS_CHANGE", $iblock_r["LID"], $arEventFields); } else { // it was new one $arEventFields = array("ID" => $PARENT_ID, "IBLOCK_ID" => $new_r["IBLOCK_ID"], "IBLOCK_TYPE" => $iblock_r["IBLOCK_TYPE_ID"], "ADMIN_EMAIL" => implode(",", $arAdmin), "BCC" => implode(",", $arBCC), "STATUS_ID" => $NEW_STATUS_ID, "STATUS_TITLE" => CIblockElement::WF_GetStatusTitle($NEW_STATUS_ID), "DATE_CREATE" => $parent_r["DATE_CREATE"], "CREATED_BY_ID" => $parent_r["CREATED_BY"], "CREATED_BY_NAME" => $parent_r["CREATED_USER_NAME"], "CREATED_BY_EMAIL" => $parent_r["CREATED_BY_EMAIL"], "NAME" => $new_r["NAME"], "PREVIEW_HTML" => $new_r["PREVIEW_TEXT_TYPE"] == "html" ? $new_r["PREVIEW_TEXT"] : TxtToHtml($new_r["PREVIEW_TEXT"]), "PREVIEW_TEXT" => $new_r["PREVIEW_TEXT_TYPE"] == "text" ? $new_r["PREVIEW_TEXT"] : HtmlToTxt($new_r["PREVIEW_TEXT"]), "PREVIEW" => $new_r["PREVIEW_TEXT"], "PREVIEW_TYPE" => $new_r["PREVIEW_TEXT_TYPE"], "SECTION_ID" => $new_r["IBLOCK_SECTION_ID"], "DETAIL_HTML" => $new_r["DETAIL_TEXT_TYPE"] == "html" ? $new_r["DETAIL_TEXT"] : TxtToHtml($new_r["DETAIL_TEXT"]), "DETAIL_TEXT" => $new_r["DETAIL_TEXT_TYPE"] == "text" ? $new_r["DETAIL_TEXT"] : HtmlToTxt($new_r["DETAIL_TEXT"]), "DETAIL" => $new_r["DETAIL_TEXT"], "DETAIL_TYPE" => $new_r["DETAIL_TEXT_TYPE"], "COMMENTS" => $new_r["WF_COMMENTS"]); CEvent::Send("WF_NEW_IBLOCK_ELEMENT", $iblock_r["LID"], $arEventFields); } } } } } }
public static function SetMove($DOCUMENT_ID, $STATUS_ID, $OLD_STATUS_ID, $LOG_ID) { $err_mess = CAllWorkflow::err_mess() . "<br>Function: SetMove<br>Line: "; global $DB, $USER, $APPLICATION; $DOCUMENT_ID = intval($DOCUMENT_ID); $STATUS_ID = intval($STATUS_ID); $OLD_STATUS_ID = intval($OLD_STATUS_ID); $LOG_ID = intval($LOG_ID); $arFields = array("TIMESTAMP_X" => $DB->GetNowFunction(), "DOCUMENT_ID" => $DOCUMENT_ID, "OLD_STATUS_ID" => $OLD_STATUS_ID, "STATUS_ID" => $STATUS_ID, "LOG_ID" => $LOG_ID, "USER_ID" => intval($USER->GetID())); $DB->Insert("b_workflow_move", $arFields, $err_mess . __LINE__); if ($STATUS_ID != $OLD_STATUS_ID) { CTimeZone::Disable(); $d = CWorkflow::GetByID($DOCUMENT_ID); CTimeZone::Enable(); if ($dr = $d->Fetch()) { $STATUS_ID = $dr["STATUS_ID"]; // document creator $ENTERED_BY_USER_ID = $dr["ENTERED_BY"]; // gather email of the workflow admins $WORKFLOW_ADMIN_GROUP_ID = COption::GetOptionInt("workflow", "WORKFLOW_ADMIN_GROUP_ID", 0); $strSql = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tU.ID,\n\t\t\t\t\t\tU.EMAIL\n\t\t\t\t\tFROM\n\t\t\t\t\t\tb_user U,\n\t\t\t\t\t\tb_user_group UG\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tUG.GROUP_ID = {$WORKFLOW_ADMIN_GROUP_ID}\n\t\t\t\t\t\tand U.ID = UG.USER_ID\n\t\t\t\t\t\tand U.ACTIVE = 'Y'\n\t\t\t\t"; $a = $DB->Query($strSql, false, $err_mess . __LINE__); $arAdmin = array(); while ($ar = $a->Fetch()) { $arAdmin[$ar["ID"]] = $ar["EMAIL"]; } // gather email for BCC $arBCC = array(); // gather all who changed doc in its current status $strSql = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tUSER_ID\n\t\t\t\t\tFROM\n\t\t\t\t\t\tb_workflow_move\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tDOCUMENT_ID = {$DOCUMENT_ID}\n\t\t\t\t\t\tand OLD_STATUS_ID = {$STATUS_ID}\n\t\t\t\t"; $z = $DB->Query($strSql, false, $err_mess . __LINE__); while ($zr = $z->Fetch()) { $arBCC[$zr["EMAIL"]] = $zr["EMAIL"]; } // gather all editors // in case status have notifier flag $strSql = "\n\t\t\t\t\tSELECT DISTINCT\n\t\t\t\t\t\tUG.USER_ID\n\t\t\t\t\t\t,U.EMAIL\n\t\t\t\t\tFROM\n\t\t\t\t\t\tb_workflow_status S,\n\t\t\t\t\t\tb_workflow_status2group SG,\n\t\t\t\t\t\tb_user U,\n\t\t\t\t\t\tb_user_group UG\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tS.ID = {$STATUS_ID}\n\t\t\t\t\t\tand S.NOTIFY = 'Y'\n\t\t\t\t\t\tand SG.STATUS_ID = S.ID\n\t\t\t\t\t\tand SG.PERMISSION_TYPE = '2'\n\t\t\t\t\t\tand UG.GROUP_ID = SG.GROUP_ID\n\t\t\t\t\t\tand U.ID = UG.USER_ID\n\t\t\t\t\t\tand U.ACTIVE = 'Y'\n\t\t\t\t"; $z = $DB->Query($strSql, false, $err_mess . __LINE__); while ($zr = $z->Fetch()) { if (!array_key_exists($zr["EMAIL"], $arBCC)) { $grp = array(); $rs = $USER->GetUserGroupList($zr["USER_ID"]); while ($ar = $rs->Fetch()) { $grp[] = $ar["GROUP_ID"]; } $arTasks = $APPLICATION->GetFileAccessPermission($dr["FILENAME"], $grp, true); foreach ($arTasks as $task_id) { $arOps = CTask::GetOperations($task_id, true); if (in_array("fm_edit_in_workflow", $arOps)) { $arBCC[$zr["EMAIL"]] = $zr["EMAIL"]; break; } } } } unset($arBCC[$dr["EUSER_EMAIL"]]); if (array_key_exists($dr["ENTERED_BY"], $arAdmin)) { $dr["EUSER_NAME"] .= " (Admin)"; } // it is not new doc if ($OLD_STATUS_ID > 0) { if (array_key_exists($dr["MODIFIED_BY"], $arAdmin)) { $dr["MUSER_NAME"] .= " (Admin)"; } $q = CWorkflowStatus::GetByID($OLD_STATUS_ID); $qr = $q->Fetch(); // send change notification $arEventFields = array("ID" => $dr["ID"], "ADMIN_EMAIL" => implode(",", $arAdmin), "BCC" => implode(",", $arBCC), "PREV_STATUS_ID" => $OLD_STATUS_ID, "PREV_STATUS_TITLE" => $qr["TITLE"], "STATUS_ID" => $dr["STATUS_ID"], "STATUS_TITLE" => $dr["STATUS_TITLE"], "DATE_ENTER" => $dr["DATE_ENTER"], "ENTERED_BY_ID" => $dr["ENTERED_BY"], "ENTERED_BY_NAME" => $dr["EUSER_NAME"], "ENTERED_BY_EMAIL" => $dr["EUSER_EMAIL"], "DATE_MODIFY" => $dr["DATE_MODIFY"], "MODIFIED_BY_ID" => $dr["MODIFIED_BY"], "MODIFIED_BY_NAME" => $dr["MUSER_NAME"], "FILENAME" => $dr["FILENAME"], "SITE_ID" => $dr["SITE_ID"], "TITLE" => $dr["TITLE"], "BODY_HTML" => $dr["BODY_TYPE"] == "html" ? $dr["BODY"] : TxtToHtml($dr["BODY"]), "BODY_TEXT" => $dr["BODY_TYPE"] == "text" ? $dr["BODY"] : HtmlToTxt($dr["BODY"]), "BODY" => $dr["BODY"], "BODY_TYPE" => $dr["BODY_TYPE"], "COMMENTS" => $dr["COMMENTS"]); CEvent::Send("WF_STATUS_CHANGE", $dr["SITE_ID"], $arEventFields); } else { // it was new one $arEventFields = array("ID" => $dr["ID"], "ADMIN_EMAIL" => implode(",", $arAdmin), "BCC" => implode(",", $arBCC), "STATUS_ID" => $dr["STATUS_ID"], "STATUS_TITLE" => $dr["STATUS_TITLE"], "DATE_ENTER" => $dr["DATE_ENTER"], "ENTERED_BY_ID" => $dr["ENTERED_BY"], "ENTERED_BY_NAME" => $dr["EUSER_NAME"], "ENTERED_BY_EMAIL" => $dr["EUSER_EMAIL"], "FILENAME" => $dr["FILENAME"], "SITE_ID" => $dr["SITE_ID"], "TITLE" => $dr["TITLE"], "BODY_HTML" => $dr["BODY_TYPE"] == "html" ? $dr["BODY"] : TxtToHtml($dr["BODY"]), "BODY_TEXT" => $dr["BODY_TYPE"] == "text" ? $dr["BODY"] : HtmlToTxt($dr["BODY"]), "BODY" => $dr["BODY"], "BODY_TYPE" => $dr["BODY_TYPE"], "COMMENTS" => $dr["COMMENTS"]); CEvent::Send("WF_NEW_DOCUMENT", $dr["SITE_ID"], $arEventFields); } } } }