<? global $vis_language; global $vis_forward;
$vis_forward = isset($operation['vis_forward']) ? $operation['vis_forward'] : ''; ?>
<div>
    <span id="vis_category_main_0" class="vis_tree_main_cat" onclick="vis_toggle_subcategory_view(0)">
		<span class="vis-icon vis-icon-arrow-open"></span>
		<? echo $vis_language['TXTROOT']; ?>
	</span>
	<?php if($quick_insert == -1){ ?>
	<span onclick="$(this).visExecution('load_module', '<? echo $vis_language['TXTADDCATEGORY']; ?>', {'vis_module':'selfhelp', 'vis_operation':'add_new_category', 'cache':'true', 'vis_parent_id':0, 'vis_domain_id':<? echo $domain; ?>})" title="<? echo $vis_language['TXTADDCATEGORY']; ?>" class="vis-icon-med vis-icon-add-category"></span>
	<?php }
	if(isset($selfhelp) && $selfhelp!=NULL) { ?>
		<div id="vis_category_sub_0" class="vis_tree_cat"> <? vis_show_subcategories($selfhelp, $quick_insert, $domain,$attachmentids); ?> </div>
    <? } ?>
</div>
<?
    function vis_show_subcategories($details, $links, $domain, $attachmentids='') {
        global $vis_language; 
        for($i=0;$i<count($details);$i++) {
            if(isset($details[$i]['subcat']) && $details[$i]['subcat']!=NULL) {$class='vis-icon vis-icon-arrow-open';} else { $class='vis-icon-med vis-icon-category'; } ?>
			<div>
				<span id="vis_category_main_<? echo $details[$i]['selfhelp_id']; ?>" class="vis_tree_main_cat">
					<span onclick="vis_toggle_subcategory_view(<? echo $details[$i]['selfhelp_id']; ?>)" class="<? echo $class; ?> vis-pointer"></span>
					<?php if($links==-1) { ?>
					<span onclick="$(this).visExecution('load_module', '<? echo addslashes(substr($details[$i]['selfhelp_title'],0,15)); ?>', {'vis_module':'selfhelp', 'vis_operation':'view_category', 'vis_category_id':<? echo $details[$i]['selfhelp_id']; ?>, 'vis_domain_id':<? echo $domain; ?>})"><? echo $details[$i]['selfhelp_title']; ?></span>
					<?php } else { echo "<span>" . $details[$i]['selfhelp_title'] . "</span>"; } ?>
				</span>
				<? if($links==-1) { ?>
				<span onclick="$(this).visExecution('load_module', '<? echo $vis_language['TXTADDCATEGORY']; ?>', {'vis_module':'selfhelp', 'vis_operation':'add_new_category', 'cache':'true', 'vis_parent_id':<? echo $details[$i]['selfhelp_id']; ?>, 'vis_domain_id':<? echo $domain; ?>})" class="vis-icon-med vis-icon-add-category" title="<? echo $vis_language['TXTADDCATEGORY']; ?>" ></span>
				<span onclick="$(this).visExecution('load_module', '<? echo $vis_language['TXTADDARTICLE']; ?>', {'vis_module':'selfhelp', 'vis_operation':'new_article', 'cache':'true', 'vis_category_id':<? echo $details[$i]['selfhelp_id']; ?>})" class="vis-icon-med vis-icon-add-article" title="<? echo $vis_language['TXTADDARTICLE']; ?>"></span>
				<? } ?>
			</div>
			<?
				if(isset($details[$i]['subcat']) && $details[$i]['subcat']!=NULL) { ?>
			<div id="vis_category_sub_<? echo $details[$i]['selfhelp_id']; ?>" class="vis_tree_cat"> <?
				vis_show_subcategories($details[$i]['subcat'], $links, $domain); ?> </div>
			<?
				}
				if(isset($details[$i]['article']) && $details[$i]['article']!=-1) { ?>
					<div id="vis_article_sub_<? echo $details[$i]['selfhelp_id']; ?>" class="vis_tree_cat"> <?
				vis_show_articles($details[$i]['article'], $links, $attachmentids); ?> </div>
			<?
				}
		}
    }
    function vis_show_articles($articles, $location, $attachmentids='') {
		global $vis_forward;
		$position = ($vis_forward != '') ? 'vis_forward_attachments' : (($location==0)?'vis_new_ticket_attachments':'vis_reply_attachments');
		for($i=0;$i<count($articles);$i++) {
			echo '<div onclick="';
			if($location==-1) { ?> $(this).visExecution('load_module', '<? echo addslashes(str_replace(array('"', "'", '/', '\\'), '', substr($articles[$i]['article_title'],0,15))); ?>', {'vis_module':'selfhelp', 'vis_operation':'view_article', 'vis_article_id':<? echo $articles[$i]['article_id']; ?>}); <? }
			else { ?> $('#vis_selfhelp_quickinsert').dialog('close'); $('#vis_ticket_post_<? echo $location; ?>').visExecution('load_area', {'vis_module':'selfhelp', 'vis_operation':'add_quick_article', 'vis_as_val':1, 'vis_article_id':<? echo $articles[$i]['article_id']; ?>}, function(){$('#vis_ticket_post_<? echo $location; ?>').wysiwyg('setContent', $('#vis_ticket_post_<? echo $location; ?>').val())}); $('#<?= $position ?>').visExecution('load_area', {'vis_module':'selfhelp', 'vis_operation':'add_quick_attachments','attachment_ids':'<? echo $attachmentids;?>', 'vis_ticket_id':<? echo $location; ?>,'vis_article_id':<? echo $articles[$i]['article_id']; if($location!=0) echo ", 'vis_ticket_reply':1"; if($vis_forward != '') echo ", 'vis_forward': 1"?>}); <? }
			echo '"><span class="vis-pointer"><span class="vis-icon-med vis-icon-article"></span> '.$articles[$i]['article_title'].'</span></div>';
		}
    } ?>
<script>
    function vis_toggle_subcategory_view(catid) {
        $("#vis_category_main_"+catid).children('span').toggleClass("vis-icon-arrow-open").toggleClass("vis-icon-arrow-close");
        $("#vis_category_sub_"+catid).slideToggle();
        $("#vis_article_sub_"+catid).slideToggle();
    }
</script>