[request] Help with some sql



Hello. I am running a bnc service and i have a sql partfrom an eggdrop (tcl) that posts new created, deleted, suspended bnc Infos into my forum.
The problem is now that my coder left us, because of some family things and i want to move all my vb to xf. I hope now to find someone that can help me rewriting the following Code so i can use it for xenForo.

    package require mysqltcl
    proc tosql {ident topic text {ip ""}} {
        global [namespace current]::sqlsettings [namespace current]::writetomysql
        if {!$writetomysql} { return }

        ### CFG
        set forumid $sqlsettings(forumid)
        set tableprefix $sqlsettings(tableprefix)
        set poster $sqlsettings(poster)
        set posterid $sqlsettings(posterid)

        ### HOST
        set host $sqlsettings(host)
        set user $sqlsettings(user)
        set pass $sqlsettings(pass)
        set db $sqlsettings(db)

        # connect
        set con [::mysql::connect -host $host -user $user -password $pass -db $db]
        set con [::mysql::connect -host $host -user $user -password $pass -db $db]

        # first check id thread needs to be created
        set result [::mysql::sel $con "SELECT * FROM `[join "$tableprefix thread" ""]` WHERE forumid = $forumid AND title = '$ident'" -list]
        ::mysql::endquery $con
        if {[llength $result] == 0} {
            # insert thread for actual post
            ::mysql::sel $con "INSERT INTO `[join "$tableprefix thread" ""]` (`threadid`,`title`,`prefixid`,`firstpostid`,`lastpostid`,`lastpost`,`forumid`, \
            `pollid`,`open`,`replycount`,`hiddencount`,`deletedcount`,`postusername`,`postuserid`,`lastposter`, \
            `dateline`,`views`,`iconid`,`notes`,`visible`,`sticky`,`votenum`,`votetotal`,`attach`,`similar`,`taglist`,`autoskip`) \
            VALUES (NULL,'$ident','','0','0','0','$forumid','0','1','0','0','0','$poster','$posterid','','0','0','0','','1','0','0','0','0','',NULL,'0')"
            ::mysql::endquery $con

            # select thread for ident
            set result [::mysql::sel $con "SELECT * FROM `[join "$tableprefix thread" ""]` WHERE forumid = $forumid AND title = '$ident'" -list]
            ::mysql::endquery $con

            # increase threadcount of forum
            ::mysql::sel $con "UPDATE [join "$tableprefix forum" ""] SET threadcount = threadcount + 1 where forumid = $forumid"
            ::mysql::endquery $con
        } else {
            # increase replycount of thread
            ::mysql::sel $con "UPDATE [join "$tableprefix thread" ""] SET replycount = replycount +1 where threadid =[lindex $result 0 0]"
            ::mysql::endquery $con
        # increase replycount of forum
        ::mysql::sel $con "UPDATE [join "$tableprefix forum" ""] SET replycount = replycount + 1 where forumid = $forumid"
        ::mysql::endquery $con

        # insert actual post
        ::mysql::sel $con "INSERT INTO `[join "$tableprefix post" ""]` (`postid`,`threadid`,`parentid`,`username`,`userid`,`title`,`dateline`,`pagetext`,`allowsmilie`, \
        `showsignature`,`ipaddress`,`iconid`,`visible`,`attach`,`infraction`,`reportthreadid`) \
        VALUES (NULL,'[lindex $result 0 0]','0','$poster','$posterid','$topic','[unixtime]','$text','0','0','$ip','0','1','0','0','0')"
        set postid [::mysql::insertid $con]
        ::mysql::endquery $con

        # set bot as lastposter
        # in thread
        ::mysql::sel $con "UPDATE [join "$tableprefix thread" ""] SET lastposter = '$poster', lastpostid = $postid, lastpost = [unixtime] where threadid = [lindex $result 0 0]"
        ::mysql::endquery $con
        # in forum
        ::mysql::sel $con "UPDATE [join "$tableprefix forum" ""] SET lastpost = [unixtime], lastposter = '$poster', lastpostid = $postid, lastthread = '[lindex $result 0 1]', lastthreadid = [lindex $result 0 0] where forumid = $forumid"
        ::mysql::endquery $con

        ::mysql::close $con
        return $result
    proc randsort {list} {
        for {set x 0} {$x < [join "[expr {int(rand()*[join "1 [string repeat "0" [expr {int(rand()*10)}]]" ""])}] 1" ""]} {incr x} {
            set out ""
            foreach item $list {
                set r [expr {int([llength $out]*rand())}]
                set out [linsert $out $r $item]
            set list $out
        return $out
    proc vdur {t} { return [expr [string map {"y" "*220752000+" "M" "*18144000+" "w" "*604800+" "d" "*86400+" "h" "*3600+" "m" "*60+" "s" "*1"} "$t+0"]] }
    proc dur {in} { set o ""; set i "0"; set t "220752000 y 18144000 M 604800 w 86400 d 3600 h 60 m 1 s"; while {$in > 0} { if {[set tmp [lindex [split [expr {$in/[lindex $t $i]}] "."] 0]] > 0} { append o "$tmp"; append o [lindex $t [expr $i+1]] }; incr in -[expr $tmp*[lindex $t $i]]; incr i 2 }; return $o }
Thanks for any help.


This is no addon... this is a part of a script i use on an eggdrop, which has nothing to do with an addon....
And why a paid job? maybe i will find someone that is willing to help without thinking about money ;)