1 | <?php |
||
2 | /** |
||
3 | * TDMDownload |
||
4 | * |
||
5 | * You may not change or alter any portion of this comment or credits |
||
6 | * of supporting developers from this source code or any supporting source code |
||
7 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
11 | * |
||
12 | * @copyright Gregory Mage (Aka Mage) |
||
13 | * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
||
14 | * @author Gregory Mage (Aka Mage) |
||
15 | */ |
||
16 | |||
17 | include_once 'header.php'; |
||
18 | // template d'affichage |
||
19 | $xoopsOption['template_main'] = 'tdmdownloads_ratefile.tpl'; |
||
20 | include_once XOOPS_ROOT_PATH.'/header.php'; |
||
21 | $xoTheme->addStylesheet( XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/css/styles.css', null ); |
||
22 | //On recupere la valeur de l'argument op dans l'URL$ |
||
23 | $op = TDMDownloads_CleanVars($_REQUEST, 'op', 'liste', 'string'); |
||
24 | $lid = TDMDownloads_CleanVars($_REQUEST, 'lid', 0, 'int'); |
||
25 | |||
26 | //redirection si pas de permission de vote |
||
27 | if ($perm_vote == false) { |
||
28 | redirect_header('index.php', 2, _NOPERM); |
||
29 | exit(); |
||
30 | } |
||
31 | |||
32 | $view_downloads = $downloads_Handler->get($lid); |
||
33 | // redirection si le t�l�chargement n'existe pas ou n'est pas activ� |
||
34 | if (count($view_downloads) == 0 || $view_downloads->getVar('status') == 0) { |
||
35 | redirect_header('index.php', 3, _MD_TDMDOWNLOADS_SINGLEFILE_NONEXISTENT); |
||
36 | exit(); |
||
37 | } |
||
38 | |||
39 | //redirection si pas de permission (cat) |
||
40 | $categories = TDMDownloads_MygetItemIds('tdmdownloads_view', 'TDMDownloads'); |
||
41 | if (!in_array($view_downloads->getVar('cid'), $categories)) { |
||
42 | redirect_header(XOOPS_URL, 2, _NOPERM); |
||
43 | exit(); |
||
44 | } |
||
45 | |||
46 | //Les valeurs de op qui vont permettre d'aller dans les differentes parties de la page |
||
47 | switch ($op) { |
||
48 | // Vue liste |
||
49 | case "liste": |
||
50 | //tableau des cat�gories |
||
51 | $criteria = new CriteriaCompo(); |
||
52 | $criteria->setSort('cat_weight ASC, cat_title'); |
||
53 | $criteria->setOrder('ASC'); |
||
54 | $criteria->add(new Criteria('cat_cid', '(' . implode(',', $categories) . ')','IN')); |
||
55 | $downloadscat_arr = $downloadscat_Handler->getall($criteria); |
||
56 | $mytree = new XoopsObjectTree($downloadscat_arr, 'cat_cid', 'cat_pid'); |
||
57 | //navigation |
||
58 | $navigation = TDMDownloads_PathTreeUrl($mytree, $view_downloads->getVar('cid'), $downloadscat_arr, 'cat_title', $prefix = ' <img src="images/deco/arrow.gif" alt="arrow" /> ', true, 'ASC', true); |
||
59 | $navigation .= ' <img src="images/deco/arrow.gif" alt="arrow" /> <a title="' . $view_downloads->getVar('title') . '" href="singlefile.php?lid=' . $view_downloads->getVar('lid') . '">' . $view_downloads->getVar('title') . '</a>'; |
||
60 | $navigation .= ' <img src="images/deco/arrow.gif" alt="arrow" /> ' . _MD_TDMDOWNLOADS_SINGLEFILE_RATHFILE; |
||
61 | $xoopsTpl->assign('navigation', $navigation); |
||
62 | // r�f�rencement |
||
63 | // titre de la page |
||
64 | $pagetitle = _MD_TDMDOWNLOADS_SINGLEFILE_RATHFILE . ' - ' . $view_downloads->getVar('title') . ' - '; |
||
65 | $pagetitle .= TDMDownloads_PathTreeUrl($mytree, $view_downloads->getVar('cid'), $downloadscat_arr, 'cat_title', $prefix = ' - ', false, 'DESC', true); |
||
66 | $xoopsTpl->assign('xoops_pagetitle', $pagetitle); |
||
67 | //description |
||
68 | $xoTheme->addMeta( 'meta', 'description', strip_tags(_MD_TDMDOWNLOADS_SINGLEFILE_RATHFILE . ' (' . $view_downloads->getVar('title') . ')')); |
||
69 | //Affichage du formulaire de notation des t�l�chargements |
||
70 | $obj = $downloadsvotedata_Handler->create(); |
||
71 | $form = $obj->getForm($lid); |
||
72 | $xoopsTpl->assign('themeForm', $form->render()); |
||
73 | break; |
||
74 | |||
75 | // save |
||
76 | case "save": |
||
77 | $obj = $downloadsvotedata_Handler->create(); |
||
78 | if (empty($xoopsUser)) { |
||
79 | $ratinguser = 0; |
||
80 | } else { |
||
81 | $ratinguser = $xoopsUser->getVar('uid'); |
||
82 | } |
||
83 | // si c'est un membre on v�rifie qu'il ne vote pas pour son fichier |
||
84 | if ($ratinguser != 0) { |
||
85 | $criteria = new CriteriaCompo(); |
||
86 | $criteria->add(new Criteria('lid', $lid)); |
||
87 | $downloads_arr = $downloads_Handler->getall($criteria); |
||
88 | foreach (array_keys($downloads_arr) as $i) { |
||
89 | if ($downloads_arr[$i]->getVar('submitter') == $ratinguser) { |
||
90 | redirect_header('singlefile.php?lid=' . intval($_REQUEST['lid']), 2, _MD_TDMDOWNLOADS_RATEFILE_CANTVOTEOWN); |
||
91 | exit(); |
||
92 | } |
||
93 | } |
||
94 | // si c'est un membre on v�rifie qu'il ne vote pas 2 fois |
||
95 | $criteria = new CriteriaCompo(); |
||
96 | $criteria->add(new Criteria('lid', $lid)); |
||
97 | $downloadsvotes_arr = $downloadsvotedata_Handler->getall($criteria); |
||
98 | foreach (array_keys($downloadsvotes_arr) as $i) { |
||
99 | if ($downloadsvotes_arr[$i]->getVar('ratinguser') == $ratinguser) { |
||
100 | redirect_header('singlefile.php?lid=' . intval($_REQUEST['lid']), 2, _MD_TDMDOWNLOADS_RATEFILE_VOTEONCE); |
||
101 | exit(); |
||
102 | } |
||
103 | } |
||
104 | } else { |
||
105 | // si c'est un utilisateur anonyme on v�rifie qu'il ne vote pas 2 fois par jour |
||
106 | $yesterday = (time()-86400); |
||
107 | $criteria = new CriteriaCompo(); |
||
108 | $criteria->add(new Criteria('lid', $lid)); |
||
109 | $criteria->add(new Criteria('ratinguser', 0)); |
||
110 | $criteria->add(new Criteria('ratinghostname', getenv("REMOTE_ADDR"))); |
||
111 | $criteria->add(new Criteria('ratingtimestamp', $yesterday, '>')); |
||
112 | if ($downloadsvotedata_Handler->getCount($criteria) >= 1) { |
||
113 | redirect_header('singlefile.php?lid=' . intval($_REQUEST['lid']), 2, _MD_TDMDOWNLOADS_RATEFILE_VOTEONCE); |
||
114 | exit(); |
||
115 | } |
||
116 | } |
||
117 | $erreur = false; |
||
118 | $message_erreur = ''; |
||
119 | // Test avant la validation |
||
120 | $rating = intval($_POST['rating']); |
||
121 | if ($rating < 0 || $rating > 10) { |
||
122 | $message_erreur.= _MD_TDMDOWNLOADS_RATEFILE_NORATING . '<br>'; |
||
123 | $erreur=true; |
||
124 | } |
||
125 | xoops_load("captcha"); |
||
126 | $xoopsCaptcha = XoopsCaptcha::getInstance(); |
||
127 | if ( !$xoopsCaptcha->verify() ) { |
||
128 | $message_erreur.=$xoopsCaptcha->getMessage() . '<br>'; |
||
129 | $erreur=true; |
||
130 | } |
||
131 | $obj->setVar('lid', $lid); |
||
132 | $obj->setVar('ratinguser', $ratinguser); |
||
133 | $obj->setVar('rating', $rating); |
||
134 | $obj->setVar('ratinghostname', getenv("REMOTE_ADDR")); |
||
135 | $obj->setVar('ratingtimestamp', time()); |
||
136 | if ($erreur==true) { |
||
0 ignored issues
–
show
|
|||
137 | $xoopsTpl->assign('message_erreur', $message_erreur); |
||
138 | } else { |
||
139 | if ($downloadsvotedata_Handler->insert($obj)) { |
||
140 | $criteria = new CriteriaCompo(); |
||
141 | $criteria->add(new Criteria('lid', $lid)); |
||
142 | $downloadsvotes_arr = $downloadsvotedata_Handler->getall($criteria); |
||
143 | $total_vote = $downloadsvotedata_Handler->getCount($criteria); |
||
144 | $total_rating = 0; |
||
145 | foreach (array_keys($downloadsvotes_arr) as $i) { |
||
146 | $total_rating += $downloadsvotes_arr[$i]->getVar('rating'); |
||
147 | } |
||
148 | $rating = $total_rating / $total_vote; |
||
149 | $objdownloads = $downloads_Handler->get($lid); |
||
150 | $objdownloads->setVar('rating', number_format($rating, 1)); |
||
151 | $objdownloads->setVar('votes', $total_vote); |
||
152 | if ($downloads_Handler->insert($objdownloads)) { |
||
153 | redirect_header('singlefile.php?lid=' . $lid, 2, _MD_TDMDOWNLOADS_RATEFILE_VOTEOK); |
||
154 | } |
||
155 | echo $objdownloads->getHtmlErrors(); |
||
156 | } |
||
157 | echo $obj->getHtmlErrors(); |
||
158 | } |
||
159 | //Affichage du formulaire de notation des t�l�chargements |
||
160 | $form = $obj->getForm($lid); |
||
161 | $xoopsTpl->assign('themeForm', $form->render()); |
||
162 | |||
163 | break; |
||
164 | } |
||
165 | include XOOPS_ROOT_PATH.'/footer.php'; |
||
166 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.