PageRenderTime 46ms CodeModel.GetById 4ms RepoModel.GetById 1ms app.codeStats 0ms

/01.Source/01.CORE/includes/blocks/global.voting.php

http://creative-portal.googlecode.com/
PHP | 141 lines | 103 code | 27 blank | 11 comment | 12 complexity | 7f0498449072b3d5d1cdab079539f9be MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2010 VINADES., JSC. All rights reserved
  6. * @Createdate 3/25/2010 18:6
  7. */
  8. if ( ! defined( 'NV_SYSTEM' ) ) die( 'Stop!!!' );
  9. if ( ! function_exists( 'nv_block_voting' ) )
  10. {
  11. /**
  12. * nv_block_voting()
  13. *
  14. * @return
  15. */
  16. function nv_block_voting ( )
  17. {
  18. global $db, $my_head, $site_mods, $global_config, $client_info;
  19. $content = "";
  20. if ( ! isset( $site_mods['voting'] ) ) return "";
  21. $sql = "SELECT `vid`, `question`,`acceptcm`, `who_view`, `groups_view`, `publ_time`, `exp_time`
  22. FROM `" . NV_PREFIXLANG . "_" . $site_mods['voting']['module_data'] . "`
  23. WHERE `act`=1";
  24. $list = nv_db_cache( $sql, 'vid', 'voting' );
  25. if ( empty( $list ) ) return "";
  26. $allowed = array();
  27. $is_update = array();
  28. $a = 0;
  29. foreach ( $list as $row )
  30. {
  31. if ( ( int )$row['exp_time'] < 0 or ( ( int )$row['exp_time'] > 0 and $row['exp_time'] < NV_CURRENTTIME ) )
  32. {
  33. $is_update = $row['vid'];
  34. }
  35. else
  36. {
  37. if ( nv_set_allow( $row['who_view'], $row['groups_view'] ) )
  38. {
  39. $allowed[$a] = $row;
  40. $a ++;
  41. }
  42. }
  43. }
  44. if ( ! empty( $is_update ) )
  45. {
  46. $is_update = implode( ",", $is_update );
  47. $sql = "UPDATE `" . NV_PREFIXLANG . "_" . $site_mods['voting']['module_data'] . "`
  48. SET `act`=0 WHERE `id` IN (" . $is_update . ")";
  49. $db->sql_query( $sql );
  50. nv_del_moduleCache( 'voting' );
  51. }
  52. if ( $allowed )
  53. {
  54. $a --;
  55. $rand = rand( 0, $a );
  56. $current_voting = $allowed[$rand];
  57. $sql = "SELECT `id`, `vid`, `title` FROM `" . NV_PREFIXLANG . "_" . $site_mods['voting']['module_data'] . "_rows`
  58. WHERE `vid` = " . $current_voting['vid'] . " ORDER BY `id` ASC";
  59. $list = nv_db_cache( $sql, '', 'voting' );
  60. if ( empty( $list ) ) return "";
  61. include_once ( NV_ROOTDIR . "/modules/" . $site_mods['voting']['module_file'] . "/language/" . NV_LANG_INTERFACE . ".php" );
  62. if ( file_exists( NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $site_mods['voting']['module_file'] . "/global.voting.tpl" ) )
  63. {
  64. $block_theme = $global_config['module_theme'];
  65. }
  66. elseif ( file_exists( NV_ROOTDIR . "/themes/" . $global_config['site_theme'] . "/modules/" . $site_mods['voting']['module_file'] . "/global.voting.tpl" ) )
  67. {
  68. $block_theme = $global_config['site_theme'];
  69. }
  70. else
  71. {
  72. $block_theme = "default";
  73. }
  74. if ( ! defined( 'SHADOWBOX' ) )
  75. {
  76. $my_head .= "<link rel=\"Stylesheet\" href=\"" . NV_BASE_SITEURL . "js/shadowbox/shadowbox.css\" />\n";
  77. $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/shadowbox/shadowbox.js\"></script>\n";
  78. $my_head .= "<script type=\"text/javascript\">Shadowbox.init();</script>";
  79. define( 'SHADOWBOX', true );
  80. }
  81. $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "modules/" . $site_mods['voting']['module_file'] . "/js/user.js\"></script>\n";
  82. $action = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=voting";
  83. $voting_array = array( //
  84. "checkss" => md5( $current_voting['vid'] . $client_info['session_id'] . $global_config['sitekey'] ), //
  85. "accept" => ( int )$current_voting['acceptcm'], //
  86. "errsm" => ( int )$current_voting['acceptcm'] > 1 ? sprintf( $lang_module['voting_warning_all'], ( int )$current_voting['acceptcm'] ) : $lang_module['voting_warning_accept1'], //
  87. "vid" => $current_voting['vid'], //
  88. "question" => $current_voting['question'], //
  89. "action" => $action, //
  90. "langresult" => $lang_module['voting_result'], //
  91. "langsubmit" => $lang_module['voting_hits'] //
  92. );
  93. $xtpl = new XTemplate( "global.voting.tpl", NV_ROOTDIR . "/themes/" . $block_theme . "/modules/" . $site_mods['voting']['module_file'] );
  94. $xtpl->assign( 'VOTING', $voting_array );
  95. foreach ( $list as $row )
  96. {
  97. $xtpl->assign( 'RESULT', $row );
  98. if ( ( int )$current_voting['acceptcm'] > 1 )
  99. {
  100. $xtpl->parse( 'main.resultn' );
  101. }
  102. else
  103. {
  104. $xtpl->parse( 'main.result1' );
  105. }
  106. }
  107. $xtpl->parse( 'main' );
  108. $content = $xtpl->text( 'main' );
  109. }
  110. return $content;
  111. }
  112. }
  113. $content = nv_block_voting();
  114. ?>