/
departments.php
1930 lines (1673 loc) · 66.3 KB
/
departments.php
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
//*****
//Contains functions that create department-specific features
//Features include student profile modifications, course taxonomy terms
//*****
//include other classes
require_once('classes/wp-admin-menu-classes.php'); //allows us to modify the order of admin menus
//***WP Hooks
//Add user profile w WP hooks
//add_action('signup_extra_fields', 'add_custom_signup_fields');
add_action( 'show_user_profile', 'add_custom_user_profile_fields' );
add_action( 'edit_user_profile', 'add_custom_user_profile_fields' );
add_action( 'personal_options_update', 'save_custom_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_custom_user_profile_fields' );
//Hook for adding custom post and taxonomies
add_action('init', 'setup_custom_tax');
add_filter( 'wp_page_menu', 'custom_page_menu' ,10,2 ); //adds custom posts to nav menu
//adds help bubble for taxonomy meta-block
add_action( "admin_head-post-new.php", 'meta_box_instruction' ); //new post
add_action( "admin_head-post.php", 'meta_box_instruction' ); //edit post
//Add network admin screen for departments
add_action('network_admin_menu', 'control_dept_info');
add_action('wp_ajax_set_default_dept', 'set_default_dept_ajax' );
//Setup department taxonomy settings page
add_action('wp_ajax_tax_select_dept', 'tax_select_dept_ajax');
add_action('wp_ajax_tax_show_terms', 'tax_show_terms_ajax');
add_action('wp_ajax_tax_add_tax', 'tax_add_tax_ajax');
add_action('wp_ajax_tax_edit_tax', 'tax_edit_tax_ajax');
add_action('wp_ajax_tax_delete_tax', 'tax_delete_tax_ajax');
add_action('wp_ajax_tax_add_term', 'tax_add_term_ajax');
add_action('wp_ajax_tax_edit_term', 'tax_edit_term_ajax');
add_action('wp_ajax_tax_delete_term', 'tax_delete_term_ajax');
add_action('wp_ajax_tax_add_posttype', 'tax_add_posttype_ajax');
add_action('wp_ajax_tax_edit_posttype', 'tax_edit_posttype_ajax');
add_action('wp_ajax_tax_delete_posttype', 'tax_delete_posttype_ajax');
//Setup department courses settings pages
add_action('wp_ajax_add_dept_submit', 'add_dept_save_ajax' );
add_action('wp_ajax_add_course_select_dept', 'add_course_deptselect');
add_action('wp_ajax_add_course_submit', 'add_course_save_ajax');
add_action('wp_ajax_add_course_delete', 'add_course_delete_ajax');
//Setup department evaluation settings pages ajax
add_action('wp_ajax_eval_select_dept', 'eval_select_dept');
add_action('wp_ajax_eval_add_section', 'eval_add_section');
add_action('wp_ajax_eval_edit_section', 'eval_edit_section');
add_action('wp_ajax_eval_delete_section', 'eval_delete_section');
add_action('wp_ajax_eval_show_questions', 'eval_show_questions');
add_action('wp_ajax_eval_add_question', 'eval_add_question');
add_action('wp_ajax_eval_edit_question', 'eval_edit_question');
add_action('wp_ajax_eval_delete_question', 'eval_delete_question');
//***Functions
//function to unregister a custom post type
//not used yet = could be used for RAGS as they have custom post types
function unregister_post_type( $post_type, $slug = '' ){
global $wp_post_types;
if ( isset( $wp_post_types[ $post_type ] ) ) {
unset( $wp_post_types[ $post_type ] );
$slug = ( !$slug ) ? 'edit.php?post_type=' . $post_type : $slug;
remove_menu_page( $slug );
}
}
//add in custom user profile fields in profile page
function add_custom_user_profile_fields( $user ) {
global $wpdb;
//$wpdb->flush();
$major = get_user_major(); //get_user_major($user->id);
$depts = get_depts();
?>
<h3><?php _e('Student Information', 'your_textdomain'); ?></h3>
<table class="form-table">
<tr>
<th>
<label for="major"><?php _e('Major', 'your_textdomain'); ?>
</label></th>
<td>
<select name="major" id="major">
<option>---</option>
<?php
foreach ($depts as $dept) {
if($major == $dept->id) echo "<option value='$dept->id' selected='selected'>$dept->name</option>";
else echo "<option value='$dept->id'>$dept->name</option>";
}
?>
</select>
<span class="description"><?php _e('Select your major.', 'your_textdomain'); insert_help('choose_major'); ?></span>
</td>
</tr>
</table>
<?php }
//save custom user profile fields
function save_custom_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) return FALSE;
//change user meta field
update_usermeta( $user_id, 'major', $_POST['major'] ); //included for professors so we can add them into blogs as users - they have to be a usermeta since they don't have portfolios
update_option('student_major', $_POST['major']);
replace_course_terms($user_id);
setup_custom_tax();
//used to enable new post types
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
//add in custom user profile fields in signup page
function add_custom_signup_fields() {
/*commented out - can't figure out how to save fields on registration submit
$major = get_user_major($user->id);
$depts = get_depts();
?>
<label for="major"><?php _e('Major', 'your_textdomain'); ?></label>
<select name="major" id="major">
<?php
foreach ($depts as $dept) {
if($major == $dept->id) echo "<option value='$dept->id' selected='selected'>$dept->name</option>";
else echo "<option value='$dept->id'>$dept->name</option>";
}
?>
</select>
<span class="description"><?php _e('Select your major.', 'your_textdomain'); ?></span>
<?php
*/
}
//function to rewrite course taxonomy terms based on major
function replace_course_terms($user_id) {
$major = get_user_major(); //replaced by site option($user_id);
//delete ALL course taxonomy terms
$courses_terms = get_terms( 'courses', array('hide_empty'=>'0') );
foreach($courses_terms as $term) {
wp_delete_term( $term->term_id, 'courses' );
}
$courses = get_courses($major);
//loop through the $all_courses array, adding each as a new term
foreach ($courses as $a_course) {
wp_insert_term(
$a_course->number, // the term
'courses', // the taxonomy (hard-coded to courses taxonomy)
array(
'description'=> $a_course->title,
'slug' => strtolower($a_course->number)
//'parent'=> $parent_term_id
)
);
}
}
function setup_custom_tax() {
$user_id = get_current_user_id();
$major = get_user_major(); //($user_id);
$depts = get_depts();
foreach($depts as $dept) {
if ($major == $dept->id) $major_abbr = $dept->abbr;
}
switch ($major_abbr) {
case 'RATS':
setup_rats_student();
break;
}
//get taxes from database, add to all post types
$taxes_arr = get_taxes($major);
foreach($taxes_arr as $t) {
$taxes[$t->id]['slug'] = $t->tax_slug;
$taxes[$t->id]['settings'] = $t->tax_settings;
$taxes[$t->id]['terms'] = get_tax_terms($t->id);
}
$post_types = get_post_types();
unset($post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item']);
//create custom post types
$pid = get_posttypes_id($major);
if ($pid) {
$reserved_posts = array('post', 'page','attachment','revision','nav_menu_item');
$slug = strtolower(str_replace(' ', '_', $taxes[$pid]['slug']));
$existing_taxes = get_taxonomies();
$default_settings = array('public' => true, 'label' => $taxes[$pid]['slug'], 'capability_type' => 'page', 'hierarchical' => true, 'taxonomies' => $existing_taxes );
if ( !in_array($slug, $reserved_posts) ) { // make sure we're not trying to add a reserved post type
foreach($taxes[$pid]['terms'] as $p) {
if(strlen($p->term_settings)) {
$settings_arr = explode("\ndefault_content=", $p->term_settings, 2);
$saved_settings = array();
$settings_temp = explode("\n", $settings_arr[0]);
foreach($settings_temp as $st) {
$tmp = explode("=", $st, 2);
$tmp[1] = str_replace(', ', ',', $tmp[1]);
if(strpos($tmp[1], ',')) $tmp[1] = explode(',', $tmp[1]);
$saved_settings[ $tmp[0] ] = $tmp[1];
}
$settings = array_merge($default_settings, $saved_settings);
} else $settings = $default_settings;
if(!isset($settings['label'])) $settings['label'] = str_replace(' ', '_', $p->term_slug);
register_post_type(
strtolower(str_replace(' ', '_', $p->term_slug)), //post type slug
$settings //settings
);
//add default content filter
add_filter( 'default_content', 'seu_posts_default_content', 10, 2 );
}
}
}
//create taxonomies
foreach($taxes as $tax) {
if( strtolower($tax['slug']) != 'posts' ) {
$slug = strtolower(str_replace(' ', '_', $tax['slug']));
$default_settings = array(
'post_types' => $post_types,
'args' => array('label'=>$slug, 'rewrite'=>array('slug'=>$slug), 'show_admin_column'=> true)
);
$settings = array();
$saved_settings = array();
$settings_temp = explode("\n", $tax['settings']);
foreach($settings_temp as $st) {
$tmp = explode("=", $st, 2);
$tmp[1] = str_replace(', ', ',', $tmp[1]);
if(strpos($tmp[1], ',')) $tmp[1] = explode(',', $tmp[1]);
$saved_settings[ $tmp[0] ] = $tmp[1];
}
if(isset($saved_settings['post_types']))
$settings['post_types'] = $saved_settings['post_types'];
else
$settings['post_types'] = $default_settings['post_types'];
unset($saved_settings['post_types']);
$settings['args'] = array_merge($default_settings['args'], $saved_settings);
register_taxonomy(
$slug,
$settings['post_types'],
$settings['args']
);
foreach($tax['terms'] as $term) {
$term_slug = strtolower(str_replace(' ', '_', $term->term_slug));
$default_settings = array('slug'=>$term_slug, 'description'=>$term_slug);
$settings = array();
$saved_settings = array();
$settings_temp = explode("\n", $term->term_settings);
foreach($settings_temp as $st) {
$tmp = explode("=", $st, 2);
$tmp[1] = str_replace(', ', ',', $tmp[1]);
if(strpos($tmp[1], ',')) $tmp[1] = explode(',', $tmp[1]);
$saved_settings[ $tmp[0] ] = $tmp[1];
}
$settings = array_merge($default_settings, $saved_settings);
if( !term_exists($term_slug, $slug) ) {
wp_insert_term(
$term_slug, // the term
$slug, // the taxonomy
$settings // the settings
);
} //if
} //foreach
} //if
} //foreach
} //function
function seu_posts_default_content() {
$major = get_user_major();
$pid = get_posttypes_id($major);
$posttypes = get_tax_terms($pid);
foreach($posttypes as $ptype) {
$pslug = strtolower( str_replace(' ', '_', $ptype->term_slug) );
if($pslug == $_GET['post_type']) {
$settings_arr = explode("\ndefault_content=", $ptype->term_settings, 2);
return stripslashes( urldecode($settings_arr[1]) );
}
}
}
function setup_rats_student() {
//adds in features that are custom for RATS students
//Create Personal Statements post type
register_post_type( 'personal_statement',
array('labels' => array('name' => __( 'Personal Statements' ),'singular_name' => __( 'Personal Statement' ), 'add_new_item' => __('Add new Personal Statement') ),
'description' => 'Your written statement of who you are academically.',
'public' => true,
'has_archive' => true,
'menu_position' => 6,
'capability_type' => 'page',
'show_in_nav_menus' => true,
'hierarchical' => true
)
);
//Create Classroom Experiences post type
register_post_type( 'classroom',
array('labels' => array('name' => __( 'Classroom Experiences' ), 'singular_name' => __( 'Classroom Experience' ), 'add_new_item' => __('Add new Classroom Experience') ),
'description' => 'A post that describes what you learned in a particular class',
'public' => true,
'has_archive' => true,
'menu_position' => 7,
'capability_type' => 'post',
'show_in_nav_menus' => true,
'taxonomies' => array('rats_outcomes', 'courses'),
'hierarchical' => false
)
);
//Create Related Life Experiences post type
register_post_type( 'related_life',
array('labels' => array('name' => __( 'Related Life Experiences' ),'singular_name' => __( 'Related Experience' ), 'add_new_item' => __('Add new Life Experience') ),
'description' => 'A post that describes a life experience you had that is related to your learning. An example would be a school-sponsored mission trip.',
'public' => true,
'has_archive' => true,
'menu_position' => 8,
'capability_type' => 'post',
'show_in_nav_menus' => true,
'taxonomies' => array('rats_outcomes'),
'hierarchical' => false
)
);
//Create Resume post type
register_post_type( 'resume',
array('labels' => array('name' => __( 'Resumes' ),'singular_name' => __( 'Resume' ), 'add_new_item' => __('Add new Resume') ),
'description' => 'Your current resume or curriculum vita.',
'public' => true,
'has_archive' => true,
'menu_position' => 5,
'capability_type' => 'page',
'show_in_nav_menus' => true,
'hierarchical' => true
)
);
//order the admin menus
add_action('admin_menu','order_admin_menu');
//sets up the default content for the 2 custom post types
add_filter( 'default_content', 'rats_default_content', 10, 2 );
}
function order_admin_menu() {
//reorders the left menu in admin screen for the new post types
global $menu;
swap_admin_menu_sections('Posts', 'Resumes');
}
function custom_page_menu($menu, $args) {
//adds the custom posts to the default nav menu
// get supplied args
$list_args = $args;
// Overide some menu settings
$list_args['echo'] = false;
$list_args['title_li'] = '';
$list_args['show_home'] = false;
$list_args['exclude'] = 4; // excluding the homepage as I am manually adding it to the start below
// get the current page object as we will need to refer to it when setting current items below
global $wp_query;
$current_page = $wp_query->get_queried_object();
// Show Home item at the start of the menu
$menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '" title="' . esc_attr(__('Home')) . '">' . $args['link_before'] . __('Home') . $args['link_after'] . '</a></li>';
// Now add the normal page collection which belongs in the nav
$list_args['post_type'] = 'page';
$menu .= wp_list_pages($list_args) ;
// Loop through the custom post types HIERARCHICAL and add them to the menu
$pages_args = array('public'=>true, '_builtin'=>false, 'hierarchical'=>true);
$pages = get_post_types($pages_args, 'objects');
//sort the pages array by menu_order
$sorter=array();
$ret=array();
reset($pages);
foreach ($pages as $page) {
$sorter[$page->rewrite['slug']] = $page->menu_position;
}
asort($sorter);
foreach ($sorter as $ii => $va) {
foreach ($pages as $pt) {
if($pt->rewrite['slug'] == $ii) $ret[]=$pt;
}
}
$pages=$ret;
foreach($pages as $obj_pt) {
$list_args['post_type'] = $obj_pt->rewrite['slug'];
$menu .= wp_list_pages($list_args); //this does not allow ordering of menu items - it goes by date descending
}
// Loop through the custom post types NOT HIERARCHICAL and add them to the menu
$posts_args = array('public'=>true, '_builtin'=>false, 'hierarchical'=>false);
$posts = get_post_types($posts_args, 'objects');
//sort the posts array by menu_order
$sorter=array();
$ret=array();
reset($posts);
foreach ($posts as $post) {
$sorter[$post->rewrite['slug']] = $post->menu_position;
}
asort($sorter);
foreach ($sorter as $ii => $va) {
foreach ($posts as $pt) {
if($pt->rewrite['slug'] == $ii) $ret[]=$pt;
}
}
$posts=$ret;
foreach($posts as $obj_pt) {
$submenu = '';
$list_args['post_type'] = $obj_pt->rewrite['slug'];
$the_query = new WP_Query( 'post_type='.$obj_pt->rewrite['slug'] );
//show main link if there are any posts of that type
if ($the_query->have_posts() )
$menu .= '<li><a href="' .home_url( '/' ) . $obj_pt->rewrite['slug'] . '/">' . $obj_pt->labels->name . '</a><ul>';
// The Loop - add in all posts of that type
while ( $the_query->have_posts() ) : $the_query->the_post();
$submenu .= '<li><a href="' .get_permalink() .'">' .get_the_title() .'</a></li>';
endwhile;
$menu .= $submenu;
// Reset Post Data
wp_reset_postdata();
$menu .= '</ul></li>';
}
// glue the menu together and send back
if ( $menu )
$menu = '<ul>' . $menu . '</ul>';
$menu = '<div>' . $menu . "</div>\n";
return $menu;
}
function rats_default_content( $content, $post ) {
//sets up the default content for the custom RATS post types
switch( $post->post_type ) {
case 'resume':
$content = "<p>Include your current resume or curriculum vita on this page.</p>
<p>You can either type your resume into this textbox as an html document or insert a Word/PDF version using Scribd.
<br>If you want to insert a Word or PDF version, use the <em>Upload/Insert -> From Scribd</em> feature directly above this textbox.</p>";
break;
case 'personal_statement':
$content = "<p>At the minimum, you must include the personal statement you write as a Senior. Either copy and paste the content or use the <em>Upload/Insert -> From Scribd</em> feature directly <em>above</em> this textbox.</p>
<p>You may also want to include the personal statement that you wrote as a Freshman in the Methods course.</p>
<p>You should probably only show this page to professors. <strong>Deny</strong> the World and <strong>Allow</strong> professors in the radio buttons directly <em>below</em> this post.";
break;
case 'classroom':
$content = "Course title: <br>
Instructor: <br>
School: <br>
Semester: <hr>
<ol>
<li>Mark the learning outcomes and course in the boxes to the right.</li>
<li>Inside this text box, type a brief description of the course, its major units, and how performance was measured (e.g. exams, papers, presentations).</li>
<li>Inside this text box, write a brief narrative that explains what material you examined and what you learned that allowed you to fulfill the learning outcomes you marked.</li>
<li>Inside this text box, clearly describe how your performance was measured in the course. Include any papers, tests, and other documents that demonstrate what you learned in this class. Insert these documents using the Add Media → Insert Document feature directly above this text box.</li></ol>";
break;
case 'related_life':
$content = "Concise description of the activity:<br>
Dates<br>
From: To: <hr>
<ol>
<li>Mark the learning outcomes in the box to the right.</li>
<li>Inside this text box, type a brief description of the life experience.</li>
<li>Inside this text box, write a brief narrative that explains what you learned that allowed you to fulfill the learning outcomes you marked.</li>
<li>Include any papers, tests, and other documents that demonstrate what you learned in this class. Insert these documents using the Add Media → Insert Document feature directly above this text box.</li></ol>";
break;
}
return $content;
}
function meta_box_instruction($d) {
//adds help bubble to meta-boxes in new post pages
global $post;
foreach(get_object_taxonomies($post->post_type) as $tax) {
switch ($tax) {
case 'rats_outcomes':
$help_key = 'rats_outcomes';
$help = str_replace("\n", "\\\n", return_help($help_key));
echo "<script type='text/javascript'>
jQuery(document).ready(function(){
jQuery('#rats_outcomes-tabs').append(\"" .$help ."\");
});</script>";
break;
case 'courses':
$help_key = 'mark_courses';
$help = str_replace("\n", "\\\n", return_help($help_key));
echo "<script type='text/javascript'>
jQuery(document).ready(function(){
jQuery('#courses-tabs').append(\"" .$help ."\");
});</script>";
break;
}
}
}
function control_dept_info() {
add_menu_page('SEUFolios Departments', 'Departments', 'manage_options', 'seufolios_departments', 'control_dept_options','' , 21);
add_submenu_page( 'seufolios_departments', 'Department Taxonomies', 'Taxonomies', 'manage_options', 'seufolios_departments_taxes', 'control_tax_list' );
add_submenu_page( 'seufolios_departments', 'Department Evaluations', 'Evaluations', 'manage_options', 'seufolios_departments_evaluations', 'control_evaluation_questions');
}
function control_dept_options() {
//creates the dept network admin page
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
?>
<style>
table.seufolios {
border-spacing:0;
}
table.seufolios th, table.seufolios td {
text-align:left;
padding-right:2em;
}
table.seufolios tr:nth-child(even) {
background-color: #EEE;
}
</style>
<div class="wrap">
<h2>Current Departments</h2>
<div id="dept_body">
<table class="seufolios">
<tr><th>Abbr</th><th>Name</th></tr>
<?php
$depts = get_depts();
foreach($depts as $dept) {
echo "<tr><td>$dept->abbr</td><td>$dept->name</td></tr>\n";
}
?>
</table>
</div>
<div id="dept_form">
<h2>Add New Department</h2>
<form name="add_new" id="add_new" method="POST">
<label for="new_abbr">Dept. Abbreviation</label> <input type="text" name="new_abbr" maxlength="4">
<label for="new_title">Dept. Title</label> <input type="text" name="new_title" >
<br><br>
<input type="submit" value="Add Department" />
</form>
</div>
<div id="default_dept_container">
<h2>Set Default Department</h2>
<p>What department should students be included in by default?<br>
Students may override this in their user profile settings.</p>
<form name="set_default_dept" id="set_default_dept" method="POST">
<select name="default_dept" id="default_dept">
<option>---</option>
<?php
$depts = get_depts();
$current_default = get_site_option('seu_default_dept_id');
foreach ($depts as $dept) {
if($current_default == $dept->id) echo "<option value='$dept->id' selected='selected'>$dept->name</option>";
else echo "<option value='$dept->id'>$dept->name</option>";
}
?>
</select>
<input type="submit" value="Set Default">
</form>
<br>
<div id="default_dept_feedback" style="color:#333;"> </div>
</div>
</div>
<script>
jQuery('#add_new').submit(function() {
var b = jQuery(this).serialize();
jQuery.post( ajaxurl,
{
'action':'add_dept_submit',
'data': b
},
function (response) {
jQuery('#dept_body').html(response);
});
return false;
});
jQuery('#set_default_dept').submit(function() {
var b = jQuery(this).serialize();
jQuery.post( ajaxurl,
{
'action':'set_default_dept',
'data': b
},
function (response) {
jQuery('#default_dept_feedback').html(response);
});
return false;
});
</script>
<?php
}
function set_default_dept_ajax() {
//controls the default department option submission
//create array from post data
$data = array();
$data_1 = explode('&', $_POST['data']);
foreach($data_1 as $line) {
$line1 = explode('=', $line);
$data[$line1[0]] = $line1[1];
}
$result = update_site_option('seu_default_dept_id', $data['default_dept']);
echo "$result <br>";
echo "Default department id set to " .$data['default_dept'];
die();
}
function control_tax_list() {
//sets up network admin page for custom taxonomies
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
//initialize styles
global $seufolios_dir;
wp_enqueue_style('seu-admin-styles', $seufolios_dir .'/classes/styles-admin.css');
//intitialize post types
$depts = get_depts();
foreach($depts as $dept) {
$pid = get_posttypes_id($dept->id);
if(!$pid) {
global $wpdb;
$taxes_table_name = $wpdb->base_prefix . "seufolios_taxes";
$rows_affected = $wpdb->insert( $taxes_table_name, array( 'dept_id' => $dept->id, 'tax_slug' => 'Posts' ) );
}
}
?>
<div class="wrap">
<h2>Department Taxonomies and Post Types</h2>
<div id="choose_dept">
<form name="choose_dept" id="choose_dept">
<select name="dept_select" id="dept_select">
<option value="0">--Select a Department--</option>
<?php
$depts = get_depts();
foreach($depts as $dept) {
echo "<option value='$dept->id'> $dept->name</option>\n";
}
?>
</select>
</form>
</div>
<!--Taxes-->
<div id="taxes" class="main_group">
<h3>Taxonomies</h3>
<div id="taxes_list">
</div>
<div id="taxes_form">
<h3>Add New Taxonomy</h3>
<form name="add_new_tax" id="add_new_tax" method="POST">
<table>
<tr>
<td class="align_right"><label for="tax_slug">Taxonomy</label></td><td><input type="text" name="tax_slug" size="20" placeholder='Required. Internal name.'></td>
</tr><tr>
<td class="align_right"><label for="tax_settings">Settings</label></td><td><textarea name="tax_settings" placeholder='Optional. Follow the guidelines below.'></textarea></td>
</tr><tr>
<td class="align_right"></td><td><input type="submit" value="Add Taxonomy" /></td>
</tr></table>
</form>
</div>
</div>
<!--Terms-->
<div id="terms" class="main_group">
<h3>Terms</h3>
<div id="terms_list">
</div>
<div id="tax_terms_form">
<h3>Add New Term</h3>
<form name="add_new_term" id="add_new_term" method="POST">
<input type="hidden" name="tax_id" id="tax_id" value="">
<table>
<tr>
<td class="align_right"><label for="term_slug">Term Slug</label></td><td><input type="text" name="term_slug" size="20" placeholder='Required. Internal name.'></td>
</tr><tr>
<td class="align_right"><label for="term_settings">Term Settings</label></td><td><textarea name="term_settings" size="20" placeholder='Optional. Follow the guidelines below.'></textarea></td>
</tr><tr>
<td class="align_right"></td><td><input type="submit" value="Add Term" /></td>
</tr></table>
</form>
</div>
</div>
<!--Post Types -->
<div id="posttypes" class="main_group">
<h3>Custom Post Types</h3>
<div id="posttypes_list">
</div>
<div id="posttypes_form">
<h3>Add New Post Type</h3>
<form name="add_new_posttype" id="add_new_posttype" method="POST">
<input type="hidden" name="posttype_id" id="posttype_id" value="">
<table>
<tr>
<td class="align_right"><label for="posttype_slug">Post Type Slug</label></td><td><input type="text" name="posttype_slug" size="20" placeholder='Required. Internal name.'></td>
</tr><tr>
<td class="align_right"><label for="posttype_settings">Settings</label></td><td><textarea name="posttype_settings" size="50" placeholder='Optional. Follow the guidelines below.'></textarea></td>
</tr><tr>
<td class="align_right"><label for="posttype_content">Default Content</label></td><td><textarea name="posttype_content" size="50" placeholder='Optional. "Strict HTML" formatting is possible.'></textarea></td>
</tr><tr>
<td class="align_right"></td><td><input type="submit" value="Add Term" /></td>
</tr></table>
</form>
</div>
</div>
<!--Taxonomy Instructions -->
<div id="tax_instructions" class="main_group">
<h3>Instructions</h3>
<p class='narrative'>The settings field needs to be a series of key and value pairs in a special format. Create the series by putting an equal sign (<strong>=</strong>) between the key and value and a line break (<strong>return key</strong>) between different settings. Some values need to be an array. If you need the value to be an array, separate the entries with a comma (<strong>,</strong>).</p>
<p class='narrative'>Create custom <em>Post Types</em> using the same form as you use to create a <em>Taxonomy</em>. Create a category for the custom post types by making a taxonomy. The Taxonomy slug needs to be <strong>Posts</strong>. Individual post types are entered as <strong>Terms</strong>, with the post type settings going in <strong>Term Settings</strong>.</p>
<p class='narrative'> The WordPress codex has a full list of the settings available for the <a href="http://codex.wordpress.org/Function_Reference/register_taxonomy">taxonomy</a>, <a href="http://codex.wordpress.org/Function_Reference/wp_insert_term">term</a>, and <a href="http://codex.wordpress.org/Function_Reference/register_post_type">post type</a> fields.
<p class='settings'>Default settings for a <em>Taxonomy</em> entry:<br>post_types=<?php $post_types = get_post_types(array('show_ui'=>true, '_builtin'=>true)); unset($post_types['attachment']); $return=''; foreach($post_types as $pt) $return.=$pt.', '; echo substr($return, 0, -2); ?><br>label={Taxonomy Slug}<br>show_admin_column=true</p>
<p class='settings'>Default settings for a <em>Term</em> entry:<br>slug={Term Slug}<br>description={Term Slug}</p>
<p class='settings'>Default settings for a <em>Post Type</em> entry:<br>public=true<br>capability_type=page<br>hierarchical=true<br>taxonomies=<?php $currtax= get_taxonomies(array('show_ui'=>true, '_builtin'=>true)); $return=''; foreach($currtax as $ct) $return.=$ct.', '; echo substr($return, 0, -2); ?></p>
</div>
</div>
<script>
//Department Select
jQuery('#dept_select').change(function()
{
var b = jQuery(this).val();
jQuery.post( ajaxurl,
{
'action':'tax_select_dept',
'data': b
},
function (response) {
var arr=JSON.parse(response);
jQuery('#taxes_list').html(arr.taxes);
jQuery('#posttypes_list').html(arr.posttypes);
});
jQuery('#taxes_form, #posttypes_form, #posttypes h3, #taxes h3').show(); //.css('display','block');
//jQuery('#posttypes_form').css('display','block');
});
//Show terms
function show_terms(tax_id, button) {
jQuery('#terms h3').show();
jQuery.post( ajaxurl,
{
'action':'tax_show_terms',
'data': tax_id
},
function (response) {
jQuery('#terms_list').html(response);
});
jQuery('#tax_terms_form').css('display','block');
jQuery('#tax_id').val(tax_id);
//reset selected class
jQuery('.selected').removeClass();
//add new selected class
var tableRow = button.parentNode.parentNode;
tableRow.className = 'selected';
return false;
}
//Add new tax
jQuery('#add_new_tax').submit(function() {
var b = jQuery(this).serialize() + '&dept_id=' + jQuery('#dept_select').val();
jQuery.post( ajaxurl,
{
'action':'tax_add_tax',
'data': b
},
function (response) {
jQuery('#taxes_list').html(response);
});
jQuery(this).each (function(){
this.reset();
});
return false;
});
//Edit a tax
function edit_tax(id) {
var tds = jQuery('#tax_row_'+id+' td');
var old_tax_slug = tds[0].innerHTML;
var old_tax_settings = tds[1].innerHTML;
var innerHTML = "<td><input class='edit_form_field' type='hidden' name='tax_id' id='tax_id' value='" + id + "'>" +
"<input class='edit_form_field' type='text' name='tax_slug' id='tax_slug' size='10' value='" +old_tax_slug+ "'></td>" +
"<td><textarea class='edit_form_field' name='tax_settings' id='tax_settings'>"+old_tax_settings+"</textarea>" +
"<td><button type='submit' onclick='edit_tax_submit();'>Done</button> " +
"<button id='delete_"+id+"' class='delete_button' type='button' onclick='delete_tax("+id+")'>Delete</button></td>";
jQuery('#tax_row_'+id).html(innerHTML);
return false;
}
//Submit the Edit Section
function edit_tax_submit() {
var b = jQuery(".edit_form_field").serialize() + '&dept_id=' + jQuery('#dept_select').val();
console.log(b);
jQuery.post( ajaxurl,
{
'action':'tax_edit_tax',
'data': b
},
function (response) {
jQuery('#taxes_list').html(response);
});
return false;
}
//Delete a section
function delete_tax(tax_id) {
jQuery.post( ajaxurl,
{
'action':'tax_delete_tax',
'data': 'tax_id='+tax_id +'&dept_id=' + jQuery('#dept_select').val(),
},
function (response) {
jQuery('#taxes_list').html(response);
});
return false;
}
//Add new term
jQuery('#add_new_term').submit(function() {
var b = jQuery(this).serialize() + '&dept_id=' + jQuery('#dept_select').val();
jQuery.post( ajaxurl,
{
'action':'tax_add_term',
'data': b
},
function (response) {
jQuery('#terms_list').html(response);
});
jQuery(this).each (function(){
this.reset();
});
return false;
});
//Edit a term
function edit_term(id) {
var tds = jQuery('#term_row_'+id+' td');
var old_term_slug = tds[0].innerHTML;
var old_term_settings = tds[1].innerHTML;
var innerHTML = "<td><input class='edit_form_field' type='hidden' name='term_id' id='term_id' value='" + id + "'>" +
"<input class='edit_form_field' type='hidden' name='tax_id' id='tax_id' value='" + jQuery('div#taxes_list table tr.selected').attr('id').match(/[\d]+$/) + "'>" +
"<input class='edit_form_field' type='text' name='term_slug' id='term_slug' size='10' value='" +old_term_slug+ "'></td>" +
"<td><textarea class='edit_form_field' type='text' name='term_settings' id='term_settings'>"+old_term_settings+"</textarea>" +
"<td><button type='submit' onclick='edit_term_submit();'>Done</button> " +
"<button id='delete_"+id+"' class='delete_button' type='button' onclick='delete_term("+id+")'>Delete</button></td>";
jQuery('#term_row_'+id).html(innerHTML);
return false;
}
//Submit the Edit Term
function edit_term_submit() {
var b = jQuery(".edit_form_field").serialize();
console.log(b);
jQuery.post( ajaxurl,
{
'action':'tax_edit_term',
'data': b
},
function (response) {
jQuery('#terms_list').html(response);
});
return false;
}
//Delete a term
function delete_term(term_id) {
jQuery.post( ajaxurl,
{
'action':'tax_delete_term',
'data': jQuery('.edit_form_field').serialize(),
},
function (response) {
jQuery('#terms_list').html(response);
});
return false;
}
//Add new post type
jQuery('#add_new_posttype').submit(function() {
var b = jQuery(this).serialize() + '&dept_id=' + jQuery('#dept_select').val();
jQuery.post( ajaxurl,
{
'action':'tax_add_posttype',
'data': b
},
function (response) {
jQuery('#posttypes_list').html(response);
});
jQuery(this).each (function(){
this.reset();
});
return false;
});
//Edit a post type
function edit_post(id) {
var tds = jQuery('#post_row_'+id+' td');
var old_post_slug = tds[0].innerHTML;
var old_post_settings = tds[1].innerHTML;
var old_post_content = tds[2].innerHTML;
var innerHTML = "<td><input class='edit_form_field' type='hidden' name='posttype_id' id='posttype_id' value='" + id + "'>" +
"<input class='edit_form_field' type='text' name='posttype_slug' id='posttype_slug' size='10' value='" +old_post_slug+ "'></td>" +
"<td><textarea class='edit_form_field' type='text' name='posttype_settings' id='posttype_settings'>"+old_post_settings+"</textarea></td>" +
"<td><textarea class='edit_form_field' type='text' name='posttype_content' id='posttype_content'>"+old_post_content+"</textarea></td>" +
"<td><button type='submit' onclick='edit_post_submit();'>Done</button> " +
"<button id='delete_"+id+"' class='delete_button' type='button' onclick='delete_post("+id+")'>Delete</button></td>";
jQuery('#post_row_'+id).html(innerHTML);
return false;
}
//Submit the Edit Post
function edit_post_submit() {
var b = jQuery(".edit_form_field").serialize() + '&dept_id=' + jQuery('#dept_select').val();
jQuery.post( ajaxurl,
{
'action':'tax_edit_posttype',
'data': b
},
function (response) {
jQuery('#posttypes_list').html(response);
});
return false;
}
//Delete a post
function delete_post(term_id) {
jQuery.post( ajaxurl,
{
'action':'tax_delete_posttype',
'data': jQuery('.edit_form_field').serialize() + '&dept_id=' + jQuery('#dept_select').val(),
},
function (response) {
jQuery('#posttypes_list').html(response);
});
return false;
}
</script>
<?php