/**
  * Save a mailbox and either redirect the client or display the add/edit with errors
  * @param array $params the parameters for the request
  * @return array the vars and template for the mailbox adding/editing when there are errors saving
  */
 public function saveMailbox($params)
 {
     $openSRS = new openSRS_mail($params["configoption1"], $params["configoption2"], $params["configoption3"], $params["configoption4"], $params["configoption5"]);
     $success = false;
     if ($this->getVar("new")) {
         //$mailboxName = $this->getVar("mailbox");
         $mailboxName = $this->getVar("mailbox") . "@" . $params["domain"];
         $result = $openSRS->getMailbox($params["domain"], $mailboxName);
         if (!filter_var($mailboxName, FILTER_VALIDATE_EMAIL)) {
             $this->vars["error"][] = "Invalid Email format. (ex. john.doe or john_doe or johndoe)";
         } elseif (strlen($this->getVar("title")) > 60) {
             $this->vars["error"][] = "Maximum 60 charcters are allowed for Title. (ex. Ms. or Mr.)";
         } elseif (strlen($this->getVar("firstName")) > 255) {
             $this->vars["error"][] = "Maximum 255 charcters are allowed for First Name.";
         } elseif (strlen($this->getVar("lastName")) > 255) {
             $this->vars["error"][] = "Maximum 255 charcters are allowed for Last Name.";
         } elseif (strlen($this->getVar("phone")) > 30) {
             $this->vars["error"][] = "Maximum 30 charcters are allowed for Phone.";
         } elseif (strlen($this->getVar("fax")) > 30) {
             $this->vars["error"][] = "Maximum 30 charcters are allowed for Fax.";
         } else {
             if ($result["is_success"]) {
                 print_r($result);
                 $this->vars["error"][] = "The mailbox cannot be added because it already exists.";
                 return $this->addEditMailbox($params);
             } else {
                 if ($result["response_code"] == 2) {
                     $password = $this->getVar("password");
                     $passwordConfirm = $this->getVar("passwordConfirm");
                     $mailbox = $this->getVar("mailbox");
                     if (empty($password)) {
                         $this->vars["error"][] = "The password cannot be empty";
                     }
                     if ($password != $passwordConfirm) {
                         $this->vars["error"][] = "The passwords do not match";
                     }
                     if (empty($mailbox)) {
                         $this->vars["error"][] = "The mailbox name cannot be empty";
                     }
                     $aliases = $this->getVar("aliases");
                     if (!empty($aliases)) {
                         $aliasAddresses = explode("\n", $aliases);
                         foreach ($aliasAddresses as $alid => $aliasAddress) {
                             if (!$aliasAddress) {
                                 unset($aliasAddress[$alid]);
                                 continue;
                             }
                             $aliasAddress = trim($aliasAddress);
                             $aliasAddresses[$alid] = $aliasAddress;
                             if (!filter_var($aliasAddress, FILTER_VALIDATE_EMAIL)) {
                                 $this->vars["error"][] = "The alias address \"" . $aliasAddress . "\" is not valid.";
                             }
                         }
                         $aliasAddresses = $openSRS->validateAliasForward($params["domain"], $this->getVar("mailbox"), $aliasAddresses);
                     }
                     if (empty($this->vars["error"])) {
                         /*$result = $openSRS->createMailbox(
                            $params["domain"],
                            $mailboxName,
                            $this->getVar("workgroup"),
                            $password,
                            $this->getVar("firstName"),
                            $this->getVar("lastName"),
                            $this->getVar("title"),
                            $this->getVar("phone"),
                            $this->getVar("fax")
                           );*/
                         $result = $openSRS->createMailbox($params["domain"], $mailboxName, $this->getVar("workgroup"), $password, $this->getVar("firstName"), $this->getVar("lastName"), $this->getVar("title"), $this->getVar("phone"), $this->getVar("fax"), $aliasAddresses, $_GET["type"]);
                         if ($result["is_success"]) {
                             $success = "&added=true";
                         } else {
                             $this->vars["error"][] = $result["response_text"];
                         }
                     }
                 } else {
                     $this->vars["error"][] = $result["response_text"];
                 }
             }
         }
     } else {
         $mailboxName = $this->getVar("mailbox");
         $result = $openSRS->getMailbox($params["domain"], $mailboxName);
         if ($result["is_success"]) {
             $password = $this->getVar("password");
             $passwordConfirm = $this->getVar("passwordConfirm");
             $mailbox = $this->getVar("mailbox");
             if (!empty($password) && $password != $passwordConfirm) {
                 $this->vars["error"][] = "The passwords do not match";
             } elseif (strlen($this->getVar("title")) > 60) {
                 $this->vars["error"][] = "Maximum 60 charcters are allowed for Title. (ex. Ms. or Mr.)";
             } elseif (strlen($this->getVar("firstName")) > 255) {
                 $this->vars["error"][] = "Maximum 255 charcters are allowed for First Name.";
             } elseif (strlen($this->getVar("lastName")) > 255) {
                 $this->vars["error"][] = "Maximum 255 charcters are allowed for Last Name.";
             } elseif (strlen($this->getVar("phone")) > 30) {
                 $this->vars["error"][] = "Maximum 30 charcters are allowed for Phone.";
             } elseif (strlen($this->getVar("fax")) > 30) {
                 $this->vars["error"][] = "Maximum 30 charcters are allowed for Fax.";
             }
             $aliases = $this->getVar("aliases");
             if (!empty($aliases)) {
                 $aliasAddresses = explode("\n", $aliases);
                 foreach ($aliasAddresses as $alid => $aliasAddress) {
                     if (!$aliasAddress) {
                         unset($aliasAddress[$alid]);
                         continue;
                     }
                     $aliasAddress = trim($aliasAddress);
                     $aliasAddresses[$alid] = $aliasAddress;
                     if (!filter_var($aliasAddress, FILTER_VALIDATE_EMAIL)) {
                         $this->vars["error"][] = "The alias address \"" . $aliasAddress . "\" is not valid.";
                     }
                 }
                 $aliasAddresses = $openSRS->validateAliasForward($params["domain"], $this->getVar("mailbox"), $aliasAddresses);
             }
             if (empty($this->vars["error"])) {
                 /*$result = $openSRS->changeMailbox(
                 			$params["domain"],
                 			$mailboxName,
                 			$this->getVar("workgroup"),
                 			$password,
                 			$this->getVar("firstName"),
                 			$this->getVar("lastName"),
                 			$this->getVar("title"),
                 			$this->getVar("phone"),
                 			$this->getVar("fax")
                 		);*/
                 $result = $openSRS->changeMailbox($params["domain"], $mailboxName, $this->getVar("workgroup"), $password, $this->getVar("firstName"), $this->getVar("lastName"), $this->getVar("title"), $this->getVar("phone"), $this->getVar("fax"), $aliasAddresses, $_GET["type"]);
                 if ($result["is_success"]) {
                     $success = "&edited=true";
                 } else {
                     $this->vars["error"][] = $result["response_text"];
                 }
             }
         } else {
             $this->vars["error"][] = $result["response_text"];
         }
     }
     if ($success) {
         header("Location: /clientarea.php?action=productdetails&id=" . $params["serviceid"] . $success);
     } else {
         return $this->addEditMailbox($params);
     }
 }
 /**
  * Save a mailbox and either redirect the client or display the add/edit with errors
  * @param array $params the parameters for the request
  * @return array the vars and template for the mailbox adding/editing when there are errors saving
  */
 public function saveMailbox($params)
 {
     $openSRS = new openSRS_mail($params["configoption1"], $params["configoption2"], $params["configoption3"], $params["configoption4"], $params["configoption5"]);
     $success = false;
     if ($this->getVar("new")) {
         $mailboxName = $this->getVar("mailbox");
         $result = $openSRS->getMailbox($params["domain"], $mailboxName);
         if ($result["is_success"]) {
             $this->vars["error"][] = "The mailbox cannot be added because it already exists.";
             return $this->addEditMailbox($params);
         } else {
             if ($result["response_code"] == 17) {
                 $password = $this->getVar("password");
                 $passwordConfirm = $this->getVar("passwordConfirm");
                 $mailbox = $this->getVar("mailbox");
                 if (empty($password)) {
                     $this->vars["error"][] = "The password cannot be empty";
                 }
                 if ($password != $passwordConfirm) {
                     $this->vars["error"][] = "The passwords do not match";
                 }
                 if (empty($mailbox)) {
                     $this->vars["error"][] = "The mailbox name cannot be empty";
                 }
                 if (empty($this->vars["error"])) {
                     $result = $openSRS->createMailbox($params["domain"], $mailboxName, $this->getVar("workgroup"), $password, $this->getVar("firstName"), $this->getVar("lastName"), $this->getVar("title"), $this->getVar("phone"), $this->getVar("fax"));
                     if ($result["is_success"]) {
                         $success = "&added=true";
                     } else {
                         $this->vars["error"][] = $result["response_text"];
                     }
                 }
             } else {
                 $this->vars["error"][] = $result["response_text"];
             }
         }
     } else {
         $mailboxName = $this->getVar("mailbox");
         $result = $openSRS->getMailbox($params["domain"], $mailboxName);
         if ($result["is_success"]) {
             $password = $this->getVar("password");
             $passwordConfirm = $this->getVar("passwordConfirm");
             $mailbox = $this->getVar("mailbox");
             if (!empty($password) && $password != $passwordConfirm) {
                 $this->vars["error"][] = "The passwords do not match";
             }
             if (empty($this->vars["error"])) {
                 $result = $openSRS->changeMailbox($params["domain"], $mailboxName, $this->getVar("workgroup"), $password, $this->getVar("firstName"), $this->getVar("lastName"), $this->getVar("title"), $this->getVar("phone"), $this->getVar("fax"));
                 if ($result["is_success"]) {
                     $success = "&edited=true";
                 } else {
                     $this->vars["error"][] = $result["response_text"];
                 }
             }
         } else {
             $this->vars["error"][] = $result["response_text"];
         }
     }
     if ($success) {
         header("Location: clientarea.php?action=productdetails&id=" . $params["serviceid"] . $success);
     } else {
         return $this->addEditMailbox($params);
     }
 }