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
<?php
function faculty_admin_template_settings($form_state) {  

	$form['template1'] = array(
   '#type'        => 'fieldset',
	 '#title'       => t('Faculty detail page template'),
    '#description'   => t('Enter code to build the faculty detail pages. Include <em>&lt;?php ?&gt;</em> tags.'),    
	 '#collapsible' => TRUE,
	 '#collapsed'   => TRUE,
	);


	$form['template1']['faculty_detail_template'] = array( 
    '#type'          => 'textarea',
    '#title'         => t('Faculty detail page template'),
    '#rows'          => 40,
		'#default_value' => variable_get('faculty_detail_template', faculty_default_template()),
  );
  
  $form['variables'] = array(
	  '#type' => 'fieldset',
	  '#title' => t('Available variables'),
	  '#collapsible' => TRUE,
	  '#collapsed' => TRUE,
    '#description' => t('Below are the available variables for use. Some variables may not be available for all people.
      Most variables do not output HTML elements, so you will need to wrap them in HTML tags. Be sure to include <em>&lt;?php ?&gt;</em> tags.'),
	);
	
	$form['variables']['info'] = array(
	  '#type' => 'item',
	  '#value' => faculty_default_variables(),
	);  

  $form = system_settings_form($form);
  
  # Make sure that our custom submit funtion gets called last!
  $form['#submit'][] = 'faculty_submit';
  
  return $form;
}

function faculty_submit($form, &$form_state){ 
  // Clear caches for list and detail pages.
  cache_clear_all('faculty_list', 'cache', TRUE);
  cache_clear_all('faculty_detail_load', 'cache', TRUE);
  
  // Check if the template variable exists, if not, create it (for when reset is clicked)
  $template = variable_get('faculty_detail_template', NULL);
  if (empty($template)) {
    variable_set('faculty_detail_template', faculty_default_template());
  }
}

/**
 *
 * @return string default template
 */
function faculty_default_template () {

// nowdoc is available since PHP 5.3.0!
// use single quotes if PHP version is lower
  
$template = <<<'EOD'
<?php print $photo; ?><br />

<?php if($titles): ?>
<?php print $titles; ?>
<?php endif; ?>

<?php if($address): ?>
<p><?php print $address; ?></p>
<?php endif; ?>

<?php if($email): ?>
<p><?php print $email; ?></p>
<?php endif; ?>

<?php if($office_phone): ?>
<?php print $office_phone; ?>
<?php endif; ?>

<?php if($education): ?>
<h2>Education</h2>
<?php print $education; ?>
<?php endif; ?>

<?php if($biography): ?>
<h2>Biography</h2>
<p><?php print $biography; ?></p>
<?php endif; ?>  
EOD;
  
return $template;
}

/**
 *
 * @return an unordered list of available variables
 */
function faculty_default_variables() {
 
  $items = array(
    array('$firstname'),
    array('$lastname'),
    array('$degree'),
    array('$mission'),
    array('$emai'),
    array('$office_phone'),
    array('$biography'),
    array('$research_interests'),
    array('$clinical_interests'),
    array('$research_overview'),
    array('$research_summary'),
    array('$current_projects'),
    array('$organizations'),
    array('$academic_location'),
    array('$professional_awards'),
    array('$education'),
    array('$address'),
    array('$photo'),
    array('$departments'),
    array('$titles'),
    array('$featured_publications'),
    array('$related_links'),
    array('$current_projects'),
  ); 
  
  return theme_item_list($items, NULL, 'ul');
}