<!DOCTYPE html>
<html lang="en">
<head>
	<!-- Main navbar -->
		<?php 

		helper('form');

		$this->session = session();

		$validation = \Config\Services::validation();


		echo view('admin/common_header'); ?>
	<!-- /main navbar -->
	

	<!-- date picker JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/js/core/libraries/jquery_ui/interactions.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/core/libraries/jquery_ui/widgets.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/core/libraries/jquery_ui/effects.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/extensions/mousewheel.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/core/libraries/jquery_ui/globalize/globalize.js');?>"></script>
	
	<!-- Bootsrap form validation JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/js/formValidation.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/bootstrap.js');?>"></script>

	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/forms/styling/uniform.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/pnotify.min.js');?>"></script>
	<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/forms/selects/bootstrap_multiselect.js');?>"></script>
	
	<!-- Theme JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/js/core/app.js');?>"></script>
	<!-- /theme JS files -->
	
	<!-- bootsrap switch checkbox JS files -->
    <script src="<?php echo base_url('assets/boots/js/bootstrap-switch.js');?>"></script>

    <!-- file upload JS files -->
	<script type="text/javascript" src="<?php echo base_url('assets/boots/js/fileinput.min.js');?>"></script>

    <!-- notify JS files -->
    <script type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/jgrowl.min.js');?>"></script>
	
	<script type="text/javascript" src="<?php echo base_url('assets/js/pages/form_multiselect.js');?>"></script>
	<!-- /theme JS files -->

	
<style>    
    div.checker {
    	top: 18px !important;
    }
    .multiselect-container {
        min-width: 0px;
    }
    .kv-file-content img.file-preview-image {
    	width: 150px !important;
    }

</style>
</head>

<body class="navbar-top-md-md">
	<!-- <div class="pre_loader"></div> -->
	<!-- Fixed navbars wrapper -->
	<div class="navbar-fixed-top">

		<!-- Main navbar -->
		<?php echo view('admin/mainnav'); ?>
		<!-- /main navbar -->


		<!-- Second navbar -->
		<?php echo view('admin/secondnav'); ?>
		<!-- /second navbar -->

	</div>
	<!-- /fixed navbars wrapper -->


	<!-- Page header -->
	<div class="page-header">
		<div class="page-header-content">
			<div class="page-title">
				<h4><i id="icon-bck" class="icon-arrow-left52 position-left"></i> <span class="text-semibold"><?php echo lang('language_lang.subadmin_lbl'); ?></span></h4>

				<ul class="breadcrumb breadcrumb-caret position-right">
					<?php foreach ($breadcrumbs as $breadcrumb) { if(isset($breadcrumb['href'])){?>
					    <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
					<?php } else { ?> <li><?php echo $breadcrumb['text']; ?></li><?php } } ?>
				</ul>
			</div>
			<?php echo view('admin/'.$module_name.'_header'); ?>
			
		</div>
	</div>
	<!-- /page header -->


	<!-- Page container -->
	<div class="page-container">

		<!-- Page content -->
		<div class="page-content">

			<!-- Main content -->
			<div class="content-wrapper">

				<!-- Horizontal form -->
				<div class="panel panel-flat">
					<div class="panel-heading">
						<h5 class="panel-title">
						<?php 
							if(isset($subadmin_data->id)) { 
	                           echo lang('language_lang.editsubadmin_lbl');
	                        }
	                        else{
	                           echo lang('language_lang.addsubadmin_lbl');
	                        }
                        ?>
						</h5>
						<div class="heading-elements">
							<ul class="icons-list">
		                		<li><a data-action="collapse"></a></li>
		                		<li><a data-action="close"></a></li>
		                	</ul>
	                	</div>
                	</div>
                	
					<div class="panel-body">
							
                           <form class="form-horizontal form-profile" action="<?=site_url($action); ?>" method="post" enctype="multipart/form-data">
							<?php 
								if($validation->listErrors()) { 
									$form_err_data = str_replace('<p>', '', $validation->listErrors());
									$form_err_data = str_replace('</p>', '', $form_err_data);
									$form_err_data = str_replace('.', '', $form_err_data);
							?>
									
									<script type="text/javascript">
									
									(function( $ ) {
										$.jGrowl.defaults.closer = false;
								        var from_daa = '<?php $form_err_data;?>';
										$.jGrowl(from_daa, {
								            header: '<?php echo lang("language_lang.error");?>',
								            theme: 'bg-danger'
								        });
								    
									})(jQuery);


									</script>
							<?php
								}

							?>
                               <div class="form-group  has-feedback <?php if($validation->getError('username')) echo "has-error";?>">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.subadmin_username'); ?><span class="text-danger">*</span></label>
								    <div class="col-lg-4">
									    <div style="width:100%;" class="input-group">
										    <input type="text" name="username" class="form-control"  placeholder="<?php echo lang('language_lang.subadmin_plc_username_lbl'); ?>" value="<?php echo set_value('username',isset($subadmin_data->username) ? $subadmin_data->username : ''); ?>">
									    </div>
									    <?php echo $validation->getError('username', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								    </div>
								</div>
                          <?php      if(isset($subadmin_data->id)) { ?>

                          <?php } else { ?>
								<div class="form-group  has-feedback <?php if($validation->getError('newpwd')) echo "has-error";?>">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.change_pwd_sub'); ?>  <span class="text-danger">*</span></label>
								    <div class="col-lg-4">
									    <div style="width:100%;" class="input-group">
										    <input type="password" name="newpwd" class="form-control"  placeholder="<?php echo lang('language_lang.change_pwd_sub'); ?>" value="">
									    </div>
									    <?php echo $validation->getError('newpwd', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								    </div>
								</div>

								<div class="form-group  has-feedback <?php if($validation->getError('confirm')) echo "has-error";?>">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.admin_confirm_pwd'); ?>  <span class="text-danger">*</span></label>
								    <div class="col-lg-4">
									    <div style="width:100%;" class="input-group">
										    <input type="password" name="confirm" class="form-control"  placeholder="<?php echo lang('language_lang.admin_plc_confirm_lbl'); ?>" value="">
									    </div>
									    <?php echo $validation->getError('confirm', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								    </div>
								</div>

								<?php } ?>

								<div class="form-group  has-feedback <?php if($validation->getError('email')) echo "has-error";?>">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.admin_email_lbl'); ?>  <span class="text-danger">*</span></label>
								    <div class="col-lg-4">
									    <div style="width:100%;" class="input-group">
										    <input type="text" name="email" class="form-control"  placeholder="<?php echo lang('language_lang.subadmin_plc_email_lbl'); ?>" value="<?php echo set_value('email',isset($subadmin_data->email) ? $subadmin_data->email : ''); ?>">
									    </div>
									    <?php echo $validation->getError('email', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								    </div>
								</div>

								<div class="form-group  has-feedback <?php if($validation->getError('contact_email')) echo "has-error";?>">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.admin_contact_lbl'); ?>  <span class="text-danger">*</span></label>
								    <div class="col-lg-4">
									    <div style="width:100%;" class="input-group">
										    <input type="text" name="contact_email" class="form-control"  placeholder="<?php echo lang('language_lang.subadmin_plc_contemail_lbl'); ?>" value="<?php echo set_value('contact_email',isset($subadmin_data->contact_email) ? $subadmin_data->contact_email : ''); ?>">
									    </div>
									    <?php echo $validation->getError('contact_email', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								    </div>
								</div>

								<!-- Select All option selected -->
								<div class="form-group has-feedback <?php if($validation->getError('user_id[]')) echo "has-error";?>">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.subadmin_previlage');?></label>
									<div class="col-lg-4">
										<div class="multi-select-full">

											<?php if(isset($subadmin_data)) { $display = json_decode($subadmin_data->permission);  } ?>
											
											<select name="user_id[]" class="form-control multiselect-clickable-groups" multiple="multiple">

												<optgroup label="<?php echo lang('language_lang.text_settings'); ?>">
												<!--<?php foreach ($user_list as $list_data => $value) { ?>
													<option <?php if(isset($subadmin_data)) { if(in_array($value, $display)) { echo 'selected="selected"'; } } ?> value="<?php echo $value; ?>"><?php echo $value;?></option>
											    <?php } ?>-->
											    <?php
											    	foreach ($user_list as $list_data => $value) {

											    		if($value=='adminsettings')
											    			$value1="Tradesettings";
											    		else if($value=='Paysettings')
											    			$value1="Payment Currency Settings";
											    		else
											    			$value1=$value;
											    		?>
											    		<option <?php if(isset($subadmin_data)) { if(in_array($value, $display)) { echo 'selected="selected"'; } } ?> value="<?php echo $value; ?>"><?php echo $value1;?></option>

											    		<?php

											    	} 

											    ?>
												</optgroup>

												<optgroup label="<?php echo lang('language_lang.text_extra'); ?>">
												<?php foreach ($user_list1 as $list_data => $value) {?>
													<option <?php if(isset($subadmin_data)) { if(in_array($value, $display)) { echo 'selected="selected"'; } } ?> value="<?php echo $value; ?>"><?php echo $value;?></option>
											    <?php } ?>
												</optgroup>

												<optgroup label="<?php echo lang('language_lang.menu_user'); ?>">
												<?php foreach ($user_list2 as $list_data => $value) { ?>
													<option <?php if(isset($subadmin_data)) { if(in_array($value, $display)) { echo 'selected="selected"'; } } ?> value="<?php echo $value; ?>"><?php echo $value;?></option>
											    <?php } ?>
												</optgroup>

												<optgroup label="<?php echo lang('language_lang.menu_finance'); ?>">
												<?php 
												foreach ($finance as $finance_data => $value) 
												{ 
												    
												   
												    	if($value=='Finance/bonus')
											    			$value1="Add Points";
											    		else if($value=='Finance/penalty')
											    			$value1="Deduct Points";
											    		else
											    			$value1=str_replace('Finance/','',$value);
												?>
													<option <?php if(isset($subadmin_data)) { if(in_array($value, $display)) { echo 'selected="selected"'; } } ?> value="<?php echo $value; ?>"><?php echo $value1;?></option>
											    <?php } ?>
												</optgroup>

												<optgroup label="<?php echo lang('language_lang.menu_transaction_history'); ?>">
											<!--	<?php foreach ($history as $history_data => $value) { ?>
													<option <?php if(isset($subadmin_data)) { if(in_array($value, $display)) { echo 'selected="selected"'; } } ?> value="<?php echo $value; ?>"><?php echo ucfirst(str_replace('History/', '', $value));?></option>


											    <?php } ?>-->


											    <?php
											    	foreach ($history as $history_data => $value) {

											    		/*$value=ucfirst(str_replace('History/', '', $value));

											    		if($value=='Exchange')
											    			$value1="Exchange Price History";
											    		if($value=='Exchanges')
											    			$value1="Exchange BUY/SELL History";
											    		else
											    			$value1=$value;	*/
											    			$value1=ucfirst(str_replace("History/",'', $value));
															if($value1=='Exchange')
											    				$value1="Exchange Price History";
											    			if($value1=='Exchanges')
											    				$value1="Exchange BUY/SELL History";
											    			
											    		?>
											    		<option <?php if(isset($subadmin_data)) { if(in_array($value, $display)) { echo 'selected="selected"'; } } ?> value="<?php echo $value; ?>"><?php echo ucfirst($value1);?></option>

											    		<?php

											    	} 

											    ?>

											
												</optgroup>

												<optgroup label="<?php echo lang('language_lang.menu_reports'); ?>">
												<?php foreach ($reports as $reports_data => $value) { ?>
													<option <?php if(isset($subadmin_data)) { if(in_array($value, $display)) { echo 'selected="selected"'; } } ?> value="<?php echo $value; ?>"><?php echo ucfirst(str_replace('Reports/', '', $value));?></option>
											    <?php } ?>

											  
												</optgroup>

												

												<optgroup label="<?php echo lang('language_lang.support_lbl'); ?>">
												<?php foreach ($user_list4 as $list_data => $value) { ?>
													<option <?php if(isset($subadmin_data)) { if(in_array($value, $display)) { echo 'selected="selected"'; } }?> value="<?php echo $value; ?>"><?php echo $value;?></option>
											    <?php } ?>
												</optgroup>

									
											</select>
											<?php echo $validation->getError('user_id[]', '<div class="form-control-feedback"></div><span class="help-block">', '</span>'); ?>
										</div>

									</div>
								</div>

								<div class="form-group  has-feedback <?php if($validation->getError('contact_num')) echo "has-error";?>">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.admin_contactnum_lbl'); ?>  <span class="text-danger">*</span></label>
								    <div class="col-lg-4">
									    <div style="width:100%;" class="input-group">
										    <input type="text" name="contact_num" class="form-control"  placeholder="<?php echo lang('language_lang.subadmin_plc_contnum_lbl'); ?>" value="<?php echo set_value('contact_num',isset($subadmin_data->contact_num) ? $subadmin_data->contact_num : ''); ?>">
									    </div>
									    <?php echo $validation->getError('contact_num', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
								    </div>
								</div>

                                

								<div class="form-group  <?php if($validation->getError('profile_pic')) echo "has-error";?>">
									<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.admin_profile_pic'); ?> <span class="text-danger">*</span></label>
									
									<div class="col-lg-4" style="width:auto;">
										<div>
											<input type="file" name="profile_pic" class="file-input-extensions" value="<?php echo set_value('profile_pic', isset($subadmin_data->profile_pic) ? "/..".$subadmin_data->profile_pic : '' ); ?>">
										</div>
										<span class="help-block"><?php echo lang('language_lang.profile_pic_extension');?></span>
										<?php echo $validation->getError('profile_pic', '<div class="form-control-feedback"><i class="icon-cancel-circle2"></i></div><span class="help-block">', '</span>'); ?>
									</div>
								</div>   
						   
							
							<!-- Switch single -->
							<div class="form-group <?php if($validation->getError('message_status')) echo "has-error";?>">
								<label class="control-label col-lg-2 text-semibold"><?php echo lang('language_lang.message_status'); ?> </label>
								<div class="col-lg-6">
									<div class="checkbox checkbox-switch">
										<label>
											<input type="checkbox" <?php if(isset($subadmin_data)) { if($subadmin_data->status == '1') { echo "checked"; } } ?> name="message_status" data-on-color="success" data-off-color="danger" data-on-text="<?php echo lang('language_lang.On');?>" data-off-text="<?php echo lang('language_lang.Off');?>" class="switchery">
										</label>
									</div>
									<?php echo $validation->getError('message_status', '<label class="validation-error-label">', '</label>'); ?>
								</div>
							</div>
							
							<?php 
								if(isset($subadmin_data->id)) { 
							?>
							<input type="hidden" name="id" value="<?php echo $subadmin_data->id;?>"/>
							<?php } ?>

							<div class="text-right col-lg-8">
								<button type="submit" class="btn btn-primary"><?php if(isset($subadmin_data->id)) {  echo lang('language_lang.button_update'); } else { echo lang('language_lang.button_save'); } ?> <i class="icon-arrow-right14 position-right"></i></button>
							</div>
						</form>
					</div>
				</div>
				<!-- /horizotal form -->

			</div>
			<!-- /main content -->

		</div>
		<!-- /page content -->
		

		<!-- Footer -->
		<div class="footer text-muted">
			<?php echo site_footer();?>
		</div>
		<!-- /footer -->

	</div>
	<!-- /page container -->

	<script type="text/javascript">
		jQuery.noConflict();
		(function( $ ) {
		$(function() {

			$(document).ready(function() {

				$.jGrowl.defaults.closer = false;

				<?php if(isset($form_err_data)) { ?>
					$.jGrowl('<?php echo trim($form_err_data);?>', {
			            header: '<?php echo lang("language_lang.error");?>',
			            theme: 'bg-danger'
			        });
				<?php } ?>


				<?php if($this->session->getFlashData('error_message')) { ?>
					$.jGrowl("<?php echo $this->session->getFlashData('error_message');?>", {
			            header: '<?php echo lang("language_lang.error");?>',
			            theme: 'bg-danger'
			        });
	            <?php } ?>
	                    
	            <?php if($this->session->getFlashData('success_message')) { ?>
	                $.jGrowl("<?php echo $this->session->getFlashData('success_message');?>", {
			            header: '<?php echo lang("language_lang.success");?>',
			            theme: 'bg-success'
			        });
	            <?php } ?>

	          

			    $('.form-profile').formValidation({
			    	framework: 'bootstrap',
			    	excluded: [':disabled'],
			        icon: {
			            validating: 'glyphicon glyphicon-refresh'
			        },
			        fields: {
			            username: {
		               message: '<?php echo lang("language_lang.sub_admin_username_invalid");?>',
                            validators: {
                                notEmpty: {
                                    message: '<?php echo lang("language_lang.sub_admin_username_valid");?>'
                                },
                                regexp: {
                                    regexp: /^[a-z]+$/i,
                                    message: '<?php echo lang("language_lang.sub_admin_username_invalid");?>'
                                },
                                stringLength: {
                                min: 5,
                                message: '<?php echo lang("language_lang.subuser_name_char");?>'
                                }
                            }
		            },
		            

		             email: {
		                 validators: {
                                notEmpty: {
                                    message: '<?php echo lang("language_lang.contact_email_required");?>'
                                },
                                regexp: {
                                    regexp: /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/,
                                    message: '<?php echo lang("language_lang.contact_email_valid"); ?>'
                                }
                            }
		            },
		            contact_email: {
		                 validators: {
                                notEmpty: {
                                    message: '<?php echo lang("language_lang.cont_email_required");?>'
                                },
                                regexp: {
                                    regexp: /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/,
                                    message: '<?php echo lang("language_lang.cont_email_valid"); ?>'
                                }
                            }
		            },
		            contact_num: {
		            	 validators: {
                                notEmpty: {
                                    message: '<?php echo lang("language_lang.admin_contact_num_empty");?>'
                                },
                                digits: {
                                    message: '<?php echo lang("language_lang.admin_contact_num_num");?>'
                                },
                                stringLength: {
                                min: 6,
                                message: '<?php echo lang("language_lang.admin_contact_num_max_limit");?>'
                                }
                                 
                            }
		            },
		             <?php      if(isset($subadmin_data->id)) { ?>

		             	profile_pic: {
			            validators: {
			                file: {
			                    extension: 'jpg,jpeg,png,gif',
			                    type: 'image/jpg,image/jpeg,image/png, image/png',
			                    message: '<?php echo lang("language_lang.admin_profile_must");?>'
			                }
			            }
			        },

                          <?php } else { ?>
		            profile_pic: {
			            validators: {
			            	notEmpty: {
                                    message: '<?php echo lang("language_lang.sub_prof_empty");?>'
                                },
			                file: {
			                    extension: 'jpg,jpeg,png,gif',
			                    type: 'image/jpg,image/jpeg,image/png, image/png',
			                    message: '<?php echo lang("language_lang.admin_profile_must");?>'
			                }
			            }
			        },
			        <?php } ?>

			        <?php      if(isset($subadmin_data->id)) { ?>

                          <?php } else { ?>
                          	newpwd: {
                            validators: {
                                notEmpty: {
                                    message: '<?php echo lang("language_lang.user_password_empty");?>'
                                }

                            }
                        },
                        confirm: {
                            validators: {
                                notEmpty: {
                                    message: '<?php echo lang("language_lang.user_confirmpassword_empty");?>'
                                },
                                identical: {
                                    field: "newpwd",
                                    message: '<?php echo lang("language_lang.user_confirmpassword_match");?>'
                                }

                            }
                        },

                        <?php } ?>
		                'user_id[]': {
			                message: '<?php echo lang("language_lang.message_userlist_valid");?>',
			                validators: {
			                    notEmpty: {
			                        message: '<?php echo lang("language_lang.message_userlist_required");?>'
			                    }
			                }
			            }

			            
			        }
			    })
				

			});

   
	    // $(".switch").bootstrapSwitch();
	    $(".file-input-extensions").fileinput({
		    uploadUrl: "http://localhost/file-upload-single/1", // server upload action
		    uploadAsync: false,
		    minFileCount: 1,
		    maxFileCount: 1,
		    overwriteInitial: true,
		    showUpload: false,
		    <?php if(isset($subadmin_data->profile_pic)) { ?>
		    	initialPreview: ["<?php echo base_url('content/profile/'.$subadmin_data->profile_pic);?>"],
		    	initialPreviewAsData: true, // identify if you are sending preview data only and not the raw markup
		    	initialPreviewFileType: 'image', // image is the default and can be overridden in config below
		    <?php } ?>
		    allowedFileExtensions: ["jpg", "gif", "png", "jpeg"],
		    uploadExtraData: {
		        img_key: "1000"
		    }
		});
		    // $('[name="page_content"]').ckeditor();
		 	$('#icon-bck').on('click',function() {
				window.history.back();
			});
			
		    $(".switchery").bootstrapSwitch();
		    // $("#countries").msDropdown();

		});
		})(jQuery);
	
	</script>

</body>
</html>
