public static function add_history($invoice_id, $message) { if (class_exists('module_note', false) && module_note::is_plugin_enabled()) { module_note::save_note(array('owner_table' => 'invoice', 'owner_id' => $invoice_id, 'note' => $message, 'rel_data' => self::link_open($invoice_id), 'note_time' => time())); } }
public static function add_history($customer_id, $message) { if (class_exists('module_note', false)) { module_note::save_note(array('owner_table' => 'customer', 'owner_id' => $customer_id, 'note' => $message, 'rel_data' => self::link_open($customer_id), 'note_time' => time())); } }
public static function add_history($job_id, $message) { module_note::save_note(array('owner_table' => 'job', 'owner_id' => $job_id, 'note' => $message, 'rel_data' => self::link_open($job_id), 'note_time' => time())); }
public static function handle_import_row($row, $debug, $add_to_group, $extra_options) { $debug_string = ''; if (!isset($row['name'])) { $row['name'] = ''; } if (!isset($row['url'])) { $row['url'] = ''; } if (isset($row['website_id']) && (int) $row['website_id'] > 0) { // check if this ID exists. $website = self::get_website($row['website_id']); if (!$website || $website['website_id'] != $row['website_id']) { $row['website_id'] = 0; } } if (!isset($row['website_id']) || !$row['website_id']) { $row['website_id'] = 0; } if (isset($row['name']) && strlen(trim($row['name']))) { // we have a website name! // search for a website based on name. $website = get_single('website', 'name', $row['name']); if ($website && $website['website_id'] > 0) { $row['website_id'] = $website['website_id']; } } else { if (isset($row['url'])) { $row['name'] = $row['url']; } } if (!$row['website_id'] && isset($row['url']) && strlen(trim($row['url']))) { // we have a url! find a match too. $website = get_single('website', 'url', $row['url']); if ($website && $website['website_id'] > 0) { $row['website_id'] = $website['website_id']; } } if (!strlen($row['name']) && !strlen($row['url'])) { $debug_string .= _l('No website data to import'); if ($debug) { echo $debug_string; } return false; } // duplicates. //print_r($extra_options);exit; if (isset($extra_options['duplicates']) && $extra_options['duplicates'] == 'ignore' && (int) $row['website_id'] > 0) { if ($debug) { $debug_string .= _l('Skipping import, duplicate of website %s', self::link_open($row['website_id'], true)); echo $debug_string; } // don't import duplicates return false; } $row['customer_id'] = 0; // todo - support importing of this id? nah if (isset($row['customer_name']) && strlen(trim($row['customer_name'])) > 0) { // check if this customer exists. $customer = get_single('customer', 'customer_name', $row['customer_name']); if ($customer && $customer['customer_id'] > 0) { $row['customer_id'] = $customer['customer_id']; $debug_string .= _l('Linked to customer %s', module_customer::link_open($row['customer_id'], true)) . ' '; } else { $debug_string .= _l('Create new customer: %s', htmlspecialchars($row['customer_name'])) . ' '; } } else { $debug_string .= _l('No customer') . ' '; } if ($row['website_id']) { $debug_string .= _l('Replace existing website: %s', self::link_open($row['website_id'], true)) . ' '; } else { $debug_string .= _l('Insert new website: %s', htmlspecialchars($row['url'])) . ' '; } $customer_primary_user_id = 0; if ($row['customer_id'] > 0 && isset($row['customer_contact_email']) && strlen(trim($row['customer_contact_email']))) { $users = module_user::get_users(array('customer_id' => $row['customer_id'] > 0)); foreach ($users as $user) { if (strtolower(trim($user['email'])) == strtolower(trim($row['customer_contact_email']))) { $customer_primary_user_id = $user['user_id']; $debug_string .= _l('Customer primary contact is: %s', module_user::link_open_contact($customer_primary_user_id, true)) . ' '; break; } } } if ($debug) { echo $debug_string; return true; } if (isset($extra_options['duplicates']) && $extra_options['duplicates'] == 'ignore' && $row['customer_id'] > 0) { // don't update customer record with new one. } else { if (isset($row['customer_name']) && strlen(trim($row['customer_name'])) > 0 || $row['customer_id'] > 0) { // update customer record with new one. $row['customer_id'] = update_insert('customer_id', $row['customer_id'], 'customer', $row); if (isset($row['customer_contact_fname']) || isset($row['customer_contact_email'])) { $data = array('customer_id' => $row['customer_id']); if (isset($row['customer_contact_fname'])) { $data['name'] = $row['customer_contact_fname']; } if (isset($row['customer_contact_lname'])) { $data['last_name'] = $row['customer_contact_lname']; } if (isset($row['customer_contact_email'])) { $data['email'] = $row['customer_contact_email']; } if (isset($row['customer_contact_phone'])) { $data['phone'] = $row['customer_contact_phone']; } $customer_primary_user_id = update_insert("user_id", $customer_primary_user_id, "user", $data); module_customer::set_primary_user_id($row['customer_id'], $customer_primary_user_id); } } } $website_id = (int) $row['website_id']; // check if this ID exists. $website = self::get_website($website_id); if (!$website || $website['website_id'] != $website_id) { $website_id = 0; } $website_id = update_insert("website_id", $website_id, "website", $row); // 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' => 'website', 'owner_id' => $website_id, 'note' => trim($row['notes']), 'note_time' => time())); } } // 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) { foreach ($extra as $extra_key => $extra_val) { // does this one exist? $existing_extra = module_extra::get_extras(array('owner_table' => 'website', 'owner_id' => $website_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' => 'website', 'owner_id' => $website_id); $extra_id = (int) $extra_id; update_insert('extra_id', $extra_id, 'extra', $extra_db); } } foreach ($add_to_group as $group_id => $tf) { module_group::add_to_group($group_id, $website_id, 'website'); } return $website_id; }