<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0'>
	<channel>
		<title>cotonti.com : cot_selectbox_structure</title>
		<link>https://www.cotonti.com</link>
		<description>Останні повідомлення в темі</description>
		<generator>Cotonti</generator>
		<language>en</language>
		<pubDate>Mon, 20 Apr 2026 02:26:02 -0000</pubDate>

		<item>
			<title>Kopusha</title>
			<description><![CDATA[<p>Помогите написать код или поделитесь готовым. Есть такая функция - </p>

<p>"PRDADD_FORM_CAT" =&gt; cot_selectbox_structure('market', $ritem['item_cat'], 'rcat'),</p>

<p>Она формирует выпадающий список из структуры модуля. У меня в i18n_structure есть переведенная структура, как дописать свою функцию для вывода с учетом локализации?</p>

<pre class="brush:php;gutter:false;toolbar:false;">
function cot_selectbox_structure($extension, $check, $name, $subcat = '', $hideprivate = true, $is_module = true,
                                 $add_empty = false, $attrs = '', $custom_rc = '')
{
	global $structure;

	$structure[$extension] = (is_array($structure[$extension])) ? $structure[$extension] : array();

	$result_array = array();
	foreach ($structure[$extension] as $i =&gt; $x)
	{
		$display = ($hideprivate &amp;&amp; $is_module) ? cot_auth($extension, $i, 'W') : true;
		if ($display &amp;&amp; !empty($subcat) &amp;&amp; isset($structure[$extension][$subcat]))
		{
			$mtch = $structure[$extension][$subcat]['path'].".";
			$mtchlen = mb_strlen($mtch);
			$display = (mb_substr($x['path'], 0, $mtchlen) == $mtch || $i === $subcat);
		}

		if ((!$is_module || cot_auth($extension, $i, 'R')) &amp;&amp; $i!='all' &amp;&amp; $display)
		{
			$result_array[$i] = $x['tpath'];
		}
	}
	$result = cot_selectbox($check, $name, array_keys($result_array), array_values($result_array), $add_empty, $attrs, $custom_rc);

	return($result);
}
</pre>

<p> </p>
<p class="updated"><strong>Added 55 minutes later:</strong></p><p>В итоге благодаря Виктору сделал, с небольшим комстылем. Готовый код - </p>

<pre class="brush:php;gutter:false;toolbar:false;">
function cot_selectbox_structure($extension, $check, $name, $subcat = '', $hideprivate = true, $is_module = true,
                                 $add_empty = false, $attrs = '', $custom_rc = '')
{
	require_once cot_incfile('i18n', 'plug');
	global $structure, $i18n_structure, $i18n_enabled, $i18n_read, $i18n_notmain, $i18n_locale;
	$i18n_locale = cot_import('l', 'G', 'ALP');
	$structure[$extension] = (is_array($structure[$extension])) ? $structure[$extension] : array();

	$result_array = array();
	foreach ($structure[$extension] as $i =&gt; $x)
	{
		$display = ($hideprivate &amp;&amp; $is_module) ? cot_auth($extension, $i, 'W') : true;
		if ($display &amp;&amp; !empty($subcat) &amp;&amp; isset($structure[$extension][$subcat]))
		{
			$mtch = $structure[$extension][$subcat]['path'].".";
			$mtchlen = mb_strlen($mtch);
			$display = (mb_substr($x['path'], 0, $mtchlen) == $mtch || $i === $subcat);
		}

		if ((!$is_module || cot_auth($extension, $i, 'R')) &amp;&amp; $i!='all' &amp;&amp; $display)
		{
			$result_array[$i] = $x['tpath'];
		}
		
		if ($i18n_locale &amp;&amp; $i18n_locale != 'en')
		{
			$cat_title = $i18n_structure[$i][$i18n_locale];
			$result_array[$i] = $cat_title['title'];
		}		
	}
	$result = cot_selectbox($check, $name, array_keys($result_array), array_values($result_array), $add_empty, $attrs, $custom_rc);

	return($result);
}
</pre>

<p>Пришлось </p>

<pre class="brush:php;gutter:false;toolbar:false;" style="font-size:15px;background-image:url(&quot;../img/code-blueprint.png&quot;);">
if ($i18n_locale &amp;&amp; $i18n_locale != 'en')</pre>

<p>так как почемуто в forms.php не идет проверка на $cfg['plugin']['i18n']['defaultlang']</p>
<p class="updated"><strong>Added 15 minutes later:</strong></p><p><u><strong>И не смог справится с подкатегориями</strong></u></p>

<p>Вот код где надо добавить условие если не en язык то брать title подкатегории с i18n, помогите</p>

<pre class="brush:php;gutter:false;toolbar:false;">
function cot_structure_children($area, $cat, $allsublev = true,  $firstcat = true, $userrights = true, $sqlprep = true)
{
	global $structure, $db;

	$mtch = '';
	$mtchlen = $mtchlvl = 0;

	if ($cat != '')
	{
		$mtch = $structure[$area][$cat]['path'] . '.';
		$mtchlen = mb_strlen($mtch);
		$mtchlvl = mb_substr_count($mtch, ".");
	}

	$catsub = array();
	if ($cat != '' &amp;&amp; $firstcat &amp;&amp; (($userrights &amp;&amp; cot_auth($area, $cat, 'R') || !$userrights)))
	{
		$catsub[] = $cat;
	}

	foreach ($structure[$area] as $i =&gt; $x)
	{
		if (($cat == '' || mb_substr($x['path'], 0, $mtchlen) == $mtch) &amp;&amp; (($userrights &amp;&amp; cot_auth($area, $i, 'R') || !$userrights)))
		{
			//$subcat = mb_substr($x['path'], $mtchlen + 1);
			if ($allsublev || (!$allsublev &amp;&amp; mb_substr_count($x['path'],".") == $mtchlvl))
			{
				$i = ($sqlprep) ? $db-&gt;prep($i) : $i;
				$catsub[] = $i;
			}
		}
	}
	return($catsub);
}
</pre>

<p> </p>
]]></description>
			<pubDate>Thu, 05 Лис 2020 09:36:08 -0000</pubDate>
			<link><![CDATA[https://www.cotonti.com/ua/forums?m=posts&q=9043&d=0#post45188]]></link>
		</item>
	</channel>
</rss>