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
|
<?php
// $Id$
/*
Approval Status :
0 - Pending
1 - Approved
2 - Dis-Approved
3 - Solved
Solution Status :
0 - Pending
1 - Approved
2 - Dis-Approved
Solution Display :
0 - No
1 - Yes
Tables :
lab_migration_solution : approval_status
0 - Pending
1 - Approved
2 - Disapproved (delete it)
*/
function lab_migration_proposal_form($form_state)
{
global $user;
/************************ start approve book details ************************/
$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
$proposal_data = db_fetch_object($proposal_q);
if ($proposal_data)
{
if ($proposal_data->approval_status == 0 || $proposal_data->approval_status == 1) {
drupal_set_message(t('We have already received your proposal.'), 'status');
drupal_goto('');
return;
}
}
$form['#attributes'] = array('enctype' => "multipart/form-data");
$form['name_title'] = array(
'#type' => 'select',
'#title' => t('Title'),
'#options' => array('Mr' => 'Mr', 'Ms' => 'Ms', 'Mrs' => 'Mrs', 'Dr' => 'Dr', 'Prof' => 'Prof'),
'#required' => TRUE,
);
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name of the Proposer'),
'#size' => 30,
'#maxlength' => 50,
'#required' => TRUE,
);
$form['email_id'] = array(
'#type' => 'textfield',
'#title' => t('Email'),
'#size' => 30,
'#value' => $user->mail,
'#disabled' => TRUE,
);
$form['contact_ph'] = array(
'#type' => 'textfield',
'#title' => t('Contact Phone No.'),
'#size' => 30,
'#maxlength' => 15,
'#required' => TRUE,
);
$form['department'] = array(
'#type' => 'select',
'#title' => t('Department/Branch'),
'#options' => array('' => 'Please select...',
'Computer Engineering' => 'Computer Engineering',
'Electrical Engineering' => 'Electrical Engineering',
'Electronics Engineering' => 'Electronics Engineering',
'Chemical Engineering' => 'Chemical Engineering',
'Instrumentation Engineering' => 'Instrumentation Engineering',
'Mechanical Engineering' => 'Mechanical Engineering',
'Civil Engineering' => 'Civil Engineering',
'Physics' => 'Physics',
'Mathematics' => 'Mathematics',
'Others' => 'Others'),
'#required' => TRUE,
);
$form['university'] = array(
'#type' => 'textfield',
'#title' => t('University/Institute'),
'#size' => 30,
'#maxlength' => 50,
'#required' => TRUE,
);
$form['lab_title'] = array(
'#type' => 'textfield',
'#title' => t('Title of the Lab'),
'#size' => 50,
'#required' => TRUE,
);
$first_experiemnt = TRUE;
for ($counter = 1; $counter <= 15; $counter++) {
$form['lab_experiment-' . $counter] = array(
'#type' => 'textfield',
'#title' => t('Title of the Experiment ') . $counter,
'#size' => 50,
'#required' => $first_experiemnt,
);
$first_experiemnt = FALSE;
}
$form['solution_provider_uid'] = array(
'#type' => 'radios',
'#title' => t('Do you want to provide the solution'),
'#options' => array('1' => 'Yes', '2' => 'No'),
'#required' => TRUE,
'#default_value' => '1',
);
$form['solution_display'] = array(
'#type' => 'radios',
'#title' => t('Do you want to display the solution on the www.scilab.in website'),
'#options' => array('1' => 'Yes', '2' => 'No'),
'#required' => TRUE,
'#default_value' => '1',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
);
return $form;
}
function lab_migration_proposal_form_validate($form, &$form_state)
{
if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['contact_ph']))
form_set_error('mobile', t('Invalid contact phone number'));
return;
}
function lab_migration_proposal_form_submit($form, &$form_state)
{
global $user;
if (!$user->uid) {
drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error');
return;
}
$solution_provider_uid = 0;
$solution_status = 0;
$solution_provider_name_title = '';
$solution_provider_name = '';
$solution_provider_contact_ph = '';
$solution_provider_department = '';
$solution_provider_university = '';
if ($form_state['values']['solution_provider_uid'] == "1") {
$solution_provider_uid = $user->uid;
$solution_status = 1;
$solution_provider_name_title = $form_state['values']['name_title'];
$solution_provider_name = $form_state['values']['name'];
$solution_provider_contact_ph = $form_state['values']['contact_ph'];
$solution_provider_department = $form_state['values']['department'];
$solution_provider_university = $form_state['values']['university'];
} else {
$solution_provider_uid = 0;
}
$solution_display = 0;
if ($form_state['values']['solution_display'] == "1")
$solution_display = 1;
else
$solution_display = 0;
/* inserting the user proposal */
$result = db_query("INSERT INTO {lab_migration_proposal}
(uid, approver_uid, name_title, name, contact_ph, department, university, lab_title, approval_status, solution_status, solution_provider_uid, solution_display, creation_date, approval_date, solution_date, solution_provider_name_title, solution_provider_name, solution_provider_contact_ph, solution_provider_department, solution_provider_university) VALUES
(%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, 0, 0, '%s', '%s', '%s', '%s', '%s')",
$user->uid,
0,
$form_state['values']['name_title'],
$form_state['values']['name'],
$form_state['values']['contact_ph'],
$form_state['values']['department'],
$form_state['values']['university'],
$form_state['values']['lab_title'],
0,
$solution_status,
$solution_provider_uid,
$solution_display,
time(),
$solution_provider_name_title,
$solution_provider_name,
$solution_provider_contact_ph,
$solution_provider_department,
$solution_provider_university
);
if (!$result)
{
drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error');
return;
}
/* proposal id */
$proposal_id = db_last_insert_id('lab_migration_proposal', 'id');
/* adding experiments */
$number = 1;
for ($counter = 1; $counter <= 15; $counter++) {
$experiment_field_name = 'lab_experiment-' . $counter;
if (strlen(trim($form_state['values'][$experiment_field_name])) >= 1) {
$result = db_query("INSERT INTO {lab_migration_experiment} (proposal_id, number, title) VALUES (%d, %d, '%s')", $proposal_id, $number, trim($form_state['values'][$experiment_field_name]));
if (!$result)
{
drupal_set_message(t('Could not insert Title of the Experiment : ') . trim($form_state['values'][$experiment_field_name]), 'error');
} else {
$number++;
}
}
}
/* sending email */
$email_to = $user->mail;
$param['proposal_received']['proposal_id'] = $proposal_id;
$param['proposal_received']['user_id'] = $user->uid;
if (!drupal_mail('lab_migration', 'proposal_received', $email_to , language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE))
drupal_set_message('Error sending email message.', 'error');
/* sending email */
$email_to = variable_get('lab_migration_emails', '');
if (!drupal_mail('lab_migration', 'proposal_received', $email_to , language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE))
drupal_set_message('Error sending email message.', 'error');
drupal_set_message(t('We have received you Lab migration proposal. We will get back to you soon.'), 'status');
drupal_goto('');
}
|