/** * Show categories with checkboxes * * @global array $structure * @global type $cfg * @global type $gm * @global type $group * @global type $i18n_notmain * @global type $i18n_locale * @global type $i18n_read * @param type $chosen * @param type $name * @param type $parent * @param type $template * @param type $userrights * @param type $level * @return boolean */ function cot_usercategories_treecheck($chosen, $name, $parent = '', $template = '', $userrights = 'W', $level = 0) { global $structure, $cfg, $gm, $group; global $i18n_notmain, $i18n_locale, $i18n_read; if (empty($structure['usercategories'])) { return false; } if (!is_array($chosen)) { $chosen = explode(',', $chosen); } if (empty($parent)) { $i18n_enabled = $i18n_read; $children = array(); foreach ($structure['usercategories'] as $i => $x) { if (mb_substr_count($structure['usercategories'][$i]['path'], ".") == 0) { $children[] = $i; } } } else { $i18n_enabled = $i18n_read && cot_i18n_enabled($parent); $children = $structure['usercategories'][$parent]['subcats']; } if (count($children) == 0) { return false; } $t1 = new XTemplate(cot_tplfile(array('usercategories', 'catcheck', $template), 'plug')); $level++; foreach ($children as $row) { if (cot_auth('usercategories', $row, $userrights)) { $subcats = $structure['usercategories'][$row]['subcats']; $cattitle = htmlspecialchars($structure['usercategories'][$row]['title']); if ($i18n_enabled && $i18n_notmain) { $x_i18n = cot_i18n_get_cat($row, $i18n_locale); if ($x_i18n) { $cattitle = $x_i18n['title']; } } $t1->assign(array("CAT_ROW_CAT" => $row, "CAT_ROW_CHECKBOX" => is_array($chosen) && in_array($row, $chosen) || !is_array($chosen) && $row == $chosen ? cot_checkbox($row, $name, $cattitle, '', $row) : cot_checkbox('', $name, $cattitle, '', $row), "CAT_ROW_SUBCAT" => count($subcats) > 0 ? cot_usercategories_treecheck($chosen, $name, $row, $template, $userrights, $level) : '')); if ($i18n_enabled && $i18n_notmain) { $x_i18n = cot_i18n_get_cat($row, $i18n_locale); if ($x_i18n) { $urlparams = !$cfg['plugin']['i18n']['omitmain'] || $i18n_locale != $cfg['defaultlang'] ? "gm=" . $gm . "&cat=" . $row . "&group=" . $group . "&l=" . $i18n_locale : "gm=" . $gm . "&cat=" . $row . "&group=" . $group; $t1->assign(array('CAT_ROW_URL' => cot_url('users', $urlparams), 'CAT_ROW_TITLE' => $x_i18n['title'], 'CAT_ROW_DESC' => $x_i18n['desc'])); } } $t1->parse("MAIN.CAT_ROW"); if ($parent) { $t1->assign(array("CAT_TITLE" => htmlspecialchars($structure['usercategories'][$parent]['title']))); } $t1->assign(array("CAT_LEVEL" => $level)); } } $t1->parse("MAIN"); return $t1->text("MAIN"); }
<?php /** * [BEGIN_COT_EXT] * Hooks=users.profile.tags, users.register.tags, users.edit.tags * [END_COT_EXT] */ /** * User Categories plugin * * @package usercategories * @version 2.5.0 * @author CMSWorks Team * @copyright Copyright (c) CMSWorks.ru, littledev.ru * @license BSD */ defined('COT_CODE') or die('Wrong URL.'); require_once cot_incfile('usercategories', 'plug'); $prfx = 'USERS_REGISTER_'; if ($m == 'edit') { $prfx = 'USERS_EDIT_'; } elseif ($m == 'profile') { $prfx = 'USERS_PROFILE_'; } if ($prfx != 'USERS_REGISTER_') { $rcats = explode(',', $urr['user_cats']); } $t->assign(array($prfx . 'CAT' => cot_usercategories_treecheck($rcats, 'rcats[]')));