-
Notifications
You must be signed in to change notification settings - Fork 0
/
registrar_api.node.inc
403 lines (381 loc) · 12.1 KB
/
registrar_api.node.inc
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<?php
// $Id$
/**
* @file
* Hooks to implement the custom content types
*/
/**
* Implementation of hook_node_info().
*/
function registrar_api_node_info() {
return array(
'registrar_contact' => array(
'name' => t('Contact Handle'),
'module' => 'registrar_contact',
'description' => 'A contact handle representing a contact',
'has_body' => FALSE,
),
'registrar_api_domain' => array(
'name' => t('Domain'),
'module' => 'registrar_api_domain',
'description' => 'A domain name',
'title_label' => t('Domain'),
'has_body' => FALSE,
),
);
}
/**
* Implementation of hook_form() for the contact content type.
*/
function registrar_contact_form(&$node, $form_state) {
$type = node_get_types('type', $node);
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#size' => 20,
);
/* DB schema fields */
$form['uid'] = array(
'#type' => 'textfield',
'#title' => t('Users table uid'),
'#required' => TRUE,
'#default_value' => $node->uid,
);
$form['company_name'] = array(
'#type' => 'textfield',
'#title' => t('Company Name'),
'#required' => TRUE,
'#size' => 60,
'#maxlength' => 60,
'#autocomplete_path' => 'registrar/company/autocomplete',
'#default_value' => $node->company_name,
);
$form['initials'] = array(
'#type' => 'textfield',
'#title' => t('Initials'),
'#required' => TRUE,
'#size' => 60,
'#maxlength' => 60,
'#default_value' => $node->initials,
);
$form['firstname'] = array(
'#type' => 'textfield',
'#title' => t('Firstname'),
'#required' => TRUE,
'#size' => 60,
'#maxlength' => 60,
'#default_value' => $node->firstname,
);
$form['nameprefix'] = array(
'#type' => 'textfield',
'#title' => t('Name Prefix'),
'#required' => FALSE,
'#size' => 10,
'#maxlength' => 10,
'#default_value' => $node->nameprefix,
);
$form['lastname'] = array(
'#type' => 'textfield',
'#title' => t('Lastname'),
'#required' => TRUE,
'#size' => 60,
'#maxlength' => 60,
'#default_value' => $node->lastname,
);
$form['gender'] = array(
'#type' => 'select',
'#title' => t('Gender'),
'#required' => TRUE,
'#maxlength' => 8,
'#default_value' => $node->gender,
'#options' => array(
'M' => t("Male"),
'F' => t("Female"),
),
);
$form['street'] = array(
'#type' => 'textfield',
'#title' => t('Street'),
'#required' => TRUE,
'#size' => 60,
'#maxlength' => 60,
'#default_value' => $node->street,
);
$form['housenumber'] = array(
'#type' => 'textfield',
'#title' => t('Housenumber'),
'#required' => TRUE,
'#default_value' => $node->housenumber,
);
$form['housesuffix'] = array(
'#type' => 'textfield',
'#title' => t('Housesuffix'),
'#required' => FALSE,
'#size' => 30,
'#maxlength' => 30,
'#default_value' => $node->housesuffix,
);
$form['zipcode'] = array(
'#type' => 'textfield',
'#title' => t('Zipcode'),
'#required' => TRUE,
'#size' => 15,
'#maxlength' => 15,
'#default_value' => $node->zipcode,
);
$form['city'] = array(
'#type' => 'textfield',
'#title' => t('City'),
'#required' => TRUE,
'#size' => 60,
'#maxlength' => 200,
'#default_value' => $node->city,
);
$form['state'] = array(
'#type' => 'textfield',
'#title' => t('State'),
'#required' => TRUE,
'#size' => 60,
'#maxlength' => 200,
'#default_value' => $node->state,
);
$form['country'] = array(
'#type' => 'select',
'#title' => t('Country'),
'#required' => TRUE,
'#maxlength' => 2,
'#default_value' => $node->country,
'#options' => _registrar_api_country_codes(),
);
$form['phone_countrycode'] = array(
'#type' => 'textfield',
'#title' => t('Telephone Country code'),
'#required' => TRUE,
'#default_value' => $node->phone_countrycode,
);
$form['phone_areacode'] = array(
'#type' => 'textfield',
'#title' => t('Telephone Area code'),
'#required' => TRUE,
'#size' => 10,
'#maxlength' => 10,
'#default_value' => $node->phone_areacode,
);
$form['phone_subscribernumber'] = array(
'#type' => 'textfield',
'#title' => t('Telephone Subscriber code'),
'#required' => TRUE,
'#size' => 20,
'#maxlength' => 20,
'#default_value' => $node->phone_subscribernumber,
);
$form['fax_countrycode'] = array(
'#type' => 'textfield',
'#title' => t('Fax Country code'),
'#required' => FALSE,
'#default_value' => $node->fax_countrycode,
);
$form['fax_areacode'] = array(
'#type' => 'textfield',
'#title' => t('Fax Area code'),
'#required' => FALSE,
'#size' => 10,
'#maxlength' => 10,
'#default_value' => $node->fax_areacode,
);
$form['fax_subscribernumber'] = array(
'#type' => 'textfield',
'#title' => t('Fax Subscriber code'),
'#required' => FALSE,
'#size' => 20,
'#maxlength' => 20,
'#default_value' => $node->fax_subscribernumber,
);
$form['email'] = array(
'#type' => 'textfield',
'#title' => t('Email address'),
'#required' => TRUE,
'#size' => 60,
'#maxlength' => 255,
'#default_value' => $node->email,
);
return $form;
}
function registrar_api_domain_form(&$node, $form_state) {
$type = node_get_types('type', $node);
/* DB schema fields */
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#size' => 20,
);
$form['tld'] = array(
'#type' => 'textfield',
'#title' => t('Top level domain'),
'#required' => TRUE,
'#default_value' => $node->tld,
);
$form['registrar_handle'] = array(
'#type' => 'textfield',
'#title' => t('Registrar handle'),
'#required' => TRUE,
'#size' => 60,
'#autocomplete_path' => 'registrar/handle/autocomplete',
'#maxlength' => 60,
'#default_value' => $node->registrar_handle,
);
$form['adm_handle'] = array(
'#type' => 'textfield',
'#title' => t('Administrative handle'),
'#required' => TRUE,
'#size' => 60,
'#autocomplete_path' => 'registrar/handle/autocomplete',
'#maxlength' => 60,
'#default_value' => $node->adm_handle,
);
$form['tech_handle'] = array(
'#type' => 'textfield',
'#title' => t('Technical handle'),
'#required' => TRUE,
'#size' => 60,
'#autocomplete_path' => 'registrar/handle/autocomplete',
'#maxlength' => 60,
'#default_value' => $node->tech_handle,
);
return $form;
}
/**
* Implementation of hook_validate().
*
* If a handle doesn't exist, show an error.
* A domain needs those three handles, otherwise we can't register them
*/
function registrar_api_domain_validate($node, &$form) {
// Check if the registrar handle exists
$result = db_query("SELECT COUNT(contact.cid) FROM {registrar_api_contact} contact LEFT JOIN {node} node on ( node.nid = contact.nid ) WHERE node.title='%s'", $form['registrar_handle']['#value']);
if (db_result($result) != 1) {
form_set_error('registrar_handle', t('Registrar handle does not exist'));
}
// Check if the administrative handle exists
$result = db_query("SELECT COUNT(contact.cid) FROM {registrar_api_contact} contact LEFT JOIN {node} node on ( node.nid = contact.nid ) WHERE node.title='%s'", $form['adm_handle']['#value']);
if (db_result($result) != 1) {
form_set_error('adm_handle', t('Administrative handle does not exist'));
}
// Check if the technical handle exists
$result = db_query("SELECT COUNT(contact.cid) FROM {registrar_api_contact} contact LEFT JOIN {node} node on ( node.nid = contact.nid ) WHERE node.title='%s'", $form['tech_handle']['#value']);
if (db_result($result) != 1) {
form_set_error('tech_handle', t('Technical handle does not exist'));
}
}
/**
* Implementation of hook_insert().
*/
function registrar_contact_insert($node) {
$set_str = _registrar_api_get_set_str($node);
db_query("INSERT INTO {registrar_api_contact} SET $set_str",
$node->nid);
$cid = db_last_insert_id('registrar_api_contact', 'cid');
db_query("INSERT INTO {registrar_api_user_handles} SET cid=%d, uid=%d", $cid, $node->uid);
}
function registrar_api_domain_insert($node) {
db_query("
INSERT INTO {registrar_api_domain}
SET
nid='%d',
tld='%s',
registrar_handle=
(SELECT contact.cid FROM {registrar_api_contact} contact LEFT JOIN {node} node on ( node.nid = contact.nid ) WHERE node.title='%s'),
adm_handle=
(SELECT contact.cid FROM {registrar_api_contact} contact LEFT JOIN {node} node on ( node.nid = contact.nid ) WHERE node.title='%s'),
tech_handle=
(SELECT contact.cid FROM {registrar_api_contact} contact LEFT JOIN {node} node on ( node.nid = contact.nid ) WHERE node.title='%s')
", $node->nid, $node->tld, $node->registrar_handle, $node->adm_handle, $node->tech_handle);
}
/**
* Implementation of hook_update().
*/
function registrar_api_domain_update($node) {
// TODO: module_invoke_all('update_contact', $node);
db_query("
UPDATE {registrar_api_domain} domain
SET
registrar_handle=
(SELECT contact.cid FROM {registrar_api_contact} contact LEFT JOIN {node} node on ( node.nid = contact.nid ) WHERE node.title='%s'),
adm_handle=
(SELECT contact.cid FROM {registrar_api_contact} contact LEFT JOIN {node} node on ( node.nid = contact.nid ) WHERE node.title='%s'),
tech_handle=
(SELECT contact.cid FROM {registrar_api_contact} contact LEFT JOIN {node} node on ( node.nid = contact.nid ) WHERE node.title='%s')
WHERE domain.nid=%d;
", $node->registrar_handle, $node->adm_handle, $node->tech_handle, $node->nid);
}
/**
* Implementation of hook_view().
*/
function registrar_contact_view($node, $teaser = FALSE, $page = FALSE) {
$node->content['Contact'] = array(
'#value' => _registrar_api_format_contact_info($node, TRUE),
'#weight' => 1,
);
return $node;
}
function registrar_api_domain_view($node, $teaser = FALSE, $page = FALSE) {
$node->content['Domain'] = array(
'#value' => $node->title,
'#weight' => 1,
);
return $node;
}
/**
* Implementation of hook_load().
*/
function registrar_contact_load($node) {
$contact_data = db_fetch_object(db_query("SELECT * FROM {registrar_api_contact} WHERE nid=%d", $node->nid));
return $contact_data;
}
function registrar_api_domain_load($node) {
// Fetch the names iso the id's for the handles
// Now we can autocomplete the names iso the id's
// @see registrar_api_domain_update
// @see registrar_api_domain_insert
$domain_data = db_fetch_object(db_query("
select domain.nid, domain.tld,
tech_handle.title as tech_handle,
adm_handle.title as adm_handle,
registrar_handle.title as registrar_handle
from {registrar_api_domain} as domain
LEFT JOIN ( {registrar_api_contact} as domain_contact, {node} AS tech_handle)
on (domain.tech_handle = domain_contact.cid AND domain_contact.nid = tech_handle.nid)
LEFT JOIN ( {registrar_api_contact} as adm_contact, {node} AS adm_handle)
on (domain.adm_handle = adm_contact.cid AND adm_contact.nid = adm_handle.nid)
LEFT JOIN ( {registrar_api_contact} as registrar_contact, {node} AS registrar_handle)
on (domain.registrar_handle = registrar_contact.cid AND registrar_contact.nid = registrar_handle.nid)
WHERE domain.nid=%d", $node->nid));
return $domain_data;
}
/**
* There is no implementation of hook_delete()
* Handles may not be deleted, because the can be used by domains
* If there are domains active, and the handle is deleted, we may have a problem with renewing the domain
*/
/**
* Implementation of hook_form_alter().
*/
function registrar_api_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'registrar_contact_node_form' || $form_id == 'registrar_api_domain_node_form') {
// Move menu to the bottom
$form['menu']['#weight'] = 5;
// We need to do something hacky if CCK is being used.
if (module_exists('content')) {
$extra = variable_get('content_extra_weights_registrar_contact', array());
$extra['menu'] = 5;
variable_set('content_extra_weights_registrar_contact', $extra);
}
// Preview doesn't make sense in this context
unset($form['buttons']['preview']);
unset($form['buttons']['delete']);
}
}