if (isset($_POST['t_description']) && strlen(trim($_POST['t_description'])) > 0) {
     $t_description = trim($_POST['t_description']);
 } else {
     $t_description = "";
 }
 $t_admintools = (double) isset($_POST['t_admintools']) ? $_POST['t_admintools'] : 0;
 $t_banned = (double) isset($_POST['t_banned']) ? $_POST['t_banned'] : 0;
 $t_wormed = (double) isset($_POST['t_wormed']) ? $_POST['t_wormed'] : 0;
 $t_globalmod = (double) isset($_POST['t_globalmod']) ? $_POST['t_globalmod'] : 0;
 $t_linksmod = (double) isset($_POST['t_linksmod']) ? $_POST['t_linksmod'] : 0;
 $new_group_perms = (double) $t_banned | $t_wormed | $t_globalmod | $t_linksmod;
 if (session::check_perm(USER_PERM_FORUM_TOOLS, 0)) {
     $new_group_perms = (double) $new_group_perms | $t_admintools;
 }
 if ($valid) {
     if (($new_gid = perm_add_group($t_name, $t_description, $new_group_perms)) !== false) {
         if (isset($_POST['t_new_perms_array']) && is_array($_POST['t_new_perms_array'])) {
             $t_new_perms_array = $_POST['t_new_perms_array'];
             foreach ($t_new_perms_array as $fid) {
                 $t_post_read = (double) isset($_POST['t_post_read'][$fid]) ? $_POST['t_post_read'][$fid] : 0;
                 $t_post_create = (double) isset($_POST['t_post_create'][$fid]) ? $_POST['t_post_create'][$fid] : 0;
                 $t_thread_create = (double) isset($_POST['t_thread_create'][$fid]) ? $_POST['t_thread_create'][$fid] : 0;
                 $t_post_edit = (double) isset($_POST['t_post_edit'][$fid]) ? $_POST['t_post_edit'][$fid] : 0;
                 $t_post_delete = (double) isset($_POST['t_post_delete'][$fid]) ? $_POST['t_post_delete'][$fid] : 0;
                 $t_post_attach = (double) isset($_POST['t_post_attach'][$fid]) ? $_POST['t_post_attach'][$fid] : 0;
                 $t_moderator = (double) isset($_POST['t_moderator'][$fid]) ? $_POST['t_moderator'][$fid] : 0;
                 $t_post_html = (double) isset($_POST['t_post_html'][$fid]) ? $_POST['t_post_html'][$fid] : 0;
                 $t_post_sig = (double) isset($_POST['t_post_sig'][$fid]) ? $_POST['t_post_sig'][$fid] : 0;
                 $t_post_approval = (double) isset($_POST['t_post_approval'][$fid]) ? $_POST['t_post_approval'][$fid] : 0;
                 $new_group_perms = (double) $t_post_read | $t_post_create | $t_thread_create;
                 $new_group_perms = (double) $new_group_perms | $t_post_edit | $t_post_delete;
 if (isset($_POST['t_description']) && strlen(trim($_POST['t_description'])) > 0) {
     $t_description = trim($_POST['t_description']);
 } else {
     $t_description = "";
 }
 $t_admintools = (double) isset($_POST['t_admintools']) ? $_POST['t_admintools'] : 0;
 $t_banned = (double) isset($_POST['t_banned']) ? $_POST['t_banned'] : 0;
 $t_wormed = (double) isset($_POST['t_wormed']) ? $_POST['t_wormed'] : 0;
 $t_globalmod = (double) isset($_POST['t_globalmod']) ? $_POST['t_globalmod'] : 0;
 $t_linksmod = (double) isset($_POST['t_linksmod']) ? $_POST['t_linksmod'] : 0;
 $new_group_perms = (double) $t_banned | $t_wormed | $t_globalmod | $t_linksmod;
 if (session::check_perm(USER_PERM_FORUM_TOOLS, 0)) {
     $new_group_perms = (double) $new_group_perms | $t_admintools;
 }
 if ($valid) {
     if ($new_gid = perm_add_group($t_name, $t_description, $new_group_perms)) {
         if (isset($_POST['t_new_perms_array']) && is_array($_POST['t_new_perms_array'])) {
             $t_new_perms_array = $_POST['t_new_perms_array'];
             foreach ($t_new_perms_array as $fid) {
                 $t_post_read = (double) isset($_POST['t_post_read'][$fid]) ? $_POST['t_post_read'][$fid] : 0;
                 $t_post_create = (double) isset($_POST['t_post_create'][$fid]) ? $_POST['t_post_create'][$fid] : 0;
                 $t_thread_create = (double) isset($_POST['t_thread_create'][$fid]) ? $_POST['t_thread_create'][$fid] : 0;
                 $t_post_edit = (double) isset($_POST['t_post_edit'][$fid]) ? $_POST['t_post_edit'][$fid] : 0;
                 $t_post_delete = (double) isset($_POST['t_post_delete'][$fid]) ? $_POST['t_post_delete'][$fid] : 0;
                 $t_post_attach = (double) isset($_POST['t_post_attach'][$fid]) ? $_POST['t_post_attach'][$fid] : 0;
                 $t_moderator = (double) isset($_POST['t_moderator'][$fid]) ? $_POST['t_moderator'][$fid] : 0;
                 $t_post_html = (double) isset($_POST['t_post_html'][$fid]) ? $_POST['t_post_html'][$fid] : 0;
                 $t_post_sig = (double) isset($_POST['t_post_sig'][$fid]) ? $_POST['t_post_sig'][$fid] : 0;
                 $t_post_approval = (double) isset($_POST['t_post_approval'][$fid]) ? $_POST['t_post_approval'][$fid] : 0;
                 $new_group_perms = (double) $t_post_read | $t_post_create | $t_thread_create;
                 $new_group_perms = (double) $new_group_perms | $t_post_edit | $t_post_delete;