示例#1
0
	function SetConditions($FILTER_ID, $CONDITIONS, $bClearOther = true)
	{
		global $DB;

		$FILTER_ID = IntVal($FILTER_ID);

		$strSql=
			"SELECT ID ".
			"FROM b_mail_filter_cond ".
			"WHERE FILTER_ID=".$FILTER_ID;

		$dbr = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);

		while($dbr_arr = $dbr->Fetch())
		{
			if(is_set($CONDITIONS, $dbr_arr["ID"]) && is_array($CONDITIONS[$dbr_arr["ID"]]) && strlen($CONDITIONS[$dbr_arr["ID"]]["STRINGS"])>0)
			{
				$arFields = $CONDITIONS[$dbr_arr["ID"]];
				unset($arFields["ID"]);
				$arFields["FILTER_ID"] = $FILTER_ID;
				CMailFilterCondition::Update($dbr_arr["ID"], $arFields);
				unset($CONDITIONS[$dbr_arr["ID"]]);
			}
			elseif($bClearOther)
			{
				$DB->Query("DELETE FROM b_mail_filter_cond WHERE ID=".$dbr_arr["ID"]);
			}
		}

		foreach($CONDITIONS as $arFields)
		{
			if(is_array($arFields) && strlen($arFields["STRINGS"])>0)
			{
				$arFields["FILTER_ID"] = $FILTER_ID;
				unset($arFields["ID"]);
				CMailFilterCondition::Add($arFields);
			}
		}
	}
        $SORT = "500";
    }
    if (!isset($MAILBOX_ID)) {
        $MAILBOX_ID = $find_mailbox_id;
    }
    if ($ID > 0) {
        $ACTION_VARS = $ar_res["ACTION_VARS"];
    }
}
if ($message || $ID == 0) {
    $DB->InitTableVarsForEdit("b_mail_filter", "", "str_", "", true);
    $ar_CONDITIONS = $CONDITIONS;
} else {
    $ar_CONDITIONS = array();
    if ($ID > 0) {
        $res = CMailFilterCondition::GetList(array("id" => "asc"), array("FILTER_ID" => $ID));
        while ($ar = $res->Fetch()) {
            $ar_CONDITIONS[$ar["ID"]] = $ar;
        }
    }
}
if (!is_array($ar_CONDITIONS)) {
    $ar_CONDITIONS = array();
}
if (!$message) {
    $ar_CONDITIONS["n1"] = array();
    $ar_CONDITIONS["n2"] = array();
    $ar_CONDITIONS["n3"] = array();
}
$sDocTitle = $ID > 0 ? preg_replace("'#ID#'i", $ID, GetMessage("MAIL_FLT_EDT_TITILE_1")) : GetMessage("MAIL_FLT_EDT_TITILE_2");
$APPLICATION->SetTitle($sDocTitle);