/** * @param $versionName * @return bool|\CDBResult */ public function removeRecord($versionName) { $versionName = $this->bitrixDb->ForSql($versionName); if ($this->isMssql) { return $this->query('DELETE FROM #TABLE1# WHERE version = \'%s\'', $versionName); } else { return $this->query('DELETE FROM `#TABLE1#` WHERE `version` = "%s"', $versionName); } }
public static function InviteAttendees($ID, $arFields = array(), $arAttendees = array(), $arStatuses = array(), $bSendInvitations = true, $userId = 0) { global $DB, $CACHE_MANAGER; $ID = intVal($ID); if (!$ID) { return; } // It's new event $bNew = !isset($arFields['ID']) || $arFields['ID'] <= 0; $curAttendeesIndex = array(); $deletedAttendees = array(); $arAffectedSections = array(); if (!$bNew) { $curAttendees = self::GetAttendees($ID); $curAttendees = $curAttendees[$ID]; if (is_array($curAttendees)) { foreach ($curAttendees as $user) { $curAttendeesIndex[$user['USER_KEY']] = $user; $deletedAttendees[$user['USER_KEY']] = $user['USER_KEY']; $arAffectedSections[] = CCalendar::GetMeetingSection($user['USER_KEY']); } } } $dbAttendees = array(); $bReinvite = $arFields['~MEETING']['REINVITE'] !== false; $userId = $userId > 0 ? $userId : $arFields['MEETING_HOST']; $CACHE_MANAGER->ClearByTag('calendar_user_' . $userId); $delIdStr = ""; // List of all attendees for event foreach ($arAttendees as $userKey) { $bExternal = false; $key = false; if (substr($userKey, 0, strlen('BXEXT:')) == 'BXEXT:') { $email = substr($userKey, strlen('BXEXT:')); if (!check_email($email, true)) { continue; } $key = $email; $bExternal = true; } if (!$bExternal && intVal($userKey) > 0) { // User by ID $key = intVal($userKey); } if (!$key) { // Incorrect user continue; } unset($deletedAttendees[$key]); // Unset item from deleted list if (!$curAttendeesIndex[$key]) { $arAffectedSections[] = CCalendar::GetMeetingSection($key); } if ($curAttendeesIndex[$key] && !$bReinvite) { if (!$bNew && $key != $userId && $bSendInvitations) { if (!$bExternal && $curAttendeesIndex[$key]['STATUS'] == 'Y') { // Just send changing event notification CCalendar::SendMessage(array('mode' => 'change_notify', 'name' => $arFields['NAME'], "from" => $arFields["DT_FROM"], "to" => $arFields["DT_TO"], "location" => CCalendar::GetTextLocation($arFields["LOCATION"]), "meetingText" => $arFields["~MEETING"]["TEXT"], "guestId" => $key, "eventId" => $ID, "userId" => $userId)); } } continue; } if ($bExternal || $arFields['MEETING_HOST'] == $key) { $status = 'Y'; } else { $status = 'Q'; } $dbAttendees[$key] = array("bExternal" => $bExternal, "bReinvite" => isset($curAttendeesIndex[$key]) && $curAttendeesIndex[$key], "USER_KEY" => $key, "USER_ID" => $bExternal ? 0 : $key, "USER_EMAIL" => $bExternal ? $key : '', "USER_NAME" => "", "STATUS" => $status, "ACCESSIBILITY" => $arFields["ACCESSIBILITY"], "REMIND" => $arFields["REMIND"]); if (!$dbAttendees[$key]['bReinvite']) { $delIdStr .= ',' . (intVal($key) == $key ? intVal($key) : "'" . CDatabase::ForSql($key) . "'"); } } $delIdStr = trim($delIdStr, ', '); // Delete users from attendees list if (count($deletedAttendees) > 0) { foreach ($deletedAttendees as $key) { $att = $curAttendeesIndex[$key]; if (!$att['EVENT_ID']) { //Send email DELETE //echo "Send EMAIL DELETE \n"; } elseif ($bSendInvitations) { $CACHE_MANAGER->ClearByTag('calendar_user_' . $att["USER_ID"]); CCalendar::SendMessage(array('mode' => 'cancel', 'name' => $arFields['NAME'], "from" => $arFields["DT_FROM"], "to" => $arFields["DT_TO"], "location" => CCalendar::GetTextLocation($arFields["LOCATION"]), "guestId" => $att["USER_ID"], "eventId" => $ID, "userId" => $arFields['MEETING_HOST'])); } $curAttendeesIndex[$user['USER_KEY']] = $user; $delIdStr .= ',' . (intVal($key) == $key ? intVal($key) : "'" . CDatabase::ForSql($key) . "'"); } } $delIdStr = trim($delIdStr, ', '); if ($delIdStr != '') { $strSql = "DELETE from b_calendar_attendees WHERE EVENT_ID=" . $ID . " AND USER_KEY in(" . $delIdStr . ")"; $res = $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__); } if (CModule::IncludeModule("im")) { CIMNotify::DeleteBySubTag("CALENDAR|INVITE|" . $ID); } // Add new attendees foreach ($dbAttendees as $att) { if ($att['bReinvite']) { $status = 'Q'; if ($att['bExternal']) { $status = 'Y'; // Send email CHANGE } else { if ($arFields['MEETING_HOST'] == $att['USER_KEY']) { $status = 'Y'; } if ($att["USER_ID"] != $userId && $bSendInvitations) { $CACHE_MANAGER->ClearByTag('calendar_user_' . $att["USER_ID"]); CCalendar::SendMessage(array('mode' => 'change', 'name' => $arFields['NAME'], "from" => $arFields["DT_FROM"], "to" => $arFields["DT_TO"], "location" => CCalendar::GetTextLocation($arFields["LOCATION"]), "meetingText" => $arFields["~MEETING"]["TEXT"], "guestId" => $att["USER_ID"], "eventId" => $ID, "userId" => $userId)); } } if (isset($arStatuses[$att['USER_KEY']]) && in_array($arStatuses[$att['USER_KEY']], array('Y', 'N', 'Q'))) { $status = $arStatuses[$att['USER_KEY']]; } $strSql = "UPDATE b_calendar_attendees SET " . $DB->PrepareUpdate("b_calendar_attendees", array("STATUS" => $status)) . " WHERE EVENT_ID=" . $ID . " AND USER_KEY=" . ($att['bExternal'] ? intVal($att['USER_KEY']) : "'" . CDatabase::ForSql($att['USER_KEY']) . "'"); $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } else { if ($att['bExternal']) { // Send email INVITE } else { if ($att["USER_ID"] != $userId && $bSendInvitations) { $CACHE_MANAGER->ClearByTag('calendar_user_' . $att["USER_ID"]); CCalendar::SendMessage(array('mode' => 'invite', 'name' => $arFields['NAME'], "from" => $arFields["DT_FROM"], "to" => $arFields["DT_TO"], "location" => CCalendar::GetTextLocation($arFields["LOCATION"]), "meetingText" => $arFields["~MEETING"]["TEXT"], "guestId" => $att["USER_ID"], "eventId" => $ID, "userId" => $userId)); } } if (isset($arStatuses[$att['USER_KEY']]) && in_array($arStatuses[$att['USER_KEY']], array('Y', 'N', 'Q'))) { $att["STATUS"] = $arStatuses[$att['USER_KEY']]; } $strSql = "INSERT INTO b_calendar_attendees(EVENT_ID, USER_KEY, USER_ID, USER_EMAIL, USER_NAME, STATUS, ACCESSIBILITY, REMIND) " . "VALUES (" . $ID . ", '" . $DB->ForSql($att["USER_KEY"]) . "', " . intVal($att["USER_ID"]) . ", '" . $DB->ForSql($att["USER_EMAIL"]) . "', '" . $DB->ForSql($att["USER_NAME"]) . "', '" . $DB->ForSql($att["STATUS"]) . "','" . $DB->ForSql($att["ACCESSIBILITY"]) . "','" . $DB->ForSql($att["REMIND"]) . "')"; $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__); } } if (count($arAffectedSections) > 0) { CCalendarSect::UpdateModificationLabel($arAffectedSections); } CCalendar::ClearCache('attendees_list'); }
function FormatDate($strDate, $format = "DD.MM.YYYY HH:MI:SS", $new_format = "DD.MM.YYYY HH:MI:SS") { $strDate = trim($strDate); $new_format = str_replace("MI", "I", $new_format); $new_format = preg_replace("/([DMYIHS])\\1+/is" . BX_UTF_PCRE_MODIFIER, "\\1", $new_format); $arFormat = preg_split("/[^0-9a-z]/is", strtoupper($format)); $arDate = preg_split("/[^0-9]/", $strDate); $arParsedDate = array(); $bound = min(count($arFormat), count($arDate)); for ($i = 0; $i < $bound; $i++) { //if ($intval) $r = IntVal($arDate[$i]); else if (preg_match("/^[0-9]/", $arDate[$i])) { $r = CDatabase::ForSql($arDate[$i], 4); } else { $r = IntVal($arDate[$i]); } $arParsedDate[substr($arFormat[$i], 0, 2)] = $r; } if (intval($arParsedDate["DD"]) <= 0 || intval($arParsedDate["MM"]) <= 0 || intval($arParsedDate["YY"]) <= 0) { return false; } $strResult = ""; if (intval($arParsedDate["YY"]) > 1970 && intval($arParsedDate["YY"]) < 2038) { $ux_time = mktime(intval($arParsedDate["HH"]), intval($arParsedDate["MI"]), intval($arParsedDate["SS"]), intval($arParsedDate["MM"]), intval($arParsedDate["DD"]), intval($arParsedDate["YY"])); for ($i = 0; $i < strlen($new_format); $i++) { $simbol = substr($new_format, $i, 1); switch ($simbol) { case "F": $match = GetMessage("FORUM_MONTH_" . date("n", $ux_time)); break; case "M": $match = GetMessage("FORUM_MON_" . date("n", $ux_time)); break; case "l": $match = GetMessage("FORUM_DAY_OF_WEEK_" . date("w", $ux_time)); break; case "D": $match = GetMessage("FORUM_DOW_" . date("w", $ux_time)); break; default: $match = date(substr($new_format, $i, 1), $ux_time); break; } $strResult .= $match; } } else { if ($arParsedDate["MM"] < 1 || $arParsedDate["MM"] > 12) { $arParsedDate["MM"] = 1; } for ($i = 0; $i < strLen($new_format); $i++) { $simbol = substr($new_format, $i, 1); switch ($simbol) { case "F": $match = str_pad($arParsedDate["MM"], 2, "0", STR_PAD_LEFT); if (intVal($arParsedDate["MM"]) > 0) { $match = GetMessage("FORUM_MONTH_" . intVal($arParsedDate["MM"])); } break; case "M": $match = str_pad($arParsedDate["MM"], 2, "0", STR_PAD_LEFT); if (intVal($arParsedDate["MM"]) > 0) { $match = GetMessage("FORUM_MON_" . intVal($arParsedDate["MM"])); } break; case "l": $match = str_pad($arParsedDate["DD"], 2, "0", STR_PAD_LEFT); if (intVal($arParsedDate["DD"]) > 0) { $match = GetMessage("FORUM_DAY_OF_WEEK_" . intVal($arParsedDate["DD"])); } break; case "D": $match = str_pad($arParsedDate["DD"], 2, "0", STR_PAD_LEFT); if (intVal($arParsedDate["DD"]) > 0) { $match = GetMessage("FORUM_DOW_" . intVal($arParsedDate["DD"])); } break; case "d": $match = str_pad($arParsedDate["DD"], 2, "0", STR_PAD_LEFT); break; case "m": $match = str_pad($arParsedDate["MM"], 2, "0", STR_PAD_LEFT); break; case "j": $match = intVal($arParsedDate["MM"]); break; case "Y": $match = str_pad($arParsedDate["YY"], 4, "0", STR_PAD_LEFT); break; case "y": $match = substr($arParsedDate["YY"], 2); break; case "H": $match = str_pad($arParsedDate["HH"], 2, "0", STR_PAD_LEFT); break; case "i": $match = str_pad($arParsedDate["MI"], 2, "0", STR_PAD_LEFT); break; case "S": $match = str_pad($arParsedDate["SS"], 2, "0", STR_PAD_LEFT); break; case "g": $match = intVal($arParsedDate["HH"]); if ($match > 12) { $match = $match - 12; } case "a": case "A": $match = intVal($arParsedDate["HH"]); if ($match > 12) { $match = $match - 12 . " PM"; } else { $match .= " AM"; } if (substr($new_format, $i, 1) == "a") { $match = strToLower($match); } default: $match = substr($new_format, $i, 1); break; } $strResult .= $match; } } return $strResult; }
function FormatDate($strDate, $format = "DD.MM.YYYY HH:MI:SS", $new_format = "DD.MM.YYYY HH:MI:SS") { $strDate = trim($strDate); $new_format = str_replace("MI", "I", strtoupper($new_format)); $new_format = preg_replace("/([DMYIHGST])\\1+/is", "\\1", $new_format); $arParsedDate = ParseDateTime($strDate, $format); if (!$arParsedDate) { return false; } foreach ($arParsedDate as $k => $v) { if (preg_match("/[^0-9]/", $v)) { $arParsedDate[$k] = CDatabase::ForSql($v, 10); } else { $arParsedDate[$k] = intval($v); } } /*time hacks*/ if (isset($arParsedDate["H"])) { $arParsedDate['HH'] = intval($arParsedDate["H"]); unset($arParsedDate["H"]); } elseif (isset($arParsedDate["GG"])) { $arParsedDate['HH'] = intval($arParsedDate["GG"]); unset($arParsedDate["GG"]); } elseif (isset($arParsedDate["G"])) { $arParsedDate['HH'] = intval($arParsedDate["G"]); unset($arParsedDate["G"]); } if (isset($arParsedDate['TT']) || isset($arParsedDate['T'])) { $middletime = $arParsedDate['TT'] ? $arParsedDate['TT'] : $arParsedDate['T']; if (strcasecmp($middletime, 'pm') === 0) { if ($arParsedDate['HH'] < 12) { $arParsedDate['HH'] += 12; } } else { if ($arParsedDate['HH'] == 12) { $arParsedDate['HH'] = 0; } } if (isset($arParsedDate['TT'])) { unset($arParsedDate['TT']); } else { unset($arParsedDate['T']); } } if (isset($arParsedDate["MMMM"])) { if (is_numeric($arParsedDate["MMMM"])) { $arParsedDate['MM'] = intval($arParsedDate["MMMM"]); } else { $arParsedDate['MM'] = GetNumMonth($arParsedDate["MMMM"]); if (!$arParsedDate['MM']) { $arParsedDate['MM'] = intval(date('m', strtotime($arParsedDate["MMMM"]))); } } } elseif (isset($arParsedDate["MM"])) { $arParsedDate['MM'] = intval($arParsedDate["MM"]); } elseif (isset($arParsedDate["M"])) { if (is_numeric($arParsedDate["M"])) { $arParsedDate['MM'] = intval($arParsedDate["M"]); } else { $arParsedDate['MM'] = GetNumMonth($arParsedDate["M"], true); if (!$arParsedDate['MM']) { $arParsedDate['MM'] = intval(date('m', strtotime($arParsedDate["M"]))); } } } if (isset($arParsedDate["YYYY"])) { $arParsedDate["YY"] = $arParsedDate["YYYY"]; } if (intval($arParsedDate["DD"]) <= 0 || intval($arParsedDate["MM"]) <= 0 || intval($arParsedDate["YY"]) <= 0) { return false; } $strResult = ""; if (intval($arParsedDate["YY"]) > 1970 && intval($arParsedDate["YY"]) < 2038) { $ux_time = mktime(isset($arParsedDate["HH"]) ? intval($arParsedDate["HH"]) : 0, isset($arParsedDate["MI"]) ? intval($arParsedDate["MI"]) : 0, isset($arParsedDate["SS"]) ? intval($arParsedDate["SS"]) : 0, intval($arParsedDate["MM"]), intval($arParsedDate["DD"]), intval($arParsedDate["YY"])); $new_format_len = strlen($new_format); for ($i = 0; $i < $new_format_len; $i++) { $ch = substr($new_format, $i, 1); if ($ch == "D") { $strResult .= date("d", $ux_time); } elseif ($ch == "M") { $strResult .= date("m", $ux_time); } elseif ($ch == "Y") { $strResult .= date("Y", $ux_time); } elseif ($ch == "H") { $strResult .= date("H", $ux_time); } elseif ($ch == "G") { $strResult .= date("h", $ux_time); } elseif ($ch == "I") { $strResult .= date("i", $ux_time); } elseif ($ch == "S") { $strResult .= date("s", $ux_time); } elseif ($ch == "T") { $strResult .= date("a", $ux_time); } else { $strResult .= $ch; } } } else { if ($arParsedDate["MM"] < 1 || $arParsedDate["MM"] > 12) { $arParsedDate["MM"] = 1; } $new_format_len = strlen($new_format); for ($i = 0; $i < $new_format_len; $i++) { $ch = substr($new_format, $i, 1); if ($ch == "D") { $strResult .= str_pad($arParsedDate["DD"], 2, "0", STR_PAD_LEFT); } elseif ($ch == "M") { $strResult .= str_pad($arParsedDate["MM"], 2, "0", STR_PAD_LEFT); } elseif ($ch == "Y") { $strResult .= str_pad($arParsedDate["YY"], 4, "0", STR_PAD_LEFT); } elseif ($ch == "H") { $strResult .= str_pad($arParsedDate["HH"], 2, "0", STR_PAD_LEFT); } elseif ($ch == "I") { $strResult .= str_pad($arParsedDate["MI"], 2, "0", STR_PAD_LEFT); } elseif ($ch == "S") { $strResult .= str_pad($arParsedDate["SS"], 2, "0", STR_PAD_LEFT); } else { $strResult .= $ch; } } } return $strResult; }
public static function GetSuperposedList($Params = array()) { global $DB; $checkPermissions = $Params['checkPermissions'] !== false; $checkSocnetPermissions = $Params['checkSocnetPermissions'] !== false; $userId = isset($Params['userId']) ? intVal($Params['userId']) : self::$userId; $arResult = array(); $arSectionIds = array(); $sqlSearch = ""; // Common types $strTypes = ""; if (isset($Params['TYPES']) && is_array($Params['TYPES'])) { foreach ($Params['TYPES'] as $type) { $strTypes .= ",'" . CDatabase::ForSql($type) . "'"; } $strTypes = trim($strTypes, ", "); if ($strTypes != "") { $sqlSearch .= "(CS.CAL_TYPE in (" . $strTypes . "))"; } } // Group's calendars $strGroups = "0"; if (is_array($Params['GROUPS']) && count($Params['GROUPS']) > 0) { foreach ($Params['GROUPS'] as $ownerId) { if (IntVal($ownerId) > 0) { $strGroups .= "," . IntVal($ownerId); } } if ($strGroups != "0") { if ($sqlSearch != "") { $sqlSearch .= " OR "; } $sqlSearch .= "(CS.OWNER_ID in (" . $strGroups . ") AND CS.CAL_TYPE='group')"; } } if ($sqlSearch != "") { $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tCS.*,\n\t\t\t\t\tCT.NAME AS TYPE_NAME, CT.DESCRIPTION AS TYPE_DESC\n\t\t\t\tFROM\n\t\t\t\t\tb_calendar_section CS\n\t\t\t\t\tLEFT JOIN b_calendar_type CT ON (CS.CAL_TYPE=CT.XML_ID)\n\t\t\t\tWHERE\n\t\t\t\t\t(\n\t\t\t\t\t\tCT.ACTIVE='Y'\n\t\t\t\t\tAND\n\t\t\t\t\t\tCS.ACTIVE='Y'\n\t\t\t\t\tAND\n\t\t\t\t\t(\n\t\t\t\t\t\t{$sqlSearch}\n\t\t\t\t\t))"; $res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); while ($arRes = $res->Fetch()) { $arSectionIds[] = $arRes['ID']; $arResult[] = $arRes; } } // User's calendars $strUsers = "0"; if (is_array($Params['USERS']) && count($Params['USERS']) > 0) { foreach ($Params['USERS'] as $ownerId) { if (IntVal($ownerId) > 0) { $strUsers .= "," . IntVal($ownerId); } } if ($strUsers != "0") { $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tCS.*,\n\t\t\t\t\tU.LOGIN AS USER_LOGIN, U.NAME AS USER_NAME, U.LAST_NAME AS USER_LAST_NAME, U.SECOND_NAME AS USER_SECOND_NAME\n\t\t\t\tFROM\n\t\t\t\t\tb_calendar_section CS\n\t\t\t\t\tLEFT JOIN b_user U ON (CS.OWNER_ID=U.ID)\n\t\t\t\tWHERE\n\t\t\t\t\t(\n\t\t\t\t\t\tCS.ACTIVE='Y'\n\t\t\t\t\tAND\n\t\t\t\t\t\tCS.OWNER_ID in (" . $strUsers . ")\n\t\t\t\t\tAND\n\t\t\t\t\t\tCS.CAL_TYPE='user'\n\t\t\t\t\t)"; $res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } while ($arRes = $res->Fetch()) { $arSectionIds[] = $arRes['ID']; $arResult[] = $arRes; } } if ($checkPermissions && count($arSectionIds) > 0) { if ($checkSocnetPermissions) { if (isset($Params['USERS']) && count($Params['USERS']) > 0) { $arFeaturesU = CSocNetFeatures::IsActiveFeature(SONET_ENTITY_USER, $Params['USERS'], "calendar"); $arViewU = CSocNetFeaturesPerms::CanPerformOperation($userId, SONET_ENTITY_USER, $Params['USERS'], "calendar", 'view'); $arWriteU = CSocNetFeaturesPerms::CanPerformOperation($userId, SONET_ENTITY_GROUP, $Params['USERS'], "calendar", 'write'); } if (isset($Params['GROUPS']) && count($Params['GROUPS']) > 0) { $arFeaturesG = CSocNetFeatures::IsActiveFeature(SONET_ENTITY_GROUP, $Params['GROUPS'], "calendar"); $arViewG = CSocNetFeaturesPerms::CanPerformOperation($userId, SONET_ENTITY_GROUP, $Params['GROUPS'], "calendar", 'view'); $arWriteG = CSocNetFeaturesPerms::CanPerformOperation($userId, SONET_ENTITY_GROUP, $Params['GROUPS'], "calendar", 'write'); } } CCalendarSect::GetArrayPermissions($arSectionIds); $res = array(); $sectIds = array(); foreach ($arResult as $sect) { $sectId = $sect['ID']; $ownerId = $sect['OWNER_ID']; if (self::CanDo('calendar_view_time', $sectId) && !in_array($sectId, $sectIds)) { if ($checkSocnetPermissions) { // Disabled in socialnetwork if ($sect['CAL_TYPE'] == 'group' && (!$arFeaturesG[$ownerId] || !$arViewG[$ownerId]) || $sect['CAL_TYPE'] == 'user' && (!$arFeaturesU[$ownerId] || !$arViewU[$ownerId])) { continue; } } $sect['PERM'] = array('view_time' => self::CanDo('calendar_view_time', $sectId), 'view_title' => self::CanDo('calendar_view_title', $sectId), 'view_full' => self::CanDo('calendar_view_full', $sectId), 'add' => self::CanDo('calendar_add', $sectId), 'edit' => self::CanDo('calendar_edit', $sectId), 'edit_section' => self::CanDo('calendar_edit_section', $sectId), 'access' => self::CanDo('calendar_edit_access', $sectId)); if ($checkSocnetPermissions) { if ($sect['CAL_TYPE'] == 'group' && !$arWriteG[$ownerId] || $sect['CAL_TYPE'] == 'user' && !$arWriteU[$ownerId]) { $sect['PERM']['add'] = false; $sect['PERM']['edit'] = false; $sect['PERM']['edit_section'] = false; $sect['PERM']['access'] = false; } } if ($sect['CAL_TYPE'] == 'user') { if (isset($sect['USER_NAME'], $sect['USER_LAST_NAME'])) { $sect['OWNER_NAME'] = CCalendar::GetUserName(array("NAME" => $sect['USER_NAME'], "LAST_NAME" => $sect['USER_LAST_NAME'], "LOGIN" => $sect['USER_LOGIN'], "ID" => $ownerId, "SECOND_NAME" => $sect['USER_SECOND_NAME'])); unset($sect['USER_LOGIN']); unset($sect['USER_LAST_NAME']); unset($sect['USER_SECOND_NAME']); unset($sect['USER_NAME']); } else { $sect['OWNER_NAME'] = CCalendar::GetUserName($ownerId); } } elseif ($sect['CAL_TYPE'] == 'group' && isset($Params['arGroups'])) { $sect['OWNER_NAME'] = $Params['arGroups'][$ownerId]['NAME']; } $res[] = $sect; $sectIds[] = $sectId; } } $arResult = $res; } return $arResult; }
public static function GetList($Params = array()) { global $DB; $access = new CAccess(); $access->UpdateCodes(); $arFilter = $Params['arFilter']; $arOrder = isset($Params['arOrder']) ? $Params['arOrder'] : array('XML_ID' => 'asc'); $checkPermissions = $Params['checkPermissions'] !== false; $bCache = CCalendar::CacheTime() > 0; if ($bCache) { $cache = new CPHPCache(); $cacheId = serialize(array('type_list', $arFilter, $arOrder)); $cachePath = CCalendar::CachePath() . 'type_list'; if ($cache->InitCache(CCalendar::CacheTime(), $cacheId, $cachePath)) { $res = $cache->GetVars(); $arResult = $res["arResult"]; $arTypeXmlIds = $res["arTypeXmlIds"]; } } if (!$bCache || !isset($arTypeXmlIds)) { static $arFields = array("XML_ID" => array("FIELD_NAME" => "CT.XML_ID", "FIELD_TYPE" => "string"), "NAME" => array("FIELD_NAME" => "CT.NAME", "FIELD_TYPE" => "string"), "ACTIVE" => array("FIELD_NAME" => "CT.ACTIVE", "FIELD_TYPE" => "string"), "DESCRIPTION" => array("FIELD_NAME" => "CT.DESCRIPTION", "FIELD_TYPE" => "string"), "EXTERNAL_ID" => array("FIELD_NAME" => "CT.EXTERNAL_ID", "FIELD_TYPE" => "string")); $err_mess = "Function: CCalendarType::GetList<br>Line: "; $arSqlSearch = array(); $strSqlSearch = ""; if (is_array($arFilter)) { $filter_keys = array_keys($arFilter); for ($i = 0, $l = count($filter_keys); $i < $l; $i++) { $n = strtoupper($filter_keys[$i]); $val = $arFilter[$filter_keys[$i]]; if (is_string($val) && strlen($val) <= 0) { continue; } if ($n == 'XML_ID') { if (is_array($val)) { $strXml = ""; foreach ($val as $xmlId) { $strXml .= ",'" . CDatabase::ForSql($xmlId) . "'"; } $arSqlSearch[] = "CT.XML_ID in (" . trim($strXml, ", ") . ")"; } else { $arSqlSearch[] = GetFilterQuery("CT.XML_ID", $val, 'N'); } } if ($n == 'EXTERNAL_ID') { $arSqlSearch[] = GetFilterQuery("CT.EXTERNAL_ID", $val, 'N'); } elseif (isset($arFields[$n])) { $arSqlSearch[] = GetFilterQuery($arFields[$n]["FIELD_NAME"], $val); } } } $strOrderBy = ''; foreach ($arOrder as $by => $order) { if (isset($arFields[strtoupper($by)])) { $strOrderBy .= $arFields[strtoupper($by)]["FIELD_NAME"] . ' ' . (strtolower($order) == 'desc' ? 'desc' . (strtoupper($DB->type) == "ORACLE" ? " NULLS LAST" : "") : 'asc' . (strtoupper($DB->type) == "ORACLE" ? " NULLS FIRST" : "")) . ','; } } if (strlen($strOrderBy) > 0) { $strOrderBy = "ORDER BY " . rtrim($strOrderBy, ","); } $strSqlSearch = GetFilterSqlSearch($arSqlSearch); $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tCT.*\n\t\t\t\tFROM\n\t\t\t\t\tb_calendar_type CT\n\t\t\t\tWHERE\n\t\t\t\t\t{$strSqlSearch}\n\t\t\t\t{$strOrderBy}"; $res = $DB->Query($strSql, false, $err_mess . __LINE__); $arResult = array(); $arTypeXmlIds = array(); while ($arRes = $res->Fetch()) { $arResult[] = $arRes; $arTypeXmlIds[] = $arRes['XML_ID']; } if ($bCache) { $cache->StartDataCache(CCalendar::CacheTime(), $cacheId, $cachePath); $cache->EndDataCache(array("arResult" => $arResult, "arTypeXmlIds" => $arTypeXmlIds)); } } if ($checkPermissions && count($arTypeXmlIds) > 0) { $arPerm = self::GetArrayPermissions($arTypeXmlIds); $res = array(); $arAccessCodes = array(); foreach ($arResult as $type) { $typeXmlId = $type['XML_ID']; if (self::CanDo('calendar_type_view', $typeXmlId)) { $type['PERM'] = array('view' => self::CanDo('calendar_type_view', $typeXmlId), 'add' => self::CanDo('calendar_type_add', $typeXmlId), 'edit' => self::CanDo('calendar_type_edit', $typeXmlId), 'edit_section' => self::CanDo('calendar_type_edit_section', $typeXmlId), 'access' => self::CanDo('calendar_type_access', $typeXmlId)); if (self::CanDo('calendar_type_access', $typeXmlId)) { $type['ACCESS'] = array(); if (count($arPerm[$typeXmlId]) > 0) { // Add codes to get they full names for interface $arAccessCodes = array_merge($arAccessCodes, array_keys($arPerm[$typeXmlId])); $type['ACCESS'] = $arPerm[$typeXmlId]; } } $res[] = $type; } } CCalendar::PushAccessNames($arAccessCodes); $arResult = $res; } return $arResult; }
public static function GetList($Params = array()) { global $DB, $USER_FIELD_MANAGER; $getUF = $Params['getUserfields'] !== false; $checkPermissions = $Params['checkPermissions'] !== false; $bCache = CCalendar::CacheTime() > 0; $Params['setDefaultLimit'] = $Params['setDefaultLimit'] === true; $userId = isset($Params['userId']) ? intVal($Params['userId']) : CCalendar::GetCurUserId(); CTimeZone::Disable(); if ($bCache) { $cache = new CPHPCache(); $cacheId = 'event_list_' . md5(serialize($Params)); if ($checkPermissions) { $cacheId .= 'chper' . CCalendar::GetCurUserId() . '|'; } if (CCalendar::IsSocNet() && CCalendar::IsSocnetAdmin()) { $cacheId .= 'socnetAdmin|'; } $cacheId .= CCalendar::GetOffset(); $cachePath = CCalendar::CachePath() . 'event_list'; if ($cache->InitCache(CCalendar::CacheTime(), $cacheId, $cachePath)) { $res = $cache->GetVars(); $arResult = $res["arResult"]; $arAttendees = $res["arAttendees"]; } } if (!$bCache || !isset($arResult)) { $arFilter = $Params['arFilter']; if ($getUF) { $obUserFieldsSql = new CUserTypeSQL(); $obUserFieldsSql->SetEntity("CALENDAR_EVENT", "CE.ID"); $obUserFieldsSql->SetSelect(array("UF_*")); $obUserFieldsSql->SetFilter($arFilter); } $fetchMeetings = $Params['fetchMeetings']; $Params['fetchAttendees'] = $Params['fetchAttendees'] !== false; $skipDeclined = $Params['skipDeclined'] === true; if ($Params['setDefaultLimit'] !== false) { if (!isset($arFilter["FROM_LIMIT"])) { // default 3 month back $arFilter["FROM_LIMIT"] = CCalendar::Date(time() - 31 * 3 * 24 * 3600, false); } if (!isset($arFilter["TO_LIMIT"])) { // default one year into the future $arFilter["TO_LIMIT"] = CCalendar::Date(time() + 365 * 24 * 3600, false); } } $arOrder = isset($Params['arOrder']) ? $Params['arOrder'] : array('SORT' => 'asc'); $arFields = self::GetFields(); if ($arFilter["DELETED"] === false) { unset($arFilter["DELETED"]); } elseif (!isset($arFilter["DELETED"])) { $arFilter["DELETED"] = "N"; } $ownerId = isset($arFilter['OWNER_ID']) ? $arFilter['OWNER_ID'] : CCalendar::GetOwnerId(); $arSqlSearch = array(); if (is_array($arFilter)) { $filter_keys = array_keys($arFilter); for ($i = 0, $l = count($filter_keys); $i < $l; $i++) { $n = strtoupper($filter_keys[$i]); $val = $arFilter[$filter_keys[$i]]; if (is_string($val) && strlen($val) <= 0 || strval($val) == "NOT_REF") { continue; } if ($n == 'FROM_LIMIT') { $ts = CCalendar::Timestamp($val, false); if ($ts > 0) { $arSqlSearch[] = "CE.DATE_TO_TS_UTC>=" . $ts; } } elseif ($n == 'TO_LIMIT') { $ts = CCalendar::Timestamp($val, false); if ($ts > 0) { $arSqlSearch[] = "CE.DATE_FROM_TS_UTC<=" . ($ts + 86399); } } elseif ($n == 'OWNER_ID' && intVal($val) > 0) { $arSqlSearch[] = "CE.OWNER_ID=" . intVal($val); } if ($n == 'NAME') { $arSqlSearch[] = "CE.NAME='" . CDatabase::ForSql($val) . "'"; } elseif ($n == 'CREATED_BY') { if (is_array($val)) { $val = array_map(intVal, $val); $arSqlSearch[] = 'CE.CREATED_BY IN (\'' . implode('\',\'', $val) . '\')'; } else { if (intVal($val) > 0) { $arSqlSearch[] = "CE.CREATED_BY=" . intVal($val); } } } elseif ($n == 'SECTION') { if (!is_array($val)) { $val = array($val); } $q = ""; if (is_array($val)) { $sval = ''; foreach ($val as $sectid) { if (intVal($sectid) > 0) { $sval .= intVal($sectid) . ','; } } $sval = trim($sval, ' ,'); if ($sval != '') { $q = 'CES.SECT_ID in (' . $sval . ')'; } } if ($q != "") { $arSqlSearch[] = $q; } } elseif ($n == 'DAV_XML_ID' && is_array($val)) { array_walk($val, array($DB, 'ForSql')); $arSqlSearch[] = 'CE.DAV_XML_ID IN (\'' . implode('\',\'', $val) . '\')'; } elseif (isset($arFields[$n])) { $arSqlSearch[] = GetFilterQuery($arFields[$n]["FIELD_NAME"], $val, 'N'); } } } if ($getUF) { $r = $obUserFieldsSql->GetFilter(); if (strlen($r) > 0) { $arSqlSearch[] = "(" . $r . ")"; } } if ($skipDeclined) { //$arSqlSearch[] = "(CE.IS_MEETING<>1 OR CE.MEETING_STATUS<>'N')"; } $strSqlSearch = GetFilterSqlSearch($arSqlSearch); $strOrderBy = ''; foreach ($arOrder as $by => $order) { if (isset($arFields[strtoupper($by)])) { $strOrderBy .= $arFields[strtoupper($by)]["FIELD_NAME"] . ' ' . (strtolower($order) == 'desc' ? 'desc' . (strtoupper($DB->type) == "ORACLE" ? " NULLS LAST" : "") : 'asc' . (strtoupper($DB->type) == "ORACLE" ? " NULLS FIRST" : "")) . ','; } } if (strlen($strOrderBy) > 0) { $strOrderBy = "ORDER BY " . rtrim($strOrderBy, ","); } $selectList = ""; foreach ($arFields as $field) { $selectList .= $field['FIELD_NAME'] . ", "; } $strSql = "\n\t\t\t\tSELECT " . $selectList . "CES.SECT_ID, CES.REL\n\t\t\t\t\t" . ($getUF ? $obUserFieldsSql->GetSelect() : '') . "\n\t\t\t\tFROM\n\t\t\t\t\tb_calendar_event CE\n\t\t\t\tLEFT JOIN b_calendar_event_sect CES ON (CE.ID=CES.EVENT_ID)\n\t\t\t\t" . ($getUF ? $obUserFieldsSql->GetJoin("CE.ID") : '') . "\n\t\t\t\tWHERE\n\t\t\t\t\t{$strSqlSearch}\n\t\t\t\t{$strOrderBy}"; $res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($getUF) { $res->SetUserFields($USER_FIELD_MANAGER->GetUserFields("CALENDAR_EVENT")); } $arResult = array(); $arMeetingIds = array(); $arEvents = array(); $bIntranet = CCalendar::IsIntranetEnabled(); $defaultMeetingSection = false; while ($event = $res->Fetch()) { $event['IS_MEETING'] = intVal($event['IS_MEETING']) > 0; if ($event['IS_MEETING'] && $event['CAL_TYPE'] == 'user' && $event['OWNER_ID'] == $userId && !$event['SECT_ID']) { if (!$defaultMeetingSection) { $defaultMeetingSection = CCalendar::GetMeetingSection($userId); if (!$defaultMeetingSection || !CCalendarSect::GetById($defaultMeetingSection, false)) { $sectRes = CCalendarSect::GetSectionForOwner($event['CAL_TYPE'], $userId); $defaultMeetingSection = $sectRes['sectionId']; } } self::ConnectEventToSection($event['ID'], $defaultMeetingSection); $event['SECT_ID'] = $defaultMeetingSection; } $arEvents[] = $event; if ($bIntranet && $event['IS_MEETING']) { $arMeetingIds[] = $event['ID']; } } if ($Params['fetchAttendees'] && count($arMeetingIds) > 0) { $arAttendees = self::GetAttendees($arMeetingIds); } else { $arAttendees = array(); } foreach ($arEvents as $event) { $event["ACCESSIBILITY"] = trim($event["ACCESSIBILITY"]); if ($bIntranet && $event['IS_MEETING']) { if (isset($event['MEETING']) && $event['MEETING'] != "") { $event['MEETING'] = unserialize($event['MEETING']); if (!is_array($event['MEETING'])) { $event['MEETING'] = array(); } } // if ($arUserMeeting[$event['ID']]) // { // $status = $arUserMeeting[$event['ID']]['STATUS']; // if ($skipDeclined && $status == "N") // continue; // // if ($status == "Y" || $userId == $ownerId) // { // $event['USER_MEETING'] = array( // 'ATTENDEE_ID' => $ownerId, // 'ACCESSIBILITY' => $arUserMeeting[$event['ID']]['ACCESSIBILITY'], // 'COLOR' => $arUserMeeting[$event['ID']]['COLOR'], // 'TEXT_COLOR' => $arUserMeeting[$event['ID']]['TEXT_COLOR'], // 'DESCRIPTION' => $arUserMeeting[$event['ID']]['DESCRIPTION'], // 'STATUS' => $status, // 'REMIND' => array() // ); // // if (isset($arUserMeeting[$event['ID']]['REMIND']) && $arUserMeeting[$event['ID']]['REMIND'] != "") // { // $event['USER_MEETING']['REMIND'] = unserialize($arUserMeeting[$event['ID']]['REMIND']); // if (!is_array($event['USER_MEETING']['REMIND'])) // $event['USER_MEETING']['REMIND'] = array(); // } // } // else if (is_array($arFilter['SECTION']) && !in_array($event['SECT_ID'], $arFilter['SECTION'])) // { // continue; // } // } } if (isset($event['REMIND']) && $event['REMIND'] != "") { $event['REMIND'] = unserialize($event['REMIND']); if (!is_array($event['REMIND'])) { $event['REMIND'] = array(); } } if ($bIntranet && $event['IS_MEETING'] && isset($arAttendees[$event['ID']]) && count($arAttendees[$event['ID']]) > 0) { $event['~ATTENDEES'] = $arAttendees[$event['ID']]; } $checkPermissionsForEvent = $userId != $event['CREATED_BY']; // It's creator // It's event in user's calendar if ($checkPermissionsForEvent && $event['CAL_TYPE'] == 'user' && $userId == $event['OWNER_ID']) { $checkPermissionsForEvent = false; } if ($checkPermissionsForEvent && $event['IS_MEETING'] && $event['USER_MEETING'] && $event['USER_MEETING']['ATTENDEE_ID'] == $userId) { $checkPermissionsForEvent = false; } if ($checkPermissionsForEvent && $event['IS_MEETING'] && is_array($event['~ATTENDEES'])) { foreach ($event['~ATTENDEES'] as $att) { if ($att['USER_ID'] == $userId) { $checkPermissionsForEvent = false; break; } } } if ($checkPermissions && $checkPermissionsForEvent) { $event = self::ApplyAccessRestrictions($event, $userId); } if ($event === false) { continue; } $event = self::PreHandleEvent($event); if ($Params['parseRecursion'] && self::CheckRecurcion($event)) { self::ParseRecursion($arResult, $event, array('fromLimit' => $arFilter["FROM_LIMIT"], 'toLimit' => $arFilter["TO_LIMIT"], 'instanceCount' => isset($Params['maxInstanceCount']) ? $Params['maxInstanceCount'] : false, 'preciseLimits' => isset($Params['preciseLimits']) ? $Params['preciseLimits'] : false)); } else { self::HandleEvent($arResult, $event); } } if ($bCache) { $cache->StartDataCache(CCalendar::CacheTime(), $cacheId, $cachePath); $cache->EndDataCache(array("arResult" => $arResult, "arAttendees" => $arAttendees)); } } CTimeZone::Enable(); //self::$lastAttendeesList = $arAttendees; if (!is_array(self::$lastAttendeesList)) { self::$lastAttendeesList = $arAttendees; } elseif (is_array($arAttendees)) { foreach ($arAttendees as $eventId => $att) { self::$lastAttendeesList[$eventId] = $att; } } return $arResult; }