Sponsorenverwaltung - Team StarCraft e.V.
 All Data Structures Files Functions Variables
vcard.php
Go to the documentation of this file.
1 <?php
2  /**
3  * @file vcard.php
4  *
5  * @brief Download vCard of a contact person
6  *
7  * @details
8  * Accessing this file as a logged in user will give you the possibility to
9  * download the contact-details of a chosen user. This file will generate
10  * the vCard (encoding: ISO-8859-1) in place and allows the download.
11  *
12  * This file depends on inc/common.php.
13  *
14  * @copyright (c) 2013, Team StarCraft e.V.
15  * @version 1.0.0
16  * @author Alexander Vorndran
17  * @date 02.07.2013
18  */
19 
20  // includes
21  include("common.php");
22 
23  /// @cond MAINPART
24  if(!isUserLoggedIn()) {
25  // exit if the user is not logged in
26  die();
27  } else {
28  if(isset($_GET['id']) && ctype_digit($_GET['id'])) {
29  $contactPersonId = $_GET['id'];
30  if(contactPersonExists($contactPersonId)) {
31  // contact person exists
32 
33  // fetch contact person details
34  $contactDetails = fetchContactPersonDetailsForVCard($contactPersonId);
35 
36  // decode some spacial chars
37  foreach ($contactDetails as &$detail) {
38  $detail = htmlspecialchars_decode($detail,ENT_QUOTES);
39  $detail = str_replace(';', '', $detail);
40  }
41  // if contact person name is empty => use sponsor name
42  $contactDetails['name'] = (empty($contactDetails['name'])) ? $contactDetails['sponsor'] : $contactDetails['name'];
43 
44  // prepare filename
45  $filename = prepareFilename($contactDetails['name']);
46 
47  // set some header information
48  header("Content-type: text/vcard; charset=iso-8859-1");
49  header("Content-Disposition: attachment; filename=".$filename."_vCard.vcf");
50 
51  // set vcard file format
52  $vCardString =
53  "BEGIN:VCARD\n".
54  "VERSION:2.1\n".
55  "N;CHARSET=ISO-8859-1:".$contactDetails['name'].";\n".
56  "FN;CHARSET=ISO-8859-1:".$contactDetails['name']."\n".
57  "ORG;CHARSET=ISO-8859-1:".$contactDetails['sponsor']."\n".
58  "TITLE;CHARSET=ISO-8859-1: ".$contactDetails['position']."\n".
59  "NOTE;ENCODING=QUOTED-PRINTABLE: ".$contactDetails['newsletter']."\n".
60  "TEL;WORK;VOICE:".$contactDetails['phoneNumber']."\n".
61  "TEL;CELL;VOICE:".$contactDetails['mobileNumber']."\n".
62  "ADR;WORK;CHARSET=ISO-8859-1:;;".$contactDetails['street']." ".$contactDetails['house_number'].";".$contactDetails['town'].";;".$contactDetails['zip_code'].";".$contactDetails['country']."\n".
63  "EMAIL;PREF;INTERNET:".$contactDetails['email']."\n".
64  "REV:". date('Y-m-d H:i:s')."\n".
65  "END:VCARD";
66 
67  // output vcard
68  echo iconv('utf-8','iso-8859-1', $vCardString);
69  }
70 
71  } else {
72  die();
73  }
74  }
75  /// @endcond
76 ?>