Beispiel #1
0
}
if ((int) $user_id > 0) {
    //handle_hook("note_list",$module,"user","user_id",$user_id);
    if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
        module_note::display_notes(array('title' => 'User Notes', 'owner_table' => 'user', 'owner_id' => $user_id, 'view_link' => $module->link_open($user_id)));
    }
    if (class_exists('module_group', false) && module_group::is_plugin_enabled()) {
        module_group::display_groups(array('title' => 'User Groups', 'owner_table' => 'user', 'owner_id' => $user_id, 'view_link' => module_user::link_open($user_id)));
    }
}
hook_handle_callback('layout_column_half', 2);
if (is_file('includes/plugin_user/pages/user_admin_edit_login.php')) {
    include module_theme::include_ucm('includes/plugin_user/pages/user_admin_edit_login.php');
}
if (is_file('includes/plugin_user/pages/user_admin_edit_staff.php')) {
    include module_theme::include_ucm('includes/plugin_user/pages/user_admin_edit_staff.php');
}
if (is_file('includes/plugin_user/pages/user_admin_edit_company.php')) {
    include module_theme::include_ucm('includes/plugin_user/pages/user_admin_edit_company.php');
}
hook_handle_callback('layout_column_half', 'end');
$form_actions = array('class' => 'action_bar action_bar_center', 'elements' => array(array('type' => 'save_button', 'name' => 'butt_save', 'value' => _l('Save User')), array('ignore' => !($user_id != 1 && module_user::can_i('delete', 'Users', 'Config')), 'type' => 'delete_button', 'name' => 'butt_del', 'value' => _l('Delete')), array('type' => 'button', 'name' => 'cancel', 'value' => _l('Cancel'), 'class' => 'submit_button', 'onclick' => "window.location.href='" . $module->link_open(false) . "';")));
echo module_form::generate_form_actions($form_actions);
?>





</form>
$columns['email'] = array('title' => 'Email Address', 'callback' => function ($user) {
    module_user::print_contact_summary($user['user_id'], 'html', array('email'));
});
if ($show_customer_details) {
    $columns['customer'] = array('title' => $contact_type_permission, 'callback' => function ($user) use($contact_module_name) {
        switch ($contact_module_name) {
            case 'customer':
                echo module_customer::link_open($user['customer_id'], true, $user);
                break;
            case 'vendor':
                echo module_vendor::link_open($user['vendor_id'], true, $user);
                break;
        }
    });
}
if (class_exists('module_group', false) && module_user::can_i('view', 'Contact Groups')) {
    $columns['group'] = array('title' => 'Group', 'callback' => function ($user) {
        $groups = module_group::get_groups_search(array('owner_table' => 'user', 'owner_id' => $user['user_id']));
        $g = array();
        foreach ($groups as $group) {
            $g[] = $group['name'];
        }
        echo implode(', ', $g);
    });
}
$table_manager->set_columns($columns);
$table_manager->row_callback = function ($row_data) {
    // load the full vendor data before displaying each row so we have access to more details
    return $row_data;
    //module_user::get_user($row_data['user_id']);
};
Beispiel #3
0
 * Licence: Please check CodeCanyon.net for licence details. 
 * More licence clarification available here:  http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ 
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
$search = isset($_REQUEST['search']) && is_array($_REQUEST['search']) ? $_REQUEST['search'] : array();
$search['customer_id'] = 0;
$users = module_user::get_users($search);
// grab a list of customer sites
$sites = array();
$user_statuses = module_user::get_statuses();
$roles = module_security::get_roles();
$heading = array('title' => _l('User Administration'), 'button' => array(), 'main' => true);
if (module_user::can_i('create', 'Users', 'Config')) {
    $heading['button'][] = array('title' => 'Add new user', 'type' => 'add', 'url' => $module->link_open('new'));
}
print_heading($heading);
?>



<form action="" method="post">

<?php 
$search_bar = array('elements' => array('name' => array('title' => _l('Users Name:'), 'field' => array('type' => 'text', 'name' => 'search[generic]', 'value' => isset($search['generic']) ? $search['generic'] : ''))));
echo module_form::search_bar($search_bar);
/** START TABLE LAYOUT **/
$table_manager = module_theme::new_table_manager();
$columns = array();
}
$module->page_title = _l($page_type);
$staff_members = module_user::get_staff_members();
$staff_member_rel = array();
foreach ($staff_members as $staff_member) {
    $staff_member_rel[$staff_member['user_id']] = $staff_member['name'];
}
$customers = module_customer::get_customers($search, array('as_resource' => true));
$header_buttons = array();
if (module_customer::can_i('create', $page_type)) {
    $header_buttons[] = array('url' => module_customer::link_open('new', false), 'title' => 'Create New ' . $page_type_single, 'type' => 'add');
}
if (class_exists('module_import_export', false) && module_customer::can_i('view', 'Import ' . $page_type)) {
    $header_buttons[] = array('url' => module_import_export::import_link(array('callback' => 'module_customer::handle_import' . ($current_customer_type_id ? '_leads' : ''), 'name' => $page_type, 'return_url' => $_SERVER['REQUEST_URI'], 'group' => 'customer', 'fields' => array($page_type_single . ' ID' => 'customer_id', $page_type_single . ' Name' => 'customer_name', 'Credit' => 'credit', 'Address Line 1' => 'line_1', 'Address Line 2' => 'line_2', 'Address Suburb' => 'suburb', 'Address Country' => 'country', 'Address State' => 'state', 'Address Region' => 'region', 'Address Post Code' => 'post_code', 'Primary Contact First Name' => 'primary_user_name', 'Primary Contact Last Name' => 'primary_user_last_name', 'Primary Phone' => 'primary_user_phone', 'Primary Email' => 'primary_user_email', 'Primary Fax' => 'primary_user_fax', 'Primary Mobile' => 'primary_user_mobile', 'Primary Language' => 'primary_user_language', 'Invoice Prefix' => 'default_invoice_prefix', 'Tax Name' => 'default_tax_name', 'Tax Rate' => 'default_tax', 'Password' => 'password', 'User Role Name' => 'role', 'Notes' => 'notes', 'Staff' => 'customer_staff'), 'extra' => array(array('owner_table' => 'customer', 'owner_id' => 'customer_id'), array('owner_table' => 'user', 'owner_id' => 'primary_user_id')))), 'title' => 'Import ' . $page_type, 'type' => 'add');
}
if (file_exists('includes/plugin_user/pages/contact_admin_list.php') && module_user::can_i('view', 'All ' . $page_type_single . ' Contacts', 'Customer', 'customer')) {
    $header_buttons[] = array('url' => module_user::link_open_contact(false), 'title' => 'View All Contacts');
}
print_heading(array('main' => true, 'type' => 'h2', 'title' => $page_type, 'button' => $header_buttons));
?>


<form action="" method="post">

    <?php 
$search_bar = array('elements' => array('name' => array('title' => _l('Names, Phone or Email:'), 'field' => array('type' => 'text', 'name' => 'search[generic]', 'value' => isset($search['generic']) ? $search['generic'] : '', 'size' => 15)), 'address' => array('title' => _l('Address:'), 'field' => array('type' => 'text', 'name' => 'search[address]', 'value' => isset($search['address']) ? $search['address'] : '', 'size' => 15))));
if (class_exists('module_extra', false)) {
    $search_bar['extra_fields'] = 'customer';
}
if (class_exists('module_group', false) && module_customer::can_i('view', $page_type_single . ' Groups')) {
    $search_bar['elements']['group_id'] = array('title' => false, 'field' => array('type' => 'select', 'name' => 'search[group_id]', 'value' => isset($search['group_id']) ? $search['group_id'] : '', 'options' => module_group::get_groups('customer'), 'options_array_id' => 'name', 'blank' => _l(' Industry - ')));
// we use the "user" module to find the user details
// for the currently selected primary contact id
if ($vendor['primary_user_id']) {
    if (!module_user::can_i('view', 'All ' . $page_type_single . ' Contacts', 'Vendor', 'vendor') && $vendor['primary_user_id'] != module_security::get_loggedin_id()) {
        ob_start();
        echo '<div class="content_box_wheader"><table width="100%" border="0" cellspacing="0" cellpadding="2" class="tableclass tableclass_form"><tbody><tr><td>';
        _e('Details hidden');
        echo '</td></tr></tbody></table></div>';
        $fieldset_data = array('heading' => array('type' => 'h3', 'title' => 'Primary Contact Details'), 'class' => 'tableclass tableclass_form tableclass_full', 'elements_before' => ob_get_clean());
        if ($vendor['primary_user_id']) {
            $fieldset_data['heading']['button'] = array('title' => 'More', 'url' => module_user::link_open_contact($vendor['primary_user_id'], false));
        }
        echo module_form::generate_fieldset($fieldset_data);
        unset($fieldset_data);
    } else {
        if (!module_user::can_i('edit', 'All ' . $page_type_single . ' Contacts', 'Vendor', 'vendor') && $vendor['primary_user_id'] != module_security::get_loggedin_id()) {
            ob_start();
            // no permissions to edit.
            echo '<div class="content_box_wheader"><table width="100%" border="0" cellspacing="0" cellpadding="2" class="tableclass tableclass_form"><tbody><tr><td>';
            module_user::print_contact_summary($vendor['primary_user_id'], 'text', array('name', 'last_name', 'email'));
            echo '</td></tr></tbody></table></div>';
            $fieldset_data = array('heading' => array('type' => 'h3', 'title' => 'Primary Contact Details'), 'class' => 'tableclass tableclass_form tableclass_full', 'elements_before' => ob_get_clean());
            if ($vendor['primary_user_id']) {
                $fieldset_data['heading']['button'] = array('title' => 'More', 'url' => module_user::link_open_contact($vendor['primary_user_id'], false));
            }
            echo module_form::generate_fieldset($fieldset_data);
            unset($fieldset_data);
        } else {
            module_user::print_contact_form($vendor['primary_user_id']);
        }
    }
<?php

/** 
 * Copyright: dtbaker 2012
 * Licence: Please check CodeCanyon.net for licence details. 
 * More licence clarification available here:  http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ 
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
if (module_user::can_i('edit', 'Staff Settings', 'Config')) {
    $fieldset_data = array('heading' => array('type' => 'h3', 'title' => 'Staff Settings', 'help' => 'A staff member is someone who can be assigned to a Job, Job Task or Customer. '), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array());
    $fieldset_data['elements']['is_staff'] = array('title' => _l('Staff Member'), 'fields' => array(array('type' => 'select', 'options' => get_yes_no(), 'blank' => false, 'name' => 'is_staff', 'value' => isset($user['is_staff']) && $user['is_staff'] >= 0 ? $user['is_staff'] : (module_user::is_staff_member($user_id) ? '1' : '0'), 'help' => 'If the user is a staff member they will display in the staff drop down list.')));
    $fieldset_data['elements']['split_hours'] = array('title' => _l('Split Pricing'), 'fields' => array(array('type' => 'select', 'options' => get_yes_no(), 'blank' => false, 'name' => 'split_hours', 'value' => isset($user['split_hours']) && $user['split_hours'] >= 0 ? $user['split_hours'] : '0', 'help' => 'Will this user have a different hourly rate than what is entered on a Job? e.g. If this user is a contractor and will be paid a different amount to what the customer is charged for the project.')));
    $fieldset_data['elements']['hourly_rate'] = array('title' => _l('Hourly Rate'), 'fields' => array(array('type' => 'currency', 'name' => 'hourly_rate', 'value' => isset($user['hourly_rate']) ? $user['hourly_rate'] : '', 'help' => 'The default hourly rate this staff member will receive when working on jobs (can be changed per job).')));
    echo module_form::generate_fieldset($fieldset_data);
}
    }
    //todo: display a warning if the same email address is used within the same customer as a different contact
    //todo: display a warning if this email address is used as a main system "user" (similar to what we do in users anyway).
}
if ((int) $user_id > 0) {
    //handle_hook("note_list",$module,"user","user_id",$user_id);
    if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
        module_note::display_notes(array('title' => 'Contact Notes', 'owner_table' => 'user', 'owner_id' => $user_id, 'view_link' => $module->link_open($user_id)));
    }
    if (class_exists('module_group', false) && module_group::is_plugin_enabled()) {
        module_group::display_groups(array('title' => 'Contact Groups', 'owner_table' => 'user', 'owner_id' => $user_id, 'view_link' => module_user::link_open($user_id)));
    }
}
hook_handle_callback('layout_column_half', 2);
if (is_file('includes/plugin_user/pages/user_admin_edit_login.php')) {
    include module_theme::include_ucm('includes/plugin_user/pages/user_admin_edit_login.php');
}
if (is_file('includes/plugin_user/pages/user_admin_edit_staff.php')) {
    include module_theme::include_ucm('includes/plugin_user/pages/user_admin_edit_staff.php');
}
if ($use_master_key == 'vendor_id' && is_file('includes/plugin_user/pages/user_admin_edit_company.php')) {
    include module_theme::include_ucm('includes/plugin_user/pages/user_admin_edit_company.php');
}
hook_handle_callback('layout_column_half', 'end');
$form_actions = array('class' => 'action_bar action_bar_center', 'elements' => array(array('type' => 'save_button', 'name' => 'butt_save', 'value' => _l('Save Contact')), array('ignore' => !((int) $user_id > 1 && module_user::can_i('delete', 'Contacts', $contact_type)), 'type' => 'delete_button', 'name' => 'butt_del_contact', 'value' => _l('Delete')), array('type' => 'button', 'name' => 'cancel', 'value' => _l('Cancel'), 'class' => 'submit_button', 'onclick' => $use_master_key == 'customer_id' ? "window.location.href='" . module_customer::link_open($user['customer_id']) . "';" : "window.location.href='" . module_vendor::link_open($user['vendor_id']) . "';")));
echo module_form::generate_form_actions($form_actions);
?>


</form>
<?php

/** 
 * Copyright: dtbaker 2012
 * Licence: Please check CodeCanyon.net for licence details. 
 * More licence clarification available here:  http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ 
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
if (class_exists('module_company', false) && module_company::can_i('view', 'Company') && module_company::is_enabled() && module_user::can_i('edit', 'User')) {
    $heading = array('type' => 'h3', 'title' => 'Assigned Company');
    if (module_company::can_i('edit', 'Company')) {
        $help_text = addcslashes(_l("Here you can select which Company this Staff belongs to. This is handy if you are running multiple companies through this system and you would like to separate customers between different companies. Staff can be restricted to assigned companies from the User Role"), "'");
        $heading['button'] = array('url' => '#', 'onclick' => "alert('{$help_text}'); return false;", 'title' => 'help');
    }
    ob_start();
    ?>
        <table class="tableclass tableclass_form tableclass_full">
        <tbody>
            <tr>
                <th class="width1">
                    <?php 
    echo _l('Company');
    ?>
                </th>
                <td>
                    <?php 
    $companys = module_company::get_companys();
    foreach ($companys as $company) {
Beispiel #9
0
 public function save_user($user_id, $data, $from_public = false)
 {
     $use_master_key = $this->get_contact_master_key();
     if ($from_public) {
         $user_id = 0;
     } else {
         if ($use_master_key && isset($data[$use_master_key]) && $data[$use_master_key]) {
             if (!module_user::can_i('edit', 'Contacts', 'Customer')) {
                 set_error('Unable to edit contacts.');
                 return false;
             }
         } else {
             if (!self::can_i('edit', 'Users', 'Config')) {
                 set_error('Unable to edit users.');
                 return false;
             }
         }
         $user_id = (int) $user_id;
     }
     $temp_user = array();
     if ($user_id > 0) {
         // check permissions
         $temp_user = $this->get_user($user_id, true, false);
         if (!$temp_user || $temp_user['user_id'] != $user_id || isset($temp_user['_perms'])) {
             $user_id = false;
         }
     }
     if (!$user_id && !$from_public) {
         if ($use_master_key && isset($data[$use_master_key]) && $data[$use_master_key]) {
             if (!module_user::can_i('create', 'Contacts', 'Customer')) {
                 set_error('Unable to create new contacts.');
                 return false;
             }
         } else {
             if (!self::can_i('create', 'Users', 'Config')) {
                 set_error('Unable to create new users.');
                 return false;
             }
         }
     } else {
         if ($user_id == 1 && module_security::get_loggedin_id() != 1) {
             set_error('Sorry only the administrator can modify this account');
         }
     }
     // check the customer id is valid assignment to someone who has these perms.
     if (!$from_public) {
         if (isset($data['customer_id']) && (int) $data['customer_id'] > 0) {
             $temp_customer = module_customer::get_customer($data['customer_id']);
             if (!$temp_customer || $temp_customer['customer_id'] != $data['customer_id']) {
                 unset($data['customer_id']);
             }
         }
         if (isset($data['vendor_id']) && (int) $data['vendor_id'] > 0) {
             $temp_vendor = module_vendor::get_vendor($data['vendor_id']);
             if (!$temp_vendor || $temp_vendor['vendor_id'] != $data['vendor_id']) {
                 unset($data['vendor_id']);
             }
         }
     }
     if (isset($data['password'])) {
         unset($data['password']);
     }
     // we do the password hash thing here.
     if (isset($data['password_new']) && strlen($data['password_new'])) {
         // an admin is trying to set the password for this account.
         // same permissions checks as on the user_admin_edit_login.php page
         if (!$user_id || isset($temp_user['password']) && !$temp_user['password'] || module_user::can_i('create', 'Users Passwords', 'Config') || isset($_REQUEST['reset_password']) && $_REQUEST['reset_password'] == module_security::get_auto_login_string($user_id)) {
             // we allow the admin to set a new password without typing in previous password.
             $data['password'] = $data['password_new'];
         } else {
             set_error('Sorry, no permissions to set a new password.');
         }
     } else {
         if ($user_id && isset($data['password_new1']) && isset($data['password_new2']) && strlen($data['password_new1'])) {
             // the user is trying to change their password.
             // only do this if the user has edit password permissions and their password matches.
             if (module_user::can_i('edit', 'Users Passwords', 'Config') || $user_id == module_security::get_loggedin_id()) {
                 if (isset($data['password_old']) && (md5($data['password_old']) == $temp_user['password'] || $data['password_old'] == $temp_user['password'])) {
                     // correct old password
                     // verify new password.
                     if ($data['password_new1'] == $data['password_new2']) {
                         $data['password'] = $data['password_new1'];
                     } else {
                         set_error('Verified password mismatch. Password unchanged.');
                     }
                 } else {
                     set_error('Old password does not match. Password unchanged.');
                 }
             } else {
                 set_error('No permissions to change passwords');
             }
         }
     }
     // and we finally hash our password
     if (isset($data['password']) && strlen($data['password']) > 0) {
         $data['password'] = md5($data['password']);
         // if you change md5 also change it in customer import.
         // todo - salt? meh.
     }
     $user_id = update_insert("user_id", $user_id, "user", $data);
     $use_master_key = $this->get_contact_master_key();
     // this will be customer_id or supplier_id
     if ($use_master_key && (isset($data[$use_master_key]) && $data[$use_master_key])) {
         if ($user_id) {
             if (isset($data['customer_primary']) && $data['customer_primary']) {
                 // update the customer/supplier to mark them as primary or not..
                 switch ($use_master_key) {
                     case 'customer_id':
                         module_customer::set_primary_user_id($data['customer_id'], $user_id);
                         break;
                     case 'vendor_id':
                         module_vendor::set_primary_user_id($data['vendor_id'], $user_id);
                         break;
                 }
             } else {
                 // check if this contact was the old customer/supplier primary and
                 switch ($use_master_key) {
                     case 'customer_id':
                         $customer_data = module_customer::get_customer($data['customer_id']);
                         if ($customer_data['primary_user_id'] == $user_id) {
                             module_customer::set_primary_user_id($data['customer_id'], 0);
                         }
                         break;
                     case 'vendor_id':
                         $vendor_data = module_vendor::get_vendor($data['vendor_id']);
                         if ($vendor_data['primary_user_id'] == $user_id) {
                             module_vendor::set_primary_user_id($data['vendor_id'], 0);
                         }
                         break;
                 }
             }
         }
     }
     if (!$from_public) {
         // hack for linked user accounts.
         if ($user_id && isset($data['link_customers']) && $data['link_customers'] == 'yes' && isset($data['link_user_ids']) && is_array($data['link_user_ids']) && isset($data['email']) && $data['email']) {
             $others = module_user::get_contacts(array('email' => $data['email']));
             foreach ($data['link_user_ids'] as $link_user_id) {
                 if (!(int) $link_user_id) {
                     continue;
                 }
                 if ($link_user_id == $user_id) {
                     continue;
                 }
                 // shouldnt happen
                 foreach ($others as $other) {
                     if ($other['user_id'] == $link_user_id) {
                         // success! they'renot trying to hack us.
                         $sql = "REPLACE INTO `" . _DB_PREFIX . "user_customer_rel` SET user_id = '" . (int) $link_user_id . "', customer_id = '" . (int) $other['customer_id'] . "', `primary` = " . (int) $user_id;
                         query($sql);
                         update_insert('user_id', $link_user_id, 'user', array('linked_parent_user_id' => $user_id));
                     }
                 }
             }
             update_insert('user_id', $user_id, 'user', array('linked_parent_user_id' => $user_id));
         }
         if ($user_id && isset($data['unlink']) && $data['unlink'] == 'yes') {
             $sql = "DELETE FROM `" . _DB_PREFIX . "user_customer_rel` WHERE user_id = '" . (int) $user_id . "'";
             query($sql);
             update_insert('user_id', $user_id, 'user', array('linked_parent_user_id' => 0));
         }
         handle_hook("address_block_save", $this, "physical", "user", "user_id", $user_id);
         handle_hook("address_block_save", $this, "postal", "user", "user_id", $user_id);
         if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) {
             module_extra::save_extras('user', 'user_id', $user_id);
         }
         // find current role / permissions
         $user_data = $this->get_user($user_id);
         $previous_user_roles = $user_data['roles'];
         $re_save_role_perms = false;
         // hack to support only 1 role (we may support multi-role in the future)
         // TODO: check we have permissions to set this role id, otherwise anyone can set their own role.
         if (isset($_REQUEST['role_id'])) {
             $sql = "DELETE FROM `" . _DB_PREFIX . "user_role` WHERE user_id = '" . (int) $user_id . "'";
             query($sql);
             if ((int) $_REQUEST['role_id'] > 0) {
                 if (!isset($previous_user_roles[$_REQUEST['role_id']])) {
                     $re_save_role_perms = (int) $_REQUEST['role_id'];
                 }
                 $_REQUEST['role'] = array($_REQUEST['role_id'] => 1);
             }
         }
         // save users roles (support for multi roles in future - but probably will never happen)
         if (isset($_REQUEST['role']) && is_array($_REQUEST['role'])) {
             foreach ($_REQUEST['role'] as $role_id => $tf) {
                 $this->add_user_to_role($user_id, $role_id);
             }
         }
         if ($re_save_role_perms) {
             // copy role permissiosn to user permissions
             $sql = "DELETE FROM `" . _DB_PREFIX . "user_perm` WHERE user_id = " . (int) $user_id;
             query($sql);
             // update - we are not relying on these permissions any more.
             // if the user has a role assigned, we use those permissions period
             // we ignore all permissions in the user_perm table if the user has a role.
             // if the user doesn't have a role, then we use these user_perm permissions.
             /*$security_role = module_security::get_security_role($re_save_role_perms);
             		foreach($security_role['permissions'] as $security_permission_id => $d){
             			$sql = "INSERT INTO `"._DB_PREFIX."user_perm` SET user_id = ".(int)$user_id.", security_permission_id = '".(int)$security_permission_id."'";
             			foreach(module_security::$available_permissions as $perm){
             				$sql .= ", `".$perm."` = ".(int)$d[$perm];
             			}
             			query($sql);
             		}*/
         } else {
             if (isset($_REQUEST['permission']) && is_array($_REQUEST['permission'])) {
                 $sql = "DELETE FROM `" . _DB_PREFIX . "user_perm` WHERE user_id = '" . (int) $user_id . "'";
                 query($sql);
                 // update permissions for this user.
                 foreach ($_REQUEST['permission'] as $security_permission_id => $permissions) {
                     $actions = array();
                     foreach (module_security::$available_permissions as $permission) {
                         if (isset($permissions[$permission]) && $permissions[$permission]) {
                             $actions[$permission] = 1;
                         }
                     }
                     $sql = "REPLACE INTO `" . _DB_PREFIX . "user_perm` SET user_id = '" . (int) $user_id . "', security_permission_id = '" . (int) $security_permission_id . "' ";
                     foreach ($actions as $permission => $tf) {
                         $sql .= ", `" . mysql_real_escape_string($permission) . "` = 1";
                     }
                     query($sql);
                 }
             }
         }
         /*global $plugins;
         		if($user_id && isset($data['user_type_id']) && $data['user_type_id'] == 1 && $data['site_id']){
         			// update the site.
         			$plugins['site']->set_primary_user_id($data['site_id'],$user_id);
         		}else{
         			//this use isn't (or isnt any more) the sites primary user.
         			// unset this if he was the primary user before
         			$site_data = $plugins['site']->get_site($data['site_id']);
         			if(isset($site_data['primary_user_id']) && $site_data['primary_user_id'] == $user_id){
         				$plugins['site']->set_primary_user_id($data['site_id'],0);
         			}
         		}*/
         // save the company information if it's available
         if (class_exists('module_company', false) && module_company::can_i('edit', 'Company') && module_company::is_enabled() && module_user::can_i('edit', 'User')) {
             if (isset($_REQUEST['available_user_company']) && is_array($_REQUEST['available_user_company'])) {
                 $selected_companies = isset($_POST['user_company']) && is_array($_POST['user_company']) ? $_POST['user_company'] : array();
                 foreach ($_REQUEST['available_user_company'] as $company_id => $tf) {
                     if (!isset($selected_companies[$company_id]) || !$selected_companies[$company_id]) {
                         // remove user from this company
                         module_company::delete_user($company_id, $user_id);
                     } else {
                         // add user to this company (if they are not already existing)
                         module_company::add_user_to_company($company_id, $user_id);
                     }
                 }
             }
         }
     }
     module_cache::clear('user');
     return $user_id;
 }
        // if they are not allowed to "edit" a page, but the "view" permission exists
        // then we automatically grab the page and regex all the crap out of it that they are not allowed to change
        // eg: form elements, submit buttons, etc..
        module_security::check_page(array('category' => 'Customer', 'page_name' => 'All Customer Contacts', 'module' => 'customer', 'feature' => 'view'));
    }
    //throw new Exception('Please create a user correctly');
} else {
    $show_customer_details = false;
}
$users = module_user::get_contacts($search, true);
?>


<h2>
    <?php 
if (isset($search[$use_master_key]) && $search[$use_master_key] && module_user::can_i('create', 'Contacts', 'Customer')) {
    ?>

	<span class="button">
		<?php 
    echo create_link("Add New Contact", "add", module_user::link_generate('new', array('type' => 'contact')));
    ?>

	</span>
    <?php 
}
?>

	<?php 
echo _l(($show_customer_details ? 'All ' : '') . 'Customer Contacts');
?>
        _e('Verify Password');
        ?>
</td>
                <td>
                    <input type="password" name="password_new2" value="" />
                    <?php 
        _h('Please confirm your new password here a second time.');
        ?>
                </td>
            </tr>
        </table>
        <?php 
        $fieldset_data['elements']['password'] = array('title' => _l('Change Password'), 'fields' => array(ob_get_clean()));
    }
}
if ((module_user::can_i('view', 'Users Passwords', 'Config') && $user_id == module_security::get_loggedin_id() || module_user::can_i('edit', 'Users Passwords', 'Config')) && (int) $user_id > 0 && $user_id != "new") {
    $fieldset_data['elements']['auto'] = array('title' => _l('Auto Login Link'), 'fields' => array('<a href="' . module_security::generate_auto_login_link($user_id) . '">' . _l('right click - copy link') . '</a> ', _hr('If you give this link to a user (or bookmark it for yourself) then it will log in automatically. To re-set an auto-login link simply change your password to something new.')));
}
if (!module_security::can_user_login($user_id)) {
    $fieldset_data['elements']['warninglogin'] = array('warning' => _l('(note: this user does not have login permissions yet - login will not work)'));
}
echo module_form::generate_fieldset($fieldset_data);
// todo - hook in here for a user configuration area
// modules can load configuration variables in here.
// hmm, is this the same as user roles. i guess it is, we'll just use user roles for now.
?>

    <?php 
/*if(module_user::can_i('edit','Fine Tune Permissions','Config')){

                $user_permissions = module_security::get_user_permissions($user_id);