<?php include("includes/head.php");?>
<?php 
//$_GET['sid'] = '2';
if(isset($_GET['sid']) && $_GET['sid']!='')
{
	$query_shInfo = "SELECT * FROM ".TBL_STAKEHOLDERS." WHERE id = '$_GET[sid]'";
	$shInfo = $con->getSingleRow($query_shInfo);
}
?>
<link href="scripts/treeview/hummingbird-treeview.css" rel="stylesheet" type="text/css">
<body>
<form name="frmStockholders" id="frmStockholders">
  <input type="hidden" name="action" value="updateS1">
  <input type="hidden" name="shid" value="<?php echo isset($_GET['sid'])?$_GET['sid']:'';?>">
  
    <div class="modal-header">
      <a href='#' onclick='parent.$.colorbox.close(); return false;'><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span> </button></a>
      <h4 class="modal-title" id="myModalLabel">Update Stakeholder</h4>
    </div>
    <div class="modal-body">
      <div role="tabpanel">
        <!-- Nav tabs -->
        <ul class="nav nav-tabs" role="tablist">
          <!--<li role="presentation" class="active"><a href="#uploadTab" aria-controls="uploadTab" role="tab" data-toggle="tab">Upload</a> </li>
                                      <li role="presentation"><a href="#browseTab" aria-controls="browseTab" role="tab" data-toggle="tab">Browse</a> </li>-->
          <li class="active"><a data-toggle="tab" href="#TabGeneral"><span class="adminpro-icon adminpro-analytics tab-custon-ic"></span>General Info</a></li>
          <!--<li class="disabled"><a data-toggle="" href="#TabImportance"><span class="adminpro-icon adminpro-analytics-arrow tab-custon-ic"></span>Importance</a></li>
          <li class="disabled"><a data-toggle="" href="#TabConcerns"><span class="adminpro-icon adminpro-analytics-bridge tab-custon-ic"></span>Concerns</a> </li>
          <li class="disabled"><a data-toggle="" href="#TabInteraction"><span class="adminpro-icon adminpro-analytics-bridge tab-custon-ic"></span>Interaction</a> </li>
          <li class="disabled"><a data-toggle="" href="#TabOrientation"><span class="adminpro-icon adminpro-analytics-bridge tab-custon-ic"></span>Orientation</a> </li>
          <li class="disabled"><a data-toggle="" href="#TabStrategy"><span class="adminpro-icon adminpro-analytics-bridge tab-custon-ic"></span>Strategy</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="TabGeneral" 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">Name of Stakeholder <span style="color: #FF0000;">*</span></label>
                        </div>
                        <div class="col-lg-9">
                          <input type="text" class="form-control" name="name" id="sh_name" value="<?php echo isset($shInfo['name'])?$shInfo['name']:'';?>" 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="abbreviation" id="sh_abbreviation" value="<?php echo isset($shInfo['abbreviation'])?$shInfo['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">Logo </label>
                        </div>
                        <div class="col-lg-9">
                          <input type="file" name="sh_logo" id="sh_logo" value=""/>
                          <input type="hidden" name="old_sh_logo" value="<?php echo isset($shInfo['sh_logo'])?$shInfo['sh_logo']:'';?>">
                          <img src="uploads/stake-holders/<?php echo isset($shInfo['sh_logo'])?$shInfo['sh_logo']:'';?>" width="50" height="50"> </div>
                      </div>
                    </div>
                    <div class="form-group-inner">
                      <div class="row">
                        <div class="col-lg-3">
                          <label class="login2 pull-right pull-right-pro">Areas of Operations </label>
                        </div>
                        <div class="col-lg-9">
                          <input type="text" class="form-control" name="areas_of_operations" id="sh_areas_of_operations" value="<?php echo isset($shInfo['areas_of_operations'])?$shInfo['areas_of_operations']:'';?>"/>
                        </div>
                      </div>
                    </div>
                    <div class="form-group-inner">
                      <div class="row">
                        <div class="col-lg-3">
                          <label class="login2 pull-right pull-right-pro">PWD Oriented</label>
                        </div>
                        <div class="col-lg-9">
                          <input type="checkbox" class="" name="pwd_oriented" id="sh_pwd_oriented" value="Y" <?php if(isset($shInfo['pwd_oriented']) && $shInfo['pwd_oriented']=='Y'){?>checked<?php }?> />
                        </div>
                      </div>
                    </div>
                    <div class="form-group-inner">
                      <div class="row">
                        <div class="col-lg-3">
                          <label class="login2 pull-right pull-right-pro">Address </label>
                        </div>
                        <div class="col-lg-9">
                          <input type="text" class="form-control" name="address" id="sh_address" value="<?php echo isset($shInfo['address'])?$shInfo['address']:'';?>"/>
                        </div>
                      </div>
                    </div>
                    <div class="form-group-inner">
                      <div class="row">
                        <div class="col-lg-3">
                          <label class="login2 pull-right pull-right-pro">Focal Person </label>
                        </div>
                        <div class="col-lg-9">
                          <input type="text" class="form-control" name="focal_person" id="sh_focal_person" value="<?php echo isset($shInfo['focal_person'])?$shInfo['focal_person']:'';?>"/>
                        </div>
                      </div>
                    </div>
                    <div class="form-group-inner">
                      <div class="row">
                        <div class="col-lg-3">
                          <label class="login2 pull-right pull-right-pro">Contact# </label>
                        </div>
                        <div class="col-lg-9">
                          <input type="text" class="form-control" name="tel_no" id="sh_tel_no" value="<?php echo isset($shInfo['tel_no'])?$shInfo['tel_no']:'';?>"/>
                        </div>
                      </div>
                    </div>
                    <div class="form-group-inner">
                      <div class="row">
                        <div class="col-lg-3">
                          <label class="login2 pull-right pull-right-pro">E-mail </label>
                        </div>
                        <div class="col-lg-9">
                          <input type="text" class="form-control" name="email" id="sh_email" value="<?php echo isset($shInfo['email'])?$shInfo['email']:'';?>"/>
                        </div>
                      </div>
                    </div>
                    <div class="form-group-inner">
                      <div class="row">
                        <div class="col-lg-3">
                          <label class="login2 pull-right pull-right-pro">Website </label>
                        </div>
                        <div class="col-lg-9">
                          <input type="text" class="form-control" name="website_url" id="website_url" value="<?php echo isset($shInfo['website_url'])?$shInfo['website_url']:'';?>" placeholder="http://www.url.com" />
                        </div>
                      </div>
                    </div>
                    <div class="form-group-inner">
                      <div class="row">
                        <div class="col-lg-3">
                          <label class="login2 pull-right pull-right-pro">Select Category <span style="color: #FF0000;">*</span></label>
                        </div>
                        <div class="col-lg-6">
                          <div class="form-select-list">
                            <select class="form-control custom-select-value" name="category_id" id="sh_category_id" required>
                              <option value="">Select Category</option>
                              <?php 
								$selQry_listings = "SELECT * FROM ".TBL_CATEGORIES." ORDER BY category_title";
								$listingsInfo =  $con->getMultiRow($selQry_listings, __FILE__,__LINE__);
								$totListings = count($listingsInfo);	
									for($t=0;$t<$totListings;$t++)
									{
								?>
                              <option value="<?php echo $listingsInfo[$t]['category_id'];?>" <?php if ( isset($shInfo['category_id']) && $shInfo['category_id']==$listingsInfo[$t]['category_id']){?> selected<?php }?>><?php echo $listingsInfo[$t]['category_title'];?></option>
                              <?php }?>
                            </select>
                          </div>
                        </div>
                        <div class="col-lg-3">
                          <!--<span class="input-group-btn">
                                                    <button type="button" class="btn btn-success" data-toggle="modal" data-target="#catModal"> <i class="fa fa-plus"></i> </button>
                                                    </span>-->
                        </div>
                      </div>
                    </div>
                    
                    <div class="form-group-inner">
                      <div class="row">
                        <div class="col-lg-3">
                          <label class="login2 pull-right pull-right-pro">Introduction</label>
                        </div>
                        <div class="col-lg-9">
                          <textarea name="description" id="description_sh" rows="10" cols="40"><?php echo isset($shInfo['description'])?$shInfo['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">High Priority</label>
                        </div>
                        <div class="col-lg-9">
                          <input type="checkbox" class="" name="is_high_priority" id="is_high_priority" value="1" <?php if(isset($shInfo['is_high_priority']) && $shInfo['is_high_priority']=='1'){?>checked<?php }?> />
                        </div>
                      </div>
                    </div>
                    
                    <div class="form-group-inner">
                      <div class="row">
                        <div class="col-lg-3">
                          <label class="login2 pull-right pull-right-pro">Departments & Files <span style="color: #FF0000;">*</span></label>
                        </div>
                        <div class="col-lg-9">
                          <div id="treeview_container" class="hummingbird-treeview well h-scroll-large">
                            <ul id="treeview" class="hummingbird-base">
                              <?php 
								  //--------------- Category Info ----------
								  $srno = 0;
								  								  
								  if($_SESSION['userGroupID']==1 or $_SESSION['userGroupID']==2){								  
								    $selQry_depts = "SELECT * FROM ".TBL_DEPARTMENTS." ORDER BY name";
								  }else{
								      $selQry_depts = "SELECT * FROM ".TBL_DEPARTMENTS." where status='1' and id IN(".$userDeptAccess.") ORDER BY name";
								  }
								  $deptsInfo =  $con->getMultiRow($selQry_depts, __FILE__,__LINE__);
								  $totDeptsListings = count($deptsInfo);
									if($totDeptsListings>0)
									{
										for($dept=0;$dept<$totDeptsListings;$dept++)
										{
											$srno++;
											$deptChecked = '';
											$deptDisplay = 'none';
								  			//----------------------------------------
											$selQry_file_dept = "SELECT dept_id FROM ".TBL_STAKEHOLDERS_DEPTS_FILES." WHERE stakerholder_id = '".$_GET['sid']."' AND dept_id='".$deptsInfo[$dept]['id']."' AND is_dept_checked='1' ";
											$fileDeptInfo =  $con->getSingleRow($selQry_file_dept, __FILE__,__LINE__);
											if(!empty($fileDeptInfo['dept_id']))
											{
												$deptChecked = 'checked';
												$deptDisplay = 'block';
											}
											//----------------------------------------
											$selQry_files = "SELECT * FROM ".TBL_FILES." WHERE department_id='".$deptsInfo[$dept]['id']."' ORDER BY name";
										    $filesInfo =  $con->getMultiRow($selQry_files, __FILE__,__LINE__);
										    $totDeptsListings = count($filesInfo);
											
											if($totDeptsListings>0)
											{
												for($df=0;$df<$totDeptsListings;$df++)
												{
													//----------------------------------------
													$selQry_DeptFile = "SELECT file_id FROM ".TBL_STAKEHOLDERS_DEPTS_FILES." WHERE stakerholder_id = '".$_GET['sid']."' AND file_id='".$filesInfo[$df]['id']."'";
													$DeptFileInfo =  $con->getSingleRow($selQry_DeptFile, __FILE__,__LINE__);
													if(!empty($DeptFileInfo['file_id']))
													{
														$deptDisplay = 'block';
													}
												}	
											}	
											//----------------------------------------
								?>
                                <li><i class="fa fa-plus"></i>
                                <label>
                                <input name="depts[]" id="node-<?php echo $deptsInfo[$dept]['id'];?>" value="<?php echo $deptsInfo[$dept]['id'];?>" data-id="custom-<?php echo $deptsInfo[$dept]['id'];?>" type="checkbox" <?php echo $deptChecked;?>>
                                <?php echo $deptsInfo[$dept]['name'];?></label>
                                <ul style="margin-left:10px; display:<?php echo $deptDisplay;?>">
                                  <?php 
								  //--------------- Category Info ----------
								    $srno = 0;
									if($totDeptsListings>0)
									{
										for($file=0;$file<$totDeptsListings;$file++)
										{
											$srno++;
											$fileChcked = '';
											//----------------------------------------
											$selQry_dept_file = "SELECT file_id FROM ".TBL_STAKEHOLDERS_DEPTS_FILES." WHERE stakerholder_id = '".$_GET['sid']."' AND file_id='".$filesInfo[$file]['id']."'";
											$deptFileInfo =  $con->getSingleRow($selQry_dept_file, __FILE__,__LINE__);
											if(!empty($deptFileInfo['file_id']))
											{
												$fileChcked = 'checked';
											}
											//----------------------------------------
								  ?>
                                  <li>
                                    <i class="fa fa-minus"></i>
                                    <label>
                                    <input name="files[]" id="node-<?php echo $filesInfo[$file]['id'];?>" value="<?php echo $filesInfo[$file]['id'];?>" data-id="custom-0" type="checkbox" <?php echo $fileChcked;?>>
                                    <?php echo $filesInfo[$file]['name'];?></label>                                    
                                  </li>
                                  <?php }
								  }?>
                                </ul>
                              </li>
                              <?php }
							  }?>
                            </ul>
                          </div>
                        </div>
                      </div>
                    </div>
                    
                  </div>
                </div>
              </div>
            </div>
          </div>          
        </div>
      </div>
    </div>
    <div class="modal-footer">
      <div style="text-align:left;"><button data-loading-text="Deleting..." type="button" class="btn btn-danger" onClick="deleteSH('<?=$shInfo['id'];?>');"> <i class="fa fa-floppy-o"></i> Delete Stakeholder </button></div>
      <div style="text-align:right;">
      <a href='#' onclick='parent.$.colorbox.close(); return false;'><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></a>
      <!--<button type="button" class="btn btn-primary save">Save changes</button>-->
      <!--<button class="btn btn-sm btn-primary login-submit-cs" type="button" onClick="shActions('frmStockholders');">Update & Finish</button>-->      
      <button data-loading-text="Saving..." type="submit" class="btn btn-success"> <i class="fa fa-floppy-o"></i> Save </button>
      </div>
      
      
    </div>
</form>
<!-- jquery
		============================================ -->
<!--<script src="js/vendor/jquery-1.11.3.min.js"></script>-->
<!-- bootstrap JS
		============================================ -->
<script src="js/bootstrap.min.js"></script>
<!-- summernote JS
		============================================ -->
<script src="js/summernote.min.js"></script>
<script src="js/summernote-active.js"></script>
<!-- notification JS
		============================================ -->
<script src="js/Lobibox.js"></script>
<script src="js/notification-active.js"></script>
<!-- main JS
		============================================ -->
<script src="js/main.js"></script>

<!-- Tree View
		============================================ -->
<!--<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>-->
<script src="scripts/treeview/hummingbird-treeview.js"></script>
<script>
	$("#treeview").hummingbird();
</script>

<script>
$(document).ready(function(e){

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

	$("#frmStockholders").on('submit', function(e){
	
	e.preventDefault();
	
	var shdata = new FormData(this);
	
	var sh_name = $("#sh_name").val();
	var sh_abbreviation = $("#sh_abbreviation").val();
	var sh_areas_of_operations = $("#sh_areas_of_operations").val();
	var sh_address = $("#sh_address").val();
	var sh_focal_person = $("#sh_focal_person").val();
	var sh_tel_no = $("#sh_tel_no").val();
	var sh_email = $("#sh_email").val();
	var sh_category_id = $("#sh_category_id").val();
	
	if(sh_name=='' || sh_abbreviation=='' || sh_category_id=='')
	{		
		Lobibox.notify('error', {
			title: 'Error',					
			position: 'top right',//top left,top right,bottom left,bottom right,
			msg: 'Please, enter all mandatory fields in General Info Tab'
		});
	}
	else
	{
    	$.ajax({		
		type: 'POST',
        url: 'stackholdersActions.php',
		processData: false,
		contentType: false,
        data: shdata,
		cache: false,
		dataType: 'JSON',
        success:function(response){
			
            if(response[0].message == 'ok'){
				
				$(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val('');
    			$(':checkbox, :radio').prop('checked', false);
				$('#frmStockholders').trigger("reset");
				
				getCategoriesList('s1');
				
				//$('#myModal').modal('hide');
				
				Lobibox.notify('success', {
                    title: 'Success',
                    msg: 'Stakeholder updated successfully.'
                });
				
				parent.$.colorbox.close();
				
				//window.location.href = 'sh-identifying.php';
				
            }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 deleteSH(shid) 
{	
	var OK = confirm('Are you sure want to delete this Stakeholder?');
	if(OK)
	{	
		$.ajax({		
		type: 'POST',
		url: 'stackholdersActions.php',
		/*data: 'action=deleteSH&shid='+shid,*/
		data: { action : 'deleteSH',shid : shid },
		cache: false,
		dataType: 'JSON',
		success:function(response){				
				if(response[0].message == 'ok'){
					
					getCategoriesList('s1');
					
					//$('#myModal').modal('hide');
					
					Lobibox.notify('success', {
						title: 'Success',
						msg: 'Stakeholder deleted successfully.'
					});
					
					parent.$.colorbox.close();
					
					//window.location.href = 'sh-identifying.php';
					
				}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.'
					});
			}
		});		
	}			
};
	
</script>

</body>
</html>
