$order++;
                 $contact = $row['contact'];
                 if ($contact != $pcontact) {
                     $funcs->UpdateFirstPlayer($tid, FALSE, $contact);
                 }
                 //update contact in people table
                 $db->Execute($sql2, array($tid));
                 $db->Execute($sql3, array($tid));
             }
             unset($row);
         }
         if ($newtype) {
             if (!$sch) {
                 $sch = new tmtSchedule();
             }
             $sch->ScheduleMatches($this, $bracket_id);
         }
         if ($newtype || $matches || $results) {
             $sql = 'UPDATE ' . $pref . 'module_tmt_brackets SET chartbuild=1 WHERE bracket_id=?';
             $db->Execute($sql, array($bracket_id));
         }
     }
     $message = $res ? '' : $this->PrettyMessage('err_save', FALSE);
 } elseif (!empty($data->errmsg)) {
     $message = $data->errmsg;
 }
 if (isset($params['apply'])) {
     if (isset($params['newbracket'])) {
         unset($params['newbracket']);
     }
     unset($params['apply']);
                        $msg .= '<br />' . $errmsg;
                    }
                }
                if ($save) {
                    $sql = 'UPDATE ' . $pref . 'module_tmt_matches SET playwhen=?, score=?,	status=? WHERE match_id=?';
                    $db->Execute($sql, array($when, $score, $res, $params['match']));
                    $t = $db->GenID($pref . 'module_tmt_history_seq');
                    if ($params['sender']) {
                        $by = $params['sender'];
                    }
                    $dt->modify('now');
                    $when = strftime('%F %T', $dt->getTimestamp());
                    $sql = 'INSERT INTO ' . $pref . 'module_tmt_history (history_id,bracket_id,changer,changewhen,olddata,newdata,comment VALUES (?,?,?,?,?,?,?)';
                    $db->Execute($sql, array($t, $bracket_id, $by, $when, NULL, $tres, $this->Lang('match_added', $params['match'])));
                    $funcs = new tmtSchedule();
                    $funcs->ScheduleMatches($this, $bracket_id);
                }
                $params = array('bracket_id' => $bracket_id, 'view' => $params['view'], 'message' => $msg);
                $this->RedirectForFrontEnd($id, $returnid, 'default', $params);
            } else {
                $key = 'err_noresult2';
            }
        } else {
            $key = 'err_nomatch';
        }
    } else {
        $key = 'err_captcha';
    }
    $smarty->assign('message', $this->Lang($key));
    //fall into repeat presentation
}