<?php
if($_REQUEST['jobid']!=''){

$child=DB_fetch_assoc(DB_query("SELECT COUNT(b.parentid) AS cnt,b.parentid,a.vacancy_code,b.id as cid FROM hr_job_created a, hr_job_created_details b WHERE a.id=b.parentid AND b.parentid='".$s->GetFieldValue('hr_job_created_details',"id='".$_REQUEST['jobid']."'",'parentid')."' ",$db));


$post_count=DB_query("SELECT * FROM hr_job_created a,hr_job_created_details b WHERE a.id=b.parentid AND posting_status='y'  AND a.id='".$s->GetFieldValue('hr_job_created_details',"id='".$_REQUEST['jobid']."'",'parentid')."' ",$db);
  $cntr=DB_num_rows($post_count)+1;

$finalstr=$child['vacancy_code'].'/'.$cntr;

DB_query("update hr_job_created_details set posting_status='y' ,posting_date='".date('Y-m-d')."',job_number='".$finalstr."' where id='".$_REQUEST['jobid']."' ",$db);

$post=DB_fetch_assoc(DB_query("SELECT COUNT(b.parentid) AS cnt FROM hr_job_created a, hr_job_created_details b WHERE a.id=b.parentid AND b.parentid='".$s->GetFieldValue('hr_job_created_details',"id='".$_REQUEST['jobid']."'",'parentid')."' and posting_status='y' ",$db));

if($post['cnt']==$child['cnt'])
{
  DB_query("update hr_job_created set post_status=1 where id='".$child['parentid']."' ",$db);
}
$s->pageLocation("index.php?route=HRModule/vacancy_posting".$rurl."&tab=1&type=jobsposted");
}
?>
<h1>Jobs Pending to Post</h1>	
<div style="padding:10px;">
    <div style=" width: 20px;height: 20 ;background-color: #F39814;float:left "></div>&nbsp;&nbsp;&nbsp;<div style="float:left;padding: 3px"><strong>UnScheduled</strong></div> 
    <div style="width: 20px;height: 20 ;background-color: #009933;float:left"></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div style="float:left;padding: 3px "> <strong>Scheduled</strong></div>  
</div>
<br>
<!--<div style="float:left"><a href="index.php?route=HRModule/job_criteria_master&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>"><button type="button" >Add New</button></a></div>-->
<table width="100%" cellpadding="3" cellspacing="0" border="1" style="border:#808080 1px solid; border-collapse:collapse;">
<tr>
        <th rowspan="2" width="6%"><strong>S. No.</strong></th>
	    <th rowspan="2"><strong>Branch</strong></th>
        <th rowspan="2" width="16%"><strong>Job Type</strong></th>
        <th rowspan="2" width="10%"><strong>Vacancy Code</strong></th>
	    <th rowspan="2" width="10%"><strong>Vacancy Date</strong></th>
        <th colspan="4" style="text-align: center"><strong>Vacancy Details</strong></th>
</tr>
<tr>
        <th width="80">Designation</th>
        <th width="80">Department</th>
        <th width="80">Required</th>
        <th width="80">Action</th>
</tr>
<?php $i=0; $SQL=DB_query("SELECT * FROM hr_job_created where companyid='".$_SESSION['ACGCompanyId']."' and post_status='0' ",$db);
if(DB_num_rows($SQL)>0){
while($GetRec=DB_fetch_array($SQL)) {?>
<tr bgcolor="#fff">
	    <td><?php echo $i+1; ?></td>
	    <td><?php echo $sitename=$s->GetFieldValue('locations',"loccode='".$GetRec['branch']."'",'locationname'); ?></td>
        <td><?php if($GetRec['job_type']=="p"){ echo "Permanent"; } else if($GetRec['job_type']=="c"){ echo "Contract" ;} ?></td>
        <td><?php echo $GetRec['vacancy_code']; ?></td>
        <td><?php echo ConvertSQLDate($GetRec['vac_date']) ?></td>
        <td>
        <table border="1" width="100%" cellpadding="3" cellspacing="0">
      <?php $detsql=DB_query("select * from hr_job_created_details where parentid='".$GetRec['id']."' and posting_status='n' ",$db);  
      while($detres=DB_fetch_assoc($detsql)){?>
                <?php if($detres['schedule_status']=='1') $p="#009933"; else $p="#F39814";?>
                <tr style="background-color: <?php echo $p; ?>">
                    <td width="80"><?php $desig= DB_fetch_assoc(DB_query("select * from desigmaster where id='".$detres['designation']."' ",$db)); echo $desig['designame'];?></td>
                    <td width="80"><?php $dept= DB_fetch_assoc(DB_query("select * from deptmaster where id='".$desig['mst_departmentid']."' ",$db)); echo $dept['deptname']; ?></td>
                    <td width="80"><?php echo $detres['required']; ?></td>  
                    <td width="80">
                        <?php if($detres['posting_status']=='n'){ ?>
                        <a href="index.php?route=HRModule/vacancy_posting&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&tab=1&type=jobspending&jobid=<?php echo $detres['id'] ?>" onclick="javascript:return confirm('Sure you Want to Post this job ?');"><input type="button" value="Job Post"></a>
                    <?php } //else { echo "Posted"; }  ?>
                    </td>                       
                </tr>
      <?php } ?>
            </table></td>
</tr>
<?php $i++;} }else{?>
<tr bgcolor="#fff">
    <td colspan="9" align="center">No Result Found</td>
</tr>
<?php } ?>
</table>
</div>
</div>