True,
'deleteProfile' => True,
'editProfile' => True,
'listProfiles' => True,
'saveProfile' => True
);
var $cats;
var $nextmatchs;
var $t;
var $boqmailldap;
function __construct()
{
$this->nextmatchs =& CreateObject('phpgwapi.nextmatchs');
$this->t =& CreateObject('phpgwapi.Template',EGW_APP_TPL);
#$this->boemailadmin =& CreateObject('emailadmin.bo');
$this->boemailadmin = new emailadmin_bo();
$this->css();
}
static function getAllGroups()
{
$allGroups = $GLOBALS['egw']->accounts->get_list('groups');
foreach($allGroups as $groupInfo)
{
$groups[$groupInfo['account_id']] = $groupInfo['account_lid'];
}
asort($groups);
$allGroups = array('' => lang('any group'));
foreach($groups as $groupID => $groupName)
{
$allGroups[$groupID] = $groupName;
}
return $allGroups;
}
static function getAllUsers()
{
$allUsers = $GLOBALS['egw']->accounts->get_list('accounts');
foreach($allUsers as $userInfo)
{
$users[$userInfo['account_id']] = $userInfo['account_lid'];
}
asort($users);
$allUsers = array('' => lang('any user'));
foreach($users as $userID => $userName)
{
$allUsers[$userID] = $userName;
}
return $allUsers;
}
static function getAllApps()
{
$applications = array(
'calendar' => $GLOBALS['egw_info']['apps']['calendar']['title'],
'felamimail' => $GLOBALS['egw_info']['apps']['felamimail']['title'],
);
asort($applications);
return $applications = array_merge(array('' => lang('any application')),$applications);
}
function addProfile()
{
if(is_int(intval($_GET['account_id'])) && !empty($_GET['account_id']))
{
if ( intval($_GET['account_id']) < 0 ) {
$groupID = intval($_GET['account_id']);
} else {
$accountID = intval($_GET['account_id']);
}
}
$allGroups = self:: getAllGroups();
$allUsers = self::getAllUsers();
$applications = self::getAllApps();
$this->display_app_header();
$this->t->set_file(array("body" => "editprofile.tpl"));
$this->t->set_block('body','main');
$this->translate();
#$this->t->set_var('profile_name',$profileList[0]['description']);
$this->t->set_var('smtpActiveTab','1');
$this->t->set_var('imapActiveTab','2'); // IMAP
$this->t->set_var('application_select_box', html::select('globalsettings[ea_appname]','',$applications, true, "style='width: 250px;'"));
$this->t->set_var('group_select_box', html::select('globalsettings[ea_group]',($groupID ? $groupID :''),$allGroups, true, "style='width: 250px;'"));
$this->t->set_var('user_select_box', html::select('globalsettings[ea_user]',($accountID ? $accountID :''),$allUsers, true, "style='width: 250px;'"));
$this->t->set_var('selected_ea_active','checked="1"');
$this->t->set_var('value_description',($accountID ? $allUsers[$accountID]: ($groupID ? $allGroups[$groupID]: '')));
if ($accountID)
{
// some useful presets, if you want to create a user dedicated profile
$this->t->set_var('selected_smtpAuth','checked="1"');
$this->t->set_var('value_ea_smtp_auth_username',$allUsers[$accountID]);
$this->t->set_var('selected_imapLoginType_admin','selected="selected"');
$this->t->set_var('value_imapAuthUsername',$allUsers[$accountID]);
}
$linkData = array
(
'menuaction' => 'emailadmin.emailadmin_ui.saveProfile'
);
$this->t->set_var('action_url',$GLOBALS['egw']->link('/index.php',$linkData));
$linkData = array
(
'menuaction' => 'emailadmin.emailadmin_ui.listProfiles'
);
$this->t->set_var('back_url',$GLOBALS['egw']->link('/index.php',$linkData));
$this->t->set_var('smtptype',html::select(
'smtpsettings[smtpType]',
$profileData['smtpType'],
$this->boemailadmin->getSMTPServerTypes(),
true,
'style="width: 250px;" id="smtpselector" onchange="smtp.display(this.value);"'
));
foreach($this->boemailadmin->getIMAPServerTypes() as $key => $value) {
$imapServerTypes[$key] = $value['description'];
};
$selectFrom = html::select(
'imapsettings[imapType]',
'',
$imapServerTypes,
false,
// stupid tabs javascript assumes value=position in selectbox, here's a littel workaround ;-)
"style='width: 250px;' id='imapselector' onchange='var v=this.value; imap.display(this.value); this.value=v; ea_setIMAPDefaults(this.value);'"
);
$this->t->set_var('imaptype', $selectFrom);
$this->t->set_var('value_smtpPort', '25');
$this->t->set_var('value_imapPort', '110');
$this->t->set_var('value_imapSievePort', '2000');
$this->t->parse("out","main");
print $this->t->get('out','main');
}
function css()
{
#$appCSS =
$GLOBALS['egw_info']['flags']['css'] .=
'th.activetab
{
color:#000000;
background-color:#D3DCE3;
border-top-width : 1px;
border-top-style : solid;
border-top-color : Black;
border-left-width : 1px;
border-left-style : solid;
border-left-color : Black;
border-right-width : 1px;
border-right-style : solid;
border-right-color : Black;
}
th.inactivetab
{
color:#000000;
background-color:#E8F0F0;
border-bottom-width : 1px;
border-bottom-style : solid;
border-bottom-color : Black;
}
.td_left { border-left : 1px solid Gray; border-top : 1px solid Gray; }
.td_right { border-right : 1px solid Gray; border-top : 1px solid Gray; }
div.activetab{ display:inline; }
div.inactivetab{ display:none; }';
#return $appCSS;
}
function deleteProfile()
{
$this->boemailadmin->deleteProfile($_GET['profileid']);
$this->listProfiles();
}
function display_app_header()
{
$GLOBALS['egw']->js->validate_file('tabs','tabs');
$GLOBALS['egw_info']['flags']['include_xajax'] = True;
switch($_GET['menuaction'])
{
case 'emailadmin.emailadmin_ui.addProfile':
case 'emailadmin.emailadmin_ui.editProfile':
$GLOBALS['egw_info']['nofooter'] = true;
$GLOBALS['egw']->js->validate_file('jscode','editProfile','emailadmin');
$GLOBALS['egw']->js->set_onload('javascript:initAll();');
#$GLOBALS['egw']->js->set_onload('smtp.init();');
break;
case 'emailadmin.emailadmin_ui.listProfiles':
$GLOBALS['egw']->js->validate_file('jscode','listProfile','emailadmin');
break;
}
$GLOBALS['egw']->common->egw_header();
if($_GET['menuaction'] == 'emailadmin.emailadmin_ui.listProfiles' || $_GET['menuaction'] == 'emailadmin.emailadmin_ui.deleteProfile')
echo parse_navbar();
}
function editProfile($_profileID='') {
$allGroups = self:: getAllGroups();
$allUsers = self::getAllUsers();
$applications = self::getAllApps();
if($_profileID != '')
{
$profileID = $_profileID;
}
elseif(is_int(intval($_GET['profileid'])) && !empty($_GET['profileid']))
{
$profileID = intval($_GET['profileid']);
}
else
{
return false;
}
$profileList = $this->boemailadmin->getProfileList($profileID);
$profileData = $this->boemailadmin->getProfile($profileID);
$this->display_app_header();
$this->t->set_file(array("body" => "editprofile.tpl"));
$this->t->set_block('body','main');
$this->translate();
foreach((array)$profileData as $key => $value) {
#print "$key $value
";
switch($key) {
case 'ea_default_signature':
// nothing to do here
break;
case 'imapTLSEncryption':
$this->t->set_var('checked_'. $key .'_'. $value,'checked="1"');
break;
case 'imapTLSAuthentication':
if(!$value) {
$this->t->set_var('selected_'.$key,'checked="1"');
}
break;
case 'imapEnableCyrusAdmin':
case 'imapEnableSieve':
case 'smtpAuth':
case 'smtpLDAPUseDefault':
case 'userDefinedAccounts':
case 'userDefinedIdentities':
case 'ea_user_defined_signatures':
case 'ea_active':
#echo $key."->".$value."
";
case 'imapoldcclient':
case 'editforwardingaddress':
if($value == 'yes' || $value == 1) {
$this->t->set_var('selected_'.$key,'checked="1"');
}
break;
case 'imapType':
case 'smtpType':
case 'imapLoginType':
$this->t->set_var('selected_'.$key.'_'.$value,'selected="1"');
break;
case 'ea_appname':
$this->t->set_var('application_select_box', html::select('globalsettings[ea_appname]',$value,$applications, true, "style='width: 250px;'"));
break;
case 'ea_group':
$this->t->set_var('group_select_box', html::select('globalsettings[ea_group]',$value,$allGroups, true, "style='width: 250px;'"));
break;
case 'ea_user':
$this->t->set_var('user_select_box', html::select('globalsettings[ea_user]',$value,$allUsers, true, "style='width: 250px;'"));
break;
case 'ea_smtp_auth_username':
#echo "
value_$key,$value";
list($username,$senderadress) = explode(';',$value,2);
if (!empty($senderadress)) $this->t->set_var('value_smtp_senderadress',$senderadress);
$this->t->set_var('value_'.$key,$username);
break;
default:
$this->t->set_var('value_'.$key,$value);
break;
}
}
$linkData = array
(
'menuaction' => 'emailadmin.emailadmin_ui.saveProfile',
'profileID' => $profileID
);
$this->t->set_var('action_url',$GLOBALS['egw']->link('/index.php',$linkData));
$linkData = array
(
'menuaction' => 'emailadmin.emailadmin_ui.listProfiles'
);
$this->t->set_var('back_url',$GLOBALS['egw']->link('/index.php',$linkData));
$this->t->set_var('smtptype',html::select(
'smtpsettings[smtpType]',
$profileData['smtpType'],
$this->boemailadmin->getSMTPServerTypes(),
true,
'style="width: 250px;" id="smtpselector" onchange="smtp.display(this.value);"'
));
foreach($this->boemailadmin->getIMAPServerTypes() as $key => $value) {
$imapServerTypes[$key] = $value['description'];
};
$selectFrom = html::select(
'imapsettings[imapType]',
$profileData['imapType'],
$imapServerTypes,
true,
// stupid tabs javascript assumes value=position in selectbox, here's a littel workaround ;-)
"style='width: 250px;' id='imapselector' onchange='var v = this.value; imap.display(this.value); this.value=v;'"
);
$this->t->set_var('imaptype', $selectFrom);
$style="width:100%; border:0px; height:150px;";
$this->t->set_var('signature', html::fckEditorQuick(
'globalsettings[ea_default_signature]', 'simple',
$profileData['ea_default_signature'], '150px')
);
$this->t->parse("out","main");
print $this->t->get('out','main');
}
function listProfiles()
{
$accountID = false;
$groupID = false;
$appName = '';
$profileID = '';
if(is_int(intval($_GET['account_id'])) && !empty($_GET['account_id']))
{
if ( intval($_GET['account_id']) < 0 ) {
$groupID = intval($_GET['account_id']);
} else {
$accountID = intval($_GET['account_id']);
}
}
$this->display_app_header();
$this->t->set_file(array("body" => "listprofiles.tpl"));
$this->t->set_block('body','main');
$this->translate();
$profileList = $this->boemailadmin->getProfileList($profileID,$appName,$groupID,$accountID);
// create the data array
if ($profileList)
{
for ($i=0; $i < count($profileList); $i++)
{
$linkData = array
(
'menuaction' => 'emailadmin.emailadmin_ui.editProfile',
'nocache' => '1',
'tabpage' => '3',
'profileid' => $profileList[$i]['profileID']
);
$imapServerLink = ''.$profileList[$i]['imapServer'].'';
$linkData = array
(
'menuaction' => 'emailadmin.emailadmin_ui.editProfile',
'nocache' => '1',
'tabpage' => '1',
'profileid' => $profileList[$i]['profileID']
);
$descriptionLink = ''.$profileList[$i]['description'].'';
$linkData = array
(
'menuaction' => 'emailadmin.emailadmin_ui.editProfile',
'nocache' => '1',
'tabpage' => '2',
'profileid' => $profileList[$i]['profileID']
);
$smtpServerLink = ''.$profileList[$i]['smtpServer'].'';
$linkData = array
(
'menuaction' => 'emailadmin.emailadmin_ui.deleteProfile',
'profileid' => $profileList[$i]['profileID']
);
$deleteLink = ''.
lang('delete').'';
$application = (empty($profileList[$i]['ea_appname']) ? lang('any application') : $GLOBALS['egw_info']['apps'][$profileList[$i]['ea_appname']]['title']);
$linkData = array
(
'menuaction' => 'emailadmin.emailadmin_ui.editProfile',
'nocache' => '1',
'tabpage' => '1',
'profileid' => $profileList[$i]['profileID']
);
$applicationLink = ''.$application.'';
$group = (empty($profileList[$i]['ea_group']) ? lang('any group') : $GLOBALS['egw']->accounts->id2name($profileList[$i]['ea_group']));
$user = (empty($profileList[$i]['ea_user']) ? lang('any user') : $GLOBALS['egw']->accounts->id2name($profileList[$i]['ea_user']));
$isactive = (empty($profileList[$i]['ea_active']) ? lang('inactive') : ($profileList[$i]['ea_active']>0 ? lang('active') : lang('inactive')));
$linkData = array
(
'menuaction' => 'emailadmin.emailadmin_ui.editProfile',
'nocache' => '1',
'tabpage' => '1',
'profileid' => $profileList[$i]['profileID']
);
$groupLink = ''.$group.'';
$userLink = ''.$user.'';
$activeLink = ''.$isactive.'';
$moveButtons = ' '.
'';
$data['profile_'.$profileList[$i]['profileID']] = array(
$descriptionLink,
$smtpServerLink,
$imapServerLink,
$applicationLink,
$groupLink,
$userLink,
$activeLink,
$deleteLink,
$moveButtons,
);
}
if (($accountID || !empty($groupID)) && count($profileList)==1)
{
$linkData = array
(
'menuaction' => 'emailadmin.emailadmin_ui.editProfile',
'nocache' => '1',
'tabpage' => '1',
'profileid' => $profileList[0]['profileID']
);
print "';
}
} else {
if ($accountID || !empty($groupID)) {
$linkData = array
(
'menuaction' => 'emailadmin.emailadmin_ui.addProfile',
'nocache' => '1',
'tabpage' => '1',
'account_id' => ($accountID ? $accountID : $groupID)
);
print "';
}
}
// create the array containing the table header
$rows = array(
lang('description'),
lang('smtp server name'),
lang('imap server name'),
lang('application'),
lang('group'),
lang('user'),
lang('active'),
lang('delete'),
lang('order'),
);
if ($accountID || !empty($groupID)) {
$linkData = array
(
'menuaction' => 'emailadmin.emailadmin_ui.listProfiles',
);
$listLink = ''.
lang('reset filter').'';
if ($GLOBALS['egw_info']['user']['apps']['admin']) {
$linkData = array
(
'menuaction' => 'admin.uiaccounts.list_'.($accountID ? 'users' : 'groups'),
);
$listLink2 = ''.($accountID ? lang('Back to Admin/Userlist'): lang('Back to Admin/Grouplist')).'';
}
}
// create the table html code
$this->t->set_var('server_next_match',$this->nextMatchTable(
$rows,
$data,
lang('profile list').($accountID || !empty($groupID) ? ' '.($accountID ? lang('filtered by Account') : lang('filtered by Group')).' ['.$listLink.']'.' ['.$listLink2.']': ''),
$_start,
$_total,
$_menuAction)
);
$linkData = array
(
'menuaction' => 'emailadmin.emailadmin_ui.addProfile'
);
$this->t->set_var('add_link',$GLOBALS['egw']->link('/index.php',$linkData));
$this->t->parse("out","main");
print $this->t->get('out','main');
}
function nextMatchTable($_rows, $_data, $_description, $_start, $_total, $_menuAction)
{
$template =& CreateObject('phpgwapi.Template',EGW_APP_TPL);
$template->set_file(array("body" => "nextMatch.tpl"));
$template->set_block('body','row_list','rowList');
$template->set_block('body','header_row','headerRow');
$var = Array(
'th_bg' => $GLOBALS['egw_info']['theme']['th_bg'],
'left_next_matchs' => $this->nextmatchs->left('/index.php',$start,$total,'menuaction=emailadmin.emailadmin_ui.listServers'),
'right_next_matchs' => $this->nextmatchs->right('/admin/groups.php',$start,$total,'menuaction=emailadmin.emailadmin_ui.listServers'),
'lang_groups' => lang('user groups'),
'sort_name' => $this->nextmatchs->show_sort_order($sort,'account_lid',$order,'/index.php',lang('name'),'menuaction=emailadmin.emailadmin_ui.listServers'),
'description' => $_description,
'header_edit' => lang('Edit'),
'header_delete' => lang('Delete')
);
$template->set_var($var);
$data = '';
if(is_array($_rows))
{
foreach($_rows as $value)
{
$data .= "