2010-03-22 16:11:12 +01:00
< ? php
/**
* eGroupWare - Wizard for Adressbook CSV import
*
* @ license http :// opensource . org / licenses / gpl - license . php GPL - GNU General Public License
* @ package addressbook
* @ link http :// www . egroupware . org
* @ author Cornelius Weiss < nelius @ cwtech . de >
* @ version $Id : $
*/
2016-04-29 12:41:53 +02:00
use EGroupware\Api ;
use EGroupware\Api\Acl ;
2010-03-22 16:11:12 +01:00
class addressbook_wizard_import_contacts_csv extends importexport_wizard_basic_import_csv
{
/**
* constructor
*/
function __construct ()
{
parent :: __construct ();
$this -> steps += array (
'wizard_step50' => lang ( 'Manage mapping' ),
'wizard_step60' => lang ( 'Choose owner of imported data' ),
);
// Field mapping
2016-04-29 12:41:53 +02:00
$bocontacts = new Api\Contacts ();
2010-03-22 16:11:12 +01:00
$this -> mapping_fields = $bocontacts -> contact_fields ;
2011-03-17 00:18:48 +01:00
2016-04-29 12:41:53 +02:00
$categories = new Api\Categories ( '' , 'addressbook' );
2011-03-17 00:18:48 +01:00
$cat_list = array ();
foreach (( array ) $categories -> return_sorted_array ( 0 , False , '' , '' , '' , true , 0 , true ) as $cat )
{
$s = str_repeat ( ' ' , $cat [ 'level' ]) . stripslashes ( $cat [ 'name' ]);
2016-04-29 12:41:53 +02:00
if ( Api\Categories :: is_global ( $cat ))
2011-03-17 00:18:48 +01:00
{
$s .= ' ♦' ;
}
2024-12-12 18:56:05 +01:00
$cat_list [] = array (
'value' => 'cat-' . $cat [ 'id' ],
2011-03-17 00:18:48 +01:00
'label' => $s ,
2024-12-12 18:56:05 +01:00
'title' => $cat [ 'description' ]
2011-03-17 00:18:48 +01:00
);
}
if ( count ( $cat_list ) > 0 ) {
2024-12-12 18:56:05 +01:00
$this -> mapping_fields [] = array (
'label' => lang ( 'Categories' ),
'children' => $cat_list
);
2011-03-17 00:18:48 +01:00
}
2010-03-22 16:11:12 +01:00
foreach ( $bocontacts -> customfields as $name => $data ) {
2024-12-12 18:56:05 +01:00
$this -> mapping_fields [] = [ 'value' => '#' . $name , 'label' => $data [ 'label' ]];
2010-03-22 16:11:12 +01:00
}
unset ( $this -> mapping_fields [ 'jpegphoto' ]); // can't cvs import that
2016-04-29 12:41:53 +02:00
2014-06-16 22:16:58 +02:00
// Add in special handled fields
2023-07-18 17:19:16 +02:00
$this -> mapping_fields += addressbook_import_contacts_csv :: $special_fields ;
2010-03-22 16:11:12 +01:00
// Actions
$this -> actions = array (
'none' => lang ( 'none' ),
'update' => lang ( 'update' ),
'insert' => lang ( 'insert' ),
'delete' => lang ( 'delete' ),
);
// Conditions
$this -> conditions = array (
'exists' => lang ( 'exists' ),
2014-06-16 18:22:18 +02:00
'equal' => '='
2010-03-22 16:11:12 +01:00
);
}
function wizard_step50 ( & $content , & $sel_options , & $readonlys , & $preserv )
{
2011-03-17 00:18:48 +01:00
if ( $content [ 'field_mapping' ][ 0 ] == lang ( 'Categories' )) {
unset ( $content [ 'field_mapping' ][ 0 ]);
}
2010-03-22 16:11:12 +01:00
$result = parent :: wizard_step50 ( $content , $sel_options , $readonlys , $preserv );
$content [ 'msg' ] .= " \n * " . lang ( 'Contact ID cannot be changed by import' );
2016-04-29 12:41:53 +02:00
2010-03-22 16:11:12 +01:00
return $result ;
}
2016-04-29 12:41:53 +02:00
2010-03-22 16:11:12 +01:00
function wizard_step60 ( & $content , & $sel_options , & $readonlys , & $preserv )
{
if ( $this -> debug ) error_log ( 'addressbook.importexport.addressbook_csv_import::wizard_step60->$content ' . print_r ( $content , true ));
2010-09-23 21:49:07 +02:00
unset ( $content [ 'no_owner_map' ]);
2010-03-22 16:11:12 +01:00
// return from step60
if ( $content [ 'step' ] == 'wizard_step60' )
{
switch ( array_search ( 'pressed' , $content [ 'button' ]))
{
case 'next' :
return $GLOBALS [ 'egw' ] -> importexport_definitions_ui -> get_step ( $content [ 'step' ], 1 );
case 'previous' :
return $GLOBALS [ 'egw' ] -> importexport_definitions_ui -> get_step ( $content [ 'step' ], - 1 );
case 'finish' :
return 'wizard_finish' ;
default :
return $this -> wizard_step60 ( $content , $sel_options , $readonlys , $preserv );
}
}
// init step60
else
{
$content [ 'msg' ] = $this -> steps [ 'wizard_step60' ];
$content [ 'step' ] = 'wizard_step60' ;
2021-11-15 14:41:18 +01:00
if ( ! array_key_exists ( 'contact_owner' , $content ) && $content [ 'plugin_options' ]) {
2010-03-22 16:11:12 +01:00
$content [ 'contact_owner' ] = $content [ 'plugin_options' ][ 'contact_owner' ];
}
2021-11-15 14:41:18 +01:00
if ( ! array_key_exists ( 'owner_from_csv' , $content ) && $content [ 'plugin_options' ]) {
2010-09-23 21:49:07 +02:00
$content [ 'owner_from_csv' ] = $content [ 'plugin_options' ][ 'owner_from_csv' ];
}
2021-11-15 14:41:18 +01:00
if ( ! array_key_exists ( 'change_owner' , $content ) && $content [ 'plugin_options' ]) {
2010-09-23 21:49:07 +02:00
$content [ 'change_owner' ] = $content [ 'plugin_options' ][ 'change_owner' ];
}
2010-03-22 16:11:12 +01:00
2016-04-29 12:41:53 +02:00
$bocontacts = new Api\Contacts ();
$sel_options [ 'contact_owner' ] = array ( 'personal' => lang ( " Importer's personal " )) + $bocontacts -> get_addressbooks ( Acl :: ADD );
2018-06-21 17:44:12 +02:00
if ( ! array_key_exists ( $content [ 'contact_owner' ], $sel_options [ 'contact_owner' ]))
2017-09-27 19:34:18 +02:00
{
$sel_options [ 'contact_owner' ][ $content [ 'contact_owner' ]] = lang ( " '%1' is not allowed ('%2')! " , $content [ 'contact_owner' ], implode ( ',' , array_keys ( $sel_options [ 'contact_owner' ])));
}
2010-09-23 21:49:07 +02:00
if ( ! in_array ( 'owner' , $content [ 'field_mapping' ])) {
$content [ 'no_owner_map' ] = true ;
}
2010-03-22 16:11:12 +01:00
$preserv = $content ;
unset ( $preserv [ 'button' ]);
return 'addressbook.importexport_wizard_chooseowner' ;
}
}
}