[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - Addressbook * 4 * http://www.egroupware.org * 5 * Written by Joseph Engo <jengo@phpgroupware.org> and * 6 * Miles Lott <milos@groupwhere.org> * 7 * -------------------------------------------- * 8 * This program is free software; you can redistribute it and/or modify it * 9 * under the terms of the GNU General Public License as published by the * 10 * Free Software Foundation; either version 2 of the License, or (at your * 11 * option) any later version. * 12 \**************************************************************************/ 13 14 /* $Id: class.uivcard.inc.php 20295 2006-02-15 12:31:25Z $ */ 15 16 class uivcard 17 { 18 var $template; 19 var $contacts; 20 var $browser; 21 var $vcard; 22 var $bo; 23 24 var $public_functions = array( 25 'in' => True, 26 'out' => True 27 ); 28 29 var $extrafields = array( 30 'ophone' => 'ophone', 31 'address2' => 'address2', 32 'address3' => 'address3' 33 ); 34 35 function uivcard() 36 { 37 $this->template = &$GLOBALS['egw']->template; 38 $this->contacts = CreateObject('phpgwapi.contacts'); 39 $this->browser = CreateObject('phpgwapi.browser'); 40 $this->vcard = CreateObject('phpgwapi.vcard'); 41 $this->bo = CreateObject('addressbook.boaddressbook',True); 42 } 43 44 function in() 45 { 46 $uploadedfile = get_var('uploadedfile','FILES'); 47 $action = get_var('action',array('POST','GET')); 48 49 if($uploadedfile) 50 { 51 $ab_id = $this->bo->add_vcard($uploadedfile); 52 if($ab_id) 53 { 54 Header('Location: ' . $GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiaddressbook.view&ab_id=' . $ab_id)); 55 } 56 } 57 58 $GLOBALS['egw']->common->phpgw_header(); 59 echo parse_navbar(); 60 echo '<body bgcolor="' . $GLOBALS['egw_info']['theme']['bg_color'] . '">'; 61 62 if($action == 'GetFile') 63 { 64 echo '<b><center>' . lang('You must select a vcard. (*.vcf)') . '</b></center><br><br>'; 65 } 66 67 $this->template->set_file(array('vcardin' => 'vcardin.tpl')); 68 69 $this->template->set_var('lang_load_vcard', lang('load vcard')); 70 $this->template->set_var('vcard_header','<p> <b>' . lang('Address book - VCard in') . '</b><hr><p>'); 71 $this->template->set_var('action_url',$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uivcard.in')); 72 $this->template->set_var('lang_access',lang('Access')); 73 $this->template->set_var('lang_groups',lang('Which groups')); 74 $this->template->set_var('access_option',$access_option); 75 $this->template->set_var('group_option',$group_option); 76 77 $this->template->pparse('out','vcardin'); 78 79 $GLOBALS['egw']->common->phpgw_footer(); 80 } 81 82 function out() 83 { 84 $ab_id = get_var('ab_id',array('GET','POST')); 85 $nolname = get_var('nolname','GET'); 86 $nofname = get_var('nofname','GET'); 87 88 if($nolname || $nofname) 89 { 90 $GLOBALS['egw']->common->phpgw_header(); 91 echo parse_navbar(); 92 } 93 94 if(!$ab_id) 95 { 96 Header('Location: ' . $GLOBALS['egw']->link('/addressbook/index.php')); 97 $GLOBALS['egw']->common->phpgw_exit(); 98 } 99 100 // First, make sure they have permission to this entry 101 $check = $this->bo->read_entry(array('id' => $ab_id, 'fields' => array('owner' => 'owner'))); 102 $perms = $this->contacts->check_perms($this->contacts->grants[$check[0]['owner']],PHPGW_ACL_READ); 103 104 if((!$perms) && ($check[0]['owner'] != $GLOBALS['egw_info']['user']['account_id'])) 105 { 106 Header("Location: " . $GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiaddressbook.get_list')); 107 $GLOBALS['egw']->common->phpgw_exit(); 108 } 109 110 $extrafields = array('address2' => 'address2'); 111 $qfields = $this->contacts->stock_contact_fields + $extrafields; 112 113 $fieldlist = $this->bo->read_entry(array('id' => $ab_id, 'fields' => $qfields)); 114 $fields = $fieldlist[0]; 115 116 $email = $fields['email']; 117 $emailtype = $fields['email_type']; 118 if(!$emailtype) 119 { 120 $fields['email_type'] = 'INTERNET'; 121 } 122 $hemail = $fields['email_home']; 123 $hemailtype = $fields['email_home_type']; 124 if(!$hemailtype) 125 { 126 $fields['email_home_type'] = 'INTERNET'; 127 } 128 $firstname = $fields['n_given']; 129 $lastname = $fields['n_family']; 130 131 if(!$nolname && !$nofname) 132 { 133 /* First name and last must be in the vcard. */ 134 if($lastname == '') 135 { 136 /* Run away here. */ 137 Header('Location: ' . $GLOBALS['egw']->link('/index.php',"menuaction=addressbook.uivcard.out&nolname=1&ab_id=$ab_id")); 138 } 139 if($firstname == '') 140 { 141 Header('Location: ' . $GLOBALS['egw']->link('/index.php',"menuaction=addressbook.uivcard.out&nofname=1&ab_id=$ab_id")); 142 } 143 144 if($email) 145 { 146 $fn = explode('@',$email); 147 $filename = sprintf("%s.vcf", $fn[0]); 148 } 149 elseif($hemail) 150 { 151 $fn = explode('@',$hemail); 152 $filename = sprintf("%s.vcf", $fn[0]); 153 } 154 else 155 { 156 $fn = strtolower($firstname); 157 $filename = sprintf("%s.vcf", $fn); 158 } 159 160 // set translation variable 161 $myexport = $this->vcard->export; 162 // check that each $fields exists in the export array and 163 // set a new array to equal the translation and original value 164 while(list($name,$value) = each($fields)) 165 { 166 if($myexport[$name] && ($value != '')) 167 { 168 //echo '<br>'.$name."=".$fields[$name]."\n"; 169 $buffer[$myexport[$name]] = $value; 170 } 171 } 172 173 // create a vcard from this translated array 174 $entry = $this->vcard->out($buffer); 175 // print it using browser class for headers 176 // filename, mimetype, no length, default nocache True 177 $this->browser->content_header($filename,'text/x-vcard'); 178 echo $entry; 179 exit; 180 //$GLOBALS['egw']->common->exit; 181 } /* !nolname && !nofname */ 182 183 if($nofname) 184 { 185 echo '<br><br><center>'; 186 echo lang("This person's first name was not in the address book.") .'<br>'; 187 echo lang('Vcards require a first name entry.') . '<br><br>'; 188 echo '<a href="' . $GLOBALS['egw']->link('/addressbook/index.php', 189 "order=$order&start=$start&filter=$filter&query=$query&sort=$sort&cat_id=$cat_id") . '">' . lang('OK') . '</a>'; 190 echo '</center>'; 191 } 192 193 if($nolname) 194 { 195 echo '<br><br><center>'; 196 echo lang("This person's last name was not in the address book.") . '<br>'; 197 echo lang('Vcards require a last name entry.') . '<br><br>'; 198 echo '<a href="' . $GLOBALS['egw']->link('/addressbook/index.php', 199 "order=$order&start=$start&filter=$filter&query=$query&sort=$sort&cat_id=$cat_id") . '">' . lang('OK') . '</a>'; 200 echo '</center>'; 201 } 202 203 if($nolname || $nofname) 204 { 205 //$GLOBALS['egw']->common->phpgw_footer(); 206 } 207 } 208 } 209 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |