From 33549dcf9e75fe5cfae0548e2d663c843a6c46e6 Mon Sep 17 00:00:00 2001 From: Miles Lott Date: Tue, 19 Mar 2002 02:58:50 +0000 Subject: [PATCH] formatting --- addressbook/csv_import.php | 191 +++++++++++++++-------------- addressbook/inc/hook_admin.inc.php | 6 +- addressbook/setup/setup.inc.php | 5 +- 3 files changed, 104 insertions(+), 98 deletions(-) diff --git a/addressbook/csv_import.php b/addressbook/csv_import.php index 10e84d8edd..7983121169 100644 --- a/addressbook/csv_import.php +++ b/addressbook/csv_import.php @@ -26,10 +26,10 @@ $GLOBALS['phpgw']->template->set_block('import','ffooter','ffooterhandle'); $GLOBALS['phpgw']->template->set_block('import','imported','importedhandle'); - if ($action == 'download' && (!$fieldsep || !$csvfile || !($fp=fopen($csvfile,'r')))) + if($action == 'download' && (!$fieldsep || !$csvfile || !($fp=fopen($csvfile,'rb')))) { $action = ''; - } + } $GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/addressbook/csv_import.php')); $GLOBALS['phpgw']->template->set_var('lang_addr_action',lang('Import CSV-File into Addressbook')); @@ -39,20 +39,20 @@ $CPre = '|['; $CPreReg = '\|\['; // |{csv-fieldname} is expanded to the value of the csv-field $CPos = ']'; $CPosReg = '\]'; // if used together with @ (replacement is eval-ed) value gets autom. quoted - function dump_array( $arr ) + function dump_array($arr) { - while (list($key,$val) = each($arr)) + while(is_array($arr) && (list($key,$val) = each($arr))) { $ret .= ($ret ? ',' : '(') . "'$key' => '$val'\n"; } return $ret.')'; } - function index( $value,$arr ) + function index($value,$arr) { - while (list ($key,$val) = each($arr)) + while(is_array($arr) && (list($key,$val) = each($arr))) { - if ($value == $val) + if($value == $val) { return $key; } @@ -61,70 +61,70 @@ } // find in Addressbook, at least n_family AND (n_given OR org_name) have to match - function addr_id( $n_family,$n_given,$org_name ) + function addr_id($n_family,$n_given,$org_name) { - $addrs = $GLOBALS['phpgw']->contacts->read( 0,0,array('id'),'',"n_family=$n_family,n_given=$n_given,org_name=$org_name" ); - if (!count($addrs)) + $addrs = $GLOBALS['phpgw']->contacts->read(0,0,array('id'),'',"n_family=$n_family,n_given=$n_given,org_name=$org_name"); + if(!count($addrs)) { - $addrs = $GLOBALS['phpgw']->contacts->read( 0,0,array('id'),'',"n_family=$n_family,n_given=$n_given" ); + $addrs = $GLOBALS['phpgw']->contacts->read(0,0,array('id'),'',"n_family=$n_family,n_given=$n_given"); } - if (!count($addrs)) + if(!count($addrs)) { - $addrs = $GLOBALS['phpgw']->contacts->read( 0,0,array('id'),'',"n_family=$n_family,org_name=$org_name" ); + $addrs = $GLOBALS['phpgw']->contacts->read(0,0,array('id'),'',"n_family=$n_family,org_name=$org_name"); } - if (count($addrs)) + if(count($addrs)) { return $addrs[0]['id']; } - return False; + return False; } - $cat2id = array( ); + $cat2id = array(); function cat_id($cats) { - if (!$cats) + if(!$cats) { return ''; } $cats = split('[,;]',$cats); - while (list($k,$cat) = each($cats)) + while(list($k,$cat) = each($cats)) { - if (isset($cat2id[$cat])) + if(isset($cat2id[$cat])) { $ids[$cat] = $cat2id[$cat]; // cat is in cache } else { - if (!is_object($GLOBALS['phpgw']->categories)) + if(!is_object($GLOBALS['phpgw']->categories)) { $GLOBALS['phpgw']->categories = createobject('phpgwapi.categories'); - } - if ($id = $GLOBALS['phpgw']->categories->name2id( addslashes($cat) )) + } + 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) ); + $GLOBALS['phpgw']->categories->add(array('name' => $cat,'descr' => $cat)); + $cat2id[$cat] = $ids[$cat] = $GLOBALS['phpgw']->categories->name2id(addslashes($cat)); } } } - $id_str = implode( ',',$ids ); + $id_str = implode(',',$ids); - if (count($ids) > 1) // multiple cats need to be in ',' + if(count($ids) > 1) // multiple cats need to be in ',' { $id_str = ",$id_str,"; } return $id_str; } - switch ($action) + switch($action) { case '': // Start, ask Filename $GLOBALS['phpgw']->template->set_var('lang_csvfile',lang('CSV-Filename')); @@ -141,7 +141,7 @@ case 'download': $GLOBALS['phpgw']->preferences->read_repository(); $defaults = $GLOBALS['phpgw_info']['user']['preferences']['addressbook']['cvs_import']; - if (!is_array($defaults)) + if(!is_array($defaults)) { $defaults = array(); } @@ -157,33 +157,33 @@ $addr_names = $GLOBALS['phpgw']->contacts->stock_contact_fields + array( 'cat_id' => 'Categories: @cat_id(Cat1,Cat2)', 'access' => 'Access: public,private', - 'owner' => 'Owner: defaults to user' + 'owner' => 'Owner: defaults to user' ); - while (list($field,$name) = each($addr_names)) + while(list($field,$name) = each($addr_names)) { - if ($dn = display_name($field)) + if($dn = display_name($field)) { $addr_names[$field] = $dn; } } $addr_name_options = "