
        
<?php //include_once("assets/resources/side-includer.php"); ?>
<?php //include_once("assets/resources/top_navigator.php"); ?>
<?php
include_once("hooks/_config_.php");
$conf = new config();
//if(isset($_GET['apguky']) && isset($_GET['apgnfk'])) {
//$ctg_unqky = $view->decrypt($_GET['apguky']);
//$ctg_frgnky = $view->decrypt($_GET['apgnfk']);
$dlist = array("blog", "events", "resource", "news", "media_release", "help");
?>			
			
 	 
                                                   
            <!-- Aparent body content -->
            <div id="main-content">
				<div class="page-heading">
                    <div class="page-title">
                        <div class="row">
                            <div class="col-12 col-md-6 order-md-1 order-last">
                                <h3>Add Relavant Page</h3>
                                <p class="text-subtitle text-muted">Create New Blog Post or Page Content.</p>
                            </div>
                            <div class="col-12 col-md-6 order-md-2 order-first">
                                <nav aria-label="breadcrumb" class="breadcrumb-header float-start float-lg-end">
                                    <ol class="breadcrumb">
                                        <li class="breadcrumb-item"><a href="">Dashboard</a></li>
                                        <li class="breadcrumb-item active" aria-current="page">Add New Page
                                        </li>
                                    </ol>
                                </nav>
                            </div>
                        </div>
                    </div>
								
					<section id="basic-horizontal-layouts">
                    <div class="row match-height">
                        <div class="col-md-12 col-12">
                        <div class="card">
                            <div class="card-header">
                            <h4 class="card-title">Add New Page</h4>
                          </div>
                            <div class="card-content">
                            <div class="card-body">
<?php
$dlist = array("blog", "events", "resource", "news", "media_release", "help");
if(isset($_POST['admit_category']) && $_POST['admit_category'] == "Create New Page" 
&& isset($_POST['Category_name'])
&& isset($_FILES['ttlimg_keys'])
&& isset($_POST['Categorymeta_title'])
&& isset($_POST['Categorymeta_descp'])
&& isset($_POST['Category_metakeywrds'])) {
?>
<form class="form form-horizontal" action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"s>
                                <div class="form-body">
                    <div class="row">
                                    <div class="col-md-4">
                        <label>Blog Tittle</label>
                      </div>
                                    <div class="col-md-8 form-group">
                        <input type="text"  id="pgTitlfor"  class="form-control" name="Category_name"  placeholder="Page Tittle" value="<?php echo $_POST['Category_name']; ?>" />
                        <?php
								$ctg_nme = $isValid->iValid($_POST['Category_name'], 'Error. Invalide Text or Blank Field', 'str');
							
						?>
                      </div>
					  
					  	  
									<div class="col-md-4">
                                        <label>Page Slug</label>
                                      </div>
                                    <div class="col-md-8 form-group">
									<input type="text" id="changslg" class="form-control" name="pag_sulg_name"  placeholder="Page Slug" value="<?php echo $_POST['pag_sulg_name']; ?>" />
               						  <p><small class="text-muted">Title For URL To Appear.  Symbols Are Not Allowed Page / Blog Title</small></p>
									   <?php
										$pga_tilxul_g = $isValid->iValid($_POST['pag_sulg_name'], 'Error. Invalide Text or Blank Field', 'str');
							
									?>
                                      </div>
					  
					  
                                    <div class="col-md-4 mt-3">
                        <label>Placement</label>
                      </div>
                                    <div class="col-md-8 form-group mt-3">
                        <?php
								if(isset($_POST['Categorymeta_title']) && $_POST['Categorymeta_title'] != ""){
								?>
                        <select class="form-select" name="Categorymeta_title" style="width: 100%; padding: 10px;">
                                        <option value="<?php echo $_POST['Categorymeta_title']; ?>"><?php echo $_POST['Categorymeta_title']; ?></option>
                                      </select>
                        <div class="valid-feedback"> <i class="bx bx-radio-circle"></i> Directory Name In Which Page Will Be Created </div>
                        		<?php
										$ctg_tlt = $isValid->iValid($_POST['Categorymeta_title'], 'Error. Invalide Text or Blank Field', 'str');
										
								}else{
								?>
                        <select class="form-select" name="Categorymeta_title" style="width: 100%; padding: 10px;">
                                        <option value="">Select Root</option>
                                        <?php 
								foreach($dlist as $value){
								?>
                                        <option value="<?php echo $value; ?>"><?php echo $value; ?></option>
                                        <?php
								}
								?>
                                      </select>
                        <div class="valid-feedback"> <i class="bx bx-radio-circle"></i> Directory Name In Which Page Will Be Created </div>
                        <?php
								echo "<div class='invalid-feedback'>Error: 0 Selected, Select 1 Directory Name</div>";
								} //end if
								?>
                      </div>
                                    <div class="col-md-4 mt-3">
                        <label>Meta Description</label>
                      </div>
                                    <div class="col-md-8 form-group mt-3">
                        <input type="text"  class="form-control" name="Categorymeta_descp" placeholder="Meta Description" value="<?php echo $_POST['Categorymeta_descp']; ?>" />
							<?php
										$meta_dcspi = $isValid->iValid($_POST['Categorymeta_descp'], 'Error. Invalide Text or Blank Field', 'str');
										
								
								?>
                      </div>
						  <div class="col-md-4 mt-3">
							<label>Page Detail</label>
						  </div>
                                    <div class="col-md-8 mt-3 form-group">
                        <textarea  id="summernote"  name="Category_metakeywrds" style="width:640px; height:250px;"><?php echo $_POST['Category_metakeywrds']; ?></textarea>
                      </div>
                                    <?php
		//$ctgmt_kwrd = $isValid->iValid($_POST['Category_metakeywrds'], 'Error. Invalide Text or Blank Field', 'str');
		$ctgmt_kwrd = mysqli_real_escape_string($conf->_conni(), addslashes($_POST['Category_metakeywrds']));
		
?>
                                    <div class="col-md-4 mt-3">
                        <label>Placement</label>
                      </div>
                                    <div class="col-md-8 mt-3 form-group">
                        <div class=' m-2 form-check d-inline-block'>
                                        <div class="checkbox d-inline-block">
                            <input type="checkbox" id="checkbox1" class='form-check-input' name="top_Category" <?php if(isset($_POST['top_Category']) && $_POST['top_Category'] == "on"){?> checked="checked" <?php } ?>/>
                            <?php
if(isset($_POST['top_Category']) && $_POST['top_Category'] == "on"){
 $cg_status = 1;
}else{
 $cg_status = 0;
 
}
?>
                            <label for="checkbox1">Add to Home</label>
                          </div>
                                      </div>
                        <!--sec checkbox--->
                        <div class='form-check m-2 d-inline-block'>
                                        <div class="checkbox d-inline-block">
                            <input type="checkbox" id="checkbox1" class='form-check-input' name="footer_Category" <?php if(isset($_POST['footer_Category']) && $_POST['footer_Category'] == "on"){?> checked="checked" <?php } ?>/>
                            <?php
if(isset($_POST['footer_Category']) && $_POST['footer_Category'] == "on"){
 $ftrg_status = 1;
}else{
 $ftrg_status = 0;
 
}
?>
                            <label for="checkbox1">Add to Side Bar</label>
                          </div>
                                      </div>
                        <!--first checkbox--->
                        <div class='form-check m-2 d-inline-block'>
                                        <div class="checkbox d-inline-block">
                            <input type="checkbox" id="checkbox1" class='form-check-input' name="footer_mniu" <?php if(isset($_POST['footer_mniu']) && $_POST['footer_mniu'] == "on"){?> checked="checked" <?php } ?>/>
                            <?php
if(isset($_POST['footer_mniu']) && $_POST['footer_mniu'] == "on"){
 $fotr_lnkrmn = 1;
}else{
 $fotr_lnkrmn = 0;
 
}
?>
                            <label for="checkbox1">Add to Footer</label>
                          </div>
                                      </div>
                        <!--sec checkbox--->
                        <div class='form-check m-2 d-inline-block'>
                                        <div class="checkbox d-inline-block">
                            <input type="checkbox" id="checkbox1"class='form-check-input' name="headr_tpmin" <?php if(isset($_POST['headr_tpmin']) && $_POST['headr_tpmin'] == "on"){?> checked="checked" <?php } ?>/>
                            <?php
if(isset($_POST['headr_tpmin']) && $_POST['headr_tpmin'] == "on"){
 $hidr_liinkr = 1;
}else{
 $hidr_liinkr = 0;
 
}
?>
                            <label for="checkbox1">Add to Header</label>
                          </div>
                                      </div>
                        <!--sec checkbox--->
                      </div>
                                    <!--8 end--->
                                    <div class="col-md-4 mt-3">
                        <label>Page Title Image</label>
                      </div>
                                    <div class="col-md-8 form-group mt-3">
                        <div class="mb-3">
                       <label for="formFile" class="form-label">Upload Image From Your Gallery </label>
        <!-- <input class="with-validation-filepond" required multiple data-max-file-size="1MB" data-max-files="3"  type="file" id="formFile" name="ttlimg_keys">  -->
			                 <input data-max-files="3"  type="file" id="formFile" name="ttlimg_keys"> 
								<p><small class="text-muted">JPEG, JPG Size: 600px X 400px</small></p>
								<?php
							
								if($_FILES['ttlimg_keys'] != ''){
								 
								$uplo = miximgs_upl($_FILES['ttlimg_keys']['name'], $_FILES['ttlimg_keys']['size'], $_FILES['ttlimg_keys']['tmp_name']);
								//echo "<div id='success_alert'>Image Accepted</div>";
									
								}else{
								$uplo = '';
								echo "<div class'alert alert-light-danger color-danger'>Please Upload An Images</div>"; 
								}// end if
								?>
                                      </div>
                      </div>
                                    <!--catgory module--->
                                    <div class="col-md-4 mt-3">
                        <label>Page Category</label>
                      </div>
                                    <div class="col-md-8 form-group"> <?php echo $view->subcatelist(); ?>
                        <?php
									if(isset($_POST['subctag']) && $_POST['subctag'] != '') {
										echo $view->PageSubCatelistValidated($_POST['subctag']);
									
									$sub_arrayx = $_POST['subctag'];
									 echo "<div class='text-success'>".count($_POST['subctag'])." Categories Selected</div>";
									 
									}else{
									echo "<div class='alert alert-light-danger color-danger'><i class='bi bi-exclamation-circle'></i> Alert: 0 Selected</div>";
									}
									?>
                      </div>
                                    <!--catgory module--->
                                    <div class="col-sm-12 mt-4 d-flex justify-content-end">
                        <input class="btn btn-primary me-1 mb-1" type="submit" name="admit_category" value="Create New Page"  />
                        <button type="reset" class="btn btn-light-secondary me-1 mb-1">Reset</button>
                      </div>
                                  </div>
                  </div>
                              </form>
<?php
if(isset($ctg_nme) && $ctg_nme != ''
&& isset($pga_tilxul_g) && $pga_tilxul_g != ''
&& isset($ctg_tlt)
&& isset($meta_dcspi)
//&& isset($blgpst_img) && $blgpst_img != ''
//&& isset($ctg_mtdsp) && $ctg_mtdsp != ''
&& isset($uplo)
&& isset($ctgmt_kwrd) 
&& isset($cg_status) && isset($ftrg_status)
&& isset($fotr_lnkrmn) && isset($hidr_liinkr)
&& isset($sub_arrayx)

){

     foreach($sub_arrayx as $subeach)
	{
	list($categoryname, $mastcategoryid) = explode(':#:', $subeach);
	// cate inputer
	$subc_tb = "blg_ctg_listdt";
	$subc_content = array("cate_nam" => $categoryname, "_top_ctg" => 1, "sort_ord" => 0, "cpn_unkkid" => md5($ctg_nme), "_unk_ky" => $key->uid(), "_frgn_ky" => $mastcategoryid, "_ent_sndr" => $_SESSION['logner_bot']);
	$query->queryhandler($subc_tb, $subc_content);
	}

		
	$tab = "jrnl_adpagx";	
	$contt = array("cate_nam" => $ctg_nme, "_top_ctg" => $cg_status, "_mt_ttl" => $ctg_tlt, "_mt_descp" => $meta_dcspi, 
					"_mt_kiywrd" => $ctgmt_kwrd, "_unk_ky" => $key->uid(),"_frgn_ky" => $key->fid(),
						"_ent_sndr" => $_SESSION['logner_bot'], "blg_ttlimgxi" => $uplo, "sdbir_ctg" => $ftrg_status,
					"ftro_mnwtb" => $fotr_lnkrmn, "hadr_mntib" => $hidr_liinkr, "str_refnma" => $pga_tilxul_g, "blg_catgy" => md5($ctg_nme));  
					
					
					
					

		
	$needle = array("cate_nam");
	$heystack = array("cate_nam" => $ctg_nme);
	// check heystack. can we use content array here too just like $content[0] for heystack
	if(mysqli_num_rows($query->queryBuilder($needle, $tab, $heystack)) == 0 ) {
			if($query->queryhandler($tab, $contt)) { 
			echo "<div class='alert alert-success alert-dismissible show fade'>
           Page Has Been Created Successfully
           <button type='button' class='btn-close' data-bs-dismiss='alert' aria-label='Close'></button></div>"; 
			    
			}else{
			  echo "<div id='dup_alert'>Q1-Error</div>"; 
			 }
	}else{
		
		$dup =  "<div id='cg_dup_alert'>Error: Duplicate Entry ( Page Already Exist )</div>";
		echo $dup;
		$err->logHandler(" Error: Duplicate Entry By: '".$_SESSION['logner_bot']."' on ".date("d-m-Y")." ".date("H:i:s",time())." {Page: Create Page}  ) <--> ( ", "cerr.php");
	} // dup if

}// end 2nd if

}else{
?>
						<form class="form form-horizontal" action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"> 

                                <div class="form-body">
                                    <div class="row">
                                    <div class="col-md-4">
                                        <label>Blog Tittle</label>
                                      </div>
                                    <div class="col-md-8 form-group">
									<input type="text" id="pgTitlfor" class="form-control" name="Category_name" onchange="slugerInput(this)" placeholder="Page Tittle">
               						  <p><small class="text-muted">Add Page / Blog Title</small></p>
                                      </div>
									  
									<div class="col-md-4">
                                        <label>Page Slug</label>
                                      </div>
                                    <div class="col-md-8 form-group">
									<input type="text" id="changslg" class="form-control" name="pag_sulg_name"  placeholder="Page Slug">
               						  <p><small class="text-muted">Title For URL To Appear.  Symbols Are Not Allowed Page / Blog Title</small></p>
                                      </div>
									  
									  
                         
                                    <div class="col-md-4 mt-3">
                                        <label>Root / Directory</label>
                                      </div>
									  <div class="col-md-8 form-group mt-3">
									  <select class="form-select"  name="Categorymeta_title" style="width: 100%; padding: 10px;">
                                    <option value="">Select Root</option>
											<?php 
											foreach($dlist as $value){
											?>
											<option value="<?php echo $value; ?>"><?php echo $value; ?></option>
											<?php
											}
											?>
											</select>
											 <p><small class="text-muted">Select Root As Per Page Content</small></p>
                                      </div>
									  	
									   
                                    <div class="col-md-4 mt-3">
                                        <label>Meta Description</label>
                                      </div>
                                    <div class="col-md-8 form-group mt-3">
                                        <input type="text"  class="form-control" name="Categorymeta_descp" placeholder="Meta Description">
                                      </div>
                                    <div class="col-md-4 mt-3">
                                        <label>Page Detail</label>
                                      </div>
                                    <div class="col-md-8 mt-3 form-group">
                                    <textarea id="summernote" name="Category_metakeywrds"></textarea>
                                      </div>
                                    <div class="col-md-4 mt-3">
                                        <label>Placement</label>
                                      </div>
                                    <div class="col-md-8 mt-3 form-group">
                                        <div class=' m-2 form-check d-inline-block'>
                                        <div class="checkbox d-inline-block">
                                            <input type="checkbox" id="checkbox1" class='form-check-input' name="top_Category" />
                                            <label for="checkbox1">Add to Home</label>
                                          </div>
                                      </div>
                                        <!--sec checkbox--->
                                        <div class='form-check m-2 d-inline-block'>
                                        <div class="checkbox d-inline-block">
                                            <input type="checkbox" id="checkbox1" class='form-check-input' name="footer_Category" />
                                            <label for="checkbox1">Add to Side Bar</label>
                                          </div>
                                      </div>
                                        <!--first checkbox--->
                                        <div class='form-check m-2 d-inline-block'>
                                        <div class="checkbox d-inline-block">
                                            <input type="checkbox" id="checkbox1" class='form-check-input' name="footer_mniu" />
                                            <label for="checkbox1">Add to Footer</label>
                                          </div>
                                      </div>
                                        <!--sec checkbox--->
                                        <div class='form-check m-2 d-inline-block'>
                                        <div class="checkbox d-inline-block">
                                            <input type="checkbox" id="checkbox1" class='form-check-input' name="headr_tpmin" >
                                            <label for="checkbox1">Add to Header</label>
                                          </div>
                                      </div>
                                        <!--sec checkbox--->
                                      </div>
                                    <!--8 end--->
                                    <div class="col-md-4 mt-3">
                                        <label>Page Title Image</label>
                                      </div>
                                    <div class="col-md-8 form-group mt-3">
                                        <div class="mb-3">
                                        <label for="formFile" class="form-label">Upload Page Title Image</label>
                  <!--  <input type="file"  class="with-validation-filepond" required multiple data-max-file-size="1MB" data-max-files="3" id="formFile" name="ttlimg_keys">  -->
					
					 				 <input type="file" id="formFile" name="ttlimg_keys">
										<p><small class="text-muted">JPEG, JPG Size: 600px X 400px</small></p>
                                      </div>
                                      </div>
                                    <!--catgory module--->
                                    <div class="col-md-4 mt-3">
                                        <label>Page Category</label>
                                      </div>
                                    <div class="col-md-8 form-group">
									<?php echo $view->subcatelist(); ?>
									</div>
                                    <!--catgory module--->
                                    <div class="col-sm-12 mt-4 d-flex justify-content-end">
                                    
					<input class="btn btn-primary me-1 mb-1" type="submit" name="admit_category" value="Create New Page"  />
                                        <button type="reset" class="btn btn-light-secondary me-1 mb-1">Reset</button>
                                      </div>
                                  </div>
                                  </div>
                              </form>
 <?php } // post ?>
                              </div>
                          </div>
                          </div>
                      </div>
                      </div>
                  </section>
					
                </div><!-- page-head -->
				     </div><!-- main-content -->

<?php
//} // end get f
?>

<script type="text/javascript">
  function slugerInput(pgTitlfor) {
    var input2 = document.getElementById('changslg');
	const noSpecialChars = pgTitlfor.value.replace(/[^\w ]/g, '');
	//clean_title = noSpecialChars.replace(' ', '_');
    input2.value = noSpecialChars;
	
  } // fun
  
	 var input = document.getElementById("changslg");
	input.oninput = function (e) {
 	 e.target.value = e.target.value.replace(' ', '_');
	} 

</script>



