// Load Elgg engine
require_once dirname(dirname(dirname(__FILE__))) . "/engine/start.php";
// Load form model
require_once dirname(__FILE__) . "/models/model.php";
// Define context
set_context('form:content');
$form_id = get_input('id', 0);
$form_data_id = get_input('d', 0);
$preview = get_input('preview', 0);
$form = get_entity($form_id);
if ($form && $form->type == 'object' && get_subtype_from_id($form->subtype) == 'form:form') {
    set_page_owner($form->owner_guid);
    if ($form_data_id && ($form_data = form_get_data($form_data_id))) {
        if (get_entity($form_data_id)->canEdit()) {
            $tab_data = form_get_data_for_edit_form($form, $form_data);
        } else {
            register_error(elgg_echo('form:content_not_found'));
            forward();
        }
    } else {
        $tab_data = form_get_data_for_edit_form($form);
    }
    $title = form_form_t($form, 'title');
    $body = elgg_view('form/forms/display_form', array('form' => $form, 'tab_data' => $tab_data, 'preview' => $preview, 'form_data_id' => $form_data_id));
    $pg_owner_entity = page_owner_entity();
    $username = $pg_owner_entity->username;
    page_draw($title, elgg_view_layout("two_column_left_sidebar", '', elgg_view_title($title) . $body));
} else {
    register_error(elgg_echo('form:not_found'));
    forward();
}
 * 
 * @package Elgg
 * @subpackage Form
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * @author Kevin Jardine <*****@*****.**>
 * @copyright Radagast Solutions 2008
 * @link http://radagast.biz/
 */
$tab_data = $vars['tab_data'];
$form = $vars['form'];
$preview = $vars['preview'];
$form_data_id = $vars['form_data_id'];
if (isset($vars['description'])) {
    $description = $vars['description'];
} else {
    $description = form_form_t($form, 'description');
}
if ($preview) {
    $body = '<div class="contentWrapper">' . elgg_echo('form:preview_description') . '</div>';
} else {
    $body = '';
}
// TODO - add some intelligent way to determine the form enctype?
$body .= <<<END
<script type="text/javascript" src="{$vars['url']}mod/form/tabber/tabber.js"></script>
<link rel="stylesheet" href="{$vars['url']}mod/form/tabber/example.css" type="text/css" media="screen" />
<div class="contentWrapper">
{$description}
</div>
<div class="contentWrapper">
<form action="{$vars['url']}action/form/submit" method="post" enctype="multipart/form-data">
function form_set_menu_items()
{
    global $CONFIG;
    // add display links to menu
    $entities = get_entities_from_metadata('enable_display_menu', 1, 'object', 'form:form');
    if ($entities) {
        foreach ($entities as $form) {
            add_menu(form_form_t($form, 'display_menu_title'), $CONFIG->wwwroot . 'mod/form/my_forms.php?form_view=all&id=' . $form->getGUID());
        }
    }
    // add create links to menu
    $entities = get_entities_from_metadata('enable_create_menu', 1, 'object', 'form:form');
    if ($entities) {
        foreach ($entities as $form) {
            add_menu(form_form_t($form, 'create_menu_title'), $CONFIG->wwwroot . 'mod/form/form.php?id=' . $form->getGUID());
        }
    }
    // add search links
    $entities = get_entities_from_metadata('creates_menu', 1, 'object', 'form:search_definition');
    if ($entities) {
        foreach ($entities as $sd) {
            $form = get_entity($sd->form_id);
            add_menu(form_search_definition_t($form, $sd, 'menu'), $CONFIG->wwwroot . 'mod/form/search.php?sid=' . $sd->getGUID());
        }
    }
}
            $sd_id = $sd->getGUID();
            $body .= "<a href=\"{$vars['url']}mod/form/search.php?sid={$sd_id}\">" . form_search_definition_t($form, $sd, 'title') . "</a><br />";
        }
        $body .= '</div>';
    }
}
$forms = get_entities_from_metadata('profile', '0', 'object', 'form:form');
if ($forms) {
    foreach ($forms as $form) {
        $form_id = $form->getGUID();
        if (isloggedin()) {
            $add_bit = '<a href="' . $vars['url'] . 'mod/form/form.php?id=' . $form_id . '">' . elgg_echo('form:add_content') . '</a> | ';
        } else {
            $add_bit = '';
        }
        $sd_bit = '';
        $sd_list = get_entities_from_metadata('form_id', $form_id, 'object', 'form:search_definition');
        if ($sd_list) {
            foreach ($sd_list as $sd) {
                $sd_id = $sd->getGUID();
                $sd_bit .= "| <a href=\"{$vars['url']}mod/form/search.php?sid={$sd_id}\">" . form_search_definition_t($form, $sd, 'title') . "</a>";
            }
        }
        $body .= sprintf($form_template, form_form_t($form, 'title'), form_form_t($form, 'listing_description'), $add_bit, $form_id, $sd_bit);
    }
} else {
    if (!$profile_form) {
        $body .= '<p>' . elgg_echo('form:no_content') . '</p>';
    }
}
print $body;