<?php

// -----------------------------------------------------------------------
// This file is part of aroundme
// 
// Copyright (C) 2003, 2005 Barnraiser
// http://www.barnraiser.org/
// info@barnraiser.org
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option) any
// later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with program; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
// -----------------------------------------------------------------------

?>


<form action="g_poll_edit.php" method="post">
<input type="hidden" name="poll_id" value="<?php echo $poll['poll_id'];?>" />
<input type="hidden" name="group_id" value="<?php echo $group['group_id'];?>" />

<table width="770" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td width="180" valign="top">
			<?php
			include $templatePath . "g_menu.inc.tpl.php";
			?>

			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="10" alt="" /><br />

			<table border="0" width="100%" cellspacing="4" cellpadding="0">
				<tr>
					<td class="txt_title">
						<?php echo $lang['section_action'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td>
						<a href="g_poll.php?group_id=<?php echo $group['group_id'];?>" class="txt_sub_menu"><?php echo $lang['href_list'];?></a><br />
					</td>
				</tr>
			</table>

			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="52" alt="" /><br />

			<?php
			include $templatePath . "logo.inc.tpl.php";
			?>
		</td>

		<td width="20">&nbsp;</td>

		<td width="570" valign="top">
			<table border="0" cellspacing="0" cellpadding="4" width="100%" class="bg_1">
				<tr>
					<td class="txt_title" align="right" colspan="2">
						<?php echo $lang['hdr_poll'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<?php echo $lang['txt_poll_intro'];?><br />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="10" alt="" /><br />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<b><?php echo $lang['txt_question'];?></b><br />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<input type="text" name="data[poll_question]" size=65" value="<?php if (isset($poll['poll_question'])) { echo $poll['poll_question']; }?>" /><br />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<b><?php echo $lang['txt_start'];?></b><br />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<?php echo $start_datedropdown;?><br />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<b><?php echo $lang['txt_end'];?></b><br />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<?php echo $end_datedropdown;?><br />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<b><?php echo $lang['txt_anonymous'];?></b><br />
						<?php echo $lang['txt_anonymous_help'];?><br />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<input type="checkbox" name="data[poll_anon]" value="1"<?php if (isset($poll['poll_anon'])) { echo " checked=\"checked\" "; }?> /><br />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<b><?php echo $lang['txt_required'];?></b><br />
						<?php echo $lang['txt_required_help'];?><br />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<input type="checkbox" name="data[vote_required]" value="1"<?php if (isset($poll['vote_required'])) { echo " checked=\"checked\" "; }?> /><br />
					</td>
				</tr>
			</table>
			
			<?php
			if (!isset($poll)) {
			?>
			<table border="0" cellspacing="0" cellpadding="4" width="100%">
				<tr>
					<td colspan="2" class="txt_title" align="right">
						<?php echo $lang['section_cms'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td valign="top">
						<?php
						if ($this->group_acs->checkPermission($resource_ids['group_cms'], $privilege_ids['allow_cms_public'])) { //resource_id, Priv_id
							if ($cms_node_auto_publish == 1) {
							    $txt_cms_node = $lang['txt_cms_node_auto'];
							}
							else {
								$txt_cms_node = $lang['txt_cms_node'];
							}
							
						?>
						<input type="checkbox" name="data[cms_node]" value="1" <?php if (isset($poll['cms_node']) && $poll['cms_node'] == 1) { echo "checked=\"checked\"";}?> />&nbsp;<?php echo $txt_cms_node;?><br />
						<?php
						}
						
						if ($this->group_acs->checkPermission($resource_ids['group_cms'], $privilege_ids['allow_cms_group_home'])) { //resource_id, Priv_id
							if ($group['group_cms_auto_publish'] == 1) {
							    $txt_cms_group = $lang['txt_cms_group_auto'];
							}
							else {
								$txt_cms_group = $lang['txt_cms_group'];
							}
						?>
						<input type="checkbox" name="data[cms_group]" value="1" <?php if (isset($poll['cms_group']) && $poll['cms_group'] == 1) { echo "checked=\"checked\"";}?> />&nbsp;<?php echo $txt_cms_group;?><br />
						<?php } ?>
					</td>
				</tr>
			</table>
			
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="10" alt="" /><br />
			<?php }?>
			
			<?php
			if (isset($poll['options'])) {
			?>
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="10" alt="" /><br />

			<table border="0" cellspacing="0" cellpadding="4" width="100%">
				<tr>
					<td colspan="2" class="txt_title" align="right">
						<?php echo $lang['hdr_options'];?><br />
						<hr />
					</td>
				</tr>
				<?php
				foreach($poll['options'] as $key => $i):
				?>
				<tr>
					<td width="1%">
						<a href="g_poll_edit.php?group_id=<?php echo $group['group_id'];?>&amp;poll_id=<?php echo $poll['poll_id'];?>&amp;option_id=<?php echo $i['option_id'];?>&amp;view_poll=1"><?php echo $key+1;?></a><br />
					</td>
					<td>
						<?php echo $i['option_body'];?><br />
					</td>
				</tr>
				<?php

				//check for edit
				if (isset($option) && $option == $i['option_id']) {
					$edit_option_body = $i['option_body'];
				}

				endforeach;
				?>
				<tr>
					<td colspan="2">
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="10" alt="" /><br />
					</td>
				</tr>
				<?php
				if (isset($option)) {
				    //we edit
				?>
				<tr>
					<td colspan="2">
						<b><?php echo $lang['txt_edit_poll_option'];?></b><br />
						<?php echo $lang['txt_poll_option_help'];?><br />
					</td>
				</tr>
				<tr>
					<td>
						<input type="hidden" name="data[option_id]" value="<?php echo $option;?>" />
						<input type="text" name="data[option_body]" size=40" value="<?php echo $edit_option_body;?>" /><br />
					</td>
					<td>
						<input type="submit" name="update_poll_option" value="<?php echo $lang['sub_update'];?>" class="formInput" />&nbsp;&nbsp;
						<input type="submit" name="delete_poll_option" value="<?php echo $lang['sub_delete'];?>" class="formInput" />&nbsp;&nbsp;
						<input type="submit" name="insert_poll_option" value="<?php echo $lang['sub_add'];?>" class="formInput" /><br />
					</td>
				</tr>
				<?php
				}
				elseif (isset($display) && $display == "edit_poll") {//we add
				?>
				<tr>
					<td colspan="2">
						<b><?php echo $lang['txt_add_poll_option'];?></b><br />
						<?php echo $lang['txt_poll_option_help'];?><br />
					</td>
				</tr>
				<tr>
					<td>
						<input type="text" name="data[option_body]" size=40" value="" /><br />
					</td>
					<td>
						<input type="submit" name="insert_poll_option" value="<?php echo $lang['sub_add'];?>" class="formInput" /><br />
					</td>
				</tr>
				<?php }?>
			</table>
			
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="10" alt="" /><br />
			<?php }?>
			
			<table border="0" cellspacing="0" cellpadding="4" width="100%">
				<tr>
					<td class="txt_title" align="right" colspan="2">
						<?php echo $lang['section_publishing'];?><br />
						<hr />
					</td>
				</tr>
				<?php
				if (isset($display) && $display == "edit_poll") {
				?>
				<tr>
					<td>
						<input type="submit" name="delete_poll" value="<?php echo $lang['sub_delete'];?>" class="formInput" /><br />
					</td>
					<td align="right">
						<input type="submit" name="update_poll" value="<?php echo $lang['sub_update'];?>" class="formInput" /><br />
					</td>
				</tr>
				<?php
				}
				else {
				?>
				<tr>
					<td align="right" colspan="2">
						<input type="submit" name="insert_poll" value="<?php echo $lang['sub_add'];?>" class="formInput" /><br />
					</td>
				</tr>
				<?php }?>
			</table>
		</td>
	</tr>
</table>
</form>
