$c = array();
    $res = module_customer::get_customers();
    foreach ($res as $row) {
        $c[$row['customer_id']] = $row['customer_name'];
    }
    $fieldset_data = array('heading' => array('type' => 'h3', 'title' => _l('Advanced')), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array());
    if (count($res) <= 1 && $widget['customer_id'] && isset($c[$widget['customer_id']])) {
        $fieldset_data['elements']['change'] = array('title' => _l('Change Customer'), 'fields' => array(htmlspecialchars($c[$widget['customer_id']]), array('type' => 'hidden', 'name' => 'customer_id', 'value' => $widget['customer_id'])));
    } else {
        $fieldset_data['elements']['change'] = array('title' => _l('Change Customer'), 'fields' => array(array('type' => 'select', 'name' => 'customer_id', 'options' => $c, 'value' => $widget['customer_id'], 'help' => 'Changing a customer will also change all the current linked jobs and invoices across to this new customer.')));
    }
    echo module_form::generate_fieldset($fieldset_data);
}
if ((int) $widget_id > 0) {
    if (class_exists('module_group', false)) {
        module_group::display_groups(array('title' => 'Widget' . ' Groups', 'owner_table' => 'widget', 'owner_id' => $widget_id, 'view_link' => module_widget::link_open($widget_id)));
    }
    // and a hook for our new change request plugin
    hook_handle_callback('widget_sidebar', $widget_id);
}
hook_handle_callback('layout_column_half', 2, 65);
if ((int) $widget_id > 0) {
    if (class_exists('module_note', false)) {
        module_note::display_notes(array('title' => 'Widget' . ' Notes', 'owner_table' => 'widget', 'owner_id' => $widget_id, 'view_link' => module_widget::link_open($widget_id)));
    }
    // and a hook for our new change request plugin
    hook_handle_callback('widget_main', $widget_id);
}
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 ' . 'Widget')), array('ignore' => !((int) $widget_id && module_widget::can_i('delete', 'Widgets')), '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_widget::link_open(false) . "';")));
echo module_form::generate_form_actions($form_actions);
    include dirname(__FILE__) . '/../inc/ticket_extras_sidebar.php';
}
if (file_exists(dirname(__FILE__) . '/../inc/ticket_billing.php')) {
    include dirname(__FILE__) . '/../inc/ticket_billing.php';
}
if ((int) $ticket_id > 0 && file_exists(dirname(__FILE__) . '/../inc/ticket_priority_sidebar.php')) {
    //if($ticket['priority'] == _TICKET_PRIORITY_STATUS_ID || (isset($ticket['invoice_id']) && $ticket['invoice_id'])){
    include dirname(__FILE__) . '/../inc/ticket_priority_sidebar.php';
    // }
}
if (isset($ticket['ticket_id']) && (int) $ticket['ticket_id'] > 0 && module_ticket::can_edit_tickets()) {
    if (class_exists('module_note', false) && module_note::is_plugin_enabled() && module_config::c('ticket_enable_notes', 1)) {
        module_note::display_notes(array('title' => 'Ticket Notes', 'owner_table' => 'ticket', 'owner_id' => $ticket_id, 'view_link' => module_ticket::link_open($ticket['ticket_id'])));
    }
    if (class_exists('module_group', false) && module_config::c('ticket_enable_groups', 1)) {
        module_group::display_groups(array('title' => 'Ticket Groups', 'owner_table' => 'ticket', 'owner_id' => $ticket['ticket_id'], 'view_link' => module_ticket::link_open($ticket['ticket_id'])));
    }
}
if (module_ticket::can_edit_tickets()) {
    /** RELATED TO */
    $responsive_summary = array();
    $responsive_summary[] = module_customer::link_open($ticket['customer_id'], true);
    $fieldset_data = array('heading' => array('title' => _l('Related to'), 'type' => 'h3', 'responsive' => array('summary' => implode(', ', $responsive_summary))), 'elements' => array());
    $fieldset_data['elements'][] = array('title' => _l('Customer'), 'fields' => array(function () use($ticket_id, $ticket, $done_in_ticket_billing) {
        // moved to ticket billing..?
        if (module_ticket::can_edit_tickets() && !isset($done_in_ticket_billing)) {
            $c = array();
            $res = module_customer::get_customers();
            while ($row = array_shift($res)) {
                $c[$row['customer_id']] = $row['customer_name'];
            }
    $c = array();
    $res = module_customer::get_customers();
    foreach ($res as $row) {
        $c[$row['customer_id']] = $row['customer_name'];
    }
    $fieldset_data = array('heading' => array('type' => 'h3', 'title' => _l('Advanced')), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array());
    if (count($res) <= 1 && $website['customer_id'] && isset($c[$website['customer_id']])) {
        $fieldset_data['elements']['change'] = array('title' => _l('Change Customer'), 'fields' => array(htmlspecialchars($c[$website['customer_id']]), array('type' => 'hidden', 'name' => 'customer_id', 'value' => $website['customer_id'])));
    } else {
        $fieldset_data['elements']['change'] = array('title' => _l('Change Customer'), 'fields' => array(array('type' => 'select', 'name' => 'customer_id', 'options' => $c, 'value' => $website['customer_id'], 'help' => 'Changing a customer will also change all the current linked jobs and invoices across to this new customer.')));
    }
    echo module_form::generate_fieldset($fieldset_data);
}
if ((int) $website_id > 0) {
    if (class_exists('module_group', false)) {
        module_group::display_groups(array('title' => module_config::c('project_name_single', 'Website') . ' Groups', 'owner_table' => 'website', 'owner_id' => $website_id, 'view_link' => module_website::link_open($website_id)));
    }
    // and a hook for our new change request plugin
    hook_handle_callback('website_sidebar', $website_id);
}
hook_handle_callback('layout_column_half', 2, 65);
if ((int) $website_id > 0) {
    if (class_exists('module_note', false)) {
        $note_summary_owners = array();
        // generate a list of all possible notes we can display for this website.
        // display all the notes which are owned by all the sites we have access to
        $note_summary_owners['job'] = array();
        $note_summary_owners['invoice'] = array();
        if (class_exists('module_job', false) && module_job::is_plugin_enabled()) {
            foreach (module_job::get_jobs(array('website_id' => $website_id)) as $val) {
                $note_summary_owners['job'][] = $val['job_id'];
$title = 'User Details';
include module_theme::include_ucm('includes/plugin_user/pages/contact_admin_form.php');
if (module_config::c('users_have_address', 0)) {
    ob_start();
    handle_hook("address_block", $module, "physical", "user", "user_id");
    $fieldset_data = array('heading' => array('type' => 'h3', 'title' => 'Address'), 'elements_before' => ob_get_clean());
    echo module_form::generate_fieldset($fieldset_data);
    unset($fieldset_data);
}
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);
    }
}
if ($job_id && $job_id != 'new') {
    $note_summary_owners = array();
    // generate a list of all possible notes we can display for this job.
    // display all the notes which are owned by all the sites we have access to
    if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
        module_note::display_notes(array('title' => 'Job Notes', 'owner_table' => 'job', 'owner_id' => $job_id, 'view_link' => module_job::link_open($job_id)));
    }
    if (class_exists('module_job', false) && module_job::is_plugin_enabled()) {
        if (module_job::can_i('edit', 'Jobs')) {
            module_email::display_emails(array('title' => 'Job Emails', 'search' => array('job_id' => $job_id)));
        }
    }
    if (class_exists('module_group', false) && module_group::is_plugin_enabled()) {
        module_group::display_groups(array('title' => 'Job Groups', 'owner_table' => 'job', 'owner_id' => $job_id, 'view_link' => $module->link_open($job_id)));
    }
}
if (module_job::can_i('view', 'Job Advanced')) {
    /***** JOB ADVANCED *****/
    $fieldset_data = array('heading' => array('type' => 'h3', 'title' => 'Advanced'), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array(array('title' => 'Customer Link', 'field' => array('type' => 'html', 'value' => '<a href="' . module_job::link_public($job_id) . '" target="_blank">' . _l('Click to view external link') . '</a>', 'help' => 'You can send this link to the customer and they can view progress on their job. They can also view a list of any invoices attached to this job. This is VERY useful to stop customers asking you "how far along are you" with a job because they can see exactly where you have logged up to in the system.'))));
    if ((int) $job_id > 0 && module_job::can_i('edit', 'Jobs')) {
        $fieldset_data['elements'][] = array('title' => 'Email Job', 'field' => array('type' => 'html', 'value' => '<a href="' . module_job::link_generate($job_id, array('arguments' => array('email' => 1))) . '">' . _l('Email this Job to Customer') . '</a>', 'help' => 'You can email the customer a copy of this job. This can be a progress report or as an initial quote. '));
        $fieldset_data['elements'][] = array('title' => 'Email Staff', 'fields' => array(function () use(&$job_tasks, $job_id) {
            $allocated_staff_members = array();
            foreach ($job_tasks as $job_task) {
                if (!isset($allocated_staff_members[$job_task['user_id']])) {
                    $allocated_staff_members[$job_task['user_id']] = 0;
                }
                $allocated_staff_members[$job_task['user_id']]++;
            }
                        'name' => 'default_invoice_prefix',
                        'value' => $vendor['default_invoice_prefix'],
                        'help' => 'Every time an invoice is generated for this vendor the INVOICE NUMBER will be prefixed with this value.',
                        'size' => 5,
                    ),
                )
            );
        }
    }

    echo module_form::generate_fieldset($fieldset_data);
*/
hook_handle_callback('layout_column_half', 2);
if ($vendor_id && $vendor_id != 'new') {
    if (class_exists('module_group', false) && module_group::is_plugin_enabled()) {
        module_group::display_groups(array('title' => $page_type_single . ' Categories', 'owner_table' => 'vendor', 'owner_id' => $vendor_id, 'view_link' => $module->link_open($vendor_id)));
    }
    $note_summary_owners = array();
    // generate a list of all possible notes we can display for this vendor.
    // display all the notes which are owned by all the sites we have access to
    // display all the notes which are owned by all the users we have access to
    foreach (module_user::get_contacts(array('vendor_id' => $vendor_id)) as $val) {
        $note_summary_owners['user'][] = $val['user_id'];
    }
    /*if(class_exists('module_website',false) && module_website::is_plugin_enabled()){
          foreach(module_website::get_websites(array('vendor_id'=>$vendor_id)) as $val){
              $note_summary_owners['website'][] = $val['website_id'];
          }
      }
      if(class_exists('module_job',false) && module_job::is_plugin_enabled()){
          foreach(module_job::get_jobs(array('vendor_id'=>$vendor_id)) as $val){
            module_user::print_contact_form($customer['primary_user_id']);
        }
    }
} else {
    // hack to create new contact details.
    module_user::print_contact_form(false);
}
/*** ADDRESS **/
if (class_exists('module_address', false)) {
    module_address::print_address_form($customer_id, 'customer', 'physical', 'Address');
}
/** ADVANCED AREA **/
hook_handle_callback('layout_column_half', 2);
if ($customer_id && $customer_id != 'new') {
    if (class_exists('module_group', false) && module_group::is_plugin_enabled()) {
        module_group::display_groups(array('title' => $page_type_single . ' Groups', 'owner_table' => 'customer', 'owner_id' => $customer_id, 'view_link' => $module->link_open($customer_id)));
    }
    $note_summary_owners = array();
    // generate a list of all possible notes we can display for this customer.
    // display all the notes which are owned by all the sites we have access to
    // display all the notes which are owned by all the users we have access to
    foreach (module_user::get_contacts(array('customer_id' => $customer_id)) as $val) {
        $note_summary_owners['user'][] = $val['user_id'];
    }
    if (class_exists('module_website', false) && module_website::is_plugin_enabled()) {
        foreach (module_website::get_websites(array('customer_id' => $customer_id)) as $val) {
            $note_summary_owners['website'][] = $val['website_id'];
        }
    }
    if (class_exists('module_job', false) && module_job::is_plugin_enabled()) {
        foreach (module_job::get_jobs(array('customer_id' => $customer_id)) as $val) {
    }
}
if ($quote_id && $quote_id != 'new') {
    $note_summary_owners = array();
    // generate a list of all possible notes we can display for this quote.
    // display all the notes which are owned by all the sites we have access to
    if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
        module_note::display_notes(array('title' => 'Quote Notes', 'owner_table' => 'quote', 'owner_id' => $quote_id, 'view_link' => module_quote::link_open($quote_id)));
    }
    if (class_exists('module_quote', false) && module_quote::is_plugin_enabled()) {
        if (module_quote::can_i('edit', 'Quotes')) {
            module_email::display_emails(array('title' => 'Quote Emails', 'search' => array('quote_id' => $quote_id)));
        }
    }
    if (class_exists('module_group', false) && module_group::is_plugin_enabled()) {
        module_group::display_groups(array('title' => 'Quote Groups', 'owner_table' => 'quote', 'owner_id' => $quote_id, 'view_link' => $module->link_open($quote_id)));
    }
}
if (module_quote::can_i('view', 'Quote Advanced')) {
    /***** QUOTE ADVANCED *****/
    $fieldset_data = array('id' => 'quote_advanced', 'heading' => array('type' => 'h3', 'title' => 'Advanced'), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array());
    if ((int) $quote_id > 0 && module_quote::can_i('edit', 'Quotes')) {
        $fieldset_data['elements'][] = array('title' => 'Customer Link', 'fields' => array('<a href="' . module_quote::link_public($quote_id) . '" target="_blank">' . _l('Click to view external link') . '</a>', _hr('You can send this link to the customer and they can view progress on their quote. They can also view a list of any invoices attached to this quote. This is VERY useful to stop customers asking you "how far along are you" with a quote because they can see exactly where you have logged up to in the system.')));
        $fieldset_data['elements'][] = array('title' => 'Email Staff', 'fields' => array(function () use(&$quote_tasks, $quote_id) {
            $allocated_staff_members = array();
            foreach ($quote_tasks as $quote_task) {
                if (!isset($allocated_staff_members[$quote_task['user_id']])) {
                    $allocated_staff_members[$quote_task['user_id']] = 0;
                }
                $allocated_staff_members[$quote_task['user_id']]++;
            }
?>
" />

    <?php 
module_form::set_required(array('fields' => array('first_name' => 'Name', 'email' => 'Email')));
module_form::prevent_exit(array('valid_exits' => array('.submit_button', '.submit_small')));
hook_handle_callback('layout_column_half', 1);
$fieldset_data = array('heading' => array('type' => 'h3', 'title' => 'Member Information'), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array(array('title' => _l('First Name'), 'field' => array('name' => 'first_name', 'type' => 'text', 'value' => $member['first_name'])), array('title' => _l('Last Name'), 'field' => array('name' => 'last_name', 'type' => 'text', 'value' => $member['last_name'])), array('title' => _l('Business Name'), 'field' => array('name' => 'business', 'type' => 'text', 'value' => $member['business'])), array('title' => _l('Email'), 'field' => array('name' => 'email', 'type' => 'text', 'value' => $member['email'])), array('title' => _l('Phone'), 'field' => array('name' => 'phone', 'type' => 'text', 'value' => $member['phone'])), array('title' => _l('Mobile'), 'field' => array('name' => 'mobile', 'type' => 'text', 'value' => $member['mobile'])), array('title' => _l('External'), 'ignore' => !($member_id > 0), 'field' => array('type' => 'html', 'value' => '<a href="' . module_member::link_public_details($member_id) . '" target="_blank">' . _l('Edit Details') . '</a>', 'help' => 'You can send this link to your customer so they can edit their details.'))), 'extra_settings' => array('owner_table' => 'member', 'owner_key' => 'member_id', 'owner_id' => $member_id, 'layout' => 'table_row'));
echo module_form::generate_fieldset($fieldset_data);
if ($member_id && (int) $member_id > 0) {
    hook_handle_callback('member_edit', $member_id);
}
hook_handle_callback('layout_column_half', 2);
if ($member_id && (int) $member_id > 0) {
    if (class_exists('module_group', false)) {
        module_group::display_groups(array('title' => 'Member Groups', 'description' => _l('These are for you to group your members. The member cannot see or change these groups. You can choose members based on these groups.'), 'owner_table' => 'member', 'owner_id' => $member_id, 'view_link' => $module->link_open($member_id)));
        if (class_exists('module_newsletter', false)) {
            module_group::display_groups(array('title' => 'Newsletter', 'description' => _l('The member can choose which of the below subscriptions they would like to receive. The member can see and change these subscriptions themselves. You can choose members based on these subscriptions.'), 'owner_table' => 'newsletter_subscription', 'owner_id' => $member_id));
        }
    }
}
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')), array('ignore' => !($member_id > 0), '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>