Файл: adultscript-2.0.3-pro/files/templates/defboot/extend/plugins/categories_select.plugin.php
Строк: 20
<?php
defined('_VALID') or die('Restricted Access!');
function template_plugin_categories_select($categories = array(), $selected = array())
{
if (!$categories) {
$cache = VF::factory('cache');
if (!$categories = $cache->get('categories', 86400)) {
$db = VF::factory('database');
$db->query("SELECT cat_id, parent_id, name, slug, total_videos
FROM #__video_categories
ORDER BY slug, parent_id ASC");
if ($db->affected_rows()) {
$categories = $db->fetch_rows();
if (VCfg::get('video.subcategories')) {
$categories = VArray::tree($categories);
}
$cache->store('categories', $categories, 86400);
}
}
}
$output = array();
$output[] = '<select name="category[]" id="category" class="form-control" multiple="multiple">';
foreach ($categories as $category) {
$cat_id = $category['cat_id'];
$checked = (in_array($cat_id, $selected)) ? ' selected="selected"' : '';
$output[] = '<option value="'.$cat_id.'"'.$checked.'>'.e($category['name']).'</option>';
if (isset($category['subcategories']) && $category['subcategories']) {
foreach ($category['subcategories'] as $subcategory) {
$cat_id = $subcategory['cat_id'];
$checked = (in_array($cat_id, $selected)) ? ' selected="selected"' : '';
$output[] = '<option value="'.$cat_id.'"'.$checked.'>'.e($subcategory['name']).'</option>';
}
}
}
$output[] = '</select>';
return implode("n", $output);
}