<?php
get_header();
?>
<div id="primary" class="site-content cma-content">
    <div class="cma-main">
        <div class="cma-wrapper">
            <div id="content" role="main" class="entry-content">
                <header class="entry-header">
                    <h1 class="entry-title">
                        <?php _e('כל השאלות', 'cm-answers'); ?>
                    </h1>
                </header>
                <div style="clear:both;height:15px;"></div>

                <?php
                $currentSort = !empty($_GET['sort']) ? $_GET['sort'] : 'newest';
                ?>
                <ul class="cma-thread-orderby">
                    <li<?php if( $currentSort == 'newest' ): ?> class="cma-current-sort"<?php endif; ?>><a href="<?php echo add_query_arg(array('sort' => 'newest'), get_pagenum_link(0)); ?>"><?php _e('אחרונים', 'cm-answers'); ?></a></li>
                    <li<?php if( $currentSort == 'hottest' ): ?> class="cma-current-sort"<?php endif; ?>><a href="<?php echo add_query_arg(array('sort' => 'hottest'), get_pagenum_link(0)); ?>"><?php _e('נושא חם', 'cm-answers'); ?></a></li>
                    <?php if( CMA_AnswerThread::isRatingAllowed() ): ?><li<?php if( $currentSort == 'votes' ): ?> class="cma-current-sort"<?php endif; ?>><a href="<?php echo add_query_arg(array('sort' => 'votes'), get_pagenum_link(0)); ?>"><?php _e('הכי מדורגים', 'cm-answers'); ?></a></li><?php endif; ?>
                    <li<?php if( $currentSort == 'views' ): ?> class="cma-current-sort"<?php endif; ?>><a href="<?php echo add_query_arg(array('sort' => 'views'), get_pagenum_link(0)); ?>"><?php _e('הכי נצפים', 'cm-answers'); ?></a></li>
                </ul>
                <div class="cma-clear"></div>
                <?php
                do_action('CMA_show_messages');
                if( have_posts() ):
                    ?>
                    <table class="cma-thread-list">
                        <?php
                        while(have_posts()):
                            the_post();
                            $thread = CMA_AnswerThread::getInstance($post->ID);
                            ?>
                            <tr>
							
							                                <td class="cma-thread-summary">
                                    <div class="cma-thread-title"><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $thread->getTitle(); ?></a></div>
                                    <div class="cma-thread-updated"><?php printf(__('עודכן לפני %s ע"י %s', 'cm-answers'), CMA_AnswerThread::renderDaysAgo($thread->getUnixUpdated()), $thread->getLastPosterName()); ?></div></td>
									
							
                                    <?php $numberOfAnswers = $thread->getNumberOfAnswers(); ?>
                                <td class="cma-thread-meta"><div class="cma-thread-numbers cma-thread-answers<?php if( $numberOfAnswers == 0 ): ?> cma-thread-no-answers<?php endif; ?>"><div class="cma-thread-numbers-count cma-thread-answers-count"><?php echo $numberOfAnswers; ?></div><div class="cma-thread-numbers-caption cma-thread-answers-caption"><?php
                                            if( $numberOfAnswers == 1 ) _e('answer', 'cm-answers');
                                            else _e('תשובות', 'cm-answers');
                                            ?></div></div>
                                </td>
                                		<?php if( CMA_AnswerThread::isRatingAllowed() ): ?><td class="cma-thread-meta">
                                        <div class="cma-thread-numbers cma-thread-votes"><div class="cma-thread-numbers-count cma-thread-votes-count"><?php
                                                $votes = $thread->getVotes();
                                                echo $votes;
                                                ?></div><div class="cma-thread-numbers-caption cma-thread-votes-caption"><?php
                                                if( $votes == 1 ) _e('vote', 'cm-answers');
                                                else _e('votes', 'cm-answers');
                                                ?></div></div></td><?php endif; ?>
                                <td class="cma-thread-meta"><div class="cma-thread-numbers cma-thread-views"><div class="cma-thread-numbers-count cma-thread-views-count"><?php
                                            $views = $thread->getViews();
                                            echo $views;
                                            ?></div><div class="cma-thread-numbers-caption cma-thread-views-caption"><?php
                                            if( $views == 1 ) _e('view', 'cm-answers');
                                            else _e('צפיות', 'cm-answers');
                                            ?></div></div></td>

                                    </tr>
                            <?php
                        endwhile;
                        ?>
                    </table>
                    <div class="cma-pagination"><?php
                        echo paginate_links(array(
                            'base'     => trailingslashit(get_post_type_archive_link(CMA_AnswerThread::POST_TYPE)) . '%_%',
                            'format'   => 'page/%#%/',
                            'current'  => max(1, get_query_var('paged')),
                            'total'    => $GLOBALS['wp_query']->max_num_pages,
                            'add_args' => $currentSort != 'newest' ? array('sort' => $currentSort) : array()
                        ));
                        ?></div><?php
                endif;
                ?>
                <div class="cma-form-container">
                
                    <?php //if( is_user_logged_in() ): ?>
                        <div style="clear:both;height:40px;"></div>
                        <form method="post" class="cma-thread-add" id="cma-thread-add">
                            <input type="hidden" name="cma-action" value="add" />
                            <h3><?php _e('שאלה חדשה:', 'cm-answers'); ?></h3>
                            <div style="clear:both;height:10px;"></div>
                           <!-- <ul class="cma-form-notes">
                                <li><?php _e('ניתן לההשתמש ב', 'cm-answers'); ?>: &lt;strong&gt;, &lt;em&gt;, &lt;a&gt;</li>
                                <li><?php _e('Wrap your code using', 'cm-answers'); ?> &lt;pre&gt;&lt;/pre&gt;</li>
                            </ul>
                            -->
                            
                                שייכו את השאלה ליעד המתאים:
	                                <div style="display:block; margin-bottom:7px; position:relative">
    	                         <input type="text" onkeyup="bashSearch_global(this.id,'destToQ');" placeholder="הקלידו את שם היעד ובחרו מהרשימה שתופיעה" value="" id="cSearch_destToQ" name="cSearch_destToQ" class="fSearch" autocomplete="off" style="margin-bottom:0;"><br>
                                 <input type="hidden" value="" id="hidden_destToQ" name="hidden_destToQ">
<div id="showMyLike_destToQ" style="position:absolute"></div>                                  
        	                        </div>
                                
                                
                                
                            <input type="text" size="50" name="thread_title" placeholder="<?php _e('כותרת', 'cm-answers'); ?>" /><br />
                            <textarea name="thread_comment" cols="50" rows="3" placeholder="<?php _e('תוכן השאלה', 'cm-answers'); ?>"></textarea><br />
                            <div style="clear:both;height:5px;"></div>
                            <label>
                                <input name="thread_notify" type="checkbox" value="1"/>
                                <?php _e('עדכן אותי שיש שינויים', 'cm-answers'); ?></label><br />
                            <div style="clear:both;height:10px;"></div>
                            <input type="submit" value="<?php _e('הוסף שאלה', 'cm-answers'); ?>" />
                        </form>
                        <?php
                   // else:
                     //   do_action('CMA_login_form');
                   // endif;
                    ?>
                </div>
            </div>
            <span class="cma_poweredby"><a href="http://plugins.cminds.com/" target="_blank" class="cma_poweredbylink">CreativeMinds WordPress Plugins</a> <a href="http://answers.cminds.com/" target="_blank" class="cma_poweredbylink">CM Answers</a></span>

        </div>
        <?php if( CMA_AnswerThread::isSidebarEnabled() && is_active_sidebar('cm-answers-sidebar') ): ?>
            <?php
            $maxWidth = CMA_AnswerThread::getSidebarMaxWidth() > 0 ? 'style="max-width:' . $maxWidth . 'px"' : '';
            ?>
            <div id="secondary" role="complementary" class="widget-area cma-sidebar" <?php echo $maxWidth; ?>>
                <?php dynamic_sidebar('cm-answers-sidebar'); ?>
            </div>
        <?php endif; ?>
    </div>
</div>
<?php
get_footer();
