예제 #1
0
$customer_import = array('customer_name' => $callername, 'customer_extra' => array('Medium' => $referrermedium, 'Source' => $callsource, 'Campaign' => $utm_campaign, 'Content' => $utm_content, 'Term' => $utm_term, 'Query' => $keywords, 'Conversion URL' => $last_requested_url, 'IP Address' => $ip, 'Called In' => $datetime), 'address' => array('line_1' => '123 Test Street', 'line_2' => '', 'suburb' => $callercity, 'state' => $callerstate, 'post_code' => $callerzip), 'contact' => array('name' => $callername, 'last_name' => $callername, 'email' => $trackingnum, 'mobile' => $callernum));
include 'init.php';
// the UCM init code.
$customer_id = $plugins['customer']->save_customer('new', array('customer_name' => $customer_import['customer_name']));
if (!$customer_id) {
    echo 'Failed to create customer';
    exit;
}
if (!empty($customer_import['customer_extra'])) {
    foreach ($customer_import['customer_extra'] as $extra_key => $extra_val) {
        // Add the Medium extra field to that newly created customer
        $extra_db = array('extra_key' => $extra_key, 'extra' => $extra_val, 'owner_table' => 'customer', 'owner_id' => $customer_id);
        $extra_id = update_insert('extra_id', false, 'extra', $extra_db);
    }
}
if (!empty($customer_import['address'])) {
    // Save the address for the customer
    $customer_import['address']['owner_id'] = $customer_id;
    $customer_import['address']['owner_table'] = 'customer';
    $customer_import['address']['address_type'] = 'physical';
    module_address::save_address(false, $customer_import['address']);
}
if (!empty($customer_import['contact'])) {
    // add the contact details to this customer record
    $customer_import['contact']['customer_id'] = $customer_id;
    $contact_user_id = $plugins['user']->create_user($customer_import['contact'], 'signup');
    if ($contact_user_id) {
        module_customer::set_primary_user_id($customer_id, $contact_user_id);
    }
}
echo "Created a customer with ID {$customer_id} and a contact with ID {$contact_user_id} ";
예제 #2
0
    google.maps.event.addListener(item, 'click', function(event) {
        infowindow.close();
        infowindow = new google.maps.InfoWindow({
            content: content,
            position: event.latLng
        });
        infowindow.open(map, item);
    });
}

var customer_address = [];
<?php 
$customer_addresses = array();
$customers = module_customer::get_customers(array('customer_id' => isset($_REQUEST['customer_id']) && (int) $_REQUEST['customer_id'] > 0 ? (int) $_REQUEST['customer_id'] : false), array('columns' => 'c.customer_id, c.customer_name'));
foreach ($customers as $customer) {
    $address = module_address::get_address($customer['customer_id'], 'customer', 'physical');
    if (!empty($address)) {
        $address_count = 0;
        $customer['full_address'] = '';
        foreach (array('line_1', 'line_2', 'suburb', 'state', 'region', 'country', 'post_code') as $key) {
            if (!empty($address[$key])) {
                $address_count++;
                $customer['full_address'] .= $address[$key] . ', ';
            }
            $customer[$key] = $address[$key];
        }
        if ($address_count > 1) {
            $customer['address_id'] = $address['address_id'];
            $customer['full_address'] = rtrim($customer['full_address'], ', ');
            $customer['address_hash'] = md5(serialize($address));
            $geocode = get_single('map', 'address_id', $address['address_id']);
예제 #3
0
 public function external_hook($hook)
 {
     switch ($hook) {
         case 'public_signup_form':
             $signup_form = module_template::get_template_by_key('customer_signup_form_wrapper');
             $signup_form->page_title = $signup_form->description;
             $signup_form->assign_values(array('signup_form' => self::get_customer_signup_form_html()));
             echo $signup_form->render('pretty_html');
             exit;
         case 'public_signup':
             // sign out if testing.
             if (module_security::is_logged_in()) {
                 set_message('Logged out due to signup');
                 module_security::logout();
             }
             $result = array('messages' => array());
             function customer_signup_complete($result)
             {
                 if (isset($_REQUEST['via_ajax'])) {
                     echo json_encode($result);
                 } else {
                     echo implode('<br/>', $result['messages']);
                 }
                 exit;
             }
             if (!module_config::c('customer_signup_allowed', 0)) {
                 $result['error'] = 1;
                 $result['messages'][] = 'Customer signup disabled';
                 customer_signup_complete($result);
             }
             //recaptcha on signup form.
             if (module_config::c('captcha_on_signup_form', 0)) {
                 if (!module_captcha::check_captcha_form()) {
                     $result['error'] = 1;
                     $result['messages'][] = 'Captcha fail, please go back and enter correct captcha code.';
                     customer_signup_complete($result);
                 }
             }
             $customer = isset($_POST['customer']) && is_array($_POST['customer']) ? $_POST['customer'] : array();
             $contact = isset($_POST['contact']) && is_array($_POST['contact']) ? $_POST['contact'] : array();
             $contact_extra = isset($contact['extra']) && is_array($contact['extra']) ? $contact['extra'] : array();
             $contact_group = isset($contact['group_ids']) && is_array($contact['group_ids']) ? $contact['group_ids'] : array();
             $customer_extra = isset($customer['extra']) ? $customer['extra'] : array();
             $customer_group = isset($customer['group_ids']) && is_array($customer['group_ids']) ? $customer['group_ids'] : array();
             $address = isset($_POST['address']) ? $_POST['address'] : array();
             $website = isset($_POST['website']) ? $_POST['website'] : array();
             $website_extra = isset($website['extra']) ? $website['extra'] : array();
             $website_group = isset($website['group_ids']) && is_array($website['group_ids']) ? $website['group_ids'] : array();
             $job = isset($_POST['job']) ? $_POST['job'] : array();
             $job_extra = isset($job['extra']) ? $job['extra'] : array();
             $subscription = isset($_POST['subscription']) ? $_POST['subscription'] : array();
             // sanatise possibly problematic fields:
             // customer:
             $allowed = array('name', 'last_name', 'customer_name', 'email', 'phone', 'mobile', 'extra', 'type');
             foreach ($customer as $key => $val) {
                 if (!in_array($key, $allowed)) {
                     unset($customer[$key]);
                 }
             }
             if (isset($customer['type']) && $customer['type'] != _CUSTOMER_TYPE_NORMAL && $customer['type'] != _CUSTOMER_TYPE_LEAD) {
                 unset($customer['type']);
             }
             // added multiple contact support in the form of arrays.
             $contact_fields = array('name', 'last_name', 'email', 'phone');
             if (module_config::c('customer_signup_password', 0)) {
                 $contact_fields[] = 'password';
             }
             foreach ($contact_fields as $multi_value) {
                 if (isset($contact[$multi_value])) {
                     if (!is_array($contact[$multi_value])) {
                         $contact[$multi_value] = array($contact[$multi_value]);
                     }
                 } else {
                     if (isset($customer[$multi_value])) {
                         $contact[$multi_value] = array($customer[$multi_value]);
                     } else {
                         $contact[$multi_value] = array();
                     }
                 }
             }
             $valid_contact_email = false;
             $name_fallback = false;
             $primary_email = false;
             foreach ($contact['email'] as $contact_key => $email) {
                 if (!$name_fallback && isset($contact['name'][$contact_key])) {
                     $name_fallback = $contact['name'][$contact_key];
                 }
                 $contact['email'][$contact_key] = filter_var(strtolower(trim($email)), FILTER_VALIDATE_EMAIL);
                 if ($contact['email'][$contact_key]) {
                     $valid_contact_email = true;
                     if (!$primary_email) {
                         $primary_email = $contact['email'][$contact_key];
                         // set the primary contact details here by adding them to the master customer array
                         foreach ($contact_fields as $primary_contact_field) {
                             $customer[$primary_contact_field] = isset($contact[$primary_contact_field][$contact_key]) ? $contact[$primary_contact_field][$contact_key] : '';
                             unset($contact[$primary_contact_field][$contact_key]);
                         }
                     }
                 }
             }
             // start error checking / required fields
             if (!isset($customer['customer_name']) || !strlen($customer['customer_name'])) {
                 $customer['customer_name'] = $name_fallback;
             }
             if (!strlen($customer['customer_name'])) {
                 $result['error'] = 1;
                 $result['messages'][] = "Failed, please go back and provide a customer name.";
             }
             if (!$valid_contact_email || !$primary_email) {
                 $result['error'] = 1;
                 $result['messages'][] = "Failed, please go back and provide an email address.";
             }
             // check all posted required fields.
             function check_required($postdata, $messages = array())
             {
                 if (is_array($postdata)) {
                     foreach ($postdata as $key => $val) {
                         if (strpos($key, '_required') && strlen($val)) {
                             $required_key = str_replace('_required', '', $key);
                             if (!isset($postdata[$required_key]) || !$postdata[$required_key]) {
                                 $messages[] = 'Required field missing: ' . htmlspecialchars($val);
                             }
                         }
                         if (is_array($val)) {
                             $messages = check_required($val, $messages);
                         }
                     }
                 }
                 return $messages;
             }
             $messages = check_required($_POST);
             if (count($messages)) {
                 $result['error'] = 1;
                 $result['messages'] = array_merge($result['messages'], $messages);
             }
             if (isset($result['error'])) {
                 customer_signup_complete($result);
             }
             // end error checking / required fields.
             // check if this customer already exists in the system, based on email address
             $customer_id = false;
             $creating_new = true;
             $_REQUEST['user_id'] = 0;
             if (isset($customer['email']) && strlen($customer['email']) && !module_config::c('customer_signup_always_new', 0)) {
                 $users = module_user::get_contacts(array('email' => $customer['email']));
                 foreach ($users as $user) {
                     if (isset($user['customer_id']) && (int) $user['customer_id'] > 0) {
                         // this user exists as a customer! yey!
                         // add them to this listing.
                         $customer_id = $user['customer_id'];
                         $creating_new = false;
                         $_REQUEST['user_id'] = $user['user_id'];
                         // dont let signups update existing passwords.
                         if (isset($customer['password'])) {
                             unset($customer['password']);
                         }
                         if (isset($customer['new_password'])) {
                             unset($customer['new_password']);
                         }
                     }
                 }
             }
             $_REQUEST['extra_customer_field'] = array();
             $_REQUEST['extra_user_field'] = array();
             module_extra::$config['allow_new_keys'] = false;
             module_extra::$config['delete_existing_empties'] = false;
             // save customer extra fields.
             if (count($customer_extra)) {
                 // format the address so "save_customer" handles the save for us
                 foreach ($customer_extra as $key => $val) {
                     $_REQUEST['extra_customer_field'][] = array('key' => $key, 'val' => $val);
                 }
             }
             // save customer and customer contact details:
             $customer_id = $this->save_customer($customer_id, $customer);
             if (!$customer_id) {
                 $result['error'] = 1;
                 $result['messages'][] = 'System error: failed to create customer.';
                 customer_signup_complete($result);
             }
             $customer_data = module_customer::get_customer($customer_id);
             // todo - merge primary and secondary contact/extra/group saving into a single loop
             if (!$customer_data['primary_user_id']) {
                 $result['error'] = 1;
                 $result['messages'][] = 'System error: Failed to create customer contact.';
                 customer_signup_complete($result);
             } else {
                 $role_id = module_config::c('customer_signup_role', 0);
                 if ($role_id > 0) {
                     module_user::add_user_to_role($customer_data['primary_user_id'], $role_id);
                 }
                 // save contact extra data (repeated below for additional contacts)
                 if (isset($contact_extra[0]) && count($contact_extra[0])) {
                     $_REQUEST['extra_user_field'] = array();
                     foreach ($contact_extra[0] as $key => $val) {
                         $_REQUEST['extra_user_field'][] = array('key' => $key, 'val' => $val);
                     }
                     module_extra::save_extras('user', 'user_id', $customer_data['primary_user_id']);
                 }
                 // save contact groups
                 if (isset($contact_group[0]) && count($contact_group[0])) {
                     foreach ($contact_group[0] as $group_id => $tf) {
                         if ($tf) {
                             module_group::add_to_group($group_id, $customer_data['primary_user_id'], 'user');
                         }
                     }
                 }
             }
             foreach ($contact['email'] as $contact_key => $email) {
                 // add any additional contacts to the customer.
                 $users = module_user::get_contacts(array('email' => $email, 'customer_id' => $customer_id));
                 if (count($users)) {
                     // this contact already exists for this customer, dont update/change it.
                     continue;
                 }
                 $new_contact = array('customer_id' => $customer_id);
                 foreach ($contact_fields as $primary_contact_field) {
                     $new_contact[$primary_contact_field] = isset($contact[$primary_contact_field][$contact_key]) ? $contact[$primary_contact_field][$contact_key] : '';
                 }
                 // dont let additional contacts have passwords.
                 if (isset($new_contact['password'])) {
                     unset($new_contact['password']);
                 }
                 if (isset($new_contact['new_password'])) {
                     unset($new_contact['new_password']);
                 }
                 global $plugins;
                 $contact_user_id = $plugins['user']->create_user($new_contact, 'signup');
                 if ($contact_user_id) {
                     $role_id = module_config::c('customer_signup_role', 0);
                     if ($role_id > 0) {
                         module_user::add_user_to_role($contact_user_id, $role_id);
                     }
                     // save contact extra data  (repeated below for primary contacts)
                     if (isset($contact_extra[$contact_key]) && count($contact_extra[$contact_key])) {
                         $_REQUEST['extra_user_field'] = array();
                         foreach ($contact_extra[$contact_key] as $key => $val) {
                             $_REQUEST['extra_user_field'][] = array('key' => $key, 'val' => $val);
                         }
                         module_extra::save_extras('user', 'user_id', $contact_user_id);
                     }
                     // save contact groups
                     if (isset($contact_group[$contact_key]) && count($contact_group[$contact_key])) {
                         foreach ($contact_group[$contact_key] as $group_id => $tf) {
                             if ($tf) {
                                 module_group::add_to_group($group_id, $contact_user_id, 'user');
                             }
                         }
                     }
                 }
             }
             if (count($customer_group)) {
                 // format the address so "save_customer" handles the save for us
                 foreach ($customer_group as $group_id => $tf) {
                     if ($tf) {
                         module_group::add_to_group($group_id, $customer_id, 'customer');
                     }
                 }
             }
             $note_keys = array('customer', 'website', 'job', 'address', 'subscription');
             $note_text = _l('Customer signed up from Signup Form:');
             $note_text .= "\n\n";
             foreach ($note_keys as $note_key) {
                 $note_text .= "\n" . ucwords(_l($note_key)) . "\n";
                 if (isset($_POST[$note_key]) && is_array($_POST[$note_key])) {
                     foreach ($_POST[$note_key] as $post_key => $post_val) {
                         $note_text .= "\n - " . _l($post_key) . ": ";
                         if (is_array($post_val)) {
                             foreach ($post_val as $p => $v) {
                                 $note_text .= "\n  - - " . _l($p) . ': ' . $v;
                             }
                         } else {
                             $note_text .= $post_val;
                         }
                     }
                 }
             }
             $note_data = array('note_id' => false, 'owner_id' => $customer_id, 'owner_table' => 'customer', 'note_time' => time(), 'note' => $note_text, 'rel_data' => module_customer::link_open($customer_id), 'reminder' => 0, 'user_id' => 0);
             update_insert('note_id', false, 'note', $note_data);
             // save customer address fields.
             if (count($address)) {
                 $address_db = module_address::get_address($customer_id, 'customer', 'physical');
                 $address_id = $address_db && isset($address_db['address_id']) ? (int) $address_db['address_id'] : false;
                 $address['owner_id'] = $customer_id;
                 $address['owner_table'] = 'customer';
                 $address['address_type'] = 'physical';
                 // we have post data to save, write it to the table!!
                 module_address::save_address($address_id, $address);
             }
             // website:
             $allowed = array('url', 'name', 'extra', 'notes');
             foreach ($website as $key => $val) {
                 if (!in_array($key, $allowed)) {
                     unset($website[$key]);
                 }
             }
             $website['url'] = isset($website['url']) ? strtolower(trim($website['url'])) : '';
             $website_id = 0;
             if (count($website) && class_exists('module_website', false) && module_website::is_plugin_enabled()) {
                 if (strlen($website['url'])) {
                     // see if website already exists, don't create or update existing one for now.
                     $existing_websites = module_website::get_websites(array('customer_id' => $customer_id, 'url' => $website['url']));
                     foreach ($existing_websites as $existing_website) {
                         $website_id = $existing_website['website_id'];
                     }
                 }
                 //   echo $website_id;echo $website['url']; print_r($website_extra);exit;
                 if (!$website_id) {
                     $website_data = module_website::get_website($website_id);
                     $website_data['url'] = isset($website['url']) ? $website['url'] : 'N/A';
                     $website_data['name'] = isset($website['url']) ? $website['url'] : 'N/A';
                     $website_data['customer_id'] = $customer_id;
                     $website_id = update_insert('website_id', false, 'website', $website_data);
                     // save website extra data.
                     if ($website_id && count($website_extra)) {
                         $_REQUEST['extra_website_field'] = array();
                         foreach ($website_extra as $key => $val) {
                             $_REQUEST['extra_website_field'][] = array('key' => $key, 'val' => $val);
                         }
                         module_extra::save_extras('website', 'website_id', $website_id);
                     }
                     if ($website_id && isset($website['notes']) && strlen($website['notes'])) {
                         // add notes to this website.
                         $note_data = array('note_id' => false, 'owner_id' => $website_id, 'owner_table' => 'website', 'note_time' => time(), 'note' => $website['notes'], 'rel_data' => module_website::link_open($website_id), 'reminder' => 0, 'user_id' => $customer_data['primary_user_id']);
                         $note_id = update_insert('note_id', false, 'note', $note_data);
                     }
                 }
                 if ($website_id) {
                     if (count($website_group)) {
                         // format the address so "save_customer" handles the save for us
                         foreach ($website_group as $group_id => $tf) {
                             if ($tf) {
                                 module_group::add_to_group($group_id, $website_id, 'website');
                             }
                         }
                     }
                 }
             }
             // generate jobs for this customer.
             $job_created = array();
             if ($job && isset($job['type']) && is_array($job['type'])) {
                 if (module_config::c('customer_signup_any_job_type', 0)) {
                     foreach ($job['type'] as $type_name) {
                         // we have a match in our system. create the job.
                         $job_data = module_job::get_job(false);
                         $job_data['type'] = $type_name;
                         if (!$job_data['name']) {
                             $job_data['name'] = $type_name;
                         }
                         $job_data['website_id'] = $website_id;
                         $job_data['customer_id'] = $customer_id;
                         $job_id = update_insert('job_id', false, 'job', $job_data);
                         // todo: add default tasks for this job type.
                         $job_created[] = $job_id;
                     }
                 } else {
                     foreach (module_job::get_types() as $type_id => $type) {
                         foreach ($job['type'] as $type_name) {
                             if ($type_name == $type) {
                                 // we have a match in our system. create the job.
                                 $job_data = module_job::get_job(false);
                                 $job_data['type'] = $type;
                                 if (!$job_data['name']) {
                                     $job_data['name'] = $type;
                                 }
                                 $job_data['website_id'] = $website_id;
                                 $job_data['customer_id'] = $customer_id;
                                 $job_id = update_insert('job_id', false, 'job', $job_data);
                                 // todo: add default tasks for this job type.
                                 $job_created[] = $job_id;
                             }
                         }
                     }
                 }
                 if (count($job_created) && count($job_extra)) {
                     // save job extra data.
                     foreach ($job_created as $job_created_id) {
                         if ($job_created_id && count($job_extra)) {
                             $_REQUEST['extra_job_field'] = array();
                             foreach ($job_extra as $key => $val) {
                                 $_REQUEST['extra_job_field'][] = array('key' => $key, 'val' => $val);
                             }
                             module_extra::save_extras('job', 'job_id', $job_created_id);
                         }
                     }
                 }
             }
             // save files against customer
             $uploaded_files = array();
             if (isset($_FILES['customerfiles']) && isset($_FILES['customerfiles']['tmp_name'])) {
                 foreach ($_FILES['customerfiles']['tmp_name'] as $file_id => $tmp_file) {
                     if (is_uploaded_file($tmp_file)) {
                         // save to file module for this customer
                         $file_name = basename($_FILES['customerfiles']['name'][$file_id]);
                         if (strlen($file_name)) {
                             $file_path = 'includes/plugin_file/upload/' . md5(time() . $file_name);
                             if (move_uploaded_file($tmp_file, $file_path)) {
                                 // success! write to db.
                                 $file_data = array('customer_id' => $customer_id, 'job_id' => current($job_created), 'website_id' => $website_id, 'status' => module_config::c('file_default_status', 'Uploaded'), 'pointers' => false, 'description' => "Uploaded from Customer Signup form", 'file_time' => time(), 'file_name' => $file_name, 'file_path' => $file_path, 'file_url' => false);
                                 $file_id = update_insert('file_id', false, 'file', $file_data);
                                 $uploaded_files[] = $file_id;
                             }
                         }
                     }
                 }
             }
             // we create subscriptions for this customer/website (if none already exist)
             $subscription['subscription_name'] = array();
             $subscription['subscription_invoice'] = array();
             if (class_exists('module_subscription', false) && module_subscription::is_plugin_enabled() && isset($subscription['for']) && isset($subscription['subscriptions'])) {
                 if ($subscription['for'] == 'website' && $website_id > 0) {
                     $owner_table = 'website';
                     $owner_id = $website_id;
                 } else {
                     $owner_table = 'customer';
                     $owner_id = $customer_id;
                 }
                 $available_subscriptions = module_subscription::get_subscriptions();
                 $members_subscriptions = module_subscription::get_subscriptions_by($owner_table, $owner_id);
                 foreach ($subscription['subscriptions'] as $subscription_id => $tf) {
                     if (isset($available_subscriptions[$subscription_id])) {
                         if (isset($members_subscriptions[$subscription_id])) {
                             // we don't allow a member to sign up to the same subscription twice (just yet)
                         } else {
                             $subscription['subscription_name'][$subscription_id] = $available_subscriptions[$subscription_id]['name'];
                             $start_date = date('Y-m-d');
                             $start_modifications = module_config::c('customer_signup_subscription_start', '');
                             if ($start_modifications == 'hidden') {
                                 $start_modifications = isset($_REQUEST['customer_signup_subscription_start']) ? $_REQUEST['customer_signup_subscription_start'] : '';
                             }
                             if (!empty($start_modifications)) {
                                 $start_date = date('Y-m-d', strtotime($start_modifications));
                             }
                             $sql = "INSERT INTO `" . _DB_PREFIX . "subscription_owner` SET ";
                             $sql .= " owner_id = '" . (int) $owner_id . "'";
                             $sql .= ", owner_table = '" . mysql_real_escape_string($owner_table) . "'";
                             $sql .= ", subscription_id = '" . (int) $subscription_id . "'";
                             $sql .= ", start_date = '{$start_date}'";
                             query($sql);
                             module_subscription::update_next_due_date($subscription_id, $owner_table, $owner_id, true);
                             // and the same option here to send a subscription straight away upon signup
                             if (module_config::c('subscription_send_invoice_straight_away', 0)) {
                                 global $plugins;
                                 $plugins['subscription']->run_cron();
                                 // check if there are any invoices for this subscription
                                 $history = module_subscription::get_subscription_history($subscription_id, $owner_table, $owner_id);
                                 if (count($history) > 0) {
                                     foreach ($history as $h) {
                                         if ($h['invoice_id']) {
                                             $invoice_data = module_invoice::get_invoice($h['invoice_id']);
                                             if ($invoice_data['date_cancel'] != '0000-00-00') {
                                                 continue;
                                             }
                                             $subscription['subscription_invoice'][] = '<a href="' . module_invoice::link_public($h['invoice_id']) . '">' . _l('Invoice #%s for %s', htmlspecialchars($invoice_data['name']), dollar($invoice_data['total_amount'], true, $invoice_data['currency_id'])) . '</a>';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (!count($subscription['subscription_name'])) {
                 $subscription['subscription_name'][] = _l('N/A');
             }
             if (!count($subscription['subscription_invoice'])) {
                 $subscription['subscription_invoice'][] = _l('N/A');
             }
             $subscription['subscription_name'] = implode(', ', $subscription['subscription_name']);
             $subscription['subscription_invoice'] = implode(', ', $subscription['subscription_invoice']);
             // email the admin when a customer signs up.
             $values = array_merge($customer, $customer_extra, $website, $website_extra, $address, $subscription);
             $values['customer_name'] = $customer['customer_name'];
             $values['CUSTOMER_LINK'] = module_customer::link_open($customer_id);
             $values['CUSTOMER_NAME_LINK'] = module_customer::link_open($customer_id, true);
             if ($website_id) {
                 $values['WEBSITE_LINK'] = module_website::link_open($website_id);
                 $values['WEBSITE_NAME_LINK'] = module_website::link_open($website_id, true);
             } else {
                 $values['WEBSITE_LINK'] = _l('N/A');
                 $values['WEBSITE_NAME_LINK'] = _l('N/A');
             }
             $values['JOB_LINKS'] = '';
             if (count($job_created)) {
                 $values['JOB_LINKS'] .= 'The customer created ' . count($job_created) . ' jobs in the system: <br>';
                 foreach ($job_created as $job_created_id) {
                     $values['JOB_LINKS'] .= module_job::link_open($job_created_id, true) . "<br>\n";
                 }
             } else {
                 $values['JOB_LINKS'] = _l('N/A');
             }
             if (count($uploaded_files)) {
                 $values['uploaded_files'] = 'The customer uploaded ' . count($uploaded_files) . " files:<br>\n";
                 foreach ($uploaded_files as $uploaded_file) {
                     $values['uploaded_files'] .= module_file::link_open($uploaded_file, true) . "<br>\n";
                 }
             } else {
                 $values['uploaded_files'] = 'No files were uploaded';
             }
             $values['WEBSITE_NAME'] = isset($website['url']) ? $website['url'] : 'N/A';
             if (!$creating_new) {
                 $values['system_note'] = "Note: this signup updated the existing customer record in the system.";
             } else {
                 $values['system_note'] = "Note: this signup created a new customer record in the system.";
             }
             $customer_signup_template = module_config::c('customer_signup_email_admin_template', 'customer_signup_email_admin');
             if (isset($_REQUEST['customer_signup_email_admin_template'])) {
                 $customer_signup_template = $_REQUEST['customer_signup_email_admin_template'];
             }
             if ($customer_signup_template) {
                 $template = module_template::get_template_by_key($customer_signup_template);
                 if ($template->template_id) {
                     $template->assign_values($values);
                     $html = $template->render('html');
                     $email = module_email::new_email();
                     $email->replace_values = $values;
                     $email->set_subject($template->description);
                     $email->set_to_manual(module_config::c('customer_signup_admin_email', module_config::c('admin_email_address')));
                     // do we send images inline?
                     $email->set_html($html);
                     if ($email->send()) {
                         // it worked successfully!!
                     } else {
                         /// log err?
                     }
                 }
             }
             $customer_signup_template = module_config::c('customer_signup_email_welcome_template', 'customer_signup_email_welcome');
             if (isset($_REQUEST['customer_signup_email_welcome_template'])) {
                 $customer_signup_template = $_REQUEST['customer_signup_email_welcome_template'];
             }
             if ($customer_signup_template) {
                 $template = module_template::get_template_by_key($customer_signup_template);
                 if ($template->template_id) {
                     $template->assign_values($values);
                     $html = $template->render('html');
                     $email = module_email::new_email();
                     $email->customer_id = $customer_id;
                     $email->replace_values = $values;
                     $email->set_subject($template->description);
                     $email->set_to('user', $customer_data['primary_user_id']);
                     // do we send images inline?
                     $email->set_html($html);
                     if ($email->send()) {
                         // it worked successfully!!
                     } else {
                         /// log err?
                     }
                 }
             }
             //todo: optional redirect to url
             if (isset($_REQUEST['via_ajax'])) {
                 echo json_encode(array('success' => 1, 'customer_id' => $customer_id));
                 exit;
             }
             if (module_config::c('customer_signup_redirect', '')) {
                 redirect_browser(module_config::c('customer_signup_redirect', ''));
             }
             // load up the thank you template.
             $template = module_template::get_template_by_key('customer_signup_thank_you_page');
             $template->page_title = _l("Customer Signup");
             foreach ($values as $key => $val) {
                 if (!is_array($val)) {
                     $values[$key] = htmlspecialchars($val);
                 }
             }
             $template->assign_values($values);
             echo $template->render('pretty_html');
             exit;
             break;
     }
 }
예제 #4
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
 */
// load the address they're trying to access.
$address_id = isset($_REQUEST['address_id']) && (int) $_REQUEST['address_id'] ? (int) $_REQUEST['address_id'] : false;
if ($address_id) {
    $address_data = module_address::get_address_by_id($address_id);
    // load the form using the normal module callback.
    // todo - move this into a static method call instead of all the complicated hooks with optional parameters.
    //module_address::print_address_form($address_id);
    // do a form as well.
    ?>
	<form action="<?php 
    echo $module->link();
    ?>
" method="post">
	<input type="hidden" name="_process" value="save_from_popup">
	<input type="hidden" name="_redirect" class="redirect" value="">
	<?php 
    handle_hook("address_block", $module, $address_data['address_type'], $address_data['owner_table'], false, $address_data['owner_id']);
    ?>
	</form>
	<?php 
예제 #5
0
                return;
            } else {
                ?>

                Fatal contact linking error. Sorry I rushed this feature!
                <?php 
            }
        }
    }
}
hook_handle_callback('layout_column_half', 1);
$hide_more_button = true;
$title = 'Contact Details';
include module_theme::include_ucm('includes/plugin_user/pages/contact_admin_form.php');
if (class_exists('module_address', false) && module_config::c('users_have_address', 0)) {
    module_address::print_address_form($user_id, 'user', 'physical', 'Address');
}
?>



    <?php 
if ((int) $user_id > 0 && module_user::can_i('edit', 'Contacts', $contact_type) && strlen($user['email']) > 2 && $use_master_key == 'customer_id') {
    // check if contact exists under other customer accounts.
    $others = module_user::get_contacts(array('email' => $user['email'], "{$contact_module_name}_id" => 0));
    if (count($others) > 1) {
        foreach ($others as $other_id => $other) {
            if ($other['user_id'] == $user['user_id']) {
                // this "other" person is from teh same customer as us.
                unset($others[$other_id]);
            } else {
예제 #6
0
            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']);
        }
    }
} 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($vendor_id, 'vendor', 'physical', 'Address');
}
/** ADVANCED AREA **/
/*
    $fieldset_data = array(
        'heading' => array(
            'type' => 'h3',
            'title' => 'Advanced',
        ),
        'class' => 'tableclass tableclass_form tableclass_full',
        'elements' => array(),
    );

    if(module_vendor::can_i('edit','Vendor Credit')){
        $fieldset_data['elements']['credit'] = array(
            'title' => _l('Credit'),
예제 #7
0
$columns['phone_number'] = array('title' => 'Phone Number', 'callback' => function ($vendor) {
    if ($vendor['primary_user_id']) {
        module_user::print_contact_summary($vendor['primary_user_id'], 'html', array('phone|mobile'));
    } else {
        echo '';
    }
});
$columns['primary_contact_email'] = array('title' => 'Email Address', 'callback' => function ($vendor) {
    if ($vendor['primary_user_id']) {
        module_user::print_contact_summary($vendor['primary_user_id'], 'html', array('email'));
    } else {
        echo '';
    }
});
$columns['address'] = array('title' => 'Address', 'callback' => function ($vendor) {
    module_address::print_address($vendor['vendor_id'], 'vendor', 'physical');
});
if (class_exists('module_group', false) && module_vendor::can_i('view', $page_type_single . ' Groups')) {
    $columns['vendor_group'] = array('title' => 'Group', 'callback' => function ($vendor) {
        if (isset($vendor['group_sort_vendor'])) {
            echo htmlspecialchars($vendor['group_sort_vendor']);
        } else {
            // find the groups for this vendor.
            $groups = module_group::get_groups_search(array('owner_table' => 'vendor', 'owner_id' => $vendor['vendor_id']));
            $g = array();
            foreach ($groups as $group) {
                $g[] = $group['name'];
            }
            echo htmlspecialchars(implode(', ', $g));
        }
    });
예제 #8
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 vendors by their "vendor_name" (required field)
     // and then we assign that vendor_id to the import data.
     // our second loop through if there is a vendor_id we overwrite that existing vendor with the import data (ignoring blanks).
     // if there is no vendor id we create a new vendor record :) awesome.
     foreach ($data as $rowid => $row) {
         if (!isset($row['vendor_name']) || !trim($row['vendor_name'])) {
             unset($data[$rowid]);
             continue;
         }
         if (!isset($row['vendor_id']) || !$row['vendor_id']) {
             $data[$rowid]['vendor_id'] = 0;
         }
     }
     // now save the data.
     foreach ($data as $rowid => $row) {
         //module_cache::clear_cache();
         $vendor_id = isset($row['vendor_id']) ? (int) $row['vendor_id'] : 0;
         // check if this ID exists.
         if ($vendor_id > 0) {
             $vendor = self::get_vendor($vendor_id);
             if (!$vendor || !isset($vendor['vendor_id']) || $vendor['vendor_id'] != $vendor_id) {
                 $vendor_id = 0;
             }
         }
         if (!$vendor_id) {
             // search for a custoemr based on name.
             $vendor = get_single('vendor', 'vendor_name', $row['vendor_name']);
             //print_r($row); print_r($vendor);echo '<hr>';
             if ($vendor && $vendor['vendor_id'] > 0) {
                 $vendor_id = $vendor['vendor_id'];
             }
         }
         $vendor_id = update_insert("vendor_id", $vendor_id, "vendor", $row);
         // 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('vendor_id' => $vendor_id));
         $user_match = 0;
         foreach ($users as $user) {
             if ($user['name'] == $row['primary_user_name']) {
                 $user_match = $user['user_id'];
                 break;
             }
         }
         $user_update = array('vendor_id' => $vendor_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($vendor_id, $user_match);
         // do a hack to save address.
         $existing_address = module_address::get_address($vendor_id, 'vendor', 'physical');
         $address_id = $existing_address && isset($existing_address['address_id']) ? (int) $existing_address['address_id'] : 'new';
         $address = array_merge($row, array('owner_id' => $vendor_id, 'owner_table' => 'vendor', '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, $vendor_id, 'vendor');
         }
         // 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 vendor 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 = 'vendor' AND `extra_key` != '' GROUP BY `extra_key` ORDER BY `extra_key`";
             $vendor_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($vendor_fields[$extra_key])) {
                     // this is a vendor extra field.
                     $existing_extra = module_extra::get_extras(array('owner_table' => 'vendor', 'owner_id' => $vendor_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' => 'vendor', 'owner_id' => $vendor_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);
                     }
                 }
             }
         }
     }
 }
예제 #9
0
            if ($customer['primary_user_id']) {
                $fieldset_data['heading']['button'] = array('title' => 'More', 'url' => module_user::link_open_contact($customer['primary_user_id'], false));
            }
            echo module_form::generate_fieldset($fieldset_data);
            unset($fieldset_data);
        } else {
            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()) {
예제 #10
0
 public static function multisafepay_redirect($description, $amount, $user_id, $payment_id, $invoice_id, $currency_id)
 {
     $currency = module_config::get_currency($currency_id);
     if ($currency['code'] != 'EUR') {
         echo "Multisafepay only accepts currency in EUR";
     }
     include 'MultiSafepay.combined.php';
     $msp = new MultiSafepay();
     /*
      * Merchant Settings
      */
     $msp->test = self::is_sandbox();
     $msp->merchant['account_id'] = module_config::c('payment_method_multisafepay_account', '');
     $msp->merchant['site_id'] = module_config::c('payment_method_multisafepay_site_id', '');
     $msp->merchant['site_code'] = module_config::c('payment_method_multisafepay_side_code', '');
     $msp->merchant['notification_url'] = full_link(_EXTERNAL_TUNNEL . '?m=paymethod_multisafepay&h=ipn&method=multisafepay&type=initial');
     $msp->merchant['cancel_url'] = module_invoice::link_public($invoice_id);
     // optional automatic redirect back to the shop:
     $msp->merchant['redirect_url'] = module_invoice::link_public($invoice_id);
     /*
      * Customer Details
      */
     $invoice = $invoice_data = module_invoice::get_invoice($invoice_id);
     $customer = module_customer::get_customer($invoice_data['customer_id'], true);
     if (!$user_id) {
         $user_id = $customer['primary_user_id'];
     }
     $user = module_user::get_user($user_id, false);
     //$msp->customer['locale']           = 'nl';
     $msp->customer['firstname'] = $user['name'];
     $msp->customer['lastname'] = $user['last_name'];
     $address = module_address::get_address($invoice_data['customer_id'], 'customer', 'physical');
     $msp->customer['zipcode'] = isset($address['post_code']) ? $address['post_code'] : '';
     $msp->customer['city'] = isset($address['region']) ? $address['region'] : '';
     $msp->customer['country'] = isset($address['country']) ? $address['country'] : module_config::c('payment_method_multisafepay_country', '');
     $msp->customer['phone'] = $user['phone'];
     $msp->customer['email'] = $user['email'];
     $msp->parseCustomerAddress(isset($address['line_1']) ? $address['line_1'] : '');
     // or
     // $msp->customer['address1']         = 'Teststraat';
     // $msp->customer['housenumber']      = '21';
     /*
      * Transaction Details
      */
     $msp->transaction['id'] = self::multisafepay_custom($user_id, $payment_id, $invoice_id);
     $msp->transaction['currency'] = $currency['code'];
     $msp->transaction['amount'] = $amount * 100;
     // cents
     $msp->transaction['description'] = $description;
     $msp->transaction['items'] = '<br/><ul>';
     // copied from invoice_task_list.php
     foreach (module_invoice::get_invoice_items($invoice_id) as $invoice_item_id => $invoice_item_data) {
         // copy any changes here to template/invoice_task_list.php
         $task_hourly_rate = isset($invoice_item_data['hourly_rate']) && $invoice_item_data['hourly_rate'] != 0 ? $invoice_item_data['hourly_rate'] : $invoice_data['hourly_rate'];
         // if there are no hours logged against this task
         if (!$invoice_item_data['hours']) {
             //$task_hourly_rate=0;
         }
         // if we have a custom price for this task
         if ($invoice_item_data['amount'] != 0 && $invoice_item_data['amount'] != $invoice_item_data['hours'] * $task_hourly_rate) {
             $invoice_item_amount = $invoice_item_data['amount'];
             $task_hourly_rate = false;
         } else {
             if ($invoice_item_data['hours'] > 0) {
                 $invoice_item_amount = $invoice_item_data['hours'] * $task_hourly_rate;
             } else {
                 $invoice_item_amount = 0;
                 $task_hourly_rate = false;
             }
         }
         $msp->transaction['items'] .= '<li>';
         $msp->transaction['items'] .= $invoice_item_data['hours'] > 0 ? $invoice_item_data['hours'] . ' x ' : '';
         $msp->transaction['items'] .= $invoice_item_data['custom_description'] ? htmlspecialchars($invoice_item_data['custom_description']) : htmlspecialchars($invoice_item_data['description']);
         $msp->transaction['items'] .= ' = ' . dollar($invoice_item_amount, true, $invoice['currency_id']);
         $msp->transaction['items'] .= '</li>';
     }
     $msp->transaction['items'] .= '<li>Sub Total: ' . dollar($invoice_data['total_sub_amount'], true, $invoice_data['currency_id']) . '</li>';
     if ($invoice_data['total_tax_rate'] > 0) {
         $msp->transaction['items'] .= '<li>' . $invoice['total_tax_name'] . ' ' . $invoice['total_tax_rate'] . '% = ' . dollar($invoice['total_tax'], true, $invoice['currency_id']) . '</li>';
     }
     $msp->transaction['items'] .= '<li>Total: ' . dollar($invoice['total_amount'], true, $invoice['currency_id']) . '</li>';
     $msp->transaction['items'] .= '</ul>';
     // returns a payment url
     $url = $msp->startTransaction();
     if ($msp->error) {
         echo "Error " . $msp->error_code . ": " . $msp->error;
         exit;
     }
     // redirect
     redirect_browser($url);
     /*
             $url = 'https://www.'. (self::is_sandbox()? 'sandbox.' : '') . 'multisafepay.com/cgi-bin/webscr?';
     
             $fields = array(
                 'cmd' => '_xclick',
                 'business' => module_config::c('payment_method_multisafepay_email',_ERROR_EMAIL),
                 'currency_code' => $currency['code'],
                 'item_name' => $description,
                 'amount' => $amount,
                 'return' => module_invoice::link_open($invoice_id),
                 'notify_url' => full_link(_EXTERNAL_TUNNEL.'?m=paymethod_multisafepay&h=ipn&method=multisafepay'),
                 'custom' => self::multisafepay_custom($user_id,$payment_id,$invoice_id),
             );
     
             foreach($fields as $key=>$val){
                 $url .= $key.'='.urlencode($val).'&';
             }
     
             //echo '<a href="'.$url.'">'.$url.'</a>';exit;
     
             redirect_browser($url);
     */
 }
예제 #11
0
            $alert['subject'] = $alert[1];
        }
        if (!isset($alert['link'])) {
            $alert['link'] = $alert[12];
        }
        if (!isset($alert['other_details'])) {
            $alert['other_details'] = $alert[11];
        }
        //	    print_r($alert);
        $time = strtotime($timezone_hours . ' hours', $alert['start_time']);
        // work out the UTC time for this event, based on the timezome we have set in the configuration options
        /*DTSTART;VALUE=DATE:'.date('Ymd',$time).'
        DTEND;VALUE=DATE:'.date('Ymd',strtotime('+1 day',$time)).'*/
        if (!empty($alert['customer_id'])) {
            // grab customers address.
            $address = module_address::get_address($alert['customer_id'], 'customer', 'physical', true);
            $alert['location'] = implode(', ', $address);
        }
        if (0 < $alert['start_time']) {
            if (isset($alert['all_day']) && $alert['all_day'] || $alert[4]) {
                $end = isset($alert['end_time']) ? date('Ymd', strtotime('+1 day', $alert['end_time'])) : date('Ymd', strtotime('+1 day', $alert['start_time']));
                // it's an all day event.
                echo 'BEGIN:VEVENT
UID:' . md5($alert['subject'] . $alert['link'] . $alert['other_details']) . '@ultimateclientmanager.com
DTSTAMP:' . date('Ymd\\THis', time()) . '
DTSTART;VALUE=DATE:' . date('Ymd', $alert['start_time']) . '
DTEND;VALUE=DATE:' . $end . '
SUMMARY:' . $alert['subject'] . '
LOCATION:' . (isset($alert['location']) ? $alert['location'] : '') . '
DESCRIPTION: Customer:' . $alert['link'] . "<br />" . $alert['other_details'] . '
END:VEVENT