Application->GetVar('after_script'); if ($after_script) { return ''; } return ''; } /** * Returns section title with #section# keyword replaced with current section * * @param Array $params * @return string */ function GetSectionTitle($params) { if (array_key_exists('default', $params)) { return $params['default']; } return $this->Application->Phrase( kUtil::replaceModuleSection($params['phrase']) ); } /** * Returns section icon with #section# keyword replaced with current section * * @param Array $params * @return string */ function GetSectionIcon($params) { return kUtil::replaceModuleSection($params['icon']); } /** * Returns version of module by name * * @param Array $params * @return string */ function ModuleVersion($params) { return $this->Application->findModule('Name', $params['module'], 'Version'); } /** * Used in table form section drawing * * @param Array $params * @return string */ function DrawTree($params) { static $deep_level = 0; // when processings, then sort children by priority (key of children array) $ret = ''; $section_name = $params['section_name']; $params['name'] = $this->SelectParam($params, 'name,render_as,block'); /** @var kSectionsHelper $sections_helper */ $sections_helper = $this->Application->recallObject('SectionsHelper'); $section_data =& $sections_helper->getSectionData($section_name); $params['children_count'] = isset($section_data['children']) ? count($section_data['children']) : 0; $params['deep_level'] = $deep_level++; $template = $section_data['url']['t']; unset($section_data['url']['t']); $section_data['section_url'] = $this->Application->HREF($template, '', $section_data['url']); $ret .= $this->Application->ParseBlock( array_merge($params, $section_data) ); if (!isset($section_data['children'])) { return $ret; } ksort($section_data['children'], SORT_NUMERIC); foreach ($section_data['children'] as $section_name) { if (!$sections_helper->sectionVisible($section_name)) { continue; } $params['section_name'] = $section_name; $ret .= $this->DrawTree($params); $deep_level--; } return $ret; } function SectionInfo($params) { $section = $params['section']; if ($section == '#session#') { $section = $this->Application->RecallVar('section'); } /** @var kSectionsHelper $sections_helper */ $sections_helper = $this->Application->recallObject('SectionsHelper'); $section_data =& $sections_helper->getSectionData($section); if (!$section_data) { throw new Exception('Use of undefined section "' . $section . '" in "' . __METHOD__ . '"'); return ''; } if (array_key_exists('parent', $params) && $params['parent']) { do { $section = $section_data['parent']; $section_data =& $sections_helper->getSectionData($section); } while (array_key_exists('use_parent_header', $section_data) && $section_data['use_parent_header']); } $info = $params['info']; switch ($info) { case 'module_path': if (isset($params['module']) && $params['module']) { $module = $params['module']; } elseif (isset($section_data['icon_module'])) { $module = $section_data['icon_module']; } else { $module = '#session#'; } $res = $this->ModulePath(array('module' => $module)); break; case 'perm_section': $res = $sections_helper->getPermSection($section); break; case 'label': $res = ''; if ( $section ) { if ( $section == 'in-portal:root' ) { // don't translate label for top section, because it's already translated $res = $section_data['label']; } else { $no_editing = array_key_exists('no_editing', $params) ? $params['no_editing'] : false; $res = $this->Application->Phrase($section_data['label'], !$no_editing); } } break; default: $res = $section_data[$info]; break; } if (array_key_exists('as_label', $params) && $params['as_label']) { $res = $this->Application->Phrase($res); } return $res; } function PrintSection($params) { $section_name = $params['section_name']; if ($section_name == '#session#') { $section_name = $this->Application->RecallVar('section'); } /** @var kSectionsHelper $sections_helper */ $sections_helper = $this->Application->recallObject('SectionsHelper'); if (isset($params['use_first_child']) && $params['use_first_child']) { $section_name = $sections_helper->getFirstChild($section_name, true); } $section_data =& $sections_helper->getSectionData($section_name); $params['name'] = $this->SelectParam($params, 'name,render_as,block'); $params['section_name'] = $section_name; $url_params = $section_data['url']; unset($url_params['t']); $section_data['section_url'] = $this->Application->HREF($section_data['url']['t'], '', $url_params); $ret = $this->Application->ParseBlock( array_merge($params, $section_data) ); return $ret; } /** * Used in XML drawing for tree * * @param Array $params * @return string */ function PrintSections($params) { // when processings, then sort children by priority (key of children array) $ret = ''; $section_name = $params['section_name']; if ($section_name == '#session#') { $section_name = $this->Application->RecallVar('section'); } /** @var kSectionsHelper $sections_helper */ $sections_helper = $this->Application->recallObject('SectionsHelper'); $section_data =& $sections_helper->getSectionData($section_name); $params['name'] = $this->SelectParam($params, 'name,render_as,block'); if (!isset($section_data['children'])) { return ''; } ksort($section_data['children'], SORT_NUMERIC); foreach ($section_data['children'] as $section_name) { $params['section_name'] = $section_name; $section_data =& $sections_helper->getSectionData($section_name); if (!$sections_helper->sectionVisible($section_name)) { continue; } else { $show_mode = isset($section_data['show_mode']) ? $section_data['show_mode'] : smNORMAL; $section_data['debug_only'] = ($show_mode == smDEBUG) || ($show_mode == smSUPER_ADMIN) ? 1 : 0; } if (isset($section_data['tabs_only']) && $section_data['tabs_only']) { $perm_status = false; $folder_label = $section_data['label']; ksort($section_data['children'], SORT_NUMERIC); foreach ($section_data['children'] as $priority => $section_name) { // if only tabs in this section & none of them have permission, then skip section too $section_name = $sections_helper->getPermSection($section_name); $perm_status = $this->Application->CheckPermission($section_name.'.view', 1); if ($perm_status) { break; } } if (!$perm_status) { // no permission for all tabs -> don't display tree node either continue; } $params['section_name'] = $section_name; $section_data =& $sections_helper->getSectionData($section_name); $section_data['label'] = $folder_label; // use folder label in tree $section_data['is_tab'] = 1; } else { $section_name = $sections_helper->getPermSection($section_name); if (!$this->Application->CheckPermission($section_name.'.view', 1)) continue; } $params['children_count'] = isset($section_data['children']) ? count($section_data['children']) : 0; // remove template, so it doesn't appear as additional parameter in url $template = $section_data['url']['t']; unset($section_data['url']['t']); $section_data['section_url'] = $this->Application->HREF($template, '', $section_data['url']); $late_load = getArrayValue($section_data, 'late_load'); if ($late_load) { $t = $late_load['t']; unset($late_load['t']); $section_data['late_load'] = $this->Application->HREF($t, '', $late_load); $params['children_count'] = 99; } else { $section_data['late_load'] = ''; } // restore template $section_data['url']['t'] = $template; $ret .= $this->Application->ParseBlock( array_merge($params, $section_data) ); $params['section_name'] = $section_name; } return preg_replace("/\r\n|\n/", '', $ret); } function ListSectionPermissions($params) { $section_name = isset($params['section_name']) ? $params['section_name'] : $this->Application->GetVar('section_name'); /** @var kSectionsHelper $sections_helper */ $sections_helper = $this->Application->recallObject('SectionsHelper'); $section_data =& $sections_helper->getSectionData($section_name); $block_params = array_merge($section_data, Array('name' => $params['render_as'], 'section_name' => $section_name)); $ret = ''; foreach ($section_data['permissions'] as $perm_name) { if (preg_match('/^advanced:(.*)/', $perm_name) != $params['type']) continue; $block_params['perm_name'] = $perm_name; $ret .= $this->Application->ParseBlock($block_params); } return $ret; } function ModuleInclude($params) { foreach ($params as $param_name => $param_value) { $params[$param_name] = kUtil::replaceModuleSection($param_value); } return $this->Application->ProcessParsedTag('m', 'ModuleInclude', $params); } function TodayDate($params) { return date($params['format']); } /** * Draws section tabs using block name passed * * @param Array $params */ function ListTabs($params) { /** @var kSectionsHelper $sections_helper */ $sections_helper = $this->Application->recallObject('SectionsHelper'); $section_data =& $sections_helper->getSectionData($params['section_name']); $ret = ''; $block_params = Array('name' => $params['render_as']); ksort($section_data['children'], SORT_NUMERIC); foreach ($section_data['children'] as $priority => $section_name) { $perm_section = $sections_helper->getPermSection($section_name); if ( !$this->Application->CheckPermission($perm_section.'.view') ) { continue; } $tab_data =& $sections_helper->getSectionData($section_name); $show_mode = isset($tab_data['show_mode']) ? $tab_data['show_mode'] : smNORMAL; $debug_only = ($show_mode == smDEBUG) || ($show_mode == smSUPER_ADMIN); if ( $show_mode == smHIDE || ($debug_only && !$this->Application->isDebugMode()) ) { continue; } $block_params['t'] = $tab_data['url']['t']; $block_params['pass'] = $tab_data['url']['pass']; $block_params['title'] = $tab_data['label']; $block_params['main_prefix'] = $section_data['SectionPrefix']; $ret .= $this->Application->ParseBlock($block_params); } return $ret; } /** * Returns list of module item tabs that have view permission in current category * * @param Array $params */ function ListCatalogTabs($params) { $ret = ''; $special = isset($params['special']) ? $params['special'] : ''; $replace_main = isset($params['replace_m']) && $params['replace_m']; $skip_prefixes = isset($params['skip_prefixes']) ? explode(',', $params['skip_prefixes']) : Array(); $block_params = $this->prepareTagParams($params); $block_params['name'] = $params['render_as']; foreach ($this->Application->ModuleInfo as $module_name => $module_info) { $prefix = $module_info['Var']; if ($prefix == 'm' && $replace_main) { $prefix = 'c'; } if (in_array($prefix, $skip_prefixes) || !$this->Application->prefixRegistred($prefix) || !$this->Application->getUnitOption($prefix, 'CatalogItem')) { continue; } $icon = $this->Application->getUnitOption($prefix, 'CatalogTabIcon'); if (strpos($icon, ':') !== false) { list ($icon_module, $icon) = explode(':', $icon, 2); } else { $icon_module = 'core'; } $label = $this->Application->getUnitOption($prefix, $params['title_property']); $block_params['title'] = $label; $block_params['prefix'] = $prefix; $block_params['icon_module'] = $icon_module; $block_params['icon'] = $icon; $ret .= $this->Application->ParseBlock($block_params); } return $ret; } /** * Renders inividual catalog tab based on prefix and title_property given * * @param Array $params * @return string */ function CatalogTab($params) { $icon = $this->Application->getUnitOption($params['prefix'], 'CatalogTabIcon'); if (strpos($icon, ':') !== false) { list ($icon_module, $icon) = explode(':', $icon, 2); } else { $icon_module = 'core'; } $block_params = $this->prepareTagParams($params); $block_params['name'] = $params['render_as']; $block_params['icon_module'] = $icon_module; $block_params['icon'] = $icon; $block_params['title'] = $this->Application->getUnitOption($params['prefix'], $params['title_property']); return $this->Application->ParseBlock($block_params); } /** * Allows to construct link for opening any type of catalog item selector * * @param Array $params * @return string */ function SelectorLink($params) { $mode = 'catalog'; if (isset($params['mode'])) { // {catalog, advanced_view} $mode = $params['mode']; unset($params['mode']); } $params['t'] = 'catalog/item_selector/item_selector_'.$mode; $params['m_cat_id'] = $this->Application->getBaseCategory(); $default_params = Array('pass' => 'all,'.$params['prefix']); unset($params['prefix']); $pass_through = Array(); if (isset($params['tabs_dependant'])) { // {yes, no} $pass_through['td'] = $params['tabs_dependant']; unset($params['tabs_dependant']); } if (isset($params['selection_mode'])) { // {single, multi} $pass_through['tm'] = $params['selection_mode']; unset($params['selection_mode']); } if (isset($params['tab_prefixes'])) { // {all, none, } $pass_through['tp'] = $params['tab_prefixes']; unset($params['tab_prefixes']); } if ($pass_through) { // add pass_through to selector url if any $params['pass_through'] = implode(',', array_keys($pass_through)); $params = array_merge($params, $pass_through); } // user can override default parameters (except pass_through of course) $params = array_merge($default_params, $params); return $this->Application->ProcessParsedTag('m', 'T', $params); } function TimeFrame($params) { $w = adodb_date('w'); $m = adodb_date('m'); $y = adodb_date('Y'); //FirstDayOfWeek is 0 for Sunday and 1 for Monday $fdow = $this->Application->ConfigValue('FirstDayOfWeek'); if ( $fdow && $w == 0 ) { $w = 7; } $today_start = adodb_mktime(0, 0, 0, adodb_date('m'), adodb_date('d'), $y); $first_day_of_this_week = $today_start - ($w - $fdow) * 86400; $first_day_of_this_month = adodb_mktime(0, 0, 0, $m, 1, $y); $this_quater = ceil($m / 3); $this_quater_start = adodb_mktime(0, 0, 0, $this_quater * 3 - 2, 1, $y); switch ( $params['type'] ) { case 'last_week_start': $timestamp = $first_day_of_this_week - 86400 * 7; break; case 'last_week_end': $timestamp = $first_day_of_this_week - 1; break; case 'last_month_start': $timestamp = $m == 1 ? adodb_mktime(0, 0, 0, 12, 1, $y - 1) : adodb_mktime(0, 0, 0, $m - 1, 1, $y); break; case 'last_month_end': $timestamp = $first_day_of_this_month = adodb_mktime(0, 0, 0, $m, 1, $y) - 1; break; case 'last_quater_start': $timestamp = $this_quater == 1 ? adodb_mktime(0, 0, 0, 10, 1, $y - 1) : adodb_mktime(0, 0, 0, ($this_quater - 1) * 3 - 2, 1, $y); break; case 'last_quater_end': $timestamp = $this_quater_start - 1; break; case 'last_6_months_start': $timestamp = $m <= 6 ? adodb_mktime(0, 0, 0, $m + 6, 1, $y - 1) : adodb_mktime(0, 0, 0, $m - 6, 1, $y); break; case 'last_year_start': $timestamp = adodb_mktime(0, 0, 0, 1, 1, $y - 1); break; case 'last_year_end': $timestamp = adodb_mktime(23, 59, 59, 12, 31, $y - 1); break; default: $timestamp = 0; break; } if ( isset($params['format']) ) { $format = $params['format']; if ( preg_match("/_regional_(.*)/", $format, $regs) ) { /** @var LanguagesItem $lang */ $lang = $this->Application->recallObject('lang.current'); $format = $lang->GetDBField($regs[1]); } return adodb_date($format, $timestamp); } return $timestamp; } /** * Redirect to cache rebuild template, when required by installator * * @param Array $params */ function CheckPermCache($params) { // we have separate session between install wizard and admin console, so store in cache $global_mark = $this->Application->getDBCache('ForcePermCacheUpdate'); $local_mark = $this->Application->RecallVar('PermCache_UpdateRequired'); if ( $global_mark || $local_mark ) { $this->Application->RemoveVar('PermCache_UpdateRequired'); $rebuild_mode = $this->Application->ConfigValue('CategoryPermissionRebuildMode'); if ( $rebuild_mode == CategoryPermissionRebuild::SILENT ) { /** @var kPermCacheUpdater $updater */ $updater = $this->Application->makeClass('kPermCacheUpdater'); $updater->OneStepRun(); $this->Application->HandleEvent(new kEvent('c:OnResetCMSMenuCache')); } elseif ( $rebuild_mode == CategoryPermissionRebuild::AUTOMATIC ) { // update with progress bar return true; } } return false; } /** * Checks if current protocol is SSL * * @param Array $params * @return int */ function IsSSL($params) { return (PROTOCOL == 'https://')? 1 : 0; } function PrintColumns($params) { $picker_helper = new kColumnPickerHelper( $this->Application->RecallVar('main_prefix'), $this->Application->GetLinkedVar('grid_name') ); $cols = $picker_helper->getData(); $this->Application->Phrases->AddCachedPhrase('__FREEZER__', '-------------'); $o = ''; if ( isset($params['hidden']) && $params['hidden'] ) { foreach ( $cols->hiddenFields as $column_name ) { $title = $this->Application->Phrase($cols->getTitle($column_name)); $o .= "