<?php 

class clickCheckbox  {
  private $scope;
  private $iterator;
  private $label;
  public function __construct($entry) {

    if (isset($entry)) {
      $this->scope    = $entry->scope;
      $this->iterator = $entry->iterator;
      $this->label    = $entry->label;
    }
  }

  public function outputLayout() {

  $layout = "
    <input type='hidden' id=chkval$this->scope class=$this->iterator name='$this->scope' value=0> 
    <label>$this->label
      <input type='checkbox' id='check$this->scope'>
    </label>
  ";
  
 	return $layout;
  }	

  public function outputScript() {

    $script = "
 
$('#check$this->scope').on('click', function() {
   if ( $(this).prop('checked') )
     $('#chkval$this->scope').val(1);
   else
     $('#chkval$this->scope').val(0);
});


$('#chkval$this->scope').on('chg$this->iterator', function() {
  if ( $(this).val() == 1 )
    $('#check$this->scope').prop('checked', true);
  else
    $('#check$this->scope').prop('checked', false);
});

      
    "; 
    
    return $script;
  }
}

?>