<? 	global $vis_language;	?>
<section id="breadcrumb" class="row m-b m-l-none m-r-none">
    <div class="col-sm-6">
        <h3 class="m-b-xs text-black"><? echo $vis_language['TXTMACROS']; ?></h3>
        <ul class="breadcrumb bg-empty no-border m-b-xxs no-padder">
            <li><a class="link" href="#/home/quick_view/<? echo $vis_language['TXTHOME']; ?>"><? echo $vis_language['TXTHOME']; ?></a></li>
            <li><a class="link" href="#/home/view_macros/<? echo $vis_language['TXTMACROS']; ?>"><? echo $vis_language['TXTMACROS']; ?></a></li>
            <li class="active"><? echo (isset($macro_details) && $macro_details != -1) ? $vis_language['TXTUPDATEMACRO'] : $vis_language['TXTADDMACRO']; ?></li>
        </ul>
    </div>
</section>
<section class="padder">
    <section class="panel panel-default">
        <header class="panel-heading sub_header"><? echo (isset($macro_details) && $macro_details != -1) ? $vis_language['TXTUPDATEMACRO'] : $vis_language['TXTADDMACRO']; ?></header>
        <div class="panel-body">
            <form class="form-horizontal" data-validate="parsley" id="vis_macro_form" name="vis_macro_form" method="post">
                <div class="form-group">
                    <label class="col-sm-2 control-label"><? echo $vis_language['TXTTITLE']; ?></label>
                    <div class="col-sm-10">
                        <input class="form-control input-sm" type="text" name="vis_macro_title" value="<?= (isset($macro_details) && $macro_details != -1) ? htmlentities($macro_details['macro_title'], ENT_COMPAT, 'UTF-8') : '';?>">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label"><? echo $vis_language['TXTDEPARTMENT']; ?></label>
                    <div class="col-sm-10">
					<? 	if($department_list != -1) { ?>
						<select name="vis_dept" class="form-control input-sm selectpicker" <? if(count($department_list)>10) echo 'data-live-search="true"';?> onchange="$('#vis_ticket_properties').visExecution('load_operations', {'vis_module':'home', 'vis_operation':'get_macro_ticket_properties', 'vis_dept_id':this.value});">
							<option value="0"<?= (isset($macro_details) && $macro_details != -1 && $macro_details['department'] == 0) ? ' selected="selected"' : '';?>><? echo $vis_language['TXTNOCHANGE']; ?></option>
						<? 	foreach($department_list as $dept) { ?>
                            <option value="<?= $dept['department_id'];?>"<?= (isset($macro_details) && $macro_details != -1 && $macro_details['department'] == $dept['department_id']) ? ' selected="selected"' : '';?>><? echo $dept['domain_name'] .' :: '. $dept['department_name']; ?></option>
					<? 		} ?>
						</select>
					<?  } ?>
                    </div>
                </div>
				 <div class="form-group">
				   <label class="col-sm-2 control-label"><? echo $vis_language['TXTCHANGESLA']; ?></label>
				   <div class="col-sm-10">
					  <select name="vis_sla_id" id="vis_sla_id" class="form-control input-sm selectpicker" <? if(count($sla)>10) echo 'data-live-search="true"';?>>
						 <option value="0"><? echo$vis_language['TXTNOCHANGE']; ?></option>
						 <?  for($i=0;$i<count($sla);$i++){ $sla_selected = (isset($macro_details) && $macro_details != -1 && $macro_details['sla'] == $sla[$i]['sla_id']) ? ' selected="selected"' : '';
						 echo '<option value="'.$sla[$i]['sla_id'].'" '.$sla_selected.'>'.$sla[$i]['sla_name'].'</option>'; }?>
					  </select>
				   </div>
				</div>
				<div id="vis_ticket_properties"><? include_once(VIS_PATH_TEMPLATE.'macro_ticket_properties.php'); ?></div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><? echo $vis_language['TXTTAGS']; ?></label>
					<div class="col-sm-10">
						<input name="vis_macro_tag" id="vis_macro_tag" placeholder="<?= $vis_language['TXTTYPEHEREANDPRESSENTERTOSAVE']; ?>" data-resize="no" data-module="vis_macro_tag" type="text">
						<script type="text/javascript">
							$(document).ready(function() {
								$("#vis_macro_tag").tokenInput(
									"index.php?vis_module=ticket&vis_operation=get_tag",{
										theme: "facebook",
										searchDelay: 500,
										minChars: 3,
										queryParam: "vis_data",
										propertyToSearch: "label_name",
										tokenValue: "label_name",
										resultsFormatter: function(item){ return "<li>" + "<div style='display: inline-block;' class='m-xs'><div class='full_name'>" + item.label_name + "</div></div></li>" },
										tokenFormatter: function(item) { return "<li><p>" + item.label_name + "</p></li>" }
									}
								);
								$("div.token-input-dropdown-facebook").css('width',$(".token-input-list-facebook").width()+2+'px');
								<?	if(isset($macro_details) && $macro_details != -1 && $macro_details['tags'] != '' && count($tags) > 0) {
										for($i=0; $i<count($tags); $i++){ ?>
											$("#vis_macro_tag").tokenInput("add", {id: '0', label_name: "<?= $tags[$i]['label_name'];?>"});
									<? 	}
									} ?>
							});
						</script>
					</div>
				</div>
				<div class="form-group">
                    <label class="col-sm-2 control-label"><? echo $vis_language['TXTCONTENT']; ?></label>
                    <div class="col-sm-10">
						<textarea name="vis_post_content" id="vis_post_content" class="form-control" rows="10"><?= (isset($macro_details) && $macro_details != -1 && $macro_details['post_content'] != '') ? $macro_details['post_content'] : '';?></textarea>
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-sm-2 control-label"><? echo $vis_language['TXTCOMMENT']; ?></label>
                    <div class="col-sm-10">
						<textarea name="vis_comment" id="vis_comment" class="form-control"><?= (isset($macro_details) && $macro_details != -1 && $macro_details['comment'] != '') ? $macro_details['comment'] : '';?></textarea>
                    </div>
                </div>
				<div class="form-group">
				   <label class="col-sm-2 control-label"><? echo $vis_language['TXTDISPLAYORDER']; ?></label>
				   <div class="col-sm-10">
					  <input class="form-control input-sm" type="text" name="vis_displayorder" id="vis_displayorder" value="<?= (isset($macro_details) && $macro_details != -1 && $macro_details['display_order'] != '') ? $macro_details['display_order'] : '0';?>">
				   </div>
				</div>
				<div class="form-group">
				   <label class="col-sm-2 control-label"><? echo $vis_language['TXTACCESS']; ?></label>
				   <div class="col-sm-10">
					  <select name="vis_access" class="form-control input-sm selectpicker" >
					<?php if($macro_details['access'] == 0){?>
					<option value="0" selected="selected"><? echo $vis_language['TXTPUBLIC']; ?></option>
					<option value="1" ><? echo $vis_language['TXTPRIVATE']; ?></option>
					<?php }else{?>
					<option value="0"><? echo $vis_language['TXTPUBLIC']; ?></option>
					<option value="1" selected="selected"><? echo $vis_language['TXTPRIVATE']; ?></option>
					<?php }?>
						</select>
				   </div>
				</div>
				<div class="form-group">
				   <label class="col-sm-2 control-label"><? echo $vis_language['TXTSTATUS']; ?></label>
				   <div class="col-sm-1">
					  <label class="switch">
					  <input type="checkbox" <?= ((isset($macro_details) && $macro_details != -1 && $macro_details['is_enabled'] == 1) || (!isset($macro_details)) ) ? ' checked="checked"' : '';?> name="is_enabled"  id="is_enabled">
					  <span></span>
					  </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">
					<? if(isset($macro_details) && $macro_details != -1) { ?>
                        <button type="button" class="btn btn-primary" onclick="$('#vis_workpanel_div').visExecution('submit_form',{'vis_module':'home', 'vis_operation':'update_macro', 'vis_form':'vis_macro_form', 'vis_macro_id': <?= $macro_details['macro_id'];?>})"><? echo $vis_language['TXTUPDATE']; ?></button>
					<? } else { ?>
						<button type="button" class="btn btn-primary" onclick="$('#vis_workpanel_div').visExecution('submit_form',{'vis_module':'home', 'vis_operation':'add_macro', 'vis_form':'vis_macro_form'})"><? echo $vis_language['TXTADD']; ?></button>
					<? } ?>
                    </div>
                </div>
            </form>
        </div>
    </section>
</section>
<script>
    $(".selectpicker").selectpicker();
	<? if(!defined('VIS_HTML_EDITOR') || VIS_HTML_EDITOR==1) { ?>
	$(function(){
		$('#vis_post_content').redactor({
			buttonSource: true,
			minHeight: 180, // pixels
			maxHeight: 180,
			imageUpload: "index.php?vis_tmpst="+new Date().getTime()+"&vis_module=ticket&vis_operation=upload_file&vis_static_area=editor_image_upload",         
			imageUploadParam: 'files',
			deniedTags: ['html', 'head', 'link', 'body', 'meta', 'script','applet'],
			plugins: ['source']
		});
	});
	<? } ?>
</script>
