Changeset 265
- Timestamp:
- 04/11/08 00:01:56 (9 months ago)
- Files:
-
- trunk/Framework/Module/Responders.php (modified) (11 diffs)
- trunk/Framework/Module/Responders/Templates/Default/listResponders.tpl (modified) (4 diffs)
- trunk/Framework/Module/Responders/Templates/Default/responderConfirmDelete.tpl (modified) (1 diff)
- trunk/Framework/Module/Responders/Templates/Default/responderForm.tpl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Framework/Module/Responders.php
r247 r265 4 4 * Responders Module 5 5 * 6 * @uses ToasterAdmin_Common 7 * @package ToasterAdmin 8 * @copyright 2006-2007 Bill Shupp 9 * @author Bill Shupp <hostmaster@shupp.org> 10 * @license GPL 2.0 {@link http://www.gnu.org/licenses/gpl.txt} 6 * PHP Version 5.1.0+ 7 * 8 * @uses ToasterAdmin_Auth_Domain 9 * @category Mail 10 * @package ToasterAdmin 11 * @subpackage Module 12 * @author Bill Shupp <hostmaster@shupp.org> 13 * @copyright 2007-2008 Bill Shupp 14 * @license GPL 2.0 {@link http://www.gnu.org/licenses/gpl.txt} 15 * @link http://trac.merchbox.com/trac/toasteradmin 11 16 */ 12 17 … … 14 19 * Framework_Module_Responders 15 20 * 16 * @uses ToasterAdmin_Common 17 * @package ToasterAdmin 18 * @copyright 2006-2007 Bill Shupp 19 * @author Bill Shupp <hostmaster@shupp.org> 20 * @license GPL 2.0 {@link http://www.gnu.org/licenses/gpl.txt} 21 * Manage vpopmail auto responders 22 * 23 * @uses ToasterAdmin_Auth_Domain 24 * @category Mail 25 * @package ToasterAdmin 26 * @subpackage Module 27 * @author Bill Shupp <hostmaster@shupp.org> 28 * @copyright 2007-2008 Bill Shupp 29 * @license GPL 2.0 {@link http://www.gnu.org/licenses/gpl.txt} 30 * @link http://trac.merchbox.com/trac/toasteradmin 21 31 */ 22 32 class Framework_Module_Responders extends ToasterAdmin_Auth_Domain … … 26 36 * __construct 27 37 * 28 * class constructor38 * Check that a domain as supplied 29 39 * 30 40 * @access protected 31 41 * @return void 32 42 */ 33 function __construct() { 43 public function __construct() 44 { 34 45 parent::__construct(); 35 // Make sure doamin was supplied 36 if (($result = $this->noDomainSupplied())) { 37 return $result; 38 } 46 $this->noDomainSupplied(); 39 47 } 40 48 … … 42 50 * __default 43 51 * 44 * @access protected 45 * @return void 46 */ 47 function __default() { 52 * Run $this->listResponders() 53 * 54 * @access public 55 * @return void 56 */ 57 public function __default() 58 { 48 59 $this->listResponders(); 49 60 } 50 61 51 function listResponders() { 52 53 if (($result = $this->noDomainPrivs())) { 54 return $result; 55 } 56 57 $full_alias_array = $this->user->listAlias($this->domain); 58 if (PEAR::isError($full_alias_array)) return $full_alias_array; 59 $autoresponders_raw = $this->user->parseAliases($full_alias_array, 'responders'); 62 /** 63 * listResponders 64 * 65 * List all auto responders for a domain 66 * 67 * @access public 68 * @return void 69 */ 70 public function listResponders() 71 { 72 $f = $this->user->listAlias($this->domain); 73 $raw = $this->user->parseAliases($f, 'responders'); 60 74 61 75 // Pagintation setup 62 $total = count($ autoresponders_raw);76 $total = count($raw); 63 77 $this->paginate($total); 64 78 65 79 // List Responders 66 $autoresponders_paginated = $this->user->paginateArray($autoresponders_raw, $this->data['currentPage'], $this->data['limit']); 67 $autoresponders = array(); 68 $count = 0; 69 while (list($key,$val) = each($autoresponders_paginated)) { 70 $autoresponders[$count]['autoresponder'] = $key; 71 $autoresponders[$count]['edit_url'] = htmlspecialchars("./?module=Responders&domain={$this->domain}&autoresponder=$key&event=modifyResponder"); 72 $autoresponders[$count]['delete_url'] = htmlspecialchars("./?module=Responders&domain={$this->domain}&autoresponder=$key&event=delete"); 73 $count++; 74 } 75 $this->setData('autoresponders', $autoresponders); 76 $this->setData('add_url', htmlspecialchars("./?module=Responders&event=addResponder&domain={$this->domain}")); 77 78 // Language 79 $this->setData('LANG_AutoResponders_in_domain', _('Auto-Responders in domain')); 80 $this->setData('LANG_AutoResponders_Page', _('Auto-Responders: Page')); 81 $this->setData('LANG_Add_AutoResponder', _('Add Auto-Responder')); 82 $this->setData('LANG_Domain_Menu', _('Domain Menu')); 83 $this->setData('LANG_of', _('of')); 84 $this->setData('LANG_AutoResponder', _('Auto-Responder')); 85 $this->setData('LANG_Edit', _('Edit')); 86 $this->setData('LANG_Delete', _('Delete')); 87 $this->setData('LANG_edit', _('edit')); 88 $this->setData('LANG_delete', _('delete')); 80 $p = $this->user->paginateArray($raw, 81 $this->data['currentPage'], $this->data['limit']); 82 $a = array(); 83 $c = 0; 84 foreach ($p as $key => $val) { 85 $eurl = "./?module=Responders&domain={$this->domain}"; 86 $eurl .= "&autoresponder=$key&event=modifyResponder"; 87 $durl = "./?module=Responders&domain={$this->domain}"; 88 $durl .= "&autoresponder=$key&event=delete"; 89 90 $a[$c]['autoresponder'] = $key; 91 $a[$c]['edit_url'] = htmlspecialchars($eurl); 92 $a[$c]['delete_url'] = htmlspecialchars($durl); 93 $c++; 94 } 95 $aurl = "./?module=Responders&event=addResponder&domain={$this->domain}"; 96 $this->setData('add_url', htmlspecialchars($aurl)); 97 $this->setData('autoresponders', $a); 89 98 90 99 $this->tplFile = 'listResponders.tpl'; … … 95 104 * addResponder 96 105 * 97 * @access public 98 * @return void 99 */ 100 function addResponder() { 101 $form = $this->responderForm(); 102 $renderer =& new HTML_QuickForm_Renderer_AssocArray(); 106 * Show add responder form 107 * 108 * @access public 109 * @return void 110 */ 111 public function addResponder() 112 { 113 $form = $this->responderForm(); 114 $renderer = new HTML_QuickForm_Renderer_AssocArray(); 103 115 $form->accept($renderer); 104 116 $this->setData('form', $renderer->toAssocArray()); … … 107 119 } 108 120 109 function addResponderNow() { 110 $this->setData('LANG_responder_submit', _("Add Auto-Responder")); 111 $this->setData('LANG_responder_header', _("Add Auto-Responder to domain ")); 121 /** 122 * addResponderNow 123 * 124 * Add autoresponder 125 * 126 * @access public 127 * @return mixed addResponder() on failure, listResponders() on success 128 */ 129 public function addResponderNow() 130 { 131 $this->setData('responder_submit', _("Add Auto-Responder")); 132 $this->setData('responder_header', _("Add Auto-Responder to domain ")); 112 133 $form = $this->responderForm(); 113 134 if (!$form->validate()) { 114 $renderer = &new HTML_QuickForm_Renderer_AssocArray();135 $renderer = new HTML_QuickForm_Renderer_AssocArray(); 115 136 $form->accept($renderer); 116 137 $this->setData('form', $renderer->toAssocArray()); … … 121 142 // Split autoresponder to get user 122 143 $email_array = explode('@', $_REQUEST['autoresponder']); 123 $responder = $this->user->robotGet($this->domain, $email_array[0]); 124 if (!PEAR::isError($responder)) { 125 $this->setData('message', _('Error: autoresponder already exists: ' . $email_array[0])); 144 try { 145 $responder = $this->user->robotGet($this->domain, $email_array[0]); 146 $this->setData('message', 147 _('Error: autoresponder already exists: ' . $email_array[0])); 126 148 return $this->addResponder(); 127 } 128 129 $result = $this->user->robotSet($this->domain, $email_array[0], $_POST['subject'], $_POST['body'], $_POST['copy']); 130 if (PEAR::isError($result)) return $result; 131 $this->setData('message', _("Auto-Responder Added Successfully")); 149 } catch (Net_Vpopmaild_Exception $e) { 150 } 151 152 $result = $this->user->robotSet($this->domain, 153 $email_array[0], $_POST['subject'], $_POST['body'], $_POST['copy']); 154 $this->setData('message', _('Auto-Responder Added Successfully')); 132 155 return $this->listResponders(); 133 156 } 134 157 135 function responderForm($type = 'add', $defaults = '') { 136 $this->setData('LANG_Domain_Menu', _("Domain Menu")); 158 /** 159 * responderForm 160 * 161 * @param string $type add or modify 162 * @param string $defaults default responder data 163 * 164 * @access protected 165 * @return object HTML_Quickform object 166 */ 167 protected function responderForm($type = 'add', $defaults = '') 168 { 137 169 $this->setData('type', $type); 138 170 if ($type == 'add') { 139 $this->setData('LANG_responder_submit', _("Add")); 140 $this->setData('LANG_responder_header', _("Add Auto-Responder to domain ") . $this->domain); 171 $this->setData('responder_submit', _("Add")); 172 $this->setData('responder_header', 173 _("Add Auto-Responder to domain ") . $this->domain); 141 174 } else { 142 175 $this->setData('responder_name', $defaults['autoresponder']); 143 $this->setData('LANG_responder_submit', _("Modify")); 144 $this->setData('LANG_responder_header', _("Modify Auto-Responder ") . $_REQUEST['autoresponder']); 145 } 146 147 $form = new HTML_QuickForm('formAddAccount', 'post', "./?module=Responders&event=${type}ResponderNow&domain={$this->domain}"); 176 $this->setData('responder_submit', _("Modify")); 177 $this->setData('responder_header', 178 _("Modify Auto-Responder ") . $_REQUEST['autoresponder']); 179 } 180 181 $form = new HTML_QuickForm('formAddAccount', 'post', 182 "./?module=Responders&event=${type}ResponderNow&domain={$this->domain}"); 148 183 149 184 if ($defaults == '') { … … 155 190 if ($type == 'modify') { 156 191 $form->addElement('hidden', 'autoresponder'); 157 $form->addRule('autoresponder', _("Auto-Responder is required"), 'required', null ); 158 $form->addRule('autoresponder', _("Auto-Responder must be a full address"), 'email', null); 192 $form->addRule('autoresponder', 193 _("Auto-Responder is required"), 'required', null); 194 $form->addRule('autoresponder', 195 _("Auto-Responder must be a full address"), 'email', null); 159 196 } else { 160 197 $form->addElement('text', 'autoresponder', _('Auto-Responder')); 161 $form->addRule('autoresponder', _("Auto-Responder is required"), 'required', null, 'client'); 162 $form->addRule('autoresponder', _("Auto-Responder must be a full address"), 'email', null, 'client'); 198 $form->addRule('autoresponder', 199 _("Auto-Responder is required"), 'required', null, 'client'); 200 $form->addRule('autoresponder', 201 _("Auto-Responder must be a full address"), 'email', null, 'client'); 163 202 } 164 203 $form->addElement('text', 'copy', _("Send Copy To")); 165 204 $form->addElement('text', 'subject', _("Subject")); 166 205 $form->addElement('textarea', 'body', _("Body"), 'cols="40" rows="10"'); 167 $form->addElement('submit', 'submit', $this-> __get('LANG_responder_submit'));206 $form->addElement('submit', 'submit', $this->responder_submit); 168 207 169 208 $form->registerRule('sameDomain', 'regex', "/@$this->domain$/i"); 170 209 171 $form->addRule('autoresponder', _('Error: wrong domain in Auto-Responder'), 'sameDomain'); 172 $form->addRule('copy', _("'Save a copy' must be an email address"), 'email', null, 'client'); 173 $form->addRule('subject', _("Subject is required"), 'required', null, 'client'); 210 $form->addRule('autoresponder', 211 _('Error: wrong domain in Auto-Responder'), 'sameDomain'); 212 $form->addRule('copy', 213 _("'Save a copy' must be an email address"), 'email', null, 'client'); 214 $form->addRule('subject', 215 _("Subject is required"), 'required', null, 'client'); 174 216 $form->addRule('body', _("Body is required"), 'required', null, 'client'); 175 217 return $form; 176 218 } 177 219 178 function delete() { 220 /** 221 * delete 222 * 223 * Show delete responder page 224 * 225 * @throws Framework_Exception if autorsponder is not supplied 226 * @access public 227 * @return void 228 */ 229 public function delete() 230 { 179 231 if (!isset($_REQUEST['autoresponder'])) { 180 return PEAR::raiseError(_("Error: no responder supplied")); 181 } 182 $this->setData('LANG_Are_you_sure_you_want_to_delete_this_responder', _("Are you sure you want to delete the responder")); 183 $this->setData('LANG_cancel', _("cancel")); 184 $this->setData('LANG_delete', _("delete")); 232 throw new Framework_Exception(_('Error: no responder supplied')); 233 } 185 234 $this->setData('autoresponder', $_REQUEST['autoresponder']); 186 $this->setData('cancel_url', "./?module=Responders&event=cancelDelete&domain=" . $this->domain); 187 $this->setData('delete_now_url', "./?module=Responders&event=deleteNow&domain=" . $this->domain . "&autoresponder=" . $_REQUEST['autoresponder']); 235 $this->setData('cancel_url', 236 "./?module=Responders&event=cancelDelete&domain=" . $this->domain); 237 $durl = "./?module=Responders&event=deleteNow&domain={$this->domain}"; 238 $durl .= "&autoresponder=" . $_REQUEST['autoresponder']; 239 $this->setData('delete_now_url', $durl); 188 240 $this->tplFile = 'responderConfirmDelete.tpl'; 189 241 } 190 242 191 function deleteNow() { 243 /** 244 * deleteNow 245 * 246 * Try and delete a responder 247 * 248 * @throws Framework_Exception if autoresponder is not supplied, 249 * or on failure 250 * @access public 251 * @return void 252 */ 253 public function deleteNow() 254 { 192 255 if (!isset($_REQUEST['autoresponder'])) { 193 return PEAR::raiseError(_("Error: no responder supplied")); 194 } 195 if (!isset($_REQUEST['domain'])) { 196 return PEAR::raiseError(_("Error: no domain supplied")); 197 } 198 $array = explode('@', $_REQUEST['autoresponder']); 256 throw new Framework_Exception(_('Error: no responder supplied')); 257 } 258 $array = explode('@', $_REQUEST['autoresponder']); 199 259 $result = $this->user->robotDel($this->domain, $array[0]); 200 if (PEAR::isError($result)) return $result;201 260 $this->setData('message', _("Responder Deleted Successfully")); 202 261 return $this->listResponders(); 203 262 } 204 263 205 function cancelDelete() { 264 /** 265 * cancelDelete 266 * 267 * Cancel delete responder, list responders 268 * 269 * @access public 270 * @return void 271 */ 272 public function cancelDelete() 273 { 206 274 $this->setData('message', _("Delete Canceled")); 207 $this->listResponders(); 208 return; 209 } 210 211 function modifyResponder() { 275 return $this->listResponders(); 276 } 277 278 /** 279 * modifyResponder 280 * 281 * Show modify responder page 282 * 283 * @access public 284 * @return void 285 */ 286 public function modifyResponder() 287 { 212 288 // Make sure account was supplied 213 289 if (!isset($_REQUEST['autoresponder'])) { 214 return PEAR::raiseError(_("Error: no Auto-Responder supplied")); 215 } 216 $array = explode('@', $_REQUEST['autoresponder']); 290 throw new Framework_Exception(_("Error: no Auto-Responder supplied")); 291 } 292 $array = explode('@', $_REQUEST['autoresponder']); 293 $responder = $this->user->robotGet($this->domain, $array[0]); 294 217 295 // Setup defaults 218 $responder = $this->user->robotGet($this->domain,$array[0]); 219 if (PEAR::isError($responder)) return $responder; 220 $defaults = array(); 221 $defaults['subject'] = $responder['Subject']; 222 $defaults['body'] = implode("\n", $responder['Message']); 296 $defaults = array(); 297 $defaults['subject'] = $responder['Subject']; 298 $defaults['body'] = implode("\n", $responder['Message']); 223 299 $defaults['autoresponder'] = $_REQUEST['autoresponder']; 224 300 if (isset($responder['Forward'])) { … … 226 302 } 227 303 228 $form = $this->responderForm('modify', $defaults);229 $renderer = &new HTML_QuickForm_Renderer_AssocArray();304 $form = $this->responderForm('modify', $defaults); 305 $renderer = new HTML_QuickForm_Renderer_AssocArray(); 230 306 $form->accept($renderer); 231 307 $this->setData('form', $renderer->toAssocArray()); … … 234 310 } 235 311 236 function modifyResponderNow() { 312 /** 313 * modifyResponderNow 314 * 315 * Actually modify the responder 316 * 317 * @access public 318 * @return void 319 */ 320 public function modifyResponderNow() 321 { 237 322 // Make sure account was supplied 238 323 if (!isset($_REQUEST['autoresponder'])) { 239 return PEAR::raiseError(_("Error: no Auto-Responder supplied")); 240 } 241 $array = explode('@', $_REQUEST['autoresponder']); 324 throw new Framework_Exception(_("Error: no Auto-Responder supplied")); 325 } 326 $array = explode('@', $_REQUEST['autoresponder']); 327 $responder = $this->user->robotGet($this->domain, $array[0]); 242 328 // Setup defaults 243 $responder = $this->user->robotGet($this->domain,$array[0]); 244 if (PEAR::isError($responder)) return $responder; 245 $defaults = array(); 246 $defaults['subject'] = $responder['Subject']; 247 $defaults['body'] = implode("\n", $responder['Message']); 329 $defaults = array(); 330 $defaults['subject'] = $responder['Subject']; 331 $defaults['body'] = implode("\n", $responder['Message']); 248 332 $defaults['autoresponder'] = $_REQUEST['autoresponder']; 333 249 334 $form = $this->responderForm('modify', $defaults); 250 335 if (!$form->validate()) { 251 $renderer = &new HTML_QuickForm_Renderer_AssocArray();336 $renderer = new HTML_QuickForm_Renderer_AssocArray(); 252 337 $form->accept($renderer); 253 338 $this->setData('form', $renderer->toAssocArray()); … … 256 341 } 257 342 $result = $this->user->robotDel($this->domain, $array[0]); 258 $result = $this->user->robotSet($this->domain, $array[0], $_POST['subject'], $_POST['body'], $_POST['copy']);259 if (PEAR::isError($result)) return $result;343 $result = $this->user->robotSet($this->domain, 344 $array[0], $_POST['subject'], $_POST['body'], $_POST['copy']); 260 345 $this->setData('message', _("Auto-Responder modified successfully")); 261 346 return $this->listResponders(); trunk/Framework/Module/Responders/Templates/Default/listResponders.tpl
r105 r265 1 1 <div class="boxtop"></div> 2 2 <div class="box"> 3 { $LANG_AutoResponders_in_domain} {$domain}3 {t}AutoResponders in domain{/t} {$domain} 4 4 </div> 5 5 <div class="boxbottom"></div> … … 7 7 <div class="boxtopDomains"> 8 8 <div class="boxtopDomainscontent"> 9 <h1>{ $LANG_AutoResponders_Page} {$currentPage} {$LANG_of} {$totalPages}</h1>9 <h1>{t}AutoResponders Page{/t} {$currentPage} {t}of{/t} {$totalPages}</h1> 10 10 {framework_pager start=$start limit=$limit total=$total} 11 <a href="{$add_url}">{ $LANG_Add_AutoResponder}</a>11 <a href="{$add_url}">{t}Add AutoResponder{/t}</a> 12 12 </div> 13 13 </div> … … 17 17 <table border="0" cellspacing="0" cellpadding="0" id="datatable"> 18 18 <tr> 19 <td class="domaincell">{ $LANG_AutoResponder}</td>20 <td class="domaincell">{ $LANG_Edit}</td>21 <td class="domaincell">{ $LANG_Delete}</td>19 <td class="domaincell">{t}AutoResponder{/t}</td> 20 <td class="domaincell">{t}Edit{/t}</td> 21 <td class="domaincell">{t}Delete{/t}</td> 22 22 </tr> 23 23 … … 25 25 <tr bgcolor="<?= $this->cycle('#dddddd,#eeeeee')?>"> 26 26 <td>{$autoresponder.autoresponder}</td> 27 <td><a href="{$autoresponder.edit_url}">{ $LANG_edit}</a></td>28 <td><a href="{$autoresponder.delete_url}">{ $LANG_delete}</a></td>27 <td><a href="{$autoresponder.edit_url}">{t}edit{/t}</a></td> 28 <td><a href="{$autoresponder.delete_url}">{t}delete{/t}</a></td> 29 29 </tr> 30 30 {/foreach} 31 31 </table> 32 <center><a href="{$domain_url}">{ $LANG_Domain_Menu}</a></center>32 <center><a href="{$domain_url}">{t}Domain Menu{/t}</a></center> 33 33 </div> 34 34 <div class="boxbottom"></div> trunk/Framework/Module/Responders/Templates/Default/responderConfirmDelete.tpl
r175 r265 1 1 <div class="boxtop"></div> 2 2 <div class="box"> 3 { $LANG_Are_you_sure_you_want_to_delete_this_responder} "{$autoresponder}"?3 {t}Are you sure you want to delete this responder{/t} "{$autoresponder}"? 4 4 <br> 5 <a href="{$cancel_url}">{ $LANG_cancel}</a>   |   <a href="{$delete_now_url}">{$LANG_delete}5 <a href="{$cancel_url}">{t}cancel{/t}</a>   |   <a href="{$delete_now_url}">{t}delete{/t} 6 6 </div> 7 7 <div class="boxbottom"></div> trunk/Framework/Module/Responders/Templates/Default/responderForm.tpl
r175 r265 1 1 <div class="boxtop"></div> 2 <div class="box">{$ LANG_responder_header}</div>2 <div class="box">{$responder_header}</div> 3 3 <div class="boxbottom"></div> 4 4 … … 41 41 42 42 <div class="boxtop"></div> 43 <div class="box"><a href="{$domain_url}">{ $LANG_Domain_Menu}</a></div>43 <div class="box"><a href="{$domain_url}">{t}Domain Menu{/t}</a></div> 44 44 <div class="boxbottom"></div>
