<%~if in.action eq 'bike_form'%>

  <%~if in.formsubmit%><%-- form submit --%>
    <%~set res = Plugins::GForum::Bikes::bike_submit %>
    <%~if res.error%>Error occurred: <%res.error%><%endparse%><%endif%>
    <%~if in.bike_add%><%set success = "The bike was added"%><%elsif in.bike_edit%><%set success = "The bike was updated"%><%elsif in.delete_it%><%set success = "The bike was deleted"%><%endif%>

    <%~if success%>
<%include include_bike_list.html%>
      <%endparse%>
    <%~endif%>
  <%~endif%>

  <%~set select_bike_id = $form.select_bike_id%>
  <%~if select_bike_id%>
    <%~Plugins::GForum::Bikes::get_user_bikes($user_id)%>
    <%~loop user_bikes_loop%>
      <%if bike_id == $select_bike_id%>
<%include include_bike_form.html%>
        <%lastloop%>
      <%endif%>
    <%~endloop%>
  <%~else%>
<%include include_bike_form.html%>
  <%~endif%>
  <%~endparse%>
<%~endif%>

<!DOCTYPE html>
<html lang="en">
<head>
  <title><%cat_full_name%>: User Profile: <%user_username%></title>
  <%include include_common_head.html%>
</head>
<body class="page-<%page_id%>">
  <div class="container-b">
    <%include include_header.html%>

    <div class="main">
      <%~set content_header_title = $user_username%>

      <%~init array breadcrumbs%><%init hash breadcrumbs.0%>
      <%~set breadcrumbs.0.name = $user_username%>
      <%~set url_user_username = escape_url unescape_html $user_username%>

      <div class="contentwrapper clearfix">
        <div class="sidebar">
            <%include include_sidebar.html%>
        </div>

        <%include include_breadcrumb.html%>

        <div class="content"><%-- start content--%>
          <%include include_content_header.html%>
          <form action="<%GForum::SEO::url()%>"><%hidden_form%></form>

          <div class="clearfix">
            <div class="col-6 account-info">
              <div class="dtable form">
                <div class="drow">
                  <div class="dcell name">Status</div>
                  <div class="dcell divider"></div>
                  <div class="dcell value">
                    <%user_status_string%> - <%----%>
                    <%~if user_invisible and current.user_status < $ADMINISTRATOR%>Offline
                    <%~elsif user_online%><span class="user-online">Online</span>
                    <%~else%>Offline
                    <%~endif%>
                  </div>
                </div>
                <div class="drow">
                  <div class="dcell name">Registered</div>
                  <div class="dcell divider"></div>
                  <div class="dcell value"><%user_registered_date%></div>
                </div>
                <div class="drow">
                  <div class="dcell name">Last Logged On</div>
                  <div class="dcell divider"></div>
                  <div class="dcell value"><%user_last_logon_date%></div>
                </div>
                <%~if not user_invisible or current_user_status == 3%>
                <div class="drow">
                  <div class="dcell name">Local Time</div>
                  <div class="dcell divider"></div>
                  <div class="dcell value"><%user_localdate%></div>
                </div>
                <%~endif%>
                <div class="drow">
                  <div class="dcell name">Posts</div>
                  <div class="dcell divider"></div>
                  <div class="dcell value">
                      <%user_posts%> (<%user_posts /1 $user_days_registered%> per day) | 
                      <a class="profile-favourites" href="<%GForum::SEO::url(params => "do=search_results;search_user_username=$url_user_username")%>">view posts</a>
                      <%--
                      <a class="profile-favourites" href="<%GForum::SEO::url(params => "do=others_favourites;user_id=$user_id")%>"><%num_favourites_others%></a> favourited by others<br/>
                      <a class="profile-favourites" href="<%GForum::SEO::url(params => "do=user_favourites;user_id=$user_id")%>"><%num_favourites%></a> favourited by <%user_username%>
                      --%>
                  </div>
                </div>
                <div class="drow">
                  <div class="dcell name">Real Name</div>
                  <div class="dcell divider"></div>
                  <div class="dcell value"><%user_real_name || 'No name entered.'%></div>
                </div>
                <%~if user_occupation%>
                <div class="drow">
                  <div class="dcell name">Occupation</div>
                  <div class="dcell divider"></div>
                  <div class="dcell value"><%user_occupation%></div>
                </div>
                <%~endif%>
                <%~if user_interests%>
                <div class="drow">
                  <div class="dcell name">Interests</div>
                  <div class="dcell divider"></div>
                  <div class="dcell value"><%user_interests%></div>
                </div>
                <%~endif%>
                <div class="drow">
                  <div class="dcell name">Location</div>
                  <div class="dcell divider"></div>
                  <div class="dcell value"><%user_location || 'No location entered.'%></div>
                </div>
                <div class="drow">
                  <div class="dcell name">E-mail</div>
                  <div class="dcell divider"></div>
                  <div class="dcell value">
                    <%~if current_user_id and $current_user_status >= 3%>
                    <a href="mailto:<%user_email%>"><%user_email%></a>
                    <%~else%>
                    <%user_disp_email || 'No email entered.'%>
                    <%~endif%>
                  </div>
                </div>
                <%~if current_user_id and $current_user_status >= 3%>
                <div class="drow">
                  <div class="dcell name">Admin Options</div>
                  <div class="dcell divider"></div>
                  <div class="dcell value">
    	            <a href="/cgi-bin/admin/db.cgi?db=User;do=search_results;user_id=<%user_id%>;user_id-opt=%3D;display=details" target="admin">Details</a> | <a href="/cgi-bin/admin/db.cgi?db=User;do=modify_search_results;user_id=<%user_id%>;user_id-opt=%3D" target="admin">Modify</a> | <a href="/cgi-bin/admin/db.cgi?db=User;do=delete_search_results;user_id=<%user_id%>;user_id-opt=%3D" target="admin">Delete</a>
                  </div>
                </div>
                <%~endif%>
                <%~if user_homepage%>
                <div class="drow">
                  <div class="dcell name">Homepage</div>
                  <div class="dcell divider"></div>
                  <div class="dcell value"><%if user_homepage%><a href="<%user_homepage%>" target="_blank"><%user_homepage%></a><%endif%></div>
                </div>
                <%~endif%>
                <%~if user_twitter%>
                <div class="drow">
                  <div class="dcell name">Twitter</div>
                  <div class="dcell divider"></div>
                  <div class="dcell value"><%user_twitter%></div>
                </div>
                <%~endif%>
                <%~if user_about%>
                <div class="drow">
                  <div class="dcell name">About Me</div>
                  <div class="dcell divider"></div>
                  <div class="dcell value"><%user_about%></div>
                </div>
                <%~endif%>
              </div>
            </div>
            <div class="col-6 account-photos">
              <h4>Photos</h4>
              <div class="photo-wrapper">
                <%Plugins::GForum::SlideShow::generate_paths($user_id)%>
                <%if user_image1 and $user_image1_large_path%><a href="<%user_image1_large_path%>" data-lightbox="photo"><img src="<%user_image1_thumbnail_path%>" border="0" /></a><%endif%>
                <%if user_image2 and $user_image2_large_path%><a href="<%user_image2_large_path%>" data-lightbox="photo"><img src="<%user_image2_thumbnail_path%>" border="0" /></a><%endif%>
                <%if user_image3 and $user_image3_large_path%><a href="<%user_image3_large_path%>" data-lightbox="photo"><img src="<%user_image3_thumbnail_path%>" border="0" /></a><%endif%>
                <%if user_image4 and $user_image4_large_path%><a href="<%user_image4_large_path%>" data-lightbox="photo"><img src="<%user_image4_thumbnail_path%>" border="0" /></a><%endif%>
                <%if user_image5 and $user_image5_large_path%><a href="<%user_image5_large_path%>" data-lightbox="photo"><img src="<%user_image5_thumbnail_path%>" border="0" /></a><%endif%>
                <%if user_image6 and $user_image6_large_path%><a href="<%user_image6_large_path%>" data-lightbox="photo"><img src="<%user_image6_thumbnail_path%>" border="0" /></a><%endif%>
              </div>
              <%~if current_user_username eq $user_username%>
              <div class="btn-wrapper">
                <a href="<%GForum::SEO::url(params => "do=user_profile_basic")%>" title="Update Photos" class="btn">Update Photos</a>
              </div>
              <%~endif%>
            </div>
          </div>

          <div class="clearfix">
            <div class="col-6 account-races">
              <h4>Races</h4>
              <%~if user_username eq $current_user_username or user_show_racetags%>
              <%~if user_show_racetags%>
              <%~mixed_calendar_loop($user_id, $user_username)%>
              <%~endif%>
              <%~endif%>

              <%~if race_loop.length%>
              <%~get_cgi_value('from')%>
              <div class="dtable form">
                <%~loop race_loop%>
                <div class="drow">
                  <div class="dcell name"></div>
                  <div class="dcell divider"></div>
                  <div class="dcell value">
                    <%~if user_race%>
                      <%~if url%><a href="<%url%>"><%endif%><span class="race-name"><%name%></span><%if url%></a><%endif%>
                    <%~else%>
                    <a href="<%url%><%if cgi_from eq 'racecalendar'%>?<%hidden_query%><%endif%>&from=gforum"><span class="race-name"><%name%></span></a>
                    <%~endif%>
                    <%if user_race and $current_user_username eq $user_username%> - <small><a href="<%cgi_root_url%>/gforum.cgi?do=personal_race_edit_form;race_id=<%id%><%hidden_query%>">[edit]</a></small><%endif%>
                    <span class="race-info"><br /><%location%><br /><%racedate%></span>
                  </div>
                </div>
                <%~endloop%>
              </div>
              <p><b>Note:</b> to deselect a race from your personal calendar, click the race's link, then click "untag this race."</p>
              <%~else%>
              <p>No race found.</p>
              <%~endif%>

              <%if current_user_username eq $user_username%>
              <div class="btn-wrapper">
                <a href="<%GForum::SEO::url(params => "do=personal_race_add_form")%>" class="btn">Add a Personal Race</a>
              </div>
              <%endif%>
            </div>
            <div class="col-6 account-retailers">
              <h4>Retailers</h4>
              <%~slowtwitch_retailer_loop($user_username)%>
              <%~if shop_loop.length%>
              <div class="dtable form">
                <%~loop shop_loop%>
                <div class="drow">
                  <div class="dcell name"></div>
                  <div class="dcell divider"></div>
                  <div class="dcell value">
                    <a href="<%url%><%if cgi_from eq 'retailers'%>?<%hidden_query%><%endif%>&from=gforum"><%name%></a>
                    <br /><%location%>
                  </div>
                </div>
                <%~endloop%>
              </div>
              <p><b>Note:</b> to deselect a retailer from your personal shopping list, click the shop's link, then click "untag this shop."</p>
              <%~else%>
              <p>No retailer found.</p>
              <%~endif%>
            </div>
          </div>

          <h4>Bike Fit Manager</h4>
          <div class="clearfix">
            <div class="col-6 account-coordinates">
              <div class="dtable form">
                <div class="drow">
                  <div class="dcell name"></div>
                  <div class="dcell divider"></div>
                  <div class="dcell value">
                    <div class="title">Personal Fit Coordinates</div>
                    <div class="tria-view">
                      <div class="title">Triathlon view</div>
                      <img src="<%static_url%>/images/fit_triathlon.jpg" />
                    </div>
                    <div class="road-view">
                      <div class="title">Road view</div>
                      <img src="<%static_url%>/images/fit_road.jpg" />
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div id="account-bikes" class="col-6 account-bikes">
              <div class="bike-form"></div>
              <div class="bike-list">
                <%include include_bike_list.html%> 
                <%~if current_user_id == $user_id%>
                <div class="btn-wrapper">
                  <a href="<%GForum::SEO::url(params => "username=$user_username;action=bike_form")%>" rel="edit" class="btn">Add a Bike</a>
                </div>
                <%~endif%>
              </div>
            </div>
          </div>

          <%~if current_user_id%>
          <%Plugins::GForum::SlideShow::change_logs($user_id)%>
          <%~if username_log_loop.length%>
          <h4>Change Logs</h4>
          <div class="dtable">
            <%~loop username_log_loop%>
            <div class="drow">
              <div class="dcell date"><%GT::Date::date_transform($Log_time,'%yyyy%-%mm%-%dd% %HH%:%MM%:%ss%','%yyyy%-%mm%-%dd%')%></div>
              <div class="dcell"><%Log_old_username%></div>
              <div class="dcell"><%Log_new_username%></div>
            </div>
            <%~endloop%>
          </div>
          <%~endif%>
          <%endif%>

        </div><%-- end content --%>
      </div>

    </div>
    <%include include_footer.html%>
  </div>
</body>
<%~include include_global_js.html%>
<script type="text/javascript" src="<%static_url%>/js/lightbox.min.js"></script>
  <script type="text/javascript">
    $(document).ready(function() {
      GForum.init_post_only();

      var url = "<%GForum::SEO::url(params => "username=$user_username")%>";

      /* bike form actions */
      var _closeForm = function() {
          $('.account-bikes .bike-form').slideUp('fast', function() { $(this).html(''); });
          $('.account-bikes .bike-list').show();
      };

      /* bike details */
      var _initViewBike = function() {
        $('.account-bikes a[rel=more]').each(function() {
          $(this).click(function() {
            var item = $(this).parent().siblings('.bike-info').find('.bike-details');
            if (item.is(':visible')) {
              item.slideUp();
              $(this).html('View More');
            }
            else {
              item.slideDown();
              $(this).html('Hide More');
            }
            return false;
          })
        });
      };


      var _initEditBike = function() {
        $('.account-bikes a[rel=edit]').each(function() {
          $(this).click(function() {
            $.ajax({
              url: $(this).attr('href'),
              dataType: 'html',
              success: function(html) {
                $('.account-bikes .bike-form').html(html).slideDown('fast', function() {
                  $(this).find('form').ajaxForm({
                    success: function(html) {
                      if (html.search(/Error/) >= 0) {
                        $('.account-bikes .error').html(html).show();
                      }
                      else {
                        $('.account-bikes .bike-list').html(html);
                        _initViewBike();
                        _initEditBike();
                        _closeForm();
                      }
                    }
                  });

                  $(this).find('.sprite-close').click(function() {
                    _closeForm();
                    return false;
                  });

                  var obj = $(this);
                  $(this).find('input[name=bdelete]').click(function() {
                    if (confirm("Are you sure you want to delete this bike?")) {
                      obj.find('input[name=delete_it]').val('1');
                      obj.find('form').submit();
                    }
                  })
                });
                $('.account-bikes .bike-list').hide();
              }
            })
            return false;
          })
        })
      };

      _initViewBike();
      _initEditBike();

    });
  </script>
</html>
