3 if($_REQUEST['plog_sync'] == 1){
4 //update the plog_users table with ATutor members
6 $sql = "SELECT * from ".TABLE_PREFIX."members";
7 $result = mysql_query($sql,$db);
9 // But first check to see if the user already exists
10 $sqlu = "SELECT user, password FROM ".PLOG_PREFIX."users";
11 $resultu = mysql_query($sqlu,$db);
14 while($rowu = mysql_fetch_array($resultu)){
16 $existing_users[$i]= $rowu[0];
17 $existing_pwd[$i]=$rowu[1];
22 while ($row = mysql_fetch_array($result)){
23 if(!in_array($row[1],$existing_users) || (in_array($row[1],$existing_users) && !in_array(md5($row[2]),$existing_pwd))){
24 $sql2 = "REPLACE INTO ".PLOG_PREFIX."users VALUES ('$row[0]','$row[1]','".md5($row[2])."','$row[3]','$row[5] $row[6]','','a:0:{}','1','0')";
25 if(!$result5 = mysql_query($sql2)){
26 $msg->addError('PLOG_UPDATE_MEMBERS_FAILED');
29 $msg->addFeedback('PLOG_UPDATE_MEMBERS_SAVED');
33 //debug(md5($row[2]));
39 // The synchronizing of admin accounts is a problem because they are not admin members
40 // and don't have a user ID. or a course they are associated to. The following code was a first attempt
41 // at merging the admins into the plog_users table.
45 $sql = "SELECT * from ".TABLE_PREFIX."admins";
46 $result3 = mysql_query($sql);
48 $sql5="SELECT user FROM ".PLOG_PREFIX."users";
49 $result5 = mysql_query($sql5,$db);
52 while($row5 = mysql_fetch_array($result5)){
54 $existing_admins[$i] = $row5[0];
56 //update the plog_users table with ATutor admins
58 while ($row = mysql_fetch_array($result3)){
60 $admin_pref = 's:0:"";';
61 if(!in_array($row[0], $existing_admins)){
62 $sql3 = "REPLACE INTO ".PLOG_PREFIX."users VALUES ( ";
64 if($existing_admins != ''){
65 $sql3 .= ' \''. $existing_admins[$row[0]].'\',';
70 $sql3 .= "'$row[0]','".md5($row[1])."','$row[3]','$row[2]','','$admin_pref ','1','0')";
72 if(!$result4 = mysql_query($sql3, $db)){
73 $msg->addError('PLOG_UPDATE_ADMINS_FAILED');
75 $msg->addFeedback('PLOG_UPDATE_ADMINS_SAVED');
83 // get a list of course titles and create values for the mangled_blog values in the plog_blogs table
85 //update the plog_blogs table with ATutor courses. Creates one blog per course and assigns the instructor as the blog owner
87 $sql5 = "SELECT * FROM ".TABLE_PREFIX."courses";
88 $result5 = mysql_query($sql5,$db);
90 // But first check to see if the course already exists
91 $sqlb = "SELECT id FROM ".PLOG_PREFIX."blogs";
92 $resultb = mysql_query($sqlb,$db);
94 while($rowb = mysql_fetch_array($resultb)){
96 $existing_blogs[$i]= $rowb[0];
99 $default_blog_settings = 'O:12:"blogsettings":3:{s:6:"_objId";N;s:3:"log";N;s:6:"_props";a:14:{s:6:"locale";s:5:"en_UK";s:14:"show_posts_max";s:2:"15";s:8:"template";s:7:"blueish";s:17:"show_more_enabled";b:1;s:16:"recent_posts_max";s:2:"10";s:17:"xmlrpc_ping_hosts";a:2:{i:0;s:27:"http://rpc.weblogs.com/RPC2";i:1;s:0:"";}s:16:"htmlarea_enabled";b:1;s:16:"comments_enabled";b:1;s:16:"categories_order";s:1:"1";s:14:"comments_order";s:1:"1";s:11:"time_offset";s:2:"-5";s:21:"link_categories_order";s:1:"1";s:29:"show_future_posts_in_calendar";b:0;s:27:"new_drafts_autosave_enabled";b:0;}}';
101 while ($row = mysql_fetch_array($result5)){
104 if(!in_array($row[0], $existing_blogs)){
105 $course_title = addslashes($row[6]);
106 $spec_chars = array("'");
107 $temp_course_title = str_replace($spec_chars, "","$row[6]");
108 $temp_array = explode(" ", $temp_course_title);
109 $temp_mangle = strtolower($temp_array[0]."_".$temp_array[1]);
110 $sql2 = "REPLACE INTO ".PLOG_PREFIX."blogs VALUES ('$row[0]','$course_title','$row[1]','','$default_blog_settings','$temp_mangle','1','1')";
112 if(!$result1 = mysql_query($sql2)){
113 $msg->addError('PLOG_UPDATE_COURSE_FAILED');
116 $msg->addFeedback('PLOG_UPDATE_COURSE_SAVED');
122 //update plog_users_permissions with enrolled courses. Allows course members to write to the course blog
124 $sql6 = "SELECT * FROM ".TABLE_PREFIX."course_enrollment WHERE approved='y'";
125 $result6 = mysql_query($sql6,$db);
127 // first check if permission to write to course blogs already exists
129 $sqlk = "SELECT * FROM ".PLOG_PREFIX."users_permissions";
130 $resultk = mysql_query($sqlk,$db);
132 $existing_permissions = array();
133 while($rowk = mysql_fetch_array($resultk)){
135 $existing_permissions[$i]= $rowk[1].','.$rowk[2];
137 while ($row = mysql_fetch_array($result6)){
138 $this_permission = $row[1].','.$row[0];
139 if(!in_array($this_permission, $existing_permissions)) {
140 $sqlx = "REPLACE INTO ".PLOG_PREFIX."users_permissions VALUES ('','$row[1]','$row[0]','2')";
141 if(!$resultx = mysql_query($sqlx,$db)){
142 $msg->addError('PLOG_UPDATE_PERMISSIONS_FAILED');
145 $msg->addFeedback('PLOG_UPDATE_PERMISSIONS_SAVED');
151 //create an initial category for each course
152 $sqlcat = "SELECT * from ".TABLE_PREFIX."courses";
153 $resultcat = mysql_query($sqlcat,$db);
155 // But first check to see if a default course blog categoy already exists
156 $sqlm = "SELECT blog_id FROM ".PLOG_PREFIX."articles_categories";
157 $resultm = mysql_query($sqlm,$db);
160 while($rowm = mysql_fetch_array($resultm)){
162 $existing_cats[$i]= $rowm[0];
166 $default_cat_properties = 's:0:"";';
167 while($rowcat = mysql_fetch_array($resultcat)){
168 if(!in_array($rowcat[0], $existing_cats)){
169 $temp_title = str_replace("'","", $rowcat[6]);
170 $temp_cat_array = explode(" ", $temp_title);
171 $temp_cat_mangle = strtolower($temp_cat_array[0]."_".$temp_cat_array[1]);
172 $course_title = addslashes($rowcat[6]);
173 $sqlcat1 = "REPLACE INTO ".PLOG_PREFIX."articles_categories SET
175 name = '$course_title',
177 blog_id = '$rowcat[0]',
178 last_modification = now(),
181 description = '$course_title',
182 properties = '$default_cat_properties',
183 mangled_name = '$temp_cat_mangle'";
185 if(!$resultcat1 = mysql_query($sqlcat1,$db)){
186 $msg->addError('PLOG_UPDATE_CATS_FAILED');
189 $msg->addFeedback('PLOG_UPDATE_CATS_SAVED');
196 if( !$msg->containsFeedbacks() && !$msg->containsErrors()){
197 $msg->addFeedback('PLOG_UPDATE_NOT_REQUIRED');