Exemple #1
0
 /**
  * main ucp function
  * @param int $id
  * @param string $mode
  */
 function main($id, $mode)
 {
     global $db, $user, $auth, $template, $config, $phpbb_root_path, $phpEx;
     // Attach the language files
     $user->add_lang(array('mods/dkp_admin', 'mods/dkp_common', 'acp/common'));
     $guilds = new \bbdkp\controller\guilds\Guilds();
     $guildlist = $guilds->guildlist(1);
     if (count($guildlist) == 0) {
         trigger_error('ERROR_NOGUILD', E_USER_WARNING);
     }
     $mode = $mode == '' ? 'characters' : $mode;
     // GET processing logic
     add_form_key('cocoa');
     switch ($mode) {
         case 'characters':
             /***
              *
              * ucp tab 1
              * list of characters
              *
              */
             $this->link = '';
             $submit = isset($_POST['submit']) ? true : false;
             $member = new \bbdkp\controller\members\Members();
             if ($submit) {
                 if (!check_form_key('cocoa')) {
                     trigger_error('FORM_INVALID');
                 }
                 $member_id = (int) request_var('memberlist', 0);
                 $member->member_id = $member_id;
                 $member->Getmember();
                 $member->Claim_Member();
                 // Generate confirmation page. It will redirect back to the calling page
                 meta_refresh(2, $this->u_action);
                 $message = sprintf($user->lang['CHARACTERS_UPDATED'], $member->member_name) . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
                 unset($member);
                 trigger_error($message);
             }
             $show_buttons = true;
             $s_guildmembers = ' ';
             //if user has no access to claiming chars, don't show the add button.
             if (!$auth->acl_get('u_dkpucp')) {
                 $show_buttons = false;
             }
             if ($member->has_reached_maxbbdkpaccounts()) {
                 $show_buttons = false;
             }
             //if there are no chars at all, do not show add button
             $sql = 'SELECT count(*) AS mcount FROM ' . MEMBER_LIST_TABLE . ' WHERE member_rank_id < 90  ';
             $result = $db->sql_query($sql, 0);
             $mcount = (int) $db->sql_fetchfield('mcount');
             $show = true;
             if ($mcount == 0) {
                 $show = false;
             }
             if ($show) {
                 // list all characters bound to me
                 $this->listmychars();
                 // build popup for adding new chars to my phpbb account, get only those that are not assigned yet.
                 // note if someone picks a guildmember that does not belong to them then the guild admin can override this in acp
                 $member->listallmembers($guilds->guildid, true);
                 if (count($member->guildmemberlist) > 0) {
                     foreach ($member->guildmemberlist as $id => $m) {
                         $s_guildmembers .= '<option value="' . $m['member_id'] . '">' . $m['rank_name'] . ' ' . $m['member_name'] . '-' . $m['member_realm'] . '</option>';
                     }
                 } else {
                     $show_buttons = false;
                 }
             }
             $db->sql_freeresult($result);
             unset($member);
             // These template variables are used on all the pages
             $template->assign_vars(array('S_DKPMEMBER_OPTIONS' => $s_guildmembers, 'S_SHOW' => $show, 'S_SHOW_BUTTONS' => $show_buttons, 'U_ACTION' => $this->u_action, 'LA_ALERT_AJAX' => $user->lang['ALERT_AJAX'], 'LA_ALERT_OLDBROWSER' => $user->lang['ALERT_OLDBROWSER'], 'UA_MEMBERLIST' => append_sid("{$phpbb_root_path}styles/" . rawurlencode($user->theme['template_path']) . '/template/dkp/findmemberlist.' . $phpEx)));
             $this->tpl_name = 'dkp/ucp_dkp';
             $this->page_title = $user->lang['UCP_DKP_CHARACTERS'];
             break;
         case 'characteradd':
             /**
              *
              * ucp tab 2
              * character add/edit
              *
              */
             //get member_id if selected from pulldown
             $member_id = request_var('hidden_member_id', request_var(URI_NAMEID, 0));
             $submit = isset($_POST['add']) ? true : false;
             $update = isset($_POST['update']) ? true : false;
             $delete = isset($_POST['delete']) ? true : false;
             if ($submit || $update || $delete) {
                 if ($delete) {
                     // check if user can delete character
                     if (!$auth->acl_get('u_dkp_chardelete')) {
                         trigger_error($user->lang['NOUCPDELCHARS']);
                     }
                     if (confirm_box(true)) {
                         $deletemember = new \bbdkp\controller\members\Members();
                         $deletemember->member_id = request_var('del_member_id', 0);
                         $deletemember->Getmember();
                         $deletemember->Deletemember();
                         $success_message = sprintf($user->lang['ADMIN_DELETE_MEMBERS_SUCCESS'], $deletemember->member_name);
                         trigger_error($success_message);
                     } else {
                         $deletemember = new \bbdkp\controller\members\Members();
                         $deletemember->member_id = request_var('member_id', 0);
                         $deletemember->Getmember();
                         $s_hidden_fields = build_hidden_fields(array('delete' => true, 'del_member_id' => $deletemember->member_id));
                         confirm_box(false, sprintf($user->lang['CONFIRM_DELETE_MEMBER'], $deletemember->member_name), $s_hidden_fields);
                     }
                 }
                 if ($submit) {
                     // add character
                     if (!check_form_key('characteradd')) {
                         trigger_error('FORM_INVALID');
                     }
                     $newmember = new \bbdkp\controller\members\Members();
                     if ($newmember->has_reached_maxbbdkpaccounts()) {
                         trigger_error(sprintf($user->lang['MAX_CHARS_EXCEEDED'], $config['bbdkp_maxchars']), E_USER_WARNING);
                     }
                     $newmember->game_id = request_var('game_id', '');
                     // get member name
                     $newmember->member_region = request_var('region_id', '');
                     $newmember->member_name = utf8_normalize_nfc(request_var('member_name', '', true));
                     $newmember->member_class_id = request_var('member_class_id', 1);
                     $newmember->member_race_id = request_var('member_race_id', 1);
                     $newmember->member_role = request_var('member_role', '');
                     $newmember->member_region = request_var('region_id', '');
                     $newmember->member_gender_id = isset($_POST['gender']) ? request_var('gender', '') : '0';
                     $newmember->member_title = utf8_normalize_nfc(request_var('member_title', '', true));
                     $newmember->member_realm = utf8_normalize_nfc(request_var('realm', '', true));
                     $newmember->member_guild_id = request_var('member_guild_id', 0);
                     $newmember->member_rank_id = request_var('member_rank_id', 99);
                     $newmember->member_level = request_var('member_level', 1);
                     $newmember->member_comment = utf8_normalize_nfc(request_var('member_comment', '', true));
                     $newmember->member_joindate = mktime(0, 0, 0, request_var('member_joindate_mo', 0), request_var('member_joindate_d', 0), request_var('member_joindate_y', 0));
                     $newmember->member_outdate = mktime(0, 0, 0, 12, 31, 2030);
                     if (request_var('member_outdate_mo', 0) + request_var('member_outdate_d', 0) != 0) {
                         $newmember->member_outdate = mktime(0, 0, 0, request_var('member_outdate_mo', 0), request_var('member_outdate_d', 0), request_var('member_outdate_y', 0));
                     }
                     $newmember->member_achiev = request_var('member_achiev', 0);
                     $newmember->member_armory_url = utf8_normalize_nfc(request_var('member_armorylink', '', true));
                     $newmember->phpbb_user_id = $user->data['user_id'];
                     $newmember->member_status = request_var('activated', 0) > 0 ? 1 : 0;
                     $newmember->Makemember();
                     if ($newmember->member_id > 0) {
                         // record added.
                         $newmember->member_comment = sprintf($user->lang['ADMIN_ADD_MEMBER_SUCCESS'], ucwords($newmember->member_name), date("F j, Y, g:i a"));
                         $newmember->Armory_getmember();
                         $newmember->Updatemember($newmember);
                         meta_refresh(1, $this->u_action . '&amp;member_id=' . $newmember->member_id);
                         $success_message = sprintf($user->lang['ADMIN_ADD_MEMBER_SUCCESS'], ucwords($newmember->member_name), date("F j, Y, g:i a"));
                         trigger_error($success_message, E_USER_NOTICE);
                     } else {
                         meta_refresh(1, $this->u_action . '&amp;member_id=' . $newmember->member_id);
                         $failure_message = sprintf($user->lang['ADMIN_ADD_MEMBER_FAIL'], ucwords($newmember->member_name), $newmember->member_id);
                         trigger_error($failure_message, E_USER_WARNING);
                     }
                 }
                 if ($update) {
                     //update
                     if (!check_form_key('characteradd')) {
                         trigger_error('FORM_INVALID');
                     }
                     // check if user can update character
                     if (!$auth->acl_get('u_dkp_charupdate')) {
                         trigger_error($user->lang['NOUCPUPDCHARS']);
                     }
                     $updatemember = $this->UpdateMyCharacter($member_id);
                     meta_refresh(1, $this->u_action . '&amp;member_id=' . $updatemember->member_id);
                     //$success_message = sprintf($user->lang['ADMIN_UPDATE_MEMBER_SUCCESS'], ucwords($updatemember->member_name))  . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
                     //trigger_error($success_message, E_USER_NOTICE);
                 }
             }
             //template fill
             $this->fill_addmember($member_id, $guildlist);
             $template->assign_vars(array('LA_ALERT_AJAX' => $user->lang['ALERT_AJAX'], 'LA_ALERT_OLDBROWSER' => $user->lang['ALERT_OLDBROWSER'], 'LA_MSG_NAME_EMPTY' => $user->lang['FV_REQUIRED_NAME'], 'UA_FINDGAMERANK' => append_sid("{$phpbb_root_path}styles/" . rawurlencode($user->theme['template_path']) . '/template/dkp/findGameRank.' . $phpEx), 'UA_FINDCLASSRACE' => append_sid("{$phpbb_root_path}styles/" . rawurlencode($user->theme['template_path']) . '/template/dkp/findclassrace.' . $phpEx)));
             $this->tpl_name = 'dkp/ucp_dkp_charadd';
             break;
     }
 }
Exemple #2
0
    /**
     * Build addmember template
     *
     * @param $mode
     */
    private function BuildTemplateAddEditmembers($mode)
    {
        global $template, $db, $config, $user, $phpbb_admin_path, $phpEx;
        $member_id = request_var('hidden_member_id', request_var(URI_NAMEID, 0));
        $editmember = new \bbdkp\controller\members\Members($member_id);
        $S_ADD = $member_id > 0 ? false : true;
        if ($S_ADD) {
            // set defaults
            $editmember->member_guild_id = request_var(URI_GUILD, 0);
        }
        $Guild = new \bbdkp\controller\guilds\Guilds($editmember->member_guild_id);
        $guildlist = $Guild->guildlist();
        if ($S_ADD) {
            $editmember->game_id = $Guild->game_id;
            $editmember->member_rank_id = $Guild->raidtrackerrank;
            $editmember->member_status = 1;
            $editmember->member_gender_id = 0;
        }
        foreach ($guildlist as $g) {
            //populate guild popup
            $template->assign_block_vars('guild_row', array('VALUE' => $g['id'], 'SELECTED' => $g['id'] == $editmember->member_guild_id ? ' selected="selected"' : '', 'OPTION' => !empty($g['name']) ? $g['name'] : '(None)'));
        }
        // Game dropdown
        if (isset($this->games)) {
            foreach ($this->games as $gameid => $gamename) {
                $template->assign_block_vars('game_row', array('VALUE' => $gameid, 'SELECTED' => $editmember->game_id == $gameid ? ' selected="selected"' : '', 'OPTION' => $gamename));
            }
        } else {
            trigger_error('ERROR_NOGAMES', E_USER_WARNING);
        }
        foreach ($this->regions as $key => $regionname) {
            $template->assign_block_vars('region_row', array('VALUE' => $key, 'SELECTED' => $editmember->member_region == $key ? ' selected="selected"' : '', 'OPTION' => !empty($regionname) ? $regionname : '(None)'));
        }
        // Rank drop-down -> for initial load
        // reloading is done from ajax to prevent redraw
        $Ranks = new \bbdkp\controller\guilds\Ranks($editmember->member_guild_id);
        $result = $Ranks->listranks();
        while ($row = $db->sql_fetchrow($result)) {
            $template->assign_block_vars('rank_row', array('VALUE' => $row['rank_id'], 'SELECTED' => $editmember->member_rank_id == $row['rank_id'] ? ' selected="selected"' : '', 'OPTION' => !empty($row['rank_name']) ? $row['rank_name'] : '(None)'));
        }
        // Race dropdown
        // reloading is done from ajax to prevent redraw
        $sql_array = array('SELECT' => '  r.race_id, l.name as race_name ', 'FROM' => array(RACE_TABLE => 'r', BB_LANGUAGE => 'l'), 'WHERE' => " r.race_id = l.attribute_id\n\t\t\t\t\t\t\t\tAND r.game_id = '" . $editmember->game_id . "'\n\t\t\t\t\t\t\t\tAND l.attribute='race'\n\t\t\t\t\t\t\t\tAND l.game_id = r.game_id\n\t\t\t\t\t\t\t\tAND l.language= '" . $config['bbdkp_lang'] . "'", 'ORDER_BY' => 'l.name asc');
        $sql = $db->sql_build_query('SELECT', $sql_array);
        $result = $db->sql_query($sql);
        if ($editmember->member_id > 0) {
            while ($row = $db->sql_fetchrow($result)) {
                $template->assign_block_vars('race_row', array('VALUE' => $row['race_id'], 'SELECTED' => $editmember->member_race_id == $row['race_id'] ? ' selected="selected"' : '', 'OPTION' => !empty($row['race_name']) ? $row['race_name'] : '(None)'));
            }
        } else {
            while ($row = $db->sql_fetchrow($result)) {
                $template->assign_block_vars('race_row', array('VALUE' => $row['race_id'], 'SELECTED' => '', 'OPTION' => !empty($row['race_name']) ? $row['race_name'] : '(None)'));
            }
        }
        $db->sql_freeresult($result);
        //
        // Class dropdown
        // reloading is done from ajax to prevent redraw
        $sql_array = array('SELECT' => ' c.class_id, l.name as class_name, c.class_hide,
									  c.class_min_level, class_max_level, c.class_armor_type , c.imagename ', 'FROM' => array(CLASS_TABLE => 'c', BB_LANGUAGE => 'l'), 'WHERE' => " l.game_id = c.game_id  AND c.game_id = '" . $editmember->game_id . "'\n\t\t\t\t\tAND l.attribute_id = c.class_id  AND l.language= '" . $config['bbdkp_lang'] . "' AND l.attribute = 'class' ", 'ORDER_BY' => 'l.name asc');
        $sql = $db->sql_build_query('SELECT', $sql_array);
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            if ($row['class_min_level'] <= 1) {
                $option = !empty($row['class_name']) ? $row['class_name'] . "\n\t\t\t\t\t\t Level (" . $row['class_min_level'] . " - " . $row['class_max_level'] . ")" : '(None)';
            } else {
                $option = !empty($row['class_name']) ? $row['class_name'] . "\n\t\t\t\t\t\t Level " . $row['class_min_level'] . "+" : '(None)';
            }
            if ($editmember->member_id != 0) {
                $template->assign_block_vars('class_row', array('VALUE' => $row['class_id'], 'SELECTED' => $editmember->member_class_id == $row['class_id'] ? ' selected="selected"' : '', 'OPTION' => $option));
            } else {
                $template->assign_block_vars('class_row', array('VALUE' => $row['class_id'], 'SELECTED' => '', 'OPTION' => $option));
            }
        }
        $db->sql_freeresult($result);
        // get roles
        $Roles = new \bbdkp\controller\games\Roles();
        $Roles->game_id = $Guild->game_id;
        $Roles->guild_id = $editmember->member_guild_id;
        $listroles = $Roles->listroles();
        foreach ($listroles as $roleid => $Role) {
            $template->assign_block_vars('role_row', array('VALUE' => $Role['role_id'], 'SELECTED' => $editmember->member_role == $Role['role_id'] ? ' selected="selected"' : '', 'OPTION' => $Role['rolename']));
        }
        // build presets for joindate pulldowns
        $now = getdate();
        $s_memberjoin_day_options = '<option value="0"	>--</option>';
        for ($i = 1; $i < 32; $i++) {
            $day = $editmember->member_id > 0 ? $editmember->member_joindate_d : $now['mday'];
            $selected = $i == $day ? ' selected="selected"' : '';
            $s_memberjoin_day_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
        }
        $s_memberjoin_month_options = '<option value="0">--</option>';
        for ($i = 1; $i < 13; $i++) {
            $month = $editmember->member_id > 0 ? $editmember->member_joindate_mo : $now['mon'];
            $selected = $i == $month ? ' selected="selected"' : '';
            $s_memberjoin_month_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
        }
        $s_memberjoin_year_options = '<option value="0">--</option>';
        for ($i = $now['year'] - 10; $i <= $now['year']; $i++) {
            $yr = $editmember->member_id > 0 ? $editmember->member_joindate_y : $now['year'];
            $selected = $i == $yr ? ' selected="selected"' : '';
            $s_memberjoin_year_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
        }
        // build presets for outdate pulldowns
        $s_memberout_day_options = '<option value="0"' . ($editmember->member_id > 0 ? $editmember->member_outdate != 0 ? '' : ' selected="selected"' : ' selected="selected"') . '>--</option>';
        for ($i = 1; $i < 32; $i++) {
            if ($editmember->member_id > 0 && $editmember->member_outdate != 0) {
                $day = $editmember->member_outdate_d;
                $selected = $i == $day ? ' selected="selected"' : '';
            } else {
                $selected = '';
            }
            $s_memberout_day_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
        }
        $s_memberout_month_options = '<option value="0"' . ($editmember->member_id > 0 ? $editmember->member_outdate != 0 ? '' : ' selected="selected"' : ' selected="selected"') . '>--</option>';
        for ($i = 1; $i < 13; $i++) {
            if ($editmember->member_id > 0 && $editmember->member_outdate != 0) {
                $month = $editmember->member_outdate_mo;
                $selected = $i == $month ? ' selected="selected"' : '';
            } else {
                $selected = '';
            }
            $s_memberout_month_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
        }
        $s_memberout_year_options = '<option value="0"' . ($editmember->member_id > 0 ? $editmember->member_outdate != 0 ? '' : ' selected="selected"' : ' selected="selected"') . '>--</option>';
        for ($i = $now['year'] - 10; $i <= $now['year'] + 10; $i++) {
            if ($editmember->member_id > 0 && $editmember->member_outdate != 0) {
                $yr = $editmember->member_outdate_y;
                $selected = $i == $yr ? ' selected="selected"' : '';
            } else {
                $selected = '';
            }
            $s_memberout_year_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
        }
        // phpbb User dropdown
        $phpbb_user_id = $editmember->member_id > 0 ? $editmember->phpbb_user_id : 0;
        $sql_array = array('SELECT' => ' u.user_id, u.username ', 'FROM' => array(USERS_TABLE => 'u'), 'WHERE' => " u.group_id != 6 and u.group_id != 1 ", 'ORDER_BY' => " u.username ASC");
        $sql = $db->sql_build_query('SELECT', $sql_array);
        $result = $db->sql_query($sql);
        $s_phpbb_user = '******' . ($phpbb_user_id == 0 ? ' selected="selected"' : '') . '>--</option>';
        while ($row = $db->sql_fetchrow($result)) {
            $selected = $row['user_id'] == $phpbb_user_id ? ' selected="selected"' : '';
            $s_phpbb_user .= '<option value="' . $row['user_id'] . '"' . $selected . '>' . $row['username'] . '</option>';
        }
        unset($now);
        $form_key = 'mm_addmember';
        add_form_key($form_key);
        $template->assign_vars(array('L_TITLE' => $user->lang['ACP_MM_ADDMEMBER'], 'L_EXPLAIN' => $user->lang['ACP_MM_ADDMEMBER_EXPLAIN'], 'F_ADD_MEMBER' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_mm&amp;mode=mm_addmember&amp;"), 'STATUS' => $editmember->member_status == 1 ? 'checked="checked"' : '', 'MEMBER_NAME' => $editmember->member_name, 'MEMBER_ID' => $editmember->member_id, 'MEMBER_LEVEL' => $editmember->member_level, 'REALM' => $editmember->member_realm, 'DEACTIVATE_REASON' => $editmember->deactivate_reason == '' ? '' : $user->lang[$editmember->deactivate_reason], 'STATUS_LOCK' => $editmember->deactivate_reason == '' ? false : true, 'MEMBER_ACHIEV' => $editmember->member_achiev, 'MEMBER_TITLE' => $editmember->member_title, 'MALE_CHECKED' => $editmember->member_gender_id == '0' ? ' checked="checked"' : '', 'FEMALE_CHECKED' => $editmember->member_gender_id == '1' ? ' checked="checked"' : '', 'MEMBER_COMMENT' => $editmember->member_comment, 'S_CAN_HAVE_ARMORY' => $editmember->game_id == 'wow' || $editmember->game_id == 'aion' ? true : false, 'MEMBER_URL' => $editmember->member_armory_url, 'MEMBER_PORTRAIT' => $editmember->member_portrait_url, 'S_MEMBER_PORTRAIT_EXISTS' => strlen($editmember->member_portrait_url) > 1 ? true : false, 'S_CAN_GENERATE_ARMORY' => $editmember->game_id == 'wow' ? true : false, 'COLORCODE' => $editmember->colorcode == '' ? '#254689' : $editmember->colorcode, 'CLASS_IMAGE' => $editmember->class_image, 'S_CLASS_IMAGE_EXISTS' => strlen($editmember->class_image) > 1 ? true : false, 'RACE_IMAGE' => $editmember->race_image, 'S_RACE_IMAGE_EXISTS' => strlen($editmember->race_image) > 1 ? true : false, 'S_JOINDATE_DAY_OPTIONS' => $s_memberjoin_day_options, 'S_JOINDATE_MONTH_OPTIONS' => $s_memberjoin_month_options, 'S_JOINDATE_YEAR_OPTIONS' => $s_memberjoin_year_options, 'S_OUTDATE_DAY_OPTIONS' => $s_memberout_day_options, 'S_OUTDATE_MONTH_OPTIONS' => $s_memberout_month_options, 'S_OUTDATE_YEAR_OPTIONS' => $s_memberout_year_options, 'S_PHPBBUSER_OPTIONS' => $s_phpbb_user, 'TITLE_NAME' => $editmember->game_id == 'wow' ? sprintf($editmember->member_title, $editmember->member_name) : '', 'LA_ALERT_AJAX' => $user->lang['ALERT_AJAX'], 'LA_ALERT_OLDBROWSER' => $user->lang['ALERT_OLDBROWSER'], 'LA_MSG_NAME_EMPTY' => $user->lang['FV_REQUIRED_NAME'], 'UA_FINDRANK' => append_sid($phpbb_admin_path . "style/dkp/findrank.{$phpEx}"), 'UA_FINDCLASSRACE' => append_sid($phpbb_admin_path . "style/dkp/findclassrace.{$phpEx}"), 'S_ADD' => $S_ADD));
        $this->page_title = 'ACP_MM_ADDMEMBER';
        $this->tpl_name = 'dkp/acp_' . $mode;
    }
Exemple #3
0
 /**
  * list dkp points per pool and member
  */
 private function list_memberdkp()
 {
     global $user, $template, $config, $phpbb_admin_path, $phpEx;
     $pagination = '';
     // guild dropdown
     $submit = isset($_POST['member_guild_id']) ? true : false;
     $Guild = new \bbdkp\controller\guilds\Guilds();
     $guildlist = $Guild->guildlist(1);
     if ($submit) {
         $Guild->guildid = request_var('member_guild_id', 0);
     } else {
         foreach ($guildlist as $g) {
             $Guild->guildid = $g['id'];
             $Guild->name = $g['name'];
             if ($Guild->guildid == 0 && $Guild->name == 'Guildless') {
                 trigger_error('ERROR_NOGUILD', E_USER_WARNING);
             }
             break;
         }
     }
     foreach ($guildlist as $g) {
         $template->assign_block_vars('guild_row', array('VALUE' => $g['id'], 'SELECTED' => $g['id'] == $Guild->guildid ? ' selected="selected"' : '', 'OPTION' => !empty($g['name']) ? $g['name'] : '(None)'));
     }
     $this->PointsController->guild_id = $Guild->guildid;
     $this->PointsController->show_inactive = false;
     /* dkp pool */
     $this->PointsController->query_by_pool = true;
     $this->PointsController->dkpsys_id = 0;
     if (isset($_GET[URI_DKPSYS]) or isset($_POST[URI_DKPSYS])) {
         //user clicked on add raid from event editscreen
         $this->PointsController->dkpsys_id = request_var(URI_DKPSYS, 0);
     }
     if ($this->PointsController->dkpsys_id == 0) {
         if (count((array) $this->PointsController->dkpsys) == 0) {
             trigger_error('ERROR_NOPOOLS', E_USER_WARNING);
         }
         //get default dkp pool
         foreach ($this->PointsController->dkpsys as $pool) {
             if ($pool['default'] == 'Y') {
                 $this->PointsController->dkpsys_id = $pool['id'];
                 break;
             }
         }
         //if still 0 then get first one
         if ($this->PointsController->dkpsys_id == 0) {
             foreach ($this->PointsController->dkpsys as $pool) {
                 $this->PointsController->dkpsys_id = $pool['id'];
                 break;
             }
         }
     }
     foreach ($this->PointsController->dkpsys as $pool) {
         $template->assign_block_vars('dkpsys_row', array('VALUE' => $pool['id'], 'SELECTED' => $pool['id'] == $this->PointsController->dkpsys_id ? ' selected="selected"' : '', 'OPTION' => !empty($pool['name']) ? $pool['name'] : '(None)'));
     }
     /***  end drop-down query ***/
     $start = request_var('start', 0, false);
     $this->PointsController->member_filter = utf8_normalize_nfc(request_var('member_name', '', true));
     if ($this->PointsController->member_filter != '') {
         $this->PointsController->query_by_name = true;
     }
     if ($config['bbdkp_epgp'] == '1') {
         $memberlist = $this->PointsController->listEPGPaccounts($start, true);
     } else {
         $memberlist = $this->PointsController->listdkpaccounts($start, true);
     }
     $current_order = $memberlist[1];
     $lines = $memberlist[2];
     // all accounts
     $membersids = array();
     if ($lines > 0) {
         foreach ($memberlist[0] as $member_id => $dkp) {
             $template->assign_block_vars('members_row', $dkp);
             $membersids[$member_id] = 1;
         }
         if ($this->PointsController->query_by_name == true) {
             $pagination = generate_pagination(append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_mdkp&mode=mm_listmemberdkp&amp;member_name=" . $this->PointsController->member_filter . "&amp;o=" . $current_order['uri']['current']), $lines, $config['bbdkp_user_llimit'], $start, true, 'start');
         } else {
             $pagination = generate_pagination(append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_mdkp&mode=mm_listmemberdkp&amp;o=" . $current_order['uri']['current']), $lines, $config['bbdkp_user_llimit'], $start, true, 'start');
         }
     }
     /***  Labels  ***/
     $footcount_text = sprintf($user->lang['LISTMEMBERS_FOOTCOUNT'], $lines);
     $output = array('IDLIST' => implode(",", $membersids), 'F_MEMBERS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_mdkp&amp;mode=mm_listmemberdkp&amp;") . '&amp;mode=mm_editmemberdkp', 'L_TITLE' => $user->lang['ACP_DKP_LISTMEMBERDKP'], 'L_EXPLAIN' => $user->lang['ACP_MM_LISTMEMBERDKP_EXPLAIN'], 'BUTTON_NAME' => 'delete', 'BUTTON_VALUE' => $user->lang['DELETE_SELECTED_MEMBERS'], 'O_NAME' => $current_order['uri'][1], 'O_RANK' => $current_order['uri'][2], 'O_LEVEL' => $current_order['uri'][3], 'O_CLASS' => $current_order['uri'][4], 'O_RAIDVALUE' => $current_order['uri'][5], 'O_ADJUSTMENT' => $current_order['uri'][10], 'O_SPENT' => $current_order['uri'][12], 'O_LASTRAID' => $current_order['uri'][17], 'S_SHOWZS' => $config['bbdkp_zerosum'] == '1' ? true : false, 'S_SHOWDECAY' => $config['bbdkp_decay'] == '1' ? true : false, 'S_SHOWEPGP' => $config['bbdkp_epgp'] == '1' ? true : false, 'S_SHOWTIME' => $config['bbdkp_timebased'] == '1' ? true : false, 'U_LIST_MEMBERDKP' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_mdkp&amp;" . URI_DKPSYS . "=" . $this->PointsController->dkpsys_id . "&amp;mode=mm_listmemberdkp") . '&amp;mod=list&amp;', 'S_NOTMM' => false, 'LISTMEMBERS_FOOTCOUNT' => $footcount_text, 'DKPSYS' => $this->PointsController->dkpsys_id, 'DKPSYSNAME' => $this->PointsController->dkpsys[$this->PointsController->dkpsys_id]['name'], 'PAGINATION' => $pagination, 'MEMBER_NAME' => $this->PointsController->member_filter);
     if ($config['bbdkp_timebased'] == 1) {
         $output['O_TIMEBONUS'] = $current_order['uri'][6];
     }
     if ($config['bbdkp_zerosum'] == 1) {
         $output['O_ZSBONUS'] = $current_order['uri'][7];
     }
     if ($config['bbdkp_decay'] == 1) {
         $output['O_RDECAY'] = $current_order['uri'][9];
         $output['O_IDECAY'] = $current_order['uri'][13];
     }
     if ($config['bbdkp_epgp'] == 1) {
         $output['O_EP'] = $current_order['uri'][11];
         $output['O_GP'] = $current_order['uri'][14];
         $output['O_PR'] = $current_order['uri'][15];
     } else {
         $output['O_EARNED'] = $current_order['uri'][8];
         $output['O_CURRENT'] = $current_order['uri'][16];
     }
     $template->assign_vars($output);
 }
Exemple #4
0
    public function __construct()
    {
        //global phpbb vars
        global $config, $db, $user, $phpbb_root_path, $phpbb_admin_path, $phpEx;
        $user->add_lang(array('mods/dkp_raidtracker'));
        $raidid = request_var('r', 0);
        if ($raidid == 0) {
            trigger_error($user->lang['RT_STEP2_ERR_RAIDID'], E_USER_WARNING);
        }
        $this->Raidtrackerlink = '<br /><a href="' . append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_rt_import&amp;mode=rt_import") . '"><h3>Return to Index</h3></a>';
        $batchid = '';
        // get raidinfo
        $sql = 'SELECT event_id, dkpsys_id, batchid, realm, starttime, endtime , zone, note, difficulty, raidvalue
			FROM ' . RT_TEMP_RAIDINFO . ' where raidid = ' . (int) $raidid;
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $batchid = $row['batchid'];
            $this->Raid = array('batchid' => $batchid, 'raidid' => $raidid, 'realm' => $row['realm'], 'starttime' => $row['starttime'], 'endtime' => $row['endtime'], 'zone' => $row['zone'], 'note' => $row['note'], 'difficulty' => $row['difficulty'], 'event_id' => $row['event_id'], 'dkpsys_id' => $row['dkpsys_id'], 'raidvalue' => $row['raidvalue']);
        }
        $db->sql_freeresult($result);
        /**
         * populate guild list
         *
         */
        $Guild = new \bbdkp\controller\guilds\Guilds();
        $guildlist = $Guild->guildlist(1);
        foreach ($guildlist as $g) {
            $this->guild[] = array('id' => $g['id'], 'selected' => '', 'name' => $g['name']);
        }
        // playerinfo and calculation of Time bonus
        $sql_array = array('SELECT' => 'p.playerid, p.playername, p.guild, p.race, p.sex,
							p.class, p.level, j.jointime, j.leavetime, j.realm  ', 'FROM' => array(RT_TEMP_PLAYERINFO => 'p', RT_TEMP_JOININFO => 'j'), 'WHERE' => "j.batchid = p.batchid AND j.playername = p.playername\n\t\t\t\t\tAND p.batchid = '" . $batchid . "'", 'ORDER_BY' => "p.playername ASC, j.jointime ASC");
        $sql = $db->sql_build_query('SELECT', $sql_array);
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $time_bonus = 0;
            $cmins = 0;
            $chours = 0;
            $diff = $this->get_time_difference($row['jointime'], $row['leavetime']);
            // express in minutes
            $timediff = $diff['hours'] * 60 + $diff['minutes'];
            $timeunits = intval($timediff / $config['bbdkp_timeunit']);
            // convert to number of earned timeunits
            $cmins = $timeunits * $config['bbdkp_timeunit'] / 60 - floor($timeunits * $config['bbdkp_timeunit'] / 60);
            //get back counted time
            $chours = intval($timeunits * $config['bbdkp_timeunit'] / 60);
            if ($config['bbdkp_timebased'] == '1') {
                //if we have a $config interval bigger than 0 minutes then calculate time bonus
                if ((int) $config['bbdkp_timeunit'] > 0) {
                    $time_bonus = round($config['bbdkp_dkptimeunit'] * $timeunits, 2);
                }
            }
            $allplayerinfo[$row['playerid']] = array('jointime' => $row['jointime'], 'leavetime' => $row['leavetime'], 'raiddurationtime' => sprintf("%02d", $chours) . ':' . sprintf("%02d", $cmins), 'timebasis' => round($config['bbdkp_dkptimeunit'] / $config['bbdkp_timeunit'], 2), 'timebonus' => $time_bonus, 'memberid' => 0, 'name' => $row['playername'], 'playerid' => $row['playerid'], 'race' => $row['race'], 'class' => $row['class'], 'level' => $row['level'], 'guild' => $row['guild'], 'sex' => $row['sex'], 'realm' => $row['realm']);
        }
        $db->sql_freeresult($result);
        $this->Raid['allplayerinfo'] = $allplayerinfo;
        /*
         * add attendees to raid
         */
        $totalplayernr = 0;
        $attendingplayers = '';
        switch ($config['bbdkp_rt_attendancefilter']) {
            case RT_AF_NONE:
                // attendance set to all : all players in the raid
                foreach ($allplayerinfo as $player) {
                    $attendingplayers[] = $player['name'];
                    $totalplayernr++;
                }
                break;
            default:
                // attendance set for boss or loot kill : all players present at bosskill
                $sql = 'SELECT distinct playername, realm FROM ' . RT_TEMP_ATTENDEES . " where batchid = '" . $batchid . "' order by playername";
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    if (strlen($row['realm']) > 3) {
                        $attendingplayers[] = $row['playername'] . '-' . $row['realm'];
                    } else {
                        $attendingplayers[] = $row['playername'];
                    }
                    $totalplayernr += 1;
                }
                $db->sql_freeresult($result);
                // there was no bosskill?
                if ($totalplayernr == 0) {
                    foreach ($allplayerinfo as $player) {
                        if (strlen($player['realm']) > 3) {
                            $attendingplayers[] = $player['name'] . '-' . $player['realm'];
                        } else {
                            $attendingplayers[] = $player['name'];
                        }
                        $totalplayernr++;
                    }
                }
                break;
        }
        $this->Raid['playersattending'] = $attendingplayers;
        /*
         * loop bossarray
         */
        $Bosskills = array();
        $lootid = 0;
        $sql_array = array('SELECT' => 'b.bossid, b.bossname , b.time, b.difficulty, b.raidvalue ', 'FROM' => array(RT_TEMP_BOSSKILLS => 'b'), 'WHERE' => " b.batchid = '" . $db->sql_escape($batchid) . "'", 'ORDER_BY' => ' b.time ');
        $sql = $db->sql_build_query('SELECT', $sql_array);
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            // initialise loop variables
            $bossattendees = array();
            $loot = array();
            $nr_boss_attendees = 0;
            /* adding attendees */
            $sql_array2 = array('SELECT' => 'n.playername ', 'FROM' => array(RT_TEMP_ATTENDEES => 'n'), 'WHERE' => " n.bossname = '" . $db->sql_escape($row['bossname']) . "'\n\t\t\t\t\tAND\t n.batchid = '" . $db->sql_escape($batchid) . "'", 'ORDER_BY' => 'n.playername');
            $sql2 = $db->sql_build_query('SELECT', $sql_array2);
            $result2 = $db->sql_query($sql2);
            while ($row2 = $db->sql_fetchrow($result2)) {
                $nr_boss_attendees++;
                $bossattendees[] = $row2['playername'];
            }
            $db->sql_freeresult($result2);
            /* adding loot for this boss */
            // set boss lootcounter to 0
            $sql_array3 = array('SELECT' => 'b.bossname, l.itemid, l.itemname, l.playername, l.time, l.note, l.cost, l.realm	', 'FROM' => array(RT_TEMP_BOSSKILLS => 'b', RT_TEMP_LOOT => 'l'), 'WHERE' => " b.bossname = l.boss\n\t\t\t\t\t\t  AND l.itemid NOT IN ( SELECT ignore_items_wow_id FROM " . RT_IGNORE_ITEMS_TABLE . " )\n\t\t\t\t\t\t  AND b.bossname = '" . $db->sql_escape($row['bossname']) . "'\n\t\t\t\t\t\t  AND b.batchid = l.batchid\n\t\t\t\t\t\t  AND b.batchid = '" . $db->sql_escape($batchid) . "'");
            $sql3 = $db->sql_build_query('SELECT', $sql_array3);
            $result3 = $db->sql_query($sql3);
            // loop loot of this boss
            while ($row3 = $db->sql_fetchrow($result3)) {
                $loot[] = array('lootnr' => $lootid, 'itemid' => $row3['itemid'], 'itemname' => $row3['itemname'], 'playername' => $row3['playername'], 'realm' => $row3['realm'], 'loottime' => date("Z", $row3['time']), 'lootnote' => $row3['note'], 'cost' => $row3['cost'] > 0.0 ? $row3['cost'] : number_format($config['bbdkp_rt_defaultcost'], 2));
                $lootid++;
            }
            $db->sql_freeresult($result3);
            /* combining attendees and loot into boss array */
            $Bosskills[] = array('bossname' => $row['bossname'], 'time' => $row['time'], 'difficulty' => $row['difficulty'], 'raidvalue' => $row['raidvalue'], 'bossattendees' => $bossattendees, 'countattendees' => $nr_boss_attendees, 'loot' => $loot);
            // unset for next loop
            unset($bossattendees);
            unset($nr_boss_attendees);
            unset($loot);
        }
        $db->sql_freeresult($result);
        /*** adding trash mobs ****/
        // get own raids. there has to be an own raid called "Trash mob"
        $sql = "SELECT * FROM " . RT_OWN_RAIDS_TABLE;
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $this->ownraid[] = $row['own_raid_name'];
        }
        $db->sql_freeresult($result);
        //match between own raids and Temp loot table but not matching bosskill table or ignored items
        $sql_array = array('SELECT' => 'b.own_raid_name, l.itemid, l.itemname, l.playername, l.time, l.note, l.cost, l.realm ', 'FROM' => array(RT_OWN_RAIDS_TABLE => 'b', RT_TEMP_LOOT => 'l'), 'WHERE' => ' b.own_raid_name = l.boss
				  AND b.own_raid_name NOT IN (SELECT bossname FROM ' . RT_TEMP_BOSSKILLS . " where batchid = '" . $db->sql_escape($batchid) . "' )\n\t\t\t\t  AND l.itemid NOT IN ( SELECT ignore_items_wow_id FROM " . RT_IGNORE_ITEMS_TABLE . " )\n\t\t\t\t  AND l.batchid = '" . $db->sql_escape($batchid) . "'");
        $sql = $db->sql_build_query('SELECT', $sql_array);
        $result = $db->sql_query($sql);
        $nr_ownraid_attendees = 0;
        $loot = array();
        $bossattendees = array();
        while ($row = $db->sql_fetchrow($result)) {
            $own_raid_name = $row['own_raid_name'];
            $loot[] = array('lootnr' => $lootid, 'itemid' => $row['itemid'], 'itemname' => $row['itemname'], 'playername' => $row['playername'], 'realm' => $row['realm'], 'loottime' => date("Z", $row['time']), 'lootnote' => $row['note'], 'cost' => $row['cost'] > 0.0 ? $row['cost'] : number_format($config['bbdkp_rt_defaultcost'], 2));
            ++$lootid;
            $bossattendees[] = $row['playername'];
        }
        $db->sql_freeresult($result);
        $bossattendees = array_unique($bossattendees);
        if (count($loot) > 0 && count($bossattendees) > 0) {
            // add trash mob loot to $boskills
            $Bosskills[] = array('bossname' => (string) $own_raid_name, 'time' => (int) $this->Raid['starttime'], 'difficulty' => 1, 'raidvalue' => 0.0, 'bossattendees' => (array) $bossattendees, 'countattendees' => (int) count($bossattendees), 'loot' => (array) $loot);
        }
        /* adding boss array to raid */
        $this->Raid['bosskills'] = $Bosskills;
        //unsetting
        unset($Bosskills);
        unset($loot);
        unset($bossattendees);
        /*
         * populate dkp pool list
         */
        $sql = 'SELECT dkpsys_name, dkpsys_id, dkpsys_default FROM ' . DKPSYS_TABLE;
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $this->dkplist[] = array('dkpsys_id' => $row['dkpsys_id'], 'dkpsys_name' => $row['dkpsys_name']);
        }
        $db->sql_freeresult($result);
        /*
         * Populate Eventlist of this dkp pool
         */
        $sql_array = array('SELECT' => 'b.event_name, b.event_id , b.event_value ', 'FROM' => array(EVENTS_TABLE => 'b'), 'WHERE' => ' b.event_dkpid = ' . intval($this->Raid['dkpsys_id']), 'ORDER_BY' => ' b.event_id ');
        $sql = $db->sql_build_query('SELECT', $sql_array);
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            if ($row['event_id'] == $this->Raid['event_id']) {
                $this->Raid['event_value'] = $row['event_value'];
            }
            $this->eventlist[] = array('event_id' => $row['event_id'], 'event_name' => $row['event_name'], 'event_value' => $row['event_value']);
        }
        $db->sql_freeresult($result);
        // display the form
        $this->display_form();
    }
Exemple #5
0
 public function raid_check()
 {
     global $db, $user, $config;
     global $phpbb_root_path, $phpbb_admin_path, $phpEx;
     /* Input Cleanup */
     $log = utf8_normalize_nfc(request_var('raidlog', ' ', true));
     $log = str_replace("&", "and", html_entity_decode($log));
     if (strlen($log) <= 1) {
         trigger_error($user->lang['RT_STEP1_NODATA'] . $this->Raidtrackerlink, E_USER_WARNING);
     }
     /*
      * validate xml
      *
      */
     // switch on libxml error handler
     libxml_use_internal_errors(true);
     // load and set CDATA as Text nodes
     // returns a SimpleXMLElement  object
     $this->doc = simplexml_load_string($log, 'SimpleXMLElement', LIBXML_NOCDATA);
     $xml = explode("\n", $log);
     if (!$this->doc) {
         $errors = libxml_get_errors();
         if (!empty($errors)) {
             $message = '';
             foreach ($errors as $error) {
                 $message .= utf8_htmlspecialchars($xml[$error->line - 1]) . '<br />' . utf8_htmlspecialchars($xml[$error->line]) . '<br />' . utf8_htmlspecialchars($xml[$error->line + 1]) . "<br />";
                 switch ($error->level) {
                     case LIBXML_ERR_WARNING:
                         $message .= "Warning {$error->code}: ";
                         break;
                     case LIBXML_ERR_ERROR:
                         $message .= "Error {$error->code}: ";
                         break;
                     case LIBXML_ERR_FATAL:
                         $message .= "Fatal Error {$error->code}: ";
                         break;
                 }
                 $message .= trim($error->message) . '. ' . "Line: {$error->line}, " . "Column: {$error->column}<br />";
                 if ($error->file) {
                     $message .= "  File: {$error->file}<br />";
                 }
                 $message .= "--------------------------------------------<br />";
             }
             $message = $user->lang['RT_STEP1_INVALIDSTRING_MSG'] . '<br />--------------------------------------------<br />' . $message;
             // set error handler off - to free memory
             libxml_clear_errors();
             // display errors
             trigger_error($message . $this->Raidtrackerlink, E_USER_WARNING);
         }
     }
     /**********************************************************
      * validate tags before processing
      **********************************************************/
     //check realm
     $this->realm = 'n/a';
     if (isset($this->doc->realm)) {
         $this->realm = (string) $this->doc->realm[0];
     } else {
         //define realm from bbdkp default guild
         $Guild = new \bbdkp\controller\guilds\Guilds();
         $guildlist = $Guild->guildlist(1);
         foreach ($guildlist as $g) {
             if ($this->realm == 'n/a') {
                 $this->realm = $g['realm'];
             }
         }
     }
     // check start tag
     if (isset($this->doc->start)) {
         $this->start = (int) is_numeric((string) $this->doc->start[0]) ? (string) $this->doc->start[0] : strtotime((string) $this->doc->start[0]);
     } else {
         trigger_error($user->lang['RT_ERR_NOSTARTTAG'] . $this->Raidtrackerlink, E_USER_WARNING);
     }
     /*you can't parse a raid twice : check for an already parsed raid 30 minutes before or after this one */
     $sql = ' select count(*) as checktime from ' . RT_TEMP_RAIDINFO . ' ';
     $sql .= ' where (starttime < ' . strval($this->start + 1800) . ' ) and ( starttime  > ' . strval($this->start - 1800) . ' ) ';
     $result = $result = $db->sql_query($sql);
     $checkexists = (int) $db->sql_fetchfield('checktime');
     $db->sql_freeresult($result);
     if ($checkexists != 0) {
         trigger_error($user->lang['RT_ERR_DUPLICATE'] . $this->Raidtrackerlink, E_USER_WARNING);
     }
     //raid end
     if (isset($this->doc->end)) {
         $this->end = (int) is_numeric((string) $this->doc->end[0]) ? (string) $this->doc->end[0] : strtotime((string) $this->doc->end[0]);
     } else {
         trigger_error($user->lang['RT_ERR_NOENDTAG'] . $this->Raidtrackerlink, E_USER_WARNING);
     }
     //check if there is a bosskill tag
     $this->Bosskills = array();
     if (isset($this->doc->BossKills)) {
         $this->Bosskills = (array) $this->doc->BossKills[0];
         if (sizeof($this->Bosskills) > 0) {
             foreach ($this->Bosskills as $key => $Bosskill) {
                 $Bosskill = (array) $Bosskill;
                 $bosskilltime[] = (int) is_numeric((string) $Bosskill['time']) ? (string) $Bosskill['time'] : strtotime((string) $Bosskill['time']);
             }
             if ($this->end == 0) {
                 // assume end at last bosskill time
                 $this->end = max($bosskilltime) + 10;
             }
         }
     }
     if (!isset($this->doc->PlayerInfos)) {
         trigger_error($user->lang['RT_ERR_NOPLAYERINFOSTAG'] . $this->Raidtrackerlink, E_USER_WARNING);
     }
     if (!isset($this->doc->PlayerInfos->key1->name)) {
         // no name tag
         trigger_error($user->lang['RT_ERR_NOPLAYER_NAME_STAG'] . $this->Raidtrackerlink, E_USER_WARNING);
     }
     if (!isset($this->doc->PlayerInfos->key1->race)) {
         // no race tag
         trigger_error($user->lang['RT_ERR_NOPLAYER_RACE_TAG'] . $this->Raidtrackerlink, E_USER_WARNING);
     }
     if (!isset($this->doc->PlayerInfos->key1->class)) {
         // no class tag
         trigger_error($user->lang['RT_ERR_NOPLAYER_CLASS_TAG'] . $this->Raidtrackerlink, E_USER_WARNING);
     }
     if (!isset($this->doc->PlayerInfos->key1->level)) {
         // no level tag
         trigger_error($user->lang['RT_ERR_NOPLAYER_LEVEL_TAG'] . $this->Raidtrackerlink, E_USER_WARNING);
     }
     if (!isset($this->doc->Join)) {
         trigger_error($user->lang['RT_ERR_NOJOINTAG'] . $this->Raidtrackerlink, E_USER_WARNING);
     }
     if (!isset($this->doc->Leave)) {
         trigger_error($user->lang['RT_ERR_NOLEAVETAG'] . $this->Raidtrackerlink, E_USER_WARNING);
     }
     return true;
 }
 /**
  * Main
  *
  * @param $id
  * @param $mode
  */
 public function main($id, $mode)
 {
     global $db, $user, $auth, $template, $cache;
     global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
     $user->add_lang(array('mods/raidplanner', 'mods/dkp_common'));
     if (!$auth->acl_get('a_raid_config')) {
         trigger_error($user->lang['USER_CANNOT_MANAGE_RAIDPLANNER']);
     }
     // main tabs
     $template->assign_vars(array('RAIDPLANNER_VERSION' => $config['bbdkp_raidplanner'], 'U_RP_PLANNER_SETTINGS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=raidplanner&amp;mode=rp_settings"), 'U_RP_CAL_SETTINGS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=raidplanner&amp;mode=rp_cal_settings"), 'U_RP_TEAMS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=raidplanner&amp;mode=rp_teams"), 'U_RP_TEAMSLIST' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=raidplanner&amp;mode=rp_teams"), 'U_RP_TEAMSEDIT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=raidplanner&amp;mode=rp_teams_edit"), 'U_RP_COMPOSITION' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=raidplanner&amp;mode=rp_composition")));
     $link = '<br /><a href="' . append_sid("{$phpbb_root_path}adm/index.{$phpEx}", "i=raidplanner&amp;mode={$mode}") . '"><p>' . $user->lang['RETURN_RP'] . '</p></a>';
     if (!class_exists('\\bbdkp\\admin\\Admin')) {
         require "{$phpbb_root_path}includes/bbdkp/admin/admin.{$phpEx}";
     }
     $bbdkp = new \bbdkp\admin\Admin();
     switch ($mode) {
         case 'rp_settings':
             $update = isset($_POST['update_rp_settings']) ? true : false;
             // check the form key
             if ($update) {
                 if (!check_form_key('acp_raidplanner')) {
                     trigger_error('FORM_INVALID');
                 }
             }
             // update Raidplan settings
             if ($update) {
                 $invitehour = request_var('event_invite_hh', 0) * 60 + request_var('event_invite_mm', 0);
                 set_config('rp_default_invite_time', $invitehour, 0);
                 $starthour = request_var('event_start_hh', 0) * 60 + request_var('event_start_mm', 0);
                 set_config('rp_default_start_time', $starthour, 0);
                 $endhour = request_var('event_end_hh', 0) * 60 + request_var('event_end_mm', 0);
                 set_config('rp_default_end_time', $endhour, 0);
                 $freezetime = request_var('freeze_time', 0);
                 set_config('rp_default_freezetime', $freezetime, 0);
                 $expire_time = request_var('expire_time', 0);
                 set_config('rp_default_expiretime', $expire_time, 0);
                 $rp_enable_past_raids = request_var('rp_enable_past_raids', 0);
                 set_config('rp_enable_past_raids', $rp_enable_past_raids, 0);
                 $disp_upcoming = request_var('disp_next_raidplans', 0);
                 set_config('rp_display_next_raidplans', $disp_upcoming, 0);
                 $send_pm_rpchange = request_var('send_pm_rpchange', 0);
                 set_config('rp_pm_rpchange', $send_pm_rpchange, 0);
                 $send_email_rpchange = request_var('send_email_rpchange', 0);
                 set_config('rp_email_rpchange', $send_email_rpchange, 0);
                 $send_pm_signup = request_var('send_pm_signup', 0);
                 set_config('rp_pm_signup', $send_pm_signup, 0);
                 $send_email_signup = request_var('send_email_signup', 0);
                 set_config('rp_email_signup', $send_email_signup, 0);
                 $push_mode = request_var('push_mode', 0);
                 set_config('rp_rppushmode', $push_mode, 0);
                 $cache->destroy('config');
                 $message = "";
                 $message .= '<br />' . sprintf($user->lang['RPSETTINGS_UPDATED'], E_USER_NOTICE);
                 meta_refresh(1, $this->u_action);
                 trigger_error($message . $link);
             }
             // build presets for invite hour pulldown
             $invhour = intval($config['rp_default_invite_time'] / 60);
             for ($i = 0; $i <= 23; $i++) {
                 $template->assign_block_vars('event_invite_hh', array('KEY' => $i, 'VALUE' => $i, 'SELECTED' => $i == $invhour ? ' selected="selected"' : ''));
             }
             // build presets for invite minute pulldown
             $invmin = $config['rp_default_invite_time'] - $invhour * 60;
             for ($i = 0; $i <= 59; $i++) {
                 $template->assign_block_vars('event_invite_mm', array('KEY' => $i, 'VALUE' => $i, 'SELECTED' => $i == $invmin ? ' selected="selected"' : ''));
             }
             // build presets for start hour pulldown
             $starthour = intval($config['rp_default_start_time'] / 60);
             for ($i = 0; $i <= 23; $i++) {
                 $template->assign_block_vars('event_start_hh', array('KEY' => $i, 'VALUE' => $i, 'SELECTED' => $i == $starthour ? ' selected="selected"' : ''));
             }
             // build presets for start minute pulldown
             $startmin = $config['rp_default_start_time'] - $starthour * 60;
             for ($i = 0; $i <= 59; $i++) {
                 $template->assign_block_vars('event_start_mm', array('KEY' => $i, 'VALUE' => $i, 'SELECTED' => $i == $startmin ? ' selected="selected"' : ''));
             }
             // build presets for end hour pulldown
             $endhour = intval($config['rp_default_end_time'] / 60);
             for ($i = 0; $i <= 23; $i++) {
                 $template->assign_block_vars('event_end_hh', array('KEY' => $i, 'VALUE' => $i, 'SELECTED' => $i == $endhour ? ' selected="selected"' : ''));
             }
             // build presets for end minute pulldown
             $endmin = $config['rp_default_end_time'] - $endhour * 60;
             for ($i = 0; $i <= 59; $i++) {
                 $template->assign_block_vars('event_end_mm', array('KEY' => $i, 'VALUE' => $i, 'SELECTED' => $i == $endmin ? ' selected="selected"' : ''));
             }
             $template->assign_vars(array('RAIDPLANNER_VERSION' => $config['bbdkp_raidplanner'], 'ENABLEPASTRAIDS_CHECKED' => (int) $config['rp_enable_past_raids'] == 1 ? "checked='checked'" : '', 'FROZEN_TIME' => $config['rp_default_freezetime'], 'EXPIRE_TIME' => $config['rp_default_expiretime'], 'DISP_NEXT_EVENTS_DISABLED' => $config['rp_index_display_week'] == 1 ? "disabled='disabled'" : '', 'DISP_NEXT_EVENTS' => $config['rp_display_next_raidplans'], 'DISP_EVENTS_1_DAY_CHECKED' => $config['rp_disp_raidplans_only_on_start'] == '1' ? "checked='checked'" : '', 'SEL_AUTOPUSHRAIDPLAN' => (int) $config['rp_rppushmode'] == 0 ? "selected='selected'" : '', 'SEL_MANUALPUSHRAIDPLAN' => (int) $config['rp_rppushmode'] == 1 ? "selected='selected'" : '', 'SEL_NOPUSHRAIDPLAN' => (int) $config['rp_rppushmode'] == 2 ? "selected='selected'" : '', 'SENDPMRP_CHECKED' => (int) $config['rp_pm_rpchange'] == 1 ? "checked='checked'" : '', 'SENDEMAILRP_CHECKED' => (int) $config['rp_email_rpchange'] == 1 ? "checked='checked'" : '', 'SENDPMSIGN_CHECKED' => (int) $config['rp_pm_signup'] == 1 ? "checked='checked'" : '', 'SENDEMAILSIGN_CHECKED' => (int) $config['rp_email_signup'] == 1 ? "checked='checked'" : '', 'PRUNE_FREQ' => (int) $config['rp_prune_frequency'] / 86400, 'PRUNE_LIMIT' => (int) $config['rp_prune_limit'] / 86400, 'POPULATE_FREQ' => (int) $config['rp_populate_frequency'] / 86400, 'POPULATE_LIMIT' => (int) $config['rp_populate_limit'] / 86400, 'U_PLUS_HOUR' => $this->u_action . "&amp;calPlusHour=1&amp;plusVal=1", 'U_MINUS_HOUR' => $this->u_action . "&amp;calPlusHour=1&amp;plusVal=0", 'U_ACTION' => $this->u_action));
             $this->tpl_name = 'dkp/acp_' . $mode;
             $form_key = 'acp_raidplanner';
             add_form_key($form_key);
             break;
         case 'rp_cal_settings':
             $updatecal = isset($_POST['update_rp_settings_cal']) ? true : false;
             // check the form key
             if ($updatecal) {
                 if (!check_form_key('acp_raidplanner')) {
                     trigger_error('FORM_INVALID');
                 }
             }
             // update all calendar settings
             if ($updatecal) {
                 set_config('rp_show_welcomemsg', isset($_POST['show_welcome']) ? 1 : 0, 0);
                 $text = utf8_normalize_nfc(request_var('welcome_message', '', true));
                 $uid = $bitfield = $options = '';
                 // will be modified by generate_text_for_storage
                 $allow_bbcode = $allow_urls = $allow_smilies = true;
                 generate_text_for_storage($text, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
                 $sql = 'UPDATE ' . RP_RAIDPLAN_ANNOUNCEMENT . " SET\n\t\t\t\t\t\t\tannouncement_msg = '" . (string) $db->sql_escape($text) . "' ,\n\t\t\t\t\t\t\tannouncement_timestamp = " . (int) time() . " ,\n\t\t\t\t\t\t\tbbcode_bitfield = \t'" . (string) $bitfield . "' ,\n\t\t\t\t\t\t\tbbcode_uid = \t\t'" . (string) $uid . "'\n\t\t\t\t\t\t\tWHERE announcement_id = 1";
                 $db->sql_query($sql);
                 $disp_week = request_var('disp_week', 0);
                 set_config('rp_index_display_week', $disp_week, 0);
                 $first_day = request_var('first_day', 0);
                 set_config('rp_first_day_of_week', $first_day, 0);
                 $hour_mode = request_var('hour_mode', 12);
                 set_config('rp_hour_mode', $hour_mode, 0);
                 $disp_trunc = request_var('disp_trunc', 0);
                 set_config('rp_display_truncated_name', $disp_trunc, 0);
                 $disp_hidden_groups = request_var('disp_hidden_groups', '');
                 set_config('rp_display_hidden_groups', $disp_hidden_groups, 0);
                 $disp_raidplans_1_day = request_var('disp_raidplans_1_day', 0);
                 set_config('rp_disp_raidplans_only_on_start', $disp_raidplans_1_day, 0);
                 $date_format = request_var('date_format', 'M d, Y');
                 set_config('rp_date_format', $date_format, 0);
                 $show_name = request_var('show_name', 0);
                 set_config('rp_show_name', $show_name, 0);
                 $date_time_format = request_var('date_time_format', 'M d, Y h:i a');
                 set_config('rp_date_time_format', $date_time_format, 0);
                 $time_format = request_var('time_format', 'h:i a');
                 set_config('rp_time_format', $time_format, 0);
                 // prune_freq is entered in days by user, but stored in seconds
                 $prune_freq = request_var('prune_freq', 0);
                 $prune_freq = 86400 * $prune_freq;
                 set_config('rp_prune_frequency', $prune_freq, 0);
                 // prune_limit is entered in days by user, but stored in seconds
                 $prune_limit = request_var('prune_limit', 0);
                 $prune_limit = 86400 * $prune_limit;
                 set_config('rp_prune_limit', $prune_limit, 0);
                 // auto populate recurring raidplan settings
                 // populate_freq is entered in days by user, but stored in seconds
                 $populate_freq = request_var('populate_freq', 0);
                 $populate_freq = 86400 * $populate_freq;
                 set_config('rp_populate_frequency', $populate_freq, 0);
                 // populate_limit is entered in days by user, but stored in seconds
                 $populate_limit = request_var('populate_limit', 0);
                 $populate_limit = 86400 * $populate_limit;
                 set_config('rp_populate_limit', $populate_limit, 0);
                 $cache->destroy('config');
                 $message = '<br />' . sprintf($user->lang['CALSETTINGS_UPDATED'], E_USER_NOTICE);
                 meta_refresh(1, $this->u_action);
                 trigger_error($message . $link);
             }
             $sel_monday = $sel_tuesday = $sel_wednesday = $sel_thursday = $sel_friday = $sel_saturday = $sel_sunday = "";
             switch ($config['rp_first_day_of_week']) {
                 case 0:
                     $sel_monday = "selected='selected'";
                     break;
                 case 1:
                     $sel_tuesday = "selected='selected'";
                     break;
                 case 2:
                     $sel_wednesday = "selected='selected'";
                     break;
                 case 3:
                     $sel_thursday = "selected='selected'";
                     break;
                 case 4:
                     $sel_friday = "selected='selected'";
                     break;
                 case 5:
                     $sel_saturday = "selected='selected'";
                     break;
                 case 6:
                     $sel_sunday = "selected='selected'";
                     break;
             }
             // get welcome msg
             $sql = 'SELECT announcement_msg, bbcode_bitfield, bbcode_uid FROM ' . RP_RAIDPLAN_ANNOUNCEMENT;
             $db->sql_query($sql);
             $result = $db->sql_query($sql);
             while ($row = $db->sql_fetchrow($result)) {
                 $text = $row['announcement_msg'];
                 $bitfield = $row['bbcode_bitfield'];
                 $uid = $row['bbcode_uid'];
             }
             $textarr = generate_text_for_edit($text, $uid, $bitfield, 7);
             $template->assign_vars(array('SHOW_WELCOME' => (int) $config['rp_show_welcomemsg'] == 1 ? 'checked="checked"' : "", 'WELCOME_MESSAGE' => $textarr['text'], 'DISP_WEEK_CHECKED' => $config['rp_index_display_week'] == 1 ? "checked='checked'" : '', 'SEL_MONDAY' => $sel_monday, 'SEL_TUESDAY' => $sel_tuesday, 'SEL_WEDNESDAY' => $sel_wednesday, 'SEL_THURSDAY' => $sel_thursday, 'SEL_FRIDAY' => $sel_friday, 'SEL_SATURDAY' => $sel_saturday, 'SEL_SUNDAY' => $sel_sunday, 'SEL_12_HOURS' => $config['rp_hour_mode'] == 12 ? "selected='selected'" : '', 'SEL_24_HOURS' => $config['rp_hour_mode'] != 12 ? "selected='selected'" : '', 'DISP_TRUNCATED' => $config['rp_display_truncated_name'], 'DISP_HIDDEN_GROUPS_CHECKED' => $config['rp_display_hidden_groups'] == '1' ? "checked='checked'" : '', 'DATE_FORMAT' => $config['rp_date_format'], 'DATE_TIME_FORMAT' => $config['rp_date_time_format'], 'TIME_FORMAT' => $config['rp_time_format'], 'SHOW_NAME' => (int) $config['rp_show_name'] == 1 ? 'checked="checked"' : ""));
             $this->tpl_name = 'dkp/acp_' . $mode;
             $form_key = 'acp_raidplanner';
             add_form_key($form_key);
             break;
         case 'rp_teams':
             $this->listteam($mode);
             break;
         case 'rp_teams_edit':
             //include the guilds class
             if (!class_exists('\\bbdkp\\controller\\guilds\\Guilds')) {
                 require "{$phpbb_root_path}includes/bbdkp/controller/guilds/Guilds.{$phpEx}";
             }
             if (!class_exists('\\bbdkp\\controller\\games\\Game')) {
                 require "{$phpbb_root_path}includes/bbdkp/controller/games/Game.{$phpEx}";
             }
             $action = request_var('action', '');
             $game_id = request_var('game_id', '');
             $guild_id = request_var(URI_GUILD, 1);
             $teams_id = request_var('teams_id', 1);
             $role_id = request_var('role_id', 1);
             $addteam = isset($_POST['addteam']) ? true : false;
             $updateteam = isset($_POST['updateteam']) ? true : false;
             $newroleadd = isset($_POST['newroleadd']) ? true : false;
             if ($action == 'deleteteam') {
                 $this->DeleteTeam($teams_id);
                 $success_message = sprintf($user->lang['TEAM_DELETE_SUCCESS'], $teams_id);
                 $link = '<br /><a href="' . append_sid("{$phpbb_root_path}adm/index.{$phpEx}", "i=raidplanner&amp;mode=rp_teams") . '"><p>' . $user->lang['RETURN_RP'] . '</p></a>';
                 meta_refresh(1, append_sid("{$phpbb_root_path}adm/index.{$phpEx}", "i=raidplanner&amp;mode=rp_teams"));
                 trigger_error($success_message . $link);
             } elseif ($action == 'editteam') {
                 // prepare edit template
                 $team = $this->getteam($teams_id);
                 $template->assign_vars(array('S_UPDATE' => true, 'TEAM_ID' => $teams_id));
                 $listroles = $this->listroles($teams_id);
                 $showaddline = true;
                 if ($this->rolesneeded >= $team['team_size']) {
                     $showaddline = false;
                 }
                 // get guilds
                 $Guild = new \bbdkp\controller\guilds\Guilds();
                 $guildlist = $Guild->guildlist($guild_id);
                 foreach ($guildlist as $g) {
                     $template->assign_block_vars('guild_row', array('VALUE' => $g['id'], 'SELECTED' => $team['guild_id'] == $g['id'] ? ' selected="selected"' : '', 'OPTION' => !empty($g['name']) ? $g['name'] : '(None)'));
                 }
                 //get games
                 if (!class_exists('\\bbdkp\\admin\\Admin')) {
                     require "{$phpbb_root_path}includes/bbdkp/admin/admin.{$phpEx}";
                 }
                 $bbdkp = new \bbdkp\admin\Admin();
                 if (isset($bbdkp->games)) {
                     foreach ($bbdkp->games as $key => $gamename) {
                         $template->assign_block_vars('game_row', array('VALUE' => $key, 'SELECTED' => $team['game_id'] == $key ? ' selected="selected"' : '', 'OPTION' => !empty($gamename) ? $gamename : '(None)'));
                     }
                 } else {
                     trigger_error('ERROR_NOGAMES', E_USER_WARNING);
                 }
                 // get roles
                 $Roles = new \bbdkp\controller\games\Roles();
                 $Roles->game_id = $team['game_id'];
                 $Roles->guild_id = $team['guild_id'];
                 $listroles = $Roles->listroles();
                 foreach ($listroles as $roleid => $Role) {
                     $template->assign_block_vars('allroles', array('VALUE' => $Role['role_id'], 'SELECTED' => '', 'OPTION' => $Role['rolename']));
                 }
                 $template->assign_vars(array('S_ADDNEW_SHOW' => $showaddline));
             } elseif ($updateteam || $addteam) {
                 $template->assign_vars(array('S_ADD' => true));
                 if (!check_form_key('acp_raidplanner')) {
                     trigger_error('FORM_INVALID');
                 }
                 $teamdata = array('team_name' => utf8_normalize_nfc(request_var('teamname', 'New Team', true)), 'team_size' => request_var('teamsize', 0), 'game_id' => request_var('game_id', ''), 'guild_id' => request_var('guild_id', 0));
                 $error = $teamdata['team_name'] == '' ? trigger_error($user->lang['TEAMROLE_NAME_EMPTY'], E_USER_WARNING) : '';
                 $error = $teamdata['team_size'] == '' ? trigger_error($user->lang['TEAMROLE_SIZE_EMPTY'], E_USER_WARNING) : '';
                 if ($addteam) {
                     $sql = 'INSERT INTO ' . RP_TEAMS . $db->sql_build_array('INSERT', $teamdata);
                     $db->sql_query($sql);
                     $teams_id = $db->sql_nextid();
                     $success_message = sprintf($user->lang['TEAM_ADD_SUCCESS'], utf8_normalize_nfc(request_var('newteamname', 'New Team', true)));
                     $link = '<br /><a href="' . append_sid("{$phpbb_root_path}adm/index.{$phpEx}", "i=raidplanner&amp;mode=rp_teams") . '"><p>' . $user->lang['RETURN_RP'] . '</p></a>';
                     meta_refresh(1, append_sid("{$phpbb_root_path}adm/index.{$phpEx}", "i=raidplanner&amp;mode=rp_teams"));
                     trigger_error($success_message . $link);
                 }
                 if ($updateteam) {
                     $link = '<br /><a href="' . append_sid("{$phpbb_root_path}adm/index.{$phpEx}", "i=raidplanner&amp;mode=rp_teams_edit&amp;action=editteam&amp;teams_id=" . $teams_id) . '"><p>' . $user->lang['RETURN_RP'] . '</p></a>';
                     $sql = 'UPDATE ' . RP_TEAMS . ' SET ' . $db->sql_build_array('UPDATE', $teamdata) . '
                          WHERE teams_id=' . (int) $teams_id;
                     $db->sql_query($sql);
                     $roledata = request_var('rolesize', array(0 => 0));
                     $sumneeded = 0;
                     foreach ($roledata as $roleid => $Roleneeded) {
                         $sumneeded += $Roleneeded;
                     }
                     if ($sumneeded > $teamdata['team_size']) {
                         $success_message = sprintf($user->lang['TEAMROLE_UPDATE_FAIL'], $teams_id, $teamdata['team_size'], $sumneeded);
                         trigger_error($success_message . $link, E_USER_WARNING);
                     }
                     foreach ($roledata as $roleid => $Roleneeded) {
                         $updroles = array('role_needed' => $Roleneeded);
                         $sql = 'UPDATE ' . RP_TEAMSIZE . ' SET ' . $db->sql_build_array('UPDATE', $updroles) . ' WHERE teams_id=' . (int) $teams_id . ' AND role_id = ' . $roleid;
                         $db->sql_query($sql);
                     }
                     $success_message = sprintf($user->lang['TEAM_UPDATE_SUCCESS'], $teams_id);
                     meta_refresh(1, append_sid("{$phpbb_root_path}adm/index.{$phpEx}", "i=raidplanner&amp;mode=rp_teams"));
                     trigger_error($success_message . $link);
                 }
             } elseif ($action == 'deleterole') {
                 $this->DeleteOneRole($teams_id, $role_id);
                 $success_message = sprintf($user->lang['ADMIN_DELETE_ROLE_SUCCESS'], $role_id);
                 $link = '<br /><a href="' . append_sid("{$phpbb_root_path}adm/index.{$phpEx}", "i=raidplanner&amp;mode=rp_teams") . '"><p>' . $user->lang['RETURN_RP'] . '</p></a>';
                 meta_refresh(1, append_sid("{$phpbb_root_path}adm/index.{$phpEx}", "i=raidplanner&amp;mode=rp_teams"));
                 trigger_error($success_message . $link);
             } elseif ($newroleadd) {
                 $newrolesize = request_var('newrolesize', 1);
                 $role_id = request_var('newrole_id', 1);
                 $this->AddOneRole($teams_id, $game_id, $role_id, $newrolesize);
                 $success_message = sprintf($user->lang['ADMIN_ADD_ROLE_SUCCESS'], $role_id);
                 $link = '<br /><a href="' . append_sid("{$phpbb_root_path}adm/index.{$phpEx}", "i=raidplanner&amp;mode=rp_teams") . '"><p>' . $user->lang['RETURN_RP'] . '</p></a>';
                 meta_refresh(1, append_sid("{$phpbb_root_path}adm/index.{$phpEx}", "i=raidplanner&amp;mode=rp_teams"));
                 trigger_error($success_message . $link);
             } else {
                 // default load add team template
                 $template->assign_vars(array('S_ADD' => true, 'TEAM_ID' => $teams_id));
                 $Guild = new \bbdkp\controller\guilds\Guilds();
                 $guildlist = $Guild->guildlist($guild_id);
                 foreach ($guildlist as $g) {
                     $template->assign_block_vars('guild_row', array('VALUE' => $g['id'], 'SELECTED' => '', 'OPTION' => !empty($g['name']) ? $g['name'] : '(None)'));
                 }
                 if (isset($bbdkp->games)) {
                     foreach ($bbdkp->games as $key => $gamename) {
                         $template->assign_block_vars('game_row', array('VALUE' => $key, 'SELECTED' => '', 'OPTION' => !empty($gamename) ? $gamename : '(None)'));
                     }
                 } else {
                     trigger_error('ERROR_NOGAMES', E_USER_WARNING);
                 }
             }
             $this->tpl_name = 'dkp/acp_' . $mode;
             $form_key = 'acp_raidplanner';
             add_form_key($form_key);
             break;
     }
 }
Exemple #7
0
    /**
     * main dkp_adj acp function
     * @param integer $id
     * @param string $mode
     */
    public function main($id, $mode)
    {
        global $db, $user, $template;
        global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
        $this->adjustment = new \bbdkp\controller\adjustments\Adjust();
        //always late binding in php
        $this->link = '<br /><a href="' . append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_adj&amp;mode=listiadj") . '"><h3>' . $user->lang['RETURN_DKPINDEX'] . '</h3></a>';
        $this->tpl_name = 'dkp/acp_' . $mode;
        switch ($mode) {
            case 'listiadj':
                if (count($this->games) == 0) {
                    trigger_error($user->lang['ERROR_NOGAMES'], E_USER_WARNING);
                }
                $showadd = isset($_POST['addiadj']) ? true : false;
                if ($showadd) {
                    redirect(append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_adj&amp;mode=addiadj"));
                    break;
                }
                // guild dropdown
                $submit = isset($_POST['member_guild_id']) ? true : false;
                $Guild = new \bbdkp\controller\guilds\Guilds();
                $guildlist = $Guild->guildlist(1);
                if ($submit) {
                    $Guild->guildid = request_var('member_guild_id', 0);
                } else {
                    foreach ($guildlist as $g) {
                        $Guild->guildid = $g['id'];
                        $Guild->name = $g['name'];
                        if ($Guild->guildid == 0 && $Guild->name == 'Guildless') {
                            trigger_error('ERROR_NOGUILD', E_USER_WARNING);
                        }
                        break;
                    }
                }
                foreach ($guildlist as $g) {
                    $template->assign_block_vars('guild_row', array('VALUE' => $g['id'], 'SELECTED' => $g['id'] == $Guild->guildid ? ' selected="selected"' : '', 'OPTION' => !empty($g['name']) ? $g['name'] : '(None)'));
                }
                $this->adjustment->setAdjustmentDkpid(0);
                if (isset($_GET[URI_DKPSYS]) or isset($_POST[URI_DKPSYS])) {
                    $this->adjustment->setAdjustmentDkpid(request_var(URI_DKPSYS, 0));
                }
                if ($this->adjustment->getAdjustmentDkpid() == 0) {
                    if (count((array) $this->adjustment->getDkpsys()) == 0) {
                        trigger_error('ERROR_NOPOOLS', E_USER_WARNING);
                    }
                    //get default dkp pool
                    foreach ($this->adjustment->getDkpsys() as $pool) {
                        if ($pool['default'] == 'Y') {
                            $this->adjustment->setAdjustmentDkpid($pool['id']);
                            break;
                        }
                    }
                    //if still 0 then get first one
                    if ($this->adjustment->getAdjustmentDkpid() == 0) {
                        foreach ($this->adjustment->getDkpsys() as $pool) {
                            $this->adjustment->setAdjustmentDkpid($pool['id']);
                            break;
                        }
                    }
                }
                foreach ($this->adjustment->getDkpsys() as $pool) {
                    $template->assign_block_vars('dkpsys_row', array('VALUE' => $pool['id'], 'SELECTED' => $pool['id'] == $this->adjustment->getAdjustmentDkpid() ? ' selected="selected"' : '', 'OPTION' => !empty($pool['name']) ? $pool['name'] : '(None)'));
                }
                /*** end DKPSYS drop-down ***/
                $sort_order = array(0 => array('adjustment_id desc', 'adjustment_id asc'), 1 => array('adjustment_date desc, member_name asc', 'adjustment_date asc, member_name asc'), 2 => array('adjustment_dkpid', 'adjustment_dkpid desc'), 3 => array('dkpsys_name', 'dkpsys_name desc'), 4 => array('member_name', 'member_name desc'), 5 => array('adjustment_reason', 'adjustment_reason desc'), 6 => array('adjustment_value desc', 'adjustment_value'), 7 => array('adjustment_added_by', 'adjustment_added_by desc'));
                $member_filter = utf8_normalize_nfc(request_var('member_name', '', true));
                $result2 = $this->adjustment->countadjust(0, $member_filter, $Guild->guildid);
                $total_adjustments = (int) $db->sql_fetchfield('total_adjustments');
                $db->sql_freeresult($result2);
                $start = request_var('start', 0);
                if ($member_filter != '') {
                    $u_list_adjustments = append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_adj&amp;mode=listiadj&amp;" . URI_DKPSYS . "=" . $this->adjustment->getAdjustmentDkpid()) . '&amp;member_name=' . $member_filter;
                } else {
                    $u_list_adjustments = append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_adj&amp;mode=listiadj&amp;" . URI_DKPSYS . "=" . $this->adjustment->getAdjustmentDkpid());
                }
                $current_order = $this->switch_order($sort_order);
                $result = $this->adjustment->ListAdjustments($current_order['sql'], 0, $start, $Guild->guildid, $member_filter);
                while ($adj = $db->sql_fetchrow($result)) {
                    $template->assign_block_vars('adjustments_row', array('U_ADD_ADJUSTMENT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_adj&amp;mode=addiadj") . '&amp;' . URI_ADJUSTMENT . '=' . $adj['adjustment_id'] . '&amp;' . URI_DKPSYS . '=' . $adj['adjustment_dkpid'], 'DATE' => date($config['bbdkp_date_format'], $adj['adjustment_date']), 'ADJID' => $adj['adjustment_id'], 'DKPID' => $adj['adjustment_dkpid'], 'DKPPOOL' => $adj['dkpsys_name'], 'COLORCODE' => $adj['colorcode'] == '' ? '#254689' : $adj['colorcode'], 'CLASS_IMAGE' => strlen($adj['imagename']) > 1 ? $phpbb_root_path . "images/bbdkp/class_images/" . $adj['imagename'] . ".png" : '', 'S_CLASS_IMAGE_EXISTS' => strlen($adj['imagename']) > 1 ? true : false, 'U_VIEW_MEMBER' => isset($adj['member_name']) ? append_sid("{$phpbb_root_path}dkp.{$phpEx}", "page=member&amp;" . URI_NAMEID . '=' . $adj['member_id'] . '&amp;' . URI_DKPSYS . '=' . $adj['adjustment_dkpid']) : '', 'U_VIEW_MEMBER_ACP' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_mdkp&amp;mode=mm_editmemberdkp") . '&amp;member_id=' . $adj['member_id'] . '&amp;' . URI_DKPSYS . '=' . $adj['adjustment_dkpid'], 'MEMBER' => isset($adj['member_name']) ? $adj['member_name'] : '', 'REASON' => isset($adj['adjustment_reason']) ? $adj['adjustment_reason'] : '', 'CAN_DECAY' => $adj['can_decay'], 'ADJUSTMENT' => $adj['adjustment_value'] == 0 ? '' : number_format($adj['adjustment_value'], 2), 'ADJ_DECAY' => -1 * $adj['adj_decay'] == 0 ? '' : -1 * $adj['adj_decay'], 'ADJUSTMENT_NET' => $adj['adjustment_value'] - $adj['adj_decay'] == 0 ? '' : number_format($adj['adjustment_value'] - $adj['adj_decay'], 2), 'DECAY_TIME' => $adj['decay_time'] != 0 ? date($config['bbdkp_date_format'], $adj['decay_time']) : '', 'ADDED_BY' => $adj['adjustment_added_by'], 'MEMBER_NAME' => $member_filter));
                }
                $db->sql_freeresult($result);
                $listadj_footcount = sprintf($user->lang['LISTADJ_FOOTCOUNT'], $total_adjustments, $config['bbdkp_user_alimit']);
                $pagination = generate_pagination(append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_adj&amp;mode=listiadj&amp;dkpsys_id=" . $this->adjustment->getAdjustmentDkpid()), $total_adjustments, $config['bbdkp_user_alimit'], $start, true);
                $template->assign_vars(array('L_TITLE' => $user->lang['ACP_LISTIADJ'], 'L_EXPLAIN' => $user->lang['ACP_LISTIADJ_EXPLAIN'], 'S_SHOW' => $total_adjustments > 0 ? true : false, 'O_ADJID' => $current_order['uri'][0], 'O_DATE' => $current_order['uri'][1], 'O_DKPID' => $current_order['uri'][2], 'O_DKPPOOL' => $current_order['uri'][3], 'O_MEMBER' => $current_order['uri'][4], 'O_REASON' => $current_order['uri'][5], 'O_ADJUSTMENT' => $current_order['uri'][6], 'O_ADDED_BY' => $current_order['uri'][7], 'U_LIST_ADJUSTMENTS' => $u_list_adjustments, 'MEMBER_NAME' => $member_filter, 'START' => $start, 'S_GROUP_ADJ' => false, 'LISTADJ_FOOTCOUNT' => $listadj_footcount, 'ADJUSTMENT_PAGINATION' => $pagination, 'TOTAL_ADJUSTMENTS' => 'Total Adjustments', 'PAGE_NUMBER' => on_page($total_adjustments, $config['bbdkp_user_alimit'], $start)));
                $this->page_title = 'ACP_LISTIADJ';
                break;
            case 'addiadj':
                $form_key = 'acp_dkp_adj';
                add_form_key($form_key);
                //  begin DKPSYS drop-down
                $dkpsys_id = 1;
                $sql = 'SELECT dkpsys_id, dkpsys_name, dkpsys_default
                    FROM ' . DKPSYS_TABLE . "\n\t\t            WHERE dkpsys_status = 'Y'\n                    ORDER BY dkpsys_name";
                $resultdkpsys = $db->sql_query($sql);
                $showadj = new \bbdkp\controller\adjustments\Adjust();
                $adjust_id = request_var(URI_ADJUSTMENT, 0);
                $dkpsys_id = request_var(URI_DKPSYS, 0);
                if ($adjust_id != 0 && $dkpsys_id != 0) {
                    $showadj->get($adjust_id);
                    while ($row2 = $db->sql_fetchrow($resultdkpsys)) {
                        $template->assign_block_vars('adj_dkpid_row', array('VALUE' => $row2['dkpsys_id'], 'SELECTED' => $row2['dkpsys_id'] == $showadj->getAdjustmentDkpid() ? ' selected="selected"' : '', 'OPTION' => !empty($row2['dkpsys_name']) ? $row2['dkpsys_name'] : '(None)'));
                    }
                } else {
                    // we dont have a GET so put default dkp pool in pulldown
                    while ($row2 = $db->sql_fetchrow($resultdkpsys)) {
                        //dkpsys_default
                        $template->assign_block_vars('adj_dkpid_row', array('VALUE' => $row2['dkpsys_id'], 'SELECTED' => $row2['dkpsys_default'] == 'Y' ? ' selected="selected"' : '', 'OPTION' => !empty($row2['dkpsys_name']) ? $row2['dkpsys_name'] : '(None)'));
                        if ($row2['dkpsys_default'] == 'Y') {
                            $dkpsys_id = $row2['dkpsys_id'];
                        }
                    }
                }
                //  end DKPSYS drop-down
                $submit = isset($_POST['add']) ? true : false;
                $update = isset($_POST['update']) ? true : false;
                $delete = isset($_POST['delete']) ? true : false;
                if ($submit || $update) {
                    if (!check_form_key('acp_dkp_adj')) {
                        trigger_error('FORM_INVALID');
                    }
                }
                $now = getdate();
                $s_day_options = '';
                $day = $showadj->getAdjustmentDate() > 0 ? date('j', $showadj->getAdjustmentDate()) : $now['mday'];
                for ($i = 1; $i < 32; $i++) {
                    $selected = $i == $day ? ' selected="selected"' : '';
                    $s_day_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                $s_month_options = '';
                $month = $showadj->getAdjustmentDate() > 0 ? date('n', $showadj->getAdjustmentDate()) : $now['mon'];
                for ($i = 1; $i < 13; $i++) {
                    $selected = $i == $month ? ' selected="selected"' : '';
                    $s_month_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                $s_year_options = '';
                $yr = $showadj->getAdjustmentDate() > 0 ? date('Y', $showadj->getAdjustmentDate()) : $now['year'];
                for ($i = $now['year'] - 10; $i <= $now['year']; $i++) {
                    $selected = $i == $yr ? ' selected="selected"' : '';
                    $s_year_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                if ($submit) {
                    global $user;
                    $this->error_check();
                    $newadjust = new \bbdkp\controller\adjustments\Adjust();
                    $temp = str_replace(".", "", request_var('adjustment_value', 0.0));
                    $temp2 = (double) str_replace(",", ".", $temp);
                    $newadjust->setAdjustmentValue($temp2);
                    $newadjust->setAdjustmentReason(utf8_normalize_nfc(request_var('adjustment_reason', '', true)));
                    $newadjust->setCanDecay(request_var('adj_decayable', 1));
                    $newadjust->setAdjDecay(0);
                    $newadjust->setDecayTime(0);
                    $newadjust->setAdjustmentDate(mktime(12, 0, 0, request_var('adjustment_month', 0), request_var('adjustment_day', 0), request_var('adjustment_year', 0)));
                    $newadjust->setAdjustmentDkpid(request_var('adj_dkpid', 0));
                    $newadjust->setAdjustmentGroupkey($this->gen_group_key($this->time, $newadjust->getAdjustmentReason(), $newadjust->getAdjustmentValue()));
                    $newadjust->setAdjustmentAddedBy($user->data['username']);
                    $members = request_var('member_names', array(0 => 0), true);
                    $member_names = array();
                    foreach ($members as $member_id) {
                        $member = new \bbdkp\controller\members\Members();
                        $member->member_id = $member_id;
                        $member->Getmember();
                        $newadjust->setMemberId($member_id);
                        $newadjust->setMemberName($member->member_name);
                        $member_names[] = $member->member_name;
                        $newadjust->add();
                    }
                    //
                    // Logging
                    //
                    $log_action = array('header' => 'L_ACTION_INDIVADJ_ADDED', 'L_ADJUSTMENT' => $newadjust->getAdjustmentValue(), 'L_REASON' => $newadjust->getAdjustmentReason(), 'L_MEMBERS' => implode(', ', $member_names), 'L_ADDED_BY' => $newadjust->getAdjustmentAddedBy());
                    $this->log_insert(array('log_type' => 'L_ACTION_INDIVADJ_ADDED', 'log_action' => $log_action));
                    $success_message = sprintf($user->lang['ADMIN_ADD_IADJ_SUCCESS'], $config['bbdkp_dkp_name'], $newadjust->getAdjustmentValue(), implode(', ', $member_names));
                    trigger_error($success_message . $this->link);
                }
                if ($update) {
                    $this->error_check();
                    $oldadjust = new \bbdkp\controller\adjustments\Adjust();
                    $oldadjust->adjustment_id = request_var('hidden_id', 0);
                    $oldadjust->get($oldadjust->adjustment_id);
                    foreach ($oldadjust->getMembersSamegroupkey() as $member_id) {
                        $oldmembers = new \bbdkp\controller\members\Members();
                        $oldmembers->member_id = $member_id;
                        $oldmembers->Getmember();
                        $oldmember_names[] = $oldmembers->member_name;
                        unset($oldmembers);
                        // remove old adjustment
                        $oldadjust->delete();
                    }
                    $updadjust = new \bbdkp\controller\adjustments\Adjust();
                    $temp = str_replace(".", "", request_var('adjustment_value', 0.0));
                    $temp2 = (double) str_replace(",", ".", $temp);
                    $updadjust->setAdjustmentValue($temp2);
                    $updadjust->setAdjustmentReason(utf8_normalize_nfc(request_var('adjustment_reason', '', true)));
                    $updadjust->setCanDecay(request_var('adj_decayable', 1));
                    $updadjust->setAdjDecay(request_var('adjustment_decay', 0.0));
                    $updadjust->setDecayTime($oldadjust->getDecayTime());
                    $updadjust->setAdjustmentDate(mktime(12, 0, 0, request_var('adjustment_month', 0), request_var('adjustment_day', 0), request_var('adjustment_year', 0)));
                    $updadjust->setAdjustmentDkpid(request_var('adj_dkpid', 0));
                    $updadjust->setAdjustmentAddedBy($user->data['username']);
                    $updadjust->setAdjustmentGroupkey($updadjust->gen_group_key($this->time, $updadjust->getAdjustmentReason(), $updadjust->getAdjustmentValue()));
                    $members = request_var('member_names', array(0 => 0), true);
                    foreach ($members as $member_id) {
                        $member = new \bbdkp\controller\members\Members();
                        $member->member_id = $member_id;
                        $updadjust->setMembersSamegroupkey($member_id);
                        $member->Getmember();
                        $updadjust->setMemberId($member_id);
                        $updadjust->setMemberName($member->member_name);
                        $member_names[] = $member->member_name;
                        $updadjust->add();
                        unset($member);
                    }
                    //
                    // Logging
                    //
                    $log_action = array('header' => 'L_ACTION_INDIVADJ_UPDATED', 'id' => $adjust_id, 'L_ADJUSTMENT_BEFORE' => $oldadjust->getAdjustmentValue(), 'L_REASON_BEFORE' => $oldadjust->getAdjustmentReason(), 'L_MEMBERS_BEFORE' => implode(', ', $oldmember_names), 'L_ADJUSTMENT_AFTER' => $updadjust->getAdjustmentValue(), 'L_REASON_AFTER' => $updadjust->getAdjustmentReason(), 'L_MEMBERS_AFTER' => implode(', ', $member_names), 'L_UPDATED_BY' => $user->data['username']);
                    $this->log_insert(array('log_type' => $log_action['header'], 'log_action' => $log_action));
                    $success_message = sprintf($user->lang['ADMIN_UPDATE_IADJ_SUCCESS'], $config['bbdkp_dkp_name'], $updadjust->getAdjustmentValue(), implode(', ', $member_names));
                    trigger_error($success_message . $this->link);
                }
                if ($delete) {
                    if (confirm_box(true)) {
                        // get form vars
                        $adjust_id = request_var('xhidden_id', 0);
                        $deleteadj = new \bbdkp\controller\adjustments\Adjust();
                        $deleteadj->get($adjust_id);
                        $deleteadj->delete();
                        // Logging
                        $log_action = array('header' => 'L_ACTION_INDIVADJ_DELETED', 'id' => $adjust_id, 'L_ADJUSTMENT' => $deleteadj->getAdjustmentValue(), 'L_REASON' => $deleteadj->getAdjustmentReason(), 'L_MEMBERS' => $deleteadj->getMemberName());
                        $this->log_insert(array('log_type' => $log_action['header'], 'log_action' => $log_action));
                        //
                        // Success messages
                        $success_message = sprintf($user->lang['ADMIN_DELETE_IADJ_SUCCESS'], $config['bbdkp_dkp_name'], $deleteadj->getAdjustmentValue(), $deleteadj->getMemberName());
                        trigger_error($success_message . $this->link);
                    } else {
                        $s_hidden_fields = build_hidden_fields(array('delete' => true, 'xhidden_id' => request_var('hidden_id', 0)));
                        $template->assign_vars(array('S_HIDDEN_FIELDS' => $s_hidden_fields));
                        confirm_box(false, $user->lang['CONFIRM_DELETE_IADJ'], $s_hidden_fields);
                    }
                }
                //guild dropdown
                $guildid = request_var('member_guild_id', 0);
                $Guild = new \bbdkp\controller\guilds\Guilds();
                $guildlist = $Guild->guildlist(1);
                foreach ((array) $guildlist as $g) {
                    if ($guildid == 0) {
                        $guildid = $g['id'];
                    }
                    if ($g['guilddefault'] == 1) {
                        $guildid = $g['id'];
                    }
                    $template->assign_block_vars('guild_row', array('VALUE' => $g['id'], 'SELECTED' => $guildid == $g['id'] ? ' selected="selected"' : '', 'OPTION' => $g['name']));
                }
                /* mark members as selected */
                $sql = 'SELECT member_id, member_name FROM ' . MEMBER_LIST_TABLE . '
						WHERE member_guild_id = ' . $guildid . '
						ORDER BY member_name ';
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    if ($adjust_id) {
                        //editmode
                        $selected = @in_array($row['member_id'], $showadj->getMembersSamegroupkey()) ? ' selected="selected"' : '';
                    } else {
                        //newmode
                        $selected = @in_array($row['member_id'], utf8_normalize_nfc(request_var('member_names', array(0 => 0)))) ? ' selected="selected"' : '';
                    }
                    $template->assign_block_vars('members_row', array('VALUE' => $row['member_id'], 'SELECTED' => $selected, 'OPTION' => $row['member_name']));
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('L_TITLE' => $showadj->adjustment_id == 0 ? $user->lang['ADD_IADJ_TITLE'] : $user->lang['EDIT_IADJ_TITLE'], 'L_EXPLAIN' => $user->lang['ACP_ADDIADJ_EXPLAIN'], 'F_ADD_ADJUSTMENT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_adj&amp;mode=addiadj"), 'ADJUSTMENT_ID' => $showadj->adjustment_id, 'DKP_ID' => $showadj->getAdjustmentDkpid(), 'ADJUSTMENT_VALUE' => number_format($showadj->getAdjustmentValue(), 2), 'ADJUSTMENT_REASON' => $showadj->getAdjustmentReason(), 'ADJUSTMENT_DECAY' => number_format($showadj->getAdjDecay(), 2), 'S_DAY_OPTIONS' => $s_day_options, 'S_MONTH_OPTIONS' => $s_month_options, 'S_YEAR_OPTIONS' => $s_year_options, 'CAN_DECAY_NO_CHECKED' => $showadj->getCanDecay() == 0 ? ' checked="checked"' : '', 'CAN_DECAY_YES_CHECKED' => $showadj->getCanDecay() == 1 ? ' checked="checked"' : '', 'MSG_VALUE_EMPTY' => $user->lang['FV_REQUIRED_ADJUSTMENT'], 'UA_FINDMEMBERS' => append_sid($phpbb_admin_path . "style/dkp/findmembers.{$phpEx}"), 'S_ADD' => !$showadj->adjustment_id ? true : false));
                $this->page_title = 'ACP_ADDIADJ';
                break;
        }
    }
Exemple #8
0
    /**
     * list items for a pool. master-detail form
     *
     */
    private function listitems()
    {
        global $db, $user, $config, $template, $phpEx, $phpbb_admin_path, $phpbb_root_path;
        if (count((array) $this->LootController->dkpsys) == 0) {
            trigger_error('ERROR_NOPOOLS', E_USER_WARNING);
        }
        // guild dropdown
        $submit = isset($_POST['member_guild_id']) ? true : false;
        $Guild = new \bbdkp\controller\guilds\Guilds();
        $guildlist = $Guild->guildlist(1);
        if ($submit) {
            $Guild->guildid = request_var('member_guild_id', 0);
        } else {
            foreach ($guildlist as $g) {
                $Guild->guildid = $g['id'];
                $Guild->name = $g['name'];
                if ($Guild->guildid == 0 && $Guild->name == 'Guildless') {
                    trigger_error('ERROR_NOGUILD', E_USER_WARNING);
                }
                break;
            }
        }
        foreach ($guildlist as $g) {
            $template->assign_block_vars('guild_row', array('VALUE' => $g['id'], 'SELECTED' => $g['id'] == $Guild->guildid ? ' selected="selected"' : '', 'OPTION' => !empty($g['name']) ? $g['name'] : '(None)'));
        }
        /***  DKPSYS drop-down query ***/
        $dkpsys_id = 0;
        // select all dkp pools that have raids
        $sql_array = array('SELECT' => 'd.dkpsys_id, d.dkpsys_name, d.dkpsys_default', 'FROM' => array(DKPSYS_TABLE => 'd', EVENTS_TABLE => 'e', RAIDS_TABLE => 'r'), 'WHERE' => 'd.dkpsys_id = e.event_dkpid
	    				and e.event_id = r.event_id ', 'GROUP_BY' => 'd.dkpsys_id, d.dkpsys_name, d.dkpsys_default');
        $sql = $db->sql_build_query('SELECT', $sql_array);
        $result = $db->sql_query($sql);
        $submit = isset($_POST['dkpsys_id']) ? true : false;
        if ($submit) {
            $dkpsys_id = request_var('dkpsys_id', 0);
        } else {
            while ($row = $db->sql_fetchrow($result)) {
                if ($row['dkpsys_default'] == "Y") {
                    $dkpsys_id = $row['dkpsys_id'];
                }
            }
            if ($dkpsys_id == 0) {
                $result = $db->sql_query_limit($sql, 1);
                while ($row = $db->sql_fetchrow($result)) {
                    $dkpsys_id = $row['dkpsys_id'];
                }
            }
        }
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $template->assign_block_vars('dkpsys_row', array('VALUE' => $row['dkpsys_id'], 'SELECTED' => $row['dkpsys_id'] == $dkpsys_id ? ' selected="selected"' : '', 'OPTION' => !empty($row['dkpsys_name']) ? $row['dkpsys_name'] : '(None)'));
            $poolhasitems = true;
        }
        $db->sql_freeresult($result);
        /***  end drop-down query ***/
        // user clicks on master raid list
        $raid_id = request_var('raid_id', 0);
        $lootcount = $this->LootController->Countloot(0, 0, $Guild->guildid);
        if ($lootcount > 0) {
            $total_raids = (int) $this->RaidController->guildraidcount($dkpsys_id, $Guild->guildid);
            $start = request_var('start', 0, false);
            $sort_order = array(0 => array('raid_id desc', 'raid_id'), 1 => array('event_name desc', 'event_name'));
            $current_order = $this->switch_order($sort_order);
            // populate raid master grid
            $this->RaidController->listraids($dkpsys_id, $start, 0, $Guild->guildid);
            foreach ($this->RaidController->raidlist as $id => $raid) {
                $template->assign_block_vars('raids_row', array('EVENTCOLOR' => !empty($raid['event_color']) ? $raid['event_color'] : '', 'U_VIEW_RAID' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_raid&amp;mode=editraid&amp;" . URI_RAID . "={$id}"), 'ID' => $id, 'DATE' => $user->format_date($raid['raid_start']), 'RAIDNAME' => $raid['event_name'], 'RAIDNOTE' => $raid['raid_note'], 'ONCLICK' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_item&amp;mode=listitems&amp;" . URI_DKPSYS . "={$dkpsys_id}&amp;" . URI_RAID . "={$id}&amp;start=" . $start)));
                if ($raid_id == $id) {
                    $raid_name = $raid['event_name'];
                    $raid_date = $user->format_date($raid['raid_start']);
                }
            }
            $raidpgination = generate_pagination(append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_item&amp;mode=listitems&amp;" . URI_DKPSYS . "=" . $dkpsys_id . "&amp;o=" . $current_order['uri']['current']), $total_raids, $config['bbdkp_user_rlimit'], $start, true);
            // detail grid for items
            $sql1 = 'SELECT count(*) as countitems FROM ' . RAID_ITEMS_TABLE . ' where raid_id = ' . $raid_id;
            $result1 = $db->sql_query($sql1);
            $total_items = (int) $db->sql_fetchfield('countitems', false, $result1);
            $db->sql_freeresult($result1);
            $start = request_var('start', 0);
            $sort_order = array(0 => array('i.item_date desc', 'item_date'), 1 => array('l.member_name', 'member_name desc'), 2 => array('i.item_name', 'item_name desc'), 3 => array('e.event_name', 'event_name desc'), 4 => array('i.item_value desc', 'item_value'), 5 => array('d.dkpsys_name desc', 'dkpsys_name'));
            $current_order = $this->switch_order($sort_order);
            $items_result = $this->LootController->listRaidLoot($dkpsys_id, $raid_id, $current_order['sql']);
            $listitems_footcount = sprintf($user->lang['LISTPURCHASED_FOOTCOUNT_SHORT'], $total_items);
            $this->bbtips = false;
            while ($item = $db->sql_fetchrow($items_result)) {
                if ($this->bbtips == true && $item['item_gameid'] == 'wow') {
                    if (is_numeric($item['item_gameid'])) {
                        $item_name = '<strong>' . $this->bbtips->parse('[itemdkp]' . $item['item_gameid'] . '[/itemdkp]') . '</strong>';
                    } else {
                        $item_name = '<strong>' . $this->bbtips->parse('[itemdkp]' . $item['item_name'] . '[/itemdkp]') . '</strong>';
                    }
                } else {
                    $item_name = $item['item_name'];
                }
                $template->assign_block_vars('items_row', array('COLORCODE' => $item['colorcode'] == '' ? '#254689' : $item['colorcode'], 'CLASS_IMAGE' => strlen($item['imagename']) > 1 ? $phpbb_root_path . "images/bbdkp/class_images/" . $item['imagename'] . ".png" : '', 'S_CLASS_IMAGE_EXISTS' => strlen($item['imagename']) > 1 ? true : false, 'DATE' => !empty($item['item_date']) ? $user->format_date($item['item_date'], $config['bbdkp_date_format']) : '&nbsp;', 'BUYER' => !empty($item['member_name']) ? $item['member_name'] : '&lt;<i>Not Found</i>&gt;', 'ITEMNAME' => $item_name, 'RAID' => !empty($item['event_name']) ? $item['event_name'] : '&lt;<i>Not Found</i>&gt;', 'U_VIEW_BUYER' => !empty($item['member_name']) ? append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_mdkp&amp;mode=mm_editmemberdkp&amp;member_id={$item['member_id']}&amp;" . URI_DKPSYS . "={$item['event_dkpid']}") : '', 'U_VIEW_ITEM' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_item&amp;mode=additem&amp;" . URI_ITEM . "={$item['item_id']}&amp;" . URI_RAID . "={$raid_id}"), 'VALUE' => $item['item_value']));
            }
            $db->sql_freeresult($items_result);
            $template->assign_vars(array('ICON_VIEWLOOT' => '<img src="' . $phpbb_admin_path . 'images/glyphs/view.gif" alt="' . $user->lang['ITEMS'] . '" title="' . $user->lang['ITEMS'] . '" />', 'S_SHOW' => true, 'F_LIST_ITEM' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_item&amp;mode=listitems"), 'L_TITLE' => $user->lang['ACP_LISTITEMS'], 'L_EXPLAIN' => $user->lang['ACP_LISTITEMS_EXPLAIN'], 'O_DATE' => $current_order['uri'][0], 'O_BUYER' => $current_order['uri'][1], 'O_NAME' => $current_order['uri'][2], 'O_RAID' => $current_order['uri'][3], 'O_VALUE' => $current_order['uri'][4], 'U_LIST_ITEMS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_item&amp;mode=listitems&amp;start={$start}&amp;" . URI_RAID . '=' . $raid_id), 'S_BBTIPS' => $this->bbtips, 'START' => $start, 'LISTITEMS_FOOTCOUNT' => $listitems_footcount, 'RAID_PAGINATION' => $raidpgination));
        } else {
            $template->assign_vars(array('F_LIST_ITEM' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_item&amp;mode=listitems"), 'L_TITLE' => $user->lang['ACP_LISTITEMS'], 'L_EXPLAIN' => $user->lang['ACP_LISTITEMS_EXPLAIN'], 'S_SHOW' => false, 'S_BBTIPS' => $this->bbtips));
        }
    }
Exemple #9
0
 /**
  * lists all raids
  *
  */
 private function listraids()
 {
     global $user, $config, $template, $phpbb_admin_path, $phpEx;
     // add dkpsys button redirect
     $showadd = isset($_POST['raidadd']) ? true : false;
     if ($showadd) {
         redirect(append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_raid&amp;mode=addraid"));
     }
     // guild dropdown
     $submit = isset($_POST['member_guild_id']) ? true : false;
     $Guild = new \bbdkp\controller\guilds\Guilds();
     $guildlist = $Guild->guildlist(1);
     if ($submit) {
         $Guild->guildid = request_var('member_guild_id', 0);
     } else {
         foreach ($guildlist as $g) {
             $Guild->guildid = $g['id'];
             $Guild->name = $g['name'];
             if ($Guild->guildid == 0 && $Guild->name == 'Guildless') {
                 trigger_error('ERROR_NOGUILD', E_USER_WARNING);
             }
             break;
         }
     }
     foreach ($guildlist as $g) {
         $template->assign_block_vars('guild_row', array('VALUE' => $g['id'], 'SELECTED' => $g['id'] == $Guild->guildid ? ' selected="selected"' : '', 'OPTION' => !empty($g['name']) ? $g['name'] : '(None)'));
     }
     /* dkp pool */
     $dkpsys_id = 0;
     if (isset($_GET[URI_DKPSYS]) or isset($_POST[URI_DKPSYS])) {
         //user clicked on add raid from event editscreen
         $dkpsys_id = request_var(URI_DKPSYS, 0);
     }
     if ($dkpsys_id == 0) {
         if (count((array) $this->RaidController->dkpsys) == 0) {
             trigger_error('ERROR_NOPOOLS', E_USER_WARNING);
         }
         //get default dkp pool
         foreach ($this->RaidController->dkpsys as $pool) {
             if ($pool['default'] == 'Y') {
                 $dkpsys_id = $pool['id'];
                 break;
             }
         }
         //if still 0 then get first one
         if ($dkpsys_id == 0) {
             foreach ($this->RaidController->dkpsys as $pool) {
                 $dkpsys_id = $pool['id'];
                 break;
             }
         }
     }
     foreach ($this->RaidController->dkpsys as $pool) {
         $selected = $pool['id'] == $dkpsys_id ? true : false;
         $template->assign_block_vars('dkpsys_row', array('VALUE' => $pool['id'], 'SELECTED' => $selected ? ' selected="selected"' : '', 'OPTION' => !empty($pool['name']) ? $pool['name'] : '(None)'));
     }
     $this->RaidController->dkpid = $dkpsys_id;
     $this->RaidController->guildid = $Guild->guildid;
     $start = \request_var('start', 0, false);
     $this->RaidController->listraids($this->RaidController->dkpid, $start);
     foreach ((array) $this->RaidController->raidlist as $raid_id => $raid) {
         $template->assign_block_vars('raids_row', array('ID' => $raid['raid_id'], 'DATE' => $raid['date'], 'NAME' => $raid['event_name'], 'NOTE' => $raid['note'], 'RAIDVALUE' => $raid['raidvalue'], 'TIMEVALUE' => $raid['timevalue'], 'ZSVALUE' => $raid['zsvalue'], 'DECAYVALUE' => $raid['decayvalue'], 'TOTAL' => $raid['total'], 'U_VIEW_RAID' => $raid['viewlink'], 'U_COPY_RAID' => $raid['copylink'], 'U_DELETE_RAID' => $raid['deletelink']));
     }
     $template->assign_vars(array('L_TITLE' => $user->lang['ACP_LISTRAIDS'], 'L_EXPLAIN' => $user->lang['ACP_LISTRAIDS_EXPLAIN'], 'O_ID' => $this->RaidController->raidlistorder['uri'][0], 'O_DATE' => $this->RaidController->raidlistorder['uri'][1], 'O_NAME' => $this->RaidController->raidlistorder['uri'][2], 'O_NOTE' => $this->RaidController->raidlistorder['uri'][3], 'O_RAIDVALUE' => $this->RaidController->raidlistorder['uri'][4], 'O_TIMEVALUE' => $this->RaidController->raidlistorder['uri'][5], 'O_ZSVALUE' => $this->RaidController->raidlistorder['uri'][6], 'O_DECAYVALUE' => $this->RaidController->raidlistorder['uri'][7], 'O_TOTALVALUE' => $this->RaidController->raidlistorder['uri'][8], 'S_SHOWTIME' => $config['bbdkp_timebased'] == '1' ? true : false, 'S_SHOWZS' => $config['bbdkp_zerosum'] == '1' ? true : false, 'S_SHOWDECAY' => $config['bbdkp_decay'] == '1' ? true : false, 'U_LIST_RAIDS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_raid&amp;mode=listraids&amp;dkpsys_id=" . $this->RaidController->dkpid), 'START' => $start, 'LISTRAIDS_FOOTCOUNT' => sprintf($user->lang['LISTRAIDS_FOOTCOUNT'], $this->RaidController->totalraidcount, $config['bbdkp_user_rlimit']), 'RAID_PAGINATION' => generate_pagination(append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_raid&amp;mode=listraids&amp;dkpsys_id=" . $this->RaidController->dkpid . "&amp;o=" . $this->RaidController->raidlistorder['uri']['current']), $this->RaidController->totalraidcount, $config['bbdkp_user_rlimit'], $start, true), 'ICON_RCOPY' => '<img src="' . $phpbb_admin_path . 'images/file_new.gif" alt="' . $user->lang['DUPLICATE_RAID'] . '" title="' . $user->lang['DUPLICATE_RAID'] . '" />'));
 }
 public function main($id, $mode)
 {
     global $user, $template, $phpEx, $phpbb_admin_path, $phpbb_root_path, $db;
     $user->add_lang(array('mods/dkp_admin', 'mods/dkp_common', 'mods/dkp_gameworld'));
     $this->tpl_name = 'dkp/acp_bossprogress';
     switch ($mode) {
         case 'guildprogress':
             $selectguild = isset($_POST['member_guild_id']) ? true : false;
             $submit = isset($_POST['bpsave']) ? true : false;
             $Guild = new \bbdkp\controller\guilds\Guilds();
             $guildlist = $Guild->guildlist(1);
             if (count((array) $guildlist) == 0) {
                 trigger_error('ERROR_NOGUILD', E_USER_WARNING);
             }
             if ($selectguild) {
                 $Guild->guildid = request_var('member_guild_id', 0);
             } else {
                 $Guild->guildid = request_var('hidden_guild_id', request_var('guild_id', 0));
             }
             $Guild->Getguild();
             if ($submit) {
                 $selectgame = request_var('hidden_game_id', '');
                 $krequest = new \bbdkp\admin\krequest();
                 $zones = $krequest->variable('boss', array('' => array('' => array('' => ''))), true, \bbdkp\admin\krequest::POST);
                 $krequest->enable_super_globals();
                 unset($krequest);
                 foreach ($zones as $bosses) {
                     $boss_ids = array();
                     foreach ($bosses as $id => $boss) {
                         if (isset($boss['killed']) || $boss['killdate'] != '' && $this->validateDate($boss['killdate'])) {
                             if ($boss['killdate'] != '') {
                                 $kd = \date_create($boss['killdate']);
                                 $kd = date_format($kd, 'U');
                             } else {
                                 $kd = time();
                             }
                             $sql_ary[] = array('guild_id' => $Guild->guildid, 'boss_id' => $id, 'bosskilled' => 1, 'bosskilldate' => $kd, 'bosscounter' => 1);
                             unset($kd);
                         }
                         $boss_ids[] = $id;
                     }
                     $sql = 'DELETE FROM ' . GUILD_BOSS . ' WHERE guild_id = ' . $Guild->guildid . ' AND ' . $db->sql_in_set('boss_id', $boss_ids);
                     $db->sql_query($sql);
                     $db->sql_multi_insert(GUILD_BOSS, $sql_ary);
                     unset($boss, $boss_ids, $sql_ary, $sql);
                 }
             }
             foreach ($guildlist as $g) {
                 if ($Guild->guildid == 0) {
                     $Guild->guildid = $g['id'];
                     $Guild->name = $g['name'];
                     $Guild->Getguild();
                 }
                 if ($Guild->guildid == 0 && $Guild->name == 'Guildless') {
                     trigger_error('ERROR_NOGUILD', E_USER_WARNING);
                 }
                 break;
             }
             foreach ($guildlist as $g) {
                 $template->assign_block_vars('guild_row', array('VALUE' => $g['id'], 'SELECTED' => $g['id'] == $Guild->guildid ? ' selected="selected"' : '', 'OPTION' => !empty($g['name']) ? $g['name'] : '(None)'));
             }
             $this->igame = new games\Game();
             $this->igame->game_id = $Guild->game_id;
             $this->igame->Get();
             $bp = new \bbdkp\controller\Raids\GuildProgress();
             $data = $bp->GetProgress($Guild);
             $numzones = 0;
             foreach ($data as $zone_id => $zone) {
                 $numzones += 1;
             }
             $start = request_var('start', 0);
             $template->assign_vars(array('PAGINATION' => generate_pagination(append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_bossprogress&amp;mode=guildprogress&amp;guild_id=" . $Guild->guildid), $numzones, 2, $start, true), 'PAGE_NUMBER' => on_page($numzones, 2, $start), 'F_CONFIG' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_bossprogress&amp;mode=guildprogress&amp;guild_id=" . $Guild->guildid), 'GUILD_ID' => $Guild->guildid, 'GAME_ID' => $Guild->game_id));
             $i = 0;
             $j = 0;
             foreach ($data as $zone_id => $zone) {
                 $i += 1;
                 if ($i >= $start) {
                     $j += 1;
                     //show max 2 zones per page
                     if ($j <= 2) {
                         $template->assign_block_vars('zone', array('ZONE_NAME' => $zone['zonename'], 'ZONE_ID' => $zone['zoneid'], 'ZONE_PROGRESSIMG' => $zone['zoneimage'], 'ZONE_BACKGROUNDIMG' => $zone['zonebackground'], 'ZONECOMPLETE' => $zone['zonecomplete'], 'ZONESTATS' => $zone['zonestats']));
                         foreach ($zone['bosses'] as $boss_id => $boss) {
                             $killdate = '';
                             if ($boss['bosskilldate'] != '') {
                                 $killdate = date('d-m-y', $boss['bosskilldate']);
                                 // convert UNIX timestamp to PHP DateTime
                             }
                             $template->assign_block_vars('zone.boss', array('BOSS_NAME' => $boss['bossname'], 'BOSS_IMAGENAME' => $phpbb_root_path . "images/bbdkp/gameworld/" . $Guild->game_id . "/bosses/" . $boss['imagename'] . ".png", 'BOSS_ID' => $boss['id'], 'BOSS_WEBID' => $boss['webid'], 'BOSS_TYPE' => $boss['type'], 'BOSS_URL' => sprintf($this->igame->getBossbaseurl(), $boss['webid']), 'BOSS_URLVIEW' => $phpbb_root_path . "images/bbdkp/icons/view.gif", 'BOSS_KILLED' => $boss['bosskilled'] == 1 ? 'checked="checked"' : '', 'BOSS_SHOW' => $boss['bossshow'] == 1 ? "checked=checked" : '', 'BOSS_KILLDATE' => $killdate, 'BOSS_COUNTER' => $boss['bosscounter'], 'S_BOSS_KILLED' => $boss['bosskilled']));
                         }
                     }
                 }
             }
             break;
     }
 }
Exemple #11
0
 /**
  * Member class constructor
  *
  * @param int $member_id
  * @param array $guildlist
  */
 function __construct($member_id = 0, $guildlist = null)
 {
     global $phpbb_root_path, $phpEx;
     parent::__construct();
     if (isset($member_id)) {
         if ($member_id > 0) {
             $this->member_id = $member_id;
             $this->Getmember();
         }
     } else {
         $this->member_id = 0;
     }
     $this->guildmemberlist = array();
     if ($guildlist == null) {
         //include the guilds class
         if (!class_exists('\\bbdkp\\controller\\guilds\\Guilds')) {
             require "{$phpbb_root_path}includes/bbdkp/controller/guilds/Guilds.{$phpEx}";
         }
         $guild = new \bbdkp\controller\guilds\Guilds();
         $this->guildlist = $guild->guildlist(1);
     } else {
         $this->guildlist = $guildlist;
     }
 }
Exemple #12
0
    function main($id, $mode)
    {
        global $db, $user, $template;
        global $config, $phpbb_admin_path, $phpEx;
        $user->add_lang(array('common'));
        $user->add_lang(array('mods/dkp_admin'));
        $user->add_lang(array('mods/dkp_common'));
        $user->add_lang(array('mods/apply'));
        $this->link = '<br /><a href="' . append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_apply&amp;mode=apply_settings") . '"><h3>' . $user->lang['APPLY_ACP_RETURN'] . '</h3></a>';
        $this->apptype = array('title' => $user->lang['APPLY_ACP_TITLE'], 'charname' => $user->lang['APPLY_ACP_CHARNAME'], 'gameraceclass' => $user->lang['APPLY_GAME'], 'regionrealm' => $user->lang['APPLY_REGION'], 'level' => $user->lang['APPLY_LEVEL'], 'gender' => $user->lang['APPLY_GENDER'], 'Inputbox' => $user->lang['APPLY_ACP_INPUTBOX'], 'Textbox' => $user->lang['APPLY_ACP_TXTBOX'], 'Textboxbbcode' => $user->lang['APPLY_ACP_TXTBOXBBCODE'], 'Selectbox' => $user->lang['APPLY_ACP_SELECTBOX'], 'Radiobuttons' => $user->lang['APPLY_ACP_RADIOBOX'], 'Checkboxes' => $user->lang['APPLY_ACP_CHECKBOX']);
        $Guild = new \bbdkp\controller\guilds\Guilds();
        $guildlist = $Guild->guildlist(1);
        foreach ($guildlist as $g) {
            $template->assign_block_vars('guild_row', array('VALUE' => $g['id'], 'SELECTED' => $g['id'] == $Guild->guildid ? ' selected="selected"' : '', 'OPTION' => !empty($g['name']) ? $g['name'] : '(None)'));
        }
        if (count($guildlist) == 0) {
            trigger_error($user->lang['ERROR_NOGUILD'], E_USER_WARNING);
        }
        switch ($mode) {
            case 'apply_edittemplate':
                $this->form_key = '554k6Qmm5clM3dUhq67jX0M';
                add_form_key($this->form_key);
                $appformsupdate = isset($_POST['update']) ? true : false;
                if ($appformsupdate) {
                    //do update and return
                    if (!check_form_key($this->form_key)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
                    }
                    $applytemplate_id = request_var('template_id', 0);
                    $sql_ary = array('template_name' => utf8_normalize_nfc(request_var('apptemplate_name', ' ', true)), 'guild_id' => request_var('candidate_guild_id', 0), 'forum_id' => request_var('applyforum_id', 0), 'question_color' => request_var('postqcolor', '#1961a9'), 'answer_color' => request_var('postacolor', '#4880b1'), 'gchoice' => request_var('addbbdkp', 0), 'statpos' => request_var('statpos', ''));
                    $sql = 'UPDATE ' . APPTEMPLATELIST_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE template_id = ' . $applytemplate_id;
                    $db->sql_query($sql);
                    // welcome text
                    $welcometext = utf8_normalize_nfc(request_var('welcome_message', '', true));
                    $uid = $bitfield = $options = '';
                    // will be modified by
                    $allow_bbcode = $allow_urls = $allow_smilies = true;
                    generate_text_for_storage($welcometext, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
                    $sql = 'UPDATE ' . APPHEADER_TABLE . " SET\n\t\t\t\t\t\t\t\tannouncement_msg = '" . (string) $db->sql_escape($welcometext) . "' ,\n\t\t\t\t\t\t\t\tannouncement_timestamp = " . (int) time() . " ,\n\t\t\t\t\t\t\t\tbbcode_bitfield = \t'" . (string) $bitfield . "' ,\n\t\t\t\t\t\t\t\tbbcode_uid = \t\t'" . (string) $uid . "'\n\t\t\t\t\t\t\tWHERE template_id = " . $applytemplate_id;
                    $db->sql_query($sql);
                    //colors
                    meta_refresh(1, append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_apply&amp;mode=apply_settings"));
                    trigger_error(sprintf($user->lang['ACP_APPLY_TEMPLATEEDIT_SUCCESS'], $applytemplate_id) . $this->link, E_USER_NOTICE);
                } else {
                    //display form
                    $applytemplate_id = request_var('applytemplate_id', 0);
                    $guildname = '';
                    //general template parameters
                    $result = $db->sql_query('SELECT * FROM ' . APPTEMPLATELIST_TABLE . ' WHERE template_id = ' . $applytemplate_id);
                    $template_info = $db->sql_fetchrowset($result);
                    $template_info = $template_info[0];
                    foreach ($guildlist as $key => $guild) {
                        if ($template_info['guild_id'] == $guild['id']) {
                            $guildname = $guild['name'];
                        }
                    }
                    $selected = '';
                    $statpos = array('APPLY_TOP' => $user->lang['APPLY_TOP'], 'APPLY_NOSTATS' => $user->lang['APPLY_NOSTATS'], 'APPLY_BOTTOM' => $user->lang['APPLY_BOTTOM']);
                    $s_statposition = '';
                    foreach ($statpos as $key => $value) {
                        $selected = $key == $template_info['statpos'] ? ' selected="selected"' : '';
                        $s_statposition .= '<option value="' . $key . '" ' . $selected . '> ' . $value . '</option>';
                    }
                    $foruminfo = $this->apply_get_forum_info($template_info['forum_id']);
                    // get welcome msg
                    $sql = 'SELECT announcement_msg, bbcode_bitfield, bbcode_uid FROM ' . APPHEADER_TABLE . ' WHERE template_id = ' . $applytemplate_id;
                    $result = $db->sql_query($sql);
                    $text = "";
                    $bitfield = "";
                    $uid = "";
                    while ($row = $db->sql_fetchrow($result)) {
                        $text = $row['announcement_msg'];
                        $bitfield = $row['bbcode_bitfield'];
                        $uid = $row['bbcode_uid'];
                    }
                    $db->sql_freeresult($result);
                    $textarr = generate_text_for_edit($text, $uid, $bitfield, 7);
                    $template->assign_vars(array('WELCOME_MESSAGE' => $textarr['text'], 'TEMPLATE_ID' => $applytemplate_id, 'STATSPOSITIONS' => $s_statposition, 'FORUMNAME' => $foruminfo['forum_name'], 'GUILDNAME' => $guildname, 'TEMPLATEFORUM_OPTIONS' => make_forum_select($template_info['forum_id'], false, false, true), 'TEMPLATE_NAME' => $template_info['template_name'], 'POSTQCOLOR' => $template_info['question_color'], 'POSTACOLOR' => $template_info['answer_color'], 'F_ADDBBDKP' => $template_info['gchoice']));
                }
                $this->page_title = $user->lang['ACP_DKP_APPLY_TEMPLATE_EDIT'];
                $this->tpl_name = 'dkp/acp_' . $mode;
                break;
            case 'apply_settings':
                // show settings
                $this->form_key = '2uE88d0k5Jy0ZWLQV53WKO2';
                add_form_key($this->form_key);
                // getting template definitions
                $applytemplate_id = request_var('applytemplate_id', request_var('apptemplate_id_hidden', 0));
                if ($applytemplate_id == 0) {
                    $i = 0;
                    // get first row
                    $result = $db->sql_query('SELECT * FROM ' . APPTEMPLATELIST_TABLE . ' ORDER BY template_id');
                    while ($row = $db->sql_fetchrow($result)) {
                        if ($i == 0) {
                            $applytemplate_id = $row['template_id'];
                        }
                        $i += 1;
                    }
                    $db->sql_freeresult($result);
                }
                /**
                 * handlers
                 */
                /*
                 * general appform settings
                 */
                if (isset($_POST['appformsettings'])) {
                    $this->appformsettings();
                }
                /**
                 * deleting an entire template
                 */
                if (isset($_GET['apptemplatedelete'])) {
                    $this->apptemplatedelete($applytemplate_id);
                }
                /**
                 * adding an new template
                 */
                if (isset($_POST['apptemplateadd'])) {
                    $this->apptemplate_add();
                }
                /**
                 * adds a template question
                 */
                if (isset($_POST['appformquestionadd'])) {
                    $this->appformquestion_add($applytemplate_id);
                }
                /**
                 * deletes a template question
                 */
                if (isset($_GET['appquestiondelete'])) {
                    $this->question_delete();
                }
                /**
                 * updates template question
                 */
                if (isset($_POST['appformquestionupdate'])) {
                    $this->appformquestionupdate($applytemplate_id);
                }
                // user pressed question order arrows
                if (isset($_GET['appquestionmove_up'])) {
                    $this->movequestion(-1, $applytemplate_id);
                }
                if (isset($_GET['appquestionmove_down'])) {
                    $this->movequestion(1, $applytemplate_id);
                }
                /**
                 * loading template types
                 */
                $result = $db->sql_query('SELECT * FROM ' . APPTEMPLATELIST_TABLE);
                $guildname = '';
                while ($row = $db->sql_fetchrow($result)) {
                    foreach ($guildlist as $key => $guild) {
                        if ($row['guild_id'] == $guild['id']) {
                            $guildname = $guild['name'];
                        }
                    }
                    $foruminfo = $this->apply_get_forum_info($row['forum_id']);
                    $template->assign_block_vars('apptemplatelist', array('ID' => $row['template_id'], 'STATUS' => $row['status'], 'TEMPLATE_NAME' => $row['template_name'], 'GUILDNAME' => $guildname, 'ADDBBDKP' => $row['gchoice'] == 0 ? $user->lang['NO'] : $user->lang['YES'], 'FORUMID' => $foruminfo['forum_name'], 'SELECTED' => $applytemplate_id == $row['template_id'] ? ' selected = "selected"' : '', 'FORUM_OPTIONS' => make_forum_select($row['forum_id'], false, false, true), 'U_DELETE_TEMPLATE' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_apply&amp;mode=apply_settings&amp;apptemplatedelete=1&amp;applytemplate_id={$row['template_id']}"), 'U_EDIT_TEMPLATE' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_apply&amp;mode=apply_edittemplate&amp;applytemplate_id={$row['template_id']}")));
                }
                $db->sql_freeresult($result);
                /*
                 * loading app questions
                 * 12 question types supported
                 */
                foreach ($this->apptype as $key => $value) {
                    $template->assign_block_vars('template_type', array('TYPE' => $key, 'VALUE' => $value, 'SELECTED' => $key == $applytemplate_id ? ' selected="selected"' : ''));
                }
                $sql = 'SELECT * FROM ' . APPTEMPLATE_TABLE . ' a
                		INNER JOIN ' . APPTEMPLATELIST_TABLE . ' b
		                ON b.template_id = a.template_id
		                WHERE a.template_id = ' . $applytemplate_id . '
		                ORDER BY a.qorder ';
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $checked = '';
                    if ($row['mandatory'] == 'True') {
                        $checked = ' checked="checked"';
                    }
                    $questionshow = '';
                    if ((int) $row['showquestion'] == 1) {
                        $questionshow = ' checked="checked"';
                    }
                    $titleinvisible = '';
                    $optioninvisible = '';
                    $questioninvisible = '';
                    $optionenabled = '';
                    switch ($row['type']) {
                        case 'title':
                            $questioninvisible = ' visibility:hidden;';
                            $optionenabled = ' disabled="disabled"';
                            $optioninvisible = ' visibility:hidden;';
                            break;
                        case 'charname':
                        case 'gameraceclass':
                        case 'regionrealm':
                        case 'level':
                        case 'gender':
                            $titleinvisible = ' visibility:hidden;';
                            $questioninvisible = ' visibility:hidden;';
                            $optionenabled = ' disabled="disabled"';
                            $optioninvisible = ' visibility:hidden;';
                            break;
                        case 'Inputbox':
                        case 'Textbox':
                        case 'Textboxbbcode':
                            $optionenabled = ' disabled="disabled"';
                            $optioninvisible = ' visibility:hidden;';
                            break;
                        case 'Selectbox':
                        case 'Radiobuttons':
                        case 'Checkboxes':
                            break;
                    }
                    $template->assign_block_vars('apptemplate', array('QORDER' => $row['qorder'], 'TEMPLATE' => $row['template_name'], 'HEADER' => $row['header'], 'QUESTION' => $row['question'], 'TITLEINVISIBLE' => $titleinvisible, 'QUESTIONINVISIBLE' => $questioninvisible, 'MANDATORY' => $row['mandatory'], 'OPTIONS' => $row['options'], 'QMANDATORY_CHECKED' => $questionshow, 'OPTIONDISABLED' => $optionenabled, 'OPTIONINVISIBLE' => $optioninvisible, 'CHECKED' => $checked, 'ID' => $row['id'], 'U_APPQUESTIONMOVE_UP' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_apply&amp;mode=apply_settings&amp;appquestionmove_up=1&amp;id={$row['id']}&amp;applytemplate_id=" . $applytemplate_id), 'U_APPQUESTIONMOVE_DOWN' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_apply&amp;mode=apply_settings&amp;appquestionmove_down=1&amp;id={$row['id']}&amp;applytemplate_id=" . $applytemplate_id), 'U_APPQUESTIONDELETE' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=dkp_apply&amp;mode=apply_settings&amp;appquestiondelete=1&amp;id={$row['id']}&amp;applytemplate_id=" . $applytemplate_id)));
                    foreach ($this->apptype as $key => $value) {
                        $template->assign_block_vars('apptemplate.template_type', array('TYPE' => $key, 'VALUE' => $value, 'SELECTED' => $key == $row['type'] ? ' selected="selected"' : ''));
                    }
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('TEMPLATE_ID' => $applytemplate_id, 'ADDTEMPLATEFORUM_OPTIONS' => make_forum_select(0, false, false, true), 'REALM' => str_replace("+", " ", $config['bbdkp_apply_realm']), 'APPLY_VERS' => $config['bbdkp_apply_version']));
                $this->page_title = $user->lang['ACP_DKP_APPLY'];
                $this->tpl_name = 'dkp/acp_' . $mode;
                break;
        }
    }