function controlToHTML($name)
 {
     // First, grab the data for the users
     if (!defined("SYS_USERS")) {
         require_once BASE . "subsystems/users.php";
     }
     $users = array();
     foreach (exponent_users_getAllUsers() as $u) {
         $users[$u->id] = $u->firstname . " " . $u->lastname . ' (' . $u->username . ')';
     }
     uasort($users, 'strnatcmp');
     $html = "<script type='text/javascript' src='" . PATH_RELATIVE . "js/ContactControl.js'></script>";
     $html .= "<table cellpadding='0' cellspacing='0' border='0'><tr><td>";
     $html .= '<input type="radio" id="r_' . $name . '_users" name="' . $name . '_type" value="0" onClick="activateContactControl(0,\'' . $name . '\');" />User:'******'<select name="' . $name . '[0]" id="' . $name . '_users">';
     foreach ($users as $id => $uname) {
         $html .= '<option ';
         if ($this->default == $id && $this->type == 0) {
             $html .= 'selected ';
         }
         $html .= 'value="' . $id . '">' . $uname . '</option>';
     }
     $html .= '</select>';
     $html .= '</td></tr><tr><td>';
     $html .= '<input type="radio" id="r_' . $name . '_email" name="' . $name . '_type" value="1" onClick="activateContactControl(1,\'' . $name . '\');" />Email:';
     $html .= '<input type="text" name="' . $name . '[1]" id="' . $name . '_email" ';
     if ($this->type == 1) {
         $html .= 'value="' . $this->default . '" ';
     }
     $html .= '/>';
     $html .= '</td></tr></table>';
     $html .= '<script type="text/javascript">activateContactControl(' . $this->type . ',"' . $name . '");</script>';
     return $html;
 }
 function form($object)
 {
     $i18n = exponent_lang_loadFile('database/inbox_contactbanned.php');
     if (!defined('SYS_FORMS')) {
         require_once BASE . 'subsystems/forms.php';
     }
     exponent_forms_initialize();
     $form = new form();
     if (!defined('SYS_USERS')) {
         require_once BASE . 'subsystems/users.php';
     }
     $users = array();
     foreach (exponent_users_getAllUsers() as $u) {
         // Get the current user.
         $thisuser = $_SESSION['/']['user'];
         if ($u->is_acting_admin == 0 && $u->id != $thisuser->id) {
             $users[$u->id] = $u->firstname . ' ' . $u->lastname . ' (' . $u->username . ')';
         }
     }
     global $db;
     foreach ($db->selectObjects('inbox_contactbanned', 'owner=' . $thisuser->id) as $b) {
         unset($users[$b->user_id]);
     }
     $form->register('uid', $i18n['uid'], new dropdowncontrol(0, $users));
     $form->register('submit', '', new buttongroupcontrol($i18n['save'], '', $i18n['cancel']));
     return $form;
 }
 function form($object)
 {
     $i18n = exponent_lang_loadFile('datatypes/formbuilder_form.php');
     global $db;
     if (!defined('SYS_FORMS')) {
         require_once BASE . 'subsystems/forms.php';
     }
     if (!defined('SYS_USERS')) {
         require_once BASE . 'subsystems/users.php';
     }
     //global $user;
     exponent_forms_initialize();
     $form = new form();
     if (!isset($object->id)) {
         $object->name = '';
         $object->description = '';
         $object->is_email = 0;
         $object->is_saved = 1;
         $object->response = $i18n['default_response'];
         $object->resetbtn = $i18n['default_resetbtn'];
         $object->submitbtn = $i18n['default_submitbtn'];
         $object->subject = $i18n['default_subject'];
     } else {
         $form->meta('id', $object->id);
     }
     $form->register('name', $i18n['name'], new textcontrol($object->name));
     $form->register('description', $i18n['description'], new texteditorcontrol($object->description));
     $form->register('response', $i18n['response'], new htmleditorcontrol($object->response));
     $form->register(null, '', new htmlcontrol('<br><br><b>' . $i18n['button_header'] . '</b><br><hr><br>'));
     $form->register('submitbtn', $i18n['submitbtn'], new textcontrol($object->submitbtn));
     $form->register('resetbtn', $i18n['resetbtn'], new textcontrol($object->resetbtn));
     $form->register(null, '', new htmlcontrol('<br><br><b>' . $i18n['email_header'] . '</b><br><hr><br>'));
     $form->register('is_email', $i18n['is_email'], new checkboxcontrol($object->is_email, false));
     $userlist = array();
     $users = exponent_users_getAllUsers();
     foreach ($users as $locuser) {
         $userlist[$locuser->id] = $locuser->username;
     }
     $defaults = array();
     foreach ($db->selectObjects('formbuilder_address', 'form_id=' . $object->id . ' and user_id != 0') as $address) {
         $locuser = exponent_users_getUserById($address->user_id);
         $defaults[$locuser->id] = $locuser->username;
     }
     $form->register('users', $i18n['users'], new listbuildercontrol($defaults, $userlist));
     $groups = exponent_users_getAllGroups();
     $grouplist = array();
     $defaults = array();
     foreach ($groups as $group) {
         $grouplist[$group->id] = $group->name;
     }
     if ($grouplist != null) {
         foreach ($db->selectObjects('formbuilder_address', 'form_id=' . $object->id . ' and group_id != 0') as $address) {
             $group = exponent_users_getGroupById($address->group_id);
             $defaults[$group->id] = $group->name;
         }
         $form->register('groups', $i18n['groups'], new listbuildercontrol($defaults, $grouplist));
     }
     $defaults = array();
     foreach ($db->selectObjects('formbuilder_address', 'form_id=' . $object->id . " and email != ''") as $address) {
         $defaults[$address->email] = $address->email;
     }
     $form->register('addresses', $i18n['addresses'], new listbuildercontrol($defaults, null));
     $form->register('subject', $i18n['subject'], new textcontrol($object->subject));
     $form->register(null, '', new htmlcontrol('<br /><br /><b>' . $i18n['database_header'] . '</b><br /><hr size="1" /><br />'));
     $form->register('is_saved', $i18n['is_saved'], new checkboxcontrol($object->is_saved, false));
     $form->register(null, '', new htmlcontrol('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $i18n['warning_data_loss'] . '<br />'));
     if ($object->is_saved == 1) {
         $form->controls['is_saved']->disabled = true;
         $form->meta('is_saved', '1');
     }
     $form->register(null, '', new htmlcontrol('<br /><br /><br />'));
     $form->register('submit', '', new buttongroupcontrol($i18n['save'], '', $i18n['cancel']));
     return $form;
 }
 function form($object)
 {
     $i18n = exponent_lang_loadFile('datatypes/inbox_contactlist.php');
     if (!defined('SYS_FORMS')) {
         include_once BASE . 'subsystems/forms.php';
     }
     exponent_forms_initialize();
     $form = new form();
     if (!isset($object->id)) {
         $object->name = '';
         $object->description = '';
         $object->_members = array();
     } else {
         $form->meta('id', $object->id);
     }
     $form->register('name', $i18n['name'], new textcontrol($object->name));
     $form->register('description', $i18n['description'], new texteditorcontrol($object->description));
     $users = array();
     if (!defined('SYS_USERS')) {
         require_once BASE . 'subsystems/users.php';
     }
     global $user;
     if (exponent_permissions_check('contact_all', exponent_core_makeLocation('InboxModule'))) {
         foreach (exponent_users_getAllUsers() as $u) {
             $users[$u->id] = $u;
         }
     } else {
         foreach (exponent_users_getGroupsForUser($user, 1, 0) as $g) {
             foreach (exponent_users_getUsersInGroup($g) as $u) {
                 $users[$u->id] = $u;
             }
         }
     }
     foreach (array_keys($users) as $i) {
         $users[$i] = $users[$i]->firstname . ' ' . $users[$i]->lastname . ' (' . $users[$i]->username . ')';
     }
     global $db;
     // Process other uses who the current user has blocked, and remove them from the list
     // Process other users who have blocked the current user, and remove them from the list.
     foreach ($db->selectObjects('inbox_contactbanned', 'owner=' . $user->id . ' OR user_id=' . $user->id) as $blocked) {
         if ($blocked->user_id == $user->id) {
             // Blocked by someone else.  Remove the owner (user who blocked us)
             unset($users[$blocked->owner]);
         } else {
             if ($blocked->owner == $user->id) {
                 // We blocked the user, remove the blocked user_id
                 unset($users[$blocked->user_id]);
             }
         }
     }
     $members = array();
     for ($i = 0; $i < count($object->_members); $i++) {
         $tmp = $object->_members[$i];
         $members[$tmp] = $users[$tmp];
         unset($users[$tmp]);
     }
     if (count($members) || count($users)) {
         $form->register('members', $i18n['members'], new listbuildercontrol($members, $users));
         $form->register('submit', '', new buttongroupcontrol($i18n['save'], '', $i18n['cancel']));
     } else {
         $submit = new buttongroupcontrol($i18n['save'], '', $i18n['cancel']);
         $submit->disabled = 1;
         $form->register(null, '', new htmlcontrol($i18n['nomembers']));
         $form->register('submit', '', $submit);
     }
     return $form;
 }
if (exponent_permissions_check('administrate', $loc)) {
    if (exponent_template_getModuleViewFile($loc->mod, '_userpermissions', false) == TEMPLATE_FALLBACK_VIEW) {
        $template = new template('common', '_userpermissions', $loc);
    } else {
        $template = new template($loc->mod, '_userpermissions', $loc);
    }
    $template->assign('user_form', 1);
    if (!defined('SYS_USERS')) {
        include_once BASE . 'subsystems/users.php';
    }
    $users = array();
    $modclass = $loc->mod;
    $mod = new $modclass();
    $perms = $mod->permissions($loc->int);
    $have_users = 0;
    foreach (exponent_users_getAllUsers(0) as $u) {
        $have_users = 1;
        foreach ($perms as $perm => $name) {
            $var = 'perms_' . $perm;
            if (exponent_permissions_checkUser($u, $perm, $loc, true)) {
                $u->{$var} = 1;
            } else {
                if (exponent_permissions_checkUser($u, $perm, $loc)) {
                    $u->{$var} = 2;
                } else {
                    $u->{$var} = 0;
                }
            }
        }
        $users[] = $u;
    }
$_GET['id'] = intval($_GET['id']);
$memb = $db->selectObject('groupmembership', 'member_id=' . $user->id . ' AND group_id=' . $_GET['id'] . ' AND is_admin=1');
$perm_level = 0;
if ($memb) {
    $perm_level = 1;
}
if (exponent_permissions_check('user_management', exponent_core_makeLocation('AdministrationModule'))) {
    $perm_level = 2;
}
if ($perm_level) {
    $group = $db->selectObject('group', 'id=' . $_GET['id']);
    if ($group != null) {
        if (!defined('SYS_USERS')) {
            require_once BASE . 'subsystems/users.php';
        }
        $users = exponent_users_getAllUsers(0);
        $members = array();
        $admins = array();
        foreach ($db->selectObjects('groupmembership', 'group_id=' . $group->id) as $m) {
            $members[] = $m->member_id;
            if ($m->is_admin == 1) {
                $admins[] = $m->member_id;
            }
        }
        for ($i = 0; $i < count($users); $i++) {
            if (in_array($users[$i]->id, $members)) {
                $users[$i]->is_member = 1;
            } else {
                $users[$i]->is_member = 0;
            }
            if (in_array($users[$i]->id, $admins)) {
 function form($object)
 {
     $i18n = exponent_lang_loadFile('datatypes/privatemessage.php');
     if (!defined('SYS_FORMS')) {
         require_once BASE . 'subsystems/forms.php';
     }
     exponent_forms_initialize();
     $form = new form();
     $users = array();
     $groups = array();
     global $db, $user;
     if (!defined('SYS_USERS')) {
         require_once BASE . 'subsystems/users.php';
     }
     if (exponent_permissions_check('contact_all', exponent_core_makeLocation('InboxModule'))) {
         foreach (exponent_users_getAllUsers() as $u) {
             $users[$u->id] = $u->firstname . ' ' . $u->lastname . ' (' . $u->username . ')';
         }
     } else {
         foreach (exponent_users_getGroupsForUser($user, 1, 0) as $g) {
             foreach (exponent_users_getUsersInGroup($g) as $u) {
                 $users[$u->id] = $u->firstname . ' ' . $u->lastname . ' (' . $u->username . ')';
             }
         }
     }
     // Process other uses who the current user has blocked, and remove them from the list
     // Process other users who have blocked the current user, and remove them from the list.
     foreach ($db->selectObjects('inbox_contactbanned', 'owner=' . $user->id . ' OR user_id=' . $user->id) as $blocked) {
         if ($blocked->user_id == $user->id) {
             // Blocked by someone else.  Remove the owner (user who blocked us)
             unset($users[$blocked->owner]);
         } else {
             if ($blocked->owner == $user->id) {
                 // We blocked the user, remove the blocked user_id
                 unset($users[$blocked->user_id]);
             }
         }
     }
     uasort($users, 'strnatcmp');
     $groups = array();
     foreach ($db->selectObjects('inbox_contactlist', 'owner=' . $user->id) as $g) {
         $groups['list_' . $g->id] = $g->name . ' ' . $i18n['personal_list'];
     }
     if (exponent_permissions_check('contact_all', exponent_core_makeLocation('InboxModule'))) {
         foreach (exponent_users_getAllGroups(1, 0) as $g) {
             $groups['group_' . $g->id] = $g->name . ' ' . $i18n['system_group'];
         }
     } else {
         foreach (exponent_users_getGroupsForUser($user, 1, 0) as $g) {
             $groups['group_' . $g->id] = $g->name . ' ' . $i18n['system_group'];
         }
     }
     uasort($groups, 'strnatcmp');
     $recipient_caption = $i18n['recipient'];
     $group_recipient_caption = $i18n['group_recipient'];
     $btn = new buttongroupcontrol($i18n['save'], '', $i18n['cancel']);
     $object->group_recipient = array();
     if ($object == null || !isset($object->recipient)) {
         $object->subject = '';
         $object->body = '';
         $object->recipient = array();
         if (!count($users) && !count($groups)) {
             $btn->disabled = true;
         }
     } else {
         if (!defined('SYS_USERS')) {
             require_once BASE . 'subsystems/users.php';
         }
         $u = exponent_users_getUserById($object->recipient);
         $form->register(null, '', new htmlcontrol(sprintf($i18n['replyto'], $u->firstname . ' ' . $u->lastname . ' (' . $u->username . ')')));
         $form->meta('replyto', $object->recipient);
         $object->recipient = array();
         unset($users[$u->id]);
         $recipient_caption = $i18n['copyto'];
         $group_recipient_caption = $i18n['group_copyto'];
     }
     if (count($users)) {
         $form->register('recipients', $recipient_caption, new listbuildercontrol($object->recipient, $users));
     }
     if (count($groups)) {
         $form->register('group_recipients', $group_recipient_caption, new listbuildercontrol($object->group_recipient, $groups));
     }
     if (!count($groups) && !count($users)) {
         $form->register(null, '', new htmlcontrol('<div class="error">' . $i18n['nocontacts'] . '</div>'));
     }
     $form->register('subject', $i18n['subject'], new textcontrol($object->subject));
     $form->register('body', $i18n['body'], new htmleditorcontrol($object->body));
     $form->register('submit', '', $btn);
     return $form;
 }