diff --git a/application/core/Admin_Controller.php b/application/core/Admin_Controller.php index d86c627..86d1cc3 100644 --- a/application/core/Admin_Controller.php +++ b/application/core/Admin_Controller.php @@ -12,7 +12,9 @@ function __construct() { $this->load->helper('url'); - if (!$this->session->userdata('user_id')) { + $user_id = $this->session->userdata('user_id'); + + if (!$user_id) { redirect('sessions/login'); @@ -28,14 +30,19 @@ function __construct() { $this->load->database(); - $this->load->helper(array('uri', 'mcb_currency', 'mcb_invoice', 'mcb_date', 'mcb_icon', 'mcb_custom', 'mcb_app')); + $this->load->helper(array('uri', 'mcb_currency', 'mcb_invoice', + 'mcb_date', 'mcb_icon', 'mcb_custom', 'mcb_app', + 'mcb_invoice_amount', 'mcb_invoice_item', + 'mcb_invoice_payment', 'mcb_numbers')); - $this->load->model(array('mcb_modules/mdl_mcb_modules','mcb_data/mdl_mcb_data')); + $this->load->model(array('mcb_modules/mdl_mcb_modules','mcb_data/mdl_mcb_data','mcb_data/mdl_mcb_userdata')); $this->mdl_mcb_modules->set_module_data(); $this->mdl_mcb_data->set_session_data(); + $this->mdl_mcb_userdata->set_session_data($user_id); + $this->mdl_mcb_modules->load_custom_languages(); $this->load->language('mcb', $this->mdl_mcb_data->setting('default_language')); diff --git a/application/core/Client_Center_Controller.php b/application/core/Client_Center_Controller.php index 5ae8b23..83fa1c6 100644 --- a/application/core/Client_Center_Controller.php +++ b/application/core/Client_Center_Controller.php @@ -2,45 +2,48 @@ class Client_Center_Controller extends MX_Controller { - function __construct($var_required = NULL) { + function __construct($var_required = NULL) { - parent::__construct(); + parent::__construct(); - $this->load->database(); + $this->load->database(); - $this->load->helper('url'); + $this->load->helper('url'); - $this->load->model('mcb_modules/mdl_mcb_modules'); + $this->load->model('mcb_modules/mdl_mcb_modules'); - $this->load->library('session'); - - if ($this->session->userdata('is_admin')) { + $this->load->library('session'); - redirect('client_center/admin'); + if ($this->session->userdata('is_admin')) { - } + redirect('client_center/admin'); - if ($var_required and (!$this->session->userdata($var_required))) { + } - redirect('client_center/sessions/login'); + if ($var_required and (!$this->session->userdata($var_required))) { - } + redirect('sessions/login'); - $this->load->model('mcb_data/mdl_mcb_data'); + } - $this->mdl_mcb_data->set_session_data(); + $this->load->model('mcb_data/mdl_mcb_data'); - $this->load->helper(array('uri', 'mcb_currency', 'mcb_invoice', 'mcb_date', 'mcb_icon', 'mcb_custom', 'mcb_app')); + $this->mdl_mcb_data->set_session_data(); + + $this->load->helper(array('uri', 'mcb_currency', 'mcb_invoice', + 'mcb_date', 'mcb_icon', 'mcb_custom', 'mcb_app', + 'mcb_invoice_amount', 'mcb_invoice_item', + 'mcb_invoice_payment', 'mcb_numbers')); - $this->load->language('mcb', $this->mdl_mcb_data->setting('default_language')); + $this->load->language('mcb', $this->mdl_mcb_data->setting('default_language')); - $this->load->library('form_validation'); + $this->load->library('form_validation'); - $this->load->model('fields/mdl_fields'); + $this->load->model('fields/mdl_fields'); - $this->form_validation->set_error_delimiters('
', '
'); + $this->form_validation->set_error_delimiters('
', '
'); - } + } } diff --git a/application/core/MY_Model.php b/application/core/MY_Model.php index 007e351..d84bcb3 100644 --- a/application/core/MY_Model.php +++ b/application/core/MY_Model.php @@ -1,11 +1,14 @@ $value) { - $this->db->like($key, $value); + $this->db->where('(' . $key . " LIKE '%" . $value . "%' or " . $key . " LIKE '" . $value . "%')"); } diff --git a/application/helpers/mcb_currency_helper.php b/application/helpers/mcb_currency_helper.php index 7d63e20..176cdf3 100644 --- a/application/helpers/mcb_currency_helper.php +++ b/application/helpers/mcb_currency_helper.php @@ -1,10 +1,10 @@ mdl_mcb_data->setting('currency_symbol_placement') == 'before') { diff --git a/application/helpers/mcb_date_helper.php b/application/helpers/mcb_date_helper.php index 7c233ae..cc6e543 100644 --- a/application/helpers/mcb_date_helper.php +++ b/application/helpers/mcb_date_helper.php @@ -57,4 +57,84 @@ function standardize_date($date) { } +function date_formats($format = NULL, $element = NULL) { + + $date_formats = array( + 'm/d/Y' => array( + 'key' => 'm/d/Y', + 'picker' => 'mm/dd/yy', + 'mask' => '99/99/9999', + 'dropdown' => 'mm/dd/yyyy'), + 'm/d/y' => array( + 'key' => 'm/d/y', + 'picker' => 'mm/dd/y', + 'mask' => '99/99/99', + 'dropdown' => 'mm/dd/yy'), + 'Y/m/d' => array( + 'key' => 'Y/m/d', + 'picker' => 'yy/mm/dd', + 'mask' => '9999/99/99', + 'dropdown' => 'yyyy/mm/dd'), + 'd/m/Y' => array( + 'key' => 'd/m/Y', + 'picker' => 'dd/mm/yy', + 'mask' => '99/99/9999', + 'dropdown' => 'dd/mm/yyyy'), + 'd/m/y' => array( + 'key' => 'd/m/y', + 'picker' => 'dd/mm/y', + 'mask' => '99/99/99', + 'dropdown' => 'dd/mm/yy'), + 'm-d-Y' => array( + 'key' => 'm-d-Y', + 'picker' => 'mm-dd-yy', + 'mask' => '99-99-9999', + 'dropdown' => 'mm-dd-yyyy'), + 'm-d-y' => array( + 'key' => 'm-d-y', + 'picker' => 'mm-dd-y', + 'mask' => '99-99-99', + 'dropdown' => 'mm-dd-yy'), + 'Y-m-d' => array( + 'key' => 'Y-m-d', + 'picker' => 'yy-mm-dd', + 'mask' => '9999-99-99', + 'dropdown' => 'yyyy-mm-dd'), + 'y-m-d' => array( + 'key' => 'y-m-d', + 'picker' => 'y-mm-dd', + 'mask' => '99-99-99', + 'dropdown' => 'yy-mm-dd'), + 'd.m.Y' => array( + 'key' => 'd.m.Y', + 'picker' => 'dd.mm.yy', + 'mask' => '99.99.9999', + 'dropdown' => 'dd.mm.yyyy'), + 'd.m.y' => array( + 'key' => 'd.m.y', + 'picker' => 'dd.mm.y', + 'mask' => '99.99.99', + 'dropdown' => 'dd.mm.yy') + ); + + if ($format and $element) { + + return $date_formats[$format][$element]; + + } + + elseif ($format) { + + return $date_formats[$format]; + + } + + else { + + return $date_formats; + + } + +} + ?> \ No newline at end of file diff --git a/application/helpers/mcb_invoice_amount_helper.php b/application/helpers/mcb_invoice_amount_helper.php index 1fe6269..ad7daaa 100644 --- a/application/helpers/mcb_invoice_amount_helper.php +++ b/application/helpers/mcb_invoice_amount_helper.php @@ -60,8 +60,10 @@ function invoice_tax_rate_amount($invoice_tax_rate) { function invoice_tax_rate_name($invoice_tax_rate) { + $CI =& get_instance(); + /* Invoice tax rate */ - return $invoice_tax_rate->tax_rate_name . ' @ ' . $invoice_tax_rate->tax_rate_percent . '%'; + return $invoice_tax_rate->tax_rate_name . ' @ ' . format_number($invoice_tax_rate->tax_rate_percent, TRUE, $CI->mdl_mcb_data->setting('decimal_taxes_num')) . '%'; } diff --git a/application/helpers/mcb_invoice_helper.php b/application/helpers/mcb_invoice_helper.php index 0bba608..9d7de04 100644 --- a/application/helpers/mcb_invoice_helper.php +++ b/application/helpers/mcb_invoice_helper.php @@ -1,9 +1,5 @@ load->helper(array('mcb_invoice_amount', 'mcb_invoice_item', 'mcb_invoice_payment', 'mcb_numbers')); - /** * BEGIN COMPANY (FROM) SPECIFIC HELPERS */ @@ -57,6 +53,12 @@ function invoice_from_email($invoice) { } +function invoice_from_fax_number($invoice) { + + return $invoice->from_fax_number; + +} + function invoice_from_name($invoice) { /* First + Last name invoice is from */ @@ -99,6 +101,34 @@ function invoice_from_zip_city($invoice) { } +function invoice_payment_link($invoice) { + + global $CI; + + if ($CI->mdl_mcb_data->setting('merchant_enabled')) { + + $link = $CI->lib_output->payment_link($invoice); + + /** Unless I'm just stupid (highly likely), the PDF seems to want the + * entire GET string urlencoded... + */ + if ($CI->uri->segment(2) == 'generate_pdf') { + + $replace = substr($link, strpos($link, '?') + 1); + $replace = substr($replace, 0, strpos($replace, '">') - 2); + + $link = str_replace($replace, urlencode($replace), $link); + + } + + return $link; + + } + + return ''; + +} + function invoice_tax_id($invoice) { global $CI; @@ -165,7 +195,13 @@ function invoice_to_country($invoice) { function invoice_to_email_address($invoice) { - return $invoice->client_email_address; + return $invoice->client_email_address; + +} + +function invoice_to_fax_number($invoice) { + + return $invoice->client_fax_number; } @@ -279,14 +315,14 @@ function invoice_logo($output_type = 'pdf') { if ($output_type == 'pdf') { - /** Use a system path to include the image in the PDF **/ + /** Use a system path to include the image in the PDF **/ return ''; } elseif ($output_type == 'html') { - /** Use a URL to include the image in the HTML **/ + /** Use a URL to include the image in the HTML **/ return ''; } diff --git a/application/helpers/mcb_invoice_item_helper.php b/application/helpers/mcb_invoice_item_helper.php index f006002..843bfe8 100644 --- a/application/helpers/mcb_invoice_item_helper.php +++ b/application/helpers/mcb_invoice_item_helper.php @@ -49,7 +49,9 @@ function invoice_item_tax($item) { function invoice_item_tax_rate($item) { - return $item->tax_rate_percent . '%'; + $CI =& get_instance(); + + return format_number($item->tax_rate_percent, TRUE, $CI->mdl_mcb_data->setting('decimal_taxes_num')) . '%'; } @@ -62,8 +64,10 @@ function invoice_item_tax_sum($sum) { function invoice_item_tax_sum_name($sum) { + $CI =& get_instance(); + /* For display purposes */ - return $sum->tax_rate_name . ' @ ' . $sum->tax_rate_percent . '%'; + return $sum->tax_rate_name . ' @ ' . format_number($sum->tax_rate_percent, TRUE, $CI->mdl_mcb_data->setting('decimal_taxes_num')) . '%'; } function invoice_item_total($item) { diff --git a/application/helpers/mpdf_helper.php b/application/helpers/mpdf_helper.php index 85992a0..871d082 100644 --- a/application/helpers/mpdf_helper.php +++ b/application/helpers/mpdf_helper.php @@ -14,7 +14,7 @@ function pdf_create($html, $filename, $stream=TRUE) { if ($stream) { - $mpdf->Output($filename, 'I'); + $mpdf->Output($filename . '.pdf', 'I'); } diff --git a/application/language/english/mcb_lang.php b/application/language/english/mcb_lang.php index a4e621d..8c357c3 100644 --- a/application/language/english/mcb_lang.php +++ b/application/language/english/mcb_lang.php @@ -392,8 +392,9 @@ /* NEW FOR 0.9.4.1 */ $lang['item_tax_rate'] = 'Item Tax Rate'; $lang['item_tax_option'] = 'Item Tax Option'; -$lang['item_tax_option_0'] = 'Add to Total'; -$lang['item_tax_option_1'] = 'Include in Total'; +// These two items are changed below in 0.9.6 +//$lang['item_tax_option_0'] = 'Add to Total'; +//$lang['item_tax_option_1'] = 'Include in Total'; /* NEW FOR 0.9.4.2 */ $lang['default_quote_group'] = 'Default Quote Group'; @@ -456,4 +457,69 @@ $lang['footer'] = 'Footer'; $lang['inventory_type_in_use'] = 'The Inventory Type specified is already in use.'; +/* NEW FOR 0.9.6 (0.10)*/ +//$lang['item_tax_option_0'] = 'Add to Total'; +//$lang['item_tax_option_1'] = 'Include in Total'; +$lang['account_deposits'] = 'Account Deposits'; +$lang['apply_credit'] = 'Apply Credit'; +$lang['calendar_view'] = 'Calendar View'; +$lang['control_center'] = 'Control Center'; +$lang['copy'] = 'Copy'; +$lang['credit_amount'] = 'Credit Amount'; +$lang['dashboard_show_quotes'] = 'Show Quotes'; +$lang['email_body_template'] = 'Default Body Template'; +$lang['email_footer_template'] = 'Default Footer Template'; +$lang['enter_deposit'] = 'Enter Deposit'; +$lang['initial_stock_quantity'] = 'Initial Stock Quantity'; +$lang['invoice_count'] = 'Invoice Count'; +$lang['item_tax_option_0'] = 'Add to Amount'; +$lang['item_tax_option_1'] = 'Include in Amount'; +$lang['list_view'] = 'List View'; +$lang['my_profile'] = 'My Profile'; +$lang['sales'] = 'Sales'; +$lang['sales_with_tax'] = 'Sales With Tax'; +$lang['sales_by_customer'] = 'Sales by Customer'; + +/* Calendar */ +$lang['calendarToday'] = 'Today'; +$lang['calendarDay'] = 'Day'; +$lang['calendarWeek'] = 'Week'; +$lang['calendarMonth'] = 'Month'; +$lang['months'] = array("January","February","March","April","May","June","July","August","September","October","November","December"); +$lang['monthsShort'] = array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); +$lang['days'] = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); +$lang['daysShort'] = array("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); + +/* NEW FOR 0.11 */ +$lang['active'] = 'Active'; +$lang['amount_greater_than_zero'] = 'The Amount must be greater than zero.'; +$lang['default_invoice_email_template'] = 'Default Invoice Email Template'; +$lang['default_item_tax_option'] = 'Default Item Tax Option'; +$lang['default_overdue_invoice_email_template'] = 'Default Overdue Invoice Email Template'; +$lang['default_payment_method'] = 'Default Payment Method'; +$lang['email_body'] = 'Email Body'; +$lang['email_footer'] = 'Email Footer'; +$lang['email_template_form'] = 'Email Template Form'; +$lang['email_template_title'] = 'Email Template Title'; +$lang['email_templates'] = 'Email Templates'; +$lang['merchant_account_id'] = 'Merchant Account ID'; +$lang['merchant_currency_code'] = 'Merchant Currency Code'; +$lang['merchant_driver'] = 'Merchant Driver'; +$lang['merchant_enabled'] = 'Merchant Enabled'; +$lang['merchant_online_payment'] = 'Online Payment'; +$lang['merchant_pay_online'] = 'Pay Online'; +$lang['merchant_payment_cancelled'] = 'Your payment has been cancelled.'; +$lang['merchant_payment_finished'] = 'Thank you for your payment.'; +$lang['merchant_test_mode'] = 'Merchant Test Mode'; +$lang['no'] = 'No'; +$lang['off'] = 'Off'; +$lang['on'] = 'On'; +$lang['yes'] = 'Yes'; + +/* NEW FOR 0.12 */ +$lang['clear'] = 'Clear'; +$lang['default_apply_invoice_tax'] = 'Default Apply Invoice Tax to Items'; +$lang['group_by'] = 'Group By'; +$lang['payment_entered'] = 'A payment of %s was applied'; + ?> \ No newline at end of file diff --git a/application/libraries/MY_Form_validation.php b/application/libraries/MY_Form_validation.php index d1fa463..046d633 100644 --- a/application/libraries/MY_Form_validation.php +++ b/application/libraries/MY_Form_validation.php @@ -2,6 +2,8 @@ class MY_Form_validation extends CI_Form_validation { + public $_field_data = array(); + function run($module = '', $group = '') { (is_object($module)) AND $this->CI =& $module; return parent::run($group); diff --git a/application/libraries/Merchant/Merchant.php b/application/libraries/Merchant/Merchant.php new file mode 100644 index 0000000..9ddd031 --- /dev/null +++ b/application/libraries/Merchant/Merchant.php @@ -0,0 +1,147 @@ +valid_drivers = array('merchant_paypal'); + + /** Load a copy of the CI object */ + $this->CI =& get_instance(); + + /** Load the language helper */ + $this->CI->load->helper('language'); + + } + + public function curl_get($url, $post_data = NULL) { + + /** Standard cURL function to send & receive responsee */ + + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_HEADER, FALSE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + + if ($post_data) { + + if (is_array($post_data)) { + + $post_data = http_build_query($post_data); + + } + + curl_setopt($ch, CURLOPT_POST, TRUE); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + + } + + $response = curl_exec($ch); + + curl_close($ch); + + return $response; + + } + + /** Generates and returns a form for payment, which posts to Merchant */ + public function payment_form($params, $form_name = 'merchant_form') { + + $post_url = $this->{$this->driver}->post_url(); + + $form_data = $this->{$this->driver}->form_data($params); + + $form = '
'; + + foreach ($form_data as $key => $value) { + + $form .= ''; + + } + + $form .= ''; + + $form .= '
'; + + return $form; + + } + + /** Generates and returns a link for payment, which directs to Merchant */ + public function payment_link($params) { + + $url = $this->{$this->driver}->post_url(); + + $data = $this->{$this->driver}->link_data($params); + + $return = '' . lang('merchant_pay_online') . ''; + + return $return; + + } + + /** The driver handles the merchant response via this method */ + public function notify() { + + return $this->{$this->driver}->driver_notify(); + + } + + /** @TODO This should be moved somewhere outside of the merchant library */ + public function save_response($response) { + + $this->CI->db->insert('mcb_merchant_responses', $response); + + } + +} + +?> \ No newline at end of file diff --git a/application/libraries/Merchant/drivers/Merchant_paypal.php b/application/libraries/Merchant/drivers/Merchant_paypal.php new file mode 100644 index 0000000..2cf3dbf --- /dev/null +++ b/application/libraries/Merchant/drivers/Merchant_paypal.php @@ -0,0 +1,119 @@ +test_mode == TRUE) ? self::PROCESS_URL_TEST : self::PROCESS_URL; + + } + + public function form_data($params) { + + $data = array( + 'rm' => '2', + 'cmd' => '_xclick', + 'business' => $params['merchant_account_id'], + 'return' => $params['return_url'], + 'cancel_return' => $params['cancel_url'], + 'notify_url' => $params['notify_url'], + 'item_name' => $params['reference'], + 'amount' => $params['amount'], + 'currency_code' => $params['currency_code'], + 'no_shipping' => 1, + 'custom' => $params['custom'] + ); + + return $data; + + } + + public function link_data($params) { + + $data = array( + 'rm' => '2', + 'cmd' => '_xclick', + 'business' => urlencode($params['merchant_account_id']), + 'return' => urlencode($params['return_url']), + 'cancel_return' => urlencode($params['cancel_url']), + 'notify_url' => urlencode($params['notify_url']), + 'item_name' => urlencode($params['reference']), + 'amount' => urlencode($params['amount']), + 'currency_code' => urlencode($params['currency_code']), + 'no_shipping' => 1, + 'custom' => urlencode($params['custom']) + ); + + return $data; + + } + + public function driver_notify() { + + $ipn_response = $_POST; + + $post_validation = $ipn_response; + $post_validation['cmd'] = '_notify-validate'; + + $response = $this->curl_get($this->post_url(), $post_validation); + + $db_array = array( + 'merchant_response_payment_id' => 0, + 'merchant_response_client_id' => 0, + 'merchant_response_invoice_id' => $ipn_response['custom'], + 'merchant_response_amount' => $ipn_response['mc_gross'], + 'merchant_response_method' => 'PayPal', + 'merchant_response_status' => $response, + 'merchant_response_payment_status' => $ipn_response['payment_status'], + 'merchant_response_post' => serialize($ipn_response) + ); + + $this->save_response($db_array); + + log_message('DEBUG', $response); + + if ($response == 'VERIFIED' and $ipn_response['payment_status'] == 'Completed') { + + return TRUE; + + } + + return FALSE; + + } + +} + +?> \ No newline at end of file diff --git a/application/modules_core/calendar/controllers/calendar.php b/application/modules_core/calendar/controllers/calendar.php new file mode 100644 index 0000000..3604cdf --- /dev/null +++ b/application/modules_core/calendar/controllers/calendar.php @@ -0,0 +1,54 @@ +input->post('btn_list_view')) { + + redirect('invoices'); + + } + + elseif ($this->input->post('btn_add_invoice')) { + + redirect('invoices/create'); + + } + + $this->load->model('invoices/mdl_invoices'); + + } + + function index() { + + $this->load->view('index'); + + } + + public function jquery_get_invoices($status = 'open') { + + $function = "get_" . $status; + + $invoices = $this->mdl_invoices->$function(); + + $inv_array = array(); + + foreach ($invoices as $invoice) { + + $inv_array[] = array( + 'id' => $invoice->invoice_id, + 'title' => $invoice->client_name . ' (' . display_currency($invoice->invoice_total) . ')', + 'start' => date('Y-m-d', $invoice->invoice_due_date), + 'url' => './invoices/edit/invoice_id/'. $invoice->invoice_id, + ); + + } + + echo json_encode($inv_array); + + } + +} \ No newline at end of file diff --git a/application/modules_core/calendar/controllers/index.html b/application/modules_core/calendar/controllers/index.html new file mode 100644 index 0000000..c942a79 --- /dev/null +++ b/application/modules_core/calendar/controllers/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/application/modules_core/calendar/credit.txt b/application/modules_core/calendar/credit.txt new file mode 100644 index 0000000..e354bbb --- /dev/null +++ b/application/modules_core/calendar/credit.txt @@ -0,0 +1 @@ +Calendar module for MyClientBase provided by Omar Orellana \ No newline at end of file diff --git a/application/modules_core/calendar/models/index.html b/application/modules_core/calendar/models/index.html new file mode 100644 index 0000000..c942a79 --- /dev/null +++ b/application/modules_core/calendar/models/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/application/modules_core/calendar/views/header_insert.php b/application/modules_core/calendar/views/header_insert.php new file mode 100644 index 0000000..0fa9f47 --- /dev/null +++ b/application/modules_core/calendar/views/header_insert.php @@ -0,0 +1,132 @@ + + + + +lang->line('buttonArr')); ?> + + + + \ No newline at end of file diff --git a/application/modules_core/calendar/views/index.html b/application/modules_core/calendar/views/index.html new file mode 100644 index 0000000..c942a79 --- /dev/null +++ b/application/modules_core/calendar/views/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/application/modules_core/calendar/views/index.php b/application/modules_core/calendar/views/index.php new file mode 100644 index 0000000..ac04c4d --- /dev/null +++ b/application/modules_core/calendar/views/index.php @@ -0,0 +1,28 @@ +load->view('dashboard/header', array('header_insert'=>'calendar/header_insert')); ?> + +
+ +
+ +

lang->line('invoices') : $this->lang->line('quotes')); ?> + +
+ + +
+
+

+ +
+ + +
+ +
+ +
+ +
+ + +load->view('dashboard/footer'); ?> \ No newline at end of file diff --git a/application/modules_core/client_center/controllers/admin.php b/application/modules_core/client_center/controllers/admin.php index d8ed0b9..a019d4a 100644 --- a/application/modules_core/client_center/controllers/admin.php +++ b/application/modules_core/client_center/controllers/admin.php @@ -32,8 +32,6 @@ function form() { if (!$this->mdl_client_center->validate()) { - $this->load->helper('form'); - if (!$_POST AND uri_assoc('user_id', 4)) { $this->mdl_client_center->prep_validation(uri_assoc('user_id', 4)); @@ -42,11 +40,7 @@ function form() { $this->load->model('clients/mdl_clients'); - $data = array( - 'clients' => $this->mdl_clients->get() - ); - - $this->load->view('admin_form', $data); + $this->load->view('admin_form'); } @@ -86,4 +80,4 @@ function _post_handler() { } -?> +?> \ No newline at end of file diff --git a/application/modules_core/client_center/controllers/client_center.php b/application/modules_core/client_center/controllers/client_center.php index c6d7ad9..8e54c80 100644 --- a/application/modules_core/client_center/controllers/client_center.php +++ b/application/modules_core/client_center/controllers/client_center.php @@ -2,19 +2,24 @@ class Client_Center extends Client_Center_Controller { - function __construct() { + public function __construct() { parent::__construct('client_id'); - $this->load->model('invoices/mdl_invoices'); + $this->load->model( + array( + 'invoices/mdl_invoices', + 'mdl_client_center' + ) + ); - $this->load->model('mdl_client_center'); + $this->load->library('invoices/lib_output'); $this->load->helper('text'); } - function index() { + public function index() { $params = array( 'open' => array( @@ -57,7 +62,7 @@ function index() { } - function invoices() { + public function invoices() { $params = array( 'limit' => 25, @@ -78,42 +83,63 @@ function invoices() { } - function view_invoice() { + public function quotes() { $params = array( - 'where' => array( - 'mcb_invoices.invoice_id' => uri_assoc('invoice_id'), + 'limit' => 25, + 'paginate' => TRUE, + 'page' => uri_assoc('page', 4), + 'where' => array( 'mcb_invoices.client_id' => $this->session->userdata('client_id'), - 'mcb_invoices.invoice_is_quote' => 0 - ) + 'mcb_invoices.invoice_is_quote' => 1 + ), + 'set_client' => TRUE ); - $invoice = $this->mdl_invoices->get($params); + $data = array( + 'quotes' => $this->mdl_invoices->get($params) + ); - $invoice_items = $this->mdl_invoices->get_invoice_items($invoice->invoice_id); + $this->load->view('quotes', $data); - $invoice_tax_rates = $this->mdl_invoices->get_invoice_tax_rates($invoice->invoice_id); + } - $invoice_payments = $this->mdl_invoices->get_invoice_payments($invoice->invoice_id); + public function view_invoice() { - $data = array( - 'invoice' => $invoice, - 'invoice_items' => $invoice_items, - 'invoice_tax_rates' => $invoice_tax_rates, - 'invoice_payments' => $invoice_payments + $params = array( + 'where' => array( + 'mcb_invoices.invoice_id' => uri_assoc('invoice_id'), + 'mcb_invoices.client_id' => $this->session->userdata('client_id') + ) ); - if (!$data['invoice']) { + $invoice = $this->mdl_invoices->get($params); + + if (!$invoice) { redirect('client_center'); } + $invoice_items = $this->mdl_invoices->get_invoice_items($invoice->invoice_id); + + $invoice_tax_rates = $this->mdl_invoices->get_invoice_tax_rates($invoice->invoice_id); + + $invoice_payments = $this->mdl_invoices->get_invoice_payments($invoice->invoice_id); + + $data = array( + 'invoice' => $invoice, + 'invoice_items' => $invoice_items, + 'invoice_tax_rates' => $invoice_tax_rates, + 'invoice_payments' => $invoice_payments, + 'is_quote' => $invoice->invoice_is_quote + ); + $this->load->view('invoice_view', $data); } - function generate_pdf() { + public function generate_pdf() { $invoice_id = uri_assoc('invoice_id'); @@ -123,15 +149,15 @@ function generate_pdf() { } - $this->load->library('invoices/lib_output'); + $this->load->model('invoices/mdl_invoice_history'); - $this->mdl_invoices->save_invoice_history($invoice_id, $this->session->userdata('user_id'), $this->lang->line('client_generated_invoice_pdf')); + $this->mdl_invoice_history->save($invoice_id, $this->session->userdata('user_id'), $this->lang->line('client_generated_invoice_pdf')); $this->lib_output->pdf($invoice_id, $this->_get_invoice_template()); } - function generate_html() { + public function generate_html() { $invoice_id = uri_assoc('invoice_id'); @@ -141,29 +167,41 @@ function generate_html() { } - $this->load->library('invoices/lib_output'); + $this->load->model('invoices/mdl_invoice_history'); - $this->mdl_invoices->save_invoice_history($invoice_id, $this->session->userdata('user_id'), $this->lang->line('client_generated_invoice_html')); + $this->mdl_invoice_history->save($invoice_id, $this->session->userdata('user_id'), $this->lang->line('client_generated_invoice_html')); $this->lib_output->html($invoice_id, $this->_get_invoice_template()); } - function _get_invoice_template() { + public function _get_invoice_template() { - $this->load->model('mcb_data/mdl_mcb_client_data'); + $this->load->model('mcb_data/mdl_mcb_client_data'); - $invoice_template = $this->mdl_mcb_client_data->get($this->session->userdata('client_id'), 'default_invoice_template'); + $invoice_template = $this->mdl_mcb_client_data->get($this->session->userdata('client_id'), 'default_invoice_template'); - if (!$invoice_template) { + if (!$invoice_template) { - $invoice_template = $this->mdl_mcb_data->setting('default_invoice_template'); + $invoice_template = $this->mdl_mcb_data->setting('default_invoice_template'); - } + } + + return $invoice_template; + + } + + public function merchant_return() { - return $invoice_template; + $this->load->view('merchant_return'); - } + } + + public function merchant_cancel() { + + $this->load->view('merchant_cancel'); + + } } diff --git a/application/modules_core/client_center/models/mdl_client_center.php b/application/modules_core/client_center/models/mdl_client_center.php index 054e6a2..dae4048 100644 --- a/application/modules_core/client_center/models/mdl_client_center.php +++ b/application/modules_core/client_center/models/mdl_client_center.php @@ -2,7 +2,7 @@ class Mdl_Client_Center extends MY_Model { - function __construct() { + public function __construct() { parent::__construct(); @@ -20,20 +20,47 @@ function __construct() { } - function validate() { + public function validate() { + $this->form_validation->set_rules('client_id_autocomplete_label'); $this->form_validation->set_rules('client_id', $this->lang->line('client'), 'required'); - $this->form_validation->set_rules('username', $this->lang->line('username'), 'required'); + $this->form_validation->set_rules('username', $this->lang->line('username'), 'required|callback_username_check'); $this->form_validation->set_rules('password', $this->lang->line('password'), 'required'); $this->form_validation->set_rules('passwordv', $this->lang->line('passwordv'), 'required|matches[password]'); + $this->form_validation->set_rules('email_address', $this->lang->line('email_address'), 'required'); return parent::validate($this); } - function save($db_array, $user_id = NULL) { + public function username_check($username) { + + $this->db->where('username', $username); + + if (uri_assoc('user_id', 4)) { + + $this->db->where('user_id <>', uri_assoc('user_id', 4)); + + } + + $query = $this->db->get('mcb_users'); + + if ($query->num_rows()) { + + $this->form_validation->set_message('username_check', $this->lang->line('username_already_exists')); + + return FALSE; + + } + + return TRUE; + + } + + public function save($db_array, $user_id = NULL) { unset($db_array['passwordv']); + unset($db_array['client_id_autocomplete_label']); $db_array['password'] = md5($db_array['password']); @@ -41,7 +68,15 @@ function save($db_array, $user_id = NULL) { } - function invoice_belongs_to_client($invoice_id, $client_id) { + public function prep_validation($client_id) { + + parent::prep_validation($client_id); + + $this->form_values['client_id_autocomplete_label'] = $this->form_values['client_name']; + + } + + public function invoice_belongs_to_client($invoice_id, $client_id) { $this->db->where('invoice_id', $invoice_id); diff --git a/application/modules_core/client_center/views/account_form.php b/application/modules_core/client_center/views/account_form.php index 007da68..601bfa5 100644 --- a/application/modules_core/client_center/views/account_form.php +++ b/application/modules_core/client_center/views/account_form.php @@ -141,6 +141,6 @@ -load->view('dashboard/sidebar', array('side_block'=>'client_center/sidebar_change_pw')); ?> +load->view('sidebar_change_pw'); ?> load->view('dashboard/footer'); ?> \ No newline at end of file diff --git a/application/modules_core/client_center/views/admin_form.php b/application/modules_core/client_center/views/admin_form.php index 8e0b9f7..5473617 100644 --- a/application/modules_core/client_center/views/admin_form.php +++ b/application/modules_core/client_center/views/admin_form.php @@ -1,4 +1,4 @@ -load->view('dashboard/header'); ?> +load->view('dashboard/header', array('header_insert'=>array('client_center/jquery_client_ac'))); ?>
@@ -17,11 +17,8 @@
- + +
@@ -40,6 +37,11 @@
+
+
+
+
+
 
diff --git a/application/modules_core/client_center/views/admin_index.php b/application/modules_core/client_center/views/admin_index.php index 288e426..2d899aa 100644 --- a/application/modules_core/client_center/views/admin_index.php +++ b/application/modules_core/client_center/views/admin_index.php @@ -4,7 +4,11 @@
-

lang->line('client_center'); ?>load->view('dashboard/btn_add', array('btn_name'=>'btn_add_account', 'btn_value'=>$this->lang->line('create_account'))); ?>

+

lang->line('client_center'); ?> + + load->view('dashboard/btn_add', array('btn_name'=>'btn_add_account', 'btn_value'=>$this->lang->line('create_account'))); ?> + +

load->view('dashboard/system_messages'); ?> diff --git a/application/modules_core/client_center/views/admin_sidebar.php b/application/modules_core/client_center/views/admin_sidebar.php index 7b2397b..486be28 100644 --- a/application/modules_core/client_center/views/admin_sidebar.php +++ b/application/modules_core/client_center/views/admin_sidebar.php @@ -2,7 +2,7 @@
-

lang->line('quicklinks'); ?>

+

lang->line('quicklinks'); ?>