/modules/ngstats/stats.php

https://bitbucket.org/netgen/ngstats · PHP · 174 lines · 120 code · 27 blank · 27 comment · 24 complexity · 43beb009ddc2ae73b0caf2ece17976a3 MD5 · raw file

  1. <?php
  2. // SOFTWARE NAME:
  3. // SOFTWARE RELEASE: 1.1
  4. // COPYRIGHT NOTICE:
  5. // SOFTWARE LICENSE: GNU General Public License v2.0
  6. // NOTICE: >
  7. // This program is free software; you can redistribute it and/or
  8. // modify it under the terms of version 2.0 of the GNU General
  9. // Public License as published by the Free Software Foundation.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of version 2.0 of the GNU General
  17. // Public License along with this program; if not, write to the Free
  18. // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19. // MA 02110-1301, USA.
  20. $http = eZHTTPTool::instance();
  21. $hasPost = false;
  22. $tpl = eZTemplate::factory();
  23. $Module = $Params["Module"];
  24. // ovo je primjer kako izvuci class parametar
  25. //$Params['class'];
  26. //$Params['user'];
  27. $Result = array();
  28. $stats_ini = eZINI::instance('stats.ini');
  29. $ini_classes = $stats_ini->variable('ListSettings', 'IncludeClasses');
  30. $ini_usergroups = $stats_ini->variable('ListSettings', 'IncludeUserGroups');
  31. $classObjects = eZPersistentObject::fetchObjectList( eZContentClass::definition(),
  32. null);
  33. $classList = array();
  34. foreach ($classObjects as $object)
  35. {
  36. if (in_array($object->attribute('identifier'), $ini_classes))
  37. {
  38. $classList[]=$object;
  39. }
  40. }
  41. $userObjects = eZPersistentObject::fetchOBjectList( eZUser::definition(),
  42. null );
  43. $userList = array();
  44. foreach ($userObjects as $user)
  45. {
  46. // $userGroup = $user->attribute( 'contentobject' )->attribute( 'main_node' )->attribute( 'parent' )->attribute( 'name' );
  47. $userGroups = $user->groups( true );
  48. foreach($userGroups as $userGroupObject)
  49. {
  50. if (in_array($userGroupObject->attribute('name'), $ini_usergroups))
  51. {
  52. $userList[]=$user;
  53. break;
  54. }
  55. }
  56. }
  57. //setting the module param class
  58. $classIdentifier = '';
  59. if ( isset( $Params['class'] ) )
  60. {
  61. $classIdentifier = $Params['class'];
  62. }
  63. if ( $http->hasPostVariable( 'user_class' ) )
  64. {
  65. $classIdentifier = $http->postVariable( 'user_class' );
  66. $hasPost = true;
  67. }
  68. //setting the module param user
  69. $userIdentifier = '';
  70. if ( isset( $Params['user'] ) )
  71. {
  72. $userIdentifier = $Params['user'];
  73. }
  74. if ( $http->hasPostVariable( 'user_id' ) )
  75. {
  76. $userIdentifier = $http->postVariable( 'user_id' );
  77. $hasPost = true;
  78. }
  79. //setting the module param begindate
  80. $begindate = mktime(0, 0, 0, 1, 1, 1972);
  81. $bd = 1;
  82. $bm = 1;
  83. $by = 1972;
  84. if ( isset( $Params['begindate'] ) )
  85. {
  86. $begindate = $Params['begindate'];
  87. }
  88. if ( $http->hasPostVariable( 'bd' ) && ($http->postVariable( 'bd' )!='') )
  89. {
  90. $bd = $http->postVariable( 'bd' );
  91. $hasPost = true;
  92. }
  93. if ( $http->hasPostVariable( 'bm' ) && ($http->postVariable( 'bm' )!='') )
  94. {
  95. $bm = $http->postVariable( 'bm' );
  96. $hasPost = true;
  97. }
  98. if ( $http->hasPostVariable( 'by' ) && ($http->postVariable( 'by' )!='') )
  99. {
  100. $by = $http->postVariable( 'by' );
  101. $hasPost = true;
  102. }
  103. $begindate = mktime(0, 0, 0, $bm, $bd, $by);
  104. //setting the module param enddate
  105. $enddate = time();
  106. $ed = 0;
  107. $em = 0;
  108. $ey = 0;
  109. if ( isset( $Params['enddate'] ) )
  110. {
  111. $enddate = $Params['enddate'];
  112. }
  113. if ( $http->hasPostVariable( 'ed' ) && ($http->postVariable( 'ed' )!='') )
  114. {
  115. $ed = $http->postVariable( 'ed' );
  116. $hasPost = true;
  117. }
  118. if ( $http->hasPostVariable( 'em' ) && ($http->postVariable( 'em' )!='') )
  119. {
  120. $em = $http->postVariable( 'em' );
  121. $hasPost = true;
  122. }
  123. if ( $http->hasPostVariable( 'ey' ) && ($http->postVariable( 'ey' )!='') )
  124. {
  125. $ey = $http->postVariable( 'ey' );
  126. $hasPost = true;
  127. }
  128. if ( ($ed!=0) && ($em!=0) && ($ey!=0) ) {
  129. $enddate = mktime(23, 59, 59, $em, $ed, $ey);
  130. }
  131. $tpl->setVariable('classlist', $classList);
  132. $tpl->setVariable('userlist', $userList);
  133. $offset = $Params['Offset'];
  134. $tpl->setVariable( 'view_parameters', array( 'offset' => $offset ) );
  135. if ($hasPost)
  136. {
  137. // converting post variables into ordered parameters
  138. $Module->redirectToView( 'stats', array( $classIdentifier,
  139. $userIdentifier,
  140. $begindate,
  141. $enddate ) );
  142. }
  143. $Result['content'] = $tpl->fetch('design:ngstats/stats.tpl');
  144. $Result['left_menu'] = "design:ngstats/leftmenu.tpl";
  145. $Result['path'] = array( array( 'url' => 'ngstats/stats',
  146. 'text' => 'User statistics' ) );
  147. ?>