phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] CVS: infolog csv_import.php,1.7,1.7.2.1


From: Ralf Becker <address@hidden>
Subject: [Phpgroupware-cvs] CVS: infolog csv_import.php,1.7,1.7.2.1
Date: Tue, 05 Mar 2002 08:01:19 -0500

Update of /cvsroot/phpgroupware/infolog
In directory subversions:/tmp/cvs-serv2120

Modified Files:
      Tag: Version-0_9_14-branch
        csv_import.php 
Log Message:
allowing multiple cats to be separated by ';' or ','
saving field-assignments now in preferences and not longer in a separate file 
in /tmp

Index: csv_import.php
===================================================================
RCS file: /cvsroot/phpgroupware/infolog/csv_import.php,v
retrieving revision 1.7
retrieving revision 1.7.2.1
diff -C2 -r1.7 -r1.7.2.1
*** csv_import.php      4 Oct 2001 20:13:00 -0000       1.7
--- csv_import.php      5 Mar 2002 13:01:17 -0000       1.7.2.1
***************
*** 86,112 ****
  $cat2id = array( );
  
! function cat_id( $cats )
  {
        if (!$cats)
                return '';
!               
!       $cats = explode(',',$cats);
!       
!       while (list($k,$cat) = each($cats)) {
!               if (isset($cat2id[$cat])) {
!                       $ids[$cat] = $cat2id[$cat];                             
                                // cat is in cache
!               } else {
!                       if (!is_object($GLOBALS['phpgw']->categories)) {
                                $GLOBALS['phpgw']->categories = 
createobject('phpgwapi.categories');
!                       }                       
!                       if ($id = $GLOBALS['phpgw']->categories->name2id( $cat 
)) {     // cat exists
                                $cat2id[$cat] = $ids[$cat] = $id;
!                       } else {                                                
                                                                        // 
create new cat
!                               $GLOBALS['phpgw']->categories->add( 
$cat,0,$cat,'','public',0);
!                               $cat2id[$cat] = $ids[$cat] = 
$GLOBALS['phpgw']->categories->name2id( $cat );
                        }
                }
        }
!       return implode( ',',$ids );
  }
  
--- 86,128 ----
  $cat2id = array( );
  
! function cat_id($cats)
  {
        if (!$cats)
+       {
                return '';
!       }
! 
!       $cats = split('[,;]',$cats);
! 
!       while (list($k,$cat) = each($cats))
!       {
!               if (isset($cat2id[$cat]))
!               {
!                       $ids[$cat] = $cat2id[$cat];     // cat is in cache
!               }
!               else
!               {
!                       if (!is_object($GLOBALS['phpgw']->categories))
!                       {
                                $GLOBALS['phpgw']->categories = 
createobject('phpgwapi.categories');
!                       }
!                       if ($id = $GLOBALS['phpgw']->categories->name2id( 
addslashes($cat) ))
!                       {       // cat exists
                                $cat2id[$cat] = $ids[$cat] = $id;
!                       }
!                       else
!                       {       // create new cat
!                               $GLOBALS['phpgw']->categories->add( 
array('name' => $cat,'descr' => $cat ));
!                               $cat2id[$cat] = $ids[$cat] = 
$GLOBALS['phpgw']->categories->name2id( addslashes($cat) );
                        }
                }
        }
!       $id_str = implode( ',',$ids );
! 
!       if (count($ids) > 1)            // multiple cats need to be in ','
!       {
!               $id_str = ",$id_str,";
!       }
!       return  $id_str;
  }
  
***************
*** 125,133 ****
  
        case 'download':
!               $pref_file = '/tmp/csv_import_info_log.php';
!               if (is_readable($pref_file) && ($prefs = 
fopen($pref_file,'r'))) {
!                       eval(fread($prefs,8000));
!                       // echo "<p>defaults = 
array".dump_array($defaults)."</p>\n";
!               }       else {
                        $defaults = array();
                }
--- 141,148 ----
  
        case 'download':
!               $GLOBALS['phpgw']->preferences->read_repository();
!               $defaults = 
$GLOBALS['phpgw_info']['user']['preferences']['infolog']['cvs_import'];
!               if (!is_array($defaults))
!               {
                        $defaults = array();
                }
***************
*** 139,144 ****
                $t->parse('fheaderhandle','fheader');
                $hiddenvars .= '<input type="hidden" name="action" 
value="import">'."\n".
!                                                       '<input type="hidden" 
name="fieldsep" value="'.$fieldsep."\">\n".
!                                                       '<input type="hidden" 
name="pref_file" value="'.$pref_file."\">\n";
  
                $info_names = array(    'type'          => 'Type: 
task,phone,note,confirm,reject,email,fax',
--- 154,158 ----
                $t->parse('fheaderhandle','fheader');
                $hiddenvars .= '<input type="hidden" name="action" 
value="import">'."\n".
!                                                       '<input type="hidden" 
name="fieldsep" value="'.$fieldsep."\">\n";
  
                $info_names = array(    'type'          => 'Type: 
task,phone,note,confirm,reject,email,fax',
***************
*** 162,165 ****
--- 176,180 ----
                                                                        
'addr_id'       =>      'Addressbook id, to set use @addr_id(nlast,nfirst,org)' 
);
  
+               /* this are settings to import from Lotus Organizer
                $mktime_lotus = "${PSep}0?([0-9]+)[ .:-]+0?([0-9]*)[ 
.:-]+0?([0-9]*)[ .:-]+0?([0-9]*)[ .:-]+0?([0-9]*)[ 
.:-]+0?([0-9]*)address@hidden(${VPre}4,${VPre}5,${VPre}6,${VPre}2,${VPre}3,${VPre}1)";
  
***************
*** 175,179 ****
                                                                        'no CSV 
1'              =>      "type${PSep}phone",
                                                                        'no CSV 
2'              =>      "address@hidden(${CPre}Notiz$CPos,0,60).' ...'" );
! 
                $info_name_options = "<option value=\"\">none\n";
                while (list($field,$name) = each($info_names)) {
--- 190,194 ----
                                                                        'no CSV 
1'              =>      "type${PSep}phone",
                                                                        'no CSV 
2'              =>      "address@hidden(${CPre}Notiz$CPos,0,60).' ...'" );
!               */
                $info_name_options = "<option value=\"\">none\n";
                while (list($field,$name) = each($info_names)) {
***************
*** 244,262 ****
                $fp=fopen($csvfile,"r");
                $csv_fields = fgetcsv($fp,8000,$fieldsep);
  
                $info_fields = array_diff($info_fields,array( '' ));    // 
throw away empty / not assigned entrys
  
!               if ($pref_file) {
!                       // echo "writing pref_file ...<p>";
!                       if (file_exists($pref_file)) 
rename($pref_file,$pref_file.'.old');
!                       $pref = fopen($pref_file,'w');
!                       while (list($csv_idx,$info) = each($info_fields)) {
!                               $defaults[$csv_fields[$csv_idx]] = $info;
!                               if ($trans[$csv_idx])
!                                       $defaults[$csv_fields[$csv_idx]] .= 
$PSep.$trans[$csv_idx];
                        }
-                       fwrite($pref,'$defaults = array'.dump_array( $defaults 
).';');
-                       fclose($pref);
                }
                $log = "<table border=1>\n\t<tr><td>#</td>\n";
  
--- 259,283 ----
                $fp=fopen($csvfile,"r");
                $csv_fields = fgetcsv($fp,8000,$fieldsep);
+               $csv_fields[] = 'no CSV 1';                                     
        // eg. for static assignments
+               $csv_fields[] = 'no CSV 2';
+               $csv_fields[] = 'no CSV 3';
  
                $info_fields = array_diff($info_fields,array( '' ));    // 
throw away empty / not assigned entrys
  
!               $defaults = array();
!               while (list($csv_idx,$info) = each($info_fields))
!               {       // convert $trans[$csv_idx] into array of pattern => 
value
!                       $defaults[$csv_fields[$csv_idx]] = $info;
!                       if ($trans[$csv_idx])
!                       {
!                               $defaults[$csv_fields[$csv_idx]] .= 
$PSep.addslashes($trans[$csv_idx]);
                        }
                }
+ 
+               $GLOBALS['phpgw']->preferences->read_repository();
+               $test = 
$GLOBALS['phpgw']->preferences->add('infolog','cvs_import',$defaults);
+               echo "add('infolog','cvs_import',defaults) ="; 
_debug_array($test);
+               $GLOBALS['phpgw']->preferences->save_repository(True);
+ 
                $log = "<table border=1>\n\t<tr><td>#</td>\n";
  
***************
*** 297,305 ****
                                                        // echo "'$val'</p>";
  
-                                                       $quote = $val[0] == '@' 
? "'" : '';
- 
                                                        $reg = 
$CPreReg.'([a-zA-Z_0-9]+)'.$CPosReg;
                                                        while 
(ereg($reg,$val,$vars)) { // expand all CSV fields
!                                                               $val = 
str_replace($CPre.$vars[1].$CPos,$quote.$fields[index($vars[1],$csv_fields)].$quote,$val);
                                                        }
                                                        if ($val[0] == '@') {
--- 318,324 ----
                                                        // echo "'$val'</p>";
  
                                                        $reg = 
$CPreReg.'([a-zA-Z_0-9]+)'.$CPosReg;
                                                        while 
(ereg($reg,$val,$vars)) { // expand all CSV fields
!                                                               $val = 
str_replace($CPre.$vars[1].$CPos,$val[0] == '@' ? 
"'".addslashes($fields[index($vars[1],$csv_fields)])."'" : 
$fields[index($vars[1],$csv_fields)],$val);
                                                        }
                                                        if ($val[0] == '@') {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]