Beispiel #1
0
    public function add_km_to_user($id, $meeting_km = false, $return_form)
    {
        global $user, $db, $config, $meeting_config, $phpbb_root_path, $phpEx;
        if (!$meeting_km || $meeting_km == '') {
            trigger_error($user->lang['Err_kilom_1'] . $return_form);
        } elseif ($meeting_km < 0) {
            trigger_error($user->lang['Err_kilom_2'] . $return_form);
        } else {
            $meeting_km = round($meeting_km);
            // Добавление км участникам
            $sql = "SELECT meeting_km, meeting_by_user, meeting_coorg, meeting_marshrut \n\t\t\t\tFROM " . MEETING_DATA_TABLE . "\n\t\t\t\tWHERE meeting_id = {$id}";
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $meet_tekush_km = $row['meeting_km'];
                $meet_organizator = $row['meeting_by_user'];
                $meeting_coorg = $row['meeting_coorg'];
                $meeting_marshrut = $row['meeting_marshrut'];
            }
            $db->sql_freeresult($result);
            $sql = "SELECT m.*, u1.user_id as user, u1.user_meeting_uchast, u1.user_km, u1.user_reputation, u1.group_id FROM " . MEETING_USER_TABLE . " m, " . USERS_TABLE . " u1\n\t\t\t\tWHERE m.meeting_id = {$id}\n\t\t\t\tAND m.user_id = u1.user_id\n\t\t\t\tORDER BY user_id";
            $result = $db->sql_query($sql);
            $vicherk_rows = $uchast_rows = array();
            while ($row = $db->sql_fetchrow($result)) {
                $vicherk_rows[] = $row;
                if ($row['group_id'] == 1194 || $row['group_id'] == 44) {
                    $uchast_rows[] = $row['user_id'];
                }
            }
            $db->sql_freeresult($result);
            $total_uchast = count($vicherk_rows);
            // Цикл по участникам
            if ($total_uchast != 0) {
                $sql_in = '';
                for ($i = 0; $i < $total_uchast; $i++) {
                    $id_uchastnik = $vicherk_rows[$i]['user_id'];
                    $sql = "SELECT user_id, pf_user_km FROM " . PROFILE_FIELDS_DATA_TABLE . "\n\t\t\t\t\t\tWHERE user_id = {$id_uchastnik}";
                    $result = $db->sql_query($sql);
                    $row = $db->sql_fetchrow($result);
                    $db->sql_freeresult($result);
                    $user_tekush_km = $row['pf_user_km'];
                    $user_raschet_km = $user_tekush_km + $meeting_km - $meet_tekush_km;
                    $user_raschet_km = $user_raschet_km <= 0 ? 0 : $user_raschet_km;
                    $sql = "SELECT user_id, pf_user_km FROM " . PROFILE_FIELDS_DATA_TABLE . "\n\t\t\t\t\t\tWHERE user_id = {$id_uchastnik}";
                    $result = $db->sql_query($sql);
                    $row = $db->sql_fetchrow($result);
                    $db->sql_freeresult($result);
                    if (!$row) {
                        $sql = "INSERT INTO " . PROFILE_FIELDS_DATA_TABLE . " (user_id, pf_user_km) VALUES ({$id_uchastnik}, {$meeting_km})";
                        $db->sql_query($sql);
                    } else {
                        $sql = "UPDATE " . PROFILE_FIELDS_DATA_TABLE . "\n\t\t\t\t\t\t\tSET pf_user_km = {$user_raschet_km}\n\t\t\t\t\t\t\tWHERE user_id = {$id_uchastnik}";
                        $db->sql_query($sql);
                    }
                    $sql_in .= ($sql_in != '' ? ', ' : '') . intval($id_uchastnik);
                }
            } else {
                trigger_error($user->lang['NO_KM_NULL_UCHAST'] . $return_form);
            }
            // Проверка групп.
            $group_members = array();
            $sql = "SELECT user_id, group_id FROM " . USER_GROUP_TABLE . "  \n\t\t\t\t\tWHERE group_id = 44 \n\t\t\t\t\tAND user_id IN ({$sql_in})\n\t\t\t\t\tORDER BY user_id";
            $result = $db->sql_query($sql);
            $db->sql_freeresult($result);
            if ($result) {
                do {
                    $group_members[] = $row['user_id'];
                } while ($row = $db->sql_fetchrow($result));
                $members_count = count($group_members);
            } else {
                $members_count = 0;
            }
            if (sizeof($uchast_rows)) {
                $newuser = array_diff($uchast_rows, $group_members);
            }
            // Добавление Участников в группу "участники"
            $users = $uchast_rows;
            if (!function_exists('auto_group')) {
                include $phpbb_root_path . 'includes/functions_autogroup.' . $phpEx;
            }
            auto_group($users);
            $sql_ary = array('meeting_km' => $meeting_km);
            $sql = 'UPDATE ' . MEETING_DATA_TABLE . '
					SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
					WHERE meeting_id = ' . $id;
            $db->sql_query($sql);
            $total_tekush_km = $meeting_config['total_km'];
            $total_raschet_km = $total_tekush_km + $meeting_km - $meet_tekush_km;
            $sql_ary_t = array('config_value' => $total_raschet_km);
            $sql = 'UPDATE ' . MEETING_CONFIG_TABLE . '
					SET ' . $db->sql_build_array('UPDATE', $sql_ary_t) . '
					WHERE config_name = "total_km"';
            $db->sql_query($sql);
            //Повышение репутации (сделать участников массивом)
            if ($config['rp_enable'] && $meet_tekush_km == 0) {
                include_once $phpbb_root_path . 'includes/functions_reputation.' . $phpEx;
                add_rep_meeting($vicherk_rows, $id, $meet_organizator, $meeting_coorg);
            }
            if ($meeting_marshrut) {
                add_marshrut_km($id, $meeting_km);
            }
        }
    }
Beispiel #2
0
                                $group_members[] = $row['user_id'];
                            } while ($row = $db->sql_fetchrow($result));
                            $members_count = count($group_members);
                        } else {
                            $members_count = 0;
                        }
                        if (sizeof($uchast_rows)) {
                            $newuser = array_diff($uchast_rows, $group_members);
                        }
                        // Добавление Участников в группу "участники"
                        $users = $uchast_rows;
                        if (!function_exists('auto_group')) {
                            include $phpbb_root_path . 'includes/functions_autogroup.' . $phpEx;
                        }
                        if (sizeof($users)) {
                            auto_group($users);
                        }
                        //------------------------------------------
                        $sql_ary = array('meeting_km' => $meeting_km);
                        $sql = 'UPDATE ' . MEETING_DATA_TABLE . '
			SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
			WHERE meeting_id = ' . $id;
                        $db->sql_query($sql);
                        $total_tekush_km = $meeting_config['total_km'];
                        $total_raschet_km = $total_tekush_km + $meeting_km - $meet_tekush_km;
                        $sql_ary_t = array('config_value' => $total_raschet_km);
                        $sql = 'UPDATE ' . MEETING_CONFIG_TABLE . '
			SET ' . $db->sql_build_array('UPDATE', $sql_ary_t) . '
			WHERE config_name = "total_km"';
                        $db->sql_query($sql);
                        if ($meeting_marshrut) {
Beispiel #3
0
             $sql = "INSERT INTO " . PROFILE_FIELDS_DATA_TABLE . " (user_id, pf_meeting_uchast) VALUES ({$meeting_user}, 1)";
             $db->sql_query($sql);
         } else {
             $new_meeting_km = $row['pf_user_km'] + $meeting_km;
             $count_uchast = $row['pf_meeting_uchast'] + 1;
             $sql = "UPDATE " . PROFILE_FIELDS_DATA_TABLE . "\n\t\t\t\t\t\tSET pf_meeting_uchast = {$count_uchast},\n\t\t\t\t\t\tpf_user_km = {$new_meeting_km}\n\t\t\t\t\t\tWHERE user_id = {$meeting_user}";
             $db->sql_query($sql);
         }
     }
 }
 //------------------------------------
 // Äîáàâëåíèå Ó÷àñòíèêà â ãðóïïó "ó÷àñòíèêè", åñëè ïîêàçàòåëè ìåíüøå óñòàíîâëåííûõ
 if (!function_exists('auto_group')) {
     include $phpbb_root_path . 'includes/functions_autogroup.' . $phpEx;
 }
 auto_group($meeting_user);
 // Âîçðàñò çàïèñûâàåìîãî ó÷àñòíèêà
 // Start add - Birthday MOD
 $meeting_user_age = 0;
 $now = getdate(time() + $user->timezone + $user->dst - date('Z'));
 list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $that_usr_birthday));
 if ($bday_year) {
     $diff = $now['mon'] - $bday_month;
     if ($diff == 0) {
         $diff = $now['mday'] - $bday_day < 0 ? 1 : 0;
     } else {
         $diff = $diff < 0 ? 1 : 0;
     }
     $meeting_user_age = (int) ($now['year'] - $bday_year - $diff);
 }
 // End add - Birthday MOD