update_db.inc.php 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * Update the Dokeos database from an older version
  23. * Notice : This script has to be included by index.php and update_courses.php
  24. *
  25. * @package dokeos.install
  26. * @todo
  27. * - conditional changing of tables. Currently we execute for example
  28. * ALTER TABLE `$dbNameForm`.`cours` instructions without checking wether this is necessary.
  29. * - reorganise code into functions
  30. ==============================================================================
  31. */
  32. require_once("install_upgrade.lib.php");
  33. /*
  34. ==============================================================================
  35. MAIN CODE
  36. ==============================================================================
  37. */
  38. if (defined('DOKEOS_INSTALL') || defined('DOKEOS_COURSE_UPDATE'))
  39. {
  40. if (empty ($updateFromConfigFile) || !file_exists($_POST['updatePath'].$updateFromConfigFile) || !in_array(get_config_param('clarolineVersion'), $updateFromVersion))
  41. {
  42. echo '<b>Error !</b> Dokeos '.implode('|', $updateFromVersion).' has not been found.<br><br>
  43. Please go back to step 1.
  44. <p><input type="submit" name="step1" value="&lt; Back"></p>
  45. </td></tr></table></form></body></html>';
  46. exit ();
  47. }
  48. $dbGlu = get_config_param('dbGlu');
  49. if ($singleDbForm)
  50. {
  51. $courseTablePrefix = get_config_param('courseTablePrefix');
  52. }
  53. $dbScormForm = eregi_replace('[^a-z0-9_-]', '', $dbScormForm);
  54. if (!empty ($dbPrefixForm) && !ereg('^'.$dbPrefixForm, $dbScormForm))
  55. {
  56. $dbScormForm = $dbPrefixForm.$dbScormForm;
  57. }
  58. if (empty ($dbScormForm) || $dbScormForm == 'mysql' || $dbScormForm == $dbPrefixForm)
  59. {
  60. $dbScormForm = $dbPrefixForm.'scorm';
  61. }
  62. @ mysql_connect($dbHostForm, $dbUsernameForm, $dbPassForm);
  63. if (mysql_errno() > 0)
  64. {
  65. $no = mysql_errno();
  66. $msg = mysql_error();
  67. echo '<hr>['.$no.'] - '.$msg.'<hr>
  68. The mySQL server doesn\'t work or login / pass is bad.<br><br>
  69. Please check these values :<br><br>
  70. <b>host</b> : '.$dbHostForm.'<br>
  71. <b>user</b> : '.$dbUsernameForm.'<br>
  72. <b>password</b> : '.$dbPassForm.'<br><br>
  73. Please go back to step '. (defined('DOKEOS_INSTALL') ? '3' : '1').'.
  74. <p><input type="submit" name="step'. (defined('DOKEOS_INSTALL') ? '3' : '1').'" value="&lt; Back"></p>
  75. </td></tr></table></form></body></html>';
  76. exit ();
  77. }
  78. /*
  79. -----------------------------------------------------------
  80. Normal upgrade procedure:
  81. start by updating main, statistic, scorm, user databases
  82. -----------------------------------------------------------
  83. */
  84. if (defined('DOKEOS_INSTALL'))
  85. {
  86. /*
  87. -----------------------------------------------------------
  88. Update the main Dokeos database
  89. -----------------------------------------------------------
  90. */
  91. include ("../lang/english/create_course.inc.php");
  92. if ($languageForm != 'english')
  93. {
  94. include ("../lang/$languageForm/create_course.inc.php");
  95. }
  96. mysql_query("CREATE TABLE `$dbNameForm`.`language` (
  97. `id` tinyint(3) unsigned NOT NULL auto_increment,
  98. `original_name` varchar(255) default NULL,
  99. `english_name` varchar(255) default NULL,
  100. `isocode` varchar(10) default NULL,
  101. `dokeos_folder` varchar(250) default NULL,
  102. `available` tinyint(4) NOT NULL default '1',
  103. PRIMARY KEY (`id`)
  104. ) TYPE=MyISAM");
  105. mysql_query("CREATE TABLE `$dbNameForm`.`session` (
  106. `sess_id` varchar(32) NOT NULL default '',
  107. `sess_name` varchar(10) NOT NULL default '',
  108. `sess_time` int(11) NOT NULL default '0',
  109. `sess_start` int(11) NOT NULL default '0',
  110. `sess_value` text NOT NULL,
  111. PRIMARY KEY (`sess_id`)
  112. ) TYPE=MyISAM");
  113. mysql_query("CREATE TABLE `$dbNameForm`.`settings_current` (
  114. `id` int(10) unsigned NOT NULL auto_increment,
  115. `variable` varchar(255) default NULL,
  116. `subkey` varchar(255) default NULL,
  117. `type` varchar(255) default NULL,
  118. `category` varchar(255) default NULL,
  119. `selected_value` varchar(255) default NULL,
  120. `title` varchar(255) NOT NULL default '',
  121. `comment` varchar(255) default NULL,
  122. `scope` varchar(50) default NULL,
  123. `subkeytext` varchar(255) default NULL,
  124. UNIQUE KEY `id` (`id`)
  125. ) TYPE=MyISAM");
  126. mysql_query("CREATE TABLE `$dbNameForm`.`settings_options` (
  127. `id` int(10) unsigned NOT NULL auto_increment,
  128. `variable` varchar(255) default NULL,
  129. `value` varchar(255) default NULL,
  130. `display_text` varchar(255) NOT NULL default '',
  131. PRIMARY KEY (`id`),
  132. UNIQUE KEY `id` (`id`)
  133. ) TYPE=MyISAM");
  134. mysql_query("CREATE TABLE `$dbNameForm`.`sys_announcement` (
  135. `id` int(10) unsigned NOT NULL auto_increment,
  136. `date_start` datetime NOT NULL default '0000-00-00 00:00:00',
  137. `date_end` datetime NOT NULL default '0000-00-00 00:00:00',
  138. `visible_teacher` enum('true','false') NOT NULL default 'false',
  139. `visible_student` enum('true','false') NOT NULL default 'false',
  140. `visible_guest` enum('true','false') NOT NULL default 'false',
  141. `title` varchar(250) NOT NULL default '',
  142. `content` text NOT NULL,
  143. PRIMARY KEY (`id`)
  144. ) TYPE=MyISAM");
  145. mysql_query("DROP TABLE `$dbNameForm`.`todo`");
  146. mysql_query("DROP TABLE `$dbNameForm`.`pma_bookmark`");
  147. mysql_query("DROP TABLE `$dbNameForm`.`pma_column_comments`");
  148. mysql_query("DROP TABLE `$dbNameForm`.`pma_pdf_pages`");
  149. mysql_query("DROP TABLE `$dbNameForm`.`pma_relation`");
  150. mysql_query("DROP TABLE `$dbNameForm`.`pma_table_coords`");
  151. mysql_query("DROP TABLE `$dbNameForm`.`pma_table_info`");
  152. mysql_query("ALTER TABLE `$dbNameForm`.`admin` CHANGE `idUser` `user_id` INT UNSIGNED DEFAULT '0' NOT NULL");
  153. mysql_query("ALTER TABLE `$dbNameForm`.`admin` DROP INDEX `idUser`");
  154. mysql_query("ALTER TABLE `$dbNameForm`.`admin` ADD UNIQUE (`user_id`)");
  155. mysql_query("ALTER TABLE `$dbNameForm`.`class` ADD `code` VARCHAR(40) DEFAULT '' AFTER `id`");
  156. mysql_query("ALTER TABLE `$dbNameForm`.`class` CHANGE `name` `name` TEXT NOT NULL");
  157. mysql_query("ALTER TABLE `$dbNameForm`.`class_user` CHANGE `id_class` `class_id` MEDIUMINT(8) UNSIGNED DEFAULT '0' NOT NULL");
  158. mysql_query("ALTER TABLE `$dbNameForm`.`class_user` CHANGE `id_user` `user_id` INT UNSIGNED DEFAULT '0' NOT NULL");
  159. mysql_query("ALTER TABLE `$dbNameForm`.`cours` RENAME `$dbNameForm`.`course`");
  160. mysql_query("ALTER TABLE `$dbNameForm`.`course` DROP `cours_id`");
  161. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `code` `code` VARCHAR(40) NOT NULL");
  162. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `directory` `directory` VARCHAR(40) DEFAULT NULL");
  163. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `dbName` `db_name` VARCHAR(40) DEFAULT NULL");
  164. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `languageCourse` `course_language` VARCHAR(20) DEFAULT NULL");
  165. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `intitule` `title` VARCHAR(250) DEFAULT NULL");
  166. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `faculte` `category_code` VARCHAR(40) DEFAULT NULL");
  167. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `visible` `visibility` TINYINT(4) DEFAULT '0'");
  168. mysql_query("ALTER TABLE `$dbNameForm`.`course` DROP `cahier_charges`");
  169. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `scoreShow` `show_score` INT(11) DEFAULT '1' NOT NULL");
  170. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `titulaires` `tutor_name` VARCHAR(200) DEFAULT NULL");
  171. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `fake_code` `visual_code` VARCHAR(40) DEFAULT NULL");
  172. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `departmentUrlName` `department_name` VARCHAR(30) DEFAULT NULL");
  173. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `departmentUrl` `department_url` VARCHAR(180) DEFAULT NULL");
  174. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `diskQuota` `disk_quota` INT(10) UNSIGNED DEFAULT NULL");
  175. mysql_query("ALTER TABLE `$dbNameForm`.`course` DROP `versionDb`");
  176. mysql_query("ALTER TABLE `$dbNameForm`.`course` DROP `versionClaro`");
  177. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `lastVisit` `last_visit` DATETIME DEFAULT NULL");
  178. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `lastEdit` `last_edit` DATETIME DEFAULT NULL");
  179. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `creationDate` `creation_date` DATETIME DEFAULT NULL");
  180. mysql_query("ALTER TABLE `$dbNameForm`.`course` CHANGE `expirationDate` `expiration_date` DATETIME DEFAULT NULL");
  181. mysql_query("ALTER TABLE `$dbNameForm`.`course` ADD `target_course_code` VARCHAR(40)");
  182. mysql_query("ALTER TABLE `$dbNameForm`.`course` ADD `subscribe` TINYINT(4) DEFAULT '1' NOT NULL");
  183. mysql_query("ALTER TABLE `$dbNameForm`.`course` ADD `unsubscribe` TINYINT(4) DEFAULT '1' NOT NULL");
  184. mysql_query("ALTER TABLE `$dbNameForm`.`course` DROP PRIMARY KEY");
  185. mysql_query("ALTER TABLE `$dbNameForm`.`course` ADD PRIMARY KEY (`code`)");
  186. mysql_query("UPDATE `$dbNameForm`.`course` SET visibility='1' WHERE visibility='0'");
  187. mysql_query("UPDATE `$dbNameForm`.`course` SET visibility='3' WHERE visibility='2'");
  188. mysql_query("ALTER TABLE `$dbNameForm`.`faculte` RENAME `$dbNameForm`.`course_category`");
  189. mysql_query("ALTER TABLE `$dbNameForm`.`course_category` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  190. mysql_query("ALTER TABLE `$dbNameForm`.`course_category` CHANGE `code_P` `parent_id` VARCHAR(40) DEFAULT NULL");
  191. mysql_query("ALTER TABLE `$dbNameForm`.`course_category` DROP `bc`");
  192. mysql_query("ALTER TABLE `$dbNameForm`.`course_category` CHANGE `treePos` `tree_pos` INT(10) UNSIGNED DEFAULT NULL");
  193. mysql_query("ALTER TABLE `$dbNameForm`.`course_category` CHANGE `nb_childs` `children_count` SMALLINT(6) DEFAULT NULL");
  194. mysql_query("ALTER TABLE `$dbNameForm`.`course_category` CHANGE `canHaveCoursesChild` `auth_course_child` ENUM('TRUE', 'FALSE') DEFAULT 'TRUE'");
  195. mysql_query("ALTER TABLE `$dbNameForm`.`course_category` CHANGE `canHaveCatChild` `auth_cat_child` ENUM('TRUE', 'FALSE') DEFAULT 'TRUE'");
  196. mysql_query("ALTER TABLE `$dbNameForm`.`course_category` DROP INDEX `code_P`");
  197. mysql_query("ALTER TABLE `$dbNameForm`.`course_category` DROP INDEX `treePos`");
  198. mysql_query("ALTER TABLE `$dbNameForm`.`course_category` ADD UNIQUE (`code`)");
  199. mysql_query("ALTER TABLE `$dbNameForm`.`course_category` ADD INDEX (`parent_id`)");
  200. mysql_query("ALTER TABLE `$dbNameForm`.`course_category` ADD INDEX (`tree_pos`)");
  201. mysql_query("ALTER TABLE `$dbNameForm`.`tools_basic` RENAME `$dbNameForm`.`course_module`");
  202. mysql_query("ALTER TABLE `$dbNameForm`.`course_module` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  203. mysql_query("ALTER TABLE `$dbNameForm`.`course_module` CHANGE `rubrique` `name` VARCHAR(100) NOT NULL");
  204. mysql_query("ALTER TABLE `$dbNameForm`.`course_module` CHANGE `lien` `link` VARCHAR(255) NOT NULL");
  205. mysql_query("ALTER TABLE `$dbNameForm`.`course_module` CHANGE `row` `row` INT(10) UNSIGNED DEFAULT '0' NOT NULL");
  206. mysql_query("ALTER TABLE `$dbNameForm`.`course_module` CHANGE `column` `column` INT(10) UNSIGNED DEFAULT '0' NOT NULL");
  207. mysql_query("ALTER TABLE `$dbNameForm`.`cours_class` RENAME `$dbNameForm`.`course_rel_class`");
  208. mysql_query("ALTER TABLE `$dbNameForm`.`course_rel_class` CHANGE `code_cours` `course_code` CHAR(40) NOT NULL");
  209. mysql_query("ALTER TABLE `$dbNameForm`.`course_rel_class` CHANGE `id_class` `class_id` MEDIUMINT(8) UNSIGNED DEFAULT '0' NOT NULL");
  210. mysql_query("ALTER TABLE `$dbNameForm`.`cours_user` RENAME `$dbNameForm`.`course_rel_user`");
  211. mysql_query("ALTER TABLE `$dbNameForm`.`course_rel_user` CHANGE `code_cours` `course_code` VARCHAR(40) NOT NULL");
  212. mysql_query("ALTER TABLE `$dbNameForm`.`course_rel_user` CHANGE `statut` `status` TINYINT(4) DEFAULT '5' NOT NULL");
  213. mysql_query("ALTER TABLE `$dbNameForm`.`course_rel_user` CHANGE `user_id` `user_id` INT UNSIGNED DEFAULT '0' NOT NULL");
  214. mysql_query("ALTER TABLE `$dbNameForm`.`course_rel_user` CHANGE `team` `group_id` INT(11) DEFAULT '0' NOT NULL");
  215. mysql_query("ALTER TABLE `$dbNameForm`.`course_rel_user` CHANGE `tutor` `tutor_id` INT UNSIGNED DEFAULT '0' NOT NULL");
  216. mysql_query("ALTER TABLE `$dbNameForm`.`course_rel_user` ADD `sort` INT");
  217. mysql_query("ALTER TABLE `$dbNameForm`.`course_rel_user` ADD `user_course_cat` INT DEFAULT '0'");
  218. mysql_query("ALTER TABLE `$dbNameForm`.`user` CHANGE `user_id` `user_id` INT UNSIGNED NOT NULL AUTO_INCREMENT");
  219. mysql_query("ALTER TABLE `$dbNameForm`.`user` CHANGE `nom` `lastname` VARCHAR(60) DEFAULT NULL");
  220. mysql_query("ALTER TABLE `$dbNameForm`.`user` CHANGE `prenom` `firstname` VARCHAR(60) DEFAULT NULL");
  221. mysql_query("ALTER TABLE `$dbNameForm`.`user` CHANGE `username` `username` VARCHAR(20) NOT NULL");
  222. mysql_query("ALTER TABLE `$dbNameForm`.`user` CHANGE `password` `password` VARCHAR(50) NOT NULL");
  223. mysql_query("ALTER TABLE `$dbNameForm`.`user` CHANGE `authSource` `auth_source` VARCHAR(50) DEFAULT '".LOCAL_AUTH_SOURCE."'");
  224. mysql_query("ALTER TABLE `$dbNameForm`.`user` CHANGE `statut` `status` TINYINT(4) DEFAULT '5' NOT NULL");
  225. mysql_query("ALTER TABLE `$dbNameForm`.`user` CHANGE `officialCode` `official_code` VARCHAR(40) DEFAULT NULL");
  226. mysql_query("ALTER TABLE `$dbNameForm`.`user` CHANGE `phoneNumber` `phone` VARCHAR(30) DEFAULT NULL");
  227. mysql_query("ALTER TABLE `$dbNameForm`.`user` CHANGE `pictureUri` `picture_uri` VARCHAR(250) DEFAULT NULL");
  228. mysql_query("ALTER TABLE `$dbNameForm`.`user` CHANGE `creatorId` `creator_id` INT UNSIGNED DEFAULT NULL");
  229. mysql_query("ALTER TABLE `$dbNameForm`.`user` ADD `competences` TEXT AFTER `creator_id`");
  230. mysql_query("ALTER TABLE `$dbNameForm`.`user` ADD `diplomas` TEXT AFTER `competences`");
  231. mysql_query("ALTER TABLE `$dbNameForm`.`user` ADD `openarea` TEXT AFTER `diplomas`");
  232. mysql_query("ALTER TABLE `$dbNameForm`.`user` ADD `teach` TEXT AFTER `openarea`");
  233. mysql_query("ALTER TABLE `$dbNameForm`.`user` ADD `productions` VARCHAR(250) AFTER `teach`");
  234. mysql_query("ALTER TABLE `$dbNameForm`.`user` ADD `chatcall_user_id` INT UNSIGNED NOT NULL AFTER `productions`");
  235. mysql_query("ALTER TABLE `$dbNameForm`.`user` ADD `chatcall_date` DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL AFTER `chatcall_user_id`");
  236. mysql_query("ALTER TABLE `$dbNameForm`.`user` ADD `chatcall_text` VARCHAR(50) NOT NULL AFTER `chatcall_date`");
  237. $language_table = "`$dbNameForm`.`language`";
  238. fill_language_table($language_table);
  239. $installation_settings['institution_form'] = $institutionForm;
  240. $installation_settings['institution_url_form'] = $institutionUrlForm;
  241. $installation_settings['campus_form'] = $campusForm;
  242. $installation_settings['email_form'] = $emailForm;
  243. $installation_settings['admin_last_name'] = $adminLastName;
  244. $installation_settings['admin_first_name'] = $adminFirstName;
  245. $installation_settings['language_form'] = $languageForm;
  246. $installation_settings['allow_self_registration'] = $allowSelfReg;
  247. $installation_settings['allow_teacher_self_registration'] = $allowSelfRegProf;
  248. $installation_settings['admin_phone_form'] = $adminPhoneForm;
  249. $current_settings_table = "`$dbNameForm`.`settings_current`";
  250. fill_current_settings_table($current_settings_table, $installation_settings);
  251. $settings_options_table = "`$dbNameForm`.`settings_options`";
  252. fill_settings_options_table($settings_options_table);
  253. mysql_query("INSERT INTO `$dbNameForm`.`course_module` (`name`,`link`,`image`,`row`,`column`,`position`) VALUES
  254. ('AddedLearnpath', NULL, 'scormbuilder.gif', 0, 0, 'external'),
  255. ('".TOOL_BACKUP."', 'coursecopy/backup.php' , 'backup.gif', 2, 1, 'courseadmin'),
  256. ('".TOOL_COPY_COURSE_CONTENT."', 'coursecopy/copy_course.php' , 'copy.gif', 2, 2, 'courseadmin'),
  257. ('".TOOL_RECYCLE_COURSE."', 'coursecopy/recycle_course.php' , 'recycle.gif', 2, 3, 'courseadmin')");
  258. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_COURSE_DESCRIPTION."' WHERE link LIKE 'course_description/%'");
  259. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_CALENDAR_EVENT."' WHERE link LIKE 'calendar/%'");
  260. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_DOCUMENT."' WHERE link LIKE 'document/%'");
  261. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_ANNOUNCEMENT."' WHERE link LIKE 'announcements/%'");
  262. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_BB_FORUM."' WHERE link LIKE 'phpbb/%'");
  263. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_LINK."' WHERE link = 'link/link.php'");
  264. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_DROPBOX."' WHERE link LIKE 'dropbox/%'");
  265. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_QUIZ."' WHERE link LIKE 'exercice/%'");
  266. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_USER."' WHERE link LIKE 'user/%'");
  267. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_GROUP."' WHERE link LIKE 'group/%'");
  268. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_CHAT."' WHERE link LIKE 'chat/%'");
  269. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_CONFERENCE."' WHERE link LIKE 'online/%'");
  270. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_STUDENTPUBLICATION."' WHERE link LIKE 'work/%'");
  271. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_TRACKING."' WHERE link LIKE 'tracking/%'");
  272. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_HOMEPAGE_LINK."' WHERE link = 'link/link.php?action=addlink'");
  273. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_COURSE_SETTING."' WHERE link LIKE 'course_info/%'");
  274. mysql_query("UPDATE `$dbNameForm`.`course_module` SET name='".TOOL_LEARNPATH."' WHERE link LIKE 'scorm/%'");
  275. // existing courses should have a value entered for sort into the course_rel_user table
  276. $tbl_user=`$dbNameForm`.`user`;
  277. $tbl_course_user=`$dbNameForm`.`course_rel_user`;
  278. $sqlusers="SELECT * FROM $tbl_user";
  279. $resultusers=api_sql_query($sqlusers);
  280. while ($row=mysql_fetch_array($resultusers))
  281. {
  282. $counter=1;
  283. $sql_course_user="SELECT * FROM $tbl_course_user WHERE user_id='".$row['user_id']."'";
  284. $result_course_user=api_sql_query($sql_course_user);
  285. while ($rowcu=mysql_fetch_array($result_course_user))
  286. {
  287. $update="UPDATE $tbl_course_user SET sort='$counter' WHERE user_id='".$row['user_id']."' AND course_code='".$rowcu['course_code']."'";
  288. $resultupdate=api_sql_query($update);
  289. $counter++;
  290. }
  291. }
  292. /*
  293. -----------------------------------------------------------
  294. Update the tracking Dokeos database
  295. -----------------------------------------------------------
  296. */
  297. mysql_query("CREATE TABLE `$dbStatsForm`.`track_e_hotpotatoes` (
  298. `exe_name` varchar(255) NOT NULL default '',
  299. `exe_user_id` int unsigned default NULL,
  300. `exe_date` datetime NOT NULL default '0000-00-00 00:00:00',
  301. `exe_cours_id` varchar(20) NOT NULL default '',
  302. `exe_result` tinyint(4) NOT NULL default '0',
  303. `exe_weighting` tinyint(4) NOT NULL default '0'
  304. ) TYPE=MyISAM");
  305. mysql_query("CREATE TABLE `$dbStatsForm`.`track_e_online` (
  306. `login_id` int(11) NOT NULL auto_increment,
  307. `login_user_id` int unsigned NOT NULL default '0',
  308. `login_date` datetime NOT NULL default '0000-00-00 00:00:00',
  309. `login_ip` varchar(39) NOT NULL default '',
  310. PRIMARY KEY (`login_id`),
  311. KEY `login_user_id` (`login_user_id`)
  312. ) TYPE=MyISAM");
  313. mysql_query("ALTER TABLE `$dbStatsForm`.`track_e_access` CHANGE `access_user_id` `access_user_id` INT UNSIGNED DEFAULT NULL");
  314. mysql_query("ALTER TABLE `$dbStatsForm`.`track_e_default` CHANGE `default_user_id` `default_user_id` INT UNSIGNED DEFAULT '0' NOT NULL");
  315. mysql_query("ALTER TABLE `$dbStatsForm`.`track_e_downloads` CHANGE `down_user_id` `down_user_id` INT UNSIGNED DEFAULT NULL");
  316. mysql_query("ALTER TABLE `$dbStatsForm`.`track_e_exercices` CHANGE `exe_user_id` `exe_user_id` INT UNSIGNED DEFAULT NULL");
  317. mysql_query("ALTER TABLE `$dbStatsForm`.`track_e_exercices` CHANGE `exe_cours_id` `exe_cours_id` VARCHAR(40) NOT NULL DEFAULT ''");
  318. mysql_query("ALTER TABLE `$dbStatsForm`.`track_e_exercices` CHANGE `exe_exo_id` `exe_exo_id` MEDIUMINT UNSIGNED NOT NULL DEFAULT '0'");
  319. mysql_query("ALTER TABLE `$dbStatsForm`.`track_e_exercices` CHANGE `exe_result` `exe_result` SMALLINT NOT NULL DEFAULT '0'");
  320. mysql_query("ALTER TABLE `$dbStatsForm`.`track_e_exercices` CHANGE `exe_weighting` `exe_weighting` SMALLINT NOT NULL DEFAULT '0'");
  321. mysql_query("ALTER TABLE `$dbStatsForm`.`track_e_hotpotatoes` CHANGE `exe_cours_id` `exe_cours_id` VARCHAR(40) NOT NULL DEFAULT ''");
  322. mysql_query("ALTER TABLE `$dbStatsForm`.`track_e_hotpotatoes` CHANGE `exe_result` `exe_result` SMALLINT NOT NULL DEFAULT '0'");
  323. mysql_query("ALTER TABLE `$dbStatsForm`.`track_e_hotpotatoes` CHANGE `exe_weighting` `exe_weighting` SMALLINT NOT NULL DEFAULT '0'");
  324. mysql_query("ALTER TABLE `$dbStatsForm`.`track_e_lastaccess` CHANGE `access_user_id` `access_user_id` INT UNSIGNED DEFAULT NULL");
  325. mysql_query("ALTER TABLE `$dbStatsForm`.`track_e_links` CHANGE `links_user_id` `links_user_id` INT UNSIGNED DEFAULT NULL");
  326. mysql_query("ALTER TABLE `$dbStatsForm`.`track_e_login` CHANGE `login_user_id` `login_user_id` INT UNSIGNED DEFAULT '0' NOT NULL");
  327. mysql_query("ALTER TABLE `$dbStatsForm`.`track_e_uploads` CHANGE `upload_user_id` `upload_user_id` INT UNSIGNED DEFAULT NULL");
  328. /*
  329. -----------------------------------------------------------
  330. Create the User database
  331. -----------------------------------------------------------
  332. */
  333. $sql = "CREATE DATABASE IF NOT EXISTS `$dbUserForm`";
  334. mysql_query($sql);
  335. mysql_query("CREATE TABLE `$dbUserForm`.`personal_agenda` (
  336. `id` int NOT NULL auto_increment,
  337. `user` int unsigned,
  338. `title` text,
  339. `text` text,
  340. `date` datetime default NULL,
  341. `enddate` datetime default NULL,
  342. `course` varchar(255),
  343. UNIQUE KEY `id` (`id`))
  344. TYPE=MyISAM");
  345. mysql_query("CREATE TABLE `$dbUserForm`.`user_course_category` (
  346. `id` int unsigned NOT NULL auto_increment,
  347. `user_id` int unsigned NOT NULL default '0',
  348. `title` text NOT NULL,
  349. PRIMARY KEY (`id`)
  350. ) TYPE=MyISAM");
  351. }
  352. /*
  353. -----------------------------------------------------------
  354. Update the Dokeos course databases
  355. this part can be accessed in two ways:
  356. - from the normal upgrade process
  357. - from the script update_courses.php,
  358. which is used to upgrade more than MAX_COURSE_TRANSFER courses
  359. Every time this script is accessed, only
  360. MAX_COURSE_TRANSFER courses are upgraded.
  361. -----------------------------------------------------------
  362. */
  363. $newPath = str_replace('\\', '/', realpath('../..')).'/';
  364. $coursePath = array ();
  365. $courseDB = array ();
  366. $nbr_courses = 0;
  367. if ($result = mysql_query("SELECT code,db_name,directory,course_language FROM `$dbNameForm`.`course` WHERE target_course_code IS NULL"))
  368. {
  369. $i = 0;
  370. $nbr_courses = mysql_num_rows($result);
  371. while ($i < MAX_COURSE_TRANSFER && (list ($course_code, $mysql_base_course, $directory, $languageCourse) = mysql_fetch_row($result)))
  372. {
  373. if (!file_exists($newPath.'courses/'.$directory))
  374. {
  375. if ($singleDbForm)
  376. {
  377. $prefix = $courseTablePrefix.$mysql_base_course.$dbGlu;
  378. $mysql_base_course = $dbNameForm.'`.`'.$courseTablePrefix.$mysql_base_course;
  379. }
  380. else
  381. {
  382. $prefix = '';
  383. }
  384. $coursePath[$course_code] = $directory;
  385. $courseDB[$course_code] = $mysql_base_course;
  386. include ("../lang/english/create_course.inc.php");
  387. if ($languageCourse != 'english')
  388. {
  389. include ("../lang/$languageCourse/create_course.inc.php");
  390. }
  391. mysql_query("CREATE TABLE `$mysql_base_course".$dbGlu."chat_connected` (
  392. `user_id` int unsigned NOT NULL default '0',
  393. `last_connection` datetime NOT NULL default '0000-00-00 00:00:00',
  394. PRIMARY KEY (`user_id`)
  395. ) TYPE=MyISAM");
  396. mysql_query("CREATE TABLE `$mysql_base_course".$dbGlu."online_connected` (
  397. `user_id` int unsigned NOT NULL default '0',
  398. `last_connection` datetime NOT NULL default '0000-00-00 00:00:00',
  399. PRIMARY KEY (`user_id`)
  400. ) TYPE=MyISAM");
  401. mysql_query("CREATE TABLE `$mysql_base_course".$dbGlu."online_link` (
  402. `id` smallint(5) unsigned NOT NULL auto_increment,
  403. `name` char(50) NOT NULL default '',
  404. `url` char(100) NOT NULL default '',
  405. PRIMARY KEY (`id`)
  406. ) TYPE=MyISAM");
  407. mysql_query("DROP TABLE `$mysql_base_course".$dbGlu."online`");
  408. mysql_query("DROP TABLE `$mysql_base_course".$dbGlu."pages`");
  409. mysql_query("DROP TABLE `$mysql_base_course".$dbGlu."work_student`");
  410. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."last_tooledit` RENAME `".$prefix."item_property`");
  411. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."item_property` CHANGE `last_date` `lastedit_date` DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL");
  412. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."item_property` CHANGE `ref` `ref` INT(10) NOT NULL");
  413. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."item_property` CHANGE `type` `lastedit_type` VARCHAR(100) NOT NULL");
  414. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."item_property` CHANGE `user_id` `lastedit_user_id` INT UNSIGNED DEFAULT '0' NOT NULL");
  415. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."item_property` CHANGE `group_id` `to_group_id` INT(10) UNSIGNED DEFAULT NULL");
  416. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."item_property` ADD `to_user_id` INT UNSIGNED DEFAULT NULL");
  417. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."item_property` ADD `visibility` TINYINT(1) DEFAULT '1' NOT NULL");
  418. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."item_property` ADD `start_visible` DATETIME NOT NULL");
  419. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."item_property` ADD `end_visible` DATETIME NOT NULL");
  420. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."item_property` ADD `insert_user_id` INT UNSIGNED NOT NULL AFTER `tool`");
  421. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."item_property` ADD `insert_date` DATETIME NOT NULL AFTER `insert_user_id`");
  422. /*
  423. -----------------------------------------------------------
  424. Update the announcement table
  425. -----------------------------------------------------------
  426. */
  427. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."announcement` CHANGE `contenu` `content` TEXT DEFAULT NULL");
  428. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."announcement` CHANGE `id` `id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT");
  429. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."announcement` CHANGE `temps` `end_date` DATE DEFAULT NULL");
  430. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."announcement` DROP `code_cours`");
  431. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."announcement` CHANGE `ordre` `display_order` MEDIUMINT(9) DEFAULT '0' NOT NULL");
  432. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."announcement` ADD `title` TEXT AFTER `id`");
  433. // Set item-properties of announcements and generate a title for the announcement
  434. $sql = "SELECT id,end_date,content FROM `$mysql_base_course".$dbGlu."announcement`";
  435. $res = mysql_query($sql);
  436. while ($obj = mysql_fetch_object($res))
  437. {
  438. $content_parts = explode('<br>',trim($obj->content));
  439. $title = strip_tags($content_parts[0]);
  440. if( strlen(trim($title)) == 0)
  441. {
  442. $title = substr(strip_tags($title),0,50).'...';
  443. }
  444. $sql = "UPDATE `$mysql_base_course".$dbGlu."announcement` SET title = '".mysql_real_escape_string($title)."' WHERE id='".$obj->id."'";
  445. mysql_query($sql);
  446. $sql = "INSERT INTO `$mysql_base_course".$dbGlu."item_property` SET ";
  447. $sql .= " tool = '".TOOL_ANNOUNCEMENT."', ";
  448. $sql .= " insert_date = '".$obj->end_date." 00:00:00', ";
  449. $sql .= " lastedit_date = '".$obj->end_date." 00:00:00', ";
  450. $sql .= " ref = '".$obj->id."', ";
  451. $sql .= " lastedit_type = 'AnnouncementAdded', ";
  452. $sql .= " to_group_id = '0' ";
  453. mysql_query($sql);
  454. }
  455. /*
  456. -----------------------------------------------------------
  457. Update the bb_whosonline table
  458. -----------------------------------------------------------
  459. */
  460. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."bb_whosonline` CHANGE `date` `online_date` VARCHAR(255) DEFAULT NULL");
  461. /*
  462. -----------------------------------------------------------
  463. Update the calendar_event table
  464. -----------------------------------------------------------
  465. */
  466. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."calendar_event` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  467. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."calendar_event` CHANGE `titre` `title` VARCHAR(200) NOT NULL");
  468. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."calendar_event` CHANGE `contenu` `content` TEXT DEFAULT NULL");
  469. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."calendar_event` CHANGE `day` `start_date` DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL");
  470. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."calendar_event` DROP `hour`");
  471. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."calendar_event` DROP `lasting`");
  472. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."calendar_event` ADD `end_date` DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL");
  473. // Set item-properties of calendar events
  474. $sql = "SELECT id,start_date FROM `$mysql_base_course".$dbGlu."calendar_event`";
  475. $res = mysql_query($sql);
  476. while ($obj = mysql_fetch_object($res))
  477. {
  478. $sql = "INSERT INTO `$mysql_base_course".$dbGlu."item_property` SET ";
  479. $sql .= " tool = '".TOOL_CALENDAR_EVENT."', ";
  480. $sql .= " insert_date = NOW(), ";
  481. $sql .= " lastedit_date = NOW(), ";
  482. $sql .= " ref = '".$obj->id."', ";
  483. $sql .= " lastedit_type = 'AgendaAdded', ";
  484. $sql .= " to_group_id = '0' ";
  485. mysql_query($sql);
  486. }
  487. /*
  488. -----------------------------------------------------------
  489. Update the course_description table
  490. -----------------------------------------------------------
  491. */
  492. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."course_description` CHANGE `id` `id` TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT");
  493. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."course_description` DROP `upDate`");
  494. /*
  495. -----------------------------------------------------------
  496. Update the document table
  497. -----------------------------------------------------------
  498. */
  499. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."document` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  500. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."document` CHANGE `comment` `comment` TEXT DEFAULT NULL");
  501. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."document` ADD `title` VARCHAR(255) AFTER `comment`");
  502. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."document` ADD `size` INT(16) NOT NULL");
  503. // @note: Item properties of documents are set in update_files.inc.php
  504. /*
  505. -----------------------------------------------------------
  506. Update the dropbox tables
  507. -----------------------------------------------------------
  508. */
  509. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."dropbox_file` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  510. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."dropbox_file` CHANGE `uploaderId` `uploader_id` INT(10) UNSIGNED DEFAULT '0' NOT NULL");
  511. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."dropbox_file` CHANGE `filesize` `filesize` INT(10) UNSIGNED DEFAULT '0' NOT NULL");
  512. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."dropbox_file` CHANGE `uploadDate` `upload_date` DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL");
  513. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."dropbox_file` CHANGE `lastUploadDate` `last_upload_date` DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL");
  514. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."dropbox_person` CHANGE `fileId` `file_id` INT(10) UNSIGNED DEFAULT '0' NOT NULL");
  515. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."dropbox_person` CHANGE `personId` `user_id` INT UNSIGNED DEFAULT '0' NOT NULL");
  516. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."dropbox_post` CHANGE `fileId` `file_id` INT(10) UNSIGNED DEFAULT '0' NOT NULL");
  517. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."dropbox_post` CHANGE `recipientId` `dest_user_id` INT UNSIGNED DEFAULT '0' NOT NULL");
  518. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."dropbox_post` ADD `feedback_date` DATETIME NOT NULL");
  519. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."dropbox_post` ADD `feedback` TEXT");
  520. // Set item-properties of dropbox files
  521. $sql = "SELECT * FROM `$mysql_base_course".$dbGlu."dropbox_file` f, `$mysql_base_course".$dbGlu."dropbox_post` p WHERE f.id = p.file_id";
  522. $res = mysql_query($sql);
  523. while ($obj = mysql_fetch_object($res))
  524. {
  525. $sql = "INSERT INTO `$mysql_base_course".$dbGlu."item_property` SET ";
  526. $sql .= " tool = '".TOOL_DROPBOX."', ";
  527. $sql .= " insert_date = '".$obj->upload_date."', ";
  528. $sql .= " lastedit_date = '".$obj->last_upload_date."', ";
  529. $sql .= " ref = '".$obj->id."', ";
  530. $sql .= " lastedit_type = 'DropboxFileAdded', ";
  531. $sql .= " to_group_id = '0', ";
  532. $sql .= " to_user_id = '".$obj->dest_user_id."', ";
  533. $sql .= " insert_user_id = '".$obj->uploader_id."'";
  534. mysql_query($sql);
  535. }
  536. /*
  537. -----------------------------------------------------------
  538. Update the forum tables (functions are at the end of this file)
  539. -----------------------------------------------------------
  540. */
  541. // Define the phpbb tables
  542. $phpbb_categories="`".$_course["dbNameGlu"]."bb_categories"."`";
  543. $phpbb_forums="`".$_course["dbNameGlu"]."bb_forums"."`";
  544. $phpbb_threads="`".$_course["dbNameGlu"]."bb_topics"."`";
  545. $phpbb_posts="`".$_course["dbNameGlu"]."bb_posts"."`";
  546. $phpbb_poststext="`".$_course["dbNameGlu"]."bb_posts_text"."`";
  547. $group_info="`".$_course["dbNameGlu"]."group_info"."`";
  548. // get all the added resources
  549. $added_resources=get_added_resources();
  550. // ************* MIGRATE FORUMCATEGORIES *************
  551. $sql_phpbb_categories="SELECT * FROM $phpbb_categories";
  552. $result_phpbb_categories=api_sql_query($sql_phpbb_categories, __LINE__, __FILE__);
  553. while ($row_phpbb_categories=mysql_fetch_array($result_phpbb_categories))
  554. {
  555. $values['forum_category_title']=$row_phpbb_categories['cat_title'];
  556. $return=store_forumcategory($values);
  557. }
  558. // ************* MIGRATE FORUMS *************
  559. $sql_phpbb_forums="SELECT forums.*, forumscat.cat_title, group_info.id as group_id , group_info.forum_state
  560. FROM $phpbb_forums forums, $phpbb_categories forumscat
  561. LEFT JOIN $group_info group_info
  562. ON forums.forum_id=group_info.forum_id
  563. WHERE forums.cat_id=forumscat.cat_id";
  564. $result_phpbb_forums=api_sql_query($sql_phpbb_forums,__LINE__,__FILE__);
  565. while ($row_phpbb_forums=mysql_fetch_array($result_phpbb_forums))
  566. {
  567. $values['forum_title']=$row_phpbb_forums['forum_name'];
  568. $values['forum_comment']=$row_phpbb_forums['forum_desc'];
  569. $values['forum_category']=get_forumcategory_id_by_name($row_phpbb_forums['cat_title']);
  570. $values['allow_anonymous_group']['allow_anonymous']=0;
  571. $values['students_can_edit_group']['students_can_edit']=0;
  572. $values['approval_direct_group']['approval_direct']=0;
  573. $values['allow_attachments_group']['allow_attachments']=1;
  574. $values['allow_new_threads_group']['allow_new_threads']=1;
  575. $values['default_view_type_group']['default_view_type']='flat';
  576. if (is_null($row_phpbb_forums['group_id']))
  577. {
  578. $groupid_of_groupforum=0;
  579. }
  580. else
  581. {
  582. $groupid_of_groupforum=$row_phpbb_forums['group_id'];
  583. }
  584. $values['group_forum']=$groupid_of_groupforum;
  585. if ($row_phpbb_forums['forum_state']=='2')
  586. {
  587. $group_forum_status='private';
  588. }
  589. else
  590. {
  591. $group_forum_status='public';
  592. }
  593. $values['public_private_group_forum_group']['public_private_group_forum']=$group_forum_status;
  594. //echo get_forumcategory_id_by_name($row_phpbb_forums['forum_name']);
  595. $return=store_forum($values);
  596. // ************* MIGRATE THREADS *************
  597. // We now migrate all the threads in this forum
  598. $threads_posts_counter=migrate_threads_of_forum($row_phpbb_forums['forum_id'], $return['id']);
  599. }
  600. /*
  601. -----------------------------------------------------------
  602. Update the group tables
  603. -----------------------------------------------------------
  604. */
  605. mysql_query("CREATE TABLE `$mysql_base_course".$dbGlu."group_category` (
  606. `id` int(10) unsigned NOT NULL auto_increment,
  607. `title` varchar(255) NOT NULL default '',
  608. `description` text NOT NULL,
  609. `forum_state` tinyint(3) unsigned NOT NULL default '1',
  610. `doc_state` tinyint(3) unsigned NOT NULL default '1',
  611. `max_student` smallint(5) unsigned NOT NULL default '8',
  612. `self_reg_allowed` enum('0','1') NOT NULL default '0',
  613. `self_unreg_allowed` enum('0','1') NOT NULL default '0',
  614. `groups_per_user` smallint(5) unsigned NOT NULL default '0',
  615. `display_order` smallint(5) unsigned NOT NULL default '0',
  616. PRIMARY KEY (`id`)
  617. ) TYPE=MyISAM");
  618. // Get the group-properties from old portal
  619. $sql = "SELECT * FROM `$mysql_base_course".$dbGlu."group_property`";
  620. $res = mysql_query($sql);
  621. $group_properties = mysql_fetch_array($res,MYSQL_ASSOC);
  622. mysql_query("DROP TABLE `$mysql_base_course".$dbGlu."group_property`");
  623. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_team` RENAME `".$prefix."group_info`");
  624. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_info` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  625. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_info` CHANGE `tutor` `tutor_id` MEDIUMINT(8) UNSIGNED DEFAULT NULL");
  626. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_info` CHANGE `forumId` `forum_id` INT(10) UNSIGNED DEFAULT NULL");
  627. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_info` CHANGE `maxStudent` `max_student` SMALLINT(5) UNSIGNED DEFAULT '8' NOT NULL");
  628. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_info` CHANGE `secretDirectory` `secret_directory` VARCHAR(200) DEFAULT NULL");
  629. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_info` ADD `self_registration_allowed` ENUM('0', '1') DEFAULT '0' NOT NULL");
  630. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_info` ADD `self_unregistration_allowed` ENUM('0', '1') DEFAULT '0' NOT NULL");
  631. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_info` ADD `category_id` INT(10) UNSIGNED NOT NULL AFTER `name`");
  632. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_info` ADD `forum_state` ENUM('0', '1', '2') DEFAULT '0' NOT NULL AFTER `tutor_id`");
  633. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_info` ADD `doc_state` ENUM('0', '1', '2') DEFAULT '0' NOT NULL AFTER `max_student`");
  634. // Update group-properties (doc_state = always private, forum_state ~ old group properties, category_id = default category)
  635. $forum_state = ($group_properties['private']) == '0' ? '1' : '2';
  636. mysql_query("UPDATE `$mysql_base_course".$dbGlu."group_info` SET category_id='2', doc_state='2', forum_state = '".$forum_state."', secret_directory = CONCAT('/',secret_directory)");
  637. mysql_query("UPDATE `$mysql_base_course".$dbGlu."group_info` SET tutor_id='0' WHERE tutor_id IS NULL");
  638. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_rel_team_user` RENAME `".$prefix."group_rel_user`");
  639. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_rel_user` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  640. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_rel_user` CHANGE `user` `user_id` INT UNSIGNED DEFAULT '0' NOT NULL");
  641. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_rel_user` CHANGE `team` `group_id` INT(10) UNSIGNED DEFAULT '0' NOT NULL");
  642. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."group_rel_user` CHANGE `role` `role` CHAR(50) NOT NULL");
  643. mysql_query("INSERT INTO `$mysql_base_course".$dbGlu."group_category` (`id`,`title`,`groups_per_user`) VALUES ('2','".get_lang('DefaultGroupCategory')."','".$group_properties['nbCoursPerUser']."')");
  644. /*
  645. -----------------------------------------------------------
  646. Update the learnpath tables
  647. -----------------------------------------------------------
  648. */
  649. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_chapters` RENAME `".$prefix."learnpath_chapter`");
  650. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_chapter` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  651. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_chapter` CHANGE `learnpath_id` `learnpath_id` INT(10) UNSIGNED DEFAULT NULL");
  652. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_chapter` CHANGE `ordre` `display_order` MEDIUMINT(8) UNSIGNED DEFAULT '0' NOT NULL");
  653. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_chapter` ADD `parent_chapter_id` INT UNSIGNED DEFAULT 0 NOT NULL AFTER `chapter_description`");
  654. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_items` RENAME `".$prefix."learnpath_item`");
  655. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_item` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  656. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_item` CHANGE `chapter` `chapter_id` INT(10) UNSIGNED DEFAULT NULL");
  657. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_item` CHANGE `item_id` `item_id` INT(10) UNSIGNED DEFAULT NULL");
  658. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_item` CHANGE `ordre` `display_order` SMALLINT(6) DEFAULT NULL");
  659. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_item` CHANGE `prereq` `prereq_id` INT(10) UNSIGNED DEFAULT NULL");
  660. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_item` ADD `prereq_completion_limit` VARCHAR(10) DEFAULT NULL");
  661. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_main` CHANGE `learnpath_id` `learnpath_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  662. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_users` RENAME `".$prefix."learnpath_user`");
  663. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_user` CHANGE `user_id` `user_id` INT UNSIGNED DEFAULT '0' NOT NULL");
  664. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_user` CHANGE `learnpath_id` `learnpath_id` INT(10) UNSIGNED DEFAULT '0' NOT NULL");
  665. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_user` CHANGE `learnpath_item_id` `learnpath_item_id` INT(10) UNSIGNED DEFAULT NULL");
  666. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."learnpath_user` CHANGE `score` `score` SMALLINT(6) DEFAULT NULL");
  667. /*
  668. -----------------------------------------------------------
  669. Update the link tables
  670. -----------------------------------------------------------
  671. */
  672. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."link` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  673. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."link` CHANGE `url` `url` TEXT NOT NULL");
  674. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."link` CHANGE `titre` `title` VARCHAR(150) DEFAULT NULL");
  675. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."link` CHANGE `category` `category_id` SMALLINT(5) UNSIGNED DEFAULT NULL");
  676. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."link` CHANGE `ordre` `display_order` SMALLINT(5) UNSIGNED DEFAULT '0' NOT NULL");
  677. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."link` ADD `on_homepage` ENUM('0', '1') DEFAULT '0' NOT NULL");
  678. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."link_categories` RENAME `".$prefix."link_category`");
  679. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."link_category` CHANGE `id` `id` SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT");
  680. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."link_category` CHANGE `categoryname` `category_title` VARCHAR(255) NOT NULL");
  681. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."link_category` CHANGE `ordre` `display_order` MEDIUMINT(8) UNSIGNED DEFAULT '0' NOT NULL");
  682. // Set item-properties of links
  683. $sql = "SELECT id FROM `$mysql_base_course".$dbGlu."link`";
  684. $res = mysql_query($sql);
  685. while ($obj = mysql_fetch_object($res))
  686. {
  687. $sql = "INSERT INTO `$mysql_base_course".$dbGlu."item_property` SET ";
  688. $sql .= " tool = '".TOOL_LINK."', ";
  689. $sql .= " insert_date = NOW(), ";
  690. $sql .= " lastedit_date = NOW(), ";
  691. $sql .= " ref = '".$obj->id."', ";
  692. $sql .= " lastedit_type = 'LinkAdded', ";
  693. $sql .= " to_group_id = '0' ";
  694. mysql_query($sql);
  695. }
  696. // move all the links on the course homepage to the links tool
  697. // step 1: count the max display order of the 0 category_id
  698. $sql="SELECT * FROM `$mysql_base_course".$dbGlu."link` WHERE category_id='0' ORDER BY display_order DESC";
  699. $result2=mysql_query($sql);
  700. $row=mysql_fetch_array($result2);
  701. $maxsort=$row['display_order'];
  702. // step 2: select all the links that were added to the course homepage
  703. $sql="SELECT * FROM `$mysql_base_course".$dbGlu."tool` WHERE link LIKE 'http://%'";
  704. $result2 = mysql_query($sql);
  705. while ($row=mysql_fetch_array($result2))
  706. {
  707. $maxsort++;
  708. // step 3: for each link on homepage: add to the links table
  709. $sqlinsert="INSERT INTO `$mysql_base_course".$dbGlu."link` (url, title, category_id, display_order, on_homepage) VALUES('".$row['link']."','".$row['name']."','0','".$maxsort."','1')";
  710. $resultinsert=mysql_query($sqlinsert);
  711. $insertid=mysql_insert_id();
  712. // step 4: for each link on homepage: add the link in the item_property table
  713. $sql_item_property = "INSERT INTO `$mysql_base_course".$dbGlu."item_property` SET ";
  714. $sql_item_property .= " tool = '".TOOL_LINK."', ";
  715. $sql_item_property .= " ref = '".$insertid."', ";
  716. $sql_item_property .= " lastedit_type = 'LinkAdded', ";
  717. $sql_item_property .= " to_group_id = '0' ";
  718. api_sql_query($sql_item_property);
  719. // step 5: for each link on homepage: delete the link in the tool table.
  720. $sqldelete="DELETE FROM `$mysql_base_course".$dbGlu."tool` WHERE id='".$row['id']."'";
  721. $resultdelete=mysql_query($sqldelete);
  722. }
  723. /*
  724. -----------------------------------------------------------
  725. Update the quiz tables
  726. -----------------------------------------------------------
  727. */
  728. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."quiz_rel_test_question` RENAME `".$prefix."quiz_rel_question`");
  729. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."quiz_test` RENAME `".$prefix."quiz`");
  730. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."quiz` CHANGE `titre` `title` VARCHAR(200) NOT NULL");
  731. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."quiz` CHANGE `description` `description` TEXT");
  732. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."quiz` CHANGE `sound` `sound` VARCHAR(50)");
  733. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."quiz` CHANGE `type` `type` TINYINT(3) UNSIGNED DEFAULT '1' NOT NULL");
  734. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."quiz` CHANGE `active` `active` ENUM('0', '1') DEFAULT '0' NOT NULL");
  735. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."quiz_answer` CHANGE `reponse` `answer` TEXT NOT NULL");
  736. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."quiz_answer` CHANGE `ponderation` `ponderation` SMALLINT(6) DEFAULT NULL");
  737. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."quiz_answer` CHANGE `r_position` `position` MEDIUMINT(8) UNSIGNED DEFAULT '1' NOT NULL");
  738. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."quiz_question` CHANGE `description` `description` TEXT");
  739. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."quiz_question` CHANGE `q_position` `position` MEDIUMINT(8) UNSIGNED DEFAULT '1' NOT NULL");
  740. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."quiz_question` CHANGE `picture` `picture` VARCHAR(50)");
  741. /*
  742. -----------------------------------------------------------
  743. Update the resource linker table
  744. -----------------------------------------------------------
  745. */
  746. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."added_resources` RENAME `".$prefix."resource`");
  747. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."resource` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  748. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."resource` CHANGE `source_id` `source_id` INT(10) UNSIGNED DEFAULT NULL");
  749. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."resource` CHANGE `resource_id` `resource_id` INT(10) UNSIGNED DEFAULT NULL");
  750. /*
  751. -----------------------------------------------------------
  752. Update the scormdocument table
  753. -----------------------------------------------------------
  754. */
  755. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."scormdocument` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  756. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."scormdocument` ADD `name` VARCHAR(100)");
  757. /*
  758. -----------------------------------------------------------
  759. Update the student_publication table
  760. -----------------------------------------------------------
  761. */
  762. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."assignment_doc` RENAME `".$prefix."student_publication`");
  763. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."student_publication` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  764. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."student_publication` CHANGE `titre` `title` VARCHAR(200) DEFAULT NULL");
  765. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."student_publication` CHANGE `auteurs` `author` VARCHAR(200) DEFAULT NULL");
  766. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."student_publication` CHANGE `active` `active` TINYINT(4) DEFAULT NULL");
  767. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."student_publication` CHANGE `accepted` `accepted` TINYINT(4) DEFAULT '0'");
  768. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."student_publication` CHANGE `date` `sent_date` DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL");
  769. /*
  770. -----------------------------------------------------------
  771. Update the tool introduction table
  772. -----------------------------------------------------------
  773. */
  774. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."tool_intro` CHANGE `id` `id` VARCHAR(50) NOT NULL");
  775. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."tool_intro` CHANGE `texte_intro` `intro_text` TEXT NOT NULL");
  776. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool_intro` SET id='".TOOL_COURSE_HOMEPAGE."' WHERE id = '1'");
  777. /*
  778. -----------------------------------------------------------
  779. Update the user information tables
  780. -----------------------------------------------------------
  781. */
  782. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."userinfo_content` CHANGE `user_id` `user_id` INT(10) UNSIGNED DEFAULT '0' NOT NULL");
  783. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."userinfo_content` CHANGE `def_id` `definition_id` INT(10) UNSIGNED DEFAULT '0' NOT NULL");
  784. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."userinfo_content` CHANGE `ed_ip` `editor_ip` VARCHAR(39) DEFAULT NULL");
  785. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."userinfo_content` CHANGE `ed_date` `edition_time` DATETIME DEFAULT NULL");
  786. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."userinfo_content` CHANGE `content` `content` TEXT NOT NULL");
  787. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."userinfo_def` CHANGE `nbLine` `line_count` TINYINT(3) UNSIGNED DEFAULT '5' NOT NULL");
  788. /*
  789. -----------------------------------------------------------
  790. Update the tool table
  791. -----------------------------------------------------------
  792. */
  793. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."tool_list` RENAME `".$prefix."tool`");
  794. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."tool` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT");
  795. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."tool` CHANGE `rubrique` `name` VARCHAR(100) NOT NULL");
  796. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."tool` CHANGE `lien` `link` VARCHAR(255) NOT NULL");
  797. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."tool` CHANGE `visible` `visibility` TINYINT(3) UNSIGNED DEFAULT '0'");
  798. mysql_query("ALTER TABLE `$mysql_base_course".$dbGlu."tool` CHANGE `addedTool` `added_tool` ENUM('0', '1') DEFAULT '0'");
  799. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_COURSE_DESCRIPTION."' WHERE link LIKE 'course_description/%'");
  800. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_CALENDAR_EVENT."' WHERE link LIKE 'calendar/%'");
  801. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_DOCUMENT."' WHERE link LIKE 'document/%'");
  802. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_ANNOUNCEMENT."' WHERE link LIKE 'announcements/%'");
  803. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_BB_FORUM."' WHERE link LIKE 'phpbb/%'");
  804. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_LINK."' WHERE link = 'link/link.php'");
  805. mysql_query("Update `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_DROPBOX."' WHERE link LIKE 'dropbox/%'");
  806. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_QUIZ."' WHERE link LIKE 'exercice/%'");
  807. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_USER."' WHERE link LIKE 'user/%'");
  808. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_GROUP."' WHERE link LIKE 'group/%'");
  809. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_CHAT."' WHERE link LIKE 'chat/%'");
  810. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_CONFERENCE."' WHERE link LIKE 'online/%'");
  811. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_STUDENTPUBLICATION."' WHERE link LIKE 'work/%'");
  812. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_TRACKING."' WHERE link LIKE 'tracking/%'");
  813. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_COURSE_SETTING."' WHERE link LIKE 'course_info/%'");
  814. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_LEARNPATH."' WHERE link LIKE 'scorm/%'");
  815. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET name='".TOOL_HOMEPAGE_LINK."', link='link/link.php?action=addlink' WHERE link LIKE 'external_module/%'");
  816. //mysql_query("INSERT INTO `$mysql_base_course".$dbGlu."tool` (`id`, `name`, `link`, `image`, `visibility`, `admin`, `address`, `added_tool`, `target`) VALUES ('', '".TOOL_BACKUP."', 'coursecopy/backup.php', 'backup.gif', '0', '1', '', '0', '_self')");
  817. mysql_query("INSERT INTO `$mysql_base_course".$dbGlu."tool` (`id`, `name`, `link`, `image`, `visibility`, `admin`, `address`, `added_tool`, `target`) VALUES ('', '".TOOL_COPY_COURSE_CONTENT."', 'coursecopy/copy_course.php', 'copy.gif', '0', '1', '', '0', '_self')");
  818. //mysql_query("INSERT INTO `$mysql_base_course".$dbGlu."tool` (`id`, `name`, `link`, `image`, `visibility`, `admin`, `address`, `added_tool`, `target`) VALUES ('', '".TOOL_RECYCLE_COURSE."', 'coursecopy/recycle_course.php', 'recycle.gif', '0', '1', '', '0', '_self')");
  819. mysql_query("UPDATE `$mysql_base_course".$dbGlu."tool` SET `added_tool` = '0' WHERE `added_tool` = ''");
  820. $i ++;
  821. }
  822. else
  823. {
  824. $nbr_courses --;
  825. }
  826. }
  827. }
  828. }
  829. else
  830. {
  831. echo 'You are not allowed here !';
  832. }
  833. /**
  834. * This function stores the forum category in the database. The new category is added to the end.
  835. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  836. */
  837. function store_forumcategory($values)
  838. {
  839. global $table_categories;
  840. global $_course;
  841. global $_uid;
  842. // find the max cat_order. The new forum category is added at the end => max cat_order + &
  843. $sql="SELECT MAX(cat_order) as sort_max FROM ".mysql_real_escape_string($table_categories);
  844. $result=api_sql_query($sql);
  845. $row=mysql_fetch_array($result);
  846. $new_max=$row['sort_max']+1;
  847. $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)."')";
  848. api_sql_query($sql);
  849. $last_id=mysql_insert_id();
  850. api_item_property_update($_course, TOOL_FORUM_CATEGORY, $last_id,"ForumCategoryAdded", $_uid);
  851. return array('id'=>$last_id,'title'=>$values['forum_category_title']) ;
  852. }
  853. /**
  854. * This function stores the forum in the database. The new forum is added to the end.
  855. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  856. */
  857. function store_forum($values)
  858. {
  859. global $table_forums;
  860. global $_course;
  861. global $_uid;
  862. // find the max forum_order for the given category. The new forum is added at the end => max cat_order + &
  863. $sql="SELECT MAX(forum_order) as sort_max FROM ".$table_forums." WHERE forum_category=".mysql_real_escape_string($values['forum_category']);
  864. $result=api_sql_query($sql);
  865. $row=mysql_fetch_array($result);
  866. $new_max=$row['sort_max']+1;
  867. $sql="INSERT INTO ".$table_forums."
  868. (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)
  869. VALUES ('".mysql_real_escape_string($values['forum_title'])."',
  870. '".mysql_real_escape_string($values['forum_comment'])."',
  871. '".mysql_real_escape_string($values['forum_category'])."',
  872. '".mysql_real_escape_string($values['allow_anonymous_group']['allow_anonymous'])."',
  873. '".mysql_real_escape_string($values['students_can_edit_group']['students_can_edit'])."',
  874. '".mysql_real_escape_string($values['approval_direct_group']['approval_direct'])."',
  875. '".mysql_real_escape_string($values['allow_attachments_group']['allow_attachments'])."',
  876. '".mysql_real_escape_string($values['allow_new_threads_group']['allow_new_threads'])."',
  877. '".mysql_real_escape_string($values['default_view_type_group']['default_view_type'])."',
  878. '".mysql_real_escape_string($values['group_forum'])."',
  879. '".mysql_real_escape_string($values['public_private_group_forum_group']['public_private_group_forum'])."',
  880. '".mysql_real_escape_string($new_max)."')";
  881. api_sql_query($sql, __LINE__,__FILE__);
  882. $last_id=mysql_insert_id();
  883. api_item_property_update($_course, TOOL_FORUM, $last_id,"ForumCategoryAdded", $_uid);
  884. return array('id'=>$last_id, 'title'=>$values['forum_title']);
  885. }
  886. /**
  887. * This function stores a new thread. This is done through an entry in the forum_thread table AND
  888. * in the forum_post table because. The threads are also stored in the item_property table. (forum posts are not (yet))
  889. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  890. */
  891. function store_thread($values)
  892. {
  893. global $table_threads;
  894. global $table_posts;
  895. global $_uid;
  896. global $_course;
  897. global $current_forum;
  898. // We first store an entry in the forum_thread table because the thread_id is used in the forum_post table
  899. $sql="INSERT INTO $table_threads (thread_title, forum_id, thread_poster_id, thread_poster_name, thread_views, thread_date, thread_sticky)
  900. VALUES ('".mysql_real_escape_string($values['post_title'])."',
  901. '".mysql_real_escape_string($values['forum_id'])."',
  902. '".mysql_real_escape_string($values['user_id'])."',
  903. '".mysql_real_escape_string($values['poster_name'])."',
  904. '".mysql_real_escape_string($values['topic_views'])."',
  905. '".mysql_real_escape_string($values['post_date'])."',
  906. '".mysql_real_escape_string($values['thread_sticky'])."')";
  907. $result=api_sql_query($sql, __LINE__, __FILE__);
  908. $last_thread_id=mysql_insert_id();
  909. api_item_property_update($_course, TOOL_FORUM_THREAD, $last_thread_id,"ForumThreadAdded", $_uid);
  910. // if the forum properties tell that the posts have to be approved we have to put the whole thread invisible
  911. // because otherwise the students will see the thread and not the post in the thread.
  912. // we also have to change $visible because the post itself has to be visible in this case (otherwise the teacher would have
  913. // to make the thread visible AND the post
  914. if ($values['visible']==0)
  915. {
  916. api_item_property_update($_course, TOOL_FORUM_THREAD, $last_thread_id,"invisible", $_uid);
  917. $visible=1;
  918. }
  919. return $last_thread_id;
  920. }
  921. /**
  922. * This function migrates the threads of a given phpbb forum to a new forum of the new forum tool
  923. * @param $phpbb_forum_id the forum_id of the old (phpbb) forum
  924. * @param $new_forum_id the forum_id in the new forum
  925. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  926. */
  927. function migrate_threads_of_forum($phpbb_forum_id, $new_forum_id)
  928. {
  929. global $phpbb_threads;
  930. global $table_forums;
  931. $table_users = Database :: get_main_table(MAIN_USER_TABLE);
  932. $sql_phpbb_threads="SELECT forum.*, users.user_id
  933. FROM $phpbb_threads forum, $table_users users
  934. WHERE forum_id='".mysql_real_escape_string($phpbb_forum_id)."'
  935. AND forum.nom=users.lastname AND forum.prenom=users.firstname
  936. ";
  937. $result_phpbb_threads=api_sql_query($sql_phpbb_threads);
  938. $threads_counter=0;
  939. while ($row_phpbb_threads=mysql_fetch_array($result_phpbb_threads))
  940. {
  941. $values['post_title']=$row_phpbb_threads['topic_title'];
  942. $values['forum_id']=$new_forum_id;
  943. $values['user_id']=$row_phpbb_threads['user_id'];
  944. $values['poster_name']=0;
  945. $values['topic_views']=$row_phpbb_threads['topic_views'];
  946. $values['post_date']=$row_phpbb_threads['topic_time'];
  947. $values['thread_sticky']=0;
  948. $values['visible']=$row_phpbb_threads['visible'];
  949. //my_print_r($values);
  950. $new_forum_thread_id=store_thread($values);
  951. // now we migrate the posts of the given thread
  952. $posts_counter=$posts_counter+migrate_posts_of_thread($row_phpbb_threads['topic_id'], $new_forum_thread_id, $new_forum_id);
  953. $threads_counter++;
  954. }
  955. // Now we update the forum_forum table with the total number of posts for the given forum.
  956. $sql="UPDATE $table_forums
  957. SET forum_posts='".mysql_real_escape_string($posts_counter)."',
  958. forum_threads='".mysql_real_escape_string($threads_counter)."'
  959. WHERE forum_id='".mysql_real_escape_string($new_forum_id)."'";
  960. //echo $sql;
  961. $result=api_sql_query($sql);
  962. return array("threads"=>$threads_counter, "posts"=>$posts_counter);
  963. }
  964. /**
  965. * This function migrates the posts of a given phpbb thread (topic) to a thread in the new forum tool
  966. * @param $phpbb_forum_id the forum_id of the old (phpbb) forum
  967. * @param $new_forum_id the forum_id in the new forum
  968. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  969. */
  970. function migrate_posts_of_thread($phpbb_thread_id, $new_forum_thread_id, $new_forum_id)
  971. {
  972. global $phpbb_posts;
  973. global $phpbb_poststext;
  974. global $table_posts;
  975. global $table_threads;
  976. global $added_resources;
  977. $table_users = Database :: get_main_table(MAIN_USER_TABLE);
  978. $table_added_resources = Database::get_course_table(LINKED_RESOURCES_TABLE);
  979. $post_counter=0;
  980. $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
  981. WHERE posts.post_id=posts_text.post_id
  982. AND posts.nom=users.lastname
  983. AND posts.prenom=users.firstname
  984. AND posts.topic_id='".mysql_real_escape_string($phpbb_thread_id)."'
  985. ";
  986. $result_phpbb_posts=api_sql_query($sql_phpbb_posts);
  987. while($row_phpbb_posts=mysql_fetch_array($result_phpbb_posts))
  988. {
  989. $values=array();
  990. $values['post_title']=$row_phpbb_posts['post_title'];
  991. $values['post_text']=$row_phpbb_posts['post_text'];
  992. $values['thread_id']=$new_forum_thread_id;
  993. $values['forum_id']=$new_forum_id;
  994. $values['user_id']=$row_phpbb_posts['user_id'];
  995. $values['post_date']=$row_phpbb_posts['post_time'];
  996. $values['post_notification']=$row_phpbb_posts['topic_notify'];
  997. $values['post_parent_id']=0;
  998. $values['visible']=1;
  999. // We first store an entry in the forum_post table
  1000. $sql="INSERT INTO $table_posts (post_title, post_text, thread_id, forum_id, poster_id, post_date, post_notification, post_parent_id, visible)
  1001. VALUES ('".mysql_real_escape_string($values['post_title'])."',
  1002. '".mysql_real_escape_string($values['post_text'])."',
  1003. '".mysql_real_escape_string($values['thread_id'])."',
  1004. '".mysql_real_escape_string($values['forum_id'])."',
  1005. '".mysql_real_escape_string($values['user_id'])."',
  1006. '".mysql_real_escape_string($values['post_date'])."',
  1007. '".mysql_real_escape_string($values['post_notification'])."',
  1008. '".mysql_real_escape_string($values['post_parent_id'])."',
  1009. '".mysql_real_escape_string($values['visible'])."')";
  1010. $result=api_sql_query($sql, __LINE__, __FILE__);
  1011. $post_counter++;
  1012. $last_post_id=mysql_insert_id();
  1013. // We check if there added resources and if so we update them
  1014. if (in_array($row_phpbb_posts['post_id'],$added_resources))
  1015. {
  1016. $sql_update_added_resource="UPDATE $table_added_resources
  1017. SET source_type='forum_post', source_id='".mysql_real_escape_string($last_post_id)."'
  1018. WHERE source_type='".mysql_real_escape_string(TOOL_BB_POST)."' AND source_id='".mysql_real_escape_string($row_phpbb_posts['post_id'])."'";
  1019. echo $sql_update_added_resource;
  1020. $result=api_sql_query($sql_update_added_resource, __LINE__, __FILE__);
  1021. }
  1022. }
  1023. // update the thread_last_post of the post table AND the
  1024. $sql="UPDATE $table_threads SET thread_last_post='".mysql_real_escape_string($last_post_id)."',
  1025. thread_replies='".mysql_real_escape_string($post_counter-1)."'
  1026. WHERE thread_id='".mysql_real_escape_string($new_forum_thread_id)."'";
  1027. //echo $sql;
  1028. $result=api_sql_query($sql, __LINE__, __FILE__);
  1029. //echo $sql;
  1030. return $post_counter;
  1031. }
  1032. /**
  1033. * This function gets all the added resources for phpbb forum posts
  1034. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1035. */
  1036. function get_added_resources()
  1037. {
  1038. $table_added_resources = Database::get_course_table(LINKED_RESOURCES_TABLE);
  1039. $return_array=array();
  1040. // TODO: now we also migrate the added resources.
  1041. $sql_added_resources="SELECT * FROM $table_added_resources WHERE source_type='".mysql_real_escape_string(TOOL_BB_POST)."'";
  1042. $result=api_sql_query($sql_added_resources);
  1043. while ($row=mysql_fetch_array($result))
  1044. {
  1045. $return_array[]=$row['source_id'];
  1046. }
  1047. return $return_array;
  1048. }
  1049. /**
  1050. * This function gets the forum category information based on the name
  1051. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  1052. */
  1053. function get_forumcategory_id_by_name($forum_category_name)
  1054. {
  1055. global $table_categories;
  1056. $sql="SELECT cat_id FROM $table_categories WHERE cat_title='".mysql_real_escape_string($forum_category_name)."'";
  1057. //echo $sql;
  1058. $result=api_sql_query($sql,__LINE__,__FILE__);
  1059. $row=mysql_fetch_array($result);
  1060. //echo $row['cat_id'];
  1061. return $row['cat_id'];
  1062. }
  1063. ?>