Skip to content

Commit 97e25b9

Browse files
committed
Conflicts: application/language/spanish/config_lang.php application/language/spanish/employees_lang.php application/language/spanish/module_lang.php application/language/spanish/reports_lang.php database/database.sql database/database_10.9-11.0.sql
2 parents 2bbbc87 + 5d8e2c4 commit 97e25b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+5705
-760
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
application/config/database.php
2-
.htaccess
2+
.htaccess
3+
*~
4+
.buildpath
5+
.settings
6+
.project

application/config/autoload.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
| $autoload['libraries'] = array('database', 'session', 'xmlrpc');
4040
*/
4141

42-
$autoload['libraries'] = array('database','form_validation','session','user_agent', 'pagination');
42+
$autoload['libraries'] = array('database','session','form_validation','session','user_agent','pagination','MailChimp');
4343

4444

4545
/*
@@ -52,7 +52,7 @@
5252
*/
5353

5454
//sale
55-
$autoload['helper'] = array('form','url','table','text','currency', 'html', 'download');
55+
$autoload['helper'] = array('form','url','table','mailchimp','text','currency', 'html','download');
5656

5757

5858
/*

application/config/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
$route['reports/(specific_:any)/(:any)/(:any)/(:any)'] = "reports/$1/$2/$3/$4";
5757
$route['reports/specific_customer'] = "reports/specific_customer_input";
5858
$route['reports/specific_employee'] = "reports/specific_employee_input";
59+
$route['reports/specific_item'] = "reports/specific_item_input";
5960

6061
$route['scaffolding_trigger'] = "";
6162

application/controllers/config.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,22 @@ function index()
1111
{
1212
$this->load->view("config");
1313
}
14+
15+
function mailchimpinfo()
16+
{
17+
$this->load->view('mailchimpinfo');
18+
}
1419

1520
function save()
1621
{
22+
if ($key = $this->input->post('mc_api_key')) {
23+
$this->load->library('MailChimp', array('api_key'=>$key), 'MailChimp');
24+
$success = ($this->MailChimp->ping() === "Everything's Chimpy!");
25+
$mc_message = $success ? 'Connected to MailChimp! '
26+
: "Unable to connect to MailChimp. Please check your connection and your API key. ";
27+
$validated_api_key = $success ? $this->input->post('mc_api_key') : '';
28+
}
29+
1730
$batch_save_data=array(
1831
'company'=>$this->input->post('company'),
1932
'address'=>$this->input->post('address'),
@@ -28,17 +41,17 @@ function save()
2841
'return_policy'=>$this->input->post('return_policy'),
2942
'language'=>$this->input->post('language'),
3043
'timezone'=>$this->input->post('timezone'),
44+
'mc_api_key'=>$validated_api_key,
3145
'print_after_sale'=>$this->input->post('print_after_sale')
3246
);
3347

3448
if($_SERVER['HTTP_HOST'] !='demo.phppointofsale.com' && $this->Appconfig->batch_save($batch_save_data))
3549
{
36-
echo json_encode(array('success'=>true,'message'=>$this->lang->line('config_saved_successfully')));
50+
echo json_encode(array('success'=>true,'message'=>$mc_message . $this->lang->line('config_saved_successfully')));
3751
}
3852
else
3953
{
40-
echo json_encode(array('success'=>false,'message'=>$this->lang->line('config_saved_unsuccessfully')));
41-
54+
echo json_encode(array('success'=>false,'message'=>$mc_message . $this->lang->line('config_saved_unsuccessfully')));
4255
}
4356
}
4457
}

application/controllers/customers.php

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ function __construct()
99

1010
function index()
1111
{
12+
$data['mailchimp']=($this->config->item('mc_api_key') != null);
1213
$config['base_url'] = site_url('?c=customers&m=index');
1314
$config['total_rows'] = $this->Customer->count_all();
1415
$config['per_page'] = '20';
1516
$this->pagination->initialize($config);
16-
1717
$data['controller_name']=strtolower(get_class());
18+
1819
$data['form_width']=$this->get_form_width();
1920
$data['manage_table']=get_people_manage_table($this->Customer->get_all($config['per_page'], $this->input->get('per_page')),$this);
2021
$this->load->view('people/manage',$data);
@@ -29,7 +30,7 @@ function search()
2930
$data_rows=get_people_manage_table_data_rows($this->Customer->search($search),$this);
3031
echo $data_rows;
3132
}
32-
33+
3334
/*
3435
Gives search suggestions based on what is being searched for
3536
*/
@@ -44,7 +45,19 @@ function suggest()
4445
*/
4546
function view($customer_id=-1)
4647
{
47-
$data['person_info']=$this->Customer->get_info($customer_id);
48+
$email=preg_replace('/.*email:([^\/]*)\/.*/', '$1', uri_string());
49+
if ($email != uri_string()) {
50+
$data['person_info']=$customer_id == -1 ? $this->Customer->get_by_email($email) : $this->Customer->get_info($customer_id);
51+
if (!$data['person_info'] && $email) {
52+
if ($key = $this->config->item('mc_api_key')) {
53+
$this->load->library('MailChimp', array($key) , 'MailChimp');
54+
$data['person_info'] = $this->MailChimp->getPersonDataByEmail($email);
55+
}
56+
}
57+
} else {
58+
$data['person_info'] = $this->Customer->get_info($customer_id);
59+
}
60+
4861
$this->load->view("customers/form",$data);
4962
}
5063

@@ -75,13 +88,40 @@ function save($customer_id=-1)
7588
//New customer
7689
if($customer_id==-1)
7790
{
78-
echo json_encode(array('success'=>true,'message'=>$this->lang->line('customers_successful_adding').' '.
79-
$person_data['first_name'].' '.$person_data['last_name'],'person_id'=>$customer_data['person_id']));
91+
$subscriptionInfo = '';
92+
if ($key = $this->config->item('mc_api_key')) {
93+
$this->load->library('MailChimp', array($key) , 'MailChimp');
94+
95+
if ($this->MailChimp->handleSubscriptionForPerson($customer_data['person_id'])) {
96+
$subscriptionInfo = $this->lang->line('common_successful_subscription');
97+
} else {
98+
$subscriptionInfo = $this->lang->line('common_unsuccessful_subscription').': '.$this->MailChimp->errorMessage;
99+
}
100+
}
101+
102+
echo json_encode(array('success'=>true,
103+
'message'=>$this->lang->line('customers_successful_adding').' '.
104+
$person_data['first_name'].' '.
105+
$person_data['last_name'].' '.
106+
$subscriptionInfo,
107+
'person_id'=>$customer_data['person_id']));
80108
}
81109
else //previous customer
82110
{
111+
$subscriptionInfo = '';
112+
if ($key = $this->config->item('mc_api_key')) {
113+
$this->load->library('MailChimp', array($key) , 'MailChimp');
114+
115+
if ($this->MailChimp->handleSubscriptionForPerson($customer_id, true)) {
116+
$subscriptionInfo = $this->lang->line('common_successful_subscription');
117+
} else {
118+
$subscriptionInfo = $this->lang->line('common_unsuccessful_subscription').': '.$this->MailChimp->errorMessage;
119+
}
120+
}
121+
83122
echo json_encode(array('success'=>true,'message'=>$this->lang->line('customers_successful_updating').' '.
84-
$person_data['first_name'].' '.$person_data['last_name'],'person_id'=>$customer_id));
123+
$person_data['first_name'].' '.$person_data['last_name'].'. '.
124+
$subscriptionInfo.' ','person_id'=>$customer_id));
85125
}
86126
}
87127
else//failure

application/controllers/employees.php

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ function __construct()
99

1010
function index()
1111
{
12+
$data['mailchimp']=($this->config->item('mc_api_key') != null);
13+
$data['controller_name'] = strtolower(get_class());
1214
$config['base_url'] = site_url('?c=employees&m=index');
1315
$config['total_rows'] = $this->Employee->count_all();
1416
$config['per_page'] = '20';
1517
$this->pagination->initialize($config);
16-
17-
$data['controller_name']=strtolower(get_class());
18+
1819
$data['form_width']=$this->get_form_width();
1920
$data['manage_table']=get_people_manage_table($this->Employee->get_all($config['per_page'], $this->input->get('per_page')),$this);
2021
$this->load->view('people/manage',$data);
@@ -44,7 +45,22 @@ function suggest()
4445
*/
4546
function view($employee_id=-1)
4647
{
47-
$data['person_info']=$this->Employee->get_info($employee_id);
48+
$email=preg_replace('/.*email:([^\/]*)\/.*/', '$1', uri_string());
49+
50+
if ($email != uri_string()) {
51+
$data['person_info']=$employee_id == -1 ? $this->Employee->get_by_email($email) : $this->Employee->get_info($employee_id);
52+
if (!$data['person_info'] && $email) {
53+
if ($key = $this->config->item('mc_api_key')) {
54+
$this->load->library('MailChimp', array($key) , 'MailChimp');
55+
$data['person_info'] = $this->MailChimp->getPersonDataByEmail($email);
56+
}
57+
}
58+
59+
} else {
60+
$data['person_info']= $this->Employee->get_info($employee_id);
61+
}
62+
63+
4864
$data['all_modules']=$this->Module->get_all_modules();
4965
$this->load->view("employees/form",$data);
5066
}
@@ -93,13 +109,35 @@ function save($employee_id=-1)
93109
//New employee
94110
if($employee_id==-1)
95111
{
112+
$subscriptionInfo = '';
113+
if ($key = $this->config->item('mc_api_key')) {
114+
$this->load->library('MailChimp', array($key) , 'MailChimp');
115+
116+
if ($this->MailChimp->handleSubscriptionForPerson($employee_data['person_id'])) {
117+
$subscriptionInfo = $this->lang->line('common_successful_subscription');
118+
} else {
119+
$subscriptionInfo = $this->lang->line('common_unsuccessful_subscription');
120+
}
121+
}
122+
96123
echo json_encode(array('success'=>true,'message'=>$this->lang->line('employees_successful_adding').' '.
97-
$person_data['first_name'].' '.$person_data['last_name'],'person_id'=>$employee_data['person_id']));
124+
$person_data['first_name'].' '.$person_data['last_name'].'. '.$subscriptionInfo,'person_id'=>$employee_data['person_id']));
98125
}
99126
else //previous employee
100127
{
128+
$subscriptionInfo = '';
129+
if ($key = $this->config->item('mc_api_key')) {
130+
$this->load->library('MailChimp', array($key) , 'MailChimp');
131+
132+
if ($this->MailChimp->handleSubscriptionForPerson($employee_id, true)) {
133+
$subscriptionInfo = $this->lang->line('common_successful_subscription');
134+
} else {
135+
$subscriptionInfo = $this->lang->line('common_unsuccessful_subscription');
136+
}
137+
}
138+
101139
echo json_encode(array('success'=>true,'message'=>$this->lang->line('employees_successful_updating').' '.
102-
$person_data['first_name'].' '.$person_data['last_name'],'person_id'=>$employee_id));
140+
$person_data['first_name'].' '.$person_data['last_name'].'. '.$subscriptionInfo,'person_id'=>$employee_id));
103141
}
104142
}
105143
else//failure
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
require_once ("secure_area.php");
3+
class Mailchimpdash extends Secure_area
4+
{
5+
public function __construct()
6+
{
7+
parent::__construct();
8+
9+
if ($key = $this->Appconfig->get('mc_api_key')) {
10+
$this->load->library('MailChimp', array($key), 'MailChimp');
11+
} else {
12+
show_error($this->lang->line('common_mailchimp_dashboard_rejected'));
13+
}
14+
}
15+
16+
public function index()
17+
{
18+
$this->load->view("mailchimpdash/index");
19+
}
20+
21+
public function lists($list_id = null, $filter = null)
22+
{
23+
$data['lists'] = $this->MailChimp->lists();
24+
if ($list_id) {
25+
$data['list_id'] = $list_id;
26+
}
27+
28+
if ($filter) {
29+
$data['filter'] = $filter;
30+
}
31+
32+
$this->load->view("mailchimpdash/lists", $data);
33+
}
34+
35+
public function listsajax()
36+
{
37+
if ($id = $this->input->post('listid')) {
38+
if ($start = $this->input->post('start')) {
39+
$members = $this->MailChimp->listMembers($id, 'subscribed', NULL, $start, 25);
40+
} else {
41+
$members = $this->MailChimp->listMembers($id, 'subscribed', NULL, 0, 25);
42+
}
43+
} else {
44+
$data['message'] = $this->lang->line('common_list_error');
45+
}
46+
47+
if (!$members) {
48+
$data['message'] = $this->lang->line('common_list_nomembers');
49+
}
50+
51+
$data['total'] = $members['total'];
52+
$data['start'] = $start;
53+
54+
if ($members['total'] > $start+25) {
55+
$data['visible'] = ($start+1)." through ".$start+25;
56+
} else {
57+
$data['visible'] = ($start+1)." through ".$members['total'];
58+
}
59+
60+
if ($filters = $this->input->post('filters')) {
61+
$filters = explode(',', $filters);
62+
$data['filters'] = $filters;
63+
}
64+
65+
$data['members'] = array();
66+
67+
foreach ($members['data'] as $member)
68+
{
69+
$person = $this->Person->get_by_email($member['email']);
70+
71+
if (!$person) {
72+
$person = $this->MailChimp->getPersonDataByEmail($member['email'], $id);
73+
}
74+
75+
if (!$filters
76+
|| in_array(strtolower($this->Person->get_person_type($person->person_id)).'s', $filters)) {
77+
$data['members'][] = $person;
78+
}
79+
}
80+
81+
$data['listid'] = $id;
82+
83+
// style for info bar at bottom;
84+
if ($start == 0 && $members['total'] <= 25) {
85+
$style = 'width: 860px; float; none;';
86+
} else if ($members['total'] <= 25) {
87+
$style = 'margin-right: 127px;';
88+
} else if ($start == 0) {
89+
$style = 'margin-left: 127px;';
90+
}
91+
92+
$data['style'] = $style;
93+
94+
$this->load->view("mailchimpdash/listsajax",$data);
95+
}
96+
97+
public function listremoveajax()
98+
{
99+
$listID = $this->input->post('listid');
100+
$email = $this->input->post('email');
101+
102+
if ($result = $this->MailChimp->listUnsubscribe($listID, $email, false, false, false)) {
103+
echo json_encode(array('success'=>true,'message'=>"Unsubscribed {$email} from list"));
104+
} else {
105+
echo json_encode(array('success'=>false,'message'=>"Could not unsubscribe {$email} from list: ".$this->MailChimp->errorMessage));
106+
}
107+
}
108+
109+
public function update_email_row($person_id, $list)
110+
{
111+
$person = $this->Person->get_info($person_id);
112+
echo display_email_data($person, $list, false);
113+
}
114+
115+
}
116+
?>

0 commit comments

Comments
 (0)