summaryrefslogtreecommitdiff
path: root/dwsim_flowsheet.module
blob: 7e2a5a941402dac4296567fdc1a96eff6ae63f65 (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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
<?php
// $Id$
require_once('general_deletion.inc');
require_once('email.inc');
/**
 * Implementation of hook_menu().
 */
function dwsim_flowsheet_menu()
{
	$items = array();
	/* PROPOSAL */
	$items['flowsheeting-project/proposal'] = array(
		'title' => 'Flowsheet Proposal Form',
		'description' => 'Flowsheet Proposal Form Proposal Form',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'dwsim_flowsheet_proposal_form'
		),
		'access arguments' => array(
			'dwsim flowsheet create proposal'
		),
		'type' => MENU_NORMAL_ITEM,
		'file' => 'proposal.inc'
	);
	$items['flowsheeting-project/manage-proposal'] = array(
		'title' => 'Manage Flowsheet Proposals',
		'description' => 'Manage Flowsheet Proposals',
		'page callback' => 'dwsim_flowsheet_proposal_pending',
		'access callback' => 'user_access',
		'access arguments' => array(
			'dwsim flowsheet manage proposal'
		),
		'file' => 'manage_proposal.inc'
	);
	$items['flowsheeting-project/manage-proposal/pending'] = array(
		'title' => 'Pending Proposals',
		'description' => 'Pending dwsim flowsheet Proposals Queue',
		'page callback' => 'dwsim_flowsheet_proposal_pending',
		'access callback' => 'user_access',
		'access arguments' => array(
			'dwsim flowsheet manage proposal'
		),
		'type' => MENU_DEFAULT_LOCAL_TASK,
		'weight' => 1,
		'file' => 'manage_proposal.inc'
	);
	$items['flowsheeting-project/manage-proposal/all'] = array(
		'title' => 'All Proposals',
		'description' => 'All Proposals',
		'page callback' => 'dwsim_flowsheet_proposal_all',
		'access callback' => 'user_access',
		'access arguments' => array(
			'dwsim flowsheet manage proposal'
		),
		'type' => MENU_LOCAL_TASK,
		'weight' => 2,
		'file' => 'manage_proposal.inc'
	);
	$items['flowsheeting-project/manage-proposal/approved_proposals'] = array(
		'title' => 'Approved Proposals',
		'description' => 'Approved Proposals',
		'page callback' => 'dwsim_flowsheet_approved_tab',
		'access callback' => 'user_access',
		'access arguments' => array(
			'dwsim flowsheet manage proposal'
		),
		'type' => MENU_LOCAL_TASK,
		'weight' => 3,
		'file' => 'proposals_review_tab.inc'
	);
	$items['flowsheeting-project/manage-proposal/uploaded_proposals'] = array(
		'title' => 'Uploaded Proposals',
		'description' => 'Uploaded Proposals',
		'page callback' => 'dwsim_flowsheet_uploaded_tab',
		'access callback' => 'user_access',
		'access arguments' => array(
			'dwsim flowsheet manage proposal'
		),
		'type' => MENU_LOCAL_TASK,
		'weight' => 4,
		'file' => 'proposals_review_tab.inc'
	);
	$items['flowsheeting-project/manage-proposal/completed_proposals'] = array(
		'title' => 'Completed Proposals',
		'description' => 'Completed Proposals',
		'page callback' => 'drupal_get_form',
		'page arguments' => array('dwsim_flowsheet_completed_tab_form'),
		'access callback' => 'user_access',
		'access arguments' => array(
			'dwsim flowsheet manage proposal'
		),
		'type' => MENU_LOCAL_TASK,
		'weight' => 5,
		'file' => 'proposals_review_tab.inc'
	);
	/*$items['flowsheeting-project/download'] = array(
		'title' => 'Flowsheet Download Proposals',
		'description' => 'Flowsheet Download Proposals',
		'page callback' => 'dwsim_flowsheet_download_proposals_tab',
		'access callback' => 'user_access',
		'access arguments' => array(
			'dwsim flowsheet manage proposal'
		),
		'file' => 'proposals_review_tab.inc'
	);*/
	$items['flowsheeting-project/manage-proposal/approve'] = array(
		'title' => 'Approve Proposal',
		'description' => 'Approve Proposal',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'dwsim_flowsheet_proposal_approval_form'
		),
		'access arguments' => array(
			'dwsim flowsheet manage proposal'
		),
		'type' => MENU_CALLBACK,
		'file' => 'manage_proposal.inc'
	);
	$items['flowsheeting-project/manage-proposal/solution-proposal-approve'] = array(
		'title' => 'Approve Solution Proposal',
		'description' => 'Approve Solution Proposal',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'dwsim_flowsheet_solution_proposal_approval_form'
		),
		'access arguments' => array(
			'dwsim flowsheet manage proposal'
		),
		'type' => MENU_CALLBACK,
		'file' => 'manage_solution_proposal.inc'
	);
	$items['flowsheeting-project/manage-proposal/edit'] = array(
		'title' => 'Edit Proposal',
		'description' => 'Edit Proposal',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'dwsim_flowsheet_proposal_edit_form'
		),
		'access arguments' => array(
			'dwsim flowsheet manage proposal'
		),
		'type' => MENU_CALLBACK,
		'file' => 'manage_proposal.inc'
	);
	$items['flowsheeting-project/manage-proposal/status'] = array(
		'title' => 'Proposal Status',
		'description' => 'Proposal Status',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'dwsim_flowsheet_proposal_status_form'
		),
		'access arguments' => array(
			'dwsim flowsheet approve proposal'
		),
		'type' => MENU_CALLBACK,
		'file' => 'manage_proposal.inc'
	);
	$items['flowsheeting-project/show-proposal'] = array(
		'title' => 'dwsim flowsheet Solution Proposal',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'dwsim_flowsheet_solution_proposal_form'
		),
		'access arguments' => array(
			'dwsim flowsheet propose solution'
		),
		'type' => MENU_CALLBACK,
		'file' => 'solution_proposal.inc'
	);
	/* CODE REVIEW */
	$items['flowsheeting-project/code-approval'] = array(
		'title' => 'LM Manage Code Approval',
		'description' => 'Manage Code Approval',
		'page callback' => 'dwsim_flowsheet_code_approval',
		'access arguments' => array(
			'dwsim flowsheet approve code'
		),
		'type' => MENU_NORMAL_ITEM,
		'file' => 'code_approval.inc'
	);
	$items['flowsheeting-project/abstract-approval/approve'] = array(
		'title' => 'Code Approval',
		'description' => 'Code Approval',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'dwsim_flowsheet_abstract_approval_form'
		),
		'access arguments' => array(
			'dwsim flowsheet approve code'
		),
		'type' => MENU_DEFAULT_LOCAL_TASK,
		'weight' => 1,
		'file' => 'code_approval.inc'
	);
	$items['flowsheeting-project/abstract-approval/bulk'] = array(
		'title' => 'Bulk Manage',
		'description' => 'Bulk Mangage',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'dwsim_flowsheet_abstract_bulk_approval_form'
		),
		'access arguments' => array(
			'dwsim flowsheet bulk manage abstract'
		),
		'type' => MENU_LOCAL_TASK,
		'weight' => 2,
		'file' => 'abstract_bulk_approval.inc'
	);
	$items['flowsheeting-project/code-approval/bulk'] = array(
		'title' => 'Bulk Manage',
		'description' => 'Bulk Mangage',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'dwsim_flowsheet_bulk_approval_form'
		),
		'access arguments' => array(
			'dwsim flowsheet bulk manage abstract'
		),
		'type' => MENU_LOCAL_TASK,
		'weight' => 2,
		'file' => 'bulk_approval.inc'
	);
	$items['flowsheeting-project/code-approval/upload'] = array(
		'title' => 'Upload Code',
		'description' => 'Admin Upload',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'dwsim_flowsheet_bulk_upload_code_form'
		),
		'access arguments' => array(
			'dwsim flowsheet bulk manage abstract'
		),
		'type' => MENU_CALLBACK,
		'weight' => 4,
		'file' => 'bulk_upload_code.inc'
	);
	$items['flowsheeting-project/code-approval/notes'] = array(
		'title' => 'Notes for Reviewers',
		'description' => 'Notes for Reviewers',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'dwsim_flowsheet_lab_notes_form'
		),
		'access arguments' => array(
			'dwsim flowsheet bulk manage abstract'
		),
		'type' => MENU_CALLBACK,
		'weight' => 4,
		'file' => 'notes.inc'
	);
	/* CODE UPLOAD */
	$items['flowsheeting-project/abstract-code'] = array(
		'title' => 'Abstract and Flowsheet Submission',
		'description' => 'Abstract Submission',
		'page callback' => 'dwsim_flowsheet_abstract',
		'access callback' => 'user_access',
		'access arguments' => array(
			'dwsim flowsheet upload code'
		),
		'file' => 'upload_code.inc'
	);
	$items['flowsheeting-project/abstract-code/flowsheet-project-list'] = array(
		'title' => 'Flowsheet project',
		'description' => 'List Experiments',
		'page callback' => 'dwsim_flowsheet_abstract',
		'access arguments' => array(
			'dwsim flowsheet upload code'
		),
		'type' => MENU_DEFAULT_LOCAL_TASK,
		'file' => 'upload_code.inc',
		'weight' => 1
	);
	$items['flowsheeting-project/abstract-code/upload'] = array(
		'title' => 'Abstract and Flowsheet Submission',
		'description' => 'Abstract Submission',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'dwsim_flowsheet_upload_abstract_code_form'
		),
		'access arguments' => array(
			'dwsim flowsheet upload code'
		),
		'type' => MENU_LOCAL_TASK,
		'file' => 'upload_code.inc',
		'weight' => 2
	);
	$items['flowsheeting-project/abstract-code/delete'] = array(
		'title' => 'Delete Solution',
		'description' => 'Delete Solution',
		'page callback' => 'dwsim_flowsheet_upload_code_delete',
		'access arguments' => array(
			'dwsim flowsheet upload code'
		),
		'type' => MENU_CALLBACK,
		'file' => 'upload_code_delete.inc'
	);
	/* CODE DOWNLOADS */
	$items['flowsheeting-project/download/file'] = array(
		'title' => 'Code Download',
		'description' => 'Code Download',
		'page callback' => 'dwsim_flowsheet_download_solution_file',
		'access arguments' => array(
			'dwsim flowsheet download code'
		),
		'type' => MENU_CALLBACK,
		'file' => 'download.inc'
	);
	$items['flowsheeting-project/download/project-file'] = array(
		'title' => 'Code Download',
		'description' => 'Code Download',
		'page callback' => 'dwsim_flowsheet_download_abstract',
		'access arguments' => array(
			'dwsim flowsheet download code'
		),
		'type' => MENU_CALLBACK,
		'file' => 'download.inc'
	);
	$items['flowsheeting-project/download/solution'] = array(
		'title' => 'Code Download',
		'description' => 'Code Download',
		'page callback' => 'dwsim_flowsheet_download_solution',
		'access arguments' => array(
			'dwsim flowsheet download code'
		),
		'type' => MENU_CALLBACK,
		'file' => 'download.inc'
	);
	$items['flowsheeting-project/download/experiment'] = array(
		'title' => 'Code Download',
		'description' => 'Code Download',
		'page callback' => 'dwsim_flowsheet_download_experiment',
		'access arguments' => array(
			'dwsim flowsheet download code'
		),
		'type' => MENU_CALLBACK,
		'file' => 'download.inc'
	);
	$items['flowsheeting-project/download/lab'] = array(
		'title' => 'Code Download',
		'description' => 'Code Download',
		'page callback' => 'dwsim_flowsheet_download_lab',
		'access arguments' => array(
			'dwsim flowsheet download code'
		),
		'type' => MENU_CALLBACK,
		'file' => 'download.inc'
	);
	$items['flowsheeting-project/full-download/experiment'] = array(
		'title' => 'Code Download',
		'description' => 'Code Download',
		'page callback' => 'dwsim_flowsheet_download_full_experiment',
		'access arguments' => array(
			'dwsim flowsheet approve code'
		),
		'type' => MENU_CALLBACK,
		'file' => 'full_download.inc'
	);
	$items['flowsheeting-project/full-download/project'] = array(
		'title' => 'Code Download',
		'description' => 'Code Download',
		'page callback' => 'dwsim_flowsheet_download_full_project',
		'access arguments' => array(
			'dwsim flowsheet download code'
		),
		'type' => MENU_CALLBACK,
		'file' => 'full_download.inc'
	);
	$items['flowsheeting-project/download-proposals'] = array(
		'title' => 'Download Proposals',
		'description' => 'Download Proposals',
		'page callback' => 'dwsim_flowsheet_download_proposals',
		'access arguments' => array(
			'dwsim flowsheet download proposals'
		),
		'type' => MENU_CALLBACK,
		'file' => 'download.inc'
	);
	/* COMPLETED dwsim flowsheetS */
	$items['flowsheeting-project/completed-flowsheet'] = array(
		'title' => 'Completed Flowsheets',
		'page callback' => 'dwsim_flowsheet_completed_proposals_all',
		'access arguments' => array(
			'dwsim flowsheet download code'
		),
		'file' => 'flowsheet_details.inc'
	);
	/* LABS IN PROGRESS */
	$items['flowsheeting-project/flowsheet-progress'] = array(
		'title' => 'Flowsheets in Progress',
		'page callback' => 'dwsim_flowsheet_progress_all',
		'access arguments' => array(
			'dwsim flowsheet download code'
		),
		'file' => 'flowsheet_details.inc'
	);
	/* DOWNLOAD FOR EVERYONE */
	$items['flowsheeting-project/dwsim-flowsheet-run'] = array(
		'title' => 'Download Codes',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'dwsim_flowsheet_run_form'
		),
		'access arguments' => array(
			'dwsim flowsheet download code'
		),
		'type' => MENU_NORMAL_ITEM,
		'file' => 'run.inc'
	);
	$items['flowsheeting-project/download/user-defined-compound-file'] = array(
		'title' => 'Download user defined compound file',
		'description' => 'Download user defined compound',
		'page callback' => 'dwsim_flowsheet_download_user_defined_compound',
		'access arguments' => array(
			'download code'
		),
		'type' => MENU_CALLBACK,
		'file' => 'download.inc'
	);
	/* LATEX SCRIPT */
	$items['flowsheeting-project/generate-lab'] = array(
		'title' => 'Generate Lab',
		'description' => 'Generate Lab From Latex Script',
		'page callback' => 'dwsim_flowsheet_download_lab_pdf',
		'access arguments' => array(
			'dwsim flowsheet generate lab'
		),
		'type' => MENU_CALLBACK,
		'file' => 'latex.inc'
	);
	$items['flowsheeting-project/delete-lab'] = array(
		'title' => 'Delete Lab PDF',
		'description' => 'Delete Lab PDF',
		'page callback' => 'dwsim_flowsheet_delete_lab_pdf',
		'access arguments' => array(
			'dwsim flowsheet approve code'
		),
		'type' => MENU_CALLBACK,
		'file' => 'latex.inc'
	);
	/* ADMIN SETTINGS */
	$items['admin/settings/dwsim-flowsheet'] = array(
		'title' => 'dwsim flowsheet Settings',
		'description' => 'dwsim flowsheet Settings',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'dwsim_flowsheet_settings_form'
		),
		'access arguments' => array(
			'administer dwsim flowsheet'
		),
		'type' => MENU_NORMAL_ITEM,
		'file' => 'settings.inc'
	);
	/* AJAX REQUEST */
	$items["lab-bulk-manage-exp/ajax"] = array(
		"title" => "Ajax callbacks",
		"page callback" => "lab_bulk_manage_exp_ajax",
		"access arguments" => array(
			"dwsim flowsheet bulk manage abstract"
		),
		"type" => MENU_CALLBACK,
		'file' => 'bulk_approval.inc'
	);
	$items['flowsheeting-project/certificates'] = array(
		'title' => 'List of Flowsheet Certificates',
		'description' => 'List of flowsheet Certificates',
		'page callback' => '_list_flowsheet_certificates',
		'access arguments' => array(
			'list flowsheet certificates'
		),
		'file' => 'pdf/list_flowsheet_certificate.inc'
	);
	$items['flowsheeting-project/certificates/generate-pdf'] = array(
		'title' => 'Download Certificate',
		'description' => 'Download Certificate',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'generate_pdf'
		),
		'type' => MENU_CALLBACK,
		'access arguments' => array(
			'generate pdf'
		),
		'file' => 'pdf/cert_new.inc'
	);
	$items['flowsheeting-project/certificates-custom'] = array(
		'title' => 'List of Flowsheet Custom Certificates',
		'description' => 'List of flowsheet Custom Certificates',
		'page callback' => '_list_flowsheet_custom_certificates',
		'access arguments' => array(
			'list flowsheet custom certificates'
		),
		'file' => 'pdf/list_mentor_certificates.inc'
	);
	$items['flowsheeting-project/certificates-custom/pdf'] = array(
		'title' => 'Download Certificate',
		'description' => 'Download Certificate',
		'page callback' => 'drupal_get_form',
		'page arguments' => array(
			'generate_pdf'
		),
		'type' => MENU_CALLBACK,
		'access arguments' => array(
			'generate pdf'
		),
		'file' => 'pdf/mentor_cert_pdf.inc'
	);
	$items["flowsheeting-project/certificates/verify"] = array(
		"title" => "Certificate Verification",
		"page callback" => "verify_certificates",
		"access arguments" => array(
			"verify certificates"
		),
		'type' => MENU_CALLBACK,
		'file' => 'pdf/verify_certificates.inc'
	);
	return $items;
}
/**
 * Implementation of hook_perm().
 */
function dwsim_flowsheet_permission()
{
	return array(
		'dwsim flowsheet create proposal' => array(
			'title' => t('dwsim flowsheet create proposal'),
			'restrict access' => TRUE
		),
		'dwsim flowsheet manage proposal' => array(
			'title' => t('dwsim flowsheet manage proposal'),
			'restrict access' => TRUE
		),
		'dwsim flowsheet edit proposal' => array(
			'title' => t('dwsim flowsheet edit proposal'),
			'restrict access' => TRUE
		),
		'dwsim flowsheet approve proposal' => array(
			'title' => t('dwsim flowsheet approve proposal'),
			'restrict access' => TRUE
		),
		'dwsim flowsheet propose solution' => array(
			'title' => t('dwsim flowsheet propose solution'),
			'restrict access' => TRUE
		),
		'dwsim flowsheet approve abstract' => array(
			'title' => t('dwsim flowsheet approve code'),
			'restrict access' => TRUE
		),
		'dwsim flowsheet bulk manage abstract' => array(
			'title' => t('dwsim flowsheet bulk manage abstract'),
			'restrict access' => TRUE
		),
		'dwsim flowsheet bulk delete abstract' => array(
			'title' => t('dwsim flowsheet bulk delete code'),
			'restrict access' => TRUE
		),
		'dwsim flowsheet upload abstract' => array(
			'title' => t('dwsim flowsheet upload code'),
			'restrict access' => TRUE
		),
		'dwsim flowsheet download abstract' => array(
			'title' => t('dwsim flowsheet download code'),
			'restrict access' => TRUE
		),
		'dwsim flowsheet download proposals' => array(
			'title' => t('dwsim flowsheet download proposals'),
			'restrict access' => TRUE
		),
		'administer dwsim flowsheet' => array(
			'title' => t('administer dwsim flowsheet'),
			'restrict access' => TRUE
		),
		'dwsim flowsheet generate abstract' => array(
			'title' => t('dwsim flowsheet generate abstract'),
			'restrict access' => TRUE
		),
		"list flowsheet certificates" => array(
			"title" => t("list flowsheet certificates"),
			"description" => t("Allows users to list flowsheet certificates.")
		),
		"list flowsheet custom certificates" => array(
			"title" => t("list flowsheet custom certificates"),
			"description" => t("Allows users to list flowsheet custom certificates.")
		),
		"generate pdf" => array(
			"title" => t("Generate pdf"),
			"description" => t("Allows users to Generate pdf.")
		)
	);
	// return array('dwsim flowsheet create proposal', 'dwsim flowsheet manage proposal', 'dwsim flowsheet edit proposal', 'dwsim flowsheet approve proposal', 'dwsim flowsheet propose solution', 'dwsim flowsheet approve code', 'dwsim flowsheet bulk manage abstract', 'dwsim flowsheet bulk delete code', 'dwsim flowsheet upload code', 'dwsim flowsheet download code', 'administer dwsim flowsheet', 'dwsim flowsheet generate lab');
}
/* AJAX CALLS */
function dwsim_flowsheet_ajax()
{
	$query_type = arg(2);
	if ($query_type == 'chapter_title')
	{
		$chapter_number = arg(3);
		$preference_id = arg(4);
		//$chapter_q = db_query("SELECT * FROM {dwsim_flowsheet_chapter} WHERE number = %d AND preference_id = %d LIMIT 1", $chapter_number, $preference_id);
		$query = db_select('dwsim_flowsheet_chapter');
		$query->fields('dwsim_flowsheet_chapter');
		$query->condition('number', $chapter_number);
		$query->condition('preference_id', $preference_id);
		$query->range(0, 1);
		$chapter_q = $query->execute();
		if ($chapter_data = $chapter_q->fetchObject())
		{
			echo $chapter_data->name;
			return;
		} //$chapter_data = $chapter_q->fetchObject()
	} //$query_type == 'chapter_title'
	else if ($query_type == 'example_exists')
	{
		$chapter_number = arg(3);
		$preference_id = arg(4);
		$example_number = arg(5);
		$chapter_id = 0;
		$query = db_select('dwsim_flowsheet_chapter');
		$query->fields('dwsim_flowsheet_chapter');
		$query->condition('number', $chapter_number);
		$query->condition('preference_id', $preference_id);
		$query->range(0, 1);
		$chapter_q = $query->execute();
		if (!$chapter_data = $chapter_q->fetchObject())
		{
			echo '';
			return;
		} //!$chapter_data = $chapter_q->fetchObject()
		else
		{
			$chapter_id = $chapter_data->id;
		}
		$query = db_select('dwsim_flowsheet_example');
		$query->fields('dwsim_flowsheet_example');
		$query->condition('chapter_id', $chapter_id);
		$query->condition('number', $example_number);
		$query->range(0, 1);
		$example_q = $query->execute();
		if ($example_data = $example_q->fetchObject())
		{
			if ($example_data->approval_status == 1)
				echo 'Warning! Solution already approved. You cannot upload the same solution again.';
			else
				echo 'Warning! Solution already uploaded. Delete the solution and reupload it.';
			return;
		} //$example_data = $example_q->fetchObject()
	} //$query_type == 'example_exists'
	echo '';
}
/*************************** VALIDATION FUNCTIONS *****************************/
function dwsim_flowsheet_check_valid_filename($file_name)
{
	if (!preg_match('/^[0-9a-zA-Z\.\_]+$/', $file_name))
		return FALSE;
	else if (substr_count($file_name, ".") > 1)
		return FALSE;
	else
		return TRUE;
}
function dwsim_flowsheet_check_name($name = '')
{
	if (!preg_match('/^[0-9a-zA-Z\ ]+$/', $name))
		return FALSE;
	else
		return TRUE;
}
function dwsim_flowsheet_check_code_number($number = '')
{
	if (!preg_match('/^[0-9]+$/', $number))
		return FALSE;
	else
		return TRUE;
}
function dwsim_flowsheet_path()
{
	return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'dwsim_uploads/dwsim_flowsheet_uploads/';
}
/************************* USER VERIFICATION FUNCTIONS ************************/
function dwsim_flowsheet_get_proposal()
{
	global $user;
	//$proposal_q = db_query("SELECT * FROM {dwsim_flowsheet_proposal} WHERE solution_provider_uid = ".$user->uid." AND solution_status = 2 ORDER BY id DESC LIMIT 1");
	$query = db_select('dwsim_flowsheet_proposal');
	$query->fields('dwsim_flowsheet_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)
	{
		drupal_set_message("You do not have any approved DWSIM Flowsheet proposal. Please propose the flowsheet proposal", 'error');
		drupal_goto('');
	} //!$proposal_data
	switch ($proposal_data->approval_status)
	{
		case 0:
			drupal_set_message(t('Proposal is awaiting approval.'), 'status');
			return FALSE;
		case 1:
			return $proposal_data;
		case 2:
			drupal_set_message(t('Proposal has been dis-approved.'), 'error');
			return FALSE;
		case 3:
			drupal_set_message(t('Proposal has been marked as completed.'), 'status');
			return FALSE;
		default:
			drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
			return FALSE;
	} //$proposal_data->approval_status
	return FALSE;
}
/*************************************************************************/
/***** Function To convert only first charater of string in uppercase ****/
/*************************************************************************/
function dwsim_flowsheet_ucname($string)
{
	$string = ucwords(strtolower($string));
	foreach (array(
		'-',
		'\''
	) as $delimiter)
	{
		if (strpos($string, $delimiter) !== false)
		{
			$string = implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
		} //strpos($string, $delimiter) !== false
	} //array( '-', '\'' ) as $delimiter
	return $string;
}
function _df_sentence_case($string)
{
	$string = ucwords(strtolower($string));
	foreach (array(
		'-',
		'\''
	) as $delimiter)
	{
		if (strpos($string, $delimiter) !== false)
		{
			$string = implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
		} //strpos($string, $delimiter) !== false
	} //array( '-', '\'' ) as $delimiter
	return $string;
}
function _df_list_of_dwsim_compound()
{
	$dwsim_compound = array();
	$query = db_select('dwsim_flowsheet_compounds_from_dwsim');
	$query->fields('dwsim_flowsheet_compounds_from_dwsim');
	$query->orderBy('id', 'ASC');
	$dwsim_compound_list = $query->execute();
	while ($dwsim_compound_list_data = $dwsim_compound_list->fetchObject())
	{
		$dwsim_compound[$dwsim_compound_list_data->compound] = $dwsim_compound_list_data->compound;
	} //$dwsim_compound_list_data = $dwsim_compound_list->fetchObject()
	return $dwsim_compound;
}
function _df_list_of_unit_operations()
{
	$dwsim_unit_operations = array();
	$query = db_select('dwsim_flowsheet_unit_operations');
	$query->fields('dwsim_flowsheet_unit_operations');
	$query->orderBy('id', 'ASC');
	$dwsim_unit_operations_list = $query->execute();
	while ($dwsim_unit_operations_list_data = $dwsim_unit_operations_list->fetchObject())
	{
		$dwsim_unit_operations[$dwsim_unit_operations_list_data->unit_operations] = $dwsim_unit_operations_list_data->unit_operations;
	} //$dwsim_unit_operations_list_data = $dwsim_unit_operations_list->fetchObject()
	return $dwsim_unit_operations;
}
function _df_list_of_thermodynamic_packages()
{
	$dwsim_thermodynamic_packages = array();
	$query = db_select('dwsim_flowsheet_thermodynamic_packages');
	$query->fields('dwsim_flowsheet_thermodynamic_packages');
	$query->orderBy('thermodynamic_packages', 'ASC');
	$dwsim_thermodynamic_packages_list = $query->execute();
	while ($dwsim_thermodynamic_packages_list_data = $dwsim_thermodynamic_packages_list->fetchObject())
	{
		$dwsim_thermodynamic_packages[$dwsim_thermodynamic_packages_list_data->thermodynamic_packages] = $dwsim_thermodynamic_packages_list_data->thermodynamic_packages;
	} //$dwsim_thermodynamic_packages_list_data = $dwsim_thermodynamic_packages_list->fetchObject()
	return $dwsim_thermodynamic_packages;
}
function _df_list_of_logical_block()
{
	$dwsim_logical_block = array();
	$query = db_select('dwsim_flowsheet_logical_block');
	$query->fields('dwsim_flowsheet_logical_block');
	$query->orderBy('id', 'ASC');
	$dwsim_logical_block_list = $query->execute();
	while ($dwsim_logical_block_list_data = $dwsim_logical_block_list->fetchObject())
	{
		$dwsim_logical_block[$dwsim_logical_block_list_data->logical_block] = $dwsim_logical_block_list_data->logical_block;
	} //$dwsim_logical_block_list_data = $dwsim_logical_block_list->fetchObject()
	return $dwsim_logical_block;
}
function _df_list_of_states()
{
	$states = array(
		0 => '-Select-'
	);
	$query = db_select('list_states_of_india');
	$query->fields('list_states_of_india');
	//$query->orderBy('', '');
	$states_list = $query->execute();
	while ($states_list_data = $states_list->fetchObject())
	{
		$states[$states_list_data->state] = $states_list_data->state;
	} //$states_list_data = $states_list->fetchObject()
	return $states;
}
function _df_list_of_cities()
{
	$city = array(
		0 => '-Select-'
	);
	$query = db_select('list_cities_of_india');
	$query->fields('list_cities_of_india');
	$query->orderBy('city', 'ASC');
	$city_list = $query->execute();
	while ($city_list_data = $city_list->fetchObject())
	{
		$city[$city_list_data->city] = $city_list_data->city;
	} //$city_list_data = $city_list->fetchObject()
	return $city;
}
function _df_list_of_pincodes()
{
	$pincode = array(
		0 => '-Select-'
	);
	$query = db_select('list_of_all_india_pincode');
	$query->fields('list_of_all_india_pincode');
	$query->orderBy('pincode', 'ASC');
	$pincode_list = $query->execute();
	while ($pincode_list_data = $pincode_list->fetchObject())
	{
		$pincode[$pincode_list_data->pincode] = $pincode_list_data->pincode;
	} //$pincode_list_data = $pincode_list->fetchObject()
	return $pincode;
}
function _df_list_of_departments()
{
	$department = array();
	$query = db_select('list_of_departments');
	$query->fields('list_of_departments');
	$query->orderBy('id', 'DESC');
	$department_list = $query->execute();
	while ($department_list_data = $department_list->fetchObject())
	{
		$department[$department_list_data->department] = $department_list_data->department;
	} //$department_list_data = $department_list->fetchObject()
	return $department;
}
function _df_list_of_software_version()
{
	$software_version = array();
	$query = db_select('dwsim_software_version');
	$query->fields('dwsim_software_version');
	$query->orderBy('id', 'ASC');
	$software_version_list = $query->execute();
	while ($software_version_list_data = $software_version_list->fetchObject())
	{
		$software_version[$software_version_list_data->dwsim_version] = $software_version_list_data->dwsim_version;
	} //$software_version_list_data = $software_version_list->fetchObject()
	return $software_version;
}
function _df_dir_name($project, $proposar_name)
{

	$project_title = ucname($project);
	$proposar_name = ucname($proposar_name);
	$dir_name = $project_title . ' By ' . $proposar_name;
	$directory_name = str_replace("__", "_", str_replace(" ", "_", str_replace("/", " ", $dir_name)));
	return $directory_name;
}
function dwsim_flowsheet_document_path()
{
	return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'dwsim_uploads/dwsim_flowsheet_uploads/';
}
function DF_RenameDir($proposal_id, $dir_name)
{
	$proposal_id = $proposal_id;
	$dir_name = $dir_name;
	$query = db_query("SELECT directory_name,id FROM dwsim_flowsheet_proposal WHERE id = :proposal_id", array(
		':proposal_id' => $proposal_id
	));
	$result = $query->fetchObject();
	if ($result != NULL)
	{
		$files = scandir(dwsim_flowsheet_path());
		$files_id_dir = dwsim_flowsheet_path() . $result->id;
		//var_dump($files);die;
		$file_dir = dwsim_flowsheet_path() . $result->directory_name;
		if (is_dir($file_dir))
		{
			$new_directory_name = rename(dwsim_flowsheet_path() . $result->directory_name, dwsim_flowsheet_path() . $dir_name);
			return $new_directory_name;
		} //is_dir($file_dir)
		else if (is_dir($files_id_dir))
		{
			$new_directory_name = rename(dwsim_flowsheet_path() . $result->id, dwsim_flowsheet_path() . $dir_name);
			return $new_directory_name;
		} //is_dir($files_id_dir)
		else
		{
			drupal_set_message('Directory not available for rename.');
			return;
		}
	} //$result != NULL
	else
	{
		drupal_set_message('Project directory name not present in databse');
		return;
	}
	//var_dump($files);die;
	/* if ($files != NULL)
	{
	$new_directory_name = rename(dwsim_flowsheet_path() . $result->directory_name, dwsim_flowsheet_path() . $dir_name) or drupal_set_message("Unable to rename folder");
	}
	else
	{
	$new_directory_name = 'Can not rename the directory. Directory not present';
	}*/
	return;
}
function CreateReadmeFileDWSIMFlowsheetingProject($proposal_id)
{
	$result = db_query("
                        SELECT * from dwsim_flowsheet_proposal WHERE id = :proposal_id", array(
		":proposal_id" => $proposal_id
	));
	$proposal_data = $result->fetchObject();
	$root_path = dwsim_flowsheet_path();
	$readme_file = fopen($root_path . $proposal_data->directory_name . "/README.txt", "w") or die("Unable to open file!");
	$txt = "";
	$txt .= "About the flowsheet";
	$txt .= "\n" . "\n";
	$txt .= "Title Of The Flowsheet Project: " . $proposal_data->project_title . "\n";
	$txt .= "Proposar Name: " . $proposal_data->name_title . " " . $proposal_data->contributor_name . "\n";
	$txt .= "University: " . $proposal_data->university . "\n";
	$txt .= "\n" . "\n";
	$txt .= "DWSIM Flowsheet Project By FOSSEE, IIT Bombay" . "\n";
	fwrite($readme_file, $txt);
	fclose($readme_file);
	return $txt;
}
function rrmdir_project($prop_id)
{
	$proposal_id = $prop_id;
	$result = db_query("
					SELECT * from dwsim_flowsheet_proposal WHERE id = :proposal_id", array(
		":proposal_id" => $proposal_id
	));
	$proposal_data = $result->fetchObject();
	$root_path = dwsim_flowsheet_document_path();
	$dir = $root_path . $proposal_data->directory_name;
	if ($proposal_data->id == $prop_id)
	{
		if (is_dir($dir))
		{
			$objects = scandir($dir);
			foreach ($objects as $object)
			{
				if ($object != "." && $object != "..")
				{
					if (filetype($dir . "/" . $object) == "dir")
					{
						rrmdir($dir . "/" . $object);
					} //filetype($dir . "/" . $object) == "dir"
					else
					{
						unlink($dir . "/" . $object);
					}
				} //$object != "." && $object != ".."
			} //$objects as $object
			reset($objects);
			rmdir($dir);
			$msg = drupal_set_message("Directory deleted successfully");
			return $msg;
		} //is_dir($dir)
		$msg = drupal_set_message("Directory not present");
		return $msg;
	} //$proposal_data->id == $prop_id
	else
	{
		$msg = drupal_set_message("Data not found");
		return $msg;
	}
}
function rrmdir($dir)
{
	if (is_dir($dir))
	{
		$objects = scandir($dir);
		foreach ($objects as $object)
		{
			if ($object != "." && $object != "..")
			{
				if (filetype($dir . "/" . $object) == "dir")
					rrmdir($dir . "/" . $object);
				else
					unlink($dir . "/" . $object);
			} //$object != "." && $object != ".."
		} //$objects as $object
		reset($objects);
		rmdir($dir);
	} //is_dir($dir)
}
function _dwsim_flowsheet_list_of_user_defined_compound($proposal_id)
{
	$data = "";
	//$query = db_select('dwsim_flowsheet_user_defined_compound');
	//$query->fields('dwsim_flowsheet_user_defined_compound');
	//$query->condition('proposal_id', $proposal_id, '=');
	//$query->orderBy('user_defined_compound', 'ASC');
	$user_defined_compound_list = db_query("SELECT * FROM dwsim_flowsheet_user_defined_compound WHERE proposal_id = :proposal_id", array(":proposal_id" => $proposal_id));
	$headers = array(
		"List of user defined compounds used in process flowsheet",
		"CAS No."
	);
	if($user_defined_compound_list){
	$rows = array();
	while ($row = $user_defined_compound_list->fetchObject())
	{
		$item = array(
			"{$row->user_defined_compound}",
			"{$row->cas_no}"
		);
		array_push($rows, $item);
	} //$row = $user_defined_compound_list->fetchObject()
	
	$data .= theme('table', array(
		'header' => $headers,
		'rows' => $rows
	));
	}else{
		$data .= "Not entered";
	}
	return $data;
}