2 require_once('init.php');
3 require_once('Contact_Vcard_Parse.php');
4 require_once('xml.php');
7 if(! $_SESSION['ldapab']['username'] ){
8 header("Location: login.php");
13 if(isset($_FILES['userfile'])){
14 if (is_uploaded_file($_FILES['userfile']['tmp_name'])){
15 if(preg_match('/\.vcf$/i', $_FILES['userfile']['name'])){
17 $vcfparser = new Contact_Vcard_Parse();
18 $vcards = $vcfparser->fromFile($_FILES['userfile']['tmp_name']);
19 }elseif(preg_match('/^addressbook\.xml$/i', $_FILES['userfile']['name'])){
20 //parse Zaurus Addressbook
21 $contacts = XML_unserialize(@join('',@file($_FILES['userfile']['tmp_name'])));
23 $error = "Only *.vcf or addressbook.xml are accepted";
26 switch($_FILES['userfile']['error']){
27 case 0: //no error; possible file attack!
28 $error = "There was a problem with your upload.";
30 case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
31 $error = "The file you are trying to upload is too big.";
33 case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
34 $error = "The file you are trying to upload is too big.";
36 case 3: //uploaded file was only partially uploaded
37 $error = "The file you are trying upload was only partially uploaded.";
39 case 4: //no file was uploaded
40 $error = "You must select a VCF file for upload.";
42 default: //a default error, just in case! :)
43 $error = "There was a problem with your upload.";
49 //prepare templates for all found entries
52 foreach ($vcards as $vcard){
53 $entry = vcard_entry($vcard);
54 $smarty->clear_all_assign();
56 $smarty->assign('entry',$entry);
57 $list .= $smarty->fetch('import_entry.tpl');
59 }elseif(count($contacts)){
60 foreach ($contacts['AddressBook']['Contacts']['Contact'] as $contact){
61 if (!is_array($contact)) continue;
62 $entry = zaurus_entry($contact);
63 $smarty->clear_all_assign();
65 $smarty->assign('entry',$entry);
66 $list .= $smarty->fetch('import_entry.tpl');
74 $smarty->assign('error',$error);
75 $smarty->assign('list',$list);
77 $smarty->display('header.tpl');
78 $smarty->display('import.tpl');
79 $smarty->display('footer.tpl');
82 function zaurus_entry($cnct){
83 $entry['name'] = $cnct['LastName'];
84 $entry['givenname'] = trim($cnct['FirstName'].' '.$cnct['MiddleName']);
85 $entry['title'] = $cnct['JobTitle'];
86 $entry['organization'] = $cnct['Company'];
87 $entry['office'] = $cnct['Office'];
88 $entry['note'] = $cnct['Notes'];
89 $entry['mail'] = split(' ',$cnct['Emails']);
90 $entry['street'] = $cnct['BusinessStreet'];
91 $entry['location'] = $cnct['BusinessCity'];
92 $entry['zip'] = $cnct['BusinessZip'];
93 $entry['homestreet'] = $cnct['HomeStreet']."\n". //str
94 $cnct['HomeZip']." ". //plz
95 $cnct['HomeCity']; //ort
96 $entry['homephone'] = $cnct['HomePhone'];
97 $entry['phone'] = $cnct['BusinessPhone'];
98 $entry['fax'] = empty($cnct['BusinessFax']) ? $cnct['HomeFax'] : $cnct['BusinessFax'];
99 $entry['mobile'] = empty($cnct['HomeMobile']) ? $cnct['BusinessMobile'] : $cnct['HomeMobile'];
100 $entry['fax'] = empty($cnct['BusinessFax']) ? $cnct['HomeFax'] : $cnct['BusinessFax'];
102 # $entry['anniversary'] = $cnt[''];
104 utf8_decode_array($entry);
108 function vcard_entry($vcf){
109 $entry['name'] = $vcf['N'][0]['value'][0][0];
110 $entry['givenname'] = trim($vcf['N'][0]['value'][1][0].' '.$vcf['N'][0]['value'][2][0]);
111 $entry['title'] = $vcf['N'][0]['value'][3][0];
112 $entry['organization'] = $vcf['ORG'][0]['value'][0][0];
113 $entry['office'] = $vcf['ORG'][0]['value'][1][0];
114 $entry['note'] = $vcf['NOTE'][0]['value'][0][0];
115 $entry['url'] = $vcf['URL'][0]['value'][0][0];
116 $bday = $vcf['BDAY'][0]['value'][0][0];
117 $entry['anniversary'] = substr($bday,0,4).'-'.substr($bday,4,2).'-'.substr($bday,6,2);
119 foreach($vcf['TEL'] as $tel){
120 if( empty($entry['phone']) &&
121 array_search('WORK',$tel['param']['TYPE']) !== FALSE &&
122 array_search('VOICE',$tel['param']['TYPE']) !== FALSE){
124 $entry['phone'] = $tel['value'][0][0];
125 }elseif(empty($entry['fax']) &&
126 array_search('FAX',$tel['param']['TYPE']) !== FALSE){
127 $entry['fax'] = $tel['value'][0][0];
128 }elseif(empty($entry['mobile']) &&
129 array_search('CELL',$tel['param']['TYPE']) !== FALSE){
130 $entry['mobile'] = $tel['value'][0][0];
131 }elseif(empty($entry['pager']) &&
132 array_search('PAGER',$tel['param']['TYPE']) !== FALSE){
133 $entry['pager'] = $tel['value'][0][0];
134 }elseif(empty($entry['homephone']) &&
135 array_search('HOME',$tel['param']['TYPE']) !== FALSE &&
136 array_search('VOICE',$tel['param']['TYPE']) !== FALSE){
137 $entry['homephone'] = $tel['value'][0][0];
140 foreach($vcf['EMAIL'] as $mail){
141 $entry['mail'][] = $mail['value'][0][0];
143 foreach($vcf['ADR'] as $adr){
144 if(array_search('HOME',$adr['param']['TYPE']) !== FALSE){
145 $entry['homestreet'] = $adr['value'][2][0]."\n". //str
146 $adr['value'][5][0]." ". //plz
147 $adr['value'][3][0]; //ort
149 }elseif(array_search('WORK',$adr['param']['TYPE']) !== FALSE){
150 $entry['street'] = $adr['value'][2][0];
151 $entry['location'] = $adr['value'][3][0];
152 $entry['zip'] = $adr['value'][5][0];