Fixes for globals and session data - which is mostly unused for now

This commit is contained in:
Miles Lott 2003-10-19 07:00:53 +00:00
parent 760bed3735
commit 4a49600904
2 changed files with 113 additions and 56 deletions

View File

@ -31,8 +31,9 @@
var $cat_id; var $cat_id;
var $use_session = False; var $use_session = False;
var $debug = False;
function boXport ($session=False) function boXport($session=False)
{ {
$this->contacts = $GLOBALS['phpgw']->contacts; $this->contacts = $GLOBALS['phpgw']->contacts;
$this->so = CreateObject('addressbook.soaddressbook'); $this->so = CreateObject('addressbook.soaddressbook');
@ -41,32 +42,60 @@
$this->read_sessiondata(); $this->read_sessiondata();
$this->use_session = True; $this->use_session = True;
} }
global $start,$limit,$query,$sort,$order,$filter,$cat_id; $_start = get_var('_start',array('POST','GET'));
$_query = get_var('_query',array('POST','GET'));
$_sort = get_var('_sort',array('POST','GET'));
$_order = get_var('_order',array('POST','GET'));
$_filter = get_var('_filter',array('POST','GET'));
$_cat_id = get_var('_cat_id',array('POST','GET'));
$_fcat_id = get_var('_fcat_id',array('POST','GET'));
if($start || $start == 0) { $this->start = $start; } if(!empty($_start) || ($_start == '0') || ($_start == 0))
if($limit) { $this->limit = $limit; } {
if($query) { $this->query = $query; } if($this->debug) { echo '<br>overriding $start: "' . $this->start . '" now "' . $_start . '"'; }
if($sort) { $this->sort = $sort; } $this->start = $_start;
if($order) { $this->order = $order; } }
if($filter) { $this->filter = $filter; } if($_limit)
$this->cat_id = $cat_id; {
$this->limit = $_limit;
}
if((empty($_query) && !empty($this->query)) || !empty($_query))
{
$this->query = $_query;
} }
function save_sessiondata() if(isset($GLOBALS['HTTP_POST_VARS']['fcat_id']) || isset($GLOBALS['HTTP_POST_VARS']['fcat_id']))
{ {
global $start,$limit,$query,$sort,$order,$filter,$cat_id; $this->cat_id = $_fcat_id;
}
else
{
$this->cat_id = -1;
}
if ($this->use_session) if(isset($_sort) && !empty($_sort))
{
if($this->debug) { echo '<br>overriding $sort: "' . $this->sort . '" now "' . $_sort . '"'; }
$this->sort = $_sort;
}
if(isset($_order) && !empty($_order))
{
if($this->debug) { echo '<br>overriding $order: "' . $this->order . '" now "' . $_order . '"'; }
$this->order = $_order;
}
if(isset($_filter) && !empty($_filter))
{
if($this->debug) { echo '<br>overriding $filter: "' . $this->filter . '" now "' . $_filter . '"'; }
$this->filter = $_filter;
}
}
function save_sessiondata($data)
{
if($this->use_session)
{ {
$data = array(
'start' => $start,
'limit' => $limit,
'query' => $query,
'sort' => $sort,
'order' => $order,
'filter' => $filter,
'cat_id' => $cat_id
);
if($this->debug) { echo '<br>Save:'; _debug_array($data); } if($this->debug) { echo '<br>Save:'; _debug_array($data); }
$GLOBALS['phpgw']->session->appsession('session_data','addressbook',$data); $GLOBALS['phpgw']->session->appsession('session_data','addressbook',$data);
} }
@ -84,26 +113,30 @@
$this->order = $data['order']; $this->order = $data['order'];
$this->filter = $data['filter']; $this->filter = $data['filter'];
$this->cat_id = $data['cat_id']; $this->cat_id = $data['cat_id'];
if($this->debug) { echo '<br>read_sessiondata();'; $this->_debug_sqsof(); }
} }
function import($tsvfile,$conv_type,$private,$fcat_id) function import($tsvfile,$conv_type,$private,$fcat_id)
{ {
include (PHPGW_APP_INC . '/import/' . $conv_type); include(PHPGW_APP_INC . '/import/' . $conv_type);
if ($private == '') { $private = 'public'; } if($private == '')
{
$private = 'public';
}
$row = 0; $row = 0;
$buffer = array(); $buffer = array();
$contacts = new import_conv; $contacts = new import_conv;
$buffer = $contacts->import_start_file($buffer); $buffer = $contacts->import_start_file($buffer);
$fp = fopen($tsvfile,'r'); $fp = fopen($tsvfile,'r');
if ($contacts->type == 'csv') if($contacts->type == 'csv')
{ {
while ($data = fgetcsv($fp,8000,',')) while($data = fgetcsv($fp,8000,','))
{ {
$num = count($data); $num = count($data);
$row++; $row++;
if ($row == 1) if($row == 1)
{ {
$header = $data; $header = $data;
/* Changed here to ignore the header, set to our array /* Changed here to ignore the header, set to our array
@ -116,10 +149,10 @@
else else
{ {
$buffer = $contacts->import_start_record($buffer); $buffer = $contacts->import_start_record($buffer);
for ($c=0; $c<$num; $c++ ) for($c=0; $c<$num; $c++ )
{ {
//Send name/value pairs along with the buffer //Send name/value pairs along with the buffer
if ($contacts->import[$header[$c]] != '' && $data[$c] != '') if($contacts->import[$header[$c]] != '' && $data[$c] != '')
{ {
$buffer = $contacts->import_new_attrib($buffer, $contacts->import[$header[$c]],$data[$c]); $buffer = $contacts->import_new_attrib($buffer, $contacts->import[$header[$c]],$data[$c]);
} }
@ -128,25 +161,25 @@
} }
} }
} }
elseif ($contacts->type == 'ldif') elseif($contacts->type == 'ldif')
{ {
while ($data = fgets($fp,8000)) while($data = fgets($fp,8000))
{ {
$url = ""; $url = "";
list($name,$value,$extra) = split(':', $data); list($name,$value,$extra) = split(':', $data);
if (substr($name,0,2) == 'dn') if(substr($name,0,2) == 'dn')
{ {
$buffer = $contacts->import_start_record($buffer); $buffer = $contacts->import_start_record($buffer);
} }
$test = trim($value); $test = trim($value);
if ($name && !empty($test) && $extra) if($name && !empty($test) && $extra)
{ {
// Probable url string // Probable url string
$url = $test; $url = $test;
$value = $extra; $value = $extra;
} }
elseif ($name && empty($test) && $extra) elseif($name && empty($test) && $extra)
{ {
// Probable multiline encoding // Probable multiline encoding
$newval = base64_decode(trim($extra)); $newval = base64_decode(trim($extra));
@ -154,21 +187,21 @@
//echo $name.':'.$value; //echo $name.':'.$value;
} }
if ($name && $value) if($name && $value)
{ {
$test = split(',mail=',$value); $test = split(',mail=',$value);
if ($test[1]) if($test[1])
{ {
$name = "mail"; $name = 'mail';
$value = $test[1]; $value = $test[1];
} }
if ($url) if($url)
{ {
$name = "homeurl"; $name = 'homeurl';
$value = $url. ':' . $value; $value = $url. ':' . $value;
} }
//echo '<br>'.$j.': '.$name.' => '.$value; //echo '<br>'.$j.': '.$name.' => '.$value;
if ($contacts->import[$name] != '' && $value != '') if($contacts->import[$name] != '' && $value != '')
{ {
$buffer = $contacts->import_new_attrib($buffer, $contacts->import[$name],$value); $buffer = $contacts->import_new_attrib($buffer, $contacts->import[$name],$value);
} }
@ -182,33 +215,33 @@
else else
{ {
$needToCallEndRecord = 0; $needToCallEndRecord = 0;
while ($data = fgets($fp,8000)) while($data = fgets($fp,8000))
{ {
$data = trim($data); $data = trim($data);
// RB 2001/05/07 added for Lotus Organizer // RB 2001/05/07 added for Lotus Organizer
while (substr($data,-1) == '=') while(substr($data,-1) == '=')
{ {
// '=' at end-of-line --> line to be continued with next line // '=' at end-of-line --> line to be continued with next line
$data = substr($data,0,-1) . trim(fgets($fp,8000)); $data = substr($data,0,-1) . trim(fgets($fp,8000));
} }
if (strstr($data,';ENCODING=QUOTED-PRINTABLE')) if(strstr($data,';ENCODING=QUOTED-PRINTABLE'))
{ {
// RB 2001/05/07 added for Lotus Organizer // RB 2001/05/07 added for Lotus Organizer
$data = quoted_printable_decode(str_replace(';ENCODING=QUOTED-PRINTABLE','',$data)); $data = quoted_printable_decode(str_replace(';ENCODING=QUOTED-PRINTABLE','',$data));
} }
list($name,$value) = explode(':', $data,2); // RB 2001/05/09 to allow ':' in Values (not only in URL's) list($name,$value) = explode(':', $data,2); // RB 2001/05/09 to allow ':' in Values (not only in URL's)
if (strtolower(substr($name,0,5)) == 'begin') if(strtolower(substr($name,0,5)) == 'begin')
{ {
$buffer = $contacts->import_start_record($buffer); $buffer = $contacts->import_start_record($buffer);
$needToCallEndRecord = 1; $needToCallEndRecord = 1;
} }
if ($name && $value) if($name && $value)
{ {
reset($contacts->import); reset($contacts->import);
while ( list($fname,$fvalue) = each($contacts->import) ) while(list($fname,$fvalue) = each($contacts->import))
{ {
if ( strstr(strtolower($name), $contacts->import[$fname]) ) if(strstr(strtolower($name), $contacts->import[$fname]))
{ {
$buffer = $contacts->import_new_attrib($buffer,$name,$value); $buffer = $contacts->import_new_attrib($buffer,$name,$value);
} }
@ -221,8 +254,10 @@
} }
} }
if($needToCallEndRecord) if($needToCallEndRecord)
{
$buffer = $contacts->import_end_record($buffer); $buffer = $contacts->import_end_record($buffer);
} }
}
fclose($fp); fclose($fp);
$buffer = $contacts->import_end_file($buffer,$private,$fcat_id); $buffer = $contacts->import_end_file($buffer,$private,$fcat_id);
@ -231,15 +266,15 @@
function export($conv_type,$cat_id='') function export($conv_type,$cat_id='')
{ {
include (PHPGW_APP_INC . '/export/' . $conv_type); include(PHPGW_APP_INC . '/export/' . $conv_type);
$buffer=array(); $buffer = array();
$contacts = new export_conv; $contacts = new export_conv;
// Read in user custom fields, if any // Read in user custom fields, if any
$customfields = array(); $customfields = array();
while (list($col,$descr) = @each($GLOBALS['phpgw_info']['user']['preferences']['addressbook'])) while(list($col,$descr) = @each($GLOBALS['phpgw_info']['user']['preferences']['addressbook']))
{ {
if ( substr($col,0,6) == 'extra_' ) if(substr($col,0,6) == 'extra_')
{ {
$field = ereg_replace('extra_','',$col); $field = ereg_replace('extra_','',$col);
$field = ereg_replace(' ','_',$field); $field = ereg_replace(' ','_',$field);
@ -251,12 +286,13 @@
'address2' => 'address2', 'address2' => 'address2',
'address3' => 'address3' 'address3' => 'address3'
); );
if ($contacts->type != 'vcard')
if($contacts->type != 'vcard')
{ {
$contacts->qfields = $contacts->stock_contact_fields;# + $extrafields;# + $customfields; $contacts->qfields = $contacts->stock_contact_fields;# + $extrafields;# + $customfields;
} }
if (!empty($cat_id)) if(!empty($cat_id))
{ {
$buffer = $contacts->export_start_file($buffer,$cat_id); $buffer = $contacts->export_start_file($buffer,$cat_id);
} }
@ -265,10 +301,10 @@
$buffer = $contacts->export_start_file($buffer); $buffer = $contacts->export_start_file($buffer);
} }
for ($i=0;$i<count($contacts->ids);$i++) for($i=0;$i<count($contacts->ids);$i++)
{ {
$buffer = $contacts->export_start_record($buffer); $buffer = $contacts->export_start_record($buffer);
while( list($name,$value) = each($contacts->currentrecord) ) while(list($name,$value) = each($contacts->currentrecord))
{ {
$buffer = $contacts->export_new_attrib($buffer,$name,$value); $buffer = $contacts->export_new_attrib($buffer,$name,$value);
} }

View File

@ -37,6 +37,11 @@
$this->bo = CreateObject('addressbook.boXport',True); $this->bo = CreateObject('addressbook.boXport',True);
$this->browser = CreateObject('phpgwapi.browser'); $this->browser = CreateObject('phpgwapi.browser');
$this->_set_sessiondata();
}
function _set_sessiondata()
{
$this->start = $this->bo->start; $this->start = $this->bo->start;
$this->limit = $this->bo->limit; $this->limit = $this->bo->limit;
$this->query = $this->bo->query; $this->query = $this->bo->query;
@ -44,6 +49,22 @@
$this->order = $this->bo->order; $this->order = $this->bo->order;
$this->filter = $this->bo->filter; $this->filter = $this->bo->filter;
$this->cat_id = $this->bo->cat_id; $this->cat_id = $this->bo->cat_id;
if($this->debug) { $this->_debug_sqsof(); }
}
/* Called only by index(), just prior to page footer. */
function save_sessiondata()
{
$data = array(
'start' => $this->start,
'limit' => $this->limit,
'query' => $this->query,
'sort' => $this->sort,
'order' => $this->order,
'filter' => $this->filter,
'cat_id' => $this->cat_id
);
$this->bo->save_sessiondata($data);
} }
/* Return a select form element with the categories option dialog in it */ /* Return a select form element with the categories option dialog in it */