$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[] = "$id.$v"; } } if( in_array("chatmessage.agentId", $absent) ) { runsql("ALTER TABLE chatmessage ADD agentId int NOT NULL DEFAULT 0 AFTER ikind", $link); runsql("update chatmessage,chatoperator set agentId = operatorid where agentId = 0 AND ikind = 2 AND (vclocalename = tname OR vccommonname = tname)", $link); } if( in_array("chatthread.agentId", $absent) ) { runsql("ALTER TABLE chatthread ADD agentId int NOT NULL DEFAULT 0 AFTER agentName", $link); runsql("update chatthread,chatoperator set agentId = operatorid where agentId = 0 AND (vclocalename = agentName OR vccommonname = agentName)", $link); } if( in_array("chatthread.agentTyping", $absent) ) { runsql("ALTER TABLE chatthread ADD agentTyping int DEFAULT 0", $link); } if( in_array("chatthread.userTyping", $absent) ) { runsql("ALTER TABLE chatthread ADD userTyping int DEFAULT 0", $link); } if( in_array("chatthread.messageCount", $absent) ) { runsql("ALTER TABLE chatthread ADD messageCount varchar(16)", $link); runsql("ALTER TABLE chatmessage ADD index idx_threadid_ikind (threadid, ikind)", $link); runsql("UPDATE chatthread t SET t.messageCount = (SELECT COUNT(*) FROM chatmessage WHERE chatmessage.threadid = t.threadid AND ikind = 1)", $link); runsql("ALTER TABLE chatmessage DROP INDEX idx_threadid_ikind", $link); } } } mysql_close($link); header("Location: ".dirname($_SERVER['PHP_SELF'])."/index.php"); exit; ?>