2005-11-04 00:47:52 +01:00
< ? php
2006-06-13 06:30:16 +02:00
/**
2011-04-07 09:28:46 +02:00
* EGroupware - Addressbook - user interface
2006-06-13 06:30:16 +02:00
*
* @ link www . egroupware . org
* @ author Cornelius Weiss < egw @ von - und - zu - weiss . de >
* @ author Ralf Becker < RalfBecker - AT - outdoor - training . de >
2016-02-17 14:23:27 +01:00
* @ copyright ( c ) 2005 - 16 by Ralf Becker < RalfBecker - AT - outdoor - training . de >
2008-04-04 10:14:30 +02:00
* @ copyright ( c ) 2005 / 6 by Cornelius Weiss < egw @ von - und - zu - weiss . de >
2006-06-13 06:30:16 +02:00
* @ package addressbook
* @ license http :// opensource . org / licenses / gpl - license . php GPL - GNU General Public License
2008-04-18 08:10:31 +02:00
* @ version $Id $
2006-06-13 06:30:16 +02:00
*/
2005-11-04 00:47:52 +01:00
2016-04-06 11:49:50 +02:00
use EGroupware\Api ;
2016-04-29 12:41:53 +02:00
use EGroupware\Api\Link ;
use EGroupware\Api\Framework ;
use EGroupware\Api\Egw ;
use EGroupware\Api\Acl ;
use EGroupware\Api\Vfs ;
use EGroupware\Api\Etemplate ;
2016-04-06 11:49:50 +02:00
2005-11-04 00:47:52 +01:00
/**
* General user interface object of the adressbook
*/
2008-05-10 14:02:49 +02:00
class addressbook_ui extends addressbook_bo
2005-11-04 00:47:52 +01:00
{
2009-05-11 08:47:38 +02:00
public $public_functions = array (
2005-11-04 00:47:52 +01:00
'search' => True ,
'edit' => True ,
2005-11-11 21:50:12 +01:00
'view' => True ,
2006-04-23 16:40:31 +02:00
'index' => True ,
'photo' => True ,
2006-06-16 06:44:58 +02:00
'emailpopup' => True ,
2006-07-08 02:36:23 +02:00
'migrate2ldap' => True ,
2009-05-09 09:58:16 +02:00
'admin_set_fileas' => True ,
2009-11-11 09:44:51 +01:00
'admin_set_all_cleanup' => True ,
2008-03-10 17:33:17 +01:00
'cat_add' => True ,
2005-11-04 00:47:52 +01:00
);
2009-05-11 08:47:38 +02:00
protected $org_views ;
2005-11-04 00:47:52 +01:00
2007-05-22 10:02:06 +02:00
/**
* Addressbook configuration ( stored as phpgwapi = general server config )
*
* @ var array
*/
2009-05-11 08:47:38 +02:00
protected $config ;
2010-08-30 12:21:23 +02:00
/**
* Fields to copy , default if nothing specified in config
2010-11-04 21:40:33 +01:00
*
2010-08-30 12:21:23 +02:00
* @ var array
*/
static public $copy_fields = array (
'org_name' ,
'org_unit' ,
'adr_one_street' ,
'adr_one_street2' ,
'adr_one_locality' ,
'adr_one_region' ,
'adr_one_postalcode' ,
'adr_one_countryname' ,
2011-03-07 18:25:54 +01:00
'adr_one_countrycode' ,
2010-08-30 12:21:23 +02:00
'email' ,
'url' ,
'tel_work' ,
'cat_id'
);
2014-03-06 19:39:52 +01:00
/**
* Instance of eTemplate class
*
2016-04-29 12:41:53 +02:00
* @ var Etemplate
2014-03-06 19:39:52 +01:00
*/
protected $tmpl ;
2006-12-16 13:02:14 +01:00
/**
2009-05-11 08:47:38 +02:00
* Constructor
2006-12-16 13:02:14 +01:00
*
2009-05-11 08:47:38 +02:00
* @ param string $contact_app
2006-12-16 13:02:14 +01:00
*/
2008-05-10 14:02:49 +02:00
function __construct ( $contact_app = 'addressbook' )
2005-11-04 00:47:52 +01:00
{
2008-05-10 14:02:49 +02:00
parent :: __construct ( $contact_app );
2006-04-23 16:40:31 +02:00
2016-04-29 12:41:53 +02:00
$this -> tmpl = new Etemplate ();
2005-11-04 00:47:52 +01:00
2006-04-30 11:34:24 +02:00
$this -> org_views = array (
'org_name' => lang ( 'Organisations' ),
'org_name,adr_one_locality' => lang ( 'Organisations by location' ),
'org_name,org_unit' => lang ( 'Organisations by departments' ),
);
2006-04-23 16:40:31 +02:00
2011-09-15 16:46:56 +02:00
// make sure the hook for export_limit is registered
2016-04-29 12:41:53 +02:00
if ( ! Api\Hooks :: exists ( 'export_limit' , 'addressbook' )) Api\Hooks :: read ( true );
2011-09-15 16:46:56 +02:00
2006-06-17 20:50:07 +02:00
$this -> config =& $GLOBALS [ 'egw_info' ][ 'server' ];
2008-10-16 13:17:49 +02:00
// check if a contact specific export limit is set, if yes use it also for etemplate's csv export
2016-04-29 12:41:53 +02:00
$this -> config [ 'export_limit' ] = $this -> config [ 'contact_export_limit' ] = Api\Storage\Merge :: getExportLimit ( $app = 'addressbook' );
2011-09-15 16:46:56 +02:00
2011-08-26 15:50:20 +02:00
if ( $this -> config [ 'copy_fields' ] && ( $fields = is_array ( $this -> config [ 'copy_fields' ]) ?
$this -> config [ 'copy_fields' ] : unserialize ( $this -> config [ 'copy_fields' ])))
2010-08-30 12:21:23 +02:00
{
2011-03-07 19:32:20 +01:00
// Set country code if country name is selected
$supported_fields = $this -> get_fields ( 'supported' , null , 0 );
if ( in_array ( 'adr_one_countrycode' , $supported_fields ) && in_array ( 'adr_one_countryname' , $fields ))
{
$fields [] = 'adr_one_countrycode' ;
}
if ( in_array ( 'adr_two_countrycode' , $supported_fields ) && in_array ( 'adr_two_countryname' , $fields ))
{
$fields [] = 'adr_two_countrycode' ;
}
2010-08-30 12:21:23 +02:00
self :: $copy_fields = $fields ;
}
2006-04-23 16:40:31 +02:00
}
2008-04-18 08:10:31 +02:00
2006-04-23 16:40:31 +02:00
/**
* List contacts of an addressbook
*
2016-04-29 12:41:53 +02:00
* @ param array $_content = null submitted content
* @ param string $msg = null message to show
* @ param boolean $do_email = false do an email - selection popup or the regular index - page
2006-04-23 16:40:31 +02:00
*/
2016-04-29 12:41:53 +02:00
function index ( $_content = null , $msg = null , $do_email = false )
2006-04-23 16:40:31 +02:00
{
2016-04-29 12:41:53 +02:00
//echo "<p>uicontacts::index(".print_r($_content,true).",'$msg')</p>\n";
if (( $re_submit = is_array ( $_content )))
2006-04-23 16:40:31 +02:00
{
2016-04-29 12:41:53 +02:00
$do_email = $_content [ 'do_email' ];
2005-11-04 00:47:52 +01:00
2016-04-29 12:41:53 +02:00
if ( isset ( $_content [ 'nm' ][ 'rows' ][ 'delete' ])) // handle a single delete like delete with the checkboxes
2006-04-23 16:40:31 +02:00
{
2016-04-29 12:41:53 +02:00
list ( $id ) = @ each ( $_content [ 'nm' ][ 'rows' ][ 'delete' ]);
$_content [ 'nm' ][ 'action' ] = 'delete' ;
$_content [ 'nm' ][ 'selected' ] = array ( $id );
2006-04-23 16:40:31 +02:00
}
2016-04-29 12:41:53 +02:00
if ( isset ( $_content [ 'nm' ][ 'rows' ][ 'document' ])) // handle insert in default document button like an action
2007-06-17 15:55:43 +02:00
{
2016-04-29 12:41:53 +02:00
list ( $id ) = @ each ( $_content [ 'nm' ][ 'rows' ][ 'document' ]);
$_content [ 'nm' ][ 'action' ] = 'document' ;
$_content [ 'nm' ][ 'selected' ] = array ( $id );
2007-06-17 15:55:43 +02:00
}
2016-04-29 12:41:53 +02:00
if ( $_content [ 'nm' ][ 'action' ] !== '' && $_content [ 'nm' ][ 'action' ] !== null )
2006-04-23 16:40:31 +02:00
{
2016-04-29 12:41:53 +02:00
if ( ! count ( $_content [ 'nm' ][ 'selected' ]) && ! $_content [ 'nm' ][ 'select_all' ] && $_content [ 'nm' ][ 'action' ] != 'delete_list' )
2006-04-23 16:40:31 +02:00
{
$msg = lang ( 'You need to select some contacts first' );
}
2016-04-29 12:41:53 +02:00
elseif ( $_content [ 'nm' ][ 'action' ] == 'view_org' ) // org-view via context menu
2011-04-25 13:30:37 +02:00
{
2016-04-29 12:41:53 +02:00
$_content [ 'nm' ][ 'org_view' ] = array_shift ( $_content [ 'nm' ][ 'selected' ]);
2011-04-25 13:30:37 +02:00
}
2006-04-23 16:40:31 +02:00
else
{
2016-04-29 12:41:53 +02:00
$success = $failed = $action_msg = null ;
if ( $this -> action ( $_content [ 'nm' ][ 'action' ], $_content [ 'nm' ][ 'selected' ], $_content [ 'nm' ][ 'select_all' ],
$success , $failed , $action_msg , $_content [ 'do_email' ] ? 'email' : 'index' , $msg , $_content [ 'nm' ][ 'checkboxes' ]))
2006-04-23 16:40:31 +02:00
{
$msg .= lang ( '%1 contact(s) %2' , $success , $action_msg );
2016-04-29 12:41:53 +02:00
Framework :: message ( $msg );
2006-04-23 16:40:31 +02:00
}
2007-03-13 14:38:15 +01:00
elseif ( is_null ( $msg ))
2006-04-23 16:40:31 +02:00
{
$msg .= lang ( '%1 contact(s) %2, %3 failed because of insufficent rights !!!' , $success , $action_msg , $failed );
2016-04-29 12:41:53 +02:00
Framework :: message ( $msg , 'error' );
2006-04-23 16:40:31 +02:00
}
2014-02-06 00:36:01 +01:00
$msg = '' ;
2006-04-23 16:40:31 +02:00
}
}
2016-04-29 12:41:53 +02:00
if ( $_content [ 'nm' ][ 'rows' ][ 'infolog' ])
2006-10-23 13:48:56 +02:00
{
2016-04-29 12:41:53 +02:00
list ( $org ) = each ( $_content [ 'nm' ][ 'rows' ][ 'infolog' ]);
2006-10-23 13:48:56 +02:00
return $this -> infolog_org_view ( $org );
}
2016-04-29 12:41:53 +02:00
if ( $_content [ 'nm' ][ 'rows' ][ 'view' ]) // show all contacts of an organisation
2006-04-30 11:34:24 +02:00
{
2016-04-29 12:41:53 +02:00
list ( $org_view ) = each ( $_content [ 'nm' ][ 'rows' ][ 'view' ]);
2006-04-30 11:34:24 +02:00
}
else
{
2016-04-29 12:41:53 +02:00
$org_view = $_content [ 'nm' ][ 'org_view' ];
2006-04-30 11:34:24 +02:00
}
2016-04-29 12:41:53 +02:00
$typeselection = $_content [ 'nm' ][ 'col_filter' ][ 'tid' ];
2006-04-23 16:40:31 +02:00
}
2007-03-13 14:38:15 +01:00
elseif ( $_GET [ 'add_list' ])
{
2007-05-25 20:20:57 +02:00
$list = $this -> add_list ( $_GET [ 'add_list' ], $_GET [ 'owner' ] ? $_GET [ 'owner' ] : $this -> user );
if ( $list === true )
{
$msg = lang ( 'List already exists!' );
}
elseif ( $list )
2007-03-13 14:38:15 +01:00
{
$msg = lang ( 'List created' );
}
else
{
$msg = lang ( 'List creation failed, no rights!' );
}
}
2006-06-16 06:44:58 +02:00
$preserv = array (
'do_email' => $do_email ,
);
2016-04-29 12:41:53 +02:00
$to = $_content [ 'nm' ][ 'to' ];
2014-02-06 00:36:01 +01:00
$content = array ();
if ( $msg || $_GET [ 'msg' ])
{
2016-04-29 12:41:53 +02:00
Framework :: message ( $msg ? $msg : $_GET [ 'msg' ]);
2014-02-06 00:36:01 +01:00
}
2007-11-23 09:32:08 +01:00
2016-04-29 12:41:53 +02:00
$content [ 'nm' ] = Api\Cache :: getSession ( 'addressbook' , $do_email ? 'email' : 'index' );
2006-04-24 13:15:10 +02:00
if ( ! is_array ( $content [ 'nm' ]))
2006-04-23 16:40:31 +02:00
{
$content [ 'nm' ] = array (
2008-05-10 14:02:49 +02:00
'get_rows' => 'addressbook.addressbook_ui.get_rows' , // I method/callback to request the data for the rows eg. 'notes.bo.get_rows'
2006-04-23 16:40:31 +02:00
'bottom_too' => false , // I show the nextmatch-line (arrows, filters, search, ...) again after the rows
'never_hide' => True , // I never hide the nextmatch-line if less then maxmatch entrie
'start' => 0 , // IO position in list
2006-10-07 11:17:30 +02:00
'cat_id' => '' , // IO category, if not 'no_cat' => True
2006-04-23 16:40:31 +02:00
'search' => '' , // IO search pattern
'order' => 'n_family' , // IO name of the column to sort after (optional for the sortheaders)
'sort' => 'ASC' , // IO direction of the sort: 'ASC' or 'DESC'
'col_filter' => array (), // IO array of column-name value pairs (optional for the filterheaders)
2016-02-17 14:23:27 +01:00
//'cat_id_label' => lang('Categories'),
//'filter_label' => lang('Addressbook'), // I label for filter (optional)
2006-06-24 08:09:02 +02:00
'filter' => '' , // =All // IO filter, if not 'no_filter' => True
2006-04-23 16:40:31 +02:00
'filter_no_lang' => True , // I set no_lang for filter (=dont translate the options)
'no_filter2' => True , // I disable the 2. filter (params are the same as for filter)
2016-02-17 14:23:27 +01:00
//'filter2_label'=> lang('Distribution lists'), // IO filter2, if not 'no_filter2' => True
2006-04-23 16:40:31 +02:00
'filter2' => '' , // IO filter2, if not 'no_filter2' => True
'filter2_no_lang' => True , // I set no_lang for filter2 (=dont translate the options)
'lettersearch' => true ,
2011-07-12 16:36:59 +02:00
'do_email' => $do_email ? 1 : 0 ,
2014-09-24 10:26:19 +02:00
// using a positiv list now, as we constantly adding new columns in addressbook, but not removing them from default
'default_cols' => 'type,n_fileas_n_given_n_family_n_family_n_given_org_name_n_family_n_given_n_fileas,' .
2015-09-08 18:48:42 +02:00
'number,org_name,org_unit,' .
2014-09-24 10:26:19 +02:00
'business_adr_one_countrycode_adr_one_postalcode,tel_work_tel_cell_tel_home,url_email_email_home' ,
/* old negative list
'default_cols' => '!cat_id,contact_created_contact_modified,distribution_list,contact_id,owner,room' , */
2017-01-24 16:43:57 +01:00
'filter2_onchange' => " return app.addressbook.filter2_onchange(); " ,
2008-06-05 14:04:00 +02:00
'manual' => $do_email ? ' ' : false , // space for the manual icon
2011-04-17 16:10:05 +02:00
//'actions' => $this->get_actions(), // set on each request, as it depends on some filters
'row_id' => 'id' ,
2014-03-18 23:55:48 +01:00
'row_modified' => 'modified' ,
2015-03-02 22:50:25 +01:00
'is_parent' => 'org_count' ,
'parent_id' => 'parent_id' ,
2013-03-21 00:11:54 +01:00
'favorites' => true ,
2016-02-29 15:19:33 +01:00
'placeholder_actions' => array ( 'add' )
2006-04-23 16:40:31 +02:00
);
2008-06-05 14:04:00 +02:00
2007-05-25 20:20:57 +02:00
if ( $do_email )
{
2013-09-20 12:50:48 +02:00
$content [ 'nm' ][ 'filter2_onchange' ] = 'app.addressbook.filter2_onchange_email();' ;
2007-05-25 20:20:57 +02:00
}
2006-04-23 16:40:31 +02:00
// use the state of the last session stored in the user prefs
2006-06-16 06:44:58 +02:00
if (( $state = @ unserialize ( $this -> prefs [ $do_email ? 'email_state' : 'index_state' ])))
2006-04-23 16:40:31 +02:00
{
$content [ 'nm' ] = array_merge ( $content [ 'nm' ], $state );
}
}
2016-02-17 14:23:27 +01:00
$sel_options [ 'cat_id' ] = array ( '' => lang ( 'All categories' ), '0' => lang ( 'None' ));
2014-02-27 21:20:15 +01:00
2014-10-27 19:43:03 +01:00
// Edit and delete list actions depends on permissions
2016-04-29 12:41:53 +02:00
if ( $this -> get_lists ( Acl :: EDIT ))
2013-04-15 17:14:36 +02:00
{
2014-10-28 20:11:10 +01:00
$content [ 'nm' ][ 'placeholder_actions' ][] = 'rename_list' ;
$content [ 'nm' ][ 'placeholder_actions' ][] = 'delete_list' ;
2013-04-15 17:14:36 +02:00
}
2009-12-08 22:27:56 +01:00
// Search parameter passed in
if ( $_GET [ 'search' ]) {
$content [ 'nm' ][ 'search' ] = $_GET [ 'search' ];
}
2008-10-20 21:35:18 +02:00
if ( isset ( $typeselection )) $content [ 'nm' ][ 'col_filter' ][ 'tid' ] = $typeselection ;
2011-11-09 10:06:27 +01:00
// save the tid for use in creating new addressbook entrys via UI. Current tid is to be used as type of new entrys
//error_log(__METHOD__.__LINE__.' '.$content['nm']['col_filter']['tid']);
2016-04-29 12:41:53 +02:00
Api\Cache :: setSession ( 'addressbook' , 'active_tid' , $content [ 'nm' ][ 'col_filter' ][ 'tid' ]);
2007-05-03 07:07:30 +02:00
if ( $this -> lists_available ())
2007-03-13 14:38:15 +01:00
{
2016-04-29 12:41:53 +02:00
$sel_options [ 'filter2' ] = $this -> get_lists ( Acl :: READ , array ( '' => lang ( 'No distribution list' )));
2007-05-03 07:07:30 +02:00
$sel_options [ 'filter2' ][ 'add' ] = lang ( 'Add a new list' ) . '...' ; // put it at the end
2007-03-13 14:38:15 +01:00
}
2006-06-17 20:50:07 +02:00
if ( $do_email )
2006-06-16 06:44:58 +02:00
{
2006-06-17 20:50:07 +02:00
if ( ! $re_submit )
{
2011-03-29 11:43:37 +02:00
$content [ 'nm' ][ 'to' ] = 'to' ; // use 'bcc' if you want bcc as preselected standard mailaddress scope
2007-11-06 16:45:40 +01:00
$content [ 'nm' ][ 'email_type' ] = $this -> prefs [ 'distributionListPreferredMail' ] ? $this -> prefs [ 'distributionListPreferredMail' ] : 'email' ;
2006-06-17 20:50:07 +02:00
$content [ 'nm' ][ 'search' ] = '@' ;
}
2007-05-25 20:20:57 +02:00
else
{
$content [ 'nm' ][ 'to' ] = $to ;
2007-11-06 16:45:40 +01:00
$content [ 'nm' ][ 'email_type' ] = $this -> prefs [ 'distributionListPreferredMail' ] ? $this -> prefs [ 'distributionListPreferredMail' ] : 'email' ;
2007-05-25 20:20:57 +02:00
}
2006-06-17 20:50:07 +02:00
$content [ 'nm' ][ 'header_left' ] = 'addressbook.email.left' ;
}
// Organisation stuff is not (yet) availible with ldap
elseif ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'contact_repository' ] != 'ldap' )
{
$content [ 'nm' ][ 'header_left' ] = 'addressbook.index.left' ;
2006-06-16 06:44:58 +02:00
}
2016-04-29 12:41:53 +02:00
$sel_options [ 'filter' ] = $sel_options [ 'owner' ] = $this -> get_addressbooks ( Acl :: READ , lang ( 'All addressbooks' ));
2007-03-13 14:38:15 +01:00
$sel_options [ 'to' ] = array (
'to' => 'To' ,
'cc' => 'Cc' ,
'bcc' => 'Bcc' ,
2006-04-23 16:40:31 +02:00
);
2016-05-09 20:42:27 +02:00
$sel_options [ 'adr_one_countrycode' ][ '-custom-' ] = lang ( 'No country selected' );
2011-04-17 16:10:05 +02:00
// if there is any export limit set, pass it on to the nextmatch, to be evaluated by the export
if ( isset ( $this -> config [ 'contact_export_limit' ]) && ( int ) $this -> config [ 'contact_export_limit' ]) $content [ 'nm' ][ 'export_limit' ] = $this -> config [ 'contact_export_limit' ];
// dont show tid-selection if we have only one content_type
2011-04-25 13:30:37 +02:00
// be a bit more sophisticated about it
2011-04-17 16:10:05 +02:00
$availabletypes = array_keys ( $this -> content_types );
if ( $content [ 'nm' ][ 'col_filter' ][ 'tid' ] && ! in_array ( $content [ 'nm' ][ 'col_filter' ][ 'tid' ], $availabletypes ))
{
//_debug_array(array('Typefilter:'=> $content['nm']['col_filter']['tid'],'Available Types:'=>$availabletypes,'action:'=>'remove invalid filter'));
unset ( $content [ 'nm' ][ 'col_filter' ][ 'tid' ]);
}
if ( ! isset ( $content [ 'nm' ][ 'col_filter' ][ 'tid' ])) $content [ 'nm' ][ 'col_filter' ][ 'tid' ] = $availabletypes [ 0 ];
if ( count ( $this -> content_types ) > 1 )
{
foreach ( $this -> content_types as $tid => $data )
{
2013-06-04 00:43:03 +02:00
$sel_options [ 'tid' ][ $tid ] = $data [ 'name' ];
2011-04-17 16:10:05 +02:00
}
}
2015-02-04 11:30:59 +01:00
else
{
2016-03-29 17:37:50 +02:00
$this -> tmpl -> disableElement ( 'nm[col_filter][tid]' );
2015-02-04 11:30:59 +01:00
}
2011-04-17 16:10:05 +02:00
// get the availible org-views plus the label of the contacts view of one org
$sel_options [ 'org_view' ] = $this -> org_views ;
2015-03-03 23:23:19 +01:00
if ( isset ( $org_view ))
{
$content [ 'nm' ][ 'org_view' ] = $org_view ;
}
2011-04-25 13:30:37 +02:00
2013-12-19 11:31:44 +01:00
$content [ 'nm' ][ 'actions' ] = $this -> get_actions ( $content [ 'nm' ][ 'col_filter' ][ 'tid' ], $content [ 'nm' ][ 'org_view' ]);
2011-04-25 13:30:37 +02:00
2011-04-17 16:10:05 +02:00
if ( ! isset ( $sel_options [ 'org_view' ][( string ) $content [ 'nm' ][ 'org_view' ]]))
{
2013-10-22 00:18:41 +02:00
$sel_options [ 'org_view' ] += $this -> _get_org_name (( string ) $content [ 'nm' ][ 'org_view' ]);
2011-04-17 16:10:05 +02:00
}
// unset the filters regarding organisations, when there is no organisation selected
if ( empty ( $sel_options [ 'org_view' ][( string ) $content [ 'nm' ][ 'org_view' ]]) || stripos ( $org_view , " : " ) === false )
{
unset ( $content [ 'nm' ][ 'col_filter' ][ 'org_name' ]);
unset ( $content [ 'nm' ][ 'col_filter' ][ 'org_unit' ]);
unset ( $content [ 'nm' ][ 'col_filter' ][ 'adr_one_locality' ]);
}
$content [ 'nm' ][ 'org_view_label' ] = $sel_options [ 'org_view' ][( string ) $content [ 'nm' ][ 'org_view' ]];
2013-09-20 12:50:48 +02:00
$this -> tmpl -> read ( $do_email ? 'addressbook.email' : 'addressbook.index' );
2011-04-17 16:10:05 +02:00
return $this -> tmpl -> exec ( $do_email ? 'addressbook.addressbook_ui.emailpopup' : 'addressbook.addressbook_ui.index' ,
2016-04-29 12:41:53 +02:00
$content , $sel_options , array (), $preserv , $do_email ? 2 : 0 );
2011-04-17 16:10:05 +02:00
}
/**
* Get actions / context menu items
*
2016-04-29 12:41:53 +02:00
* @ param string $tid_filter = null
* @ return array see Etemplate\Widget\Nextmatch :: get_actions ()
2011-04-17 16:10:05 +02:00
*/
2016-04-29 12:41:53 +02:00
public function get_actions ( $tid_filter = null )
2011-04-17 16:10:05 +02:00
{
2015-03-10 16:41:53 +01:00
// Contact view
$actions = array (
'view' => array (
'caption' => 'CRM-View' ,
'default' => $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'addressbook' ][ 'crm_list' ] != '~edit~' ,
'allowOnMultiple' => false ,
'group' => $group = 1 ,
'onExecute' => 'javaScript:app.addressbook.view' ,
'disableClass' => 'contact_organisation' ,
'hideOnDisabled' => true ,
// Children added below
2016-03-09 13:31:55 +01:00
'children' => array (),
'hideOnMobile' => true
2015-03-10 16:41:53 +01:00
),
'open' => array (
'caption' => 'Open' ,
'default' => $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'addressbook' ][ 'crm_list' ] == '~edit~' ,
'allowOnMultiple' => false ,
'disableClass' => 'contact_organisation' ,
'hideOnDisabled' => true ,
'url' => 'menuaction=addressbook.addressbook_ui.edit&contact_id=$id' ,
2016-04-29 12:41:53 +02:00
'popup' => Link :: get_registry ( 'addressbook' , 'edit_popup' ),
2015-03-10 16:41:53 +01:00
'group' => $group ,
),
'add' => array (
'caption' => 'Add' ,
'group' => $group ,
'disableClass' => 'contact_organisation' ,
'hideOnDisabled' => true ,
'children' => array (
'new' => array (
'caption' => 'New' ,
'url' => 'menuaction=addressbook.addressbook_ui.edit' ,
2016-04-29 12:41:53 +02:00
'popup' => Link :: get_registry ( 'addressbook' , 'add_popup' ),
2015-03-10 16:41:53 +01:00
'icon' => 'new' ,
),
'copy' => array (
'caption' => 'Copy' ,
'url' => 'menuaction=addressbook.addressbook_ui.edit&makecp=1&contact_id=$id' ,
2016-04-29 12:41:53 +02:00
'popup' => Link :: get_registry ( 'addressbook' , 'add_popup' ),
2015-03-10 16:41:53 +01:00
'allowOnMultiple' => false ,
'icon' => 'copy' ,
2011-04-25 13:30:37 +02:00
),
),
2016-03-09 13:31:55 +01:00
'hideOnMobile' => true
2015-03-10 16:41:53 +01:00
),
);
// CRM view options
$crm_count = 0 ;
$crm_apps = array ( 'infolog' , 'tracker' );
foreach ( $crm_apps as $app )
{
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ $app ]) $crm_count ++ ;
}
if ( $crm_count > 1 )
{
2014-03-25 17:53:36 +01:00
foreach ( $crm_apps as $app )
{
2015-03-10 16:41:53 +01:00
$actions [ 'view' ][ 'children' ][ " view- $app " ] = array (
'caption' => $app ,
'icon' => " $app /navbar "
);
2014-03-25 17:53:36 +01:00
}
2011-04-25 13:30:37 +02:00
}
2015-04-24 17:13:45 +02:00
2015-03-10 16:41:53 +01:00
// org view
$actions += array (
'view_org' => array (
'caption' => 'View' ,
'default' => true ,
'allowOnMultiple' => false ,
'group' => $group = 1 ,
'disableClass' => 'contact_contact' ,
'hideOnDisabled' => true
),
'add_org' => array (
'caption' => 'Add' ,
'group' => $group ,
'allowOnMultiple' => false ,
'disableClass' => 'contact_contact' ,
'hideOnDisabled' => true ,
'url' => 'menuaction=addressbook.addressbook_ui.edit&org=$id' ,
2016-04-29 12:41:53 +02:00
'popup' => Link :: get_registry ( 'addressbook' , 'add_popup' ),
2015-03-10 16:41:53 +01:00
),
);
2011-04-17 16:10:05 +02:00
++ $group ; // other AB related stuff group: lists, AB's, categories
// categories submenu
$actions [ 'cat' ] = array (
'caption' => 'Categories' ,
'group' => $group ,
'children' => array (
2016-04-29 12:41:53 +02:00
'cat_add' => Etemplate\Widget\Nextmatch :: category_action (
2012-10-15 19:57:58 +02:00
'addressbook' , $group , 'Add category' , 'cat_add_' ,
2016-04-29 12:41:53 +02:00
true , 0 , Etemplate\Widget\Nextmatch :: DEFAULT_MAX_MENU_LENGTH , false
2011-04-25 16:13:40 +02:00
) + array (
'icon' => 'foldertree_nolines_plus' ,
'disableClass' => 'rowNoEdit' ,
),
2016-04-29 12:41:53 +02:00
'cat_del' => Etemplate\Widget\Nextmatch :: category_action (
2012-10-15 19:57:58 +02:00
'addressbook' , $group , 'Delete category' , 'cat_del_' ,
2016-04-29 12:41:53 +02:00
true , 0 , Etemplate\Widget\Nextmatch :: DEFAULT_MAX_MENU_LENGTH , false
2011-04-25 16:13:40 +02:00
) + array (
'icon' => 'foldertree_nolines_minus' ,
'disableClass' => 'rowNoEdit' ,
2014-02-12 12:07:33 +01:00
),
2011-04-17 16:10:05 +02:00
),
);
if ( ! $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'preferences' ]) unset ( $actions [ 'cats' ][ 'children' ][ 'cat_edit' ]);
// Submenu for all distributionlist stuff
$actions [ 'lists' ] = array (
'caption' => 'Distribution lists' ,
'children' => array (
'list_add' => array (
'caption' => 'Add a new list' ,
'icon' => 'new' ,
2013-09-20 12:50:48 +02:00
'onExecute' => 'javaScript:app.addressbook.add_new_list' ,
2011-04-17 16:10:05 +02:00
),
),
'group' => $group ,
);
2016-04-29 12:41:53 +02:00
if (( $add_lists = $this -> get_lists ( Acl :: EDIT ))) // do we have distribution lists?, and are we allowed to edit them
2011-04-17 16:10:05 +02:00
{
$actions [ 'lists' ][ 'children' ] += array (
'to_list' => array (
'caption' => 'Add to distribution list' ,
'children' => $add_lists ,
'prefix' => 'to_list_' ,
'icon' => 'foldertree_nolines_plus' ,
2012-01-05 05:10:54 +01:00
'enabled' => ( $add_lists ? true : false ), // if there are editable lists, allow to add a contact to one of them,
2011-12-28 11:55:24 +01:00
//'disableClass' => 'rowNoEdit', // wether you are allowed to edit the contact or not, as you alter a list, not the contact
2011-04-17 16:10:05 +02:00
),
'remove_from_list' => array (
'caption' => 'Remove from distribution list' ,
'confirm' => 'Remove selected contacts from distribution list' ,
'icon' => 'foldertree_nolines_minus' ,
2013-09-20 12:50:48 +02:00
'enabled' => 'javaScript:app.addressbook.nm_compare_field' ,
2011-04-25 16:13:40 +02:00
'fieldId' => 'exec[nm][filter2]' ,
'fieldValue' => '!' , // enable if list != ''
2011-04-17 16:10:05 +02:00
),
2014-10-27 19:43:03 +01:00
'rename_list' => array (
'caption' => 'Rename selected distribution list' ,
'icon' => 'edit' ,
'enabled' => 'javaScript:app.addressbook.nm_compare_field' ,
'fieldId' => 'exec[nm][filter2]' ,
'fieldValue' => '!' , // enable if list != ''
'onExecute' => 'javaScript:app.addressbook.rename_list'
),
2011-04-17 16:10:05 +02:00
'delete_list' => array (
'caption' => 'Delete selected distribution list!' ,
'confirm' => 'Delete selected distribution list!' ,
'icon' => 'delete' ,
2013-09-20 12:50:48 +02:00
'enabled' => 'javaScript:app.addressbook.nm_compare_field' ,
2011-04-25 16:13:40 +02:00
'fieldId' => 'exec[nm][filter2]' ,
'fieldValue' => '!' , // enable if list != ''
2011-04-17 16:10:05 +02:00
),
);
2013-06-10 21:47:09 +02:00
if ( is_subclass_of ( 'etemplate' , 'etemplate_new' ))
{
$actions [ 'lists' ][ 'children' ][ 'remove_from_list' ][ 'fieldId' ] = 'filter2' ;
2014-10-28 20:11:10 +01:00
$actions [ 'lists' ][ 'children' ][ 'rename_list' ][ 'fieldId' ] = 'filter2' ;
2013-06-10 21:47:09 +02:00
$actions [ 'lists' ][ 'children' ][ 'delete_list' ][ 'fieldId' ] = 'filter2' ;
}
2011-04-17 16:10:05 +02:00
}
// move to AB
2016-04-29 12:41:53 +02:00
if (( $move2addressbooks = $this -> get_addressbooks ( Acl :: ADD ))) // do we have addressbooks, we should
2011-04-17 16:10:05 +02:00
{
2014-08-19 16:12:40 +02:00
unset ( $move2addressbooks [ 0 ]); // do not offer action to move contact to an account, as we dont support that currrently
2011-04-25 13:30:37 +02:00
foreach ( $move2addressbooks as $owner => $label )
{
2016-04-29 12:41:53 +02:00
$icon = $type_label = null ;
2011-04-25 13:30:37 +02:00
$this -> type_icon (( int ) $owner , substr ( $owner , - 1 ) == 'p' , 'n' , $icon , $type_label );
$move2addressbooks [ $owner ] = array (
'icon' => $icon ,
'caption' => $label ,
);
}
2013-11-08 19:51:37 +01:00
// copy checkbox
$move2addressbooks = array (
'copy' => array (
'id' => 'move_to_copy' ,
'caption' => 'Copy instead of move' ,
'checkbox' => true ,
)) + $move2addressbooks ;
2011-04-17 16:10:05 +02:00
$actions [ 'move_to' ] = array (
'caption' => 'Move to addressbook' ,
'children' => $move2addressbooks ,
'prefix' => 'move_to_' ,
'group' => $group ,
2011-04-25 16:13:40 +02:00
'disableClass' => 'rowNoDelete' ,
2016-03-09 13:31:55 +01:00
'hideOnMobile' => true
2011-04-17 16:10:05 +02:00
);
}
$actions [ 'merge' ] = array (
'caption' => 'Merge contacts' ,
'confirm' => 'Merge into first or account, deletes all other!' ,
'hint' => 'Merge into first or account, deletes all other!' ,
2011-04-17 23:25:01 +02:00
'allowOnMultiple' => 'only' ,
2011-04-17 16:10:05 +02:00
'group' => $group ,
2016-03-09 13:31:55 +01:00
'hideOnMobile' => true
2011-04-17 16:10:05 +02:00
);
++ $group ; // integration with other apps: infolog, calendar, filemanager
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'infolog' ])
{
$actions [ 'infolog_app' ] = array (
'caption' => 'InfoLog' ,
'icon' => 'infolog/navbar' ,
'group' => $group ,
'children' => array (
'infolog' => array (
'caption' => lang ( 'View linked InfoLog entries' ),
'icon' => 'infolog/navbar' ,
2014-03-18 20:20:29 +01:00
'onExecute' => 'javaScript:app.addressbook.view_infolog' ,
'allowOnMultiple' => true ,
2015-03-12 00:15:50 +01:00
'hideOnDisabled' => true ,
2011-04-17 16:10:05 +02:00
),
'infolog_add' => array (
'caption' => 'Add a new Infolog' ,
'icon' => 'new' ,
2011-04-26 18:22:10 +02:00
'url' => 'menuaction=infolog.infolog_ui.edit&type=task&action=addressbook&action_id=$id' ,
2016-04-29 12:41:53 +02:00
'popup' => Link :: get_registry ( 'infolog' , 'add_popup' ),
2013-09-20 12:50:48 +02:00
'onExecute' => 'javaScript:app.addressbook.add_task' , // call server for org-view only
2011-04-17 16:10:05 +02:00
),
2016-03-09 13:31:55 +01:00
),
'hideOnMobile' => true
2011-04-17 16:10:05 +02:00
);
}
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'calendar' ])
{
$actions [ 'calendar' ] = array (
'icon' => 'calendar/navbar' ,
2012-01-05 05:10:54 +01:00
'caption' => 'Calendar' ,
2011-04-17 16:10:05 +02:00
'group' => $group ,
2012-01-05 05:10:54 +01:00
'children' => array (
'calendar_view' => array (
'caption' => 'Show' ,
'icon' => 'view' ,
2015-03-17 20:14:00 +01:00
'onExecute' => 'javaScript:app.addressbook.view_calendar' ,
2015-03-12 00:15:50 +01:00
'targetapp' => 'calendar' , // open in calendar tab,
'hideOnDisabled' => true ,
2012-01-05 05:10:54 +01:00
),
'calendar_add' => array (
'caption' => 'Add appointment' ,
'icon' => 'new' ,
2016-04-29 12:41:53 +02:00
'popup' => Link :: get_registry ( 'calendar' , 'add_popup' ),
2015-03-17 20:14:00 +01:00
'onExecute' => 'javaScript:app.addressbook.add_cal' ,
2012-01-05 05:10:54 +01:00
),
),
2016-03-09 13:31:55 +01:00
'hideOnMobile' => true
2011-04-17 16:10:05 +02:00
);
}
2013-12-19 15:14:50 +01:00
//Send to email
$actions [ 'email' ] = array (
'caption' => 'Email' ,
'icon' => 'mail/navbar' ,
2015-03-12 00:15:50 +01:00
'disableClass' => 'contact_organisation' ,
'hideOnDisabled' => true ,
2013-12-19 15:14:50 +01:00
'group' => $group ,
'children' => array (
2014-01-13 18:40:36 +01:00
'add_to_to' => array (
2014-01-15 14:01:31 +01:00
'caption' => lang ( 'Add to To' ),
2014-01-13 18:40:36 +01:00
'no_lang' => true ,
'onExecute' => 'javaScript:app.addressbook.addEmail' ,
),
2014-01-06 11:12:51 +01:00
'add_to_cc' => array (
2014-01-15 14:01:31 +01:00
'caption' => lang ( 'Add to Cc' ),
2014-01-06 11:12:51 +01:00
'no_lang' => true ,
2014-01-13 18:40:36 +01:00
'onExecute' => 'javaScript:app.addressbook.addEmail' ,
2014-01-06 11:12:51 +01:00
),
'add_to_bcc' => array (
2014-01-15 14:01:31 +01:00
'caption' => lang ( 'Add to BCc' ),
2014-01-06 11:12:51 +01:00
'no_lang' => true ,
2014-01-13 18:40:36 +01:00
'onExecute' => 'javaScript:app.addressbook.addEmail' ,
2014-01-06 11:12:51 +01:00
),
2013-12-19 15:14:50 +01:00
'email_business' => array (
2014-01-15 14:01:31 +01:00
'caption' => lang ( 'Business email' ),
2013-12-19 15:14:50 +01:00
'no_lang' => true ,
2014-01-13 18:40:36 +01:00
'checkbox' => true ,
'group' => $group ,
2014-01-15 12:22:37 +01:00
'onExecute' => 'javaScript:app.addressbook.mailCheckbox' ,
'checked' => $this -> prefs [ 'preferredMail' ][ 'business' ],
2013-12-19 15:14:50 +01:00
),
'email_home' => array (
2014-01-15 14:01:31 +01:00
'caption' => lang ( 'Home email' ),
2013-12-19 15:14:50 +01:00
'no_lang' => true ,
2014-01-13 18:40:36 +01:00
'checkbox' => true ,
'group' => $group ,
2014-01-15 12:22:37 +01:00
'onExecute' => 'javaScript:app.addressbook.mailCheckbox' ,
'checked' => $this -> prefs [ 'preferredMail' ][ 'private' ],
2013-12-19 15:14:50 +01:00
),
),
2011-04-17 16:10:05 +02:00
2013-12-19 15:14:50 +01:00
);
2014-01-15 12:22:37 +01:00
if ( ! $this -> prefs [ 'preferredMail' ])
$actions [ 'email' ][ 'children' ][ 'email_business' ][ 'checked' ] = true ;
2013-12-19 16:53:26 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'filemanager' ])
{
$actions [ 'filemanager' ] = array (
'icon' => 'filemanager/navbar' ,
'caption' => 'Filemanager' ,
2014-01-16 18:23:39 +01:00
'url' => 'menuaction=filemanager.filemanager_ui.index&path=/apps/addressbook/$id&ajax=true' ,
2013-12-19 16:53:26 +01:00
'allowOnMultiple' => false ,
'group' => $group ,
// disable for for org-views, as it needs contact-ids
2015-03-12 00:15:50 +01:00
'disableClass' => 'contact_organisation' ,
2016-03-09 13:31:55 +01:00
'hideOnMobile' => true
2013-12-19 16:53:26 +01:00
);
}
2016-05-20 15:50:26 +02:00
$actions [ 'geolocation' ] = array (
'caption' => 'GeoLocation' ,
'icon' => 'map' ,
'group' => ++ $group ,
'children' => array (
'private' => array (
'caption' => 'Private Address' ,
'enabled' => 'javaScript:app.addressbook.geoLocation_enabled' ,
2016-05-25 12:50:18 +02:00
'onExecute' => 'javaScript:app.addressbook.geoLocationExec' ,
2016-05-20 15:50:26 +02:00
),
'business' => array (
2016-05-25 14:26:15 +02:00
'caption' => 'Business Address' ,
2016-05-20 15:50:26 +02:00
'enabled' => 'javaScript:app.addressbook.geoLocation_enabled' ,
2016-05-25 12:50:18 +02:00
'onExecute' => 'javaScript:app.addressbook.geoLocationExec' ,
2016-05-20 15:50:26 +02:00
)
)
);
2011-04-17 16:10:05 +02:00
// check if user is an admin or the export is not generally turned off (contact_export_limit is non-numerical, eg. no)
2016-04-29 12:41:53 +02:00
$exception = Api\Storage\Merge :: is_export_limit_excepted ();
2011-08-17 17:38:56 +02:00
if (( isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ]) || $exception ) || ! $this -> config [ 'contact_export_limit' ] || ( int ) $this -> config [ 'contact_export_limit' ])
2011-04-17 16:10:05 +02:00
{
$actions [ 'export' ] = array (
'caption' => 'Export' ,
'icon' => 'filesave' ,
'group' => ++ $group ,
'children' => array (
2012-02-27 17:06:10 +01:00
'csv' => array (
'caption' => 'Export as CSV' ,
'allowOnMultiple' => true ,
2014-07-07 18:47:08 +02:00
'url' => 'menuaction=importexport.importexport_export_ui.export_dialog&appname=addressbook&plugin=addressbook_export_contacts_csv&selection=$id&select_all=$select_all' ,
2013-05-29 22:51:28 +02:00
'popup' => '850x440'
2012-02-27 17:06:10 +01:00
),
2013-10-04 14:48:11 +02:00
'vcard' => array (
'caption' => 'Export as VCard' ,
'postSubmit' => true , // download needs post submit (not Ajax) to work
2016-04-29 12:41:53 +02:00
'icon' => Vfs :: mime_icon ( 'text/vcard' ),
2013-10-04 14:48:11 +02:00
),
2011-04-17 16:10:05 +02:00
),
2016-03-09 13:31:55 +01:00
'hideOnMobile' => true
2011-04-17 16:10:05 +02:00
);
}
2016-04-06 11:49:50 +02:00
$actions [ 'documents' ] = Api\Contacts\Merge :: document_action (
2011-04-25 13:30:37 +02:00
$this -> prefs [ 'document_dir' ], $group , 'Insert in document' , 'document_' ,
2011-06-16 13:36:15 +02:00
$this -> prefs [ 'default_document' ], $this -> config [ 'contact_export_limit' ]
2011-04-25 13:30:37 +02:00
);
2014-03-21 12:54:38 +01:00
if ( isset ( $GLOBALS [ 'egw_info' ][ 'apps' ][ 'stylite' ]) && ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'felamimail' ] || $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'mail' ]))
2011-11-29 13:07:11 +01:00
{
$actions [ 'mail' ] = array (
'caption' => lang ( 'Mail VCard' ),
'icon' => 'filemanager/mail_post_to' ,
'group' => $group ,
2013-09-20 12:50:48 +02:00
'onExecute' => 'javaScript:app.addressbook.adb_mail_vcard' ,
2015-03-12 00:15:50 +01:00
'disableClass' => 'contact_organisation' ,
'hideOnDisabled' => true ,
2016-03-09 13:31:55 +01:00
'hideOnMobile' => true
2011-11-29 13:07:11 +01:00
);
}
2011-04-17 16:10:05 +02:00
++ $group ;
if ( ! ( $tid_filter == 'D' && ! $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ] && $this -> config [ 'history' ] != 'userpurge' ))
{
$actions [ 'delete' ] = array (
'caption' => 'Delete' ,
'confirm' => 'Delete this contact' ,
2011-04-17 23:25:01 +02:00
'confirm_multiple' => 'Delete these entries' ,
2011-04-17 16:10:05 +02:00
'group' => $group ,
2011-04-17 23:25:01 +02:00
'disableClass' => 'rowNoDelete' ,
2011-04-17 16:10:05 +02:00
);
}
2016-04-29 12:41:53 +02:00
if ( $this -> grants [ 0 ] & Acl :: DELETE )
2014-03-19 14:20:46 +01:00
{
$actions [ 'delete_account' ] = array (
'caption' => 'Delete' ,
'icon' => 'delete' ,
'group' => $group ,
'enableClass' => 'rowAccount' ,
'hideOnDisabled' => true ,
'popup' => '400x200' ,
'url' => 'menuaction=admin.admin_account.delete&contact_id=$id' ,
);
$actions [ 'delete' ][ 'hideOnDisabled' ] = true ;
}
2011-04-17 16:10:05 +02:00
if ( $tid_filter == 'D' )
{
$actions [ 'undelete' ] = array (
'caption' => 'Un-delete' ,
2012-12-31 23:05:14 +01:00
'icon' => 'revert' ,
2011-04-17 16:10:05 +02:00
'group' => $group ,
2011-04-25 16:13:40 +02:00
'disableClass' => 'rowNoEdit' ,
2011-04-17 16:10:05 +02:00
);
}
2016-05-04 21:07:54 +02:00
if ( isset ( $actions [ 'export' ][ 'children' ][ 'csv' ]) &&
( ! isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'importexport' ]) ||
! importexport_helper_functions :: has_definitions ( 'addressbook' , 'export' )))
{
unset ( $actions [ 'export' ][ 'children' ][ 'csv' ]);
}
2016-02-02 11:26:13 +01:00
// Intercept open action in order to open entry into view mode instead of edit
2016-04-29 12:41:53 +02:00
if ( Api\Header\UserAgent :: mobile ())
2016-02-04 18:25:52 +01:00
{
$actions [ 'open' ][ 'onExecute' ] = 'javaScript:app.addressbook.viewEntry' ;
2016-05-25 16:44:23 +02:00
$actions [ 'open' ][ 'mobileViewTemplate' ] = 'view?' . filemtime ( Api\Etemplate\Widget\Template :: rel2path ( '/addressbook/templates/mobile/view.xet' ));
2016-02-05 10:38:21 +01:00
$actions [ 'view' ][ 'default' ] = false ;
$actions [ 'open' ][ 'default' ] = true ;
2016-02-04 18:25:52 +01:00
}
2011-04-25 13:30:37 +02:00
//echo "<p>".__METHOD__."($do_email, $tid_filter, $org_view)</p>\n"; _debug_array($actions);
2013-06-04 01:10:23 +02:00
// Allow contacts to be dragged
/*
$actions [ 'drag' ] = array (
'type' => 'drag' ,
'dragType' => 'addressbook'
);
*/
2011-04-17 16:10:05 +02:00
return $actions ;
}
2013-11-08 19:51:37 +01:00
2013-10-22 00:18:41 +02:00
/**
* Get the name of an organization from an ID for the org_view filter
*
* @ param string $org
* @ return Array ID => name
*/
private function _get_org_name ( $org )
{
$org_name = array ();
if ( strpos ( $org , '*AND*' ) !== false ) $org = str_replace ( '*AND*' , '&' , $org );
foreach ( explode ( '|||' , $org ) as $part )
{
list (, $name ) = explode ( ':' , $part , 2 );
if ( $name ) $org_name [] = $name ;
}
2016-04-29 12:41:53 +02:00
$name = implode ( ': ' , $org_name );
return $name ? array ( $org => $name ) : array ();
2013-10-22 00:18:41 +02:00
}
2013-11-08 19:51:37 +01:00
2006-06-16 06:44:58 +02:00
/**
* Email address - selection popup
*
2016-04-29 12:41:53 +02:00
* @ param array $content = null submitted content
* @ param string $msg = null message to show
2006-06-16 06:44:58 +02:00
*/
function emailpopup ( $content = null , $msg = null )
2008-04-18 08:10:31 +02:00
{
2007-05-25 20:20:57 +02:00
if ( strpos ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'java_script' ], 'addEmail' ) === false )
2006-06-16 06:44:58 +02:00
{
2013-07-17 16:53:24 +02:00
$handler = 'opener.addEmail(to,email)' ;
2007-05-25 20:20:57 +02:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'java_script' ] .= "
2006-06-16 06:44:58 +02:00
< script >
2013-07-17 16:53:24 +02:00
window . egw_LAB . wait ( function () {
2006-06-16 06:44:58 +02:00
window . focus ();
2008-04-18 08:10:31 +02:00
2013-07-17 16:53:24 +02:00
window . addEmail = function ( email )
2006-06-16 06:44:58 +02:00
{
2007-05-25 20:20:57 +02:00
var to = 'to' ;
2010-12-07 14:57:16 +01:00
splitter = email . indexOf ( ' <' );
namepart = email . substring ( 0 , splitter );
emailpart = email . substring ( splitter );
email = namepart . replace ( /@/ g , ' ' ) + emailpart ;
2011-02-15 12:38:20 +01:00
2008-04-18 08:10:31 +02:00
if ( document . getElementById ( 'exec[nm][to][cc]' ) . checked == true )
2007-05-25 20:20:57 +02:00
{
to = 'cc' ;
}
else
{
if ( document . getElementById ( 'exec[nm][to][bcc]' ) . checked == true )
{
to = 'bcc' ;
}
}
2006-06-16 06:44:58 +02:00
$handler ;
2013-07-17 16:53:24 +02:00
};
});
2006-06-16 06:44:58 +02:00
</ script >
" ;
2007-05-25 20:20:57 +02:00
}
2006-06-16 06:44:58 +02:00
return $this -> index ( $content , $msg , true );
2005-11-04 00:47:52 +01:00
}
2008-04-18 08:10:31 +02:00
2014-03-18 20:20:29 +01:00
/**
* Return the contacts in an organisation via AJAX
*
* @ param string | string [] $org Organisation ID
2016-04-29 12:41:53 +02:00
* @ param mixed $_query Query filters ( category , etc ) to use , or null to use session
2014-03-18 20:20:29 +01:00
* @ return array
*/
2016-04-29 12:41:53 +02:00
public function ajax_organisation_contacts ( $org , $_query = null )
2014-03-18 20:20:29 +01:00
{
$org_contacts = array ();
2016-04-29 12:41:53 +02:00
$query = ! $_query ? Api\Cache :: getSession ( 'addressbook' , 'index' ) : $_query ;
2014-03-18 20:20:29 +01:00
$query [ 'num_rows' ] = - 1 ; // all
if ( ! is_array ( $query [ 'col_filter' ])) $query [ 'col_filter' ] = array ();
2014-03-19 14:20:46 +01:00
2014-03-18 20:20:29 +01:00
if ( ! is_array ( $org )) $org = array ( $org );
foreach ( $org as $org_name )
{
$query [ 'org_view' ] = $org_name ;
$checked = array ();
2016-04-29 12:41:53 +02:00
$readonlys = null ;
$this -> get_rows ( $query , $checked , $readonlys , true ); // true = only return the id's
2014-03-18 20:20:29 +01:00
if ( $checked [ 0 ])
{
$org_contacts = array_merge ( $org_contacts , $checked );
}
}
2016-04-29 12:41:53 +02:00
Api\Json\Response :: get () -> data ( array_unique ( $org_contacts ));
2014-03-18 20:20:29 +01:00
}
2006-10-23 13:48:56 +02:00
/**
* Show the infologs of an whole organisation
*
* @ param string $org
*/
function infolog_org_view ( $org )
{
2016-04-29 12:41:53 +02:00
$query = Api\Cache :: getSession ( 'addressbook' , 'index' );
2006-10-23 13:48:56 +02:00
$query [ 'num_rows' ] = - 1 ; // all
$query [ 'org_view' ] = $org ;
2007-05-22 20:06:38 +02:00
$query [ 'searchletter' ] = '' ;
2016-04-29 12:41:53 +02:00
$checked = $readonlys = null ;
2006-10-23 13:48:56 +02:00
$this -> get_rows ( $query , $checked , $readonlys , true ); // true = only return the id's
if ( count ( $checked ) > 1 ) // use a nicely formatted org-name as title in infolog
{
$parts = array ();
2009-07-20 14:11:05 +02:00
if ( strpos ( $org , '*AND*' ) !== false ) $org = str_replace ( '*AND*' , '&' , $org );
2006-10-23 13:48:56 +02:00
foreach ( explode ( '|||' , $org ) as $part )
{
list (, $part ) = explode ( ':' , $part , 2 );
if ( $part ) $parts [] = $part ;
}
$org = implode ( ', ' , $parts );
}
else
{
$org = '' ; // use infolog default of link-title
}
2016-04-29 12:41:53 +02:00
Egw :: redirect_link ( '/index.php' , array (
2008-10-07 15:04:49 +02:00
'menuaction' => 'infolog.infolog_ui.index' ,
2006-10-23 13:48:56 +02:00
'action' => 'addressbook' ,
'action_id' => implode ( ',' , $checked ),
'action_title' => $org ,
2014-03-13 20:04:47 +01:00
), 'infolog' );
2006-10-23 13:48:56 +02:00
}
2008-04-18 08:10:31 +02:00
2014-10-27 19:43:03 +01:00
/**
2014-10-28 20:50:19 +01:00
* Create or rename an existing email list
2014-10-27 19:43:03 +01:00
*
2014-10-28 20:50:19 +01:00
* @ param int $list_id ID of existing list , or 0 for a new one
* @ param string $new_name List name
2016-04-29 12:41:53 +02:00
* @ param int $_owner List owner , or empty for current user
2016-12-20 16:47:33 +01:00
* @ param string [] [ $contacts ] List of contacts to add to the array
2014-10-27 19:43:03 +01:00
* @ return boolean | string
*/
2016-12-20 16:47:33 +01:00
function ajax_set_list ( $list_id , $new_name , $_owner = false , $contacts = array ())
2014-10-27 19:43:03 +01:00
{
2014-10-28 20:50:19 +01:00
// Set owner to current user, if not set
2016-04-29 12:41:53 +02:00
$owner = $_owner ? $_owner : $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_id' ];
2016-09-15 17:37:04 +02:00
// if admin forced or set default for add_default pref
// consider default_addressbook as owner which already
// covered all cases in contacts class.
if ( $owner == ( int ) $GLOBALS [ 'egw' ] -> preferences -> default [ 'addressbook' ][ 'add_default' ] ||
$owner == ( int ) $GLOBALS [ 'egw' ] -> preferences -> forced [ 'addressbook' ][ 'add_default' ])
{
$owner = $this -> default_addressbook ;
}
2014-10-27 19:43:03 +01:00
// Check for valid list & permissions
2014-10-28 20:50:19 +01:00
if ( ! ( int ) $list_id && ! $this -> check_list ( null , EGW_ACL_ADD | EGW_ACL_EDIT , $owner ))
2014-10-27 19:43:03 +01:00
{
2016-04-29 12:41:53 +02:00
Api\Json\Response :: get () -> apply ( 'egw.message' , array ( lang ( 'List creation failed, no rights!' ), 'error' ));
2014-10-27 19:43:03 +01:00
return ;
}
2016-04-29 12:41:53 +02:00
if (( int ) $list_id && ! $this -> check_list (( int ) $list_id , Acl :: EDIT , $owner ))
2014-10-27 19:43:03 +01:00
{
2016-04-29 12:41:53 +02:00
Api\Json\Response :: get () -> apply ( 'egw.message' , array ( lang ( 'Insufficent rights to edit this list!' ), 'error' ));
2014-10-27 19:43:03 +01:00
return ;
}
2014-10-28 20:50:19 +01:00
$list = array ( 'list_owner' => $owner );
2014-10-27 19:43:03 +01:00
// Rename
2014-10-28 20:50:19 +01:00
if ( $list_id )
{
$list = $this -> read_list (( int ) $list_id );
}
2014-10-27 19:43:03 +01:00
$list [ 'list_name' ] = $new_name ;
2014-10-28 20:50:19 +01:00
$new_id = $this -> add_list ( array ( 'list_id' => ( int ) $list_id ), $list [ 'list_owner' ], array (), $list );
2015-02-04 11:30:59 +01:00
2016-12-20 16:47:33 +01:00
if ( $contacts )
{
$this -> add2list ( $contacts , $new_id );
}
2016-04-29 12:41:53 +02:00
Api\Json\Response :: get () -> apply ( 'egw.message' , array (
2014-10-28 20:50:19 +01:00
$new_id == $list_id ? lang ( 'Distribution list renamed' ) : lang ( 'List created' ),
'success'
));
2014-10-27 19:43:03 +01:00
// Success, just update selectbox to new value
2016-04-29 12:41:53 +02:00
Api\Json\Response :: get () -> data ( $new_id == $list_id ? " true " : $new_id );
2014-10-27 19:43:03 +01:00
}
2016-05-25 12:50:18 +02:00
/**
* Ajax function to get contact data out of provided account_id
*
2016-06-01 09:55:57 +02:00
* @ param string $account_id
2016-05-25 12:50:18 +02:00
*/
function ajax_get_contact ( $account_id )
{
$bo = new Api\Contacts ();
2016-06-01 09:55:57 +02:00
$contact = $bo -> read ( 'account:' . $account_id );
2016-05-25 12:50:18 +02:00
Api\Json\Response :: get () -> data ( $contact );
}
2016-06-09 23:05:25 +02:00
/**
* Disable / clear advanced search
*
* Advanced search is stored server side in session no matter what the nextmatch
* sends , so we have to clear it here .
*/
public static function ajax_clear_advanced_search ()
{
$query = Api\Cache :: getSession ( 'addressbook' , 'index' );
unset ( $query [ 'advanced_search' ]);
Api\Cache :: setSession ( 'addressbook' , 'index' , $query );
Api\Cache :: setSession ( 'addressbook' , 'advanced_search' , false );
}
2016-06-15 12:09:24 +02:00
2006-04-23 16:40:31 +02:00
/**
* apply an action to multiple contacts
*
* @ param string / int $action 'delete' , 'vcard' , 'csv' or nummerical account_id to move contacts to that addessbook
* @ param array $checked contact id ' s to use if ! $use_all
* @ param boolean $use_all if true use all contacts of the current selection ( in the session )
* @ param int & $success number of succeded actions
* @ param int & $failed number of failed actions ( not enought permissions )
* @ param string & $action_msg translated verb for the actions , to be used in a message like % 1 contacts 'deleted'
2007-05-25 20:20:57 +02:00
* @ param string / array $session_name 'index' or 'email' , or array with session - data depending if we are in the main list or the popup
2006-04-23 16:40:31 +02:00
* @ return boolean true if all actions succeded , false otherwise
*/
2013-11-08 19:51:37 +01:00
function action ( $action , $checked , $use_all , & $success , & $failed , & $action_msg , $session_name , & $msg , $checkboxes = NULL )
2006-04-23 16:40:31 +02:00
{
2008-04-18 08:10:31 +02:00
//echo "<p>uicontacts::action('$action',".print_r($checked,true).','.(int)$use_all.",...)</p>\n";
2006-04-23 16:40:31 +02:00
$success = $failed = 0 ;
2007-03-13 14:38:15 +01:00
if ( $use_all || in_array ( $action , array ( 'remove_from_list' , 'delete_list' )))
2006-04-23 16:40:31 +02:00
{
// get the whole selection
2016-04-29 12:41:53 +02:00
$query = is_array ( $session_name ) ? $session_name : Api\Cache :: getSession ( 'addressbook' , $session_name );
2008-04-18 08:10:31 +02:00
2007-03-13 14:38:15 +01:00
if ( $use_all )
{
2007-05-22 10:02:06 +02:00
@ set_time_limit ( 0 ); // switch off the execution time limit, as it's for big selections to small
2007-03-13 14:38:15 +01:00
$query [ 'num_rows' ] = - 1 ; // all
2016-04-29 12:41:53 +02:00
$readonlys = null ;
2007-03-13 14:38:15 +01:00
$this -> get_rows ( $query , $checked , $readonlys , true ); // true = only return the id's
}
2006-04-23 16:40:31 +02:00
}
2006-04-30 11:34:24 +02:00
// replace org_name:* id's with all id's of that org
$org_contacts = array ();
2007-03-13 14:38:15 +01:00
foreach (( array ) $checked as $n => $id )
2006-04-30 11:34:24 +02:00
{
if ( substr ( $id , 0 , 9 ) == 'org_name:' )
{
2007-03-13 14:38:15 +01:00
if ( count ( $checked ) == 1 && ! count ( $org_contacts ) && $action == 'infolog' )
2006-10-23 13:48:56 +02:00
{
return $this -> infolog_org_view ( $id ); // uses the org-name, instead of 'selected contacts'
}
2006-04-30 11:34:24 +02:00
unset ( $checked [ $n ]);
2016-04-29 12:41:53 +02:00
$query = Api\Cache :: getSession ( 'addressbook' , $session_name );
2006-04-30 11:34:24 +02:00
$query [ 'num_rows' ] = - 1 ; // all
$query [ 'org_view' ] = $id ;
2007-03-13 14:38:15 +01:00
unset ( $query [ 'filter2' ]);
2016-04-29 12:41:53 +02:00
$extra = $readonlys = null ;
2006-04-30 11:34:24 +02:00
$this -> get_rows ( $query , $extra , $readonlys , true ); // true = only return the id's
if ( $extra [ 0 ]) $org_contacts = array_merge ( $org_contacts , $extra );
2008-04-18 08:10:31 +02:00
}
2006-04-30 11:34:24 +02:00
}
if ( $org_contacts ) $checked = array_unique ( $checked ? array_merge ( $checked , $org_contacts ) : $org_contacts );
2006-12-13 14:39:00 +01:00
//_debug_array($checked); exit;
2008-04-18 08:10:31 +02:00
2008-02-21 12:54:22 +01:00
if ( substr ( $action , 0 , 8 ) == 'move_to_' )
{
2008-08-13 08:18:03 +02:00
$action = ( int ) substr ( $action , 8 ) . ( substr ( $action , - 1 ) == 'p' ? 'p' : '' );
2008-02-21 12:54:22 +01:00
}
2011-04-25 16:13:40 +02:00
elseif ( substr ( $action , 0 , 8 ) == 'to_list_' )
2007-03-13 14:38:15 +01:00
{
$to_list = ( int ) substr ( $action , 8 );
$action = 'to_list' ;
}
2011-04-25 16:13:40 +02:00
elseif ( substr ( $action , 0 , 9 ) == 'document_' )
2007-06-17 15:55:43 +02:00
{
2007-06-19 19:06:32 +02:00
$document = substr ( $action , 9 );
2007-06-17 15:55:43 +02:00
$action = 'document' ;
}
2011-04-25 16:13:40 +02:00
elseif ( substr ( $action , 0 , 4 ) == 'cat_' ) // cat_add_123 or cat_del_456
{
$cat_id = ( int ) substr ( $action , 8 );
$action = substr ( $action , 0 , 7 );
}
2007-05-22 10:02:06 +02:00
// Security: stop non-admins to export more then the configured number of contacts
2016-04-29 12:41:53 +02:00
if ( in_array ( $action , array ( 'csv' , 'vcard' )) && $this -> config [ 'contact_export_limit' ] && ! Api\Storage\Merge :: is_export_limit_excepted () &&
2008-10-16 13:17:49 +02:00
( ! is_numeric ( $this -> config [ 'contact_export_limit' ]) || count ( $checked ) > $this -> config [ 'contact_export_limit' ]))
2007-05-22 10:02:06 +02:00
{
$action_msg = lang ( 'exported' );
$failed = count ( $checked );
return false ;
}
2006-04-26 23:23:38 +02:00
switch ( $action )
{
2006-07-09 01:02:30 +02:00
case 'vcard' :
$action_msg = lang ( 'exported' );
2012-02-10 21:32:45 +01:00
$vcard = new addressbook_vcal ( 'addressbook' , 'text/vcard' );
$vcard -> export ( $checked );
2006-07-09 01:02:30 +02:00
// does not return!
$Ok = false ;
2008-04-18 08:10:31 +02:00
break ;
2006-12-19 12:25:44 +01:00
case 'merge' :
2016-04-29 12:41:53 +02:00
$error_msg = null ;
2006-12-19 12:25:44 +01:00
$success = $this -> merge ( $checked , $error_msg );
$failed = count ( $checked ) - ( int ) $success ;
$action_msg = lang ( 'merged' );
$checked = array (); // to not start the single actions
break ;
2007-03-13 14:38:15 +01:00
case 'delete_list' :
if ( ! $query [ 'filter2' ])
{
$msg = lang ( 'You need to select a distribution list' );
}
elseif ( $this -> delete_list ( $query [ 'filter2' ]) === false )
{
$msg = lang ( 'Insufficent rights to delete this list!' );
}
else
{
$msg = lang ( 'Distribution list deleted' );
unset ( $query [ 'filter2' ]);
2016-04-29 12:41:53 +02:00
Api\Cache :: setSession ( 'addressbook' , $session_name , $query );
2007-03-13 14:38:15 +01:00
}
2007-06-17 15:55:43 +02:00
return false ;
2015-02-04 11:30:59 +01:00
2007-06-17 15:55:43 +02:00
case 'document' :
2011-06-14 12:48:15 +02:00
if ( ! $document ) $document = $this -> prefs [ 'default_document' ];
2016-04-06 11:49:50 +02:00
$document_merge = new Api\Contacts\Merge ();
2011-06-14 12:48:15 +02:00
$msg = $document_merge -> download ( $document , $checked , '' , $this -> prefs [ 'document_dir' ]);
2011-06-16 13:36:15 +02:00
$failed = count ( $checked );
2007-06-17 15:55:43 +02:00
return false ;
2008-04-26 10:47:26 +02:00
2008-04-23 10:22:22 +02:00
case 'infolog_add' :
2016-04-29 12:41:53 +02:00
Framework :: popup ( Egw :: link ( '/index.php' , array (
2011-04-26 18:22:10 +02:00
'menuaction' => 'infolog.infolog_ui.edit' ,
'type' => 'task' ,
'action' => 'addressbook' ,
'action_id' => implode ( ',' , $checked ),
2016-04-29 12:41:53 +02:00
)), '_blank' , Link :: get_registry ( 'infolog' , 'add_popup' ));
2011-04-26 18:22:10 +02:00
$msg = '' ; // no message, as we send none in javascript too and users sees opening popup
return false ;
2012-01-05 05:10:54 +01:00
case 'calendar_add' : // add appointment for org-views, other views are handled directly in javascript
2016-04-29 12:41:53 +02:00
Framework :: popup ( Egw :: link ( '/index.php' , array (
2011-04-26 18:22:10 +02:00
'menuaction' => 'calendar.calendar_uiforms.edit' ,
'participants' => 'c' . implode ( ',c' , $checked ),
2016-04-29 12:41:53 +02:00
)), '_blank' , Link :: get_registry ( 'calendar' , 'add_popup' ));
2011-04-26 18:22:10 +02:00
$msg = '' ; // no message, as we send none in javascript too and users sees opening popup
2008-04-26 10:47:26 +02:00
return false ;
2012-01-05 05:10:54 +01:00
2015-03-17 20:14:00 +01:00
case 'calendar_view' : // show calendar for org-views, although all views are handled directly in javascript
2016-04-29 12:41:53 +02:00
Egw :: redirect_link ( '/index.php' , array (
2012-01-05 05:10:54 +01:00
'menuaction' => 'calendar.calendar_uiviews.index' ,
'owner' => 'c' . implode ( ',c' , $checked ),
));
2011-04-25 16:13:40 +02:00
}
2011-08-29 14:20:16 +02:00
foreach ( $checked as $id )
2011-04-25 16:13:40 +02:00
{
switch ( $action )
{
case 'cat_add' :
case 'cat_del' :
2016-04-29 12:41:53 +02:00
if (( $Ok = !! ( $contact = $this -> read ( $id )) && $this -> check_perms ( Acl :: EDIT , $contact )))
2008-03-10 17:33:17 +01:00
{
2011-04-25 16:13:40 +02:00
$action_msg = $action == 'cat_add' ? lang ( 'categorie added' ) : lang ( 'categorie delete' );
2016-04-29 12:41:53 +02:00
$cat_ids = $contact [ 'cat_id' ] ? explode ( ',' , $contact [ 'cat_id' ]) : array (); //existing Api\Categories
2011-04-25 16:13:40 +02:00
if ( $action == 'cat_add' )
2008-03-10 17:33:17 +01:00
{
2011-04-25 16:13:40 +02:00
$cat_ids [] = $cat_id ;
$cat_ids = array_unique ( $cat_ids );
2008-03-10 17:33:17 +01:00
}
2011-04-25 16:13:40 +02:00
elseif ((( $key = array_search ( $cat_id , $cat_ids ))) !== false )
2008-03-10 17:33:17 +01:00
{
2011-04-25 16:13:40 +02:00
unset ( $cat_ids [ $key ]);
2008-03-10 17:33:17 +01:00
}
2016-04-29 12:41:53 +02:00
$ids = $cat_ids ? implode ( ',' , $cat_ids ) : null ;
if ( $ids !== $contact [ 'cat_id' ])
2008-03-10 17:33:17 +01:00
{
2016-04-29 12:41:53 +02:00
$contact [ 'cat_id' ] = $ids ;
2011-04-25 16:13:40 +02:00
$Ok = $this -> save ( $contact );
2008-03-10 17:33:17 +01:00
}
}
2011-04-25 16:13:40 +02:00
break ;
2006-04-23 16:40:31 +02:00
case 'delete' :
$action_msg = lang ( 'deleted' );
2016-04-29 12:41:53 +02:00
if (( $Ok = !! ( $contact = $this -> read ( $id )) && $this -> check_perms ( Acl :: DELETE , $contact )))
2006-04-23 16:40:31 +02:00
{
2012-03-07 13:05:02 +01:00
if ( $contact [ 'owner' ] || // regular contact or
2015-07-23 19:40:48 +02:00
empty ( $contact [ 'account_id' ]) || // accounts without account_id
2012-03-07 13:05:02 +01:00
// already deleted account (should no longer happen, but needed to allow for cleanup)
2016-03-06 14:45:15 +01:00
$contact [ 'tid' ] == self :: DELETED_TYPE )
2006-04-23 16:40:31 +02:00
{
2016-03-06 14:45:15 +01:00
$Ok = $this -> delete ( $id , $contact [ 'tid' ] != self :: DELETED_TYPE && $contact [ 'account_id' ]);
2006-04-23 16:40:31 +02:00
}
2006-06-14 18:53:14 +02:00
// delete single account --> redirect to admin
2008-04-18 08:10:31 +02:00
elseif ( count ( $checked ) == 1 && $contact [ 'account_id' ])
2006-04-23 16:40:31 +02:00
{
2016-04-29 12:41:53 +02:00
Egw :: redirect_link ( '/index.php' , array (
2014-03-19 14:20:46 +01:00
'menuaction' => 'admin.admin_account.delete' ,
2006-04-23 16:40:31 +02:00
'account_id' => $contact [ 'account_id' ],
));
// this does NOT return!
}
2016-04-29 12:41:53 +02:00
else // no mass delete of Api\Accounts
2006-04-23 16:40:31 +02:00
{
$Ok = false ;
}
}
break ;
2011-04-25 16:13:40 +02:00
2010-09-23 23:55:06 +02:00
case 'undelete' :
$action_msg = lang ( 'recovered' );
2016-04-29 12:41:53 +02:00
if (( $contact = $this -> read ( $id )))
2010-09-23 23:55:06 +02:00
{
$contact [ 'tid' ] = 'n' ;
$Ok = $this -> save ( $contact );
}
break ;
2008-04-18 08:10:31 +02:00
2006-10-22 13:40:43 +02:00
case 'email' :
case 'email_home' :
2016-04-29 12:41:53 +02:00
/* this cant work anymore , as Framework :: set_onload does not longer exist
$action_fallback = $action == 'email' ? 'email_home' : 'email' ;
2007-11-06 16:45:40 +01:00
$action_msg = lang ( 'added' );
2016-04-29 12:41:53 +02:00
if (( $contact = $this -> read ( $id )))
2006-10-22 13:40:43 +02:00
{
2007-11-06 16:45:40 +01:00
if ( strpos ( $contact [ $action ], '@' ) !== false )
{
$email = $contact [ $action ];
}
elseif ( strpos ( $contact [ $action_fallback ], '@' ) !== false )
{
$email = $contact [ $action_fallback ];
}
else
{
$Ok = $email = false ;
}
if ( $email )
{
2010-12-06 16:02:56 +01:00
$contact [ 'n_fn' ] = str_replace ( array ( ',' , '@' ), ' ' , $contact [ 'n_fn' ]);
2016-04-29 12:41:53 +02:00
Framework :: set_onload ( " addEmail(' " . addslashes (
2010-11-25 14:38:38 +01:00
$contact [ 'n_fn' ] ? $contact [ 'n_fn' ] . ' <' . trim ( $email ) . '>' : trim ( $email )) . " '); " );
//error_log(__METHOD__.__LINE__."addEmail('".addslashes(
// $contact['n_fn'] ? $contact['n_fn'].' <'.trim($email).'>' : trim($email))."');");
2007-11-06 16:45:40 +01:00
$Ok = true ;
}
2016-04-29 12:41:53 +02:00
} */
2006-10-22 13:40:43 +02:00
break ;
2008-04-18 08:10:31 +02:00
2007-03-13 14:38:15 +01:00
case 'remove_from_list' :
$action_msg = lang ( 'removed from distribution list' );
if ( ! $query [ 'filter2' ])
{
$msg = lang ( 'You need to select a distribution list' );
return false ;
}
else
{
$Ok = $this -> remove_from_list ( $id , $query [ 'filter2' ]) !== false ;
}
break ;
2008-04-18 08:10:31 +02:00
2007-03-13 14:38:15 +01:00
case 'to_list' :
$action_msg = lang ( 'added to distribution list' );
if ( ! $to_list )
{
$msg = lang ( 'You need to select a distribution list' );
return false ;
}
else
{
$Ok = $this -> add2list ( $id , $to_list ) !== false ;
}
break ;
2011-04-26 18:22:10 +02:00
2006-04-23 16:40:31 +02:00
default : // move to an other addressbook
2016-04-29 12:41:53 +02:00
if ( ! ( int ) $action || ! ( $this -> grants [( string ) ( int ) $action ] & Acl :: EDIT )) // might be ADD in the future
2006-04-23 16:40:31 +02:00
{
return false ;
}
2013-11-08 19:51:37 +01:00
if ( ! $checkboxes [ 'move_to_copy' ])
2006-04-23 16:40:31 +02:00
{
2013-11-08 19:51:37 +01:00
$action_msg = lang ( 'moved' );
2016-04-29 12:41:53 +02:00
if (( $Ok = !! ( $contact = $this -> read ( $id )) && $this -> check_perms ( Acl :: DELETE , $contact )))
2006-04-23 16:40:31 +02:00
{
2016-04-29 12:41:53 +02:00
if ( ! $contact [ 'owner' ]) // no (mass-)move of Api\Accounts
2013-11-08 19:51:37 +01:00
{
$Ok = false ;
}
elseif ( $contact [ 'owner' ] != ( int ) $action || $contact [ 'private' ] != ( int )( substr ( $action , - 1 ) == 'p' ))
{
$contact [ 'owner' ] = ( int ) $action ;
$contact [ 'private' ] = ( int )( substr ( $action , - 1 ) == 'p' );
$Ok = $this -> save ( $contact );
}
2006-04-23 16:40:31 +02:00
}
2013-11-08 19:51:37 +01:00
}
else
{
$action_msg = lang ( 'copied' );
2016-04-29 12:41:53 +02:00
if (( $Ok = !! ( $contact = $this -> read ( $id )) && $this -> check_perms ( Acl :: READ , $contact )))
2006-04-23 16:40:31 +02:00
{
2015-12-15 23:38:22 +01:00
if ( $contact [ 'owner' ] != ( int ) $action || $contact [ 'private' ] != ( int )( substr ( $action , - 1 ) == 'p' ))
2013-11-08 19:51:37 +01:00
{
2015-12-15 23:38:22 +01:00
$this -> copy_contact ( $contact , false ); // do NOT use self::$copy_fields, copy everything but uid etc.
$links = $contact [ 'link_to' ][ 'to_id' ];
2013-11-08 19:51:37 +01:00
$contact [ 'owner' ] = ( int ) $action ;
$contact [ 'private' ] = ( int )( substr ( $action , - 1 ) == 'p' );
$Ok = $this -> save ( $contact );
2015-12-15 23:38:22 +01:00
if ( $Ok && is_array ( $links ))
{
2016-04-29 12:41:53 +02:00
Link :: link ( 'addressbook' , $contact [ 'id' ], $links );
2015-12-15 23:38:22 +01:00
}
2013-11-08 19:51:37 +01:00
}
2006-04-23 16:40:31 +02:00
}
}
break ;
}
if ( $Ok )
{
++ $success ;
}
2006-10-22 13:40:43 +02:00
elseif ( $action != 'email' && $action != 'email_home' )
2006-04-23 16:40:31 +02:00
{
++ $failed ;
}
}
return ! $failed ;
}
2015-12-15 23:38:22 +01:00
/**
* Copy a given contact ( not storing it ! )
*
* Taken care only configured fields get copied and certain fields never to copy ( uid etc . ) .
*
* @ param array & $content
* @ param boolean $only_copy_fields = true true : only copy fields configured for copying ( eg . no name ),
* false : copy everything , but never to copy fields
*/
function copy_contact ( array & $content , $only_copy_fields = true )
{
$content [ 'link_to' ][ 'to_id' ] = 0 ;
2016-04-29 12:41:53 +02:00
Link :: link ( 'addressbook' , $content [ 'link_to' ][ 'to_id' ], 'addressbook' , $content [ 'id' ],
lang ( 'Copied by %1, from record #%2.' , Api\Accounts :: format_username ( '' ,
2015-12-15 23:38:22 +01:00
$GLOBALS [ 'egw_info' ][ 'user' ][ 'account_firstname' ], $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_lastname' ]),
$content [ 'id' ]));
// create a new contact with the content of the old
foreach ( array_keys ( $content ) as $key )
{
if ( $only_copy_fields && ! in_array ( $key , self :: $copy_fields ) || in_array ( $key , array ( 'id' , 'etag' , 'carddav_name' , 'uid' )))
{
unset ( $content [ $key ]);
}
}
if ( ! isset ( $content [ 'owner' ]))
{
$content [ 'owner' ] = $this -> default_private ? $this -> user . 'p' : $this -> default_addressbook ;
}
$content [ 'creator' ] = $this -> user ;
$content [ 'created' ] = $this -> now_su ;
}
2006-04-23 16:40:31 +02:00
/**
* rows callback for index nextmatch
*
2008-04-18 08:10:31 +02:00
* @ internal
2006-04-23 16:40:31 +02:00
* @ param array & $query
* @ param array & $rows returned rows / cups
2016-04-29 12:41:53 +02:00
* @ param array & $readonlys eg . to disable buttons based on Acl
* @ param boolean $id_only = false if true only return ( via $rows ) an array of contact - ids , dont save state to session
2006-04-23 16:40:31 +02:00
* @ return int total number of contacts matching the selection
*/
function get_rows ( & $query , & $rows , & $readonlys , $id_only = false )
{
2006-11-13 15:53:40 +01:00
$do_email = $query [ 'do_email' ];
2008-10-20 21:35:18 +02:00
$what = $query [ 'sitemgr_display' ] ? $query [ 'sitemgr_display' ] : ( $do_email ? 'email' : 'index' );
2009-10-30 12:18:47 +01:00
if ( ! $id_only && ! $query [ 'csv_export' ]) // do NOT store state for csv_export or querying id's (no regular view)
2009-07-18 17:17:41 +02:00
{
2014-02-27 21:20:15 +01:00
$store_query = $query ;
// Do not store these
2017-04-04 16:52:25 +02:00
foreach ( array ( 'options-cat_id' , 'actions' , 'action_links' , 'placeholder_actions' ) as $key )
2014-02-27 21:20:15 +01:00
{
unset ( $store_query [ $key ]);
}
2016-06-09 23:05:25 +02:00
$old_state = $store_query ;
Api\Cache :: setSession ( 'addressbook' , $what , $store_query );
2009-07-18 17:17:41 +02:00
}
else
{
2016-04-29 12:41:53 +02:00
$old_state = Api\Cache :: getSession ( 'addressbook' , $what );
2009-07-18 17:17:41 +02:00
}
2015-03-12 00:15:50 +01:00
if ( ! isset ( $this -> org_views [( string ) $query [ 'org_view' ]]) || strpos ( $query [ 'org_view' ], ':' ) === false ) // we dont have an org view, unset the according col_filters
2008-03-10 13:15:47 +01:00
{
if ( isset ( $query [ 'col_filter' ][ 'org_name' ])) unset ( $query [ 'col_filter' ][ 'org_name' ]);
if ( isset ( $query [ 'col_filter' ][ 'adr_one_locality' ])) unset ( $query [ 'col_filter' ][ 'adr_one_locality' ]);
if ( isset ( $query [ 'col_filter' ][ 'org_unit' ])) unset ( $query [ 'col_filter' ][ 'org_unit' ]);
}
2008-02-21 12:54:22 +01:00
2006-10-31 08:56:34 +01:00
if ( isset ( $this -> org_views [( string ) $query [ 'org_view' ]])) // we have an org view, reset the advanced search
{
2011-03-29 11:43:37 +02:00
//_debug_array(array('Search'=>$query['search'],
2011-03-30 15:31:09 +02:00
// 'AdvancedSearch'=>$query['advanced_search']));
//if (is_array($query['search'])) unset($query['search']);
//unset($query['advanced_search']);
if ( ! $query [ 'search' ] && $old_state [ 'advanced_search' ]) $query [ 'advanced_search' ] = $old_state [ 'advanced_search' ];
2006-10-31 08:56:34 +01:00
}
2016-06-09 23:05:25 +02:00
elseif ( ! $query [ 'search' ] && array_key_exists ( 'advanced_search' , $old_state )) // eg. paging in an advanced search
2006-10-31 08:56:34 +01:00
{
$query [ 'advanced_search' ] = $old_state [ 'advanced_search' ];
}
2016-04-29 12:41:53 +02:00
/* this cant work anymore , as Framework :: set_onload no longer exists
2010-06-15 18:08:10 +02:00
if ( $do_email && etemplate :: $loop )
2006-10-22 13:40:43 +02:00
{ // remove previous addEmail() calls, otherwise they will be run again
2016-04-29 12:41:53 +02:00
Framework :: set_onload ( preg_replace ( '/addEmail\([^)]+\);/' , '' , Framework :: set_onload ()), true );
} */
2012-02-01 21:34:32 +01:00
// Make sure old lettersearch filter doesn't stay - current letter filter will be added later
foreach ( $query [ 'col_filter' ] as $key => $col_filter )
{
if ( ! is_numeric ( $key )) continue ;
if ( preg_match ( '/' . $GLOBALS [ 'egw' ] -> db -> capabilities [ 'case_insensitive_like' ] .
2015-11-24 21:50:36 +01:00
' ' . $GLOBALS [ 'egw' ] -> db -> quote ( '[a-z]%' ) . '$/' , $col_filter ) == 1
2012-02-01 21:34:32 +01:00
)
{
unset ( $query [ 'col_filter' ][ $key ]);
}
}
2006-04-23 16:40:31 +02:00
//echo "<p>uicontacts::get_rows(".print_r($query,true).")</p>\n";
if ( ! $id_only )
{
2006-06-13 23:53:00 +02:00
// check if accounts are stored in ldap, which does NOT yet support the org-views
if ( $this -> so_accounts && $query [ 'filter' ] === '0' && $query [ 'org_view' ])
{
if ( $old_state [ 'filter' ] === '0' ) // user changed to org_view
{
$query [ 'filter' ] = '' ; // --> change filter to all contacts
}
else // user changed to accounts
{
$query [ 'org_view' ] = '' ; // --> change to regular contacts view
}
}
2006-10-07 12:18:35 +02:00
if ( $query [ 'org_view' ] && isset ( $this -> org_views [ $old_state [ 'org_view' ]]) && ! isset ( $this -> org_views [ $query [ 'org_view' ]]))
{
$query [ 'searchletter' ] = '' ; // reset lettersearch if viewing the contacts of one organisation
}
2006-04-23 16:40:31 +02:00
// save the state of the index in the user prefs
$state = serialize ( array (
2006-04-30 11:34:24 +02:00
'filter' => $query [ 'filter' ],
'cat_id' => $query [ 'cat_id' ],
'order' => $query [ 'order' ],
'sort' => $query [ 'sort' ],
2006-04-24 13:15:10 +02:00
'col_filter' => array ( 'tid' => $query [ 'col_filter' ][ 'tid' ]),
2006-04-30 11:34:24 +02:00
'org_view' => $query [ 'org_view' ],
2006-04-23 16:40:31 +02:00
));
2012-03-29 14:59:22 +02:00
if ( $state != $this -> prefs [ $what . '_state' ] && ! $query [ 'csv_export' ])
2008-02-21 12:54:22 +01:00
{
2008-10-20 21:35:18 +02:00
$GLOBALS [ 'egw' ] -> preferences -> add ( 'addressbook' , $what . '_state' , $state );
2006-06-13 23:53:00 +02:00
// save prefs, but do NOT invalid the cache (unnecessary)
$GLOBALS [ 'egw' ] -> preferences -> save_repository ( false , 'user' , false );
2006-04-23 16:40:31 +02:00
}
}
2006-10-31 08:56:34 +01:00
unset ( $old_state );
2006-10-02 09:49:00 +02:00
if (( string ) $query [ 'cat_id' ] != '' )
2006-04-23 16:40:31 +02:00
{
2006-10-02 09:49:00 +02:00
$query [ 'col_filter' ][ 'cat_id' ] = $query [ 'cat_id' ] ? $query [ 'cat_id' ] : null ;
}
else
{
unset ( $query [ 'col_filter' ][ 'cat_id' ]);
2006-04-23 16:40:31 +02:00
}
if ( $query [ 'filter' ] !== '' ) // not all addressbooks
{
$query [ 'col_filter' ][ 'owner' ] = ( string ) ( int ) $query [ 'filter' ];
if ( $this -> private_addressbook )
{
$query [ 'col_filter' ][ 'private' ] = substr ( $query [ 'filter' ], - 1 ) == 'p' ? 1 : 0 ;
}
}
2013-02-05 12:47:32 +01:00
else
{
unset ( $query [ 'col_filter' ][ 'owner' ]);
unset ( $query [ 'col_filter' ][ 'private' ]);
}
2007-03-13 14:38:15 +01:00
if (( int ) $query [ 'filter2' ]) // not no distribution list
{
$query [ 'col_filter' ][ 'list' ] = ( string ) ( int ) $query [ 'filter2' ];
}
else
{
unset ( $query [ 'col_filter' ][ 'list' ]);
}
2007-04-30 17:18:29 +02:00
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'addressbook' ][ 'hide_accounts' ])
{
$query [ 'col_filter' ][ 'account_id' ] = null ;
}
2017-01-23 11:16:24 +01:00
// all backends allow now at least to use groups as distribution lists
$query [ 'no_filter2' ] = false ;
2008-04-18 08:10:31 +02:00
2015-03-02 22:50:25 +01:00
if ( isset ( $this -> org_views [( string ) $query [ 'org_view' ]]) && ! $query [ 'col_filter' ][ 'parent_id' ]) // we have an org view
2006-04-23 16:40:31 +02:00
{
2015-03-02 22:50:25 +01:00
// Query doesn't like empties
unset ( $query [ 'col_filter' ][ 'parent_id' ]);
2015-04-24 17:13:45 +02:00
2014-03-13 20:04:47 +01:00
if ( $query [ 'actions' ] && $query [ 'actions' ][ 'open' ])
2014-02-03 21:13:52 +01:00
{
// Just switched from contact view, update actions
$query [ 'actions' ] = $this -> get_actions ( $query [ 'col_filter' ][ 'tid' ], $query [ 'org_view' ]);
}
2007-03-13 14:38:15 +01:00
unset ( $query [ 'col_filter' ][ 'list' ]); // does not work together
$query [ 'no_filter2' ] = true ; // switch the distribution list selection off
2006-04-30 11:34:24 +02:00
$query [ 'template' ] = 'addressbook.index.org_rows' ;
2013-11-08 19:51:37 +01:00
2006-04-30 11:34:24 +02:00
if ( $query [ 'order' ] != 'org_name' )
{
$query [ 'sort' ] = 'ASC' ;
$query [ 'order' ] = 'org_name' ;
}
2011-03-30 15:31:09 +02:00
if ( $query [ 'advanced_search' ])
{
$query [ 'op' ] = $query [ 'advanced_search' ][ 'operator' ];
unset ( $query [ 'advanced_search' ][ 'operator' ]);
$query [ 'wildcard' ] = $query [ 'advanced_search' ][ 'meth_select' ];
unset ( $query [ 'advanced_search' ][ 'meth_select' ]);
$original_search = $query [ 'search' ];
$query [ 'search' ] = $query [ 'advanced_search' ];
}
2008-04-18 08:10:31 +02:00
2011-03-30 15:31:09 +02:00
$rows = parent :: organisations ( $query );
if ( $query [ 'advanced_search' ])
{
$query [ 'search' ] = $original_search ;
unset ( $query [ 'wildcard' ]);
unset ( $query [ 'op' ]);
}
2007-05-04 13:57:37 +02:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'params' ][ 'manual' ] = array ( 'page' => 'ManualAddressbookIndexOrga' );
2006-04-23 16:40:31 +02:00
}
2006-04-30 11:34:24 +02:00
else // contacts view
2006-04-23 16:40:31 +02:00
{
2008-02-21 12:54:22 +01:00
if ( $query [ 'sitemgr_display' ])
{
$query [ 'template' ] = $query [ 'sitemgr_display' ] . '.rows' ;
2009-10-30 12:18:47 +01:00
}
else
{
2008-02-21 12:54:22 +01:00
$query [ 'template' ] = $do_email ? 'addressbook.email.rows' : 'addressbook.index.rows' ;
}
2015-03-02 22:50:25 +01:00
if ( $query [ 'col_filter' ][ 'parent_id' ])
{
$query [ 'org_view' ] = $query [ 'col_filter' ][ 'parent_id' ];
$query [ 'template' ] = 'addressbook.index.org_rows' ;
}
// Query doesn't like parent_id
unset ( $query [ 'col_filter' ][ 'parent_id' ]);
2006-04-30 11:34:24 +02:00
if ( $query [ 'org_view' ]) // view the contacts of one organisation only
2013-11-08 19:51:37 +01:00
{
2009-10-30 12:18:47 +01:00
if ( strpos ( $query [ 'org_view' ], '*AND*' ) !== false ) $query [ 'org_view' ] = str_replace ( '*AND*' , '&' , $query [ 'org_view' ]);
2006-04-30 11:34:24 +02:00
foreach ( explode ( '|||' , $query [ 'org_view' ]) as $part )
{
list ( $name , $value ) = explode ( ':' , $part , 2 );
2014-06-03 11:54:53 +02:00
// do NOT set invalid column, as this gives an SQL error ("AND AND" in sql)
if ( in_array ( $name , array ( 'org_name' , 'org_unit' , 'adr_one_location' )))
{
$query [ 'col_filter' ][ $name ] = $value ;
}
2006-04-30 11:34:24 +02:00
}
}
2014-02-03 21:13:52 +01:00
else if ( $query [ 'actions' ] && ! $query [ 'actions' ][ 'edit' ])
{
// Just switched from org view, update actions
$query [ 'actions' ] = $this -> get_actions ( $query [ 'col_filter' ][ 'tid' ], $query [ 'org_view' ]);
}
2006-09-25 12:18:05 +02:00
// translate the select order to the really used over all 3 columns
2006-04-30 11:34:24 +02:00
$sort = $query [ 'sort' ];
2007-06-03 10:42:59 +02:00
switch ( $query [ 'order' ]) // "xxx<>'' DESC" sorts contacts with empty order-criteria always at the end
2006-09-25 12:18:05 +02:00
{ // we don't exclude them, as the total would otherwise depend on the order-criteria
2006-04-30 11:34:24 +02:00
case 'org_name' :
2010-05-12 16:37:36 +02:00
$order = " egw_addressbook.org_name<>''DESC,egw_addressbook.org_name $sort ,n_family $sort ,n_given $sort " ;
2006-04-30 11:34:24 +02:00
break ;
default :
2008-01-19 06:41:04 +01:00
if ( $query [ 'order' ][ 0 ] == '#' ) // we order by a custom field
{
2010-04-09 00:42:25 +02:00
$order = " { $query [ 'order' ] } $sort ,org_name $sort ,n_family $sort ,n_given $sort " ;
2008-01-19 06:41:04 +01:00
break ;
}
2006-04-30 11:34:24 +02:00
$query [ 'order' ] = 'n_family' ;
case 'n_family' :
2007-06-03 10:42:59 +02:00
$order = " n_family<>'' DESC,n_family $sort ,n_given $sort ,org_name $sort " ;
2006-04-30 11:34:24 +02:00
break ;
case 'n_given' :
2007-06-03 10:42:59 +02:00
$order = " n_given<>'' DESC,n_given $sort ,n_family $sort ,org_name $sort " ;
2006-04-30 11:34:24 +02:00
break ;
case 'n_fileas' :
2007-06-03 10:42:59 +02:00
$order = " n_fileas<>'' DESC,n_fileas $sort " ;
2006-04-30 11:34:24 +02:00
break ;
2006-12-11 08:35:49 +01:00
case 'adr_one_postalcode' :
2011-11-11 17:56:08 +01:00
case 'adr_two_postalcode' :
$order = $query [ 'order' ] . " <>'' DESC, " . $query [ 'order' ] . " $sort ,org_name $sort ,n_family $sort ,n_given $sort " ;
2006-12-11 08:35:49 +01:00
break ;
2007-03-07 13:31:48 +01:00
case 'contact_modified' :
case 'contact_created' :
$order = " $query[order] IS NULL, $query[order] $sort ,org_name $sort ,n_family $sort ,n_given $sort " ;
break ;
2010-09-29 12:38:44 +02:00
case 'contact_id' :
2012-05-14 20:00:19 +02:00
$order = " egw_addressbook. $query[order] $sort " ;
2006-04-30 11:34:24 +02:00
}
2006-09-25 12:18:05 +02:00
if ( $query [ 'searchletter' ]) // only show contacts if the order-criteria starts with the given letter
2006-04-30 11:34:24 +02:00
{
2011-06-06 18:41:17 +02:00
$no_letter_search = array ( 'adr_one_postalcode' , 'adr_two_postalcode' , 'contact_id' , 'contact_created' , 'contact_modified' );
$query [ 'col_filter' ][] = ( in_array ( $query [ 'order' ], $no_letter_search ) ? 'org_name' : ( substr ( $query [ 'order' ], 0 , 1 ) == '#' ? '' : 'egw_addressbook.' ) . $query [ 'order' ]) . ' ' .
2015-11-24 21:50:36 +01:00
$GLOBALS [ 'egw' ] -> db -> capabilities [ 'case_insensitive_like' ] . ' ' . $GLOBALS [ 'egw' ] -> db -> quote ( strtolower ( $query [ 'searchletter' ]) . '%' );
2006-04-30 11:34:24 +02:00
}
2006-10-24 21:20:37 +02:00
$wildcard = '%' ;
$op = 'OR' ;
2006-10-31 08:56:34 +01:00
if ( $query [ 'advanced_search' ])
2006-10-24 21:20:37 +02:00
{
2014-09-08 20:47:40 +02:00
// Make sure op & wildcard are only valid options
$op = $query [ 'advanced_search' ][ 'operator' ] == $op ? $op : 'AND' ;
2006-10-31 08:56:34 +01:00
unset ( $query [ 'advanced_search' ][ 'operator' ]);
2016-06-26 18:52:45 +02:00
$wildcard = $query [ 'advanced_search' ][ 'meth_select' ] == $wildcard ? $wildcard : '' ;
2006-10-31 08:56:34 +01:00
unset ( $query [ 'advanced_search' ][ 'meth_select' ]);
2006-10-24 21:20:37 +02:00
}
2010-11-04 21:40:33 +01:00
//if ($do_email ) $email_only = array('id','owner','tid','n_fn','n_family','n_given','org_name','email','email_home');
2007-05-22 10:02:06 +02:00
$rows = parent :: search ( $query [ 'advanced_search' ] ? $query [ 'advanced_search' ] : $query [ 'search' ], $id_only ,
2006-10-24 21:20:37 +02:00
$order , '' , $wildcard , false , $op , array (( int ) $query [ 'start' ],( int ) $query [ 'num_rows' ]), $query [ 'col_filter' ]);
2007-05-26 09:58:37 +02:00
// do we need to read the custom fields, depends on the column is enabled and customfields exist
2009-10-30 12:18:47 +01:00
// $query['csv_export'] allways needs to read ALL cf's
2016-04-29 12:41:53 +02:00
$columsel = $this -> prefs [ 'nextmatch-addressbook.' . ( $do_email ? 'email' : 'index' ) . '.rows' ];
$available_distib_lists = $this -> get_lists ( Acl :: READ );
$columselection = $columsel && ! $query [ 'csv_export' ] ? explode ( ',' , $columsel ) : array ();
2017-03-08 17:53:52 +01:00
$ids = $calendar_participants = array ();
2007-09-14 12:31:08 +02:00
if ( ! $id_only && $rows )
2006-04-30 11:34:24 +02:00
{
2009-10-30 12:18:47 +01:00
$show_custom_fields = ( ! $columselection || in_array ( 'customfields' , $columselection ) || $query [ 'csv_export' ]) && $this -> customfields ;
2009-10-15 17:00:49 +02:00
$show_calendar = ! $columselection || in_array ( 'calendar_calendar' , $columselection );
2009-10-30 12:18:47 +01:00
$show_distributionlist = ! $columselection || in_array ( 'distrib_lists' , $columselection ) || count ( $available_distib_lists );
2008-01-31 13:52:43 +01:00
if ( $show_calendar || $show_custom_fields || $show_distributionlist )
2006-04-30 11:34:24 +02:00
{
2007-09-14 12:31:08 +02:00
foreach ( $rows as $val )
{
$ids [] = $val [ 'id' ];
2017-03-08 17:53:52 +01:00
$calendar_participants [ $val [ 'id' ]] = $val [ 'account_id' ] ? $val [ 'account_id' ] : 'c' . $val [ 'id' ];
2007-09-14 12:31:08 +02:00
}
2008-04-02 10:24:52 +02:00
if ( $show_custom_fields )
{
foreach ( $columselection as $col )
{
if ( $col [ 0 ] == '#' ) $selected_cfs [] = substr ( $col , 1 );
}
$customfields = $this -> read_customfields ( $ids , $selected_cfs );
}
2017-03-08 17:53:52 +01:00
if ( $show_calendar && ! empty ( $ids )) $calendar = $this -> read_calendar ( $calendar_participants );
2008-04-18 08:10:31 +02:00
// distributionlist memership for the entrys
2016-04-29 12:41:53 +02:00
//_debug_array($this->get_lists(Acl::EDIT));
2008-03-31 07:40:53 +02:00
if ( $show_distributionlist && $available_distib_lists )
{
$distributionlist = $this -> read_distributionlist ( $ids , array_keys ( $available_distib_lists ));
}
2006-04-30 11:34:24 +02:00
}
}
2006-04-23 16:40:31 +02:00
}
2006-04-30 11:34:24 +02:00
if ( ! $rows ) $rows = array ();
2006-04-23 16:40:31 +02:00
2006-04-26 23:23:38 +02:00
if ( $id_only )
{
foreach ( $rows as $n => $row )
{
$rows [ $n ] = $row [ 'id' ];
}
return $this -> total ; // no need to set other fields or $readonlys
}
2006-04-23 16:40:31 +02:00
$order = $query [ 'order' ];
2008-04-18 08:10:31 +02:00
2006-04-23 16:40:31 +02:00
$readonlys = array ();
2011-04-17 16:10:05 +02:00
foreach ( $rows as $n => & $row )
2006-04-23 16:40:31 +02:00
{
$given = $row [ 'n_given' ] ? $row [ 'n_given' ] : ( $row [ 'n_prefix' ] ? $row [ 'n_prefix' ] : '' );
switch ( $order )
{
2007-03-07 13:31:48 +01:00
default : // postalcode, created, modified, ...
2006-04-23 16:40:31 +02:00
case 'org_name' :
2006-04-24 13:15:10 +02:00
$row [ 'line1' ] = $row [ 'org_name' ];
$row [ 'line2' ] = $row [ 'n_family' ] . ( $given ? ', ' . $given : '' );
2006-04-23 16:40:31 +02:00
break ;
case 'n_family' :
2006-04-24 13:15:10 +02:00
$row [ 'line1' ] = $row [ 'n_family' ] . ( $given ? ', ' . $given : '' );
$row [ 'line2' ] = $row [ 'org_name' ];
2006-04-23 16:40:31 +02:00
break ;
case 'n_given' :
2006-04-24 13:15:10 +02:00
$row [ 'line1' ] = $given . ' ' . $row [ 'n_family' ];
$row [ 'line2' ] = $row [ 'org_name' ];
break ;
case 'n_fileas' :
2006-09-25 12:18:05 +02:00
if ( ! $row [ 'n_fileas' ]) $row [ 'n_fileas' ] = $this -> fileas ( $row );
2006-04-24 13:15:10 +02:00
list ( $row [ 'line1' ], $row [ 'line2' ]) = explode ( ': ' , $row [ 'n_fileas' ]);
2006-04-23 16:40:31 +02:00
break ;
}
2006-04-30 11:34:24 +02:00
if ( isset ( $this -> org_views [( string ) $query [ 'org_view' ]]))
2006-04-23 16:40:31 +02:00
{
2006-04-30 11:34:24 +02:00
$row [ 'type' ] = 'home' ;
$row [ 'type_label' ] = lang ( 'Organisation' );
2008-04-18 08:10:31 +02:00
2016-04-29 12:41:53 +02:00
if ( $query [ 'filter' ] && ! ( $this -> grants [( int ) $query [ 'filter' ]] & Acl :: DELETE ))
2011-04-17 23:25:01 +02:00
{
2011-04-28 11:12:30 +02:00
$row [ 'class' ] .= 'rowNoDelete ' ;
2011-04-17 23:25:01 +02:00
}
2011-04-28 11:12:30 +02:00
$row [ 'class' ] .= 'rowNoEdit ' ; // no edit in OrgView
2015-03-10 16:41:53 +01:00
$row [ 'class' ] .= 'contact_organisation ' ;
2006-04-23 16:40:31 +02:00
}
2006-04-30 11:34:24 +02:00
else
2006-04-23 16:40:31 +02:00
{
2006-04-30 11:34:24 +02:00
$this -> type_icon ( $row [ 'owner' ], $row [ 'private' ], $row [ 'tid' ], $row [ 'type' ], $row [ 'type_label' ]);
2008-04-18 08:10:31 +02:00
2008-06-11 09:17:30 +02:00
static $tel2show = array ( 'tel_work' , 'tel_cell' , 'tel_home' , 'tel_fax' );
2016-04-29 12:41:53 +02:00
static $prefer_marker = null ;
2013-02-05 12:24:02 +01:00
if ( is_null ( $prefer_marker ))
{
// as et2 adds options with .text(), it can't be entities, but php knows no string literals with utf-8
2016-05-19 16:59:08 +02:00
$prefer_marker = html_entity_decode ( ' ☆' , ENT_NOQUOTES , 'utf-8' );
2013-02-05 12:24:02 +01:00
}
2006-04-30 11:34:24 +02:00
foreach ( $tel2show as $name )
{
2013-02-05 12:24:02 +01:00
$row [ $name ] .= ' ' . ( $row [ 'tel_prefer' ] == $name ? $prefer_marker : '' ); // .' ' to NOT remove the field
2006-04-30 11:34:24 +02:00
}
// allways show the prefered phone, if not already shown
if ( ! in_array ( $row [ 'tel_prefer' ], $tel2show ) && $row [ $row [ 'tel_prefer' ]])
{
2013-02-05 12:24:02 +01:00
$row [ 'tel_prefered' ] = $row [ $row [ 'tel_prefer' ]] . $prefer_marker ;
2006-04-30 11:34:24 +02:00
}
2015-07-23 19:40:48 +02:00
if ( ! $row [ 'owner' ] && $row [ 'account_id' ] > 0 )
2014-03-19 14:20:46 +01:00
{
2015-04-24 17:13:45 +02:00
$row [ 'class' ] .= 'rowAccount rowNoDelete ' ;
2014-03-19 14:20:46 +01:00
}
2016-04-29 12:41:53 +02:00
elseif ( ! $this -> check_perms ( Acl :: DELETE , $row ) || ( ! $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ] && $this -> config [ 'history' ] != 'userpurge' && $query [ 'col_filter' ][ 'tid' ] == self :: DELETED_TYPE ))
2011-04-17 23:25:01 +02:00
{
2011-04-28 11:12:30 +02:00
$row [ 'class' ] .= 'rowNoDelete ' ;
2011-04-17 23:25:01 +02:00
}
2016-04-29 12:41:53 +02:00
if ( ! $this -> check_perms ( Acl :: EDIT , $row ))
2011-04-17 23:25:01 +02:00
{
2011-04-28 11:12:30 +02:00
$row [ 'class' ] .= 'rowNoEdit ' ;
2011-04-17 23:25:01 +02:00
}
2015-03-10 16:41:53 +01:00
$row [ 'class' ] .= 'contact_contact ' ;
2008-04-18 08:10:31 +02:00
2013-02-05 09:07:02 +01:00
unset ( $row [ 'jpegphoto' ]); // unused and messes up json encoding (not utf-8)
2006-04-30 11:34:24 +02:00
if ( isset ( $customfields [ $row [ 'id' ]]))
2006-04-23 16:40:31 +02:00
{
2006-04-30 11:34:24 +02:00
foreach ( $this -> customfields as $name => $data )
{
2010-04-09 00:42:25 +02:00
$row [ '#' . $name ] = $customfields [ $row [ 'id' ]][ '#' . $name ];
2006-04-30 11:34:24 +02:00
}
2006-04-23 16:40:31 +02:00
}
2008-01-31 13:52:43 +01:00
if ( isset ( $distributionlist [ $row [ 'id' ]]))
{
$row [ 'distrib_lists' ] = implode ( " \n " , array_values ( $distributionlist [ $row [ 'id' ]]));
//if ($show_distributionlist) $readonlys['distrib_lists'] =true;
}
2017-03-08 17:53:52 +01:00
if ( isset ( $calendar [ $calendar_participants [ $row [ 'id' ]]]))
2007-09-14 12:03:18 +02:00
{
2017-03-08 17:53:52 +01:00
foreach ( $calendar [ $calendar_participants [ $row [ 'id' ]]] as $name => $data )
2007-09-14 12:03:18 +02:00
{
$row [ $name ] = $data ;
}
}
2006-06-17 20:50:07 +02:00
}
2007-06-17 15:55:43 +02:00
2007-05-03 10:17:31 +02:00
// hide region for address format 'postcode_city'
if (( $row [ 'addr_format' ] = $this -> addr_format_by_country ( $row [ 'adr_one_countryname' ])) == 'postcode_city' ) unset ( $row [ 'adr_one_region' ]);
if (( $row [ 'addr_format2' ] = $this -> addr_format_by_country ( $row [ 'adr_two_countryname' ])) == 'postcode_city' ) unset ( $row [ 'adr_two_region' ]);
2010-03-05 09:28:25 +01:00
2009-11-26 09:32:18 +01:00
// respect category permissions
if ( ! empty ( $row [ 'cat_id' ]))
{
2016-04-29 12:41:53 +02:00
$row [ 'cat_id' ] = $this -> categories -> check_list ( Acl :: READ , $row [ 'cat_id' ]);
2009-11-26 09:32:18 +01:00
}
2006-04-23 16:40:31 +02:00
}
2016-03-14 18:22:09 +01:00
$rows [ 'no_distribution_list' ] = ( bool ) $query [ 'filter2' ];
2009-05-30 09:39:58 +02:00
2006-04-23 16:40:31 +02:00
// disable customfields column, if we have no customefield(s)
2014-07-16 16:30:25 +02:00
if ( ! $this -> customfields ) $rows [ 'no_customfields' ] = true ;
2014-02-28 11:13:26 +01:00
2006-04-23 16:40:31 +02:00
$rows [ 'order' ] = $order ;
2006-04-30 20:03:06 +02:00
$rows [ 'call_popup' ] = $this -> config [ 'call_popup' ];
2006-04-23 16:40:31 +02:00
$rows [ 'customfields' ] = array_values ( $this -> customfields );
2008-04-18 08:10:31 +02:00
2006-04-30 11:34:24 +02:00
// full app-header with all search criteria specially for the print
2016-02-17 20:56:54 +01:00
$header = array ();
2006-04-30 11:34:24 +02:00
if ( $query [ 'filter' ] !== '' && ! isset ( $this -> org_views [ $query [ 'org_view' ]]))
2008-04-18 08:10:31 +02:00
{
2016-02-17 20:56:54 +01:00
$header [] = ( $query [ 'filter' ] == '0' ? lang ( 'accounts' ) :
2008-04-18 08:10:31 +02:00
( $GLOBALS [ 'egw' ] -> accounts -> get_type ( $query [ 'filter' ]) == 'g' ?
2006-04-23 16:40:31 +02:00
lang ( 'Group %1' , $GLOBALS [ 'egw' ] -> accounts -> id2name ( $query [ 'filter' ])) :
2016-04-29 12:41:53 +02:00
Api\Accounts :: username (( int ) $query [ 'filter' ]) .
2006-04-23 16:40:31 +02:00
( substr ( $query [ 'filter' ], - 1 ) == 'p' ? ' (' . lang ( 'private' ) . ')' : '' )));
}
2006-04-30 11:34:24 +02:00
if ( $query [ 'org_view' ])
{
2016-02-17 20:56:54 +01:00
$header [] = $query [ 'org_view_label' ];
2013-10-22 00:18:41 +02:00
// Make sure option is there
if ( ! array_key_exists ( $query [ 'org_view' ], $this -> org_views ))
{
$this -> org_views += $this -> _get_org_name ( $query [ 'org_view' ]);
$rows [ 'sel_options' ][ 'org_view' ] = $this -> org_views ;
}
2006-04-30 11:34:24 +02:00
}
2008-04-18 08:10:31 +02:00
if ( $query [ 'advanced_search' ])
2006-10-31 08:56:34 +01:00
{
2016-02-17 20:56:54 +01:00
$header [] = lang ( 'Advanced search' );
2006-10-31 08:56:34 +01:00
}
2006-04-23 16:40:31 +02:00
if ( $query [ 'cat_id' ])
{
2016-02-17 20:56:54 +01:00
$header [] = lang ( 'Category' ) . ' ' . $GLOBALS [ 'egw' ] -> categories -> id2name ( $query [ 'cat_id' ]);
2006-04-23 16:40:31 +02:00
}
2006-10-31 08:56:34 +01:00
if ( $query [ 'searchletter' ])
2006-04-23 16:40:31 +02:00
{
2006-12-11 08:35:49 +01:00
$order = $order == 'n_given' ? lang ( 'first name' ) : ( $order == 'n_family' ? lang ( 'last name' ) : lang ( 'Organisation' ));
2016-02-17 20:56:54 +01:00
$header [] = lang ( " %1 starts with '%2' " , $order , $query [ 'searchletter' ]);
2006-04-23 16:40:31 +02:00
}
2011-03-30 15:31:09 +02:00
if ( $query [ 'search' ] && ! $query [ 'advanced_search' ]) // do not add that, if we have advanced search active
2006-04-23 16:40:31 +02:00
{
2016-02-17 20:56:54 +01:00
$header [] = lang ( " Search for '%1' " , $query [ 'search' ]);
2006-04-23 16:40:31 +02:00
}
2016-02-17 20:56:54 +01:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = implode ( ': ' , $header );
2006-10-31 08:56:34 +01:00
return $this -> total ;
2006-04-23 16:40:31 +02:00
}
/**
* Get addressbook type icon from owner , private and tid
*
2016-04-29 12:41:53 +02:00
* @ param int $owner user - or group - id or 0 for Api\Accounts
2008-04-18 08:10:31 +02:00
* @ param boolean $private
2006-04-23 16:40:31 +02:00
* @ param string $tid 'n' for regular addressbook
* @ param string & $icon icon - name
* @ param string & $label translated label
*/
function type_icon ( $owner , $private , $tid , & $icon , & $label )
{
if ( ! $owner )
{
$icon = 'accounts' ;
$label = lang ( 'accounts' );
}
2007-06-03 13:42:39 +02:00
elseif ( $private )
2006-04-23 16:40:31 +02:00
{
$icon = 'private' ;
$label = lang ( 'private' );
}
elseif ( $GLOBALS [ 'egw' ] -> accounts -> get_type ( $owner ) == 'g' )
{
$icon = 'group' ;
$label = lang ( 'group %1' , $GLOBALS [ 'egw' ] -> accounts -> id2name ( $owner ));
}
else
{
$icon = 'personal' ;
2016-04-29 12:41:53 +02:00
$label = $owner == $this -> user ? lang ( 'personal' ) : Api\Accounts :: username ( $owner );
2008-04-18 08:10:31 +02:00
}
2008-10-20 21:35:18 +02:00
// show tid icon for tid!='n' AND only if one is defined
2016-04-29 12:41:53 +02:00
if ( $tid != 'n' && Api\Image :: find ( 'addressbook' , $this -> content_types [ $tid ][ 'name' ]))
2014-11-19 23:06:30 +01:00
{
2016-04-29 12:41:53 +02:00
$icon = Api\Image :: find ( 'addressbook' , $this -> content_types [ $tid ][ 'name' ]);
2014-11-19 23:06:30 +01:00
}
2015-02-04 11:30:59 +01:00
2014-11-19 23:06:30 +01:00
// Legacy - from when icons could be anywhere
2008-10-20 21:35:18 +02:00
if ( $tid != 'n' && $this -> content_types [ $tid ][ 'options' ][ 'icon' ])
{
$icon = $this -> content_types [ $tid ][ 'options' ][ 'icon' ];
$label = $this -> content_types [ $tid ][ 'name' ] . ' (' . $label . ')' ;
}
2006-04-23 16:40:31 +02:00
}
2005-11-11 21:50:12 +01:00
/**
2008-04-18 08:10:31 +02: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
2009-11-13 09:01:28 +01:00
* @ param int $_GET [ 'contact_id' ] contact_id mainly for popup use
* @ param bool $_GET [ 'makecp' ] true if you want to copy the contact given by $_GET [ 'contact_id' ]
2005-11-11 21:50:12 +01:00
*/
2005-11-13 18:51:41 +01:00
function edit ( $content = null )
2005-11-04 00:47:52 +01:00
{
if ( is_array ( $content ))
{
2006-03-14 15:26:55 +01:00
list ( $button ) = @ each ( $content [ 'button' ]);
2006-04-23 16:40:31 +02:00
unset ( $content [ 'button' ]);
$content [ 'private' ] = ( int ) ( $content [ 'owner' ] && substr ( $content [ 'owner' ], - 1 ) == 'p' );
$content [ 'owner' ] = ( string ) ( int ) $content [ 'owner' ];
2013-07-31 10:13:20 +02:00
$content [ 'cat_id' ] = $this -> config [ 'cat_tab' ] === 'Tree' ? $content [ 'cat_id_tree' ] : $content [ 'cat_id' ];
2014-06-02 15:35:59 +02:00
if ( $this -> config [ 'private_cf_tab' ]) $content = ( array ) $content [ 'private_cfs' ] + $content ;
2013-06-04 01:10:23 +02:00
unset ( $content [ 'private_cfs' ]);
2006-04-23 16:40:31 +02:00
2005-11-13 18:51:41 +01:00
switch ( $button )
2005-11-04 00:47:52 +01:00
{
2005-11-13 18:51:41 +01:00
case 'save' :
case 'apply' :
2014-10-13 15:33:10 +02:00
if ( $content [ 'presets_fields' ])
{
// unset the duplicate_filed after submit because we don't need to warn user for second time about contact duplication
unset ( $content [ 'presets_fields' ]);
}
2014-03-21 18:12:32 +01:00
if ( $content [ 'delete_photo' ])
{
$content [ 'jpegphoto' ] = null ;
unset ( $content [ 'delete_photo' ]);
}
2008-04-18 08:10:31 +02:00
if ( is_array ( $content [ 'upload_photo' ]) && ! empty ( $content [ 'upload_photo' ][ 'tmp_name' ]) &&
2010-11-04 21:40:33 +01:00
$content [ 'upload_photo' ][ 'tmp_name' ] != 'none' &&
( $f = fopen ( $content [ 'upload_photo' ][ 'tmp_name' ], 'r' )))
2006-04-23 16:40:31 +02:00
{
2010-11-04 21:40:33 +01:00
$content [ 'jpegphoto' ] = $this -> resize_photo ( $f );
fclose ( $f );
2007-04-18 17:39:48 +02:00
unset ( $content [ 'upload_photo' ]);
2006-04-23 16:40:31 +02:00
}
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' ];
}
2010-03-08 12:14:49 +01:00
$fullname = $old_fullname = parent :: fullname ( $content );
2006-04-30 11:34:24 +02:00
if ( $content [ 'id' ] && $content [ 'org_name' ] && $content [ 'change_org' ])
{
$old_org_entry = $this -> read ( $content [ 'id' ]);
2010-03-08 12:14:49 +01:00
$old_fullname = ( $old_org_entry [ 'n_fn' ] ? $old_org_entry [ 'n_fn' ] : parent :: fullname ( $old_org_entry ));
2006-04-30 11:34:24 +02:00
}
2010-11-04 21:40:33 +01:00
if ( $content [ 'n_fn' ] != $fullname || $fullname != $old_fullname )
2010-03-05 09:28:25 +01:00
{
unset ( $content [ 'n_fn' ]);
}
2010-09-28 01:02:32 +02:00
// Country codes
foreach ( array ( 'adr_one' , 'adr_two' ) as $c_prefix )
{
if ( $content [ $c_prefix . '_countrycode' ] == '-custom-' )
{
$content [ $c_prefix . '_countrycode' ] = null ;
}
}
2014-03-18 16:10:57 +01:00
$content [ 'msg' ] = '' ;
$this -> error = false ;
foreach (( array ) $content [ 'pre_save_callbacks' ] as $callback )
2006-04-30 11:34:24 +02:00
{
2014-03-18 16:10:57 +01:00
try {
if (( $success_msg = call_user_func_array ( $callback , array ( & $content ))))
{
$content [ 'msg' ] .= ( $content [ 'msg' ] ? ', ' : '' ) . $success_msg ;
}
}
catch ( Exception $ex ) {
$content [ 'msg' ] .= ( $content [ 'msg' ] ? ', ' : '' ) . $ex -> getMessage ();
$button = 'apply' ; // do not close dialog
$this -> error = true ;
break ;
}
}
if ( $this -> error )
{
// error in pre_save_callbacks
}
elseif ( $this -> save ( $content ))
{
$content [ 'msg' ] .= ( $content [ 'msg' ] ? ', ' : '' ) . lang ( 'Contact saved' );
foreach (( array ) $content [ 'post_save_callbacks' ] as $callback )
{
try {
if (( $success_msg = call_user_func_array ( $callback , array ( & $content ))))
{
$content [ 'msg' ] .= ', ' . $success_msg ;
}
}
2016-04-29 12:41:53 +02:00
catch ( Api\Exception\Redirect $r )
2014-10-15 16:55:08 +02:00
{
// catch it to continue execution and rethrow it later
}
2014-03-18 16:10:57 +01:00
catch ( Exception $ex ) {
$content [ 'msg' ] .= ', ' . $ex -> getMessage ();
$button = 'apply' ; // do not close dialog
$this -> error = true ;
break ;
}
}
2006-04-30 11:34:24 +02:00
if ( $content [ 'change_org' ] && $old_org_entry && ( $changed = $this -> changed_fields ( $old_org_entry , $content , true )) &&
( $members = $this -> org_similar ( $old_org_entry [ 'org_name' ], $changed )))
{
//foreach($changed as $name => $old_value) echo "<p>$name: '$old_value' --> '{$content[$name]}'</p>\n";
list ( $changed_members , $changed_fields , $failed_members ) = $this -> change_org ( $old_org_entry [ 'org_name' ], $changed , $content , $members );
if ( $changed_members )
{
$content [ 'msg' ] .= ', ' . lang ( '%1 fields in %2 other organisation member(s) changed' , $changed_fields , $changed_members );
}
if ( $failed_members )
{
$content [ 'msg' ] .= ', ' . lang ( 'failed to change %1 organisation member(s) (insufficent rights) !!!' , $failed_members );
}
}
}
2008-04-25 21:06:15 +02:00
elseif ( $this -> error === true )
{
$content [ 'msg' ] = lang ( 'Error: the entry has been updated since you opened it for editing!' ) . '<br />' .
lang ( 'Copy your changes to the clipboard, %1reload the entry%2 and merge them.' , '<a href="' .
2016-04-29 12:41:53 +02:00
htmlspecialchars ( Egw :: link ( '/index.php' , array (
2008-05-10 14:02:49 +02:00
'menuaction' => 'addressbook.addressbook_ui.edit' ,
2008-04-25 21:06:15 +02:00
'contact_id' => $content [ 'id' ],
))) . '">' , '</a>' );
break ; // dont refresh the list
}
2006-04-30 11:34:24 +02:00
else
{
2006-06-13 23:53:00 +02:00
$content [ 'msg' ] = lang ( 'Error saving the contact !!!' ) .
( $this -> error ? ' ' . $this -> error : '' );
2006-04-30 11:34:24 +02:00
$button = 'apply' ; // to not leave the dialog
}
2005-11-13 19:22:43 +01:00
// writing links for new entry, existing ones are handled by the widget itself
2008-04-18 08:10:31 +02:00
if ( $links && $content [ 'id' ])
2005-11-13 19:22:43 +01:00
{
2016-04-29 12:41:53 +02:00
Link :: link ( 'addressbook' , $content [ 'id' ], $links );
2005-11-13 19:22:43 +01:00
}
2016-04-11 22:38:12 +02:00
// Update client side global datastore
2016-04-29 12:41:53 +02:00
$response = Api\Json\Response :: get ();
2016-04-11 22:38:12 +02:00
$response -> generic ( 'data' , array ( 'uid' => 'addressbook::' . $content [ 'id' ], 'data' => $content ));
2016-04-29 12:41:53 +02:00
Framework :: refresh_opener ( $content [ 'msg' ], 'addressbook' , $content [ 'id' ], $content [ 'id' ] ? 'edit' : 'add' ,
2014-03-18 16:10:57 +01:00
null , null , null , $this -> error ? 'error' : 'success' );
2014-10-15 16:55:08 +02:00
// re-throw redirect exception, if there's no error
if ( ! $this -> error && isset ( $r ))
{
throw $r ;
}
2005-11-13 19:22:43 +01:00
if ( $button == 'save' )
{
2016-04-29 12:41:53 +02:00
Framework :: window_close ();
2005-11-13 19:22:43 +01:00
}
2014-03-18 16:10:57 +01:00
else
{
2016-04-29 12:41:53 +02:00
Framework :: message ( $content [ 'msg' ], $this -> error ? 'error' : 'success' );
2014-03-18 16:10:57 +01:00
unset ( $content [ 'msg' ]);
}
2005-11-23 18:07:33 +01:00
$content [ 'link_to' ][ 'to_id' ] = $content [ 'id' ];
2005-11-13 18:51:41 +01:00
break ;
2008-04-18 08:10:31 +02:00
2005-11-13 18:51:41 +01:00
case 'delete' :
2016-04-29 12:41:53 +02:00
$success = $failed = $action_msg = null ;
2008-04-26 10:47:26 +02:00
if ( $this -> action ( 'delete' , array ( $content [ 'id' ]), false , $success , $failed , $action_msg , '' , $content [ 'msg' ]))
2005-11-13 18:51:41 +01:00
{
2013-09-20 12:50:48 +02:00
if ( $GLOBALS [ 'egw' ] -> currentapp == 'addressbook' )
{
2016-04-29 12:41:53 +02:00
Framework :: refresh_opener ( lang ( 'Contact deleted' ), 'addressbook' , $content [ 'id' ], 'delete' );
Framework :: window_close ();
2013-09-20 12:50:48 +02:00
}
else
{
2016-04-29 12:41:53 +02:00
Framework :: refresh_opener ( lang ( 'Contact deleted' ), 'addressbook' , $content [ 'id' ], null , 'addressbook' );
Framework :: window_close ();
2013-09-20 12:50:48 +02:00
}
2005-11-13 18:51:41 +01:00
}
2006-04-30 11:34:24 +02:00
else
{
$content [ 'msg' ] = lang ( 'Error deleting the contact !!!' );
}
2005-11-13 18:51:41 +01:00
break ;
2005-11-04 00:47:52 +01:00
}
2016-04-29 12:41:53 +02:00
$view = ! $this -> check_perms ( Acl :: EDIT , $content );
2005-11-04 00:47:52 +01:00
}
else
{
$content = array ();
2006-04-23 16:40:31 +02:00
$contact_id = $_GET [ 'contact_id' ] ? $_GET [ 'contact_id' ] : (( int ) $_GET [ 'account_id' ] ? 'account:' . ( int ) $_GET [ 'account_id' ] : 0 );
2015-05-27 07:31:16 +02:00
$view = ( boolean ) $_GET [ 'view' ];
2006-04-23 16:40:31 +02:00
// new contact --> set some defaults
if ( $contact_id && is_array ( $content = $this -> read ( $contact_id )))
2005-11-04 00:47:52 +01:00
{
2006-04-23 16:40:31 +02:00
$contact_id = $content [ 'id' ]; // it could have been: "account:$account_id"
2016-04-29 12:41:53 +02:00
if ( ! $this -> check_perms ( Acl :: EDIT , $content ))
2014-03-12 14:29:52 +01:00
{
$view = true ;
}
2005-11-04 00:47:52 +01:00
}
2006-04-23 16:40:31 +02:00
else // not found
2005-12-01 18:21:38 +01:00
{
2016-04-29 12:41:53 +02:00
$state = Api\Cache :: getSession ( 'addressbook' , 'index' );
2006-04-30 11:34:24 +02:00
// check if we create the new contact in an existing org
2012-07-17 14:15:10 +02:00
if (( $org = $_GET [ 'org' ]))
2006-04-30 11:34:24 +02:00
{
2012-07-17 14:15:10 +02:00
// arguments containing a comma get quoted by etemplate/js/nextmatch_action.js
2016-04-29 12:41:53 +02:00
// leading to error in Api\Db::column_data_implode, if not unquoted
2012-07-17 14:15:10 +02:00
if ( $org [ 0 ] == '"' ) $org = substr ( $org , 1 , - 1 );
$content = $this -> read_org ( $org );
2006-04-30 11:34:24 +02:00
}
elseif ( $state [ 'org_view' ] && ! isset ( $this -> org_views [ $state [ 'org_view' ]]))
{
$content = $this -> read_org ( $state [ 'org_view' ]);
}
2008-10-10 13:25:35 +02:00
else
2006-12-04 13:41:03 +01:00
{
2008-10-10 13:25:35 +02:00
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'country' ])
{
2011-03-07 18:25:54 +01:00
$content [ 'adr_one_countrycode' ] =
$GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'country' ];
2011-03-07 18:27:53 +01:00
$content [ 'adr_one_countryname' ] =
$GLOBALS [ 'egw' ] -> country -> get_full_name ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'country' ]);
2013-08-16 16:49:08 +02:00
$content [ 'adr_two_countrycode' ] =
$GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'country' ];
$content [ 'adr_two_countryname' ] =
$GLOBALS [ 'egw' ] -> country -> get_full_name ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'country' ]);
2008-10-10 13:25:35 +02:00
}
if ( $this -> prefs [ 'fileas_default' ]) $content [ 'fileas_type' ] = $this -> prefs [ 'fileas_default' ];
2006-12-04 13:41:03 +01:00
}
2006-04-23 16:40:31 +02:00
if ( isset ( $_GET [ 'owner' ]) && $_GET [ 'owner' ] !== '' )
{
$content [ 'owner' ] = $_GET [ 'owner' ];
}
else
{
2014-04-17 10:55:21 +02:00
$content [ 'owner' ] = ( string ) $state [ 'filter' ];
2006-04-23 16:40:31 +02:00
}
$content [ 'private' ] = ( int ) ( $content [ 'owner' ] && substr ( $content [ 'owner' ], - 1 ) == 'p' );
2016-04-29 12:41:53 +02:00
if ( $content [ 'owner' ] === '' || ! ( $this -> grants [ $content [ 'owner' ] = ( string ) ( int ) $content [ 'owner' ]] & Acl :: ADD ))
2006-04-23 16:40:31 +02:00
{
2007-12-15 00:20:18 +01:00
$content [ 'owner' ] = $this -> default_addressbook ;
$content [ 'private' ] = ( int ) $this -> default_private ;
2006-10-07 11:17:30 +02:00
2016-04-29 12:41:53 +02:00
if ( ! ( $this -> grants [ $content [ 'owner' ] = ( string ) ( int ) $content [ 'owner' ]] & Acl :: ADD ))
2006-10-07 11:17:30 +02:00
{
$content [ 'owner' ] = ( string ) $this -> user ;
$content [ 'private' ] = 0 ;
}
2006-04-23 16:40:31 +02:00
}
2006-03-14 15:26:55 +01:00
$new_type = array_keys ( $this -> content_types );
2011-11-09 10:06:27 +01:00
// fetch active type to preset the type, if param typeid is not passed
2016-04-29 12:41:53 +02:00
$active_tid = Api\Cache :: getSession ( 'addressbook' , 'active_tid' );
2011-11-09 10:06:27 +01:00
if ( $active_tid && strtoupper ( $active_tid ) === 'D' ) unset ( $active_tid );
$content [ 'tid' ] = $_GET [ 'typeid' ] ? $_GET [ 'typeid' ] : ( $active_tid ? $active_tid : $new_type [ 0 ]);
2006-08-24 18:06:45 +02:00
foreach ( $this -> get_contact_columns () as $field )
2005-12-01 18:21:38 +01:00
{
2014-04-17 10:55:21 +02:00
if ( $_GET [ 'presets' ][ $field ])
{
if ( $field == 'email' || $field == 'email_home' )
{
$singleAddress = imap_rfc822_parse_adrlist ( $_GET [ 'presets' ][ $field ], '' );
//error_log(__METHOD__.__LINE__.' Address:'.$singleAddress[0]->mailbox."@".$singleAddress[0]->host.", ".$singleAddress[0]->personal);
if ( ! ( ! is_array ( $singleAddress ) || count ( $singleAddress ) < 1 ))
{
$content [ $field ] = $singleAddress [ 0 ] -> mailbox . " @ " . $singleAddress [ 0 ] -> host ;
if ( ! empty ( $singleAddress [ 0 ] -> personal ))
{
if ( strpos ( $singleAddress [ 0 ] -> personal , ',' ) === false )
{
list ( $P_n_given , $P_n_family , $P_org_name ) = explode ( ' ' , $singleAddress [ 0 ] -> personal , 3 );
if ( strlen ( trim ( $P_n_given )) > 0 ) $content [ 'n_given' ] = trim ( $P_n_given );
if ( strlen ( trim ( $P_n_family )) > 0 ) $content [ 'n_family' ] = trim ( $P_n_family );
if ( strlen ( trim ( $P_org_name )) > 0 ) $content [ 'org_name' ] = trim ( $P_org_name );
}
else
{
list ( $P_n_family , $P_other ) = explode ( ',' , $singleAddress [ 0 ] -> personal , 2 );
if ( strlen ( trim ( $P_n_family )) > 0 ) $content [ 'n_family' ] = trim ( $P_n_family );
if ( strlen ( trim ( $P_other )) > 0 )
{
list ( $P_n_given , $P_org_name ) = explode ( ',' , $P_other , 2 );
if ( strlen ( trim ( $P_n_given )) > 0 ) $content [ 'n_given' ] = trim ( $P_n_given );
if ( strlen ( trim ( $P_org_name )) > 0 ) $content [ 'org_name' ] = trim ( $P_org_name );
}
}
}
}
else
{
$content [ $field ] = $_GET [ 'presets' ][ $field ];
}
}
else
{
$content [ $field ] = $_GET [ 'presets' ][ $field ];
}
}
2012-10-24 16:22:24 +02:00
}
if ( isset ( $_GET [ 'presets' ]))
{
foreach ( array ( 'email' , 'email_home' , 'n_family' , 'n_given' , 'org_name' ) as $field )
2012-10-24 12:14:09 +02:00
{
2012-10-24 16:22:24 +02:00
if ( ! empty ( $content [ $field ]))
2012-10-24 12:14:09 +02:00
{
2014-10-13 15:33:10 +02:00
//Set the presets fields in content in order to be able to use them later in client side for checking duplication only on first time load
// after save/apply we unset them
$content [ 'presets_fields' ][] = $field ;
2012-10-24 16:22:24 +02:00
break ;
2012-10-24 12:14:09 +02:00
}
}
2014-04-17 10:55:21 +02:00
if ( empty ( $content [ 'n_fn' ])) $content [ 'n_fn' ] = $this -> fullname ( $content );
2005-12-01 18:21:38 +01:00
}
2006-04-23 16:40:31 +02:00
$content [ 'creator' ] = $this -> user ;
$content [ 'created' ] = $this -> now_su ;
2006-04-30 11:34:24 +02:00
unset ( $state );
2014-04-17 10:55:21 +02:00
//_debug_array($content);
2005-12-01 18:21:38 +01:00
}
2011-01-13 13:09:06 +01:00
2010-02-05 04:34:17 +01:00
if ( $_GET [ 'msg' ]) $content [ 'msg' ] = strip_tags ( $_GET [ 'msg' ]); // dont allow HTML!
2005-11-23 18:07:33 +01:00
if ( $content && $_GET [ 'makecp' ]) // copy the contact
{
2015-12-15 23:38:22 +01:00
$this -> copy_contact ( $content );
2016-11-24 18:30:36 +01:00
$content [ 'msg' ] = lang ( '%1 copied - the copy can now be edited' , lang ( Link :: get_registry ( 'addressbook' , 'entry' )));
2015-08-20 15:05:00 +02:00
$view = false ;
2005-11-23 18:07:33 +01:00
}
else
{
2011-01-13 13:09:06 +01:00
if ( is_numeric ( $contact_id )) $content [ 'link_to' ][ 'to_id' ] = $contact_id ;
2005-11-23 18:07:33 +01:00
}
2006-12-11 08:35:49 +01:00
// automatic link new entries to entries specified in the url
if ( ! $contact_id && isset ( $_REQUEST [ 'link_app' ]) && isset ( $_REQUEST [ 'link_id' ]) && ! is_array ( $content [ 'link_to' ][ 'to_id' ]))
{
$link_ids = is_array ( $_REQUEST [ 'link_id' ]) ? $_REQUEST [ 'link_id' ] : array ( $_REQUEST [ 'link_id' ]);
foreach ( is_array ( $_REQUEST [ 'link_app' ]) ? $_REQUEST [ 'link_app' ] : array ( $_REQUEST [ 'link_app' ]) as $n => $link_app )
{
$link_id = $link_ids [ $n ];
if ( preg_match ( '/^[a-z_0-9-]+:[:a-z_0-9-]+$/i' , $link_app . ':' . $link_id )) // gard against XSS
{
2016-04-29 12:41:53 +02:00
Link :: link ( 'addressbook' , $content [ 'link_to' ][ 'to_id' ], $link_app , $link_id );
2006-12-11 08:35:49 +01:00
}
}
}
2005-11-04 00:47:52 +01:00
}
2007-10-19 10:34:47 +02:00
if ( $content [ 'id' ])
{
// last and next calendar date
2017-03-08 17:53:52 +01:00
list (, $dates ) = each ( $this -> read_calendar ( array ( $content [ 'account_id' ] ? $content [ 'account_id' ] : 'c' . $content [ 'id' ]), false ));
2007-10-19 10:34:47 +02:00
if ( is_array ( $dates )) $content += $dates ;
}
2013-02-07 11:51:00 +01:00
// Avoid ID conflict with tree & selectboxes
$content [ 'cat_id_tree' ] = $content [ 'cat_id' ];
2013-06-04 01:10:23 +02:00
// Avoid setting conflicts with private custom fields
2017-04-13 17:25:47 +02:00
$content [ 'private_cfs' ] = array ();
foreach ( Api\Storage\Customfields :: get ( 'addressbook' , true ) as $name => $cf )
2014-06-02 15:35:59 +02:00
{
2017-04-13 17:25:47 +02:00
if ( $this -> config [ 'private_cf_tab' ] && $cf [ 'private' ] && isset ( $content [ '#' . $name ]))
2014-06-02 15:35:59 +02:00
{
2017-04-13 17:25:47 +02:00
$content [ 'private_cfs' ][ '#' . $name ] = $content [ '#' . $name ];
}
2014-06-02 15:35:59 +02:00
}
2017-04-13 17:25:47 +02:00
2007-05-03 10:17:31 +02:00
// how to display addresses
$content [ 'addr_format' ] = $this -> addr_format_by_country ( $content [ 'adr_one_countryname' ]);
$content [ 'addr_format2' ] = $this -> addr_format_by_country ( $content [ 'adr_two_countryname' ]);
2008-04-18 08:10:31 +02:00
2005-11-04 00:47:52 +01:00
//_debug_array($content);
2016-04-29 12:41:53 +02:00
$readonlys [ 'button[delete]' ] = ! $content [ 'owner' ] || ! $this -> check_perms ( Acl :: DELETE , $content );
2005-11-13 18:51:41 +01:00
$readonlys [ 'button[copy]' ] = $readonlys [ 'button[edit]' ] = $readonlys [ 'button[vcard]' ] = true ;
2014-03-12 14:29:52 +01:00
$readonlys [ 'button[save]' ] = $readonlys [ 'button[apply]' ] = $view ;
2015-05-27 07:31:16 +02:00
if ( $view )
{
$readonlys [ '__ALL__' ] = true ;
$readonlys [ 'button[cancel]' ] = false ;
}
2005-11-11 21:50:12 +01:00
2006-04-23 16:40:31 +02:00
$sel_options [ 'fileas_type' ] = $this -> fileas_options ( $content );
2015-04-15 17:57:19 +02:00
$sel_options [ 'adr_one_countrycode' ][ '-custom-' ] = lang ( 'Custom' );
2016-04-29 12:41:53 +02:00
$sel_options [ 'owner' ] = $this -> get_addressbooks ( Acl :: ADD );
2014-08-19 16:12:40 +02:00
if ( $content [ 'owner' ]) unset ( $sel_options [ 'owner' ][ 0 ]); // do not offer to switch to accounts, as we do not support moving contacts to accounts
2006-04-23 16:40:31 +02:00
if (( string ) $content [ 'owner' ] !== '' )
{
if ( ! isset ( $sel_options [ 'owner' ][( int ) $content [ 'owner' ]]))
{
2006-04-25 14:43:41 +02:00
$sel_options [ 'owner' ][( int ) $content [ 'owner' ]] = ! $content [ 'owner' ] ? lang ( 'Accounts' ) :
2016-04-29 12:41:53 +02:00
Api\Accounts :: username ( $content [ 'owner' ]);
2006-04-23 16:40:31 +02:00
}
$readonlys [ 'owner' ] = ! $content [ 'owner' ] || // dont allow to move accounts, as this mean deleting the user incl. all content he owns
2016-04-29 12:41:53 +02:00
$content [ 'id' ] && ! $this -> check_perms ( Acl :: DELETE , $content ); // you need delete rights to move an existing contact into an other addressbook
2006-04-23 16:40:31 +02:00
}
2006-06-13 06:30:16 +02:00
// set the unsupported fields from the backend to readonly
foreach ( $this -> get_fields ( 'unsupported' , $content [ 'id' ], $content [ 'owner' ]) as $field )
{
$readonlys [ $field ] = true ;
}
2015-05-27 07:31:16 +02:00
// for editing own account, make all fields not allowed by own_account_acl readonly
if ( ! $this -> is_admin () && ! $content [ 'owner' ] && $content [ 'account_id' ] == $this -> user && $this -> own_account_acl && ! $view )
{
$readonlys [ '__ALL__' ] = true ;
$readonlys [ 'button[cancel]' ] = false ;
foreach ( $this -> own_account_acl as $field )
{
$readonlys [ $field ] = false ;
}
2016-09-29 16:17:45 +02:00
if ( ! $readonlys [ 'jpegphoto' ])
{
$readonlys = array_merge ( $readonlys , array (
'upload_photo' => false ,
'delete_photo' => false ,
'addressbook.edit.upload' => false
));
}
2015-05-27 07:31:16 +02:00
}
if ( isset ( $readonlys [ 'n_fileas' ])) $readonlys [ 'fileas_type' ] = $readonlys [ 'n_fileas' ];
2006-12-07 20:11:39 +01:00
// disable not needed tabs
2009-05-11 08:47:38 +02:00
$readonlys [ 'tabs' ][ 'cats' ] = ! ( $content [ 'cat_tab' ] = $this -> config [ 'cat_tab' ]);
2012-02-17 16:00:51 +01:00
$readonlys [ 'tabs' ][ 'custom' ] = ! $this -> customfields || $this -> get_backend ( $content [ 'id' ], $content [ 'owner' ]) == $this -> so_accounts ;
2017-04-19 18:44:13 +02:00
$readonlys [ 'tabs' ][ 'custom_private' ] = $readonlys [ 'tabs' ][ 'custom' ] || ! $this -> config [ 'private_cf_tab' ];
2009-05-11 08:47:38 +02:00
$readonlys [ 'tabs' ][ 'distribution_list' ] = ! $content [ 'distrib_lists' ]; #false;
2013-07-11 17:33:59 +02:00
$readonlys [ 'tabs' ][ 'history' ] = $this -> contact_repository != 'sql' || ! $content [ 'id' ] ||
$this -> account_repository != 'sql' && $content [ 'account_id' ];
2014-02-13 15:07:42 +01:00
if ( ! $content [ 'id' ]) $readonlys [ 'button[delete]' ] = ! $content [ 'id' ];
2008-01-19 06:41:04 +01:00
if ( $this -> config [ 'private_cf_tab' ]) $content [ 'no_private_cfs' ] = 0 ;
2012-05-15 18:52:25 +02:00
$readonlys [ 'change_org' ] = empty ( $content [ 'org_name' ]) || $view ;
2008-04-18 08:10:31 +02:00
2006-12-07 20:11:39 +01:00
// for editing the own account (by a non-admin), enable only the fields allowed via the "own_account_acl"
2016-04-29 12:41:53 +02:00
if ( ! $content [ 'owner' ] && ! $this -> check_perms ( Acl :: EDIT , $content ))
{
$this -> _set_readonlys_for_own_account_acl ( $readonlys , $content [ 'id' ]);
}
for ( $i = - 23 ; $i <= 23 ; $i ++ )
2006-09-15 09:16:07 +02:00
{
2016-04-29 12:41:53 +02:00
$tz [ $i ] = ( $i > 0 ? '+' : '' ) . $i ;
2006-09-15 09:16:07 +02:00
}
2005-11-04 00:47:52 +01:00
$sel_options [ 'tz' ] = $tz ;
2014-01-23 16:49:07 +01:00
$content [ 'tz' ] = $content [ 'tz' ] ? $content [ 'tz' ] : '0' ;
2006-04-30 11:34:24 +02:00
if ( count ( $this -> content_types ) > 1 )
{
foreach ( $this -> content_types as $type => $data )
{
$sel_options [ 'tid' ][ $type ] = $data [ 'name' ];
}
2016-04-29 12:41:53 +02:00
$content [ 'typegfx' ] = Api\Html :: image ( 'addressbook' , $this -> content_types [ $content [ 'tid' ]][ 'options' ][ 'icon' ], '' , ' width="16px" height="16px"' );
2006-04-30 11:34:24 +02:00
}
else
{
$content [ 'no_tid' ] = true ;
}
2006-10-21 22:14:31 +02:00
2013-08-26 09:35:42 +02:00
$content [ 'view' ] = false ;
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
);
2010-02-08 18:53:47 +01:00
2010-09-27 18:39:54 +02:00
// Links for deleted entries
2016-03-06 14:45:15 +01:00
if ( $content [ 'tid' ] == self :: DELETED_TYPE )
2010-09-27 18:39:54 +02:00
{
$content [ 'link_to' ][ 'show_deleted' ] = true ;
2010-11-22 18:10:11 +01:00
if ( ! $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ] && $this -> config [ 'history' ] != 'userpurge' )
{
$readonlys [ 'button[delete]' ] = true ;
}
2010-09-27 18:39:54 +02:00
}
2010-02-08 18:53:47 +01:00
// Enable history
$this -> setup_history ( $content , $sel_options );
2014-03-06 16:10:22 +01:00
$content [ 'photo' ] = $this -> photo_src ( $content [ 'id' ], $content [ 'jpegphoto' ], 'photo' , $content [ 'etag' ]);
2006-04-23 16:40:31 +02:00
if ( $content [ 'private' ]) $content [ 'owner' ] .= 'p' ;
2014-10-09 14:03:14 +02:00
// for custom types, check if we have a custom edit template named "addressbook.edit.$type", $type is the name
if ( in_array ( $content [ 'tid' ], array ( 'n' , self :: DELETED_TYPE )) || ! $this -> tmpl -> read ( 'addressbook.edit.' . $this -> content_types [ $content [ 'tid' ]][ 'name' ]))
2007-06-17 15:15:13 +02:00
{
$this -> tmpl -> read ( 'addressbook.edit' );
}
2014-03-17 16:28:20 +01:00
// allow other apps to add tabs to addressbook edit
$preserve = $content ;
2014-03-21 18:12:32 +01:00
$content [ 'jpegphoto' ] = ! empty ( $content [ 'jpegphoto' ]); // unused and messes up json encoding (not utf-8)
2014-03-17 16:28:20 +01:00
$this -> tmpl -> setElementAttribute ( 'tabs' , 'add_tabs' , true );
$tabs =& $this -> tmpl -> getElementAttribute ( 'tabs' , 'tabs' );
2014-09-06 12:00:42 +02:00
if (( $first_call = ! isset ( $tabs )))
{
$tabs = array ();
}
//error_log(__LINE__.': '.__METHOD__."() first_call=$first_call");
2016-04-29 12:41:53 +02:00
$hook_data = Api\Hooks :: process ( array ( 'location' => 'addressbook_edit' ) + $content );
2014-03-17 16:28:20 +01:00
//error_log(__METHOD__."() hook_data=".array2string($hook_data));
foreach ( $hook_data as $extra_tabs )
{
if ( ! $extra_tabs ) continue ;
foreach ( isset ( $extra_tabs [ 0 ]) ? $extra_tabs : array ( $extra_tabs ) as $extra_tab )
{
if ( $extra_tab [ 'data' ] && is_array ( $extra_tab [ 'data' ]))
{
$content = array_merge ( $content , $extra_tab [ 'data' ]);
}
if ( $extra_tab [ 'preserve' ] && is_array ( $extra_tab [ 'preserve' ]))
{
$preserve = array_merge ( $preserve , $extra_tab [ 'preserve' ]);
}
if ( $extra_tab [ 'readonlys' ] && is_array ( $extra_tab [ 'readonlys' ]))
{
$readonlys = array_merge ( $readonlys , $extra_tab [ 'readonlys' ]);
}
2014-09-06 12:00:42 +02:00
// we must NOT add tabs and callbacks more then once!
if ( ! $first_call ) continue ;
2014-03-18 16:10:57 +01:00
if ( ! empty ( $extra_tab [ 'pre_save_callback' ]))
{
$preserve [ 'pre_save_callbacks' ][] = $extra_tab [ 'pre_save_callback' ];
}
if ( ! empty ( $extra_tab [ 'post_save_callback' ]))
{
$preserve [ 'post_save_callbacks' ][] = $extra_tab [ 'post_save_callback' ];
}
2014-09-06 12:00:42 +02:00
if ( ! empty ( $extra_tab [ 'label' ]) && ! empty ( $extra_tab [ 'name' ]))
{
$tabs [] = array (
'label' => $extra_tab [ 'label' ],
'template' => $extra_tab [ 'name' ],
'prepend' => $extra_tab [ 'prepend' ],
);
}
//error_log(__METHOD__."() changed tabs=".array2string($tabs));
2014-03-17 16:28:20 +01:00
}
}
return $this -> tmpl -> exec ( 'addressbook.addressbook_ui.edit' , $content , $sel_options , $readonlys , $preserve , 2 );
2005-11-11 21:50:12 +01:00
}
2008-04-18 08:10:31 +02:00
2007-06-03 14:24:49 +02:00
/**
* Set the readonlys for non - admins editing their own account
*
* @ param array & $readonlys
* @ param int $id
*/
function _set_readonlys_for_own_account_acl ( & $readonlys , $id )
{
// regular fields depending on the backend
foreach ( $this -> get_fields ( 'supported' , $id , 0 ) as $field )
{
if ( ! $this -> own_account_acl || ! in_array ( $field , $this -> own_account_acl ))
{
$readonlys [ $field ] = true ;
switch ( $field )
{
2008-04-18 08:10:31 +02:00
case 'tel_work' :
case 'tel_cell' :
case 'tel_home' :
2007-06-03 14:24:49 +02:00
$readonlys [ $field . '2' ] = true ;
break ;
case 'n_fileas' :
$readonlys [ 'fileas_type' ] = true ;
break ;
}
}
}
// custom fields
if ( $this -> customfields )
{
2016-04-29 12:41:53 +02:00
foreach ( array_keys ( $this -> customfields ) as $name )
2007-06-03 14:24:49 +02:00
{
if ( ! $this -> own_account_acl || ! in_array ( '#' . $name , $this -> own_account_acl ))
{
$readonlys [ '#' . $name ] = true ;
}
}
}
// links
if ( ! $this -> own_account_acl || ! in_array ( 'link_to' , $this -> own_account_acl ))
{
$readonlys [ 'link_to' ] = true ;
}
}
2008-04-18 08:10:31 +02:00
2012-09-06 14:26:11 +02:00
/**
* Doublicate check : returns similar contacts : same email or 2 of name , firstname , org
*
* Also update / return fileas options , if necessary .
*
* @ param array $values contact values from form
* @ param string $name name of changed value , eg . " email "
2016-04-29 12:41:53 +02:00
* @ param int $own_id = 0 own contact id , to not check against it
2012-09-06 14:26:11 +02:00
* @ return array with keys 'msg' => " EMail address exists, do you want to open contact? " ( or null if not existing )
* 'data' => array of id => " full name (addressbook) " pairs
* 'fileas_options'
*/
public function ajax_check_values ( $values , $name , $own_id = 0 )
2006-04-23 16:40:31 +02:00
{
2016-04-29 12:41:53 +02:00
$matches = null ;
2012-09-06 14:26:11 +02:00
if ( preg_match ( '/^exec\[([^\]]+)\]$/' , $name , $matches )) $name = $matches [ 1 ]; // remove exec[ ]
2006-04-23 16:40:31 +02:00
2012-09-06 14:26:11 +02:00
$ret = array ( 'doublicates' => array (), 'msg' => null );
// if email changed, check for doublicates
if ( in_array ( $name , array ( 'email' , 'email_home' )))
{
2016-06-20 10:03:03 +02:00
if ( preg_match ( Etemplate\Widget\Url :: EMAIL_PREG , $values [ $name ])) // only search for real email addresses, to not return to many contacts
2012-09-06 14:26:11 +02:00
{
$contacts = parent :: search ( array (
'email' => $values [ $name ],
'email_home' => $values [ $name ],
2016-04-29 12:41:53 +02:00
), false , '' , '' , '' , false , 'OR' );
2012-09-06 14:26:11 +02:00
}
}
else
{
// only set fileas-options if other then email changed
$ret [ 'fileas_options' ] = array_values ( $this -> fileas_options ( $values ));
2013-06-19 21:02:41 +02:00
// Full options for et2
$ret [ 'fileas_sel_options' ] = $this -> fileas_options ( $values );
2012-09-06 14:26:11 +02:00
// if name, firstname or org changed and at least 2 are specified, check for doublicates
if ( in_array ( $name , array ( 'n_given' , 'n_family' , 'org_name' )) &&
! empty ( $values [ 'n_given' ]) +! empty ( $values [ 'n_family' ]) +! empty ( $values [ 'org_name' ]) >= 2 )
{
$filter = array ();
foreach ( array ( 'email' , 'n_given' , 'n_family' , 'org_name' ) as $n ) // use email too, to exclude obvious false positives
{
if ( ! empty ( $values [ $n ])) $filter [ $n ] = $values [ $n ];
}
2016-04-29 12:41:53 +02:00
$contacts = parent :: search ( '' , false , '' , '' , '' , false , 'AND' , false , $filter );
2012-09-06 14:26:11 +02:00
}
}
if ( $contacts )
{
foreach ( $contacts as $contact )
{
if ( $own_id && $contact [ 'id' ] == $own_id ) continue ;
$ret [ 'doublicates' ][ $contact [ 'id' ]] = $this -> fileas ( $contact ) . ' (' .
( ! $contact [ 'owner' ] ? lang ( 'Accounts' ) : ( $contact [ 'owner' ] == $this -> user ?
2016-04-29 12:41:53 +02:00
( $contact [ 'private' ] ? lang ( 'Private' ) : lang ( 'Personal' )) : Api\Accounts :: username ( $contact [ 'owner' ]))) . ')' ;
2012-09-06 14:26:11 +02:00
}
if ( $ret [ 'doublicates' ])
{
$ret [ 'msg' ] = lang ( 'Similar contacts found:' ) .
" \n \n " . implode ( " \n " , $ret [ 'doublicates' ]) . " \n \n " .
lang ( 'Open for editing?' );
}
}
2012-10-24 12:18:13 +02:00
//error_log(__METHOD__.'('.array2string($values).", '$name', $own_id) doublicates found ".array2string($ret['doublicates']));
2016-04-29 12:41:53 +02:00
Api\Json\Response :: get () -> data ( $ret );
2006-04-23 16:40:31 +02:00
}
2008-04-18 08:10:31 +02:00
2014-03-10 22:15:23 +01:00
/**
* CRM view
*
* @ param array $content
*/
function view ( array $content = null )
2005-11-11 21:50:12 +01:00
{
2014-03-25 17:53:36 +01:00
// CRM list comes from content, request, or preference
$crm_list = $content [ 'crm_list' ] ? $content [ 'crm_list' ] :
( $_GET [ 'crm_list' ] ? $_GET [ 'crm_list' ] : $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'addressbook' ][ 'crm_list' ]);
2014-04-08 16:20:22 +02:00
if ( ! $crm_list || $crm_list == '~edit~' ) $crm_list = 'infolog' ;
2014-03-25 17:53:36 +01:00
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' ]);
2014-03-10 22:15:23 +01:00
switch ( $content [ 'toolbar' ] ? $content [ 'toolbar' ] : $button )
2005-11-11 21:50:12 +01:00
{
2005-11-13 18:51:41 +01:00
case 'vcard' :
2016-04-29 12:41:53 +02:00
Egw :: redirect_link ( '/index.php' , 'menuaction=addressbook.uivcard.out&ab_id=' . $content [ 'id' ]);
2005-11-13 18:51:41 +01:00
case 'cancel' :
2016-04-29 12:41:53 +02:00
Egw :: redirect_link ( '/index.php' , 'menuaction=addressbook.addressbook_ui.index&ajax=true' );
2005-11-13 18:51:41 +01:00
case 'delete' :
2016-04-29 12:41:53 +02:00
Egw :: redirect_link ( '/index.php' , array (
2008-05-10 14:02:49 +02:00
'menuaction' => 'addressbook.addressbook_ui.index' ,
2008-04-22 08:08:01 +02:00
'msg' => $this -> delete ( $content ) ? lang ( 'Contact deleted' ) : lang ( 'Error deleting the contact !!!' ),
2006-03-28 13:41:48 +02:00
));
2014-03-12 14:29:52 +01:00
case 'next' :
$inc = 1 ;
// fall through
case 'back' :
if ( ! isset ( $inc )) $inc = - 1 ;
// get next/previous contact in selection
2016-04-29 12:41:53 +02:00
$query = Api\Cache :: getSession ( 'addressbook' , 'index' );
2014-03-12 14:29:52 +01:00
$query [ 'start' ] = $content [ 'index' ] + $inc ;
$query [ 'num_rows' ] = 1 ;
$rows = $readonlys = array ();
$num_rows = $this -> get_rows ( $query , $rows , $readonlys , true );
//error_log(__METHOD__."() get_rows()=$num_rows rows=".array2string($rows));
$contact_id = $rows [ 0 ];
if ( ! $contact_id || ! is_array ( $content = $this -> read ( $contact_id )))
{
2016-04-29 12:41:53 +02:00
Egw :: redirect_link ( '/index.php' , array (
2014-03-12 14:29:52 +01:00
'menuaction' => 'addressbook.addressbook_ui.index' ,
'msg' => $content ,
'ajax' => 'true'
));
}
$content [ 'index' ] = $query [ 'start' ];
2014-03-12 16:21:01 +01:00
2014-03-12 23:42:06 +01:00
// List nextmatch is already there, just update the filter
2016-04-29 12:41:53 +02:00
if ( $contact_id && Api\Json\Request :: isJSONRequest ())
2014-03-12 16:21:01 +01:00
{
2014-03-25 17:53:36 +01:00
switch ( $crm_list )
2014-03-12 23:42:06 +01:00
{
case 'infolog' :
2014-03-19 21:21:05 +01:00
case 'tracker' :
2014-03-13 09:15:41 +01:00
default :
2016-04-29 12:41:53 +02:00
Api\Json\Response :: get () -> apply ( 'app.addressbook.view_set_list' , Array ( Array ( 'action' => 'addressbook' , 'action_id' => $contact_id )));
2014-03-12 23:42:06 +01:00
break ;
}
2014-03-12 16:21:01 +01:00
2014-03-12 23:42:06 +01:00
// Clear contact_id, it's used as a flag to send the list
2014-03-12 16:21:01 +01:00
unset ( $contact_id );
}
2014-03-12 14:29:52 +01:00
break ;
2005-11-11 21:50:12 +01:00
}
}
else
{
2015-10-07 11:31:10 +02:00
// allow to search eg. for a phone number
if ( isset ( $_GET [ 'search' ]))
{
2016-04-29 12:41:53 +02:00
$query = Api\Cache :: getSession ( 'addressbook' , 'index' );
2015-10-07 11:31:10 +02:00
$query [ 'search' ] = $_GET [ 'search' ];
unset ( $_GET [ 'search' ]);
// reset all filters
unset ( $query [ 'advanced_search' ]);
$query [ 'col_filter' ] = array ();
$query [ 'filter' ] = $query [ 'filter2' ] = $query [ 'cat_id' ] = '' ;
2016-04-29 12:41:53 +02:00
Api\Cache :: setSession ( 'addressbook' , 'index' , $query );
2015-10-07 11:31:10 +02:00
$query [ 'start' ] = 0 ;
$query [ 'num_rows' ] = 1 ;
$rows = $readonlys = array ();
$num_rows = $this -> get_rows ( $query , $rows , $readonlys , true );
$_GET [ 'contact_id' ] = array_shift ( $rows );
$_GET [ 'index' ] = 0 ;
}
2012-05-03 17:23:30 +02:00
$contact_id = $_GET [ 'contact_id' ] ? $_GET [ 'contact_id' ] : (( int ) $_GET [ 'account_id' ] ? 'account:' . ( int ) $_GET [ 'account_id' ] : 0 );
if ( ! $contact_id || ! is_array ( $content = $this -> read ( $contact_id )))
2006-03-28 13:41:48 +02:00
{
2016-04-29 12:41:53 +02:00
Egw :: redirect_link ( '/index.php' , array (
2008-05-10 14:02:49 +02:00
'menuaction' => 'addressbook.addressbook_ui.index' ,
2006-03-28 13:41:48 +02:00
'msg' => $content ,
2013-11-27 01:12:11 +01:00
'ajax' => 'true'
2015-10-07 11:31:10 +02:00
) + ( isset ( $_GET [ 'search' ]) ? array ( 'search' => $_GET [ 'search' ]) : array ()));
2006-03-28 13:41:48 +02:00
}
2014-03-12 14:29:52 +01:00
if ( isset ( $_GET [ 'index' ]))
{
$content [ 'index' ] = ( int ) $_GET [ 'index' ];
// get number of rows to determine if we can have a next button
2016-04-29 12:41:53 +02:00
$query = Api\Cache :: getSession ( 'addressbook' , 'index' );
2014-03-12 14:29:52 +01:00
$query [ 'start' ] = $content [ 'index' ];
$query [ 'num_rows' ] = 1 ;
$rows = $readonlys = array ();
$num_rows = $this -> get_rows ( $query , $rows , $readonlys , true );
}
2005-11-11 21:50:12 +01:00
}
2014-08-06 01:27:06 +02:00
$content [ 'jpegphoto' ] = ! empty ( $content [ 'jpegphoto' ]); // unused and messes up json encoding (not utf-8)
2011-04-19 17:03:58 +02:00
// make everything not explicit mentioned readonly
$readonlys [ '__ALL__' ] = true ;
$readonlys [ 'photo' ] = $readonlys [ 'button[cancel]' ] = $readonlys [ 'button[copy]' ] =
2014-03-10 22:15:23 +01:00
$readonlys [ 'button[ok]' ] = $readonlys [ 'button[more]' ] = $readonlys [ 'toolbar' ] = false ;
2011-04-19 17:03:58 +02:00
2006-04-30 11:34:24 +02:00
foreach ( array_keys ( $this -> contact_fields ) as $key )
2005-11-11 21:50:12 +01:00
{
2008-08-25 15:49:32 +02:00
if ( in_array ( $key , array ( 'tel_home' , 'tel_work' , 'tel_cell' , 'tel_fax' )))
2005-11-13 18:51:41 +01:00
{
$content [ $key . '2' ] = $content [ $key ];
2008-04-18 08:10:31 +02:00
}
2005-11-11 21:50:12 +01:00
}
2010-03-05 09:28:25 +01:00
2009-11-20 09:49:39 +01:00
// respect category permissions
if ( ! empty ( $content [ 'cat_id' ]))
{
2016-04-29 12:41:53 +02:00
$content [ 'cat_id' ] = $this -> categories -> check_list ( Acl :: READ , $content [ 'cat_id' ]);
2009-11-20 09:49:39 +01:00
}
2013-12-05 21:38:16 +01:00
$content [ 'cat_id_tree' ] = $content [ 'cat_id' ];
2009-11-26 09:32:18 +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' ],
);
2010-09-27 18:39:54 +02:00
// Links for deleted entries
2016-03-06 14:45:15 +01:00
if ( $content [ 'tid' ] == self :: DELETED_TYPE )
2010-09-27 18:39:54 +02:00
{
$content [ 'link_to' ][ 'show_deleted' ] = true ;
}
2016-04-29 12:41:53 +02:00
$readonlys [ 'button[delete]' ] = ! $content [ 'owner' ] || ! $this -> check_perms ( Acl :: DELETE , $content );
$readonlys [ 'button[edit]' ] = ! $this -> check_perms ( Acl :: EDIT , $content );
2006-04-30 11:34:24 +02:00
2007-06-23 09:09:52 +02:00
// how to display addresses
$content [ 'addr_format' ] = $this -> addr_format_by_country ( $content [ 'adr_one_countryname' ]);
$content [ 'addr_format2' ] = $this -> addr_format_by_country ( $content [ 'adr_two_countryname' ]);
2008-04-18 08:10:31 +02:00
2006-04-23 16:40:31 +02:00
$sel_options [ 'fileas_type' ][ $content [ 'fileas_type' ]] = $this -> fileas ( $content );
$sel_options [ 'owner' ] = $this -> get_addressbooks ();
2016-04-29 12:41:53 +02:00
for ( $i = - 23 ; $i <= 23 ; $i ++ )
{
$tz [ $i ] = ( $i > 0 ? '+' : '' ) . $i ;
}
2006-03-14 15:26:55 +01:00
$sel_options [ 'tz' ] = $tz ;
$content [ 'tz' ] = $content [ 'tz' ] ? $content [ 'tz' ] : 0 ;
2006-04-30 11:34:24 +02:00
if ( count ( $this -> content_types ) > 1 )
{
foreach ( $this -> content_types as $type => $data )
{
$sel_options [ 'tid' ][ $type ] = $data [ 'name' ];
}
2016-04-29 12:41:53 +02:00
$content [ 'typegfx' ] = Api\Html :: image ( 'addressbook' , $this -> content_types [ $content [ 'tid' ]][ 'options' ][ 'icon' ], '' , ' width="16px" height="16px"' );
2006-04-30 11:34:24 +02:00
}
else
{
$content [ 'no_tid' ] = true ;
}
2014-03-06 19:39:52 +01:00
$this -> tmpl -> read ( 'addressbook.view' );
/* if ( ! $this -> tmpl -> read ( $this -> content_types [ $content [ 'tid' ]][ 'options' ][ 'template' ] ? $this -> content_types [ $content [ 'tid' ]][ 'options' ][ 'template' ] : 'addressbook.edit' ))
2006-03-14 15:26:55 +01:00
{
2007-06-17 15:15:13 +02:00
$content [ 'msg' ] = lang ( 'WARNING: Template "%1" not found, using default template instead.' , $this -> content_types [ $content [ 'tid' ]][ 'options' ][ 'template' ]) . " \n " ;
$content [ 'msg' ] .= lang ( 'Please update the templatename in your customfields section!' );
$this -> tmpl -> read ( 'addressbook.edit' );
2014-03-06 19:39:52 +01:00
} */
2007-06-03 13:42:39 +02:00
if ( $this -> private_addressbook && $content [ 'private' ] && $content [ 'owner' ] == $this -> user )
{
$content [ 'owner' ] .= 'p' ;
}
2012-05-15 17:52:11 +02:00
$this -> tmpl -> set_cell_attribute ( 'change_org' , 'disabled' , true );
2010-02-08 18:53:47 +01:00
2011-02-17 21:00:54 +01:00
// Prevent double countries - invalid code blanks it, disabling doesn't work
$content [ 'adr_one_countrycode' ] = '-' ;
$content [ 'adr_two_countrycode' ] = '-' ;
2010-02-08 18:53:47 +01:00
// Enable history
$this -> setup_history ( $content , $sel_options );
2007-10-19 10:34:47 +02:00
// disable not needed tabs
2009-05-11 08:47:38 +02:00
$readonlys [ 'tabs' ][ 'cats' ] = ! ( $content [ 'cat_tab' ] = $this -> config [ 'cat_tab' ]);
$readonlys [ 'tabs' ][ 'custom' ] = ! $this -> customfields ;
$readonlys [ 'tabs' ][ 'custom_private' ] = ! $this -> customfields || ! $this -> config [ 'private_cf_tab' ];
$readonlys [ 'tabs' ][ 'distribution_list' ] = ! $content [ 'distrib_lists' ]; #false;
2013-07-11 17:33:59 +02:00
$readonlys [ 'tabs' ][ 'history' ] = $this -> contact_repository != 'sql' || ! $content [ 'id' ] ||
$this -> account_repository != 'sql' && $content [ 'account_id' ];
2008-01-19 06:41:04 +01:00
if ( $this -> config [ 'private_cf_tab' ]) $content [ 'no_private_cfs' ] = 0 ;
2008-04-18 08:10:31 +02:00
2007-10-19 10:34:47 +02:00
// last and next calendar date
2017-03-08 17:53:52 +01:00
if ( ! empty ( $content [ 'id' ])) list (, $dates ) = each ( $this -> read_calendar ( array ( $content [ 'account_id' ] ? $content [ 'account_id' ] : 'c' . $content [ 'id' ]), false ));
2007-10-19 10:34:47 +02:00
if ( is_array ( $dates )) $content += $dates ;
2011-06-22 20:14:52 +02:00
// Disable importexport
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'disable_importexport' ][ 'export' ] = true ;
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'disable_importexport' ][ 'merge' ] = true ;
2006-12-11 08:35:49 +01:00
// set id for automatic linking via quick add
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentid' ] = $content [ 'id' ];
2014-02-12 12:07:33 +01:00
// load app.css for addressbook explicit, as addressbook_view hooks changes currentapp!
2016-04-29 12:41:53 +02:00
Framework :: includeCSS ( 'addressbook' , 'app' );
2011-05-02 15:34:59 +02:00
2014-03-10 22:15:23 +01:00
// dont show an app-header
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = '' ;
2014-03-12 14:29:52 +01:00
$actions = array (
'open' => array (
'caption' => 'Open' ,
2014-03-06 19:39:52 +01:00
'toolbarDefault' => true ,
),
'copy' => 'Copy' ,
'delete' => array (
'caption' => 'Delete' ,
'confirm' => 'Delete this entry' ,
),
'cancel' => array (
'caption' => 'Cancel' ,
'toolbarDefault' => true ,
),
'back' => array (
'caption' => 'Back' ,
'toolbarDefault' => true ,
),
'next' => array (
'caption' => 'Next' ,
'toolbarDefault' => true ,
),
2014-03-12 14:29:52 +01:00
);
if ( ! isset ( $content [ 'index' ]) || ! $content [ 'index' ])
{
unset ( $actions [ 'back' ]);
}
if ( ! isset ( $content [ 'index' ]) || $content [ 'index' ] >= $num_rows - 1 )
{
unset ( $actions [ 'next' ]);
}
$this -> tmpl -> setElementAttribute ( 'toolbar' , 'actions' , $actions );
2014-03-06 19:39:52 +01:00
2014-03-10 13:32:19 +01:00
// always show sidebox, as it contains contact-data
unset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'auto_hide_sidebox' ]);
2014-03-19 21:21:05 +01:00
// need to load list's app.js now, as exec calls header before other app can include it
2016-04-29 12:41:53 +02:00
Framework :: includeJS ( '/' . $crm_list . '/js/app.js' );
2014-03-10 13:32:19 +01:00
2014-03-12 14:29:52 +01:00
$this -> tmpl -> exec ( 'addressbook.addressbook_ui.view' , $content , $sel_options , $readonlys , array (
'id' => $content [ 'id' ],
'index' => $content [ 'index' ],
2014-03-25 17:53:36 +01:00
'crm_list' => $crm_list
2014-03-12 14:29:52 +01:00
));
2007-06-03 15:21:13 +02:00
2014-03-11 16:26:09 +01:00
// Only load this on first time - we're using AJAX, so it stays there through submits.
// Sending it again (via ajax) will break the addressbook.view etemplate2
if ( $contact_id )
{
2016-04-29 12:41:53 +02:00
Api\Hooks :: single ( array (
2014-03-11 16:26:09 +01:00
'location' => 'addressbook_view' ,
'ab_id' => $content [ 'id' ]
2014-03-25 17:53:36 +01:00
), $crm_list );
2014-03-11 16:26:09 +01:00
}
2005-11-04 00:47:52 +01:00
}
2008-04-18 08:10:31 +02: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 )
{
2007-04-29 16:28:47 +02:00
if ( strpos ( $email , '@' ) == false ) return '' ;
2005-11-18 18:03:23 +01:00
2014-03-21 12:54:38 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'mail' ])
{
return array (
'menuaction' => 'mail.mail_compose.compose' ,
'send_to' => base64_encode ( $email )
);
}
2005-11-18 18:03:23 +01:00
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 ;
}
2006-12-19 12:25:44 +01:00
/**
* Extended search
*
* @ param array $_content
* @ return string
*/
2006-10-24 21:20:37 +02:00
function search ( $_content = array ())
2005-11-04 00:47:52 +01:00
{
2010-10-12 16:01:36 +02:00
if ( ! empty ( $_content ))
{
2014-02-12 12:07:33 +01:00
2014-09-09 23:55:00 +02:00
$_content [ 'cat_id' ] = $this -> config [ 'cat_tab' ] === 'Tree' ? $_content [ 'cat_id_tree' ] : $_content [ 'cat_id' ];
2016-04-29 12:41:53 +02:00
$response = Api\Json\Response :: get ();
2008-04-18 08:10:31 +02:00
2016-04-29 12:41:53 +02:00
$query = Api\Cache :: getSession ( 'addressbook' , 'index' );
2008-04-18 08:10:31 +02:00
2014-01-31 17:04:05 +01:00
if ( $_content [ 'button' ][ 'cancelsearch' ])
2010-10-12 16:01:36 +02:00
{
unset ( $query [ 'advanced_search' ]);
}
else
2007-07-12 15:02:19 +02:00
{
2010-10-12 16:01:36 +02:00
$query [ 'advanced_search' ] = array_intersect_key ( $_content , array_flip ( array_merge ( $this -> get_contact_columns (), array ( 'operator' , 'meth_select' ))));
foreach ( $query [ 'advanced_search' ] as $key => $value )
{
if ( ! $value ) unset ( $query [ 'advanced_search' ][ $key ]);
}
2014-09-08 20:47:40 +02:00
// Skip n_fn, it causes problems in sql
unset ( $query [ 'advanced_search' ][ 'n_fn' ]);
2007-07-12 15:02:19 +02:00
}
$query [ 'search' ] = '' ;
// store the index state in the session
2016-04-29 12:41:53 +02:00
Api\Cache :: setSession ( 'addressbook' , 'index' , $query );
2007-07-12 15:02:19 +02:00
// store the advanced search in the session to call it again
2016-04-29 12:41:53 +02:00
Api\Cache :: setSession ( 'addressbook' , 'advanced_search' , $query [ 'advanced_search' ]);
2014-09-08 20:47:40 +02:00
// Update client / nextmatch with filters, or clear
$response -> call ( " app.addressbook.adv_search " , array ( 'advanced_search' => $_content [ 'button' ][ 'search' ] ? $query [ 'advanced_search' ] : '' ));
if ( $_content [ 'button' ][ 'cancelsearch' ])
{
2016-04-29 12:41:53 +02:00
Framework :: window_close ();
2014-09-08 20:47:40 +02:00
// No need to reload popup
return ;
}
2006-10-24 21:20:37 +02:00
}
2014-02-12 12:07:33 +01:00
2006-10-24 21:20:37 +02:00
$GLOBALS [ 'egw_info' ][ 'etemplate' ][ 'advanced_search' ] = true ;
2008-04-18 08:10:31 +02:00
2006-10-21 22:14:31 +02:00
// initialize etemplate arrays
2010-10-12 16:01:36 +02:00
$sel_options = $readonlys = array ();
2016-11-07 17:23:22 +01:00
$this -> tmpl -> read ( 'addressbook.edit' );
2016-04-29 12:41:53 +02:00
$content = Api\Cache :: getSession ( 'addressbook' , 'advanced_search' );
2010-10-12 16:01:36 +02:00
$content [ 'n_fn' ] = $this -> fullname ( $content );
2014-09-09 23:55:00 +02:00
// Avoid ID conflict with tree & selectboxes
$content [ 'cat_id_tree' ] = $content [ 'cat_id' ];
2008-04-18 08:10:31 +02:00
2016-04-29 12:41:53 +02:00
for ( $i = - 23 ; $i <= 23 ; $i ++ )
{
$tz [ $i ] = ( $i > 0 ? '+' : '' ) . $i ;
}
2005-11-04 00:47:52 +01:00
$sel_options [ 'tz' ] = $tz + array ( '' => lang ( 'doesn\'t matter' ));
2006-03-14 15:26:55 +01:00
$sel_options [ 'tid' ][] = lang ( 'all' );
//foreach($this->content_types as $type => $data) $sel_options['tid'][$type] = $data['name'];
2008-04-18 08:10:31 +02:00
2006-10-24 21:20:37 +02:00
// configure search options
2016-04-29 12:41:53 +02:00
$sel_options [ 'owner' ] = $this -> get_addressbooks ( Acl :: READ , lang ( 'all' ));
2006-10-24 21:20:37 +02:00
$sel_options [ 'operator' ] = array (
2008-10-05 08:16:13 +02:00
'AND' => 'AND' ,
2006-10-24 21:20:37 +02:00
'OR' => 'OR' ,
);
$sel_options [ 'meth_select' ] = array (
'%' => lang ( 'contains' ),
false => lang ( 'exact' ),
);
2007-05-15 16:23:28 +02:00
if ( $this -> customfields )
{
foreach ( $this -> customfields as $name => $data )
{
2014-09-09 10:36:34 +02:00
if ( substr ( $data [ 'type' ], 0 , 6 ) == 'select' && ! ( $data [ 'rows' ] > 1 ))
2007-05-15 16:23:28 +02:00
{
if ( ! isset ( $content [ '#' . $name ])) $content [ '#' . $name ] = '' ;
if ( ! isset ( $data [ 'values' ][ '' ])) $sel_options [ '#' . $name ][ '' ] = lang ( 'Select one' );
}
2016-11-07 17:23:22 +01:00
// Make them not required, otherwise you can't search
$this -> tmpl -> setElementAttribute ( '#' . $name , 'needed' , FALSE );
2007-05-15 16:23:28 +02:00
}
}
2006-10-24 21:20:37 +02:00
// configure edit template as search dialog
2006-04-24 22:52:14 +02:00
$readonlys [ 'change_photo' ] = true ;
2006-10-21 22:14:31 +02:00
$readonlys [ 'fileas_type' ] = true ;
$readonlys [ 'creator' ] = true ;
2008-08-26 12:40:20 +02:00
// this setting will enable (and show) the search and cancel buttons, setting this to true will hide the before mentioned buttons completely
$readonlys [ 'button' ] = false ;
2006-12-16 13:02:14 +01:00
// disable not needed tabs
2009-05-11 08:47:38 +02:00
$readonlys [ 'tabs' ][ 'cats' ] = ! ( $content [ 'cat_tab' ] = $this -> config [ 'cat_tab' ]);
$readonlys [ 'tabs' ][ 'custom' ] = ! $this -> customfields ;
$readonlys [ 'tabs' ][ 'custom_private' ] = ! $this -> customfields || ! $this -> config [ 'private_cf_tab' ];
$readonlys [ 'tabs' ][ 'links' ] = true ;
$readonlys [ 'tabs' ][ 'distribution_list' ] = true ;
2014-02-03 14:32:34 +01:00
$readonlys [ 'tabs' ][ 'history' ] = true ;
2008-08-26 12:40:20 +02:00
// setting hidebuttons for content will hide the 'normal' addressbook edit dialog buttons
2006-10-21 22:14:31 +02:00
$content [ 'hidebuttons' ] = true ;
2006-10-24 21:20:37 +02:00
$content [ 'no_tid' ] = true ;
2014-01-31 17:04:05 +01:00
$content [ 'showsearchbuttons' ] = true ; // enable search operation and search buttons| they're disabled by default
2014-02-03 17:19:49 +01:00
if ( $this -> config [ 'private_cf_tab' ]) $content [ 'no_private_cfs' ] = 0 ;
2014-02-12 12:07:33 +01:00
2012-05-15 18:52:25 +02:00
$this -> tmpl -> set_cell_attribute ( 'change_org' , 'disabled' , true );
2014-01-31 17:04:05 +01:00
return $this -> tmpl -> exec ( 'addressbook.addressbook_ui.search' , $content , $sel_options , $readonlys , array (), 2 );
2005-11-04 00:47:52 +01:00
}
2006-04-30 20:03:06 +02:00
/**
* download photo of the given ( $_GET [ 'contact_id' ] or $_GET [ 'account_id' ]) contact
*/
2006-04-23 16:40:31 +02:00
function photo ()
{
ob_start ();
2008-04-18 08:10:31 +02:00
$contact_id = isset ( $_GET [ 'contact_id' ]) ? $_GET [ 'contact_id' ] :
2006-04-23 16:40:31 +02:00
( isset ( $_GET [ 'account_id' ]) ? 'account:' . $_GET [ 'account_id' ] : 0 );
2008-04-18 08:10:31 +02:00
2006-04-23 16:40:31 +02:00
if ( substr ( $contact_id , 0 , 8 ) == 'account:' )
{
$contact_id = $GLOBALS [ 'egw' ] -> accounts -> id2name ( substr ( $contact_id , 8 ), 'person_id' );
}
if ( ! ( $contact = $this -> read ( $contact_id )) || ! $contact [ 'jpegphoto' ])
{
2016-04-29 12:41:53 +02:00
Egw :: redirect ( Api\Image :: find ( 'addressbook' , 'photo' ));
2006-04-23 16:40:31 +02:00
}
2014-03-06 16:10:22 +01:00
// use an etag over the image mapp
$etag = '"' . $contact [ 'id' ] . ':' . $contact [ 'etag' ] . '"' ;
2006-04-23 16:40:31 +02:00
if ( ! ob_get_contents ())
{
header ( 'Content-type: image/jpeg' );
2014-03-06 16:10:22 +01:00
header ( 'ETag: ' . $etag );
// if etag parameter given in url, we can allow browser to cache picture via an Expires header
// different url with different etag parameter will force a reload
if ( isset ( $_GET [ 'etag' ]))
{
2016-04-29 12:41:53 +02:00
Api\Session :: cache_control ( 30 * 86400 ); // cache for 30 days
2014-03-06 16:10:22 +01:00
}
// if servers send a If-None-Match header, response with 304 Not Modified, if etag matches
if ( isset ( $_SERVER [ 'HTTP_IF_NONE_MATCH' ]) && $_SERVER [ 'HTTP_IF_NONE_MATCH' ] === $etag )
{
header ( " HTTP/1.1 304 Not Modified " );
}
else
{
header ( 'Content-length: ' . bytes ( $contact [ 'jpegphoto' ]));
echo $contact [ 'jpegphoto' ];
}
2016-04-29 12:41:53 +02:00
exit ();
2006-04-23 16:40:31 +02:00
}
}
2008-04-18 08:10:31 +02:00
2009-05-09 09:58:16 +02:00
/**
* Migrate contacts to or from LDAP ( called by Admin >> Addressbook >> Site configuration ( Admin only )
*
*/
2006-07-08 02:36:23 +02:00
function migrate2ldap ()
{
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( 'Addressbook' ) . ' - ' . lang ( 'Migration to LDAP' );
2016-05-14 21:26:36 +02:00
echo $GLOBALS [ 'egw' ] -> framework -> header ();
echo $GLOBALS [ 'egw' ] -> framework -> navbar ();
2008-04-18 08:10:31 +02:00
2006-09-15 09:16:07 +02:00
if ( ! $this -> is_admin ())
2006-07-08 02:36:23 +02:00
{
echo '<h1>' . lang ( 'Permission denied !!!' ) . " </h1> \n " ;
}
else
{
parent :: migrate2ldap ( $_GET [ 'type' ]);
echo '<p style="margin-top: 20px;"><b>' . lang ( 'Migration finished' ) . " </b></p> \n " ;
}
2016-05-14 21:26:36 +02:00
echo $GLOBALS [ 'egw' ] -> framework -> footer ();
2006-07-08 02:36:23 +02:00
}
2008-04-18 08:10:31 +02:00
2009-05-09 09:58:16 +02:00
/**
* Set n_fileas ( and n_fn ) in contacts of all users ( called by Admin >> Addressbook >> Site configuration ( Admin only )
*
* If $_GET [ all ] all fileas fields will be set , if ! $_GET [ all ] only empty ones
*
*/
function admin_set_fileas ()
{
2016-04-29 12:41:53 +02:00
Api\Translation :: add_app ( 'admin' );
2009-05-09 09:58:16 +02:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( 'Addressbook' ) . ' - ' . lang ( 'Contact maintenance' );
2016-05-14 21:26:36 +02:00
echo $GLOBALS [ 'egw' ] -> framework -> header ();
echo $GLOBALS [ 'egw' ] -> framework -> navbar ();
2009-05-09 09:58:16 +02:00
// check if user has admin rights AND if a valid fileas type is given (Security)
if ( ! $this -> is_admin () || $_GET [ 'type' ] != '' && ! in_array ( $_GET [ 'type' ], $this -> fileas_types ))
{
echo '<h1>' . lang ( 'Permission denied !!!' ) . " </h1> \n " ;
}
else
{
2016-04-29 12:41:53 +02:00
$errors = null ;
$updated = parent :: set_all_fileas ( $_GET [ 'type' ],( boolean ) $_GET [ 'all' ], $errors , true ); // true = ignore Acl
2009-05-09 09:58:16 +02:00
echo '<p style="margin-top: 20px;"><b>' . lang ( '%1 contacts updated (%2 errors).' , $updated , $errors ) . " </b></p> \n " ;
}
2016-05-14 21:26:36 +02:00
echo $GLOBALS [ 'egw' ] -> framework -> footer ();
2009-05-09 09:58:16 +02:00
}
2010-03-05 09:28:25 +01:00
2009-11-11 09:44:51 +01:00
/**
* Cleanup all contacts of all users ( called by Admin >> Addressbook >> Site configuration ( Admin only )
*
*/
function admin_set_all_cleanup ()
{
2016-04-29 12:41:53 +02:00
Api\Translation :: add_app ( 'admin' );
2009-11-11 09:44:51 +01:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( 'Addressbook' ) . ' - ' . lang ( 'Contact maintenance' );
2016-05-14 21:26:36 +02:00
echo $GLOBALS [ 'egw' ] -> framework -> header ();
echo $GLOBALS [ 'egw' ] -> framework -> navbar ();
2009-11-11 09:44:51 +01:00
// check if user has admin rights (Security)
if ( ! $this -> is_admin ())
{
echo '<h1>' . lang ( 'Permission denied !!!' ) . " </h1> \n " ;
}
else
{
2016-04-29 12:41:53 +02:00
$errors = null ;
$updated = parent :: set_all_cleanup ( $errors , true ); // true = ignore Acl
2009-11-11 09:44:51 +01:00
echo '<p style="margin-top: 20px;"><b>' . lang ( '%1 contacts updated (%2 errors).' , $updated , $errors ) . " </b></p> \n " ;
}
2016-05-14 21:26:36 +02:00
echo $GLOBALS [ 'egw' ] -> framework -> footer ();
2009-11-11 09:44:51 +01:00
}
2009-05-09 09:58:16 +02:00
2010-02-08 18:53:47 +01:00
/**
* Set up history log widget
*/
2010-11-13 10:10:11 +01:00
protected function setup_history ( & $content , & $sel_options )
{
if ( $this -> contact_repository == 'ldap' || ! $content [ 'id' ] ||
$this -> account_repository == 'ldap' && $content [ 'account_id' ])
{
return ; // no history for ldap as history table only allows integer id's
}
2010-02-08 18:53:47 +01:00
$content [ 'history' ] = array (
'id' => $content [ 'id' ],
'app' => 'addressbook' ,
'status-widgets' => array (
'owner' => 'select-account' ,
2011-02-18 19:28:11 +01:00
'creator' => 'select-account' ,
'created' => 'date-time' ,
2010-02-08 18:53:47 +01:00
'cat_id' => 'select-cat' ,
2010-11-15 17:29:31 +01:00
'adr_one_countrycode' => 'select-country' ,
'adr_two_countrycode' => 'select-country' ,
2010-02-08 18:53:47 +01:00
),
);
2010-11-13 10:10:11 +01:00
foreach ( $this -> content_types as $id => $settings )
{
2010-02-08 18:53:47 +01:00
$content [ 'history' ][ 'status-widgets' ][ 'tid' ][ $id ] = $settings [ 'name' ];
}
$sel_options [ 'status' ] = $this -> contact_fields ;
2010-02-12 17:47:15 +01:00
2011-04-19 17:03:58 +02:00
// custom fields no longer need to be added, historylog-widget "knows" about them
2010-02-08 18:53:47 +01:00
}
2005-11-11 21:50:12 +01:00
}