*/
extract(FormVariables::GetVariables(array('action', 'page', 'sort_column', 'sort_order', 'object_type_id', 'object_id', 'parent_id', 'message_data', 'template', 'close')));
$mf = new MessageFactory();
$action = Misc::findSubmitButton();
switch ($action) {
    case 'submit_message':
        //Debug::setVerbosity(11);
        if (!$permission->Check('message', 'enabled') or !$permission->Check('message', 'add')) {
            $permission->Redirect(FALSE);
            //Redirect
        }
        if (isset($object_type_id) and isset($object_id)) {
            if (!isset($parent_id)) {
                $parent_id = 0;
            }
            $mf->setObjectType($object_type_id);
            $mf->setObject($object_id);
            $mf->setParent($parent_id);
            $mf->setPriority();
            $mf->setStatus('UNREAD');
            $mf->setSubject($message_data['subject']);
            $mf->setBody($message_data['body']);
            if ($mf->isValid()) {
                $mf->Save();
                Redirect::Page(URLBuilder::getURL(array('template' => $template, 'close' => 1, 'object_type_id' => $object_type_id, 'object_id' => $object_id), 'EmbeddedMessageList.php'));
                break;
            }
        }
    default:
        if (isset($object_type_id) and isset($object_id)) {
            $mlf = new MessageListFactory();
 function postSave()
 {
     //Save message here after we have the request_id.
     //if ( $this->isNew() == TRUE ) {
     if ($this->getMessage() !== FALSE) {
         $mf = new MessageFactory();
         $mf->setObjectType(50);
         //Request
         $mf->setObject($this->getID());
         $mf->setParent(0);
         $mf->setPriority();
         $mf->setStatus('UNREAD');
         $mf->setBody($this->getMessage());
         if ($mf->isValid()) {
             return $mf->Save();
         }
     }
     return TRUE;
 }