2005-11-04 00:47:52 +01:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* eGroupWare - Adressbook - General user interface object *
|
|
|
|
* http://www.egroupware.org *
|
|
|
|
* Written and (c) 2005 by Cornelius_weiss <egw@von-und-zu-weiss.de> *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* 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$ */
|
|
|
|
|
|
|
|
require_once(EGW_INCLUDE_ROOT.'/addressbook/inc/class.bocontacts.inc.php');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* General user interface object of the adressbook
|
|
|
|
*
|
2005-11-11 21:50:12 +01:00
|
|
|
* @package addressbook
|
2005-11-04 00:47:52 +01:00
|
|
|
* @author Cornelius Weiss <egw@von-und-zu-weiss.de>
|
|
|
|
* @copyright (c) 2005 by Cornelius Weiss <egw@von-und-zu-weiss.de>
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
*/
|
|
|
|
class uicontacts extends bocontacts
|
|
|
|
{
|
|
|
|
var $public_functions = array(
|
|
|
|
'search' => True,
|
|
|
|
'edit' => True,
|
2005-11-11 21:50:12 +01:00
|
|
|
'view' => True,
|
2005-11-04 00:47:52 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
function uicontacts($contact_app='addressbook')
|
|
|
|
{
|
|
|
|
$this->bocontacts($contact_app);
|
|
|
|
foreach(array(
|
|
|
|
'tmpl' => 'etemplate.etemplate',
|
|
|
|
) as $my => $app_class)
|
|
|
|
{
|
|
|
|
list(,$class) = explode('.',$app_class);
|
|
|
|
|
|
|
|
if (!is_object($GLOBALS['egw']->$class))
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->$class =& CreateObject($app_class);
|
|
|
|
}
|
|
|
|
$this->$my = &$GLOBALS['egw']->$class;
|
|
|
|
}
|
|
|
|
// our javascript
|
|
|
|
// to be moved in a seperate file if rewrite is over
|
|
|
|
$GLOBALS['egw_info']['flags']['java_script'] .= $this->js();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-11-11 21:50:12 +01:00
|
|
|
/**
|
2005-11-13 18:51:41 +01:00
|
|
|
* Edit a contact
|
2005-11-11 21:50:12 +01:00
|
|
|
*
|
2005-11-13 18:51:41 +01:00
|
|
|
* @param array $content=null submitted content
|
2005-11-11 21:50:12 +01:00
|
|
|
* @param int $_GET['contact_id'] contact_id manly for popup use
|
|
|
|
* @param bool $_GET['makecp'] ture if you want do copy the contact given by $_GET['contact_id']
|
|
|
|
*/
|
2005-11-13 18:51:41 +01:00
|
|
|
function edit($content=null)
|
2005-11-04 00:47:52 +01:00
|
|
|
{
|
2005-11-23 18:07:33 +01:00
|
|
|
if (!is_object($this->link))
|
|
|
|
{
|
|
|
|
if (!is_object($GLOBALS['egw']->link))
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->link =& CreateObject('phpgwapi.bolink');
|
|
|
|
}
|
|
|
|
$this->link =& $GLOBALS['egw']->link;
|
|
|
|
}
|
2005-11-04 00:47:52 +01:00
|
|
|
if (is_array($content))
|
|
|
|
{
|
2005-11-13 18:51:41 +01:00
|
|
|
list($button) = each($content['button']);
|
|
|
|
switch($button)
|
2005-11-04 00:47:52 +01:00
|
|
|
{
|
2005-11-13 18:51:41 +01:00
|
|
|
case 'save':
|
|
|
|
case 'apply':
|
2005-11-13 19:22:43 +01:00
|
|
|
$links = false;
|
|
|
|
if (!$content['id'] && is_array($content['link_to']['to_id']))
|
|
|
|
{
|
|
|
|
$links = $content['link_to']['to_id'];
|
|
|
|
}
|
2005-11-13 18:51:41 +01:00
|
|
|
$content = $this->save($content);
|
2005-11-13 19:22:43 +01:00
|
|
|
// writing links for new entry, existing ones are handled by the widget itself
|
|
|
|
if ($links && $content['id'])
|
|
|
|
{
|
|
|
|
$this->link->link('addressbook',$content['id'],$links);
|
|
|
|
}
|
|
|
|
if ($button == 'save')
|
|
|
|
{
|
|
|
|
echo "<html><body><script>var referer = opener.location;opener.location.href = referer;window.close();</script></body></html>\n";
|
|
|
|
$GLOBALS['egw']->common->egw_exit();
|
|
|
|
}
|
2005-11-23 18:07:33 +01:00
|
|
|
$content['link_to']['to_id'] = $content['id'];
|
2005-11-13 18:51:41 +01:00
|
|
|
$GLOBALS['egw_info']['flags']['java_script'] .= "<script LANGUAGE=\"JavaScript\">
|
|
|
|
var referer = opener.location;
|
|
|
|
opener.location.href = referer;</script>";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete':
|
|
|
|
if(!$this->delete($content));
|
|
|
|
{
|
|
|
|
echo "<html><body><script>var referer = opener.location;opener.location.href = referer;window.close();</script></body></html>\n";
|
|
|
|
$GLOBALS['egw']->common->egw_exit();
|
|
|
|
}
|
|
|
|
break;
|
2005-11-04 00:47:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$content = array();
|
2005-11-13 18:51:41 +01:00
|
|
|
$contact_id = $_GET['contact_id'] ? $_GET['contact_id'] : 0;
|
2005-12-01 18:21:38 +01:00
|
|
|
$view = $_GET['view'];
|
2005-11-11 21:50:12 +01:00
|
|
|
|
2005-11-13 18:51:41 +01:00
|
|
|
if ($contact_id)
|
2005-11-04 00:47:52 +01:00
|
|
|
{
|
2005-11-13 18:51:41 +01:00
|
|
|
$content = $this->read($contact_id);
|
2005-11-04 00:47:52 +01:00
|
|
|
}
|
2005-12-01 18:21:38 +01:00
|
|
|
else // look if we have presets for a new contact
|
|
|
|
{
|
|
|
|
foreach($this->get_contact_conlumns() as $field => $data)
|
|
|
|
{
|
|
|
|
if ($_GET['presets'][$field]) $content[$field] = $_GET['presets'][$field];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-23 18:07:33 +01:00
|
|
|
if($content && $_GET['makecp']) // copy the contact
|
|
|
|
{
|
|
|
|
$content['link_to']['to_id'] = 0;
|
|
|
|
$this->link->link('addressbook',$content['link_to']['to_id'],'addressbook',$content['id'],
|
|
|
|
lang('Copied by %1, from record #%2.',$GLOBALS['egw']->common->display_fullname('',
|
|
|
|
$GLOBALS['egw_info']['user']['account_firstname'],$GLOBALS['egw_info']['user']['account_lastname']),
|
|
|
|
$content['id']));
|
|
|
|
unset($content['id']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$content['link_to']['to_id'] = (int) $contact_id;
|
|
|
|
}
|
2005-11-04 00:47:52 +01:00
|
|
|
}
|
2005-11-11 21:50:12 +01:00
|
|
|
|
2005-11-04 00:47:52 +01:00
|
|
|
//_debug_array($content);
|
2005-11-11 21:50:12 +01:00
|
|
|
$readonlys['button[delete]'] = !$this->check_perms(EGW_ACL_DELETE,$content);
|
2005-11-13 18:51:41 +01:00
|
|
|
$readonlys['button[copy]'] = $readonlys['button[edit]'] = $readonlys['button[vcard]'] = true;
|
2005-11-11 21:50:12 +01:00
|
|
|
|
2005-11-04 00:47:52 +01:00
|
|
|
$preserv = array(
|
|
|
|
'id' => $content['id'],
|
|
|
|
'lid' => $content['lid'],
|
|
|
|
'tid' => $content['tid'],
|
|
|
|
'owner' => $content['owner'],
|
|
|
|
'fn' => $content['fn'],
|
|
|
|
'geo' => $content['geo'],
|
2005-11-11 21:50:12 +01:00
|
|
|
'access' => $content['access'],
|
2005-11-04 00:47:52 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
for($i = -23; $i<=23; $i++) $tz[$i] = ($i > 0 ? '+' : '').$i;
|
|
|
|
$sel_options['tz'] = $tz;
|
|
|
|
$content['tz'] = $content['tz'] ? $content['tz'] : 0;
|
|
|
|
|
2005-11-23 18:07:33 +01:00
|
|
|
$content['link_to'] = array(
|
2005-11-13 19:22:43 +01:00
|
|
|
'to_app' => 'addressbook',
|
2005-11-23 18:07:33 +01:00
|
|
|
'to_id' => $content['link_to']['to_id'],
|
2005-11-13 19:22:43 +01:00
|
|
|
);
|
|
|
|
|
2005-11-04 00:47:52 +01:00
|
|
|
$this->tmpl->read('addressbook.edit');
|
2005-11-11 21:50:12 +01:00
|
|
|
return $this->tmpl->exec('addressbook.uicontacts.edit',$content,$sel_options,$readonlys,$preserv, 2);
|
|
|
|
}
|
|
|
|
|
2005-11-13 18:51:41 +01:00
|
|
|
function view($content=null)
|
2005-11-11 21:50:12 +01:00
|
|
|
{
|
|
|
|
if(is_array($content))
|
|
|
|
{
|
2005-11-13 18:51:41 +01:00
|
|
|
list($button) = each($content['button']);
|
|
|
|
switch ($button)
|
2005-11-11 21:50:12 +01:00
|
|
|
{
|
2005-11-13 18:51:41 +01:00
|
|
|
case 'vcard':
|
|
|
|
$GLOBALS['egw']->redirect_link('/index.php','menuaction=addressbook.uivcard.out&ab_id=' .$content['id']);
|
|
|
|
|
|
|
|
case 'cancel':
|
2005-11-11 21:50:12 +01:00
|
|
|
$GLOBALS['egw']->redirect_link('/index.php','menuaction=addressbook.uiaddressbook.index');
|
2005-11-13 18:51:41 +01:00
|
|
|
|
|
|
|
case 'delete':
|
|
|
|
if(!$this->delete($content))
|
|
|
|
{
|
|
|
|
$content['msg'] = lang('Something went wrong by deleting this contact');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->redirect_link('/index.php','menuaction=addressbook.uiaddressbook.index');
|
|
|
|
}
|
2005-11-11 21:50:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$contact_id = $_GET['contact_id'];
|
|
|
|
if(!$contact_id) return false;
|
|
|
|
|
|
|
|
$content = $this->read($contact_id);
|
|
|
|
}
|
2005-11-13 18:51:41 +01:00
|
|
|
foreach($content as $key => $val)
|
2005-11-11 21:50:12 +01:00
|
|
|
{
|
2005-11-13 18:51:41 +01:00
|
|
|
$readonlys[$key] = true;
|
|
|
|
if (in_array($key,array('tel_home','tel_work','tel_cell')))
|
|
|
|
{
|
|
|
|
$readonlys[$key.'2'] = true;
|
|
|
|
$content[$key.'2'] = $content[$key];
|
|
|
|
}
|
2005-11-11 21:50:12 +01:00
|
|
|
}
|
2005-11-13 18:51:41 +01:00
|
|
|
$content['view'] = true;
|
2005-11-23 18:07:33 +01:00
|
|
|
$content['link_to'] = array(
|
2005-11-14 18:46:23 +01:00
|
|
|
'to_app' => 'addressbook',
|
|
|
|
'to_id' => $content['id'],
|
|
|
|
);
|
2005-11-23 18:07:33 +01:00
|
|
|
$readonlys['link_to'] = $readonlys['customfields'] = true;
|
2005-11-13 18:51:41 +01:00
|
|
|
$readonlys['button[save]'] = $readonlys['button[apply]'] = true;
|
2005-11-11 21:50:12 +01:00
|
|
|
$readonlys['button[delete]'] = !$this->check_perms(EGW_ACL_DELETE,$content);
|
2005-11-13 18:51:41 +01:00
|
|
|
$readonlys['button[edit]'] = !$this->check_perms(EGW_ACL_EDIT,$content);
|
2006-02-17 11:38:00 +01:00
|
|
|
|
|
|
|
for($i = -23; $i<=23; $i++) $tz[$i] = ($i > 0 ? '+' : '').$i;
|
|
|
|
$sel_options['tz'] = $tz;
|
|
|
|
$content['tz'] = $content['tz'] ? $content['tz'] : 0;
|
2005-11-13 18:51:41 +01:00
|
|
|
|
|
|
|
$this->tmpl->read('addressbook.edit');
|
2005-11-18 18:03:23 +01:00
|
|
|
foreach(array('email','email_home','url') as $name)
|
|
|
|
{
|
|
|
|
if ($content[$name] )
|
|
|
|
{
|
|
|
|
$url = $name == 'url' ? $content[$name] : $this->email2link($content[$name]);
|
|
|
|
if (!is_array($url))
|
|
|
|
{
|
|
|
|
$this->tmpl->set_cell_attribute($name,'size','b,,1');
|
|
|
|
}
|
|
|
|
elseif ($url)
|
|
|
|
{
|
|
|
|
$content[$name.'_link'] = $url;
|
|
|
|
$this->tmpl->set_cell_attribute($name,'size','b,@'.$name.'_link,,,_blank');
|
|
|
|
}
|
|
|
|
$this->tmpl->set_cell_attribute($name,'type','label');
|
|
|
|
$this->tmpl->set_cell_attribute($name,'no_lang',true);
|
|
|
|
}
|
|
|
|
}
|
2005-11-11 21:50:12 +01:00
|
|
|
$this->tmpl->exec('addressbook.uicontacts.view',$content,$sel_options,$readonlys,array('id' => $content['id']));
|
|
|
|
|
|
|
|
$GLOBALS['egw']->hooks->process(array(
|
|
|
|
'location' => 'addressbook_view',
|
|
|
|
'ab_id' => $content['id']
|
|
|
|
));
|
2005-11-04 00:47:52 +01:00
|
|
|
}
|
|
|
|
|
2005-11-18 18:03:23 +01:00
|
|
|
/**
|
|
|
|
* convert email-address in compose link
|
|
|
|
*
|
|
|
|
* @param string $email email-addresse
|
|
|
|
* @return array/string array with get-params or mailto:$email, or '' or no mail addresse
|
|
|
|
*/
|
|
|
|
function email2link($email)
|
|
|
|
{
|
|
|
|
if (!strstr($email,'@')) return '';
|
|
|
|
|
|
|
|
if($GLOBALS['egw_info']['user']['apps']['felamimail'])
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'menuaction' => 'felamimail.uicompose.compose',
|
|
|
|
'send_to' => base64_encode($email)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if($GLOBALS['egw_info']['user']['apps']['email'])
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'menuaction' => 'email.uicompose.compose',
|
|
|
|
'to' => $email,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return 'mailto:' . $email;
|
|
|
|
}
|
|
|
|
|
2005-11-04 00:47:52 +01:00
|
|
|
function search($content='')
|
|
|
|
{
|
2005-11-09 20:15:22 +01:00
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('Addressbook'). ' - '. lang('Advanced search');
|
2005-11-04 00:47:52 +01:00
|
|
|
if(!($GLOBALS['egw_info']['server']['contact_repository'] == 'sql' || !isset($GLOBALS['egw_info']['server']['contact_repository'])))
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->common->phpgw_header();
|
|
|
|
echo parse_navbar();
|
|
|
|
echo '<p> Advanced Search is not supported for ldap storage yet. Sorry! </p>';
|
|
|
|
$GLOBALS['egw']->common->egw_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is no fun yet, as we dont have a sortorder in prefs now, AND as we are not able to sort within cf.
|
|
|
|
// $prefs = $GLOBALS['egw']->preferences->read_repository();
|
|
|
|
// foreach($prefs['addressbook'] as $key => $value)
|
|
|
|
// {
|
|
|
|
// if($value == 'addressbook_on') $content['advs']['colums_to_present'][$key] = lang($key);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// echo 'addressbook.uicontacts.search->content:'; _debug_array($content);
|
|
|
|
$content['advs']['hidebuttons'] = true;
|
|
|
|
$content['advs']['input_template'] = 'addressbook.edit';
|
|
|
|
$content['advs']['search_method'] = 'addressbook.bocontacts.search';
|
|
|
|
$content['advs']['search_class_constructor'] = $contact_app;
|
|
|
|
$content['advs']['colums_to_present'] = array(
|
|
|
|
'id' => 'id',
|
|
|
|
'n_given' => lang('first name'),
|
|
|
|
'n_family' => lang('last name'),
|
|
|
|
'email_home' => lang('home email'),
|
2005-11-08 00:06:16 +01:00
|
|
|
'email' => lang('work email'),
|
2005-11-04 00:47:52 +01:00
|
|
|
'tel_home' => lang('tel home'),
|
|
|
|
);
|
2005-11-09 20:15:22 +01:00
|
|
|
|
|
|
|
$content['advs']['row_actions'] = array(
|
2005-12-18 20:06:32 +01:00
|
|
|
'view' => array(
|
|
|
|
'type' => 'button',
|
|
|
|
'options' => array(
|
|
|
|
'size' => 'view',
|
|
|
|
'onclick' => "location.href='".$GLOBALS['egw']->link('/index.php',
|
|
|
|
array('menuaction' => 'addressbook.uicontacts.view',)).'&contact_id=$row_cont[id]\';return false;',
|
|
|
|
)),
|
2005-11-09 20:15:22 +01:00
|
|
|
'edit' => array(
|
|
|
|
'type' => 'button',
|
|
|
|
'options' => array(
|
|
|
|
'size' => 'edit',
|
|
|
|
'onclick' => 'window.open(\''.
|
|
|
|
$GLOBALS['egw']->link('/index.php?menuaction=addressbook.uicontacts.edit').
|
2006-03-01 20:32:31 +01:00
|
|
|
'&contact_id=$row_cont[id] \',\'\',\'dependent=yes,width=850,height=440,location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes\');
|
2005-11-09 20:15:22 +01:00
|
|
|
return false;',
|
|
|
|
)),
|
|
|
|
'delete' => array(
|
|
|
|
'type' => 'button',
|
|
|
|
'method' => 'addressbook.bocontacts.delete',
|
|
|
|
'options' => array(
|
|
|
|
'size' => 'delete',
|
|
|
|
'onclick' => 'if(!confirm(\''. lang('Do your really want to delete this contact?'). '\')) return false;',
|
|
|
|
)),
|
|
|
|
);
|
2005-11-08 00:06:16 +01:00
|
|
|
/* $content['advs']['actions']['email'] = array(
|
|
|
|
'type' => 'button',
|
|
|
|
'options' => array(
|
|
|
|
'label' => lang('email'),
|
|
|
|
'no_lang' => true,
|
|
|
|
));
|
|
|
|
$content['advs']['actions']['export'] = array(
|
|
|
|
'type' => 'button',
|
|
|
|
'options' => array(
|
|
|
|
'label' => lang('export'),
|
|
|
|
'no_lang' => true,
|
|
|
|
));*/
|
|
|
|
$content['advs']['actions']['delete'] = array(
|
2005-11-04 00:47:52 +01:00
|
|
|
'type' => 'button',
|
|
|
|
'method' => 'addressbook.bocontacts.delete',
|
|
|
|
'options' => array(
|
|
|
|
'label' => lang('delete'),
|
|
|
|
'no_lang' => true,
|
2005-11-08 00:06:16 +01:00
|
|
|
'onclick' => 'if(!confirm(\''. lang('WARNING: All contacts found will be deleted!'). '\')) return false;',
|
|
|
|
));
|
|
|
|
|
2005-11-04 00:47:52 +01:00
|
|
|
for($i = -23; $i<=23; $i++) $tz[$i] = ($i > 0 ? '+' : '').$i;
|
|
|
|
$sel_options['tz'] = $tz + array('' => lang('doesn\'t matter'));
|
|
|
|
|
|
|
|
$this->tmpl->read('addressbook.search');
|
2005-11-11 21:50:12 +01:00
|
|
|
return $this->tmpl->exec('addressbook.uicontacts.search',$content,$sel_options,$readonlys,$preserv);
|
2005-11-04 00:47:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function js()
|
|
|
|
{
|
|
|
|
return '<script LANGUAGE="JavaScript">
|
|
|
|
|
2005-11-14 18:29:39 +01:00
|
|
|
function showphones(form)
|
|
|
|
{
|
2005-11-04 00:47:52 +01:00
|
|
|
set_style_by_class("table","editphones","display","inline");
|
2005-11-14 18:29:39 +01:00
|
|
|
if (form) {
|
|
|
|
copyvalues(form,"tel_home","tel_home2");
|
|
|
|
copyvalues(form,"tel_work","tel_work2");
|
|
|
|
copyvalues(form,"tel_cell","tel_cell2");
|
|
|
|
}
|
2005-11-04 00:47:52 +01:00
|
|
|
}
|
|
|
|
|
2005-11-14 18:29:39 +01:00
|
|
|
function hidephones(form)
|
|
|
|
{
|
2005-11-04 00:47:52 +01:00
|
|
|
set_style_by_class("table","editphones","display","none");
|
2005-11-14 18:29:39 +01:00
|
|
|
if (form) {
|
|
|
|
copyvalues(form,"tel_home2","tel_home");
|
|
|
|
copyvalues(form,"tel_work2","tel_work");
|
|
|
|
copyvalues(form,"tel_cell2","tel_cell");
|
|
|
|
}
|
2005-11-04 00:47:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function copyvalues(form,src,dst){
|
|
|
|
var srcelement = getElement(form,src); //ById("exec["+src+"]");
|
|
|
|
var dstelement = getElement(form,dst); //ById("exec["+dst+"]");
|
2005-11-14 18:29:39 +01:00
|
|
|
if (srcelement && dstelement) {
|
|
|
|
dstelement.value = srcelement.value;
|
|
|
|
}
|
2005-11-04 00:47:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function getElement(form,pattern){
|
|
|
|
for (i = 0; i < form.length; i++){
|
|
|
|
if(form.elements[i].name){
|
|
|
|
var found = form.elements[i].name.search(pattern);
|
|
|
|
if (found != -1){
|
|
|
|
return form.elements[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>';
|
|
|
|
}
|
2005-11-11 21:50:12 +01:00
|
|
|
}
|