<?php
		if (!isset($gCms)) exit;

		if (isset($params['cancel']))
		{
			$this->Redirect($id, 'defaultadmin', $returnid);
		}

		$commentid = '';
		if (isset($params['commentid']))
		{
			$commentid = $params['commentid'];
		}

		$data = '';
		if (isset($params['data']))
		{
			$data = $params['data'];
		}

		$author = '';
		if (isset($params['author']))
		{
			$author = $params['author'];
			if ($author != '')
			{
				if ($data != '')
				{
					$modifydate = time();
					$query = 'UPDATE '.cms_db_prefix().'module_comments SET comment_data=?, comment_author=?, modified_date=? WHERE comment_id = ?';
					$db->Execute($query, array($data, $author, $db->DBTimeStamp($modifydate), $commentid));

					$this->Redirect($id, 'defaultadmin', $returnid);
				}
				else
				{
					echo '<p class="error">'.$this->Lang('nocontentgiven').'</p>';
				}
			}
			else
			{
				echo '<p class="error">'.$this->Lang('noauthorgiven').'</p>';
			}
		}
		else
		{
			$query = 'SELECT * FROM '.cms_db_prefix().'module_comments WHERE comment_id = ?';
			$dbresult = $db->Execute($query, array($commentid));

			while (($row = $dbresult->FetchRow()))
			{
				$author = $row['comment_author'];
				$data = $row['comment_data'];
				$postdate = $row['comment_date'];
				$pageid = $row['page_id'];
				$createdate = $row['create_date'];
				$modifydate = $row['modified_date'];
			}
		}


		#Display template
		$this->smarty->assign('startform', $this->CreateFormStart($id, 'editcomment', $returnid));
		$this->smarty->assign('endform', $this->CreateFormEnd());

        $this->smarty->assign('authortext', $this->Lang('author'));
		$this->smarty->assign('inputauthor', $this->CreateInputText($id, 'author', $author, 30, 255));

		$this->smarty->assign('datatext', $this->Lang('data'));
		$this->smarty->assign('inputdata', $this->CreateTextArea(false, $id, $data, 'data'));

		$this->smarty->assign('pageidtext', $this->Lang('pageid'));
		$this->smarty->assign('inputpageid', ContentManager::GetPageAliasFromID($pageid));
		
		$this->smarty->assign('postdatetext', $this->Lang('postdate'));
		$this->smarty->assign('inputpostdate', $postdate);
		
		$this->smarty->assign('createdatetext', $this->Lang('createdate'));
		$this->smarty->assign('inputcreatedate', $createdate);
		
		$this->smarty->assign('modifydatetext', $this->Lang('modifydate'));
		$this->smarty->assign('inputmodifydate', $modifydate);
		
		$this->smarty->assign('hidden', $this->CreateInputHidden($id, 'commentid', $commentid));
		$this->smarty->assign('submit', $this->CreateInputSubmit($id, 'submit', lang('submit')));
		$this->smarty->assign('cancel', $this->CreateInputSubmit($id, 'cancel', lang('cancel')));

		echo $this->ProcessTemplate('editcomment.tpl');
?>
