123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689 |
- <?php
- require_once("install_upgrade.lib.php");
- if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
- {
-
- if (empty ($updateFromConfigFile) || !file_exists($_POST['updatePath'].$updateFromConfigFile) || !in_array(get_config_param('clarolineVersion'), $update_from_version))
- {
- echo '<b>'.get_lang('Error').' !</b> Dokeos '.implode('|', $updateFromVersion).' '.get_lang('HasNotBeenFound').'.<br><br>
- '.get_lang('PleasGoBackToStep1').'.
- <p><input type="submit" name="step1" value="< '.get_lang('Back').'"></p>
- </td></tr></table></form></body></html>';
- exit ();
- }
-
-
-
- $_configuration['db_glue'] = get_config_param('dbGlu');
- if ($singleDbForm)
- {
- $_configuration['table_prefix'] = get_config_param('courseTablePrefix');
- }
- $dbScormForm = eregi_replace('[^a-z0-9_-]', '', $dbScormForm);
- if (!empty ($dbPrefixForm) && !ereg('^'.$dbPrefixForm, $dbScormForm))
- {
- $dbScormForm = $dbPrefixForm.$dbScormForm;
- }
- if (empty ($dbScormForm) || $dbScormForm == 'mysql' || $dbScormForm == $dbPrefixForm)
- {
- $dbScormForm = $dbPrefixForm.'scorm';
- }
- @mysql_connect($dbHostForm, $dbUsernameForm, $dbPassForm);
-
- if (mysql_errno() > 0)
- {
- $no = mysql_errno();
- $msg = mysql_error();
- echo '<hr>['.$no.'] - '.$msg.'<hr>
- '.get_lang('DBServerDoesntWorkOrLoginPassIsWrong').'.<br><br>
- '.get_lang('PleaseCheckTheseValues').' :<br><br>
- <b>'.get_lang('DBHost').'</b> : '.$dbHostForm.'<br>
- <b>'.get_lang('DBLogin').'</b> : '.$dbUsernameForm.'<br>
- <b>'.get_lang('DBPassword').'</b> : '.$dbPassForm.'<br><br>
- '.get_lang('PleaseGoBackToStep').' '. (defined('DOKEOS_INSTALL') ? '3' : '1').'.
- <p><input type="submit" name="step'. (defined('DOKEOS_INSTALL') ? '3' : '1').'" value="< '.get_lang('Back').'"></p>
- </td></tr></table></form></body></html>';
- exit ();
- }
-
-
-
- $only_test = false;
- if (defined('DOKEOS_INSTALL'))
- {
-
- include ("../lang/english/create_course.inc.php");
- if ($languageForm != 'english')
- {
-
- include ("../lang/$languageForm/create_course.inc.php");
- }
-
-
- $m_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','main');
- if(count($m_q_list)>0)
- {
-
-
- mysql_select_db($dbNameForm);
- foreach($m_q_list as $query){
- if($only_test){
- echo "mysql_query($dbNameForm,$query)<br/>";
- }else{
- $res = mysql_query($query);
- }
- }
- }
-
-
-
-
-
-
-
- $s_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','stats');
- if(count($s_q_list)>0)
- {
-
-
- mysql_select_db($dbStatsForm);
- foreach($s_q_list as $query){
- if($only_test){
- echo "mysql_query($dbStatsForm,$query)<br/>";
- }else{
- $res = mysql_query($query);
- }
- }
- }
-
- $u_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','user');
- if(count($u_q_list)>0)
- {
-
-
- mysql_select_db($dbUserForm);
- foreach($u_q_list as $query){
- if($only_test){
- echo "mysql_query($dbUserForm,$query)<br/>";
- }else{
- $res = mysql_query($query);
- }
- }
- }
-
- die();
-
-
- }
-
-
- $c_q_list = get_sql_file_contents('migrate-db-1.6.x-1.8.0-pre.sql','course');
- if(count($c_q_list)>0)
- {
-
- mysql_select_db($dbNameForm);
- $res = mysql_query("SELECT code,db_name,directory,course_language FROM course WHERE target_course_code IS NULL");
- if($res===false){die('Error while querying the courses list in update_db.inc.php');}
- if(mysql_num_rows($res)>0)
- {
- while($row = mysql_fetch_array($res))
- {
- $list[] = $row;
- }
- foreach($list as $row)
- {
-
-
- mysql_select_db($row['db_name']);
- foreach($c_q_list as $query)
- {
- if($only_test)
- {
- echo "mysql_query(".$row['db_name'].",$query)<br/>";
- }else{
- $res = mysql_query($query);
- }
- }
-
-
-
-
-
-
-
- $sql_orig = "SELECT * FROM bb_categories";
- $res_orig = mysql_query($sql_orig);
- while($row = mysql_fetch_array($res_orig)){
- $sql = "INSERT INTO forum_category " .
- "(cat_id,cat_title,cat_comment,cat_order,locked) VALUES " .
- "('".$row['cat_id']."','".$row['cat_title']."','','".$row['cat_order']."',0)";
- $res = mysql_query($sql);
- }
- $sql_orig = "SELECT * FROM bb_forums ORDER BY forum_last_post_id desc";
- $res_orig = mysql_query($sql_orig);
- $order = 1;
- while($row = mysql_fetch_array($res_orig)){
- $sql = "INSERT INTO forum_forum " .
- "(forum_id,forum_category,allow_edit,forum_comment," .
- "forum_title," .
- "forum_last_post, forum_threads," .
- "locked, forum_posts, " .
- "allow_new_threads, forum_order) VALUES " .
- "('".$row['forum_id']."','".$row['cat_id']."',1,'".$row['forum_desc']."'," .
- "'".$row['forum_name']."'," .
- "'".$row['forum_last_post_id']."','".$row['forum_topics']."'," .
- "0,'".$row['forum_posts']."'," .
- "1,$order)";
- $res = mysql_query($sql);
- $order++;
- }
- $sql_orig = "SELECT * FROM bb_topics";
- $res_orig = mysql_query($sql_orig);
- while($row = mysql_fetch_array($res_orig)){
-
- $time = $row['topic_time'];
- $name = $row['prenom']." ".$row['nom'];
- $sql = "INSERT INTO forum_thread " .
- "(thread_id,forum_id,thread_poster_id," .
- "locked,thread_replies,thread_sticky,thread_title," .
- "thread_poster_name, thread_date, thread_last_post," .
- "thread_views) VALUES " .
- "('".$row['topic_id']."','".$row['forum_id']."','".$row['topic_poster']."'," .
- "0,'".$row['topic_replies']."',0,'".$row['topic_title']."'," .
- "'$name','$time','".$row['topic_last_post_id']."'," .
- "'".$row['topic_views']."')";
- $res = mysql_query($sql);
- }
- $sql_orig = "SELECT * FROM bb_posts, bb_posts_text WHERE bb_posts.post_id = bb_posts_text.post_id";
- $res_orig = mysql_query($sql_orig);
- while($row = mysql_fetch_array($res_orig)){
-
- $time = $row['post_time'];
- $name = $row['prenom']." ".$row['nom'];
- $sql = "INSERT INTO forum_post " .
- "(post_id,forum_id,thread_id," .
- "poster_id,post_parent_id,visible, " .
- "post_title,poster_name, post_text, " .
- "post_date, post_notification) VALUES " .
- "('".$row['post_id']."','".$row['forum_id']."','".$row['topic_id']."'," .
- "'".$row['poster_id']."','".$row['parent_id']."',1," .
- "'".$row['post_title']."','$name', '".$row['post_text']."'," .
- "'$time',0)";
- $res = mysql_query($sql);
- }
- }
- }
- }
- $newPath = str_replace('\\', '/', realpath('../..')).'/';
- $coursePath = array ();
- $courseDB = array ();
- $nbr_courses = 0;
- if ($result = mysql_query("SELECT code,db_name,directory,course_language FROM `$dbNameForm`.`course` WHERE target_course_code IS NULL"))
- {
- $i = 0;
- $nbr_courses = mysql_num_rows($result);
- while ($i < MAX_COURSE_TRANSFER && (list ($course_code, $mysql_base_course, $directory, $languageCourse) = mysql_fetch_row($result)))
- {
- if (!file_exists($newPath.'courses/'.$directory))
- {
- if ($singleDbForm)
- {
- $prefix = $_configuration['table_prefix'].$mysql_base_course.$_configuration['db_glue'];
- $mysql_base_course = $dbNameForm.'`.`'.$_configuration['table_prefix'].$mysql_base_course;
- }
- else
- {
- $prefix = '';
- }
- $coursePath[$course_code] = $directory;
- $courseDB[$course_code] = $mysql_base_course;
- include ("../lang/english/create_course.inc.php");
- if ($languageCourse != 'english')
- {
- include ("../lang/$languageCourse/create_course.inc.php");
- }
-
-
-
-
- $i ++;
- }
- else
- {
- $nbr_courses --;
- }
- }
- }
- }
- else
- {
- echo 'You are not allowed here !';
- }
- function store_forumcategory($values)
- {
- global $table_categories;
- global $_course;
- global $_user;
-
-
- $sql="SELECT MAX(cat_order) as sort_max FROM ".mysql_real_escape_string($table_categories);
- $result=api_sql_query($sql);
- $row=mysql_fetch_array($result);
- $new_max=$row['sort_max']+1;
- $sql="INSERT INTO ".$table_categories." (cat_title, cat_comment, cat_order) VALUES ('".mysql_real_escape_string($values['forum_category_title'])."','".mysql_real_escape_string($values['forum_category_comment'])."','".mysql_real_escape_string($new_max)."')";
- api_sql_query($sql);
- $last_id=mysql_insert_id();
- api_item_property_update($_course, TOOL_FORUM_CATEGORY, $last_id,"ForumCategoryAdded", $_user['user_id']);
- return array('id'=>$last_id,'title'=>$values['forum_category_title']) ;
- }
- function store_forum($values)
- {
- global $table_forums;
- global $_course;
- global $_user;
-
- $sql="SELECT MAX(forum_order) as sort_max FROM ".$table_forums." WHERE forum_category=".mysql_real_escape_string($values['forum_category']);
- $result=api_sql_query($sql);
- $row=mysql_fetch_array($result);
- $new_max=$row['sort_max']+1;
-
- $sql="INSERT INTO ".$table_forums."
- (forum_title, forum_comment, forum_category, allow_anonymous, allow_edit, approval_direct_post, allow_attachments, allow_new_threads, default_view, forum_of_group, forum_group_public_private, forum_order)
- VALUES ('".mysql_real_escape_string($values['forum_title'])."',
- '".mysql_real_escape_string($values['forum_comment'])."',
- '".mysql_real_escape_string($values['forum_category'])."',
- '".mysql_real_escape_string($values['allow_anonymous_group']['allow_anonymous'])."',
- '".mysql_real_escape_string($values['students_can_edit_group']['students_can_edit'])."',
- '".mysql_real_escape_string($values['approval_direct_group']['approval_direct'])."',
- '".mysql_real_escape_string($values['allow_attachments_group']['allow_attachments'])."',
- '".mysql_real_escape_string($values['allow_new_threads_group']['allow_new_threads'])."',
- '".mysql_real_escape_string($values['default_view_type_group']['default_view_type'])."',
- '".mysql_real_escape_string($values['group_forum'])."',
- '".mysql_real_escape_string($values['public_private_group_forum_group']['public_private_group_forum'])."',
- '".mysql_real_escape_string($new_max)."')";
- api_sql_query($sql, __LINE__,__FILE__);
- $last_id=mysql_insert_id();
- api_item_property_update($_course, TOOL_FORUM, $last_id,"ForumCategoryAdded", $_user['user_id']);
- return array('id'=>$last_id, 'title'=>$values['forum_title']);
- }
- function store_thread($values)
- {
- global $table_threads;
- global $table_posts;
- global $_user;
- global $_course;
- global $current_forum;
-
-
- $sql="INSERT INTO $table_threads (thread_title, forum_id, thread_poster_id, thread_poster_name, thread_views, thread_date, thread_sticky)
- VALUES ('".mysql_real_escape_string($values['post_title'])."',
- '".mysql_real_escape_string($values['forum_id'])."',
- '".mysql_real_escape_string($values['user_id'])."',
- '".mysql_real_escape_string($values['poster_name'])."',
- '".mysql_real_escape_string($values['topic_views'])."',
- '".mysql_real_escape_string($values['post_date'])."',
- '".mysql_real_escape_string($values['thread_sticky'])."')";
- $result=api_sql_query($sql, __LINE__, __FILE__);
- $last_thread_id=mysql_insert_id();
- api_item_property_update($_course, TOOL_FORUM_THREAD, $last_thread_id,"ForumThreadAdded", $_user['user_id']);
-
-
-
-
- if ($values['visible']==0)
- {
- api_item_property_update($_course, TOOL_FORUM_THREAD, $last_thread_id,"invisible", $_user['user_id']);
- $visible=1;
- }
- return $last_thread_id;
- }
- function migrate_threads_of_forum($phpbb_forum_id, $new_forum_id)
- {
- global $phpbb_threads;
- global $table_forums;
-
- $table_users = Database :: get_main_table(TABLE_MAIN_USER);
-
- $sql_phpbb_threads="SELECT forum.*, users.user_id
- FROM $phpbb_threads forum, $table_users users
- WHERE forum_id='".mysql_real_escape_string($phpbb_forum_id)."'
- AND forum.nom=users.lastname AND forum.prenom=users.firstname
- ";
- $result_phpbb_threads=api_sql_query($sql_phpbb_threads);
- $threads_counter=0;
- while ($row_phpbb_threads=mysql_fetch_array($result_phpbb_threads))
- {
- $values['post_title']=$row_phpbb_threads['topic_title'];
- $values['forum_id']=$new_forum_id;
- $values['user_id']=$row_phpbb_threads['user_id'];
- $values['poster_name']=0;
- $values['topic_views']=$row_phpbb_threads['topic_views'];
- $values['post_date']=$row_phpbb_threads['topic_time'];
- $values['thread_sticky']=0;
- $values['visible']=$row_phpbb_threads['visible'];
-
- $new_forum_thread_id=store_thread($values);
-
-
- $posts_counter=$posts_counter+migrate_posts_of_thread($row_phpbb_threads['topic_id'], $new_forum_thread_id, $new_forum_id);
-
- $threads_counter++;
- }
-
-
- $sql="UPDATE $table_forums
- SET forum_posts='".mysql_real_escape_string($posts_counter)."',
- forum_threads='".mysql_real_escape_string($threads_counter)."'
- WHERE forum_id='".mysql_real_escape_string($new_forum_id)."'";
-
- $result=api_sql_query($sql);
- return array("threads"=>$threads_counter, "posts"=>$posts_counter);
- }
- function migrate_posts_of_thread($phpbb_thread_id, $new_forum_thread_id, $new_forum_id)
- {
- global $phpbb_posts;
- global $phpbb_poststext;
- global $table_posts;
- global $table_threads;
- global $added_resources;
-
- $table_users = Database :: get_main_table(TABLE_MAIN_USER);
- $table_added_resources = Database::get_course_table(TABLE_LINKED_RESOURCES);
-
-
- $post_counter=0;
-
- $sql_phpbb_posts="SELECT posts.*, posts_text.*, users.user_id, users.lastname, users.firstname FROM $phpbb_posts posts, $phpbb_poststext posts_text, $table_users users
- WHERE posts.post_id=posts_text.post_id
- AND posts.nom=users.lastname
- AND posts.prenom=users.firstname
- AND posts.topic_id='".mysql_real_escape_string($phpbb_thread_id)."'
- ";
- $result_phpbb_posts=api_sql_query($sql_phpbb_posts);
- while($row_phpbb_posts=mysql_fetch_array($result_phpbb_posts))
- {
- $values=array();
- $values['post_title']=$row_phpbb_posts['post_title'];
- $values['post_text']=$row_phpbb_posts['post_text'];
- $values['thread_id']=$new_forum_thread_id;
- $values['forum_id']=$new_forum_id;
- $values['user_id']=$row_phpbb_posts['user_id'];
- $values['post_date']=$row_phpbb_posts['post_time'];
- $values['post_notification']=$row_phpbb_posts['topic_notify'];
- $values['post_parent_id']=0;
- $values['visible']=1;
-
-
- $sql="INSERT INTO $table_posts (post_title, post_text, thread_id, forum_id, poster_id, post_date, post_notification, post_parent_id, visible)
- VALUES ('".mysql_real_escape_string($values['post_title'])."',
- '".mysql_real_escape_string($values['post_text'])."',
- '".mysql_real_escape_string($values['thread_id'])."',
- '".mysql_real_escape_string($values['forum_id'])."',
- '".mysql_real_escape_string($values['user_id'])."',
- '".mysql_real_escape_string($values['post_date'])."',
- '".mysql_real_escape_string($values['post_notification'])."',
- '".mysql_real_escape_string($values['post_parent_id'])."',
- '".mysql_real_escape_string($values['visible'])."')";
- $result=api_sql_query($sql, __LINE__, __FILE__);
- $post_counter++;
- $last_post_id=mysql_insert_id();
-
-
-
- if (in_array($row_phpbb_posts['post_id'],$added_resources))
- {
- $sql_update_added_resource="UPDATE $table_added_resources
- SET source_type='forum_post', source_id='".mysql_real_escape_string($last_post_id)."'
- WHERE source_type='".mysql_real_escape_string(TOOL_BB_POST)."' AND source_id='".mysql_real_escape_string($row_phpbb_posts['post_id'])."'";
- echo $sql_update_added_resource;
- $result=api_sql_query($sql_update_added_resource, __LINE__, __FILE__);
- }
- }
-
-
- $sql="UPDATE $table_threads SET thread_last_post='".mysql_real_escape_string($last_post_id)."',
- thread_replies='".mysql_real_escape_string($post_counter-1)."'
- WHERE thread_id='".mysql_real_escape_string($new_forum_thread_id)."'";
-
- $result=api_sql_query($sql, __LINE__, __FILE__);
-
- return $post_counter;
- }
- function get_added_resources()
- {
- $table_added_resources = Database::get_course_table(TABLE_LINKED_RESOURCES);
- $return_array=array();
-
- $sql_added_resources="SELECT * FROM $table_added_resources WHERE source_type='".mysql_real_escape_string(TOOL_BB_POST)."'";
- $result=api_sql_query($sql_added_resources);
- while ($row=mysql_fetch_array($result))
- {
- $return_array[]=$row['source_id'];
- }
- return $return_array;
- }
- function get_forumcategory_id_by_name($forum_category_name)
- {
- global $table_categories;
-
- $sql="SELECT cat_id FROM $table_categories WHERE cat_title='".mysql_real_escape_string($forum_category_name)."'";
-
- $result=api_sql_query($sql,__LINE__,__FILE__);
- $row=mysql_fetch_array($result);
-
- return $row['cat_id'];
- }
- ?>
|