<?php 

class formDataHandler {
  private $scope;
  private $position;
  private $label;
  private $formDefs;
  private $confirmModal;

  public function __construct ($entry) {
    if (isset($entry)) {
      $this->scope    = $entry->scope;
      $this->headText = $entry->headText;
      $this->bodyText = $entry->bodyText;
      $this->disabled = $entry->disabled;
      $this->iterator = $entry->iterator;
      $this->label    = $entry->label;
      $this->defLab   = explode ("_", $entry->label)[0];

      if (isset($entry->indexMask))
         $this->indexMask = $entry->indexMask;
      else
        $this->indexMask = 10;
      
      if (isset($entry->readyMask))
         $this->readyMask = $entry->readyMask;
      else
        $this->readyMask = 0;

      if (isset($entry->stateMask))
         $this->stateMask = $entry->stateMask;
      else
        $this->stateMask = 0;

      if (isset($entry->hideCommit))
         $this->hideCommit = $entry->hideCommit;
      else
        $this->hideCommit = 0;

      if (isset($entry->childSlider))
         $this->childSlider = $entry->childSlider;
      else
        $this->childSlider = "panel0";

      if (isset($entry->summaryTable))
        $this->summaryTable = $entry->summaryTable;
      else
        $this->summaryTable = "";

      if (isset($entry->imageCapture))
        $this->imageCapture = $entry->imageCapture;
      else
        $this->imageCapture = "";

      if (null !== $entry->formDef0)
        $this->formDef0 = json_encode($entry->formDef0);
      else
        $this->formDef0 = '{}';

      if (null !== $entry->formDef1)
        $this->formDef1 = json_encode($entry->formDef1);
      else
        $this->formDef1 = '{}';

      if (isset($entry->formData))
        $this->formData = json_encode($entry->formData);
      else
        $this->formData = '{}';

      if (isset($entry->selectId))
        $this->selectId = $entry->selectId;
      else
        $this->selectId = 0;

      if (isset($entry->summaryId))
        $this->summaryId = $entry->summaryId;
      else
        $this->summaryId = 0;

      if (isset($entry->filterId))
        $this->filterId = $entry->filterId;
      else
        $this->filterId = 0;

      if (isset($entry->button))
        $this->button = "display:$entry->button";
      else
        $this->button = "";

      if (isset($entry->position) && $entry->position == "left")
        $this->position = "float:left";
      else
        $this->position = "float:right";

      if (isset($entry->confirmModal)) 
        $this->confirmModal = $entry->confirmModal;
      else
        $this->confirmModal = 0;

    }
  }
  
  public function outputLayout() {
  
$html = "

<button id='fdh$this->iterator' class='btn btn-inverse fdh$this->iterator' value='$this->label' 
  onclick='processForm$this->scope();' style='$this->position;$this->button'>
  $this->defLab
</button>
    ";
  	return $html;
  }
  
  public function outputScript() {
		
    $script = "

if (multiFunction === undefined)
  var multiFunction = [];

// define data structure once
if (PanelStatus === undefined) {

  // object definition
  function PanelStatus (formid) {
    this.formid = formid; 
    this.sels = [];
    this.getMask = function() {
        return this.mask;
    };
    this.setComp = function(id, index) {
      var comp = PanelStatus.prototype.complete;

//alert (id + '-' + comp + '|' + index + ' cond:' + (id > 0) + ' OR:' + (index | comp));

//      if (index == 1)
//        PanelStatus.prototype.complete = this.state ;
      
      if (id > 0) 
        PanelStatus.prototype.complete = index | comp;
      else
        PanelStatus.prototype.complete = ~index & comp;

//alert (id + '-' + PanelStatus.prototype.complete + '-'+ index);
    };
  }
  PanelStatus.prototype.complete = 000;
}  
 
// instantiate object for this form 
var form$this->scope = new PanelStatus('$this->iterator');
form$this->scope.form = '$this->iterator';
form$this->scope.index = '$this->indexMask';
form$this->scope.unIndex = 0;
form$this->scope.unValue = 0;
form$this->scope.reIndex = 0;
form$this->scope.reValue = 0;
form$this->scope.readyMask = parseInt('$this->readyMask');
form$this->scope.sels[0] = 0;

var str = '$this->summaryId';
var summaryId$this->scope = (isNaN (str)) ? str : parseInt (str);
var fkeyId$this->scope = 0;
var formDefs$this->scope = [];
formDefs$this->scope[0]  = JSON.parse('$this->formDef0');
formDefs$this->scope[1]  = JSON.parse('$this->formDef1');
var currDef$this->scope  = 0;

var formData$this->scope = JSON.parse('$this->formData');
var filterId$this->scope = $this->filterId;
var selectId$this->scope = $this->selectId;
hideCommit$this->scope = $this->hideCommit;
//hideCommit$this->scope = 0;

//document.getElementById('fdh$this->iterator').style.display = '$this->display';

for (var i=0; i<formData$this->scope.length; i++) {
  if (formData$this->scope[i].action == 'sendid') {
//alert (formData$this->scope[i].field + '|' + formData$this->scope[i].sequent + '|' + formData$this->scope[i].sequent_frm + '|' + formData$this->scope[i].sequent_upd + '|' + formData$this->scope[i].sequent_ent);
    formData$this->scope[i].sequent = toObject$this->scope (formData$this->scope[i].sequent); 
    formData$this->scope[i].sequent_frm = toObject$this->scope (formData$this->scope[i].sequent_frm); 
    formData$this->scope[i].sequent_upd = toObject$this->scope (formData$this->scope[i].sequent_upd); 
    formData$this->scope[i].sequent_ent = toObject$this->scope (formData$this->scope[i].sequent_ent); 
    formData$this->scope[i].sequent_chk = toObject$this->scope (formData$this->scope[i].sequent_chk); 
//alert ('sequent:' + formData$this->scope[i].sequent.length);    
  }
}

$(document).ready(function() {
  if (form$this->scope.index > 1) {
    row$this->scope (selectId$this->scope, '---', 'sequent_upd'); //CC
  }
});

function toObject$this->scope (str) {
  var obj = {};
  if (str.length > 0) {
    var ele = str.split(',');
    for (var j=0;j<ele.length;j++) {
      var propval =  ele[j].split(':');
      var prop = propval[0];
      var val = propval[1];
      obj[prop] = val;
    }
  }    
  return obj;
}

function processForm$this->scope () {
//  document.getElementById('valmsg$this->scope').innerHTML = '';
  var valid$this->scope = [];
  valid$this->scope.fields = '';
  valid$this->scope.message = '';
  valid$this->scope.mandatoryCheck = false;
  valid$this->scope.uniqueCheck = false;
  valid$this->scope.confirmCheck = false;
  
  var ampersand = '';
  var dash = '';
  
  for (var i=0; i < formData$this->scope.length; i++) {

//alert (formData$this->scope[i]['field'] + ' m:' + formData$this->scope[i]['mandatory']
//       + ' t:' + formData$this->scope[i]['uniquekey'] +  ' c:' + formData$this->scope[i]['confirm'] 
//       + ' db:' + formData$this->scope[i]['dbvalue'] + ' new:' + formData$this->scope[i]['newvalue']);
    
    if (formData$this->scope[i]['dbcolumn'] == 'fkid' || 
        formData$this->scope[i]['dbcolumn'] == 'id') {
      valid$this->scope.fields += ampersand + formData$this->scope[i]['dbcolumn'] +
                '=' + formData$this->scope[i]['newvalue'];
      ampersand = '&';            
    }

    if (formData$this->scope[i]['mandatory'] == 1 && 
        formData$this->scope[i]['newvalue'] == 0) {
      valid$this->scope.message += dash + 'Missing ' + formData$this->scope[i]['label'];
      dash = '&#8212';
      valid$this->scope.mandatoryCheck = true;
    }

    if (formData$this->scope[i]['uniquekey'] == 1) {
 
      valid$this->scope.fields += ampersand + formData$this->scope[i]['dbcolumn'] +
                '=' + formData$this->scope[i]['newvalue'];
      ampersand = '&';            

      if (formData$this->scope[i]['dbvalue'] != formData$this->scope[i]['newvalue'])
        valid$this->scope.uniqueCheck = true;
    }
    if (formData$this->scope[i]['confirm'] == 1 && 
        formData$this->scope[i]['dbvalue'] != 0 && 
        formData$this->scope[i]['dbvalue'] != 
        formData$this->scope[i]['newvalue']) {
      document.getElementById('cnfmsg$this->confirmModal').innerHTML = 
        formData$this->scope[i]['label'] + ': ' + formData$this->scope[i]['dbvalue'] + ' to ' + formData$this->scope[i]['newvalue'];   
      valid$this->scope.confirmCheck = true;
    }
  }
  
  submit$this->scope (valid$this->scope);
}

function submit$this->scope (valid) {
//alert (valid.confirmCheck);

  if (!(valid.mandatoryCheck || valid.uniqueCheck || valid.confirmCheck))
    put$this->scope ();

  else if (valid.mandatoryCheck)
    document.getElementById('valmsg$this->scope').innerHTML = valid.message;

  else if (valid.uniqueCheck && valid.message == '')
    key$this->scope (valid);

  else if (valid.uniqueCheck)
    document.getElementById('valmsg$this->scope').innerHTML = valid.message;

  else if (valid.confirmCheck)
    $('#modal$this->confirmModal').modal('show'); 
}

function confirm$this->iterator (okay) {
  if (okay)    
    put$this->scope ();
}

function isEmpty(obj) {
  for(var key in obj) {
    if (obj.hasOwnProperty(key))
      return false;
  }
  return true;
}

function com$this->scope (message) {
  var key = Object.keys(message);
logMessage ('<td>com msg</td><td>' + key +  '</td><td>$this->scope</td><td>' + message[key][0] + '</td><td>' + message[key][1] + '</td><td>' + message[key][2] + '</td><td>' + message[key][3] + '</td><td>' + message[key][4] + '</td>'); 
//alert ('com$this->scope:' + key + ' ' + message[key][0] + ' ' + message[key][1] + ' ' + message[key][2] + ' ' + message[key][3]);
  if (key == 'fkeyId') {
    if (fkeyId$this->scope != message[key][0]) {
      fkeyId$this->scope = message[key][0];
      formDefs$this->scope[0].fkid = fkeyId$this->scope;
      formDefs$this->scope[1].fkid = fkeyId$this->scope;
    }
  }
  
  else if (key == 'fkeyDate') {
      formDefs$this->scope[0].date = message[key][0];
      formDefs$this->scope[1].date = message[key][0];
  }

  else if (key == 'summaryId') {
//alert ('com$this->scope:' + key + ' ' + message[key][0] + ' ' + message[key][1] + ' ' + message[key][2] + ' ' + message[key][3]);
    summaryId$this->scope = message[key][0];
//    if (summaryId$this->scope == 0) 
//      $('.fdh$this->iterator').hide();      

    formDefs$this->scope[currDef$this->scope].fkid = summaryId$this->scope;
    selectId$this->scope = 0;
    row$this->scope (0, message[key][3], 'sequent_upd');   //CC
//    row$this->scope (0, message[key][3], 'sequent_frm');   //CI
  }

  else if (key == 'selectId') {
    row$this->scope (message[key][0], message[key][3], 'sequent_frm'); //CC 
//    row$this->scope (message[key][0], message[key][3], 'sequent_upd'); //CI 
  }    

  else if (key == 'displayInd') {
//alert ('displayInd fdh$this->iterator:' + form$this->scope.index);    

    if (form$this->scope.index == 1 && message[key][0] == 0 && message[key][2] == 'sequent_frm') { 
      var firstOf = true;
      $('.fdh$this->iterator').each(function() {
        if (firstOf) {
          $(this).show();      
          $(this).prop('disabled', false);
          firstOf = false;
        }    
        else {
          $(this).hide();      
          $(this).prop('disabled', true);
        }
      });
    }
    
    // Entry
    else if (form$this->scope.index == 1 && message[key][0] == 0 && message[key][2] == 'sequent_upd') {    
      $('.fdh$this->iterator').each(function() {
        $(this).hide();      
        $(this).prop('disabled', true);
      });
    }

    else if (form$this->scope.index == 1 && message[key][0] > 0 && message[key][2] == 'sequent_upd') {    
      var firstOf = true;
      $($('.fdh$this->iterator').get().reverse()).each(function() {
        if (firstOf) {
          $(this).show();      
          $(this).prop('disabled', false);
          firstOf = false;
        }    
        else {
          $(this).hide();      
          $(this).prop('disabled', true);
        }    
      });
    }

    else if (message[key][0] === 0 && message[key][2] == 'sequent_upd') {
      if (selectId$this->scope > 0)
        $('.fdh$this->iterator').show();      
    }

    else if (message[key][0] === 0 && message[key][2] == 'sequent_frm') {
//alert ('hide fdh$this->iterator');    
      $('.fdh$this->iterator').hide();      
    }

    else if (message[key][0] === 1 && message[key][2] == 'sequent_frm') {
    
      $('.fdh$this->iterator').show();      
    }

    else if (message[key][0] > 0 && message[key][2] == 'sequent_upd') {    
      $('.fdh$this->iterator').hide();      
    } 

    else if (message[key][0] !== '' && message[key][2] == 'sequent_upd') { 
//    else if (message[key][0] !== '') { 
      $('.fdh$this->iterator').show();      
    } 

    else if (message[key][0] === '' && message[key][2] == 'sequent_upd') { 
//    else if (message[key][0] === '') { 
      $('.fdh$this->iterator').hide();      
    } 

    else if (message[key][0] !== '' && message[key][2] == 'sequent_frm') { 
//    else if (message[key][0] !== '') { 
      $('.fdh$this->iterator').hide();      
    } 

    else if (message[key][0] === '' && message[key][2] == 'sequent_frm') { 
//    else if (message[key][0] === '') { 
      $('.fdh$this->iterator').show();      
    } 

  }

}

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

function set$this->iterator (value, text) {
  selectId$this->scope = value;
}

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

function newValue$this->scope (message) {
  document.getElementById('valmsg$this->scope').innerHTML = '';
  var key = Object.keys(message);
logMessage ('<td>newValue</td><td>' + key +  '</td><td>$this->scope</td><td>' + message[key][0] + '</td><td>' + message[key][1] + '</td><td>' + message[key][2] + '</td><td>' + message[key][3] + '</td><td>' + message[key][4] + '</td>');  
  
  var index = message[key][3];
  var source = '';
  if (message[key][2] == 'formentry')
    source = 'sequent_frm';
  else
    source = message[key][2];
//alert ('newValue key: ' + key +  ' value:' + message[key][0] + ' text:' + message[key][3] + ' index:'  + index + ' source:' + source + ' crtl idx:' + form$this->scope.index);    

  for (i=0; i < formData$this->scope.length; i++) {

//alert ('fd:' + formData$this->scope[i]['field'] + '==' + key);
 
    if (formData$this->scope[i]['field'] == key) {

      if (formData$this->scope[i]['dbcolumn'] == 'id') {
        selectId$this->scope = message[key][0];
        row$this->scope (selectId$this->scope, '---', source);
      }

      else {
        formData$this->scope[i]['newvalue'] = message[key][0];
        formData$this->scope[i]['newtext'] = message[key][1];

        var formControl = modForm$this->scope (formData$this->scope[i], source);

//alert ('index:' + form$this->scope.index);

        if (formControl.action == 'sendid') {
//alert ('field:' + formData$this->scope[i]['field']);             
          prcAction$this->scope (formControl, message[key][0], message[key][1], message[key][3], source);
        }

        else if (formControl.action == 'switch') 
          switchForm$this->scope (formControl.sequent, message[key][0], message[key][1]);

        if (formControl.commit == 1)
          processForm$this->scope();
      }
    }
  }    
}

// Populate detail form
function setForm$this->scope (selectId, dbResult, source) {
//alert ('$this->scope setForm selectId:' + selectId);
  var setType;
  for (var i=0; i<formData$this->scope.length; i++) {
    var column = formData$this->scope[i]['dbcolumn']; 

//alert ('setform col:' + formData$this->scope[i]['field'] + ' ' + column + '#' + dbResult[column] + '#' + selectId + formData$this->scope[i]['sequent'].length);

    if (selectId == 0) {
      setType = 'default';
      formData$this->scope[i]['dbvalue'] = 0;
      formData$this->scope[i]['dbtext'] = '';
    }
    else {
      setType = 'database';
      formData$this->scope[i]['dbvalue'] = dbResult[column];
      formData$this->scope[i]['dbtext'] = dbResult[column+'_text'];
    }
    formData$this->scope[i]['newvalue'] = dbResult[column];
    formData$this->scope[i]['newtext'] = dbResult[column+'_text'];
    
    var field = formData$this->scope[i]['field'];
    var setField = 'set' + field; 
    var setFunction = setField + '';

//alert (setField + ' ' + dbResult[column] + ':' + dbResult[column+'_text'] + ':');
    multiFunction[setField][setFunction] (dbResult[column],dbResult[column+'_text']);

    var formControl = modForm$this->scope (formData$this->scope[i], source);
//alert (field + ':' + formControl.action);    
    if (formControl.action == 'sendid') {
//alert ('field:' + formControl.field + ' ' +  formData$this->scope.length);    
//alert (formControl + ':' + dbResult[column] + ':' + dbResult[column+'_text'] + ':' + form$this->scope.index + ':' + source);
      prcAction$this->scope (formControl, dbResult[column], dbResult[column+'_text'], form$this->scope.index, source);
//alert ('finish:' + formControl.field + ' ' +  formData$this->scope.length);    
    }
  }
}

function modForm$this->scope (control, source) {
  return control;
}

function prcAction$this->scope (control, value, text, index, source) {
//alert ('prc:$this->scope ' + control.action + ' val:' + value + ' index:' + index + ' source:' + source);
  sendCom$this->scope (control.sequent, value, text, index, source);
  var seq = control[source];
//alert ('seq:' + control.sequent + ' ' + control.frm_sequent + ' ' + control.upd_sequent + ' ' + control.end_sequent);  
  sendCom$this->scope (seq, value, text, index, source);
}
 
function sendCom$this->scope (sequents, value, text, index, source) {
  var keys = Object.keys(sequents);
    for (var i=0; i<keys.length; i++) {
      var key = keys[i];
      var idx = sequents[key]
//alert ('$this->scope i:' + i + ' key:' + key + ' idx:' + idx +  ' keyr:' + key.replace(/\d+$/, ''));      
      var comField = 'com' + key.replace(/\d+$/, ''); 
      var comFunction = comField + '';
//alert ('idx:' + idx + 'index:' + index + ' ' + value + '-' + comField);
      var msgContent = [];
//alert (value + ':' + text + ':' + comField + ':' + index + ':' + '$this->scope');
      
      msgContent[idx] = [value, text, source, index, 'send com'];
      multiFunction[comField][comFunction] (msgContent);
  }
}

function switchForm$this->scope (sequent, value, text) {
  var keys = Object.keys(sequent);

  if (currDef$this->scope != value) {
     currDef$this->scope = value;
     row$this->scope (0, '---', 'sequent_frm');
  }     
}

function frmCommit$this->scope (sequent, value, text) {
  var keys = Object.keys(sequent);
//  if (value > 0)
}
// Populate detail form
function setData$this->scope () {
  var reqData = 'summaryid=' + summaryId$this->scope + '&' + 'filterid=' + filterId$this->scope;
  for (var i=0; i < formData$this->scope.length; i++) {
    reqData += '&' + formData$this->scope[i]['dbcolumn'] + '=' + formData$this->scope[i]['newvalue'] +
               '&' + formData$this->scope[i]['dbcolumn'] + '_text=' + formData$this->scope[i]['newtext'];
  }
  return reqData;
}

// ROW form db data for selected summary row
function row$this->scope (selectId, index, source) {
logMessage ('<td>get row</td><td>recordId</td><td>$this->scope</td><td>' + selectId + '</td><td></td><td>' + source + '</td><td>' + index + '</td><td>set db/def values</td>');  
//alert ('form:$this->iterator row$this->scope' + ' index:' + index + ' selid:' + selectId + ' hide:' + hideCommit$this->scope);
//alert (form$this->scope.readyMask + '-' + form$this->scope.complete + '-' + selectId);
//alert ('$this->display');
//alert('row$this->scope sumid:' + formDefs$this->scope[currDef$this->scope].sumid + ' ' + selectId);
//alert ('ROW form:$this->iterator ' + selectId + ' ' + source )
  if (selectId == 0) { 
//alert ('$this->scope fkid:' + formDefs$this->scope[currDef$this->scope].fkid);  
    $('#del$this->iterator').prop('disabled', true);
    $('.fdh$this->iterator').html($('#fdh$this->iterator').prop('value').split('_')[0]);
//    $('.fdh$this->iterator').prop('disabled', $this->disableCommit);
    $('.tog$this->iterator').prop('disabled', true);
//alert ('$this->scope ' + '$this->childSlider');
    if ('$this->childSlider' != 'panel0')
      $('[class^=$this->childSlider]').each(function(){ $(this).slideUp('slow'); });

    setForm$this->scope(selectId, formDefs$this->scope[currDef$this->scope], source);
  }
  else {
    $('#del$this->iterator').prop('disabled', false);
    $('.fdh$this->iterator').html($('#fdh$this->iterator').prop('value').split('_')[1]);
//    $('.fdh$this->iterator').prop('disabled', false);
    $('.tog$this->iterator').prop('disabled', false);

    var xhr = new XMLHttpRequest();
    var params = 'selectid=' + selectId + '&';
    
    if (1) 
      params += 'fkeyid=' + form$this->scope.unValue + '&' + 'index=' + form$this->scope.unIndex;
    else
      params += 'fkeyid=' + form$this->scope.reValue + '&' + 'index=' + form$this->scope.reIndex;

    xhr.open('POST', 'ajax/row$this->scope.php', true);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xhr.onreadystatechange = function() {//Call a function when the state changes.
      if (xhr.readyState == 4 && xhr.status == 200) {
        var response = JSON.parse(xhr.responseText);
        setForm$this->scope(selectId, response, source);
      }
    }
    xhr.send(params);
  }
}

// check for existing parent mapping
function map$this->scope () {
  var xhr = new XMLHttpRequest();
  var params = '';
  var ampersand = '';
  var fkidUnset = false;

  for (var i=0; i < formData$this->scope.length; i++) {
//alert (formData$this->scope[i]['field'] + '=' + formData$this->scope[i]['newvalue']);  
    if (formData$this->scope[i]['field'].substr(0,3) == 'fky') {
      params += ampersand + formData$this->scope[i]['dbcolumn'] + '=' + formData$this->scope[i]['newvalue'] +
               '&' + formData$this->scope[i]['dbcolumn'] + '_text=' + formData$this->scope[i]['newtext'];
      ampersand = '&';
      if (formData$this->scope[i]['newvalue'] == 0)
        fkidUnset = true;
//alert (params);        
    }    
  }

  if (fkidUnset) 
    formDefs$this->scope[currDef$this->scope].fkid = 0;
    
  else { 
    xhr.open('POST', 'ajax/map$this->scope.php', true);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xhr.onreadystatechange = function() {//Call a function when the state changes.
      if (xhr.readyState == 4 && xhr.status == 200) {
        var response = JSON.parse(xhr.responseText);
        formDefs$this->scope[currDef$this->scope].fkid = response;
        var source = (response == 0) ? 'sequent_frm' : 'sequent_upd'; 
        row$this->scope (0, '---', source);
      }
    }
    xhr.send(params);
  }    
}

// Ajax get form db data for selected summary row
function key$this->scope (valid) {
  var xhr = new XMLHttpRequest();
  xhr.open('POST', 'ajax/key$this->scope.php', true);
  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xhr.onreadystatechange = function() {//Call a function when the state changes.
    if (xhr.readyState == 4 && xhr.status == 200) {
      var response = JSON.parse(xhr.responseText);
      valid.uniqueCheck = response[0];
      valid.message = response[1];
//alert (response[0]);      
      submit$this->scope (valid);
    }
  }
  xhr.send(valid.fields);
}

function put$this->scope() {
  var params = setData$this->scope ();
  var xhr = new XMLHttpRequest();
  xhr.open('POST', 'ajax/put$this->scope.php', true);
  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xhr.onreadystatechange = function() {//Call a function when the state changes.
    if (xhr.readyState == 4 && xhr.status == 200) {
      var response = JSON.parse(xhr.responseText);
      row$this->scope (response, '---', 'sequent_upd')
    }  
  }
  xhr.send(params);
}

function del$this->iterator() {

  var params = setData$this->scope ();
  var xhr = new XMLHttpRequest();
  xhr.open('POST', 'ajax/del$this->iterator.php', true);
  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xhr.onreadystatechange = function() {//Call a function when the state changes.

    if (xhr.readyState == 4 && xhr.status == 200) {
      var response = JSON.parse(xhr.responseText);
//      formDefs$this->scope[currDef$this->scope].fkid = response;
      $('#del$this->iterator').prop('disabled', true);
      row$this->scope (0, '---', 'sequent_upd')
    }
  }  
  xhr.send(params);
}


    ";
    return $script;
  }
}

?>
