<?php 

class SelectDateForm {

  private $scope;
  private $scopeId;
  private $label;
  private $date;
  private $iterator;
  private $entryNow;

  public function __construct($entry) {
    if (isset($entry)) {
      $this->scope    = $entry->scope;
      $this->scopeId  = $entry->scopeId;
      $this->label    = $entry->label;
      $this->iterator = $entry->iterator;
      $this->entryNow = $entry->entryNow;
      
      if (isset($entry->sendId))
        $this->sendId = $entry->sendId;
      else
        $this->sendId = 0;

      $this->postMessages = "";
      if (null !== $entry->listeners) {
        $listeners = explode(",", $entry->listeners);
        for ($i=0; $i<count($listeners); $i++) {
          $this->postMessages .= "listener" . $listeners[$i] . "(msgContent); ";
        }
      }    
    } 
  }
  
  public function outputLayout() {

    $layout = "
<label>$this->label</label><br>
<input type='date' id='date$this->scope' class='$this->iterator' 
  name='$this->scope' style='width:150px;'>
    "; 

    return $layout;
  }

  public function outputScript() {

    $script = "

$(document).on('change', '#date$this->scope', function (e) {
  var frmValue =  $(this).val();
  send$this->scope (frmValue, frmValue);
});

function set$this->scope (dbValue, dbText) {
  document.getElementById('date$this->scope').value = dbValue;
}

multiFunction['set$this->scope'] = {
  set$this->scope:set$this->scope
}; 

function send$this->scope (value, text) {
  var msgContent = [];
  msgContent.$this->scope = [value, text, 'formentry', '$this->scope', 'new field value'];
  newValue$this->iterator (msgContent);
}

    ";
    return $script;
  }
}

?>

