<?php

session_start();

require_once('../config.php');

if(isset($_SESSION['uid'])=="" )

header("Location: ../index.php");

$userid=$_SESSION['uid'];


// CATEGORY IMAGE FETCH START

$categoryid = $_GET['categoryid'];

if($_POST["categoryname"] != "")
{

    $categoryname = $_POST['categoryname'];
    $categorysubname = $_POST['categorysubname'];
    $categorydescription = $_POST['categorydescription'];
	
    $imageinsert = $db->prepare("UPDATE tbl_category SET categoryname=:categoryname,categorysubname=:categorysubname,categorydescription=:categorydescription WHERE gallery_id=:gallery_id");
				
	$imageinsert->execute(array(':gallery_id' => $categoryid, ':categoryname' => $categoryname, ':categorysubname' => $categorysubname, ':categorydescription' => $categorydescription));
                
	header("Location:manage-category.php?categoryid=$categoryid");
    
}

if($categoryid != "")
{
  $galleryfetchb=$db->prepare("SELECT * FROM tbl_category where delete_status=? AND gallery_id = ? AND status = 'Before' ORDER BY order_id");
  $galleryfetchb->execute(array('0', $categoryid));
  
    $galleryfetchA=$db->prepare("SELECT * FROM tbl_category where delete_status=? AND gallery_id = ? AND status = 'After' ORDER BY order_id");
  $galleryfetchA->execute(array('0', $categoryid));


  $gallerydetail=$db->prepare("SELECT * FROM tbl_category where delete_status=? AND gallery_id = ?");
  $gallerydetail->execute(array('0', $categoryid));
  $gallerytitle = $gallerydetail->fetch(PDO::FETCH_ASSOC);
}

// CATEGORY IMAGE FETCH END


// IMAGE RANK ORDER START

if($_GET['imagerankorder']!="")
{
	$alldeleteids = explode(",",$_GET['imagerankorder']);
	$magazineid = explode(",",$_GET['mgid1']);
	for ($i=0;$i<count($alldeleteids);$i++)
	{
    $stmtupf=$db->prepare("update tbl_category set order_id=:field1 where id=:field2");
    $stmtupf->execute(array(':field1' => $alldeleteids[$i],':field2' => $magazineid[$i]));
	}
  
  header("Location:manage-category.php?categoryid=$categoryid");
}	


// IMAGE RANK ORDER END



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=1200">
<title>Control Panel | Cabrera Property Management</title>
<link href="../styles.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans&display=swap" rel="stylesheet">
<link rel="SHORTCUT ICON" href="../images/propertymanagement.ico">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-154924656-21"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-154924656-21');
</script>
<script type="text/javascript">
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
</script>
<script src="../js/jquery-1.9.1.js"></script>
<script type="text/javascript">

$(function () {		

	$('.btnGetAll').click(function () {

if ($('.chkNumber:checked').length) {

	var chkId = '';	

	$('.chkNumber:checked').each(function () {

	chkId += $(this).val() + ",";  });		  		  

	chkId = chkId.slice(0, -1);	

		if(confirm('Are you sure you would like to delete?')) {	

		var url = "global_deletepage.php?pageflag=user&deleteids=" + chkId;

		window.open(url, "PartySearch", "width=530,height=500,left=220,top=100"); } 

		else { return false; }	

	} else { alert('No User Name Have Been Selected To Delete'); } });	

	$('.chkSelectAll').click(function () {

	$('.chkNumber').prop('checked', $(this).is(':checked')); });

	$('.chkNumber').click(function () {

	if ($('.chkNumber:checked').length == $('.chkNumber').length){

	$('.chkSelectAll').prop('checked', true); }

	else { $('.chkSelectAll').prop('checked', false); }
	
   });
});

</script>

<script src="../js/jquery-1.9.1.js" type="text/javascript"></script>

<script type="text/javascript" src="tinymce/js/tinymce/tinymce.min.js"></script>

<script type="text/javascript">

tinymce.init({

selector: "#categorydescription",
relative_urls : false,
remove_script_host : false,
convert_urls : true,
valid_elements : '*[*]',
plugins: [

"advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",

"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",

"table contextmenu directionality emoticons template textcolor paste textcolor colorpicker textpattern"

],



toolbar1: "newdocument | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect",

toolbar2: "cut copy paste | searchreplace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor image media code | insertdatetime preview | forecolor backcolor",

toolbar3: "table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft",



menubar: false,

toolbar_items_size: 'small',



style_formats: [

{title: 'Bold text', inline: 'b'},

{title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},

{title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},

{title: 'Example 1', inline: 'span', classes: 'example1'},

{title: 'Example 2', inline: 'span', classes: 'example2'},

{title: 'Table styles'},

{title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}

],



templates: [

{title: 'Test template 1', content: 'Test 1'},

{title: 'Test template 2', content: 'Test 2'}

]

});


</script>


<script>

 function galleryvalidateForm()
        {
            var validationpassed = true;

            if( document.getElementById("categoryname").value == '' )
            {
                alert('Please enter category name and try again');
                document.getElementById('categoryname').focus();
                validationpassed = false;
                return false;
            }

			if(validationpassed)
            {
                document.getElementById('galleryform').submit();
                return true;
            }
            
        }

</script>

</head>

<body onload="MM_preloadImages('../images/home2.png','../images/about2.png','../images/portfolio2.png','../images/services2.png','../images/salesrentals2.png','../images/homeimprovements2.png','../images/contact2.png')">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
     <tr>
		<td align="center" ><?php include('headercontent.php'); ?></td>
	</tr>
  <tr>
    <td align="center" background="../images/pagebg.jpg" class="repeatx"><table width="1000" border="0" cellpadding="0" cellspacing="0" class="medspacing">
      <tr>
        <td><img src="../images/t.gif" width="20" height="30" alt="" border="0" /></td>
      </tr>
      <tr>
        <td align="left" valign="top"><table width="1000" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="center" class="gray6"><em>You Are Currently Logged In As: <strong><?php echo $_SESSION['lgfullname'];?></strong> (<a href="../logout.php">Log Out</a> or <a href="#">Switch To Member Access</a>)</em></td>
          </tr>
          <tr>
            <td><img src="../images/t.gif" width="15" height="5" alt="" /></td>
          </tr>
          <tr>
            <td bgcolor="#2065B0"><table width="1000" border="0" cellspacing="15" cellpadding="0">
              <tr>
                <td align="center" class="size18 white"><a href="index.php" class="whitelink">USER ACCOUNTS</a> &nbsp; | &nbsp; <a href="pages.php" class="whitelink">WEB SITE PAGES</a> &nbsp; | &nbsp; <a href="files.php" class="whitelink">UPLOAD FILES</a> &nbsp; | &nbsp; <a href="template.php" class="whitelink">SITE TEMPLATE</a> &nbsp; | &nbsp; <a href="data.php" class="whitelink">STORED DATA</a></td>
              </tr>
            </table></td>
          </tr>
        </table>
		
		<table width="1000" border="0" cellspacing="0" cellpadding="0">
        <h1>Manage Category > <?php echo $gallerytitle['categoryname']; ?> </h1>

          <!-- CATEGORY FETCH START -->
		  <form method='post' name="galleryform" id="galleryform" enctype='multipart/form-data'>
		<tr>
            <td colspan=""><img src="../images/t.gif" width="10" height="15" alt=""/></td>
        </tr>
        <tr>
            <td>
                <strong>
                    Category Upload:
                </strong>
            </td>
        </tr>
        <tr>
            <td colspan=""><img src="../images/t.gif" width="10" height="15" alt=""/></td>
        </tr>

        <tr>
            <td>
                <table width="1000" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td colspan="">
                            <strong>Category Name:</strong>
                        </td>
						<td colspan="">
                            <strong>Category Sub Name:</strong>
                        </td>
                    </tr>
                    <tr>
                        <td colspan=""><img src="../images/t.gif" width="10" height="5" alt=""/></td>
                    </tr>
                    <tr>
					<?php
					
					
					$galleryfetch1=$db->prepare("SELECT * FROM tbl_category where delete_status=? AND gallery_id = ?");
					$galleryfetch1->execute(array('0', $categoryid));
					$gallerytitle1 = $galleryfetch1->fetch(PDO::FETCH_ASSOC);
					
					if($_POST['categoryname']!="")
					{
						$cname=$_POST['categoryname'];
					}
					else
					{
						$cname=$gallerytitle1['categoryname'];
					}
					
					if($_POST['categorysubname']!="")
					{
						$csname=$_POST['categorysubname'];
					}
					else
					{
						$csname=$gallerytitle1['categorysubname'];
					}
					
					if($_POST['categorydescription']!="")
					{
						$cdname=$_POST['categorydescription'];
					}
					else
					{
						$cdname=$gallerytitle1['categorydescription'];
					}
					
					?>
                        <td colspan="">
                            <input type="text" name="categoryname" id="categoryname" style="width: 55%;" value="<?php echo $cname; ?>">
                        </td>
						<td colspan="">
                            <input type="text" name="categorysubname" id="categorysubname" style="width: 55%;" value="<?php echo $csname; ?>">
                        </td>
                    </tr>
					<tr>
                        <td colspan=""><img src="../images/t.gif" width="10" height="15" alt=""/></td>
                    </tr>
					 <tr>
                        <td colspan="">
                            <strong>Category Description:</strong>
                        </td>
                    </tr>
                    <tr>
                        <td colspan=""><img src="../images/t.gif" width="10" height="15" alt=""/></td>
                    </tr>
					<tr>
                        <td colspan="3">
                           <textarea name="categorydescription" rows="15" cols="3" id="categorydescription" style="width:100%"><?php echo $cdname; ?></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td colspan=""><img src="../images/t.gif" width="10" height="15" alt=""/></td>
                    </tr>
                    <tr>
                        <td colspan="">
                            <input type='button' value='Upload' name='uploadgallery' onclick="galleryvalidateForm()"> &nbsp; <input type="button" name="button5" id="button5" value="Cancel" onclick="window.location.href='update_page.php?id=15'" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan=""><img src="../images/t.gif" width="10" height="45" alt=""/></td>
                    </tr>
					<tr>
					<td colspan="3" bgcolor="#CCCCCC" ><img src="../images/t.gif" width="1000" height="1" alt="" border="0" /></td>
					</tr>
					</table>
            </td>
        </tr>
        </form>
		
		<tr>
		<td>
          <table width="1000" border="0" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF">
            <tr>
                <td colspan=""><img src="../images/t.gif" width="10" height="15" alt=""/></td>
            </tr>
            <tr>
              <td>
                <input type="button" name="imagedeletebutton" id="imagedeletebutton" value="Delete Selected">

                <input type="button" name="imagerankorderbutton" id="imagerankorderbutton" value="Update Rank Order">
              </td>
            </tr>
            <tr>
                <td colspan=""><img src="../images/t.gif" width="10" height="15" alt=""/></td>
            </tr>
          </table>
<!-- Before -->

          <table width="1000" border="0" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF">
		  
		  	 <tr>
                        <td colspan="">
                            <strong>Before Images:</strong>
                        </td>
              </tr>

            <?php
              
              $td = 0;
              while($galleryfetchresult = $galleryfetchb->fetch(PDO::FETCH_ASSOC))
              {
                if($td == 0)
                {
                    echo('<tr>');     
                }
            ?>
                    <td width="250">
                        <img src="../categories/<?php echo $galleryfetchresult['imagename'];?>" width="100%"  height="250" alt="<?php echo $galleryfetchresult['imagename'];?>"/>
                        <div align="center" style="margin-top:10px;">
                          <input type="checkbox" name="galleryimage" class="galleryimage" value="<?php echo $galleryfetchresult['id'];?>">
                          <input type="text" name="imagerankorder" class="imagerankorder" size="3" value="<?php echo $galleryfetchresult['order_id'];?>">
                        </div>
                    </td>

                    <?php
                        $td++;
                        if($td == 3)
                        {
                          echo('</tr>');
                          $td = 0;
                        }
                    ?>
            <?php
              } 
            ?>



          </table>
		  <!-- Before -->
		  
		  <!-- After -->
		  <table width="1000" border="0" cellpadding="5" cellspacing="1" bgcolor="#FFFFFF">
					  	 <tr>
                        <td colspan="">
                            <strong>After Images:</strong>
                        </td>
              </tr>
            <?php
              
              $atd = 0;
              while($galleryfetchresultA = $galleryfetchA->fetch(PDO::FETCH_ASSOC))
              {
                if($atd == 0)
                {
                    echo('<tr>');     
                }
            ?>
                    <td width="250">
                        <img src="../categories/<?php echo $galleryfetchresultA['imagename'];?>" width="100%"  height="250" alt="<?php echo $galleryfetchresultA['imagename'];?>"/>
                        <div align="center" style="margin-top:10px;">
                          <input type="checkbox" name="galleryimage" class="galleryimage" value="<?php echo $galleryfetchresultA['id'];?>">
                          <input type="text" name="imagerankorder" class="imagerankorder" size="3" value="<?php echo $galleryfetchresultA['order_id'];?>">
                        </div>
                    </td>

                    <?php
                        $atd++;
                        if($atd == 3)
                        {
                          echo('</tr>');
                          $atd = 0;
                        }
                    ?>
            <?php
              } 
            ?>
		    			

          </table>
		  
		  <!-- After -->
		  </td>
      </tr>
	  </table>
          <!-- CATEGORY FETCH END --></td>
      </tr>
      <tr>
        <td><img src="../images/t.gif" width="20" height="30" alt="" border="0" /></td>
      </tr>
    </table></td>
  </tr>
 
<tr>
    <td><?php include('footercontent.php'); ?></td>
 </tr>
</table>


<script src="../js/jquery-1.9.1.js"></script>

<script type="text/javascript">

  $(function () 
  {		
    $('#imagedeletebutton').click(function () 
    {
      if ($('.galleryimage:checked').length) 
      {
        var chkId = '';	

        $('.galleryimage:checked').each(function () 
        {
          chkId += $(this).val() + ",";  
        });		  		  

        chkId = chkId.slice(0, -1);	

        if(confirm('Are you sure you would like to delete?')) 
        {	
          var url = "global_deletepage.php?pageflag=categoryimage&deleteids=" + chkId;
          window.open(url, "PartySearch", "width=530,height=500,left=220,top=100"); 
        }  
        else 
        { 
          return false; 
        }	
      } 
      else 
      { 
        alert('No Image Have Been Selected To Delete'); 
      } 
    });	

  });


</script>

<script>

  $(function () 
  {		
    $('#imagerankorderbutton').click(function () 
    {
      var categoryid = '<?php echo $categoryid; ?>'
      var chkId1 = '';	
      $('.imagerankorder').each(function () {
      chkId1 += $(this).val() + ",";  });		  	
      chkId1 = chkId1.slice(0, -1);	
      
      var mgid1 = '';	
      $('.galleryimage').each(function () {
      mgid1 += $(this).val() + ",";  });		  		  
      mgid1 = mgid1.slice(0, -1);
      
      if(confirm('Are you sure you would like to Update Order..?')) 
      {	
        window.location.href = "http://<?php echo $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']?>?categoryid="+categoryid+"&imagerankorder="+chkId1+"&mgid1="+mgid1;		
      } 
      else 
      { 
        return false; 
      }	
    });
  });


</script>

</body>
</html>
