Location: PHPKode > projects > XMail PHP Admin Interface (XPAI) > xpai/includes/uservars.php
<?php
if (!$in_xpai)
  die;

if (($_SESSION['loginstatus'] >= $login_level['LoginUser']) && ($_SESSION['edit_user'] != "*") && ($_SESSION['edit_domain'] != "*"))
{
  echo "<h1><a href=\"javascript:help('xpai_help.html#uservars','".$helpwidth."','".$helpheight."')\"><img src='gfx/ico_help.png' alt='Help' border='0'></a>&nbsp;&nbsp;";
  echo "Details for user<br><span class=\"blue\">".$_SESSION['edit_user']."@".$_SESSION['edit_domain']."</span></h1>";

  if (!isset($_REQUEST['Go']))
  {
    $user = $mail_server->userlist($_SESSION['edit_domain'], $_SESSION['edit_user']);
    $password = $user[0][2];

    $vars = $mail_server->uservars($_SESSION['edit_domain'], $_SESSION['edit_user']);

    $IMAP_active = false;
    if (isset($enable_IMAP) && $enable_IMAP)
    {
      foreach ($vars as $var)
      {
        if ($var[0] == $IMAP_configword)
        {
          if ($var[1] == "1")
          {
            $IMAP_active = true;
            break;
          }
        }
      }
    }

    if ($_SESSION['loginstatus'] >= $login_level['LoginPostmaster'])
    {
?>
  <form name='frmUserDetails' action='main.php' method='post'>
    <input type='hidden' name='action' value='uservars'>
    <input type='hidden' name='subaction' value='Password'>
    <input type='hidden' name='Go' value='true'>
<?
      if (isset($enable_IMAP) && $enable_IMAP)
      {
?>  
    <input type='hidden' name='IMAP_old_status' value='<? echo ($IMAP_active ? "1" : "0"); ?>'>
<?
      }
?>
    <table border='0' class='tbl'>
      <tr>
        <th width="10"></th>
        <th width="150"></th>
        <th width="*"></th>
      </tr>
      <tr>
        <td rowspan='3'>&nbsp;</td>
        <td><strong>User name:<strong></td>
        <td>
          <input type='text' name='username' readonly='yes' size='30' style='width: 400px;' value='<?php echo $_SESSION['edit_user']; ?>'>
        </td>
      </tr>
      <tr>
        <td><strong>User password:</strong></td>
        <td>
          <input type='password' name='password1' size='30' style='width: 400px;'>
        </td>
      </tr>
      <tr>
        <td><strong>User password (repeat):</strong></td>
        <td>
          <input type='password' name='password2' size='30' style='width: 400px;'> 
        </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><input type='submit' name='save' value=' Change password '></td>
      </tr>
    </table>
  </form>
<?php
    }
?>
  <form name='frmUserVars' action='main.php' method='post'>
    <input type='hidden' name='action' value='uservars'>
    <input type='hidden' name='subaction' value='uservars'>
    <input type='hidden' name='Go' value='true'>
    <table border='0' class='tbl'>
      <tr>
        <th width="10"></th>
        <th width="150"></th>
        <th width="*"></th>
      </tr>
<?php
    foreach ($vars as $var)
    {
      if (isset($enable_IMAP) && $enable_IMAP)
      {
        if ($var[0] == $IMAP_configword)
        {
          continue;
        }
      }
      if (($_SESSION['loginstatus'] >= $login_level['LoginPostmaster']) || in_array($var[0], $user_show_fields))
      {
?>
        <tr>
          <td>&nbsp;</td>
          <td><strong><?php echo $var[0]; ?><strong></td>
          <td>
<?php
        if (($_SESSION['loginstatus'] == $login_level['LoginSuperuser']) || (($_SESSION['loginstatus'] >= $login_level['LoginPostmaster']) && in_array($var[0], $postmaster_edit_fields))  || in_array($var[0], $user_edit_fields))
          echo "<input type='text' name='var_".$var[0]."' size='30' style='width: 400px;' value='".$var[1]."'>";
        else
          echo "$var[1]";
?>
          </td>
        </tr>
<?php
      }
    }
    if (($_SESSION['loginstatus'] == $login_level['LoginSuperuser']) || ($_SESSION['loginstatus'] >= $login_level['LoginPostmaster'] && in_array("Custom", $postmaster_edit_fields)))
    {
?>
      <tr>
        <td>&nbsp;</td>
        <td>
          <input type='text' name='xtr_var' size='30' style='width: 150px;'>
        </td>
        <td>
          <input type='text' name='xtr_value' size='30' style='width: 400px;'>
        </td>
      </tr>
<?php
    }
?>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><input type='submit' name='save' value=' Save values '></td>
      </tr>
    </table>
  </form>

<?php
    if (isset($enable_filters) && $enable_filters && count($filter_files))
    {
?>
  <h1>Filter settings</h1>
  
  <form name='frmUserFilter' action='main.php' method='post'>
    <input type='hidden' name='action' value='uservars'>
    <input type='hidden' name='subaction' value='filter'>
    <input type='hidden' name='Go' value='true'>
    <table border='0' class='tbl'>
      <tr>
        <th width="10"></th>
        <th width="150"></th>
        <th width="*"></th>
      </tr>
<?php
      $filters_is = $mail_server->get_filtersin($_SESSION['edit_user']."@".$_SESSION['edit_domain']);
      foreach ($filter_files as $filter_key => $filter_value)
      {
        $enabled = false;
        foreach ($filters_is as $filter_is)
        {
          if ($filter_is == $filter_value)
          {
            $enabled = true;
            break;
          }
        }
?>
      <tr>
        <td><input type='checkbox' name='filter_<?php echo $filter_value; ?>' <?php if ($enabled) echo 'checked'; ?>></td>
        <td><strong><?php echo $filter_key; ?><strong></td>
      </tr>
<?php
      }
?>     
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><input type='submit' name='save' value=' Save values '></td>
      </tr>
    </table>
  </form>
<?php 
    }

    if ($_SESSION['edit_user_type'] != 'M')
    {
      if (isset($enable_IMAP) && $enable_IMAP)
      {
?>  
  <h1>IMAP Settings</h1>

  <form name='frmUserIMAP' action='main.php' method='post'>
    <input type='hidden' name='action' value='uservars'>
    <input type='hidden' name='subaction' value='IMAP'>
    <input type='hidden' name='Go' value='true'>
    <input type='hidden' name='IMAP_old_status' value='<? echo ($IMAP_active ? "1" : "0"); ?>'>
    <table border='0' class='tbl'>
      <tr>
        <th width="10"></th>
        <th width="150"></th>
        <th width="*"></th>
      </tr>
      <tr>
      <td><input type='checkbox' name='IMAP_status' <?php if ($IMAP_active) echo 'checked'; ?>></td>
      <td><strong>IMAP<strong></td>
      </tr>
      <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><input type='submit' name='save' value=' Save values '></td>
      </tr>
    </table>
  </form>
<?php
      } 
    }

    if ($_SESSION['edit_user_type'] != 'M')
    {
?>  
  <h1>Statistic data</h1>

  <table border='0' class='tbl'>
    <tr>
      <th width="10"></th>
      <th width="150"></th>
      <th width="*"></th>
    </tr>
<?php
      $ustats = $mail_server->userstats($_SESSION['edit_domain'], $_SESSION['edit_user']);
      if (is_array($ustats))
      {
        foreach($ustats as $stats)
        {
?>
    <tr>
      <td>&nbsp;</td>
      <td><strong><?php echo "$stats[0]";?></strong></td>
      <td><strong><?php echo "$stats[1]";?></strong></td>
    </tr>
<?php
        }
      } else {
        echo "<strong>Not available.</strong><br><br>";
      }
    }
?>
  </table>
  <h1><br>User aliases</h1>
  <table border='0' class='tbl'>
    <tr>
      <th width="10"></th>
      <th width="150"></th>
      <th width="*"></th>
    </tr>
<?php
    $aliaslist = $mail_server->aliaslist("*", "*", $_SESSION['edit_user'].'@'.$_SESSION['edit_domain']);
    if (!isset($aliaslist[0]))
    {
      echo "<tr>";
      echo "<td>&nbsp;</td>";
      echo "<td><strong>No aliases defined.</strong><br><br></td>";
    } else {
      sort($aliaslist);
      foreach($aliaslist as $alias) {
        echo '<tr>';
        if ($_SESSION['loginstatus'] >= $login_level['LoginPostmaster'])
        {
?>
      <td>
        <a href="main.php?action=aliasdel&orig=uservars&sel_alias=<?php echo $alias[1]; ?>&sel_aliasdom=<?php echo $alias[0]; ?>" onclick="return window.confirm('Really delete alias <?php echo $alias[1]."@".$alias[0]; ?>?')">
          <img src='gfx/ico_delete.png' alt='Delete user alias' border='0'>
        </a>
      </td>
<?php
         } else {
           echo '<td>&nbsp;</td>';
         }
         echo '<td>'.$alias[1].'@'.$alias[0].'</td>';
      }
    }
    echo "</tr></table><br><br>";
  } else {
    if ($_REQUEST['subaction'] == 'Password')
    {
      if ($_REQUEST['password1'] != "")
      {
        if (!strcmp($_REQUEST['password1'], $_REQUEST['password2']) && !strcmp(htmlentities($_REQUEST['password1']), $_REQUEST['password1']))
        {
          if ($mail_server->userpasswd($_SESSION['edit_domain'], $_SESSION['edit_user'], $_REQUEST['password1']))
          {
//            echo "Password for <strong>".$_SESSION['edit_user']."@".$_SESSION['edit_domain']."</strong> was changed successfully.<br>";
            echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
            if (isset($enable_IMAP) && $enable_IMAP && ($_REQUEST['IMAP_old_status'] == "1"))
            {
              $mail_server->update_IMAP($_SESSION['edit_user']."@".$_SESSION['edit_domain'], $_SESSION['edit_user'], $_SESSION['edit_domain'], $_REQUEST['password1'], "PASSWORD", true, true, true); 
            }
            
          } else {
            echo "Password for <strong>".$_SESSION['edit_user']."@".$_SESSION['edit_domain']."</strong> could not be changed.<br>";
            echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
          }
        } else {
          if (strcmp(htmlentities($_REQUEST['password1']), $_REQUEST['password1']))
            echo "Passwords contains illegal characters - changed failed.<br>";
          else 
            echo "Passwords are not identical - changed failed.<br>";
        }
      } else {
        echo "Password is empty - changed failed.<br>";
      }
    } else {
      if ($_REQUEST['subaction'] == 'uservars')
      {
        $vars = '';
        $contain_illegal = false;
        $add_tab = "";
        foreach($_REQUEST as $var=>$val) 
        {
          if (ereg("var_", $var)) 
          {
            $var = substr($var, 4);
            if ($val == '') $val = '.|rm';
            $vars .= $add_tab."$var\t$val";
            $add_tab = "\t";
            if (strcmp(htmlentities($var), $var) || strcmp(htmlentities($val), $val))
            {
              $contain_illegal = true;          
            }
          }
        }
        if (($_SESSION['loginstatus'] >= $login_level['LoginPostmaster']) && !$contain_illegal)
        {
          if ($_REQUEST['xtr_var'] != '' && $_REQUEST['xtr_value'] != '') 
          {
            $vars .= str_replace(" ", "", $add_tab.$_REQUEST['xtr_var'])."\t".$_REQUEST['xtr_value'];
            if (strcmp(htmlentities($_REQUEST['xtr_var']), $_REQUEST['xtr_var']) || strcmp(htmlentities($_REQUEST['xtr_value']), $_REQUEST['xtr_value']))
            {
              $contain_illegal = true;
            }
          }
        }
        if (!$contain_illegal)
        {
          if ($mail_server->uservarsset($_SESSION['edit_domain'], $_SESSION['edit_user'], $vars)) {
            echo "Values for <strong>".$_SESSION['edit_user']."@".$_SESSION['edit_domain']."</strong> were saved successfully<br>";
            echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
          } else {
            echo "Values for <strong>".$_SESSION['edit_user']."@".$_SESSION['edit_domain']."</strong> could not be saved.<br>";
            echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
          }
        } else {
          echo "User variables and/or values contained illegal characters - discarded.<br>";
        }
      } else {
        if (isset($enable_filters) && $enable_filters && ($_REQUEST['subaction'] == 'filter'))
        {
          foreach ($filter_files as $filter_value)
          {
            $filter_name = ereg_replace("\.", "_", $filter_value);
            $mail_server->upd_filtersin($_SESSION['edit_user']."@".$_SESSION['edit_domain'], $filter_value, (isset($_REQUEST["filter_".$filter_name]) ? 1 : 0)); 
          }
          echo "Filter settings for <strong>".$_SESSION['edit_user']."@".$_SESSION['edit_domain']."</strong> were changed successfully.<br>";
          echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
        } else {
          if (isset($enable_IMAP) && $enable_IMAP && ($_REQUEST['subaction'] == 'IMAP'))
          {
            if ((isset($_REQUEST['IMAP_status']) ? "1" : "0") !=  $_REQUEST['IMAP_old_status'])
            {
              $vars = $IMAP_configword."\t".(isset($_REQUEST['IMAP_status']) ? "1" : "0");
              $mail_server->uservarsset($_SESSION['edit_domain'], $_SESSION['edit_user'], $vars);
              $user = $mail_server->userlist($_SESSION['edit_domain'], $_SESSION['edit_user']);
              if ($mail_server->update_IMAP($_SESSION['edit_user']."@".$_SESSION['edit_domain'], $_SESSION['edit_user'], $_SESSION['edit_domain'], $user[0][2], (isset($_REQUEST['IMAP_status']) ? "CREATE" : "DELETE"), true, true, true))
              { 
                echo "IMAP settings for <strong>".$_SESSION['edit_user']."@".$_SESSION['edit_domain']."</strong> were changed successfully.<br>";
                echo "Server result: ".$_SESSION['LastXMAILResult']."<br><br>";
              } else {
                echo "Unable to change IMAP settings for <strong>".$_SESSION['edit_user']."@".$_SESSION['edit_domain']."</strong>.<br><br>";
              }
            } else {
              echo "No change in IMAP settings for <strong>".$_SESSION['edit_user']."@".$_SESSION['edit_domain']."</strong>.<br>";
            }
          }
        }
      }
    }
  ?>
  <form action='main.php' method='post'>
    <input type='hidden' name='action' value='uservars'>
    <input type='hidden' name='domain' value='<?php echo $_SESSION['edit_domain']; ?>'>
    <input type='hidden' name='username' value='<?php echo $_SESSION['edit_user']; ?>'>
    <input type='submit' name='click' style='width: 50px;' value=' OK '>
  </form>

<?php
  }
} else {
  echo "<br><br><h2>Authorization failed to access this function!</h2><br><br>";
} ?>

Return current item: XMail PHP Admin Interface (XPAI)