mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-13 09:28:29 +01:00
Add the beginnings of remote ldap search capability (with add)
This commit is contained in:
parent
a1aa3788b9
commit
f93684a40f
134
addressbook/inc/class.remote.inc.php
Normal file
134
addressbook/inc/class.remote.inc.php
Normal file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**************************************************************************\
|
||||
* phpGroupWare - addressbook *
|
||||
* http://www.phpgroupware.org *
|
||||
* Written by Joseph Engo <jengo@mail.com> *
|
||||
* -------------------------------------------- *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms of the GNU General Public License as published by the *
|
||||
* Free Software Foundation; either version 2 of the License, or (at your *
|
||||
* option) any later version. *
|
||||
\**************************************************************************/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
class remote
|
||||
{
|
||||
var $servers = array(
|
||||
'BigFoot' => array(
|
||||
'host' => 'ldap.bigfoot.com',
|
||||
'basedn' => '',
|
||||
'search' => 'cn',
|
||||
'attrs' => 'mail,cn,o,surname,givenname',
|
||||
'enabled' => True
|
||||
),
|
||||
);
|
||||
var $serverid = '';
|
||||
|
||||
var $ldap = 0;
|
||||
|
||||
function remote($serverid='BigFoot')
|
||||
{
|
||||
$GLOBALS['phpgw']->db->query("SELECT * FROM phpgw_addressbook_servers",__LINE__,__FILE__);
|
||||
while ($GLOBALS['phpgw']->db->next_record())
|
||||
{
|
||||
if ($GLOBALS['phpgw']->db->f('name'))
|
||||
{
|
||||
$this->servers[$GLOBALS['phpgw']->db->f('name')] = array(
|
||||
'host' => $GLOBALS['phpgw']->db->f('host'),
|
||||
'basedn' => $GLOBALS['phpgw']->db->f('basedn'),
|
||||
'search' => $GLOBALS['phpgw']->db->f('search'),
|
||||
'attrs' => $GLOBALS['phpgw']->db->f('attrs'),
|
||||
'enabled' => $GLOBALS['phpgw']->db->f('enabled')
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->serverid = $serverid;
|
||||
$this->ldap = $this->_connect($this->serverid);
|
||||
//$this->search();
|
||||
}
|
||||
|
||||
function _connect($serverid='BigFoot')
|
||||
{
|
||||
if (!$ds = ldap_connect($this->servers[$serverid]['host']))
|
||||
{
|
||||
printf("<b>Error: Can't connect to LDAP server %s!</b><br>",$this->servers[$serverid]['host']);
|
||||
return False;
|
||||
}
|
||||
@ldap_bind($ds);
|
||||
|
||||
return $ds;
|
||||
}
|
||||
|
||||
function search($query='')
|
||||
{
|
||||
if(!$query)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(isset($this->servers[$this->serverid]['attrs']))
|
||||
{
|
||||
$attrs = explode(',',$this->servers[$this->serverid]['attrs']);
|
||||
$found = ldap_search($this->ldap,$this->servers[$this->serverid]['basedn'],$this->servers[$this->serverid]['search'] . '=*' . $query . '*',$attrs);
|
||||
}
|
||||
else
|
||||
{
|
||||
$found = ldap_search($this->ldap,$this->servers[$this->serverid]['basedn'],$this->servers[$this->serverid]['search'] . '=*' . $query . '*');
|
||||
}
|
||||
|
||||
$ldap_fields = @ldap_get_entries($this->ldap, $found);
|
||||
|
||||
$out = $this->clean($ldap_fields);
|
||||
$out = $this->convert($out);
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
function clean($value)
|
||||
{
|
||||
if(!is_int($value) && ($value != 'count'))
|
||||
{
|
||||
if(is_array($value))
|
||||
{
|
||||
while(list($x,$y) = @each($value))
|
||||
{
|
||||
/* Fill a new output array, but do not include things like array( 0 => mail) */
|
||||
if(isset($this->servers[$this->serverid]['attrs']) &&
|
||||
!@in_array($y,explode(',',$this->servers[$this->serverid]['attrs'])))
|
||||
{
|
||||
$out[$x] = $this->clean($y);
|
||||
}
|
||||
}
|
||||
unset($out['count']);
|
||||
return $out;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function convert($in='')
|
||||
{
|
||||
if(is_array($in))
|
||||
{
|
||||
while(list($key,$value) = each($in))
|
||||
{
|
||||
$out[] = array(
|
||||
'fn' => $value['cn'][0],
|
||||
'n_family' => $value['sn'][0] ? $value['sn'][0] : $value['surname'][0],
|
||||
'email' => $value['mail'][0],
|
||||
'owner' => $GLOBALS['phpgw_info']['user']['account_id']
|
||||
);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $in;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
@ -36,11 +36,13 @@
|
||||
'index' => True,
|
||||
'view' => True,
|
||||
'add' => True,
|
||||
'addfromremote' => True,
|
||||
'add_email' => True,
|
||||
'copy' => True,
|
||||
'edit' => True,
|
||||
'delete' => True,
|
||||
'preferences' => True
|
||||
'preferences' => True,
|
||||
'remote_search' => True
|
||||
);
|
||||
|
||||
var $extrafields = array(
|
||||
@ -192,6 +194,34 @@
|
||||
return $cats_link;
|
||||
}
|
||||
|
||||
function remote_search_option()
|
||||
{
|
||||
$remote = CreateObject('addressbook.remote');
|
||||
$servers = $remote->servers;
|
||||
$search_remote = '';
|
||||
|
||||
/* show search box and server dropdown */
|
||||
while(list($server,$data) = @each($servers))
|
||||
{
|
||||
$search_remote .= ' <option value="' . $server . '"';
|
||||
if($server == $this->server)
|
||||
{
|
||||
$search_remote .= ' selected';
|
||||
}
|
||||
$search_remote .= '>' . $server . '</option>' . "\n";
|
||||
}
|
||||
|
||||
return $search_remote;
|
||||
}
|
||||
|
||||
function remote_search()
|
||||
{
|
||||
// _debug_array($GLOBALS['HTTP_POST_VARS']);
|
||||
$remote = CreateObject('addressbook.remote',$GLOBALS['HTTP_POST_VARS']['serverid']);
|
||||
$entries = $remote->search($GLOBALS['HTTP_POST_VARS']['remote_query']);
|
||||
$this->index($entries);
|
||||
}
|
||||
|
||||
/* this cleans up the fieldnames for display */
|
||||
function display_name($column)
|
||||
{
|
||||
@ -257,7 +287,7 @@
|
||||
/*
|
||||
Former index.php
|
||||
*/
|
||||
function index()
|
||||
function index($entries='')
|
||||
{
|
||||
$GLOBALS['phpgw']->common->phpgw_header();
|
||||
echo parse_navbar();
|
||||
@ -411,12 +441,12 @@
|
||||
$userid = $GLOBALS['phpgw_info']['user']['account_id'];
|
||||
}
|
||||
|
||||
if($nosearch && !$this->query)
|
||||
if($nosearch && !$this->query && !$entries)
|
||||
{
|
||||
$entries = array();
|
||||
$total_records = 0;
|
||||
}
|
||||
else
|
||||
elseif(!$entries)
|
||||
{
|
||||
/* read the entry list */
|
||||
$entries = $this->bo->read_entries(array(
|
||||
@ -429,29 +459,39 @@
|
||||
'order' => $this->order
|
||||
));
|
||||
$total_records = $this->bo->total;
|
||||
$this->template->set_var('lang_view',lang('View'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$total_records = count($entries);
|
||||
$this->template->set_var('lang_view',lang('Add'));
|
||||
$showadd = True;
|
||||
}
|
||||
|
||||
/* global here so nextmatchs accepts our setting of $query and $filter */
|
||||
// $GLOBALS['query'] = $this->query;
|
||||
// $GLOBALS['filter'] = $this->filter;
|
||||
|
||||
$search_filter = $GLOBALS['phpgw']->nextmatchs->show_tpl('/index.php',
|
||||
$this->start, $total_records,'&menuaction=addressbook.uiaddressbook.index&fcat_id='.$this->cat_id,'75%',
|
||||
$GLOBALS['phpgw_info']['theme']['th_bg'],1,1,1,1,$this->cat_id);
|
||||
// $query = $filter = '';
|
||||
|
||||
$search_remote = $this->remote_search_option();
|
||||
|
||||
$lang_showing = $GLOBALS['phpgw']->nextmatchs->show_hits($total_records,$this->start);
|
||||
|
||||
/* set basic vars and parse the header */
|
||||
$this->template->set_var('font',$GLOBALS['phpgw_info']['theme']['font']);
|
||||
$this->template->set_var('lang_view',lang('View'));
|
||||
$this->template->set_var('row_on',$GLOBALS['phpgw_info']['theme']['row_on']);
|
||||
// $this->template->set_var('lang_view',lang('View'));
|
||||
$this->template->set_var('lang_vcard',lang('VCard'));
|
||||
$this->template->set_var('lang_edit',lang('Edit'));
|
||||
$this->template->set_var('lang_owner',lang('Owner'));
|
||||
$this->template->set_var('lang_go',lang('Go'));
|
||||
|
||||
$this->template->set_var('searchreturn',$noprefs . ' ' . $searchreturn);
|
||||
$this->template->set_var('remote_search',$GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uiaddressbook.remote_search'));
|
||||
$this->template->set_var('remote_query',$GLOBALS['HTTP_POST_VARS']['remote_query']);
|
||||
$this->template->set_var('lang_remote_search',lang('Remote Search'));
|
||||
$this->template->set_var('lang_showing',$lang_showing);
|
||||
$this->template->set_var('search_filter',$search_filter);
|
||||
$this->template->set_var('search_remote',$search_remote);
|
||||
$this->template->set_var('cats',lang('Category'));
|
||||
$this->template->set_var('cats_url',$GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uiaddressbook.index'));
|
||||
/* $this->template->set_var('cats_link',$this->cat_option($this->cat_id)); */
|
||||
@ -531,15 +571,16 @@
|
||||
$this->template->parse('columns','column',True);
|
||||
}
|
||||
|
||||
if(1)
|
||||
if(!$showadd)
|
||||
{
|
||||
$this->template->set_var('row_view_link',$GLOBALS['phpgw']->link('/index.php',
|
||||
'menuaction=addressbook.uiaddressbook.view&ab_id=' . $entries[$i]['id']));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->template->set_var('row_view_link','');
|
||||
$this->template->set_var('lang_view',lang('Private'));
|
||||
$this->template->set_var('row_view_link',$GLOBALS['phpgw']->link('/index.php',
|
||||
'menuaction=addressbook.uiaddressbook.addfromremote&fields=' . urlencode(serialize($entries[$i]))));
|
||||
// $this->template->set_var('lang_view',lang('Add'));
|
||||
}
|
||||
|
||||
$this->template->set_var('row_vcard_link',$GLOBALS['phpgw']->link('/index.php',
|
||||
@ -622,6 +663,16 @@
|
||||
Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uiaddressbook.edit&ab_id=' . $ab_id));
|
||||
}
|
||||
|
||||
function addfromremote()
|
||||
{
|
||||
$fields = get_var('fields',array('GET'));
|
||||
$fields = stripslashes(urldecode($fields));
|
||||
$fields = unserialize($fields);
|
||||
$fields['note'] = "\nCopied from remote search.";
|
||||
$ab_id = $this->bo->add_entry($fields);
|
||||
Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uiaddressbook.edit&ab_id=' . $ab_id));
|
||||
}
|
||||
|
||||
function add()
|
||||
{
|
||||
if($GLOBALS['HTTP_POST_VARS']['submit'])
|
||||
@ -646,7 +697,7 @@
|
||||
$GLOBALS['phpgw']->common->phpgw_header();
|
||||
echo parse_navbar();
|
||||
|
||||
$this->addressbook_form('','menuaction=addressbook.uiaddressbook.add','Add','',$customfields,$this->cat_id);
|
||||
$this->addressbook_form('','menuaction=addressbook.uiaddressbook.add','Add','',$customfields,$this->cat_id,True);
|
||||
|
||||
$this->template->set_var('lang_ok',lang('ok'));
|
||||
$this->template->set_var('lang_clear',lang('clear'));
|
||||
|
Loading…
Reference in New Issue
Block a user