<?PHP
#
#   FILE:  EditPasswordMailComplete.php
#
#   Part of the Collection Workflow Integration System (CWIS)
#   Copyright 2001-2013 Edward Almasy and Internet Scout Research Group
#   http://scout.wisc.edu/cwis/
#

# ----- EXPORTED FUNCTIONS ---------------------------------------------------

# ----- LOCAL FUNCTIONS ------------------------------------------------------

# ----- MAIN -----------------------------------------------------------------

# check if current user is authorized
if (!CheckAuthorization(PRIV_SYSADMIN, PRIV_USERADMIN)) {  return;  }

if (isset($_POST["F_PasswordMailSubject"]))
    $F_PasswordMailSubject = $_POST["F_PasswordMailSubject"];
else
    $F_PasswordMailSubject = $Session->Get("F_PasswordMailSubject");

if (isset($_POST["F_PasswordMailBody"]))
    $F_PasswordMailBody = $_POST["F_PasswordMailBody"];
else
    $F_PasswordMailBody = $Session->Get("F_PasswordMailBody");

# if save changes was requested
if ($_POST["Submit"] != "Cancel")
{
    # if new e-mail subject is valid
    $F_PasswordMailSubject = trim($F_PasswordMailSubject);
    if (strlen($F_PasswordMailSubject) > 0)
    {
        # save new e-mail subject
        $SysConfig->PasswordMailSubject($F_PasswordMailSubject);
    }
    else
    {
        # add error message to error list
        $ErrorMessages = new ErrorList();
        $ErrorMessages->AddMessage(
                "The subject line must contain some text.");
        $Session->PassVariable("F_PasswordMailSubject");
    }

    # if new e-mail body is valid
    $F_PasswordMailBody = trim($F_PasswordMailBody);
    if ((substr_count($F_PasswordMailBody, "X-ACTIVATIONURL-X") > 0)
            || ((substr_count($F_PasswordMailBody, "X-MANUALACTIVATIONURL-X") > 0)
                && (substr_count($F_PasswordMailBody, "X-USERNAME-X") > 0)
                && (substr_count($F_PasswordMailBody, "X-ACTIVATIONCODE-X") > 0)))
    {
        # save new e-mail body
        $SysConfig->PasswordMailBody($F_PasswordMailBody);
    }
    else
    {
        # add error message to error list
        $ErrorMessages = new ErrorList();
        $ErrorMessages->AddMessage(
                "The message body must, at minimum, contain the special string"
                ." for either the <b>activation URL</b> or the"
                ." <b>user name</b>, <b>activation code</b>, and <b>manual activation URL</b>.");
        $Session->PassVariable("F_PasswordMailBody");
    }
}

# if errors were found
if (isset($ErrorMessages))
{
    # return to editing page with error messages
    $Session->PassVariable("ErrorMessages");
    $AF->SetJumpToPage("EditPasswordMail");
}
else
{
    # go to classification selection page for parent of edited classification
    $AF->SetJumpToPage("SysAdmin");
}

?>
