<?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.
// -----------------------------------------------------------------------

?>

<script language="JavaScript" src="js/imageHandling.js" type="text/javascript"></script>
<script type="text/javascript" src="js/calendar.js"></script>
<script type="text/javascript" src="<?php echo $languagePath;?>calendar/calendar-lang.js"></script>
<script type="text/javascript" src="js/calendar-setup.js"></script>

<form action="pol_edit.php" method="post" name="frm" id="id_frm">
<input type="hidden" name="poll_id" value="<?php if(isset($poll['poll_id'])) { echo $poll['poll_id'];}?>" />
<input type="hidden" name="group_id" value="<?php if(isset($group['group_id'])) { echo $group['group_id'];} elseif (isset($poll['group_id'])) { echo $poll['group_id'];}?>" />

<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td width="760" valign="top">
			<div class="box_top">
				<?php echo $lang['hdr_poll'];?><br />
			</div>
			
			<div class="box_mid" style="padding: 9px;">
			<table border="0" cellspacing="0" cellpadding="0" width="100%">
				<tr>
					<td>
						<?php echo $lang['txt_poll_intro'];?><br />
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="12" alt="" /><br />
						
					</td>
					<td colspan="2">
						<br />
					</td>
				</tr>
				<tr>
					<td valign="top">
						<fieldset>
						<legend><?php echo $lang['txt_header_1'];?></legend>
						<p>
						<?php echo $lang['txt_overview_intro'];?><br />
						</p>
					
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />
						
						<table border="0" cellspacing="0" cellpadding="0" width="100%">
							<tr>
								<td valign="top" width="380">
									<p>
									<label for="id_question"><?php echo $lang['txt_question'];?></label>
									<input id="id_question" type="text" name="poll_question" size="45" value="<?php if (isset($poll['poll_question'])) { echo $poll['poll_question'];}?>" /><br />
									</p>
								</td>
								<td valign="top">
									<table border="0" cellspacing="0" cellpadding="0">
										<tr>
											<td valign="top" width="25">
												<input type="checkbox" id="id_anonymous" name="poll_anon" class="checkbox" value="1"<?php if (isset($poll['poll_anon'])) { echo " checked=\"checked\" "; }?> />
											</td>
											<td>
												<label style="width:100%" for="id_anonymous"><?php echo $lang['txt_anonymous'];?></label><br />
											</td>
										</tr>
										<tr>
											<td valign="top" width="25">
												<input id="id_required" type="checkbox" name="vote_required" class="checkbox" size="35" value=""<?php if (isset($poll['vote_required'])) { echo " checked=\"checked\" "; }?> />
											</td>
											<td>
												<label style="width:100%" for="id_required"><?php echo $lang['txt_required'];?></label><br />
											</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
						</fieldset>
						
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" /><br />
						
						<fieldset>
						<legend><?php echo $lang['txt_header_2'];?></legend>
						<p>
						<?php echo $lang['txt_date_intro'];?><br />
						</p>
					
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />
						
						
						
						<table border="0" cellspacing="0" cellpadding="0" width="100%">
							<tr>
								<td valign="top">
			  						<div id="startdate">
									<p>
			  						<label for="id_poll_start_date"><?php echo $lang['form_label_start_date'];?></label>
			  						<input id="id_poll_start_date" type="text" maxlength="10" name="poll_start_date" size="11" value="<?php if(isset($poll['poll_start_date'])) { echo $poll['poll_start_date'];}?>" />
			  						<img src="<?php echo $templatePath;?>img/cal_icon.png" id="id_cal_pop1" width="34" height="21" border="0" alt=""onmouseover="this.style.background='red';" onmouseout="this.style.background=''" />
			  						</p>
									
									<script type="text/javascript">
			  							function dateChanged1(calendar) {
			  							 	if (calendar.dateClicked) {
			  							   		var y = calendar.date.getFullYear();
			  							   		var m = calendar.date.getMonth()+1;     // integer, 0..11
			  							   		var d = calendar.date.getDate();      // integer, 1..31
			  									var h = calendar.date.getHours();      // integer, 1..31
			  									var i = calendar.date.getMinutes();      // integer, 1..31
			  							
			  									document.frm.id_poll_start_date.value = y + '-' + m + '-' + d;
			  									document.frm.id_poll_start_time.value = h + ':' + i;
			  									calendar.callCloseHandler();
			  							 	}
			  							};
			  							
			  						  	Calendar.setup({           // our callback function
			  						        ifFormat       :    "%m-%d-%Y %k:%M",
			  						        button         :    "id_cal_pop1",
			  						        align          :    "Tl", // popup alignment
			  						        singleClick    :    true,
			  								showsTime      :    true,
			  						      	onSelect    : dateChanged1
			  						    });
			  						</script>
									</div>
								</td>
								<td>
									<div id="starttime">
									<p>
									<label for="id_poll_start_time"><?php echo $lang['form_label_start_time'];?></label>
									<input id="id_poll_start_time" type="text" maxlength="5" name="poll_start_time" size="6" value="<?php if(isset($poll['poll_start_time'])) { echo $poll['poll_start_time'];}?>" />
									</p>
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div id="enddate">
									<p>
									<label for="id_poll_end_date"><?php echo $lang['form_label_end_date'];?></label>
									<input id="id_poll_end_date" type="text" maxlength="10" name="poll_end_date" size="11" value="<?php if(isset($poll['poll_end_date'])) { echo $poll['poll_end_date'];}?>" />
									<img src="<?php echo $templatePath;?>img/cal_icon.png" id="id_cal_pop2" width="34" height="21" border="0" alt=""onmouseover="this.style.background='red';" onmouseout="this.style.background=''" />
								  	</p>
									
									<script type="text/javascript">
										function dateChanged2(calendar) {
										 	if (calendar.dateClicked) {
										   		var y = calendar.date.getFullYear();
										   		var m = calendar.date.getMonth()+1;     // integer, 0..11
										   		var d = calendar.date.getDate();      // integer, 1..31
												var h = calendar.date.getHours();      // integer, 1..31
												var i = calendar.date.getMinutes();      // integer, 1..31
										
												document.frm.id_poll_end_date.value = y + '-' + m + '-' + d;
												document.frm.id_poll_end_time.value = h + ':' + i;
												calendar.callCloseHandler();
										 	}
										};
										
									  	Calendar.setup({           // our callback function
									        ifFormat       :    "%m-%d-%Y %k:%M",
									        button         :    "id_cal_pop2",
									        align          :    "Tl", // popup alignment
									        singleClick    :    true,
											showsTime      :    true,
									      	onSelect    : dateChanged2
									    });
									  
									</script>
									</div>
								</td>
								<td>
									<div id="endtime">
									<p>
									<label for="id_poll_end_time"><?php echo $lang['form_label_end_time'];?></label>
									<input id="id_poll_end_time" type="text" maxlength="5" name="poll_end_time" size="6" value="<?php if(isset($poll['poll_end_time'])) { echo $poll['poll_end_time'];}?>" />
									</p>
									</div>
								</td>
							</tr>
						</table>
						</fieldset>
						
						
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" /><br />
						
						<fieldset>
						<legend><?php echo $lang['txt_header_3'];?></legend>
						<p>
						<?php
						if (!isset($poll['poll_id'])) {
							echo $lang['txt_not_saved'];
						}
						else {
							echo $lang['txt_option_intro'];
						}
						?><br />
						</p>
						
						<table border="0" cellspacing="0" cellpadding="4" width="100%">
							<?php
							if (!empty($poll['options'])) {
							foreach($poll['options'] as $key => $i):
							?>
							<tr>
								<td width="1%">
									<?php
									if (isset($group)) {
									?>
									<a href="pol_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'];?>"><?php echo $key+1;?></a><br />
									<?php
									}
									else {
									?>
									<a href="pol_edit.php?poll_id=<?php echo $poll['poll_id'];?>&amp;option_id=<?php echo $i['option_id'];?>"><?php echo $key+1;?></a><br />
									<?php }?>
								</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>
						</table>
						</fieldset>
						
						
						<?php
						if (isset($poll['poll_id'])) {
						?>
						
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" /><br />
						
						<fieldset>
						<legend><?php echo $lang['txt_header_4'];?></legend>
						<p>
						<?php echo $lang['txt_poll_option_intro'];?><br />
						</p>
						
						<table border="0" cellspacing="0" cellpadding="4" width="100%">
							<?php
							if (isset($option)) {
							    //we edit
							?>
							<tr>
								<td>
									<input type="hidden" name="option_id" value="<?php echo $option;?>" />
									<input type="text" name="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="button_urgent" />&nbsp;&nbsp;
									<input type="submit" name="delete_poll_option" value="<?php echo $lang['sub_delete'];?>" class="button_urgent" />&nbsp;&nbsp;
									<input type="submit" name="insert_poll_option" value="<?php echo $lang['sub_add'];?>" class="button_urgent" /><br />
								</td>
							</tr>
							<?php
							}
							elseif (isset($display) && $display == "edit_poll") {//we add
							?>
							<tr>
								<td>
									<input type="text" name="option_body" size=40" value="" /><br />
								</td>
								<td>
									<input type="submit" name="insert_poll_option" value="<?php echo $lang['sub_add'];?>" class="button_urgent" /><br />
								</td>
							</tr>
							<?php }?>
						</table>
						</fieldset>
						<?php }?>
						
						
						
						
					</td>
					<td>
						<img src="<?php echo $templatePath;?>img/pixel.png" width="10" height="1" alt="" /><br />
					</td>
					<td valign="top" width="200">
						<fieldset>
						<legend><?php echo $lang['txt_header_5'];?></legend>
						<p>
						<?php echo $lang['txt_publishing_intro'];?><br />
						</p>
					
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />
						
						<?php
						//find out what value rsp has
						if (isset($poll['rsp'])) {
							foreach($poll['rsp'] as $key => $rsp):
								if ($rsp['level_id'] == $rspconfig['rsp_level']['degree']) {
									$rsp_degree_set = 1;
									$rsp_degree = $rsp['degree_id'];
								}
								elseif ($rsp['level_id'] == $rspconfig['rsp_level']['node']) {
									$rsp_node = 1;
								}
								elseif ($rsp['level_id'] == $rspconfig['rsp_level']['public']) {
									$rsp_public = 1;
								}
								elseif ($rsp['level_id'] == $rspconfig['rsp_level']['group']['home']) {
									$rsp_group_home = 1;
								}
							endforeach;
						}
						
						if (isset($group)) {
						?>
						<table border="0" cellspacing="0" cellpadding="4" width="100%">
							<?php
							if ($this->group_acs->checkPermission($resource_ids['group_rsp'], $privilege_ids['allow_rsp_public'])) { //resource_id, Priv_id
							?>
							<tr>
								<td valign="top">
									<input id="id_allow_rsp_public" type="checkbox" name="rsp_public" class="checkbox" value="1" <?php if (isset($rsp_public) && $rsp_public == 1) { echo "checked=\"checked\"";}?> />
								</td>
								<td valign="top">
									<label style="width:100%" for="id_allow_rsp_public"><?php echo $lang['txt_publish_public_help'];?></label><br />
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="3" alt="" /><br />
								</td>
							<tr>
							<?php 
							}
							if ($this->group_acs->checkPermission($resource_ids['group_rsp'], $privilege_ids['allow_rsp_node'])) { //resource_id, Priv_id
								if ($rspconfig['node']['auto_publish'] == 1) {
									$txt_rsp_node = $lang['form_rsp_node_auto'];
								}
								else {
									$txt_rsp_node = $lang['form_rsp_node'];
								}
							?>
							<tr>
								<td valign="top">
									<input id="id_allow_rsp_node" type="checkbox" name="rsp_node" class="checkbox" value="1" <?php if (isset($rsp_node) && $rsp_node == 1) { echo "checked=\"checked\"";}?> />
								</td>
								<td valign="top">
									<label style="width:100%" for="id_allow_rsp_node"><?php echo $txt_rsp_node;?></label><br />
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="3" alt="" /><br />
								</td>
							<tr>
							<?php
							}
							if ($this->group_acs->checkPermission($resource_ids['group_rsp'], $privilege_ids['allow_rsp_group_home'])) { //resource_id, Priv_id
								if ($group['group_rsp_auto_publish'] == 1) {
									$txt_rsp_group = $lang['form_rsp_group_auto'];
								}
								else {
									$txt_rsp_group = $lang['form_rsp_group'];
								}
							?>
							<tr>
								<td valign="top">
									<input id="id_allow_rsp_group" type="checkbox" name="rsp_group" class="checkbox" value="1" <?php if (isset($rsp_group_home) && $rsp_group_home == 1) { echo "checked=\"checked\"";}?> /><br />
								</td>
								<td valign="top">
									<label style="width:100%" for="id_allow_rsp_group"><?php echo $txt_rsp_group;?></label><br />
								</td>
							</tr>
							<?php } ?>
						</table>
						<?php 
						}
						else {
						?>
						
						<script type="text/javascript">
						function setDegreeEveryone(id) {
							if (id.checked) {
								document.getElementById('id_degree_id').checked=true;
							}
						}
						function setPublishingOff() {
							document.getElementById('id_level_id_node').checked=false;
							document.getElementById('id_level_id_public').checked=false;
							
						}
						</script>
						<table border="0" cellspacing="0" cellpadding="2" width="100%">
							<tr>
								<td width="1">
									<input type="radio" class="checkbox" name="rsp_degree" value="" checked="checked" /><br />
								</td>
								<td>
									<?php echo $lang['form_just_me'];?><br />
								</td>
							</tr>
							<?php
							$selected="";
							if (isset($rsp_degree_set) && empty($rsp_degree)) {
								$selected=" checked=\"checked\"";
							}
							?>
							<tr>
								<td>
									<input id="id_degree_id" class="checkbox" type="radio" name="rsp_degree" value="all"<?php echo $selected;?> /><br />
								</td>
								<td>
									<?php echo $lang['txt_publish_level'];?><br />
								</td>
							</tr>
							<?php
							
							if ($this->user_acs->checkPermission($resource_ids['rsp'], $privilege_ids['allow_rsp_node'])) { //resourece_id, Priv_id
							$selected="";
							if (isset($rsp_node) && $rsp_node == 1) {
								$selected=" checked=\"checked\"";
							}
							?>
							<tr>
								<td valign="top">
									<input type="checkbox" id="id_level_id_node" name="rsp_node" value="1"<?php echo $selected;?> class="checkbox" onChange="javascript:setDegreeEveryone(this);" /><br />
								</td>
								<td>
									<?php echo $lang['txt_publish_node_help'];?><br />
								</td>
							</tr>
							<?php
							}
							
							if ($this->user_acs->checkPermission($resource_ids['rsp'], $privilege_ids['allow_rsp_public'])) { //resourece_id, Priv_id
							$selected="";
							if (isset($rsp_public) && $rsp_public == 1) {
								$selected=" checked=\"checked\"";
							}
							?>
							<tr>
								<td valign="top">
									<input type="checkbox" id="id_level_id_public" name="rsp_public" value="1"<?php echo $selected;?> class="checkbox" onChange="javascript:setDegreeEveryone(this);" /><br />
								</td>
								<td>
									<?php echo $lang['txt_publish_public_help'];?><br />
								</td>
							</tr>
							<?php }?>
						</table>
						<?php }?>
						</fieldset>
						
						<script type="text/javascript">
						//check php did not set either of the publishing buttons
						if (document.getElementById('id_level_id_public').checked) {
							document.getElementById('id_degree_id').checked=true;
						}
						if (document.getElementById('id_level_id_node').checked) {
							document.getElementById('id_degree_id').checked=true;
						}
						</script>
						
						
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" /><br />
						
						<fieldset>
						<legend><?php echo $lang['txt_header_6'];?></legend>
						<p>
						<?php echo $lang['txt_save_intro'];?><br />
						</p>
					
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />
						
						<input type="submit" name="save" class="button_urgent" value="<?php echo $lang['form_submit_save'];?>" />&nbsp;
						<input type="submit" name="save_go" class="button_urgent" value="<?php echo $lang['form_submit_save_go'];?>" /><br />
					
						</fieldset>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

