fix_rooms.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Finds the sessions without access date and defines (for all sessions without access date older than 30
  4. * days in the past from now) a new access date based on the period (which can be found in the session
  5. * name).
  6. * @package chamilo.migrate
  7. */
  8. require_once '../../main/inc/global.inc.php';
  9. $log = 'sessions_dates_changes.txt';
  10. $ts = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_OPTIONS);
  11. $tv = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES);
  12. //$sql = "SELECT * FROM $ts WHERE access_start_date = '0000-00-00 00:00:00' AND access_end_date = '0000-00-00 00:00:00' ORDER BY name";
  13. //$sql = "SELECT * FROM $ts WHERE access_start_date = '0000-00-00 00:00:00' OR access_end_date = '0000-00-00 00:00:00' ORDER BY name";
  14. $sql = "SELECT id, option_value, option_display_text FROM $ts WHERE field_id = 6";
  15. echo $sql."\n";
  16. $res = Database::query($sql);
  17. if ($res !== false) {
  18. while ($row = Database::fetch_assoc($res)) {
  19. //echo "Session ".$row['name']." has no start/end date\n";
  20. $aid = $row['option_value'];
  21. $name = $row['option_display_text'];
  22. //$name = substr($name,5).' '.substr($name,0,4);
  23. // Get one session with this room
  24. $sql2 = "SELECT * FROM $tv WHERE field_id = 6 AND field_value = '$aid' LIMIT 1";
  25. //echo $sql2."\n";
  26. $res2 = Database::query($sql2);
  27. $row2 = Database::fetch_assoc($res2);
  28. if (empty($row2['session_id'])) { continue; }
  29. $session_id = $row2['session_id'];
  30. $sql3 = "SELECT field_value FROM $tv WHERE field_id = 3 AND session_id = $session_id";
  31. $res3 = Database::query($sql3);
  32. $row3 = Database::fetch_assoc($res3);
  33. if (empty($row3['field_value'])) { continue; }
  34. $branch_id = $row3['field_value'];
  35. $sql4 = "SELECT option_display_text FROM $ts WHERE field_id = 3 and option_value = '$branch_id'";
  36. $res4 = Database::query($sql4);
  37. $row4 = Database::fetch_assoc($res4);
  38. if (!empty($row4['option_display_text'])) {
  39. $name = substr($row4['option_display_text'],13).' - '.$name;
  40. echo $name."\n";
  41. $sql5 = "UPDATE $ts SET option_display_text = '$name' WHERE id = ".$row['id'];
  42. $res5 = Database::query($sql5);
  43. }
  44. }
  45. }