// *************************************************************************************
    // *************************************************************************************
    // Data for for See Authorizations
    // *************************************************************************************
    case "seeAuthorizations":
        echo '{"totals": "3", "row": [ { "id": "1", name: "None"}, { id: "2", "name": "Only Mine"}, { "id": "3", "name": "All"}]}';
        break;
        // *************************************************************************************
        // Data for for AccessControl
        // *************************************************************************************
    // *************************************************************************************
    // Data for for AccessControl
    // *************************************************************************************
    case "accessControls":
        $sql = "SELECT id, role_name FROM acl_roles ORDER BY role_name";
        $mitos_db->setSQL($sql);
        foreach ($mitos_db->execStatement(PDO::FETCH_ASSOC) as $urow) {
            $count++;
            $buff .= '{';
            $buff .= ' "id": "' . dataEncode($urow['id']) . '",';
            $buff .= ' "role_name": "' . dataEncode($urow['role_name']) . '"},' . chr(13);
        }
        $buff = substr($buff, 0, -2);
        // Delete the last comma.
        echo '{';
        echo '"totals": "' . $count . '", ' . chr(13);
        echo '"row": [' . chr(13);
        echo $buff;
        echo ']}' . chr(13);
        break;
}
//------------------------------------------
// Database class instance
//------------------------------------------
$mitos_db = new dbHelper();
// *************************************************************************************
// Validate and pass the POST variables to an array
// This is the moment to validate the entered values from the user
// although Sencha EXTJS make good validation, we could check again
// just in case
// *************************************************************************************
$row['list_id'] = dataEncode($data->list_id);
$row['option_id'] = dataEncode($data->option_id);
$row['title'] = dataEncode($data->title);
$row['seq'] = dataEncode($data->seq);
$row['is_default'] = trim($data->is_default) == 'true' ? 1 : 0;
$row['option_value'] = dataEncode($data->option_value);
$row['mapping'] = dataEncode($data->mapping);
$row['notes'] = dataEncode($data->notes);
// *************************************************************************************
// Finally that validated POST variables is inserted to the database
// This one make the JOB of two, if it has an ID key run the UPDATE statement
// if not run the INSERT stament
// *************************************************************************************
$sql = $mitos_db->sqlBind($row, "list_options", "u", "id='" . $data->id . "'");
$mitos_db->setSQL($sql);
$ret = $mitos_db->execLog();
if ($ret == "") {
    echo '{ success: false, errors: { reason: "' . $ret[2] . '" }}';
} else {
    echo "{ success: true }";
}
$row['state'] = dataEncode($data['state']);
$row['zip'] = dataEncode($data['zip']);
// secondary address
$row['street2'] = dataEncode($data['street2']);
$row['streetb2'] = dataEncode($data['streetb2']);
$row['city2'] = dataEncode($data['city2']);
$row['state2'] = dataEncode($data['state2']);
$row['zip2'] = dataEncode($data['zip2']);
// phones
$row['phone'] = dataEncode($data['phone']);
$row['phonew1'] = dataEncode($data['phonew1']);
$row['phonew2'] = dataEncode($data['phonew2']);
$row['phonecell'] = dataEncode($data['phonecell']);
$row['fax'] = dataEncode($data['fax']);
//additional info
$row['email'] = dataEncode($data['email']);
$row['assistant'] = dataEncode($data['assistant']);
$row['url'] = dataEncode($data['url']);
$row['upin'] = dataEncode($data['upin']);
$row['npi'] = dataEncode($data['npi']);
$row['federaltaxid'] = dataEncode($data['federaltaxid']);
$row['taxonomy'] = dataEncode($data['taxonomy']);
$row['notes'] = dataEncode($data['notes']);
// *************************************************************************************
// Finally that validated POST variables is inserted to the database
// This one make the JOB of two, if it has an ID key run the UPDATE statement
// if not run the INSERT stament
// *************************************************************************************
$mitos_db->setSQL("INSERT INTO users \n     \t\t\t      SET username          = '******', " . "\n\t\t\t\t          password          = '******', " . "\n\t\t\t\t          abook_type        = '" . $row['abook_type'] . "', " . "\n\t\t\t\t          title             = '" . $row['title'] . "', " . "\n\t\t\t\t          fname             = '" . $row['fname'] . "', " . "\n\t\t\t\t          mname             = '" . $row['mname'] . "', " . "\n\t\t\t\t          lname             = '" . $row['lname'] . "', " . "\n\t\t\t\t          specialty         = '" . $row['specialty'] . "', " . "\n\t\t\t\t          organization      = '" . $row['organization'] . "', " . "\n\t\t\t\t          valedictory       = '" . $row['valedictory'] . "', " . "\n\t\t\t\t          street            = '" . $row['street'] . "', " . "\n\t\t\t\t          streetb           = '" . $row['streetb'] . "', " . "\n\t\t\t\t          city              = '" . $row['city'] . "', " . "\n\t\t\t\t          state             = '" . $row['state'] . "', " . "\n\t\t\t\t          zip               = '" . $row['zip'] . "', " . "\n\t\t\t\t          street2           = '" . $row['street2'] . "', " . "\n\t\t\t\t          streetb2          = '" . $row['streetb2'] . "', " . "\n\t\t\t\t          city2             = '" . $row['city2'] . "', " . "\n\t\t\t\t          state2            = '" . $row['state2'] . "', " . "\n\t\t\t\t          zip2              = '" . $row['zip2'] . "', " . "\n\t\t\t\t          phone             = '" . $row['phone'] . "', " . "\n\t\t\t\t          phonew1           = '" . $row['phonew1'] . "', " . "\n\t\t\t\t          phonew2           = '" . $row['phonew2'] . "', " . "\n\t\t\t\t          phonecell         = '" . $row['phonecell'] . "', " . "\n\t\t\t\t          fax               = '" . $row['fax'] . "', " . "\n\t\t\t\t          email             = '" . $row['email'] . "', " . "\n\t\t\t\t          assistant         = '" . $row['assistant'] . "', " . "\n\t\t\t\t          url               = '" . $row['url'] . "', " . "\n\t\t\t\t          upin              = '" . $row['upin'] . "', " . "\n\t\t\t\t          npi               = '" . $row['npi'] . "', " . "\n\t\t\t\t          federaltaxid      = '" . $row['federaltaxid'] . "', " . "\n\t\t\t\t          taxonomy          = '" . $row['taxonomy'] . "', " . "\n\t\t\t\t          notes             = '" . $row['notes'] . "'");
$mitos_db->execLog();
echo "{ success: true }";
        $buff = substr($buff, 0, -2);
        // Delete the last comma.
        echo '{';
        echo '"totals": "' . $count . '", ' . chr(13);
        echo '"row": [' . chr(13);
        echo $buff;
        echo ']}' . chr(13);
        break;
        // *************************************************************************************
        // Data for for storeTypes
        // *************************************************************************************
    // *************************************************************************************
    // Data for for storeTypes
    // *************************************************************************************
    case "types":
        $mitos_db->setSQL("SELECT option_id, title \n\t\t        \t\t\t FROM list_options\n\t\t        \t\t\tWHERE list_id = 'abook_type'");
        foreach ($mitos_db->execStatement(PDO::FETCH_ASSOC) as $urow) {
            $count++;
            $buff .= "{";
            $buff .= " option_id: '" . dataEncode($urow['option_id']) . "',";
            $buff .= " title: '" . dataEncode($urow['title']) . "'}," . chr(13);
        }
        $buff = substr($buff, 0, -2);
        // Delete the last comma.
        echo '{';
        echo '"totals": "' . $count . '", ' . chr(13);
        echo '"row": [' . chr(13);
        echo $buff;
        echo ']}' . chr(13);
        break;
}
            $count++;
            $buff .= '{';
            $buff .= ' "ct_id": ' . $urow['ct_id'] . ',';
            $buff .= ' "ct_key": "' . dataEncode($urow['ct_key']) . '"},' . chr(13);
        }
        $buff = substr($buff, 0, -2);
        // Delete the last comma.
        echo '{';
        echo '"totals": "' . $count . '", ' . chr(13);
        echo '"row": [' . chr(13);
        echo $buff;
        echo ']}' . chr(13);
        break;
    case "calcategories":
        $sql = "SELECT * FROM calendar_categories ORDER BY cattype, catname";
        $mitos_db->setSQL($sql);
        foreach ($mitos_db->execStatement(PDO::FETCH_ASSOC) as $urow) {
            $count++;
            $buff .= '{';
            $buff .= ' "catid": "' . dataEncode($urow['catid']) . '",';
            $buff .= ' "catname": "' . dataEncode($urow['catname']) . '"},' . chr(13);
        }
        $buff = substr($buff, 0, -2);
        // Delete the last comma.
        echo '{';
        echo '"totals": "' . $count . '", ' . chr(13);
        echo '"row": [' . chr(13);
        echo $buff;
        echo ']}' . chr(13);
        break;
}
        $rec['pos_code'] = '0' . $urow['pos_code'];
    } else {
        $rec['pos_code'] = $urow['pos_code'];
    }
    $buff .= "{";
    $buff .= " id: '" . dataEncode($urow['id']) . "',";
    $buff .= " name: '" . dataEncode($urow['name']) . "',";
    $buff .= " phone: '" . dataEncode($urow['phone']) . "',";
    $buff .= " fax: '" . dataEncode($urow['fax']) . "',";
    $buff .= " street: '" . dataEncode($urow['street']) . "',";
    $buff .= " city: '" . dataEncode($urow['city']) . "',";
    $buff .= " state: '" . dataEncode($urow['state']) . "',";
    $buff .= " postal_code: '" . dataEncode($urow['postal_code']) . "',";
    $buff .= " federal_ein: '" . dataEncode($urow['federal_ein']) . "',";
    $buff .= " service_location: '" . dataEncode($rec['service_location']) . "',";
    $buff .= " billing_location: '" . dataEncode($rec['billing_location']) . "',";
    $buff .= " accepts_assignment: '" . dataEncode($rec['accepts_assignment']) . "',";
    $buff .= " pos_code: '" . dataEncode($rec['pos_code']) . "',";
    $buff .= " attn: '" . dataEncode($urow['attn']) . "',";
    $buff .= " domain_identifier: '" . dataEncode($urow['domain_identifier']) . "',";
    $buff .= " facility_npi: '" . dataEncode($urow['facility_npi']) . "',";
    $buff .= " tax_id_type: '" . dataEncode($urow['tax_id_type']) . "',";
    $buff .= " country_code: '" . dataEncode($urow['country_code']) . "'}," . chr(13);
}
$buff = substr($buff, 0, -2);
// Delete the last comma.
echo $_GET['callback'] . '({';
echo "totals: " . $total . ", " . chr(13);
echo "row: [" . chr(13);
echo $buff;
echo "]})" . chr(13);
// *************************************************************************************
$row['name'] = dataEncode($data[0]->name);
$row['phone'] = dataEncode($data[0]->phone);
$row['fax'] = dataEncode($data[0]->fax);
$row['street'] = dataEncode($data[0]->street);
$row['city'] = dataEncode($data[0]->city);
$row['state'] = dataEncode($data[0]->state);
$row['postal_code'] = dataEncode($data[0]->postal_code);
$row['country_code'] = dataEncode($data[0]->country_code);
$row['federal_ein'] = dataEncode($data[0]->federal_ein);
$row['service_location'] = isset($data[0]->service_location) ? 1 : 0;
$row['accepts_assignment'] = isset($data[0]->accepts_assignment) ? 1 : 0;
$row['billing_location'] = isset($data[0]->billing_location) ? 1 : 0;
$row['pos_code'] = dataEncode($data[0]->pos_code);
$row['domain_identifier'] = dataEncode($data[0]->domain_identifier);
$row['attn'] = dataEncode($data[0]->attn);
$row['tax_id_type'] = dataEncode($data[0]->tax_id_type);
$row['facility_npi'] = dataEncode($data[0]->facility_npi);
// *************************************************************************************
// Finally that validated POST variables is inserted to the database
// This one make the JOB of two, if it has an ID key run the UPDATE statement
// if not run the INSERT stament
// *************************************************************************************
$sql = "INSERT INTO \n\t\t\t\tfacility \n\t\t\tSET\n\t\t\t\tname \t\t\t\t= " . $row['name'] . ", " . "\n\t\t\t\tphone \t\t\t\t= " . $row['phone'] . ", " . "\n\t\t\t\tfax \t\t\t\t= " . $row['fax'] . ", " . "\n\t\t\t\tstreet \t\t\t\t= " . $row['street'] . ", " . "\n\t\t\t\tcity \t\t\t\t= " . $row['city'] . ", " . "\n\t\t\t\tstate \t\t\t\t= " . $row['state'] . ", " . "\n\t\t\t\tpostal_code \t\t= " . $row['postal_code'] . ", " . "\n\t\t\t\tcountry_code \t\t= " . $row['country_code'] . ", " . "\n\t\t\t\tfederal_ein \t\t= " . $row['federal_ein'] . ", " . "\n\t\t\t\tservice_location \t= " . $row['service_location'] . ", " . " \n\t\t\t\tbilling_location \t= " . $row['billing_location'] . ", " . "\n\t\t\t\taccepts_assignment \t= " . $row['accepts_assignment'] . ", " . "\n\t\t\t\tpos_code \t\t\t= " . $row['pos_code'] . ", " . "\n\t\t\t\tdomain_identifier \t= " . $row['domain_identifier'] . ", " . "\n\t\t\t\tattn \t\t\t\t= " . $row['attn'] . ", " . " \n\t\t\t\ttax_id_type \t\t= " . $row['tax_id_type'] . ", " . "\n\t\t\t\tfacility_npi \t\t= " . $row['facility_npi'];
$mitos_db->setSQL($sql);
$ret = $mitos_db->execOnly();
if ($ret == "") {
    echo '{ success: false, errors: { reason: "' . $ret[2] . '" }}';
} else {
    echo "{ success: true }";
}