-
Notifications
You must be signed in to change notification settings - Fork 0
/
people.php
145 lines (111 loc) · 4 KB
/
people.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
<?php
/*
* This script parses the csv table people/people.csv for the people section
*
* On load, it parses the data and stores it into an array, afterwards
* the echo only output the arrays
*
*/
/**
* set language to utf8 such that the csv files work properly
*/
header("Content-Type: text/html; charset=utf-8");
setlocale(LC_ALL, 'us_US.UTF-8');
/**
* small helper, similar to python array.get(default_value)
*/
function get(&$var, $default="") {
return isset($var) ? $var : $default;
}
function gett($pf="", &$var, $default="") {
return $pf . ($var ? $var : $default);
}
/**
* en/decrypts an email address using rotN method
* (let js then decrypt it afterwards, using -N)
*
* use my own de/encryption, based on the idea of rot13
*/
function encrypt($s, $n=0) {
static $letters = '[email protected]_nCTUpcDSWhzygKBYXetNvLwdGMb-mIFi';
$nchr = strlen($letters);
$n = (((int)$n) + $nchr) % $nchr;
$rep = substr($letters, $n) . substr($letters, 0, $n);
return strtr($s, $letters, $rep);
}
/**
* reads a cvs file
* $offset: how many lines to ignore at the beginning of the csv file
*
* will put persons into categories (from col 3)
* will sort by the (string) date in col 5
*/
function read_csv($filename="people.csv", $offset=3) {
$row=0;
#$people = array();
function cmp_by_jdate($a, $b) {
return strnatcmp($a['jdate'], $b['jdate']);
}
function cmp_by_last($a, $b) {
return strnatcmp($a['last'], $b['last']);
}
if (($handle = fopen("people/" . $filename, "r")) !== FALSE) {
# get rid of the first $offset lines
for (;$offset>0;$offset--){$data = fgetcsv($handle);}
while (($d = fgetcsv($handle)) !== FALSE) {
#print $d;
# check if name field was full, otherwise skip his empty line
if ($d[2]) {
$d2 = array(
'title'=>$d[0],
'first'=>$d[1],
'last' => ($d[2]),
'func' =>$d[4],
'foto' =>$d[7],
'mail' =>$d[8],
'hp' =>$d[9],
'buro' =>$d[10],
'tel' =>$d[11],
'jdate'=>$d[5], # join date used for sorting
'ldate'=>$d[6] # leave date used for sorting
) ;
$people[$d[3]][] = $d2;
}
}
fclose($handle);
# sort $people by their join date $jdate
foreach ($people as $group => &$members) {
usort($members, 'cmp_by_last');
#$people[$group] = $members;
}
return $people;
}
else {
return FALSE;
}
}
function get_people($filter) {
global $people;
foreach ($people[$filter] as $p) {
$str = "<div class=\"adressblock clearfix\">\n";
$str .= " <h3>" . get($p['title'], '') . " {$p['first']} {$p['last']}</h3>\n"; #mind the space before first
$str .= " <img class=\"floatimg\" alt=\"".gett("",$p['foto'], "anon.jpg")."\" src=\"" . gett("people/",$p['foto'], "anon.jpg") . "\">\n";
$str .= " <p>";
$str .= $p['func'] ? "({$p['func']})<br>" : "" ;
$str .= $p['hp'] ? "<a href='{$p['hp']}'>Homepage</a> " : "" ;
if ($p['hp'] and $p['mail']) {
$str .= " | ";
}
/* encrypt email adresses, let js decrypt them */
$encr_adr = encrypt($p['mail'], 21);
$str .= $p['mail'] ? "<a class='iimeil' href='mailto:[email protected]?body=Please%20enable%20javascript%20to%20decrypt%20email%20adresses.%20Alternativly%20you%20can%20try%20http%3A%2F%2Fwww.phonebook.uzh.ch%2F' data-iimeil='{$encr_adr}' title='email address'>eMail</a><br>" : "" ;
$str .= $p['buro'] ? "Office: {$p['buro']}<br>" : "" ;
$str .= $p['tel'] ? "<a href='tel:" . preg_replace('/\s+/', '', $p['tel']) . "'>Phone: {$p['tel']}</a><br>" : "" ;
$str .= "</p>\n";
$str .= "</div>\n";
echo $str;
}
}
$people = read_csv();
#print_r($people);
?>