[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - Addressbook * 4 * http://www.egroupware.org * 5 * Written by Miles Lott <milos@groupwhere.org> * 6 * ------------------------------------------------------------------------ * 7 * This program is free software; you can redistribute it and/or modify it * 8 * under the terms of the GNU General Public License as published by the * 9 * Free Software Foundation; either version 2 of the License, or (at your * 10 * option) any later version. * 11 \**************************************************************************/ 12 13 /* $Id: class.uiXport.inc.php 20295 2006-02-15 12:31:25Z $ */ 14 15 class uiXport 16 { 17 var $template; 18 var $public_functions = array( 19 'import' => True, 20 'export' => True 21 ); 22 var $bo; 23 var $cat; 24 25 var $start; 26 var $limit; 27 var $query; 28 var $sort; 29 var $order; 30 var $filter; 31 var $cat_id; 32 33 function uiXport() 34 { 35 $this->template = $GLOBALS['egw']->template; 36 $this->cat = CreateObject('phpgwapi.categories'); 37 $this->bo = CreateObject('addressbook.boXport',True); 38 $this->browser = CreateObject('phpgwapi.browser'); 39 40 $this->_set_sessiondata(); 41 } 42 43 function _set_sessiondata() 44 { 45 $this->start = $this->bo->start; 46 $this->limit = $this->bo->limit; 47 $this->query = $this->bo->query; 48 $this->sort = $this->bo->sort; 49 $this->order = $this->bo->order; 50 $this->filter = $this->bo->filter; 51 $this->cat_id = $this->bo->cat_id; 52 if($this->debug) { $this->_debug_sqsof(); } 53 } 54 55 /* Called only by index(), just prior to page footer. */ 56 function save_sessiondata() 57 { 58 $data = array( 59 'start' => $this->start, 60 'limit' => $this->limit, 61 'query' => $this->query, 62 'sort' => $this->sort, 63 'order' => $this->order, 64 'filter' => $this->filter, 65 'cat_id' => $this->cat_id 66 ); 67 $this->bo->save_sessiondata($data); 68 } 69 70 /* Return a select form element with the categories option dialog in it */ 71 function cat_option($cat_id='',$notall=False,$java=True,$multiple=False) 72 { 73 if($java) 74 { 75 $jselect = ' onChange="this.form.submit();"'; 76 } 77 /* Setup all and none first */ 78 $cats_link = "\n" .'<select name="fcat_id'.($multiple?'[]':'').'"' .$jselect . ($multiple ? 'multiple size="3"' : '') . ">\n"; 79 if(!$notall) 80 { 81 $cats_link .= '<option value=""'; 82 if($cat_id=='all') 83 { 84 $cats_link .= ' selected'; 85 } 86 $cats_link .= '>'.lang('all').'</option>'."\n"; 87 } 88 89 /* Get global and app-specific category listings */ 90 $cats_link .= $this->cat->formated_list('select','all',$cat_id,True); 91 $cats_link .= '</select>'."\n"; 92 return $cats_link; 93 } 94 95 function import() 96 { 97 $tsvfile = get_var('tsvfile','FILES'); 98 $tsvfilename = get_var('tsvfilename','POST'); 99 $convert = get_var('convert','POST'); 100 $conv_type = get_var('conv_type','POST'); 101 $fcat_id = get_var('fcat_id','POST'); 102 $private = get_var('private','POST'); 103 $download = get_var('download','POST'); 104 105 if($convert) 106 { 107 if($conv_type == 'none') 108 { 109 $GLOBALS['egw_info']['flags']['noheader'] = False; 110 $GLOBALS['egw_info']['flags']['noheader'] = True; 111 $GLOBALS['egw']->common->phpgw_header(); 112 echo parse_navbar(); 113 echo lang('<b>No conversion type <none> could be located.</b> Please choose a conversion type from the list'); 114 echo ' <a href="'.$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiXport.import') . '">' . lang('OK') . '</a>'; 115 $GLOBALS['egw']->common->phpgw_footer(); 116 $GLOBALS['egw']->common->phpgw_exit(); 117 } 118 $buffer = $this->bo->import($tsvfile,$conv_type,$private,$fcat_id); 119 120 if($download == '') 121 { 122 if($conv_type == 'Debug LDAP' || $conv_type == 'Debug SQL') 123 { 124 // filename, default application/octet-stream, length of file, default nocache True 125 $GLOBALS['egw']->browser->content_header($tsvfilename,'',strlen($buffer)); 126 echo $buffer; 127 } 128 else 129 { 130 $GLOBALS['egw']->common->phpgw_header(); 131 echo parse_navbar(); 132 echo "<pre>$buffer</pre>"; 133 echo '<a href="'.$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiaddressbook.index') . '">'.lang('OK').'</a>'; 134 $GLOBALS['egw']->common->phpgw_footer(); 135 } 136 } 137 else 138 { 139 $GLOBALS['egw']->common->phpgw_header(); 140 echo parse_navbar(); 141 echo "<pre>$buffer</pre>"; 142 echo '<a href="'.$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiaddressbook.index'). '">'.lang('OK').'</a>'; 143 $GLOBALS['egw']->common->phpgw_footer(); 144 } 145 } 146 else 147 { 148 $GLOBALS['egw']->common->phpgw_header(); 149 echo parse_navbar(); 150 151 set_time_limit(0); 152 153 $this->template->set_file(array('import' => 'import.tpl')); 154 155 $dir_handle = opendir(PHPGW_APP_INC . SEP . 'import'); 156 $i=0; $myfilearray = ''; 157 while($file = readdir($dir_handle)) 158 { 159 if((substr($file, 0, 1) != '.') && is_file(PHPGW_APP_INC . SEP . 'import' . SEP . $file)) 160 { 161 $myfilearray[$i] = $file; 162 $i++; 163 } 164 } 165 closedir($dir_handle); 166 sort($myfilearray); 167 for($i=0;$i<count($myfilearray);$i++) 168 { 169 if ($myfilearray[$i] == 'Import_Multiple_VCard') 170 { 171 $fname = lang('import multiple vcard'); 172 } 173 else 174 { 175 $fname = str_replace('Import_from_', lang('import from') . ' ' ,$myfilearray[$i]); 176 $fname = str_replace('_', ' ', $fname); 177 } 178 $conv .= '<OPTION VALUE="' . $myfilearray[$i].'">' . $fname . '</OPTION>'; 179 } 180 181 $this->template->set_var('lang_none', lang('none')); 182 $this->template->set_var('lang_cancel',lang('Cancel')); 183 $this->template->set_var('lang_cat',lang('Select Category')); 184 $this->template->set_var('cancel_url',$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiaddressbook.index')); 185 $this->template->set_var('navbar_bg',$GLOBALS['egw_info']['theme']['navbar_bg']); 186 $this->template->set_var('navbar_text',$GLOBALS['egw_info']['theme']['navbar_text']); 187 $this->template->set_var('import_text',lang('Import from LDIF, CSV, or VCard')); 188 $this->template->set_var('action_url',$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiXport.import')); 189 $this->template->set_var('cat_link',$this->cat_option($this->cat_id,True,False)); 190 $this->template->set_var('tsvfilename',''); 191 $this->template->set_var('conv',$conv); 192 $this->template->set_var('debug',lang('Debug output in browser')); 193 $this->template->set_var('filetype',lang('LDIF')); 194 $this->template->set_var('download',lang('Submit')); 195 $this->template->set_var('start',$this->start); 196 $this->template->set_var('sort',$this->sort); 197 $this->template->set_var('order',$this->order); 198 $this->template->set_var('filter',$this->filter); 199 $this->template->set_var('query',$this->query); 200 $this->template->set_var('cat_id',$this->cat_id); 201 $this->template->set_var('lang_import_instructions',lang('import_instructions')); 202 $this->template->set_var('zip_note',''); 203 if(extension_loaded('zip')) 204 { 205 $this->template->set_var('zip_note',lang('zip_note')); 206 } 207 208 $this->template->set_var('lang_exported_file',lang('enter the path to the exported file here')); 209 $this->template->set_var('lang_conv_type',lang('select the type of conversion')); 210 $this->template->set_var('lang_mark_priv',lang('Mark records as private')); 211 $this->template->set_var('lang_debug',lang('Debug output in browser')); 212 $this->template->pparse('out','import'); 213 } 214 // $GLOBALS['egw']->common->phpgw_footer(); 215 } 216 217 function export() 218 { 219 $convert = get_var('convert','POST'); 220 $conv_type = get_var('conv_type','POST'); 221 $fcat_id = get_var('fcat_id','POST'); 222 $download = get_var('download','POST'); 223 $tsvfilename = get_var('tsvfilename','POST'); 224 225 if($convert) 226 { 227 if($conv_type == 'none') 228 { 229 $GLOBALS['egw_info']['flags']['noheader'] = False; 230 $GLOBALS['egw_info']['flags']['noheader'] = True; 231 $GLOBALS['egw']->common->phpgw_header(); 232 echo parse_navbar(); 233 echo lang('<b>No conversion type <none> could be located.</b> Please choose a conversion type from the list'); 234 echo ' <a href="'.$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiXport.export') . '">' . lang('OK') . '</a>'; 235 $GLOBALS['egw']->common->phpgw_footer(); 236 $GLOBALS['egw']->common->phpgw_exit(); 237 } 238 239 $buffer = $this->bo->export($conv_type,$fcat_id); 240 241 if($conv_type == 'Palm_PDB') 242 { 243 $pdb = CreateObject('addressbook.pdb'); 244 $pdb->fetch($buffer, 'phpgw Contacts', $tsvfilename); 245 } 246 elseif($download == 'on') 247 { 248 // filename, default application/octet-stream, length of file, default nocache True 249 $this->browser->content_header($tsvfilename,'application/x-octet-stream',strlen($buffer)); 250 echo $buffer; 251 } 252 else 253 { 254 $GLOBALS['egw']->common->phpgw_header(); 255 echo parse_navbar(); 256 echo "<pre>\n"; 257 echo $buffer; 258 echo "\n</pre>\n"; 259 echo '<a href="'.$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiXport.export') . '">' . lang('OK') . '</a>'; 260 $GLOBALS['egw']->common->phpgw_footer(); 261 } 262 } 263 else 264 { 265 $GLOBALS['egw']->common->phpgw_header(); 266 echo parse_navbar(); 267 268 set_time_limit(0); 269 270 $this->template->set_file(array('export' => 'export.tpl')); 271 272 $dir_handle = opendir(PHPGW_APP_INC. SEP . 'export'); 273 $i=0; $myfilearray = ''; 274 while($file = readdir($dir_handle)) 275 { 276 if((substr($file, 0, 1) != '.') && is_file(PHPGW_APP_INC . SEP . 'export' . SEP . $file)) 277 { 278 $myfilearray[$i] = $file; 279 $i++; 280 } 281 } 282 closedir($dir_handle); 283 sort($myfilearray); 284 for($i=0;$i<count($myfilearray);$i++) 285 { 286 if ($myfilearray[$i] == 'Multiple_VCard') 287 { 288 $fname = lang('multiple vcard'); 289 } 290 else 291 { 292 $fname = str_replace('_',' ',$myfilearray[$i]); 293 } 294 $conv .= ' <option value="'.$myfilearray[$i].'">'.$fname.'</option>'."\n"; 295 } 296 297 $this->template->set_var('lang_none', lang('none')); 298 $this->template->set_var('lang_cancel',lang('Cancel')); 299 $this->template->set_var('lang_cat',lang('Select Category')); 300 $this->template->set_var('lang_export_instructions',lang('Download export file (Uncheck to debug output in browser)')); 301 $this->template->set_var('lang_select',lang('Select the type of conversion:')); 302 $this->template->set_var('cat_link',$this->cat_option($this->cat_id,False,False)); 303 $this->template->set_var('cancel_url',$GLOBALS['egw']->link('/addressbook/index.php')); 304 $this->template->set_var('navbar_bg',$GLOBALS['egw_info']['theme']['navbar_bg']); 305 $this->template->set_var('navbar_text',$GLOBALS['egw_info']['theme']['navbar_text']); 306 $this->template->set_var('export_text',lang('Export from Addressbook')); 307 $this->template->set_var('action_url',$GLOBALS['egw']->link('/index.php','menuaction=addressbook.uiXport.export')); 308 $this->template->set_var('filename',lang('Export file name')); 309 $this->template->set_var('conv',$conv); 310 $this->template->set_var('debug',lang('')); 311 $this->template->set_var('download',lang('Submit')); 312 $this->template->set_var('start',$this->start); 313 $this->template->set_var('sort',$this->sort); 314 $this->template->set_var('order',$this->order); 315 $this->template->set_var('filter',$this->filter); 316 $this->template->set_var('query',$this->query); 317 $this->template->set_var('cat_id',$this->cat_id); 318 $this->template->pparse('out','export'); 319 320 $GLOBALS['egw']->common->phpgw_footer(); 321 } 322 } 323 } 324 ?>
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 |