-
Notifications
You must be signed in to change notification settings - Fork 4
/
solution_proposal.inc
executable file
·393 lines (387 loc) · 14.1 KB
/
solution_proposal.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
<?php
// $Id$
function lab_migration_proposal_open()
{
global $user;
/* get open proposal list */
$proposal_rows = array();
//$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE approval_status = 1 AND solution_provider_uid = 0");
$query = db_select('lab_migration_proposal');
$query->fields('lab_migration_proposal');
$query->condition('approval_status', 1);
$query->condition('solution_provider_uid', 0);
$proposal_q = $query->execute();
$proposal_q_count = $proposal_q->rowCount();
if ($proposal_q_count != 0)
{
while ($proposal_data = $proposal_q->fetchObject())
{
$proposal_rows[] = array(
l($proposal_data->lab_title, 'lab-migration/show-proposal/' . $proposal_data->id),
l('Apply', 'lab-migration/show-proposal/' . $proposal_data->id)
);
}
$proposal_header = array(
'Title of the Lab',
'Actions'
);
$return_html = theme('table', array(
'header' => $proposal_header,
'rows' => $proposal_rows
));
}
else
{
$return_html = 'No proposals are available';
}
return $return_html;
}
function lab_migration_solution_proposal_form($form, $form_state)
{
global $user;
$proposal_id = (int) arg(2);
//$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id);
$query = db_select('lab_migration_proposal');
$query->fields('lab_migration_proposal');
$query->condition('id', $proposal_id);
$proposal_q = $query->execute();
$proposal_data = $proposal_q->fetchObject();
if (!$proposal_data)
{
drupal_set_message("Invalid proposal.", 'error');
drupal_goto('');
}
//var_dump($proposal_data->name); die;
$form['name'] = array(
'#type' => 'item',
'#markup' => l($proposal_data->name_title . ' ' . $proposal_data->name, 'user/' . $proposal_data->uid),
'#title' => t('Proposer Name')
);
$form['lab_title'] = array(
'#type' => 'item',
'#markup' => $proposal_data->lab_title,
'#title' => t('Title of the Lab')
);
$experiment_html = '';
//$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d", $proposal_id);
$query = db_select('lab_migration_experiment');
$query->fields('lab_migration_experiment');
$query->condition('proposal_id', $proposal_id);
$experiment_q = $query->execute();
while ($experiment_data = $experiment_q->fetchObject())
{
$experiment_html .= $experiment_data->title . "<br/>";
}
$form['experiment'] = array(
'#type' => 'item',
'#markup' => $experiment_html,
'#title' => t('Experiment List')
);
$form['solution_provider_name_title'] = array(
'#type' => 'select',
'#title' => t('Title'),
'#options' => array(
'Mr' => 'Mr',
'Ms' => 'Ms',
'Mrs' => 'Mrs',
'Dr' => 'Dr',
'Prof' => 'Prof'
),
'#required' => TRUE
);
$form['solution_provider_name'] = array(
'#type' => 'textfield',
'#title' => t('Name of the Solution Provider'),
'#size' => 30,
'#maxlength' => 50,
'#required' => TRUE
);
$form['solution_provider_email_id'] = array(
'#type' => 'textfield',
'#title' => t('Email'),
'#size' => 30,
'#value' => $user->mail,
'#disabled' => TRUE
);
$form['solution_provider_contact_ph'] = array(
'#type' => 'textfield',
'#title' => t('Contact No.'),
'#size' => 30,
'#maxlength' => 15,
'#required' => TRUE
);
$form['solution_provider_department'] = array(
'#type' => 'select',
'#title' => t('Department/Branch'),
'#options' => _list_of_departments(),
'#required' => TRUE
);
$form['solution_provider_university'] = array(
'#type' => 'textfield',
'#title' => t('University/Institute'),
'#size' => 30,
'#maxlength' => 50,
'#required' => TRUE
);
$form['country'] = array(
'#type' => 'select',
'#title' => t('Country'),
'#options' => array(
'India' => 'India',
'Others' => 'Others'
),
'#required' => TRUE,
'#tree' => TRUE,
'#validated' => TRUE
);
$form['other_country'] = array(
'#type' => 'textfield',
'#title' => t('Other than India'),
'#size' => 100,
'#attributes' => array(
'placeholder' => t('Enter your country name')
),
'#states' => array(
'visible' => array(
':input[name="country"]' => array(
'value' => 'Others'
)
)
)
);
$form['other_state'] = array(
'#type' => 'textfield',
'#title' => t('State other than India'),
'#size' => 100,
'#attributes' => array(
'placeholder' => t('Enter your state/region name')
),
'#states' => array(
'visible' => array(
':input[name="country"]' => array(
'value' => 'Others'
)
)
)
);
$form['other_city'] = array(
'#type' => 'textfield',
'#title' => t('City other than India'),
'#size' => 100,
'#attributes' => array(
'placeholder' => t('Enter your city name')
),
'#states' => array(
'visible' => array(
':input[name="country"]' => array(
'value' => 'Others'
)
)
)
);
$form['all_state'] = array(
'#type' => 'select',
'#title' => t('State'),
'#options' => _lm_list_of_states(),
'#validated' => TRUE,
'#states' => array(
'visible' => array(
':input[name="country"]' => array(
'value' => 'India'
)
)
)
);
$form['city'] = array(
'#type' => 'select',
'#title' => t('City'),
'#options' => _lm_list_of_cities(),
'#states' => array(
'visible' => array(
':input[name="country"]' => array(
'value' => 'India'
)
)
)
);
$form['pincode'] = array(
'#type' => 'textfield',
'#title' => t('Pincode'),
'#size' => 30,
'#maxlength' => 6,
'#required' => False,
'#attributes' => array(
'placeholder' => 'Enter pincode....'
)
);
$form['version'] = array(
'#type' => 'select',
'#title' => t('Version'),
'#options' => _list_of_software_version(),
'#required' => TRUE
);
$form['older'] = array(
'#type' => 'textfield',
'#size' => 30,
'#maxlength' => 50,
//'#required' => TRUE,
'#description' => t('Specify the Older version used'),
'#states' => array(
'visible' => array(
':input[name="version"]' => array(
'value' => 'olderversion'
)
)
)
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Apply for Solution')
);
return $form;
}
function lab_migration_solution_proposal_form_validate($form, &$form_state)
{
global $user;
if ($form_state['values']['country'] == 'Others')
{
if ($form_state['values']['other_country'] == '')
{
form_set_error('other_country', t('Enter country name'));
// $form_state['values']['country'] = $form_state['values']['other_country'];
}
else
{
$form_state['values']['country'] = $form_state['values']['other_country'];
}
if ($form_state['values']['other_state'] == '')
{
form_set_error('other_state', t('Enter state name'));
// $form_state['values']['country'] = $form_state['values']['other_country'];
}
else
{
$form_state['values']['all_state'] = $form_state['values']['other_state'];
}
if ($form_state['values']['other_city'] == '')
{
form_set_error('other_city', t('Enter city name'));
// $form_state['values']['country'] = $form_state['values']['other_country'];
}
else
{
$form_state['values']['city'] = $form_state['values']['other_city'];
}
}
else
{
if ($form_state['values']['country'] == '')
{
form_set_error('country', t('Select country name'));
// $form_state['values']['country'] = $form_state['values']['other_country'];
}
if ($form_state['values']['all_state'] == '')
{
form_set_error('all_state', t('Select state name'));
// $form_state['values']['country'] = $form_state['values']['other_country'];
}
if ($form_state['values']['city'] == '')
{
form_set_error('city', t('Select city name'));
// $form_state['values']['country'] = $form_state['values']['other_country'];
}
}
if ($form_state['values']['version'] == 'olderversion')
{
if ($form_state['values']['older'] == '')
{
form_set_error('older', t('Please provide valid version'));
}
}
return;
//$solution_provider_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE solution_provider_uid = ".$user->uid." AND approval_status IN (0, 1) AND solution_status IN (0, 1, 2)");
$query = db_select('lab_migration_proposal');
$query->fields('lab_migration_proposal');
$query->condition('solution_provider_uid', $user->uid);
$query->condition('approval_status', array(
0,
1
), 'IN');
$query->condition('solution_status', array(
0,
1,
2
), 'IN');
$solution_provider_q = $query->execute();
if ($solution_provider_q->fetchObject())
{
form_set_error('', t("You have already applied for a solution. Please compelete that before applying for another solution."));
drupal_goto('lab-migration/open-proposal');
}
}
function lab_migration_solution_proposal_form_submit($form, &$form_state)
{
global $user;
$proposal_id = (int) arg(2);
if ($form_state['values']['version'] == 'olderversion')
{
$form_state['values']['version'] = $form_state['values']['older'];
}
//$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id);
$query = db_select('lab_migration_proposal');
$query->fields('lab_migration_proposal');
$query->condition('id', $proposal_id);
$proposal_q = $query->execute();
$proposal_data = $proposal_q->fetchObject();
if (!$proposal_data)
{
drupal_set_message("Invalid proposal.", 'error');
drupal_goto('lab-migration/open-proposal');
}
if ($proposal_data->solution_provider_uid != 0)
{
drupal_set_message("Someone has already applied for solving this Lab.", 'error');
drupal_goto('lab-migration/open-proposal');
}
$query = "UPDATE {lab_migration_proposal} set solution_provider_uid = :uid, solution_status = :solution_status, solution_provider_name_title = :solution_provider_name_title, solution_provider_name = :solution_provider_contact_name, solution_provider_contact_ph = :solution_provider_contact_ph, solution_provider_department = :solution_provider_department, solution_provider_university = :solution_provider_university , solution_provider_city = :solution_provider_city, solution_provider_pincode = :solution_provider_pincode, solution_provider_state = :solution_provider_state,solution_provider_country = :solution_provider_country, r_version = :r_version WHERE id = :proposal_id";
$args = array(
":uid" => $user->uid,
":solution_status" => 1,
":solution_provider_name_title" => $form_state['values']['solution_provider_name_title'],
":solution_provider_contact_name" => $form_state['values']['solution_provider_name'],
":solution_provider_contact_ph" => $form_state['values']['solution_provider_contact_ph'],
":solution_provider_department" => $form_state['values']['solution_provider_department'],
":solution_provider_university" => $form_state['values']['solution_provider_university'],
":solution_provider_city" => $form_state['values']['city'],
":solution_provider_pincode" => $form_state['values']['pincode'],
":solution_provider_state" => $form_state['values']['all_state'],
":solution_provider_country" => $form_state['values']['country'],
":r_version" => $form_state['values']['version'],
":proposal_id" => $proposal_id
);
$result = db_query($query, $args);
drupal_set_message("We have received your application. We will get back to you soon.", 'status');
/* sending email */
$email_to = $user->mail;
$from = variable_get('lab_migration_from_email', '');
$bcc = variable_get('lab_migration_emails', '');
$cc = variable_get('lab_migration_cc_emails', '');
$param['solution_proposal_received']['proposal_id'] = $proposal_id;
$param['solution_proposal_received']['user_id'] = $user->uid;
$param['solution_proposal_received']['headers'] = array(
'From' => $from,
'MIME-Version' => '1.0',
'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
'Content-Transfer-Encoding' => '8Bit',
'X-Mailer' => 'Drupal',
'Cc' => $cc,
'Bcc' => $bcc
);
if (!drupal_mail('lab_migration', 'solution_proposal_received', $email_to, language_default(), $param, $from, TRUE))
drupal_set_message('Error sending email message.', 'error');
/* sending email */
/* $email_to = variable_get('lab_migration_emails', '');
if (!drupal_mail('lab_migration', 'solution_proposal_received', $email_to , language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE))
drupal_set_message('Error sending email message.', 'error');*/
drupal_goto('lab-migration/open-proposal');
}