Changeset 224
- Timestamp:
- 12/09/07 11:45:21 (1 year ago)
- Files:
-
- trunk/Framework/Module/Forwards.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Framework/Module/Forwards.php
r222 r224 36 36 * __construct 37 37 * 38 * class constructor39 * 40 * @access p rotected41 * @return result of listForwards()42 */ 43 function __construct() {38 * Check that a domain was supplied 39 * 40 * @access public 41 * @return void 42 */ 43 public function __construct() { 44 44 parent::__construct(); 45 $this->noDomainSupplied() )) {45 $this->noDomainSupplied(); 46 46 } 47 47 … … 49 49 * __default 50 50 * 51 * @access protected 51 * Run listForwards() by default 52 * 53 * @access public 52 54 * @return void 53 55 */ 54 function __default() {56 public function __default() { 55 57 return $this->listForwards(); 56 58 } … … 59 61 * listForwards 60 62 * 63 * List Forwards 64 * 61 65 * @access public 62 66 * @return void 63 67 */ 64 function listForwards() {68 public function listForwards() { 65 69 66 70 // Pagintation setup … … 112 116 * addForward 113 117 * 118 * Show Add Forward form 119 * 114 120 * @access public 115 121 * @return mixed void on success, PEAR_Error on failure 116 122 */ 117 function addForward() {123 public function addForward() { 118 124 $form = $this->addForwardForm(); 119 125 $renderer =& new HTML_QuickForm_Renderer_AssocArray(); … … 121 127 $this->setData('form', $renderer->toAssocArray()); 122 128 $this->tplFile = 'addForward.tpl'; 129 return; 123 130 } 124 131 … … 126 133 * addForwardForm 127 134 * 128 * @access public 129 * @return object $form 130 */ 131 function addForwardForm() { 135 * Create Add Forward Form 136 * 137 * @access private 138 * @return object $form HTML_QuickForm Object 139 */ 140 private function addForwardForm() { 132 141 // Lang 133 142 $this->setData('LANG_Forward_Name', _("Forward Name")); … … 155 164 * addForwardNow 156 165 * 166 * Try and actually add a forward 167 * 157 168 * @access public 158 169 * @return mixed PEAR_Error on failure, listForwards() on success 159 170 */ 160 function addForwardNow() {171 public function addForwardNow() { 161 172 $form = $this->addForwardForm(); 162 173 if (!$form->validate()) { … … 171 182 $this->setData('destination', $_REQUEST['destination']); 172 183 173 $result = $this->addForwardLine(); 174 if (PEAR::isError($result)) { 175 if ($result->getMessage() == 'Forward Exists') { 176 $this->setData('message', _("Forward already exists")); 177 return $this->addForward(); 178 } 179 return $result; 184 try { 185 $this->addNewForward(); 186 } catch (Exception $e) { 187 $this->setData('message', $e->getMessage()); 188 return $this->addForward(); 180 189 } 181 190 $this->setData('message', _("Forward Added Successfully")); … … 184 193 185 194 /** 195 * addNewForward 196 * 197 * Add new forward file 198 * 199 * @access protected 200 * @return void 201 */ 202 protected function addNewForward() 203 { 204 $file = '.qmail-' . $this->data['forward']; 205 // Verify that it doesn't exist 206 try { 207 $contents = $this->user->readFile($this->domain, '', $file); 208 } catch (Net_Vpopmaild_Exception $e) { 209 if ($e->getCode() != 0.2102) { 210 throw new Framework_Exception($e->getMessage(), $e->getCode()); 211 } 212 } 213 214 $contents = array('&' . $this->data['destination']); 215 $result = $this->user->writeFile($contents, $this->domain, '', $file); 216 return true; 217 } 218 219 /** 186 220 * addForwardLine 187 221 * 188 * @param string $type 222 * Add forward line to existing forward 223 * 189 224 * @access protected 190 * @return mixed true on success, PEAR_Error on failure 191 */ 192 protected function addForwardLine($type = 'new') { 193 194 $contents = $this->user->readFile($this->domain, '', ".qmail-" . $this->data['forward']); 195 if ($type == 'new') { 196 if (!PEAR::isError($contents)) { 197 return PEAR::raiseError('Forward Exists'); 198 } else if ($contents->getMessage() != '-ERR 2102 No such file or directory') { 199 return $contents; 200 } else { 201 $contents = array(); 202 } 203 } else { 204 if (PEAR::isError($contents)) return $contents; 205 } 206 225 * @return bool true on success, false if forward exists 226 */ 227 protected function addForwardLine() 228 { 229 $file = '.qmail-' . $this->data['forward']; 230 // Let exception bubble up 231 $contents = $this->user->readFile($this->domain, '', $file); 232 $destination = '&' . $this->data['destination']; 207 233 // Now build a new array without that forward 208 if (in_array("&" . $this->data['destination'], $contents)) { 209 $this->setData('message', 'Error: destination already exists'); 210 return $this->modifyForward(); 211 } 212 array_push($contents, "&" . $this->data['destination']); 213 $result = $this->user->writeFile($contents, $this->domain, '', ".qmail-" . $this->data['forward']); 214 if (PEAR::isError($result)) { 215 return $result; 216 } 234 if (in_array($destination, $contents)) { 235 return false; 236 } 237 array_push($contents, $destination); 238 $result = $this->user->writeFile($contents, $this->domain, '', $file); 217 239 return true; 218 240 } … … 332 354 $this->setData('destination', $_REQUEST['destination']); 333 355 334 $result = $this->addForwardLine($type = 'modify'); 335 if (PEAR::isError($result)) { 336 if ($result->getMessage() == 'Error: destination already exists') { 337 $this->setData('message', _("Error: destination already exists")); 338 return $this->modifyForward(); 339 } else { 340 return $result; 341 } 356 if (!$this->addForwardLine()) { 357 $this->setData('message', _("Error: destination already exists")); 358 return $this->modifyForward(); 342 359 } 343 360 $this->setData('message', _("Destination Added Successfully")); … … 419 436 * deleteForward 420 437 * 421 * @access p ublic438 * @access protected 422 439 * @return mixed listForwards() on success, PEAR_Error on failure 423 440 */ 424 function deleteForward() {441 protected function deleteForward() { 425 442 // Make sure forward was supplied 426 443 if (!isset($_REQUEST['forward'])) {
