3 This is a slightly modified version of the sync_plog file, adjusted to work with LifeType 1.1
4 It is not implemented in the atutor_plog-0.1 module. To implement it switch the require
5 lines at the top of the admin.plog.php and the instructor_index.php files.
7 if($_REQUEST['plog_sync'] == 1){
8 //update the plog_users table with ATutor members
10 $sql = "SELECT * from ".TABLE_PREFIX."members";
11 $result = mysql_query($sql,$db);
13 // But first check to see if the user already exists
14 $sqlu = "SELECT user, password FROM ".PLOG_PREFIX."users";
15 $resultu = mysql_query($sqlu,$db);
18 while($rowu = mysql_fetch_array($resultu)){
20 $existing_users[$i]= $rowu[0];
21 $existing_pwd[$i]= $rowu[1];
24 while ($row = mysql_fetch_array($result)){
25 if(!in_array($row[1],$existing_users) || (in_array($row[1],$existing_users) && !in_array(md5($row[2]),$existing_pwd))){
26 $sql2 = "REPLACE INTO ".PLOG_PREFIX."users SET
29 password = '".md5($row[2])."',
31 full_name = '".$row[5].$row[6]."',
35 resource_picture_id = '',
39 //this was the old 1.0.2 query
40 //VALUES ('$row[0]','$row[1]','".md5($row[2])."','$row[3]','$row[5] $row[6]','','a:0:{}','1','0')";
42 if(!$result1 = mysql_query($sql2)){
43 $msg->addError('PLOG_UPDATE_MEMBERS_FAILED');
46 $msg->addFeedback('PLOG_UPDATE_MEMBERS_SAVED');
53 // The synchronizing of admin accounts is a problem because they are not admin members
54 // and don't have a user ID. or a course they are associated to. The following code was a first attempt
55 // at merging the admins into the plog_users table.
59 $sql = "SELECT * from ".TABLE_PREFIX."admins";
60 $result3 = mysql_query($sql);
62 $sql5="SELECT user FROM ".PLOG_PREFIX."users";
63 $result5 = mysql_query($sql5,$db);
66 while($row5 = mysql_fetch_array($result5)){
68 $existing_admins[$i] = $row5[0];
70 //update the plog_users table with ATutor admins
72 while ($row = mysql_fetch_array($result3)){
74 $admin_pref = 's:0:"";';
75 if(!in_array($row[0], $existing_admins)){
76 $sql3 = "REPLACE INTO ".PLOG_PREFIX."users VALUES ( ";
78 if($existing_admins != ''){
79 $sql3 .= ' \''. $existing_admins[$row[0]].'\',';
84 $sql3 .= "'$row[0]','".md5($row[1])."','$row[3]','$row[2]','','$admin_pref ','1','0')";
86 if(!$result4 = mysql_query($sql3, $db)){
87 $msg->addError('PLOG_UPDATE_ADMINS_FAILED');
89 $msg->addFeedback('PLOG_UPDATE_ADMINS_SAVED');
97 // get a list of course titles and create values for the mangled_blog values in the plog_blogs table
99 //update the plog_blogs table with ATutor courses. Creates one blog per course and assigns the instructor as the blog owner
101 $sql5 = "SELECT * FROM ".TABLE_PREFIX."courses";
102 $result5 = mysql_query($sql5,$db);
104 // But first check to see if the course already exists
105 $sqlb = "SELECT id FROM ".PLOG_PREFIX."blogs";
106 $resultb = mysql_query($sqlb,$db);
108 while($rowb = mysql_fetch_array($resultb)){
110 $existing_blogs[$i]= $rowb[0];
113 // the 1.0.2 default blog setting
114 //$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;}}';
116 // the 1.1 default blog settings
117 $default_blog_settings = 'O:12:"blogsettings":1:{s:6:"_props";a:11:{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";s:1:"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";s:1:"1";s:16:"comments_enabled";s:1:"1";s:16:"categories_order";i:0;s:14:"comments_order";s:1:"1";s:11:"time_offset";s:1:"0";}}';
119 while ($row = mysql_fetch_array($result5)){
121 if(!in_array($row[0], $existing_blogs)){
122 $course_title = addslashes($row[6]);
123 $spec_chars = array("'");
124 $temp_course_title = str_replace($spec_chars, "","$row[6]");
125 $temp_array = explode(" ", $temp_course_title);
126 $temp_mangle = strtolower($temp_array[0]."_".$temp_array[1]);
127 $sql2 = "REPLACE INTO ".PLOG_PREFIX."blogs SET
129 blog = '$course_title',
130 owner_id = '$row[1]',
131 blog_category_id = '0',
133 settings = '$default_blog_settings',
134 mangled_blog = '$temp_mangl',
136 show_in_summary = '1',
137 create_date = 'now()',
138 last_update_date = 'now()',
141 num_trackbacks = '0'";
143 //VALUES ('$row[0]','$course_title','$row[1]','','$default_blog_settings','$temp_mangle','1','1')";
145 if(!$result1 = mysql_query($sql2)){
146 $msg->addError('PLOG_UPDATE_COURSE_FAILED');
149 $msg->addFeedback('PLOG_UPDATE_COURSE_SAVED');
155 //update plog_users_permissions with enrolled courses. Allows course members to write to the course blog
157 $sql6 = "SELECT * FROM ".TABLE_PREFIX."course_enrollment WHERE approved='y'";
158 $result6 = mysql_query($sql6,$db);
160 // first check if permission to write to course blogs already exists
162 $sqlk = "SELECT * FROM ".PLOG_PREFIX."users_permissions";
163 $resultk = mysql_query($sqlk,$db);
166 while($rowk = mysql_fetch_array($resultk)){
168 $existing_permissions[$i]= $rowk[1].','.$rowk[2];
171 while ($row = mysql_fetch_array($result6)){
172 $this_permission = $row[1].','.$row[0];
173 if(!in_array($this_permission, $existing_permissions)) {
174 $sqlx = "REPLACE INTO ".PLOG_PREFIX."users_permissions VALUES ('','$row[1]','$row[0]','2')";
175 if(!$resultx = mysql_query($sqlx,$db)){
176 $msg->addError('PLOG_UPDATE_PERMISSIONS_FAILED');
179 $msg->addFeedback('PLOG_UPDATE_PERMISSIONS_SAVED');
185 //create an initial category for each course
186 $sqlcat = "SELECT * from ".TABLE_PREFIX."courses";
187 $resultcat = mysql_query($sqlcat,$db);
189 // But first check to see if a default course blog categoy already exists
190 $sqlm = "SELECT blog_id FROM ".PLOG_PREFIX."articles_categories";
191 $resultm = mysql_query($sqlm,$db);
194 while($rowm = mysql_fetch_array($resultm)){
196 $existing_cats[$i]= $rowm[0];
200 $default_cat_properties = 's:0:"";';
201 while($rowcat = mysql_fetch_array($resultcat)){
202 if(!in_array($rowcat[0], $existing_cats)){
203 $temp_title = str_replace("'","", $rowcat[6]);
204 $temp_cat_array = explode(" ", $temp_title);
205 $temp_cat_mangle = strtolower($temp_cat_array[0]."_".$temp_cat_array[1]);
206 $course_title = addslashes($rowcat[6]);
207 $sqlcat1 = "REPLACE INTO ".PLOG_PREFIX."articles_categories SET
209 name = '$course_title',
211 blog_id = '$rowcat[0]',
212 last_modification = now(),
215 description = '$course_title',
216 properties = '$default_cat_properties',
217 mangled_name = '$temp_cat_mangle'";
219 if(!$resultcat1 = mysql_query($sqlcat1,$db)){
220 $msg->addError('PLOG_UPDATE_CATS_FAILED');
223 $msg->addFeedback('PLOG_UPDATE_CATS_SAVED');
230 if( !$msg->containsFeedbacks() && !$msg->containsErrors()){
231 $msg->addFeedback('PLOG_UPDATE_NOT_REQUIRED');