<?php

	require_once( $GLOBALS["site_root"] . "/includes/widgets/AdminAjaxTable.inc.php" );

	class AdminNewsletterTable extends AdminAjaxTable {
		protected $ng_id = 0;
		protected $nu_id = 0;

		public function __construct( $id , $parent ) {
			parent::__construct( $id , $parent );
			$this->sTableName = "newsletter_newsletters";
			$this->sIdField = "newsletter_newsletter_id";
			$this->iPagesize = 100;
		}

		public function constructToolbarHeader() {}

		public function whereClause() {
			$filters = array();
			if ($this->ng_id) $filters[]=sprintf( "newsletter_group_id=%d" , $this->ng_id );
			if ($this->nu_id) $filters[]=sprintf( "newsletter_newsletter_id in (select newsletter_newsletter_id from newsletter_newsletters where newsletter_user_id=%d)" , $this->nu_id );
			if (empty( $filters )) return "";
			return " where " . implode( " and " , $filters );
		}

		public function constructColumns() {
			$this->addColumn( "nl_title" , __("newsletters_Newsletter_title","attr" ) , false );
			$this->addColumn( "nl_senttstamp" , __("newsletters_Newsletter_sent_at","attr") , false );
		}

		public function constructField( $rownum , $row , $colname ) {
			$field = parent::constructField( $rownum , $row , $colname );
			$rd = $this->aData[$rownum];
			switch ($colname) {
			case "ctstamp":
				$field->setValue( fo3_format_tstamp_to_screen( $rd[$colname] ) );
				break;

			}
			return $field;
		}

		public function setNewsletterGroupId( $v ) { $this->ng_id = $v; }
		public function setNewsletterUserId( $v ) { $this->nu_id = $v; }

		public function render() {
			if ($this->sRendered) return $this->sRendered;
			$this->setParam( "tbodyattrs" , "style=\"height: 190px;\"" );
			return parent::render();
		}
	}

?>
