ajax.card.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /* For license terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This script answers to AJAX calls to store a new piece as revealed
  6. * in the plugin_card_game table.
  7. *
  8. * @author Damien Renou
  9. *
  10. * @package chamilo.plugin.card_game
  11. */
  12. require_once __DIR__.'/../../../main/inc/global.inc.php';
  13. $cardGameSession = Session::read('cardgame');
  14. if (!empty($cardGameSession)) {
  15. if ($cardGameSession == 'havedeck') {
  16. $part = '1';
  17. if (isset($_GET['part'])) {
  18. $part = (int) $_GET['part'];
  19. $userId = api_get_user_id();
  20. if (isset($userId)) {
  21. $sql = "UPDATE plugin_card_game
  22. SET access_date = CURDATE(), parts = CONCAT(parts,'!!$part;!')
  23. WHERE user_id = $userId";
  24. Database::query($sql);
  25. Session::write('cardgame', 'done');
  26. $sql = "UPDATE plugin_card_game
  27. SET pan = pan + 1, parts = ''
  28. WHERE parts LIKE '%!1;%' AND parts LIKE '%!2;%' AND parts LIKE '%!3;%' AND parts LIKE '%!4;%' AND parts LIKE '%!5;%' AND parts LIKE '%!6;%' AND parts LIKE '%!7%' AND parts LIKE '%!8%' AND parts LIKE '%!9%' AND parts LIKE '%10%' AND parts LIKE '%11%' AND parts LIKE '%12%' AND parts LIKE '%13%' AND parts LIKE '%14%' AND parts LIKE '%15%'
  29. AND user_id = $userId";
  30. Database::query($sql);
  31. }
  32. } elseif (isset($_GET['loose'])) {
  33. $userId = api_get_user_id();
  34. if (isset($userId)) {
  35. $sql = "UPDATE plugin_card_game
  36. SET access_date = CURDATE()
  37. WHERE user_id = $userId";
  38. Database::query($sql);
  39. Session::write('cardgame', 'done');
  40. }
  41. }
  42. }
  43. }