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