-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathacm_school.module
executable file
·2956 lines (2646 loc) · 94.9 KB
/
acm_school.module
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
/*
* @file
*
* An educational institution. A school within Acadaman can be registered.
*
* Drupal implementation of school module
*/
define('COURSE_REGISTERED', TRUE);
define('COURSE_NOT_REGISTERED', FALSE);
/**
* Implements hook_menu
*/
function acm_school_menu() {
global $admission_application_info_label;
$modules = array('uni_school', 'nurspri_school', 'high_school', 'college_school');
$items = array();
// if variable_get(acm_instance, '') == 1, make this menu item available, else return 404
if(!variable_get('setup_step', 'done') && variable_get('acm_instance', 0)) {
$items['setup'] = array(
'title' => t('Setup Acadaman'),
'description' => t('Setup Acadaman for the first time'),
'page callback' => 'acm_school_setup',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
}
// @deprecated. /setup is used.
$items['schoolsetup'] = array(
'title' => t('Setup'),
'description' => t('School setup'),
'page callback' => 'drupal_get_form',
'page arguments' => array('acm_school_setup_user_form', 1), // function callback
'access arguments' => array('setup school'),
'access callback' => TRUE // user_access('setup school'). any hook_access works here
);
$items['setup/user/add'] = array(
'title' => t('Setup Acadaman - Add User'),
'description' => t('Add user(s)'),
'page callback' => 'drupal_get_form',
'page arguments' => 'acm_school_setup_user_form', // form id
'access arguments' => array(),
'type' => MENU_CALLBACK,
);
$items['setup/faculty/add'] = array(
'title' => t('Setup Acadaman - Add Faculty'),
'description' => t('Add faculty(s)'),
'page callback' => 'drupal_get_form',
'page arguments' => 'acm_school_setup_faculty_form', // form id
'access arguments' => array(),
'type' => MENU_CALLBACK,
);
// General settings for a school
$items['admin/settings/school'] = array(
'title' => t('School Settings'),
'description' => t('Acadaman school settings'),
'page callback' => 'acm_school_settings_callback',
//'access callback' => array('administer nodes'), // change to administer settings
'access arguments' => array('administer school settings'),
'type' => MENU_CALLBACK
);
// Settings for school admission
$items['admin/settings/school/admission/%'] = array(
'title' => t('Configure Admission'),
'description' => t('School admission settings'),
'page callback' => 'acm_school_settings_admission_callback',
'page arguments' => array(4),
'access arguments' => array('administer school settings'),
'type' => MENU_CALLBACK
);
// View current settings of admission
$items['admission'] = array(
'title' => t('Admission'),
'description' => t('Admission'),
'page callback' => 'acm_school_admission_view_callback',
'access arguments' => array('view admission'),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
// callback form for a student application
$items['admission/apply'] = array(
'title' => t('Application to [School name]'),
'description' => t('Student application for admission to a school'),
//'page callback' => 'acm_school_admission_application_callback',
'page callback' => 'acm_school_admission_form',
//'page arguments' => array('acm_school_admission_form'),
'access arguments' => array(), // create admission application - only anon has access
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
// profile edit
$items['admission/apply/%acm_school_profile/profile/edit'] = array(
'title' => 'Edit Profile',
//'title arguments' =>
'page callback' => 'acm_school_profile_edit',
'page arguments' => array(2),
'access callback' => TRUE, //'acm_school_profile_access',
'access arguments' => array(), //array(1),
'type' => MENU_CALLBACK,
//'load arguments' => array('%uid', '%index')
'load arguments' => array(2)
);
// profile edit urls for the rest of application labels as implemented
// by different modules
if($admission_application_info_label) {
foreach($admission_application_info_label as $key => $label) {
// remove profile. Already handled by admission/apply/%/profile/edit
if($key == 'profile') {
unset($label);
}
if($key == 'module') {
$module = $label;
}
// construct the rest of the menu items
//$items["admission/apply/%$module_admission_$key/%acm_school_profile/edit"] = array(
//);
}
}
// menu items for admission application Information
foreach(module_implements('admission_application_info') as $module) {
$info = module_invoke($module, 'admission_application_info');
foreach($info as $key => $value)
$items["admission/apply/%acm_school_profile/" . $value['title'] . "/edit"] = array(
'title' => 'Edit ' . $value['title'],
//'page callback' => "$module_admission_" . $value['title'] . 'edit',
'page callback' => $module . '_admission_' . $value['title'] . '_edit',
'page arguments' => array(2),
'access callback' => TRUE,
'access arguments' => array(),
'type' => MENU_CALLBACK,
'load arguments' => array(2)
);
}
/* $items["admission/apply/%acm_school_profile/course/edit"] = array(
'title' => 'Edit Course',
'page callback' => 'uni_school_admission_course_edit',
'page arguments' => array(2),
'access callback' => TRUE,
'access arguments' => array(),
'type' => MENU_CALLBACK,
'load arguments' => array(2)
);*/
// callback to the view of admission applications
$items['admission/applications'] = array(
'title' => t('Admission applications'),
'description' => t('List of applicant admission applications'),
'page callback' => 'acm_school_admission_applications_list_callback',
'access arguments' => array(''), // view admission applications
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
// Acadaman custom home
$items['front'] = array(
'title' => t('Welcome to Acadaman!'),
'description' => t('Acadaman dashboard'),
'page callback' => 'acm_school_frontpage_callback', // hook_dashboard
'access callback' => TRUE,
'access arguments' => array(), // access content
'type' => MENU_CALLBACK
);
// Details of a student application to a school
// A student application is her profile
// for student admission form @see admission/apply
$items['application'] = array(
'title' => t('MyApplication'),
'description' => t('Student application'),
'page callback' => 'acm_school_student_application_view_callback',
'access arguments' => array('view student application'),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
//$items['application/profile/edit'] = array(
//);
$items['courses'] = array(
'title' => t('Courses'),
'description' => t('Student course registration'),
'page callback' => 'acm_school_student_course_callback',
//'page arguments' => array(1),
'access arguments' => array('register course'), // see student module in 'student course'
'access callback' => TRUE,
//'load arguments' => array('%map'),
'type' => MENU_CALLBACK
);
if(acm_school_module_exists(array('uni_school', 'college_school'))) {
$items['programme/%acm_school_programme'] = array(
'title' => t(''),
'description' => t(''),
'page callback' => 'acm_school_programme_callback',
'page arguments' => array(1),
'access arguments' => array('view programme'),
'access callback' => TRUE,
'load arguments' => array('%map'),
'type' => MENU_CALLBACK
);
/*$items['course/%acm_school_course'] = array(
'title' => t('Course'),
'description' => t('Course'),
'page callback' => 'acm_school_course_callback',
'page arguments' => array(1),
'access arguments' => array('view course'),
'access callback' => TRUE,
'load arguments' => array('%map'),
'type' => MENU_CALLBACK
);*/
// student course register ajax callback
$items['courses/ajax/register'] = array(
'page callback' => 'student_course_register_ajax',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
// settings for course
$items['admin/settings/school/course/%'] = array(
'title' => t('Configure Course - %'),
'description' => t('Course settings'),
'page callback' => 'acm_school_settings_course_callback',
'page arguments' => array(4),
'access arguments' => array('administer course settings'),
'access callback' => TRUE,
'load arguments' => array('%map'),
'type' => MENU_CALLBACK
);
// settings for course
/*$items['admin/settings/school/course/configure/%'] = array(
'title' => t('Configure %'),
'description' => t('Course settings'),
'page callback' => 'acm_school_configure_course_callback',
'page arguments' => array(1),
'access arguments' => array('administer course settings'),
'type' => MENU_CALLBACK
);*/
// faculty view and features
$items['faculty/%acm_school_faculty'] = array(
'title' => t('Faculty'),
'description' => t('School Faculty'),
'page callback' => 'acm_school_faculty_view',
'page arguments' => array(1),
'access arguments' => array('view faculty'),
'access callback' => TRUE,
'load arguments' => array('%map'),
'type' => MENU_CALLBACK
);
// settings for faculty
$items['admin/settings/school/faculty/%'] = array(
'title' => t('Configure Faculty'),
'description' => t('School faculty settings'),
'page callback' => 'acm_school_settings_faculty_callback',
'page arguments' => array(4),
'access arguments' => array('administer faculty settings'),
'type' => MENU_CALLBACK
);
// The department of a student
$items['department/%'] = array(
'title' => t('Department'),
'description' => t('School Department'),
'page callback' => 'acm_school_department_view',
'page arguments' => array(1),
'access arguments' => array('view department'),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
// settings for department
$items['admin/settings/school/department/%'] = array(
'title' => t('Configure Department'),
'description' => t('School department settings'),
'page callback' => 'acm_school_settings_department_callback',
'page arguments' => array(4),
'access arguments' => array('administer department settings'),
'type' => MENU_CALLBACK
);
}
// programme settings
$items['admin/settings/school/programme/%'] = array(
'title' => t('Configure Programme'),
'description' => t('School programme settings'),
'page callback' => 'acm_school_settings_programme_callback',
'page arguments' => array(4),
'access arguments' => array('administer programme settings'),
'type' => MENU_CALLBACK
);
// grade view and features
$items['grade'] = array(
'title' => t('Grade'),
'description' => t('School Grade'),
'page callback' => 'acm_school_grade_view',
'access arguments' => array('view grade'),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
// General settings for grade
$items['admin/settings/school/grade/%'] = array(
'title' => t('Configure Grade'),
'description' => t('School grade settings'),
'page callback' => 'acm_school_settings_grade_callback',
'page arguments' => array(4),
'access arguments' => array('administer school settings'), // change to administer grade settiings
'type' => MENU_CALLBACK
);
$items['grade/ahah/grade-system/callback'] = array(
'page callback' => 'grade_system_dropdown_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
// Config to score a student
$items['admin/settings/school/score/%'] = array(
'title' => t('Score a student'),
'description' => t('Student score'),
'page callback' => 'acm_school_settings_score_callback',
'page arguments' => array(4),
'access arguments' => array('score a student'),
'type' => MENU_CALLBACK
);
$items['score/ahah/programme/callback'] = array(
'page callback' => 'score_programme_dropdown_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['score/ahah/course/callback'] = array(
'page callback' => 'score_course_dropdown_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
$items['score/ahah/score/callback'] = array(
'page callback' => 'acm_school_score_autotextfields_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
// fees view and features
$items['fees'] = array(
'title' => t('Fees'),
'description' => t('School Fees'),
'page callback' => 'acm_school_fees_view_callback',
'access arguments' => array('view fees'),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
// settings for fees
$items['admin/settings/school/fees'] = array(
'title' => t('Configure Fees'),
//'title arguments' => '',
'description' => t('School fees settings'),
'page callback' => 'acm_school_settings_fees_callback',
'access arguments' => array('administer fees settings'),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
$items['admin/settings/school/fees/%'] = array(
'title' => t('Configure Fees'),
//'title arguments' => '',
'description' => t('School fees settings'),
'page callback' => 'acm_school_settings_fees_callback',
'page arguments' => array(4),
'access arguments' => array('administer fees settings'),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
$items['admin/settings/school/fees/%/%/setup'] = array(
'title' => t('Setup Fees'),
'description' => t('Setup fees for the institution'),
'page callback' => 'acm_school_settings_fees_setup_callback',
'page arguments' => array(4,5),
'access arguments' => array('administer fees settings'),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
// General settings for users
$items['admin/settings/school/users'] = array(
);
// myapplication
// course
// department
// mygrades
// fees
// dorm
return $items;
}
/**
* Implements hook_perm
*
* @return array
*/
function acm_school_perm(){
return array(
'administer school settings','view admission','view faculty',
'administer faculty settings','administer department settings',
'view student application', 'view student applications', 'setup school',
'administer course settings', 'administer grade settings',
'administer fees settings', 'administer programme settings', 'register course', 'score a student'
);
}
/**
* Implements hook_acm_roles_perm
*
* Assigns permission(s) to role(s)
*
* @return array
*/
function acm_school_acm_roles_perm() {
return array(
'Staff' => 'administer school settings',
'Staff' => 'view admission',
'Staff' => 'administer faculty settings',
'Staff' => 'administer department settings',
'Staff' => 'administer grade settings',
'Staff' => 'administer course settings',
'Staff' => 'administer programme settings',
'Student' => 'view student application',
'Staff' => 'view student applications', // view all student applications
'Staff' => 'setup school',
'Student' => 'register course',
'Lecturer' => 'score a student'
);
}
/**
* Implements hook_acm_roles
*
* Defines default roles for the school module
*
* @return array
*/
function acm_school_acm_roles() {
// Available default roles for all school types
return array('Applicant', 'Student', 'Bursar', 'Supervisor', 'Cleaner', 'Student parent', 'Staff');
}
/**
* Menu callback to setup acadaman for the first time
*
* Handles the setup process to setup a school for the first time.
* Setup task items are:
* - add-user
*/
function acm_school_setup() {
global $base_url;
// module_invoke hook_acm_setup_form
/*foreach(module_implements('acm_setup_form') as $module) {
// lists = module_invoke('setup_steps_list');
}*/
// the first hook defines the steps wc contains the form ids
// and inside it, it also registers another hook, that keeps tab of the implementation of the steps
// setup_steps_list
//
// setup_steps($step) // called inside setup_step_list. Alternatively, we can just get everything done inside setup_steps
if(!isset($_GET['step']) | empty($_GET['step'])) {
$step = 'add-user';
$output = drupal_get_form('acm_school_setup_user_form');
}
// this is always called
if(isset($_GET['step']) && !in_array($_GET['step'], acm_school_reserved_steps())) {
foreach(module_implements('setup_tasks') as $module) {
$output = module_invoke($module, 'setup_tasks');
}
}
if($_GET['step'] == 'finished') {
$output = '<p>' . t('Your school has been setup successfully') . '</p>';
$output .= '<p>' . t('Please visit the @admin to configure other school settings.', array('@admin' => l('school settings page', $base_url . '/admin/settings/school'))) . '</p>';
$step = 'done';
variable_set('setup_step', 'done');
variable_set('acm_instance', 1);
// @todo remove /setup from menu_router
}
return $output;
}
/**
* Form callback to setup user.
*
* Adds the Acadaman user and assigns the staff role. This user
* is the admin user for this Acadaman instance.
*
* The super-user (uid 1) account is kept with Acadaman for remote
* administration purposes.
*
* @todo Add clearer docs
*/
function acm_school_setup_user_form(&$form_state) {
$form['#attributes'] = array('class' => 'form-horizontal');
$form['username'] = array(
'#type' => 'textfield',
'#title' => 'Username',
//'#required' => TRUE
);
$form['password'] = array(
);
$form['email'] = array();
$form['role'] = array();
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save and continue'),
//'#weight' => 15,
);
//watchdog('setup', 'url is @url', array('@url' => $url));
//$form['#action'] = $url;
//$form['#redirect'] = FALSE;
// Allow the profile to alter this form. $form_state isn't available
// here, but to conform to the hook_form_alter() signature, we pass
// an empty array.
/*$hook_form_alter = $_GET['profile'] .'_form_alter';
if (function_exists($hook_form_alter)) {
$hook_form_alter($form, array(), 'install_configure');
}*/
return $form;
}
/**
* acm_school_setup_user_form submit callback
* @param type $form
* @param type $form_state
*/
function acm_school_setup_user_form_submit($form, $form_state) {
// if validation is successful
// make sure this form id is removed from $form['setup']
drupal_goto('setup', 'step=setup');
}
/**
* A list of setup steps
*
* @deprecated @see acm_school_setup
*/
function acm_school_steps_list($active = NULL) {
$steps = array('setup-user' => t('Add User'));
// Add steps defined by other modules hook_steps_list implementation.
foreach(module_implements('steps_list') as $module) {
$result = module_invoke($module, 'steps_list');
}
if(is_array($result)) {
$steps += $result;
}
// Add finished step as the last task.
$steps += array('finished');
// Let the theming function know that 'finished' and 'done'
// include everything, so every step is completed.
if (in_array($active, array('finished', 'done'))) {
$active = NULL;
}
}
/**
* called in setup() to verify setup
* if step == finished or done, redirect to dashboard
*
* @deprecated @see acm_school_setup
*/
function verify_setup() {
// Read the variable manually using the @ so we don't trigger an error if it fails.
$result = @db_query("SELECT value FROM {variable} WHERE name = '%s'", 'install_step');
if ($result) {
return unserialize(db_result($result));
}
}
/**
* The list of reserved tasks to run in the installer.
*/
function acm_school_reserved_steps() {
//return array('setup', 'setup-user', 'setup-finished', 'finished', 'done');
return array('finished', 'done');
}
/**
* Menu callback for /acadaman
*/
function acm_school_frontpage_callback() {
if(!user_is_logged_in()) {
variable_set('site_frontpage', 'user/login');
drupal_goto();
}
foreach(module_implements('acm_dashboard') as $module) {
variable_set('site_frontpage', 'front');
return module_invoke($module, 'acm_dashboard');
}
}
/**
* Implements hook_acm_dashboard
*
* @todo Implement activity stream for the dashboard in an IFrame
*/
function acm_school_acm_dashboard() {
global $user;
drupal_set_title('Welcome to Acadaman!');
//(array)$user->profile = acm_school_profile_load($user->uid);
$content = array('name' => 'Dashboard');
//$content['profile'] = $user->profile;
//dsm($user->profile);
$content['profile_card'] = theme('profile_card', $user->profile);
$updates = array(t('Updates'));
//$content['updates'] = theme('updates', $updates);
$content['updates'] = t('Updates');
//$title = 'Dashboard';
// common dashboard not dependent on role type
//return theme('item_list', $items, $title);
return theme('acm_dashboard', $content);
}
/**
* @see acm_school_theme
*/
function theme_profile_card($profile) {
$picture = theme('profile_picture', $profile['picture']);
$fullnames = theme('fullnames', $profile);
$output = "<div>$picture $fullnames</div>";
return $output;
}
/**
* Theme user fullnames
*
* @see acm_school_theme
*/
function theme_fullnames($profile) {
$firstname = $profile['firstname'];
$lastname = $profile['lastname'];
$fullnames = implode(' ', array($firstname, $lastname));
return "<h3>$fullnames</h3>";
}
/**
* Theme user profile picture
*
* @see acm_school_theme
*/
function theme_profile_picture($profile) {
$picture = $profile['picture'];
return theme('image', $picture);
}
function theme_updates($updates) {
}
/**
* Implements hook_FORM_ID_alter
*/
function acm_school_form_user_login_alter(&$form, $form_state) {
// Ensure a valid submit array.
$form['#submit'] = is_array($form['#submit']) ? $form['#submit'] : array();
// Replace core's registration function with custom registration function.
// Put the custom submit handler first, so other submit handlers have a valid
// user to work with upon registration.
$key = array_search('user_login_submit', $form['#submit']);
if ($key !== FALSE) {
unset($form['#submit'][$key]);
}
array_unshift($form['#submit'], 'acm_school_user_login_submit');
}
/**
* Submit callback to login a user.
*
* @see acm_school_form_user_login_alter
*/
function acm_school_user_login_submit($form, &$form_state) {
global $user;
// if variable_get('acm_instance', 1) == 1 // set by drush during install
// redirect to /setup
// return;
// else
//if (variable_get('acm_instance', '') == TRUE && $user->uid) {// the eduerp admin
if(variable_get('acm_instance', 0) && $user->uid) {
watchdog('login', 'logged in user has access and logs in successfully');
$form_state['redirect'] = 'setup';
return;
} else {
if ($user->uid) {
// set instance variable to 0 after completion of the post-install steps
variable_set('site_frontpage', 'front');
//$form_state['redirect'] = 'user/'. $user->uid; // /acadaman (the dashboard)
$form_state['redirect'] = '';
return;
}
}
}
/**
* Implements hook_FORM_ID_alter
*/
function acm_school_form_search_theme_form_alter(&$form, $form_state) {
$form['search_theme_form']['#title'] = '';
$form['search_theme_form']['#attributes'] = array('class' => 'span3');
$form['submit']['#attributes'] = array('class' => 'hidden');
}
/**
* Implements hook_theme
*/
function acm_school_theme() {
$template_path = array('path' => drupal_get_path('module', 'acm_school') . '/templates');
$theme = array(
'course' => array(
'arguments' => array('node' => NULL, 'course' => NULL),
//'template' => 'course',
),
'acm_dashboard' => $template_path + array(
'arguments' => array('content' => NULL),
'template' => 'acm_dashboard', // acm_dashboard is implemented as template hook. To implement as function, remove this line
),
'school_settings' => $template_path + array(
'arguments' => array('school_settings' => NULL),
'template' => 'school_settings',
),
'faculty_view' => $template_path + array(
'arguments' => array('faculty' => NULL),
'template' => 'faculty'
),
'department_view' => $template_path + array(
'arguments' => array('department' => NULL),
'template' => 'department'
),
'grade_view' => array(
'arguments' => array('grade' => NULL),
//'template' => 'grade'
),
'fees_view' => $template_path + array(
'arguments' => array('fees' => NULL),
'template' => 'fees'
),
'fees_item_list' => array(
'arguments' => array('view' => NULL)
),
'admission_view' => $template_path + array(
'arguments' => array('admission' => NULL),
'template' => 'admission'
),
'student_application' => array( // student application
'arguments' => array('student_application' => NULL),
//'template' => 'student_application'
),
'student_course' => array(
'arguments' => array('student_course' => NULL)
),
'admission_applications' => array(
'arguments' => array('admission_applications' => NULL),
),
'profile_picture' => array(
'arguments' => array('profile' => NULL)
),
'fullnames' => array(
'arguments' => array('profile' => NULL)
),
'profile_card' => array(
'arguments' => array('profile' => NULL)
),
'updates' => array(
'arguments' => array('updates' => NULL)
),
'student_profile_form' => array(
'arguments' => array('form' => NULL)
),
);
return $theme;
}
/**
* Implements hook_acm_school_info
*/
function acm_school_acm_school_info() {
}
/**
* Implements hook_acm_school_profile
*/
function acm_school_acm_school_profile() {
}
/**
* Implements hook_acm_school_analytics
*/
function acm_school_acm_school_analytics() {
}
/**
* Implements hook_acm_studentprofile
*
* A student profile is contained in student application
*/
function acm_school_acm_studentprofile($profile) {
return drupal_get_form("acm_school_student_profile_form", $profile, NULL);
}
/**
* Form callback handler for student profile form
*
* @see acm_school_acm_studentprofile
*/
function acm_school_student_profile_form(&$form_state, $profile, $steps_order, $hook = 'profile') {
$edit = (empty($form_state['values'])) ? (array)$profile : $form_state['values'];
$form['#attributes'] = array('class' => 'form-horizontal');
$form['basic'] = array(
'#type' => 'markup',
'#value' => '<div style="background:#f6f6f2; padding:5px">Basic Information</div>',
'#weight' => -30
);
$form['firstname'] = array(
'#type' => 'textfield',
'#title' => t('First name'),
'#default_value' => $edit['firstname'],
'#required' => TRUE,
/*'#prefix' => '<div class="controls">',
'#suffix' => '</div>'*/
'#weight' => -29
);
$form['lastname'] = array(
'#type' => 'textfield',
'#title' => t('Last name'),
'#default_value' => $edit['lastname'],
'#required' => TRUE,
'#weight' => -28
);
$form['other'] = array(
'#type' => 'textfield',
'#title' => t('Other'),
'#default_value' => $edit['other'],
'#weight' => -27
);
$form['email'] = array(
'#type' => 'textfield',
'#title' => t('Email'),
'#default_value' => $edit['email'],
'#required' => TRUE,
'#weight' => -26
);
$gender = array('M' => 'M', 'F' => 'F');
$form['gender'] = array(
'#type' => 'select',
'#title' => t('Gender'),
'#options' => $gender,
'#default_value' => $edit['gender'],
'#required' => TRUE,
'#weight' => -25
);
// add dob here. YYYY-MM-DD
// stored as timestamp, converted to individual date
// elements on retrieval @see date()
$form['phone'] = array(
'#type' => 'textfield',
'#title' => t('Phone'),
'#default_value' => $edit['phone'],
'#weight' => -24
);
$form['mobile'] = array(
'#type' => 'textfield',
'#title' => t('Mobile'),
'#default_value' => $edit['mobile'],
);
$form['maritalstatus'] = array(
'#type' => 'select',
'#title' => t('Marital status'),
'#options' => MaritalStatus::listMaritalStatus(),
'#default_value' => $edit['maritalstatus'],
'#required' => TRUE,
);
$form['nationality'] = array(
'#type' => 'select',
'#title' => t('Nationality'),
'#default_value' => $edit['nationality'],
'#options' => array(0 => 'Other'), // LocationCountry::listLocationCountry()
//'#required' => TRUE,
);
$form['state'] = array(
'#type' => 'select',
'#title' => t('State'),
'#options' => array(0 => 'Other'), // LocationState::listLocationState()
'#default_value' => $edit['state'],
'#required' => TRUE,
);
$form['city'] = array(
'#type' => 'textfield',
'#title' => t('City'),
'#default_value' => $edit['city'],
);
$form['postalcode'] = array(
'#type' => 'textfield',
'#title' => t('Postal or zip code'),
'#default_value' => $edit['postalcode'],
'#required' => TRUE
);
$form['lga'] = array( // Only applicable to British colonized countries
'#type' => 'select',
'#title' => t('LGA'),
'#options' => array(0 => 'Other'), // LocationLga::listLocationLga()
'#default_value' => $edit['lga'],
);
$form['religion'] = array(
'#type' => 'select',
'#title' => t('Religion'),
'#options' => array(0 => 'Other'),
'#default_value' => $edit['religion'],
);
$form['address1'] = array(
'#type' => 'textfield',
'#title' => t('Address1'),
'#default_value' => $edit['address1'],
'#required' => TRUE,
);
$form['address2'] = array(
'#type' => 'textfield',
'#title' => t('Address2'),
'#default_value' => $edit['address2'],
);
$form['picture'] = array(
'#type' => 'file',
'#title' => t('Photo'),
'#default_value' => $edit['picture'],
'#description' => t('upload a photo'),
);
$form['signature'] = array(
'#type' => 'file',
'#title' => t('Signature'),
'#default_value' => $edit['signature'],
'#description' => t('upload your signature'),
);
if(!isset($profile['profile_state'])) { // change to !isset($edit)
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save and continue',
'#attributes' => array('class' => 'btn'),
);
} else {
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save',
'#attributes' => array('class' => 'btn'),
);
}
// use of _ and setting of it's value as a form element automatically
// places this in form_state['values'] for easy access in submit and
// validate functions
$form['_current'] = array('#type' => 'value', '#value' => $hook);
$form['_steps'] = array('#type' => 'value', '#value' => $steps_order);
//$form['_profile'] = array('#type' => 'value', '#value' => $profile);
$form['_profile'] = array('#type' => 'value', '#value' => $edit);
$form['#theme'] = array('acm_school_student_profile_form', 'student_profile_form');
return $form;
}
/**
* Submit callback for adding or updating a profile
*
* @param type $form
* @param type $form_state
*/
function acm_school_student_profile_form_submit($form, &$form_state) {
$profile = $form_state['values']['_profile'];
$steps = $form_state['values']['_steps'];
$current = $form_state['values']['_current'];
$email = $form_state['values']['email'];
dsm($form_state['values']);
/*$maritalstatus = Utils::array_value_given_key($form_state['values']['maritalstatus'], MaritalStatus::listMaritalStatus());
$form_state['values']['maritalstatus'] = $maritalstatus;
$gender = Utils::array_value_given_key($form_state['values']['gender'], array(1 => 'M', 2 => 'F'));
$form_state['values']['gender'] = $gender;*/
if($current == 'profile') {
//$next = current($steps);
$next = current($current);
}else if(!next($steps)) {
$next = next($steps);
}