-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrupaltonetsuite.module
More file actions
224 lines (207 loc) · 6.54 KB
/
Copy pathdrupaltonetsuite.module
File metadata and controls
224 lines (207 loc) · 6.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
function drupaltonetsuite_help() {
}
/*
* Implementing hook_menu()
*/
function drupaltonetsuite_menu() {
$items = array();
$items['drupaltonetsuite'] = array(
'title' => t('DrupalToNetsuite'),
'position' => 'left',
'page callback' => 'drupaltonetsuite_all',
'access arguments' => array('access netsuitetodrupal'),
'description' => t('Main D2N Page'),
'type' => MENU_NORMAL_ITEM,
);
$items['drupaltonetsuite/form'] = array(
'title' => t('Create new Lead'),
'position' => 'left',
'page callback' => 'drupaltonetsuite_form',
'access arguments' => array('access netsuitetodrupal'),
'description' => t('Create a new Lead'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/settings/drupaltonetsuite'] = array(
'title' => 'DrupalToNetsuite',
'page callback' => 'drupal_get_form',
'page arguments' => array('drupaltonetsuite_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
'file' => 'drupaltonetsuite.admin.inc',
);
return $items;
}
/*
*Implementing hook_perm()
*/
function drupaltonetsuite_perm() {
return array( 'access netsuitetodrupal' , 'administer netsuitetodrupal');
}
/*
* Implementing hook_path()
*/
function drupaltonetsuite_path() {
if (function_exists('drupal_get_path')) {
// Let drupal set the path
$path = drupal_get_path('module', 'drupaltonetsuite');
}
else {
// Fallback to trying to find the path based on PHP's knowledge of our
// current path.
$path = dirname(__FILE__);
}
return $path;
}
/*
*Implementing hook_form()
*/
function drupaltonetsuite_form() {
return drupal_get_form('drupaltonetsuite_my_form');
}
/*
* Creating the Leads Form, TODO: Let the admin create this form using formbuilder
*/
function drupaltonetsuite_my_form($form_state) {
$form['name'] = array(
'#type' => 'fieldset',
'#title' => t('Personal Details'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['name']['first'] = array(
'#type' => 'textfield',
'#title' => t('First Name'),
'#required' => TRUE,
'#description' => t('Please your First Name'),
'#size' => 20,
'#maxlength' => 20,
);
$form['name']['last'] = array(
'#type' => 'textfield',
'#title' => t('LastName'),
'#required' => TRUE,
'#description' => t('Please Enter yout Last Name'),
'#size' => 20,
'#maxlength' => 20,
);
$form['name']['email'] = array (
'#type' => 'textfield',
'#title' => t('Email ID'),
'#required' => TRUE,
'#description' => t('Please Enter your email address'),
'#size' => 20,
);
$form['name']['phone'] = array (
'#type' => 'textfield',
'#title' => t('Phone No'),
'#required' => TRUE,
'#description' => t('Please enter your PhoneNO'),
'#size' => 20,
'#maxlength' => 10,
);
$form['company'] = array(
'#type' => 'fieldset',
'#title' => t('Company Details'),
'#collapsible' => TRUE,
'#collasped' => FALSE,
);
$form['company']['company_name'] = array(
'#type' => 'textfield',
'#title' => t('Company Name'),
'#required' => TRUE,
'#description' => t('Please enter your Company Name'),
'#size' => 20,
'#maxlength' => 20,
);
$form['company']['address'] = array(
'#type' => 'textarea',
'#title' => t('Company Address'),
'#description' => t('Please enter your Company Address'),
'#size' => 5,
);
$form['company']['country'] = array (
'#type' => 'textfield',
'#title' => t('Country'),
'#description' => t('Please enter you Country Name'),
'#size' => 20,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
$form['reset'] = array(
'#type' => 'submit',
'#value' => 'Reset Form',
'#validate' => array('drupaltonetsuite_my_form_validate'),
);
return $form;
}
/*
* Reseting the Leads Form
*/
function drupaltonetsuite_my_form_clear($form, &$form_state) {
$form_state['rebuild'] = TRUE;
}
//Form Validation
function drupaltonetsuite_my_form_validate($form, &$form_state) {
$first_name = $form_state['values']['first'];
$last_name = $form_state['values']['last'];
$year_of_birth = $form_state['values']['dob'];
if (!$first_name)
form_set_error('first' , 'Please enter First Name');
if (!$last_name)
form_set_error('last', 'Please Enter Last Name');
if ($year_of_birth && ($year_of_birth < 1900 || $year_of_birth > 2010)) {
form_set_error('dob', 'Enter a year between 1900 and 2010.');
}
}
/*
* TODO: Post data to Netsuite from the Form
*/
function drupaltonetsuite_my_form_submit($form, &$form_state) {
//$first_name = $form_state['values']['first'];
//$last_name = $form_state['values']['last'];
//$dob = $form_state['values']['dob'];
//drupal_set_message(t('The form has been submitted.<br>FirstName is:').$first_name.t('<br>LastName is: ').$last_name);
include_once (drupaltonetsuite_path().'/PHPtoolkit.inc');
$myNSclient = new nsClient( nsHost::live );
$email = "spuvala@argusoft.com";
$password = "argusadmin!";
$account = "TSTDRV658597";
$role = "3";
// set request level credentials. (email, password, account#, internal id of role)
$myNSclient->setPassport($email, $password, $account, $role);
//include_once (drupaltonetsuite_path().'/login_info.inc');
$customerFields = array (
'isPerson' => false,
'firstName' => $form_state['values']['first'],
'lastName' => $form_state['values']['last'],
'companyName' => $form_state['values']['company_name'],
'phone' => $form_state['values']['phone'],
'email' => $form_state['values']['email'],
//'country' => $form_state['values']['country'],
'giveAccess' => false,
'entityStatus' => array('internalId' => '6'),
);
// create Customer record
$customer = new nsComplexObject('Customer');
// set fields
$customer->setFields($customerFields);
// perform add operation and store nsWriteResponse object in $addResponse variable
$addResponse = $myNSclient->add($customer);
// handle add response
if (!$addResponse->isSuccess) {
echo "Lead couldnot be added in netsuite. Error: " .$addResponse->statusDetail[0]->message;
} else {
echo "Lead has been successfully added";
}
}
/*
* Creating a netsuite page with all the features available to the admin
*/
function drupaltonetsuite_all() {
global $base_url;
$message = "This module lets the you integrate netsuite with drupal<br>It provides basic functionality such a creating leads,assigning territories,adding sales representatives<br><a href=".$base_url."/drupaltonetsuite/form>Create a New Lead</a>";
return $message;
}