public function init()
 {
     $this->links = array();
     $this->module_name = "webnpro_menu_module_redbooth";
     $this->module_position = '13';
     $this->version = '1.0';
     module_config::save_config('_menu_order_webnpro_menu_module_redbooth', '13');
 }
 public function init()
 {
     $this->links = array();
     $this->module_name = "webnpro_menu_module_template_builder";
     $this->module_position = '10';
     $this->version = '1.0';
     module_config::save_config('_menu_order_webnpro_menu_module_template_builder', '10');
 }
Ejemplo n.º 3
0
 public function init()
 {
     $this->module_name = "cache";
     $this->module_position = 1;
     $this->version = 2.229;
     // 2.229 - 2014-07-28 - menu generation speed improvement
     // 2.228 - 2014-05-12 - cache bug fixing
     // 2.227 - 2013-10-02 - cache bug fixing
     // 2.226 - 2013-09-12 - hopefully a BIG new speed improvement - change advanced cache_enabled to 1
     // 2.225 - 2013-09-12 - debug_cache advanced option added
     // 2.224 - 2013-09-10 - dashboard speed fix
     // 2.223 - 2013-09-08 - cache size fix
     // 2.222 - 2013-09-06 - cache_objects configuration variable (not cache_object)
     // 2.221 - 2013-09-03 - cache improvements and bug fixing
     // 2.22 - 2013-08-31 - cache and speed improvements
     // 2.21 - 2013-08-30 - better memcache support
     // 2.2 - 2013-08-30 - starting work on memcache support
     // version bug fix? maybe?
     // use memcache if it exists
     if (class_exists('Memcache', false) && module_config::c('cache_enabled', 1) && module_config::c('memcache_active', 0)) {
         self::$_memcache_instance = new Memcache();
         if (self::$_memcache_instance->connect(module_config::c('memcache_address', '127.0.0.1'), module_config::c('memcache_port', '11211'))) {
             //module_config::c('memcache_address','localhost'), )){
             self::$_memcache_prefix = md5(session_id() . _UCM_SECRET . _DB_PREFIX . _DB_NAME . _DB_USER . _DB_PASS);
             // what version of information are we requesting (inremented each time something is deleted, inserted or updated)
             // bad, but cannot think of any other easy quick way to invalidate caches upon updates
             self::$_memcache_version = self::$_memcache_instance->get(self::$_memcache_prefix . 'version');
             if (!self::$_memcache_version) {
                 self::$_memcache_version = 1;
             }
             self::$_use_memcache = true;
         }
     } else {
         if (module_config::c('cache_enabled', 1) && $this->db_table_exists('cache_store')) {
             $sql = "SELECT * FROM `" . _DB_PREFIX . "cache_store` WHERE expire_time > " . time();
             foreach (qa($sql) as $res) {
                 if (!isset(self::$_db_cache[$res['cache_group']])) {
                     self::$_db_cache[$res['cache_group']] = array();
                 }
                 self::$_db_cache[$res['cache_group']][$res['cache_key']] = $res['cache_data'];
             }
             register_shutdown_function('module_cache::shutdown_write_cached_data');
         }
     }
     // change to low number by default
     if (module_config::c('cache_objects', 120) == 3600) {
         module_config::save_config('cache_objects', 120);
     }
     if (module_config::c('cache_enabled', 1) && $this->db_table_exists('cache')) {
         $sql = "SELECT * FROM `" . _DB_PREFIX . "cache`";
         foreach (qa($sql) as $r) {
             self::$_cache_expiry[$r['cache_group']] = $r['expire_time'];
         }
     }
 }
Ejemplo n.º 4
0
 public static function save_job($job_id, $data)
 {
     if (isset($data['default_renew_auto']) && !isset($data['renew_auto'])) {
         $data['renew_auto'] = 0;
     }
     if (isset($data['default_renew_invoice']) && !isset($data['renew_invoice'])) {
         $data['renew_invoice'] = 0;
     }
     if (isset($data['total_percent_complete_override']) && $data['total_percent_complete_override'] != '' && $data['total_percent_complete_override'] <= 100) {
         $data['total_percent_complete_manual'] = 1;
         $data['total_percent_complete'] = $data['total_percent_complete_override'] / 100;
     } else {
         $data['total_percent_complete_manual'] = 0;
     }
     if (isset($data['customer_id']) && $data['customer_id'] > 0) {
         // check we have access to this customer from this job.
         $customer_check = module_customer::get_customer($data['customer_id']);
         if (!$customer_check || $customer_check['customer_id'] != $data['customer_id']) {
             unset($data['customer_id']);
         }
     }
     if (isset($data['website_id']) && $data['website_id']) {
         $website = module_website::get_website($data['website_id']);
         if ($website && (int) $website['website_id'] > 0 && $website['website_id'] == $data['website_id']) {
             // website exists.
             // make this one match the website customer_id, or set teh website customer_id if it doesn't have any.
             if ((int) $website['customer_id'] > 0) {
                 if ($data['customer_id'] > 0 && $data['customer_id'] != $website['customer_id']) {
                     set_message('Changed this Job to match the Website customer');
                 }
                 $data['customer_id'] = $website['customer_id'];
             } else {
                 if (isset($data['customer_id']) && $data['customer_id'] > 0) {
                     // set the website customer id to this as well.
                     update_insert('website_id', $website['website_id'], 'website', array('customer_id' => $data['customer_id']));
                 }
             }
         }
     }
     if ((int) $job_id > 0) {
         $original_job_data = self::get_job($job_id, false);
         if (!$original_job_data || $original_job_data['job_id'] != $job_id) {
             $original_job_data = array();
             $job_id = false;
         }
     } else {
         $original_job_data = array();
         $job_id = false;
     }
     if (!(int) $job_id && module_config::c('job_name_incrementing', 0)) {
         // incrememnt next job number on save.
         $job_number = module_config::c('job_name_incrementing_next', 1);
         module_config::save_config('job_name_incrementing_next', $job_number + 1);
     }
     $job_id = update_insert("job_id", $job_id, "job", $data);
     if ($job_id) {
         // save the job tax rates (copied from invoice.php)
         if (isset($data['tax_ids']) && isset($data['tax_names']) && $data['tax_percents']) {
             $existing_taxes = get_multiple('job_tax', array('job_id' => $job_id), 'job_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 job_tax table, we confirm this id matches this job.
                         $job_tax_id = $val;
                         unset($existing_taxes[$job_tax_id]);
                         // so we know which ones to remove from the end.
                     } else {
                         $job_tax_id = false;
                         // create new record
                     }
                     $job_tax_data = array('job_id' => $job_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);
                     $job_tax_id = update_insert('job_tax_id', $job_tax_id, 'job_tax', $job_tax_data);
                 }
             }
             foreach ($existing_taxes as $existing_tax) {
                 delete_from_db('job_tax', array('job_id', 'job_tax_id'), array($job_id, $existing_tax['job_tax_id']));
             }
         }
         module_cache::clear('job');
         $result = self::save_job_tasks($job_id, $data);
         $check_completed = true;
         switch ($result['status']) {
             case 'created':
                 // we added a new task.
                 break;
             case 'deleted':
                 // we deleted a task.
                 break;
             case 'edited':
                 // we changed a task (ie: completed?);
                 break;
             default:
                 // nothing changed.
                 // $check_completed = false;
                 break;
         }
         if ($check_completed) {
             self::update_job_completion_status($job_id);
         }
         if ($original_job_data) {
             // we check if the hourly rate has changed
             if (isset($data['hourly_rate']) && $data['hourly_rate'] != $original_job_data['hourly_rate']) {
                 // update all the task hours, but only for hourly tasks:
                 $sql = "UPDATE `" . _DB_PREFIX . "task` SET `amount` = 0 WHERE `hours` > 0 AND job_id = " . (int) $job_id . " AND ( manual_task_type = " . _TASK_TYPE_HOURS_AMOUNT;
                 if ($data['default_task_type'] == _TASK_TYPE_HOURS_AMOUNT) {
                     $sql .= " OR manual_task_type = -1 ";
                 }
                 $sql .= " )";
                 query($sql);
             }
             // check if the job assigned user id has changed.
             if (module_config::c('job_allow_staff_assignment', 1)) {
                 if (isset($data['user_id'])) {
                     // && $data['user_id'] != $original_job_data['user_id']){
                     // user id has changed! update any that were the old user id.
                     $sql = "UPDATE `" . _DB_PREFIX . "task` SET `user_id` = " . (int) $data['user_id'] . " WHERE (`user_id` = " . (int) $original_job_data['user_id'] . " OR user_id = 0) AND job_id = " . (int) $job_id;
                     query($sql);
                 }
             }
             // check if the due date has changed.
             if (isset($original_job_data['date_due']) && $original_job_data['date_due'] && isset($data['date_due']) && $data['date_due'] && $data['date_due'] != '0000-00-00' && $original_job_data['date_due'] != $data['date_due']) {
                 // the date has changed.
                 // update all the tasks with this new date.
                 $tasks = self::get_tasks($job_id);
                 foreach ($tasks as $task) {
                     if (!$task['date_due'] || $task['date_due'] == '0000-00-00') {
                         // no previously set task date. set it
                         update_insert('task_id', $task['task_id'], 'task', array('date_due' => $data['date_due']));
                     } else {
                         if ($task['date_due'] == $original_job_data['date_due']) {
                             // the date was the old date. do we change it?
                             // only change it on incompleted tasks.
                             $percentage = self::get_percentage($task);
                             if ($percentage < 1 || module_config::c('job_tasks_overwrite_completed_due_dates', 0) && $percentage == 1) {
                                 update_insert('task_id', $task['task_id'], 'task', array('date_due' => $data['date_due']));
                             }
                         } else {
                             // there's a new date
                             if (module_config::c('job_tasks_overwrite_diff_due_date', 0)) {
                                 update_insert('task_id', $task['task_id'], 'task', array('date_due' => $data['date_due']));
                             }
                         }
                     }
                 }
             }
         }
     }
     if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) {
         module_extra::save_extras('job', 'job_id', $job_id);
     }
     module_cache::clear('job');
     return $job_id;
 }
Ejemplo n.º 5
0
 public static function save_quote($quote_id, $data)
 {
     if (isset($data['customer_id']) && $data['customer_id'] > 0) {
         // check we have access to this customer from this quote.
         $customer_check = module_customer::get_customer($data['customer_id']);
         if (!$customer_check || $customer_check['customer_id'] != $data['customer_id']) {
             unset($data['customer_id']);
         }
     }
     if (isset($data['website_id']) && $data['website_id']) {
         $website = module_website::get_website($data['website_id']);
         if ($website && (int) $website['website_id'] > 0 && $website['website_id'] == $data['website_id']) {
             // website exists.
             // make this one match the website customer_id, or set teh website customer_id if it doesn't have any.
             if ((int) $website['customer_id'] > 0) {
                 if ($data['customer_id'] > 0 && $data['customer_id'] != $website['customer_id']) {
                     set_message('Changed this Quote to match the Website customer');
                 }
                 $data['customer_id'] = $website['customer_id'];
             } else {
                 if (isset($data['customer_id']) && $data['customer_id'] > 0) {
                     // set the website customer id to this as well.
                     update_insert('website_id', $website['website_id'], 'website', array('customer_id' => $data['customer_id']));
                 }
             }
         }
     }
     if ((int) $quote_id > 0) {
         $original_quote_data = self::get_quote($quote_id, false);
         if (!$original_quote_data || $original_quote_data['quote_id'] != $quote_id) {
             $original_quote_data = array();
             $quote_id = false;
         }
     } else {
         $original_quote_data = array();
         $quote_id = false;
     }
     // check create permissions.
     if (!$quote_id && !self::can_i('create', 'Quotes')) {
         // user not allowed to create quotes.
         set_error('Unable to create new Quotes');
         redirect_browser(self::link_open(false));
     }
     if (!(int) $quote_id && module_config::c('quote_name_incrementing', 0)) {
         // incrememnt next quote number on save.
         $quote_number = module_config::c('quote_name_incrementing_next', 1);
         module_config::save_config('quote_name_incrementing_next', $quote_number + 1);
     }
     $quote_id = update_insert("quote_id", $quote_id, "quote", $data);
     $return = false;
     if ($quote_id) {
         hook_handle_callback('quote_save', $quote_id);
         // save the quote tax rates (copied from invoice.php)
         if (isset($data['tax_ids']) && isset($data['tax_names']) && $data['tax_percents']) {
             $existing_taxes = get_multiple('quote_tax', array('quote_id' => $quote_id), 'quote_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 quote_tax table, we confirm this id matches this quote.
                         $quote_tax_id = $val;
                         unset($existing_taxes[$quote_tax_id]);
                         // so we know which ones to remove from the end.
                     } else {
                         $quote_tax_id = false;
                         // create new record
                     }
                     $quote_tax_data = array('quote_id' => $quote_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);
                     $quote_tax_id = update_insert('quote_tax_id', $quote_tax_id, 'quote_tax', $quote_tax_data);
                 }
             }
             foreach ($existing_taxes as $existing_tax) {
                 delete_from_db('quote_tax', array('quote_id', 'quote_tax_id'), array($quote_id, $existing_tax['quote_tax_id']));
             }
         }
         module_cache::clear('quote');
         $return = array('quote_id' => $quote_id, 'task_result' => self::save_quote_tasks($quote_id, $data));
         $check_completed = true;
         switch ($return['task_result']['status']) {
             case 'created':
                 // we added a new task.
                 break;
             case 'deleted':
                 // we deleted a task.
                 break;
             case 'edited':
                 // we changed a task (ie: completed?);
                 break;
             default:
                 // nothing changed.
                 // $check_completed = false;
                 break;
         }
         if ($check_completed) {
             self::update_quote_completion_status($quote_id);
         }
         if ($original_quote_data) {
             // we check if the hourly rate has changed
             if (isset($data['hourly_rate']) && $data['hourly_rate'] != $original_quote_data['hourly_rate']) {
                 // update all the task hours, but only for hourly tasks:
                 $sql = "UPDATE `" . _DB_PREFIX . "quote_task` SET `amount` = 0 WHERE `hours` > 0 AND quote_id = " . (int) $quote_id . " AND ( manual_task_type = " . _TASK_TYPE_HOURS_AMOUNT;
                 if ($data['default_task_type'] == _TASK_TYPE_HOURS_AMOUNT) {
                     $sql .= " OR manual_task_type = -1 ";
                 }
                 $sql .= " )";
                 query($sql);
             }
             // check if the quote assigned user id has changed.
             if (module_config::c('quote_allow_staff_assignment', 1)) {
                 if (isset($data['user_id'])) {
                     // && $data['user_id'] != $original_quote_data['user_id']){
                     // user id has changed! update any that were the old user id.
                     $sql = "UPDATE `" . _DB_PREFIX . "quote_task` SET `user_id` = " . (int) $data['user_id'] . " WHERE (`user_id` = " . (int) $original_quote_data['user_id'] . " OR user_id = 0) AND quote_id = " . (int) $quote_id;
                     query($sql);
                 }
             }
             // check if the quote was approved.
             if (!isset($original_quote_data['date_approved']) || !$original_quote_data['date_approved'] || $original_quote_data['date_approved'] == '0000-00-00') {
                 // original quote wasn't approved.
                 if (isset($data['date_approved']) && !empty($data['date_approved']) && $data['date_approved'] != '0000-00-00') {
                     // quote was approved!
                     self::quote_approved($quote_id);
                 }
             }
         }
     }
     if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) {
         module_extra::save_extras('quote', 'quote_id', $quote_id);
     }
     module_cache::clear('quote');
     return $return;
 }
Ejemplo n.º 6
0
 /**
  * Save menu
  * @param array $items
  */
 public function save_menu($items)
 {
     if (!isset($menu_items)) {
         $menu_items = array();
     }
     if (!isset($external_menu_items)) {
         $external_menu_items = array();
     }
     if (!isset($items)) {
         $items = array();
     }
     $before_dashboard = true;
     $i = 0;
     foreach ($items['menu_name'] as $item) {
         if ($items['menu_name'][$i] != '') {
             $menu_items[$i]['name'] = $items['menu_name'][$i];
             $menu_items[$i]['icon_name'] = $items['menu_icon'][$i];
             $menu_items[$i]['url'] = $items['menu_url'][$i];
             $menu_items[$i]['m'] = $items['menu_module'][$i] != '' ? $items['menu_module'][$i] : "webnpro_menu_module_" . module_webnpro_menu_editor::slug($menu_item['name']);
             $menu_items[$i]['p'] = $items['menu_page'][$i];
             if ($menu_items[$i]['m'] == 'dashboard') {
                 $before_dashboard = false;
             }
             if ($before_dashboard) {
                 $menu_items[$i]['order'] = $i - 9999;
             } else {
                 $menu_items[$i]['order'] = $i;
             }
             if ($menu_items[$i]['url'] != '' && $menu_items[$i]['m'] != 'dashboard') {
                 $external_menu_items[] = $menu_items[$i];
             }
             // Save menu order
             module_config::save_config('_menu_order_' . $menu_items[$i]['m'], $i);
             $i++;
         }
     }
     // Create new custom menu modules
     if (count($external_menu_items)) {
         module_webnpro_menu_editor::create_menu_plugins($external_menu_items);
         header('Location: ' . $_SERVER['REQUEST_URI']);
     }
     /* END public function save_menu($items) */
 }
Ejemplo n.º 7
0
 public function complete_plugin_installation($plugin_name)
 {
     global $plugins;
     $result = array('message' => '');
     $new_system_version = module_config::current_version();
     $fail = false;
     if (isset($plugins[$plugin_name])) {
         $result['message'] .= "Processing update: <span style='text-decoration:underline;'>" . $plugin_name . "</span> - Current Version: " . $plugins[$plugin_name]->get_plugin_version() . ".... ";
         ob_start();
         if ($version = $plugins[$plugin_name]->install_upgrade()) {
             $result['message'] .= '<span class="success_text">all good</span>';
             $new_system_version = max($version, $new_system_version);
             $plugins[$plugin_name]->init();
             // lol typo - oh well.
             $plugins[$plugin_name]->set_insatlled_plugin_version($version);
         } else {
             $fail = true;
             $result['message'] .= '<span class="error_text">failed</span> ';
         }
         $result['message'] .= ob_get_clean() . '<br/>';
         $result['message'] .= '<br/>';
         if ($fail) {
             $result['message'] .= _('Some things failed. Please go back and try again.');
         } else {
             $result['message'] .= '<strong>' . _l('Success! Everything worked.') . '</strong>';
             module_config::set_system_version($new_system_version);
             module_config::save_config('last_update', time());
         }
         if (isset($_SESSION['_message']) && count($_SESSION['_message'])) {
             $result['message'] .= '<br/>';
             $result['message'] .= implode('<br/>', $_SESSION['_message']);
             unset($_SESSION['_errors']);
         }
         if (isset($_SESSION['_errors']) && count($_SESSION['_errors'])) {
             $result['message'] .= '<br/>';
             $result['message'] .= implode('<br/>', $_SESSION['_errors']);
             unset($_SESSION['_errors']);
         }
     } else {
         if ($plugin_name == 'corefiles' || $plugin_name == 'database') {
         } else {
             $fail = true;
         }
     }
     // hack to clear db field cache:
     module_cache::clear('db');
     if (!$fail) {
         $result['success'] = 1;
     }
     return $result;
 }
Ejemplo n.º 8
0
/** 
 * Copyright: dtbaker 2012
 * Licence: Please check CodeCanyon.net for licence details. 
 * More licence clarification available here:  http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ 
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
if (!module_config::can_i('view', 'Settings')) {
    redirect_browser(_BASE_HREF);
}
print_heading('Menu Order (beta!)');
if (isset($_REQUEST['save_config']) && is_array($_REQUEST['save_config'])) {
    foreach ($_REQUEST['save_config'] as $key => $val) {
        module_config::save_config($key, $val);
    }
    set_message('Menu order saved');
}
?>

<form action="" method="post">
    <table class="tableclass tableclass_rows">
        <thead>
        <tr>
            <th class="width2">
                <?php 
_e('Menu Item');
?>
            </th>
            <th>
Ejemplo n.º 9
0
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
if (!module_finance::can_i('view', 'Finance Upcoming')) {
    redirect_browser(_BASE_HREF);
}
$module->page_title = 'Recurring';
$search = isset($_REQUEST['search']) ? $_REQUEST['search'] : array();
if (module_config::c('finance_recurring_show_finished', 0)) {
    $search['show_finished'] = true;
}
if (!isset($search['date_to'])) {
    $search['date_to'] = print_date(strtotime('+' . (int) module_config::c('finance_recurring_months', 6) . ' months'));
}
$balance = isset($_REQUEST['balance']) ? (double) $_REQUEST['balance'] : module_config::c('finance_recurring_start_balance', 0);
module_config::save_config('finance_recurring_start_balance', $balance);
$_SESSION['_finance_recurring_ids'] = array();
module_debug::log(array('title' => 'calling get_recurrings', 'data' => ''));
$upcoming_finances_unsorted = module_finance::get_recurrings($search);
module_debug::log(array('title' => 'finished calling get_recurrings', 'data' => 'count: ' . count($upcoming_finances_unsorted)));
$upcoming_finances = array();
$limit_timestamp = isset($search['date_to']) && !empty($search['date_to']) ? strtotime(input_date($search['date_to'])) : strtotime('+' . (int) module_config::c('finance_recurring_months', 6) . ' months');
$duplicate_limit = 30;
$upcoming_finance_key = 0;
foreach ($upcoming_finances_unsorted as $recurring) {
    $time = strtotime($recurring['next_due_date']);
    $original = true;
    $count = 0;
    while ($time < $limit_timestamp) {
        $next_time = 0;
        if ($count++ > $duplicate_limit) {
Ejemplo n.º 10
0
 public static function run_cron($debug = false)
 {
     // only run this cron max once every hour
     // so if the cron job runs every 5 minutes only execute this every 20
     $refresh_interval = module_config::c('customer_status_cron_refresh_time', 60);
     $last_customer_refresh = module_config::c('customer_status_cron_refresh_last', 0);
     if ($last_customer_refresh <= 0 || $last_customer_refresh + $refresh_interval * 60 <= time()) {
         module_config::save_config('customer_status_cron_refresh_last', time());
         // find any customers with unpaid invoices
         if (class_exists('module_invoice', false)) {
             $sql = "SELECT * FROM `" . _DB_PREFIX . "customer` c ";
             $sql .= " RIGHT JOIN `" . _DB_PREFIX . "invoice` i ON c.customer_id = i.customer_id";
             $sql .= " WHERE ";
             $sql .= " c.customer_status = 0 ";
             $sql .= " OR ( i.date_paid = '0000-00-00' AND i.date_due <= '" . date('Y-m-d') . "' AND c.customer_status != " . _CUSTOMER_STATUS_OVERDUE . " )";
             $sql .= " OR ( i.date_paid != '0000-00-00' AND ( c.customer_status = " . _CUSTOMER_STATUS_OWING . " OR c.customer_status = " . _CUSTOMER_STATUS_OVERDUE . " ) )";
             $sql .= " GROUP BY c.customer_id";
             $customers = qa($sql);
             //print_r($customers);
             foreach ($customers as $c) {
                 self::update_customer_status($c['customer_id'], $debug);
             }
         }
     }
 }
Ejemplo n.º 11
0
    $correct_hash = md5(_UCM_SECRET . ' secret hash ');
    if (!isset($_REQUEST['hash']) || $_REQUEST['hash'] != $correct_hash) {
        echo 'failed - please check cron.php link in settings';
        exit;
    }
}
$_SERVER['REMOTE_ADDR'] = false;
$_SERVER['HTTP_HOST'] = false;
$_SERVER['REQUEST_URI'] = false;
$noredirect = true;
$disable_sessions = true;
require_once "init.php";
// stop running cron multiple times
$cron_minimum_delay = 180;
// 180 seconds = 3 mins.
$last_cron_run_time = module_config::c('cron_last_run', 0);
if ($last_cron_run_time > 0 && $last_cron_run_time + $cron_minimum_delay >= $cron_start_time) {
    // the last cron job ran less than 3 minutes ago, don't run it again.
    exit;
}
$cron_debug = module_config::c('debug_cron_jobs', 0);
foreach ($plugins as $plugin_name => &$plugin) {
    if (method_exists($plugin, 'run_cron')) {
        if ($cron_debug) {
            echo "Running {$plugin_name} cron job <br>\n";
        }
        $plugin->run_cron($cron_debug);
    }
}
module_config::save_config('cron_last_run', $cron_start_time);
Ejemplo n.º 12
0
 /**
  * Update the plugin and redirect back to the plugins settings page
  * @return string Messages about the updating procedure
  */
 public function update()
 {
     echo '<font color="green"><strong>' . _l('[ DOWNLOAD THE LATEST VERSION ]') . '</strong></font>';
     $plugin_directory = dirname(__FILE__) . '/../';
     $info = parse_ini_file(dirname(__FILE__) . '/../plugin.info');
     $plugin_name = $info['modulename'];
     $plugin_ver = $info['version'];
     $plugin_id = $info['id'];
     $api_url = "http://zeus.webnpro.com/api/api.php";
     $zipFile = $plugin_id . '.zip';
     $zipDir = dirname(__FILE__) . '/updates/';
     //Make the directory if we need to...
     if (!is_dir($zipDir)) {
         mkdir($zipDir, 0755, true);
     }
     $zipFile = $zipDir . $zipFile;
     $zipResource = fopen($zipFile, "w");
     $curlvars = "download=1&id=" . $plugin_id . "&ver=" . $plugin_ver . "&key=" . module_config::c($plugin_name . '_envato_license_number', 1);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $api_url);
     curl_setopt($ch, CURLOPT_HEADER, false);
     curl_setopt($ch, CURLOPT_POST, count($curlvars));
     curl_setopt($ch, CURLOPT_POSTFIELDS, $curlvars);
     curl_setopt($ch, CURLOPT_FAILONERROR, true);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_AUTOREFERER, true);
     curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
     curl_setopt($ch, CURLOPT_TIMEOUT, 10);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($ch, CURLOPT_FILE, $zipResource);
     $data = curl_exec($ch);
     curl_close($ch);
     fclose($zipFile);
     echo '<font color="green"><strong>' . _l('[ UPDATE THE FILES ]') . '</strong></font>';
     //Open The File And Do Stuff
     $zipHandle = zip_open($zipFile);
     while ($aF = zip_read($zipHandle)) {
         $thisFileName = zip_entry_name($aF);
         $thisFileDir = dirname($thisFileName);
         //Continue if its not a file
         if (substr($thisFileName, -1, 1) == '/') {
             continue;
         }
         //Make the directory if we need to...
         if (!is_dir($plugin_directory . $thisFileDir)) {
             mkdir($plugin_directory . $thisFileDir, 0755, true);
         }
         //Overwrite the file
         if (!is_dir($plugin_directory . $thisFileName)) {
             $contents = zip_entry_read($aF, zip_entry_filesize($aF));
             $file_ext = array_pop(explode(".", $thisFileName));
             $ext_ignore = array('png', 'jpg', 'gif');
             if (!in_array($file_ext, $ext_ignore)) {
                 $contents = str_replace("\r\n", "\n", $contents);
             }
             $updateThis = '';
             $updateThis = fopen($plugin_directory . $thisFileName, 'w');
             fwrite($updateThis, $contents);
             fclose($updateThis);
             unset($contents);
         }
     }
     //If we need to run commands, then do it.
     if (is_file($plugin_directory . '/_update.php')) {
         echo '<font color="green"><strong>' . _l('[ RUN UPDATE SCRIPT ]') . '</strong></font>';
         include $plugin_directory . '/_update.php';
         unlink($plugin_directory . '/_update.php');
     }
     // Delete the downloaded zip file
     if (is_file($zipFile)) {
         unlink($zipFile);
     }
     // Set the new plugin version in the config table
     module_config::save_config('_plugin_version_' . $plugin_name, $plugin_ver);
     echo '<font color="green"><strong>' . _l('[ PLUGIN UPDATED ]') . '</strong></font><br>';
     echo '<font color="red"><strong><a style="color: red; font-weight: bold;" href="' . $this->settingsURL() . '">' . _l('[ REDIRECT BACK TO THE PLUGINS SETTINGS PAGE IN 5 SECONDS ]') . '</a></strong></font>';
     header("Refresh: 5;url=" . $this->settingsURL());
     return $output;
     /* END public function update() */
 }
Ejemplo n.º 13
0
';
					ucm.backup.backup_post_data = {backup_file:'<?php 
            echo $backup_file_base;
            ?>
'};
					ucm.backup.init();
					ucm.backup.start_backup();
				});
			</script>

			<?php 
        } else {
            if (isset($_GET['completed'])) {
                // we've just automatically redirected from completing the backup.
                // save this backup date/time in the database so we can use it to generate backup reminders.
                module_config::save_config('backup_time', time());
            }
            $fieldset_data = array('heading' => array('title' => _l('Backup'), 'type' => 'h3'), 'elements' => array());
            $fieldset_data['elements'] = array(array('message' => _l('Important: Please download this backup file and save it in a secure location. Once this backup has been downloaded to your computer please delete it from here.')), array('message' => _l('After downloading, please unzip this backup on your computer and confirm all the files and database exist.')), array('title' => 'Created Date', 'fields' => array(print_date(isset($backup['date_created']) ? $backup['date_created'] : time(), true))), array('title' => 'Backup Size', 'fields' => array(function () use($backup) {
                if (isset($backup['backup_file']) && strlen($backup['backup_file']) && file_exists(_BACKUP_BASE_DIR . basename($backup['backup_file']) . '.zip')) {
                    echo module_file::format_bytes(filesize(_BACKUP_BASE_DIR . basename($backup['backup_file']) . '.zip')) . ' ' . _l('files');
                    echo '<br/> ';
                }
                if (isset($backup['backup_file']) && strlen($backup['backup_file']) && file_exists(_BACKUP_BASE_DIR . basename($backup['backup_file']) . '.sql')) {
                    echo module_file::format_bytes(filesize(_BACKUP_BASE_DIR . basename($backup['backup_file']) . '.sql')) . ' ' . _l('database');
                    echo '<br/> ';
                }
                if (isset($backup['backup_file']) && strlen($backup['backup_file']) && file_exists(_BACKUP_BASE_DIR . basename($backup['backup_file']) . '.sql.gz')) {
                    echo module_file::format_bytes(filesize(_BACKUP_BASE_DIR . basename($backup['backup_file']) . '.sql.gz')) . ' ' . _l('database');
                    echo '<br/> ';
                }
Ejemplo n.º 14
0
 * IP Address: 67.79.165.254
 */
if (!module_config::can_i('view', 'Settings')) {
    redirect_browser(_BASE_HREF);
}
if (class_exists('module_security', false)) {
    // if they are not allowed to "edit" a page, but the "view" permission exists
    // then we automatically grab the page and regex all the crap out of it that they are not allowed to change
    // eg: form elements, submit buttons, etc..
    module_security::check_page(array('category' => 'Config', 'page_name' => 'Settings', 'module' => 'config', 'feature' => 'Edit'));
}
$module->page_title = 'System Settings';
print_heading(array('title' => 'Basic System Settings', 'type' => 'h2', 'main' => true));
$settings = array(array('key' => 'system_base_dir', 'default' => '/', 'type' => 'text', 'description' => 'Base URL for your system (eg: / or /admin/)'), array('key' => 'system_base_href', 'default' => '', 'type' => 'text', 'description' => 'URL for your system (eg: http://foo.com)'), array('key' => 'admin_system_name', 'default' => 'Ultimate Client Manager', 'type' => 'text', 'description' => 'Name your system'), array('key' => 'header_title', 'default' => 'UCM', 'type' => 'text', 'description' => 'Text to appear in header'), 'date_format' => array('key' => 'date_format', 'default' => 'd/m/Y', 'type' => 'text', 'description' => 'Date format for system'), 'date_input' => array('key' => 'date_input', 'default' => '1', 'type' => 'select', 'description' => 'Date format', 'options' => array(1 => 'd/m/Y', 2 => 'Y/m/d', 3 => 'm/d/Y')), array('key' => 'timezone', 'default' => 'America/New_York', 'type' => 'text', 'description' => 'Your timezone (<a href="http://php.net/manual/en/timezones.php">see all</a>) '), array('key' => 'alert_days_in_future', 'default' => '5', 'type' => 'text', 'description' => 'Days to alert due tasks in future (for dashboard)'), array('key' => 'hide_extra', 'default' => '1', 'type' => 'checkbox', 'description' => 'Hide "extra" form fields by default'), array('key' => 'hourly_rate', 'default' => '60', 'type' => 'text', 'description' => 'Default hourly rate'), array('key' => 'job_type_default', 'default' => 'Website Design', 'type' => 'text', 'description' => 'Default type of job'), array('key' => 'tax_name', 'default' => 'TAX', 'type' => 'text', 'description' => 'What is your TAX called? (eg: GST)'), array('key' => 'tax_percent', 'default' => '10', 'type' => 'text', 'description' => 'Percentage tax to calculate by default? (eg: 10)'), array('key' => 'todo_list_limit', 'default' => '6', 'type' => 'text', 'description' => 'Number of TODO items to show'), array('key' => 'admin_email_address', 'default' => '*****@*****.**', 'type' => 'text', 'description' => 'The admins email address'));
if (in_array(module_config::c('date_format', 'd/m/Y'), $settings['date_input']['options'])) {
    unset($settings['date_format']);
    // hack to save the 'date_format' based on the date input
    $current_format = $settings['date_input']['options'][module_config::c('date_input', 1)];
    if ($current_format) {
        module_config::save_config('date_format', $current_format);
    }
}
if (class_exists('module_security', false)) {
    $roles = array();
    foreach (module_security::get_roles() as $r) {
        $roles[$r['security_role_id']] = $r['name'];
    }
    $settings[] = array('key' => 'contact_default_role', 'default' => '', 'type' => 'select', 'options' => $roles, 'description' => 'When creating a new contact, assign this role<br>(don\'t give them too many permissions!)');
    $settings[] = array('key' => 'user_default_role', 'default' => '', 'type' => 'select', 'options' => $roles, 'description' => 'When creating a new user, assign this role');
}
module_config::print_settings_form(array('settings' => $settings));
Ejemplo n.º 15
0
    public static function output_dashboard_alerts($ajax = false)
    {
        module_debug::log(array('title' => 'Outputting Dashboard Alerts', 'data' => ''));
        if ($ajax && module_config::c('dashboard_alerts_as_tabs', 1)) {
            $items_to_hide = json_decode(module_config::c('_dashboard_item_hide' . module_security::get_loggedin_id(), '{}'), true);
            if (!is_array($items_to_hide)) {
                $items_to_hide = array();
            }
            if (isset($_REQUEST['hide_item']) && strlen($_REQUEST['hide_item'])) {
                $items_to_hide[] = $_REQUEST['hide_item'];
                module_config::save_config('_dashboard_item_hide' . module_security::get_loggedin_id(), json_encode($items_to_hide));
            }
            $dashboard_alerts = array();
            include module_theme::include_ucm('includes/plugin_dashboard/pages/dashboard_alerts.php');
            // output some javascript that will load our ajax hooks and display in a tab one by one
            ?>

            <script type="text/javascript">
                $(function(){
                    setTimeout(function(){
                        //$('body').append('<scr'+'ipt type="text/javascript" src="<?php 
            echo _BASE_HREF;
            ?>
?m=dashboard&_process=ajax_dashboard_tabs"></scri'+'pt>');
                        var scriptObject = document.createElement('script');
                        scriptObject .type = 'text/javascript';
                        scriptObject .async = true;
                        scriptObject .src = "<?php 
            echo _BASE_HREF;
            ?>
?m=dashboard&_process=ajax_dashboard_tabs&<?php 
            echo isset($_REQUEST['show_hidden']) ? 'show_hidden' : '';
            ?>
";
                        document.getElementsByTagName('head')[0].appendChild(scriptObject );
                        $('#dashboard_tabs').before('<p id="tabs_loading"><?php 
            _e('Loading Alerts...');
            ?>
</p>');
                    }, 200);
                });
            </script>

            <?php 
        } else {
            // we collect alerts from various places using our UCM hooks:
            $dashboard_alerts = self::get_dashboard_alerts();
            include module_theme::include_ucm('includes/plugin_dashboard/pages/dashboard_alerts.php');
        }
    }
Ejemplo n.º 16
0
<?php

/** 
 * Copyright: dtbaker 2012
 * Licence: Please check CodeCanyon.net for licence details. 
 * More licence clarification available here:  http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ 
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca
 * Package Date: 2015-11-25 02:55:20 
 * IP Address: 67.79.165.254
 */
if (_UCM_INSTALLED && !module_security::is_logged_in() && !module_config::c('cron_last_run', 0) && !module_config::c('initial_setup_complete', 0)) {
    module_config::save_config('initial_setup_complete', 1);
    $_REQUEST['auto_login'] = module_security::get_auto_login_string(1);
    if (!module_security::auto_login(false)) {
        echo 'Failed to login automatically...';
    }
}
if (_UCM_INSTALLED && !module_security::is_logged_in()) {
    ob_end_clean();
    echo 'Something went wrong. Please login and go to Settings > Upgrade. <a href="' . _BASE_HREF . '">Click here to login</a>.';
    exit;
}
print_heading('Step #3: Initial system update');
if (isset($_REQUEST['run_upgrade']) || isset($_REQUEST['install_upgrade']) && isset($_REQUEST['save_license_codes']) && isset($_REQUEST['license_codes']) && trim($_REQUEST['license_codes'][0])) {
    $setup_upgrade_hack = true;
    include 'includes/plugin_config/pages/config_upgrade.php';
} else {
    ?>

    <p>
Ejemplo n.º 17
0
<?php

/** 
 * Copyright: dtbaker 2012
 * Licence: Please check CodeCanyon.net for licence details. 
 * More licence clarification available here:  http://codecanyon.net/wiki/support/legal-terms/licensing-terms/ 
 * Deploy: 9809 f200f46c2a19bb98d112f2d32a8de0c4
 * Envato: 4ffca17e-861e-4921-86c3-8931978c40ca, 0a3014a3-2b8f-460b-8850-d6025aa845f8
 * Package Date: 2015-11-25 03:08:08 
 * IP Address: 67.79.165.254
 */
if (isset($_REQUEST['sort_order']) && is_array($_REQUEST['sort_order']) && isset($_REQUEST['auth']) && module_form::get_secure_key() == $_REQUEST['auth'] && module_security::is_logged_in()) {
    module_config::save_config('dash_widgets_sort_' . module_security::get_loggedin_id(), json_encode($_REQUEST['sort_order']));
}
module_config::register_css('theme', 'morris.css', full_link('/includes/plugin_theme_adminlte/css/morris.css'), 12);
module_config::register_css('theme', 'ionicons.min.css', full_link('/includes/plugin_theme_adminlte/css/ionicons.min.css'), 12);
module_config::register_js('theme', 'raphael-min.js', full_link('/includes/plugin_theme_adminlte/js/AdminLTE/raphael-min.js'), 12);
module_config::register_js('theme', 'morris.min.js', full_link('/includes/plugin_theme_adminlte/js/AdminLTE/morris.min.js'), 13);
module_config::register_js('theme', 'dashboard.js', full_link('/includes/plugin_theme_adminlte/js/AdminLTE/dashboard.js'), 14);
$calling_module = 'home';
$home_widgets = handle_hook('dashboard_widgets', $calling_module);
$home_widgets2 = hook_handle_callback('dashboard_widgets');
if (is_array($home_widgets2)) {
    $home_widgets = array_merge($home_widgets, $home_widgets2);
}
// group the widgets into columsn.
// the default columns is 3, but each widget can specify which column group they want to appear in.
// layout the default widget structure in the order we want it to display on the page:
$widget_columns = array();
$widget_columns[4] = array(1 => array(), 2 => array(), 3 => array(), 4 => array());
$widget_columns[1] = array(1 => array());
Ejemplo n.º 18
0
 public static function check_for_upgrades($requested_plugin = '', $get_file_contents = 0)
 {
     // compile a list of current plugins
     // along with the users installation code
     // send it to our server and get a response with a list of available updates for this user.
     $current_plugins = array();
     $current_files = array();
     global $plugins;
     if (_DEBUG_MODE) {
         module_debug::log(array('title' => 'Checking for upgrades:', 'data' => 'start'));
     }
     foreach ($plugins as $plugin_name => $p) {
         if ($requested_plugin && $requested_plugin != $plugin_name) {
             continue;
         }
         if (!$p->is_plugin_enabled()) {
             $p->init();
         }
         $current_plugins[$plugin_name] = $p->get_plugin_version();
         // find all the files related to this plugin.
         if (function_exists('getFilesFromDir') && module_config::c('upgrade_post_file_list', 1)) {
             $directory = 'includes/plugin_' . $plugin_name . '/';
             $files = getFilesFromDir($directory);
             $files = array_flip($files);
             foreach ($files as $file => $tf) {
                 // ignore certain files.
                 if (strpos($file, 'plugin_file/upload') !== false || strpos($file, 'plugin_data/upload') !== false || strpos($file, '/cache/') !== false || strpos($file, '/html2ps/') !== false || strpos($file, 'backup/backups/backup_') !== false || strpos($file, '/attachments/') !== false || strpos($file, '/temp/') !== false || strpos($file, '/tmp/') !== false) {
                     unset($files[$file]);
                 } else {
                     $d = preg_replace('#Envato:[^\\r\\n]*#', '', preg_replace('#Package Date:[^\\r\\n]*#', '', preg_replace('#IP Address:[^\\r\\n]*#', '', preg_replace('#Licence:[^\\r\\n]*#', '', file_get_contents($file)))));
                     $files[$file] = md5(base64_encode($d));
                 }
             }
             $current_files[$plugin_name] = $files;
         }
         if (_DEBUG_MODE) {
             module_debug::log(array('title' => 'Checking for upgrades:', 'data' => $plugin_name . ' done'));
         }
     }
     //print_r($current_files);exit;
     $available_updates = array();
     $post_fields = array('application' => _APPLICATION_ID, 'installation_code' => module_config::c('_installation_code'), 'current_version' => module_config::c('_admin_system_version', 2.1), 'current_plugins' => json_encode($current_plugins), 'current_files' => json_encode($current_files), 'client_ip' => $_SERVER['REMOTE_ADDR'], 'installation_location' => full_link('/'), 'requested_plugin' => $requested_plugin, 'get_file_contents' => $get_file_contents);
     $url = module_config::c('ucm_upgrade_url', 'http://api.ultimateclientmanager.com/upgrade.php');
     if ($url == 'http://ultimateclientmanager.com/api/upgrade.php') {
         $url = 'http://api.ultimateclientmanager.com/upgrade.php';
         // hack to use new update subdomain
     }
     if ($url != 'http://ultimateclientmanager.com/api/upgrade.php' && $url != 'http://api.ultimateclientmanager.com/upgrade.php') {
         set_error('Incorrect API url');
         redirect_browser(_BASE_HREF);
     }
     if (_DEBUG_MODE) {
         module_debug::log(array('title' => 'Checking for upgrades:', 'data' => 'Posting to API'));
     }
     if (!function_exists('curl_init')) {
         $postdata = http_build_query($post_fields);
         $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
         $context = stream_context_create($opts);
         $result = file_get_contents($url, false, $context);
     } else {
         //$url = 'http://localhost/ucm/web/api/upgrade.php';
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_HEADER, false);
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
         curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
         // fixes netregistr, may break others?
         $result = curl_exec($ch);
     }
     $data = json_decode($result, true);
     if (_DEBUG_MODE) {
         module_debug::log(array('title' => 'Checking for upgrades:', 'data' => 'Received response from API'));
     }
     if ($data && isset($data['available_updates']) && is_array($data['available_updates'])) {
         $available_updates = $data['available_updates'];
     }
     if ($data && isset($data['licence_codes']) && is_array($data['licence_codes'])) {
         // find out what the licence codes  are (url / name) so we can dispaly this under each code nicely.
         foreach ($data['licence_codes'] as $code => $foo) {
             if (strlen($code) > 10 && strlen($foo) > 10) {
                 module_config::save_config('_licence_code_' . $code, $foo);
                 // this might not be working
             }
         }
     }
     if (!$data) {
         echo $result;
     }
     //echo '<pre>';print_r($current_plugins);print_r($result);echo '</pre>';
     return $available_updates;
 }
Ejemplo n.º 19
0
                                    $p->init();
                                    // lol typo - oh well.
                                    $p->set_insatlled_plugin_version($set_versions[$plugin_name]);
                                }
                            }
                            //}
                            if ($fail) {
                                print_header_message();
                                echo '<br><br>';
                                _e('Some things failed. Please go back and try again');
                            } else {
                                echo '<br><br><strong>';
                                _e('Success! Everything worked.');
                                echo '</strong>';
                                module_config::set_system_version($new_system_version);
                                module_config::save_config('last_update', time());
                            }
                            if (isset($setup_upgrade_hack)) {
                                ?>
        <input type="button" name="go" value="<?php 
                                _e('Continue');
                                ?>
" class="submit_button" onclick="window.location.href='?m=setup&step=4';">
        <?php 
                            }
                        } else {
                            $license_codes = explode('|', module_config::c('_installation_code', ''));
                            foreach ($license_codes as $license_code_id => $license_code) {
                                if (!trim($license_code)) {
                                    unset($license_codes[$license_code_id]);
                                }
Ejemplo n.º 20
0
 function set_insatlled_plugin_version($version)
 {
     module_config::save_config('_plugin_version_' . $this->module_name, $version);
 }
Ejemplo n.º 21
0
 private static function new_invoice_number($customer_id)
 {
     $invoice_number = '';
     if (function_exists('custom_invoice_number')) {
         $invoice_number = custom_invoice_number();
     }
     $invoice_prefix = '';
     if ($customer_id > 0) {
         $customer_data = module_customer::get_customer($customer_id);
         if ($customer_data && isset($customer_data['default_invoice_prefix'])) {
             $invoice_prefix = $customer_data['default_invoice_prefix'];
         }
     }
     if (!$invoice_number) {
         if (module_config::c('invoice_name_match_job', 0) && isset($_REQUEST['job_id']) && (int) $_REQUEST['job_id'] > 0) {
             $job = module_job::get_job($_REQUEST['job_id']);
             // todo: confirm tis isn't a data leak risk oh well.
             $invoice_number = $invoice_prefix . $job['name'];
         } else {
             if (module_config::c('invoice_incrementing', 0)) {
                 $invoice_number = module_config::c('invoice_incrementing_next', 1);
                 // see if there is an invoice number matching this one.
                 $this_invoice_number = $invoice_number;
                 do {
                     $invoices = get_multiple('invoice', array('name' => $invoice_prefix . $this_invoice_number));
                     //self::get_invoices(array('name'=>$invoice_prefix.$this_invoice_number)); //'customer_id'=>$customer_id,
                     if (!$invoices) {
                         $invoice_number = $this_invoice_number;
                         break;
                     } else {
                         // an invoice exists with this same number.
                         // is it from last year?
                         if (module_config::c('invoice_increment_date_check', 'Y') == 'Y') {
                             $has_year_match = false;
                             foreach ($invoices as $invoice) {
                                 if (date('Y') == date('Y', strtotime($invoice['date_create']))) {
                                     $has_year_match = true;
                                 }
                             }
                             if (!$has_year_match) {
                                 // this invoice number is from last year, we can use it.
                                 $invoice_number = $this_invoice_number;
                                 break;
                             }
                         }
                         $this_invoice_number++;
                     }
                 } while (count($invoices));
                 module_config::save_config('invoice_incrementing_next', $invoice_number);
                 $invoice_number = $invoice_prefix . $invoice_number;
             } else {
                 $invoice_number = $invoice_prefix . date('ymd', self::$new_invoice_number_date ? strtotime(self::$new_invoice_number_date) : time());
                 //$invoice_number = $invoice_prefix . date('ymd');
                 // check if this invoice number exists for this customer
                 // if it does exist we create a suffix a, b, c, d etc..
                 // this isn't atomic - if two invoices are created for the same customer at the same time then
                 // this probably wont work. but for this system it's fine.
                 $this_invoice_number = $invoice_number;
                 $suffix_ascii = 65;
                 // 65 is A
                 $suffix_ascii2 = 0;
                 // 65 is A
                 do {
                     if ($suffix_ascii == 91) {
                         // we've exhausted all invoices for today.
                         $suffix_ascii = 65;
                         // reset to A
                         if (!$suffix_ascii2) {
                             // first loop, start with A
                             $suffix_ascii2 = 65;
                             // set 2nd suffix to A, work with this.
                         } else {
                             $suffix_ascii2++;
                             // move from A to B
                         }
                     }
                     $invoices = self::get_invoices(array('name' => $this_invoice_number));
                     //'customer_id'=>$customer_id,
                     if (!count($invoices)) {
                         $invoice_number = $this_invoice_number;
                     } else {
                         $this_invoice_number = $invoice_number . ($suffix_ascii2 ? chr($suffix_ascii2) : '') . chr($suffix_ascii);
                     }
                     $suffix_ascii++;
                 } while (count($invoices) && $suffix_ascii <= 91 && $suffix_ascii2 <= 90);
                 //90 is Z
             }
         }
     }
     return $invoice_number;
 }
Ejemplo n.º 22
0
 public function external_hook($hook)
 {
     switch ($hook) {
         case 'do_backup':
             $result = array();
             $result['error'] = 'Backup failure';
             header("Content-type: text/javascript");
             $backup_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false;
             $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false;
             $backup_file_check = isset($_POST['backup_file']) ? trim($_POST['backup_file']) : false;
             $backup_type = isset($_POST['backup_type']) ? trim($_POST['backup_type']) : false;
             if ($backup_id > 0 && $hash && $backup_file_check && $backup_type) {
                 $correct_hash = $this->link_external_backup($backup_id, true);
                 if ($correct_hash == $hash) {
                     // all good to print a receipt for this payment.
                     $backup_data = $this->get_backup($backup_id);
                     if ($backup_data && $backup_data['backup_id'] == $backup_id && $backup_data['backup_file'] && $backup_data['backup_file'] == $backup_file_check) {
                         if (_DEMO_MODE) {
                             $result['error'] = 'Sorry, cannot make backups in demo mode.';
                         } else {
                             // is a backup in progress?
                             $backup_in_progress = module_config::c('backup_in_progress', 0);
                             if ($backup_in_progress > time() - 120) {
                                 // another backup process is running, tell the javascript to retry...
                                 $result['retry'] = 1;
                                 unset($result['error']);
                             } else {
                                 module_config::save_config('backup_in_progress', time());
                                 @set_time_limit(0);
                                 // create the backup.
                                 switch ($backup_type) {
                                     case 'file':
                                         $path = isset($_POST['path']) ? $_POST['path'] : false;
                                         if ($path) {
                                             $recurisive = isset($_POST['recurisive']) ? $_POST['recurisive'] : false;
                                             // backup this path and add it to the includes file.
                                             $zip_file_name = _BACKUP_BASE_DIR . basename($backup_data['backup_file']) . '.zip';
                                             $backup_result = $this->backup_system_files(dirname(__FILE__) . '/../../', $path, $recurisive, $zip_file_name);
                                             if (is_array($backup_result) && $backup_result[1]) {
                                                 // we successfully backed up some files.
                                                 $result['count'] = $backup_result[0];
                                                 unset($result['error']);
                                             } else {
                                                 $result['error'] = 'Failed to backup';
                                             }
                                         }
                                         break;
                                     case 'database':
                                         //
                                         $table_name = isset($_POST['name']) ? $_POST['name'] : false;
                                         if ($table_name) {
                                             $sql_file_name = _BACKUP_BASE_DIR . basename($backup_data['backup_file']) . '.sql';
                                             $count = $this->backup_database_tables($table_name, $sql_file_name);
                                             if ($count !== false) {
                                                 $result['count'] = $count;
                                                 unset($result['error']);
                                             }
                                         }
                                         break;
                                 }
                                 module_config::save_config('backup_in_progress', 0);
                             }
                         }
                     }
                 }
             }
             echo json_encode($result);
             exit;
             break;
     }
 }
Ejemplo n.º 23
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;
     }
 }
Ejemplo n.º 24
0
 public static function get_secure_key()
 {
     // generate a secure key for all sensitive form submissions.
     $hash = module_config::c('secure_hash', 0);
     if (!$hash) {
         $hash = md5(microtime() . mt_rand(1, 4000) . __FILE__ . time());
         // not very secure. meh.
         module_config::save_config('secure_hash', $hash);
     }
     $hash = md5($hash . "secure for user " . module_security::get_loggedin_id() . " with name " . module_security::get_loggedin_name() . session_id());
     return $hash;
 }