Пример #1
0
/** 
 * 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
 */
$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 **/
Пример #2
0
<?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
 */
$module->page_title = _l('Customer Signup');
print_heading(array('title' => 'Customer Signup Form', 'type' => 'h2', 'main' => true));
$roles = array();
foreach (module_security::get_roles() as $r) {
    $roles[$r['security_role_id']] = $r['name'];
}
ob_start();
$invoice_templates = array();
$invoice_templates['customer_signup_thank_you_page'] = 1;
$invoice_templates['customer_signup_email_welcome'] = 1;
$invoice_templates['customer_signup_email_admin'] = 1;
$invoice_templates['customer_signup_form_wrapper'] = 1;
foreach ($invoice_templates as $template_key => $tf) {
    module_template::link_open_popup($template_key);
}
$template_html = ob_get_clean();
module_config::print_settings_form(array(array('key' => 'customer_signup_allowed', 'default' => 0, 'type' => 'select', 'options' => array(0 => _l('Not allowed'), 1 => _l('Allowed')), 'description' => 'Enable customer signup form'), array('key' => 'customer_signup_always_new', 'default' => 0, 'type' => 'select', 'options' => array(0 => _l('Allow Update of Existing Customer Entries'), 1 => _l('Always Create New Customer Entries')), 'description' => 'Matching email address action', 'help' => 'If a customer fills in this form and the email address already exists in the system then it can update the existing entry instead of creating a new customer entry. If updating existing entry then the new customer name will be applied, which could differ from existing company name. Set this option to "Always Create New Customer Entry" if you do not want a customer to be able to update their existing details.'), array('key' => 'customer_signup_password', 'default' => 0, 'type' => 'select', 'options' => array(0 => _l('No Password, Admin creates password for each new account (most secure option)'), 1 => _l('Allow Primary User to pick a Password on Signup')), 'description' => 'User Passwords', 'help' => 'If a user has a password they can login to the system and see all their details.'), array('key' => 'customer_signup_role', 'default' => 0, 'type' => 'select', 'options' => $roles, 'description' => 'User Role', 'help' => 'Assign this User Role to all newly created contacts.'), array('key' => 'captcha_on_signup_form', 'default' => 0, 'type' => 'select', 'options' => array(0 => _l('No'), 1 => _l('Yes')), 'description' => 'Use CAPTCHA on signup form'), array('key' => 'customer_signup_redirect', 'default' => '', 'type' => 'text', 'description' => 'Redirect URL', 'help' => 'If no redirect URL is set then the standard thank you message will be displayed. This can be changed in Settings > Templates > customer_signup_thank_you_page'), array('key' => 'customer_signup_admin_email', 'default' => module_config::c('admin_email_address'), 'type' => 'text', 'description' => 'What email address will signup notifications be sent to'), array('key' => 'customer_signup_contact_count', 'default' => 1, 'type' => 'text', 'description' => 'Number of customer contacts'), array('key' => 'customer_signup_password', 'default' => 0, 'type' => 'select', 'options' => array(0 => _l('No'), 1 => _l('Yes')), 'description' => 'Ask for Password'), array('key' => 'customer_signup_on_login', 'default' => 0, 'type' => 'select', 'options' => array(0 => _l('No'), 1 => _l('Yes')), 'description' => 'Show Signup Link on Login Page'), array('key' => 'customer_signup_on_login_url', 'default' => '', 'type' => 'text', 'description' => 'Signup Page URL', 'help' => 'If you have placed the signup form on a page of your website, put that website URL here (e.g. http://www.yourwebsite.com/signup.html)'), array('key' => 'customer_signup_subscription_start', 'default' => '', 'type' => 'text', 'description' => 'Subscription Start Date Modification', 'help' => 'How much to modify the subscription start date by (if they choose a Subscription during signup). Examples are: +5 days or +2 weeks'), array('type' => 'html', 'description' => 'Templates', 'html' => $template_html)));
$form_html = module_customer::get_customer_signup_form_html();
?>
Пример #3
0
 public static function handle_import($data, $add_to_group)
 {
     // woo! we're doing an import.
     // our first loop we go through and find matching customers by their "customer_name" (required field)
     // and then we assign that customer_id to the import data.
     // our second loop through if there is a customer_id we overwrite that existing customer with the import data (ignoring blanks).
     // if there is no customer id we create a new customer record :) awesome.
     foreach ($data as $rowid => $row) {
         if (!isset($row['customer_name']) || !trim($row['customer_name'])) {
             unset($data[$rowid]);
             continue;
         }
         if (!isset($row['customer_id']) || !$row['customer_id']) {
             $data[$rowid]['customer_id'] = 0;
         }
     }
     $staff_members = module_user::get_staff_members();
     $staff_member_rel = array();
     $staff_member_rel2 = array();
     foreach ($staff_members as $staff_member) {
         $staff_member_rel[$staff_member['name']] = $staff_member['user_id'];
         $staff_member_rel2[$staff_member['name'] . ' ' . $staff_member['last_name']] = $staff_member['user_id'];
     }
     // now save the data.
     foreach ($data as $rowid => $row) {
         //module_cache::clear_cache();
         $customer_id = isset($row['customer_id']) ? (int) $row['customer_id'] : 0;
         // check if this ID exists.
         if ($customer_id > 0) {
             $customer = self::get_customer($customer_id);
             if (!$customer || !isset($customer['customer_id']) || $customer['customer_id'] != $customer_id) {
                 $customer_id = 0;
             }
         }
         if (!$customer_id) {
             // search for a custoemr based on name.
             $customer = get_single('customer', 'customer_name', $row['customer_name']);
             //print_r($row); print_r($customer);echo '<hr>';
             if ($customer && $customer['customer_id'] > 0) {
                 $customer_id = $customer['customer_id'];
             }
         }
         $customer_id = update_insert("customer_id", $customer_id, "customer", $row);
         // add staff to customer.
         if (isset($row['customer_staff'])) {
             $staff_split = explode(',', $row['customer_staff']);
             foreach ($staff_split as $staff_name) {
                 $staff_name2 = trim($staff_name);
                 $staff_id = false;
                 if (isset($staff_member_rel[$staff_name])) {
                     $staff_id = $staff_member_rel[$staff_name];
                 } else {
                     if (isset($staff_member_rel[$staff_name2])) {
                         $staff_id = $staff_member_rel[$staff_name2];
                     } else {
                         if (isset($staff_member_rel2[$staff_name])) {
                             $staff_id = $staff_member_rel2[$staff_name];
                         } else {
                             if (isset($staff_member_rel2[$staff_name2])) {
                                 $staff_id = $staff_member_rel2[$staff_name2];
                             }
                         }
                     }
                 }
                 if ($staff_id) {
                     $sql = "REPLACE INTO `" . _DB_PREFIX . "customer_user_rel` SET ";
                     $sql .= " `user_id` = " . (int) $staff_id;
                     $sql .= ", `customer_id` = " . (int) $customer_id;
                     query($sql);
                 }
             }
         }
         // ad notes if possible
         if (isset($row['notes']) && strlen(trim($row['notes']))) {
             if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
                 module_note::save_note(array('owner_table' => 'customer', 'owner_id' => $customer_id, 'note' => trim($row['notes']), 'note_time' => time()));
             }
         }
         // see if we're updating an old contact, or adding a new primary contact.
         // match on name since that's a required field.
         $users = module_user::get_contacts(array('customer_id' => $customer_id));
         $user_match = 0;
         foreach ($users as $user) {
             if ($user['name'] == $row['primary_user_name']) {
                 $user_match = $user['user_id'];
                 break;
             }
         }
         $user_update = array('customer_id' => $customer_id);
         if (isset($row['primary_user_name'])) {
             $user_update['name'] = $row['primary_user_name'];
         }
         if (isset($row['primary_user_last_name'])) {
             $user_update['last_name'] = $row['primary_user_last_name'];
         }
         if (isset($row['primary_user_email'])) {
             $user_update['email'] = $row['primary_user_email'];
         }
         if (isset($row['primary_user_phone'])) {
             $user_update['phone'] = $row['primary_user_phone'];
         }
         if (isset($row['primary_user_fax'])) {
             $user_update['fax'] = $row['primary_user_fax'];
         }
         if (isset($row['primary_user_mobile'])) {
             $user_update['mobile'] = $row['primary_user_mobile'];
         }
         if (isset($row['primary_user_language'])) {
             $user_update['language'] = $row['primary_user_language'];
         }
         if (isset($row['password']) && strlen($row['password'])) {
             $user_update['password'] = md5(trim($row['password']));
         }
         $user_match = update_insert("user_id", $user_match, "user", $user_update);
         if ($user_match && isset($row['role']) && strlen(trim($row['role']))) {
             // find this role name and assign it to this user.
             $role = module_security::get_roles(array('name' => $row['role']));
             if ($role) {
                 $user_role = array_shift($role);
                 $role_id = $user_role['security_role_id'];
                 module_user::add_user_to_role($user_match, $role_id);
             }
         }
         self::set_primary_user_id($customer_id, $user_match);
         // do a hack to save address.
         $existing_address = module_address::get_address($customer_id, 'customer', 'physical');
         $address_id = $existing_address && isset($existing_address['address_id']) ? (int) $existing_address['address_id'] : 'new';
         $address = array_merge($row, array('owner_id' => $customer_id, 'owner_table' => 'customer', 'address_type' => 'physical'));
         module_address::save_address($address_id, $address);
         foreach ($add_to_group as $group_id => $tf) {
             module_group::add_to_group($group_id, $customer_id, 'customer');
         }
         // handle any extra fields.
         $extra = array();
         foreach ($row as $key => $val) {
             if (!strlen(trim($val))) {
                 continue;
             }
             if (strpos($key, 'extra:') !== false) {
                 $extra_key = str_replace('extra:', '', $key);
                 if (strlen($extra_key)) {
                     $extra[$extra_key] = $val;
                 }
             }
         }
         if ($extra) {
             // we handle extra importing for customer extra fields and contact extra fields.
             // sort out which are which.
             // but they have to be unique names. for now. oh well that'll do.
             $sql = "SELECT `extra_key` as `id` FROM `" . _DB_PREFIX . "extra` WHERE owner_table = 'customer' AND `extra_key` != '' GROUP BY `extra_key` ORDER BY `extra_key`";
             $customer_fields = qa($sql);
             $sql = "SELECT `extra_key` as `id` FROM `" . _DB_PREFIX . "extra` WHERE owner_table = 'user' AND `extra_key` != '' GROUP BY `extra_key` ORDER BY `extra_key`";
             $contact_fields = qa($sql);
             foreach ($extra as $extra_key => $extra_val) {
                 // does this one exist?
                 if (isset($customer_fields[$extra_key])) {
                     // this is a customer extra field.
                     $existing_extra = module_extra::get_extras(array('owner_table' => 'customer', 'owner_id' => $customer_id, 'extra_key' => $extra_key));
                     $extra_id = false;
                     foreach ($existing_extra as $key => $val) {
                         if ($val['extra_key'] == $extra_key) {
                             $extra_id = $val['extra_id'];
                         }
                     }
                     $extra_db = array('extra_key' => $extra_key, 'extra' => $extra_val, 'owner_table' => 'customer', 'owner_id' => $customer_id);
                     $extra_id = (int) $extra_id;
                     update_insert('extra_id', $extra_id, 'extra', $extra_db);
                 } else {
                     if ($user_match && isset($contact_fields[$extra_key])) {
                         // this is a primary contact extra field
                         $existing_extra = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $user_match, 'extra_key' => $extra_key));
                         $extra_id = false;
                         foreach ($existing_extra as $key => $val) {
                             if ($val['extra_key'] == $extra_key) {
                                 $extra_id = $val['extra_id'];
                             }
                         }
                         $extra_db = array('extra_key' => $extra_key, 'extra' => $extra_val, 'owner_table' => 'user', 'owner_id' => $user_match);
                         $extra_id = (int) $extra_id;
                         update_insert('extra_id', $extra_id, 'extra', $extra_db);
                     }
                 }
             }
         }
     }
 }