1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class IMP_Views_Compose
16: {
17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32:
33: static public function showCompose($args)
34: {
35: global $conf, $injector, $prefs, $registry, $session;
36:
37: $result = array(
38: 'html' => '',
39: 'js' => array(),
40: 'jsonload' => array()
41: );
42:
43: $t = $injector->createInstance('Horde_Template');
44: $t->setOption('gettext', true);
45:
46: if (!empty($args['composeCache'])) {
47: $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create($args['composeCache']);
48: $t->set('composeCache', $args['composeCache']);
49: }
50:
51: if (empty($args['redirect'])) {
52:
53: $identity = $injector->getInstance('IMP_Identity');
54: $t->set('selected_identity', intval($identity->getDefault()));
55:
56:
57: $result['js'] = array_merge($result['js'], $injector->getInstance('IMP_Ui_Compose')->identityJs());
58:
59: if ($t->get('composeCache') && count($imp_compose)) {
60: foreach ($imp_compose as $num => $atc) {
61: $mime = $atc['part'];
62: $opts = array(
63: 'name' => $mime->getName(true),
64: 'num' => intval($num),
65: 'size' => $mime->getSize(),
66: 'type' => $mime->getType()
67: );
68: if (!empty($args['fwdattach'])) {
69: $opts['fwdattach'] = 1;
70: }
71: $result['jsonload'][] = 'DimpCompose.addAttach(' . Horde_Serialize::serialize($opts, Horde_Serialize::JSON, 'UTF-8') . ')';
72: }
73: }
74:
75: if (!empty($args['qreply'])) {
76: $result['js'][] = 'DIMP.conf_compose.qreply = 1';
77: }
78:
79: if ($session->get('imp', 'rteavail')) {
80: $t->set('compose_html', !empty($args['show_editor']));
81: $t->set('rte', true);
82:
83: IMP_Ui_Editor::init(!$t->get('compose_html'));
84: }
85:
86:
87: if ($injector->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_FOLDERS)) {
88: $t->set('save_sent_mail', !$prefs->isLocked('save_sent_mail'));
89:
90: if (!empty($conf['user']['select_sentmail_folder']) &&
91: !$prefs->isLocked('sent_mail_folder')) {
92: 93:
94: foreach (array_keys($identity->getAll('id')) as $ident) {
95: $folder = $identity->getValue('sent_mail_folder', $ident);
96: if ($folder instanceof IMP_Mailbox) {
97: $folder->create();
98: }
99: }
100:
101: $flist = array();
102: $imaptree = $injector->getInstance('IMP_Imap_Tree');
103:
104: foreach ($imaptree as $val) {
105: $tmp = array(
106: 'f' => $val->display,
107: 'l' => Horde_String::abbreviate(str_repeat(' ', 2 * $val->level) . $val->basename, 30),
108: 'v' => $val->container ? '' : $val->form_to
109: );
110: if ($tmp['f'] == $tmp['v']) {
111: unset($tmp['f']);
112: }
113: $flist[] = $tmp;
114: }
115: $result['js'] = array_merge($result['js'], Horde::addInlineJsVars(array(
116: 'DIMP.conf_compose.flist' => $flist
117: ), array('ret_vars' => true)));
118: }
119: }
120:
121: $compose_link = Horde::getServiceLink('ajax', 'imp');
122: $compose_link->pathInfo = 'addAttachment';
123: $t->set('compose_link', $compose_link);
124:
125: $t->set('send_button', IMP_Dimp::actionButton(array(
126: 'icon' => 'Forward',
127: 'id' => 'send_button',
128: 'title' => _("Send")
129: )));
130: $t->set('spell_button', IMP_Dimp::actionButton(array(
131: 'id' => 'spellcheck',
132: 'title' => _("Check Spelling")
133: )));
134: $t->set('draft_button', IMP_Dimp::actionButton(array(
135: 'icon' => 'Drafts',
136: 'id' => 'draft_button',
137: 'title' => _("Save as Draft")
138: )));
139:
140: $d_read = $prefs->getValue('request_mdn');
141: if ($d_read != 'never') {
142: $t->set('read_receipt', true);
143: $t->set('read_receipt_set', ($d_read != 'ask'));
144: }
145:
146: $t->set('priority', $prefs->getValue('set_priority'));
147: if (!$prefs->isLocked('default_encrypt') &&
148: ($prefs->getValue('use_pgp') || $prefs->getValue('use_smime'))) {
149: $t->set('encrypt', $prefs->getValue('default_encrypt'));
150: }
151:
152: $select_list = array();
153: foreach ($identity->getSelectList() as $id => $from) {
154: $select_list[] = array(
155: 'label' => htmlspecialchars($from),
156: 'sel' => ($id == $t->get('selected_identity')),
157: 'val' => htmlspecialchars($id)
158: );
159: }
160: $t->set('select_list', $select_list);
161:
162: $save_attach = $prefs->getValue('save_attachments');
163: if (strpos($save_attach, 'prompt') !== false) {
164: $t->set('save_attach', true);
165: $t->set('save_attach_set', strpos($save_attach, 'yes') !== false);
166: }
167: } else {
168: $result['js'] = array_merge($result['js'], Horde::addInlineJsVars(array(
169: '-DIMP.conf_compose.redirect' => 1
170: ), array('ret_vars' => true)));
171: }
172:
173: $t->set('bcc', $prefs->getValue('compose_bcc'));
174: $t->set('cc', $prefs->getValue('compose_cc'));
175: $t->set('bcc_or_cc', $t->get('bcc') || $t->get('cc'));
176: $t->set('compose_enable', IMP::canCompose());
177: $t->set('forminput', Horde_Util::formInput());
178: $t->set('redirect_button', IMP_Dimp::actionButton(array(
179: 'icon' => 'Forward',
180: 'id' => 'send_button_redirect',
181: 'title' => _("Redirect")
182: )));
183:
184: $result['html'] = $t->fetch(IMP_TEMPLATES . '/dimp/compose/compose.html');
185:
186: return $result;
187: }
188:
189: }
190: