Пример #1
0
 public function is_allowed_for_invoice($invoice_id)
 {
     if (!self::is_enabled()) {
         return false;
     }
     $old_default = module_config::c('__inv_google_' . $invoice_id);
     if ($old_default !== false) {
         $this->set_allowed_for_invoice($invoice_id, $old_default);
         delete_from_db('config', 'key', '__inv_google_' . $invoice_id);
         module_cache::clear('config');
         return $old_default;
     }
     // check for manually enabled invoice payment method.
     $invoice_payment_methods = module_invoice::get_invoice_payment_methods($invoice_id);
     if (isset($invoice_payment_methods['google'])) {
         return $invoice_payment_methods['google']['enabled'];
     }
     return module_config::c('payment_method_google_enabled_default', 1);
 }
Пример #2
0
 public function is_allowed_for_invoice($invoice_id)
 {
     if (!self::is_enabled()) {
         return false;
     }
     $old_default = module_config::c('__inv_coinbase_' . $invoice_id);
     if ($old_default !== false) {
         $this->set_allowed_for_invoice($invoice_id, $old_default);
         delete_from_db('config', 'key', '__inv_coinbase_' . $invoice_id);
         module_cache::clear('config');
         return $old_default;
     }
     // check for manually enabled invoice payment method.
     $invoice_payment_methods = module_invoice::get_invoice_payment_methods($invoice_id);
     if (isset($invoice_payment_methods['coinbase'])) {
         return $invoice_payment_methods['coinbase']['enabled'];
     }
     // check currency and value amounts
     $invoice_data = module_invoice::get_invoice($invoice_id);
     $cur = trim(strtolower(module_config::c('payment_method_coinbase_currency', '')));
     $dollar_limit = module_config::c('payment_method_coinbase_limit_type', 'above');
     $dollar_value = module_config::c('payment_method_coinbase_limit_value', 0);
     if ($dollar_limit == 'above' && $invoice_data['total_amount_due'] < $dollar_value) {
         return false;
     } else {
         if ($dollar_limit == 'below' && $invoice_data['total_amount_due'] > $dollar_value) {
             return false;
         }
     }
     if (strlen($cur) > 1) {
         $allowed_currencies = explode(',', $cur);
         if (count($allowed_currencies)) {
             $currency = module_config::get_currency($invoice_data['currency_id']);
             if (!in_array(strtolower($currency['code']), $allowed_currencies)) {
                 return false;
             }
         }
     }
     return module_config::c('payment_method_coinbase_enabled_default', 1);
 }
Пример #3
0
 public function delete()
 {
     if ($this->social_twitter_message_id) {
         delete_from_db('social_twitter_message', 'social_twitter_message_id', $this->social_twitter_message_id);
     }
 }
Пример #4
0
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
if (!module_config::can_i('view', 'Settings')) {
    redirect_browser(_BASE_HREF);
}
if (!module_config::can_i('edit', 'Settings')) {
    redirect_browser(_BASE_HREF);
}
if (isset($_REQUEST['currency_id'])) {
    $currency_id = (int) $_REQUEST['currency_id'];
    $currency = get_single('currency', 'currency_id', $currency_id);
    if (isset($_REQUEST['butdelete_currency'])) {
        if (module_form::confirm_delete('currency_id', 'Really delete currency: ' . htmlspecialchars($currency['code']))) {
            delete_from_db('currency', 'currency_id', $currency_id);
            set_message(_l('Currency deleted successfully'));
            redirect_browser($_SERVER['REQUEST_URI'] . (strpos($_SERVER['REQUEST_URI'], '?') === false ? '?' : '&') . 'deleted=true');
        }
    } else {
        if (isset($_REQUEST['save'])) {
            update_insert('currency_id', $currency_id, 'currency', $_POST);
            set_message('Currency saved successfully');
            //redirect_browser('?saved=true');
            redirect_browser($_SERVER['REQUEST_URI'] . (strpos($_SERVER['REQUEST_URI'], '?') === false ? '?' : '&') . 'saved=true');
        }
    }
    $currency = get_single('currency', 'currency_id', $currency_id);
    print_heading(array('title' => 'Edit Currency', 'type' => 'h2', 'main' => true));
    ?>
Пример #5
0
<?php

if (!($order_id = $_SESSION['order_id']) || !isset($_POST['id'])) {
    die('no order');
}
$id = abs((int) $_POST['id']);
if ($id) {
    $result = delete_from_db('additional_orders_items', "id = {$id} AND order_id = {$order_id}");
}
Пример #6
0
 public function process()
 {
     if ('save_faq_product' == $_REQUEST['_process']) {
         if (!module_faq::can_i('edit', 'FAQ')) {
             die('No perms to save faq.');
         }
         if (isset($_POST['envato_item_ids'])) {
             $_POST['envato_item_ids'] = implode('|', $_POST['envato_item_ids']);
         }
         $faq_product_id = update_insert('faq_product_id', $_REQUEST['faq_product_id'], 'faq_product', $_POST);
         if (isset($_REQUEST['butt_del'])) {
             // deleting ticket type all together
             if (module_form::confirm_delete('customer_id', _l("Really delete FAQ Product?"), self::link_open_faq_product($_REQUEST['faq_product_id']))) {
                 delete_from_db('faq_product', 'faq_product_id', $_REQUEST['faq_product_id']);
                 set_message('FAQ Product deleted successfully.');
                 redirect_browser($this->link_open_faq_product(false));
             }
         }
         set_message('FAQ Product saved successfully');
         redirect_browser($this->link_open_faq_product($faq_product_id));
     } else {
         if ('save_faq' == $_REQUEST['_process']) {
             if (!module_faq::can_i('edit', 'FAQ')) {
                 die('No perms to save faq.');
             }
             if (isset($_REQUEST['new_product_name']) && strlen(trim($_REQUEST['new_product_name']))) {
                 $faq_product_id = update_insert('faq_product_id', false, 'faq_product', array('name' => trim($_REQUEST['new_product_name'])));
                 if (!isset($_REQUEST['faq_product_ids'])) {
                     $_REQUEST['faq_product_ids'] = array();
                 }
                 $_REQUEST['faq_product_ids'][] = $faq_product_id;
             }
             $faq_id = update_insert('faq_id', $_REQUEST['faq_id'], 'faq', $_POST);
             delete_from_db('faq_product_rel', 'faq_id', $faq_id);
             if (isset($_REQUEST['faq_product_ids']) && is_array($_REQUEST['faq_product_ids'])) {
                 foreach ($_REQUEST['faq_product_ids'] as $faq_product_id) {
                     if ((int) $faq_product_id > 0) {
                         $sql = "INSERT INTO `" . _DB_PREFIX . "faq_product_rel` SET faq_id = " . (int) $faq_id . ", faq_product_id = " . (int) $faq_product_id;
                         query($sql);
                     }
                 }
             }
             if (isset($_REQUEST['butt_del'])) {
                 // deleting ticket type all together
                 if (module_form::confirm_delete('customer_id', _l("Really delete FAQ item?"), self::link_open($_REQUEST['faq_id']))) {
                     delete_from_db('faq', 'faq_id', $_REQUEST['faq_id']);
                     delete_from_db('faq_product_rel', 'faq_id', $_REQUEST['faq_id']);
                     set_message('FAQ deleted successfully.');
                     redirect_browser($this->link_open(false));
                 }
             }
             set_message('FAQ saved successfully');
             redirect_browser($this->link_open($faq_id));
         }
     }
 }
Пример #7
0
 public static function hook_quote_delete($callback_name, $quote_id)
 {
     if ((int) $quote_id > 0) {
         // remove existing.
         delete_from_db('ticket_quote_rel', 'quote_id', $quote_id);
     }
 }
Пример #8
0
 public function delete()
 {
     if ($this->file_id && module_file::can_i('delete', 'Files')) {
         $file_data = $this->get_data();
         if ($this->can_i_access()) {
             // delete any sub files of buckets first.
             // todo: recurisive testing.
             if ($file_data['bucket']) {
                 $sub_files = module_file::get_files(array('bucket_parent_file_id' => $file_data['file_id']));
                 foreach ($sub_files as $sub_file) {
                     if ($sub_file['file_id'] && $sub_file['bucket_parent_file_id'] == $this->file_id) {
                         $sub_file_ucm = new ucm_file($sub_file['file_id']);
                         $sub_file_ucm->delete();
                     }
                 }
             }
             // delete the physical file.
             if ($file_data['file_path'] && is_file($file_data['file_path'])) {
                 unlink($file_data['file_path']);
             }
             // delete the db entry.
             delete_from_db('file', 'file_id', $this->file_id);
             // delete any comments.
             delete_from_db('file_comment', 'file_id', $this->file_id);
             // delete any staff rel.
             delete_from_db('file_user_rel', 'file_id', $this->file_id);
             // delete any notifications
             delete_from_db('file_notification', 'file_id', $this->file_id);
         }
     }
 }
Пример #9
0
 public function delete()
 {
     if ($this->social_facebook_message_id) {
         delete_from_db('social_facebook_message', 'social_facebook_message_id', $this->social_facebook_message_id);
     }
 }
Пример #10
0
 public static function template_handle_save($template_id, $data)
 {
     // check if we're savniga company id and that this user has access to this company, and permissions to edit templates.
     $company_id = isset($_REQUEST['company_id']) ? (int) $_REQUEST['company_id'] : false;
     if ($company_id) {
         $company = self::get_company($company_id);
         if ($company) {
             $existing_template = module_template::get_template($template_id);
             if ($existing_template && $existing_template['template_id'] == $template_id) {
                 // we're saving a template for this particular company.
                 // if it's an empty template content then we remove this company template so it reverts to the system default.
                 if (isset($data['content']) && !strlen(trim($data['content']))) {
                     delete_from_db('company_template', array('company_id', 'template_id'), array($company_id, $template_id));
                     set_message('Company template successfully reset to default');
                     redirect_browser(module_template::link_open($template_id));
                 } else {
                     $sql = 'REPLACE INTO `' . _DB_PREFIX . "company_template` SET company_id = " . (int) $company_id . ", `template_id` = " . (int) $template_id . ", `description` = '" . mysql_real_escape_string(isset($data['description']) ? $data['description'] : '') . "', `content` = '" . mysql_real_escape_string(isset($data['content']) ? $data['content'] : '') . "', `wysiwyg` = '" . mysql_real_escape_string(isset($data['wysiwyg']) ? $data['wysiwyg'] : '') . "'";
                     query($sql);
                     set_message('Unique company template successfully updated');
                     redirect_browser(module_template::link_open($template_id) . '&company_id=' . $company_id);
                 }
             }
         }
     }
 }
Пример #11
0
function exit_room($params)
{
    $chat_room_id = $params['chat_room_id'];
    $user_id = $_SESSION['user_id'];
    insert_to_db(array('user_id' => $user_id, 'message' => "*** has left the chat ***", 'chat_room_id' => $chat_room_id), 'chat_messages');
    $statement = "user_id = " . $user_id . " AND chat_room_id = " . $chat_room_id;
    delete_from_db("chat_rooms__got__users", $statement);
}
Пример #12
0
 public static function unsubscribe_member_via_email($email, $reason = 'unsubscribe', $remove = false)
 {
     // add thsi email to a blacklist.
     // or remove them if they re-subscribe.
     $email = strtolower(trim(filter_var($email, FILTER_VALIDATE_EMAIL)));
     if (strlen($email) > 3) {
         if ($remove) {
             // remove all occurances of this email address.
             delete_from_db('newsletter_blacklist', 'email', $email);
         } else {
             if (!self::email_blacklisted($email)) {
                 // check if it already exists ^^
                 // add to backlist.
                 update_insert('newsletter_blacklist_id', 'new', 'newsletter_blacklist', array('email' => $email, 'time' => time(), 'reason' => $reason));
             }
         }
         return true;
     }
     return false;
 }
Пример #13
0
    if ($sku) {
        $command .= " -c " . escapeshellarg($sku);
    }
    if ($debug) {
        $command .= " --debug";
    }
    $filename = str_replace(" ", "-", $title);
    $filename = preg_replace("/[^-a-zA-Z0-9]/", "", $filename);
    $filename = strtolower($filename) . ".pdf";
    header("Content-Type: application/pdf");
    header("Content-disposition: attachment; filename={$filename}");
    passthru($command);
} else {
    if ($_POST['store']) {
        store_in_db($db, $title, $subtitle, $url, $sku);
        $rowid = $db->lastInsertRowid();
        show_id($rowid);
    } else {
        if ($_POST['update']) {
            update_in_db($db, $id, $title, $subtitle, $url, $sku);
            show_id($id);
        } else {
            if ($_POST['delete']) {
                delete_from_db($db, $id);
                show_id(-1);
            } else {
                show_id(-1);
            }
        }
    }
}
Пример #14
0
 public function process()
 {
     if ('save_backup' == $_REQUEST['_process']) {
         if (!module_backup::can_i('edit', 'Backups')) {
             die('No perms to save backup.');
         }
         if (!module_form::check_secure_key()) {
             die('Invalid auth');
         }
         if (_DEMO_MODE) {
             die('Sorry, cannot make backups in demo mode.cd ');
         }
         $backup_id = update_insert('backup_id', $_REQUEST['backup_id'], 'backup', $_POST);
         if (isset($_REQUEST['butt_del']) && self::can_i('delete', 'Backups')) {
             // and the file.
             $backup = $this->get_backup($backup_id);
             if ($backup && $backup['backup_id'] == $backup_id && module_form::confirm_delete('backup_id', _l('Really delete this backup?'), self::link_open($backup_id))) {
                 if (isset($backup['backup_file']) && strlen($backup['backup_file'])) {
                     if (file_exists(_BACKUP_BASE_DIR . basename($backup['backup_file']) . '.sql')) {
                         @unlink(_BACKUP_BASE_DIR . basename($backup['backup_file']) . '.sql');
                     }
                     if (file_exists(_BACKUP_BASE_DIR . basename($backup['backup_file']) . '.sql.gz')) {
                         @unlink(_BACKUP_BASE_DIR . basename($backup['backup_file']) . '.sql.gz');
                     }
                     if (file_exists(_BACKUP_BASE_DIR . basename($backup['backup_file']) . '.zip')) {
                         @unlink(_BACKUP_BASE_DIR . basename($backup['backup_file']) . '.zip');
                     }
                 }
                 delete_from_db('backup', 'backup_id', $backup['backup_id']);
                 set_message('Backup deleted successfully.');
                 redirect_browser($this->link_open(false));
             }
         }
         set_message('Backup saved successfully');
         redirect_browser($this->link_open($backup_id));
     }
 }
Пример #15
0
    die('bad link');
}
$store = db_query_to_row("SELECT * FROM `stores` WHERE id = {$id}");
if (!$store) {
    die('store not found');
}
import('store');
if (isset($_POST['shop_name'])) {
    $update = array();
    if (!store_validate($update)) {
        $error_msg = 'All fields must be filled';
    } else {
        $hanging_methods = $update['hanging_methods'];
        unset($update['hanging_methods']);
        if (update_in_db('stores', $update, '`id`=' . $id)) {
            delete_from_db('stores_hanging_methods', '`store_id`=' . $id);
            $store_hanging_methods = array();
            foreach ($hanging_methods as $value) {
                $store_hanging_methods[] = array('store_id' => $id, 'hanging_method_id' => $value);
            }
            insert_multi_to_db('stores_hanging_methods', $store_hanging_methods);
            $_SESSION['edit_store_msg'] = 'Store Successfully Updated';
            header('location: /store/edit/' . $id);
            die;
        }
    }
}
$hanging_methods = get_hanging_methods();
$store_hanging_methods = db_query_to_list('SELECT `hanging_method_id` FROM `stores_hanging_methods` WHERE `store_id`=' . $id, 'hanging_method_id');
$template = set_template('store', 'edit');
$link = THEME . 'template2.php';
Пример #16
0
 public static function save_default_tasks($default_task_list_id, $name, $task_data)
 {
     if ((int) $default_task_list_id > 0 && !count($task_data)) {
         // deleting a task.
         delete_from_db('extra', array('extra_id', 'owner_table'), array($default_task_list_id, 'job_task_defaults'));
         return false;
     } else {
         $extra_db = array('extra' => serialize($task_data), 'owner_table' => 'job_task_defaults', 'owner_id' => 1);
         if (!(int) $default_task_list_id) {
             $extra_db['extra_key'] = $name;
             // don't update names of previous ones.
         }
         $extra_id = update_insert('extra_id', $default_task_list_id, 'extra', $extra_db);
         return $extra_id;
     }
 }
Пример #17
0
 public function delete_product_category($product_category_id)
 {
     $product_category_id = (int) $product_category_id;
     delete_from_db('product_category', 'product_category_id', $product_category_id);
     $sql = "UPDATE `" . _DB_PREFIX . "product` SET product_category_id = 0 WHERE product_category_id = " . (int) $product_category_id;
     query($sql);
 }
Пример #18
0
 public static function hook_website_deleted($callback_name, $website_id)
 {
     if ((int) $website_id > 0) {
         // check if this website is linked to any subscription payments.
         $members_subscriptions = module_subscription::get_subscriptions_by('website', $website_id, false, true);
         foreach ($members_subscriptions as $members_subscription) {
             delete_from_db('subscription_history', 'subscription_owner_id', $members_subscription['subscription_owner_id']);
         }
         delete_from_db('subscription_owner', array('owner_id', 'owner_table'), array($website_id, 'website'));
     }
 }
Пример #19
0
 public function process()
 {
     if ('save_extra_default' == $_REQUEST['_process']) {
         if (!module_config::can_i('edit', 'Settings')) {
             die('No perms to save extra field settings.');
         }
         if (isset($_REQUEST['butt_del'])) {
             if (module_form::confirm_delete('extra_default_id', _l("Really delete this extra field and ALL extra data linked to this field?"), $_SERVER['REQUEST_URI'])) {
                 $extra_default = module_extra::get_extra_default($_REQUEST['extra_default_id']);
                 if ($extra_default && $extra_default['extra_default_id'] == $_REQUEST['extra_default_id'] && $extra_default['owner_table'] && $extra_default['extra_key']) {
                     $extra_values = get_multiple('extra', array('owner_table' => $extra_default['owner_table'], 'extra_key' => $extra_default['extra_key']), 'extra_id', 'exact', 'owner_id');
                     if ($extra_values) {
                         foreach ($extra_values as $extra_value) {
                             if ($extra_value['owner_table'] == $extra_default['owner_table'] && $extra_value['extra_key'] == $extra_default['extra_key']) {
                                 delete_from_db('extra', 'extra_id', $extra_value['extra_id']);
                             }
                         }
                     }
                 }
                 delete_from_db('extra_default', 'extra_default_id', $_REQUEST['extra_default_id']);
                 set_message('Extra field deleted successfully.');
                 redirect_browser(str_replace('extra_default_id', 'extra_default_id_deleted', $_SERVER['REQUEST_URI']));
             }
         }
         if ((int) $_REQUEST['extra_default_id'] > 0) {
             $extra_default = module_extra::get_extra_default($_REQUEST['extra_default_id']);
             if ($extra_default && $extra_default['extra_default_id'] == $_REQUEST['extra_default_id'] && $extra_default['owner_table'] && $extra_default['extra_key']) {
                 if (isset($_POST['extra_key']) && !empty($_POST['extra_key']) && $_POST['extra_key'] != $extra_default['extra_key']) {
                     // they have renamed the key, rename all the existing ones in the system.
                     $extra_values = get_multiple('extra', array('owner_table' => $extra_default['owner_table'], 'extra_key' => $extra_default['extra_key']), 'extra_id', 'exact', 'owner_id');
                     if ($extra_values) {
                         foreach ($extra_values as $extra_value) {
                             if ($extra_value['owner_table'] == $extra_default['owner_table'] && $extra_value['extra_key'] == $extra_default['extra_key']) {
                                 update_insert('extra_id', $extra_value['extra_id'], 'extra', array('extra_key' => $_POST['extra_key']));
                             }
                         }
                     }
                 }
             }
         }
         $data = $_POST;
         if (isset($data['options']) && is_array($data['options'])) {
             $data['options'] = json_encode($data['options']);
         }
         update_insert('extra_default_id', $_REQUEST['extra_default_id'], 'extra_default', $data);
         set_message('Extra field saved successfully');
         redirect_browser($_SERVER['REQUEST_URI']);
     }
 }
Пример #20
0
 public function process()
 {
     if ("ajax_calendar" == $_REQUEST['_process'] && module_calendar::can_i('view', 'Calendar')) {
         // ajax functions from wdCalendar. copied from the datafeed.php sample files.
         header('Content-type: text/javascript');
         $ret = array();
         $method = isset($_REQUEST['method']) ? $_REQUEST['method'] : false;
         switch ($method) {
             case "quick_add":
                 if (module_calendar::can_i('create', 'Calendar')) {
                     $ret = addCalendar($_POST["CalendarStartTime"], $_POST["CalendarEndTime"], $_POST["CalendarTitle"], $_POST["IsAllDayEvent"]);
                 }
                 break;
             case "list":
                 $ret = listCalendar($_POST["showdate"], $_POST["viewtype"]);
                 break;
             case "quick_update":
                 if (module_calendar::can_i('edit', 'Calendar')) {
                     $ret = updateCalendar($_POST["calendarId"], $_POST["CalendarStartTime"], $_POST["CalendarEndTime"]);
                 }
                 break;
             case "quick_remove":
                 if (module_calendar::can_i('delete', 'Calendar')) {
                     $ret = removeCalendar($_POST["calendarId"]);
                 }
                 break;
         }
         echo json_encode($ret);
         exit;
     }
     if ("save_calendar_entry" == $_REQUEST['_process']) {
         header('Content-type: text/javascript');
         $calendar_id = isset($_REQUEST['calendar_id']) ? (int) $_REQUEST['calendar_id'] : 0;
         $response = array();
         if ($calendar_id && module_calendar::can_i('edit', 'Calendar') || !$calendar_id && module_calendar::can_i('create', 'Calendar')) {
             $data = $_REQUEST;
             if (isset($data['start'])) {
                 $start_time = $data['start'];
                 if (isset($data['start_time']) && (!isset($data['is_all_day']) || !$data['is_all_day'])) {
                     $data['is_all_day'] = 0;
                     $time_hack = $data['start_time'];
                     $time_hack = str_ireplace(_l("am"), '', $time_hack);
                     $time_hack = str_ireplace(_l("pm"), '', $time_hack);
                     $bits = explode(':', $time_hack);
                     if (strpos($data['end_time'], _l("pm"))) {
                         if ($bits[0] < 12) {
                             $bits[0] += 12;
                         }
                     }
                     // add the time if it exists
                     $start_time .= ' ' . implode(':', $bits) . ':00';
                     $data['start'] = strtotime(input_date($start_time, true));
                 } else {
                     $data['start'] = strtotime(input_date($start_time));
                 }
             }
             if (isset($data['end'])) {
                 $end_time = $data['end'];
                 if (isset($data['end_time']) && (!isset($data['is_all_day']) || !$data['is_all_day'])) {
                     $data['is_all_day'] = 0;
                     $time_hack = $data['end_time'];
                     $time_hack = str_ireplace(_l("am"), '', $time_hack);
                     $time_hack = str_ireplace(_l("pm"), '', $time_hack);
                     $bits = explode(':', $time_hack);
                     if (strpos($data['end_time'], _l("pm"))) {
                         if ($bits[0] < 12) {
                             $bits[0] += 12;
                         }
                     }
                     // add the time if it exists
                     $end_time .= ' ' . implode(':', $bits) . ':00';
                     //echo $end_time;
                     $data['end'] = strtotime(input_date($end_time, true));
                 } else {
                     $data['end'] = strtotime(input_date($end_time));
                 }
             }
             if (!$data['start'] || !$data['end']) {
                 $response['message'] = 'Missing Date';
             } else {
                 //print_r($_REQUEST); print_r($data); exit;
                 $calendar_id = update_insert('calendar_id', $calendar_id, 'calendar', $data);
                 if ($calendar_id) {
                     // save staff members.
                     $staff_ids = isset($_REQUEST['staff_ids']) && is_array($_REQUEST['staff_ids']) ? $_REQUEST['staff_ids'] : array();
                     delete_from_db('calendar_user_rel', 'calendar_id', $calendar_id);
                     foreach ($staff_ids as $staff_id) {
                         if ((int) $staff_id > 0) {
                             $sql = "INSERT INTO `" . _DB_PREFIX . "calendar_user_rel` SET calendar_id = " . (int) $calendar_id . ", user_id = " . (int) $staff_id;
                             query($sql);
                         }
                     }
                     $response['calendar_id'] = $calendar_id;
                     $response['message'] = 'Success';
                 } else {
                     $response['message'] = 'Error Saving';
                 }
             }
         } else {
             $response['message'] = 'Access Denied';
         }
         echo json_encode($response);
         exit;
     }
 }
Пример #21
0
    $security_role = module_security::get_security_role($security_role_id);
    if (!$security_role) {
        $security_role_id = 'new';
    }
}
if ($security_role_id == 'new' || !$security_role_id) {
    if (class_exists('module_security', false)) {
        module_security::check_page(array('category' => 'Security', 'page_name' => 'Security Roles', 'module' => 'security', 'feature' => 'create'));
    }
    $security_role = array('security_role_id' => 'new', 'name' => '');
}
if (module_security::can_i('edit', 'Security Roles', 'Security') && isset($_REQUEST['delete_security_permission_id'])) {
    $id = (int) $_REQUEST['delete_security_permission_id'];
    if ($id > 0) {
        delete_from_db('security_permission', 'security_permission_id', $id);
        delete_from_db('security_role_perm', 'security_permission_id', $id);
    }
    redirect_browser(module_security::link_open_role($security_role_id) . '&advanced');
}
if (isset($_REQUEST['export_json'])) {
    $export_json = array();
}
?>


	
<form action="" method="post">
	<input type="hidden" name="_process" value="save_security_role" />
	<input type="hidden" name="security_role_id" value="<?php 
echo $security_role_id;
?>
Пример #22
0
 function delete_data_type($data_type_id)
 {
     $data_type_id = (int) $data_type_id;
     if ((int) $data_type_id > 0 && $this->can_i('delete', _MODULE_DATA_NAME)) {
         $records = get_multiple('data_record', array('data_type_id' => $data_type_id));
         foreach ($records as $record) {
             if ($record['data_type_id'] == $data_type_id && $record['data_record_id'] > 0) {
                 delete_from_db('data_record_revision', 'data_record_id', $record['data_record_id']);
                 delete_from_db('data_record', 'data_record_id', $record['data_record_id']);
                 delete_from_db('data_store', 'data_record_id', $record['data_record_id']);
             }
         }
         delete_from_db('data_field', 'data_type_id', $data_type_id);
         delete_from_db('data_field_group', 'data_type_id', $data_type_id);
         $sql = "DELETE FROM " . _DB_PREFIX . "data_type WHERE data_type_id = '" . $data_type_id . "' LIMIT 1";
         query($sql);
     }
 }
Пример #23
0
 public function delete_customer($customer_id, $remove_linked_data = true)
 {
     $customer_id = (int) $customer_id;
     if ($customer_id > 0) {
         if (_DEMO_MODE && $customer_id == 1) {
             set_error('Sorry this is a Demo Customer. It cannot be changed.');
             redirect_browser(self::link_open($customer_id));
         }
         $customer = self::get_customer($customer_id);
         if ($customer && $customer['customer_id'] == $customer_id) {
             // todo: Delete emails (wack these in this customer_deleted hook)
             hook_handle_callback('customer_deleted', $customer_id, $remove_linked_data);
             if (class_exists('module_group', false)) {
                 // remove the customer from his groups
                 module_group::delete_member($customer_id, 'customer');
             }
             if (class_exists('module_extra', false)) {
                 module_extra::delete_extras('customer', 'customer_id', $customer_id);
             }
             // remove the contacts from this customer
             foreach (module_user::get_contacts(array('customer_id' => $customer_id)) as $val) {
                 if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                     module_user::delete_user($val['user_id']);
                 }
             }
             // remove staff
             delete_from_db('customer_user_rel', 'customer_id', $customer_id);
             if (class_exists('module_note', false)) {
                 module_note::note_delete("customer", 'customer_id', $customer_id);
             }
             handle_hook("address_delete", $this, 'all', "customer", 'customer_id', $customer_id);
             // todo, check the 'delete' permission on each one of these 'delete' method calls
             // do that better when we remove each of these and put them into the customer delete hook
             if ($remove_linked_data) {
                 if (class_exists('module_website', false) && module_website::is_plugin_enabled()) {
                     foreach (module_website::get_websites(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             module_website::delete_website($val['website_id']);
                         }
                     }
                 }
                 if (class_exists('module_job', false) && module_job::is_plugin_enabled()) {
                     foreach (module_job::get_jobs(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             module_job::delete_job($val['job_id']);
                         }
                     }
                 }
                 if (class_exists('module_invoice', false) && module_invoice::is_plugin_enabled()) {
                     foreach (module_invoice::get_invoices(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             module_invoice::delete_invoice($val['invoice_id']);
                         }
                     }
                 }
                 if (class_exists('module_quote', false) && module_quote::is_plugin_enabled()) {
                     foreach (module_quote::get_quotes(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             module_quote::delete_quote($val['quote_id']);
                         }
                     }
                 }
                 //handle_hook("file_delete",$this,"customer",'customer_id',$customer_id);
             } else {
                 // instead of deleting these records we just update them to customer_id = 0
                 if (class_exists('module_website', false) && module_website::is_plugin_enabled()) {
                     foreach (module_website::get_websites(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             update_insert('website_id', $val['website_id'], 'website', array('customer_id' => 0));
                         }
                     }
                 }
                 if (class_exists('module_job', false) && module_job::is_plugin_enabled()) {
                     foreach (module_job::get_jobs(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             update_insert('job_id', $val['job_id'], 'job', array('customer_id' => 0));
                         }
                     }
                 }
                 if (class_exists('module_invoice', false) && module_invoice::is_plugin_enabled()) {
                     foreach (module_invoice::get_invoices(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             update_insert('invoice_id', $val['invoice_id'], 'invoice', array('customer_id' => 0));
                         }
                     }
                 }
                 if (class_exists('module_quote', false) && module_quote::is_plugin_enabled()) {
                     foreach (module_quote::get_quotes(array('customer_id' => $customer_id)) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             update_insert('quote_id', $val['quote_id'], 'quote', array('customer_id' => 0));
                         }
                     }
                 }
                 if (class_exists('module_file', false) && module_file::is_plugin_enabled()) {
                     foreach (module_file::get_files(array('owner_id' => $customer_id, 'owner_table' => 'customer')) as $val) {
                         if ($val['customer_id'] && $val['customer_id'] == $customer_id) {
                             update_insert('file_id', $val['file_id'], 'file', array('owner_id' => 0, 'owner_table' => ''));
                         }
                     }
                 }
             }
             // finally delete the main customer record
             // (this is so the above code works with its sql joins)
             $sql = "DELETE FROM " . _DB_PREFIX . "customer WHERE customer_id = '" . $customer_id . "' LIMIT 1";
             query($sql);
         }
     }
 }
Пример #24
0
 public static function save_invoice($invoice_id, $data)
 {
     if (!(int) $invoice_id && isset($data['job_id']) && $data['job_id']) {
         $linkedjob = module_job::get_job($data['job_id']);
         $data['currency_id'] = $linkedjob['currency_id'];
         $data['customer_id'] = $linkedjob['customer_id'];
     }
     if ($invoice_id) {
         // used when working out the hourly rate fix below
         $original_invoice_data = self::get_invoice($invoice_id);
     } else {
         $original_invoice_data = 0;
     }
     $invoice_id = update_insert("invoice_id", $invoice_id, "invoice", $data);
     if ($invoice_id) {
         module_cache::clear('invoice');
         // save the invoice tax rates (copied to finance.php)
         if (isset($data['tax_ids']) && isset($data['tax_names']) && $data['tax_percents']) {
             $existing_taxes = get_multiple('invoice_tax', array('invoice_id' => $invoice_id), 'invoice_tax_id', 'exact', 'order');
             $order = 1;
             foreach ($data['tax_ids'] as $key => $val) {
                 if (isset($data['tax_percents'][$key]) && $data['tax_percents'][$key] == 0) {
                     // we are not saving this particular tax item because it has a 0% tax rate
                 } else {
                     if ((int) $val > 0 && isset($existing_taxes[$val])) {
                         // this means we are trying to update an existing record on the invoice_tax table, we confirm this id matches this invoice.
                         $invoice_tax_id = $val;
                         unset($existing_taxes[$invoice_tax_id]);
                         // so we know which ones to remove from the end.
                     } else {
                         $invoice_tax_id = false;
                         // create new record
                     }
                     $invoice_tax_data = array('invoice_id' => $invoice_id, 'percent' => isset($data['tax_percents'][$key]) ? $data['tax_percents'][$key] : 0, 'amount' => 0, 'name' => isset($data['tax_names'][$key]) ? $data['tax_names'][$key] : 'TAX', 'order' => $order++, 'increment' => isset($data['tax_increment_checkbox']) && $data['tax_increment_checkbox'] ? 1 : 0);
                     $invoice_tax_id = update_insert('invoice_tax_id', $invoice_tax_id, 'invoice_tax', $invoice_tax_data);
                 }
             }
             foreach ($existing_taxes as $existing_tax) {
                 delete_from_db('invoice_tax', array('invoice_id', 'invoice_tax_id'), array($invoice_id, $existing_tax['invoice_tax_id']));
             }
         }
         $invoice_data = self::get_invoice($invoice_id);
         if (!$invoice_data) {
             set_error('No permissions to access invoice.');
             return $invoice_id;
         }
         // check for new invoice_items or changed invoice_items.
         $invoice_items = self::get_invoice_items($invoice_id, $invoice_data);
         if (isset($data['invoice_invoice_item']) && is_array($data['invoice_invoice_item'])) {
             foreach ($data['invoice_invoice_item'] as $invoice_item_id => $invoice_item_data) {
                 $invoice_item_id = (int) $invoice_item_id;
                 if (!is_array($invoice_item_data)) {
                     continue;
                 }
                 if ($invoice_item_id > 0 && !isset($invoice_items[$invoice_item_id])) {
                     continue;
                 }
                 // wrong invoice_item save - will never happen.
                 if (!isset($invoice_item_data['description']) || $invoice_item_data['description'] == '') {
                     if ($invoice_item_id > 0) {
                         // remove invoice_item.
                         $sql = "DELETE FROM `" . _DB_PREFIX . "invoice_item` WHERE invoice_item_id = '{$invoice_item_id}' AND invoice_id = {$invoice_id} LIMIT 1";
                         query($sql);
                     }
                     continue;
                 }
                 // add / save this invoice_item.
                 $invoice_item_data['invoice_id'] = $invoice_id;
                 // what type of task is this?
                 $invoice_task_type = isset($invoice_item_data['manual_task_type']) && $invoice_item_data['manual_task_type'] >= 0 ? $invoice_item_data['manual_task_type'] : $invoice_data['default_task_type'];
                 $invoice_item_data['hours_mins'] = 0;
                 if (isset($invoice_item_data['hours']) && $invoice_task_type == _TASK_TYPE_HOURS_AMOUNT) {
                 }
                 if (isset($invoice_item_data['hours']) && $invoice_task_type == _TASK_TYPE_HOURS_AMOUNT && function_exists('decimal_time_in')) {
                     $invoice_item_data['hours'] = decimal_time_in($invoice_item_data['hours']);
                     if (strpos($invoice_item_data['hours'], ':') !== false) {
                         $invoice_item_data['hours_mins'] = str_replace(":", ".", $invoice_item_data['hours']);
                     }
                 } else {
                     if (isset($invoice_item_data['hours']) && strlen($invoice_item_data['hours'])) {
                         $invoice_item_data['hours'] = number_in($invoice_item_data['hours']);
                     } else {
                         $invoice_item_data['hours'] = 0;
                     }
                 }
                 // number formatting
                 //print_r($invoice_item_data);
                 if (isset($invoice_item_data['hourly_rate']) && strlen($invoice_item_data['hourly_rate'])) {
                     $invoice_item_data['hourly_rate'] = number_in($invoice_item_data['hourly_rate'], module_config::c('task_amount_decimal_places', -1));
                 }
                 //print_r($invoice_item_data);exit;
                 // somenew hacks here to support out new method of creating an item.
                 // the 'amount' column is never edited any more
                 // this column is now always automatically calculated based on
                 // 'hours' and 'hourly_rate'
                 if (!isset($invoice_item_data['amount'])) {
                     if ($invoice_task_type == _TASK_TYPE_AMOUNT_ONLY) {
                         // ignore the quantity field all together.
                         $invoice_item_data['amount'] = $invoice_item_data['hourly_rate'];
                         $invoice_item_data['hourly_rate'] = 0;
                     } else {
                         if (isset($invoice_item_data['hourly_rate']) && strlen($invoice_item_data['hourly_rate']) > 0) {
                             // if we have inputted an hourly rate (ie: not left empty)
                             if (isset($invoice_item_data['hours']) && strlen($invoice_item_data['hours']) == 0) {
                                 // no hours entered (eg: empty) so we treat whatever was in 'hourly_rate' as the amount
                                 $invoice_item_data['amount'] = $invoice_item_data['hourly_rate'];
                             } else {
                                 if (isset($invoice_item_data['hours']) && strlen($invoice_item_data['hours']) > 0) {
                                     // hours inputted, along with hourly rate. work out the new amount.
                                     $invoice_item_data['amount'] = round($invoice_item_data['hours'] * $invoice_item_data['hourly_rate'], module_config::c('currency_decimal_places', 2));
                                 }
                             }
                         }
                     }
                 }
                 if ($invoice_task_type == _TASK_TYPE_HOURS_AMOUNT) {
                     if ($invoice_item_data['hourly_rate'] == $invoice_data['hourly_rate'] || isset($original_invoice_data['hourly_rate']) && $invoice_item_data['hourly_rate'] == $original_invoice_data['hourly_rate']) {
                         $invoice_item_data['hourly_rate'] = -1;
                     }
                 }
                 // remove the amount of it equals the hourly rate.
                 /*if(isset($invoice_item_data['amount']) && isset($invoice_item_data['hours']) && $invoice_item_data['amount'] > 0 && $invoice_item_data['hours'] > 0){
                       if($invoice_item_data['amount'] - ($invoice_item_data['hours'] * $data['hourly_rate']) == 0){
                           unset($invoice_item_data['amount']);
                       }
                   }*/
                 // check if we haven't unticked a non-hourly invoice_item
                 /*if(isset($invoice_item_data['completed_t']) && $invoice_item_data['completed_t'] && !isset($invoice_item_data['completed'])){
                       $invoice_item_data['completed'] = 0;
                   }*/
                 if (!isset($invoice_item_data['taxable_t'])) {
                     $invoice_item_data['taxable'] = module_config::c('task_taxable_default', 1);
                 } else {
                     if (isset($invoice_item_data['taxable_t']) && $invoice_item_data['taxable_t'] && !isset($invoice_item_data['taxable'])) {
                         $invoice_item_data['taxable'] = 0;
                     }
                 }
                 if (!strlen($invoice_item_data['hours'])) {
                     $invoice_item_data['hours'] = 0;
                 }
                 $invoice_item_data['hourly_rate'] = number_out($invoice_item_data['hourly_rate'], false, module_config::c('task_amount_decimal_places', -1));
                 $invoice_item_data['hours'] = number_out($invoice_item_data['hours']);
                 $invoice_item_data['amount'] = number_out($invoice_item_data['amount']);
                 update_insert('invoice_item_id', $invoice_item_id, 'invoice_item', $invoice_item_data);
             }
         }
         $last_payment_time = 0;
         if (isset($data['invoice_invoice_payment']) && is_array($data['invoice_invoice_payment'])) {
             foreach ($data['invoice_invoice_payment'] as $invoice_payment_id => $invoice_payment_data) {
                 $invoice_payment_id = (int) $invoice_payment_id;
                 if (!is_array($invoice_payment_data)) {
                     continue;
                 }
                 if (isset($invoice_payment_data['amount'])) {
                     $invoice_payment_data['amount'] = number_in($invoice_payment_data['amount']);
                     // toggle between 'normal' and 'refund' payment types
                     if (isset($invoice_payment_data['payment_type'])) {
                         if ($invoice_payment_data['amount'] < 0 && $invoice_payment_data['payment_type'] == _INVOICE_PAYMENT_TYPE_NORMAL) {
                             // this is a refund.
                             $invoice_payment_data['payment_type'] = _INVOICE_PAYMENT_TYPE_REFUND;
                         } else {
                             if ($invoice_payment_data['payment_type'] == _INVOICE_PAYMENT_TYPE_REFUND) {
                                 $invoice_payment_data['payment_type'] = _INVOICE_PAYMENT_TYPE_NORMAL;
                             }
                         }
                     }
                 }
                 // check this invoice payment actually matches this invoice.
                 $invoice_payment_data_existing = false;
                 if ($invoice_payment_id > 0) {
                     $invoice_payment_data_existing = get_single('invoice_payment', array('invoice_payment_id', 'invoice_id'), array($invoice_payment_id, $invoice_id));
                     if (!$invoice_payment_data_existing || $invoice_payment_data_existing['invoice_payment_id'] != $invoice_payment_id || $invoice_payment_data_existing['invoice_id'] != $invoice_id) {
                         $invoice_payment_id = 0;
                         $invoice_payment_data_existing = false;
                     }
                 }
                 if (!isset($invoice_payment_data['amount']) || $invoice_payment_data['amount'] == '' || $invoice_payment_data['amount'] == 0) {
                     // || $invoice_payment_data['amount'] <= 0
                     if ($invoice_payment_id > 0) {
                         // if this is a customer credit payment, return that back to the customer account.
                         if ($invoice_payment_data_existing && $invoice_data['customer_id']) {
                             switch ($invoice_payment_data_existing['payment_type']) {
                                 case _INVOICE_PAYMENT_TYPE_CREDIT:
                                     module_customer::add_credit($invoice_data['customer_id'], $invoice_payment_data_existing['amount'], 'Refunded credit from invoice payment');
                                     break;
                             }
                         }
                         // remove invoice_payment.
                         $sql = "DELETE FROM `" . _DB_PREFIX . "invoice_payment` WHERE invoice_payment_id = '{$invoice_payment_id}' AND invoice_id = {$invoice_id} LIMIT 1";
                         query($sql);
                         // delete any existing transactions from the system as well.
                         hook_handle_callback('invoice_payment_deleted', $invoice_payment_id, $invoice_id);
                     }
                     continue;
                 }
                 if (!$invoice_payment_id && (!isset($_REQUEST['add_payment']) || $_REQUEST['add_payment'] != 'go')) {
                     continue;
                     // not saving a new one.
                 }
                 // add / save this invoice_payment.
                 $invoice_payment_data['invoice_id'] = $invoice_id;
                 // $invoice_payment_data['currency_id'] = $invoice_data['currency_id'];
                 $last_payment_time = max($last_payment_time, strtotime(input_date($invoice_payment_data['date_paid'])));
                 if (isset($invoice_payment_data['custom_notes'])) {
                     $details = @unserialize($invoice_payment_data['data']);
                     if (!is_array($details)) {
                         $details = array();
                     }
                     $details['custom_notes'] = $invoice_payment_data['custom_notes'];
                     $invoice_payment_data['data'] = serialize($details);
                 }
                 $invoice_payment_data['amount'] = number_out($invoice_payment_data['amount']);
                 update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', $invoice_payment_data);
             }
         }
         if (!$last_payment_time) {
             $last_payment_time = strtotime(date('Y-m-d'));
         }
         // check if the invoice has been paid
         module_cache::clear('invoice');
         //module_cache::clear_cache(); // this helps fix the bug where part payments are not caulcated a correct paid date.
         $invoice_data = self::get_invoice($invoice_id);
         if (!$invoice_data) {
             set_error('No permissions to access invoice.');
             return $invoice_id;
         }
         if ((!$invoice_data['date_paid'] || $invoice_data['date_paid'] == '0000-00-00') && $invoice_data['total_amount_due'] <= 0 && ($invoice_data['total_amount_paid'] > 0 || $invoice_data['discount_amount'] > 0) && (!$invoice_data['date_cancel'] || $invoice_data['date_cancel'] == '0000-00-00')) {
             // find the date of the last payment history.
             // if the sent date is null also update that.
             $date_sent = $invoice_data['date_sent'];
             if (!$date_sent || $date_sent == '0000-00-00') {
                 $date_sent = date('Y-m-d', $last_payment_time);
             }
             update_insert("invoice_id", $invoice_id, "invoice", array('date_paid' => date('Y-m-d', $last_payment_time), 'date_sent' => $date_sent, 'status' => _l('Paid')));
             // hook for our ticketing plugin to mark a priority support ticket as paid.
             // or anything else down the track.
             module_cache::clear('invoice');
             handle_hook('invoice_paid', $invoice_id);
             if (module_config::c('invoice_automatic_receipt', 1)) {
                 // send receipt to customer.
                 self::email_invoice_to_customer($invoice_id);
             }
         }
         if ($invoice_data['total_amount_due'] > 0) {
             // update the status to unpaid.
             update_insert("invoice_id", $invoice_id, "invoice", array('date_paid' => '', 'status' => $invoice_data['status'] == _l('Paid') ? module_config::s('invoice_status_default', 'New') : $invoice_data['status']));
         }
         if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) {
             module_extra::save_extras('invoice', 'invoice_id', $invoice_id);
         }
         if ($invoice_data['customer_id']) {
             //module_cache::clear_cache();
             module_cache::clear('invoice');
             module_customer::update_customer_status($invoice_data['customer_id']);
         }
         hook_handle_callback('invoice_saved', $invoice_id, $invoice_data);
     }
     module_cache::clear('invoice');
     module_cache::clear('job');
     return $invoice_id;
 }
Пример #25
0
 public function delete_pin($pin_id)
 {
     delete_from_db('extra', array('owner_table', 'extra_id', 'owner_id'), array('pin', $pin_id, module_security::get_loggedin_id()));
 }
Пример #26
0
 public function process()
 {
     switch ($_REQUEST['_process']) {
         case 'quick_save_finance':
             if (isset($_REQUEST['link_go']) && $_REQUEST['link_go'] == 'go') {
                 module_finance::handle_link_transactions();
             } else {
                 // check for date / name at least.
                 $date = trim($_REQUEST['transaction_date']);
                 $name = trim($_REQUEST['name']);
                 if (!$date || !$name) {
                     redirect_browser(module_finance::link_open(false));
                 }
                 $credit = trim($_REQUEST['credit']);
                 $debit = trim($_REQUEST['debit']);
                 if ($credit > 0) {
                     $_POST['type'] = 'i';
                     $_POST['amount'] = $credit;
                 } else {
                     $_POST['type'] = 'e';
                     $_POST['amount'] = $debit;
                 }
             }
         case 'save_finance':
             if (isset($_REQUEST['butt_del'])) {
                 $this->delete($_REQUEST['finance_id']);
                 redirect_browser(self::link_open(false));
             }
             if (isset($_REQUEST['butt_unlink'])) {
                 // unlink this finance_id from other finance_ids.
                 $sql = "UPDATE `" . _DB_PREFIX . "finance` SET parent_finance_id = 0 WHERE parent_finance_id = '" . (int) $_REQUEST['finance_id'] . "'";
                 query($sql);
                 $sql = "UPDATE `" . _DB_PREFIX . "invoice_payment` SET parent_finance_id = 0 WHERE parent_finance_id = '" . (int) $_REQUEST['finance_id'] . "'";
                 query($sql);
                 redirect_browser(self::link_open(false));
             }
             $temp_data = $this->get_finance($_REQUEST['finance_id']);
             $data = $_POST + $temp_data;
             // save the finance categories and account.
             $account_id = $_REQUEST['finance_account_id'];
             if ((string) (int) $account_id != (string) $account_id && strlen($account_id) > 2) {
                 // we have a new account to create.
                 $account_id = update_insert('finance_account_id', 'new', 'finance_account', array('name' => $account_id));
             }
             $data['finance_account_id'] = $account_id;
             $finance_id = update_insert('finance_id', isset($_REQUEST['finance_id']) ? $_REQUEST['finance_id'] : 'new', 'finance', $data);
             module_extra::save_extras('finance', 'finance_id', $finance_id);
             if (!isset($data['tax_ids']) && isset($data['taxes']) && is_array($data['taxes'])) {
                 // default data when saving a new invoice payment to finance area
                 $data['tax_ids'] = array();
                 $data['tax_names'] = array();
                 $data['tax_percents'] = array();
                 $data['tax_increment_checkbox'] = 0;
                 foreach ($data['taxes'] as $tax) {
                     $data['tax_ids'][] = false;
                     $data['tax_names'][] = $tax['name'];
                     $data['tax_percents'][] = $tax['percent'];
                     $data['tax_amount'][] = $tax['amount'];
                     if ($tax['increment']) {
                         $data['tax_increment_checkbox'] = 1;
                     }
                 }
             }
             // save the finance tax rates (copied from invoice.php)
             if (isset($data['tax_ids']) && isset($data['tax_names']) && $data['tax_percents']) {
                 $existing_taxes = get_multiple('finance_tax', array('finance_id' => $finance_id), 'finance_tax_id', 'exact', 'order');
                 $order = 1;
                 foreach ($data['tax_ids'] as $key => $val) {
                     if ((int) $val > 0 && isset($existing_taxes[$val])) {
                         // this means we are trying to update an existing record on the finance_tax table, we confirm this id matches this finance.
                         $finance_tax_id = $val;
                         unset($existing_taxes[$finance_tax_id]);
                         // so we know which ones to remove from the end.
                     } else {
                         $finance_tax_id = false;
                         // create new record
                     }
                     $finance_tax_data = array('finance_id' => $finance_id, 'percent' => isset($data['tax_percents'][$key]) ? $data['tax_percents'][$key] : 0, 'amount' => isset($data['tax_amount'][$key]) ? $data['tax_amount'][$key] : 0, 'name' => isset($data['tax_names'][$key]) ? $data['tax_names'][$key] : 'TAX', 'order' => $order++, 'increment' => isset($data['tax_increment_checkbox']) && $data['tax_increment_checkbox'] ? 1 : 0);
                     $finance_tax_id = update_insert('finance_tax_id', $finance_tax_id, 'finance_tax', $finance_tax_data);
                 }
                 foreach ($existing_taxes as $existing_tax) {
                     delete_from_db('finance_tax', array('finance_id', 'finance_tax_id'), array($finance_id, $existing_tax['finance_tax_id']));
                 }
             }
             $category_ids = isset($_REQUEST['finance_category_id']) && is_array($_REQUEST['finance_category_id']) ? $_REQUEST['finance_category_id'] : array();
             $sql = "DELETE FROM `" . _DB_PREFIX . "finance_category_rel` WHERE finance_id = {$finance_id}";
             query($sql);
             foreach ($category_ids as $category_id) {
                 $category_id = (int) $category_id;
                 if ($category_id <= 0) {
                     continue;
                 }
                 $sql = "REPLACE INTO `" . _DB_PREFIX . "finance_category_rel` SET finance_id = {$finance_id}, finance_category_id = {$category_id}";
                 query($sql);
             }
             if (isset($_REQUEST['finance_category_new']) && strlen(trim($_REQUEST['finance_category_new'])) > 0) {
                 $category_name = trim($_REQUEST['finance_category_new']);
                 $category_id = update_insert('finance_category_id', 'new', 'finance_category', array('name' => $category_name));
                 if (isset($_REQUEST['finance_category_new_checked'])) {
                     $sql = "REPLACE INTO `" . _DB_PREFIX . "finance_category_rel` SET finance_id = {$finance_id}, finance_category_id = {$category_id}";
                     query($sql);
                 }
             }
             if (isset($_REQUEST['invoice_payment_id']) && (int) $_REQUEST['invoice_payment_id'] > 0) {
                 // link this as a child invoice payment to this one.
                 update_insert('invoice_payment_id', $_REQUEST['invoice_payment_id'], 'invoice_payment', array('parent_finance_id' => $finance_id));
             }
             if (isset($_REQUEST['finance_recurring_id']) && (int) $_REQUEST['finance_recurring_id'] > 0) {
                 // if we have set a custom "next recurring date" then we don't recalculate this date unless we are saving a new finance id.
                 $recurring = self::get_recurring($_REQUEST['finance_recurring_id']);
                 if (!(int) $_REQUEST['finance_id'] || !$recurring['next_due_date_custom']) {
                     self::calculate_recurring_date((int) $_REQUEST['finance_recurring_id'], true);
                 }
                 // we also have to adjust the starting balance of our recurring amount by this amount.
                 // just a little helpful feature.
                 if (!(int) $_REQUEST['finance_id']) {
                     $balance = module_config::c('finance_recurring_start_balance', 0);
                     if ($balance != 0) {
                         if ($data['type'] == 'e') {
                             $balance -= $data['amount'];
                         } else {
                             if ($data['type'] == 'i') {
                                 $balance += $data['amount'];
                             }
                         }
                         module_config::save_config('finance_recurring_start_balance', $balance);
                     }
                 }
                 // redirect back to recurring listing.
                 set_message('Recurring transaction saved successfully');
                 if (isset($_REQUEST['recurring_next']) && $_REQUEST['recurring_next']) {
                     redirect_browser($_REQUEST['recurring_next']);
                 }
                 redirect_browser(self::link_open_recurring(false));
             }
             set_message(_l('Transaction saved successfully: %s', module_finance::link_open($finance_id, true)));
             if (isset($_REQUEST['job_id']) && (int) $_REQUEST['job_id'] > 0) {
                 redirect_browser(module_job::link_open((int) $_REQUEST['job_id']));
             }
             if (isset($_REQUEST['butt_save_return'])) {
                 if (isset($_REQUEST['_redirect']) && strlen($_REQUEST['_redirect'])) {
                     redirect_browser($_REQUEST['_redirect']);
                 }
                 redirect_browser(self::link_open(false, false));
             }
             if ($_REQUEST['_process'] == 'quick_save_finance') {
                 redirect_browser(self::link_open(false, false));
             }
             redirect_browser(self::link_open($finance_id, false));
             break;
         case 'save_recurring':
             if (isset($_REQUEST['butt_del'])) {
                 $this->delete_recurring($_REQUEST['finance_recurring_id']);
                 redirect_browser(self::link_open_recurring(false));
             }
             $data = $_POST;
             // save the finance categories and account.
             $account_id = $_REQUEST['finance_account_id'];
             if ((string) (int) $account_id != (string) $account_id && strlen($account_id) > 2) {
                 // we have a new account to create.
                 $account_id = update_insert('finance_account_id', 'new', 'finance_account', array('name' => $account_id));
             }
             if (isset($_REQUEST['finance_recurring_id']) && (int) $_REQUEST['finance_recurring_id']) {
                 $original_finance_recurring = self::get_recurring($_REQUEST['finance_recurring_id']);
             } else {
                 $original_finance_recurring = array();
             }
             $data['finance_account_id'] = $account_id;
             $finance_recurring_id = update_insert('finance_recurring_id', isset($_REQUEST['finance_recurring_id']) ? $_REQUEST['finance_recurring_id'] : 'new', 'finance_recurring', $data);
             if ((int) $finance_recurring_id > 0) {
                 $category_ids = isset($_REQUEST['finance_category_id']) && is_array($_REQUEST['finance_category_id']) ? $_REQUEST['finance_category_id'] : array();
                 $sql = "DELETE FROM `" . _DB_PREFIX . "finance_recurring_catrel` WHERE finance_recurring_id = {$finance_recurring_id}";
                 query($sql);
                 foreach ($category_ids as $category_id) {
                     $category_id = (int) $category_id;
                     if ($category_id <= 0) {
                         continue;
                     }
                     $sql = "REPLACE INTO `" . _DB_PREFIX . "finance_recurring_catrel` SET finance_recurring_id = {$finance_recurring_id}, finance_category_id = {$category_id}";
                     query($sql);
                 }
                 if (isset($_REQUEST['finance_category_new']) && strlen(trim($_REQUEST['finance_category_new'])) > 0) {
                     $category_name = trim($_REQUEST['finance_category_new']);
                     $category_id = update_insert('finance_category_id', 'new', 'finance_category', array('name' => $category_name));
                     if (isset($_REQUEST['finance_category_new_checked'])) {
                         $sql = "REPLACE INTO `" . _DB_PREFIX . "finance_recurring_catrel` SET finance_recurring_id = {$finance_recurring_id}, finance_category_id = {$category_id}";
                         query($sql);
                     }
                 }
                 $calculated_next_date = self::calculate_recurring_date($finance_recurring_id);
                 if (isset($data['set_next_due_date']) && $data['set_next_due_date']) {
                     $next_date = input_date($data['set_next_due_date']);
                     $next_due_date_real = module_finance::calculate_recurring_date($finance_recurring_id, true, false);
                     if ($next_date != $next_due_date_real) {
                         // we have accustom date.
                         update_insert('finance_recurring_id', $finance_recurring_id, 'finance_recurring', array('next_due_date' => $next_date, 'next_due_date_custom' => 1));
                     } else {
                         // date is the same. not doing a custom date any more
                         update_insert('finance_recurring_id', $finance_recurring_id, 'finance_recurring', array('next_due_date' => $next_due_date_real, 'next_due_date_custom' => 0));
                     }
                 }
                 /*
                                     $finance_recurring = self::get_recurring($finance_recurring_id);
                                     if($finance_recurring['next_due_date_custom']){
                                         $next_due_date_real = module_finance::calculate_recurring_date($finance_recurring_id,true,false);
                                         // unset the "custom" flag if we've picked the same date as what it should be.
                                         if($next_due_date_real == $finance_recurring['next_due_date']){
                                             module_finance::calculate_recurring_date($finance_recurring_id,true,true);
                                         }
                                     }*/
             }
             set_message('Recurring transaction saved successfully');
             //redirect_browser(self::link_open($finance_id,false));
             redirect_browser(self::link_open_recurring(false, false));
             break;
     }
 }
Пример #27
0
 public static function hook_customer_deleted($callback_name, $customer_id, $remove_linked_data)
 {
     if ((int) $customer_id > 0) {
         delete_from_db('email', 'customer_id', $customer_id);
     }
 }