Ejemplo n.º 1
0
    }
}
//(int)$ticket_id > 0 &&
if (file_exists(dirname(__FILE__) . '/../inc/ticket_extras_sidebar.php')) {
    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();
Ejemplo n.º 2
0
        // this option isn't in the listing. add it in.
        $user_temp = module_user::get_user($invoice['user_id'], false);
        $c[$invoice['user_id']] = $user_temp['name'] . ' ' . $user_temp['last_name'] . ' ' . _l('(under different customer)');
    }
    $fieldset_data['elements'][] = array('title' => 'Contact', 'field' => array('type' => 'select', 'name' => 'user_id', 'value' => $invoice['user_id'], 'options' => $c, 'blank' => false));
}
echo module_form::generate_fieldset($fieldset_data);
unset($fieldset_data);
if ((int) $invoice_id > 0) {
    hook_handle_callback('invoice_sidebar', $invoice_id);
}
if ($invoice_id && $invoice_id != 'new') {
    $note_summary_owners = array();
    // generate a list of all possible notes we can display for this invoice.
    // 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' => 'Invoice Notes', 'owner_table' => 'invoice', 'owner_id' => $invoice_id, 'view_link' => module_invoice::link_open($invoice_id), 'public' => array('enabled' => true, 'title' => 'Public', 'text' => 'Yes, show this note in invoice', 'help' => 'If this is ticked then this note will be available to the customer and will be included in the {INVOICE_NOTES} shortcode in the invoice template.')));
    }
    if (module_invoice::can_i('edit', 'Invoices')) {
        module_email::display_emails(array('title' => 'Invoice Emails', 'search' => array('invoice_id' => $invoice_id)));
    }
}
if ((int) $invoice_id > 0 && (!$invoice['date_sent'] || $invoice['date_sent'] == '0000-00-00') && module_security::is_page_editable()) {
    ob_start();
    ?>


            <div class="tableclass_form content">

                <p style="text-align: center;">
                    <input type="submit" name="butt_email" id="butt_email2" value="<?php 
Ejemplo n.º 3
0
 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()));
     }
 }
Ejemplo n.º 4
0
 public static function delete_job($job_id)
 {
     $job_id = (int) $job_id;
     if (_DEMO_MODE && $job_id == 1) {
         return;
     }
     if ((int) $job_id > 0) {
         $original_job_data = self::get_job($job_id);
         if (!$original_job_data || $original_job_data['job_id'] != $job_id) {
             return false;
         }
     }
     if (!self::can_i('delete', 'Jobs')) {
         return false;
     }
     $sql = "DELETE FROM " . _DB_PREFIX . "job WHERE job_id = '" . $job_id . "' LIMIT 1";
     $res = query($sql);
     $sql = "DELETE FROM " . _DB_PREFIX . "task WHERE job_id = '" . $job_id . "'";
     $res = query($sql);
     $sql = "DELETE FROM " . _DB_PREFIX . "task_log WHERE job_id = '" . $job_id . "'";
     $res = query($sql);
     $sql = "UPDATE " . _DB_PREFIX . "job SET renew_job_id = NULL WHERE renew_job_id = '" . $job_id . "'";
     $res = query($sql);
     if (class_exists('module_file', false)) {
         $sql = "UPDATE " . _DB_PREFIX . "file SET job_id = 0 WHERE job_id = '" . $job_id . "'";
         query($sql);
     }
     if (class_exists('module_group', false)) {
         module_group::delete_member($job_id, 'job');
     }
     foreach (module_invoice::get_invoices(array('job_id' => $job_id)) as $val) {
         // only delete this invoice if it has no tasks left
         // it could be a combined invoice with other jobs now.
         $invoice_items = module_invoice::get_invoice_items($val['invoice_id']);
         if (!count($invoice_items)) {
             module_invoice::delete_invoice($val['invoice_id']);
         }
     }
     if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
         module_note::note_delete("job", $job_id);
     }
     if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) {
         module_extra::delete_extras('job', 'job_id', $job_id);
     }
     hook_handle_callback('job_delete', $job_id);
     module_cache::clear('job');
 }
Ejemplo n.º 5
0
 public static function delete_quote($quote_id)
 {
     $quote_id = (int) $quote_id;
     if (_DEMO_MODE && $quote_id == 1) {
         return;
     }
     if ((int) $quote_id > 0) {
         $original_quote_data = self::get_quote($quote_id);
         if (!$original_quote_data || $original_quote_data['quote_id'] != $quote_id) {
             return false;
         }
     } else {
         return false;
     }
     if (!self::can_i('delete', 'Quotes')) {
         return false;
     }
     $sql = "DELETE FROM " . _DB_PREFIX . "quote WHERE quote_id = '" . $quote_id . "' LIMIT 1";
     $res = query($sql);
     $sql = "DELETE FROM " . _DB_PREFIX . "quote_tax WHERE quote_id = '" . $quote_id . "'";
     $res = query($sql);
     $sql = "DELETE FROM " . _DB_PREFIX . "quote_task WHERE quote_id = '" . $quote_id . "'";
     $res = query($sql);
     if (class_exists('module_file', false)) {
         $sql = "UPDATE " . _DB_PREFIX . "file SET quote_id = 0 WHERE quote_id = '" . $quote_id . "'";
         query($sql);
     }
     if (class_exists('module_group', false)) {
         module_group::delete_member($quote_id, 'quote');
     }
     if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
         module_note::note_delete("quote", $quote_id);
     }
     if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) {
         module_extra::delete_extras('quote', 'quote_id', $quote_id);
     }
     hook_handle_callback('quote_delete', $quote_id);
     module_cache::clear('quote');
 }
Ejemplo n.º 6
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);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 7
0
 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;
 }