<?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_blog.php" method="post">
<input type="hidden" name="user_id" value="<?php echo $user['user_id'];?>" />

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

			<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['section_action'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td>
						<a href="my_blog.php" class="txt_sub_menu"><?php echo $lang['href_list'];?></a><br />
						<a href="my_blog.php?add_blog=1" class="txt_sub_menu"><?php echo $lang['href_add_blog'];?></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">
			<?php
			if (isset($display) && $display == "add_blog") {
			?>
			<?php
			if (count($user['language_ids']) == 1) {
			?>
			<input type="hidden" name="data[language_id]" value="<?php echo $user['language_id'];?>" />
			<?php
			}
			?>
			<table border="0" cellspacing="0" cellpadding="4" width="100%">
				<tr>
					<td colspan="2" class="txt_title" align="right">
						<?php echo $lang['hdr_blog'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td>
						<table border="0" cellspacing="0" cellpadding="4" width="100%">
							<tr>
								<td valign="top">
									<b><?php echo $lang['txt_blog_title'];?></b><br />
									<span class="txt_footer"><?php echo $lang['txt_blog_title_help'];?></span><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<input type="text" name="data[blog_title]" class="formInput" size="50" value="<?php if (isset($blog['blog_title'])) echo $blog['blog_title'];?>" /><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<b><?php echo $lang['txt_blog_synopsis'];?></b><br />
									<span class="txt_footer"><?php echo $lang['txt_blog_synopsis_help'];?></span><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<textarea name="data[blog_synopsis]" rows="1" cols="85" class="formInput" /><?php if (isset($blog['blog_synopsis'])) echo $blog['blog_synopsis'];?></textarea><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<b><?php echo $lang['txt_blog_body'];?></b><br />
									<span class="txt_footer"><?php echo $lang['txt_blog_body_help'];?></span><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<textarea name="data[blog_body]" rows="10" cols="85" class="formInput" /><?php if (isset($blog['blog_body'])) echo $blog['blog_body'];?></textarea><br />
								</td>
							</tr>
							<tr>
								<td>
									<b><?php echo $lang['txt_genre'];?></b><br />
									<span class="txt_footer"><?php echo $lang['txt_genre_help'];?></span><br />
								</td>
							</tr>
							<tr>
								<td>
									<select name="data[genre_id]" class="formInput">
										<option value="0"><?php echo $lang['txt_other'];?></option>
										<?php
										foreach($lang['arr_genre'] as $key => $i):
											$selected = "";
											if(isset($blog['genre_id']) && $blog['genre_id'] == $key) {
												$selected = " selected=\"selected\"";
											}
											print "<option value='" . $key . "'" . $selected . ">" . $i . "</option>";
										endforeach;
										?>
									</select>
								</td>
						    </tr>
							<?php
							if (count($user['language_ids']) > 1) {
							?>
							<tr>
								<td valign="top">
									<b><?php echo $lang['txt_language'];?></b><br />
									<span class="txt_footer"><?php echo $lang['txt_language_help'];?></span><br />
								</td>
							</tr>
							<tr>
								<td>
									<select name="data[language_id]" class="formInput">
										<?php foreach($user['language_ids'] as $key => $i): ?>
										
										<option value="<?php echo $i;?>" <?php if($user['language_id'] == $i) echo "selected=\"selected\"";?>><?php echo $lang['arr_lang_name'][$i];?></option>
										
										<?php endforeach; ?>
									</select><br />
								</td>
							</tr>
							<?php
							}
							?>
						</table>
						
						<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 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">
										<?php
										$selected=" checked=\"checked\"";
										foreach($lang['sn']['degree'] as $key => $i):
										
										if (isset($blog['degree_id']) && $key == $blog['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 (isset($blog['level_id']) && $level_node == $blog['level_id']) {
											$selected=" checked=\"checked\"";
										}
										?>
										<tr>
											<td>
												<input type="radio" name="data[degree_id]" value="node"<?php echo $selected;?> /><br />
											</td>
											<td>
												<b><?php echo $lang['txt_publish_node'];?></b><br />
											</td>
										</tr>
										<tr>
											<td>
												<br />
											</td>
											<td class="txt_footer">
												<?php echo $lang['txt_publish_node_help'];?><br />
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<tr>
								<td>
									<input type="checkbox" name="data[blog_allow_comments]" value="1" <?php if (isset($blog['blog_allow_comments']) && $blog['blog_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%">
							<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">
										<tr>
											<?php
											$images_per_row = 4;
											$r = 0;
											foreach($images as $key => $i):
						
						
											$selected = "";
												if (isset($blog['file_id']) && $blog['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_blog" value="<?php echo $lang['sub_preview'];?>" class="formInput" />&nbsp;&nbsp;

									<?php
									if (isset($blog['blog_id']) && $blog['blog_id'] > 0) {
									?>
									<input type="hidden" name="data[blog_id]" value="<?php echo $blog['blog_id'];?>" />
									<input type="submit" name="update_blog" value="<?php echo $lang['sub_save'];?>" class="formInput" />
									<?php
									}
									else {
									?>
									<input type="submit" name="insert_blog" value="<?php echo $lang['sub_save'];?>" class="formInput" />
									<?php
									}
									?>
									<br />
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			<?php
			}
			else if (isset($display) && $display == "preview_blog") {
			?>
			<input type="hidden" name="data[blog_id]" value="<?php if (isset($blog['blog_id'])) {echo $blog['blog_id'];}?>" />
			<input type="hidden" name="data[blog_title]" value="<?php echo $blog['blog_title'];?>" />
			<input type="hidden" name="data[blog_synopsis]" value="<?php echo $blog['blog_synopsis'];?>" />
			<input type="hidden" name="data[blog_body]" value="<?php echo $blog['blog_body'];?>" />
			<input type="hidden" name="data[level_id]" value="<?php echo $blog['level_id'];?>" />
			<input type="hidden" name="data[degree_id]" value="<?php echo $blog['degree_id'];?>" />
			<input type="hidden" name="data[genre_id]" value="<?php echo $blog['genre_id'];?>" />
			<input type="hidden" name="data[file_id]" value="<?php if (isset($blog['file_id'])) { echo $blog['file_id'];}?>" />
			<input type="hidden" name="data[language_id]" value="<?php if (isset($blog['language_id'])) { echo $blog['language_id'];}?>" />
			<input type="hidden" name="data[blog_allow_comments]" value="<?php if (isset($blog['blog_allow_comments'])) { echo $blog['blog_allow_comments'];}?>" />
				
			<table border="0" cellspacing="0" cellpadding="4" width="100%">
				<tr>
					<td colspan="2" class="txt_title" align="right">
						<?php echo $lang['hdr_blog'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td>
						<table border="0" cellspacing="0" cellpadding="4" width="100%">


							<tr>
								<td>
									<?php echo $blog['blog_title'];?><br />
								</td>
								<td align="right" class="txt_footer" nowrap>
									<?php echo $lang['txt_genre'];?>:

									<?php
									if (isset($blog['genre_id']) && $blog['genre_id'] > 0) {
									    echo $lang['arr_genre'][$blog['genre_id']];
									}
									else {
										echo $lang['txt_other'];
									}
									?>
									<br />
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<?php echo $blog['blog_synopsis'];?><br />
									<p>
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<?php echo $blog['blog_body_display'];?><br />
								</td>
							</tr>
							<tr>
								<td align="right" colspan="2">
									<input type="submit" name="edit_blog_again" value="<?php echo $lang['sub_edit'];?>" class="formInput" />&nbsp;&nbsp;
									<?php
									if (isset($blog['blog_id'])) {
										$next_action = "update_blog";
									}
									else {
										$next_action = "insert_blog";
									}
									?>

									<input type="submit" name="<?php echo $next_action;?>" value="<?php echo $lang['sub_save'];?>" class="formInput" />
									<br />
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>

			<?php
			}
			else if (isset($display) && $display == "view_blog") {
			?>
			<input type="hidden" name="blog_id" value="<?php echo $blog['blog_id'];?>" />
			
			<table border="0" cellspacing="0" cellpadding="4" width="100%">
				<tr>
					<td colspan="2" class="txt_title" align="right">
						<?php echo $lang['hdr_blog'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td>
						<table border="0" cellspacing="0" cellpadding="4" width="100%">
							<tr>
								<td class="txt_footer">
									<?php echo $blog['blog_create_datetime'];?><br />
								</td>
								<td align="right" class="txt_footer" nowrap>
									<?php echo $lang['txt_genre'];?>:

									<?php
									if (isset($blog['genre_id']) && $blog['genre_id'] > 0) {
									    echo $lang['arr_genre'][$blog['genre_id']];
									}
									else {
										echo $lang['txt_other'];
									}
									?>
									<br />
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<b><?php echo $blog['blog_title'];?></b><br />
									<?php echo $blog['blog_body_display'];?><br />
								</td>
							</tr>
							<tr>
								<td class="txt_footer">
									<?php
									if (isset($comments) && count($comments) > 0) {
										echo $lang['txt_comment_no_delete'];
									}
									else {
									?>
									<input type="submit" name="delete_blog" value="<?php echo $lang['sub_delete'];?>" class="formInput" />
									<?php }?><br />
								</td>
								<td align="right">
									<input type="submit" name="edit_blog" value="<?php echo $lang['sub_edit'];?>" class="formInput" /><br />
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="10" alt="" /><br />
			
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td class="txt_title" align="right">
						<?php echo $lang['section_comments'];?><br />
						<hr />
					</td>
				</tr>
				<?php
				if (isset($comments)) {
				foreach($comments as $key => $i):
				?>
				<tr>
					<td>
						<table width="100%" cellpadding="4" cellspacing="0" border="0">
							<tr>
								<td class="txt_footer" colspan="2">
									<?php echo $lang['txt_from'];?>: <a href="sn_profile.php?user_id=<?php echo $i['user_id'];?>" class="txt_footer_link"><?php echo $i['profile_nic'];?></a>&nbsp;(<?php echo $lang['txt_joined'];?>: <?php echo $i['profile_create_datetime'];?>, <?php echo $lang['txt_hometown'];?>: <?php echo $i['profile_hometown'];?>)<br />
									<?php echo $lang['txt_comment_datetime'];?>: <?php echo $i['comment_create_datetime'];?><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<?php echo $i['comment_body'];?><br />
								</td>
						    </tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="4" alt="" /><br />
					</td>
				</tr>
				<?php
				endforeach;
				}
				else {
				?>
				<tr>
					<td>
						<?php echo $lang['err_no_comments'];?><br />
					</td>
				</tr>
				<?php }?>
			</table>

			<?php
			}
			else {
			?>
			<table border="0" cellspacing="0" cellpadding="4" width="100%">
				<tr>
					<td colspan="2" class="txt_title" align="right">
						<?php echo $lang['hdr_blog'];?><br />
						<hr />
					</td>
				</tr>
				<?php
				if (isset($blogs)) {
				?>
				<tr>
					<td>
						<table border="0" cellspacing="0" cellpadding="4" width="100%">
							<?php
							foreach($blogs as $key => $i):
							?>
							<tr>
								<td>
									<a href="my_blog.php?blog_id=<?php echo $i['blog_id'];?>"><img align="left" src="get_file.php?file=<?php echo $i['image']['file'];?>" border="0" class="picture_left" title="<?php echo $i['image']['file_title'];?>"></a>
									<a href="my_blog.php?blog_id=<?php echo $i['blog_id'];?>"><?php echo $i['blog_title'];?></a><br />
								</td>
								<td align="right">
									<?php echo $i['blog_create_datetime'];?><br />
								</td>
							</tr>
							<tr>
								<td colspan="2" class="txt_footer">
									<?php echo $i['blog_synopsis'];?><br />
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="4" alt="" /><br />
								</td>
							</tr>
							<?php
							endforeach;
							?>
						</table>
					</td>
				</tr>
				<?php 
				}
				else {
				?>
				<tr>
					<td>
						<?php echo $lang['err_no_blogs'];?><br />
					</td>
				</tr>
				<?php }?>
			</table>
			<?php }?>
		</td>
	</tr>
</table>
</form>
