[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] addressbook csv_import.php, 1.4.2.6.2.3, 1.4.2.6.2.4
From: |
Jonathan Rivera <address@hidden> |
Subject: |
[Phpgroupware-cvs] addressbook csv_import.php, 1.4.2.6.2.3, 1.4.2.6.2.4 |
Date: |
Sun, 26 Oct 2003 04:50:45 +0000 |
Update of /cvsroot/phpgroupware/addressbook
In directory subversions:/tmp/cvs-serv3415/addressbook
Modified Files:
Tag: Version-0_9_16-branch
csv_import.php
Log Message:
Csv import now works with new contacts backend. I do some changes in ui, now
you can select a category from yours categories and can select the owner too.
Index: csv_import.php
===================================================================
RCS file: /cvsroot/phpgroupware/addressbook/csv_import.php,v
retrieving revision 1.4.2.6.2.3
retrieving revision 1.4.2.6.2.4
diff -C2 -d -r1.4.2.6.2.3 -r1.4.2.6.2.4
*** csv_import.php 8 Sep 2003 13:26:35 -0000 1.4.2.6.2.3
--- csv_import.php 26 Oct 2003 04:50:42 -0000 1.4.2.6.2.4
***************
*** 67,133 ****
}
- // 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)
- {
- $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");
- }
- if(!count($addrs))
- {
- $addrs =
$GLOBALS['phpgw']->contacts->read(0,0,array('id'),'',"n_family=$n_family,org_name=$org_name");
- }
-
- if(count($addrs))
- {
- return $addrs[0]['id'];
- }
-
- return False;
- }
$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;
- }
switch($_POST['action'])
--- 67,73 ----
***************
*** 161,172 ****
. '<input type="hidden" name="fieldsep"
value="'.$_POST['fieldsep']."\">\n";
! $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',
! 'address2' => 'address line 2',
! 'address3' => 'address line 3',
! 'ophone' => 'Other Phone'
! );
$config = CreateObject('phpgwapi.config','addressbook');
$config->read_repository();
--- 101,115 ----
. '<input type="hidden" name="fieldsep"
value="'.$_POST['fieldsep']."\">\n";
!
! $field_names =
$GLOBALS['phpgw']->contacts->import_fields;
! $loc_names = $field_names['locations'];
! unset($field_names['locations']);
! $comm_name =
linearize_query($GLOBALS['phpgw']->contacts->get_contact_comm_descr(),'comm_description');
! $location_types =
linearize_query($GLOBALS['phpgw']->contacts->get_contact_addr_type(),
'addr_description');
!
! $loc_names = set_location_type($location_types,
$loc_names);
!
! $addr_names = $field_names + $comm_name + $loc_names;
!
$config = CreateObject('phpgwapi.config','addressbook');
$config->read_repository();
***************
*** 190,196 ****
}
$csv_fields = fgetcsv($fp,8000,$_POST['fieldsep']);
! $csv_fields[] = 'no CSV 1'; // eg. for static
assignments
! $csv_fields[] = 'no CSV 2';
! $csv_fields[] = 'no CSV 3';
foreach($csv_fields as $csv_idx => $csv_field)
{
--- 133,137 ----
}
$csv_fields = fgetcsv($fp,8000,$_POST['fieldsep']);
!
foreach($csv_fields as $csv_idx => $csv_field)
{
***************
*** 210,213 ****
--- 151,173 ----
$GLOBALS['phpgw']->template->parse('fieldshandle','fields',True);
}
+
+
$GLOBALS['phpgw']->template->set_var('csv_field','Categories');
+
$GLOBALS['phpgw']->template->set_var('csv_idx','cat_id');
+ $GLOBALS['phpgw']->template->set_var('trans','');
+
$GLOBALS['phpgw']->template->set_var('addr_fields',get_categories());
+
$GLOBALS['phpgw']->template->parse('fieldshandle','fields',True);
+
+
$GLOBALS['phpgw']->template->set_var('csv_field','Access');
+
$GLOBALS['phpgw']->template->set_var('csv_idx','access');
+ $GLOBALS['phpgw']->template->set_var('trans','');
+
$GLOBALS['phpgw']->template->set_var('addr_fields',get_access());
+
$GLOBALS['phpgw']->template->parse('fieldshandle','fields',True);
+
+
$GLOBALS['phpgw']->template->set_var('csv_field','Owner');
+ $GLOBALS['phpgw']->template->set_var('csv_idx','owner');
+ $GLOBALS['phpgw']->template->set_var('trans','');
+
$GLOBALS['phpgw']->template->set_var('addr_fields',get_owner());
+
$GLOBALS['phpgw']->template->parse('fieldshandle','fields',True);
+
$GLOBALS['phpgw']->template->set_var('lang_start',lang('Startrecord'));
$GLOBALS['phpgw']->template->set_var('start',$_POST['start']);
***************
*** 258,266 ****
$fp=fopen($csvfile,'rb');
$csv_fields = fgetcsv($fp,8000,$_POST['fieldsep']);
- $csv_fields[] = 'no CSV 1'; // eg. for static
assignments
- $csv_fields[] = 'no CSV 2';
- $csv_fields[] = 'no CSV 3';
$addr_fields =
array_diff($_POST['addr_fields'],array('')); // throw away empty / not
assigned entrys
$defaults = array();
--- 218,233 ----
$fp=fopen($csvfile,'rb');
$csv_fields = fgetcsv($fp,8000,$_POST['fieldsep']);
+ $cat_id = $_POST['addr_fields']['cat_id'];
+ $access = $_POST['addr_fields']['access'];
+ $owner = $_POST['addr_fields']['owner'];
+ unset($_POST['addr_fields']['cat_id']);
+ unset($_POST['addr_fields']['access']);
+ unset($_POST['addr_fields']['owner']);
$addr_fields =
array_diff($_POST['addr_fields'],array('')); // throw away empty / not
assigned entrys
+ $all_fields =
$GLOBALS['phpgw']->contacts->import_fields;
+ $location_fields = array_keys($all_fields['locations']);
+ unset($all_fields['locations']);
+ $comm_fields =
linearize_query($GLOBALS['phpgw']->contacts->get_contact_comm_descr(),'comm_description');
$defaults = array();
***************
*** 281,286 ****
foreach($addr_fields as $csv_idx => $addr)
! { // convert $_POST['trans'][$csv_idx] into array
of pattern => value
! // if (!$_POST['debug']) echo "<p>$csv_idx:
".$csv_fields[$csv_idx].": $addr".($_POST['trans'][$csv_idx] ? ':
'.$_POST['trans'][$csv_idx] : '')."</p>";
$pat_reps =
explode($PSep,stripslashes($_POST['trans'][$csv_idx]));
$replaces = ''; $values = '';
--- 248,252 ----
foreach($addr_fields as $csv_idx => $addr)
! {
$pat_reps =
explode($PSep,stripslashes($_POST['trans'][$csv_idx]));
$replaces = ''; $values = '';
***************
*** 305,314 ****
$log .= "\t\t<td><b>$addr</b></td>\n";
}
- if (!in_array('fn',$addr_fields)) // autocreate
full name, if not set by user
- {
- $log .= "\t\t<td><b>fn</b></td>\n";
-
- $auto_fn =
array('n_prefix','n_given','n_middle','n_family','n_suffix');
- }
$start = $_POST['start'] < 1 ? 1 : $_POST['start'];
--- 271,274 ----
***************
*** 364,386 ****
}
}
! $values[$addr] = $val;
!
! $log .= "\t\t<td>$val</td>\n";
! }
! // if (!isset($values['datecreated']))
$values['datecreated'] = $values['startdate'];
!
! if (is_array($auto_fn) &&
!isset($values['fn'])) // autocreate full name
! {
! reset($auto_fn);
! while (list($idx,$name) =
each($auto_fn))
{
! $values['fn'] .= ($values['fn']
!= '' && $values[$name] != '' ? ' ' : '') . $values[$name];
}
! $log .=
"\t\t<td>".$values['fn']."</td>\n";
}
if(!$_POST['debug'])
{
! $GLOBALS['phpgw']->contacts->add(
$values['owner'] ? $values['owner'] :
$GLOBALS['phpgw_info']['user']['account_id'],
!
$values,$values['access'],$values['cat_id']);
// echo "<p>adding:
".dump_array($values)."</p>\n";
}
--- 324,352 ----
}
}
! //$values[$addr] = $val;
! if(in_array($addr, $comm_fields))
{
!
$fields_to_add['comm_media'][$addr] = $val;
}
!
elseif(in_array(substr($addr,strpos($addr, '_') +1), $location_fields))
! {
! $type = substr($addr,0,
strpos($addr, '_') );
! $data =
substr($addr,strpos($addr, '_') +1);
!
$fields_to_add['locations'][$type]['type'] = $type;
!
$fields_to_add['locations'][$type][$data] = $val;
! }
! else
! {
! $fields_to_add[$addr] = $val;
! }
!
! $log .= "\t\t<td>$val</td>\n";
}
+ $fields_to_add['categories'] = array($cat_id);
+ $fields_to_add['access'] = $access;
+ $fields_to_add['owner'] = $owner;
if(!$_POST['debug'])
{
!
$GLOBALS['phpgw']->contacts->contact_import($fields_to_add);
// echo "<p>adding:
".dump_array($values)."</p>\n";
}
***************
*** 399,401 ****
--- 365,424 ----
$GLOBALS['phpgw']->template->pfp('out','import',True);
$GLOBALS['phpgw']->common->phpgw_footer();
+
+ function linearize_query($qresult,$key)
+ {
+ //print_r($qresult);
+ reset($qresult);
+ for($i=0;$i < count($qresult);$i++)
+ {
+ $ret[$qresult[$i][$key]]=$qresult[$i][$key];
+ }
+ return $ret;
+ }
+
+ function set_location_type($location_types=array(),
$location_fields=array())
+ {
+ foreach($location_types as $type)
+ {
+ foreach($location_fields as $key => $field)
+ {
+ $locations[$type . '_' . $key] = $type . ' ' .
$field;
+ }
+ }
+ return $locations;
+ }
+
+ function get_categories()
+ {
+ $cat = CreateObject('phpgwapi.categories');
+ $cats_link = $cat->formated_list('select','all',$cat_id,True);
+ return $cats_link;
+ }
+
+ function get_access()
+ {
+ $access = '<option>public</option>';
+ $access .= '<option>private</option>';
+ return $access;
+ }
+
+ function get_owner()
+ {
+ $account_list =
$GLOBALS['phpgw']->accounts->get_list('accounts');
+ if (is_array($account_list))
+ {
+ foreach($account_list as $entry)
+ {
+ $user_list .= '<option value="' .
$entry['account_id'] . '"'
+ . $selected . '>'
+ .
$GLOBALS['phpgw']->common->display_fullname(
+ $entry['account_lid'],
+ $entry['account_firstname'],
+ $entry['account_lastname'])
+ . '</option>'."\n";
+ }
+ }
+ return $user_list;
+ }
+
?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] addressbook csv_import.php, 1.4.2.6.2.3, 1.4.2.6.2.4,
Jonathan Rivera <address@hidden> <=