(no commit message)
[atutor.git] / admin / fix_content.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
7 /* http://atutor.ca                                                                                             */
8 /*                                                              */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License  */
11 /* as published by the Free Software Foundation.                                */
12 /****************************************************************/
13 // $Id$
14
15 define('AT_INCLUDE_PATH', '../include/');
16
17 require(AT_INCLUDE_PATH.'vitals.inc.php');
18 admin_authenticate(AT_ADMIN_PRIV_ADMIN);
19
20 require(AT_INCLUDE_PATH.'header.inc.php');
21
22 echo '<div style="padding-left: 30px;"><pre>';
23
24 echo "cpID\torder\t cID";
25
26 $sql    = "SELECT content_id, content_parent_id, ordering, course_id FROM ".TABLE_PREFIX."content ORDER BY course_id, content_parent_id, ordering";
27 $result = mysql_query($sql, $db);
28 while ($row = mysql_fetch_assoc($result)) {
29         if ($current_course_id != $row['course_id']) {
30                 echo "\n\n-- course id $row[course_id]\n\n";
31                 $current_course_id = $row['course_id'];
32                 unset($current_parent_id);
33                 unset($ordering);
34         }
35         echo $row['content_parent_id'] . "\t" . $row['ordering'] . "\t" . $row['content_id'];
36         if ($current_parent_id != $row['content_parent_id']) {
37                 $current_parent_id = $row['content_parent_id'];
38                 $ordering = 1;
39         }
40
41         if ($row['ordering'] != $ordering) {
42                 echo "\t mismatch : expecting $ordering [fixed]";
43                 $sql = "UPDATE ".TABLE_PREFIX."content SET ordering=$ordering WHERE content_id=$row[content_id]";
44                 mysql_query($sql, $db);
45                 write_to_log(AT_ADMIN_LOG_UPDATE, 'content', mysql_affected_rows($db), $sql);
46         }
47
48          echo "\n";
49
50         $ordering++;
51 }
52
53 echo' </pre></div>';
54
55 require(AT_INCLUDE_PATH.'footer.inc.php');
56 ?>