<?php //client_addressbook_data.php
if(file_exists('../../../'.$_REQUEST['tenant'].'/config.php')){require_once('../../../'.$_REQUEST['tenant'].'/config.php'); }
if(file_exists('/config.php')){require_once('/config.php'); }
$stmt = $GLOBALS['con']->prepare("SELECT * FROM `address_book` WHERE `clientnumber`=? ORDER BY ABS(indexer) DESC")or die(mysqli_error($GLOBALS['con']));
$stmt->bind_param('i',$_REQUEST['clientnumber']);$stmt->execute();$cr=$stmt->get_result();$stmt->close();
$count=mysqli_num_rows($cr);

$c=1;
while($cd=mysqli_fetch_array($cr)){
if($cd['auto']=="1"){$auto="checked";}
else{$auto="";}

$select = '<select class="form-select form-select-sm" onchange="updateAssignment(this, '.$cd['id'].')">';
$select .= '<option value="all"'.($cd['assignment_type'] == 'all' ? ' selected' : '').'>All</option>';
$select .= '<option value="billing"'.($cd['assignment_type'] == 'billing' ? ' selected' : '').'>Billing</option>';
$select .= '<option value="renewal"'.($cd['assignment_type'] == 'renewal' ? ' selected' : '').'>Renewal</option>';
$select .= '<option value="delivery"'.($cd['assignment_type'] == 'delivery' ? ' selected' : '').'>Delivery</option>';
$select .= '</select>';

$tdata.='<tr id="R'.$cd['id'].'">
<td><input id="FN_'.$cd['id'].'" name="firstName_'.$cd['id'].'" class="form-control" type="text" value="'.$cd['firstName'].'" ></td>
<td><input id="LN_'.$cd['id'].'" name="lastName_'.$cd['id'].'" class="form-control" type="text" value="'.$cd['lastName'].'" ></td>
<td><input id="P_'.$cd['id'].'" name="phone1_'.$cd['id'].'" type="text" class="form-control" value="'.$cd['phone1'].'" ></td>
<td><input id="M_'.$cd['id'].'" name="phone2_'.$cd['id'].'" type="text" class="form-control" value="'.$cd['phone2'].'" ></td>
<td><input id="E_'.$cd['id'].'" name="email_'.$cd['id'].'" type="text" class="form-control" value="'.$cd['email'].'" ></td>
<input id="R'.$cd['id'].'ID" name="ID_'.$cd['id'].'" type="hidden" class="form-control" value="'.$cd['id'].'" >
<td class="text-center align-middle">
  <input id="V_'.$cd['id'].'" name="auto_'.$cd['id'].'" type="checkbox"
         class="form-check-input m-0 mx-auto d-block"
         onclick="checker(\''.$cd['id'].'\')" '.$auto.'>
</td> ';
        $tdata .= '<td>'.$select.'</td>';
        $tdata .= '
<td>
 <button data-id="'.$cd['id'].'" id="update" class="btn btn-success m-0 px-3 py-2 ml-4 waves-effect"><i class="fad fa-save"></i></button>
<button data-id="'.$cd['id'].'" id="remove" class="btn btn-danger m-0 px-3 py-2 waves-effect"><i class="fad fa-trash"></i></button></td>
</tr>';
}
echo $tdata;
?>