forked from aadl/sopac
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sopac.install
200 lines (177 loc) · 6.53 KB
/
sopac.install
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
<?php
// $Id$
/**
* @file
* Install, update and uninstall functions for the SOPAC module.
*/
/**
* Implementation of hook_install().
*/
function sopac_install() {
// Install the SOPAC tables
drupal_install_schema('sopac');
// Mondify custom attributes
sopac_install_custom_table_mods();
// Initialize the SOPAC profile elements
sopac_profile_setup();
}
/**
* Implementation of hook_install().
*/
function sopac_uninstall() {
// Undo custom table changes.. Just in case.
sopac_install_custom_table_mods(FALSE);
// Remove the SOPAC tables
drupal_uninstall_schema('sopac');
// Delete and remove SOPAC profile values and fields
sopac_profile_destroy();
}
/**
* Implementation of hook_schema().
*/
function sopac_schema() {
$schema['sopac_card_verify'] = array(
'description' => t('Stores profile field information.'),
'fields' => array(
'uid' => array(
'type' => 'int',
'not null' => TRUE,
'size' => 'medium',
'description' => t('Drupal user ID.'),
),
'cardnum' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => 24,
'description' => t('Library card number.'),
),
'verified' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => t('Verified boolean. 0 = NO, 1 = YES'),
),
'vdate' => array(
'type' => 'datetime',
'not null' => TRUE,
),
),
'indexes' => array(
'uid' => array('uid'),
'cardnum' => array('cardnum'),
'verified' => array('verified'),
),
);
$schema['sopac_fines_paid'] = array(
'description' => t('Stores information about fines paid.'),
'fields' => array(
'payment_id' => array(
'type' => 'serial',
'not null' => TRUE,
'size' => 'medium',
'description' => t('Payment ID #'),
),
'uid' => array(
'type' => 'int',
'not null' => TRUE,
'size' => 'medium',
'description' => t('Drupal user ID.'),
),
'trans_date' => array(
'type' => 'datetime',
'not null' => TRUE,
'description' => t('Transaction timestamp.'),
),
'amount' => array(
'type' => 'float',
'not null' => TRUE,
'size' => 'medium',
'description' => t('Transaction amount.'),
),
'fine_desc' => array(
'type' => 'char',
'not null' => TRUE,
'length' => 254,
'description' => t('Description of fine payment.'),
),
),
'primary key' => array('payment_id'),
'indexes' => array(
'uid' => array('uid'),
),
);
$schema['sopac_saved_searches'] = array(
'description' => t('Stores users saved searches.'),
'fields' => array(
'search_id' => array(
'type' => 'serial',
'not null' => TRUE,
'size' => 'medium',
'description' => t('Search ID #'),
),
'uid' => array(
'type' => 'int',
'not null' => TRUE,
'size' => 'medium',
'description' => t('Drupal user ID.'),
),
'savedate' => array(
'type' => 'datetime',
'not null' => TRUE,
'description' => t('Date the search was saved.'),
),
'search_desc' => array(
'type' => 'char',
'not null' => TRUE,
'length' => 128,
'description' => t('Search description.'),
),
'search_url' => array(
'type' => 'char',
'not null' => TRUE,
'length' => 254,
'description' => t('Search URL.'),
),
),
'primary key' => array('search_id'),
'indexes' => array(
'uid' => array('uid'),
'savedate' => array('savedate'),
),
);
return $schema;
}
/**
* Because Drupal's schema API doesn't take in to account every MySQL field type, we're compensating here.
*/
function sopac_install_custom_table_mods($install = TRUE) {
if ($install) {
db_query('ALTER TABLE {sopac_fines_paid} CHANGE trans_date trans_date TIMESTAMP NOT NULL');
db_query('ALTER TABLE {sopac_fines_paid} CHANGE trans_date trans_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP');
}
else {
db_query('ALTER TABLE {sopac_fines_paid} CHANGE trans_date trans_date DATETIME NOT NULL');
}
}
/**
* Initializes the profile fields that SOPAC uses
*/
function sopac_profile_setup() {
// Default message to the user about this profile field. This can be changed from the admin menu.
$profile_desc_cardnum = "This is the 14 digit number that is located on the back of your Darien Library library card.<br /><br />If you put it in here, you will be able to do all kinds of great things like reserve material online, see what you have checked out, renew material, and more.<br /><br />Providing a library card number is <strong>not required!</strong> We invite anyone to come participate in our online community. If you don't have your library card number handy, don't worry, you can always add it later.<br />";
// Insert the profile field configuration into the database.
db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, autocomplete, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', '%s')", 'Library Card Number', 'profile_pref_cardnum', $profile_desc_cardnum, 'Preferences', 'textfield', 0, 0, 1, 1, 0, '', '');
$profile_desc_cohist = "This option allows you to enable checkout history on your account. By enabling checkout history, you are allowing the library to keep track of your checkouts on your behalf. Checkout history allows you to see what you have checked out while it is enabled and is also used to help us reccomend other material that may be of interest to you.<br />";
// Insert the profile field configuration into the database.
db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, autocomplete, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', '%s')", 'Enable Checkout History', 'profile_pref_cohist', $profile_desc_cohist, 'Preferences', 'textfield', 0, 0, 0, 1, 0, '', '');
}
/**
* Destroys the profile fields that SOPAC uses
*/
function sopac_profile_destroy() {
$result = db_query("SELECT fid FROM {profile_fields} WHERE name = 'profile_pref_cardnum' LIMIT 1");
$db_obj = db_fetch_object($result);
db_query('DELETE FROM {profile_fields} WHERE fid = %d', $db_obj->fid);
db_query('DELETE FROM {profile_values} WHERE fid = %d', $db_obj->fid);
}