<?php
// Version: 1.1 RC2; Viewkarma


function template_main()
{
        global $context, $txt, $member, $user_info, $scripturl, $settings, $modSettings, $ID_MEMBER;


        echo '
                <div style="padding: 3px;">', theme_linktree(), '</div>
                    <form action="', $scripturl, '?action=viewkarma;start='.$context['start'].';sort='.$context['sort_by'].'', $context['sort_direction'] == 'down' ? ';desc' : '', '', '" method="post" onsubmit="if (lastClicked == \'remove_selection\' && !confirm(\'', $txt['sure_about_karma_remove'], '\')) return false; else return true;">
                <table border="0" width="100%" cellspacing="1" cellpadding="2" class="tborder" style="margin-bottom: 1ex;">
                        <tr class="titlebg" valign="middle" align="center">
                                <td align="center" colspan="', $modSettings['karmaurl'] ? '6' : '5' ,'"><b>', $txt['karmaview'], '</b> </td>
                                '; if ($user_info['is_admin']) echo ' <td align="center"></td>'; echo '
                        </tr>
                        <tr class="windowbg">';
                        $WhatPageIsIt = $_SERVER["QUERY_STRING"];
                        if (isset($_REQUEST['u'])) $UserViewing = $_REQUEST['u'];
                        if(strstr($WhatPageIsIt, "viewkarma")){ $WhatPage='viewkarma';}
                        elseif(strstr($WhatPageIsIt, "otherkarma")){ $WhatPage='otherkarma;u='.$UserViewing;}
                        else{$WhatPage='ownkarma;u='.$UserViewing.'';}
                        echo'
                                        <td width="14%" align="center"><b><a href="' . $scripturl . '?action='.$WhatPage.';start=', $context['start'], ';sort=exec', $context['sort_direction'] == 'down' && $context['sort_by'] == 'exec' ? ';asc' : '', '">', $txt['karmawho'], '', $context['sort_by'] == 'exec' ? '<img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" border="0" />' : '', '</a></b></td>
                                        <td width="14%" align="center"><b><a href="' . $scripturl . '?action='.$WhatPage.';start=', $context['start'], ';sort=targ', $context['sort_direction'] == 'down' && $context['sort_by'] == 'targ' ? ';asc' : '', '">', $txt['karmawhos'],'', $context['sort_by'] == 'targ' ? '<img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" border="0" />' : '', '</a></b></td>
                                        <td width="10%" align="center"><b><a href="' . $scripturl . '?action='.$WhatPage.';start=', $context['start'], ';sort=action', $context['sort_direction'] == 'down' && $context['sort_by'] == 'action' ? ';asc' : '', '">', $txt['karmawhat'],'', $context['sort_by'] == 'action' ? '<img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" border="0" />' : '', '</a></b></td>
                                        <td width="31%" align="center"><b>', $txt['karmadesc'],'</b></td>
                                        '; if (!empty($modSettings['karmaurl'])) echo '<td width="6%" align="center"><b>', $txt['karmawhere'],'</b></td>'; echo '
                                        <td width="25%" align="center"><b><a href="' . $scripturl . '?action='.$WhatPage.';start=', $context['start'], ';sort=time', $context['sort_direction'] == 'down' && $context['sort_by'] == 'time' ? ';asc' : '', '">', $txt['karmatime'],'', $context['sort_by'] == 'time' ? '<img src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.gif" alt="" border="0" />' : '', '</a></b></td>
                                            '; if ($user_info['is_admin']) echo ' <td align="center"><b>Delete</b></td>'; echo '
                        </tr>';

        //Выводим полученные данные в табличной форме.
        foreach ($context['karma_changes'] as $member)

if (!empty($modSettings['karmalogview']) && ($user_info['is_admin']) || (empty($modSettings['karmalogview'])) && ($user_info['is_admin']))
{
        echo '
                                <script language="JavaScript1.2" type="text/javascript"><!--
                                var lastClicked = "";
                                // --></script>
                        <tr class="windowbg">
                                <td width="14%" align="center"><a href="'. $scripturl . '?action=profile;u=' . $member['id_exec'] . '" title="' . $txt[92] . ' ' . $member['executor'] . '">' . $member['executor'] . '</a>';
                                if (!empty($modSettings['karmakarma']))
                                                echo' <span class="smalltext">(+',$member['executorkarmagood'],'/-',$member['executorkarmabad'],')</span>';
        echo '</td>
                                <td width="14%" align="center"><a href="'. $scripturl . '?action=profile;u=' . $member['id_targ'] . '" title="' . $txt[92] . ' ' . $member['target'] . '">' . $member['target'] . '</a>';
                                if (!empty($modSettings['karmakarma']))
                                                echo' <span class="smalltext">(+',$member['targetkarmagood'],'/-',$member['targetkarmabad'],')</span>';
        echo '</td>
                                <td width="10%" align="center">', $member['action'], '</td>
                                <td width="31%" align="center">', $member['Description'], '</td>';
                                if (!empty($modSettings['karmaurl']))
                                                echo '<td width="6%" align="center">',$member['link']!='PM' ? '<a href="'. $scripturl . '?topic='. $member['link'].'" target="_blank">'.$txt['karmawhereurl'].'</a>' : $txt['karmawhereurl2'],'</td>';
        echo '                  <td width="25%" align="center">', $member['time'], '</td>
                                        <td align="center"><input type="checkbox" name="delete[]" value="', $member['logtime'], '" class="check" /></td>
                        </tr>';
}
elseif (!empty($modSettings['karmalogview']))
{
        echo '
                        <tr class="windowbg">
                                <td width="14%" align="center"><a href="'. $scripturl . '?action=profile;u=' . $member['id_exec'] . '" title="' . $txt[92] . ' ' . $member['executor'] . '">' . $member['executor'] . '</a>';
                                if (!empty($modSettings['karmakarma']))
                                                echo' <span class="smalltext">(+',$member['executorkarmagood'],'/-',$member['executorkarmabad'],')</span>';
        echo '</td>
                                <td width="14%" align="center"><a href="'. $scripturl . '?action=profile;u=' . $member['id_targ'] . '" title="' . $txt[92] . ' ' . $member['target'] . '">' . $member['target'] . '</a>';
                                if (!empty($modSettings['karmakarma']))
                                                echo' <span class="smalltext">(+',$member['targetkarmagood'],'/-',$member['targetkarmabad'],')</span>';
        echo '</td>
                                <td width="10%" align="center">', $member['action'], '</td>
                                <td width="31%" align="center">', $member['Description'], '</td>';
                                if (!empty($modSettings['karmaurl']))
                                                echo '<td width="6%" align="center"><a href="'. $scripturl . '?topic=', $member['link'],'" target="_blank">'.$txt['karmawhereurl'].'</a></td>';
        echo '                  <td width="25%" align="center">', $member['time'], '</td>
                        </tr>';
}
else
{
        echo '
                        <tr class="windowbg">
                                <td width="14%" align="center" >' , $member['executor'] , '';
                                if (!empty($modSettings['karmakarma']))
                                                echo' <span class="smalltext">(+',$member['executorkarmagood'],'/-',$member['executorkarmabad'],')</span>';
        echo '</td>
                                <td width="14%" align="center">' , $member['target'] , '';
                                if (!empty($modSettings['karmakarma']))
                                                echo' <span class="smalltext">(+',$member['targetkarmagood'],'/-',$member['targetkarmabad'],')</span>';
        echo '</td>
                                <td width="10%" align="center">', $member['action'], '</td>
                                <td width="31%" align="center">', $member['Description'], '</td>
                                <td width="6%" align="center"><a href="'. $scripturl . '?topic=', $member['link'],'" target="_blank">'.$txt['karmawhereurl'].'</a></td>
                                <td width="25%" align="center">', $member['time'], '</td>
                        </tr>';
}
        //Строка с общим числом результатов и ссылками на странички с результатами
        echo'
                        <tr class="titlebg" valign="middle" align="center">
                             <td align="center" colspan="', $modSettings['karmaurl'] ? '6' : '5' ,'">(',$txt['karmanumb'].$context['totalActions'],')</td>';
                        if ($user_info['is_admin']) echo ' <td align="center"><label for="check_all1"><input type="checkbox" id="check_all1" onclick="invertAll(this, this.form, \'delete[]\'); this.form.check_all2.checked = this.checked;" class="check" /> </label></td>'; echo '
                        </tr>
                        <tr class="titlebg">
                             <td colspan="', $modSettings['karmaurl'] ? '6' : '5' ,'"><b>', $txt[139], ':</b> ', $context['page_index'] , '</td>';
                        if ($user_info['is_admin']) echo ' <td align="center"><div style="float: right;"><input type="submit" name="delete_selection" value="', $txt['karma_delete'], '" onclick="lastClicked = \'remove_selection\';" /> </div></td></form>'; echo '
                        </tr>
                        </table>';

        //Прочая статистика
        if (!empty($modSettings['karmaotherstat']))
        {
        echo '<table border="0" width="100%" cellspacing="1" cellpadding="2" class="tborder">
                     <tr class="titlebg" valign="middle" align="center">
                         <td align="center" colspan="3"><b>', $txt['karma_stat'], '</b>
                         </td>
                     </tr>
                     <tr class="windowbg">
                         <td width="38%" align="center"><b>',$txt['karma_other_stat'],'</b></td>
                         <td width="31%" align="center"><b>',$txt['karma_top_applaud'],'</b></td>
                         <td width="31%" align="center"><b>',$txt['karma_top_smite'],'</b></td>
                     </tr>

                     <tr class="windowbg">
                         <td width="38%">
              <table border="0" cellpadding="1" cellspacing="0">
                     <tr><td width="28%">',$txt['karma_max_appl'],'</td>
                     <td width="10%" align="right">',$context['memidappl'],' + [',$context['memidapplcount'],']</td></tr>
                     <tr><td width="28%">',$txt['karma_max_smit'],'</td>
                     <td width="10%" align="right">',$context['memidsmit'],' - [',$context['memidsmitcount'],']</td></tr>
                     <tr><td width="28%">',$txt['karma_today'],'</td><td width="10%" align="right">',$context['today_point'] ,'</td></tr>
                     <tr><td width="28%">',$txt['karma_today_plus'],'</td><td width="10%" align="right">',$context['today_plus'] ,'</td></tr>
                     <tr><td width="28%">',$txt['karma_today_minus'],'</td><td width="10%" align="right">',$context['today_minus'] ,'</td></tr>
              </table></td>
                         <td width="31%">
              <table border="0" cellpadding="1" cellspacing="0">';
       foreach ($context['top_applaud'] as $applauder)
                echo '   <tr class="windowbg">
                             <td width="13%" valign="top">', $applauder['link'], '</td>
                             <td width="13%" align="left" valign="top">', $applauder['num_karma'] > 0 ? '<img src="' . $settings['images_url'] . '/bar.gif" width="' . $applauder['karma_percent'] . '" height="15" alt="" border="0" />' : '&nbsp;', '</td>
                             <td width="5%" align="center" valign="top">+ ', $applauder['num_karma'], '</td>
                         </tr>';
        echo '</table></td>
                      <td width="31%">
              <table border="0" cellpadding="1" cellspacing="0">';
       foreach ($context['top_smite'] as $smiter)
                echo '   <tr class="windowbg">
                             <td width="13%" valign="top">', $smiter['link'], '</td>
                             <td width="13%" align="left" valign="top">', $smiter['num_karma'] > 0 ? '<img src="' . $settings['images_url'] . '/bar.gif" width="' . $smiter['karma_percent'] . '" height="15" alt="" border="0" />' : '&nbsp;', '</td>
                             <td width="5%" align="center" valign="top">- ', $smiter['num_karma'], '</td>
                         </tr>';
        echo '</table></td></table>';
        }


}
?>
