<?
########## Confixx(R) 3.0 Professional ############
####### Copyright SWsoft, Inc. 2004-2005 ##########
#### http://www.sw-soft.com - info@sw-soft.com ####

#
#
#
$DEBUG=0;
#
#
#

if($DEBUG){
  echo "maillist.php<br>\n";
}

include("auth.php");
//error_reporting(E_ALL);

global $db_type;
if($db_type != 'mysql'){
  include("../include/class.Pgsql.php");
}else{
  include("../include/class.Mysql.php");
}

include("../include/class.Data.php");
include("../include/class.Page.php");
include("../include/class.Cond.php");
include("../include/module.Informer.php");

//include("../include/page_functions.php");
include("../include/template/csmarty.php");

include("../events.inc.php");
include("../include/event_functions.php");

//error_reporting(E_ALL);
//echo E_ALL;
$tpl = new CSmarty();
$page = new MailListPage($PHP_AUTH_USER, $tpl);

if ( array_key_exists('maillist', $_POST) ) {
  $maillist = strtolower( trim( $_POST['maillist'] ) );
} else {
  $maillist = false;
}

if (array_key_exists('save', $_POST)){

  if ($page->save( $maillist, 
		  array_key_exists('domain', $_POST)?$_POST['domain']:false, 
		  array_key_exists('owner', $_POST)?$_POST['owner']:false, 
		  array_key_exists('pass1', $_POST)?$_POST['pass1']:false, 
		  array_key_exists('pass2', $_POST)?$_POST['pass2']:false, 
		  array_key_exists('id', $_POST)?$_POST['id']:false )){
    $page->buldMailList();

    eventAdd($OBJECT_MLLIST,$EVENT_NEW,NULL);
  }else {

    $page->buildForm( $maillist, 
		     array_key_exists('domain', $_POST)?$_POST['domain']:false, 
		     array_key_exists('owner', $_POST)?$_POST['owner']:false, 
		     array_key_exists('id', $_POST)?$_POST['id']:false);
  }

}elseif (array_key_exists('edit', $_REQUEST)){

  if($_REQUEST['edit'])	{
    $page->buildForm(false, false, false, $_REQUEST['edit']);
  }else	{
    $page->buildForm( $maillist, 
		     array_key_exists('domain', $_POST)?$_POST['domain']:false);
  }
}else {

  if(array_key_exists('ids', $_POST)){
    if(is_array($_POST['ids']) && count($_POST['ids']))
      MailListPage::deleteLists ( array_keys($_POST['ids']) );
  }
	
  if(array_key_exists('search', $_REQUEST)){
    $page->setSearchWord($_REQUEST['search']);	
  }
  if(array_key_exists('page', $_GET)){
    $page->setPageNum($_GET['page']);	
  }
  $page->buldMailList();
}

$tpl->show();





//print_r($tpl);
//$DEBUG=true;

/*
print_header();

if($_POST['ids'])
{
	foreach(array_keys($_POST['ids']) as $dd)
	{
		$u = new SQLDataRow('maillist', array('id' => $dd), 'id');
		$u->delete();
	}
}


if($_POST['add'])
{
	//echo "qwe";
//	error_reporting(E_ALL);
	
		$nl = new SQLDataRow('maillist');
		$nl->setValue('domain_id', $_POST['domains']);
		$nl->setValue('name', $_POST['ml']);
		$nl->setValue('neu', 1);
		$nl->setValue('owner_mail', $PHP_AUTH_USER);
		$nl->insert();
	
	
	$sdt = new SQLDataTable('domains', 'id');
	$sdt->setConds(new CondEq('id', $domains));
//	$DEBUG=true;
	$dom_row = $sdt->getNextRow();
	$DEBUG=false;
	
	//print_r($sdt);
	
	$smarty = new CSmarty();
	
	$smarty->assign('ml', $ml);
	$smarty->assign('domains', $dom_row->getValue("domain"));
	
	$smarty->display('user/addform.tpl');
	
	//echo "zxc<pre>";
	//print_r($smarty);
}
else
{
	$smarty = new CSmarty();
	
	$query = "SELECT maillist.name AS mlname, domains.domain AS mldomain, maillist.id AS id
	FROM maillist
	INNER JOIN domains ON ( maillist.domain_id = domains.id )";
	

	
	if($search)
	{
		$cond = new CondOR( new CondLike('maillist.name', $search) );
		$cond->addCond( new CondLike('domains.domain', $search) );
		//echo $cond->getSQL();
		
		$query .= ' WHERE ' . $cond->getSQL();
		//$data->setConds($cond);
	}
	//echo $query;
	$data = new SQLDataTable('maillist', 'id', $query);
	
	$pager = new MLPager();
	if($search)
	{
		$pager->setVar('search', $search);	
	}
	$pager->setKey('id');
	$pager->setData($data);
	$pager->setPageSize(10);
	$page = $page * 1;
	$pager->setPageNum($page);
	
	$pager->setSmarty($smarty);
	$pager->build();
	echo $pager->getHtml();
}

//print_r($pager);
print_footer();
*/
?>
