Lang column was missing from postgresql-files (?)
[moodle.git] / backup / lib.php
CommitLineData
afbe3de8 1<?PHP //$Id$
2 //This file contains all the function needed in the backup/restore utility
3 //except the mod-related funtions that are into every backuplib.php inside
4 //every mod directory
5
6 //Insert necessary category ids to backup_ids table
7 function insert_category_ids ($course,$backup_unique_code) {
8 global $CFG;
9 $status = true;
10 $status = execute_sql("INSERT INTO {$CFG->prefix}backup_ids
11 (backup_code, table_name, old_id)
12 SELECT DISTINCT '$backup_unique_code','quiz_categories',t.category
13 FROM {$CFG->prefix}quiz_questions t,
14 {$CFG->prefix}quiz_question_grades g,
15 {$CFG->prefix}quiz q
16 WHERE q.course = '$course' AND
17 g.quiz = q.id AND
18 g.question = t.id",false);
19 return $status;
20 }
21
22 //Delete category ids from backup_ids table
23 function delete_category_ids ($backup_unique_code) {
24 global $CFG;
25 $status = true;
26 $status = execute_sql("DELETE FROM {$CFG->prefix}backup_ids
27 WHERE backup_code = '$backup_unique_code'",false);
28 return $status;
29 }
1b502431 30
31 //Calculate the number of users to backup and put their ids in backup_ids
32 //Return an array of info (name,value)
33 function user_check_backup($course,$backup_unique_code,$backup_users) {
34 //$backup_users=0-->all
35 // 1-->course
36 // 2-->needed-->NOT IMPLEMEMTED
37
38 global $CFG;
39
40 if ($backup_users == 0) {
41 //Insert all users (from user)
42 $sql_insert = "INSERT INTO {$CFG->prefix}backup_ids
43 (backup_code, table_name, old_id)
44 SELECT DISTINCT '$backup_unique_code','user',u.id
45 FROM {$CFG->prefix}user u";
46 } else {
47 //Insert only course users (from user_students and user_teachers)
48 $sql_insert = "INSERT INTO {$CFG->prefix}backup_ids
49 (backup_code, table_name, old_id)
50 SELECT DISTINCT '$backup_unique_code','user',u.id
51 FROM {$CFG->prefix}user u,
52 {$CFG->prefix}user_students s,
53 {$CFG->prefix}user_teachers t
54 WHERE s.course = '$course' AND
55 t.course = s.course AND
56 (s.userid = u.id OR t.userid = u.id)";
57 }
58 //Execute the insert
59 $status = execute_sql($sql_insert,false);
60
61 //Now execute the select
62 $ids = get_records_sql("SELECT DISTINCT u.old_id,u.table_name
63 FROM {$CFG->prefix}backup_ids u
64 WHERE backup_code = '$backup_unique_code' AND
65 table_name ='user'");
66
67 //Gets the user data
68 $info[0][0] = get_string("users");
69 if ($ids) {
70 $info[0][1] = count($ids);
71 } else {
72 $info[0][1] = 0;
73 }
74
75 return $info;
76 }
afbe3de8 77
78?>