strip_html($dirty[$i][$name]);
}
}
else
{
$cleaned[$i] == $GLOBALS['phpgw']->strip_html($dirty[$i]);
}
}
return $cleaned;
}
function read_entries($data)
{
$entries = $this->so->read_entries($data);
$this->total = $this->so->contacts->total_records;
if($this->debug) { echo '
Total records="' . $this->total . '"'; }
return (is_array($entries) ? $this->strip_html($entries) : array());
}
function read_entry($data)
{
if ($this->check_perms($data,PHPGW_ACL_READ))
{
$entry = $this->so->read_entry($data['id'],$data['fields']);
return $this->strip_html($entry);
}
return array(0 => array('No access' => 'No access'));
}
function read_last_entry($fields)
{
if ($this->check_perms($fields,PHPGW_ACL_READ))
{
$entry = $this->so->read_last_entry($fields);
return $this->strip_html($entry);
}
return array(0 => array('No access' => 'No access'));
}
function add_vcard($uploadedfile='')
{
if($uploadedfile == 'none' || $uploadedfile == '')
{
return False;
}
else
{
$uploaddir = $GLOBALS['phpgw_info']['server']['temp_dir'] . SEP;
srand((double)microtime()*1000000);
$random_number = rand(100000000,999999999);
$newfilename = md5("$uploadedfile, $uploadedfile_name, "
. time() . getenv("REMOTE_ADDR") . $random_number );
copy($uploadedfile, $uploaddir . $newfilename);
$ftp = fopen($uploaddir . $newfilename . '.info','w');
fputs($ftp,"$uploadedfile_type\n$uploadedfile_name\n");
fclose($ftp);
$filename = $uploaddir . $newfilename;
$vcard = CreateObject('phpgwapi.vcard');
$entry = $vcard->in_file($filename);
/* _debug_array($entry);exit; */
$entry['owner'] = $GLOBALS['phpgw_info']['user']['account_id'];
$entry['access'] = 'private';
$entry['tid'] = 'n';
/* _debug_array($entry);exit; */
$this->so->add_entry($entry);
$ab_id = $this->get_lastid();
/* Delete the temp file. */
unlink($filename);
unlink($filename . '.info');
return (int)$ab_id;
}
}
function add_email()
{
global $name,$referer;
$named = explode(' ', $name);
for ($i=count($named);$i>=0;$i--) { $names[$i] = $named[$i]; }
if ($names[2])
{
$fields['n_given'] = $names[0];
$fields['n_middle'] = $names[1];
$fields['n_family'] = $names[2];
}
else
{
$fields['n_given'] = $names[0];
$fields['n_family'] = $names[1];
}
$fields['email'] = $add_email;
$referer = urlencode($referer);
$this->so->add_entry($GLOBALS['phpgw_info']['user']['account_id'],$fields,'private','','n');
$ab_id = $this->get_lastid();
Header('Location: '
. $GLOBALS['phpgw']->link('/index.php',"menuaction=addressbook.uiaddressbook.view&ab_id=$ab_id&referer=$referer"));
}
function add_entry($fields)
{
// setting some defaults, if not set eg. via xmlrpc
$fields['tid'] = trim($fields['tid']);
if(empty($fields['tid']))
{
$fields['tid'] = 'n';
}
if(!@$fields['owner'])
{
$fields['owner'] = $GLOBALS['phpgw_info']['user']['account_id'];
}
if(empty($fields['access']))
{
$fields['access'] = 'public';
}
return $this->so->add_entry($fields);
}
function get_lastid()
{
return $this->so->get_lastid();
}
function update_entry($fields)
{
if ($this->check_perms($fields,PHPGW_ACL_EDIT))
{
return $this->so->update_entry($fields);
}
return False;
}
function delete_entry($addr)
{
if (!is_array($addr))
{
$id = intval($addr);
}
else
{
if (is_numeric($addr[0])) // xmlrpc liefert array($id)
{
$id = intval($addr[0]);
}
else
{
$id = isset($addr['id']) ? $addr['id'] : $addr['ab_id'];
}
}
if ($this->check_perms($id,PHPGW_ACL_DELETE))
{
return $this->so->delete_entry($id);
}
return False;
}
/*!
@function check_perms
@abstract checks if user has the necessary rights on the given address or address-id
@syntax check_perms($addr,$rights)
@param $addr mixed address-record with id and owner or addr-id
@param $rights integer PHPGW_ACL_{READ|EDIT|ADD|DELETE}
@return True if the user has the requested rights, else False
*/
function check_perms($addr,$rights)
{
$ret = $this->so->contacts->check_perms(False,$rights,$addr);
//echo "boaddressbook::check_perms(".print_r($addr,True).",$rights) = ".($ret?'True':'False')."
\n";
return $ret;
}
function save_preferences($prefs,$other,$qfields,$fcat_id)
{
$GLOBALS['phpgw']->preferences->read_repository();
if (is_array($prefs))
{
/* _debug_array($prefs);exit; */
while (list($pref,$x) = each($qfields))
{
/* echo '
checking: ' . $pref . '=' . $prefs[$pref]; */
if ($prefs[$pref] == 'on')
{
$GLOBALS['phpgw']->preferences->add('addressbook',$pref,'addressbook_on');
}
else
{
$GLOBALS['phpgw']->preferences->delete('addressbook',$pref);
}
}
}
if(is_array($other))
{
$GLOBALS['phpgw']->preferences->delete('addressbook','mainscreen_showbirthdays');
if ($other['mainscreen_showbirthdays'])
{
$GLOBALS['phpgw']->preferences->add('addressbook','mainscreen_showbirthdays',True);
}
$GLOBALS['phpgw']->preferences->delete('addressbook','default_filter');
if ($other['default_filter'])
{
$GLOBALS['phpgw']->preferences->add('addressbook','default_filter',$other['default_filter']);
}
$GLOBALS['phpgw']->preferences->delete('addressbook','autosave_category');
if ($other['autosave_category'])
{
$GLOBALS['phpgw']->preferences->add('addressbook','autosave_category',True);
}
}
$GLOBALS['phpgw']->preferences->delete('addressbook','default_category');
$GLOBALS['phpgw']->preferences->add('addressbook','default_category',$fcat_id);
$GLOBALS['phpgw']->preferences->save_repository(True);
}
}
?>