<div class="page-margin">
	<div class="row">
		<div class="col-md-2 leftcol"><?php echo Wo_LoadPage("sidebar/left-sidebar"); ?></div>
		<div class="col-md-7 middlecol">
			<form class="create-group-form form-horizontal" method="post">
				<div class="page-margin mt-0">
					<div class="wow_content popular_posts_hdr flex">
						<h2>&nbsp;<?php echo $wo['lang']['create_new_group'];?></h2>
						<div class="btnss">
							<a class="btn btn-mat btn-default" data-ajax="?link1=groups" href="<?php echo Wo_SeoLink('index.php?link1=groups');?>"><?php echo $wo['lang']['cancel'];?></a>
							<button class="btn btn-main btn-mat add_wow_loader" type="submit"><?php echo $wo['lang']['create']; ?></button>
						</div>
					</div>
				</div>
			
				<div class="page-margin wow_content wow_sett_content">
					<div class="app-general-alert setting-update-alert"></div>
					
					<div class="wow_form_fields">
						<label for="group_title"><?php echo $wo['lang']['group_name']; ?></label>
						<input id="group_title" name="group_title" type="text">
					</div>
					<div class="wow_form_fields">
						<label for="group_name"><?php echo $wo['lang']['group'];?> URL</label>
						<div class="input-group">
							<span class="input-group-addon"><?php echo $wo['config']['site_url'];?>/</span>
							<input id="group_name" name="group_name" type="text">
						</div>
					</div>
					<div class="wow_form_fields">
						<label for="group_about"><?php echo $wo['lang']['description']; ?></label>
						<textarea name="about" id="group_about" rows="3"></textarea>
					</div>
					<div class="row">
						<div class="col-md-6">
							<div class="wow_form_fields">
								<label for="privacy"><?php echo $wo['lang']['group_type']; ?></label>
								<select id="privacy" name="privacy">
									<option value="1" ><?php echo $wo['lang']['public'];?> </option>
									<option value="2" ><?php echo $wo['lang']['private'];?> </option>
								</select>
							</div>
						</div>
						<div class="col-md-6">
							<div class="wow_form_fields">
								<label for="category"><?php echo $wo['lang']['category']; ?></label>
								<select name="category" id="category" onchange="GetGroupSubCategory(this)">
									<?php foreach ($wo['group_categories'] as $category_id => $category_name) {?>
									<option value="<?php echo $category_id?>"><?php echo $category_name; ?></option>
									<?php } ?>
								</select>
							</div>
						</div>
						<?php if (!empty($wo['group_sub_categories'])) { ?>
						<div class="col-md-6">
							<div class="wow_form_fields">
								<label for="group_sub_category"><?php echo $wo['lang']['sub_category']; ?></label>
								<select name="group_sub_category" id="group_sub_category">
									<?php
									if (!empty($wo['group_sub_categories'][array_keys($wo['group_categories'])[0]])) {
									foreach ($wo['group_sub_categories'][array_keys($wo['group_categories'])[0]] as $id => $sub_category) { ?>
										<option value="<?php echo $sub_category['id']?>"><?php echo $sub_category['lang']; ?></option>
									<?php } } ?>
								</select>
							</div>
						</div>
					    <?php } ?>
						<div class="clear"></div>
						<?php $fields = Wo_GetCustomFields('group'); 
						if (!empty($fields)) {
							foreach ($fields as $key => $wo['field']) {
								echo Wo_LoadPage('group/fields');
							}
						}
						?>
					</div>
					
					<input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
				</div>
			</form>
		</div>
		<!-- .col-md-8 -->
		<?php echo Wo_LoadPage('sidebar/content');?>
	</div>
	<!-- .row -->
</div>
<!-- .page-margin -->
<script type="text/javascript">
	<?php 
$js_array = json_encode($wo['group_sub_categories']);
echo "var sub_categories_array = ". $js_array . ";\n";
?>
	function GetGroupSubCategory(self) {
		id = $(self).val();
		var text = "";
		if (typeof(sub_categories_array[id]) == 'undefined') {
		    $('#group_sub_category').html('');
		}
		else{
		   	sub_categories_array[id].forEach(function(entry) {
				text = text + "<option value='"+entry.id+"'>"+entry.lang+"</option>";
			});
		    $('#group_sub_category').html(text);
		}
	}
   $(function() {
     $('form.create-group-form').ajaxForm({
       url: Wo_Ajax_Requests_File() + '?f=groups&s=create_group',
       beforeSend: function() {
         $('.create-group-form').find('.add_wow_loader').addClass('btn-loading');
       },
       success: function(data) {
         scrollToTop();
         if (data.status == 200) {
           window.location.href = data.location;
         } else {
             var errors = data.errors.join("<br>");
             $('.app-general-alert').html('<div class="alert alert-danger">' + errors + '</div>');
             $('.alert-danger').fadeIn(300);
         }
         $('.create-group-form').find('.add_wow_loader').removeClass('btn-loading');
       }
     });
   });
</script>