<?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="my_library_edit.php" method="post">
<input type="hidden" name="page" value="<?php echo $library['library_page_name'];?>" />
<input type="hidden" name="user_id" value="<?php echo $user['user_id'];?>" />
<?php
if (count($user['language_ids']) == 1) {
?>
<input type="hidden" name="data[language_id]" value="<?php echo $user['language_id'];?>" />
<?php
}
?>

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

			<?php
			if (isset($library['library_id'])) {
			?>
			<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 class="txt_title">
						<?php echo $lang['hdr_document'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td class="txt_footer">
						<b><?php echo $lang['txt_pagename'];?></b><br />
						<?php echo $library['library_page_name'];?><br />
					</td>
				</tr>
				<tr>
					<td class="txt_footer">
						<b><?php echo $lang['txt_date'];?></b><br />
						<?php echo $library['library_create_datetime'];?><br />
					</td>
				</tr>
			</table>
			<?php
			}
			?>


			<?php
			if (isset($pages)) {
			?>
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="10" alt="" /><br />

			<table width="100%" cellpadding="4" cellspacing="0" border="0" class="table_stnd">
				<tr>
					<td class="txt_title">
						<?php echo $lang['hdr_page_names'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td class="txt_footer">
						<?php
						foreach($pages as $key => $i):
						echo $i . "<br />";
						endforeach;
						?>
						<br />
					</td>
				</tr>
			</table>
			<?php
			}
			?>

			<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="table_stnd">
				<tr>
					<td colspan="2" class="txt_title" align="right">
						<?php echo $lang['hdr_library'];?><br />
						<hr />
					</td>
				</tr>

				<?php
				if (isset($display) && $display == "add_library") {
				?>

				<tr>
					<td>
						<table border="0" cellspacing="0" cellpadding="4" width="100%" class="table_nested">
							<tr>
								<td valign="top">
									<b><?php echo $lang['txt_library_title'];?></b><br />
									<span class="txt_footer"><?php echo $lang['txt_library_title_help'];?></span><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<input type="text" name="data[library_title]" class="formInput" size="80" value="<?php if (isset($library['library_title'])) echo $library['library_title'];?>" /><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<b><?php echo $lang['txt_library_desc'];?></b><br />
									<span class="txt_footer"><?php echo $lang['txt_library_desc_help'];?></span><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<textarea name="data[library_synopsis]" rows="2" cols="85" class="formInput" /><?php if (isset($library['library_synopsis'])) echo $library['library_synopsis'];?></textarea><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<b><?php echo $lang['txt_library_body'];?></b><br />
									<span class="txt_footer"><?php echo $lang['txt_library_body_help'];?></span><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<textarea name="data[library_body]" rows="10" cols="85" class="formInput"><?php if (isset($library['library_body'])) echo $library['library_body'];?></textarea><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<b><?php echo $lang['txt_default'];?></b><br />
									<span class="txt_footer"><?php echo $lang['txt_default_help'];?></span><br />
								</td>
							</tr>
							<tr>
								<td valign="top" class="txt_footer">
									<?php
									if (isset($library['library_default']) && $library['library_default'] > 0) {
									    echo $lang['txt_default_set'];
									?>
									<input type="hidden" name="data[library_default]" value="1" />
									<?php
									}
									else {
									?>
									<input type="checkbox" name="data[library_default]" value="1" />

									<?php
									}
									?><br />
								</td>
							</tr>
						</table>
						
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="10" alt="" /><br />
						
						<table border="0" cellspacing="0" cellpadding="4" width="100%" class="table_nested">
							<tr>
								<td valign="top" class="txt_title" align="right">
									<?php echo $lang['section_publishing'];?><br />
									<hr />
								</td>
							</tr>
							<tr>
								<td>
									<?php echo $lang['txt_publish_help'];?><br />
								</td>
							</tr>
							<tr>
								<td>
									<table border="0" cellspacing="0" cellpadding="2" class="table_nested">
										<?php
										$selected=" checked=\"checked\"";
										foreach($lang['sn']['degree'] as $key => $i):
										
										if (isset($library['degree_id']) && $key == $library['degree_id']) {
											$selected=" checked=\"checked\"";
										}
										?>
										<tr>
											<td width="1">
												<input type="radio" name="data[degree_id]" value="<?php echo $key;?>"<?php echo $selected;?> /><br />
											</td>
											<td>
												<b><?php echo $i;?></b><br />
											</td>
										</tr>
										<tr>
											<td>
												<br />
											</td>
											<td class="txt_footer">
												<?php echo $lang['sn']['degree_desc'][$key];?><br />
											</td>
										</tr>
										<?php
										$selected="";
										endforeach;
										if ($this->user_acs->checkPermission($resource_ids['cms'], $privilege_ids['allow_cms_node']) || $this->user_acs->checkPermission($resource_ids['cms'], $privilege_ids['allow_cms_public'])) { //resourece_id, Priv_id
										if (isset($library['level_id']) && ($level_node == $library['level_id'] || $level_public == $library['level_id']) || (isset($library['degree_id']) && $library['degree_id'] == "level")) {
											$selected=" checked=\"checked\"";
										}
										?>
										<tr>
											<td>
												<input type="radio" name="data[degree_id]" value="level"<?php echo $selected;?> /><br />
											</td>
											<td>
												<b><?php echo $lang['txt_publish_level'];?></b><br />
											</td>
										</tr>
										<?php
										}
										
										if ($this->user_acs->checkPermission($resource_ids['cms'], $privilege_ids['allow_cms_node'])) { //resourece_id, Priv_id
										$selected="";
										if ((isset($library['level_id']) && $level_node == $library['level_id']) || (isset($library['level_id_node']) && $library['level_id_node'] == $level_node)) {
											$selected=" checked=\"checked\"";
										}
										?>
										<tr>
											<td>
												<br />
											</td>
											<td class="txt_footer">
												<input type="checkbox" name="data[level_id_node]" value="1"<?php echo $selected;?> />&nbsp;
												<?php echo $lang['txt_publish_node_help'];?><br />
											</td>
										</tr>
										<?php
										}
										
										if ($this->user_acs->checkPermission($resource_ids['cms'], $privilege_ids['allow_cms_public'])) { //resourece_id, Priv_id
										$selected="";
										if ((isset($library['level_id']) && $level_public == $library['level_id']) || (isset($library['level_id_public']) && $library['level_id_public'] == $level_public)) {
											$selected=" checked=\"checked\"";
										}
										?>
										<tr>
											<td>
												<br />
											</td>
											<td class="txt_footer">
												<input type="checkbox" name="data[level_id_public]" value="1"<?php echo $selected;?> />&nbsp;
												<?php echo $lang['txt_publish_public_help'];?><br />
											</td>
										</tr>
										<?php }?>
									</table>
								</td>
							</tr>
							<tr>
								<td>
									<input type="checkbox" name="data[library_allow_comments]" value="1" <?php if (isset($library['library_allow_comments']) && $library['library_allow_comments'] == 1) echo "checked=\"checked\"";?> />&nbsp;<?php echo $lang['txt_allow_comments'];?><br />
								</td>
							</tr>
						</table>
						
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="10" alt="" /><br />
						
						<?php
						if (isset($images)) {
						?>
						<table border="0" cellspacing="0" cellpadding="4" width="100%" class="table_nested">
							<tr>
								<td colspan="<?php echo $images_per_row;?>" class="txt_title" align="right">
									<?php echo $lang['hdr_images'];?><br />
									<hr />
								</td>
							</tr>
							<tr>
								<td valign="top" colspan="<?php echo $images_per_row;?>">
									<span class="txt_footer"><?php echo $lang['txt_images_help'];?></span><br />
								</td>
							</tr>
							<tr>
								<td valign="top" colspan="<?php echo $images_per_row;?>">
									<input type="radio" value="0" name="data[file_id]" checked />&nbsp;no image<br />
								</td>
							</tr>
							<tr>
								<td>
									<table border="0" cellspacing="0" cellpadding="2" class="table_nested">
										<tr>
											<?php
											$images_per_row = 4;
											$r = 0;
											foreach($images as $key => $i):
						
						
											$selected = "";
												if (isset($library['file_id']) && $library['file_id'] == $i['file_id']) {
												    $selected = "checked";
												}
						
											?>
						
											<td valign="top">
												<img src="get_file.php?file=<?php echo $i['file']; ?>" border="0" class="picture" /><br />
												<?php echo $i['file_name']; ?>.<?php echo $i['file_suffix']; ?><br />
												<?php
												foreach($image_thumbs as $key1 => $f):
												?>
												<?php echo $i['file_name']; ?>.<?php echo $f['name']; ?><?php echo $i['file_suffix']; ?><br />
												<?php
												endforeach;
												?>
												<input type="radio" value="<?php echo $i['file_id'];?>" name="data[file_id]" <?php echo $selected;?> /><br />
											</td>
						
											<?php
											$r++;
											if ($r == $images_per_row) {
											    echo "</tr><tr>";
												$r=0;
											}
						
											endforeach;
											if ($r != $images_per_row) {
												$r = $images_per_row-$r;
												print "<td colspan=" . $r . "><br /></td>";
											}
											?>
										</tr>
									</table>
								</td>
							</tr>
						</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 align="right">
									<input type="submit" name="preview_library" value="<?php echo $lang['sub_preview'];?>" class="formInput" />&nbsp;&nbsp;
									<input type="submit" name="insert_library" value="<?php echo $lang['sub_save'];?>" class="formInput" />
									<br />
								</td>
							</tr>
						</table>
					</td>
				</tr>


				<?php
				}
				else if (isset($display) && $display == "preview_library") {
				?>
				<input type="hidden" name="data[page]" value="<?php echo $library['library_page_name'];?>" />
				<input type="hidden" name="data[library_title]" value="<?php echo $library['library_title'];?>" />
				<input type="hidden" name="data[library_synopsis]" value="<?php echo $library['library_synopsis'];?>" />
				<input type="hidden" name="data[library_body]" value="<?php echo $library['library_body'];?>" />
				<input type="hidden" name="data[library_default]" value="<?php if(isset($library['library_default'])) echo $library['library_default'];?>" />
				<input type="hidden" name="data[file_id]" value="<?php echo $library['file_id'];?>" />
				<input type="hidden" name="data[level_id_node]" value="<?php if(isset($library['level_id_node'])) echo $library['level_id_node'];?>" />
				<input type="hidden" name="data[level_id_public]" value="<?php if(isset($library['level_id_public'])) echo $library['level_id_public'];?>" />
				<input type="hidden" name="data[degree_id]" value="<?php if(isset($library['degree_id'])) echo $library['degree_id'];?>" />
				<input type="hidden" name="data[library_allow_comments]" value="<?php if(isset($library['library_allow_comments'])) echo $library['library_allow_comments'];?>" />
				
				<tr>
					<td>
						<table border="0" cellspacing="0" cellpadding="4" width="100%" class="table_nested">
							<tr>
								<td>
									<b><?php echo $lang['txt_library_desc'];?></b><br />
									<?php echo $library['library_synopsis'];?><br />
								</td>
							</tr>
							<tr>
								<td>
									<b><?php echo $library['library_title'];?></b><br />
								</td>
							</tr>

							<tr>
								<td>
									<?php echo $library['library_body_display'];?><br />
								</td>
							</tr>
							<tr>
								<td align="right">
									<input type="submit" name="edit_library_again" value="<?php echo $lang['sub_edit'];?>" class="formInput" />&nbsp;&nbsp;
									<input type="submit" name="insert_library" value="<?php echo $lang['sub_save'];?>" class="formInput" />
									<br />
								</td>
							</tr>
						</table>
					</td>
				</tr>

				<?php
				}
				elseif (isset($library['library_id'])) {
				?>
				<tr>
					<td>
						<?php echo $library['library_body'];?><br />
					</td>
				</tr>
				<?php
				}
				else {
				?>
				<tr>
					<td>
						<?php echo $lang['err_no_library'];?><br />
					</td>
				</tr>
				<?php }?>

			</table>
		</td>
	</tr>
</table>
</form>
