function SMC_displayRecords($meetingID)
{
    global $wpdb;
    global $SMC_plugin_table;
    global $SMC_reqguests;
    global $SMC_plugin_name;
    $outputHTML = "";
    $sqlQuery = 'SELECT * FROM ' . $SMC_plugin_table . ' WHERE meetingID="' . $meetingID . '" ;';
    $resultData = $wpdb->get_results($sqlQuery);
    $outputHTML .= '<table>';
    $outputHTML .= '<th>' . __('Name', $SMC_plugin_name) . '</th>';
    $outputHTML .= '<th>' . __('Present', $SMC_plugin_name) . '</th>';
    if ($SMC_reqguests == 'true') {
        $outputHTML .= '<th>' . __('Number', $SMC_plugin_name) . '</th>';
    }
    $outputHTML .= '<th>' . __('Comments', $SMC_plugin_name) . '</th>';
    foreach ($resultData as $row) {
        $outputHTML .= '<tr>';
        $outputHTML .= '<td>' . esc_html($row->userName) . '</td>';
        $outputHTML .= '<td>';
        if ($row->answer == 'checked') {
            $outputHTML .= __('Yes', $SMC_plugin_name);
        } else {
            $outputHTML .= __('No', $SMC_plugin_name);
        }
        $outputHTML .= '</td>';
        if ($SMC_reqguests == 'true') {
            $outputHTML .= '<td>' . $row->nbParticipants . '</td>';
        }
        $outputHTML .= '<td>' . esc_html($row->comments) . '</td>';
        $outputHTML .= '</tr>';
    }
    $outputHTML .= '<tr>';
    $outputHTML .= '<th><b>' . __('Total ', $SMC_plugin_name) . '</b></th>';
    if ($SMC_reqguests == 'true') {
        $outputHTML .= '<td></td>';
        $outputHTML .= '<td><b>' . SMC_countRecords($meetingID, null, false, true) . '</b></td>';
    } else {
        $outputHTML .= '<td><b>' . SMC_countRecords($meetingID, null, true, false) . '/' . SMC_countRecords($meetingID, null, false, false) . '</b></td>';
    }
    $outputHTML .= '<td></td>';
    $outputHTML .= '</tr>';
    $outputHTML .= '</table>';
    $outputHTML .= '<hr>';
    return $outputHTML;
}
function SMC_main($atts, $content = null)
{
    global $meta;
    global $SMC_date;
    global $SMC_location;
    global $SMC_reqguests;
    global $SMC_description;
    global $SMC_displayresults;
    global $SMC_usersonly;
    global $SMC_expireson;
    global $SMC_plugin_name;
    $output = "";
    $output .= '<link rel="stylesheet" type="text/css" href="' . plugin_dir_url(__FILE__) . 'simplemeetingconfirmation.css" />';
    // load custom variables
    SMC_loadShortCodeParameters($atts);
    // check if SMC_Date field was filled, if so, display meeting information
    if ($SMC_date == '') {
        $output .= SMC_display_error_message('dateMissing');
        return $output;
    }
    // check if page was posted back
    if (@$_POST['hidUpdate'] == true) {
        if ($_POST['txtDate'] == $SMC_date) {
            if ($_POST['hidError'] != '') {
                $output .= SMC_display_error_message($_POST['hidError']);
            } else {
                if (SMC_countRecords($_POST['txtDate'], $_POST['txtUser'], false, false) > 0) {
                    if (wp_get_current_user()->display_name != "") {
                        // update existing record if registered user
                        SMC_updateRegisteredUserToMeeting($_POST['txtUser'], $_POST['txtDate'], @$_POST['chkPresent'], @$_POST['txtNbGuests'], $_POST['txtComments']);
                    } else {
                        // do not update if the name already exists for open event entry
                    }
                } else {
                    // new record
                    SMC_addRegisteredUserToMeeting($_POST['txtDate'], $_POST['txtUser'], @$_POST['chkPresent'], @$_POST['txtNbGuests'], $_POST['txtComments']);
                }
            }
        }
    }
    // load data into a record
    $row_data = SMC_loadUserData($SMC_date, @$_POST['txtUser']);
    $output .= '<script src="' . plugin_dir_url(__FILE__) . 'simplemeetingconfirmation.js" type="text/javascript"></script>';
    if ($SMC_displayresults == 'true') {
        $output .= SMC_displayRecords($SMC_date);
    }
    if ($SMC_usersonly == "true" && wp_get_current_user()->display_name == "") {
        $output .= "<p>" . __("If you are logged in you can sign up", $SMC_plugin_name) . ".</p>";
    } else {
        $output .= '<form name="frmSMCRegistration" method="post" action="' . get_permalink() . '">
			<table border="2" width="80%">
				<tbody>';
        if ($SMC_description != '') {
            $output .= '<tr>';
            $output .= '<th>' . __('Event', $SMC_plugin_name) . ':</th>';
            $output .= '<td colspan="' . ($content != null ? 1 : 2) . '">' . $SMC_description . '</td>';
            $output .= '</tr>';
        }
        $output .= '<tr>
			<th>' . __('Date (dd/mm/yyyy)', $SMC_plugin_name) . ':</th>
			<td colspan="' . ($content != null ? 1 : 2) . '">' . $SMC_date . '</td>
			<input type="hidden" name="txtDate" value="' . $SMC_date . '">';
        if ($content != null) {
            $i = 3;
            // for default fields (date,  Present, submit button)
            if ($SMC_description != '') {
                $i++;
            }
            if ($SMC_location != '') {
                $i++;
            }
            if ($SMC_reqguests == 'true') {
                $i++;
            }
            if ($SMC_expireson != '') {
                if (date('d/m/Y') > date($SMC_expireson)) {
                    $i = 4;
                    // already expired, display limited number of fields
                }
            }
            $output .= '<td align="center" rowspan="' . $i . '">' . $content . '</td>';
        }
        $output .= '</tr>';
        if ($SMC_location != '') {
            $output .= '<tr>';
            $output .= '<th>' . __('Location', $SMC_plugin_name) . ':</th>';
            $output .= '<td colspan="' . ($content != null ? 1 : 2) . '">' . $SMC_location . '</td>';
            $output .= '</tr>';
        }
        if ($SMC_expireson == '' || date('d/m/Y') <= date($SMC_expireson)) {
            $output .= '<tr>
					<th>' . __('Name', $SMC_plugin_name) . ':</th>
					<td colspan="' . ($content != null ? 1 : 2) . '">';
            if ($SMC_usersonly == 'true') {
                $output .= wp_get_current_user()->display_name;
                $output .= '<input type="hidden" name="txtUser" value="' . esc_attr(wp_get_current_user()->display_name) . '">';
            } else {
                $public_username = @$_POST['txtUser'];
                if ($public_username == "") {
                    $public_username = wp_get_current_user()->display_name;
                }
                $output .= '<input type="text" name="txtUser" onBlur="this.value=trim(this.value)" value="' . esc_attr($public_username) . '">';
            }
            $output .= '</td>
					</tr>
					<tr>
					<th>' . __('Present', $SMC_plugin_name) . ':</th>
					<td colspan="' . ($content != null ? 1 : 2) . ' align="center"><input type="checkbox" checked="checked" name="chkPresent" ' . @$row_data->answer . '></td>
					</tr>';
            if ($SMC_reqguests == 'true') {
                $output .= '<tr>';
                $output .= '<th>' . __('Number of people', $SMC_plugin_name) . ':</th>';
                $output .= '<td colspan="' . ($content != null ? 1 : 2) . '"><input type="textbox" name="txtNbGuests" value="' . @$row_data->nbParticipants . '"></td>';
                $output .= '</tr>';
            }
            $output .= '<tr>
					<th>' . __('Comments', $SMC_plugin_name) . ':</th>
					<td colspan="2"><textarea name="txtComments" rows="5" cols="20">' . @$row_data->comments . '</textarea></td>
					</tr>
					<tr>';
        }
        if ($SMC_expireson != '') {
            $output .= '<th>' . __('Please reply before', $SMC_plugin_name) . ':</th>';
            $output .= '<td>' . $SMC_expireson . '</td>';
        } else {
            $output .= '<th></th>';
        }
        if ($SMC_expireson == '' || date('d/m/Y') <= date($SMC_expireson)) {
            $output .= '<td colspan="' . ($SMC_expireson != '' ? 1 : 2) . '" align="right"><input type="submit" onClick="checkFields();" name="cmdSubmit" value="' . __('Submit', $SMC_plugin_name) . '" ></td>';
        }
        $output .= '</tr>
				</tbody>
				</table>
				<input name="hidUpdate" type="hidden" value="true">
				<input name="hidError" type="hidden" value="">
				</form>';
    }
    return $output;
}