Location: PHPKode > scripts > Virtual Mail ManaGer Interface > virtual-mail-manager-interface/main.php
<?php

include "auth.php";

include_once(dirname(__FILE__) . '/vm/vm.php');
include_once(dirname(__FILE__) . '/inc/common.php');
include_once(dirname(__FILE__) . '/inc/util.php');
include_once(dirname(__FILE__) . '/config.php');

/* vmailmgr interface  */
$vm = new my_vmailmgr($_SESSION['domain'], rc4_decrypt($salt, $_SESSION['password']));

/* clean up form data */
if(ini_get("magic_quotes_gpc")) {
  $_GET['query'] = stripslashes($_GET['query']);
}

/* display page */
echo template_replace($parts['header'], array(
  'title'     => $language['main']['title'],
  'character' => $language['language']['encoding']
));

echo template_replace($parts['main_header'], array(
  'header'         => $language['main']['header'],
  'confirm_delete' => $language['main']['confirm_delete']
));

echo template_replace($parts['navigation'], array(
  'overview'    => $language['navigation']['overview'],
  'add_account' => $language['navigation']['add_account'],
  'add_alias'   => $language['navigation']['add_alias'],
  'settings'    => $language['navigation']['settings'],
  'logout'      => $language['navigation']['logout']
));

echo template_replace($parts['quicksearch'], array(
  'quicksearch' => $language['main']['quicksearch'],
  'search'      => $language['main']['search'],
  'query_value' => htmlentities($_GET['query'])
));

/* just in case creating the user list takes a while. when the users
   sees the header, it is more likely that he or she will wait for the
   complete output than pressing nervously reload and creating unnecessary
   load on the server. */
flush();

if(($list = $vm->list_users()) === false) {
  echo '<b>Fatal Error</b>: Could not list users';
}
else {

  /* sorting */
  switch($_GET['sort']) {
    case 'personal':
      array_subkey_sort($list, "personal");        
      break;    

    case 'rpersonal':
      array_subkey_rsort($list, "personal");        
      break;

    case 'raddress':    
      array_subkey_rsort($list, "username");        
      break;
      
    default:
      array_subkey_sort($list, "username");        
      break;
  }

  /* filtering */
  if(count($list) > 0) { /* why the fuck does foreach() output an error message on empty arrays? */
    foreach($list as $key => $info) {

      /* skip catchall account */
      if($info['username'] == '+') {
        $catchall = $list[$key];
        unset($list[$key]);
      }
      /* perform a search ? */
      else if(trim($_GET['query']) != '') {

        if(is_similar($_GET['query'], $info['username']) || is_similar($_GET['query'], $info['personal'])) {
          continue;
	}
        else {
          unset($list[$key]);
        }
	
      }
    }
  }

  if(trim($_GET['query'] != '')) {
    echo template_replace($parts['quicksearch_result'], array(
      'search_result' => sprintf($language['main']['search_result'], count($list)),
      'all_entries'   => $language['main']['all_entries']
    ));
  }

  echo template_replace($parts['main_table_start'], array(
    'link_address_asc'   => basename($_SERVER['PHP_SELF']) . "?" . build_query(array('sort' => 'address'), array('query')),
    'link_address_desc'  => basename($_SERVER['PHP_SELF']) . "?" . build_query(array('sort' => 'raddress'), array('query')),
    'link_personal_asc'  => basename($_SERVER['PHP_SELF']) . "?" . build_query(array('sort' => 'personal'), array('query')),
    'link_personal_desc' => basename($_SERVER['PHP_SELF']) . "?" . build_query(array('sort' => 'rpersonal'), array('query')),
    'image_sort_asc'     => $parts['image_sort_asc'],
    'image_sort_desc'    => $parts['image_sort_desc'],
    'address'            => $language['main']['address'],
    'full_name'          => $language['main']['full_name'],
    'forwards'           => $language['main']['forwards'],
    'autoresponder'      => $language['main']['autoresponder']
  ));


  if(count($list) == 0) {
    echo template_replace($parts['main_table_message'], array(
      'message' => $language['main']['none']
    ));
  }
  else {
  
    foreach($list as $key => $info) {

      if(count($info['forwards']) == 0) {
        $forwards = "&nbsp;";
      }
      else {     
        $forwards = @join("<br>", $info['forwards']);
      }

      echo template_replace($info['flags']['mailbox_enabled'] ? $parts['main_table_element'] : $parts['main_table_element_disabled'], array(
        'type'         => $info['mailboxdir'] == '' ? '<img src="templates/default/forward.gif">' : '<img src="templates/default/mailbox.gif">',
     	'username'     => $info['username'],
  	'domain'       => $_SESSION['domain'],
	'personal'     => $info['personal'],
	'forwards'     => $forwards,
        'autoresponse' => $info['mailboxdir'] == '' ? '' : ($vm->autoresponse_isset($info['username']) ? $language['main']['enabled'] : $language['main']['disabled']),
	'image_edit'   => $parts['image_edit'],
        'image_remove' => $parts['image_remove']
      ));
    }
  }
}

echo template_replace($parts['main_table_end'], array(
  'account'       => $language['main']['account'],
  'alias'         => $language['main']['alias'],
  'edit'          => $language['main']['edit'],
  'remove'        => $language['main']['remove'],
  'image_account' => $parts['image_account'],
  'image_alias'   => $parts['image_alias'],
  'image_edit'    => $parts['image_edit'],
  'image_remove'  => $parts['image_remove']
));  

if(trim($_GET['query'] == '')) {
  echo template_replace($parts['main_catchall_start'], array(
    'catchall'      => $language['main']['catchall'], 
    'catchall_none' => $language['main']['catchall_none']
  ));  

  if(count($info) > 0) {
    foreach($list as $key => $info) {
      if($catchall['forwards'][0] == $info['username']) {
        echo template_replace($parts['main_catchall_element_selected'], array(
          'name' => $info['username']
        ));
      }
      else {
        echo template_replace($parts['main_catchall_element'], array(
          'name' => $info['username']
        ));
      }
    }
  }
  
  echo template_replace($parts['main_catchall_end'], array(
    'catchall_set'  => $language['main']['catchall_set'],
    'catchall_text' => $language['main']['catchall_text']
  ));
}

echo $parts['main_footer'];

echo $parts['footer'];

?>
Return current item: Virtual Mail ManaGer Interface