2 require_once('init.php');
3 require_once('Contact_Vcard_Parse.php');
6 if(! $_SESSION['ldapab']['username'] ){
7 header("Location: login.php");
12 if(isset($_FILES['userfile'])){
13 if(preg_match('/\.vcf$/i', $_FILES['userfile']['name'])){
14 if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
16 $vcfparser = new Contact_Vcard_Parse();
17 $vcards = $vcfparser->fromFile($_FILES['userfile']['tmp_name']);
19 switch($_FILES['userfile']['error']){
20 case 0: //no error; possible file attack!
21 $error = "There was a problem with your upload.";
23 case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
24 $error = "The file you are trying to upload is too big.";
26 case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
27 $error = "The file you are trying to upload is too big.";
29 case 3: //uploaded file was only partially uploaded
30 $error = "The file you are trying upload was only partially uploaded.";
32 case 4: //no file was uploaded
33 $error = "You must select a VCF file for upload.";
35 default: //a default error, just in case! :)
36 $error = "There was a problem with your upload.";
41 $error = "Only VCF extension is allowed";
45 //prepare templates for all found VCARDs
48 foreach ($vcards as $vcard){
49 $entry = vcard_entry($vcard);
50 $smarty->clear_all_assign();
52 $smarty->assign('entry',$entry);
53 $list .= $smarty->fetch('importVCF_entry.tpl');
61 $smarty->assign('error',$error);
62 $smarty->assign('list',$list);
64 $smarty->display('header.tpl');
65 $smarty->display('importVCF.tpl');
66 $smarty->display('footer.tpl');
69 function vcard_entry($vcf){
70 $entry['name'] = $vcf['N'][0]['value'][0][0];
71 $entry['givenname'] = trim($vcf['N'][0]['value'][1][0].' '.$vcf['N'][0]['value'][2][0]);
72 $entry['title'] = $vcf['N'][0]['value'][3][0];
73 $entry['organization'] = $vcf['ORG'][0]['value'][0][0];
74 $entry['office'] = $vcf['ORG'][0]['value'][1][0];
75 $entry['note'] = $vcf['NOTE'][0]['value'][0][0];
76 $entry['url'] = $vcf['URL'][0]['value'][0][0];
77 $bday = $vcf['BDAY'][0]['value'][0][0];
78 $entry['anniversary'] = substr($bday,0,4).'-'.substr($bday,4,2).'-'.substr($bday,6,2);
80 foreach($vcf['TEL'] as $tel){
81 if( empty($entry['phone']) &&
82 array_search('WORK',$tel['param']['TYPE']) !== FALSE &&
83 array_search('VOICE',$tel['param']['TYPE']) !== FALSE){
85 $entry['phone'] = $tel['value'][0][0];
86 }elseif(empty($entry['fax']) &&
87 array_search('FAX',$tel['param']['TYPE']) !== FALSE){
88 $entry['fax'] = $tel['value'][0][0];
89 }elseif(empty($entry['mobile']) &&
90 array_search('CELL',$tel['param']['TYPE']) !== FALSE){
91 $entry['mobile'] = $tel['value'][0][0];
92 }elseif(empty($entry['pager']) &&
93 array_search('PAGER',$tel['param']['TYPE']) !== FALSE){
94 $entry['pager'] = $tel['value'][0][0];
95 }elseif(empty($entry['homephone']) &&
96 array_search('HOME',$tel['param']['TYPE']) !== FALSE &&
97 array_search('VOICE',$tel['param']['TYPE']) !== FALSE){
98 $entry['homephone'] = $tel['value'][0][0];
101 foreach($vcf['EMAIL'] as $mail){
102 $entry['mail'][] = $mail['value'][0][0];
104 foreach($vcf['ADR'] as $adr){
105 if(array_search('HOME',$adr['param']['TYPE']) !== FALSE){
106 $entry['homestreet'] = $adr['value'][2][0]."\n". //str
107 $adr['value'][5][0]." ". //plz
108 $adr['value'][3][0]; //ort
110 }elseif(array_search('WORK',$adr['param']['TYPE']) !== FALSE){
111 $entry['street'] = $adr['value'][2][0];
112 $entry['location'] = $adr['value'][3][0];
113 $entry['plz'] = $adr['value'][5][0];