109 lines
4.6 KiB
PHP
109 lines
4.6 KiB
PHP
<?php
|
|
# ***** BEGIN LICENSE BLOCK *****
|
|
# This file is part of DotClear.
|
|
# Copyright (c) 2004 Olivier Meunier and contributors. All rights
|
|
# reserved.
|
|
#
|
|
# DotClear 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 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# DotClear 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 DotClear; if not, write to the Free Software
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
#
|
|
# ***** END LICENSE BLOCK *****
|
|
|
|
buffer::str('<h2>'.__('Ticket Rating').'</h2>');
|
|
|
|
// Définition du menu
|
|
$mySubMenu->addItem(__('Home'), 'tools.php?p=ticketrating', 'images/ico_goto.png', FALSE);
|
|
$mySubMenu->addItem(__('Most rated'), 'tools.php?p=ticketrating&a=most_rated', 'images/ico_goto.png', FALSE);
|
|
$mySubMenu->addItem(__('Best rated'), 'tools.php?p=ticketrating&a=best_rated', 'images/ico_goto.png', FALSE);
|
|
|
|
/* INSTALLATION */
|
|
// Vérification de la présence de la table
|
|
if(!$rs = $con->select('SHOW TABLES FROM `'.DB_DBASE.'` LIKE \''.DB_PREFIX.'rate\''))
|
|
{
|
|
buffer::str('<h4>' . $con->error() . '</h4>');
|
|
}elseif ($rs->isEmpty()){
|
|
// La table n'existe pas, on la créé
|
|
$sql = 'CREATE TABLE IF NOT EXISTS `'.DB_PREFIX.'rate` ('.
|
|
'`rate_post_id` int(11) NOT NULL,'.
|
|
'`rate_ip` varchar(15) NOT NULL,'.
|
|
'`rate_value` tinyint(1) NOT NULL'.
|
|
')';
|
|
if($con->execute($sql))
|
|
buffer::str('<h4>' . __('<em>Ticket Rating</em> has been successfully installed!') . '</h4>');
|
|
else
|
|
buffer::str('<h4>' . $con->error() . '</h4>');
|
|
}
|
|
|
|
|
|
/* Vérifictation des mises à jour */
|
|
require_once dirname(__FILE__).'/functions.php';
|
|
$plugins_root = dirname(__FILE__).'/../';
|
|
$plugins = new plugins($plugins_root);
|
|
$plugins->getPlugins(false);
|
|
$plugins_list = $plugins->getPluginsList();
|
|
$p_info = $plugins_list['ticketrating'];
|
|
unset($plugins_list, $plugins, $plugins_root);
|
|
if($check = @file_get_contents("http://x1fr.free.fr/share/ticketrating/version"))
|
|
{
|
|
if(postRating::checkNewVersion($p_info['version'],$check))
|
|
{
|
|
buffer::str('<h3>' . __('A newer version of this plugin is available!') . '(v'.$check.')</h3>');
|
|
}
|
|
}
|
|
|
|
|
|
if(isset($_GET['a']))
|
|
{
|
|
if(($_GET['a']==='most_rated') || ($_GET['a']==='best_rated'))
|
|
{
|
|
$op = ($_GET['a']==='most_rated') ? 'count(rate_value)' : 'round(avg(rate_value),2)';
|
|
$rs = $con->select('SELECT '.$op.' as value, post_titre FROM '.DB_PREFIX.'rate,'.DB_PREFIX.'post WHERE post_id = rate_post_id GROUP BY rate_post_id ORDER BY value DESC LIMIT 0,5');
|
|
if($rs->isEmpty())
|
|
{
|
|
buffer::str(__('No ticket has been rated for now'));
|
|
}else{
|
|
buffer::str('<table class="clean-table"><caption><h4>');
|
|
($_GET['a']==='most_rated') ? buffer::str(__('Most rated')) : buffer::str(__('Best rated'));
|
|
buffer::str('</h4></caption>');
|
|
buffer::str('<tr><td><strong>'.__('Rank').'</strong></td><td><strong>'.__('Ticket').'</strong></td><td><strong>'.__('Count').'</strong></td></tr>');
|
|
$i = 1;
|
|
while ($rs->fetch())
|
|
{
|
|
$style = ($i%2 == 0) ? ' style="background:#eee;"' : '';
|
|
buffer::str('<tr '.$style.'><td>'.$i++.'</td><td>'.$rs->f('post_titre').'</td><td>'.$rs->f('value').'</td></tr>');
|
|
}
|
|
buffer::str('</table>');
|
|
}
|
|
}
|
|
}else{
|
|
$rs = $con->select('SELECT count(rate_value) as cpt FROM '.DB_PREFIX.'rate LIMIT 0,1');
|
|
if($rs->f('cpt')!=0)
|
|
{
|
|
buffer::str('<h4>' . __('Informations') . '</h4>');
|
|
buffer::str('<table class="clean-table"><tr><td>'.__('Total submit').'</td><td>'.$rs->f('cpt').'</td></tr>');
|
|
$rs = $con->select('SELECT round(avg(rate_value),2) as avg FROM '.DB_PREFIX.'rate LIMIT 0,1');
|
|
buffer::str('<tr style="background:#eee;"><td>'.__('Global average').'</td><td>'.$rs->f('avg').'</td></tr>');
|
|
buffer::str('</table>');
|
|
}else{
|
|
buffer::str(__('No ticket has been rated for now'));
|
|
}
|
|
buffer::str('<h4>' . __('Usage') . '</h4>');
|
|
buffer::str('<p>' . __('The following templates file can be edited to use the plugin: post.php and list.php') . '</p>' .
|
|
'<p>' . __('To show the rate of a ticket, paste this code in the template file:') . '</p>' .
|
|
'<pre>' . htmlspecialchars('<?php postRating::getRate(); ?>') . '</pre>'.
|
|
'<p>' . __('To show the form allowing to rate a ticket, use this:') . '</p>'.
|
|
'<pre>' . htmlspecialchars('<?php postRating::rateIt(); ?>') . '</pre>');
|
|
|
|
}
|
|
?>
|