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 >
2011-04-07 09:28:46 +02:00
* @ copyright ( c ) 2005 - 11 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
/**
* 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'
);
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
2008-03-21 21:57:01 +01: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
2005-11-04 00:47:52 +01:00
// our javascript
// to be moved in a seperate file if rewrite is over
2007-05-25 20:20:57 +02:00
if ( strpos ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'java_script' ], 'add_new_list' ) === false )
{
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'java_script' ] .= $this -> js ();
}
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
2009-05-30 09:39:58 +02:00
if ( $this -> config [ 'contact_export_limit' ])
2008-10-16 13:17:49 +02:00
{
$this -> config [ 'export_limit' ] = $this -> config [ 'contact_export_limit' ];
}
else // if not use the global one
{
$this -> config [ 'contact_export_limit' ] = $this -> config [ 'export_limit' ];
}
2010-08-30 12:21:23 +02:00
if ( $this -> config [ 'copy_fields' ] && ( $fields = unserialize ( $this -> config [ 'copy_fields' ])))
{
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
*
* @ param array $content = null submitted content
2008-04-18 08:10:31 +02:00
* @ param string $msg = null message to show
2006-06-16 06:44:58 +02:00
* @ param boolean $do_email = false do an email - selection popup or the regular index - page
2006-04-23 16:40:31 +02:00
*/
2006-06-16 06:44:58 +02:00
function index ( $content = null , $msg = null , $do_email = false )
2006-04-23 16:40:31 +02:00
{
2006-04-30 11:34:24 +02:00
//echo "<p>uicontacts::index(".print_r($content,true).",'$msg')</p>\n";
2006-06-16 06:44:58 +02:00
if (( $re_submit = is_array ( $content )))
2006-04-23 16:40:31 +02:00
{
2006-06-16 06:44:58 +02:00
$do_email = $content [ 'do_email' ];
2005-11-04 00:47:52 +01:00
2006-04-23 16:40:31 +02:00
if ( isset ( $content [ 'nm' ][ 'rows' ][ 'delete' ])) // handle a single delete like delete with the checkboxes
{
list ( $id ) = @ each ( $content [ 'nm' ][ 'rows' ][ 'delete' ]);
2011-04-17 16:10:05 +02:00
$content [ 'nm' ][ 'action' ] = 'delete' ;
$content [ 'nm' ][ 'selected' ] = array ( $id );
2006-04-23 16:40:31 +02:00
}
2007-06-17 15:55:43 +02:00
if ( isset ( $content [ 'nm' ][ 'rows' ][ 'document' ])) // handle insert in default document button like an action
{
list ( $id ) = @ each ( $content [ 'nm' ][ 'rows' ][ 'document' ]);
2011-04-17 16:10:05 +02:00
$content [ 'nm' ][ 'action' ] = 'document' ;
$content [ 'nm' ][ 'selected' ] = array ( $id );
2007-06-17 15:55:43 +02:00
}
2011-04-17 16:10:05 +02:00
if ( $content [ 'nm' ][ 'action' ] !== '' )
2006-04-23 16:40:31 +02:00
{
2011-04-17 16:10:05 +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' );
}
2011-04-25 13:30:37 +02:00
elseif ( $content [ 'nm' ][ 'action' ] == 'view' ) // org-view via context menu
{
$content [ 'nm' ][ 'org_view' ] = array_shift ( $content [ 'nm' ][ 'selected' ]);
}
2006-04-23 16:40:31 +02:00
else
{
2011-04-17 16:10:05 +02:00
if ( $this -> action ( $content [ 'nm' ][ 'action' ], $content [ 'nm' ][ 'selected' ], $content [ 'nm' ][ 'select_all' ],
2007-03-13 14:38:15 +01:00
$success , $failed , $action_msg , $content [ 'do_email' ] ? 'email' : 'index' , $msg ))
2006-04-23 16:40:31 +02:00
{
$msg .= lang ( '%1 contact(s) %2' , $success , $action_msg );
}
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 );
}
}
}
2006-10-23 13:48:56 +02:00
if ( $content [ 'nm' ][ 'rows' ][ 'infolog' ])
{
list ( $org ) = each ( $content [ 'nm' ][ 'rows' ][ 'infolog' ]);
return $this -> infolog_org_view ( $org );
}
2006-04-30 11:34:24 +02:00
if ( $content [ 'nm' ][ 'rows' ][ 'view' ]) // show all contacts of an organisation
{
list ( $org_view ) = each ( $content [ 'nm' ][ 'rows' ][ 'view' ]);
}
else
{
$org_view = $content [ 'nm' ][ 'org_view' ];
}
2008-10-20 21:35:18 +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 ,
);
2007-05-25 20:20:57 +02:00
$to = $content [ 'nm' ][ 'to' ];
2006-04-23 16:40:31 +02:00
$content = array (
'msg' => $msg ? $msg : $_GET [ 'msg' ],
);
2007-11-23 09:32:08 +01:00
2009-11-28 12:56:53 +01:00
$content [ 'nm' ] = egw_session :: appsession ( $do_email ? 'email' : 'index' , 'addressbook' );
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-10-02 09:49:00 +02:00
'options-cat_id' => array ( lang ( 'none' )),
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)
2006-06-16 06:44:58 +02:00
'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)
2007-05-01 11:17:23 +02: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 ,
2006-06-16 06:44:58 +02:00
'do_email' => $do_email ,
2011-04-17 16:10:05 +02:00
'default_cols' => '!cat_id,contact_created_contact_modified,distribution_list,contact_id,owner,legacy_actions' ,
2007-03-13 14:38:15 +01:00
'filter2_onchange' => " if(this.value=='add') { add_new_list(document.getElementById(form::name('filter')).value); this.value='';} else this.form.submit(); " ,
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' ,
2006-04-23 16:40:31 +02:00
);
2008-06-05 14:04:00 +02:00
$csv_export = new addressbook_csv ( $this );
2011-04-07 09:28:46 +02:00
$content [ 'nm' ][ 'csv_fields' ] = $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'addressbook' ][ 'nextmatch-export-definition' ] ?
2011-02-28 19:10:43 +01:00
$GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'addressbook' ][ 'nextmatch-export-definition' ] :
$csv_export -> csv_fields ( null , true );
2008-06-05 14:04:00 +02:00
2007-05-25 20:20:57 +02:00
if ( $do_email )
{
$content [ 'nm' ][ 'filter2_onchange' ] = str_replace ( 'this.form.submit();' ,
2007-11-06 16:45:40 +01:00
" { if (this.value && confirm(' " . lang ( 'Add emails of whole distribution list?' ) . " ')) add_whole_list(this.value); else this.form.submit(); } " ,
2007-05-25 20:20:57 +02:00
$content [ 'nm' ][ 'filter2_onchange' ]);
}
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 );
}
}
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 ;
2007-05-03 07:07:30 +02:00
if ( $this -> lists_available ())
2007-03-13 14:38:15 +01:00
{
2007-05-03 07:07:30 +02:00
$sel_options [ 'filter2' ] = $this -> get_lists ( EGW_ACL_READ , array ( '' => lang ( 'none' )));
$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
}
2011-02-04 17:19:38 +01:00
$sel_options [ 'filter' ] = $sel_options [ 'owner' ] = $this -> get_addressbooks ( EGW_ACL_READ , lang ( 'All' ));
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
);
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
$content [ 'nm' ][ 'header_right' ] = 'addressbook.index.right_add' ;
$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 )
{
$content [ 'nm' ][ 'header_right' ] = 'addressbook.index.right_addplus' ;
foreach ( $this -> content_types as $tid => $data )
{
$sel_options [ 'col_filter[tid]' ][ $tid ] = $data [ 'name' ];
}
}
// get the availible org-views plus the label of the contacts view of one org
$sel_options [ 'org_view' ] = $this -> org_views ;
if ( isset ( $org_view )) $content [ 'nm' ][ 'org_view' ] = $org_view ;
2011-04-25 13:30:37 +02:00
$content [ 'nm' ][ 'actions' ] = $this -> get_actions ( $do_email , $content [ 'nm' ][ 'col_filter' ][ 'tid' ], $content [ 'nm' ][ 'org_view' ]);
2011-04-17 16:10:05 +02:00
if ( ! isset ( $sel_options [ 'org_view' ][( string ) $content [ 'nm' ][ 'org_view' ]]))
{
$org_name = array ();
if ( strpos ( $content [ 'nm' ][ 'org_view' ], '*AND*' ) !== false ) $content [ 'nm' ][ 'org_view' ] = str_replace ( '*AND*' , '&' , $content [ 'nm' ][ 'org_view' ]);
foreach ( explode ( '|||' , $content [ 'nm' ][ 'org_view' ]) as $part )
{
list (, $name ) = explode ( ':' , $part , 2 );
if ( $name ) $org_name [] = $name ;
}
$org_name = implode ( ': ' , $org_name );
$sel_options [ 'org_view' ][( string ) $content [ 'nm' ][ 'org_view' ]] = $org_name ;
}
// 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' ]];
$this -> tmpl -> read ( /*$do_email ? 'addressbook.email' :*/ 'addressbook.index' );
return $this -> tmpl -> exec ( $do_email ? 'addressbook.addressbook_ui.emailpopup' : 'addressbook.addressbook_ui.index' ,
$content , $sel_options , $readonlys , $preserv , $do_email ? 2 : 0 );
}
/**
* Get actions / context menu items
*
2011-04-17 23:25:01 +02:00
* @ param boolean $do_email = false
* @ param string $tid_filter = null
2011-04-25 13:30:37 +02:00
* @ param string $org_view = null
2011-04-17 23:25:01 +02:00
* @ return array see nextmatch_widget :: get_actions ()
2011-04-17 16:10:05 +02:00
*/
2011-04-25 13:30:37 +02:00
private function get_actions ( $do_email = false , $tid_filter = null , $org_view = null )
2011-04-17 16:10:05 +02:00
{
2011-04-25 13:30:37 +02:00
// we have no org view (view of one org has context menu like regular "add contacts" view, as it shows contacts
if ( ! isset ( $this -> org_views [( string ) $org_view ]))
{
$actions = array (
'view' => array (
'caption' => 'View' ,
'default' => true ,
'allowOnMultiple' => false ,
'url' => 'menuaction=addressbook.addressbook_ui.view&contact_id=$id' ,
'popup' => egw_link :: get_registry ( 'addressbook' , 'view_popup' ),
'group' => $group = 1 ,
),
'edit' => array (
'caption' => 'Edit' ,
'allowOnMultiple' => false ,
'url' => 'menuaction=addressbook.addressbook_ui.edit&contact_id=$id' ,
'popup' => egw_link :: get_registry ( 'addressbook' , 'add_popup' ),
'group' => $group ,
'enabled' => 'javaScript:nm_not_disableClass' ,
'disableClass' => 'rowNoEdit' ,
),
'add' => array (
'caption' => 'Add' ,
'group' => $group ,
'children' => array (
'new' => array (
'caption' => 'New' ,
'url' => 'menuaction=addressbook.addressbook_ui.edit' ,
'popup' => egw_link :: get_registry ( 'addressbook' , 'add_popup' ),
),
'copy' => array (
'caption' => 'Copy' ,
'url' => 'menuaction=addressbook.addressbook_ui.edit&makecp=1&contact_id=$id' ,
'popup' => egw_link :: get_registry ( 'addressbook' , 'add_popup' ),
'allowOnMultiple' => false ,
),
),
),
);
}
else // org view
{
$actions = array (
'view' => array (
'caption' => 'View' ,
'default' => true ,
'allowOnMultiple' => false ,
'group' => $group = 1 ,
),
'add' => array (
'caption' => 'Add' ,
'group' => $group ,
'allowOnMultiple' => false ,
'url' => 'menuaction=addressbook.addressbook_ui.edit&org=$id' ,
'popup' => egw_link :: get_registry ( 'addressbook' , 'add_popup' ),
),
);
}
$actions [ 'select_all' ] = array (
'caption' => 'Whole query' ,
'checkbox' => true ,
'hint' => 'Apply the action on the whole query, NOT only the shown contacts!!!' ,
'group' => ++ $group ,
2011-04-17 16:10:05 +02:00
);
2011-04-17 23:25:01 +02:00
2011-04-17 16:10:05 +02:00
if ( $do_email )
{
$actions += array (
'email' => array (
'caption' => lang ( 'Add %1' , lang ( 'business email' )),
'no_lang' => true ,
'group' => ++ $group ,
),
'email_home' => array (
'caption' => lang ( 'Add %1' , lang ( 'home email' )),
'no_lang' => true ,
'group' => $group ,
),
);
}
++ $group ; // other AB related stuff group: lists, AB's, categories
// categories submenu
$actions [ 'cat' ] = array (
'caption' => 'Categories' ,
'group' => $group ,
'children' => array (
'cat_add' => nextmatch_widget :: category_action (
'addressbook' , $group , 'Add category' , 'cat_add_'
2011-04-25 16:13:40 +02:00
) + array (
'icon' => 'foldertree_nolines_plus' ,
'enabled' => 'javaScript:nm_not_disableClass' ,
'disableClass' => 'rowNoEdit' ,
),
2011-04-17 16:10:05 +02:00
'cat_del' => nextmatch_widget :: category_action (
'addressbook' , $group , 'Delete category' , 'cat_del_'
2011-04-25 16:13:40 +02:00
) + array (
'icon' => 'foldertree_nolines_minus' ,
'enabled' => 'javaScript:nm_not_disableClass' ,
'disableClass' => 'rowNoEdit' ,
),
2011-04-17 16:10:05 +02:00
'cat_edit' => array (
'caption' => 'Edit categories' ,
'url' => 'menuaction=preferences.uicategories.index&cats_app=addressbook&cats_level=True&global_cats=True' ,
'icon' => 'edit' ,
'group' => $group ,
),
),
);
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' ,
2011-04-25 16:13:40 +02:00
'onExecute' => 'javaScript:add_new_list' ,
2011-04-17 16:10:05 +02:00
),
),
'group' => $group ,
);
if (( $add_lists = $this -> get_lists ( EGW_ACL_EDIT ))) // do we have distribution lists?
{
$actions [ 'lists' ][ 'children' ] += array (
'to_list' => array (
'caption' => 'Add to distribution list' ,
'children' => $add_lists ,
'prefix' => 'to_list_' ,
'icon' => 'foldertree_nolines_plus' ,
2011-04-25 16:13:40 +02:00
'enabled' => 'javaScript:nm_not_disableClass' ,
'disableClass' => 'rowNoEdit' ,
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' ,
2011-04-25 16:13:40 +02:00
'enabled' => 'javaScript:nm_compare_field' ,
'fieldId' => 'exec[nm][filter2]' ,
'fieldValue' => '!' , // enable if list != ''
2011-04-17 16:10:05 +02:00
),
'delete_list' => array (
'caption' => 'Delete selected distribution list!' ,
'confirm' => 'Delete selected distribution list!' ,
'icon' => 'delete' ,
2011-04-25 16:13:40 +02:00
'enabled' => 'javaScript:nm_compare_field' ,
'fieldId' => 'exec[nm][filter2]' ,
'fieldValue' => '!' , // enable if list != ''
2011-04-17 16:10:05 +02:00
),
);
}
// move to AB
if (( $move2addressbooks = $this -> get_addressbooks ( EGW_ACL_ADD ))) // do we have addressbooks, we should
{
2011-04-25 13:30:37 +02:00
foreach ( $move2addressbooks as $owner => $label )
{
$this -> type_icon (( int ) $owner , substr ( $owner , - 1 ) == 'p' , 'n' , $icon , $type_label );
$move2addressbooks [ $owner ] = array (
'icon' => $icon ,
'caption' => $label ,
);
}
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
'enabled' => 'javaScript:nm_not_disableClass' ,
'disableClass' => 'rowNoDelete' ,
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 ,
);
++ $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' ,
),
'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' ,
'popup' => egw_link :: get_registry ( 'infolog' , 'add_popup' ),
'onExecute' => 'javaScript:add_task' , // call server for org-view only
2011-04-17 16:10:05 +02:00
),
)
);
}
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'calendar' ])
{
$actions [ 'calendar' ] = array (
'icon' => 'calendar/navbar' ,
'caption' => 'Add appointment' ,
'url' => 'menuaction=calendar.calendar_uiforms.edit&participants=c$id' ,
'popup' => egw_link :: get_registry ( 'calendar' , 'add_popup' ),
'group' => $group ,
2011-04-26 18:22:10 +02:00
'onExecute' => 'javaScript:add_cal' , // call server for org-view only
2011-04-17 16:10:05 +02:00
);
}
if ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'filemanager' ])
{
$actions [ 'filemanager' ] = array (
'icon' => 'filemanager/navbar' ,
'caption' => 'Filemanager' ,
'url' => 'menuaction=filemanager.filemanager_ui.index&path=/apps/addressbook/$id' ,
'group' => $group ,
);
}
// check if user is an admin or the export is not generally turned off (contact_export_limit is non-numerical, eg. no)
if ( isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ]) || ! $this -> config [ 'contact_export_limit' ] || ( int ) $this -> config [ 'contact_export_limit' ])
{
$actions [ 'export' ] = array (
'caption' => 'Export' ,
'icon' => 'filesave' ,
'group' => ++ $group ,
'children' => array (
'csv' => 'Export as CSV' ,
'vcard' => 'Export as VCard' ,
),
);
}
2011-04-25 13:30:37 +02:00
$actions [ 'documents' ] = addressbook_merge :: document_action (
$this -> prefs [ 'document_dir' ], $group , 'Insert in document' , 'document_' ,
$this -> prefs [ 'default_document' ]
);
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
'enabled' => 'javaScript:nm_not_disableClass' ,
'disableClass' => 'rowNoDelete' ,
2011-04-17 16:10:05 +02:00
);
}
if ( $tid_filter == 'D' )
{
$actions [ 'undelete' ] = array (
'caption' => 'Un-delete' ,
'group' => $group ,
2011-04-25 16:13:40 +02:00
'enabled' => 'javaScript:nm_not_disableClass' ,
'disableClass' => 'rowNoEdit' ,
2011-04-17 16:10:05 +02:00
);
}
2011-04-25 13:30:37 +02:00
//echo "<p>".__METHOD__."($do_email, $tid_filter, $org_view)</p>\n"; _debug_array($actions);
2011-04-17 16:10:05 +02:00
return $actions ;
}
2006-06-16 06:44:58 +02:00
/**
* Email address - selection popup
*
* @ param array $content = null submitted content
2008-04-18 08:10:31 +02:00
* @ 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
{
2007-05-25 20:20:57 +02:00
if ( $_GET [ 'compat' ]) // 1.2 felamimail or old email
{
$handler = " if (opener.document.doit[to].value != '')
2006-06-16 06:44:58 +02:00
{
opener . document . doit [ to ] . value += ',' ;
}
opener . document . doit [ to ] . value += email " ;
2007-05-25 20:20:57 +02:00
}
else // 1.3+ felamimail
{
$handler = 'opener.addEmail(to,email)' ;
}
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'java_script' ] .= "
2006-06-16 06:44:58 +02:00
< script >
window . focus ();
2008-04-18 08:10:31 +02:00
2006-06-16 06:44:58 +02:00
function addEmail ( email )
{
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 ;
2007-05-25 20:20:57 +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
2006-10-23 13:48:56 +02:00
/**
* Show the infologs of an whole organisation
*
* @ param string $org
*/
function infolog_org_view ( $org )
{
2009-11-28 12:56:53 +01:00
$query = egw_session :: appsession ( 'index' , 'addressbook' );
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' ] = '' ;
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
}
2009-11-28 12:56:53 +01: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 ,
));
}
2008-04-18 08:10:31 +02:00
2007-11-06 16:45:40 +01:00
function ajax_add_whole_list ( $list , $email_type = 'email' )
2007-05-25 20:20:57 +02:00
{
2009-11-28 12:56:53 +01:00
$query = egw_session :: appsession ( 'email' , 'addressbook' );
2007-05-25 20:20:57 +02:00
$query [ 'filter2' ] = ( int ) $list ;
2007-11-06 16:45:40 +01:00
$this -> action ( $email_type , array (), true , $success , $failed , $action_msg , $query , $msg );
2007-05-25 20:20:57 +02:00
2009-06-08 18:21:14 +02:00
$response = new xajaxResponse ();
2007-05-25 20:20:57 +02:00
2010-06-15 18:08:10 +02:00
if ( $success ) $response -> addScript ( egw_framework :: set_onload ( '' ));
2007-05-25 20:20:57 +02:00
// close window only if no errors AND something added
if ( $failed || ! $success )
{
if ( ! $msg ) $msg = $failed ? lang ( '%1 contact(s) %2, %3 failed because of insufficent rights !!!' , $success , $action_msg , $failed ) :
lang ( '%1 contact(s) %2' , $success , $action_msg );
$response -> addScript ( " alert(' " . addslashes ( $msg ) . " ') " );
// reset the filter
$response -> addScript ( " document.getElementById('exec[nm][filter2]').value=''; " );
}
else
{
2007-11-06 16:45:40 +01:00
if ( ! $msg ) $msg = lang ( '%1 contact(s) %2' , $success , $action_msg );
$response -> addScript ( " alert(' " . addslashes ( $msg ) . " ') " );
2007-05-25 20:20:57 +02:00
$response -> addScript ( 'window.close();' );
}
return $response -> getXML ();
}
2008-04-18 08:10:31 +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
*/
2007-03-13 14:38:15 +01:00
function action ( $action , $checked , $use_all , & $success , & $failed , & $action_msg , $session_name , & $msg )
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
2009-11-28 12:56:53 +01:00
$query = is_array ( $session_name ) ? $session_name : egw_session :: appsession ( $session_name , 'addressbook' );
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
$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 ]);
2009-11-28 12:56:53 +01:00
$query = egw_session :: appsession ( $session_name , 'addressbook' );
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' ]);
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
2008-10-16 13:17:49 +02:00
if ( in_array ( $action , array ( 'csv' , 'vcard' )) && $this -> config [ 'contact_export_limit' ] &&
! isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ]) &&
( ! 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 )
{
case 'csv' :
$action_msg = lang ( 'exported' );
2008-05-21 09:44:41 +02:00
$csv_export = new addressbook_csv ( $this , $this -> prefs [ 'csv_charset' ]);
2008-06-05 14:04:00 +02:00
$csv_export -> export ( $checked , $csv_export -> csv_fields ( $this -> prefs [ 'csv_fields' ]));
2006-04-26 23:23:38 +02:00
// does not return!
$Ok = true ;
break ;
2006-07-09 01:02:30 +02:00
case 'vcard' :
$action_msg = lang ( 'exported' );
2008-05-19 13:51:21 +02:00
ExecMethod ( 'addressbook.addressbook_vcal.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-10-23 13:48:56 +02:00
case 'infolog' :
2009-11-28 12:56:53 +01: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' => count ( $checked ) > 1 ? lang ( 'selected contacts' ) : '' ,
));
break ;
2008-04-18 08:10:31 +02:00
2006-12-19 12:25:44 +01:00
case 'merge' :
$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' ]);
2009-11-28 12:56:53 +01:00
egw_session :: appsession ( $session_name , 'addressbook' , $query );
2007-03-13 14:38:15 +01:00
}
2007-06-17 15:55:43 +02:00
return false ;
2008-04-18 08:10:31 +02:00
2007-06-17 15:55:43 +02:00
case 'document' :
$msg = $this -> download_document ( $checked , $document );
return false ;
2008-04-26 10:47:26 +02:00
2008-04-23 10:22:22 +02:00
case 'infolog_add' :
2011-04-26 18:22:10 +02:00
list ( $width , $height ) = explode ( 'x' , egw_link :: get_registry ( 'infolog' , 'add_popup' ));
2011-04-25 13:30:37 +02:00
egw_framework :: set_onload (
2011-04-26 18:22:10 +02:00
" egw_openWindowCentered2(' " . egw :: link ( '/index.php' , array (
'menuaction' => 'infolog.infolog_ui.edit' ,
'type' => 'task' ,
'action' => 'addressbook' ,
'action_id' => implode ( ',' , $checked ),
)) . " ','_blank', $width , $height ); " );
$msg = '' ; // no message, as we send none in javascript too and users sees opening popup
return false ;
case 'calendar' : // add appointment for org-views, other views are handled directly in javascript
list ( $width , $height ) = explode ( 'x' , egw_link :: get_registry ( 'calendar' , 'add_popup' ));
egw_framework :: set_onload (
" egw_openWindowCentered2(' " . egw :: link ( '/index.php' , array (
'menuaction' => 'calendar.calendar_uiforms.edit' ,
'participants' => 'c' . implode ( ',c' , $checked ),
)) . " ','_blank', $width , $height ); " );
$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 ;
2011-04-25 16:13:40 +02:00
}
foreach ( $checked as $id )
{
switch ( $action )
{
case 'cat_add' :
case 'cat_del' :
2008-03-10 17:33:17 +01:00
if (( $Ok = !! ( $contact = $this -> read ( $id )) && $this -> check_perms ( EGW_ACL_EDIT , $contact )))
{
2011-04-25 16:13:40 +02:00
$action_msg = $action == 'cat_add' ? lang ( 'categorie added' ) : lang ( 'categorie delete' );
$cat_ids = $contact [ 'cat_id' ] ? explode ( ',' , $contact [ 'cat_id' ]) : array (); //existing categories
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
}
2011-04-25 16:13:40 +02:00
$cat_ids = $cat_ids ? implode ( ',' , $cat_ids ) : null ;
if ( $cat_ids !== $contact [ 'cat_id' ])
2008-03-10 17:33:17 +01:00
{
2011-04-25 16:13:40 +02:00
$contact [ 'cat_id' ] = $cat_ids ;
$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' );
2006-10-22 13:40:43 +02:00
if (( $Ok = !! ( $contact = $this -> read ( $id )) && $this -> check_perms ( EGW_ACL_DELETE , $contact )))
2006-04-23 16:40:31 +02:00
{
if ( $contact [ 'owner' ]) // regular contact
{
$Ok = $this -> delete ( $id );
}
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
{
2009-11-28 12:56:53 +01:00
egw :: redirect_link ( '/index.php' , array (
2006-04-23 16:40:31 +02:00
'menuaction' => 'admin.uiaccounts.delete_user' ,
'account_id' => $contact [ 'account_id' ],
));
// this does NOT return!
}
else // no mass delete of accounts
{
$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' );
if ( $contact = $this -> read ( $id ))
{
$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' :
2007-11-06 16:45:40 +01:00
$action == 'email' ? $action_fallback = 'email_home' : $action_fallback = 'email' ;
$action_msg = lang ( 'added' );
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' ]);
2010-06-15 18:08:10 +02:00
egw_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 ;
}
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
2007-05-03 15:04:29 +02:00
if ( ! ( int ) $action || ! ( $this -> grants [( string ) ( int ) $action ] & EGW_ACL_EDIT )) // might be ADD in the future
2006-04-23 16:40:31 +02:00
{
return false ;
}
$action_msg = lang ( 'moved' );
2006-10-22 13:40:43 +02:00
if (( $Ok = !! ( $contact = $this -> read ( $id )) && $this -> check_perms ( EGW_ACL_DELETE , $contact )))
2006-04-23 16:40:31 +02:00
{
if ( ! $contact [ 'owner' ]) // no mass-change of accounts
{
$Ok = false ;
}
2007-06-25 18:36:58 +02:00
elseif ( $contact [ 'owner' ] != ( int ) $action || $contact [ 'private' ] != ( int )( substr ( $action , - 1 ) == 'p' ))
2006-04-23 16:40:31 +02:00
{
$contact [ 'owner' ] = ( int ) $action ;
2007-06-25 18:36:58 +02:00
$contact [ 'private' ] = ( int )( substr ( $action , - 1 ) == 'p' );
2006-04-23 16:40:31 +02:00
$Ok = $this -> save ( $contact );
}
}
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 ;
}
/**
* 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
* @ param array & $readonlys eg . to disable buttons based on acl
2006-10-23 13:48:56 +02:00
* @ 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
{
2009-11-28 12:56:53 +01:00
$old_state = egw_session :: appsession ( $what , 'addressbook' , $query );
2009-07-18 17:17:41 +02:00
}
else
{
2009-11-28 12:56:53 +01:00
$old_state = egw_session :: appsession ( $what , 'addressbook' );
2009-07-18 17:17:41 +02:00
}
2008-03-10 13:15:47 +01:00
if ( ! isset ( $this -> org_views [( string ) $query [ 'org_view' ]])) // we dont have an org view, unset the according col_filters
{
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
}
elseif ( ! $query [ 'search' ] && $old_state [ 'advanced_search' ]) // eg. paging in an advanced search
{
$query [ 'advanced_search' ] = $old_state [ 'advanced_search' ];
}
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
2010-06-15 18:08:10 +02:00
egw_framework :: set_onload ( preg_replace ( '/addEmail\([^)]+\);/' , '' , egw_framework :: set_onload ()), true );
2006-10-22 13:40:43 +02:00
}
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
));
2008-10-20 21:35:18 +02:00
if ( $state != $this -> prefs [ $what . '_state' ])
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 ;
}
}
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 ;
}
2007-05-01 11:17:23 +02:00
// enable/disable distribution lists depending on backend
$query [ 'no_filter2' ] = ! $this -> lists_available ( $query [ 'filter' ]);
2008-04-18 08:10:31 +02:00
2006-04-30 11:34:24 +02:00
if ( isset ( $this -> org_views [( string ) $query [ 'org_view' ]])) // we have an org view
2006-04-23 16:40:31 +02:00
{
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' ;
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' ;
}
2006-04-30 11:34:24 +02:00
if ( $query [ 'org_view' ]) // view the contacts of one organisation only
{
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 );
$query [ 'col_filter' ][ $name ] = $value ;
}
}
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' :
2007-06-03 10:42:59 +02:00
$order = " adr_one_postalcode<>'' DESC,adr_one_postalcode $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' :
$order = " $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-03-29 11:43:37 +02:00
$query [ 'col_filter' ][] = ( $query [ 'order' ] == 'adr_one_postalcode' ? 'org_name' : ( substr ( $query [ 'order' ], 0 , 1 ) == '#' ? '' : 'egw_addressbook.' ) . $query [ 'order' ]) . ' ' .
2006-12-17 09:44:05 +01:00
$GLOBALS [ 'egw' ] -> db -> capabilities [ 'case_insensitive_like' ] . ' ' . $GLOBALS [ 'egw' ] -> db -> quote ( $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
{
2006-10-31 08:56:34 +01:00
$op = $query [ 'advanced_search' ][ 'operator' ];
unset ( $query [ 'advanced_search' ][ 'operator' ]);
$wildcard = $query [ 'advanced_search' ][ 'meth_select' ];
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
2007-05-26 09:58:37 +02:00
$columselection = $this -> prefs [ 'nextmatch-addressbook.' . ( $do_email ? 'email' : 'index' ) . '.rows' ];
2008-11-02 08:10:40 +01:00
$available_distib_lists = $this -> get_lists ( EGW_ACL_READ );
2009-10-30 12:18:47 +01:00
$columselection = $columselection && ! $query [ 'csv_export' ] ? explode ( ',' , $columselection ) : 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' ];
}
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 );
}
2010-04-16 12:28:29 +02:00
if ( $show_calendar && ! empty ( $ids )) $calendar = $this -> read_calendar ( $ids );
2008-04-18 08:10:31 +02:00
// distributionlist memership for the entrys
2008-01-31 13:52:43 +01:00
//_debug_array($this->get_lists(EGW_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 ();
2009-09-22 17:17:38 +02:00
$photos = $homeaddress = $roles = $notes = false ;
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
2011-04-17 23:25:01 +02:00
if ( $query [ 'filter' ] && ! ( $this -> grants [( int ) $query [ 'filter' ]] & EGW_ACL_DELETE ))
{
$readonlys [ " delete[ $row[id] ] " ] = true ;
$row [ 'class' ] .= 'rowNoDelete' ;
}
2006-10-23 13:48:56 +02:00
$readonlys [ " infolog[ $row[id] ] " ] = ! $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'infolog' ];
2011-04-17 23:25:01 +02:00
$row [ 'class' ] .= 'rowNoEdit' ; // no edit in OrgView
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' );
2006-04-30 11:34:24 +02:00
foreach ( $tel2show as $name )
{
$row [ $name ] .= ' ' . ( $row [ 'tel_prefer' ] == $name ? '♥' : '' ); // .' ' to NOT remove the field
}
// allways show the prefered phone, if not already shown
if ( ! in_array ( $row [ 'tel_prefer' ], $tel2show ) && $row [ $row [ 'tel_prefer' ]])
{
$row [ 'tel_prefered' ] = $row [ $row [ 'tel_prefer' ]] . ' ♥' ;
}
2011-04-17 23:25:01 +02:00
if ( ! $this -> check_perms ( EGW_ACL_DELETE , $row ) || ( ! $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ] && $this -> config [ 'history' ] != 'userpurge' && $query [ 'col_filter' ][ 'tid' ] == addressbook_so :: DELETED_TYPE ))
{
$readonlys [ " delete[ $row[id] ] " ] = true ;
$row [ 'class' ] .= 'rowNoDelete' ;
}
if ( ! $this -> check_perms ( EGW_ACL_EDIT , $row ))
{
$readonlys [ " edit[ $row[id] ] " ] = true ;
$row [ 'class' ] .= 'rowNoEdit' ;
}
2008-04-18 08:10:31 +02:00
2006-04-30 11:34:24 +02:00
if ( $row [ 'photo' ]) $photos = true ;
2008-05-07 16:13:34 +02:00
if ( $row [ 'role' ]) $roles = true ;
2009-09-22 17:17:38 +02:00
if ( $row [ 'note' ]) $notes = true ;
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;
}
2007-09-14 12:03:18 +02:00
if ( isset ( $calendar [ $row [ 'id' ]]))
{
foreach ( $calendar [ $row [ 'id' ]] as $name => $data )
{
$row [ $name ] = $data ;
}
}
2006-04-30 11:34:24 +02:00
if ( $this -> prefs [ 'home_column' ] != 'never' && ! $homeaddress )
2006-04-23 16:40:31 +02:00
{
2006-04-30 11:34:24 +02:00
foreach ( array ( 'adr_two_countryname' , 'adr_two_locality' , 'adr_two_postalcode' , 'adr_two_street' , 'adr_two_street2' ) as $name )
{
if ( $row [ $name ]) $homeaddress = true ;
}
2006-04-23 16:40:31 +02:00
}
2006-06-17 20:50:07 +02:00
}
2007-06-17 15:55:43 +02:00
$readonlys [ " document[ $row[id] ] " ] = ! $this -> prefs [ 'default_document' ];
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' ]))
{
$row [ 'cat_id' ] = $this -> categories -> check_list ( EGW_ACL_READ , $row [ 'cat_id' ]);
}
2006-04-23 16:40:31 +02:00
}
2009-05-30 09:39:58 +02:00
$readonlys [ 'no_distrib_lists' ] = ( bool ) $show_distributionlist ;
2007-03-07 13:31:48 +01:00
if ( ! $this -> prefs [ 'no_auto_hide' ])
{
// disable photo column, if view contains no photo(s)
if ( ! $photos ) $rows [ 'no_photo' ] = true ;
// disable homeaddress column, if we have no homeaddress(es)
if ( ! $homeaddress ) $rows [ 'no_home' ] = true ;
2008-05-07 16:13:34 +02:00
// disable roles column
if ( ! $roles ) $rows [ 'no_role' ] = true ;
2009-09-22 17:17:38 +02:00
// disable note column
if ( ! $notes ) $rows [ 'no_note' ] = true ;
2007-03-07 13:31:48 +01:00
}
2006-04-23 16:40:31 +02:00
// disable customfields column, if we have no customefield(s)
2008-01-19 06:41:04 +01:00
if ( ! $this -> customfields /* || !$this->prefs['no_auto_hide'] && !$customfields*/ ) $rows [ 'no_customfields' ] = true ;
2006-04-23 16:40:31 +02:00
2009-05-30 09:39:58 +02:00
// disable filemanger icon if user has no access to filemanager
$readonlys [ 'filemanager/navbar' ] = ! isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'filemanager' ]);
2011-02-15 12:38:20 +01:00
$readonlys [ 'calendar' ] = ! isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'calendar' ]);
2009-05-30 09:39:58 +02: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
2006-04-23 16:40:31 +02:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( 'addressbook' );
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
{
2006-04-30 11:34:24 +02:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_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' ])) :
2009-11-28 12:43:10 +01:00
common :: grab_owner_name (( 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' ])
{
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] .= ': ' . $query [ 'org_view_label' ];
}
2008-04-18 08:10:31 +02:00
if ( $query [ 'advanced_search' ])
2006-10-31 08:56:34 +01:00
{
2009-05-30 09:39:58 +02:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] .= ': ' . lang ( 'Advanced search' );
2006-10-31 08:56:34 +01:00
}
2006-04-23 16:40:31 +02:00
if ( $query [ 'cat_id' ])
{
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] .= ': ' . lang ( 'Category' ) . ' ' . $GLOBALS [ 'egw' ] -> categories -> id2name ( $query [ 'cat_id' ]);
}
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' ));
2006-04-23 16:40:31 +02:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] .= ' - ' . lang ( " %1 starts with '%2' " , $order , $query [ 'searchletter' ]);
}
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
{
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] .= ' - ' . lang ( " Search for '%1' " , $query [ 'search' ]);
}
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
*
* @ param int $owner user - or group - id or 0 for 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' ;
2009-11-28 12:43:10 +01:00
$label = $owner == $this -> user ? lang ( 'personal' ) : common :: grab_owner_name ( $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
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' ];
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' :
2006-08-29 06:18:32 +02:00
if ( $content [ 'delete_photo' ]) $content [ 'jpegphoto' ] = null ;
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 ;
}
}
2006-04-30 11:34:24 +02:00
if ( $this -> save ( $content ))
{
$content [ 'msg' ] = lang ( 'Contact saved' );
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="' .
2009-11-28 12:56:53 +01: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
{
2008-03-08 23:45:01 +01:00
egw_link :: link ( 'addressbook' , $content [ 'id' ], $links );
2005-11-13 19:22:43 +01:00
}
if ( $button == 'save' )
{
2006-04-23 16:40:31 +02:00
echo " <html><body><script>var referer = opener.location;opener.location.href = referer+(referer.search?'&':'?')+'msg= " .
2006-04-30 11:34:24 +02:00
addslashes ( urlencode ( $content [ 'msg' ])) . " '; window.close();</script></body></html> \n " ;
2009-11-28 12:56:53 +01:00
common :: egw_exit ();
2005-11-13 19:22:43 +01:00
}
2005-11-23 18:07:33 +01:00
$content [ 'link_to' ][ 'to_id' ] = $content [ 'id' ];
2006-06-16 06:44:58 +02:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'java_script' ] .= " <script language= \" JavaScript \" >
2005-11-13 18:51:41 +01:00
var referer = opener . location ;
2006-04-30 11:34:24 +02:00
opener . location . href = referer + ( referer . search ? '&' : '?' ) + 'msg=".addslashes(urlencode($content[' msg ']))."' ; </ script > " ;
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' :
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
{
2006-04-23 16:40:31 +02:00
echo " <html><body><script>var referer = opener.location; opener.location.href = referer+(referer.search?'&':'?')+'msg= " .
2006-04-30 11:34:24 +02:00
addslashes ( urlencode ( lang ( 'Contact deleted' ))) . " ';window.close();</script></body></html> \n " ;
2009-11-28 12:43:10 +01:00
common :: egw_exit ();
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
}
2006-03-14 15:26:55 +01:00
// type change
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 );
2005-12-01 18:21:38 +01:00
$view = $_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"
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
{
2009-11-28 12:56:53 +01:00
$state = egw_session :: appsession ( 'index' , 'addressbook' );
2006-04-30 11:34:24 +02:00
// check if we create the new contact in an existing org
if ( $_GET [ 'org' ])
{
$content = $this -> read_org ( $_GET [ 'org' ]);
}
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' ]);
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
{
$content [ 'owner' ] = $state [ 'filter' ];
}
$content [ 'private' ] = ( int ) ( $content [ 'owner' ] && substr ( $content [ 'owner' ], - 1 ) == 'p' );
if ( ! ( $this -> grants [ $content [ 'owner' ] = ( string ) ( int ) $content [ 'owner' ]] & EGW_ACL_ADD ))
{
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
if ( ! ( $this -> grants [ $content [ 'owner' ] = ( string ) ( int ) $content [ 'owner' ]] & EGW_ACL_ADD ))
{
$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 );
$content [ 'tid' ] = $_GET [ 'typeid' ] ? $_GET [ 'typeid' ] : $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
{
if ( $_GET [ 'presets' ][ $field ]) $content [ $field ] = $_GET [ 'presets' ][ $field ];
}
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 );
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
{
$content [ 'link_to' ][ 'to_id' ] = 0 ;
2008-03-08 23:45:01 +01:00
egw_link :: link ( 'addressbook' , $content [ 'link_to' ][ 'to_id' ], 'addressbook' , $content [ 'id' ],
2009-11-28 12:43:10 +01:00
lang ( 'Copied by %1, from record #%2.' , common :: display_fullname ( '' ,
2005-11-23 18:07:33 +01:00
$GLOBALS [ 'egw_info' ][ 'user' ][ 'account_firstname' ], $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_lastname' ]),
$content [ 'id' ]));
2006-10-23 13:48:56 +02:00
// create a new contact with the content of the old
2010-08-25 18:47:25 +02:00
foreach ( $content as $key => $value )
2008-09-11 12:48:13 +02:00
{
2011-04-07 09:28:46 +02:00
if ( ! in_array ( $key , self :: $copy_fields ) || in_array ( $key , array ( 'etag' , 'carddav_name' , 'uid' )))
2010-08-25 18:47:25 +02:00
{
unset ( $content [ $key ]);
}
}
if ( ! isset ( $content [ 'owner' ]))
{
2010-09-02 13:26:49 +02:00
$content [ 'owner' ] = $this -> default_private ? $this -> user . 'p' : $this -> default_addressbook ;
2008-09-11 12:48:13 +02:00
}
2006-04-23 16:40:31 +02:00
$content [ 'creator' ] = $this -> user ;
$content [ 'created' ] = $this -> now_su ;
2006-10-23 13:48:56 +02:00
$content [ 'msg' ] = lang ( 'Contact copied' );
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
{
2008-03-08 23:45:01 +01:00
egw_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
list (, $dates ) = each ( $this -> read_calendar ( array ( $content [ 'id' ]), false ));
if ( is_array ( $dates )) $content += $dates ;
}
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' ]);
2010-09-28 01:02:32 +02:00
$GLOBALS [ 'egw' ] -> js -> set_onload ( 'show_custom_country(document.getElementById("exec[adr_one_countrycode]"));' );
$GLOBALS [ 'egw' ] -> js -> set_onload ( 'show_custom_country(document.getElementById("exec[adr_two_countrycode]"));' );
2008-04-18 08:10:31 +02:00
2006-07-07 01:01:29 +02:00
$content [ 'disable_change_org' ] = $view || ! $content [ 'org_name' ];
2005-11-04 00:47:52 +01:00
//_debug_array($content);
2006-10-23 13:48:56 +02:00
$readonlys [ 'button[delete]' ] = ! $content [ 'owner' ] || ! $this -> check_perms ( EGW_ACL_DELETE , $content );
2005-11-13 18:51:41 +01:00
$readonlys [ 'button[copy]' ] = $readonlys [ 'button[edit]' ] = $readonlys [ 'button[vcard]' ] = true ;
2005-11-11 21:50:12 +01:00
2006-04-23 16:40:31 +02:00
$sel_options [ 'fileas_type' ] = $this -> fileas_options ( $content );
$sel_options [ 'owner' ] = $this -> get_addressbooks ( EGW_ACL_ADD );
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' ) :
2009-11-28 12:43:10 +01:00
common :: grab_owner_name ( $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
2006-11-14 10:25:07 +01:00
$content [ 'id' ] && ! $this -> check_perms ( EGW_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 ;
}
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' ]);
$readonlys [ 'tabs' ][ 'custom' ] = ! $this -> customfields ;
$readonlys [ 'tabs' ][ 'custom_private' ] = ! $this -> customfields || ! $this -> config [ 'private_cf_tab' ];
$readonlys [ 'tabs' ][ 'distribution_list' ] = ! $content [ 'distrib_lists' ]; #false;
2010-11-13 10:10:11 +01:00
$readonlys [ 'tabs' ][ 'history' ] = $this -> contact_repository == 'ldap' || ! $content [ 'id' ] ||
$this -> account_repository == 'ldap' && $content [ 'account_id' ];
2008-04-04 10:14:30 +02:00
$readonlys [ 'button[delete]' ] = ! $content [ '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
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"
2006-09-15 09:16:07 +02:00
if ( ! $content [ 'owner' ] && ! $this -> is_admin ( $content ))
{
2007-06-03 14:24:49 +02:00
$this -> _set_readonlys_for_own_account_acl ( $readonlys , $id );
2006-09-15 09:16:07 +02:00
}
2005-11-04 00:47:52 +01:00
for ( $i = - 23 ; $i <= 23 ; $i ++ ) $tz [ $i ] = ( $i > 0 ? '+' : '' ) . $i ;
$sel_options [ 'tz' ] = $tz ;
$content [ 'tz' ] = $content [ 'tz' ] ? $content [ 'tz' ] : 0 ;
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' ];
}
2008-03-25 16:25:01 +01:00
$content [ 'typegfx' ] = 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
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
if ( $content [ 'tid' ] == addressbook_so :: DELETED_TYPE )
{
$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 );
2006-12-11 08:35:49 +01:00
$content [ 'photo' ] = $this -> photo_src ( $content [ 'id' ], $content [ 'jpegphoto' ], 'photo' );
2006-04-23 16:40:31 +02:00
if ( $content [ 'private' ]) $content [ 'owner' ] .= 'p' ;
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'include_xajax' ] = true ;
2008-04-18 08:10:31 +02:00
2008-10-20 21:35:18 +02:00
if ( ! $this -> tmpl -> read ( $this -> content_types [ $content [ 'tid' ]][ 'options' ][ 'template' ] ? $this -> content_types [ $content [ 'tid' ]][ 'options' ][ 'template' ] : 'addressbook.edit' ))
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' );
}
2008-05-10 14:02:49 +02:00
return $this -> tmpl -> exec ( 'addressbook.addressbook_ui.edit' , $content , $sel_options , $readonlys , $content , 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 )
{
foreach ( $this -> customfields as $name => $data )
{
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
2006-04-23 16:40:31 +02:00
function ajax_setFileasOptions ( $n_prefix , $n_given , $n_middle , $n_family , $n_suffix , $org_name )
{
$names = array (
'n_prefix' => $n_prefix ,
'n_given' => $n_given ,
'n_middle' => $n_middle ,
'n_family' => $n_family ,
'n_suffix' => $n_suffix ,
'org_name' => $org_name ,
);
2009-06-08 18:21:14 +02:00
$response = new xajaxResponse ();
2006-04-23 16:40:31 +02:00
$response -> addScript ( " setOptions(' " . addslashes ( implode ( " \ b " , $this -> fileas_options ( $names ))) . " '); " );
return $response -> getXML ();
}
2008-04-18 08:10:31 +02:00
2005-11-13 18:51:41 +01:00
function view ( $content = null )
2005-11-11 21:50:12 +01:00
{
if ( is_array ( $content ))
{
2005-11-13 18:51:41 +01:00
list ( $button ) = each ( $content [ 'button' ]);
switch ( $button )
2005-11-11 21:50:12 +01:00
{
2005-11-13 18:51:41 +01:00
case 'vcard' :
2009-11-28 12:56:53 +01:00
egw :: redirect_link ( '/index.php' , 'menuaction=addressbook.uivcard.out&ab_id=' . $content [ 'id' ]);
2005-11-13 18:51:41 +01:00
case 'cancel' :
2009-11-28 12:56:53 +01:00
egw :: redirect_link ( '/index.php' , 'menuaction=addressbook.addressbook_ui.index' );
2005-11-13 18:51:41 +01:00
case 'delete' :
2009-11-28 12:56:53 +01: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
));
2005-11-11 21:50:12 +01:00
}
}
else
{
2006-04-23 16:40:31 +02:00
if ( ! $_GET [ 'contact_id' ] || ! is_array ( $content = $this -> read ( $_GET [ 'contact_id' ])))
2006-03-28 13:41:48 +02:00
{
2009-11-28 12:56:53 +01: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 ,
));
}
2005-11-11 21:50:12 +01:00
}
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]' ] =
$readonlys [ 'button[ok]' ] = $readonlys [ 'button[more]' ] = false ;
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' ]))
{
2009-11-26 09:32:18 +01:00
$content [ 'cat_id' ] = $this -> categories -> check_list ( EGW_ACL_READ , $content [ 'cat_id' ]);
2009-11-20 09:49:39 +01:00
}
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
if ( $content [ 'tid' ] == addressbook_so :: DELETED_TYPE )
{
$content [ 'link_to' ][ 'show_deleted' ] = true ;
}
2006-10-23 13:48:56 +02:00
$readonlys [ 'button[delete]' ] = ! $content [ 'owner' ] || ! $this -> check_perms ( EGW_ACL_DELETE , $content );
2005-11-13 18:51:41 +01:00
$readonlys [ 'button[edit]' ] = ! $this -> check_perms ( EGW_ACL_EDIT , $content );
2007-06-03 15:21:13 +02:00
$content [ 'disable_change_org' ] = true ;
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 ();
2006-03-14 15:26:55 +01:00
for ( $i = - 23 ; $i <= 23 ; $i ++ ) $tz [ $i ] = ( $i > 0 ? '+' : '' ) . $i ;
$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' ];
}
2008-03-25 16:25:01 +01:00
$content [ 'typegfx' ] = 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 ;
}
2008-10-20 21:35:18 +02:00
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' );
2006-03-14 15:26:55 +01:00
}
2007-06-03 13:42:39 +02:00
if ( $this -> private_addressbook && $content [ 'private' ] && $content [ 'owner' ] == $this -> user )
{
$content [ 'owner' ] .= 'p' ;
}
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;
2010-11-13 10:10:11 +01:00
$readonlys [ 'tabs' ][ 'history' ] = $this -> contact_repository == 'ldap' || ! $content [ 'id' ] ||
$this -> account_repository == 'ldap' && $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
2010-04-16 12:28:29 +02:00
if ( ! empty ( $content [ 'id' ])) list (, $dates ) = each ( $this -> read_calendar ( array ( $content [ 'id' ]), false ));
2007-10-19 10:34:47 +02:00
if ( is_array ( $dates )) $content += $dates ;
2006-12-11 08:35:49 +01:00
// set id for automatic linking via quick add
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentid' ] = $content [ 'id' ];
2010-11-22 23:45:55 +01:00
// Load JS for infolog actions
egw_framework :: validate_file ( '.' , 'index' , 'infolog' );
2008-05-10 14:02:49 +02:00
$this -> tmpl -> exec ( 'addressbook.addressbook_ui.view' , $content , $sel_options , $readonlys , array ( 'id' => $content [ 'id' ]));
2007-06-03 15:21:13 +02:00
2005-11-11 21:50:12 +01:00
$GLOBALS [ 'egw' ] -> hooks -> process ( array (
'location' => 'addressbook_view' ,
'ab_id' => $content [ 'id' ]
));
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
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 ))
{
$do_email = $_content [ 'do_email' ];
2006-10-24 21:20:37 +02:00
$response = new xajaxResponse ();
2008-04-18 08:10:31 +02:00
2009-11-28 12:56:53 +01:00
$query = egw_session :: appsession ( $do_email ? 'email' : 'index' , 'addressbook' );
2008-04-18 08:10:31 +02:00
2010-10-12 16:01:36 +02:00
if ( $_content [ 'button' ][ 'cancel' ])
{
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 ]);
}
2007-07-12 15:02:19 +02:00
}
$query [ 'start' ] = 0 ;
$query [ 'search' ] = '' ;
// store the index state in the session
2009-11-28 12:56:53 +01:00
egw_session :: appsession ( $do_email ? 'email' : 'index' , 'addressbook' , $query );
2007-07-12 15:02:19 +02:00
// store the advanced search in the session to call it again
2009-11-28 12:56:53 +01:00
egw_session :: appsession ( 'advanced_search' , 'addressbook' , $query [ 'advanced_search' ]);
2008-04-18 08:10:31 +02:00
2006-10-24 21:20:37 +02:00
$response -> addScript ( "
2006-11-02 14:52:24 +01:00
var link = opener . location . href ;
link = link . replace ( / #/,'');
opener . location . href = link . replace ( / \ #/,'');
2006-10-27 15:10:51 +02:00
xajax_eT_wrapper ();
2006-10-24 21:20:37 +02:00
" );
2010-10-12 16:01:36 +02:00
if ( $_content [ 'button' ][ 'cancel' ]) $response -> addScript ( 'window.close();' );
2006-10-24 21:20:37 +02:00
return $response -> getXML ();
}
2010-10-12 16:01:36 +02:00
else
{
$do_email = strpos ( $_SERVER [ 'HTTP_REFERER' ], 'emailpopup' ) !== false ;
2006-10-24 21:20:37 +02:00
}
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'include_xajax' ] = true ;
2006-10-31 08:56:34 +01:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'java_script' ] .= " <script>window.focus()</script> " ;
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 ();
2009-11-28 12:56:53 +01:00
$content = egw_session :: appsession ( 'advanced_search' , 'addressbook' );
2010-10-12 16:01:36 +02:00
$content [ 'n_fn' ] = $this -> fullname ( $content );
2008-04-18 08:10:31 +02:00
2005-11-04 00:47:52 +01:00
for ( $i = - 23 ; $i <= 23 ; $i ++ ) $tz [ $i ] = ( $i > 0 ? '+' : '' ) . $i ;
$sel_options [ 'tz' ] = $tz + array ( '' => lang ( 'doesn\'t matter' ));
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
2006-04-24 22:52:14 +02:00
$sel_options [ 'owner' ] = $this -> get_addressbooks ( EGW_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 )
{
if ( $data [ 'type' ] == 'select' )
{
if ( ! isset ( $content [ '#' . $name ])) $content [ '#' . $name ] = '' ;
if ( ! isset ( $data [ 'values' ][ '' ])) $sel_options [ '#' . $name ][ '' ] = lang ( 'Select one' );
}
}
}
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 ;
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 ;
2006-10-31 08:56:34 +01:00
$content [ 'disable_change_org' ] = true ;
2006-10-24 21:20:37 +02:00
$this -> tmpl -> read ( 'addressbook.search' );
2010-10-12 16:01:36 +02:00
return $this -> tmpl -> exec ( 'addressbook.addressbook_ui.search' , $content , $sel_options , $readonlys , array (
'do_email' => $do_email ,
), 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' ])
{
2009-11-28 12:56:53 +01:00
egw :: redirect ( common :: image ( 'addressbook' , 'photo' ));
2006-04-23 16:40:31 +02:00
}
if ( ! ob_get_contents ())
{
header ( 'Content-type: image/jpeg' );
2006-06-13 06:30:16 +02:00
header ( 'Content-length: ' . ( extension_loaded ( mbstring ) ? mb_strlen ( $contact [ 'jpegphoto' ], 'ascii' ) : strlen ( $contact [ 'jpegphoto' ])));
2006-04-23 16:40:31 +02:00
echo $contact [ 'jpegphoto' ];
exit ;
}
}
2008-04-18 08:10:31 +02:00
2008-10-20 11:51:38 +02:00
/**
2011-04-26 18:22:10 +02:00
* Dynamic javascript functions
*
* All static stuff should go to addressbook / js / app . js
2008-10-20 11:51:38 +02:00
*
* @ return string
*/
2005-11-04 00:47:52 +01:00
function js ()
{
return ' < script LANGUAGE = " JavaScript " >
2006-10-21 22:14:31 +02:00
function adb_get_selection ( form )
{
var use_all = document . getElementById ( " exec[use_all] " );
var action = document . getElementById ( " exec[action] " );
egw_openWindowCentered (
2009-11-28 12:56:53 +01:00
" '. egw::link('/index.php','menuaction=importexport.uiexport.export_dialog&appname=addressbook').
2006-10-21 22:14:31 +02:00
' & selection = " +( use_all.checked ? " use_all " : get_selected(form, " [ rows ][ checked ][] " )),
2008-04-18 08:10:31 +02:00
" Export " , 400 , 400 );
2006-10-21 22:14:31 +02:00
action . value = " " ;
use_all . checked = false ;
2008-04-18 08:10:31 +02:00
return false ;
2006-10-21 22:14:31 +02:00
}
2008-04-18 08:10:31 +02:00
2011-04-17 16:10:05 +02:00
function add_new_list ()
2007-03-13 14:38:15 +01:00
{
2011-04-17 16:10:05 +02:00
var owner = document . getElementById ( " exec[nm][filter] " ) . value ;
2007-03-13 14:38:15 +01:00
var name = window . prompt ( " '.lang('Name for the distribution list').' " );
if ( name )
{
2009-11-28 12:56:53 +01:00
document . location . href = " '.egw::link('/index.php',array(
2008-05-10 14:02:49 +02:00
'menuaction' => $_GET [ 'menuaction' ], //'addressbook.addressbook_ui.index',
2007-03-13 14:38:15 +01:00
'add_list' => '' ,
)) . ' " +encodeURIComponent(name)+ " & owner = " +owner;
}
}
2008-10-20 11:51:38 +02:00
function do_action ( selbox )
{
if ( selbox . value != " " ) {
if ( selbox . value == " infolog_add " && ( ids = get_selected ( selbox . form , " [rows][checked][] " )) && ! document . getElementById ( " exec[use_all] " ) . checked ) {
win = window . open ( " '.egw::link('/index.php','menuaction=infolog.infolog_ui.edit&type=task&action=addressbook&action_id=').' " + ids , " _blank " , " width=750,height=550,left=100,top=200 " );
win . focus ();
2008-11-28 13:24:02 +01:00
} else if ( selbox . value == " cat_add " ) {
2008-10-20 11:51:38 +02:00
win = window . open ( " '.egw::link('/etemplate/process_exec.php','menuaction=addressbook.addressbook_ui.cat_add').' " , " _blank " , " width=300,height=400,left=100,top=200 " );
win . focus ();
2009-10-01 15:04:54 +02:00
} else if ( selbox . value == " remove_from_list " ) {
if ( confirm ( " '.lang('Remove selected contacts from distribution list').' " )) selbox . form . submit ();
} else if ( selbox . value == " delete_list " ) {
if ( confirm ( " '.lang('Delete selected distribution list!').' " )) selbox . form . submit ();
} else if ( selbox . value == " delete " ) {
if ( confirm ( " '.lang('Delete').' " )) selbox . form . submit ();
2008-10-20 11:51:38 +02:00
} else {
selbox . form . submit ();
}
selbox . value = " " ;
}
2010-09-28 01:02:32 +02:00
}
2011-04-26 18:22:10 +02:00
</ script > ' ;
2005-11-04 00:47:52 +01: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' );
2009-11-28 12:43:10 +01:00
common :: egw_header ();
2006-07-08 02:36:23 +02:00
parse_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 " ;
}
2009-11-28 12:43:10 +01:00
common :: egw_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 ()
{
translation :: add_app ( 'admin' );
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( 'Addressbook' ) . ' - ' . lang ( 'Contact maintenance' );
2009-11-28 12:43:10 +01:00
common :: egw_header ();
2009-05-09 09:58:16 +02:00
parse_navbar ();
// 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
{
$updated = parent :: set_all_fileas ( $_GET [ 'type' ],( boolean ) $_GET [ 'all' ], $errors , true ); // true = ignore acl
echo '<p style="margin-top: 20px;"><b>' . lang ( '%1 contacts updated (%2 errors).' , $updated , $errors ) . " </b></p> \n " ;
}
2009-11-28 12:43:10 +01:00
common :: egw_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 ()
{
translation :: add_app ( 'admin' );
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( 'Addressbook' ) . ' - ' . lang ( 'Contact maintenance' );
2009-11-28 12:43:10 +01:00
common :: egw_header ();
2009-11-11 09:44:51 +01:00
parse_navbar ();
// check if user has admin rights (Security)
if ( ! $this -> is_admin ())
{
echo '<h1>' . lang ( 'Permission denied !!!' ) . " </h1> \n " ;
}
else
{
$updated = parent :: set_all_cleanup ( $errors , true ); // true = ignore acl
echo '<p style="margin-top: 20px;"><b>' . lang ( '%1 contacts updated (%2 errors).' , $updated , $errors ) . " </b></p> \n " ;
}
2009-11-28 12:43:10 +01:00
common :: egw_footer ();
2009-11-11 09:44:51 +01:00
}
2009-05-09 09:58:16 +02:00
2007-06-17 15:55:43 +02:00
/**
* Download a document with inserted contact ( s )
*
* @ param array $ids contact - ids
* @ param string $document vfs - path of document
* @ return string error - message or error , otherwise the function does NOT return !
*/
function download_document ( $ids , $document = '' )
{
2008-04-15 12:28:45 +02:00
if ( ! $document )
{
$document = $this -> prefs [ 'default_document' ];
}
else
{
$document = $this -> prefs [ 'document_dir' ] . '/' . $document ;
}
if ( !@ egw_vfs :: stat ( $document ))
2007-06-17 15:55:43 +02:00
{
2007-06-19 12:19:47 +02:00
return lang ( " Document '%1' does not exist or is not readable for you! " , $document );
2007-06-17 15:55:43 +02:00
}
2009-06-08 18:21:14 +02:00
$document_merge = new addressbook_merge ();
2007-06-17 15:55:43 +02:00
return $document_merge -> download ( $document , $ids );
}
2008-04-18 08:10:31 +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
}