Conditions | 167 |
Paths | > 20000 |
Total Lines | 544 |
Code Lines | 307 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
821 | public function edit(array $content=null, $msg='', $msg_type='success') |
||
822 | { |
||
823 | // app is trying to tell something, while redirecting to wizard |
||
824 | if (empty($content) && $_GET['acc_id'] && empty($msg) && !empty( $_GET['msg'])) |
||
825 | { |
||
826 | if (stripos($_GET['msg'],'fatal error:')!==false || $_GET['msg_type'] == 'error') $msg_type = 'error'; |
||
827 | } |
||
828 | if ($content['acc_id'] || (isset($_GET['acc_id']) && (int)$_GET['acc_id'] > 0) ) Mail::unsetCachedObjects($content['acc_id']?$content['acc_id']:$_GET['acc_id']); |
||
829 | $tpl = new Etemplate('admin.mailaccount'); |
||
830 | |||
831 | if (!is_array($content) || !empty($content['acc_id']) && isset($content['old_acc_id']) && $content['acc_id'] != $content['old_acc_id']) |
||
832 | { |
||
833 | if (!is_array($content)) $content = array(); |
||
834 | if ($this->is_admin && isset($_GET['account_id'])) |
||
835 | { |
||
836 | $content['called_for'] = (int)$_GET['account_id']; |
||
837 | $content['accounts'] = iterator_to_array(Mail\Account::search($content['called_for'])); |
||
838 | if ($content['accounts']) |
||
839 | { |
||
840 | $content['acc_id'] = key($content['accounts']); |
||
841 | //error_log(__METHOD__.__LINE__.'.'.array2string($content['acc_id'])); |
||
842 | // test if the "to be selected" acccount is imap or not |
||
843 | if (is_array($content['accounts']) && count($content['accounts'])>1 && Mail\Account::is_multiple($content['acc_id'])) |
||
844 | { |
||
845 | try { |
||
846 | $account = Mail\Account::read($content['acc_id'], $content['called_for']); |
||
847 | //try to select the first account that is of type imap |
||
848 | if (!$account->is_imap()) |
||
849 | { |
||
850 | $content['acc_id'] = key($content['accounts']); |
||
851 | //error_log(__METHOD__.__LINE__.'.'.array2string($content['acc_id'])); |
||
852 | } |
||
853 | } |
||
854 | catch(Api\Exception\NotFound $e) { |
||
855 | if (self::$debug) _egw_log_exception($e); |
||
856 | } |
||
857 | } |
||
858 | } |
||
859 | if (!$content['accounts']) // no email account, call wizard |
||
860 | { |
||
861 | return $this->add(array('account_id' => (int)$_GET['account_id'])); |
||
862 | } |
||
863 | $content['accounts']['new'] = lang('Create new account'); |
||
864 | } |
||
865 | if (isset($_GET['acc_id']) && (int)$_GET['acc_id'] > 0) |
||
866 | { |
||
867 | $content['acc_id'] = (int)$_GET['acc_id']; |
||
868 | } |
||
869 | // clear current account-data, as account has changed and we going to read selected one |
||
870 | $content = array_intersect_key($content, array_flip(array('called_for', 'accounts', 'acc_id', 'tabs'))); |
||
871 | |||
872 | if ($content['acc_id'] > 0) |
||
873 | { |
||
874 | try { |
||
875 | $account = Mail\Account::read($content['acc_id'], $this->is_admin && $content['called_for'] ? |
||
876 | $content['called_for'] : $GLOBALS['egw_info']['user']['account_id']); |
||
877 | $account->getUserData(); // quota, aliases, forwards etc. |
||
878 | $content += $account->params; |
||
879 | $content['acc_sieve_enabled'] = (string)($content['acc_sieve_enabled']); |
||
880 | $content['notify_use_default'] = !$content['notify_account_id']; |
||
881 | self::fix_account_id_0($content['account_id']); |
||
882 | |||
883 | // read identities (of current user) and mark std identity |
||
884 | $content['identities'] = iterator_to_array(Mail\Account::identities($account, true, 'name', $content['called_for'])); |
||
885 | $content['std_ident_id'] = $content['ident_id']; |
||
886 | $content['identities'][$content['std_ident_id']] = lang('Standard identity'); |
||
887 | // change self::SSL_NONE (=0) to "no" used in sel_options |
||
888 | foreach(array('imap','smtp','sieve') as $type) |
||
889 | { |
||
890 | if (!$content['acc_'.$type.'_ssl']) $content['acc_'.$type.'_ssl'] = 'no'; |
||
891 | } |
||
892 | } |
||
893 | catch(Api\Exception\NotFound $e) { |
||
894 | if (self::$debug) _egw_log_exception($e); |
||
895 | Framework::window_close(lang('Account not found!')); |
||
896 | } |
||
897 | catch(Exception $e) { |
||
898 | if (self::$debug) _egw_log_exception($e); |
||
899 | Framework::window_close($e->getMessage().' ('.get_class($e).': '.$e->getCode().')'); |
||
900 | } |
||
901 | } |
||
902 | elseif ($content['acc_id'] === 'new') |
||
903 | { |
||
904 | $content['account_id'] = $content['called_for']; |
||
905 | $content['old_acc_id'] = $content['acc_id']; // to not call add/wizard, if we return from to |
||
906 | unset($content['tabs']); |
||
907 | return $this->add($content); |
||
908 | } |
||
909 | } |
||
910 | // some defaults for new accounts |
||
911 | if (!isset($content['account_id']) || empty($content['acc_id']) || $content['acc_id'] === 'new') |
||
912 | { |
||
913 | if (!isset($content['account_id'])) $content['account_id'] = array($GLOBALS['egw_info']['user']['account_id']); |
||
914 | $content['acc_user_editable'] = $content['acc_further_identities'] = true; |
||
915 | $readonlys['ident_id'] = true; // need to create standard identity first |
||
916 | } |
||
917 | if (empty($content['acc_name'])) |
||
918 | { |
||
919 | $content['acc_name'] = $content['ident_email']; |
||
920 | } |
||
921 | // disable some stuff for non-emailadmins (all values are preserved!) |
||
922 | if (!$this->is_admin) |
||
923 | { |
||
924 | $readonlys = array( |
||
925 | 'account_id' => true, 'button[multiple]' => true, 'acc_user_editable' => true, |
||
926 | 'acc_further_identities' => true, |
||
927 | 'acc_imap_type' => true, 'acc_imap_logintype' => true, 'acc_domain' => true, |
||
928 | 'acc_imap_admin_username' => true, 'acc_imap_admin_password' => true, |
||
929 | 'acc_smtp_type' => true, 'acc_smtp_auth_session' => true, |
||
930 | ); |
||
931 | } |
||
932 | // ensure correct values for single user mail accounts (we only hide them client-side) |
||
933 | if (!($is_multiple = Mail\Account::is_multiple($content))) |
||
934 | { |
||
935 | $content['acc_imap_type'] = 'EGroupware\\Api\\Mail\\Imap'; |
||
936 | unset($content['acc_imap_login_type']); |
||
937 | $content['acc_smtp_type'] = 'EGroupware\\Api\\Mail\\Smtp'; |
||
938 | unset($content['acc_smtp_auth_session']); |
||
939 | unset($content['notify_use_default']); |
||
940 | } |
||
941 | // copy ident_email_alias selectbox back to regular name |
||
942 | elseif (isset($content['ident_email_alias']) && !empty ($content['ident_email_alias'])) |
||
943 | { |
||
944 | $content['ident_email'] = $content['ident_email_alias']; |
||
945 | } |
||
946 | $edit_access = Mail\Account::check_access(Acl::EDIT, $content); |
||
947 | |||
948 | // disable notification save-default and use-default, if only one account or no edit-rights |
||
949 | $tpl->disableElement('notify_save_default', !$is_multiple || !$edit_access); |
||
950 | $tpl->disableElement('notify_use_default', !$is_multiple); |
||
951 | |||
952 | if (isset($content['button'])) |
||
953 | { |
||
954 | $button = key($content['button']); |
||
955 | unset($content['button']); |
||
956 | switch($button) |
||
957 | { |
||
958 | case 'wizard': |
||
959 | // if we just came from wizard, go back to last page/step |
||
960 | if (isset($content['smtp_connected'])) |
||
961 | { |
||
962 | return $this->smtp($content); |
||
963 | } |
||
964 | // otherwise start with first step |
||
965 | return $this->autoconfig($content); |
||
966 | |||
967 | case 'delete_identity': |
||
968 | // delete none-standard identity of current user |
||
969 | if (($this->is_admin || $content['acc_further_identities']) && |
||
970 | $content['ident_id'] > 0 && $content['std_ident_id'] != $content['ident_id']) |
||
971 | { |
||
972 | Mail\Account::delete_identity($content['ident_id']); |
||
973 | $msg = lang('Identity deleted'); |
||
974 | unset($content['identities'][$content['ident_id']]); |
||
975 | $content['ident_id'] = $content['std_ident_id']; |
||
976 | } |
||
977 | break; |
||
978 | |||
979 | case 'save': |
||
980 | case 'apply': |
||
981 | try { |
||
982 | // save none-standard identity for current user |
||
983 | if ($content['acc_id'] && $content['acc_id'] !== 'new' && |
||
984 | ($this->is_admin || $content['acc_further_identities']) && |
||
985 | $content['std_ident_id'] != $content['ident_id']) |
||
986 | { |
||
987 | $content['ident_id'] = Mail\Account::save_identity(array( |
||
988 | 'account_id' => $content['called_for'] ? $content['called_for'] : $GLOBALS['egw_info']['user']['account_id'], |
||
989 | )+$content); |
||
990 | $content['identities'][$content['ident_id']] = Mail\Account::identity_name($content); |
||
991 | $msg = lang('Identity saved.'); |
||
992 | if ($edit_access) $msg .= ' '.lang('Switch back to standard identity to save account.'); |
||
993 | } |
||
994 | elseif ($edit_access) |
||
995 | { |
||
996 | // if admin username/password given, check if it is valid |
||
997 | $account = new Mail\Account($content); |
||
998 | if ($account->acc_imap_administration) |
||
999 | { |
||
1000 | $imap = $account->imapServer(true); |
||
1001 | if ($imap) $imap->checkAdminConnection(); |
||
1002 | } |
||
1003 | // test sieve connection, if not called for other user, enabled and credentials available |
||
1004 | if (!$content['called_for'] && $account->acc_sieve_enabled && $account->acc_imap_username) |
||
1005 | { |
||
1006 | $account->imapServer()->retrieveRules(); |
||
1007 | } |
||
1008 | $new_account = !($content['acc_id'] > 0); |
||
1009 | // check for deliveryMode="forwardOnly", if a forwarding-address is given |
||
1010 | if ($content['acc_smtp_type'] != 'EGroupware\\Api\\Mail\\Smtp' && |
||
1011 | $content['deliveryMode'] == Mail\Smtp::FORWARD_ONLY && |
||
1012 | empty($content['mailForwardingAddress'])) |
||
1013 | { |
||
1014 | Etemplate::set_validation_error('mailForwardingAddress', lang('Field must not be empty !!!')); |
||
1015 | throw new Api\Exception\WrongUserinput(lang('You need to specify a forwarding address, when checking "%1"!', lang('Forward only'))); |
||
1016 | } |
||
1017 | // set notifications to store according to checkboxes |
||
1018 | if ($content['notify_save_default']) |
||
1019 | { |
||
1020 | $content['notify_account_id'] = 0; |
||
1021 | } |
||
1022 | elseif (!$content['notify_use_default']) |
||
1023 | { |
||
1024 | $content['notify_account_id'] = $content['called_for'] ? |
||
1025 | $content['called_for'] : $GLOBALS['egw_info']['user']['account_id']; |
||
1026 | } |
||
1027 | // SMIME SAVE |
||
1028 | if (isset($content['smimeKeyUpload'])) |
||
1029 | { |
||
1030 | $content['acc_smime_cred_id'] = self::save_smime_key($content, $tpl, $content['called_for']); |
||
1031 | unset($content['smimeKeyUpload']); |
||
1032 | } |
||
1033 | self::fix_account_id_0($content['account_id'], true); |
||
1034 | $content = Mail\Account::write($content, $content['called_for'] || !$this->is_admin ? |
||
1035 | $content['called_for'] : $GLOBALS['egw_info']['user']['account_id']); |
||
1036 | self::fix_account_id_0($content['account_id']); |
||
1037 | $msg = lang('Account saved.'); |
||
1038 | // user wants default notifications |
||
1039 | if ($content['acc_id'] && $content['notify_use_default']) |
||
1040 | { |
||
1041 | // delete own ones |
||
1042 | Mail\Notifications::delete($content['acc_id'], $content['called_for'] ? |
||
1043 | $content['called_for'] : $GLOBALS['egw_info']['user']['account_id']); |
||
1044 | // load default ones |
||
1045 | $content = array_merge($content, Mail\Notifications::read($content['acc_id'], 0)); |
||
1046 | } |
||
1047 | // add new std identity entry |
||
1048 | if ($new_account) |
||
1049 | { |
||
1050 | $content['std_ident_id'] = $content['ident_id']; |
||
1051 | $content['identities'] = array( |
||
1052 | $content['std_ident_id'] => lang('Standard identity')); |
||
1053 | } |
||
1054 | if (isset($content['accounts'])) |
||
1055 | { |
||
1056 | if (!isset($content['accounts'][$content['acc_id']])) // insert new account as top, not bottom |
||
1057 | { |
||
1058 | $content['accounts'] = array($content['acc_id'] => '') + $content['accounts']; |
||
1059 | } |
||
1060 | $content['accounts'][$content['acc_id']] = Mail\Account::identity_name($content, false); |
||
1061 | } |
||
1062 | } |
||
1063 | else |
||
1064 | { |
||
1065 | if ($content['notify_use_default'] && $content['notify_account_id']) |
||
1066 | { |
||
1067 | // delete own ones |
||
1068 | if (Mail\Notifications::delete($content['acc_id'], $content['called_for'] ? |
||
1069 | $content['called_for'] : $GLOBALS['egw_info']['user']['account_id'])) |
||
1070 | { |
||
1071 | $msg = lang('Notification folders updated.'); |
||
1072 | } |
||
1073 | // load default ones |
||
1074 | $content = array_merge($content, Mail\Notifications::read($content['acc_id'], 0)); |
||
1075 | } |
||
1076 | if (!$content['notify_use_default'] && is_array($content['notify_folders'])) |
||
1077 | { |
||
1078 | $content['notify_account_id'] = $content['called_for'] ? |
||
1079 | $content['called_for'] : $GLOBALS['egw_info']['user']['account_id']; |
||
1080 | if (Mail\Notifications::write($content['acc_id'], $content['notify_account_id'], |
||
1081 | $content['notify_folders'])) |
||
1082 | { |
||
1083 | $msg = lang('Notification folders updated.'); |
||
1084 | } |
||
1085 | } |
||
1086 | if ($content['acc_user_forward'] && !empty($content['acc_smtp_type']) && $content['acc_smtp_type'] != 'EGroupware\\Api\\Mail\\Smtp') |
||
1087 | { |
||
1088 | $account = new Mail\Account($content); |
||
1089 | $account->smtpServer()->saveSMTPForwarding($content['called_for'] ? |
||
1090 | $content['called_for'] : $GLOBALS['egw_info']['user']['account_id'], |
||
1091 | $content['mailForwardingAddress'], |
||
1092 | $content['forwardOnly'] ? null : 'yes'); |
||
1093 | } |
||
1094 | // smime (private) key uploaded by user himself |
||
1095 | if (!empty($content['smimeKeyUpload'])) |
||
1096 | { |
||
1097 | $content['acc_smime_cred_id'] = self::save_smime_key($content, $tpl); |
||
1098 | unset($content['smimeKeyUpload']); |
||
1099 | } |
||
1100 | } |
||
1101 | } |
||
1102 | catch (Horde_Imap_Client_Exception $e) |
||
1103 | { |
||
1104 | _egw_log_exception($e); |
||
1105 | $tpl->set_validation_error('acc_imap_admin_username', $msg=lang($e->getMessage()).($e->details?', '.lang($e->details):'')); |
||
1106 | $msg_type = 'error'; |
||
1107 | $content['tabs'] = 'admin.mailaccount.imap'; // should happen automatic |
||
1108 | break; |
||
1109 | } |
||
1110 | catch (Horde\ManageSieve\Exception\ConnectionFailed $e) |
||
1111 | { |
||
1112 | _egw_log_exception($e); |
||
1113 | $tpl->set_validation_error('acc_sieve_port', $msg=lang($e->getMessage())); |
||
1114 | $msg_type = 'error'; |
||
1115 | $content['tabs'] = 'admin.mailaccount.sieve'; // should happen automatic |
||
1116 | break; |
||
1117 | } |
||
1118 | catch (Exception $e) { |
||
1119 | $msg = lang('Error saving account!')."\n".$e->getMessage(); |
||
1120 | $button = 'apply'; |
||
1121 | $msg_type = 'error'; |
||
1122 | } |
||
1123 | if ($content['acc_id']) Mail::unsetCachedObjects($content['acc_id']); |
||
1124 | if (stripos($msg,'fatal error:')!==false) $msg_type = 'error'; |
||
1125 | Framework::refresh_opener($msg, 'emailadmin', $content['acc_id'], $new_account ? 'add' : 'update', null, null, null, $msg_type); |
||
1126 | if ($button == 'save') Framework::window_close(); |
||
1127 | break; |
||
1128 | |||
1129 | case 'delete': |
||
1130 | if (!Mail\Account::check_access(Acl::DELETE, $content)) |
||
1131 | { |
||
1132 | $msg = lang('Permission denied!'); |
||
1133 | $msg_type = 'error'; |
||
1134 | } |
||
1135 | elseif (Mail\Account::delete($content['acc_id']) > 0) |
||
1136 | { |
||
1137 | if ($content['acc_id']) Mail::unsetCachedObjects($content['acc_id']); |
||
1138 | Framework::refresh_opener(lang('Account deleted.'), 'emailadmin', $content['acc_id'], 'delete'); |
||
1139 | Framework::window_close(); |
||
1140 | } |
||
1141 | else |
||
1142 | { |
||
1143 | $msg = lang('Failed to delete account!'); |
||
1144 | $msg_type = 'error'; |
||
1145 | } |
||
1146 | } |
||
1147 | } |
||
1148 | // SMIME UPLOAD/DELETE/EXPORT control |
||
1149 | $content['hide_smime_upload'] = false; |
||
1150 | if (!empty($content['acc_smime_cred_id'])) |
||
1151 | { |
||
1152 | if (!empty($content['smime_delete_p12']) && |
||
1153 | Mail\Credentials::delete ( |
||
1154 | $content['acc_id'], |
||
1155 | $content['called_for'] ? $content['called_for'] : $GLOBALS['egw_info']['user']['account_id'], |
||
1156 | Mail\Credentials::SMIME |
||
1157 | )) |
||
1158 | { |
||
1159 | unset($content['acc_smime_password'], $content['smimeKeyUpload'], $content['smime_delete_p12'], $content['acc_smime_cred_id']); |
||
1160 | $content['hide_smime_upload'] = false; |
||
1161 | } |
||
1162 | else |
||
1163 | { |
||
1164 | // do NOT send smime private key to client side, it's unnecessary and binary blob breaks json encoding |
||
1165 | $content['acc_smime_password'] = Mail\Credentials::UNAVAILABLE; |
||
1166 | |||
1167 | $content['hide_smime_upload'] = true; |
||
1168 | } |
||
1169 | } |
||
1170 | |||
1171 | // disable delete button for new, not yet saved entries, if no delete rights or a non-standard identity selected |
||
1172 | $readonlys['button[delete]'] = empty($content['acc_id']) || |
||
1173 | !Mail\Account::check_access(Acl::DELETE, $content) || |
||
1174 | $content['ident_id'] != $content['std_ident_id']; |
||
1175 | |||
1176 | // if account is for multiple user, change delete confirmation to reflect that |
||
1177 | if (Mail\Account::is_multiple($content)) |
||
1178 | { |
||
1179 | $tpl->setElementAttribute('button[delete]', 'onclick', "et2_dialog.confirm(widget,'This is NOT a personal mail account!\\n\\nAccount will be deleted for ALL users!\\n\\nAre you really sure you want to do that?','Delete this account')"); |
||
1180 | } |
||
1181 | |||
1182 | // if no edit access, make whole dialog readonly |
||
1183 | if (!$edit_access) |
||
1184 | { |
||
1185 | $readonlys['__ALL__'] = true; |
||
1186 | $readonlys['button[cancel]'] = false; |
||
1187 | // allow to edit notification-folders |
||
1188 | $readonlys['button[save]'] = $readonlys['button[apply]'] = |
||
1189 | $readonlys['notify_folders'] = $readonlys['notify_use_default'] = false; |
||
1190 | // allow to edit sMime stuff |
||
1191 | $readonlys['smimeGenerate'] = $readonlys['smimeKeyUpload'] = $readonlys['smime_pkcs12_password'] = |
||
1192 | $readonlys['smime_export_p12'] = $readonlys['smime_delete_p12'] = false; |
||
1193 | } |
||
1194 | |||
1195 | $sel_options['acc_imap_ssl'] = $sel_options['acc_sieve_ssl'] = |
||
1196 | $sel_options['acc_smtp_ssl'] = self::$ssl_types; |
||
1197 | |||
1198 | // admin access to account with no credentials available |
||
1199 | if ($this->is_admin && (empty($content['acc_imap_username']) || empty($content['acc_imap_host']) || $content['called_for'])) |
||
1200 | { |
||
1201 | // cant connection to imap --> allow free entries in taglists |
||
1202 | foreach(array('acc_folder_sent', 'acc_folder_trash', 'acc_folder_draft', 'acc_folder_template', 'acc_folder_junk') as $folder) |
||
1203 | { |
||
1204 | $tpl->setElementAttribute($folder, 'allowFreeEntries', true); |
||
1205 | } |
||
1206 | } |
||
1207 | else |
||
1208 | { |
||
1209 | try { |
||
1210 | $sel_options['acc_folder_sent'] = $sel_options['acc_folder_trash'] = |
||
1211 | $sel_options['acc_folder_draft'] = $sel_options['acc_folder_template'] = |
||
1212 | $sel_options['acc_folder_junk'] = $sel_options['acc_folder_archive'] = |
||
1213 | $sel_options['notify_folders'] = $sel_options['acc_folder_ham'] = |
||
1214 | self::mailboxes(self::imap_client ($content)); |
||
1215 | // Allow folder notification on INBOX for popup_only |
||
1216 | if ($GLOBALS['egw_info']['user']['preferences']['notifications']['notification_chain'] == 'popup_only') |
||
1217 | { |
||
1218 | $sel_options['notify_folders']['INBOX'] = lang('INBOX'); |
||
1219 | } |
||
1220 | } |
||
1221 | catch(Exception $e) { |
||
1222 | if (self::$debug) _egw_log_exception($e); |
||
1223 | // let user know what the problem is and that he can fix it using wizard or deleting |
||
1224 | $msg = lang($e->getMessage())."\n\n".lang('You can use wizard to fix account settings or delete account.'); |
||
1225 | $msg_type = 'error'; |
||
1226 | // cant connection to imap --> allow free entries in taglists |
||
1227 | foreach(array('acc_folder_sent', 'acc_folder_trash', 'acc_folder_draft', 'acc_folder_template', 'acc_folder_junk') as $folder) |
||
1228 | { |
||
1229 | $tpl->setElementAttribute($folder, 'allowFreeEntries', true); |
||
1230 | } |
||
1231 | } |
||
1232 | } |
||
1233 | |||
1234 | $sel_options['acc_imap_type'] = Mail\Types::getIMAPServerTypes(false); |
||
1235 | $sel_options['acc_smtp_type'] = Mail\Types::getSMTPServerTypes(false); |
||
1236 | $sel_options['acc_imap_logintype'] = self::$login_types; |
||
1237 | $sel_options['ident_id'] = $content['identities']; |
||
1238 | $sel_options['acc_id'] = $content['accounts']; |
||
1239 | $sel_options['acc_further_identities'] = self::$further_identities; |
||
1240 | |||
1241 | // user is allowed to create or edit further identities |
||
1242 | if ($edit_access || $content['acc_further_identities']) |
||
1243 | { |
||
1244 | $sel_options['ident_id']['new'] = lang('Create new identity'); |
||
1245 | $readonlys['ident_id'] = false; |
||
1246 | |||
1247 | // if no edit-access and identity is not standard identity --> allow to edit identity |
||
1248 | if (!$edit_access && $content['ident_id'] != $content['std_ident_id']) |
||
1249 | { |
||
1250 | $readonlys += array( |
||
1251 | 'button[save]' => false, 'button[apply]' => false, |
||
1252 | 'button[placeholders]' => false, |
||
1253 | 'ident_name' => false, |
||
1254 | 'ident_realname' => false, 'ident_email' => false, 'ident_email_alias' => false, |
||
1255 | 'ident_org' => false, 'ident_signature' => false, |
||
1256 | ); |
||
1257 | } |
||
1258 | if ($content['ident_id'] != $content['old_ident_id'] && |
||
1259 | ($content['old_ident_id'] || $content['ident_id'] != $content['std_ident_id'])) |
||
1260 | { |
||
1261 | if ($content['ident_id'] > 0) |
||
1262 | { |
||
1263 | $identity = Mail\Account::read_identity($content['ident_id'], false, $content['called_for']); |
||
1264 | unset($identity['account_id']); |
||
1265 | $content = array_merge($content, $identity, array('ident_email_alias' => $identity['ident_email'])); |
||
1266 | } |
||
1267 | else |
||
1268 | { |
||
1269 | $content['ident_name'] = $content['ident_realname'] = $content['ident_email'] = |
||
1270 | $content['ident_email_alias'] = $content['ident_org'] = $content['ident_signature'] = ''; |
||
1271 | } |
||
1272 | if (empty($msg) && $edit_access && $content['ident_id'] && $content['ident_id'] != $content['std_ident_id']) |
||
1273 | { |
||
1274 | $msg = lang('Switch back to standard identity to save other account data.'); |
||
1275 | $msg_type = 'help'; |
||
1276 | } |
||
1277 | $content['old_ident_id'] = $content['ident_id']; |
||
1278 | } |
||
1279 | } |
||
1280 | $content['old_acc_id'] = $content['acc_id']; |
||
1281 | |||
1282 | // if only aliases are allowed for futher identities, add them as options |
||
1283 | // allow admins to always add arbitrary aliases |
||
1284 | if ($content['acc_further_identities'] == 2 && !$this->is_admin) |
||
1285 | { |
||
1286 | $sel_options['ident_email_alias'] = array_merge( |
||
1287 | array('' => $content['mailLocalAddress'].' ('.lang('Default').')'), |
||
1288 | array_combine($content['mailAlternateAddress'], $content['mailAlternateAddress'])); |
||
1289 | // if admin explicitly set a non-alias, we need to add it to aliases to keep it after storing signature by user |
||
1290 | if ($content['ident_email'] !== $content['mailLocalAddress'] && !isset($sel_options['ident_email_alias'][$content['ident_email']])) |
||
1291 | { |
||
1292 | $sel_options['ident_email_alias'][$content['ident_email']] = $content['ident_email']; |
||
1293 | } |
||
1294 | // copy ident_email to select-box ident_email_alias, as et2 requires unique ids |
||
1295 | $content['ident_email_alias'] = $content['ident_email']; |
||
1296 | $content['select_ident_mail'] = true; |
||
1297 | } |
||
1298 | |||
1299 | // only allow to delete further identities, not a standard identity |
||
1300 | $readonlys['button[delete_identity]'] = !($content['ident_id'] > 0 && $content['ident_id'] != $content['std_ident_id']); |
||
1301 | |||
1302 | // disable aliases tab for default smtp class EGroupware\Api\Mail\Smtp |
||
1303 | $readonlys['tabs']['admin.mailaccount.aliases'] = !$content['acc_smtp_type'] || |
||
1304 | $content['acc_smtp_type'] == 'EGroupware\\Api\\Mail\\Smtp'; |
||
1305 | if ($readonlys['tabs']['admin.mailaccount.aliases']) |
||
1306 | { |
||
1307 | unset($sel_options['acc_further_identities'][2]); // can limit identities to aliases without aliases ;-) |
||
1308 | } |
||
1309 | |||
1310 | // allow smtp class to disable certain features in alias tab |
||
1311 | if ($content['acc_smtp_type'] && class_exists($content['acc_smtp_type']) && |
||
1312 | is_a($content['acc_smtp_type'], 'EGroupware\\Api\\Mail\\Smtp\\Ldap', true)) |
||
1313 | { |
||
1314 | $content['no_forward_available'] = !constant($content['acc_smtp_type'].'::FORWARD_ATTR'); |
||
1315 | if (!constant($content['acc_smtp_type'].'::FORWARD_ONLY_ATTR')) |
||
1316 | { |
||
1317 | $readonlys['deliveryMode'] = true; |
||
1318 | } |
||
1319 | } |
||
1320 | |||
1321 | // account allows users to change forwards |
||
1322 | if (!$edit_access && !$readonlys['tabs']['admin.mailaccount.aliases'] && $content['acc_user_forward']) |
||
1323 | { |
||
1324 | $readonlys['mailForwardingAddress'] = false; |
||
1325 | } |
||
1326 | |||
1327 | // allow imap classes to disable certain tabs or fields |
||
1328 | if (($class = Mail\Account::getIcClass($content['acc_imap_type'])) && class_exists($class) && |
||
1329 | ($imap_ro = call_user_func(array($class, 'getUIreadonlys')))) |
||
1330 | { |
||
1331 | $readonlys = array_merge($readonlys, $imap_ro, array( |
||
1332 | 'tabs' => array_merge((array)$readonlys['tabs'], (array)$imap_ro['tabs']), |
||
1333 | )); |
||
1334 | } |
||
1335 | Framework::message($msg ? $msg : (string)$_GET['msg'], $msg_type); |
||
1336 | |||
1337 | if (is_array($content['account_id']) && count($content['account_id']) > 1) |
||
1338 | { |
||
1339 | $tpl->setElementAttribute('account_id', 'multiple', true); |
||
1340 | $readonlys['button[multiple]'] = true; |
||
1341 | } |
||
1342 | // when called by admin for existing accounts, display further administrative actions |
||
1343 | if ($content['called_for'] && $content['acc_id'] > 0) |
||
1344 | { |
||
1345 | $admin_actions = array(); |
||
1346 | foreach(Api\Hooks::process(array( |
||
1347 | 'location' => 'emailadmin_edit', |
||
1348 | 'account_id' => $content['called_for'], |
||
1349 | 'acc_id' => $content['acc_id'], |
||
1350 | )) as $actions) |
||
1351 | { |
||
1352 | if ($actions) $admin_actions = array_merge($admin_actions, $actions); |
||
1353 | } |
||
1354 | if ($admin_actions) $tpl->setElementAttribute('admin_actions', 'actions', $admin_actions); |
||
1355 | } |
||
1356 | $content['admin_actions'] = (bool)$admin_actions; |
||
1357 | |||
1358 | //try to fix identities with no domain part set e.g. alias as identity |
||
1359 | if (!strpos($content['ident_email'], '@')) |
||
1360 | { |
||
1361 | $content['ident_email'] = Mail::fixInvalidAliasAddress (Api\Accounts::id2name($content['acc_imap_account_id'], 'account_email'), $content['ident_email']); |
||
1362 | } |
||
1363 | |||
1364 | $tpl->exec(static::APP_CLASS.'edit', $content, $sel_options, $readonlys, $content, 2); |
||
1365 | } |
||
1644 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: