/** "Add new" MENU PAGE */
function pacwtt_settings_new_activities()
{
    // Database Models
    $pacwtt_model_activity = new PACWTT_Model_activity();
    echo '<h1>' . __('New Activity', 'pacwtt-plugin') . '</h1>';
    echo "<div class='wrap'>";
    $name = '';
    $description = '';
    $message = '';
    if (isset($_POST['submit'])) {
        // Form submitted
        // Chech submission origin
        if (check_admin_referer('pacwtt-activity-form')) {
            // Validation of sanitized input
            // Validation rule: no empty activity name.
            $name = sanitize_text_field($_POST['pacwtt-activity-name']);
            $description = sanitize_text_field($_POST['pacwtt-activity-description']);
            if ('' == $name) {
                $message = pacwtt_error_message([__("Field 'name' can't be empty.", 'pacwtt-plugin')]);
            } else {
                $result = $pacwtt_model_activity->insert_item($name, $description);
                if (FALSE === $result) {
                    $message = pacwtt_error_message([__("Database insertion failed.", 'pacwtt-plugin')]);
                } else {
                    // Success
                    $message = pacwtt_updated_message(__('New Activity Added.', 'pacwtt-plugin'));
                    // Reset form
                    $name = '';
                    $description = '';
                }
            }
        } else {
            wp_die(__('Insufficient privileges. Operation aborted.', 'pacwtt-plugin'));
        }
    }
    ?>
	<!--  Message Area -->
	<?php 
    echo $message;
    ?>
	<!--  Activity Form -->
	<form id="pacwtt-activity-form" method="POST" action="<?php 
    echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']);
    ?>
">
		<hr />
		<table class="form-table">
			<tbody>
				<tr valign="top">
					<th scope="row">
						<label for="pacwtt-activity-name">
							<?php 
    _e('Name', 'pacwtt-plugin');
    ?>
:<br />
							<em><?php 
    _e('(HTML tags are not allowed)', 'pacwtt-plugin');
    ?>
</em>
						</label>
					</th>	
					<td>
						<input type='text' id='pacwtt-activity-name' name='pacwtt-activity-name' value='<?php 
    echo $name;
    ?>
' maxlength='32' size='32'>
					</td>
				</tr>
				<tr valign="top">
					<th scope="row">
						<label for="pacwtt-activity-description">
							<?php 
    _e('Description', 'pacwtt-plugin');
    ?>
:<br />
							<em><?php 
    _e('(HTML tags are not allowed)', 'pacwtt-plugin');
    ?>
</em>
						</label>
					</th>
					<td>
						<input type='text' id='pacwtt-activity-description' name='pacwtt-activity-description' value='<?php 
    echo $description;
    ?>
' maxlength='255' size='64'>
					</td>			
				</tr>
			</tbody>
		</table>
		<?php 
    wp_nonce_field('pacwtt-activity-form');
    submit_button('Add', 'primary');
    ?>
	</form>
<?php 
    echo "</div>";
}