<?php

// -----------------------------------------------------------------------
// This file is part of AROUNDMe
// 
// Copyright (C) 2003 - 2006 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., 51 Franklin St, Fifth Floor, Boston, MA
// 02110-1301, 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="quz_edit.php" method="post" name="frm_edit" id="id_frm_edit">
<input type="hidden" name="quiz_id" value="<?php if(isset($quiz['quiz_id'])) { echo $quiz['quiz_id'];}?>" />
<input type="hidden" name="group_id" value="<?php if(isset($group['group_id'])) { echo $group['group_id'];} elseif (isset($quiz['group_id'])) { echo $quiz['group_id'];}?>" />


<div class="box">
	<div class="box_top">
		<b><?php echo $lang['hdr_quiz_editor'];?></b><br />
	</div>
	
	<div class="box_mid">
		<div class="content">
			<p class="txt_item_title">
				<?php echo $lang['hdr_quiz_create'];?><br />
			</p>
			
			<table border="0" cellspacing="0" cellpadding="0" width="100%">
				<tr>
					<td valign="top" width="200">
						<?php echo $lang['txt_quiz_intro'];?><br />
					</td>
					<td>
						<img src="<?php echo $templatePath;?>img/pixel.png" width="10" height="1" alt="" /><br />
					</td>
					<td valign="top" width="310">
						<p>
							<label for="id_title"><?php echo $lang['form_title'];?></label><br />
							<input id="id_title" type="text" class="input" name="quiz_title" size="45" value="<?php if (isset($quiz['quiz_title'])) { echo $quiz['quiz_title'];}?>" /><br />
						</p>
						
						<p>
							<label for="id_quiz_synopsis"><?php echo $lang['form_label_synopsis'];?></label><br />
							<textarea id="id_quiz_synopsis" name="quiz_synopsis" cols="32" rows="2"><?php if (isset($quiz['quiz_synopsis'])) { echo $quiz['quiz_synopsis'];}?></textarea><br />
						</p>
						
						<p>
							<label for="id_quiz_body_intro"><?php echo $lang['form_quiz_body_intro'];?></label><br />
						 </p>
						 
						<table border="0" cellspacing="0" cellpadding="2" width="10%">
							<tr>
								<td valign="middle" id="gui_wiki" align="right" nowrap="nowrap">
									<script language="JavaScript" type="text/javascript" src="js/gui_wiki.js"></script>&nbsp;<br />
								</td>
								<td width="1" valign="top">
									<select class="gui_select" onChange="javascript:insertTags('[', ' link name here]', this.value);">
										<option value="0"><?php echo $lang['txt_wikipagenames'];?></option>
										<?php
										if (isset($wikipages)) {
										foreach($wikipages as $key => $i):
										?>
										<option value="<?php echo $i;?>"><?php echo $i;?></option>
										<?php
										endforeach;
										}
										?>
									</select>
									<br />
								</td>
								<td width="1">
									<script language="JavaScript" type="text/javascript">
									function fileSuffixCheck (filename) {
										
										var suffix = filename.substring(filename.length-3);
										
										if (suffix=='jpg' || suffix=='png' || suffix=='gif') {
											var wikiTag = "Image ";
											var thumb = "";
										}
										else {
											var wikiTag = "File ";
											var thumb = " thumb=\"1\"";
										}
										
										insertTags('[['+wikiTag , filename+thumb+']]', '')
									}
									</script>
									
									<select class="gui_select" onChange="javascript:fileSuffixCheck(this.value);">
										<option value="0"><?php echo $lang['txt_filenames'];?></option>
										<?php
										if (isset($filenames)) {
										foreach($filenames as $key => $i):
										?>
										<option value="<?php echo $i['file_name'] . "." . $i['file_suffix'];?>"><?php echo $i['file_name'] . "." . $i['file_suffix'];?></option>
										<?php
										endforeach;
										}
										?>
									</select>
									<br />
								</td>
							</tr>
							<tr>
								<td align="right" colspan="3">
									<textarea id="id_quiz_body_intro" name="quiz_body_intro" cols="75" rows="6" onchange="textChanged = true;" tabindex="1"><?php if (isset($quiz['quiz_body_intro'])) { echo $quiz['quiz_body_intro'];}?></textarea><br />
									<script language="JavaScript" type="text/javascript">
										var txtarea = document.frm_edit.quiz_body_intro;
									</script>
								</td>
							</tr>
							<tr>
								<td align="right" colspan="4">
									<input type="submit" class="input_submit" name="preview" value="<?php echo $lang['sub_preview'];?>" />
									<?php
									if (isset($allow_spellcheck)) {
									?>
									&nbsp;&nbsp;
									<input type="button" class="input_submit" value="<?php echo $lang['sub_check_spelling'];?>" onClick="openSpellChecker();" class="button_light" />
									<?php }?>
									<br />
								</td>
							</tr>
						</table>
						
						<p>
							<?php echo $lang['txt_quiz_type_intro'];?><br />
						</p>
						
						<p>
							<label for="id_quiz_display_answers"><?php echo $lang['form_label_quiz_display_answers'];?></label>&nbsp;
							<input type="checkbox" id="id_quiz_display_answers" class="input1" name="quiz_display_answers" value="1" <?php if (!empty($quiz['quiz_display_answers'])) { echo "checked=\"checked\"";}?> onChange="javascript:setAnswerOff(this);" /><br />
						</p>
						
						<?php
						if (!empty($quiz['quiz_body_intro_preview'])) {
						?>
						
						<p>
							<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />
						</p>
						
						<p>
							<b><?php echo $lang['form_label_preview'];?></b><br />
						</p>
							
						<p>
							<?php echo $quiz['quiz_body_intro_preview'];?><br />
						</p>
						<?php }?>
					</td>
				</tr>
			</table>
			
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />
			
			<p align="right">
				<input type="submit" class="input_submit" name="save" value="<?php echo $lang['sub_save'];?>" />&nbsp;
			</p>
			
			
			<?php
			if (isset($quiz['quiz_id'])) {
			?>
			<hr />
			
			<a name="questions"></a>
			<p class="txt_item_title">
				<?php echo $lang['hdr_quiz_questions'];?><br />
			</p>
			
			<table border="0" cellspacing="0" cellpadding="0" width="100%">
				<tr>
					<td valign="top" width="50%">
						<p>
							<?php echo $lang['txt_question_intro'];?><br />
						</p>
						
						<?php
						if (!empty($quiz['questions'])) {
						?>
						<table border="0" cellspacing="0" cellpadding="4" width="100%">
							<?php
							foreach($quiz['questions'] as $key => $q):
							?>
							<tr>
								<td width="1" nowrap="nowrap">
									<a href="quz_edit.php?question_id=<?php echo $q['question_id'];?>&amp;quiz_id=<?php echo $quiz['quiz_id'];?>#questions"><?php echo $key+1;?></a><br />
								</td>
								<td colspan="2">
									<b><a href="quz_edit.php?question_id=<?php echo $q['question_id'];?>&amp;quiz_id=<?php echo $quiz['quiz_id'];?>#questions"><?php echo $q['question_body'];?></a></b><br />
								</td>
							</tr>
							<tr>
								<td colspan="3">
									<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />
								</td>
							</tr>
							<?php
							if (isset($q['options'])) {
							foreach($q['options'] as $key1 => $i):
							?>
							<tr>
								<td width="10">
									<br />
								</td>
								<td>
									<?php echo $i['option_body'];?><br />
								</td>
								<td align="right">
									<?php
									if ($i['option_id'] == $q['question_correct_option_id']) {
										echo "correct answer";
									}
									?><br />
								</td>
							</tr>
							<?php
							endforeach;
							}
							?>
							<?php
							if (!empty($q['question_answer'])) {
							?>
							<tr>
								<td width="10">
									<br />
								</td>
								<td colspan="2">
									<i><?php echo $q['question_answer'];?></i><br />
								</td>
							</tr>
							<?php }?>
							<tr>
								<td colspan="3">
									<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" /><br />
								</td>
							</tr>
							<?php
							endforeach;
							?>
						</table>
						<?php }?>
						
						<?php
						if (!isset($add_question)) {
						?>
						<p align="right">
							<a href="quz_edit.php?add_question=1&amp;quiz_id=<?php echo $quiz['quiz_id'];?>#questions"><?php echo $lang['href_add_question'];?></a><br />
						</p>
						<?php }?>
					</td>
					
					<td>
						<img src="<?php echo $templatePath;?>img/pixel.png" width="20" height="1" alt="" /><br />
					</td>
					
					<td valign="top" width="50%">
						<?php
						if (isset($add_question) || isset($quiz['question']['question_id'])) {
						?>
						
						<?php
						if (isset($quiz['question']['question_id'])) {
						?>
						<input type="hidden" class="input" name="question_id" value="<?php echo $quiz['question']['question_id'];?>" />
						<?php }?>
						
						<p>
							<label for="id_question_body"><?php echo $lang['form_label_question'];?></label><br />
							<input id="id_question_body" type="text" class="input" name="question_body" size="35" value="<?php if(isset($quiz['question']['question_body'])) { echo $quiz['question']['question_body'];}?>" /><br />
						</p>
						
						<p>
							<label for="id_question_order"><?php echo $lang['form_label_order'];?></label><br />
							<?php
							if (isset($quiz['question']['question_order'])) {
								$order = $quiz['question']['question_order'];
							}
							elseif (isset($quiz['questions'])) {
								$order = count($quiz['questions'])+1;
							}
							else {
								$order = 1;
							}
							?>
							<input id="id_question_order" type="text" class="input" name="question_order" size="6" value="<?php echo $order;?>" /><br />
						</p>
						
						<p>
							<label for="id_correct_body"><?php echo $lang['form_label_options'];?></label><br />
						</p>
						
						<table border="0" cellspacing="0" cellpadding="2" width="100%">
							<?php
							if (!isset($quiz['question']['options'])) {
								$quiz['question']['options'] = array(1,2,3);
							}
							else {
								array_push($quiz['question']['options'], 0);
							}
							
							foreach($quiz['question']['options'] as $key_options => $i):
							
							$selected = "";
							
							if((isset($quiz['question']['question_correct_option_id']) && $quiz['question']['question_correct_option_id'] == $i['option_id']) || $key_options == 0) {
								$selected = "checked=\"checked\"";
							}
							?>
							<tr>
								<td>
									<input type="hidden" name="options[<?php echo $key_options;?>][option_id]" size="35" value="<?php if(isset($i['option_id'])) { echo $i['option_id'];}?>" /><br />
									<input type="text" class="input" name="options[<?php echo $key_options;?>][option_body]" size="35" value="<?php if(isset($i['option_body'])) { echo $i['option_body'];}?>" /><br />
								</td>
								<td align="right">
									<?php
									if (isset($i['option_id'])) {
										$val = $i['option_id']; // we will update
									}
									else {
										$val = $key_options; // we insert with this
									}
									?>
									<input type="radio" class="input" name="question_correct_option_id" value="<?php echo $val;?>" <?php echo $selected;?>/><br />
								</td>
							</tr>
							<?php
							endforeach;
							?>
							<tr>
								<td colspan="2" class="note">
									<?php echo $lang['txt_note_options'];?><br />
								</td>
							</tr>
						</table>
						
						<div id="id_answer">
						<p>
							<label for="id_question_answer"><?php echo $lang['form_label_question_answer'];?></label><br />
							<textarea id="id_question_answer" name="question_answer" cols="35" rows="2"><?php if(isset($quiz['question']['question_answer'])) { echo $quiz['question']['question_answer'];}?></textarea><br />
						</p>
						</div>
						
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" /><br />
						
						<p align="right">
							<input type="submit" name="delete_question" class="input_submit" value="<?php echo $lang['sub_delete'];?>" />&nbsp;
							<input type="submit" name="update_question" class="input_submit" value="<?php echo $lang['sub_update'];?>" /><br />
						</p>
						<?php }?>
						<br />
						
						<script type="text/javascript">
						function setAnswerOff(id) {
							var displaystate = 'none';
							
							if (id.checked) {
								displaystate = 'block';
							}
							
							objShowHide('id_answer', displaystate);
						}
						
						if (document.getElementById('id_quiz_display_answers').checked==false) {
							objShowHide('id_answer', 'none');
						}
						</script>
					</td>
				</tr>
			</table>
			<?php }?>
			
			
			<?php
			if (isset($quiz['questions']) && count($quiz['questions']) > 1) {
			?>
			<hr />
			
			<a name="feedback"></a>
			
			<p class="txt_item_title">
				<?php echo $lang['hdr_quiz_feedback'];?><br />
			</p>
			
			<p>
				<?php echo $lang['txt_result_intro'];?><br />
			</p>
			
			<table border="0" cellspacing="0" cellpadding="0" width="100%">
				<tr>
					<td valign="top" width="50%">
						<p>
							<label for="id_question_answer"><?php echo $lang['form_label_pass_rate'];?></label><br />
							<?php echo $lang['txt_pass_rate_help'];?><br />
						</p>
						
						<script type="text/javascript">
						function setPercentagePassRate(id) {
							var question_count = <?php echo count($quiz['questions'])?>;
							var form_value = id;
							var percent_value = Math.round((100/question_count)*form_value);
							//if (id.checked) {
								document.getElementById('pass_rate_percentage').innerHTML= "&nbsp;("+percent_value+"&#37;)";
							//}
						}
						</script>
						
						<p>
						<input id="quiz_pass_rate_id" type="text" class="input1" size="6" name="quiz_pass_rate" value="<?php if (!empty($quiz['quiz_pass_rate'])) { echo $quiz['quiz_pass_rate'];} else { echo count($quiz['questions']);}?>"  onchange="javascript:setPercentagePassRate(this.value);" />
						<span id="pass_rate_percentage"></span>
						<br />
						</p>
						
						<script type="text/javascript">
						var form_val = document.getElementById('quiz_pass_rate_id').value;
						setPercentagePassRate(form_val);
						</script>
						
					</td>
					<td>
						<img src="<?php echo $templatePath;?>img/pixel.png" width="20" height="1" alt="" /><br />
					</td>
					<td valign="top" width="50%">
						

						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />
						
						
						
						<table border="0" cellspacing="0" cellpadding="2" width="10%">
							<tr>
								<td valign="top" colspan="4">
									<?php echo $lang['form_exit_pass'];?><br />
								</td>
							</tr>
							<tr>
								<td align="right" colspan="4">
									<textarea id="id_quiz_body" name="quiz_body_exit_pass" cols="75" rows="4"><?php if (isset($quiz['quiz_body_exit_pass'])) { echo $quiz['quiz_body_exit_pass'];}?></textarea><br />
								</td>
							</tr>
							<tr>
								<td valign="top" colspan="4">
									<?php echo $lang['form_exit_fail'];?><br />
								</td>
							</tr>
							<tr>
								<td align="right" colspan="4">
									<textarea id="id_quiz_body_exit_fail" name="quiz_body_exit_fail" cols="75" rows="4"><?php if (isset($quiz['quiz_body_exit_fail'])) { echo $quiz['quiz_body_exit_fail'];}?></textarea><br />
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />
			
			<p align="right">
				<input type="submit" class="input_submit" name="save" value="<?php echo $lang['sub_save'];?>" />&nbsp;
			</p>
			<?php }?>
			
			
			<?php
			if (!empty($quiz['quiz_pass_rate'])) {
			?>
			
			<hr />
			
			<p class="txt_item_title">
				<?php echo $lang['hdr_quiz_publish'];?><br />
			</p>
			
			
			<table border="0" cellspacing="0" cellpadding="0" width="100%">
				<tr>
					<td valign="top" width="50%">
						
						<p>
						<?php echo $lang['txt_date_intro'];?><br />
						</p>
						
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />
						
						<p>
							<?php echo $lang['txt_date_indefinitely'];?>&nbsp;
							<input type="checkbox" class="input1" name="date_indefinitely" value="1" <?php if (!empty($quiz['date_indefinitely'])) { echo "checked=\"checked\"";}?> onChange="javascript:setDatetimeOff(this);" /><br />
						</p>
						
						<div id="datetimes">
						<table border="0" cellspacing="0" cellpadding="0" width="100%">
							<tr>
								<td valign="top">
			  						<div id="startdate">
									<p>
			  						<label for="id_quiz_start_date"><?php echo $lang['form_label_start_date'];?></label>
			  						<input id="id_quiz_start_date" class="input1" type="text" maxlength="10" name="quiz_start_date" size="11" value="<?php if(isset($quiz['quiz_start_date'])) { echo $quiz['quiz_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_quiz_start_date.value = y + '-' + m + '-' + d;
			  									document.frm.id_quiz_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_quiz_start_time"><?php echo $lang['form_label_start_time'];?></label>
									<input id="id_quiz_start_time" class="input1" type="text" maxlength="5" name="quiz_start_time" size="6" value="<?php if(isset($quiz['quiz_start_time'])) { echo $quiz['quiz_start_time'];}?>" />
									</p>
									</div>
								</td>
							</tr>
							<tr>
								<td>
									<div id="enddate">
									<p>
									<label for="id_quiz_end_date"><?php echo $lang['form_label_end_date'];?></label>
									<input id="id_quiz_end_date" class="input1" type="text" maxlength="10" name="quiz_end_date" size="11" value="<?php if(isset($quiz['quiz_end_date'])) { echo $quiz['quiz_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_quiz_end_date.value = y + '-' + m + '-' + d;
												document.frm.id_quiz_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_quiz_end_time"><?php echo $lang['form_label_end_time'];?></label>
									<input id="id_quiz_end_time" type="text" class="input1" maxlength="5" name="quiz_end_time" size="6" value="<?php if(isset($quiz['quiz_end_time'])) { echo $quiz['quiz_end_time'];}?>" />
									</p>
									</div>
								</td>
							</tr>
						</table>
						</div>
						
						<script type="text/javascript">
						function setDatetimeOff(id) {
							var displaystate = 'block';
							
							if (id.checked) {
								displaystate = 'none';
							}
							
							objShowHide('datetimes', displaystate);
						}
						</script>
						
						<p>
							<label for="id_allow_comments"><?php echo $lang['form_label_retake'];?></label><br />
							<?php echo $lang['txt_retake_help'];?><br />
						</p>
						
						<p>
							<input id="id_quiz_retake_daycount" type="text" class="input1" maxlength="5" name="quiz_retake_daycount" size="6" value="<?php if(isset($quiz['quiz_retake_daycount'])) { echo $quiz['quiz_retake_daycount'];}?>" />&nbsp;<?php echo $lang['txt_retake_days'];?><br />
						</p>
						
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" /><br />
						
						<p>
							<label for="id_allow_comments"><?php echo $lang['form_label_comment'];?></label><br />
							<?php echo $lang['txt_comments_help'];?><br />
						</p>
						
						<table border="0" cellspacing="0" cellpadding="2" width="100%">
							<tr>
								<td valign="top">
									<?php
									$selected = "";
									// if no quiz we are adding and we check the box
									if (isset($quiz['quiz_allow_comments']) && $quiz['quiz_allow_comments'] == 1) {
										$selected = "checked=\"checked\"";
									}
									elseif (!isset($quiz)) {
										$selected = "checked=\"checked\"";
									}
									?>
									<input id="id_allow_comments" type="checkbox" name="quiz_allow_comments" class="checkbox" value="1" <?php echo $selected;?> /><br />
								</td>
								<td valign="top">
									<label style="width:100%;font-weight:normal;" for="id_allow_comments"><?php echo $lang['form_label_comments'];?></label><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<input id="id_track" type="checkbox" name="ins_mark" class="checkbox" value="1" <?php if (!empty($quiz['bookmark']['bookmark_notify'])) { echo "checked=\"checked\"";}?> /><br />
								</td>
								<td valign="top">
									<label style="width:100%;font-weight:normal;" for="id_track"><?php echo $lang['form_label_track'];?></label><br />
								</td>
							</tr>
						</table>
					</td>
					<td>
						<img src="<?php echo $templatePath;?>img/pixel.png" width="20" height="1" alt="" /><br />
					</td>
					<td valign="top" width="50%">
						<?php
						if (isset($images)) {
						?>
						<p>
						<label for="id_file_id"><?php echo $lang['form_label_file'];?></label><br />
						<?php echo $lang['txt_image_intro'];?><br />
						</p>

						<div>
						<p>
						<select id="id_file_id" size=4 name="file_id" onChange='javascript:setimg(this)'>
						<option value="0" selected="selected"><?php echo $lang['txt_none'];?></option>
						<?php
						$img_divs = "";
						foreach($images as $key => $i):
						$display_state = "none";
						$selected = "";
						if (isset($quiz['file_id']) && $quiz['file_id'] == $i['file_id']) {
						    $selected = "selected=\"selected\"";
							$display_state = "block";
						}
						?>
						<option value="<?php echo $i['file_id'];?>" <?php echo $selected;?>><?php echo $i['file_name'];?></option>
						<?php
						$img_divs .= "<div style=\"display:" . $display_state . ";\" id=img" . $i['file_id'] . "><img src=\"get_file.php?file=" . $i['file'] . "\" border=\"0\" class=\"picture\" /><br />" . $i['file_title'] . "</div>";
						endforeach;
						?>
						</select>
						</p>
						</div>
						<?php echo $img_divs;?>
						<?php }?>
						
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" /><br />
						
						<p>
						<label for="id_allow_rsp_public"><?php echo $lang['form_label_publishing'];?></label><br />
						<?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($quiz['rsp'])) {
							foreach($quiz['rsp'] as $key => $rsp):
								if ($rsp['level_id'] == $rspconfig['rsp_level']['node']) {
									$rsp_node = 1;
									$rsp_degree = $rsp['degree_id'];
									$rsp_node_featured = $rsp['rsp_featured'];
								}
								elseif ($rsp['level_id'] == $rspconfig['rsp_level']['public']) {
									$rsp_public = 1;
									$rsp_public_featured = $rsp['rsp_featured'];
								}
								elseif ($rsp['level_id'] == $rspconfig['rsp_level']['group']['home']) {
									$rsp_group_home = 1;
								}
							endforeach;
						}
						?>
						
						<script type="text/javascript">
						function setNodeAll(id) {
							if (id.checked) {
								document.getElementById('id_node_id').checked=true;
							}
						}
						function setPub(id) {
							if (id.checked) {
								document.getElementById('id_level_id_public').checked=true;
							}
						}
						function setPublishingOff() {
							document.getElementById('id_node_featured').checked=false;

						}
						function setPubPublishingOff() {
							document.getElementById('id_public_featured').checked=false;

						}
						</script>
						<table border="0" cellspacing="0" cellpadding="2" width="100%">
							<?php
							if (isset($group)) {
							if ($this->group_acs->checkPermission($resource_ids['group']['rsp'], $privilege_ids['allow_rsp_public'])) { //resource_id, Priv_id
								if ($rspconfig['public']['auto_publish'] == 1) {
									$txt_rsp_public = $lang['txt_publish_auto_public_help'];
								}
								else {
									$txt_rsp_public = $lang['txt_publish_public_help'];
								}
							?>
							<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 $txt_rsp_public;?></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['txt_publish_auto_node_help'];
								}
								else {
									$txt_rsp_node = $lang['txt_publish_node_help'];
								}
							?>
							<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['txt_publish_auto_group_help'];
								}
								else {
									$txt_rsp_group = $lang['txt_publish_group_help'];
								}
							?>
							<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>
							<tr>
								<td colspan="2">
									<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="3" alt="" /><br />
								</td>
							<tr>
							<?php } ?>
							<?php
							}
							else {
							?>
							<tr>
								<td width="1" valign="middle">
									<input type="radio" class="checkbox" name="rsp_node" value="" checked="checked" onClick="javascript:setPublishingOff();" /><br />
								</td>
								<td valign="middle">
									<?php echo $lang['form_just_me'];?><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->user_acs->checkPermission($resource_ids['node']['rsp'], $privilege_ids['allow_rsp_network'])) { //resource_id, Priv_id
							$selected="";
							if (isset($rsp_node) && isset($rsp_degree)) {
								$selected=" checked=\"checked\"";
							}
							?>
							<tr>
								<td width="1" valign="middle">
									<input type="radio" name="rsp_node" class="checkbox" value="1"<?php echo $selected;?> onClick="javascript:setPublishingOff();" /><br />
								</td>
								<td valign="middle">
									<?php echo $lang['txt_degree_nw'];?><br />
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="3" alt="" /><br />
								</td>
							<tr>
							<?php }?>
							
							<?php
							if ($this->user_acs->checkPermission($resource_ids['node']['rsp'], $privilege_ids['allow_rsp_node'])) { //resource_id, Priv_id
							$selected="";
							if (isset($rsp_node) && empty($rsp_degree)) {
								$selected=" checked=\"checked\"";
							}
							?>
							<tr>
								<td valign="middle">
									<input id="id_node_id" type="radio" class="checkbox" name="rsp_node" value="all"<?php echo $selected;?> /><br />
								</td>
								<td valign="middle">
									<?php echo $lang['txt_publish_all'];?><br />
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="3" alt="" /><br />
								</td>
							<tr>
							<?php }?>
							
							<?php
							if ($this->user_acs->checkPermission($resource_ids['node']['rsp'], $privilege_ids['allow_rsp_public'])) { //resource_id, Priv_id
							$selected="";
							if (isset($rsp_public)) {
								$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" onClick="javascript:setPubPublishingOff();" /><br />
								</td>
								<td>
									<?php echo $lang['form_public'];?><br />
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="3" alt="" /><br />
								</td>
							<tr>
							<?php }?>
							<?php }?>
							
							
							<?php
							// write the featured item checkboxes
							if ($this->user_acs->checkPermission($resource_ids['node']['rsp'], $privilege_ids['allow_rsp_node_featured'])) { //resource_id, Priv_id
							$selected="";
							if (!empty($rsp_node_featured)) {
								$selected=" checked=\"checked\"";
							}
							
							if ($rspconfig['node']['auto_publish'] == 1) {
								$txt_rsp_node = $lang['txt_publish_auto_node_help'];
							}
							else {
								$txt_rsp_node = $lang['txt_publish_node_help'];
							}
							?>
							<tr>
								<td valign="top">
									<input type="checkbox" id="id_node_featured" name="rsp_node_featured" value="1"<?php echo $selected;?> class="checkbox" onClick="javascript:setNodeAll(this);" /><br />
								</td>
								<td>
									<?php echo $txt_rsp_node;?><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->user_acs->checkPermission($resource_ids['node']['rsp'], $privilege_ids['allow_rsp_public_featured'])) { //resource_id, Priv_id
							$selected="";
							if (!empty($rsp_public_featured)) {
								$selected=" checked=\"checked\"";
							}
							
							if ($rspconfig['public']['auto_publish'] == 1) {
								$txt_rsp_public = $lang['txt_publish_auto_public_help'];
							}
							else {
								$txt_rsp_public = $lang['txt_publish_public_help'];
							}
							?>
							<tr>
								<td valign="top">
									<input type="checkbox" id="id_public_featured" name="rsp_public_featured" value="1"<?php echo $selected;?> class="checkbox" onClick="javascript:setPub(this);" /><br />
								</td>
								<td>
									<?php echo $txt_rsp_public;?><br />
								</td>
							</tr>
							<?php }?>
						</table>

						<script type="text/javascript">
						//check php did not set either of the publishing buttons
						if (document.getElementById('id_public_featured').checked) {
							document.getElementById('id_node_id').checked=true;
						}
						if (document.getElementById('id_node_featured').checked) {
							document.getElementById('id_node_id').checked=true;
						}
						</script>
					</td>
				</tr>
			</table>
			
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" /><br />
			
			<p align="right">
				<input type="submit" class="input_submit" name="save" value="<?php echo $lang['sub_save'];?>" />&nbsp;
				<input type="submit" class="input_submit" name="save_go" value="save and go" /><br />
			</p>
			<?php }?>
		</div>
	</div>
</div>
	
<div class="box_bottom">
	<span class="box_bottom_right"></span>
	<span class="box_bottom_left"></span>
</div>
</form>
