<?php #------------------------------------------------------------------------------- /** @author Великодный В.В. (Joonte Ltd.) */ /******************************************************************************/ /******************************************************************************/ eval(COMP_INIT); /******************************************************************************/ /******************************************************************************/ if (Is_Error(System_Load('libs/Tree.php'))) { return ERROR | @Trigger_Error(500); } #------------------------------------------------------------------------------- $__USER = $GLOBALS['__USER']; #------------------------------------------------------------------------------- $Path = Tree_Path('Groups', (int) $__USER['GroupID'], 'ID'); #------------------------------------------------------------------------------- switch (ValueOf($Path)) { case 'error': return ERROR | @Trigger_Error(500); case 'exception': return ERROR | @Trigger_Error(400); case 'array': #--------------------------------------------------------------------------- $Result = array(); #--------------------------------------------------------------------------- $Where = array(SPrintF("((`GroupID` IN (%s) OR `UserID` = %u) AND `IsActive` = 'yes') OR ((SELECT COUNT(*) FROM `OrdersOwners` WHERE `OrdersOwners`.`ServiceID` = `Services`.`ID` AND `UserID` = %u) > 0)", Implode(',', $Path), $__USER['ID'], $__USER['ID']), "`IsHidden` != 'yes'"); #--------------------------------------------------------------------------- $Services = DB_Select('Services', array('ID', 'Code', 'Item', 'ServicesGroupID', 'IsActive', '(SELECT `Name` FROM `ServicesGroups` WHERE `ServicesGroups`.`ID` = `Services`.`ServicesGroupID`) as `ServicesGroupName`', '(SELECT `SortID` FROM `ServicesGroups` WHERE `ServicesGroups`.`ID` = `Services`.`ServicesGroupID`) as `ServicesSortID`'), array('SortOn' => array('ServicesSortID', 'SortID'), 'Where' => $Where)); #--------------------------------------------------------------------------- switch (ValueOf($Services)) {
function Tree_Path($TableID, $RowID, $ColumnsIDs = 'ID') { /****************************************************************************/ $__args_types = array('string', 'integer', 'string,array'); #----------------------------------------------------------------------------- $__args__ = Func_Get_Args(); eval(FUNCTION_INIT); /****************************************************************************/ $Regulars = Regulars(); #----------------------------------------------------------------------------- if (!Preg_Match($Regulars['ID'], $TableID)) { return new gException('WRONG_TABLE_ID', 'Неверный идентификатор таблицы'); } #----------------------------------------------------------------------------- $CacheID = SPrintF('Tree_Path[%s]', Md5(SPrintF('%s:%u:%s', $TableID, $RowID, Is_String($ColumnsIDs) ? $ColumnsIDs : Implode(':', $ColumnsIDs)))); #----------------------------------------------------------------------------- $Result = CacheManager::get($CacheID); if (!$Result) { #--------------------------------------------------------------------------- $Row = DB_Select($TableID, '*', array('UNIQ', 'ID' => $RowID)); #--------------------------------------------------------------------------- switch (ValueOf($Row)) { case 'error': return ERROR | @Trigger_Error('[Tree_Path]: не возможно выбрать запись'); case 'exception': return new gException('ROW_NOT_FOUND', 'Запись не найдена'); case 'array': #----------------------------------------------------------------------- if (Is_Array($ColumnsIDs)) { #--------------------------------------------------------------------- $Adding = array(); #--------------------------------------------------------------------- foreach ($ColumnsIDs as $ColumnID) { $Adding[$ColumnID] = $Row[$ColumnID]; } } else { $Adding = $Row[$ColumnsIDs]; } #----------------------------------------------------------------------- $Result = array($Adding); #----------------------------------------------------------------------- if ($Row['ID'] != $Row['ParentID']) { #--------------------------------------------------------------------- $Parents = Tree_Path($TableID, (int) $Row['ParentID'], $ColumnsIDs); #--------------------------------------------------------------------- switch (ValueOf($Parents)) { case 'error': return ERROR | @Trigger_Error('[Tree_Path]: не удалось осуществить рекурсивный вызов'); case 'exception': return ERROR | @Trigger_Error('[Tree_Path]: при рекурсивном вызове произошла ошибка'); case 'array': $Result = Array_Merge($Result, $Parents); break; default: return ERROR | @Trigger_Error(101); } } #----------------------------------------------------------------------- CacheManager::add($CacheID, $Result); break; default: return ERROR | @Trigger_Error(101); } } #----------------------------------------------------------------------------- return $Result; }
<?php #------------------------------------------------------------------------------- /** @author Alex Keda, for www.host-food.ru */ /******************************************************************************/ /******************************************************************************/ $__args_list = array('UserID', 'GroupID', 'ServiceID', 'SchemeID', 'DaysPay', 'ServiceInfo'); /******************************************************************************/ eval(COMP_INIT); /******************************************************************************/ /******************************************************************************/ $Entrance = Tree_Path('Groups', (int) $GroupID); #----------------------------------------------------------------- switch (ValueOf($Entrance)) { case 'error': return ERROR | @Trigger_Error(500); case 'exception': return ERROR | @Trigger_Error(400); case 'array': break; default: return ERROR | @Trigger_Error(101); } #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- $UniqID = UniqID('Politics'); #------------------------------------------------------------------------------- $Create = SPrintF("CREATE TEMPORARY TABLE `%s` AS SELECT *, CONCAT(`UserID`,':',`GroupID`,':',(IF(ISNULL(`FromServiceID`),'0',`FromServiceID`)),':',(IF(ISNULL(`FromSchemesGroupID`),'0',`FromSchemesGroupID`)),':',(IF(ISNULL(`ToServiceID`),'0',`ToServiceID`)),':',(IF(ISNULL(`ToSchemeID`),'0',`ToSchemeID`)),':',(IF(ISNULL(`ToSchemesGroupID`),'0',`ToSchemesGroupID`)),':',`DaysDiscont`) AS `UniqScheme` FROM `Politics` ORDER BY `Discont` DESC", $UniqID); #------------------------------------------------------------------------------- $IsQuery = DB_Query($Create); if (Is_Error($IsQuery)) {
#------------------------------------------------------------------------------- #------------------------------------------------------------------------------- if ($Waiting >= 5) { return ERROR | @Trigger_Error('Пользователь уже работает в данный момент'); } #------------------------------------------------------------------------------- } #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- $IsQuery = DB_Query(SPrintF('SET @local.__USER_ID = %u', $User['ID'])); if (Is_Error($IsQuery)) { return ERROR | @Trigger_Error(500); } #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- $Path = Tree_Path('Groups', (int) $User['GroupID'], 'ID'); #------------------------------------------------------------------------------- switch (ValueOf($Path)) { case 'error': return ERROR | @Trigger_Error(500); case 'exception': return ERROR | @Trigger_Error(400); case 'array': break; default: return ERROR | @Trigger_Error(101); } #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- $User['Path'] = $Path; #-------------------------------------------------------------------------------
#------------------------------------------------------------------------------- if (FALSE) { #------------------------------------------------------------------------------- $Columns = array('(SELECT `SchemeID` FROM `HostingOrders` WHERE `HostingOrders`.`OrderID` = `Basket`.`OrderID`) as `SchemeID`', 'Amount'); #------------------------------------------------------------------------------- $Basket = DB_Select('Basket', $Columns, array('Where' => SPrintF('(SELECT `ServiceID` FROM `Orders` WHERE `Orders`.`ID` = `OrderID`) = 10000 AND (SELECT `ContractID` FROM `Orders` WHERE `Orders`.`ID` = `OrderID`) = %u', $DomainOrder['ContractID']))); #------------------------------------------------------------------------------- switch (ValueOf($Basket)) { case 'error': return ERROR | @Trigger_Error(500); case 'exception': # No more... break; case 'array': #------------------------------------------------------------------------------- $Entrance = Tree_Path('Groups', (int) $DomainOrder['GroupID']); #------------------------------------------------------------------------------- switch (ValueOf($Entrance)) { case 'error': return ERROR | @Trigger_Error(500); case 'exception': return ERROR | @Trigger_Error(400); case 'array': #------------------------------------------------------------------------------- foreach ($Basket as $Order) { #------------------------------------------------------------------------------- # HostingDomainPolitics deleted #------------------------------------------------------------------------------- } #------------------------------------------------------------------------------- break 2;