summaryrefslogtreecommitdiff
path: root/workshop_registration.inc
blob: 7b6d6fd7ca883e60cebfc6d056adc78e90bc26c2 (plain)
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
<?php
/* workshop booking registration form */
$date_picker_js = "
(function($)  {
        Drupal.behaviors.form_modif = {
  attach: function (context, settings) {
        $('input#edit-workshop-info-checklist-group-suggested-date-start-date-datepicker-popup-0').change(function(){
        var field_date1 = $('input#edit-workshop-info-checklist-group-suggested-date-start-date-datepicker-popup-0').val();
        console.log(field_date1);
        var str_date_array = field_date1.split('-');
        day = +str_date_array[0] + +1;
        month = str_date_array[1];
        year = str_date_array[2];
        field_date1_next = day+'-'+month+'-'+year;
            console.log(field_date1);
        if($('#edit-workshop-info-workshop-type').val() == '2-day training workshop'){
            if(day > 31 ){
                alert('Enter correct To date');
                $('input#edit-workshop-info-checklist-group-suggested-date-end-date-datepicker-popup-0').val('');
            }else{
                alert('Check the To date');
                $('input#edit-workshop-info-checklist-group-suggested-date-end-date-datepicker-popup-0').val(field_date1_next);
            }
        }else{
            $('input#edit-workshop-info-checklist-group-suggested-date-end-date-datepicker-popup-0').val(field_date1);
        }
    });
  }
};
})(jQuery);
";
drupal_add_js($date_picker_js,array(
  'type' => 'inline',
  'scope' => 'footer',
  'weight' => 5,
));

function osdag_workshop_booking_form($form, &$form_state)
{
    global $user;
    /************************ start approve book details **********************/
    $query = db_select('osdag_workshop_booking_proposal');
    $query->fields('osdag_workshop_booking_proposal');
    $query->condition('uid', $user->uid);
    $query->orderBy('id', 'DESC');
    $query->range(0, 1);
    $proposal_q = $query->execute();
    $proposal_data = $proposal_q->fetchObject();
    if ($proposal_data)
    {
        if ($proposal_data->proposal_status == 0)
        {
            drupal_set_message(t('We have already received your proposal.'),
            'status');
            drupal_goto('');
            return;
        } //$proposal_data->approval_status == 0 ||
    } //$proposal_data
    $form['#attributes'] = array(
        'enctype' => "multipart/form-data"
    );
    $form['personal_info'] = array(
        '#type' => 'fieldset',
        '#title' => t('Personal Information'),
        '#tree' => TRUE,
    );
    $form['personal_info']['name_title'] = array(
        '#type' => 'select',
        '#title' => t('Title'),
        '#options' => array(
            'Dr' => 'Dr.',
            'Prof' => 'Prof.',
            'Shri' => 'Shri',
            'Smt' => 'Smt',
            'Ku.' => 'Ku.',
            'Mr.' => 'Mr.',
            'Mrs.' => 'Mrs.',
            'Ms.' => 'Ms.',
        ),
        '#required' => TRUE
    );
    $form['personal_info']['fname'] = array(
        '#type' => 'textfield',
        '#title' => t('First Name'),
        '#size' => 30,
        '#maxlength' => 50,
        '#required' => TRUE
    );
    $form['personal_info']['lname'] = array(
        '#type' => 'textfield',
        '#title' => t('last Name'),
        '#size' => 30,
        '#maxlength' => 50,
        '#required' => TRUE
    );
    $form['personal_info']['designation'] = array(
        '#type' => 'textfield',
        '#title' => t('Designation'),
        '#size' => 30,
        '#maxlength' => 50,
        '#required' => TRUE
    );
    $form['personal_info']['email_id'] = array(
        '#type' => 'textfield',
        '#title' => t('Email'),
        '#size' => 30,
        '#value' => $user->mail,
        '#disabled' => TRUE
    );
    $form['personal_info']['contact_no'] = array(
        '#type' => 'textfield',
        '#title' => t('Contact No.'),
        '#size' => 30,
        '#maxlength' => 15,
        '#required' => TRUE
    );
    $form['organization_info'] = array(
        '#type' => 'fieldset',
        '#title' => t('Organization Information'),
        '#tree' => TRUE,
    );
    $form['organization_info']['institute_company'] = array(
        '#type' => 'textfield',
        '#title' => t('Name of the Institute/Company'),
        '#size' => 30,
        '#maxlength' => 50,
        '#required' => TRUE
    );
    $form['organization_info']['alt_email_id'] = array(
        '#type' => 'textfield',
        '#title' => t('Official (Institute/Company) Email address'),
        '#size' => 50,
        '#required' => TRUE,
        '#disabled' => False
    );
    $form['organization_info']['institute_company_address'] = array(
        '#type' => 'textarea',
        '#title' => t('Address of the Institute/Company'),
        '#size' => 50,
        '#maxlength' => 100,
        '#required' => TRUE
    );
    $form['organization_info']['city_district'] = array(
        '#type' => 'textfield',
        '#title' => t('City/District'),
        '#size' => 30,
        '#maxlength' => 50,
        '#required' => TRUE
    );
    $form['organization_info']['all_state'] = array(
        '#type' => 'select',
        '#title' => t('State'),
        '#options' => osdag_workshop_booking_list_of_states(),
        '#validated' => TRUE,
        '#required' => TRUE,
        '#states' => array(
            'visible' => array(
                ':input[name="country"]' => array(
                    'value' => 'India'
                )
            )
        )
    );
    $form['organization_info']['pincode'] = array(
        '#type' => 'textfield',
        '#title' => t('Pincode'),
        '#size' => 30,
        '#maxlength' => 6,
        '#required' => TRUE,
        '#attributes' => array(
            'placeholder' => 'Insert pincode of your city/ village....'
        ),
        '#description' => 'Please insert pincode of your institute/ university.'
    );
    $form['workshop_info'] = array(
        '#type' => 'fieldset',
        '#title' => t('Workshop Information'),
        '#tree' => TRUE,
    );
    $form['workshop_info']['workshop_type'] = array(
        '#type' => 'select',
        '#title' => t('Workshop type'),
        '#options' => array("1-day training workshop" =>
        "1-day training workshop",
        "2-day training workshop" => "2-day training workshop"),
        '#required' => TRUE
    );
    $form['workshop_info']['expected_number_of_participants'] = array(
        '#type' => 'select',
        '#title' => t('Expected number of participants'),
        '#options' => array("0 to 30" => "0 to 30",
                            "30 to 60" => "30 to 60"),
        '#description' => "[If the number of participants is more than 60 then
        request for a new workshop for the next batch of 60 students]",
        '#required' => TRUE
    );
    $form['workshop_info']['participant_type'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Participant type'),
        '#options' => array(
                        "Undergraduate students" => "Undergraduate students",
                        "Postgraduate students" => "Postgraduate students",
                        "College teachers" => "College teachers",
                        "Design engineers" => "Design engineers",
                        "Site engineers" => "Site engineers",
                        "Others" => "Others"),
        '#description' => "[If others specify]",
        '#required' => TRUE
    );
    $form['workshop_info']['if_others'] = array(
        '#type' => 'textfield',
        '#size' => 30,
        '#maxlength' => 30,
        '#required' => TRUE,
        '#states' => array(
                'visible' => array(
                    ':input[name="workshop_info[participant_type][Others]"]' =>
                    array(
                        array('checked' => True),
                    )
                )
        ),
    );
    $form['workshop_info']['checklist_group'] = array(
        '#type' => 'fieldset',
        '#title' => t('Workshop Checklist'),
        '#tree' => TRUE,
    );
    $form['workshop_info']['checklist_group']['is_computer_lab_available'] =
    array(
        '#type' => 'select',
        '#title' => t('Is a computer lab available at the organizing
        institute/company?'),
        '#options' => array("Yes" => "Yes",
                            "No" => "No"),
        '#required' => TRUE
    );
    $form['workshop_info']['checklist_group']['if_yes_1'] = array(
        '#type' => 'textfield',
        '#title' => t('What is the Operating system (Windows, Linux etc.)
        [mention OS with configuration. Ex. Windows 10 or Ubuntu 18.04 etc]'),
        '#size' => 50,
        '#maxlength' => 50,
        '#states' => array(
            'visible' => array(
                ':input[name=
                "workshop_info[checklist_group][is_computer_lab_available]"]'
                => array("value" => "Yes"),
            )
        ),
        '#default_value' => '',
    );
    $form['workshop_info']['checklist_group']['if_yes_2'] = array(
        '#type' => 'select',
        '#title' => t('Is there a projection facility at the computer lab?'),
        '#options' => array("Yes" => "Yes",
                            "No" => "No"),
        '#states' => array(
            'visible' => array(
                ':input[name=
                "workshop_info[checklist_group][is_computer_lab_available]"]'
                =>array('value' => 'Yes'),
            )
        ),
        '#default_value' => '',
        '#required' => TRUE
    );
    $form['workshop_info']['checklist_group']['if_yes_3'] = array(
        '#type' => 'select',
        '#title' => t('Are all the computers connected to the Internet?'),
        '#options' => array("Yes" => "Yes",
                            "No" => "No"),
        '#states' => array(
            'visible' => array(
                ':input[name=
                "workshop_info[checklist_group][is_computer_lab_available]"]'
                => array('value' => 'Yes'),
            )
        ),
        '#default_value' => '',
        '#required' => TRUE
    );
    $form['workshop_info']['checklist_group']['if_no_1'] = array(
        '#type' => 'select',
        '#title' => t('Every participant has to have an individual computer
        with Osdag pre-installed in it.'),
        '#options' => array("Agree" => "Agree",
                            "Disagree" => "Disagree"),
        '#states' => array(
            'visible' => array(
                ':input[name=
                "workshop_info[checklist_group][is_computer_lab_available]"]'
                => array('value' => 'No'),
            )
        ),
    );
    $form['workshop_info']['checklist_group']['if_no_2'] = array(
        '#type' => 'select',
        '#title' => t('All the participants should be accommodated in a single
        room with audio-visual projection facilities.'),
        '#options' => array("Agree" => "Agree",
                            "Disagree" => "Disagree"),
        '#states' => array(
            'visible' => array(
                ':input[name=
                "workshop_info[checklist_group][is_computer_lab_available]"]'
                => array('value' => 'No'),
            )
        ),
    );
    $form['workshop_info']['volunteers'] = array(
        '#type' => 'textfield',
        '#title' => t('Volunteers'),
        '#size' => 30,
        '#maxlength' => 6,
        '#required' => TRUE,
        '#attributes' => array(
            'placeholder' => 'Enter the number of volunteer....'
        ),
        '#description' => '(1 volunteer per 15 participants with a minimum of
        2)'
    );
    $form['workshop_info']['checklist_group']['suggested_date'] = array(
        '#type' => 'fieldset',
        '#title' => t('Suggested Date(s)'),
        '#tree' => TRUE,
    );
    $cur_year = date("Y");
    $form['workshop_info']['checklist_group']['suggested_date']['start_date'] =
    array(
        '#type' => 'date_popup',
        '#title' => t('From Date:'),
        '#date_label_position' => '',
        '#description' => '',
        '#default_value' => '',
        '#date_format' => 'd-m-Y',
        '#date_increment' => 0,
        '#date_year_range' => $cur_year.':+0',
        '#datepicker_options' => array(
            'minDate' => 10,
            'dateFormat' => date_popup_format_to_popup('d-m-Y'),
        ),
    );
    $form['workshop_info']['checklist_group']['suggested_date']['end_date'] =
    array(
        '#type' => 'date_popup',
        '#title' => t('To Date:'),
        '#date_label_position' => '',
        '#description' => '',
        '#default_value' => '',
        '#date_format' => 'd-m-Y',
        '#date_increment' => 1,
        '#date_year_range' => $cur_year.':+0',
        '#datepicker_options' => array(
            'dateFormat' => date_popup_format_to_popup('d-m-Y'),
        ),
    );
    $form['workshop_info']['proposed_travel_arrangement'] = array(
        '#type' => 'textarea',
        '#title' => t('What is the proposed travel arrangement for the Osdag
        resource people'),
        '#size' => 30,
        '#maxlength' => 100,
        '#required' => TRUE,
        '#attributes' => array(
            'placeholder' => 'Enter the proposed travel arrangement for the '.
            'Osdag resource people....'
        ),
    );
    $form['workshop_info']['how_did_you_here'] = array(
        '#type' => 'select',
        '#title' => t('How did you hear about Osdag training workshop?'),
        '#options' => array("FOSSEE/Osdag Email/website" =>
                            "FOSSEE/Osdag Email/website",
                            "FOSSEE/Osdag banner, brochure etc." =>
                            "FOSSEE/Osdag banner, brochure etc.",
                            "Web search" => "Web search",
                            "From another college" => "From another college",
                            "Word of mouth" => "Word of mouths"),
        '#required' => TRUE
    );
    $form['term_and_conditions'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Terms And Conditions'),
        '#options' => array(
            'status' => t('<a href="term-and-conditions" target="_blank">I
            agree to the Terms and Conditions</a>')
        ),
        '#required' => TRUE
    );
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Submit')
    );
    return $form;
}

function osdag_workshop_booking_form_validate($form, &$form_state)
{
    $v = $form_state['values'];
    if (!preg_match('/^[a-zA-Z \.]*$/', $v['personal_info']['fname']))
        form_set_error('fname', t('Allowed only characters'));
    if (!preg_match('/^[a-zA-Z \.]*$/', $v['personal_info']['lname']))
        form_set_error('lname', t('Allowed only characters'));
    if (!preg_match('/^[0-9\ \+]{0,15}$/', $v['personal_info']['contact_no']))
        form_set_error('contact_no', t('Invalid contact number'));
    if (!preg_match('/^[a-zA-Z \.]*$/', $v['personal_info']['designation']))
        form_set_error('designation', t('Allowed only characters'));
    if(strlen($v['organization_info']['institute_company']) < 0 ||
    $v['organization_info']['institute_company'] > 30)
        form_set_error('institute_company',
        t('Institute/company name length is invalid'));
    if((strlen($v['organization_info']['institute_company_address']) > 10) ||
    (strlen($v['organization_info']['institute_company_address']) < 100)){
        $v['organization_info']['institute_company_address'] =
        trim($v['organization_info']['institute_company_address']);
        }else{
            form_set_error('institute_company_address',
            t('Address length is invalid'));
        }
    if($v['workshop_info']['checklist_group']['is_computer_lab_available'] ==
    "Yes"){
        if(trim($v['workshop_info']['checklist_group']['if_yes_1']) == ""){
            form_set_error('if_yes_1', t('Please enter value'));
        }
        if($v['workshop_info']['checklist_group']['if_yes_2'] == ""){
            form_set_error('if_yes_2', t('Please select'));
        }
        if($v['workshop_info']['checklist_group']['if_yes_3'] == ""){
            form_set_error('if_yes_3', t('Please select'));
        }
    }
    if($v['workshop_info']['checklist_group']['is_computer_lab_available'] ==
    "No"){
        if($v['workshop_info']['checklist_group']['if_no_1'] == ""){
            form_set_error('if_yes_1', t('Please select'));
        }
        if($v['workshop_info']['checklist_group']['if_no_2'] == ""){
            form_set_error('if_yes_2', t('Please select'));
        }
    }
    if (!preg_match('/^[0-9]{0,2}$/',
        $form_state['values']['workshop_info']['volunteers']))
        form_set_error('volunteers', t('Invalid number of volunteer'));
}

function osdag_workshop_booking_form_submit($form, &$form_state)
{
    global $user;
    $v = $form_state['values'];
 /* Other for suggestions */
    if (isset($_POST['workshop_info']['participant_type']))
    {
        if (!($v['workshop_info']['if_others']))
        {
            $participant_type = implode(", ", $_POST['workshop_info']
            ['participant_type']);
            $v['participant_type'] = $participant_type;
        } 
        else
        {
            $participant_type = implode(", ", $_POST['workshop_info']
            ['participant_type']);
           $v['participant_type'] = $participant_type . "-" . " " .
           $v['workshop_info']['if_others'];
        }
    }
    $query = "INSERT INTO osdag_workshop_booking_proposal (uid,creation_date,
                title,fname,lname,designation,email_id,contact_no,
                institute_company,address_of_institute_company,org_email,
                city_district,indian_state,pincode,workshop_type,
                exp_number_of_participent,participant_type,available_computer,
                if_yes_1,if_yes_2,if_yes_3,if_no_1,if_no_2,volunteers,
                from_w_date,end_w_date,travel_arrangement,how_did_you_here,
                proposal_status,approval_date,disapprove_message) VALUES(
                :uid,:creation_date,:title,:fname,:lname,:designation,:email_id,
                :contact_no,:institute_company,:address_of_institute_company,
                :org_email,:city_district,:indian_state,:pincode,:workshop_type,
                :exp_number_of_participent,:participant_type,
                :available_computer,:if_yes_1,:if_yes_2,:if_yes_3,:if_no_1,
                :if_no_2,:volunteers,:from_w_date,:end_w_date,
                :travel_arrangement,:how_did_you_here,:proposal_status,
                :approval_date, :disapprove_message)";

    $args = array(
        ':uid' => $user->uid,
        ':creation_date' => time(),
        ':title' => $v['personal_info']['name_title'],
        ':fname' => ucfirst(strtolower($v['personal_info']['fname'])),
        ':lname' => ucfirst(strtolower($v['personal_info']['lname'])),
        ':designation' => ucwords($v['personal_info']['designation']),
        ':email_id' => $v['personal_info']['email_id'],
        ':contact_no' => $v['personal_info']['contact_no'],
        ':institute_company' => ucwords($v['organization_info']
        ['institute_company']),
        ':address_of_institute_company' => $v['organization_info']
        ['institute_company_address'],
        ':org_email' => $v['organization_info']['alt_email_id'],
        ':city_district' => ucwords($v['organization_info']['city_district']),
        ':indian_state' => ucwords($v['organization_info']['all_state']),
        ':pincode' => $v['organization_info']['pincode'],
        ':workshop_type' => $v['workshop_info']['workshop_type'],
        ':exp_number_of_participent' => $v['workshop_info']
        ['expected_number_of_participants'],
        ':participant_type' => $v['participant_type'],
        ':available_computer' => $v['workshop_info']['checklist_group']
        ['is_computer_lab_available'],
        ':if_yes_1' => ucwords($v['workshop_info']['checklist_group']
        ['if_yes_1']),
        ':if_yes_2' => $v['workshop_info']['checklist_group']['if_yes_2'],
        ':if_yes_3' => $v['workshop_info']['checklist_group']['if_yes_3'],
        ':if_no_1' => $v['workshop_info']['checklist_group']['if_no_1'],
        ':if_no_2' => $v['workshop_info']['checklist_group']['if_no_2'],
        ':volunteers' => $v['workshop_info']['volunteers'],
        ':from_w_date' => $v['workshop_info']['checklist_group']
        ['suggested_date']
        ['start_date'],
        ':end_w_date' => $v['workshop_info']['checklist_group']
        ['suggested_date']
        ['end_date'],
        ':travel_arrangement' => ucwords($v['workshop_info']
        ['proposed_travel_arrangement']),
        ':how_did_you_here' => $v['workshop_info']['how_did_you_here'],
        ':proposal_status' => 0,
        ':approval_date' => time(),
        ':disapprove_message' => 'none',
    );
        $result = db_query($query, $args, array(
            'return' => Database::RETURN_INSERT_ID
        ));
    $proposal_id = $result;
        /* sending email */
    $email_to = $user->mail;
    $from = variable_get('osdag_workshop_booking_from_email', '');
    $bcc = variable_get('osdag_workshop_booking_bcc_emails', '');
    $cc = variable_get('osdag_workshop_booking_cc_emails', '');
    $params['proposal_received']['proposal_id'] = $proposal_id;
    $params['proposal_received']['user_id'] = $user->uid;
    $params['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('osdag_workshop_booking', 'proposal_received', $email_to,
    language_default(), $params, $from, TRUE))
        drupal_set_message('Error sending email message.', 'error');
    drupal_set_message(t('We have received you osdag workshop proposal.
    We will get back to you soon.'), 'status');
    drupal_goto('');
}