<?php include("includes/head.php");?>
<?php 
//$_GET['sid'] = '2';
if(isset($_GET['catid']) && $_GET['catid']!='')
{
	$query_shInfo = "SELECT * FROM ".TBL_CATEGORIES." WHERE category_id = '$_GET[catid]'";
	$shcatInfo = $con->getSingleRow($query_shInfo);
}
?>
<body>
<form name="frmStockholdersCategories" id="frmStockholdersCategories">
  <input type="hidden" name="action" value="updateCatOrt">
  <input type="hidden" name="catid" value="<?php echo isset($_GET['catid'])?$_GET['catid']:'';?>">
  
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span> </button>
      <h4 class="modal-title" id="myModalLabel">Update Category<?php //echo $shcatInfo['category_title'];?></h4>
    </div>
    <div class="modal-body">
      <div role="tabpanel">
        <!-- Nav tabs -->
        <!--<ul class="nav nav-tabs" role="tablist">
          <li class="active"><a data-toggle="tab" href="#TabCatInfo"><span class="adminpro-icon adminpro-analytics tab-custon-ic">&nbsp;Update Category Orientation</span></a></li>          
        </ul> -->       
        <!-- Tab panes -->
        <div class="tab-content">
          <!--<div role="tabpanel" class="tab-pane active" id="uploadTab">upload Tab</div>
                                    <div role="tabpanel" class="tab-pane" id="browseTab">browseTab</div>-->
          <div id="TabCatInfo" class="tab-pane in active custon-tab-style1">
            <div class="basic-login-form-ad">
              <div class="row" style="margin-top:30px;">
                
                <div class="col-lg-12">
                  <div class="all-form-element-inner">
                    <div class="form-group-inner">
                      <div class="row">
                        <div class="col-lg-3">
                          <label class="login2 pull-right pull-right-pro">Title <span style="color: #FF0000;">*</span></label>
                        </div>
                        <div class="col-lg-9">
                          <input type="text" class="form-control" name="category_title" id="category_title" value="<?php echo isset($shcatInfo['category_title'])?$shcatInfo['category_title']:'';?>" required/>
                        </div>
                      </div>
                    </div>
                    <div class="form-group-inner">
                      <div class="row">
                        <div class="col-lg-3">
                          <label class="login2 pull-right pull-right-pro">Abbreviation <span style="color: #FF0000;">*</span></label>
                        </div>
                        <div class="col-lg-9">
                          <input type="text" class="form-control" name="category_abbreviation" id="category_abbreviation" value="<?php echo isset($shcatInfo['category_abbreviation'])?$shcatInfo['category_abbreviation']:'';?>" required/>
                        </div>
                      </div>
                    </div>
                    
                    <div class="form-group-inner">
                      <div class="row">
                        <div class="col-lg-3">
                          <label class="login2 pull-right pull-right-pro">Description</label>
                        </div>
                        <div class="col-lg-9">
                          <textarea name="category_description" id="category_description" rows="10" cols="50"><?php echo isset($shcatInfo['category_description'])?$shcatInfo['category_description']:'';?></textarea>
                          <!--<script>CKEDITOR.replace( 'description_sh' );</script>-->
                        </div>
                      </div>
                    </div>
                    
                    <div class="form-group-inner">
                      <div class="row">
                        <div class="col-lg-3">
                          <label class="login2 pull-right pull-right-pro">Orientation</label>
                        </div>
                        <div class="col-lg-9">
                          <select class="form-control custom-select-value" name="category_orientation" id="category_orientation" required style="width:250px;">
                            <option value="">Select Orientation</option>
                            <option value="red" <?php if ( isset($shcatInfo['category_orientation']) && $shcatInfo['category_orientation']=="red"){?> selected<?php }?> style="background-color:#FF0000;">Resistant</option>
                            <option value="orange" <?php if ( isset($shcatInfo['category_orientation']) && $shcatInfo['category_orientation']=="orange"){?> selected<?php }?> style=" background-color:#FF9933;">Neutral</option>
                            <option value="green" <?php if ( isset($shcatInfo['category_orientation']) && $shcatInfo['category_orientation']=="green"){?> selected<?php }?> style="background-color:#00FF00;">Supportive</option>
                          </select>
                        </div>
                      </div>
                    </div>
                    
                    <div class="form-group-inner">
                      <div class="row">
                        <div class="col-lg-3">
                          <label class="login2 pull-right pull-right-pro">Influence</label>
                        </div>
                        <div class="col-lg-9">
                          <select class="form-control custom-select-value" name="category_influence" id="category_influence" required style="width:250px;">
                            <option value="">Select Influence</option>
                            <option value="500" <?php if ( isset($shcatInfo['category_influence']) && $shcatInfo['category_influence']=="500"){?> selected<?php }?> >Low</option>
                            <option value="900" <?php if ( isset($shcatInfo['category_influence']) && $shcatInfo['category_influence']=="900"){?> selected<?php }?> >Medium</option>
                            <option value="1300" <?php if ( isset($shcatInfo['category_influence']) && $shcatInfo['category_influence']=="1300"){?> selected<?php }?> >High</option>
                          </select>
                        </div>
                      </div>
                    </div>
                    
                    
                  </div>
                </div>
                
              </div>
            </div>
          </div>          
        </div>
      </div>
    </div>
    
    <!--<div class="modal-footer">      
      <div style="text-align:right;">
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      <button data-loading-text="Saving..." type="submit" class="btn btn-success"> <i class="fa fa-floppy-o"></i> Save </button>
      </div>      
    </div>-->
    
    <div class="modal-footer">
    
      <div style="text-align:left;">
      	<button data-loading-text="Deleting..." type="button" class="btn btn-danger" onClick="deleteSHCat('<?=$shcatInfo['category_id'];?>');"> <i class="fa fa-floppy-o"></i> Delete Category </button>
         
        <button type="button" class="btn btn-primary" onClick="javascript: showAddSHModal('<?php echo $shcatInfo['category_id'];?>');return false;">Add Stakeholder</button> 
        
      </div>
      
      <div style="text-align:right;">
         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
         <button data-loading-text="Saving..." type="submit" class="btn btn-success"> <i class="fa fa-floppy-o"></i> Save </button>
      </div>      
      
    </div>
    
</form>

<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <!--<div class="modal-header">
        <h4 class="modal-title"></h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>-->
      <div class="modal-body"> </div>
      <!--<div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>-->
    </div>
  </div>
</div>

<!-- jquery
		============================================ -->
<script src="js/vendor/jquery-1.11.3.min.js"></script>
<!-- bootstrap JS
		============================================ -->
<script src="js/bootstrap.min.js"></script>
<!-- notification JS
		============================================ -->
<script src="js/Lobibox.js"></script>
<script src="js/notification-active.js"></script>
<!-- Tree Viewer JS
		============================================ -->
<script src="js/tree-line/jstree.min.js"></script>
<script src="js/tree-line/jstree.active.js"></script>

<script>
$(document).ready(function(e){
    
    $('form input').on('keypress', function(e) {
    	return e.which !== 13;
	});

	$("#frmStockholdersCategories").on('submit', function(e){
	
	e.preventDefault();
	
	var shdata = new FormData(this);
	
	var category_orientation = $("#category_orientation").val();
	
	if(category_orientation=='')
	{		
		Lobibox.notify('error', {
			title: 'Error',					
			position: 'top right',//top left,top right,bottom left,bottom right,
			msg: 'Please, enter Category Orientation!'
		});
	}
	else
	{
    	$.ajax({		
		type: 'POST',
        url: 'categoriesActions.php',
		processData: false,
		contentType: false,
        data: shdata,
		cache: false,
		dataType: 'JSON',
        success:function(response){			
            if(response[0].message == 'ok'){
				Lobibox.notify('success', {
                    title: 'Success',
                    msg: 'Data updated successfully.'
                });
				
				//loadNewData(response[0].newdata);
				loadNewData();
				
				$('#myModal').modal('hide');   
				
            }else{
                //alert('Some problem occurred, please try again.');
				Lobibox.notify('error', {
                    title: 'Error',
                    msg: 'Some problem occurred, please try again.'
                });
            }
        },
		error:function(html)
		{			
			Lobibox.notify('error', {
                    title: 'Error',
                    msg: 'Some problem occurred, Please try again.'
                });
        }
    });
	}
	});
	
});	

function deleteSHCat(catid) 
{	
	var OK = confirm('This action will also delete all the Stakehodlers in this category. Are you sure want to delete this Stakeholder?');
	if(OK)
	{	
		$.ajax({		
		type: 'POST',
		url: 'stackholdersActions.php',
		/*data: 'action=deleteSH&shid='+shid,*/
		data: { action : 'deleteSHCat',catid : catid },
		cache: false,
		dataType: 'JSON',
		success:function(response){				
				if(response[0].message == 'ok'){
					
					Lobibox.notify('success', {
						title: 'Success',
						msg: 'Category deleted successfully.'
					});
					
					//loadNewData(response[0].newdata);
					loadNewData();
					
					$('#myModal').modal('hide'); 
					
				}else{
					Lobibox.notify('error', {
						title: 'Error',
						msg: 'Some problem occurred, please try again.'
					});
				}
			},
			error:function(html)
			{			
				Lobibox.notify('error', {
						title: 'Error',
						msg: 'Some problem occurred, Please try again.'
					});
			}
		});		
	}			
}

function showAddSHModal(catid)
{
	var dataURL = "sh-add-overview.php?cid="+catid;
	$(".modal-body").html("");
	$('.modal-body').load(dataURL,function(){	
		$('#myModal').modal({show:true});
	});
}

</script>

</body>
</html>