1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Prefs_Special_Remote implements Horde_Core_Prefs_Ui_Special
24: {
25: 26:
27: public function init(Horde_Core_Prefs_Ui $ui)
28: {
29: }
30:
31: 32:
33: public function display(Horde_Core_Prefs_Ui $ui)
34: {
35: global $injector, $page_output;
36:
37: $ui->nobuttons = true;
38:
39: $page_output->addScriptFile('external/base64.js');
40: $page_output->addScriptFile('remoteprefs.js');
41: $page_output->addInlineJsVars(array(
42: 'ImpRemotePrefs.confirm_delete' => _("Are you sure you want to delete this account?"),
43: 'ImpRemotePrefs.empty_email' => _("The e-mail field cannot be empty."),
44: 'ImpRemotePrefs.empty_password' => _("The password field cannot be empty."),
45: 'ImpRemotePrefs.next' => _("Next"),
46: 'ImpRemotePrefs.wait' => _("Please wait...")
47: ));
48:
49: $view = new Horde_View(array(
50: 'templatePath' => IMP_TEMPLATES . '/prefs'
51: ));
52: $view->addHelper('Horde_Core_View_Helper_Image');
53: $view->addHelper('Text');
54:
55: switch ($ui->vars->remote_action) {
56: case 'new':
57: $view->new = true;
58: break;
59:
60: default:
61: $view->accounts = iterator_to_array($injector->getInstance('IMP_Remote'));
62: break;
63: }
64:
65: return $view->render('remote');
66: }
67:
68: 69:
70: public function update(Horde_Core_Prefs_Ui $ui)
71: {
72: global $injector, $notification;
73:
74: $remote = $injector->getInstance('IMP_Remote');
75:
76: switch ($ui->vars->remote_action) {
77: case 'add':
78: try {
79: $ob = new IMP_Remote_Account();
80: $ob->hostspec = $ui->vars->remote_server;
81: $ob->username = $ui->vars->remote_user;
82: if (strlen($ui->vars->remote_label)) {
83: $ob->label = $ui->vars->remote_label;
84: }
85: if ($ui->vars->remote_port) {
86: $ob->port = $ui->vars->remote_port;
87: }
88: if ($ui->vars->get('remote_type') == 'pop3') {
89: $ob->type = $ob::POP3;
90: }
91:
92: if (isset($ui->vars->remote_secure_autoconfig)) {
93: switch ($ui->vars->remote_secure_autoconfig) {
94: case 'starttls':
95: $ob->secure = 'tls';
96: break;
97:
98: case 'tls':
99: $ob->secure = 'ssl';
100: break;
101:
102: default:
103: $ob->secure = true;
104: break;
105: }
106: } else {
107: switch ($ui->vars->remote_secure) {
108: case 'auto':
109: $ob->secure = true;
110: break;
111:
112: case 'yes':
113: switch ($ob->type) {
114: case $ob::IMAP:
115: $tmp = new Horde_Mail_Autoconfig_Server_Imap();
116: break;
117:
118: case $ob::POP3:
119: $tmp = new Horde_Mail_Autoconfig_Server_Pop3();
120: break;
121: }
122:
123: $tmp->host = $ob->hostspec;
124: $tmp->port = $ob->port;
125: $tmp->tls = 'tls';
126:
127: $ob->secure = $tmp->valid()
128: ? 'ssl'
129: : 'tls';
130: break;
131: }
132: }
133:
134: $remote[strval($ob)] = $ob;
135:
136: $notification->push(sprintf(_("Account \"%s\" added."), $ob->label), 'horde.success');
137:
138: $injector->getInstance('IMP_Ftree')->insert($ob);
139: } catch (IMP_Exception $e) {
140: $notification->push($e, 'horde.error');
141: }
142: break;
143:
144: case 'delete':
145: if (isset($remote[$ui->vars->remote_data])) {
146: $ob = $remote[$ui->vars->remote_data];
147: unset($remote[$ui->vars->remote_data]);
148: $notification->push(sprintf(_("Account \"%s\" deleted."), $ob->label), 'horde.success');
149:
150: $injector->getInstance('IMP_Ftree')->delete($ob);
151: }
152: break;
153: }
154:
155: return false;
156: }
157:
158: }
159: