* @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/
 */
// Load flexprofile model
require_once dirname(dirname(__FILE__)) . "/models/model.php";
if ($user = page_owner()) {
    $user = page_owner_entity();
} else {
    $user = $_SESSION['user'];
    set_page_owner($user->getGUID());
}
$query = "SELECT * FROM {$CONFIG->dbprefix}users_entity join {$CONFIG->dbprefix}_content_item_discrimination on {$CONFIG->dbprefix}users_entity.guid = {$CONFIG->dbprefix}_content_item_discrimination.guid and {$CONFIG->dbprefix}_content_item_discrimination.creator_guid = \"" . $_SESSION['id'] . "\"";
$result = get_data($query);
if ($user && $user->canEdit()) {
    $data = form_get_profile_data_from_form_post();
    form_set_data($user, $data);
    // Notify of profile update
    trigger_elgg_event('profileupdate', $user->type, $user);
    //add to river
    add_to_river('river/user/default/profileupdate', 'update', $user->guid, $user->guid);
    system_message(elgg_echo("profile:saved"));
    // Forward to the user's profile
    forward($user->getUrl());
} else {
    // If we can't, display an error
    register_error(elgg_echo("profile:cantedit"));
    forward();
}
// Get access
$group->access_id = ACCESS_PUBLIC;
// Set group tool options
if (isset($CONFIG->group_tool_options)) {
    foreach ($CONFIG->group_tool_options as $group_option) {
        $group_option_toggle_name = $group_option->name . "_enable";
        if ($group_option->default_on) {
            $group_option_default_value = 'yes';
        } else {
            $group_option_default_value = 'no';
        }
        $group->{$group_option_toggle_name} = get_input($group_option_toggle_name, $group_option_default_value);
    }
}
$data = form_get_profile_data_from_form_post();
form_set_data($group, $data);
$group->save();
if (($group_owner_username = get_input('group_owner_username', '')) && ($user = get_user_by_username($group_owner_username))) {
    $new_group_owner_guid = $user->getGUID();
    $group->owner_guid = $new_group_owner_guid;
    $group->container_guid = $new_group_owner_guid;
}
if (!$group->isMember($user)) {
    $group->join($user);
}
// Creator always a member
// Now see if we have a file icon
if (isset($_FILES['icon']) && substr_count($_FILES['icon']['type'], 'image/')) {
    $prefix = "groups/" . $group->guid;
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $group->owner_guid;