1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: cInclude("includes", "functions.database.php");
19:
20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30:
31: function statsDisplayInfo($id, $type, $x, $y, $w, $h) {
32: if (strcmp($type, "article" == 0)) {
33: $text = i18n("Info about article") . " " . $id;
34: } else {
35: $text = i18n("Info about directory") . " " . $id;
36: }
37:
38: $div = new cHTMLDiv($text, "text_medium", "idElement14");
39: $div->appenStyleDefinition("border", "1px solid #e8e8ee");
40: $div->appendStyleDefinition("position", "absolute");
41: $div->appendStyleDefinition("top", $x . "px");
42: $div->appendStyleDefinition("left", $y . "px");
43: $div->appendStyleDefinition("width", $w . "px");
44: $div->appendStyleDefinition("height", $h . "px");
45:
46: return $div->toHTML();
47: }
48:
49: 50: 51: 52: 53: 54:
55: function statsArchive($yearmonth) {
56: global $cfg;
57:
58: $yearmonth = preg_replace('/\s/', '0', $yearmonth);
59:
60: $db = cRegistry::getDb();
61: $db2 = cRegistry::getDb();
62:
63: $sql = "SELECT idcatart, idlang, idclient, visited, visitdate FROM " . $cfg["tab"]["stat"];
64:
65: $db->query($sql);
66:
67: while ($db->nextRecord()) {
68: $insertSQL = "INSERT INTO
69: " . $cfg["tab"]["stat_archive"] . "
70: (archived, idcatart, idlang, idclient, visited, visitdate)
71: VALUES
72: (
73: " . $yearmonth . ",
74: " . cSecurity::toInteger($db->f(0)) . ",
75: " . cSecurity::toInteger($db->f(1)) . ",
76: " . cSecurity::toInteger($db->f(2)) . ",
77: " . cSecurity::toInteger($db->f(3)) . ",
78: '" . $db2->escape($db->f(4)) . "')";
79:
80: $db2->query($insertSQL);
81: }
82:
83: $sql = "DELETE FROM " . $cfg["tab"]["stat"];
84: $db->query($sql);
85:
86:
87: $sql = "SELECT
88: A.idcatart, B.idclient, C.idlang
89: FROM
90: " . $cfg["tab"]["cat_art"] . " AS A INNER JOIN
91: " . $cfg["tab"]["cat"] . " AS B ON A.idcat = B.idcat INNER JOIN
92: " . $cfg["tab"]["cat_lang"] . " AS C ON A.idcat = C.idcat ";
93:
94: $db->query($sql);
95:
96: while ($db->nextRecord()) {
97: $insertSQL = "INSERT INTO
98: " . $cfg["tab"]["stat"] . "
99: (idcatart, idlang, idclient, visited)
100: VALUES (
101: " . cSecurity::toInteger($db->f(0)) . ",
102: " . cSecurity::toInteger($db->f(2)) . ",
103: " . cSecurity::toInteger($db->f(1)) . ",
104: '0000-00-00 00:00:00')";
105:
106: $db2->query($insertSQL);
107: }
108: }
109:
110: 111: 112: 113: 114: 115: 116: 117:
118: function statsOverviewAll($yearmonth) {
119: global $cfg, $db, $tpl, $client, $lang, $cfgClient;
120:
121: $sDisplay = 'table-row';
122:
123: $bUseHeapTable = $cfg["statistics_heap_table"];
124:
125: $sHeapTable = $cfg['tab']['stat_heap_table'];
126:
127: if ($bUseHeapTable) {
128: if (!dbTableExists($db, $sHeapTable)) {
129: buildHeapTable($sHeapTable, $db);
130: }
131: }
132:
133: if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) {
134: $sDisplay = 'block';
135: }
136:
137: $sql = "SELECT
138: idtree, A.idcat, level, preid, C.name, visible
139: FROM
140: " . $cfg["tab"]["cat_tree"] . " AS A,
141: " . $cfg["tab"]["cat"] . " AS B,
142: " . $cfg["tab"]["cat_lang"] . " AS C
143: WHERE
144: A.idcat=B.idcat AND
145: B.idcat=C.idcat AND
146: C.idlang=" . cSecurity::toInteger($lang) . " AND
147: B.idclient=" . cSecurity::toInteger($client) . "
148: ORDER BY idtree";
149:
150: $db->query($sql);
151:
152: $currentRow = 2;
153:
154: $aRowname = array();
155: $iLevel = 0;
156: $backendUrl = cRegistry::getBackendUrl();
157: $tpl->set('s', 'IMG_EXPAND', $backendUrl . $cfg['path']['images'] . 'open_all.gif');
158: $tpl->set('s', 'IMG_COLLAPSE', $backendUrl . $cfg['path']['images'] . 'close_all.gif');
159:
160: $sumNumberOfArticles = 0;
161:
162: while ($db->nextRecord()) {
163: if ($db->f("level") == 0 && $db->f("preid") != 0) {
164: $tpl->set('d', 'PADDING_LEFT', '10');
165: $tpl->set('d', 'TEXT', ' ');
166: $tpl->set('d', 'NUMBEROFARTICLES', '');
167: $tpl->set('d', 'TOTAL', '');
168: $tpl->set('d', 'ICON', '');
169: $tpl->set('d', 'STATUS', '');
170: $tpl->set('d', 'ONCLICK', '');
171: $tpl->set('d', 'ROWNAME', '');
172: $tpl->set('d', 'INTHISLANGUAGE', '');
173: $tpl->set('d', 'EXPAND', '');
174: $tpl->set('d', 'DISPLAY_ROW', $sDisplay);
175: $tpl->set('d', 'PATH', '');
176: $tpl->set('d', 'ULR_TO_PAGE', '');
177:
178: $tpl->next();
179: $currentRow++;
180: }
181:
182: $padding_left = 10 + (15 * $db->f("level"));
183: $text = $db->f(4);
184: $idcat = $db->f("idcat");
185: $bCatVisible = $db->f("visible");
186:
187: if ($db->f("level") < $iLevel) {
188: $iDistance = $iLevel - $db->f("level");
189:
190: for ($i = 0; $i < $iDistance; $i++) {
191: array_pop($aRowname);
192: }
193: $iLevel = $db->f("level");
194: }
195:
196: if ($db->f("level") >= $iLevel) {
197: if ($db->f("level") == $iLevel) {
198: array_pop($aRowname);
199: } else {
200: $iLevel = $db->f("level");
201: }
202: array_push($aRowname, $idcat);
203: }
204:
205: $db2 = cRegistry::getDb();
206:
207: $sql = "SELECT COUNT(*) FROM " . $cfg["tab"]["cat_art"] . " WHERE idcat=" . cSecurity::toInteger($idcat);
208: $db2->query($sql);
209: $db2->nextRecord();
210:
211: $numberOfArticles = $db2->f(0);
212: $sumNumberOfArticles += $numberOfArticles;
213:
214: if (strcmp($yearmonth, "current") == 0) {
215: $sql = "SELECT SUM(visited) FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat"] . " AS B WHERE A.idcatart=B.idcatart AND A.idcat=" . cSecurity::toInteger($idcat) . " AND B.idclient=" . cSecurity::toInteger($client);
216: } else {
217: if (!$bUseHeapTable) {
218: $sql = "SELECT SUM(visited) FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat_archive"] . " AS B WHERE A.idcatart=B.idcatart AND A.idcat=" . cSecurity::toInteger($idcat) . "
219: AND B.idclient=" . cSecurity::toInteger($client) . " AND B.archived='" . $db2->escape($yearmonth) . "'";
220: } else {
221: $sql = "SELECT SUM(visited) FROM " . $db2->escape($sHeapTable) . " WHERE idcat=" . cSecurity::toInteger($idcat) . "
222: AND idclient=" . cSecurity::toInteger($client) . " AND archived='" . $db2->escape($yearmonth) . "'";
223: }
224: }
225: $db2->query($sql);
226: $db2->nextRecord();
227:
228: $total = $db2->f(0);
229:
230:
231: if (strcmp($yearmonth, "current") == 0) {
232: $sql = "SELECT SUM(visited) FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat"] . " AS B WHERE A.idcatart=B.idcatart AND A.idcat=" . cSecurity::toInteger($idcat) . "
233: AND B.idlang=" . cSecurity::toInteger($lang) . " AND B.idclient=" . cSecurity::toInteger($client);
234: } else {
235: if (!$bUseHeapTable) {
236: $sql = "SELECT SUM(visited) FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat_archive"] . " AS B WHERE A.idcatart=B.idcatart AND A.idcat=" . cSecurity::toInteger($idcat) . "
237: AND B.idlang=" . cSecurity::toInteger($lang) . " AND B.idclient=" . cSecurity::toInteger($client) . " AND B.archived='" . $db2->escape($yearmonth) . "'";
238: } else {
239: $sql = "SELECT SUM(visited) FROM " . $db2->escape($sHeapTable) . " WHERE idcat=" . cSecurity::toInteger($idcat) . " AND idlang=" . cSecurity::toInteger($lang) . "
240: AND idclient=" . cSecurity::toInteger($client) . " AND archived='" . $db2->escape($yearmonth) . "'";
241: }
242: }
243:
244: $db2->query($sql);
245: $db2->nextRecord();
246:
247: $inThisLanguage = $db2->f(0);
248:
249: $icon = '<img src="' . $cfg['path']['images'] . 'folder.gif" class="vAlignMiddle">';
250:
251:
252: $sql = "SELECT * FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["art"] . " AS B, " . $cfg["tab"]["art_lang"] . " AS C WHERE A.idcat=" . cSecurity::toInteger($idcat) . "
253: AND A.idart=B.idart AND B.idart=C.idart AND C.idlang=" . cSecurity::toInteger($lang) . " ORDER BY B.idart";
254: $db2->query($sql);
255:
256: $numrows = $db2->numRows();
257: $onclick = "";
258:
259: $online = $db->f("visible");
260: if ($bCatVisible == 1) {
261: $offonline = '<img src="' . $cfg['path']['images'] . 'online_off.gif" alt="' . i18n("Category is online") . '" title="' . i18n("Category is online") . '">';
262: } else {
263: $offonline = '<img src="' . $cfg['path']['images'] . 'offline_off.gif" alt="' . i18n("Category is offline") . '" title="' . i18n("Category is offline") . '">';
264: }
265:
266:
267: $iSumSubCategories = 0;
268: $sSql = "SELECT COUNT(*) AS cat_count FROM " . $cfg["tab"]["cat"] . " WHERE parentid=" . cSecurity::toInteger($idcat) . ";";
269: $db3 = cRegistry::getDb();
270: $db3->query($sSql);
271: if ($db3->nextRecord()) {
272: $iSumSubCategories = $db3->f('cat_count');
273: }
274: $db3->free();
275:
276: $tpl->set('d', 'PADDING_LEFT', $padding_left);
277: $tpl->set('d', 'TEXT', $text . ' (idcat: ' . cSecurity::toInteger($db->f('idcat')) . ')');
278: $tpl->set('d', 'ONCLICK', $onclick);
279: $tpl->set('d', 'ICON', $icon);
280: $tpl->set('d', 'STATUS', $offonline);
281: $tpl->set('d', 'NUMBEROFARTICLES', $numberOfArticles);
282: $tpl->set('d', 'TOTAL', $total);
283: $tpl->set('d', 'ROWNAME', implode('_', $aRowname));
284: if ($numrows > 0 || $iSumSubCategories > 0) {
285: $tpl->set('d', 'EXPAND', '<a href="javascript:changeVisibility(\'' . implode('_', $aRowname) . '\', ' . $db->f("level") . ', ' . $idcat . ')">
286: <img src="' . $cfg['path']['images'] . 'open_all.gif"
287: alt="' . i18n("Open category") . '"
288: title="' . i18n("Open category") . '"
289: id="' . implode('_', $aRowname) . '_img"
290: class="vAlignMiddle">
291: </a>');
292: } else {
293: $tpl->set('d', 'EXPAND', '<img src="' . $cfg['path']['images'] . 'spacer.gif" width="7">');
294: }
295: $tpl->set('d', 'INTHISLANGUAGE', $inThisLanguage);
296: if ($db->f("level") != 0) {
297: $tpl->set('d', 'DISPLAY_ROW', 'none');
298: } else {
299: $tpl->set('d', 'DISPLAY_ROW', $sDisplay);
300: }
301: $frontendURL = cRegistry::getFrontendUrl();
302: $cat_name = "";
303: statCreateLocationString($db->f('idcat'), " / ", $cat_name);
304: $tpl->set('d', 'PATH', i18n("Path") . ": / " . $cat_name);
305: $tpl->set('d', 'ULR_TO_PAGE', $frontendURL . 'front_content.php?idcat=' . $db->f('idcat'));
306:
307: $tpl->next();
308: $currentRow++;
309:
310: $onclick = "";
311: $text = "";
312: $numberOfArticles = "";
313: $total = "";
314: $inThisLanguage = "";
315:
316: while ($db2->nextRecord()) {
317: $idart = $db2->f("idart");
318:
319: array_push($aRowname, $idart);
320:
321: $text = "";
322: $numberOfArticles = "";
323: $total = "";
324: $inThisLanguage = "";
325:
326: $padding_left = 10 + (15 * ($db->f("level") + 1));
327:
328: $text = $db2->f("title");
329: $online = $db2->f("online");
330:
331:
332: $db3 = cRegistry::getDb();
333:
334:
335: if (strcmp($yearmonth, "current") == 0) {
336: $sql = "SELECT SUM(visited) FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat"] . " AS B WHERE A.idcatart=B.idcatart AND A.idcat=" . cSecurity::toInteger($idcat) . "
337: AND A.idart=" . cSecurity::toInteger($idart) . " AND B.idclient=" . cSecurity::toInteger($client);
338: } else {
339: if (!$bUseHeapTable) {
340: $sql = "SELECT SUM(visited) FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat_archive"] . " AS B WHERE A.idcatart=B.idcatart AND A.idcat=" . cSecurity::toInteger($idcat) . "
341: AND A.idart=" . cSecurity::toInteger($idart) . " AND B.idclient=" . cSecurity::toInteger($client) . " AND B.archived='" . $db3->escape($yearmonth) . "'";
342: } else {
343: $sql = "SELECT SUM(visited) FROM " . $db3->escape($sHeapTable) . " WHERE idcat=" . cSecurity::toInteger($idcat) . " AND idart=" . cSecurity::toInteger($idart) . "
344: AND idclient=" . cSecurity::toInteger($client) . " AND archived='" . $db3->escape($yearmonth) . "'";
345: }
346: }
347:
348: $db3->query($sql);
349: $db3->nextRecord();
350:
351: $total = $db3->f(0);
352:
353:
354: if (strcmp($yearmonth, "current") == 0) {
355: $sql = "SELECT visited, idart FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat"] . " AS B WHERE A.idcatart=B.idcatart AND A.idcat=" . cSecurity::toInteger($idcat) . "
356: AND A.idart=" . cSecurity::toInteger($idart) . " AND B.idlang=" . cSecurity::toInteger($lang) . " AND B.idclient=" . cSecurity::toInteger($client);
357: } else {
358: if (!$bUseHeapTable) {
359: $sql = "SELECT visited, idart FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat_archive"] . " AS B WHERE A.idcatart=B.idcatart AND A.idcat=" . cSecurity::toInteger($idcat) . "
360: AND A.idart=" . cSecurity::toInteger($idart) . " AND B.idlang=" . cSecurity::toInteger($lang) . " AND B.idclient=" . cSecurity::toInteger($client) . "
361: AND B.archived='" . $db3->escape($yearmonth) . "'";
362: } else {
363: $sql = "SELECT visited, idart FROM " . $db3->escape($sHeapTable) . " WHERE idcat=" . cSecurity::toInteger($idcat) . " AND idart=" . cSecurity::toInteger($idart) . "
364: AND idlang=" . cSecurity::toInteger($lang) . " AND idclient=" . cSecurity::toInteger($client) . " AND archived='" . $db3->escape($yearmonth) . "'";
365: }
366: }
367:
368: $db3->query($sql);
369: $db3->nextRecord();
370:
371: $inThisLanguage = $db3->f(0);
372:
373: if ($online == 0) {
374: $offonline = '<img src="' . $cfg['path']['images'] . 'offline_off.gif" alt="' . i18n("Article is offline") . '" title="' . i18n("Article is offline") . '">';
375: } else {
376: $offonline = '<img src="' . $cfg['path']['images'] . 'online_off.gif" alt="' . i18n("Article is online") . '" title="' . i18n("Article is online") . '">';
377: }
378:
379: $icon = '<img src="' . $cfg['path']['images'] . 'article.gif" class="vAlignMiddle">';
380: $tpl->set('d', 'PADDING_LEFT', $padding_left);
381: $tpl->set('d', 'TEXT', $text . ' (idart: ' . cSecurity::toInteger($db3->f('idart')) . ')');
382: $tpl->set('d', 'ONCLICK', "");
383: $tpl->set('d', 'ICON', $icon);
384: $tpl->set('d', 'STATUS', $offonline);
385: $tpl->set('d', 'ROWNAME', implode('_', $aRowname));
386:
387: $tpl->set('d', 'NUMBEROFARTICLES', $numberOfArticles);
388: $tpl->set('d', 'TOTAL', $total);
389: $tpl->set('d', 'INTHISLANGUAGE', $inThisLanguage);
390: $tpl->set('d', 'EXPAND', '<img src="' . $cfg['path']['images'] . 'spacer.gif" width="7">');
391: $tpl->set('d', 'DISPLAY_ROW', 'none');
392: $cat_name = "";
393: statCreateLocationString($db3->f('idart'), " / ", $cat_name);
394: $tpl->set('d', 'PATH', i18n("Path") . ": / " . $cat_name);
395: $tpl->set('d', 'ULR_TO_PAGE', $frontendURL . 'front_content.php?idart=' . $db3->f('idart'));
396: $tpl->next();
397: $currentRow++;
398:
399: array_pop($aRowname);
400: }
401: }
402:
403:
404: if (strcmp($yearmonth, "current") == 0) {
405: $sql = "SELECT SUM(visited) FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat"] . " AS B WHERE A.idcatart=B.idcatart AND B.idclient=" . cSecurity::toInteger($client);
406: } else {
407: if (!$bUseHeapTable) {
408: $sql = "SELECT SUM(visited) FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat_archive"] . " AS B WHERE A.idcatart=B.idcatart AND B.idclient=" . cSecurity::toInteger($client) . "
409: AND B.archived='" . $db->escape($yearmonth) . "'";
410: } else {
411: $sql = "SELECT SUM(visited) FROM " . $db->escape($sHeapTable) . " WHERE idclient=" . cSecurity::toInteger($client) . " AND archived='" . $db->escape($yearmonth) . "'";
412: }
413: }
414:
415: $db->query($sql);
416: $db->nextRecord();
417:
418: $total = $db->f(0);
419:
420:
421: if (strcmp($yearmonth, "current") == 0) {
422: $sql = "SELECT SUM(visited) FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat"] . " AS B WHERE A.idcatart=B.idcatart AND B.idlang=" . cSecurity::toInteger($lang) . "
423: AND B.idclient=" . cSecurity::toInteger($client);
424: } else {
425: if (!$bUseHeapTable) {
426: $sql = "SELECT SUM(visited) FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat_archive"] . " AS B WHERE A.idcatart=B.idcatart AND B.idlang=" . cSecurity::toInteger($lang) . "
427: AND B.idclient=" . cSecurity::toInteger($client) . " AND B.archived='" . $db->escape($yearmonth) . "'";
428: } else {
429: $sql = "SELECT SUM(visited) FROM " . $db->escape($sHeapTable) . " WHERE idlang=" . cSecurity::toInteger($lang) . " AND idclient=" . cSecurity::toInteger($client) . "
430: AND archived='" . $db->escape($yearmonth) . "'";
431: }
432: }
433:
434: $db->query($sql);
435: $db->nextRecord();
436:
437: $inThisLanguage = $db->f(0);
438:
439: $tpl->set('d', 'TEXT', ' ');
440: $tpl->set('d', 'ICON', '');
441: $tpl->set('d', 'STATUS', '');
442: $tpl->set('d', 'PADDING_LEFT', '10');
443: $tpl->set('d', 'NUMBEROFARTICLES', '');
444: $tpl->set('d', 'TOTAL', '');
445: $tpl->set('d', 'INTHISLANGUAGE', '');
446: $tpl->set('d', 'EXPAND', '');
447: $tpl->set('d', 'ROWNAME', '');
448: $tpl->set('d', 'ONCLICK', '');
449: $tpl->set('d', 'DISPLAY_ROW', $sDisplay);
450:
451: $tpl->set('s', 'SUMTEXT', i18n("Sum"));
452: $tpl->set('s', 'SUMNUMBEROFARTICLES', $sumNumberOfArticles);
453: $tpl->set('s', 'SUMTOTAL', $total);
454: $tpl->set('s', 'SUMINTHISLANGUAGE', $inThisLanguage);
455: $tpl->next();
456: }
457:
458: 459: 460: 461: 462: 463: 464:
465: function statsOverviewYear($year) {
466: global $cfg, $db, $tpl, $client, $lang;
467:
468: $sDisplay = 'table-row';
469:
470: if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) {
471: $sDisplay = 'block';
472: }
473:
474: $sql = "SELECT
475: idtree, A.idcat, level, preid, C.name, visible
476: FROM
477: " . $cfg["tab"]["cat_tree"] . " AS A,
478: " . $cfg["tab"]["cat"] . " AS B,
479: " . $cfg["tab"]["cat_lang"] . " AS C
480: WHERE
481: A.idcat=B.idcat AND
482: B.idcat=C.idcat AND
483: C.idlang=" . cSecurity::toInteger($lang) . " AND
484: B.idclient=" . cSecurity::toInteger($client) . "
485: ORDER BY idtree";
486:
487: $db->query($sql);
488:
489: $currentRow = 2;
490:
491: $aRowname = array();
492: $iLevel = 0;
493: $backendUrl = cRegistry::getBackendUrl();
494: $tpl->set('s', 'IMG_EXPAND', $backendUrl . $cfg['path']['images'] . 'open_all.gif');
495: $tpl->set('s', 'IMG_COLLAPSE', $backendUrl . $cfg['path']['images'] . 'close_all.gif');
496:
497: while ($db->nextRecord()) {
498: if ($db->f("level") == 0 && $db->f("preid") != 0) {
499: $tpl->set('d', 'PADDING_LEFT', '10');
500: $tpl->set('d', 'TEXT', ' ');
501: $tpl->set('d', 'NUMBEROFARTICLES', '');
502: $tpl->set('d', 'TOTAL', '');
503: $tpl->set('d', 'STATUS', '');
504: $tpl->set('d', 'ONCLICK', '');
505: $tpl->set('d', 'ICON', '');
506: $tpl->set('d', 'INTHISLANGUAGE', '');
507: $tpl->set('d', 'EXPAND', '');
508: $tpl->set('d', 'DISPLAY_ROW', $sDisplay);
509: $tpl->set('d', 'ROWNAME', '');
510: $tpl->next();
511: $currentRow++;
512: }
513:
514: $padding_left = 10 + (15 * $db->f("level"));
515: $text = $db->f(4);
516: $idcat = $db->f("idcat");
517: $bCatVisible = $db->f("visible");
518:
519: if ($db->f("level") < $iLevel) {
520: $iDistance = $iLevel - $db->f("level");
521:
522: for ($i = 0; $i < $iDistance; $i++) {
523: array_pop($aRowname);
524: }
525: $iLevel = $db->f("level");
526: }
527:
528: if ($db->f("level") >= $iLevel) {
529: if ($db->f("level") == $iLevel) {
530: array_pop($aRowname);
531: } else {
532: $iLevel = $db->f("level");
533: }
534: array_push($aRowname, $idcat);
535: }
536:
537: $db2 = cRegistry::getDb();
538:
539: $sql = "SELECT COUNT(*) FROM " . $cfg["tab"]["cat_art"] . " WHERE idcat=" . cSecurity::toInteger($idcat);
540: $db2->query($sql);
541: $db2->nextRecord();
542:
543: $numberOfArticles = $db2->f(0);
544: $sumNumberOfArticles += $numberOfArticles;
545: $sql = "SELECT SUM(visited) FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat_archive"] . " AS B WHERE A.idcatart=B.idcatart AND A.idcat=" . cSecurity::toInteger($idcat) . "
546: AND B.idclient=" . cSecurity::toInteger($client) . " AND SUBSTRING(B.archived,1,4)=" . cSecurity::toInteger($year, $db2) . " GROUP BY SUBSTRING(B.archived,1,4)";
547: $db2->query($sql);
548: $db2->nextRecord();
549:
550: $total = $db2->f(0);
551:
552:
553: $sql = "SELECT SUM(visited) FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat_archive"] . " AS B WHERE A.idcatart=B.idcatart AND A.idcat=" . cSecurity::toInteger($idcat) . "
554: AND B.idlang=" . cSecurity::toInteger($lang) . " AND B.idclient=" . cSecurity::toInteger($client) . " AND SUBSTRING(B.archived,1,4)=" . $db2->escape($year) . "
555: GROUP BY SUBSTRING(B.archived,1,4)";
556: $db2->query($sql);
557: $db2->nextRecord();
558:
559: $inThisLanguage = $db2->f(0);
560:
561: $icon = '<img src="' . $cfg['path']['images'] . 'folder.gif" class="vAlignMiddle">';
562:
563:
564: $sql = "SELECT * FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["art"] . " AS B, " . $cfg["tab"]["art_lang"] . " AS C WHERE A.idcat=" . cSecurity::toInteger($idcat) . " AND A.idart=B.idart AND B.idart=C.idart
565: AND C.idlang=" . cSecurity::toInteger($lang) . " ORDER BY B.idart";
566: $db2->query($sql);
567:
568: $numrows = $db2->numRows();
569: $onclick = "";
570:
571: if ($bCatVisible == 0) {
572: $offonline = '<img src="' . $cfg['path']['images'] . 'offline_off.gif" alt="' . i18n("Category is offline") . '" title="' . i18n("Category is offline") . '">';
573: } else {
574: $offonline = '<img src="' . $cfg['path']['images'] . 'online_off.gif" alt="' . i18n("Category is online") . '" title="' . i18n("Category is online") . '">';
575: }
576:
577:
578: $iSumSubCategories = 0;
579: $sSql = "SELECT count(*) as cat_count from " . $cfg["tab"]["cat"] . " WHERE parentid=" . cSecurity::toInteger($idcat) . ";";
580: $db3 = cRegistry::getDb();
581: $db3->query($sSql);
582: if ($db3->nextRecord()) {
583: $iSumSubCategories = $db3->f('cat_count');
584: }
585: $db3->free();
586:
587: $tpl->set('d', 'PADDING_LEFT', $padding_left);
588: $tpl->set('d', 'TEXT', $text . ' (idcat: ' . cSecurity::toInteger($db->f('idcat')) . ')');
589: $tpl->set('d', 'ONCLICK', $onclick);
590: $tpl->set('d', 'ICON', $icon);
591: $tpl->set('d', 'STATUS', $offonline);
592: $tpl->set('d', 'NUMBEROFARTICLES', $numberOfArticles);
593: $tpl->set('d', 'TOTAL', $total);
594: $tpl->set('d', 'ROWNAME', implode('_', $aRowname));
595: $tpl->set('d', 'INTHISLANGUAGE', $inThisLanguage);
596:
597: if ($numrows > 0 || $iSumSubCategories > 0) {
598: $tpl->set('d', 'EXPAND', '<a href="javascript:changeVisibility(\'' . implode('_', $aRowname) . '\', ' . $db->f("level") . ', ' . $idcat . ')">
599: <img src="' . $cfg['path']['images'] . 'open_all.gif"
600: alt="' . i18n("Open category") . '"
601: title="' . i18n("Open category") . '"
602: id="' . implode('_', $aRowname) . '_img"
603: class="vAlignMiddle">
604: </a>');
605: } else {
606: $tpl->set('d', 'EXPAND', '<img src="' . $cfg['path']['images'] . 'spacer.gif" width="7">');
607: }
608:
609: if ($db->f("level") != 0) {
610: $tpl->set('d', 'DISPLAY_ROW', 'none');
611: } else {
612: $tpl->set('d', 'DISPLAY_ROW', $sDisplay);
613: }
614: $frontendURL = cRegistry::getFrontendUrl();
615: $cat_name = "";
616: statCreateLocationString($db->f('idcat'), " / ", $cat_name);
617: $tpl->set('d', 'PATH', i18n("Path") . ": / " . $cat_name);
618: $tpl->set('d', 'ULR_TO_PAGE', $frontendURL . 'front_content.php?idcat=' . $db->f('idcat'));
619:
620: $tpl->next();
621: $currentRow++;
622:
623: $onclick = "";
624: $text = "";
625: $numberOfArticles = "";
626: $total = "";
627: $inThisLanguage = "";
628:
629: while ($db2->nextRecord()) {
630: $idart = $db2->f("idart");
631:
632: array_push($aRowname, $idart);
633:
634: $text = "";
635: $numberOfArticles = "";
636: $total = "";
637: $inThisLanguage = "";
638:
639: $padding_left = 10 + (15 * ($db->f("level") + 1));
640:
641: $text = $db2->f("title");
642: $online = $db2->f("online");
643:
644:
645: $db3 = cRegistry::getDb();
646:
647:
648: $sql = "SELECT SUM(visited) FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat_archive"] . " AS B WHERE A.idcatart=B.idcatart AND A.idcat=" . cSecurity::toInteger($idcat) . "
649: AND A.idart=" . cSecurity::toInteger($idart) . " AND B.idclient=" . cSecurity::toInteger($client) . " AND SUBSTRING(B.archived,1,4)=" . $db3->escape($year) . "
650: GROUP BY SUBSTRING(B.archived,1,4)";
651: $db3->query($sql);
652: $db3->nextRecord();
653:
654: $total = $db3->f(0);
655:
656:
657: $sql = "SELECT visited FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat_archive"] . " AS B WHERE A.idcatart=B.idcatart AND A.idcat=" . cSecurity::toInteger($idcat) . "
658: AND A.idart=" . cSecurity::toInteger($idart) . " AND B.idlang=" . cSecurity::toInteger($lang) . " AND B.idclient=" . cSecurity::toInteger($client) . "
659: AND SUBSTRING(B.archived,1,4)=" . $db3->escape($year) . " GROUP BY SUBSTRING(B.archived,1,4)";
660: $db3->query($sql);
661: $db3->nextRecord();
662:
663: $inThisLanguage = $db3->f(0);
664:
665: if ($online == 0) {
666: $offonline = '<img src="' . $cfg['path']['images'] . 'offline_off.gif" alt="' . i18n("Article is offline") . '" title="' . i18n("Article is offline") . '">';
667: } else {
668: $offonline = '<img src="' . $cfg['path']['images'] . 'online_off.gif" alt="' . i18n("Category is online") . '" title="' . i18n("Category is online") . '">';
669: }
670:
671: $icon = '<img src="' . $cfg['path']['images'] . 'article.gif" class="vAlignMiddle">';
672: $tpl->set('d', 'PADDING_LEFT', $padding_left);
673: $tpl->set('d', 'TEXT', $text . ' (idart: ' . cSecurity::toInteger($idart) . ')');
674: $tpl->set('d', 'ONCLICK', "");
675: $tpl->set('d', 'ICON', $icon);
676: $tpl->set('d', 'STATUS', $offonline);
677: $tpl->set('d', 'ROWNAME', implode('_', $aRowname));
678: $tpl->set('d', 'NUMBEROFARTICLES', $numberOfArticles);
679: $tpl->set('d', 'TOTAL', $total);
680: $tpl->set('d', 'ROWNAME', implode('_', $aRowname));
681: $tpl->set('d', 'EXPAND', '<img src="' . $cfg['path']['images'] . 'spacer.gif" width="7">');
682: $tpl->set('d', 'INTHISLANGUAGE', $inThisLanguage);
683: $tpl->set('d', 'DISPLAY_ROW', 'none');
684: $cat_name = "";
685: statCreateLocationString($idart, " / ", $cat_name);
686: $tpl->set('d', 'PATH', i18n("Path") . ": / " . $cat_name);
687: $tpl->set('d', 'ULR_TO_PAGE', $frontendURL . 'front_content.php?idart=' . $idart);
688:
689: $tpl->next();
690: $currentRow++;
691:
692: array_pop($aRowname);
693: }
694: }
695:
696:
697: $sql = "SELECT SUM(visited) FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat_archive"] . " AS B WHERE A.idcatart=B.idcatart AND B.idclient=" . cSecurity::toInteger($client) . "
698: AND SUBSTRING(B.archived,1,4)='" . $db->escape($year) . "' GROUP BY SUBSTRING(B.archived,1,4)";
699: $db->query($sql);
700: $db->nextRecord();
701:
702: $total = $db->f(0);
703:
704:
705: $sql = "SELECT SUM(visited) FROM " . $cfg["tab"]["cat_art"] . " AS A, " . $cfg["tab"]["stat_archive"] . " AS B WHERE A.idcatart=B.idcatart AND B.idlang=" . cSecurity::toInteger($lang) . "
706: AND B.idclient=" . cSecurity::toInteger($client) . " AND SUBSTRING(B.archived,1,4)='" . $db->escape($year) . "' GROUP BY SUBSTRING(B.archived,1,4)";
707: $db->query($sql);
708: $db->nextRecord();
709:
710: $inThisLanguage = $db->f(0);
711:
712: $tpl->set('d', 'TEXT', ' ');
713: $tpl->set('d', 'ICON', '');
714: $tpl->set('d', 'STATUS', '');
715: $tpl->set('d', 'PADDING_LEFT', '10');
716: $tpl->set('d', 'NUMBEROFARTICLES', '');
717: $tpl->set('d', 'TOTAL', '');
718: $tpl->set('d', 'ONCLICK', '');
719: $tpl->set('d', 'EXPAND', '');
720: $tpl->set('d', 'ROWNAME', '');
721: $tpl->set('d', 'INTHISLANGUAGE', '');
722: $tpl->set('d', 'DISPLAY_ROW', $sDisplay);
723: $tpl->set('s', 'SUMTEXT', "Summe");
724: $tpl->set('s', 'SUMNUMBEROFARTICLES', $sumNumberOfArticles);
725: $tpl->set('s', 'SUMTOTAL', $total);
726: $tpl->set('s', 'SUMINTHISLANGUAGE', $inThisLanguage);
727: $tpl->next();
728: }
729:
730: 731: 732: 733: 734: 735: 736: 737: 738:
739: function statsOverviewTop($yearmonth, $top) {
740: global $cfg, $db, $tpl, $client, $cfgClient, $lang;
741:
742: if (strcmp($yearmonth, "current") == 0) {
743: $sql = "SELECT DISTINCT
744: C.title, A.visited, C.idart
745: FROM
746: " . $cfg["tab"]["stat"] . " AS A,
747: " . $cfg["tab"]["cat_art"] . " AS B,
748: " . $cfg["tab"]["art_lang"] . " AS C
749: WHERE
750: C.idart = B.idart AND
751: C.idlang = A.idlang AND
752: B.idcatart = A.idcatart AND
753: A.idclient = " . cSecurity::toInteger($client) . " AND
754: A.idlang = " . cSecurity::toInteger($lang) . "
755: ORDER BY A.visited DESC
756: LIMIT " . $db->escape($top);
757: } else {
758: $sql = "SELECT DISTINCT
759: C.title, A.visited, B.idcat, C.idart
760: FROM
761: " . $cfg["tab"]["stat_archive"] . " AS A,
762: " . $cfg["tab"]["cat_art"] . " AS B,
763: " . $cfg["tab"]["art_lang"] . " AS C
764: WHERE
765: C.idart = B.idart AND
766: C.idlang = A.idlang AND
767: B.idcatart = A.idcatart AND
768: A.idclient = " . cSecurity::toInteger($client) . " AND
769: A.archived = '" . $db->escape($yearmonth) . "' AND
770: A.idlang = " . cSecurity::toInteger($lang) . " ORDER BY
771: A.visited DESC
772: LIMIT " . $db->escape($top);
773: }
774:
775: $db->query($sql);
776:
777: $frontendURL = cRegistry::getFrontendUrl();
778: while ($db->nextRecord()) {
779: $cat_name = "";
780: statCreateLocationString($db->f(2), " / ", $cat_name);
781: $tpl->set('d', 'PADDING_LEFT', '5');
782: $tpl->set('d', 'PATH', i18n("Path") . ": / " . $cat_name);
783: $tpl->set('d', 'TEXT', $db->f(0) . ' (idart: ' . cSecurity::toInteger($db->f('idart')) . ')');
784: $tpl->set('d', 'TOTAL', $db->f(1));
785: $tpl->set('d', 'ULR_TO_PAGE', $frontendURL . 'front_content.php?idart=' . $db->f('idart'));
786: $tpl->next();
787: }
788: }
789:
790: 791: 792: 793: 794: 795: 796: 797: 798: 799:
800: function statCreateLocationString($idcat, $seperator, &$cat_str) {
801: $cats = array();
802:
803:
804: $helper = cCategoryHelper::getInstance();
805: foreach ($helper->getCategoryPath($idcat) as $categoryLang) {
806: $cats[] = $categoryLang->getField('name');
807: }
808:
809: $cat_str = implode($seperator, $cats);
810: }
811:
812: 813: 814: 815: 816: 817: 818: 819:
820: function statsOverviewTopYear($year, $top) {
821: global $cfg, $db, $tpl, $client, $lang, $cfgClient;
822:
823: $sql = "SELECT
824: C.title, SUM(A.visited) as visited, B.idcat AS idcat, C.idart AS idart
825: FROM
826: " . $cfg["tab"]["stat_archive"] . " AS A,
827: " . $cfg["tab"]["cat_art"] . " AS B,
828: " . $cfg["tab"]["art_lang"] . " AS C
829: WHERE
830: C.idart = B.idart AND
831: C.idlang = A.idlang AND
832: B.idcatart = A.idcatart AND
833: A.idclient = " . cSecurity::toInteger($client) . " AND
834: A.archived LIKE '" . $db->escape($year) . "%' AND
835: A.idlang = " . cSecurity::toInteger($lang) . "
836: GROUP BY A.idcatart
837: ORDER BY visited DESC
838: LIMIT " . $db->escape($top);
839:
840: $db->query($sql);
841: $frontendURL = cRegistry::getFrontendUrl();
842: while ($db->nextRecord()) {
843: $cat_name = '';
844: statCreateLocationString($db->f('idcat'), " / ", $cat_name);
845:
846: $tpl->set('d', 'PADDING_LEFT', '0');
847: $tpl->set('d', 'PATH', i18n("Path") . ": / " . $cat_name);
848: $tpl->set('d', 'TEXT', $db->f(0) . ' (idart: ' . cSecurity::toInteger($db->f('idart')) . ')');
849: $tpl->set('d', 'TOTAL', $db->f(1));
850: $tpl->set('d', 'ULR_TO_PAGE', $frontendURL . 'front_content.php?idart=' . $db->f('idart'));
851: $tpl->next();
852: }
853: }
854:
855: 856: 857: 858: 859: 860:
861: function statDisplayTopChooser($default) {
862: if ($default == "top10") {
863: $defaultTop10 = "selected";
864: }
865: if ($default == "top20") {
866: $defaultTop20 = "selected";
867: }
868: if ($default == "top30") {
869: $defaultTop30 = "selected";
870: }
871: if ($default == "all") {
872: $defaultAll = "selected";
873: }
874:
875: return ("<form name=\"name\">" .
876: " <select class=\"text_medium\" onchange=\"top10Action(this)\">" .
877: " <option value=\"top10\" $defaultTop10>" . i18n("Top 10") . "</option>" .
878: " <option value=\"top20\" $defaultTop20>" . i18n("Top 20") . "</option>" .
879: " <option value=\"top30\" $defaultTop30>" . i18n("Top 30") . "</option>" .
880: " <option value=\"all\" $defaultAll>" . i18n("All") . "</option>" .
881: " </select>" .
882: "</form>");
883: }
884:
885: 886: 887: 888: 889: 890:
891: function statDisplayYearlyTopChooser($default) {
892: if ($default == "top10") {
893: $defaultTop10 = "selected";
894: }
895: if ($default == "top20") {
896: $defaultTop20 = "selected";
897: }
898: if ($default == "top30") {
899: $defaultTop30 = "selected";
900: }
901: if ($default == "all") {
902: $defaultAll = "selected";
903: }
904:
905: return ("<form name=\"name\">" .
906: " <select class=\"text_medium\" onchange=\"top10ActionYearly(this)\">" .
907: " <option value=\"top10\" $defaultTop10>" . i18n("Top 10") . "</option>" .
908: " <option value=\"top20\" $defaultTop20>" . i18n("Top 20") . "</option>" .
909: " <option value=\"top30\" $defaultTop30>" . i18n("Top 30") . "</option>" .
910: " <option value=\"all\" $defaultAll>" . i18n("All") . "</option>" .
911: " </select>" .
912: "</form>");
913: }
914:
915: 916: 917: 918: 919: 920:
921: function statGetAvailableYears($client, $lang) {
922: global $cfg, $db;
923:
924: $availableYears = array();
925:
926: $sql = "SELECT SUBSTRING(`archived`,1,4)
927: FROM
928: " . $cfg["tab"]["stat_archive"] . "
929: WHERE
930: idlang = " . cSecurity::toInteger($lang) . " AND
931: idclient = " . cSecurity::toInteger($client) . "
932: GROUP BY
933: SUBSTRING(`archived`,1,4)
934: ORDER BY
935: SUBSTRING(`archived`,1,4) DESC";
936:
937: $db->query($sql);
938: while ($db->nextRecord()) {
939: $availableYears[] = $db->f(0);
940: }
941:
942: return($availableYears);
943: }
944:
945: 946: 947: 948: 949: 950: 951:
952: function statGetAvailableMonths($year, $client, $lang) {
953: global $cfg, $db;
954:
955: $availableYears = array();
956:
957: $sql = "SELECT SUBSTRING(`archived`,5,2)
958: FROM
959: " . $cfg["tab"]["stat_archive"] . "
960: WHERE
961: idlang = " . cSecurity::toInteger($lang) . " AND
962: idclient = " . cSecurity::toInteger($client) . " AND
963: SUBSTRING(`archived`,1,4) = '" . $db->escape($year) . "'
964: GROUP BY
965: SUBSTRING(`archived`,5,2)
966: ORDER BY SUBSTRING(`archived`,5,2) DESC";
967:
968: $db->query($sql);
969: while ($db->nextRecord()) {
970: $availableYears[] = $db->f(0);
971: }
972:
973: return($availableYears);
974: }
975:
976: 977: 978: 979: 980: 981:
982: function statResetStatistic($client) {
983: global $db, $cfg;
984: $sql = "UPDATE " . $cfg["tab"]["stat"] . " SET visited=0 WHERE idclient=" . cSecurity::toInteger($client);
985: $db->query($sql);
986: }
987:
988: 989: 990: 991: 992: 993: 994:
995: function buildHeapTable($sHeapTable, $db) {
996: global $cfg;
997:
998: $sql = "DROP TABLE IF EXISTS " . $db->escape($sHeapTable) . ";";
999: $db->query($sql);
1000:
1001: $sql = "CREATE TABLE " . $db->escape($sHeapTable) . " TYPE=HEAP
1002: SELECT
1003: A.idcatart,
1004: A.idcat,
1005: A.idart,
1006: B.idstatarch,
1007: B.archived,
1008: B.idlang,
1009: B.idclient,
1010: B.visited
1011: FROM
1012: " . $cfg['tab']['cat_art'] . " AS A, " . $cfg['tab']['stat_archive'] . " AS B
1013: WHERE
1014: A.idcatart = B.idcatart;";
1015: $db->query($sql);
1016:
1017: $sql = "ALTER TABLE `" . $db->escape($sHeapTable) . "` ADD PRIMARY KEY (`idcatart`,`idcat` ,`idart`,`idstatarch` ,`archived`,`idlang`,`idclient` ,`visited`);";
1018: $db->query($sql);
1019: }
1020:
1021: ?>