<?php

include 'views/_header.tpl.php'; ?>

<style>
.search-result-page .common-title {
    padding-bottom: 5px;
	width:100%;
	display:block;
}
.list-project-in-category .list-project > .grid_3 {
    width: 21.3%;
}
.list-project-in-category .list-project .project-short {

}
.search-result-page .top-lbl-val {
    padding-bottom: 0px;
}
.list-project-in-category {
    margin-bottom: 0px;
}
.project-short.sml-thumb .bottom-project-info {
    display:none;
}
</style>

    <div class="layout-2colsxxxx container_12 clearfix">
            <div class="search-result-page">
                <div class="top-lbl-val">
                    <h3 class="common-title">Discover / <span class="fc-orange">Search</span></h3>
                    <div class="count-result">
                        <span class="fw-b fc-black"><?= $total_count_items ?></span> item<?php if ($total_count_items > 1) { echo 's'; } ?> found for “<span class="fw-b fc-black"><?= $term ?></span>”
                    </div>
                </div>

                <?php if (!empty($projects)) : ?>
                <h3 class="common-title"><span class="fc-orange">Articles &amp; Events</span></h3>
                <?php endif; ?>

                <div class="list-project-in-category">
                    <div class="list-project">
                    
	            	<?php
	            	foreach ($projects as $project) : ?>

            		<div class="grid_3">
	                    <div class="project-short sml-thumb" style="min-height:475px;">
	                        <div class="top-project-info">
	                            <div class="content-info-short clearfix">
									<div style="max-height:230px; overflow:hidden;">
	                                <a href="/project/<?= $project['id'] ?>" class="thumb-img">
	                                    <img src="/<?= $project['main_img'] ?>" alt="<?= $project['title'] ?>" />
	                                </a>
									</div>
	                                <div class="wrap-short-detail">
	                                    <h3 class="rs acticle-title"><a class="be-fc-orange" href="/project/<?= $project['id'] ?>"><?= $project['title'] ?></a></h3>
	                                    <p class="rs tiny-desc">by <a href="/profile/<?= $project['user']['user_slug'] ?>" class="fw-b fc-gray be-fc-orange"><?= $project['user']['name'] ?></a></p>
	                                    <p class="rs title-description"><?= substr(strip_tags($project['description']),0, 100) ?>...<a href="/project/<?= $project['id'] ?>" class="be-fc-orange" 
										style="font-weight:300; color:#24577C;">read more &raquo;</a></p>
	                                    <p class="rs project-location">
	                                        <i class="icon iLocation"></i>
	                                        <?= $project['location'] ?>
	                                    </p>
	                                </div>
	                            </div>
	                        </div>

	                        <div class="bottom-project-info clearfix">
                                <div class="project-progress sys_circle_progress" data-percent="0">
                                    <div class="sys_holder_sector"></div>
                                </div>
                                <div class="group-fee clearfix">

                                    <div class="fee-item">
                                        <p class="rs lbl">Views</p>
                                        <span class="val"><?= $project['views'] ?></span>
                                    </div>
                                    <div class="sep"></div>
                                    <div class="fee-item">
                                        <p class="rs lbl">Comments</p>
                                        <span class="val"><?= $project['reviews_submitted'] ?></span>
                                    </div>
                                    <div class="sep"></div>
                                    <div class="fee-item">
                                        <p class="rs lbl">Redeem Type</p>
                                        <span class="val"><?= $project['redeem_type'] ?></span>
                                    </div>
                                    <div class="sep"></div>
                                    <div class="fee-item">
                                        <p class="rs lbl">Redeem Count</p>
                                        <span class="val" style="color:#4ba220;"><?= count($project['redeems']) ?></span>
                                    </div>
                                </div>
                                <div class="clear"></div>
                            </div>
	                    </div>
	                </div>

                	<?php
                	endforeach; ?>

                    </div>
                </div><!--end: .list-project-in-category ($deals) -->
				
				<div class="clear"></div>
				
                <?php if (!empty($deals)) : ?>
                <h3 class="common-title"><span class="fc-orange">Events</span></h3>
                <?php endif; ?>

                <div class="list-project-in-category">
                    <div class="list-project">
                    
	            	<?php
	            	foreach ($deals as $deal) : ?>

            		<div class="grid_3">
	                    <div class="project-short sml-thumb" style="min-height:460px;">
	                        <div class="top-project-info">
	                            <div class="content-info-short clearfix">
									<div style="max-height:148px; overflow:hidden;"><!-- was max 230px -->
	                                	<a href="/project/<?= $deal['id'] ?>" class="thumb-img">
	                                    <img src="/<?= $deal['main_img'] ?>" alt="<?= $deal['title'] ?>" />
	                                	</a>
									</div>
	                                <div class="wrap-short-detail">
	                                    <h3 class="rs acticle-title"><a class="be-fc-orange" href="/project/<?= $deal['id'] ?>"><?= $deal['title'] ?></a></h3>
	                                    <p class="rs tiny-desc">by <a href="/profile/<?= $deal['user']['user_slug'] ?>" class="fw-b fc-gray be-fc-orange"><?= $deal['user']['name'] ?></a></p>
	                                    <p class="rs title-description"><?= substr(strip_tags($deal['description']),0, 100) ?>...<a href="/project/<?= $deal['id'] ?>" class="be-fc-orange" 
										style="font-weight:300; color:#24577C;">read more &raquo;</a></p>
	                                    <p class="rs project-location">
	                                        <i class="icon iLocation"></i>
	                                        <?= $deal['location'] ?>
	                                    </p>
										<!--<?= $deal['project_type_id'] ?>-->
	                                </div>
	                            </div>
	                        </div>

	                        <div class="bottom-project-info clearfix">
                                <div class="project-progress sys_circle_progress" data-percent="0">
                                    <div class="sys_holder_sector"></div>
                                </div>
                                <div class="group-fee clearfix">

                                    <div class="fee-item">
                                        <p class="rs lbl">Views</p>
                                        <span class="val"><?= $project['views'] ?></span>
                                    </div>
                                    <div class="sep"></div>
                                    <div class="fee-item">
                                        <p class="rs lbl">Comments</p>
                                        <span class="val"><?= $project['reviews_submitted'] ?></span>
                                    </div>
                                    <div class="sep"></div>
                                    <div class="fee-item">
                                        <p class="rs lbl">Redeem Type</p>
                                        <span class="val"><?= $project['redeem_type'] ?></span>
                                    </div>
                                    <div class="sep"></div>
                                    <div class="fee-item">
                                        <p class="rs lbl">Redeem Count</p>
                                        <span class="val" style="color:#4ba220;"><?= count($project['redeems']) ?></span>
                                    </div>
                                </div>
                                <div class="clear"></div>
                            </div>
	                    </div>
	                </div>

                	<?php
                	endforeach; ?>

                    </div>
                </div><!--end: .list-project-in-category ($deals) -->
				
				<div class="clear"></div>				
				
                <?php if (!empty($groups)) : ?><br /><br />
                <h3 class="common-title"><span class="fc-orange">Groups</span></h3>
                <?php endif; ?>

                <div class="list-project-in-category">
                    <div class="list-project">
                    <?php
                    foreach ($groups as $group) :
                        if (!$group['main_img'] && isset($group['images'][0])) {
                            $group['main_img'] = $group['images'][0]['file'];
                        }
                    ?>

                    <div class="grid_3">
                        <div class="project-short sml-thumb" style="min-height:340px;">
                            <div class="top-project-info">
                                <div class="content-info-short clearfix" style="min-height:300px;">
                                    <a href="/group/<?= $group['id'] ?>" class="thumb-img">
                                        <img src="/<?= $group['main_img'] ?>" alt="<?= $group['title'] ?>" style="max-height:200px;">
                                    </a>
                                    <div class="wrap-short-detail">
                                        <h3 class="rs acticle-title"><a class="be-fc-orange" href="/group/<?= $group['id'] ?>"><?= $group['title'] ?></a></h3>
                                        <p class="rs tiny-desc">by <a href="/group/<?= $group['user']['user_slug'] ?>" class="fw-b fc-gray be-fc-orange"><?= $group['user']['name'] ?></a></p>
                                        <p class="rs title-description"><?= substr(strip_tags($group['description']),0, 100) ?>...
                                        <a href="/group/<?= $group['id'] ?>" class="be-fc-orange" style="font-weight:bold;">read more &raquo;</a></p>
                                    </div>
                                </div>
                            </div>

                            <div class="bottom-project-info clearfix">
                                <div class="group-fee clearfix">
                                    <div class="fee-item">
                                        <p class="rs lbl">Members</p>
                                        <center><span class="val"><?= count($group['users']) ?></span></center>
                                    </div>
                                    <div class="sep"></div>
                                    <div class="fee-item">
                                        <p class="rs lbl">Comments</p>
                                        <center><span class="val"><?= count($group['comments']) ?></span></center>
                                    </div>
                                    <div class="sep"></div>
                                    <div class="fee-item">
                                        <p class="rs lbl">Created</p>
                                        <center style="font-size:8px;"><span class="val"><?= $group['date_created'] ?></span></center>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <?php
                    endforeach;
                    ?>
                    </div>
                </div><!--end: .list-project-in-category ($groups) -->
				
				<div class="clear"></div>
				
                <?php if (!empty($objects)) : ?><br /><br />
                <h3 class="common-title"><span class="fc-orange">Content</span></h3>
                <?php endif; ?>

                <div class="list-project-in-category">
                    <div class="list-project">

                    <?php
                    foreach ($objects as $object) :
                        if (!$object['main_img'] && isset($object['images'][0])) {
                            $object['main_img'] = $object['images'][0]['file'];
                        }
                    ?>

                    <div class="grid_3">
                        <div class="project-short sml-thumb">
                            <div class="top-project-info">
                                <div class="content-info-short clearfix" style="min-height:300px;">
                                    <a href="/content/<?= $object['id'] ?>" class="thumb-img">
                                        <img src="/<?= $object['main_img'] ?>" alt="<?= $object['title'] ?>" style="max-height:200px;">
                                    </a>
                                    <div class="wrap-short-detail">
                                        <?php 
                                            $is_fav   = in_array($object['id'], array_keys($current_user_favorites));
                                            $star_img = ($is_fav ? "star-on" : "star-off") . ".png"; 
                                            $star_txt = $is_fav ? "Click to Remove Favorite" : "Click to Add Favorite";
                                            $uid      = !empty($_SESSION['user_id']) ? $_SESSION['user_id'] : 0;
                                            $oid      = $object['id'];
                                        ?>
                                        <h3 class="rs acticle-title object-item" data-uid="<?= $uid ?>" data-oid="<?= $oid ?>">
                                            <?php if (isset($_SESSION['loggedin']) && !empty($uid)) : ?>
                                            <a href="#" class="toggle-favorite"><img src="/static/images/<?= $star_img ?>" alt="<?= $star_txt ?>" /></a>
                                            <?php endif; ?>
                                            <a class="be-fc-orange" href="/content/<?= $object['id'] ?>"><?= $object['title'] ?></a>
                                        </h3>
                                        <p class="rs tiny-desc">by <a href="/content/<?= $object['user']['user_slug'] ?>" class="fw-b fc-gray be-fc-orange"><?= $object['user']['name'] ?></a></p>
                                        <p class="rs title-description"><?= substr(strip_tags($object['description']),0, 100) ?>...
                                        <a href="/content/<?= $object['id'] ?>" class="be-fc-orange" style="font-weight:bold;">read more &raquo;</a></p>
                                    </div>
                                </div>
                            </div>

                            <div class="bottom-project-info clearfix">
                                <div class="group-fee clearfix">
                                    <div class="fee-item">
                                        <p class="rs lbl">Members</p>
                                        <center><span class="val"><?= count($object['users']) ?></span></center>
                                    </div>
                                    <div class="sep"></div>
                                    <div class="fee-item">
                                        <p class="rs lbl">Comments</p>
                                        <center><span class="val"><?= count($object['comments']) ?></span></center>
                                    </div>
                                    <div class="sep"></div>
                                    <div class="fee-item">
                                        <p class="rs lbl">Created</p>
                                        <center style="font-size:8px;"><span class="val"><?= $object['date_start'] ?></span></center>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <?php
                    endforeach;
                    ?>
                    </div>
                </div><!--end: .list-project-in-category ($objects) -->
				
				<div class="clear"></div>
				
                <?php if (!empty($users)) : ?><br /><br />
                <h3 class="common-title"><span class="fc-orange">Users</span></h3>
                <?php endif; ?>

                <div class="list-project-in-category">
                    <div class="list-project">
                    
                    <?php
                    foreach ($users as $index => $row) :

                        $user_image = $row['image'];
                        if (empty($user_image))
                            $user_image = "/static/images/users/default-avatar.jpg";

                        if (false === strpos($user_image, "/static/images/users/")
                            && false === strpos($user_image, "graph.facebook.com"))
                            $user_image = "/static/images/users/" . $user_image;
                    ?>
                    <div class="grid_3">
                        <div class="project-short sml-thumb">
                            <div class="top-project-info">
                                <div class="content-info-short clearfix" style="min-height:300px;">
                                    <a href="/profile/<?= $row['user_slug'] ?>" class="thumb-img">
                                        <img src="<?= $user_image ?>" alt="<?= $row['name'] ?>" 
										onerror="this.src='/static/images/users/default-avatar.jpg'"
                                        style="max-height:200px;" />
                                    </a>
                                    <div class="wrap-short-detail">
                                        <h3 class="rs acticle-title object-item">
                                            <a class="be-fc-orange" href="/profile/<?= $row['user_slug'] ?>"><?= $row['name'] ?></a>
                                        </h3>
                                        <p><a href="/profile/<?= $row['user_slug'] ?>" class="be-fc-orange" style="font-weight:300;">View Profile &raquo;</a></p>
                                    </div>
                                </div>
                            </div>
                            <div class="bottom-project-info clearfix">
                                <div class="group-fee clearfix">
                                    <div class="fee-item">
                                        <p class="rs lbl">Deals</p>
                                        <center><span class="val"><?= count($row['projects']) ?></span></center>
                                    </div>
                                    <div class="sep"></div>
                                    <div class="fee-item">
                                        <p class="rs lbl">Comments</p>
                                        <center><span class="val"><?= count($row['reviews']) ?></span></center>
                                    </div>
                                    <div class="sep"></div>
                                    <div class="fee-item">
                                        <p class="rs lbl">Groups</p>
                                        <center style="font-size:8px;"><span class="val"><?= count($row['groups']) ?></span></center>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <?php 
                    endforeach; ?>

                    </div>
                </div><!--end: .list-project-in-category ($users) -->

<!-- XXXXXXXXXXXXXXXXXX -->
<!-- XXX add categories -->
<!-- XXX add store_cats -->
<!-- XXX add items      -->
<!-- XXX add pages      -->
<!-- XXXXXXXXXXXXXXXXXX -->

                <div style="clear:both"></div>
                <!-- 
                <p class="rs ta-c">
                    <a id="showmoreproject" class="btn btn-black btn-load-more" href="#">Show more projects</a>
                </p>
                 -->
            </div><!--end: .search-result-page -->
        </div><!--end: .content -->
        
<?php include 'views/_footer.tpl.php'; ?>
