forked from extern/egroupware
include next and last date in csv export and use same fields for nextmatch csv export
This commit is contained in:
parent
4edd90a8bf
commit
28654c560e
@ -926,6 +926,86 @@ class addressbook_bo extends addressbook_so
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the next and last event of given contacts
|
||||
*
|
||||
* @param array $ids contact_id's
|
||||
* @param boolean $extra_title=true if true, use a short date only title and put the full title as extra_title (tooltip)
|
||||
* @return array
|
||||
*/
|
||||
function read_calendar($ids,$extra_title=true)
|
||||
{
|
||||
if (!$GLOBALS['egw_info']['user']['apps']['calendar']) return null;
|
||||
|
||||
$uids = array();
|
||||
foreach($ids as $id)
|
||||
{
|
||||
if (is_numeric($id)) $uids[] = 'c'.$id;
|
||||
}
|
||||
if (!$uids) return array();
|
||||
|
||||
include_once(EGW_INCLUDE_ROOT.'/calendar/inc/class.bocal.inc.php');
|
||||
$bocal = new bocal;
|
||||
$events = $bocal->search(array(
|
||||
'users' => $uids,
|
||||
'enum_recuring' => true,
|
||||
));
|
||||
if (!$events) return array();
|
||||
|
||||
//_debug_array($events);
|
||||
$calendars = array();
|
||||
foreach($events as $event)
|
||||
{
|
||||
foreach($event['participants'] as $uid => $status)
|
||||
{
|
||||
if ($uid{0} != 'c' || ($status == 'R' && !$GLOBALS['egw_info']['user']['preferences']['calendar']['show_rejected']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$id = (int)substr($uid,1);
|
||||
|
||||
if ($event['start'] < $this->now_su) // past event --> check for last event
|
||||
{
|
||||
if (!isset($calendars[$id]['last_event']) || $event['start'] > $calendars[$id]['last_event'])
|
||||
{
|
||||
$calendars[$id]['last_event'] = $event['start'];
|
||||
$link = array(
|
||||
'id' => $event['id'],
|
||||
'app' => 'calendar',
|
||||
'title' => $bocal->link_title($event),
|
||||
);
|
||||
if ($extra_title)
|
||||
{
|
||||
$link['extra_title'] = $link['title'];
|
||||
$link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],$event['start']);
|
||||
}
|
||||
$calendars[$id]['last_link'] = $link;
|
||||
}
|
||||
}
|
||||
else // future event --> check for next event
|
||||
{
|
||||
if (!isset($calendars[$id]['next_event']) || $event['start'] < $calendars[$id]['next_event'])
|
||||
{
|
||||
$calendars[$id]['next_event'] = $event['start'];
|
||||
$link = array(
|
||||
'id' => $event['id'],
|
||||
'app' => 'calendar',
|
||||
'title' => $bocal->link_title($event),
|
||||
);
|
||||
if ($extra_title)
|
||||
{
|
||||
$link['extra_title'] = $link['title'];
|
||||
$link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],$event['start']);
|
||||
}
|
||||
$calendars[$id]['next_link'] = $link;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//_debug_array($calendars);
|
||||
return $calendars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by delete-account hook, when an account get deleted --> deletes/moves the personal addressbook
|
||||
*
|
||||
|
@ -16,12 +16,29 @@
|
||||
*/
|
||||
class addressbook_csv
|
||||
{
|
||||
/**
|
||||
* Addressbook Instance
|
||||
*
|
||||
* @var addressbook_bo
|
||||
*/
|
||||
var $obj;
|
||||
var $charset;
|
||||
var $charset_out;
|
||||
var $separator;
|
||||
static $types = array(
|
||||
'select-account' => array('owner','creator','modifier'),
|
||||
'date-time' => array('modified','created','last_event','next_event'),
|
||||
'select-cat' => array('cat_id'),
|
||||
);
|
||||
|
||||
function __construct($obj,$charset=null,$separator=';')
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param addressbook_bo $obj
|
||||
* @param string $charset
|
||||
* @param string $separator
|
||||
*/
|
||||
function __construct(addressbook_bo $obj,$charset=null,$separator=';')
|
||||
{
|
||||
$this->obj = $obj;
|
||||
$this->separator = $separator;
|
||||
@ -33,13 +50,15 @@ class addressbook_csv
|
||||
* Exports some contacts as CSV: download or write to a file
|
||||
*
|
||||
* @param array $ids contact-ids
|
||||
* @param array $fields
|
||||
* @param array $fields=null default csv_fields() = all fields
|
||||
* @param string $file filename or null for download
|
||||
*/
|
||||
function export($ids,$fields,$file=null)
|
||||
function export($ids,$fields=null,$file=null)
|
||||
{
|
||||
unset($fields['jpegphoto']);
|
||||
|
||||
if (is_null($fields))
|
||||
{
|
||||
$fields = $this->csv_fields();
|
||||
}
|
||||
if (!$file)
|
||||
{
|
||||
$browser = new browser();
|
||||
@ -51,12 +70,20 @@ class addressbook_csv
|
||||
}
|
||||
fwrite($fp,$this->csv_encode($fields,$fields)."\n");
|
||||
|
||||
if (isset($fields['last_event']) || isset($fields['next_event']))
|
||||
{
|
||||
$events = $this->obj->read_calendar($ids);
|
||||
}
|
||||
foreach($ids as $id)
|
||||
{
|
||||
if (!($data = $this->obj->read($id)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ($events && isset($events[$id]) && is_array($events[$id]))
|
||||
{
|
||||
$data += $events[$id];
|
||||
}
|
||||
$this->csv_prepare($data,$fields);
|
||||
|
||||
fwrite($fp,$this->csv_encode($data,$fields)."\n");
|
||||
@ -70,6 +97,13 @@ class addressbook_csv
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* export and encode one row
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $fields
|
||||
* @return string
|
||||
*/
|
||||
function csv_encode($data,$fields)
|
||||
{
|
||||
$out = array();
|
||||
@ -91,9 +125,15 @@ class addressbook_csv
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a line of the export: replace id's and timestamps with more readable values
|
||||
*
|
||||
* @param array &$data
|
||||
* @param array $fields
|
||||
*/
|
||||
function csv_prepare(&$data,$fields)
|
||||
{
|
||||
foreach(array('owner','creator','modifier') as $name)
|
||||
foreach(self::$types['select-account'] as $name)
|
||||
{
|
||||
if ($data[$name])
|
||||
{
|
||||
@ -104,7 +144,7 @@ class addressbook_csv
|
||||
$data[$name] = lang('Accounts');
|
||||
}
|
||||
}
|
||||
foreach(array('modified','created') as $name)
|
||||
foreach(self::$types['date-time'] as $name)
|
||||
{
|
||||
if ($data[$name]) $data[$name] = date('Y-m-d H:i:s',$data[$name]);
|
||||
}
|
||||
@ -122,4 +162,52 @@ class addressbook_csv
|
||||
$data['n_fileas'] = $this->obj->fileas($data);
|
||||
$data['n_fn'] = $this->obj->fullname($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the fields to export
|
||||
*
|
||||
* @param string $csv_pref 'home', 'business' or default all
|
||||
* @param boolean $include_type=false include type information for nextmatchs csv export
|
||||
* @return array with name => label pairs
|
||||
*/
|
||||
function csv_fields($csv_pref=null,$include_type=false)
|
||||
{
|
||||
switch ($csv_pref)
|
||||
{
|
||||
case 'business':
|
||||
$fields = $this->obj->business_contact_fields;
|
||||
break;
|
||||
case 'home':
|
||||
$fields = $this->obj->home_contact_fields;
|
||||
break;
|
||||
default:
|
||||
$fields = $this->obj->contact_fields;
|
||||
foreach($this->obj->customfields as $name => $data)
|
||||
{
|
||||
$fields['#'.$name] = $data['label'];
|
||||
}
|
||||
$fields['last_event'] = lang('Last date');
|
||||
$fields['next_event'] = lang('Next date');
|
||||
break;
|
||||
}
|
||||
unset($fields['jpegphoto']);
|
||||
|
||||
if ($include_type)
|
||||
{
|
||||
foreach(self::$types as $type => $names)
|
||||
{
|
||||
foreach($names as $name)
|
||||
{
|
||||
if (isset($fields[$name]))
|
||||
{
|
||||
$fields[$name] = array(
|
||||
'type' => $type,
|
||||
'label' => $fields[$name],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
}
|
@ -185,8 +185,11 @@ class addressbook_ui extends addressbook_bo
|
||||
'do_email' => $do_email,
|
||||
'default_cols' => '!cat_id,contact_created_contact_modified,distribution_list',
|
||||
'filter2_onchange' => "if(this.value=='add') { add_new_list(document.getElementById(form::name('filter')).value); this.value='';} else this.form.submit();",
|
||||
'manual' => $do_email ? ' ' : false, // space for the manual icon
|
||||
'manual' => $do_email ? ' ' : false, // space for the manual icon
|
||||
);
|
||||
$csv_export = new addressbook_csv($this);
|
||||
$content['nm']['csv_fields'] = $csv_export->csv_fields(null,true);
|
||||
|
||||
if ($do_email)
|
||||
{
|
||||
$content['nm']['filter2_onchange'] = str_replace('this.form.submit();',
|
||||
@ -505,23 +508,7 @@ class addressbook_ui extends addressbook_bo
|
||||
case 'csv':
|
||||
$action_msg = lang('exported');
|
||||
$csv_export = new addressbook_csv($this,$this->prefs['csv_charset']);
|
||||
switch ($this->prefs['csv_fields'])
|
||||
{
|
||||
case 'business':
|
||||
$fields = $this->business_contact_fields;
|
||||
break;
|
||||
case 'home':
|
||||
$fields = $this->home_contact_fields;
|
||||
break;
|
||||
default:
|
||||
$fields = $this->contact_fields;
|
||||
foreach($this->customfields as $name => $data)
|
||||
{
|
||||
$fields['#'.$name] = $data['label'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
$csv_export->export($checked,$fields);
|
||||
$csv_export->export($checked,$csv_export->csv_fields($this->prefs['csv_fields']));
|
||||
// does not return!
|
||||
$Ok = true;
|
||||
break;
|
||||
@ -2091,86 +2078,6 @@ $readonlys['button[vcard]'] = true;
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the next and last event of given contacts
|
||||
*
|
||||
* @param array $ids contact_id's
|
||||
* @param boolean $extra_title=true if true, use a short date only title and put the full title as extra_title (tooltip)
|
||||
* @return array
|
||||
*/
|
||||
function read_calendar($ids,$extra_title=true)
|
||||
{
|
||||
if (!$GLOBALS['egw_info']['user']['apps']['calendar']) return null;
|
||||
|
||||
$uids = array();
|
||||
foreach($ids as $id)
|
||||
{
|
||||
if (is_numeric($id)) $uids[] = 'c'.$id;
|
||||
}
|
||||
if (!$uids) return array();
|
||||
|
||||
include_once(EGW_INCLUDE_ROOT.'/calendar/inc/class.bocal.inc.php');
|
||||
$bocal = new bocal;
|
||||
$events = $bocal->search(array(
|
||||
'users' => $uids,
|
||||
'enum_recuring' => true,
|
||||
));
|
||||
if (!$events) return array();
|
||||
|
||||
//_debug_array($events);
|
||||
$calendars = array();
|
||||
foreach($events as $event)
|
||||
{
|
||||
foreach($event['participants'] as $uid => $status)
|
||||
{
|
||||
if ($uid{0} != 'c' || ($status == 'R' && !$GLOBALS['egw_info']['user']['preferences']['calendar']['show_rejected']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$id = (int)substr($uid,1);
|
||||
|
||||
if ($event['start'] < $this->now_su) // past event --> check for last event
|
||||
{
|
||||
if (!isset($calendars[$id]['last_event']) || $event['start'] > $calendars[$id]['last_event'])
|
||||
{
|
||||
$calendars[$id]['last_event'] = $event['start'];
|
||||
$link = array(
|
||||
'id' => $event['id'],
|
||||
'app' => 'calendar',
|
||||
'title' => $bocal->link_title($event),
|
||||
);
|
||||
if ($extra_title)
|
||||
{
|
||||
$link['extra_title'] = $link['title'];
|
||||
$link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],$event['start']);
|
||||
}
|
||||
$calendars[$id]['last_link'] = $link;
|
||||
}
|
||||
}
|
||||
else // future event --> check for next event
|
||||
{
|
||||
if (!isset($calendars[$id]['next_event']) || $event['start'] < $calendars[$id]['next_event'])
|
||||
{
|
||||
$calendars[$id]['next_event'] = $event['start'];
|
||||
$link = array(
|
||||
'id' => $event['id'],
|
||||
'app' => 'calendar',
|
||||
'title' => $bocal->link_title($event),
|
||||
);
|
||||
if ($extra_title)
|
||||
{
|
||||
$link['extra_title'] = $link['title'];
|
||||
$link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],$event['start']);
|
||||
}
|
||||
$calendars[$id]['next_link'] = $link;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//_debug_array($calendars);
|
||||
return $calendars;
|
||||
}
|
||||
|
||||
/**
|
||||
* add a new categorie to any addressbock entry
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user