Exemple #1
0
 public static function updateGroup($arFields)
 {
     foreach ($arFields as $key => $value) {
         if (substr($key, 0, 1) == "~" || substr($key, 0, 1) == "=") {
             unset($arFields[$key]);
         }
     }
     if (isset($arFields["IMAGE_ID"])) {
         unset($arFields["IMAGE_ID"]);
     }
     $groupID = $arFields['GROUP_ID'];
     unset($arFields['GROUP_ID']);
     if (intval($groupID) <= 0) {
         throw new Exception('Wrong group ID');
     }
     $arFilter = array("ID" => $groupID);
     if (!CSocNetUser::IsCurrentUserModuleAdmin(SITE_ID, false)) {
         $arFilter['CHECK_PERMISSIONS'] = $GLOBALS["USER"]->GetID();
     }
     $dbRes = CSocNetGroup::GetList(array(), $arFilter);
     $arGroup = $dbRes->Fetch();
     if (is_array($arGroup)) {
         if ($arGroup["OWNER_ID"] == $GLOBALS["USER"]->GetID() || CSocNetUser::IsCurrentUserModuleAdmin(SITE_ID, false)) {
             $res = CSocNetGroup::Update($arGroup["ID"], $arFields, false);
             if (intval($res) <= 0) {
                 throw new Exception('Cannot update group');
             }
         } else {
             throw new Exception('User has no permissions to update group');
         }
         return $res;
     } else {
         throw new Exception('Socialnetwork group not found');
     }
     return false;
 }
Exemple #2
0
	public static function updateGroup($arFields)
	{
		$groupID = $arFields['GROUP_ID'];
		unset($arFields['GROUP_ID']);

		if(intval($groupID) <= 0)
			throw new Exception('Wrong group ID');

		$dbRes = CSocNetGroup::GetList(array(), array(
			"ID" => $groupID,
			"CHECK_PERMISSIONS" => "Y"
		));
		$arGroup = $dbRes->Fetch();
		if(is_array($arGroup))
		{
			if (
				$arGroup["OWNER_ID"] == $GLOBALS["USER"]->GetID()
				|| CSocNetUser::IsCurrentUserModuleAdmin(SITE_ID, false)
			)
			{
				$res = CSocNetGroup::Update($arGroup["ID"], $arFields, false);
				if(intval($res) <= 0)
					throw new Exception('Cannot update group');
			}
			else
				throw new Exception('User has no permissions to update group');

			return $res;
		}
		else
			throw new Exception('Socialnetwork group not found');

		return false;
	}
Exemple #3
0
 function SetOwner($userID, $groupID, $arGroup = false)
 {
     global $DB, $APPLICATION, $USER;
     if (!$arGroup) {
         $arGroup = CSocNetGroup::GetByID($groupID);
     }
     if (!$arGroup) {
         return false;
     }
     $DB->StartTransaction();
     // setting relations for the old owner
     $dbRelation = CSocNetUserToGroup::GetList(array(), array("USER_ID" => $arGroup["OWNER_ID"], "GROUP_ID" => $groupID), false, false, array("ID"));
     if ($arRelation = $dbRelation->Fetch()) {
         $arFields = array("ROLE" => SONET_ROLES_USER, "=DATE_UPDATE" => $DB->CurrentTimeFunction(), "INITIATED_BY_TYPE" => SONET_INITIATED_BY_USER, "INITIATED_BY_USER_ID" => $USER->GetID());
         if (!CSocNetUserToGroup::Update($arRelation["ID"], $arFields)) {
             $errorMessage = "";
             if ($e = $APPLICATION->GetException()) {
                 $errorMessage = $e->GetString();
             }
             if (StrLen($errorMessage) <= 0) {
                 $errorMessage = GetMessage("SONET_UG_ERROR_CANNOT_UPDATE_CURRENT_OWNER");
             }
             $APPLICATION->ThrowException($errorMessage, "ERROR_UPDATE_USER2GROUP");
             $DB->Rollback();
             return false;
         }
     } else {
         $errorMessage = "";
         if ($e = $APPLICATION->GetException()) {
             $errorMessage = $e->GetString();
         }
         if (StrLen($errorMessage) <= 0) {
             $errorMessage = GetMessage("SONET_UG_ERROR_CANNOT_GET_CURRENT_OWNER_RELATION");
         }
         $APPLICATION->ThrowException($errorMessage, "ERROR_GET_USER2GROUP");
         $DB->Rollback();
         return false;
     }
     // delete requests to the old owner
     if (strlen($errorMessage) <= 0) {
         CSocNetUserToGroup::__SpeedFileDelete($arGroup["OWNER_ID"]);
     }
     if (strlen($errorMessage) <= 0) {
         // setting relations for the new owner
         $dbRelation = CSocNetUserToGroup::GetList(array(), array("USER_ID" => $userID, "GROUP_ID" => $groupID), false, false, array("ID"));
         if ($arRelation = $dbRelation->Fetch()) {
             $arFields = array("ROLE" => SONET_ROLES_OWNER, "=DATE_UPDATE" => $DB->CurrentTimeFunction(), "INITIATED_BY_TYPE" => SONET_INITIATED_BY_USER, "INITIATED_BY_USER_ID" => $USER->GetID());
             if (!CSocNetUserToGroup::Update($arRelation["ID"], $arFields)) {
                 $errorMessage = "";
                 if ($e = $APPLICATION->GetException()) {
                     $errorMessage = $e->GetString();
                 }
                 if (StrLen($errorMessage) <= 0) {
                     $errorMessage = GetMessage("SONET_UG_ERROR_CANNOT_UPDATE_NEW_OWNER_RELATION");
                 }
                 $APPLICATION->ThrowException($errorMessage, "ERROR_UPDATE_USER2GROUP");
                 $DB->Rollback();
                 return false;
             }
         } else {
             $arFields = array("USER_ID" => $userID, "GROUP_ID" => $groupID, "ROLE" => SONET_ROLES_OWNER, "=DATE_CREATE" => $DB->CurrentTimeFunction(), "=DATE_UPDATE" => $DB->CurrentTimeFunction(), "INITIATED_BY_TYPE" => SONET_INITIATED_BY_USER, "INITIATED_BY_USER_ID" => $USER->GetID(), "MESSAGE" => false);
             if (!CSocNetUserToGroup::Add($arFields)) {
                 $errorMessage = "";
                 if ($e = $APPLICATION->GetException()) {
                     $errorMessage = $e->GetString();
                 }
                 if (StrLen($errorMessage) <= 0) {
                     $errorMessage = GetMessage("SONET_UG_ERROR_CANNOT_ADD_NEW_OWNER_RELATION");
                 }
                 $APPLICATION->ThrowException($errorMessage, "ERROR_ADD_USER2GROUP");
                 $DB->Rollback();
                 return false;
             }
         }
     }
     if (strlen($errorMessage) <= 0) {
         $GROUP_ID = CSocNetGroup::Update($groupID, array("OWNER_ID" => $userID));
         if (!$GROUP_ID || IntVal($GROUP_ID) <= 0) {
             $errorMessage = "";
             if ($e = $APPLICATION->GetException()) {
                 $errorMessage = $e->GetString();
             }
             if (StrLen($errorMessage) <= 0) {
                 $errorMessage = GetMessage("SONET_UG_ERROR_CANNOT_UPDATE_GROUP");
             }
             $APPLICATION->ThrowException($errorMessage, "ERROR_UPDATE_GROUP");
             $DB->Rollback();
             return false;
         }
     }
     if (CModule::IncludeModule("im")) {
         $bIMIncluded = true;
         $groupSiteId = CSocNetGroup::GetDefaultSiteId($groupID, $arGroup["SITE_ID"]);
         $workgroupsPage = COption::GetOptionString("socialnetwork", "workgroups_page", "/workgroups/", $groupSiteId);
         $groupUrlTemplate = COption::GetOptionString("socialnetwork", "group_path_template", "/workgroups/group/#group_id#/", $groupSiteId);
         $groupUrlTemplate = "#GROUPS_PATH#" . substr($groupUrlTemplate, strlen($workgroupsPage), strlen($groupUrlTemplate) - strlen($workgroupsPage));
         $groupUrl = str_replace(array("#group_id#", "#GROUP_ID#"), $groupID, $groupUrlTemplate);
     }
     // send message to the old owner
     if ($bIMIncluded) {
         $arTmp = CSocNetLogTools::ProcessPath(array("GROUP_URL" => $groupUrl), $arGroup["OWNER_ID"], $groupSiteId);
         $groupUrl = $arTmp["URLS"]["GROUP_URL"];
         $serverName = strpos($groupUrl, "http://") === 0 || strpos($groupUrl, "https://") === 0 ? "" : $arTmp["SERVER_NAME"];
         $arMessageFields = array("TO_USER_ID" => $arGroup["OWNER_ID"], "FROM_USER_ID" => $USER->GetID(), "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "socialnetwork", "NOTIFY_EVENT" => "owner_group", "NOTIFY_TAG" => "SOCNET|OWNER_GROUP|" . $groupID, "NOTIFY_MESSAGE" => str_replace("#NAME#", "<a href=\"" . $groupUrl . "\" class=\"bx-notifier-item-action\">" . $arGroup["NAME"] . "</a>", GetMessage("SONET_UG_OWNER2MEMBER_MESSAGE")), "NOTIFY_MESSAGE_OUT" => str_replace("#NAME#", $arGroup["NAME"], GetMessage("SONET_UG_OWNER2MEMBER_MESSAGE") . " (" . $serverName . $groupUrl . ")"));
         CIMNotify::Add($arMessageFields);
     }
     // send message to the new owner
     if ($bIMIncluded) {
         $arTmp = CSocNetLogTools::ProcessPath(array("GROUP_URL" => $groupUrl), $userID, $groupSiteId);
         $groupUrl = $arTmp["URLS"]["GROUP_URL"];
         if (strpos($groupUrl, "http://") === 0 || strpos($groupUrl, "https://") === 0) {
             $serverName = "";
         } else {
             $serverName = $arTmp["SERVER_NAME"];
         }
         $arMessageFields = array("TO_USER_ID" => $userID, "FROM_USER_ID" => $USER->GetID(), "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "socialnetwork", "NOTIFY_EVENT" => "owner_group", "NOTIFY_TAG" => "SOCNET|OWNER_GROUP|" . $groupID, "NOTIFY_MESSAGE" => str_replace("#NAME#", "<a href=\"" . $groupUrl . "\" class=\"bx-notifier-item-action\">" . $arGroup["NAME"] . "</a>", GetMessage("SONET_UG_MEMBER2OWNER_MESSAGE")), "NOTIFY_MESSAGE_OUT" => str_replace("#NAME#", $arGroup["NAME"], GetMessage("SONET_UG_MEMBER2OWNER_MESSAGE") . " (" . $serverName . $groupUrl . ")"));
         CIMNotify::Add($arMessageFields);
     }
     $arNotifyParams = array("TYPE" => "owner", "RELATION_ID" => $arRelation["ID"], "USER_ID" => $userID, "GROUP_ID" => $groupID, "GROUP_NAME" => htmlspecialcharsbx($arGroup["NAME"]), "EXCLUDE_USERS" => array($userID, $arGroup["OWNER_ID"], $USER->GetID()));
     CSocNetUserToGroup::NotifyImToModerators($arNotifyParams);
     CSocNetSubscription::Set($userID, "SG" . $groupID, "Y");
     if (strlen($errorMessage) <= 0) {
         $DB->Commit();
         return true;
     } else {
         $DB->Rollback();
         return false;
     }
 }
Exemple #4
0
 function SetLastActivity($ID, $date = false)
 {
     if (!CSocNetGroup::__ValidateID($ID)) {
         return false;
     }
     $ID = IntVal($ID);
     if ($date == false) {
         CSocNetGroup::Update($ID, array("=DATE_ACTIVITY" => $GLOBALS["DB"]->CurrentTimeFunction()));
     } else {
         CSocNetGroup::Update($ID, array("DATE_ACTIVITY" => $date));
     }
 }
Exemple #5
0
 $bError = false;
 if (!$lAdmin->IsUpdated($ID)) {
     continue;
 }
 foreach ($arFields as $key => $value) {
     $bAllowed = false;
     foreach ($arHeaders as $header) {
         if ($header["id"] === $key) {
             $bAllowed = true;
         }
     }
     if (!$bAllowed) {
         unset($arFields[$key]);
     }
 }
 if (!CSocNetGroup::Update($ID, $arFields, false)) {
     if ($ex = $APPLICATION->GetException()) {
         $lAdmin->AddUpdateError($ex->GetString(), $ID);
     } else {
         $lAdmin->AddUpdateError(GetMessage("SONET_ERROR_UPDATE"), $ID);
     }
     $DB->Rollback();
 } elseif (!empty($arFields["OWNER_ID"]) && !empty($arOwnerOld[$ID])) {
     $arUpdateFields = array("ROLE" => SONET_ROLES_USER, "=DATE_UPDATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "INITIATED_BY_TYPE" => SONET_INITIATED_BY_USER, "INITIATED_BY_USER_ID" => $GLOBALS["USER"]->GetID());
     if (!CSocNetUserToGroup::Update($arOwnerOld[$ID]["RELATION_ID"], $arUpdateFields)) {
         $bError = true;
         if ($ex = $APPLICATION->GetException()) {
             $lAdmin->AddUpdateError($ex->GetString(), $ID);
         } else {
             $lAdmin->AddUpdateError(GetMessage("SONET_ERROR_UPDATE"), $ID);
         }
Exemple #6
0
     $arResult["GROUP_ID"] = CSocNetGroup::CreateGroup($USER->GetID(), $arFields, $bAutoSubscribe);
     if (!$arResult["GROUP_ID"]) {
         if ($e = $APPLICATION->GetException()) {
             $errorMessage .= $e->GetString();
             $errorID = $e->GetID();
             if (strlen($errorID) > 0) {
                 $arResult["ErrorFields"][] = $errorID;
             }
         }
     } else {
         $bFirstStepSuccess = true;
     }
 } else {
     $arFields["=DATE_UPDATE"] = $DB->CurrentTimeFunction();
     $arFields["=DATE_ACTIVITY"] = $DB->CurrentTimeFunction();
     $arResult["GROUP_ID"] = CSocNetGroup::Update($arParams["GROUP_ID"], $arFields, $bAutoSubscribe);
     if (!$arResult["GROUP_ID"] && ($e = $APPLICATION->GetException())) {
         $errorMessage .= $e->GetString();
         $errorID = $e->GetID();
         if ($errorID == "ERROR_IMAGE_ID") {
             $arResult["ErrorFields"][] = "GROUP_IMAGE_ID";
         } elseif (isset($e->messages) && is_array($e->messages) && is_array($e->messages[0]) && array_key_exists("id", $e->messages[0])) {
             $arResult["ErrorFields"][] = $e->messages[0]["id"];
         }
     } else {
         $rsSite = CSite::GetList($by = "sort", $order = "desc", array("ACTIVE" => "Y"));
         while ($arSite = $rsSite->Fetch()) {
             BXClearCache(true, "/" . $arSite["ID"] . "/bitrix/search.tags.cloud/");
         }
     }
 }
Exemple #7
0
	function SetOwner($userID, $groupID, $arGroup = false)
	{
		global $DB, $APPLICATION, $USER;

		if (!$arGroup)
			$arGroup = CSocNetGroup::GetByID($groupID);

		if (!$arGroup)
			return false;

		$DB->StartTransaction();
				
		// setting relations for the old owner
		$dbRelation = CSocNetUserToGroup::GetList(array(), array("USER_ID" => $arGroup["OWNER_ID"], "GROUP_ID" => $groupID), false, false, array("ID"));
		if ($arRelation = $dbRelation->Fetch())
		{
			$arFields = array(
				"ROLE" => SONET_ROLES_USER,
				"=DATE_UPDATE" => $DB->CurrentTimeFunction(),
				"INITIATED_BY_TYPE" => SONET_INITIATED_BY_USER,
				"INITIATED_BY_USER_ID" => $USER->GetID(),
			);

			if (!CSocNetUserToGroup::Update($arRelation["ID"], $arFields))
			{
				$errorMessage = "";
				if ($e = $APPLICATION->GetException())
					$errorMessage = $e->GetString();
				if (StrLen($errorMessage) <= 0)
					$errorMessage = GetMessage("SONET_UG_ERROR_CANNOT_UPDATE_CURRENT_OWNER");

				$APPLICATION->ThrowException($errorMessage, "ERROR_UPDATE_USER2GROUP");
				$DB->Rollback();
				return false;
			}
		}
		else
		{
			$errorMessage = "";
			if ($e = $APPLICATION->GetException())
				$errorMessage = $e->GetString();
			if (StrLen($errorMessage) <= 0)
				$errorMessage = GetMessage("SONET_UG_ERROR_CANNOT_GET_CURRENT_OWNER_RELATION");

			$APPLICATION->ThrowException($errorMessage, "ERROR_GET_USER2GROUP");
			$DB->Rollback();
			return false;
		}

		// delete requests to the old owner
		if (strlen($errorMessage) <= 0)
			CSocNetUserToGroup::__SpeedFileDelete($arGroup["OWNER_ID"]);

		if (strlen($errorMessage) <= 0)
		{
			// setting relations for the new owner
			$dbRelation = CSocNetUserToGroup::GetList(array(), array("USER_ID" => $userID, "GROUP_ID" => $groupID), false, false, array("ID"));
			if ($arRelation = $dbRelation->Fetch())
			{
				$arFields = array(
					"ROLE" => SONET_ROLES_OWNER,
					"=DATE_UPDATE" => $DB->CurrentTimeFunction(),
					"INITIATED_BY_TYPE" => SONET_INITIATED_BY_USER,
					"INITIATED_BY_USER_ID" => $USER->GetID(),
				);

				if (!CSocNetUserToGroup::Update($arRelation["ID"], $arFields))
				{
					$errorMessage = "";
					if ($e = $APPLICATION->GetException())
						$errorMessage = $e->GetString();
					if (StrLen($errorMessage) <= 0)
						$errorMessage = GetMessage("SONET_UG_ERROR_CANNOT_UPDATE_NEW_OWNER_RELATION");

					$APPLICATION->ThrowException($errorMessage, "ERROR_UPDATE_USER2GROUP");
					$DB->Rollback();
					return false;
				}
			}
			else
			{
				$arFields = array(
					"USER_ID" => $userID,
					"GROUP_ID" => $groupID,
					"ROLE" => SONET_ROLES_OWNER,
					"=DATE_CREATE" => $DB->CurrentTimeFunction(),
					"=DATE_UPDATE" => $DB->CurrentTimeFunction(),
					"INITIATED_BY_TYPE" => SONET_INITIATED_BY_USER,
					"INITIATED_BY_USER_ID" => $USER->GetID(),
					"MESSAGE" => false,
				);

				if (!CSocNetUserToGroup::Add($arFields))
				{
					$errorMessage = "";
					if ($e = $APPLICATION->GetException())
						$errorMessage = $e->GetString();
					if (StrLen($errorMessage) <= 0)
						$errorMessage = GetMessage("SONET_UG_ERROR_CANNOT_ADD_NEW_OWNER_RELATION");

					$APPLICATION->ThrowException($errorMessage, "ERROR_ADD_USER2GROUP");
					$DB->Rollback();
					return false;
				}
			}
		}

		if (strlen($errorMessage) <= 0)
		{
			$GROUP_ID = CSocNetGroup::Update($groupID, array("OWNER_ID" => $userID));
			if (!$GROUP_ID || IntVal($GROUP_ID) <= 0)
			{
				$errorMessage = "";
				if ($e = $APPLICATION->GetException())
					$errorMessage = $e->GetString();
				if (StrLen($errorMessage) <= 0)
					$errorMessage = GetMessage("SONET_UG_ERROR_CANNOT_UPDATE_GROUP");

				$APPLICATION->ThrowException($errorMessage, "ERROR_UPDATE_GROUP");
				$DB->Rollback();
				return false;
			}
		}

		// send message to the old owner
		$arMessageFields = array(
			"FROM_USER_ID" => $USER->GetID(),
			"TO_USER_ID" => $arGroup["OWNER_ID"],
			"MESSAGE" => str_replace("#NAME#", $arGroup["NAME"], GetMessage("SONET_UG_OWNER2MEMBER_MESSAGE")),
			"=DATE_CREATE" => $DB->CurrentTimeFunction(),
			"MESSAGE_TYPE" => SONET_MESSAGE_SYSTEM
		);
		CSocNetMessages::Add($arMessageFields);

		// send message to the new owner
		$arMessageFields = array(
			"FROM_USER_ID" => $USER->GetID(),
			"TO_USER_ID" => $userID,
			"MESSAGE" => str_replace("#NAME#", $arGroup["NAME"], GetMessage("SONET_UG_MEMBER2OWNER_MESSAGE")),
			"=DATE_CREATE" => $DB->CurrentTimeFunction(),
			"MESSAGE_TYPE" => SONET_MESSAGE_SYSTEM
		);
		CSocNetMessages::Add($arMessageFields);

		// add entry to log
		$logID = CSocNetLog::Add(
			array(
				"ENTITY_TYPE" => SONET_ENTITY_GROUP,
				"SITE_ID" => $arGroup["SITE_ID"],
				"ENTITY_ID" => $groupID,
				"EVENT_ID" => "system",
				"=LOG_DATE" => $DB->CurrentTimeFunction(),
				"TITLE_TEMPLATE" => false,
				"TITLE" => "owner",
				"MESSAGE" => $userID,
				"URL" => false,
				"MODULE_ID" => false,
				"CALLBACK_FUNC" => false,
				"USER_ID" => $userID,
			)
		);
		if (intval($logID) > 0)
		{
			CSocNetLog::Update($logID, array("TMP_ID" => $logID));
			CSocNetLogRights::Add($logID, array("SA", "S".SONET_ENTITY_GROUP.$groupID, "S".SONET_ENTITY_GROUP.$groupID."_".SONET_ROLES_OWNER, "S".SONET_ENTITY_GROUP.$groupID."_".SONET_ROLES_MODERATOR, "S".SONET_ENTITY_GROUP.$groupID."_".SONET_ROLES_USER));
			CSocNetLog::SendEvent($logID, "SONET_NEW_EVENT", $logID);
		}

		if (strlen($errorMessage) <= 0)
		{
			$DB->Commit();
			return true;
		}
		else
		{
			$DB->Rollback();
			return false;	
		}
	}