<?php
 include 'tokenLookup.php';
 include 'processResponse.php';

		$prevAnswers = getSelectedDutiesByEmp($employeeID);
		 for ($i=1; $i<=mysql_num_rows($prevAnswers); $i++) {
						$prevDutyRow=mysql_fetch_array($prevAnswers);
						$prevDutyID = $prevDutyRow['Duty_ID'];
						$prevDutyArray[] = $prevDutyID;
			}
?>


<!DOCTYPE html>
<html>
	<head>
	<meta charset="utf-8" />
	<title>Job Survey - Leadership</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	</head>
<body class="blurBg-true" style="background-color:#010073">

<?php include 'cssIncludes.php' ?>
<form class="formoid-flat-blue" action="process.php?token=<?php echo $token?>" style="background-color:#FFFFFF;font-size:14px;font-family:'Lato', sans-serif;color:#666666;max-width:640px;min-width:150px" method="post">
	<div class="title"><h2>Duties Selection (1 of 2)</h2></div>
	
  <?php
    $thispage = substr(__FILE__, (strrpos ( __FILE__ , "/") +1));
    $thispage = substr($thispage, 0, strpos($thispage, "."));

    //$linenum = 0;
  ?>
  <input type="hidden" name="curPage" value="<?php echo $thispage?>">
  <input type="hidden" name="token" value="<?php echo $token?>">
  <input type="hidden" name="employeeID" value="<?php echo $employeeID?>">


<label class="title">Below are a list of duties that you may perform. Please check all duties that you perform.</label><br>
<div class='element-checkbox'>
  <input type="checkbox"  name="FD_DUTIES_LEVEL1"/>
  <table id="duties-table">
    <tbody>
	 <?php
	 // First, build include string
	 $titlesList = getSelectedJobTitlesByEmp($employeeID);
	 $includeString = "";
	 for ($i=1; $i<=mysql_num_rows($titlesList); $i++) {		// spin through titles, get duty count for each, add to dutiesCount
	  	  $row=mysql_fetch_array($titlesList);
          $jobTitleID = $row['Job_Title_ID'];
		  if ($i == 1)
		    $includeString = $jobTitleID;
		  else
		    $includeString .= "," . $jobTitleID;
	 }
	 

	 $dutiesCount = getDutiesCountByIncludeList($includeString);
	 $dutiesToGet = round($dutiesCount / 2);
	 $startingDuty = 0;
	   
	 $dutyCounter = 1;
		$minID = 0;
		$maxID = 0;
	 $dutiesList = getDutiesByIncludeList($includeString, $dutiesToGet, $startingDuty);
	 for ($j=1; $j<=mysql_num_rows($dutiesList); $j++) {
		    $drow=mysql_fetch_array($dutiesList);
      $jobDuty = $drow['Duty'];
		   	$jobDutyID = $drow['Duty_ID'];
						if ($jobDutyID > $maxID)
						  $maxID = $jobDutyID;
						if (in_array($jobDutyID, $prevDutyArray, true))
        $checkedFlag = "checked";
						else
						  $checkedFlag = "";
								
            echo "<tr>
 	            <td>
	            <label><input type='checkbox' name='FD_JOB_DUTIES_" . $jobDutyID  . "' value='" . $jobDutyID . "'" . $checkedFlag . "><span></span></label>
		        </td>
		        <td>&nbsp&nbsp&nbsp&nbsp
		        </td>
		        <td>
			    <label><span>";
		    echo $jobDuty;
		    echo "</span></label>
		    </td>
		    </tr>
		    <tr></tr><tr></tr><tr></tr><tr></tr>";
			$dutyCounter++;
	 }
		$whereClause = "'FD_JOB_DUTIES_%' AND Response BETWEEN " . $minID . " AND " . $maxID; 
      ?>

	</tbody>
	</table>
</div>

<input type="hidden" name="whereClause" value="<?php echo $whereClause?>">

 <?php include 'navSection.php' ?>
</form>

<script type="text/javascript" src="survey_files/formoid1/formoid-flat-blue.js" ></script>

</body>
</html>