$cancelbtn = optional_param('cancelbtn', false, PARAM_ALPHA);
require_login();
if ($cancelbtn) {
    redirect('index.php');
    die;
} else {
    if ($sendbtn) {
        //$messagebody = optional_param('sm_message', false, PARAM_TEXT);
        $messagebody = optional_param('sm_message', false, PARAM_RAW);
        $recipients = optional_param_array('recipient', false, PARAM_INT);
        $url = 'index.php';
        if (!empty($recipients) && !empty($messagebody)) {
            $recipients[] = $USER->id;
            $recipients = array_flip($recipients);
            $recipients = array_keys($recipients);
            $conversation = local_simple_message_conversation::create_conversation($recipients);
            $conversation->send_message($USER->id, $messagebody);
            $url = 'index.php?conversation=' . $conversation->id . '#sm-conversation';
        }
        redirect($url);
        die;
    }
}
$PAGE->set_context($context);
//TODO:
// - set url (when selected a new conversation..)
// - title
// Initialize $PAGE
$PAGE->requires->jquery();
$PAGE->requires->jquery_plugin('ui');
$PAGE->requires->jquery_plugin('ui-css');