index.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # This file is part of DotClear.
  4. # Copyright (c) 2004 Olivier Meunier and contributors. All rights
  5. # reserved.
  6. #
  7. # DotClear is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # DotClear is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with DotClear; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. # ***** END LICENSE BLOCK *****
  22. buffer::str('<h2>'.__('Ticket Rating').'</h2>');
  23. // Définition du menu
  24. $mySubMenu->addItem(__('Home'), 'tools.php?p=ticketrating', 'images/ico_goto.png', FALSE);
  25. $mySubMenu->addItem(__('Most rated'), 'tools.php?p=ticketrating&a=most_rated', 'images/ico_goto.png', FALSE);
  26. $mySubMenu->addItem(__('Best rated'), 'tools.php?p=ticketrating&a=best_rated', 'images/ico_goto.png', FALSE);
  27. /* INSTALLATION */
  28. // Vérification de la présence de la table
  29. if(!$rs = $con->select('SHOW TABLES FROM `'.DB_DBASE.'` LIKE \''.DB_PREFIX.'rate\''))
  30. {
  31. buffer::str('<h4>' . $con->error() . '</h4>');
  32. }elseif ($rs->isEmpty()){
  33. // La table n'existe pas, on la créé
  34. $sql = 'CREATE TABLE IF NOT EXISTS `'.DB_PREFIX.'rate` ('.
  35. '`rate_post_id` int(11) NOT NULL,'.
  36. '`rate_ip` varchar(15) NOT NULL,'.
  37. '`rate_value` tinyint(1) NOT NULL'.
  38. ')';
  39. if($con->execute($sql))
  40. buffer::str('<h4>' . __('<em>Ticket Rating</em> has been successfully installed!') . '</h4>');
  41. else
  42. buffer::str('<h4>' . $con->error() . '</h4>');
  43. }
  44. /* Vérifictation des mises à jour */
  45. require_once dirname(__FILE__).'/functions.php';
  46. $plugins_root = dirname(__FILE__).'/../';
  47. $plugins = new plugins($plugins_root);
  48. $plugins->getPlugins(false);
  49. $plugins_list = $plugins->getPluginsList();
  50. $p_info = $plugins_list['ticketrating'];
  51. unset($plugins_list, $plugins, $plugins_root);
  52. if($check = @file_get_contents("http://x1fr.free.fr/share/ticketrating/version"))
  53. {
  54. if(postRating::checkNewVersion($p_info['version'],$check))
  55. {
  56. buffer::str('<h3>' . __('A newer version of this plugin is available!') . '(v'.$check.')</h3>');
  57. }
  58. }
  59. if(isset($_GET['a']))
  60. {
  61. if(($_GET['a']==='most_rated') || ($_GET['a']==='best_rated'))
  62. {
  63. $op = ($_GET['a']==='most_rated') ? 'count(rate_value)' : 'round(avg(rate_value),2)';
  64. $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');
  65. if($rs->isEmpty())
  66. {
  67. buffer::str(__('No ticket has been rated for now'));
  68. }else{
  69. buffer::str('<table class="clean-table"><caption><h4>');
  70. ($_GET['a']==='most_rated') ? buffer::str(__('Most rated')) : buffer::str(__('Best rated'));
  71. buffer::str('</h4></caption>');
  72. buffer::str('<tr><td><strong>'.__('Rank').'</strong></td><td><strong>'.__('Ticket').'</strong></td><td><strong>'.__('Count').'</strong></td></tr>');
  73. $i = 1;
  74. while ($rs->fetch())
  75. {
  76. $style = ($i%2 == 0) ? ' style="background:#eee;"' : '';
  77. buffer::str('<tr '.$style.'><td>'.$i++.'</td><td>'.$rs->f('post_titre').'</td><td>'.$rs->f('value').'</td></tr>');
  78. }
  79. buffer::str('</table>');
  80. }
  81. }
  82. }else{
  83. $rs = $con->select('SELECT count(rate_value) as cpt FROM '.DB_PREFIX.'rate LIMIT 0,1');
  84. if($rs->f('cpt')!=0)
  85. {
  86. buffer::str('<h4>' . __('Informations') . '</h4>');
  87. buffer::str('<table class="clean-table"><tr><td>'.__('Total submit').'</td><td>'.$rs->f('cpt').'</td></tr>');
  88. $rs = $con->select('SELECT round(avg(rate_value),2) as avg FROM '.DB_PREFIX.'rate LIMIT 0,1');
  89. buffer::str('<tr style="background:#eee;"><td>'.__('Global average').'</td><td>'.$rs->f('avg').'</td></tr>');
  90. buffer::str('</table>');
  91. }else{
  92. buffer::str(__('No ticket has been rated for now'));
  93. }
  94. buffer::str('<h4>' . __('Usage') . '</h4>');
  95. buffer::str('<p>' . __('The following templates file can be edited to use the plugin: post.php and list.php') . '</p>' .
  96. '<p>' . __('To show the rate of a ticket, paste this code in the template file:') . '</p>' .
  97. '<pre>' . htmlspecialchars('<?php postRating::getRate(); ?>') . '</pre>'.
  98. '<p>' . __('To show the form allowing to rate a ticket, use this:') . '</p>'.
  99. '<pre>' . htmlspecialchars('<?php postRating::rateIt(); ?>') . '</pre>');
  100. }
  101. ?>