Upgrade Notes

*********************
** IMathAS 1.8     **
*********************

All database changes are now in upgrade.php.  Run that file to apply updates
to the database.

SimpleLTI has been deprecated and replaced with BasicLTI.  If you have 
$enablesimplelti in your config.php, change it to enablebasiclti.

If you do not have either currently in your config.php and want to allow 
imathas to act as a BasicLTI producer, add $enablebasiclti = true to config.php

*********************
** IMathAS 1.7     **
*********************

*** Database Changes ***

All database changes are now in upgrade.php.  Run that file to apply updates
to the database.  

*********************
** IMathAS 1.6     **
*********************
*** config.php changes - Reference config.php.dist for changes. ***
$freetypeinstalled no longer needed - autodetected
Added $enablesimplelti
Added $mathchaturl

*** Loginpage Changes ***
Reference loginpage.php.dist for changes. 
	
*** Database Changes ***
ALTER TABLE `imas_msgs` ADD `parent` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0' ,
ADD `baseid` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0' ;
ALTER TABLE `imas_msgs` ADD INDEX ( `baseid` ) ;

CREATE TABLE `mc_sessions` (
`userid` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`sessionid` VARCHAR( 32 ) NOT NULL ,
`name` VARCHAR( 254 ) NOT NULL ,
`room` INT( 10 ) NOT NULL ,
`lastping` INT( 10 ) UNSIGNED NOT NULL,
`mathdisp` TINYINT( 1 ) NOT NULL ,
`graphdisp` TINYINT( 1 ) NOT NULL,
INDEX ( `sessionid` ), INDEX( `room` ), INDEX( `lastping` )
) TYPE = innodb;

CREATE TABLE `mc_msgs` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`userid` INT( 10 ) UNSIGNED NOT NULL ,
`msg` TEXT NOT NULL ,
`time` INT( 10 ) UNSIGNED NOT NULL ,
INDEX ( `userid` ), INDEX ( `time` )
) TYPE = innodb;

ALTER TABLE `imas_courses` ADD `chatset` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';

ALTER TABLE `imas_assessments` ADD `ltisecret` VARCHAR( 10 ) NOT NULL ;
ALTER TABLE `imas_courses` ADD `ltisecret` VARCHAR( 10 ) NOT NULL ;

CREATE TABLE `imas_ltiusers` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`org` VARCHAR( 32 ) NOT NULL ,
`ltiuserid` VARCHAR( 32 ) NOT NULL ,
`userid` INT( 10 ) UNSIGNED NOT NULL 
) TYPE = innodb;

CREATE TABLE `imas_ltiaccess` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`password` VARCHAR( 32 ) NOT NULL ,
`userid` INT( 10 ) UNSIGNED NOT NULL ,
`itemid` INT( 10 ) UNSIGNED NOT NULL ,
`itemtype` TINYINT( 1 ) UNSIGNED NOT NULL ,
`created` INT( 10 ) UNSIGNED NOT NULL 
) TYPE = innodb;

CREATE TABLE `imas_ltinonces` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`nonce` TEXT NOT NULL ,
`time` INT( 10 ) UNSIGNED NOT NULL 
) TYPE = innodb;

ALTER TABLE `imas_assessments` CHANGE `timelimit` `timelimit` INT( 10 ) NOT NULL DEFAULT '0' ;
ALTER TABLE `imas_assessment_sessions` ADD `reattempting` VARCHAR( 255 ) NOT NULL ;
ALTER TABLE `imas_assessment_sessions` ADD `reviewreattempting` VARCHAR( 255 ) NOT NULL ;

ALTER TABLE `imas_users` ADD `remoteaccess` VARCHAR( 10 ) NOT NULL ;

ALTER TABLE `imas_diags` ADD `forceregen` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_diags` CHANGE `entryformat` `entryformat` CHAR( 3 ) NOT NULL DEFAULT 'C0' ;

ALTER TABLE `imas_students` ADD `gbinstrcomment` TEXT NOT NULL ;

ALTER TABLE `imas_forums` ADD INDEX ( `grpaid` );
ALTER TABLE `imas_forum_posts` ADD INDEX ( `postdate` );

ALTER TABLE `imas_inlinetext` ADD `oncal` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0',
ADD `caltag` CHAR( 1 ) NOT NULL DEFAULT '!';
ALTER TABLE `imas_inlinetext` ADD INDEX ( `oncal` ) ;

ALTER TABLE `imas_linkedtext` ADD `oncal` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0',
ADD `caltag` CHAR( 1 ) NOT NULL DEFAULT '!';
ALTER TABLE `imas_linkedtext` ADD INDEX ( `oncal` ) ;

CREATE TABLE `imas_calitems` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`courseid` INT( 10 ) UNSIGNED NOT NULL ,
`date` INT( 10 ) UNSIGNED NOT NULL ,
`title` VARCHAR( 254 ) NOT NULL ,
`tag` CHAR( 1 ) NOT NULL ,
INDEX ( `courseid` ), INDEX(`date`) 
) TYPE = innodb COMMENT = 'Calendar Items';


ALTER TABLE `imas_courses` ADD `picicons` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';

ALTER TABLE `imas_courses` ADD INDEX ( `name` );
ALTER TABLE `imas_courses` ADD INDEX ( `available` );
ALTER TABLE `imas_assessments` ADD INDEX ( `avail` );
ALTER TABLE `imas_assessments` ADD INDEX ( `reviewdate` ) ;
ALTER TABLE `imas_inlinetext` ADD INDEX ( `avail` ) ;
ALTER TABLE `imas_inlinetext` ADD INDEX ( `startdate` ) ;
ALTER TABLE `imas_inlinetext` ADD INDEX ( `enddate` ) ;
ALTER TABLE `imas_linkedtext` ADD INDEX ( `avail` ) ;
ALTER TABLE `imas_linkedtext` ADD INDEX ( `startdate` );
ALTER TABLE `imas_linkedtext` ADD INDEX ( `enddate` ) ;
ALTER TABLE `imas_forums` ADD INDEX ( `avail` ) ;
ALTER TABLE `imas_forums` ADD INDEX ( `startdate` ) ;
ALTER TABLE `imas_forums` ADD INDEX ( `enddate` ) ;
ALTER TABLE `imas_forums` ADD INDEX ( `replyby` ) ;
ALTER TABLE `imas_forums` ADD INDEX ( `postby` ) ;


*********************
** IMathAS 1.5     **
*********************

*** Database Changes ***

ALTER TABLE `imas_sessions` ADD INDEX ( `time` ) ;
ALTER TABLE `imas_users` ADD INDEX ( `rights` ); 

ALTER TABLE `imas_grades` CHANGE `score` `score` DECIMAL( 6, 1 ) UNSIGNED NULL DEFAULT '0.0';

ALTER TABLE `imas_students` ADD `lastaccess` INT( 10 ) UNSIGNED NOT NULL ;
UPDATE imas_students,imas_users SET imas_students.lastaccess=imas_users.lastaccess WHERE imas_students.userid=imas_users.id;

ALTER TABLE `imas_gbscheme` CHANGE `defgbmode` `defgbmode` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '21' ;
UPDATE `imas_assessments` SET cntingb =3 WHERE deffeedback LIKE 'Practice%';

ALTER TABLE `imas_assessments` ADD `exceptionpenalty` TINYINT( 2 ) NOT NULL DEFAULT '0';

ALTER TABLE `imas_students` ADD `latepass` TINYINT( 2 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_assessments` ADD `allowlate` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1';
ALTER TABLE `imas_courses` ADD `latepasshrs` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '24';

ALTER TABLE `imas_questionset` ADD `ancestors` TEXT NOT NULL ;
ALTER TABLE `imas_gbscheme` ADD `usersort` TINYINT( 1 ) NOT NULL DEFAULT '0';

ALTER TABLE `imas_assessments` ADD `groupmax` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '6';

ALTER TABLE `imas_courses` ADD `theme` VARCHAR( 32 ) NOT NULL DEFAULT 'default.css';

UPDATE imas_courses SET msgset=msgset+1 WHERE msgset>1;

ALTER TABLE `imas_questions` ADD `withdrawn` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';

ALTER TABLE `imas_inlinetext` ADD `avail` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1';
ALTER TABLE `imas_assessments` ADD `avail` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1';
ALTER TABLE `imas_forums` ADD `avail` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1';
ALTER TABLE `imas_linkedtext` ADD `avail` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1';

*** Run PHP code after Database Changes ***
<?php
require("validate.php");
$query = "SELECT id,defgbmode FROM imas_gbscheme";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
while (list($id,$gbmodet) = mysql_fetch_row($result)) {
	$gbmode = 2;
	if (($gbmodet&8)==8) { $gbmode += 1000;}
	if (($gbmodet&16)==16) {$gbmode += 20;}
	if (($gbmodet&4)==4) {$gbmode -= 1;}
	if (($gbmodet&1)==1) {$gbmode += 100;}
	$query = "UPDATE imas_gbscheme SET defgbmode='$gbmode' WHERE id='$id'";
	mysql_query($query) or die("Query failed : " . mysql_error());
}
echo "DONE";
?>

*********************
** IMathAS 1.4     **
*********************

*** Database Changes ***

ALTER TABLE `imas_diags` ADD `entryformat` VARCHAR( 2 ) NOT NULL DEFAULT 'C0';

ALTER TABLE `imas_users` ADD `deflib` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0',
ADD `usedeflib` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';

ALTER TABLE `imas_assessments` ADD `noprint` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_forum_views` ADD `tagged` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';

ALTER TABLE `imas_forum_posts` ADD `points` SMALLINT ( 5 ) NULL ;
ALTER TABLE `imas_forums` ADD `points` SMALLINT( 5 ) NOT NULL DEFAULT '0',
ADD `gbcategory` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0';


*********************
** IMathAS 1.3     **
*********************

*** Database Changes ***

#R56
ALTER TABLE `imas_assessment_sessions` ADD `reviewseeds` TEXT NOT NULL ,
ADD `reviewattempts` TEXT NOT NULL ,
ADD `reviewscores` TEXT NOT NULL ,
ADD `reviewlastanswers` TEXT NOT NULL ;

UPDATE imas_assessment_sessions SET reviewseeds=seeds,reviewattempts=attempts,reviewscores=scores,reviewlastanswers=lastanswers;

#R51
ALTER TABLE `imas_users` ADD `qrightsdef` TINYINT( 1 ) NOT NULL DEFAULT '0';

#R41
ALTER TABLE `imas_questions` ADD `regen` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_questions` ADD `showans` VARCHAR( 1 ) NOT NULL DEFAULT '0';

#R36
ALTER TABLE `imas_assessments` ADD `reqscoreaid` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0',
ADD `reqscore` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '0';

UPDATE imas_assessments SET timelimit = timelimit*60 WHERE timelimit>0;


*********************
** IMathAS 1.2     **
*********************

*** Config.php Changes ***

$installname = "Your install name";
$smallheaderlogo = "Text or image tag";

*** Database Changes ***
Required changes.

ALTER TABLE `imas_assessments` ADD `showcat` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_assessments` ADD `isgroup` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';

ALTER TABLE `imas_assessments` CHANGE `defpenalty` `defpenalty` VARCHAR( 6 ) NOT NULL DEFAULT '0';
ALTER TABLE `imas_questions` CHANGE `penalty` `penalty` VARCHAR( 6 ) NOT NULL DEFAULT '9999';

ALTER TABLE `imas_assessments` ADD `showhints` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1' AFTER `showcat` ;

ALTER TABLE `imas_forums` ADD `grpaid` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_assessment_sessions` ADD `agroupid` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0';

ALTER TABLE `imas_courses` ADD `available` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0',
ADD `lockaid` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0';

ALTER TABLE `imas_assessment_sessions` ADD `feedback` TEXT NOT NULL ;
ALTER TABLE `imas_students` ADD `gbcomment` TEXT NOT NULL ;

ALTER TABLE `imas_grades` ADD `feedback` TEXT NOT NULL ;


*********************
** IMathAS 1.1     **
*********************

*** Database Changes ***
Required changes.

ALTER TABLE `imas_assessments` CHANGE `shuffle` `shuffle` TINYINT( 2 ) UNSIGNED NOT NULL DEFAULT '0';

ALTER TABLE `imas_courses` ADD `blockcnt` INT( 10 ) UNSIGNED NOT NULL DEFAULT '1';

CREATE TABLE `imas_msgs` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`courseid` INT( 10 ) UNSIGNED NOT NULL ,
`title` VARCHAR( 254 ) NOT NULL ,
`message` TEXT NOT NULL ,
`msgto` INT( 10 ) NOT NULL ,
`msgfrom` INT( 10 ) NOT NULL ,
`senddate` INT( 10 ) NOT NULL ,
`isread` TINYINT( 1 ) NOT NULL 
) TYPE = innodb COMMENT = 'Internal messages';

ALTER TABLE `imas_students` ADD `section` VARCHAR( 10 ) NULL ,
ADD `code` INT( 4 ) UNSIGNED NULL ;
ALTER TABLE `imas_forums` ADD `defdisplay` INT( 1 ) UNSIGNED NOT NULL ,
ADD `replyby` INT( 10 ) UNSIGNED NOT NULL DEFAULT '2000000000',
ADD `postby` INT( 10 ) UNSIGNED NOT NULL DEFAULT '2000000000';
ALTER TABLE `imas_forum_posts` ADD `replyby` INT( 10 ) UNSIGNED NULL ;

CREATE TABLE `imas_forum_subscriptions` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`forumid` INT( 10 ) UNSIGNED NOT NULL ,
`userid` INT( 10 ) UNSIGNED NOT NULL ,
INDEX ( `forumid` , `userid` ) 
) TYPE = innodb COMMENT = 'Forum subscriptions';
	
CREATE TABLE `imas_gbscheme` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`courseid` INT( 10 ) UNSIGNED NOT NULL ,
`useweights` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0',
`orderby` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0',
`defaultcat` VARCHAR( 254 ) NOT NULL DEFAULT '0,0,1,0,-1'
) TYPE = innodb COMMENT = 'Gradebook scheme';

ALTER TABLE `imas_assessments` ADD `gbcategory` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0';

CREATE TABLE `imas_gbitems` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`courseid` INT( 10 ) UNSIGNED NOT NULL ,
`name` VARCHAR( 50 ) NOT NULL ,
`points` SMALLINT( 4 ) NOT NULL DEFAULT '0',
`showdate` INT( 10 ) UNSIGNED NOT NULL ,
`gbcategory` INT( 10 ) UNSIGNED NOT NULL ,
INDEX ( `courseid` , `showdate` ) 
) TYPE = innodb COMMENT = 'Gradebook offline items';

CREATE TABLE `imas_grades` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`gbitemid` INT( 10 ) UNSIGNED NOT NULL ,
`userid` INT( 10 ) UNSIGNED NOT NULL ,
`score` DECIMAL( 6, 1 ) UNSIGNED NOT NULL ,
INDEX ( `userid` ) 
) TYPE = innodb COMMENT = 'Offline grades';

CREATE TABLE `imas_gbcats` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 50 ) NOT NULL ,
`courseid` INT( 10 ) UNSIGNED NOT NULL ,
`scale` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '0',
`scaletype` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0',
`chop` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1',
`dropn` TINYINT( 2 ) NOT NULL DEFAULT '0',
`weight` SMALLINT( 4 ) NOT NULL DEFAULT '-1',
INDEX ( `courseid` ) 
) TYPE = innodb COMMENT = 'Gradebook Categories';

ALTER TABLE `imas_assessments` ADD `password` VARCHAR( 15 ) NOT NULL ;

ALTER TABLE `imas_users` ADD `msgnotify` TINYINT( 1 ) NOT NULL DEFAULT '0';

ALTER TABLE `imas_forums` CHANGE `description` `description` TEXT NOT NULL;

ALTER TABLE `imas_courses` ADD `msgset` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_gbscheme` ADD `defgbmode` TINYINT( 2 ) UNSIGNED NOT NULL DEFAULT '0';

ALTER TABLE `imas_assessments` ADD `cntingb` TINYINT( 1 ) NOT NULL DEFAULT '1';
ALTER TABLE `imas_gbitems` ADD `cntingb` TINYINT( 1 ) NOT NULL DEFAULT '1';
ALTER TABLE `imas_courses` ADD `topbar` VARCHAR( 32 ) NOT NULL DEFAULT '|';


UPDATE imas_forums SET replyby=0 WHERE settings=2 OR settings=3;
UPDATE imas_forums SET settings=3 WHERE settings=1;
UPDATE imas_forums SET settings=2 WHERE settings=0;

ALTER TABLE `imas_msgs` ADD INDEX ( `msgto` );
ALTER TABLE `imas_msgs` ADD INDEX ( `isread` );
ALTER TABLE `imas_exceptions` ADD INDEX ( `assessmentid` ); 
ALTER TABLE `imas_items` ADD INDEX ( `typeid` ) ;
ALTER TABLE `imas_items` ADD INDEX ( `itemtype` );
ALTER TABLE `imas_assessments` ADD INDEX ( `startdate` ); 
ALTER TABLE `imas_assessments` ADD INDEX ( `enddate` ) ;
ALTER TABLE `imas_forum_posts` ADD INDEX ( `threadid` ) ;
ALTER TABLE `imas_forum_views` ADD INDEX ( `threadid` ) ;
ALTER TABLE `imas_assessment_sessions` ADD INDEX ( `assessmentid` ); 
ALTER TABLE `imas_assessments` ADD INDEX ( `cntingb` ); 
ALTER TABLE `imas_courses` ADD INDEX ( `ownerid` ); 
ALTER TABLE `imas_diags` ADD INDEX (`cid`);
ALTER TABLE `imas_grades` ADD INDEX ( `gbitemid` );

ALTER TABLE `imas_assessments` ADD `minscore` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_courses` ADD `cploc` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_gbscheme` ADD INDEX ( `courseid` ) 

ALTER TABLE `imas_assessments` CHANGE `defpoints` `defpoints` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '10',
CHANGE `defattempts` `defattempts` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '1';
ALTER TABLE `imas_courses` CHANGE `hideicons` `hideicons` TINYINT( 2 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `allowunenroll` `allowunenroll` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `copyrights` `copyrights` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_diags` CHANGE `public` `public` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1';
ALTER TABLE `imas_forum_posts` CHANGE `posttype` `posttype` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `isanon` `isanon` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_forums` CHANGE `settings` `settings` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0',
CHANGE `defdisplay` `defdisplay` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_libraries` CHANGE `userights` `userights` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '8';
ALTER TABLE `imas_msgs` CHANGE `isread` `isread` TINYINT( 1 ) NOT NULL DEFAULT '0';
ALTER TABLE `imas_questions` CHANGE `points` `points` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '9999',
CHANGE `attempts` `attempts` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '9999';
ALTER TABLE `imas_questionset` CHANGE `userights` `userights` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '2',
CHANGE `hasimg` `hasimg` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_sessions` CHANGE `tzoffset` `tzoffset` SMALLINT( 4 ) NOT NULL DEFAULT '0';
ALTER TABLE `imas_students` CHANGE `code` `code` SMALLINT( 4 ) UNSIGNED NULL DEFAULT NULL ;
ALTER TABLE `imas_users` CHANGE `rights` `rights` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '0';

ALTER TABLE `imas_msgs` ADD `replied` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';

Use the code block below to update your existing courses to the new block format.
<?php
require("validate.php");

$query = "SELECT id,itemorder,blockcnt FROM imas_courses";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
while ($row = mysql_fetch_row($result)) {
	$blockcnt = $row[2];
	$newarray = array();
	$items = explode(',',$row[1]);
	foreach ($items as $item) {
		if (strpos($item,'~')===FALSE) {
			$newarray[] = $item;	
		} else {
			$sub = explode('~',$item);
			$newblock = array();
			$newblock['name'] = $sub[0];
			$newblock['id'] = $blockcnt;
			$blockcnt++;
			$newblock['startdate'] = $sub[1];
			$newblock['enddate'] = $sub[2];
			$newblock['SH'] = $sub[3];
			for ($i=4;$i<count($sub);$i++) {
				$newblock['items'][] = $sub[$i];
			}
			$newarray[] = $newblock;
		}
	}
	$newitemorder = addslashes(serialize($newarray));
	$query = "UPDATE imas_courses SET itemorder='$newitemorder',blockcnt='$blockcnt' WHERE id='{$row[0]}'";
	mysql_query($query) or die("Query failed : " . mysql_error());	
	
	
}

echo "Done";
?>

*********************
** IMathAS 1.0     **
*********************

Create subdirectory "qimages" in "assessment" directory.  Set permissions to 
allow server to write to this directory.

*** Database Changes ***
Required changes.

CREATE TABLE `imas_qimages` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`qsetid` INT( 10 ) UNSIGNED NOT NULL ,
`var` VARCHAR( 50 ) NOT NULL ,
`filename` VARCHAR( 100 ) NOT NULL ,
`alttext` VARCHAR( 254 ) NOT NULL ,
INDEX ( `qsetid` ) 
);
ALTER TABLE `imas_questionset` ADD `hasimg` INT( 1 ) UNSIGNED NOT NULL DEFAULT '0';

ALTER TABLE `imas_forum_posts` ADD `isanon` INT( 1 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_forums` ADD `settings` INT( 1 ) UNSIGNED NOT NULL DEFAULT '0';

ALTER TABLE `imas_courses` ADD `hideicons` INT( 2 ) UNSIGNED NOT NULL DEFAULT '0';

CREATE TABLE `imas_instr_files` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`description` VARCHAR( 254 ) NOT NULL ,
`filename` VARCHAR( 100 ) NOT NULL ,
`itemid` INT( 10 ) UNSIGNED NOT NULL ,
INDEX ( `itemid` ) 
) TYPE = innodb;

ALTER TABLE `imas_inlinetext` ADD `fileorder` TEXT NOT NULL ; 

ALTER TABLE `imas_courses` ADD `allowunenroll` INT( 1 ) UNSIGNED NOT NULL DEFAULT '0',
ADD `copyrights` INT( 1 ) UNSIGNED NOT NULL DEFAULT '0';

*********************
** IMathAS 1.0RC1  **
*********************

*** Database Changes ***
Required changes.

ALTER TABLE `imas_assessment_sessions` 
ADD `bestseeds` TEXT NOT NULL ,
ADD `bestattempts` TEXT NOT NULL ,
ADD `bestscores` TEXT NOT NULL ,
ADD `bestlastanswers` TEXT NOT NULL ;
ALTER TABLE `imas_assessments` ADD `reviewdate` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `enddate` ;
UPDATE `imas_assessment_sessions` SET bestseeds=seeds,bestattempts=attempts,bestscores=scores,bestlastanswers=lastanswers;

ALTER TABLE `imas_assessments` CHANGE `defpenalty` `defpenalty` VARCHAR( 5 ) NOT NULL DEFAULT '0';
ALTER TABLE `imas_questions` CHANGE `penalty` `penalty` VARCHAR( 5 ) NOT NULL DEFAULT '9999';

*********************
** IMathAS 1beta16 **
*********************

*** Database Changes ***
Required change.

CREATE TABLE `imas_diags` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`ownerid` INT( 10 ) UNSIGNED NOT NULL ,
`name` VARCHAR( 254 ) NOT NULL ,
`term` VARCHAR( 10 ) NOT NULL ,
`public` INT( 1 ) UNSIGNED NOT NULL DEFAULT '1',
`cid` INT( 10 ) UNSIGNED NOT NULL ,
`idprompt` VARCHAR( 254 ) NOT NULL ,
`ips` TEXT NOT NULL ,
`pws` TEXT NOT NULL ,
`sel1name` VARCHAR( 254 ) NOT NULL ,
`sel1list` TEXT NOT NULL ,
`aidlist` TEXT NOT NULL ,
`sel2name` VARCHAR( 254 ) NOT NULL ,
`sel2list` TEXT NOT NULL ,
INDEX ( `ownerid` , `public` ) 
) TYPE = innodb;


*********************
** IMathAS 1beta15 **
*********************

*** Database Changes ***
None

*** config.php Changes ***
  //absolute path or full url to Mimetex CGI, for math image fallback
  //if you do not have a local install, feel free to use:
  // $mathimgurl = "http://www.imathas.com/cgi-bin/mimetex.cgi"
  $mathimgurl = "/mimetex/mimetex.exe";
  
  //set to true if you have FreeType library installed 
  $freetypeinstalled = true;


*********************
** IMathAS 1beta14 **
*********************

CourseCreator rights level was removed.  Any existing CourseCreators need to have
rights reassigned before upgrading.

*** Database Changes ***
Required changes. 

CREATE TABLE `imas_groups` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 255 ) NOT NULL 
);

ALTER TABLE `imas_users` ADD `groupid` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0';

ALTER TABLE `imas_libraries` ADD `groupid` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_libraries` CHANGE `userights` `userights` INT( 1 ) UNSIGNED NOT NULL DEFAULT '8';
UPDATE `imas_libraries` SET userights=8 WHERE userights=2;
UPDATE `imas_libraries` SET userights=4 WHERE userights=1;

ALTER TABLE `imas_questions` ADD `category` VARCHAR( 255 ) NOT NULL DEFAULT '0';

*** Config.php Changes ***
Required changes.  Add to config.php:

//should non-admins be allowed to create new non-group libraries?
//on a single-school install, set to true; for larger installs that plan to
//use the Groups features, set to false
$allownongrouplibs = false;

//should anyone be allowed to import/export questions and libraries from the 
//course page?  Intended for easy sharing between systems, but the course page
//is cleaner if turned off.
$allowcourseimport = false;


*********************
** IMathAS 1beta13 **
*********************

*** Database Changes ***
Required changes. 

ALTER TABLE `imas_sessions` ADD `sessiondata` TEXT NOT NULL ;

*********************
** IMathAS 1beta12 **
*********************

*** Database Changes ***
Recommended changes (to allow assessments with more than ~50 questions)

ALTER TABLE `imas_assessment_sessions` CHANGE `scores` `scores` TEXT NOT NULL;
ALTER TABLE `imas_assessment_sessions` CHANGE `questions` `questions` TEXT NOT NULL;

Required changes.  

ALTER TABLE `imas_library_items` ADD `ownerid` INT( 10 ) UNSIGNED NOT NULL;

if you have existing questions, use this to assign owners to the library assignments:
(cut and paste into a .php file, put in main imathas directory, and run it)
<?php
require("validate.php");

$query = "SELECT id,ownerid FROM imas_questionset";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
while ($row = mysql_fetch_row($result)) {
	$query = "UPDATE imas_library_items SET ownerid='{$row[1]}' WHERE qsetid='{$row[0]}'";
	mysql_query($query) or die("Query failed : " . mysql_error());
}
echo "DONE";
?>

*********************
** IMathAS 1beta11 **
*********************

No changes required

*********************
** IMathAS 1beta10 **
*********************

*** Database Changes ***
Required changes.  

ALTER TABLE `imas_users` ADD `lastaccess` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_users` ADD INDEX ( `lastaccess` ) ;

ALTER TABLE `imas_questionset` ADD `uniqueid` BIGINT( 16 ) UNSIGNED NOT NULL AFTER `id` ;
ALTER TABLE `imas_libraries` ADD `uniqueid` BIGINT( 16 ) UNSIGNED NOT NULL AFTER `id` ;

ALTER TABLE `imas_questionset` ADD `adddate` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `uniqueid` ,
 ADD `lastmoddate` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `adddate` ;

ALTER TABLE `imas_libraries` ADD `adddate` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `uniqueid` ,
 ADD `lastmoddate` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `adddate` ;

if you have existing questions/libraries you wish to assign unique ids to, use this:
(cut and paste into a .php file, put in main imathas directory, and run it)
<?php
	require("validate.php");
	$query = "SELECT id FROM imas_questionset";
	$result = mysql_query($query) or die("Query failed : " . mysql_error());
	$mt = microtime();
	$now = time();
	while ($row = mysql_fetch_row($result)) {
		$uid = substr($mt,11).substr($mt,2,2).$row[0];
		$query = "UPDATE imas_questionset SET uniqueid=$uid,adddate=$now,lastmoddate=$now WHERE id={$row[0]}";
		mysql_query($query) or die("Query failed : " . mysql_error());
	}
	$query = "SELECT id FROM imas_libraries";
	$result = mysql_query($query) or die("Query failed : " . mysql_error());
	$mt = microtime();
	while ($row = mysql_fetch_row($result)) {
		$uid = substr($mt,11).substr($mt,2,2).$row[0];
		$query = "UPDATE imas_libraries SET uniqueid=$uid,adddate=$now,lastmoddate=$now WHERE id={$row[0]}";
		mysql_query($query) or die("Query failed : " . mysql_error());
	}
?>

*** Config.php changes ***
Added $sessionpath.  No change required if things are working fine already.


********************
** IMathAS 1beta9 **
********************

*** Database Changes ****
First change is required.  New tables are needed if you want to use forums.  

ALTER TABLE `imas_sessions` ADD `tzoffset` INT( 4 ) NOT NULL DEFAULT '0';

CREATE TABLE `imas_forums` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `name` varchar(50) NOT NULL default '',
  `description` varchar(254) NOT NULL default '',
  `courseid` int(10) unsigned NOT NULL default '0',
  `startdate` int(10) unsigned NOT NULL default '0',
  `enddate` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `courseid` (`courseid`)
);

CREATE TABLE `imas_forum_views` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `userid` int(10) unsigned NOT NULL default '0',
  `threadid` int(10) unsigned NOT NULL default '0',
  `lastview` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `userid` (`userid`,`threadid`)
);

CREATE TABLE `imas_forum_posts` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `forumid` int(10) unsigned NOT NULL default '0',
  `threadid` int(10) NOT NULL default '0',
  `userid` int(10) unsigned NOT NULL default '0',
  `postdate` int(10) unsigned NOT NULL default '0',
  `views` int(10) unsigned NOT NULL default '0',
  `parent` int(10) unsigned NOT NULL default '0',
  `posttype` int(1) unsigned NOT NULL default '0',
  `subject` varchar(100) NOT NULL default '',
  `message` text NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `forumid` (`forumid`)
);

*** Config.php changes ***  (not required)

Remove $TZ setting, and "if (isset($TZ)) {putenv("TZ=$TZ");}" line.

Generalized database name.  No changed needed for existing installs.


********************
** IMathAS 1beta8 **
********************

*** Database changes: (required, backwards compatible) ***
ALTER TABLE `imas_libraries` ADD `parent` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE `imas_questionset` ADD `author` VARCHAR( 254 ) NOT NULL DEFAULT 'unknown' AFTER `ownerid` ;
	
*** No changes to config.php ***
