$columns) { $curr_columns = get_columns($id, $link); if ($curr_columns === false) { show_install_err($errors[0]); } $tocreate = array_diff(array_keys($columns), $curr_columns); foreach ($tocreate as $v) { $absent_columns[] = "$id.$v"; } } if (in_array("${mysqlprefix}chatmessage.agentId", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatmessage ADD agentId int NOT NULL DEFAULT 0 AFTER ikind", $link); runsql("update ${mysqlprefix}chatmessage, ${mysqlprefix}chatoperator set agentId = operatorid where agentId = 0 AND ikind = 2 AND (vclocalename = tname OR vccommonname = tname)", $link); } if (in_array("${mysqlprefix}chatthread.agentId", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatthread ADD agentId int NOT NULL DEFAULT 0 AFTER agentName", $link); runsql("update ${mysqlprefix}chatthread, ${mysqlprefix}chatoperator set agentId = operatorid where agentId = 0 AND (vclocalename = agentName OR vccommonname = agentName)", $link); } if (in_array("${mysqlprefix}chatthread.dtmchatstarted", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatthread ADD dtmchatstarted datetime DEFAULT 0 AFTER dtmcreated", $link); runsql("update ${mysqlprefix}chatthread set dtmchatstarted = dtmcreated", $link); } if (in_array("${mysqlprefix}chatthread.agentTyping", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatthread ADD agentTyping int DEFAULT 0", $link); } if (in_array("${mysqlprefix}chatthread.userTyping", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatthread ADD userTyping int DEFAULT 0", $link); } if (in_array("${mysqlprefix}chatthread.messageCount", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatthread ADD messageCount varchar(16)", $link); runsql("ALTER TABLE ${mysqlprefix}chatmessage ADD INDEX idx_threadid_ikind (threadid, ikind)", $link); runsql("UPDATE ${mysqlprefix}chatthread t SET t.messageCount = (SELECT COUNT(*) FROM ${mysqlprefix}chatmessage WHERE ${mysqlprefix}chatmessage.threadid = t.threadid AND ikind = 1)", $link); runsql("ALTER TABLE ${mysqlprefix}chatmessage DROP INDEX idx_threadid_ikind", $link); } if (in_array("${mysqlprefix}chatthread.nextagent", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatthread ADD nextagent int NOT NULL DEFAULT 0", $link); } if (in_array("${mysqlprefix}chatthread.shownmessageid", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatthread ADD shownmessageid int NOT NULL DEFAULT 0", $link); } if (in_array("${mysqlprefix}chatthread.userid", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatthread ADD userid varchar(255) DEFAULT \"\"", $link); } if (in_array("${mysqlprefix}chatoperator.iperm", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD iperm int DEFAULT 65535", $link); } if (in_array("${mysqlprefix}chatoperator.istatus", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD istatus int DEFAULT 0", $link); } if (in_array("${mysqlprefix}chatoperator.idisabled", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD idisabled int DEFAULT 0 AFTER istatus", $link); } if (in_array("${mysqlprefix}chatoperator.vcavatar", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD vcavatar varchar(255)", $link); } if (in_array("${mysqlprefix}chatoperator.vcjabbername", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD vcjabbername varchar(255)", $link); } if (in_array("${mysqlprefix}chatoperator.vcemail", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD vcemail varchar(64)", $link); } if (in_array("${mysqlprefix}chatoperator.dtmrestore", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD dtmrestore datetime DEFAULT 0", $link); } if (in_array("${mysqlprefix}chatoperator.vcrestoretoken", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatoperator ADD vcrestoretoken varchar(64)", $link); } if (in_array("${mysqlprefix}chatresponses.vctitle", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatresponses ADD vctitle varchar(100) NOT NULL DEFAULT '' AFTER groupid", $link); } if (in_array("${mysqlprefix}chatthread.groupid", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatthread ADD groupid int references ${mysqlprefix}chatgroup(groupid)", $link); } if (in_array("${mysqlprefix}chatthread.userAgent", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatthread ADD userAgent varchar(255)", $link); } if (in_array("${mysqlprefix}chatgroup.vcemail", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD vcemail varchar(64)", $link); } if (in_array("${mysqlprefix}chatgroup.iweight", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD iweight int DEFAULT 0", $link); } if (in_array("${mysqlprefix}chatgroup.parent", $absent_columns)) { runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD parent int DEFAULT NULL AFTER groupid", $link); } // Add absent indexes $absent_indexes = array(); foreach ($dbtables_indexes as $id => $indexes) { $curr_indexes = get_indexes($id, $link); if ($curr_indexes === false) { show_install_err($errors[0]); } $tocreate = array_diff(array_keys($indexes), $curr_indexes); foreach ($tocreate as $i) { $absent_indexes[] = "$id.$i"; } } if (in_array("${mysqlprefix}chatgroup.parent", $absent_indexes)) { runsql("ALTER TABLE ${mysqlprefix}chatgroup ADD INDEX (parent)", $link); } if (in_array("${mysqlprefix}chatmessage.idx_agentid", $absent_indexes)) { runsql("ALTER TABLE ${mysqlprefix}chatmessage ADD INDEX idx_agentid (agentid)", $link); } if (in_array("${mysqlprefix}chatsitevisitor.threadid", $absent_indexes)) { runsql("ALTER TABLE ${mysqlprefix}chatsitevisitor ADD INDEX (threadid)", $link); } if (in_array("${mysqlprefix}visitedpage.visitorid", $absent_indexes)) { runsql("ALTER TABLE ${mysqlprefix}visitedpage ADD INDEX (visitorid)", $link); } } } mysql_close($link); header("Location: $webimroot/install/index.php"); exit; ?>