-
Notifications
You must be signed in to change notification settings - Fork 4
/
manage_proposal.inc
executable file
·1076 lines (1072 loc) · 35.3 KB
/
manage_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
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
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// $Id$
function circuit_simulation_proposal_pending()
{
/* get pending proposals to be approved */
$pending_rows = array();
//$pending_q = db_query("SELECT * FROM {esim_circuit_simulation_proposal} WHERE approval_status = 0 ORDER BY id DESC");
$query = db_select('esim_circuit_simulation_proposal');
$query->fields('esim_circuit_simulation_proposal');
$query->condition('approval_status', 0);
$query->orderBy('id', 'DESC');
$pending_q = $query->execute();
while ($pending_data = $pending_q->fetchObject())
{
$pending_rows[$pending_data->id] = array(
date('d-m-Y', $pending_data->creation_date),
l($pending_data->name_title . ' ' . $pending_data->contributor_name, 'user/' . $pending_data->uid),
$pending_data->project_title,
l('Approve', 'circuit-simulation-project/manage-proposal/approve/' . $pending_data->id) . ' | ' . l('Edit', 'circuit-simulation-project/manage-proposal/edit/' . $pending_data->id)
);
} //$pending_data = $pending_q->fetchObject()
/* check if there are any pending proposals */
if (!$pending_rows)
{
drupal_set_message(t('There are no pending proposals.'), 'status');
return '';
} //!$pending_rows
$pending_header = array(
'Date of Submission',
'Student Name',
'Title of the Circuit Simulation Project',
'Action'
);
//$output = theme_table($pending_header, $pending_rows);
$output = theme('table', array(
'header' => $pending_header,
'rows' => $pending_rows
));
return $output;
}
function circuit_simulation_proposal_all()
{
/* get pending proposals to be approved */
$proposal_rows = array();
//$proposal_q = db_query("SELECT * FROM {esim_circuit_simulation_proposal} ORDER BY id DESC");
$query = db_select('esim_circuit_simulation_proposal');
$query->fields('esim_circuit_simulation_proposal');
$query->orderBy('id', 'DESC');
$proposal_q = $query->execute();
while ($proposal_data = $proposal_q->fetchObject())
{
$approval_status = '';
switch ($proposal_data->approval_status)
{
case 0:
$approval_status = 'Pending';
break;
case 1:
$approval_status = 'Approved';
break;
case 2:
$approval_status = 'Dis-approved';
break;
case 3:
$approval_status = 'Completed';
break;
default:
$approval_status = 'Unknown';
break;
} //$proposal_data->approval_status
if ($proposal_data->actual_completion_date == 0)
{
$actual_completion_date = "Not Completed";
} //$proposal_data->actual_completion_date == 0
else
{
$actual_completion_date = date('d-m-Y', $proposal_data->actual_completion_date);
}
$proposal_rows[] = array(
date('d-m-Y', $proposal_data->creation_date),
l($proposal_data->contributor_name, 'user/' . $proposal_data->uid),
$proposal_data->project_title,
$actual_completion_date,
$approval_status,
l('Status', 'circuit-simulation-project/manage-proposal/status/' . $proposal_data->id) . ' | ' . l('Edit', 'circuit-simulation-project/manage-proposal/edit/' . $proposal_data->id)
);
} //$proposal_data = $proposal_q->fetchObject()
/* check if there are any pending proposals */
if (!$proposal_rows)
{
drupal_set_message(t('There are no proposals.'), 'status');
return '';
} //!$proposal_rows
$proposal_header = array(
'Date of Submission',
'Student Name',
'Title of the circuit-simulation project',
'Date of Completion',
'Status',
'Action'
);
$output = theme('table', array(
'header' => $proposal_header,
'rows' => $proposal_rows
));
return $output;
}
/******************************************************************************/
/************************** PROPOSAL APPROVAL FORM ****************************/
/******************************************************************************/
function circuit_simulation_proposal_approval_form($form, &$form_state)
{
global $user;
/* get current proposal */
$proposal_id = (int) arg(3);
//$proposal_q = db_query("SELECT * FROM {esim_circuit_simulation_proposal} WHERE id = %d", $proposal_id);
$query = db_select('esim_circuit_simulation_proposal');
$query->fields('esim_circuit_simulation_proposal');
$query->condition('id', $proposal_id);
$proposal_q = $query->execute();
if ($proposal_q)
{
if ($proposal_data = $proposal_q->fetchObject())
{
/* everything ok */
} //$proposal_data = $proposal_q->fetchObject()
else
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('circuit-simulation-project/manage-proposal');
return;
}
} //$proposal_q
else
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('circuit-simulation-project/manage-proposal');
return;
}
if ($proposal_data->project_guide_name == "NULL" || $proposal_data->project_guide_name == "")
{
$project_guide_name = "Not Entered";
} //$proposal_data->project_guide_name == NULL
else
{
$project_guide_name = $proposal_data->project_guide_name;
}
if ($proposal_data->project_guide_email_id == "NULL" || $proposal_data->project_guide_email_id == "")
{
$project_guide_email_id = "Not Entered";
} //$proposal_data->project_guide_email_id == NULL
else
{
$project_guide_email_id = $proposal_data->project_guide_email_id;
}
$form['contributor_name'] = array(
'#type' => 'item',
'#markup' => l($proposal_data->name_title . ' ' . $proposal_data->contributor_name, 'user/' . $proposal_data->uid),
'#title' => t('Student name')
);
$form['student_email_id'] = array(
'#title' => t('Student Email'),
'#type' => 'item',
'#markup' => user_load($proposal_data->uid)->mail,
'#title' => t('Email')
);
$form['contributor_contact_no'] = array(
'#title' => t('Contact No.'),
'#type' => 'item',
'#markup' => $proposal_data->contact_no,
);
$form['month_year_of_degree'] = array(
'#type' => 'date_popup',
'#title' => t('Month and year of award of degree'),
'#date_label_position' => '',
'#description' => '',
'#default_value' => $proposal_data->month_year_of_degree,
'#date_format' => 'M-Y',
'#date_increment' => 0,
'#date_year_range' => '1960:+0',
'#datepicker_options' => array(
'maxDate' => 0
),
'#disabled' => TRUE
);
$form['university'] = array(
'#type' => 'item',
'#markup' => $proposal_data->university,
'#title' => t('University/Institute')
);
$form['country'] = array(
'#type' => 'item',
'#markup' => $proposal_data->country,
'#title' => t('Country')
);
$form['all_state'] = array(
'#type' => 'item',
'#markup' => $proposal_data->state,
'#title' => t('State')
);
$form['city'] = array(
'#type' => 'item',
'#markup' => $proposal_data->city,
'#title' => t('City')
);
$form['pincode'] = array(
'#type' => 'item',
'#markup' => $proposal_data->pincode,
'#title' => t('Pincode/Postal code')
);
/*$form['version'] = array(
'#type' => 'item',
'#title' => t('eSim version'),
'#markup' => $proposal_data->version
);*/
$form['project_guide_name'] = array(
'#type' => 'item',
'#title' => t('Project guide'),
'#markup' => $project_guide_name
);
$form['project_guide_email_id'] = array(
'#type' => 'item',
'#title' => t('Project guide email'),
'#markup' => $project_guide_email_id
);
$form['project_title'] = array(
'#type' => 'item',
'#markup' => $proposal_data->project_title,
'#title' => t('Title of the Circuit Simulation Project')
);
$form['description'] = array(
'#type' => 'item',
'#markup' => $proposal_data->description,
'#title' => t('Description of the Circuit Simulation Project')
);
if (($proposal_data->samplefilepath != "") && ($proposal_data->samplefilepath != 'NULL'))
{
$str = substr($proposal_data->samplefilepath,strrpos($proposal_data->samplefilepath, '/'));
$resource_file =ltrim($str, '/');
$form['samplefilepath'] = array(
'#type' => 'item',
'#title' => t('Resource file '),
'#markup' => l($resource_file, 'circuit-simulation-project/download/resource-file/' . $proposal_id) . ""
);
} //$proposal_data->user_defined_compound_filepath != ""
else
{
$form['samplefilepath'] = array(
'#type' => 'item',
'#title' => t('Resource file '),
'#markup' => "Not uploaded<br><br>"
);
}
/*$headers = array(
"User defined compound",
"CAS No."
);
$rows = array();
$item = array(
"{$proposal_data->process_development_compound_name}",
"{$proposal_data->process_development_compound_cas_number}"
);
array_push($rows, $item);
$prodata = theme('table', array(
'header' => $headers,
'rows' => $rows
));
$form['process_development_compound_name'] = array(
'#type' => 'item',
'#title' => t('Name of compound for which process development is carried out'),
'#markup' => $prodata
);
/*
$form['process_development_compound_cas_number'] = array(
'#type' => 'item',
'#title' => t('CAS Number of compound for which process development is carried out'),
'#markup' => $proposal_data->process_development_compound_cas_number
);*/
/*$form['esim_database_compound_name'] = array(
'#type' => 'item',
'#title' => t('List of compounds from eSim Database used in process circuit simulation'),
'#markup' => $proposal_data->esim_database_compound_name
);
$form['user_defined_compounds_used_in_process_circuit_simulationcompound_name'] = array(
'#type' => 'item',
'#title' => t('List of user defined compounds used in process circuit simulation'),
'#markup' => _circuit_simulation_list_of_user_defined_compound($proposal_id)
);
if (($proposal_data->user_defined_compound_filepath != "") && ($proposal_data->user_defined_compound_filepath != 'NULL'))
{
$form['user_defined_compound_filepath'] = array(
'#type' => 'item',
'#title' => t('Uploaded the user defined compound '),
'#markup' => l('Download user defined compound list', 'circuit-simulation-project/download/user-defined-compound-file/' . $proposal_id) . "<br><br>"
);
} //$proposal_data->user_defined_compound_filepath != ""
else
{
$form['user_defined_compound_filepath'] = array(
'#type' => 'item',
'#title' => t('Uploaded the user defined compound '),
'#markup' => "Not uploaded<br><br>"
);
}*/
$form['approval'] = array(
'#type' => 'radios',
'#title' => t('eSim circuit-simulation proposal'),
'#options' => array(
'1' => 'Approve',
'2' => 'Disapprove'
),
'#required' => TRUE
);
$form['message'] = array(
'#type' => 'textarea',
'#title' => t('Reason for disapproval'),
'#attributes' => array(
'placeholder' => t('Enter reason for disapproval in minimum 30 characters '),
'cols' => 50,
'rows' => 4
),
'#states' => array(
'visible' => array(
':input[name="approval"]' => array(
'value' => '2'
)
)
)
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
);
$form['cancel'] = array(
'#type' => 'item',
'#markup' => l(t('Cancel'), 'circuit-simulation-project/manage-proposal')
);
return $form;
}
function circuit_simulation_proposal_approval_form_validate($form, &$form_state)
{
if ($form_state['values']['approval'] == 2)
{
if ($form_state['values']['message'] == '')
{
form_set_error('message', t('Reason for disapproval could not be empty'));
} //$form_state['values']['message'] == ''
} //$form_state['values']['approval'] == 2
}
function circuit_simulation_proposal_approval_form_submit($form, &$form_state)
{
global $user;
/* get current proposal */
$proposal_id = (int) arg(3);
// $proposal_q = db_query("SELECT * FROM {esim_circuit_simulation_proposal} WHERE id = %d", $proposal_id);
$query = db_select('esim_circuit_simulation_proposal');
$query->fields('esim_circuit_simulation_proposal');
$query->condition('id', $proposal_id);
$proposal_q = $query->execute();
if ($proposal_q)
{
if ($proposal_data = $proposal_q->fetchObject())
{
/* everything ok */
} //$proposal_data = $proposal_q->fetchObject()
else
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('circuit-simulation-project/manage-proposal');
return;
}
} //$proposal_q
else
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('circuit-simulation-project/manage-proposal');
return;
}
if ($form_state['values']['approval'] == 1)
{
$query = "UPDATE {esim_circuit_simulation_proposal} SET approver_uid = :uid, approval_date = :date, approval_status = 1 WHERE id = :proposal_id";
$args = array(
":uid" => $user->uid,
":date" => time(),
":proposal_id" => $proposal_id
);
db_query($query, $args);
/* sending email */
$user_data = user_load($proposal_data->uid);
$email_to = $user_data->mail;
$from = variable_get('circuit_simulation_from_email', '');
$bcc = $user->mail . ', ' . variable_get('circuit_simulation_emails', '');
$cc = variable_get('circuit_simulation_cc_emails', '');
$params['circuit_simulation_proposal_approved']['proposal_id'] = $proposal_id;
$params['circuit_simulation_proposal_approved']['user_id'] = $proposal_data->uid;
$params['circuit_simulation_proposal_approved']['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('circuit_simulation', 'circuit_simulation_proposal_approved', $email_to, language_default(), $params, $from, TRUE))
drupal_set_message('Error sending email message.', 'error');
drupal_set_message('eSim circuit-simulation proposal No. ' . $proposal_id . ' approved. User has been notified of the approval.', 'status');
drupal_goto('circuit-simulation-project/manage-proposal');
return;
} //$form_state['values']['approval'] == 1
else if ($form_state['values']['approval'] == 2)
{
$query = "UPDATE {esim_circuit_simulation_proposal} SET approver_uid = :uid, approval_date = :date, approval_status = 2, dissapproval_reason = :dissapproval_reason WHERE id = :proposal_id";
$args = array(
":uid" => $user->uid,
":date" => time(),
":dissapproval_reason" => $form_state['values']['message'],
":proposal_id" => $proposal_id
);
$result = db_query($query, $args);
/* sending email */
$user_data = user_load($proposal_data->uid);
$email_to = $user_data->mail;
$from = variable_get('circuit_simulation_from_email', '');
$bcc = $user->mail . ', ' . variable_get('circuit_simulation_emails', '');
$cc = variable_get('circuit_simulation_cc_emails', '');
$params['circuit_simulation_proposal_disapproved']['proposal_id'] = $proposal_id;
$params['circuit_simulation_proposal_disapproved']['user_id'] = $proposal_data->uid;
$params['circuit_simulation_proposal_disapproved']['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('circuit_simulation', 'circuit_simulation_proposal_disapproved', $email_to, language_default(), $params, $from, TRUE))
drupal_set_message('Error sending email message.', 'error');
drupal_set_message('eSim circuit simulation proposal No. ' . $proposal_id . ' dis-approved. User has been notified of the dis-approval.', 'error');
drupal_goto('circuit-simulation-project/manage-proposal');
return;
} //$form_state['values']['approval'] == 2
}
/******************************************************************************/
/*************************** PROPOSAL STATUS FORM *****************************/
/******************************************************************************/
function circuit_simulation_proposal_status_form($form, &$form_state)
{
global $user;
/* get current proposal */
$proposal_id = (int) arg(3);
//$proposal_q = db_query("SELECT * FROM {esim_circuit_simulation_proposal} WHERE id = %d", $proposal_id);
$query = db_select('esim_circuit_simulation_proposal');
$query->fields('esim_circuit_simulation_proposal');
$query->condition('id', $proposal_id);
$proposal_q = $query->execute();
if ($proposal_q)
{
if ($proposal_data = $proposal_q->fetchObject())
{
/* everything ok */
} //$proposal_data = $proposal_q->fetchObject()
else
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('circuit-simulation-project/manage-proposal');
return;
}
} //$proposal_q
else
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('circuit-simulation-project/manage-proposal');
return;
}
$form['contributor_name'] = array(
'#type' => 'item',
'#markup' => l($proposal_data->name_title . ' ' . $proposal_data->contributor_name, 'user/' . $proposal_data->uid),
'#title' => t('Student name')
);
$form['student_email_id'] = array(
'#title' => t('Student Email'),
'#type' => 'item',
'#markup' => user_load($proposal_data->uid)->mail,
'#title' => t('Email')
);
$form['month_year_of_degree'] = array(
'#type' => 'date_popup',
'#title' => t('Month and year of award of degree'),
'#date_label_position' => '',
'#description' => '',
'#default_value' => $proposal_data->month_year_of_degree,
'#date_format' => 'M-Y',
'#date_increment' => 0,
'#date_year_range' => '1960:+0',
'#datepicker_options' => array(
'maxDate' => 0
),
'#disabled' => TRUE
);
$form['university'] = array(
'#type' => 'item',
'#markup' => $proposal_data->university,
'#title' => t('University/Institute')
);
$form['country'] = array(
'#type' => 'item',
'#markup' => $proposal_data->country,
'#title' => t('Country')
);
$form['all_state'] = array(
'#type' => 'item',
'#markup' => $proposal_data->state,
'#title' => t('State')
);
$form['city'] = array(
'#type' => 'item',
'#markup' => $proposal_data->city,
'#title' => t('City')
);
$form['pincode'] = array(
'#type' => 'item',
'#markup' => $proposal_data->pincode,
'#title' => t('Pincode/Postal code')
);
/*$form['version'] = array(
'#type' => 'item',
'#title' => t('eSim version'),
'#markup' => $proposal_data->version
);*/
$form['project_guide_name'] = array(
'#type' => 'item',
'#title' => t('Project guide'),
'#markup' => $proposal_data->project_guide_name
);
$form['project_guide_email_id'] = array(
'#type' => 'item',
'#title' => t('Project guide email'),
'#markup' => $proposal_data->project_guide_email_id
);
$form['project_title'] = array(
'#type' => 'item',
'#markup' => $proposal_data->project_title,
'#title' => t('Title of the Circuit Simulation Project')
);
/************************** reference link filter *******************/
$url = '~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i';
$reference = preg_replace($url, '<a href="$0" target="_blank" title="$0">$0</a>', $proposal_data->reference);
/******************************/
$form['reference'] = array(
'#type' => 'item',
'#markup' => $reference,
'#title' => t('References')
);
/*$form['process_development_compound_name'] = array(
'#type' => 'item',
'#title' => t('Name of compound for which process development is carried out'),
'#markup' => $proposal_data->process_development_compound_name
);
$form['process_development_compound_cas_number'] = array(
'#type' => 'item',
'#title' => t('CAS Number of compound for which process development is carried out'),
'#markup' => $proposal_data->process_development_compound_cas_number
);
$form['esim_database_compound_name'] = array(
'#type' => 'item',
'#title' => t('List of compounds from eSim Database used in process circuit simulation'),
'#markup' => $proposal_data->esim_database_compound_name
);*/
$proposal_status = '';
switch ($proposal_data->approval_status)
{
case 0:
$proposal_status = t('Pending');
break;
case 1:
$proposal_status = t('Approved');
break;
case 2:
$proposal_status = t('Dis-approved');
break;
case 3:
$proposal_status = t('Completed');
break;
default:
$proposal_status = t('Unkown');
break;
} //$proposal_data->approval_status
/*if (_circuit_simulation_list_of_user_defined_compound($proposal_data->id) != "Not entered")
{
$form['user_defined_compounds_used_in_process_circuit_simulationcompound_name'] = array(
'#type' => 'item',
'#title' => t('List of user defined compounds used in process circuit simulation'),
'#markup' => _circuit_simulation_list_of_user_defined_compound($proposal_data->id)
);
} //$proposal_data->user_defined_compounds_used_in_process != "" || $proposal_data->user_defined_compounds_used_in_process != NULL
else
{
$form['user_defined_compounds_used_in_process_circuit_simulationcompound_name'] = array(
'#type' => 'item',
'#title' => t('List of user defined compounds used in process circuit simulation'),
'#markup' => "Not entered"
);
}
if ($proposal_data->user_defined_compound_filepath != "" && $proposal_data->user_defined_compound_filepath != "NULL")
{
$form['user_defined_compound_filepath'] = array(
'#type' => 'item',
'#title' => t('Uploaded the user defined compound '),
'#markup' => l('Download user defined compound list', 'circuit-simulation-project/download/user-defined-compound-file/' . $proposal_id) . "<br><br>"
);
} //$proposal_data->user_defined_compound_filepath != ""
else
{
$form['user_defined_compound_filepath'] = array(
'#type' => 'item',
'#title' => t('Uploaded the user defined compound '),
'#markup' => "Not uploaded<br><br>"
);
}*/
$form['proposal_status'] = array(
'#type' => 'item',
'#markup' => $proposal_status,
'#title' => t('Proposal Status')
);
if ($proposal_data->approval_status == 0)
{
$form['approve'] = array(
'#type' => 'item',
'#markup' => l('Click here', 'circuit-simulation-project/manage-proposal/approve/' . $proposal_id),
'#title' => t('Approve')
);
} //$proposal_data->approval_status == 0
if ($proposal_data->approval_status == 1)
{
$form['completed'] = array(
'#type' => 'checkbox',
'#title' => t('Completed'),
'#description' => t('Check if user has provided all the required files and pdfs.')
);
} //$proposal_data->approval_status == 1
if ($proposal_data->approval_status == 2)
{
$form['message'] = array(
'#type' => 'item',
'#markup' => $proposal_data->message,
'#title' => t('Reason for disapproval')
);
} //$proposal_data->approval_status == 2
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
);
$form['cancel'] = array(
'#type' => 'markup',
'#markup' => l(t('Cancel'), 'circuit-simulation-project/manage-proposal/all')
);
return $form;
}
function circuit_simulation_proposal_status_form_submit($form, &$form_state)
{
global $user;
/* get current proposal */
$proposal_id = (int) arg(3);
//$proposal_q = db_query("SELECT * FROM {esim_circuit_simulation_proposal} WHERE id = %d", $proposal_id);
$query = db_select('esim_circuit_simulation_proposal');
$query->fields('esim_circuit_simulation_proposal');
$query->condition('id', $proposal_id);
$proposal_q = $query->execute();
if ($proposal_q)
{
if ($proposal_data = $proposal_q->fetchObject())
{
/* everything ok */
} //$proposal_data = $proposal_q->fetchObject()
else
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('circuit-simulation-project/manage-proposal');
return;
}
} //$proposal_q
else
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('circuit-simulation-project/manage-proposal');
return;
}
/* set the book status to completed */
if ($form_state['values']['completed'] == 1)
{
$up_query = "UPDATE esim_circuit_simulation_proposal SET approval_status = :approval_status , actual_completion_date = :expected_completion_date WHERE id = :proposal_id";
$args = array(
":approval_status" => '3',
":proposal_id" => $proposal_id,
":expected_completion_date" => time()
);
$result = db_query($up_query, $args);
CreateReadmeFileeSimCircuitSimulationProject($proposal_id);
if (!$result)
{
drupal_set_message('Error in update status', 'error');
return;
} //!$result
/* sending email */
$user_data = user_load($proposal_data->uid);
$email_to = $user_data->mail;
$from = variable_get('circuit_simulation_from_email', '');
$bcc = $user->mail . ', ' . variable_get('circuit_simulation_emails', '');
$cc = variable_get('circuit_simulation_cc_emails', '');
$params['circuit_simulation_proposal_completed']['proposal_id'] = $proposal_id;
$params['circuit_simulation_proposal_completed']['user_id'] = $proposal_data->uid;
$params['circuit_simulation_proposal_completed']['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('circuit_simulation', 'circuit_simulation_proposal_completed', $email_to, language_default(), $params, $from, TRUE))
drupal_set_message('Error sending email message.', 'error');
drupal_set_message('Congratulations! eSim circuit-simulation proposal has been marked as completed. User has been notified of the completion.', 'status');
} //$form_state['values']['completed'] == 1
drupal_goto('circuit-simulation-project/manage-proposal');
return;
}
/******************************************************************************/
/**************************** PROPOSAL EDIT FORM ******************************/
/******************************************************************************/
function circuit_simulation_proposal_edit_form($form, &$form_state)
{
global $user;
/* get current proposal */
$proposal_id = (int) arg(3);
//$proposal_q = db_query("SELECT * FROM {esim_circuit_simulation_proposal} WHERE id = %d", $proposal_id);
$query = db_select('esim_circuit_simulation_proposal');
$query->fields('esim_circuit_simulation_proposal');
$query->condition('id', $proposal_id);
$proposal_q = $query->execute();
if ($proposal_q)
{
if ($proposal_data = $proposal_q->fetchObject())
{
/* everything ok */
} //$proposal_data = $proposal_q->fetchObject()
else
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('circuit-simulation-project/manage-proposal');
return;
}
} //$proposal_q
else
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('circuit-simulation-project/manage-proposal');
return;
}
$user_data = user_load($proposal_data->uid);
$form['name_title'] = array(
'#type' => 'select',
'#title' => t('Title'),
'#options' => array(
'Dr' => 'Dr',
'Prof' => 'Prof',
'Mr' => 'Mr',
'Mrs' => 'Mrs',
'Ms' => 'Ms'
),
'#required' => TRUE,
'#default_value' => $proposal_data->name_title
);
$form['contributor_name'] = array(
'#type' => 'textfield',
'#title' => t('Name of the Proposer'),
'#size' => 30,
'#maxlength' => 50,
'#required' => TRUE,
'#default_value' => $proposal_data->contributor_name
);
$form['student_email_id'] = array(
'#type' => 'item',
'#title' => t('Email'),
'#markup' => $user_data->mail
);
$form['month_year_of_degree'] = array(
'#type' => 'date_popup',
'#title' => t('Month and year of award of degree'),
'#date_label_position' => '',
'#description' => '',
'#default_value' => $proposal_data->month_year_of_degree,
'#date_format' => 'M-Y',
'#date_increment' => 0,
'#date_year_range' => '1960:+0',
'#datepicker_options' => array(
'maxDate' => 0
),
'#required' => TRUE
);
$form['university'] = array(
'#type' => 'textfield',
'#title' => t('University/Institute'),
'#size' => 200,
'#maxlength' => 200,
'#required' => TRUE,
'#default_value' => $proposal_data->university
);
$form['country'] = array(
'#type' => 'select',
'#title' => t('Country'),
'#options' => array(
'India' => 'India',
'Others' => 'Others'
),
'#default_value' => $proposal_data->country,
'#required' => TRUE,
'#tree' => TRUE,
'#validated' => TRUE
);
$form['other_country'] = array(
'#type' => 'textfield',
'#title' => t('Other than India'),
'#size' => 100,
'#default_value' => $proposal_data->country,
'#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')
),
'#default_value' => $proposal_data->state,
'#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')
),
'#default_value' => $proposal_data->city,
'#states' => array(
'visible' => array(
':input[name="country"]' => array(
'value' => 'Others'
)
)
)
);
$form['all_state'] = array(
'#type' => 'select',
'#title' => t('State'),
'#options' => _df_list_of_states(),
'#default_value' => $proposal_data->state,
'#validated' => TRUE,
'#states' => array(
'visible' => array(
':input[name="country"]' => array(
'value' => 'India'
)
)
)
);
$form['city'] = array(
'#type' => 'select',
'#title' => t('City'),
'#options' => _df_list_of_cities(),
'#default_value' => $proposal_data->city,
'#states' => array(
'visible' => array(
':input[name="country"]' => array(
'value' => 'India'
)
)
)
);
$form['pincode'] = array(
'#type' => 'textfield',
'#title' => t('Pincode'),
'#size' => 30,
'#maxlength' => 6,
'#default_value' => $proposal_data->pincode,
'#attributes' => array(
'placeholder' => 'Insert pincode of your city/ village....'
)
);
$form['project_title'] = array(
'#type' => 'textarea',
'#title' => t('Title of the Circuit Simulation Project'),
'#size' => 300,
'#maxlength' => 350,
'#required' => TRUE,
'#default_value' => $proposal_data->project_title
);
$form['reference'] = array(
'#type' => 'textarea',
'#title' => t('Reference'),
'#required' => TRUE,
'#size' => 10000,
'#attributes' => array(
'placeholder' => 'Links of must be provided....'
),
'#default_value' => $proposal_data->reference
);
$form['delete_proposal'] = array(
'#type' => 'checkbox',
'#title' => t('Delete Proposal')
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
);
$form['cancel'] = array(
'#type' => 'item',
'#markup' => l(t('Cancel'), 'circuit-simulation-project/manage-proposal')
);
return $form;
}
/*
function circuit_simulation_proposal_edit_form_validate($form, &$form_state)
{
$proposal_id = (int) arg(3);
// check before delete proposal
if ($form_state['values']['delete_proposal'] == 1)
{
//$experiment_q = db_query("SELECT * FROM {esim_circuit_simulation_experiment} WHERE proposal_id = %d", $proposal_id);
$query = db_select('esim_circuit_simulation_user_defined_compound');
$query->fields('esim_circuit_simulation_user_defined_compound');
$query->condition('proposal_id', $proposal_id);
$experiment_q = $query->execute();
while ($experiment_data = $experiment_q->fetchObject())
{
//$solution_q = db_query("SELECT * FROM {esim_circuit_simulation_solution} WHERE experiment_id = %d", $experiment_data->id);
$query = db_select('esim_circuit_simulation_user_defined_compound');
$query->fields('esim_circuit_simulation_user_defined_compound');
$query->condition('proposal_id', $proposal_id);
$solution_q = $query->execute();
if ($solution_q->fetchObject())
{
form_set_error('', t('Cannot delete proposal since there are solutions already uploaded. Use the "Bulk Manage" interface to delete this proposal'));
} //$solution_q->fetchObject()
} //$experiment_data = $experiment_q->fetchObject()
} //$form_state['values']['delete_proposal'] == 1
return;
}*/
function circuit_simulation_proposal_edit_form_submit($form, &$form_state)
{
global $user;
/* get current proposal */
$proposal_id = (int) arg(3);
// $proposal_q = db_query("SELECT * FROM {esim_circuit_simulation_proposal} WHERE id = %d", $proposal_id);
$query = db_select('esim_circuit_simulation_proposal');
$query->fields('esim_circuit_simulation_proposal');
$query->condition('id', $proposal_id);
$proposal_q = $query->execute();
if ($proposal_q)
{
if ($proposal_data = $proposal_q->fetchObject())
{
/* everything ok */
} //$proposal_data = $proposal_q->fetchObject()
else
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('circuit-simulation-project/manage-proposal');
return;
}
} //$proposal_q
else
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('circuit-simulation-project/manage-proposal');
return;
}
/* delete proposal */