Ejemplo n.º 1
0
 function Add($arFields)
 {
     global $DB;
     if (!CForumNew::CheckFields("ADD", $arFields)) {
         return false;
     }
     /***************** Event onBeforeForumAdd **************************/
     foreach (GetModuleEvents("forum", "onBeforeForumAdd", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) {
             return false;
         }
     }
     /***************** /Event ******************************************/
     if (empty($arFields)) {
         return false;
     }
     $arInsert = $DB->PrepareInsert("b_forum", $arFields);
     $strSql = "INSERT INTO b_forum(" . $arInsert[0] . ") VALUES(" . $arInsert[1] . ")";
     $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     $ID = intVal($DB->LastID());
     if ($ID > 0) {
         foreach ($arFields["SITES"] as $key => $value) {
             $DB->Query("INSERT INTO b_forum2site (FORUM_ID, SITE_ID, PATH2FORUM_MESSAGE) VALUES(" . $ID . ", '" . $DB->ForSql($key, 2) . "', '" . $DB->ForSql($value, 250) . "')", false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
         if (is_set($arFields, "GROUP_ID") && is_array($arFields["GROUP_ID"])) {
             CForumNew::SetAccessPermissions($ID, $arFields["GROUP_ID"]);
         }
     }
     /***************** Event onAfterForumAdd ***************************/
     foreach (GetModuleEvents("forum", "onAfterForumAdd", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array(&$ID, &$arFields));
     }
     /***************** /Event ******************************************/
     return $ID;
 }
Ejemplo n.º 2
0
 function Update($ID, $arFields, $bReindex = true)
 {
     global $DB;
     $ID = intVal($ID);
     $arForum_prev = array();
     $arProcAuth = array();
     if ($ID <= 0 || !CForumNew::CheckFields("UPDATE", $arFields)) {
         return false;
     }
     if ($arFields["ACTIVE"] == "N") {
         $arForum_prev = CForumNew::GetByID($ID);
     }
     /***************** Event onBeforeForumUpdate ***********************/
     foreach (GetModuleEvents("forum", "onBeforeForumUpdate", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array(&$ID, &$arFields)) === false) {
             return false;
         }
     }
     /***************** /Event ******************************************/
     if (empty($arFields)) {
         return false;
     }
     /***************** Cleaning cache **********************************/
     unset($GLOBALS["FORUM_CACHE"]["FORUM"][$ID]);
     if (CACHED_b_forum !== false) {
         $GLOBALS["CACHE_MANAGER"]->CleanDir("b_forum");
     }
     if (CACHED_b_forum2site !== false && is_array($arFields["SITES"]) && count($arFields["SITES"]) > 0) {
         $GLOBALS["CACHE_MANAGER"]->CleanDir("b_forum2site");
     }
     /***************** Cleaning cache/**********************************/
     $strUpdate = $DB->PrepareUpdate("b_forum", $arFields);
     if (!empty($strUpdate)) {
         $strSql = "UPDATE b_forum SET " . $strUpdate . " WHERE ID=" . $ID;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     }
     if (is_array($arFields["SITES"]) && count($arFields["SITES"]) > 0) {
         $DB->Query("DELETE FROM b_forum2site WHERE FORUM_ID = " . $ID);
         foreach ($arFields["SITES"] as $key => $value) {
             $value = $DB->ForSql($value, 250);
             $strSql = "INSERT INTO b_forum2site (FORUM_ID, SITE_ID, PATH2FORUM_MESSAGE) VALUES(" . $ID . ", '" . $DB->ForSql($key, 2) . "', '" . $value . "') ";
             if ($DB->type == "MYSQL") {
                 $strSql .= "ON DUPLICATE KEY UPDATE PATH2FORUM_MESSAGE='" . $value . "'";
             }
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
     }
     if (is_set($arFields, "GROUP_ID") && is_array($arFields["GROUP_ID"])) {
         CForumNew::SetAccessPermissions($ID, $arFields["GROUP_ID"]);
     }
     /***************** Event onAfterForumUpdate ************************/
     foreach (GetModuleEvents("forum", "onAfterForumUpdate", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID, $arFields));
     }
     /***************** /Event ******************************************/
     /***************** Update statistic ********************************/
     /* If forum became inactive than all statistics for users of this forum will be recalculated.*/
     if ($arFields["ACTIVE"] == "N" && $arForum_prev["ACTIVE"] == "Y") {
         $db_res = CForumMessage::GetList(array(), array("FORUM_ID" => $ID, "!AUTHOR_ID" => 0));
         while ($res = $db_res->Fetch()) {
             $res["AUTHOR_ID"] = intVal($res["AUTHOR_ID"]);
             if (!in_array($res["AUTHOR_ID"], $arProcAuth)) {
                 CForumUser::SetStat($res["AUTHOR_ID"]);
                 $arProcAuth[] = $res["AUTHOR_ID"];
             }
         }
         unset($arProcAuth);
     }
     /***************** Update search module ****************************/
     if (CModule::IncludeModule("search") && $bReindex == true) {
         if ($arFields["ACTIVE"] == "N" && $arForum_prev["ACTIVE"] == "Y" || $arFields["INDEXATION"] == "N" && $arForum_prev["INDEXATION"] == "Y") {
             CSearch::DeleteIndex("forum", false, $ID);
         } elseif (is_set($arFields, "GROUP_ID") && is_array($arFields["GROUP_ID"])) {
             $arGroups = CForumNew::GetAccessPermissions($ID);
             $arGPerm = array();
             foreach ($arGroups as $i => $group) {
                 if ($group[1] >= "E") {
                     $arGPerm[] = $group[0];
                     if ($group[0] == 2) {
                         break;
                     }
                 }
             }
             CSearch::ChangePermission("forum", $arGPerm, false, $ID);
         }
     }
     return $ID;
 }