コード例 #1
0
ファイル: user.php プロジェクト: rasuldev/torino
 public static function Update($ID, $arFields, $strUploadDir = false, $UpdateByUserId = false)
 {
     global $DB;
     $ID = intVal($ID);
     if ($ID <= 0) {
         return false;
     }
     $strUploadDir = $strUploadDir === false ? "forum/avatar" : $strUploadDir;
     $arFields1 = array();
     foreach ($arFields as $key => $value) {
         if (substr($key, 0, 1) == "=") {
             $arFields1[substr($key, 1)] = $value;
             unset($arFields[$key]);
         }
     }
     if (!CForumUser::CheckFields("UPDATE", $arFields)) {
         return false;
     }
     if (array_key_exists("AVATAR", $arFields) && is_array($arFields["AVATAR"]) && (!array_key_exists("MODULE_ID", $arFields["AVATAR"]) || strlen($arFields["AVATAR"]["MODULE_ID"]) <= 0)) {
         $arFields["AVATAR"]["MODULE_ID"] = "forum";
     }
     CFile::SaveForDB($arFields, "AVATAR", $strUploadDir);
     /***************** Event onBeforeUserUpdate ************************/
     $profileID = null;
     foreach (GetModuleEvents("forum", "onBeforeUserUpdate", true) as $arEvent) {
         if ($UpdateByUserId) {
             if ($profileID == null) {
                 $arProfile = CForumUser::GetByIDEx($ID);
                 $profileID = $arProfile['ID'];
             }
         } else {
             $profileID = $ID;
         }
         ExecuteModuleEventEx($arEvent, array($profileID, &$arFields));
     }
     /***************** /Event ******************************************/
     if (empty($arFields) && empty($arFields1)) {
         return false;
     }
     /***************** Cleaning cache **********************************/
     if (is_set($arFields, "ALLOW_POST")) {
         unset($GLOBALS["FORUM_CACHE"]["LOCKED_USERS"]);
         if (CACHED_b_forum_user !== false) {
             $GLOBALS["CACHE_MANAGER"]->CleanDir("b_forum_user");
         }
     }
     /***************** Cleaning cache/**********************************/
     $strUpdate = $DB->PrepareUpdate("b_forum_user", $arFields);
     foreach ($arFields1 as $key => $value) {
         if (strLen($strUpdate) > 0) {
             $strUpdate .= ", ";
         }
         $strUpdate .= $key . "=" . $value . " ";
     }
     if (!$UpdateByUserId) {
         $strSql = "UPDATE b_forum_user SET " . $strUpdate . " WHERE ID = " . $ID;
     } else {
         $strSql = "UPDATE b_forum_user SET " . $strUpdate . " WHERE USER_ID = " . $ID;
     }
     $arBinds = array();
     if (is_set($arFields, "INTERESTS")) {
         $arBinds["INTERESTS"] = $arFields["INTERESTS"];
     }
     $DB->QueryBind($strSql, $arBinds);
     /***************** Event onAfterUserUpdate *************************/
     foreach (GetModuleEvents("forum", "onAfterUserUpdate", true) as $arEvent) {
         if ($UpdateByUserId) {
             if ($profileID == null) {
                 $arProfile = CForumUser::GetByIDEx($ID);
                 $profileID = $arProfile['ID'];
             }
         } else {
             $profileID = $ID;
         }
         ExecuteModuleEventEx($arEvent, array($profileID, $arFields));
     }
     /***************** /Event ******************************************/
     unset($GLOBALS["FORUM_CACHE"]["USER"]);
     unset($GLOBALS["FORUM_CACHE"]["USER_ID"]);
     return $ID;
 }