<? global $vis_language; ?>
<section id="breadcrumb" class="row m-b m-l-none m-r-none">
    <? include_once(VIS_PATH_TEMPLATE.'forum_header.php'); ?>
</section>
<section class="padder">
    <section class="panel panel-default">
        <header class="panel-heading sub_header"><? echo $vis_language['TXTADDTOPIC']; ?></header>
        <div class="panel-body" id="test">
            <form class="form-horizontal" id="vis_forum_topic_form" name="vis_forum_topic_form" method="post" >
                <div class="form-group">
                    <label class="col-sm-2 control-label txt_nowrap"><? echo $vis_language['TXTDOMAIN']; ?></label>
                    <div class="col-sm-10">
                        <select name="vis_domain" id="vis_domain_new" class="form-control input-sm selectpicker"<? if(count($domain_details)>10) echo ' data-live-search="true"';?> onchange="on_domain_change($(this).val());";><?
                            if($domain_details!=-1) for($i=0;$i<count($domain_details); $i++)
                            echo '<option value="'.$domain_details[$i]['domain_id'].'" '.(($domain_details[$i]['domain_id']==$operation['vis_domain'])?' selected="selected"':'').'>'.$domain_details[$i]['domain_name'].'</option>' ?>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label txt_nowrap"><? echo $vis_language['TXTFORUMCATEGORY']; ?></label>
                    <div class="col-sm-10" id="vis_forum_category_list">
                        <select name="vis_forum_category" id="vis_forum_category_new" class="form-control input-sm selectpicker"<? if(count($forum_category_details)>10) echo ' data-live-search="true"';?> onchange="on_category_change($(this).val());";><?
                            if($forum_category_details!=-1) for($i=0;$i<count($forum_category_details); $i++)
                            echo '<option value="'.$forum_category_details[$i]['forum_cat_id'].'" '.(($forum_category_details[$i]['forum_cat_id']==$operation['vis_category'])?' selected="selected"':'').'>'.$forum_category_details[$i]['category_name'].'</option>' ?>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label txt_nowrap"><? echo $vis_language['TXTFORUMS']; ?></label>
                    <div class="col-sm-10" id="vis_forum_list">
                        <select name="vis_forum" id="vis_forum_new" class="form-control input-sm selectpicker"<? if(count($forum_details)>10) echo ' data-live-search="true"';?>><?
                            if($forum_details!=-1) for($i=0;$i<count($forum_details); $i++)
                            echo '<option value="'.$forum_details[$i]['forum_id'].'" '.(($forum_details[$i]['forum_id']==$operation['vis_forum'])?' selected="selected"':'').'>'.$forum_details[$i]['forum_title'].'</option>' ?>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label txt_nowrap"><? echo $vis_language['TXTTITLE']; ?></label>
                    <div class="col-sm-10"><input type="text" name="vis_forum_title" id="vis_forum_title" class="form-control" onblur="set_topic_url()" >
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"><? echo $vis_language['TXTURL']; ?></label>
                    <div class="col-sm-10">
                        <input class="form-control input-sm" type="text" name="vis_topic_url" id="vis_topic_url" value=""/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label txt_nowrap"><? echo $vis_language['TXTPOST']; ?></label>
                    <div class="col-sm-10"><textarea name="vis_forum_topic_post_area" id="vis_forum_topic_post_area" class="form-control"  data-minwords="6" rows="2">
                      <?php if(isset($signature) && $signature!='') echo "<br />\n\n";echo  "&nbsp;&nbsp;&nbsp;".$signature; ?>
                    </textarea>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-2">
                    </div>
                    <div class="col-sm-10">
                        <div class="col-sm-8 p-l-none" id="vis_forum_topic_attachments">
                            <?
                                $atts='';
                                if($attachments!=-1) {
                                	for($i=0;$i<count($attachments);$i++) {
                                		$atts.=$attachments[$i]['attachment_id'].','; 
                                		echo '<div class="btn-group wrapper-xxs"><label class="btn btn-xs alert-success">'.$attachments[$i]['file_name'].'</label><button class="btn btn-xs alert-success" type="button" data-dismiss="alert" onclick=\'$(this).parent().remove();vis_remove_attachment('.$attachments[$i]['attachment_id'] .',"vis_fattachments",'.$ticket_details['ticket_id'].');\'><i class="vh vh-cross"></i></button></div>';
                                	}
                                 }
                                ?>
                        </div>
                        <div class="col-sm-4 p-r-none text-right">
                            <input type="file" name="files[]" multiple="multiple" class="filestyle" data-icon="false" data-classButton="btn btn-link link" data-buttonText="<? echo $vis_language['TXTATTACHFILE']; ?>" data-input="false" onchange="$(this).visExecution('upload_file', {'vis_static_area':'#vis_forum_topic_attachments', 'vis_form':'vis_forum_topic_form', 'vis_form_attachment_area':'#vis_attachments'});" style="display:none;">
                            <input type="hidden" name="vis_location" value="<? echo VIS_DOMAIN; ?>" />
                            <input type="hidden" name="vis_attachments" id="vis_attachments" value="" />  
                            <input type="hidden" name="vis_parent_type" value="9" />
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"></label>
                    <div class="col-sm-5">
                        <label class="checkbox-inline i-checks m-r-lg">
                        <input value="1" name="vis_topic_stick" id="vis_topic_stick" type="checkbox" ><i></i>
                        <?  echo $vis_language['TXTMARKASSTICKY']; ?>
                        </label>
                    </div>
                </div>
                <div class="line b-b line-lg pull-in"></div>
                <br/>
                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-2">
                        <button type="button" class="btn btn-primary" onclick="$('#vis_workpanel_div').visExecution('submit_form',{'vis_module':'forums', 'vis_operation':'new_forum_topic', 'vis_form':'vis_forum_topic_form'})"><? echo $vis_language['TXTADD']; ?></button>
                    </div>
                </div>
        </div>
        </form>
        </div>
    </section>
</section>
<? if (!defined('VIS_HTML_EDITOR') || VIS_HTML_EDITOR == 1) { ?>	<script src="<?= VIS_PATH_PLUGINS; ?>redactor/source.js"></script> <?}?>
<script>
    $(".selectpicker").selectpicker();
    function vis_remove_attachment(topic_id){
    	$("#vis_forum_topic_form #vis_attachments").val( $("#vis_forum_topic_form #vis_attachments").val().replace(topic_id + ',', '') );
    }
    <? if (!defined('VIS_HTML_EDITOR') || VIS_HTML_EDITOR == 1) { ?>
    $(function(){
    	$('#vis_forum_topic_post_area').redactor({
    		maxHeight: '180px',
            minHeight: 180,
            deniedTags: ['html', 'head', 'link', 'body', 'meta', 'script','applet'],
    		imageUpload: "index.php?vis_tmpst="+new Date().getTime()+"&vis_module=ticket&vis_operation=upload_file&vis_static_area=editor_image_upload",         
    		imageUploadParam: 'files',
    		plugins: ['source'],
    		imageUploadErrorCallback: function(json)
    		{
    			 $("#vis_global_msg_div").show();
    			 document.getElementById("vis_global_msg_div").innerHTML = json.message;
    			 setTimeout( function(){ $("#vis_global_msg_div").hide().html(''); }, 10000);
    		}
			
    	});
    });
    <? } ?>
    function on_domain_change(domain_id)
    {
    	$.ajax
    	({ 
    	url: 'index.php',
    	data: {'vis_module':"forums", 'vis_operation':"add_forum_topic" , 'vis_domain_id':domain_id},
    	type: "POST",
    	success: function(data)
    	{
   		
			$('#vis_forum_category_list').html(data);
    		 $(".selectpicker").selectpicker();
			
    		 var vis_forum_category_id = $("#vis_forum_category_new").val();
			
    		 var res=on_category_change(vis_forum_category_id);
    	}
    	});
    }
    function on_category_change(category_id)
    {
    	
		$.ajax
    	({
    	url: 'index.php',
    	data: {'vis_module':"forums", 'vis_operation':"add_forum_topic" , 'vis_forum_category_id':category_id,'showforum':'1'},
    	type: "POST",
    	success: function(data)
    	{
    	
				$('#vis_forum_list').html(data);
				$(".selectpicker").selectpicker();
			
    	}
    	});
		
    }
    function set_topic_url(){
          var title = document.getElementById('vis_forum_title').value;
          title = title.replace(/[&\/\\#,+()$@^!`=;|~%.'":*?<>{}]/g, '');
          var url = title.trim().replace(/[-\s]+/g,"-");
          document.getElementById('vis_topic_url').value=url;
      }
</script>
<script src="<?= VIS_PATH_SCRIPT; ?>file-input/bootstrap-filestyle.min.js"></script>

