source: Forum/includes/functions_wow_ext.php @ 310

Revision 310, 257.6 KB checked in by darkman83, 15 months ago (diff)

+ LoLCoP FAQ Erweiterung um Voting Points

Line 
1<?php
2/**
3 *
4 * @package phpBB3
5 * @version $Id: functions_user.php 8494 2008-04-07 17:07:54Z acydburn $
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
8 *
9 */
10/**
11 * @ignore
12 */
13if ( ! defined ( 'IN_PHPBB' ) ) {
14    exit ( );
15}
16class wow_normal
17{
18    public $itemperpage;
19    public $db_id;
20    protected $num_queriess;
21    protected $tot_queries;
22    protected $query_result;
23    protected $tCount;
24    protected $aSql;
25    protected $sql_errs = array ();
26    protected $root_db = 0;
27    protected $forum_db = 0;
28    protected $realm_online = array ( false, false );
29    public $point_config;
30    protected $querys_register = array ();
31    protected $gallery_upload_dir;
32    protected $lol_conf = array ();
33
34    public function __construct ()
35    {
36        global $phpbb_root_path;
37        require ( $phpbb_root_path . 'config.php' );
38        require ( $phpbb_root_path . 'lol_points_config.php' );
39       
40        $this->point_config ['req'] = $points_req;
41        $this->point_config ['get'] = $points_get;
42        $this->point_config ['day'] = $points_day;
43        $this->point_config ['other'] = array ( $max_chartrans, $max_log_entries, $welcome_points, $vip_active, $lvl_multi, $max_upper_exchange, $faction_change_price );
44        $this->gallery_upload_dir = $uploaddir;
45        $this->lol_conf = $lol_config [1];
46        if ( $this->test_realm ( ) ) $this->realm_online [0] = true;
47        if ( $this->test_realm ( 2 ) ) $this->realm_online [1] = true;
48       
49
50        $this->aSql = array ();
51        $this->tCount = array ();
52        $this->root_db = $this->connect ( $this->lol_conf ['db_host_live'], $this->lol_conf ['db_live_user'], $this->lol_conf ['db_live_password'], $this->lol_conf ['db_live_accounts'] );
53        $this->forum_db = $this->connect ( $dbhost, $dbuser, $dbpasswd, $dbname );
54    }
55
56    public function __destruct ()
57    {
58        foreach ( $this->querys_register as $query )
59            $free = $this->free_result ( $query );
60        $this->close_all ( );
61        unset ( $this->itemperpage );
62        unset ( $this->db_id );
63        unset ( $this->num_queriess );
64        unset ( $this->tot_queries );
65        unset ( $this->query_result );
66        unset ( $this->root_db );
67        unset ( $this->forum_db );
68        unset ( $this->mangos_ip );
69        unset ( $this->mangos_p );
70        unset ( $this->realm_online );
71        unset ( $this->point_config );
72    }
73
74    /**
75     * @param $sqlserver
76     * @param $sqluser
77     * @param $sqlpassword
78     * @param $database
79     * @param $port
80     * @param $persistency
81     * @param $new_link
82     * @return unknown_type
83     */
84    protected function connect ( $sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false )
85    {
86        $server = $sqlserver . ( ( $port ) ? ':' . $port : '' );
87        $dbname = $database;
88        $db_con_id = ( $persistency ) ? @mysql_pconnect ( $server, $sqluser, $sqlpassword, MYSQL_CLIENT_COMPRESS ) : @mysql_connect ( $server, $sqluser, $sqlpassword, $new_link, MYSQL_CLIENT_COMPRESS );
89       
90        if ( $db_con_id && $dbname != '' ) {
91            if ( @mysql_select_db ( $dbname, $db_con_id ) ) @mysql_query ( "SET NAMES 'utf8'", $db_con_id );
92            return $db_con_id;
93        }
94        return false;
95    }
96
97    /**
98     * @param $db_name
99     * @param $db_id
100     * @return unknown_type
101     */
102    protected function db ( $db_name, $db_id )
103    {
104        if ( $db_id ) {
105            if ( @mysql_select_db ( $db_name, $db_id ) ) return $db_id;
106            else die ( $this->error ( '' ) );
107        }
108        else
109            die ( $this->error ( '' ) );
110    }
111
112    /**
113     * @param $sql
114     * @param $db_id
115     * @return unknown_type
116     */
117    protected function query ( $sql, $db_id, $print = false )
118    {
119        if ( ! stristr ( $sql, 'benchmark' ) ) {
120            $query_result = @mysql_query ( $sql, $db_id );
121            if ( $print ) print $sql . "<br>";
122            if ( $query_result ) {
123                ++ $this->num_queriess;
124                $this->query_result = $query_result;
125                $this->querys_register [ ] = $query_result;
126                return $query_result;
127            }
128            else
129                return false;
130        }
131        else {
132            $this->log_db ( $db_id, $sql );
133            return false;
134        }
135    }
136
137    /**
138     * @param $query_id
139     * @param $row
140     * @param $field
141     * @return unknown_type
142     */
143    protected function result ( $query_id = 0, $row = 0 )
144    {
145        if ( $query_id ) {
146            if ( $row ) $cur_row = @mysql_data_seek ( $query_id, $row );
147            $cur_row = @mysql_fetch_row ( $query_id );
148            return $cur_row [0];
149        }
150        else
151            return false;
152    }
153
154    /**
155     * @param $query_id
156     * @return unknown_type
157     */
158    protected function fetch_row ( $query_id = 0 )
159    {
160        return ( $query_id ) ? @mysql_fetch_row ( $query_id ) : false;
161    }
162
163    /**
164     * @param $query_id
165     * @return unknown_type
166     */
167    protected function fetch_array ( $query_id = 0 )
168    {
169        return ( $query_id ) ? @mysql_fetch_array ( $query_id, MYSQL_BOTH ) : false;
170    }
171
172    /**
173     * @param $query_id
174     * @return unknown_type
175     */
176    protected function fetch_assoc ( $query_id = 0 )
177    {
178        return ( $query_id ) ? @mysql_fetch_assoc ( $query_id ) : false;
179    }
180
181    /**
182     * @param $result
183     * @return unknown_type
184     */
185    protected function fetch_field ( $result = 0, $number )
186    {
187        return ( $result ) ? @mysql_fetch_field ( $result, $number ) : false;
188    }
189
190    /** Add a sql statement **/
191    protected function trans_AddSql ( $sql, $num = 0 )
192    {
193        $this->tCount [$num] ++;
194        $this->aSql [$num] [$this->tCount [$num]] = $sql;
195    }
196
197    // Execute transactions
198    protected function trans_Execute ( $id = 0, $num )
199    {
200        // If start transaction ok
201        if ( $this->trans_ExecuteSQL ( $id, "START TRANSACTION" ) ) {
202            $res = false;
203           
204            // Executes a sql statements
205            for ( $i = 1; $i <= count ( $this->aSql [$num] ); $i ++ ) {
206                $res = $this->trans_ExecuteSQL ( $id, $this->aSql [$num] [$i], $num );
207                // Abort, if any error
208                if ( ! $res ) break;
209            }
210           
211            // If all statements executes ok, commit transaction else rollback.
212            if ( $res ) {
213                $res = $this->trans_ExecuteSQL ( $id, "COMMIT", $num );
214                $this->aSql [$num] = '';
215                return true;
216            }
217            else {
218                $res = $this->trans_ExecuteSQL ( $id, "ROLLBACK", $num );
219                $this->aSql [$num] = '';
220                return false;
221            }
222        }
223    }
224
225    // Executes a sql statement in  MySQL database
226    protected function trans_ExecuteSQL ( $id, $sql, $num = 0, $erro = 1 )
227    {
228        if ( empty ( $sql ) || ! ( $id ) ) return 0; // Error in connection or SQL clausrule.
229       
230
231
232        if ( ! ( $res = @mysql_query ( $sql, $id ) ) ) {
233            if ( $erro ) {
234                $t_err = $this->error ( $id );
235                $this->sql_errs [$num] [ ] = array ( $t_err ['code'], $t_err ['message'], $sql );
236                return 0;
237            }
238        }
239       
240        return $res;
241    }
242
243    /**
244     * @param $query_id
245     * @return unknown_type
246     */
247    protected function num_rows ( $query_id = 0 )
248    {
249        return ( $query_id ) ? @mysql_num_rows ( $query_id ) : false;
250    }
251
252    /**
253     * @param $query_id
254     * @return unknown_type
255     */
256    protected function num_fields ( $query_id = 0 )
257    {
258        return ( $query_id ) ? @mysql_num_fields ( $query_id ) : false;
259    }
260
261    /**
262     * @param $db_id
263     * @return unknown_type
264     */
265    protected function affected_rows ( $db_id )
266    {
267        return ( $db_id ) ? @mysql_affected_rows ( $db_id ) : false;
268    }
269
270    /**
271     * @param $db_id
272     * @return unknown_type
273     */
274    protected function insert_id ( $db_id )
275    {
276        return ( $db_id ) ? @mysql_insert_id ( $db_id ) : false;
277    }
278
279    /**
280     * @return unknown_type
281     */
282    protected function get_num_queries ()
283    {
284        return $this->num_queriess;
285    }
286
287    /**
288     * @param $query_id
289     * @return unknown_type
290     */
291    protected function free_result ( $query_id = false )
292    {
293        if ( $query_id === false ) {
294            $query_id = $this->query_result;
295        }
296        return ( $query_id ) ? @mysql_free_result ( $query_id ) : false;
297    }
298
299    /**
300     * @param $value
301     * @param $db_id
302     * @return unknown_type
303     */
304    protected function quote_smart ( $value, $db_id )
305    {
306        if ( is_array ( $value ) ) {
307            $temp = array ();
308            foreach ( $value as $val )
309                $temp [ ] = $this->quote_smart ( $val, $db_id );
310            return $temp;
311        }
312        else {
313            if ( get_magic_quotes_gpc ( ) ) $value = stripslashes ( $value );
314            if ( $value === '' ) $value = NULL;
315            //$this->log_db ( $db_id, $value, "quote_smart" );
316            return @mysql_real_escape_string ( $value, $db_id );
317        }
318    }
319
320    /**
321     * @param $db_id
322     * @return unknown_type
323     */
324    protected static function error ( $db_id )
325    {
326        if ( ! $db_id ) return array ( 'message' => @mysql_connect_error ( ), 'code' => @mysql_connect_errno ( ) );
327        return array ( 'message' => @mysql_error ( $db_id ), 'code' => @mysql_errno ( $db_id ) );
328    }
329
330    /**
331     * @param $db_id
332     * @return unknown_type
333     */
334    protected function all_errors ( $num = 0 )
335    {
336        $errs = '';
337       
338        if ( is_array ( $this->sql_errs ) ) {
339            foreach ( $this->sql_errs [$num] as $err )
340                $errs .= "{$err[0]}: {$err[1]} -- SQL: {$err[2]}<br>";
341        }
342       
343        return $errs;
344    }
345
346    /**
347     * @param $db_id
348     * @return unknown_type
349     */
350    protected function close ( $db_id )
351    {
352        $this->tot_queries += $this->num_queriess;
353        if ( $db_id ) {
354            if ( $this->query_result ) @mysql_free_result ( $this->query_result );
355            $db_id_holder = $db_id;
356            $closed = @mysql_close ( $db_id );
357            return $closed;
358        }
359        else
360            return false;
361    }
362
363    /**
364     * @param $db_id
365     * @return unknown_type
366     */
367    protected function sql_nextid ( $db_id )
368    {
369        return ( $db_id ) ? @mysql_insert_id ( $db_id ) : false;
370    }
371
372    protected function table_exists ( $tablename, $db, $resource )
373    {
374        // Get a list of tables contained within the database.
375        $result = @mysql_list_tables ( $db, $resource );
376        $rcount = @mysql_num_rows ( $result );
377        // Check each in list for a match.
378        for ( $i = 0; $i < $rcount; $i ++ ) {
379            if ( @mysql_tablename ( $result, $i ) == $tablename ) return true;
380        }
381        return false;
382    }
383
384    public static function log_db ( $db_resource, $query_value, $db_action = '' )
385    {
386        global $user;
387        echo "<br>in function<br>";
388        //if ( $db_resource !== $this->dona_db ) {
389        $time = date ( 'd.m.y - G:i:s' );
390        $get_error = wow_normal::error ( $db_resource );
391        $is_error = ( strlen ( $get_error [0] ) > 0 ) ? ( $get_error [0] . " " . $get_error [1] ) : "No Error";
392        $path = $_SERVER ["DOCUMENT_ROOT"] . "/log/webuser.log";
393        $log_data = ( ! empty ( $user ) ) ? sprintf ( "User IP: %s\nTime: %s\n%s\nQuery: \"%s\"\nAction: %s\nError: %s\n\n", $user->data ['username'], $user->data ['user_ip'], $time, $db_resource, $query_value, $db_action, $is_error ) : sprintf ( "User IP: %s\nTime: %s\n%s\nQuery: \"%s\"\nAction: %s\nError: %s\n\n", wow_normal::get_ip_address ( ), $time, $db_resource, $query_value, $db_action, $is_error );
394        $file = fopen ( $path, "a" );
395        fwrite ( $file, $log_data );
396        fclose ( $file );
397   
398
399     //}
400    }
401
402    public static function get_ip_address ()
403    {
404        foreach ( array ( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ) as $key ) {
405            if ( array_key_exists ( $key, $_SERVER ) === true ) {
406                foreach ( explode ( ',', $_SERVER [$key] ) as $ip ) {
407                    if ( filter_var ( $ip, FILTER_VALIDATE_IP ) !== false ) {return $ip;}
408                }
409            }
410        }
411    }
412
413    /**
414     * @param $arr
415     * @param $search
416     * @param $exact
417     * @param $trav_keys
418     * @return unknown_type
419     */
420    protected function array_search_ext ( $arr, $search, $exact = true, $trav_keys = null )
421    {
422        if ( ! is_array ( $arr ) || ! $search || ( $trav_keys && ! is_array ( $trav_keys ) ) ) return false;
423        $res_arr = array ();
424        foreach ( $arr as $key => $val ) {
425            $used_keys = $trav_keys ? array_merge ( $trav_keys, array ( $key ) ) : array ( $key );
426            if ( ( $key === $search ) || ( ! $exact && ( strpos ( strtolower ( $key ), strtolower ( $search ) ) !== false ) ) ) $res_arr [ ] = array ( 'type' => "key", 'hit' => $key, 'keys' => $used_keys, 'val' => $val );
427            if ( is_array ( $val ) && ( $children_res = $this->array_search_ext ( $val, $search, $exact, $used_keys ) ) ) $res_arr = array_merge ( $res_arr, $children_res );
428            else if ( ! is_array ( $val ) && ( ( $val === $search ) || ( ! $exact && ( strpos ( strtolower ( $val ), strtolower ( $search ) ) !== false ) ) ) ) $res_arr [ ] = array ( 'type' => "val", 'hit' => $val, 'keys' => $used_keys, 'val' => $val );
429        }
430        return $res_arr ? $res_arr : false;
431    }
432
433    /**
434     * @return unknown_type
435     */
436    public function test_realm ( $realmId = 1 )
437    {
438        $realm = array ( 1 => array ( $this->lol_conf ['world_ext_ip_pve'], '8100' ), 2 => array ( $this->lol_conf ['world_ext_ip_vanilla'], '8200' ) );
439       
440        $s = @fsockopen ( $realm [$realmId] [0], $realm [$realmId] [1], $ERROR_NO, $ERROR_STR, (float) 0.5 );
441        if ( $s ) {
442            @fclose ( $s );
443            return true;
444        }
445        else
446            return false;
447    }
448
449    /**
450     * Account per ID oder ID per Accountname Herausfinden
451     *
452     * @param str $username
453     * @param int $accid
454     * @param str $game
455     * @return ID-OR-NAME
456     */
457   
458        protected function get_account_id_name ( $username = '', $accid = '', $charname = '', $db_table_acc = '', $game = 'wotlk' )
459    {
460        if ( ! $this->forum_db ) return "Datenbank Verbindungsfehler!";
461        if (empty($db_table_acc) && $game == 'wotlk') $db_table_acc = $this->lol_conf ['db_live_accounts'];
462        if (empty($db_table_acc) && $game == 'vanilla') $db_table_acc = $this->lol_conf ['db_live_vanilla_accounts'];
463       
464        if ( ! empty ( $username ) && empty ( $accid ) ) {
465            $username = strtolower ( $username );
466            $sql = "SELECT `id` FROM `{$db_table_acc}`.`account` WHERE `username` = '{$username}'";
467            $id = $this->query ( $sql, $this->forum_db );
468            return $this->result ( $id );
469        }
470        if ( ! empty ( $accid ) && empty ( $username ) ) {
471            $sql = "SELECT `username` FROM `{$db_table_acc}`.`account` WHERE `id` = '{$accid}'";
472            $name = $this->query ( $sql, $this->forum_db );
473            return $this->result ( $name );
474        }
475        if ( ! empty ( $charname ) ) {
476                if( $game == 'wotlk' )
477                $sql = "SELECT `account` FROM `{$this->lol_conf['db_pve_live_characters']}`.`characters` WHERE `name` = '{$charname}'";
478            else if( $game == 'vanilla' )
479                $sql = "SELECT `account` FROM `{$this->lol_conf['db_vanilla_live_characters']}`.`characters` WHERE `name` = '{$charname}'";
480           
481            $id = $this->query ( $sql, $this->forum_db );
482            return $this->result ( $id );
483        }
484        return 0;
485    }
486
487    /**
488     * Account Charactere auslesen und name + GUID als SELECT HTML Code Ausgeben oder nur die GUID als Zahl
489     *
490     * @param str $username
491     * @param bool $db
492     * @param bool $is_dev
493     * @param str $char
494     * @param bool $offline
495     * @param bool $char_only
496     * @param bool $chars_only
497     * @return GUID-OR-SELECT
498     */
499    public function get_account_chars ( $username, $db = false, $is_dev = false, $char = '', $offline = true, $char_only = false, $chars_only = false )
500    {
501        if ( empty ( $db ) ) $db = $this->forum_db;
502        if ( ! $db ) return "Datenbank Verbindungsfehler!";
503        if ( $is_dev ) $type = $this->lol_conf ['db_pve_dev_characters'];
504        else $type = $this->lol_conf ['db_pve_live_characters'];
505       
506        if ( ! empty ( $username ) ) {
507            if ( $char_only && ! empty ( $char ) ) {
508                $query = $this->result ( $this->query ( "SELECT `guid` FROM `{$type}`.`characters` WHERE `name` = '{$char}'", $db ) );
509                if ( ! $query ) return false;
510                return $query;
511            }
512            else {
513                if ( $offline ) $offline = " AND `online` = '0'";
514                $id = $this->get_account_id_name ( $username );
515                if ( ! $id ) return;
516                $query = $this->query ( "SELECT `guid`,`name` FROM `{$type}`.`characters` WHERE `account` = '{$id}'{$offline}", $db );
517                $select_code = '';
518                $chars = array ();
519                while ( $r = $this->fetch_assoc ( $query ) ) {
520                    if ( $chars_only ) $chars [ ] = $r ['name'];
521                    else {
522                        $guid = $r ['guid'];
523                        $name = $r ['name'];
524                        $select_code .= "<option value=\"{$guid}||{$name}\">&nbsp;{$name}&nbsp;</option>";
525                    }
526                }
527                return $chars_only ? $chars : $select_code;
528            }
529        }
530        return false;
531    }
532
533    /**
534     * @return online_players
535     */
536    private function players_online ()
537    {
538        $online = array ( 'PvE' => 0, 'VANILLA' => 0 );
539       
540        $template = $this->check_template ( "playersonline", "", 30 );
541        if ( $template ) return $template;
542       
543        if ( $this->realm_online [0] ) {
544            $stats_sql = "SELECT COUNT(`guid`) FROM `{$this->lol_conf ['db_pve_live_characters']}`.`characters` WHERE `online`='1'";
545            $query = $this->query ( $stats_sql, $this->forum_db );
546            $online ['PvE'] = $this->result ( $query );
547        }
548       
549        if ( $this->realm_online [1] ) {
550            $query2 = $this->query ( "SELECT COUNT(`guid`) FROM `{$this->lol_conf ['db_vanilla_live_characters']}`.`characters` WHERE `online`='1'", $this->forum_db );
551            $online ['VANILLA'] = $this->result ( $query2 );
552        }
553       
554        if ( $this->realm_online [0] /*&& $this->realm_online [1]*/ ) $this->check_template ( "playersonline", serialize ( $online ), 180, false, true, false );
555        else $this->check_template ( "playersonline", serialize ( $online ), 60, false, true, false );
556       
557        return $online;
558    }
559
560    /**
561     * @return online_mini_stats
562     */
563    private function max_players ( $realmId, $vanilla = false )
564    {
565        $vanilla_string = ( $vanilla ) ? 'vanilla' : '';
566       
567        if ( ! $this->cpu_load_to_high ( ) && ( $this->realm_online [0] || $this->realm_online [1] ) ) {
568            /*$ministats = $this->check_template ( "ministats_{$realmId}{$vanilla_string}", "", 120 );
569            if ( $ministats ) return $ministats;*/
570           
571            $which_db = ( $vanilla ) ? $this->lol_conf ['db_live_vanilla_accounts'] : $this->lol_conf ['db_live_accounts'];
572           
573            $max_player = $this->fetch_row ( $this->query ( "SELECT `starttime`, max(`maxplayers`),`uptime` FROM `{$which_db}`.`uptime` WHERE `realmid` = '{$realmId}' GROUP BY `startstring` ORDER BY 2 DESC LIMIT 1", $this->forum_db ) );
574            $max_curr = $this->result ( $this->query ( "SELECT `uptime` FROM `{$which_db}`.`uptime` WHERE `realmid` = '{$realmId}' ORDER BY `starttime` DESC LIMIT 1", $this->forum_db ) );
575            $max_time = $this->result ( $this->query ( "SELECT `uptime` FROM `{$which_db}`.`uptime` WHERE `realmid` = '{$realmId}' ORDER BY `uptime` DESC LIMIT 1", $this->forum_db ) );
576            $max = "( {$max_player[1]} Spieler )<br>Laufzeit: " . $this->intervall ( $max_curr ) . " ( " . $this->intervall ( $max_time, true ) . " )";
577            $this->check_template ( "ministats_{$realmId}{$vanilla_string}", $max, 120, false, true, false );
578            return $max;
579        }
580        else
581            return $this->check_template ( "ministats_{$realmId}{$vanilla_string}", "", 180, false, false, true );
582    }
583
584    public function online_stats ()
585    {
586        $ajax = isset ( $_GET ['ajax'] ) ? true : false;
587        $ps = isset ( $_GET ['ps'] ) ? $_GET ['ps'] : false;
588        $realm = isset ( $_GET ['realm'] ) ? $this->quote_smart ( $_GET ['realm'], $this->forum_db ) : 'PvE';
589        $players = $this->players_online ( );
590       
591        $realms = array ( 'PvE' => 1 );
592       
593        $record ['PvE'] = explode ( '<br>', $this->max_players ( $realms ['PvE'] ) );
594        $record ['VANILLA'] = explode ( '<br>', $this->max_players ( 1, true ) );
595        if ( ! is_array ( $players ) ) $players = unserialize ( $players );
596       
597        if ( $players ['PvE'] < 1000 ) $players ['PvE_STAT'] = '&nbsp;' . $players ['PvE'];
598        if ( $players ['PvE'] < 100 ) $players ['PvE_STAT'] = '&nbsp;&nbsp;&nbsp;&nbsp;' . $players ['PvE'];
599        if ( $players ['PvE'] < 10 ) $players ['PvE_STAT'] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $players ['PvE'];
600       
601        if ( $players ['VANILLA'] < 1000 ) $players ['VANILLA_STAT'] = '&nbsp;' . $players ['VANILLA'];
602        if ( $players ['VANILLA'] < 100 ) $players ['VANILLA_STAT'] = '&nbsp;&nbsp;&nbsp;&nbsp;' . $players ['VANILLA'];
603        if ( $players ['VANILLA'] < 10 ) $players ['VANILLA_STAT'] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $players ['VANILLA'];
604       
605        if ( $players ['PvE'] > 0 ) $player_stats ['PvE'] = "<font color=\"green\"><span class=\"serverstatus_ok\"><b>{$players['PvE_STAT']} Spieler Online</b></span></font> ";
606        if ( $players ['VANILLA'] > 0 ) $player_stats ['VANILLA'] = "<font color=\"green\"><span class=\"serverstatus_ok\"><b>{$players['VANILLA_STAT']} Spieler Online</b></span></font> ";
607        if ( $this->cpu_load_to_high ( ) ) $player_stats ['PvE'] = $player_stats ['VANILLA'] = "<font color=\"red\"><span class=\"serverstatus_error\"><b>Hohe Serverbelastung - Abgebrochen</b></span></font> ";
608        if ( ! $this->cpu_load_to_high ( ) && ( $players ['PvE'] == 0 ) ) $player_stats ['PvE'] = "<font color=\"red\"><span class=\"serverstatus_error\"><b>Server Offline</b></span></font> ";
609        if ( ! $this->cpu_load_to_high ( ) && ( $players ['VANILLA'] == 0 ) ) $player_stats ['VANILLA'] = "<font color=\"red\"><span class=\"serverstatus_error\"><b>Server Offline</b></span></font> ";
610        $player_stats ['PvE'] .= "<span class=\"serverstatus_font\">{$record['PvE'][0]}</span>";
611        $server_stats ['PvE'] = "<span class=\"serverstatus_font\">{$record['PvE'][1]} || set realmlist landoflegends.de</span>";
612        $player_stats ['VANILLA'] .= "<span class=\"serverstatus_font\">{$record['VANILLA'][0]}</span>";
613        $server_stats ['VANILLA'] = "<span class=\"serverstatus_font\">{$record['VANILLA'][1]} || set realmlist landoflegends.de:3800</span>";
614        $code = "
615        <script type=\"text/javascript\">
616        setInterval(\"get_content('vc_1', 'http://www.landoflegends.de/portal.php?mod=stats_data&ajax=true&ps=player&realm=PvE','get')\",120000);
617        setInterval(\"get_content('vc_2', 'http://www.landoflegends.de/portal.php?mod=stats_data&ajax=true&ps=server&realm=PvE','get')\",500000);
618        setInterval(\"get_content('vc_3', 'http://www.landoflegends.de/portal.php?mod=stats_data&ajax=true&ps=player&realm=VANILLA','get')\",120000);
619        setInterval(\"get_content('vc_4', 'http://www.landoflegends.de/portal.php?mod=stats_data&ajax=true&ps=server&realm=VANILLA','get')\",500000);
620        </script>";
621        if ( $ajax ) {
622            if ( $ps && $ps == 'player' ) $this->do_exit ( $player_stats [$realm] );
623            if ( $ps && $ps == 'server' ) $this->do_exit ( $server_stats [$realm] );
624        }
625        else
626            return "{$code}<table class=\"#serverstatus serverstatus_font\" cellpadding=\"0\" cellspacing=\"0\" height=\"60\"><tr><td>Wotlk-PvE: </td><td><dd id=\"vc_1\">{$player_stats['PvE']}</dd></td><td><dd id=\"vc_2\">{$server_stats['PvE']}</dd></td></tr>
627            <tr><td>Classic-PvP: </td><td><dd id=\"vc_3\">{$player_stats['VANILLA']}</dd></td><td><dd id=\"vc_4\">{$server_stats['VANILLA']}</dd></td></tr></table>";
628    }
629
630    /**
631     * @param $honor
632     * @param $faction
633     * @return honor_rank
634     */
635    protected function pvp_ranks ( $honor = 0, $faction = 0 )
636    {
637        $rank = '0' . $faction;
638        if ( $honor > 0 ) {
639            if ( $honor < 2000 ) $rank = 1;
640            else $rank = ceil ( $honor / 5000 ) + 1;
641        }
642        if ( $rank > 14 ) $rank = 14;
643        return $rank;
644    }
645
646    /**
647     * @param $cha
648     * @param $data
649     * @return datafield
650     */
651    protected function get_char_data ( $cha, $data )
652    {
653        if ( ! $this->root_db ) return "Datenbank Verbindungsfehler!";
654        if ( empty ( $cha ) || empty ( $data ) ) return false;
655        switch ( $data )
656        {
657            case "level":
658                $sql = "SELECT `level` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`characters` WHERE `name` = '{$cha}'";
659                break;
660            case "money":
661                $sql = "SELECT `money` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`characters` WHERE `name` = '{$cha}'";
662                break;
663            default:
664                return false;
665        }
666        $query = $this->query ( $sql, $this->forum_db );
667        if ( ! $query ) return false;
668        return $this->result ( $query );
669    }
670
671    /**
672     * @param $a
673     * @param $b
674     * @return days_in_month
675     */
676    protected function count_days ( $a, $b )
677    {
678        $gd_a = getdate ( $a );
679        $gd_b = getdate ( $b );
680        $a_new = mktime ( 12, 0, 0, $gd_a ['mon'], $gd_a ['mday'], $gd_a ['year'] );
681        $b_new = mktime ( 12, 0, 0, $gd_b ['mon'], $gd_b ['mday'], $gd_b ['year'] );
682        return round ( abs ( $a_new - $b_new ) / 86400 );
683    }
684
685    //##########################################################################################
686    // Generate paging navigation.
687    // Original from PHPBB with some modifications to make them more simple
688    /**
689     * @param $base_url
690     * @param $num_items
691     * @param $per_page
692     * @param $start_item
693     * @param $add_prevnext_text
694     * @param $thash
695     * @param $tcs
696     * @return page_navigation
697     */
698    protected function generate_paginationn ( $base_url, $num_items, $per_page, $start_item, $add_prevnext_text = true, $thash = '', $tcs = false, $ajax = false, $div_id = '' )
699    {
700        if ( ! $num_items ) return "";
701        $total_pages = ceil ( $num_items / $per_page );
702        if ( $total_pages == 1 ) {return "";}
703        $on_page = floor ( $start_item / $per_page ) + 1;
704        $page_string = "";
705        $anchor = "";
706        if ( ! empty ( $thash ) ) $add_this = "&amp;hash={$thash}";
707        else $add_this = '';
708        if ( $tcs ) $anchor = "#comments";
709        else $anchor = '';
710        if ( $total_pages > 10 ) {
711            $init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages;
712            for ( $i = 1; $i < $init_page_max + 1; $i ++ ) {
713                if ( $tcs ) $temp = "&amp;cs=" . ( ( $i - 1 ) * $per_page );
714                else $temp = '';
715               
716                $page_string .= ( $i == $on_page ) ? "<b>" . $i . "</b>" : ( ( $ajax && ! empty ( $div_id ) ) ? "<a href=\"javascript:;\" onclick=\"get_content('{$div_id}','{$base_url}&amp;start=" . ( ( $i - 1 ) * $per_page ) . "{$temp}{$add_this}{$anchor}','get');\">" . $i . "</a>" : "<a href=\"$base_url&amp;start=" . ( ( $i - 1 ) * $per_page ) . "{$temp}{$add_this}{$anchor}\">" . $i . "</a>" );
717                if ( $i < $init_page_max ) {
718                    $page_string .= ", ";
719                }
720            }
721            if ( $total_pages > 3 ) {
722                if ( $on_page > 1 && $on_page < $total_pages ) {
723                    $page_string .= ( $on_page > 5 ) ? " ... " : ", ";
724                    $init_page_min = ( $on_page > 4 ) ? $on_page : 5;
725                    $init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4;
726                    for ( $i = $init_page_min - 1; $i < $init_page_max + 2; $i ++ ) {
727                        if ( $tcs ) $temp = "&amp;cs=" . ( ( $i - 1 ) * $per_page );
728                        $page_string .= ( $i == $on_page ) ? "<b>" . $i . "</b>" : ( ( $ajax && ! empty ( $div_id ) ) ? "<a href=\"javascript:;\" onclick=\"get_content('{$div_id}','{$base_url}&amp;start=" . ( ( $i - 1 ) * $per_page ) . "{$temp}{$add_this}{$anchor}','get');\">" . $i . "</a>" : "<a href=\"$base_url&amp;start=" . ( ( $i - 1 ) * $per_page ) . "{$temp}{$add_this}{$anchor}\">" . $i . "</a>" );
729                        if ( $i < $init_page_max + 1 ) $page_string .= ", ";
730                    }
731                    $page_string .= ( $on_page < $total_pages - 4 ) ? " ... " : ", ";
732                }
733                else
734                    $page_string .= " ... ";
735                for ( $i = $total_pages - 2; $i < $total_pages + 1; $i ++ ) {
736                    if ( $tcs ) $temp = "&amp;cs=" . ( ( $i - 1 ) * $per_page );
737                    $page_string .= ( $i == $on_page ) ? "<b>" . $i . "</b>" : ( ( $ajax && ! empty ( $div_id ) ) ? "<a href=\"javascript:;\" onclick=\"get_content('{$div_id}','{$base_url}&amp;start=" . ( ( $i - 1 ) * $per_page ) . "{$temp}{$add_this}{$anchor}','get');\">" . $i . "</a>" : "<a href=\"$base_url&amp;start=" . ( ( $i - 1 ) * $per_page ) . "{$temp}{$add_this}{$anchor}\">" . $i . "</a>" );
738                    if ( $i < $total_pages ) {
739                        $page_string .= ", ";
740                    }
741                }
742            }
743        }
744        else {
745            for ( $i = 1; $i < $total_pages + 1; $i ++ ) {
746                if ( $tcs ) $temp = "&amp;cs=" . ( ( $i - 1 ) * $per_page );
747                $page_string .= ( $i == $on_page ) ? "<b>" . $i . "</b>" : ( ( $ajax && ! empty ( $div_id ) ) ? "<a href=\"javascript:;\" onclick=\"get_content('{$div_id}','{$base_url}&amp;start=" . ( ( $i - 1 ) * $per_page ) . "{$temp}{$add_this}{$anchor}','get');\">" . $i . "</a>" : "<a href=\"$base_url&amp;start=" . ( ( $i - 1 ) * $per_page ) . "{$temp}{$add_this}{$anchor}\">" . $i . "</a>" );
748                if ( $i < $total_pages ) $page_string .= ", ";
749            }
750        }
751        if ( $add_prevnext_text ) {
752            if ( $on_page > 1 ) {
753                if ( $tcs ) $temp = "&amp;cs=" . ( ( $on_page - 2 ) * $per_page );
754               
755                $page_string = ( $ajax && ! empty ( $div_id ) ) ? " <a href=\"javascript:;\" onclick=\"get_content('{$div_id}','{$base_url}&amp;start=" . ( ( $on_page - 2 ) * $per_page ) . "{$temp}{$add_this}{$anchor}','get');\">Zurück</a>&nbsp;&nbsp;" . $page_string : " <a href=\"$base_url&amp;start=" . ( ( $on_page - 2 ) * $per_page ) . "{$temp}{$add_this}{$anchor}\">Zurück</a>&nbsp;&nbsp;" . $page_string;
756            }
757            if ( $on_page < $total_pages ) {
758                if ( $tcs ) $temp = "&amp;cs=" . ( $on_page * $per_page );
759                $page_string .= ( $ajax && ! empty ( $div_id ) ) ? "&nbsp;&nbsp;<a href=\"javascript:;\" onclick=\"get_content('{$div_id}','{$base_url}&amp;start=" . ( $on_page * $per_page ) . "{$temp}{$add_this}{$anchor}','get');\">Weiter</a>" : "&nbsp;&nbsp;<a href=\"$base_url&amp;start=" . ( $on_page * $per_page ) . "{$temp}{$add_this}{$anchor}\">Weiter</a>";
760            }
761        }
762        $page_string = "Seite: " . $page_string;
763        return $page_string;
764    }
765
766    /**
767     * @param $username
768     * @param $pass
769     * @return sha_hash
770     */
771    public function sha_password ( $username, $pass )
772    {
773        $username = strtoupper ( $username );
774        $pass = strtoupper ( $pass );
775        $SHA1P = ( $username . ':' . $pass );
776        return hash ( 'sha1', $SHA1P );
777    }
778
779    /**
780     * @return cookie_string
781     */
782    public function auth_generate_cookie_string ()
783    {
784        $t_val = mt_rand ( 0, mt_getrandmax ( ) ) + mt_rand ( 0, mt_getrandmax ( ) );
785        $t_val = md5 ( $t_val ) . md5 ( time ( ) );
786        return substr ( $t_val, 0, 64 );
787    }
788
789    /**
790     * @param $x
791     * @param $y
792     * @param $zone
793     * @return Converted map to zone data
794     */
795    protected function getZoneData ( $x = 0, $y = 0, $h = 0, $zone = 0 )
796    {
797        if ( $x == 0 || $y == 0 || $zone == 0 ) return array ( 0, 0, 0, '', '' );
798        $get_exact_zone_name_sql = "SELECT `Name` FROM `zone_area_data` WHERE `Zone` = '{$zone}'";
799        $get_exact_zone_name = $this->result ( $this->query ( $get_exact_zone_name_sql, $this->forum_db ) );
800        $get_exact_zone_name = $get_exact_zone_name ? $get_exact_zone_name : '0000';
801        $get_exact_zone_name = str_replace ( "'", "\\'", $get_exact_zone_name );
802        $get_data_sql = "SELECT * FROM `zone_area_data` WHERE `Name` LIKE '%{$get_exact_zone_name}%'";
803        $get_data_query = $this->query ( $get_data_sql, $this->forum_db );
804        $get_data_rows = $this->num_rows ( $get_data_query );
805        if ( $get_data_rows == 0 ) return array ( 0, 0, 0, '', '' );
806        $z_id = $zone;
807        $z_name = '';
808        $y1 = 0;
809        $y2 = 0;
810        $x1 = 0;
811        $x2 = 0;
812        while ( $get_data = $this->fetch_row ( $get_data_query ) ) {
813            $z_id = $zone;
814            $z_name = $get_data [1];
815            $y1 = $get_data [2];
816            $y2 = $get_data [3];
817            $x1 = $get_data [4];
818            $x2 = $get_data [5];
819            switch ( $get_data [8] )
820            {
821                case 1:
822                    $special = " (Dungeon)";
823                    break;
824                case 2:
825                    $special = " (Schlachtzug)";
826                    break;
827                case 3:
828                    $special = " (Schlachtfeld)";
829                    break;
830                case 4:
831                    $special = " (Arena)";
832                    break;
833                default:
834                    $special = "";
835                    break;
836            }
837            if ( $get_data [6] !== 0 && $get_data [7] !== 0 && $h >= $get_data [6] && ( $get_data [7] == - 1 || $h <= $get_data [7] ) ) {
838                $z_id = $get_data [0];
839                break;
840            }
841            $check = false;
842            if ( ! file_exists ( $_SERVER ["DOCUMENT_ROOT"] . "/images/zones/{$z_id}.jpg" ) ) $check = true;
843            if ( $check ) {
844                for ( $i = 0; $i < 10; $i ++ )
845                    if ( file_exists ( $_SERVER ["DOCUMENT_ROOT"] . "/images/zones/{$z_id}.{$i}.jpg" ) ) {
846                        $z_id = $z_id . '.' . $i;
847                        break;
848                    }
849            }
850            if ( $zone == $get_data [0] && $get_data [6] == 0 && $get_data [7] == 0 ) break;
851        }
852        $width = 0;
853        $height = 0;
854        $_x = 0;
855        $_y = 0;
856        if ( file_exists ( $_SERVER ["DOCUMENT_ROOT"] . "/images/zones/{$z_id}.jpg" ) && $x1 != 0 && $x2 != 0 && $y1 != 0 && $y2 != 0 ) {
857            $size = @GetImageSize ( $_SERVER ["DOCUMENT_ROOT"] . "/images/zones/{$z_id}.jpg" );
858            $width = $size [0];
859            $height = $size [1];
860            if ( $width != 0 && $height != 0 ) {
861                $x = ( $x - $x1 ) / ( ( $x2 - $x1 ) / 100 );
862                $y = ( $y - $y1 ) / ( ( $y2 - $y1 ) / 100 );
863                $_x = ( $width * ( $y / 100 ) - 3 );
864                $_y = ( ( $height * ( $x / 100 ) ) + 15 );
865                $_x = ( $_x > $width ) ? 0 : $_x;
866                $_y = ( $_y > $height ) ? 0 : $_y;
867            }
868        }
869        return array ( $_x, $_y, $z_id, $z_name, $special );
870    }
871
872    /**
873     * @param $string
874     * @return parsed html code
875     */
876    protected function wow_html ( $string )
877    {
878        require 'wow_html.php';
879        return $wow_template [$string];
880    }
881
882    /**
883     * @param $string
884     * @return replaced url as link
885     */
886    protected function replace_url ( $string, $rep_txt = 'Thema Anzeigen', $preg_match = false )
887    {
888        //Alle Toplevel Domainendungen
889        $tld_endings = "com|net|org|biz|info|edu|eu|aero|coop|museum|al|as|vi|ai|ag|ar|am|";
890        $tld_endings .= "aw|ac|az|et|au|bh|by|be|bz|bj|ba|br|vg|io|bg|cl|cn|cc|dk|de|dj|ec|";
891        $tld_endings .= "ee|fo|fi|fr|tf|li|gm|gi|gr|gl|uk|gg|gy|hm|hk|in|id|ie|im|il|it|jp|";
892        $tld_endings .= "je|ca|kz|ke|ki|cg|hr|lv|lt|lu|mw|my|mt|mx|fm|md|mc|mn|ms|nz|ni|nl|";
893        $tld_endings .= "an|nu|nf|no|at|pk|pa|pe|ph|pn|pl|pt|pr|ro|ru|su|ch|yu|sc|sg|sk|si|";
894        $tld_endings .= "es|kn|sh|sf|za|gs|kr|sr|tw|tz|th|tk|to|tt|cz|tr|tm|tc|tv|ua|hu|uy|";
895        $tld_endings .= "us|uz|vu|ve|ae|vn|ws|cy";
896        //alle erlaubten Dateiendungen
897        $file_endings = "php|htm|html|xml|xhtml|jpg|jpeg|gif|png|pdf|asp|js|swf";
898        //alle Umlaute
899        $umlaute = "àáâãäåæçèéêëìíîïðñòóôöøùúûüýþÿ";
900        //Die Ausdrücke um www.... oder Strings mit einem @ usw in Links ersetzt
901        //Die zu erläutern vermag ich im Moment nicht, vielleicht folgt mal ein Tutorial dazu ;)
902        $patterns ["mail"] = "#(^|[^\"=\./a-z0-9]{1})([_a-z0-9-\." . $umlaute . "]+)" . "(\@)([a-z0-9_\-\." . $umlaute . "]+)(\.)(" . $tld_endings . ")(/)*([\s\r\t\n<>]|$)#msi";
903        $replaces ["mail"] = "\\1<a target=\"_blank\" href=\"mailto:\\2\\3\\4\\5\\6\\7\">" . "\\2\\3\\4\\5\\6\\7</a>\\8";
904        $patterns ["url"] = "#(^|[^\"=\./a-z0-9]{1})(http://|ftp://|news://|https://|ftps://)" . "([a-z0-9_\-\." . $umlaute . "]+)(\.)(" . $tld_endings . ")" . "(/([a-z0-9_\-/" . $umlaute . "]+)*)*([a-z0-9\._-]+\.(" . $file_endings . ")([^\s\n\r\t\(\)\[\]\{\}<>]+)*)*([\s\r\t\n<>]|$)#msi";
905        $replaces ["url"] = "\\1<a target=\"_blank\" href=\"\\2\\3\\4\\5\\6\\8\">{$rep_txt}</a>\\11";
906        $patterns ["ftp"] = "#(^|[^\"=\./a-z0-9]{1})(ftp\.)([a-z0-9_\-\." . $umlaute . "]+)(\.)(" . $tld_endings . ")(/([a-z0-9_\-/" . $umlaute . "]+)*)*([a-z0-9\._-]+\.(" . $file_endings . ")([^\s\n\r\t\(\)\[\]\{\}<>]+)*)*([\s\r\t\n<>]|$)#msi";
907        $replaces ["ftp"] = "\\1<a target=\"_blank\" href=\"ftp://\\2\\3\\4\\5\\6\\8\">" . "\\2\\3\\4\\5\\6\\8</a>\\11";
908        $patterns ["www"] = "#(^|[^\"=\./a-z0-9]{1})(www\.)([a-z0-9_\-\." . $umlaute . "]+)(\.)(" . $tld_endings . ")(/([a-z0-9_\-/" . $umlaute . "]+)*)*([a-z0-9\._-]+\.(" . $file_endings . ")([^\s\n\r\t\(\)\[\]\{\}<>]+)*)*([\s\r\t\n<>]|$)#msi";
909        $replaces ["www"] = "\\1<a target=\"_blank\" href=\"http://\\2\\3\\4\\5\\6\\8\">{$rep_txt}</a>\\11";
910        //Den String ersetzen oder finden...
911        if ( ! $preg_match ) $string = preg_replace ( $patterns, $replaces, $string );
912        else {
913            foreach ( $patterns as $pattern )
914                if ( preg_match ( $pattern, $string ) ) return true;
915           
916            return false;
917        }
918        //...und zurückgeben.
919        return $string;
920    }
921
922    /**
923     * @param $month
924     * @param $year
925     * @return days in month
926     */
927    protected function days_in_month ( $month, $year )
928    {
929        if ( checkdate ( $month, 31, $year ) ) return 31;
930        if ( checkdate ( $month, 30, $year ) ) return 30;
931        if ( checkdate ( $month, 29, $year ) ) return 29;
932        if ( checkdate ( $month, 28, $year ) ) return 28;
933        return 0; // error
934    }
935
936    /**
937     * @param $conf_name
938     * @param $code
939     * @param $intervall
940     * @param $register
941     * @param $update
942     * @param $get
943     * @return true or false
944     */
945    protected function check_template ( $conf_name = '', $code = '', $intervall, $register = false, $update = false, $get = false, $timeout = false )
946    {
947        if ( ! $this->forum_db ) return "Datenbank Verbindungsfehler!";
948        if ( empty ( $conf_name ) ) return false;
949        $path = $_SERVER ["DOCUMENT_ROOT"] . "/cache/" . $conf_name . ".wow";
950        $ttime = time ( );
951        if ( ! $get || ! $register || ! $update ) {
952            $get_temp = $this->query ( "SELECT * FROM `wow_template_time` WHERE `conf_name` = '{$conf_name}'", $this->forum_db );
953            $data = $this->fetch_row ( $get_temp );
954        }
955        if ( $register ) {
956            if ( ! file_exists ( $path ) ) {
957                if ( ! $this->check_file ( $conf_name ) ) {
958                    $file = fopen ( $path, "w+" );
959                    fwrite ( $file, "00" );
960                    fclose ( $file );
961                }
962                else {
963                    $file = fopen ( $path, "w+" );
964                    fwrite ( $file, "00" );
965                    fclose ( $file );
966                    return $this->check_template ( $conf_name, '', $intervall, true );
967                }
968            }
969            $query = $this->query ( "INSERT INTO `wow_template_time` VALUES ('{$conf_name}','{$ttime}')", $this->forum_db );
970            if ( ! $query ) return false;
971            return false;
972        }
973        if ( $update ) {
974            if ( ! empty ( $code ) && ! empty ( $intervall ) && file_exists ( $path ) ) {
975                if ( $this->check_file ( $conf_name ) ) {
976                    $file = fopen ( $path, "w+" );
977                    fwrite ( $file, $code );
978                    fclose ( $file );
979                }
980                else
981                    return $this->check_template ( $conf_name, $code, $intervall, false, true );
982            }
983            $new_time = ( $timeout ) ? time ( ) : strtotime ( "+{$intervall} seconds" );
984            $new_time_query = $this->query ( "UPDATE `wow_template_time` SET `time_next` = '{$new_time}' WHERE `conf_name` = '{$conf_name}'", $this->forum_db );
985            return true;
986        }
987        if ( $get ) {
988            if ( file_exists ( $path ) ) {
989                if ( $this->check_file ( $conf_name ) ) {
990                    $file = fopen ( $path, "r+" );
991                    $content = fread ( $file, filesize ( $path ) );
992                    fclose ( $file );
993                }
994                else
995                    $this->check_template ( $conf_name, '', $intervall, false, false, true );
996                if ( $content == "00" ) return false;
997                return $content;
998            }
999            else {
1000                $file = fopen ( $path, "w+" );
1001                fwrite ( $file, "00" );
1002                fclose ( $file );
1003                return $this->check_template ( $conf_name, '', $intervall, false, false, true );
1004            }
1005        }
1006        if ( $data ) {
1007            if ( time ( ) >= $data [1] ) {
1008                $new_time = strtotime ( "+{$intervall} seconds" );
1009                $data_query = $this->query ( "UPDATE `wow_template_time` SET `time_next` = '{$new_time}' WHERE `conf_name` = '{$conf_name}'", $this->forum_db );
1010                return false;
1011            }
1012            else
1013                return $this->check_template ( $conf_name, '', $intervall, false, false, true );
1014        }
1015        else {
1016            return $this->check_template ( $conf_name, '', $intervall, true );
1017        }
1018    }
1019
1020    /**
1021     * @param $sek
1022     * @return generated intervall
1023     */
1024    protected function intervall ( $sek, $short = false )
1025    {
1026        if (!$short)
1027        $i = sprintf ( '%d Tag%s %d Std.' . ' %d Min.', $sek / 86400, floor ( $sek / 86400 ) != 1 ? 'e' : '', $sek / 3600 % 24, $sek / 60 % 60 );
1028        else $i = sprintf ( '%d Tag%s', $sek / 86400, floor ( $sek / 86400 ) != 1 ? 'e' : '' );
1029       
1030        return $i;
1031    }
1032
1033    /**
1034     * @param $conf_name
1035     * @return true or false
1036     */
1037    private function check_file ( $conf_name )
1038    {
1039        $path = $_SERVER ["DOCUMENT_ROOT"] . "/cache/" . $conf_name . ".wow";
1040        if ( ! is_readable ( $path ) || ! is_writable ( $path ) ) {
1041            $uid = @fileowner ( $path );
1042            $uinfo = @posix_getpwuid ( $uid );
1043            if ( $uinfo ['name'] == "nobody" ) {
1044                unlink ( $path );
1045                return false;
1046            }
1047            return false;
1048        }
1049        return true;
1050    }
1051
1052    /**
1053     * @param $url
1054     * @param $sendData
1055     * @return true or false
1056     */
1057    public function php_post ( $url, $sendData )
1058    {
1059        $curl = curl_init ( );
1060        curl_setopt ( $curl, CURLOPT_URL, $url );
1061        curl_setopt ( $curl, CURLOPT_POST, true );
1062        curl_setopt ( $curl, CURLOPT_POSTFIELDS, $sendData );
1063        curl_exec ( $curl );
1064        curl_close ( $curl );
1065    }
1066
1067    /**
1068     * @param $password
1069     * @return generated password hash
1070     */
1071    public function gen_hash ( $password )
1072    {
1073        $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
1074        $random_state = unique_id ( );
1075        $random = '';
1076        $count = 6;
1077        if ( ( $fh = @fopen ( '/dev/urandom', 'rb' ) ) ) {
1078            $random = fread ( $fh, $count );
1079            fclose ( $fh );
1080        }
1081        if ( strlen ( $random ) < $count ) {
1082            $random = '';
1083            for ( $i = 0; $i < $count; $i += 16 ) {
1084                $random_state = md5 ( unique_id ( ) . $random_state );
1085                $random .= pack ( 'H*', md5 ( $random_state ) );
1086            }
1087            $random = substr ( $random, 0, $count );
1088        }
1089        $hash = _hash_crypt_private ( $password, _hash_gensalt_private ( $random, $itoa64 ), $itoa64 );
1090        if ( strlen ( $hash ) == 34 ) return $hash;
1091        return md5 ( $password );
1092    }
1093
1094    /**
1095     * @param $username
1096     * @param $password
1097     * @param $email
1098     * @return id of new registered user in forum
1099     */
1100    protected function forum_user_register ( $username, $password, $email )
1101    {
1102        global $config, $user;
1103       
1104        require_once 'constants.php';
1105        include_once 'functions_user.php';
1106       
1107        $server_url = generate_board_url ( );
1108        $user_actkey = gen_rand_string ( 10 );
1109        $key_len = 54 - ( strlen ( $server_url ) );
1110        $key_len = ( $key_len < 6 ) ? 6 : $key_len;
1111        $user_actkey = substr ( $user_actkey, 0, $key_len );
1112        $user_type = USER_INACTIVE;
1113        $user_inactive_reason = INACTIVE_REGISTER;
1114        $user_inactive_time = time ( );
1115        $add_user_data = array ( 'username' => $username, 'user_password' => $this->gen_hash ( $password ), 'user_email' => $email, 'group_id' => (int) 2, 'user_timezone' => (float) $config ['board_timezone'], 'user_dst' => $config ['board_dst'], 'user_lang' => $user->lang_name, 'user_type' => $user_type, 'user_actkey' => $user_actkey, 'user_ip' => $user->ip, 'user_regdate' => time ( ), 'user_inactive_reason' => $user_inactive_reason, 'user_inactive_time' => $user_inactive_time );
1116        $result = user_add ( $add_user_data );
1117        if ( $result ) {
1118            include_once 'functions_messenger.php';
1119            $messenger = new messenger ( false );
1120            $messenger->template ( 'user_welcome_inactive', $add_user_data ['user_lang'] );
1121            $messenger->to ( $add_user_data ['user_email'], $add_user_data ['username'] );
1122            $messenger->headers ( 'X-AntiAbuse: Board servername - ' . $config ['server_name'] );
1123            $messenger->headers ( 'X-AntiAbuse: User_id - ' . $result );
1124            $messenger->headers ( 'X-AntiAbuse: Username - ' . $add_user_data ['username'] );
1125            $messenger->headers ( 'X-AntiAbuse: User IP - ' . $user->ip );
1126            $messenger->assign_vars ( array ( 'WELCOME_MSG' => htmlspecialchars_decode ( sprintf ( $user->lang ['WELCOME_SUBJECT'], $config ['sitename'] ) ), 'USERNAME' => htmlspecialchars_decode ( $add_user_data ['username'] ), 'PASSWORD' => htmlspecialchars_decode ( $password ), 'U_ACTIVATE' => "$server_url/ucp.php?mode=activate&u=$result&k=$user_actkey" ) );
1127            $messenger->send ( NOTIFY_EMAIL );
1128            return $result;
1129        }
1130        return false;
1131    }
1132
1133    /**
1134     * @return nothing
1135     */
1136    public function close_all ( $forum = false, $exit = false )
1137    {
1138        global $phpbb_hook, $config;
1139        $this->close ( $this->root_db );
1140        $this->close ( $this->forum_db );
1141        if ( $forum ) {
1142            garbage_collection ( );
1143            if ( ! empty ( $phpbb_hook ) && $phpbb_hook->call_hook ( __FUNCTION__ ) ) {
1144                if ( $phpbb_hook->hook_return ( __FUNCTION__ ) ) {return $phpbb_hook->hook_return_result ( __FUNCTION__ );}
1145            }
1146            // As a pre-caution... some setups display a blank page if the flush() is not there.
1147            ( empty ( $config ['gzip_compress'] ) ) ? @flush ( ) : @ob_flush ( );
1148        }
1149        if ( $exit ) exit ( );
1150    }
1151
1152    /**
1153     * @param $user_id
1154     * @param $subject
1155     * @param $message
1156     * @return nothing
1157     */
1158    protected function phpbb_send_pm ( $user_id, $subject, $message, $from_override = 0 )
1159    {
1160        global $user;
1161       
1162        include_once 'functions_privmsgs.php';
1163        $text = utf8_normalize_nfc ( $message );
1164        $uid = $bitfield = $options = ''; // will be modified by generate_text_for_storage
1165        $allow_bbcode = $allow_smilies = true;
1166        $allow_urls = false;
1167        generate_text_for_storage ( $text, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies );
1168        $text = generate_text_for_display ( $text, $uid, $bitfield, $options );
1169        $override = ( $from_override > 0 ) ? $from_override : 48331;
1170        $user->add_lang ( 'ucp' );
1171        $pm_data = array ( 'address_list' => array ( 'u' => array ( $user_id => 'to' ) ), 'from_user_id' => $override, 'from_user_ip' => '127.0.0.1', 'from_username' => 'Systemnachricht', 'enable_sig' => false, 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => false, 'icon_id' => 0, 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, 'message' => $text );
1172        submit_pm ( 'post', $subject, $pm_data, false, 120 );
1173    }
1174
1175    /**
1176     * @param $del_acc
1177     * @param $game
1178     * @return true or false
1179     */
1180   
1181        protected function game_account_delete ( $del_acc, $game = 'wotlk' )
1182    {
1183        if ( ! $this->root_db ) return false;
1184               
1185                switch ( $game )
1186                {
1187                        case 'wotlk':
1188                                $deletes = array (
1189                                        array ( 'arena_team_member', 'guid' ),
1190                                        array ( 'character_account_data', 'guid' ),
1191                                        array ( 'character_achievement', 'guid' ),
1192                                        array ( 'character_achievement_progress', 'guid' ),
1193                                        array ( 'character_battleground_data', 'guid' ),
1194                                        array ( 'character_bgcoord', 'guid' ),
1195                                        array ( 'character_equipmentsets', 'guid' ),
1196                                        array ( 'character_talent', 'guid' ),
1197                                        array ( 'character_glyphs', 'guid' ),
1198                                        array ( 'auctionhouse', 'itemowner' ),
1199                                        array ( 'character_action', 'guid' ),
1200                                        array ( 'character_aura', 'guid' ),
1201                                        array ( 'character_gifts', 'guid' ),
1202                                        array ( 'character_homebind', 'guid' ),
1203                                        array ( 'character_instance', 'guid' ),
1204                                        array ( 'character_inventory', 'guid' ),
1205                                        array ( 'character_pet', 'owner' ),
1206                                        array ( 'character_queststatus', 'guid' ),
1207                                        array ( 'character_queststatus_daily', 'guid' ),
1208                                        array ( 'character_reputation', 'guid' ),
1209                                        array ( 'character_social', 'guid' ),
1210                                        array ( 'character_social', 'friend' ),
1211                                        array ( 'character_spell', 'guid' ),
1212                                        array ( 'character_spell_cooldown', 'guid' ),
1213                                        array ( 'corpse', 'player' ),
1214                                        array ( 'groups', 'leaderGuid' ),
1215                                        array ( 'gm_tickets', 'guid' ),
1216                                        array ( 'group_member', 'memberGuid' ),
1217                                        array ( 'group_member', 'leaderGuid' ),
1218                                        array ( 'group_instance', 'leaderGuid' ),
1219                                        array ( 'guild_member', 'guid' ),
1220                                        array ( 'petition', 'ownerguid' ),
1221                                        array ( 'petition_sign', 'ownerguid' ),
1222                                        array ( 'petition_sign', 'playerguid' ),
1223                                        array ( 'mail', 'receiver' ),
1224                                        array ( 'mail', 'sender' ),
1225                                        array ( 'mail_items', 'receiver' ),
1226                                        array ( 'characters', 'guid' ),
1227                                        array ( 'guild_bank_eventlog', 'PlayerGuid' ),
1228                                        array ( 'character_action', 'guid' ),
1229                                        array ( 'character_arena_stats', 'guid' ),
1230                                        array ( 'character_banned', 'guid' ),
1231                                        array ( 'character_queststatus_weekly', 'guid' ),
1232                                        array ( 'character_skills', 'guid' ),
1233                                        array ( 'lag_reports', 'player' ),
1234                                        array ( 'character_queststatus_rewarded', 'guid' ),
1235                                        array ( 'character_queststatus_weekly', 'guid' )
1236                                );
1237                                break;
1238                        case 'vanilla':
1239                                $deletes = array (
1240                                        array ( 'auction', 'itemowner' ),
1241                                        array ( 'character_battleground_data', 'guid' ),
1242                                        array ( 'character_action', 'guid' ),
1243                                        array ( 'character_aura', 'guid' ),
1244                                        array ( 'character_gifts', 'guid' ),
1245                                        array ( 'character_homebind', 'guid' ),
1246                                        array ( 'character_instance', 'guid' ),
1247                                        array ( 'character_inventory', 'guid' ),
1248                                        array ( 'character_pet', 'owner' ),
1249                                        array ( 'character_queststatus', 'guid' ),
1250                                        array ( 'character_honor_cp', 'guid' ),
1251                                        array ( 'character_reputation', 'guid' ),
1252                                        array ( 'character_social', 'guid' ),
1253                                        array ( 'character_social', 'friend' ),
1254                                        array ( 'character_spell', 'guid' ),
1255                                        array ( 'character_spell_cooldown', 'guid' ),
1256                                        array ( 'character_stats', 'guid' ),
1257                                        array ( 'character_tutorial', 'account' ),
1258                                        array ( 'corpse', 'player' ),
1259                                        array ( 'groups', 'leaderGuid' ),
1260                                        array ( 'character_ticket', 'guid' ),
1261                                        array ( 'group_member', 'memberGuid' ),
1262                                        array ( 'group_instance', 'leaderGuid' ),
1263                                        array ( 'guild_member', 'guid' ),
1264                                        array ( 'petition', 'ownerguid' ),
1265                                        array ( 'petition_sign', 'ownerguid' ),
1266                                        array ( 'petition_sign', 'playerguid' ),
1267                                        array ( 'item_instance', 'owner_guid' ),
1268                                        array ( 'item_loot', 'owner_guid' ),
1269                                        array ( 'mail', 'receiver' ),
1270                                        array ( 'mail', 'sender' ),
1271                                        array ( 'mail_items', 'receiver' ),
1272                                        array ( 'pet_aura', 'guid' ),
1273                                        array ( 'pet_aura', 'caster_guid' ),
1274                                        array ( 'characters', 'guid' ),
1275                                        array ( 'guild_eventlog', 'PlayerGuid1' ),
1276                                        array ( 'character_skills', 'guid' )
1277                                );
1278                                break;
1279                        default: // Funktion wird abgebrochen wenn es diesen "Game"-Server nicht gibt
1280                                return false;
1281                }
1282               
1283                if ( empty ( $del_acc ) ) return false;
1284       
1285                $d_user_id = $this->get_account_id_name ( $del_acc, '', '', '', $game );
1286       
1287                if ( empty ( $d_user_id ) || $d_user_id <= 0 ) return false;
1288               
1289                if( $game == 'wotlk' )
1290                        $get_acc_data_sql = "SELECT `last_login`, (SELECT COUNT(`name`) FROM `{$this->lol_conf ['db_live_accounts']}`.`account_holiday` WHERE `name` = '{$del_acc}') AS holiday FROM `{$this->lol_conf ['db_live_accounts']}`.`account` WHERE `id` = '{$d_user_id}'";
1291        else if( $game == 'vanilla' )
1292                        $get_acc_data_sql = "SELECT `last_login`, (SELECT COUNT(`name`) FROM `{$this->lol_conf ['db_live_accounts']}`.`account_holiday` WHERE `name` = '{$del_acc}') AS holiday FROM `{$this->lol_conf ['db_live_vanilla_accounts']}`.`account` WHERE `id` = '{$d_user_id}'";
1293               
1294                $get_acc_data_query = $this->query ( $get_acc_data_sql, $this->root_db );
1295        $get_acc_data = $this->fetch_row ( $get_acc_data_query );
1296        $date = date ( "d.m.Y_H-m-s", time ( ) );
1297        $File = $_SERVER ['DOCUMENT_ROOT'] . "/char_delete_backups/{$game}-{$del_acc}-{$date}.sql";
1298        $backup_data = array ();
1299                $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_live_accounts'], 'account_holiday', $File, 'name', $del_acc );
1300                if( $game == 'wotlk' ) {
1301                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_pve_live_characters'], 'account_data', $File, 'account', $d_user_id );
1302                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_live_accounts'], 'account', $File, 'id', $d_user_id );
1303                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_live_accounts'], 'realmcharacters', $File, 'account', $d_user_id );
1304                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_live_accounts'], 'account_banned', $File, 'id', $d_user_id );
1305                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_live_accounts'], 'account_access', $File, 'id', $d_user_id );
1306                        $sql = "SELECT `guid` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`characters` WHERE `account` = '{$d_user_id}'";
1307        }
1308                if( $game == 'vanilla' ) {
1309                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_live_vanilla_accounts'], 'account', $File, 'id', $d_user_id );
1310                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_live_vanilla_accounts'], 'realmcharacters', $File, 'acctid', $d_user_id );
1311                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_live_vanilla_accounts'], 'account_banned', $File, 'id', $d_user_id );
1312                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_live_vanilla_accounts'], 'account_access', $File, 'id', $d_user_id );
1313                        $sql = "SELECT `guid` FROM `{$this->lol_conf ['db_vanilla_live_characters']}`.`characters` WHERE `account` = '{$d_user_id}'";
1314                }
1315               
1316        $query = $this->query ( $sql, $this->root_db );
1317        if ( ! $query ) return false;
1318        $characters = array ();
1319        while ( $data = $this->fetch_row ( $query ) )
1320            $characters [ ] = $data [0];
1321        foreach ( $characters as $character )
1322            foreach ( $deletes as $dele ) {
1323                switch ( $dele [0] )
1324                {
1325                    case 'mail':
1326                        if ( $dele [1] == 'sender' && $game == 'wotlk' ) {
1327                            $get_mail_id_sql = "SELECT `id` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`mail` WHERE `sender` = '{$character}'";
1328                            $get_mail_query = $this->query ( $get_mail_id_sql, $this->root_db );
1329                            while ( $got_mail = $this->fetch_row ( $get_mail_query ) )
1330                                $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_pve_live_characters'], 'mail_items', $File, 'mail_id', $got_mail [0] );
1331                        }
1332                                                if ( $dele [1] == 'sender' && $game == 'vanilla' ) {
1333                                                        $get_mail_id_sql = "SELECT `id` FROM `{$this->lol_conf ['db_vanilla_live_characters']}`.`mail` WHERE `sender` = '{$character}'";
1334                            $get_mail_query = $this->query ( $get_mail_id_sql, $this->root_db );
1335                            while ( $got_mail = $this->fetch_row ( $get_mail_query ) )
1336                                $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_vanilla_live_characters'], 'mail_items', $File, 'mail_id', $got_mail [0] );
1337                                                }
1338                        break;
1339                    case 'character_pet':
1340                                                if( $game == 'wotlk' ) {
1341                                                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_pve_live_characters'], 'pet_aura', $File, 'guid', $character );
1342                                                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_pve_live_characters'], 'pet_spell', $File, 'guid', $character );
1343                                                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_pve_live_characters'], 'pet_spell_cooldown', $File, 'guid', $character );
1344                        }
1345                                                if( $game == 'vanilla' ) {
1346                                                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_vanilla_live_characters'], 'pet_aura', $File, 'guid', $character );
1347                                                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_vanilla_live_characters'], 'pet_spell', $File, 'guid', $character );
1348                                                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_vanilla_live_characters'], 'pet_spell_cooldown', $File, 'guid', $character );
1349                                                }
1350                                                break;
1351                    case 'character_spell_cooldown':
1352                                                if( $game == 'wotlk' )
1353                                                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_pve_live_characters'], 'character_tutorial', $File, 'account', $d_user_id );
1354                        if( $game == 'vanilla' )
1355                                                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_vanilla_live_characters'], 'character_tutorial', $File, 'account', $d_user_id );
1356                                                break;
1357                    case 'guild_member':
1358                                                if( $game == 'wotlk' )
1359                                                        $char_dbname = $this->lol_conf ['db_pve_live_characters'];
1360                                                if( $game == 'vanilla' )
1361                                                        $char_dbname = $this->lol_conf ['db_vanilla_live_characters'];
1362                                               
1363                        $get_leader_sql = "SELECT `leaderguid`, (SELECT `guildid` FROM `{$char_dbname}`.`guild_member` WHERE `guid` = '{$character}') AS gid FROM `{$char_dbname}`.`guild` WHERE guildid = (SELECT `guildid` FROM `{$char_dbname}`.`guild_member` WHERE `guid` = '{$character}')";
1364                        $get_leader = $this->fetch_row ( $this->query ( $get_leader_sql, $this->root_db ) );
1365                        if ( $get_leader && $get_leader [0] == $character ) {
1366                            $get_new_leader_guid_sql = "SELECT `guid`,`rank` FROM `{$char_dbname}`.`guild_member` WHERE `guildid` = '{$get_leader[1]}' ORDER BY `rank` LIMIT 1";
1367                            $get_new_leader_guid = $this->fetch_row ( $this->query ( $get_new_leader_guid_sql, $this->root_db ) );
1368                            if ( is_array ( $get_new_leader_guid ) ) {
1369                                $temp_data = '\n';
1370                                $temp_data .= "UPDATE `{$char_dbname}`.`guild` SET `leaderguid` = '{$get_leader[0]}' WHERE `guildid` = '{$get_leader[1]}';\n";
1371                                $temp_data .= "UPDATE `{$char_dbname}`.`guild_member` SET `rank` = '{$get_new_leader_guid[1]}' WHERE `guid` = '{$get_new_leader_guid[0]}';\n";
1372                                $temp_gf = fopen ( $File, 'w+' );
1373                                $temp_fwrite = fwrite ( $temp_gf, $temp_data );
1374                                $temp_close = fclose ( $temp_gf );
1375                                $set_new_sql = "UPDATE `{$char_dbname}`.`guild_member` SET `rank` = '1' WHERE `guid` = '{$get_new_leader_guid[0]}'";
1376                                $set_new_sql2 = "UPDATE `{$char_dbname}`.`guild` SET `leaderguid` = '{$get_new_leader_guid[0]}' WHERE `guildid` = '{$get_leader[1]}'";
1377                                $q = $this->query ( $set_new_sql, $this->root_db );
1378                                $q2 = $this->query ( $set_new_sql2, $this->root_db );
1379                            }
1380                        }
1381                        break;
1382                }
1383                                if( $game == 'wotlk' ) {
1384                                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_pve_live_characters'], $dele [0], $File, $dele [1], $character );
1385                                        $q3 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_pve_live_characters']}`.`{$dele[0]}` WHERE `{$dele[1]}` = '{$character}'", $this->root_db );
1386                                }
1387                                else if ( $game == 'vanilla' ) {
1388                                        $backup_data [ ] = $this->_mysqldump_table_data ( $this->lol_conf ['db_vanilla_live_characters'], $dele [0], $File, $dele [1], $character );
1389                                        $q3 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_vanilla_live_characters']}`.`{$dele[0]}` WHERE `{$dele[1]}` = '{$character}'", $this->root_db );
1390                                }
1391                        }
1392                if( $game == 'wotlk' ) {
1393                        $q4 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_pve_live_characters']}`.`account_data` WHERE `account` = '{$d_user_id}'", $this->root_db );
1394                        $q5 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_tutorial` WHERE `account` = '{$d_user_id}'", $this->root_db );
1395                        $q6 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_pve_live_characters']}`.`mail_items` WHERE `mail_id` NOT IN (SELECT `id` FROM `mail`)", $this->root_db );
1396                        $q7 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_pve_live_characters']}`.`pet_aura` WHERE `guid` NOT IN (SELECT `id` FROM `character_pet`)", $this->root_db );
1397                        $q8 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_pve_live_characters']}`.`pet_spell` WHERE `guid` NOT IN (SELECT `id` FROM `character_pet`)", $this->root_db );
1398                        $q9 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_pve_live_characters']}`.`pet_spell_cooldown` WHERE `guid` NOT IN (SELECT `id` FROM `character_pet`)", $this->root_db );
1399                        $q10 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_live_accounts']}`.`account_banned` WHERE `id` = '{$d_user_id}'", $this->root_db );
1400                        $q11 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_live_accounts']}`.`account_holiday` WHERE `name` = '{$del_acc}'", $this->root_db );
1401                        $q12 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_live_accounts']}`.`realmcharacters` WHERE `account` = '{$d_user_id}'", $this->root_db );
1402                        $q13 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_live_accounts']}`.`account` WHERE `id` = '{$d_user_id}'", $this->root_db );
1403                        $q14 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_live_accounts']}`.`account_access` WHERE `id` = '{$d_user_id}'", $this->root_db );
1404                        return true;
1405                }
1406                if( $game == 'vanilla' ) {
1407                        $q5 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_vanilla_live_characters']}`.`character_tutorial` WHERE `account` = '{$d_user_id}'", $this->root_db );
1408                        $q6 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_vanilla_live_characters']}`.`mail_items` WHERE `mail_id` NOT IN (SELECT `id` FROM `mail`)", $this->root_db );
1409                        $q7 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_vanilla_live_characters']}`.`pet_aura` WHERE `guid` NOT IN (SELECT `id` FROM `character_pet`)", $this->root_db );
1410                        $q8 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_vanilla_live_characters']}`.`pet_spell` WHERE `guid` NOT IN (SELECT `id` FROM `character_pet`)", $this->root_db );
1411                        $q9 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_vanilla_live_characters']}`.`pet_spell_cooldown` WHERE `guid` NOT IN (SELECT `id` FROM `character_pet`)", $this->root_db );
1412                        $q10 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_live_vanilla_accounts']}`.`account_banned` WHERE `id` = '{$d_user_id}'", $this->root_db );
1413                        $q11 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_live_accounts']}`.`account_holiday` WHERE `name` = '{$del_acc}'", $this->root_db );
1414                        $q12 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_live_vanilla_accounts']}`.`realmcharacters` WHERE `acctid` = '{$d_user_id}'", $this->root_db );
1415                        $q13 = $this->query ( "DELETE FROM `{$this->lol_conf ['db_live_vanilla_accounts']}`.`account` WHERE `id` = '{$d_user_id}'", $this->root_db );
1416                        return true;
1417                }
1418                return false;
1419    }
1420
1421    /**
1422     * @param $name
1423     * @return user forum account id
1424     */
1425    protected function get_forum_id ( $name )
1426    {
1427        if ( empty ( $name ) ) return 0;
1428        $name = strtolower ( $name );
1429        $get_name_code = "SELECT `user_id` FROM `phpbb_users` WHERE username_clean = '{$name}'";
1430        $get_name = $this->query ( $get_name_code, $this->forum_db );
1431        if ( ! $get_name ) return 0;
1432        return $this->result ( $get_name );
1433    }
1434
1435    /**
1436     * @param $name
1437     * @return user forum account data
1438     */
1439    protected function get_forum_acc_data ( $name )
1440    {
1441        if ( empty ( $name ) ) return 0;
1442        $name = strtolower ( $name );
1443        $get_data_sql = "SELECT * FROM `phpbb_users` WHERE username_clean = '{$name}'";
1444        $get_data = $this->query ( $get_data_sql, $this->forum_db );
1445        if ( ! $get_data ) return 0;
1446        return $this->fetch_assoc ( $get_data );
1447    }
1448
1449    /**
1450     * @param $name
1451     * @return user forum account id
1452     */
1453    protected function get_forum_name ( $id )
1454    {
1455        if ( empty ( $id ) ) return 0;
1456        $id = strtolower ( $id );
1457        $get_id_code = "SELECT `username_clean` FROM `phpbb_users` WHERE `user_id` = '{$id}'";
1458        $get_id = $this->query ( $get_id_code, $this->forum_db );
1459        if ( ! $get_id ) return 0;
1460        return $this->result ( $get_id );
1461    }
1462
1463    /**
1464     * @param $plain
1465     * @return encoded base64 url
1466     */
1467    public function base64url_encode ( $plain )
1468    {
1469        $base64 = base64_encode ( $plain );
1470        $base64url = strtr ( $base64, "+/", "-_" );
1471        return rtrim ( $base64url, "=" );
1472    }
1473
1474    /**
1475     * @param $base64url
1476     * @return decoded base64 url
1477     */
1478    public function base64url_decode ( $base64url )
1479    {
1480        $base64 = strtr ( $base64url, "-_", "+/" );
1481        $plain = base64_decode ( $base64 );
1482        return ( $plain );
1483    }
1484
1485    /**
1486     * @param $file
1487     * @return false or image type text string
1488     */
1489    public function image_type ( $file )
1490    {
1491        $type = strtolower ( substr ( $file, strrpos ( $file, "." ) ) );
1492        if ( ( $type == ".jpg" ) or ( $type == ".jpeg" ) ) return "jpeg";
1493        elseif ( $type == ".png" ) return "png";
1494        elseif ( $type == ".gif" ) return "gif";
1495        return FALSE;
1496    }
1497
1498    /**
1499     * @param $id
1500     * @param $url
1501     * @param $t_name
1502     * @param $units
1503     * @param $static
1504     * @param $blacklisted
1505     * @param $is_admin
1506     * @return unknown_type
1507     */
1508    public function rating_bar ( $id, $url, $t_name, $units = '', $static = '', $blacklisted = false, $is_admin = false )
1509    {
1510        if ( is_array ( $blacklisted ) && in_array ( strtolower ( $t_name ), $blacklisted ) && ! $is_admin ) return "<br><font color=\"red\">Du wurdest für die Gallery Gesperrt, du kannst keine Bilder Hochladen, Kommentare machen und Bewertungen abgeben!</font>";
1511        //set some variables
1512        if ( ! $units ) $units = 10;
1513        if ( ! $static ) $static = FALSE;
1514        // get votes, values, ips for the current rating bar
1515        $query = $this->query ( "SELECT total_votes, total_value, used_ips FROM `lol_gallery_ratings` WHERE id='{$id}'", $this->forum_db );
1516        // insert the id in the DB if it doesn't exist already
1517        // see: http://www.masugadesign.com/the-lab/scripts/unobtrusive-ajax-star-rating-bar/#comment-121
1518        if ( $this->num_rows ( $query ) == 0 ) {
1519            $sql = "INSERT INTO `lol_gallery_ratings` VALUES ('{$id}', '0', '0', '')";
1520            $result = $this->query ( $sql, $this->forum_db );
1521        }
1522        $numbers = $this->fetch_assoc ( $query );
1523        if ( $numbers ['total_votes'] < 1 ) $count = 0;
1524        else $count = $numbers ['total_votes']; //how many votes total
1525        $current_rating = $numbers ['total_value']; //total number of rating added together and stored
1526        $tense = ( $count == 1 ) ? "Bewertung" : "Bewertungen"; //plural form votes/vote
1527        // determine whether the user has voted, so we know how to draw the ul/li
1528        $sql = "SELECT `used_ips` FROM `lol_gallery_ratings` WHERE `used_ips` LIKE '%{$t_name}%' AND id='{$id}'";
1529        $voted = $this->num_rows ( $this->query ( $sql, $this->forum_db ) );
1530        $sql1 = "SELECT `poster` FROM `lol_gallery_main` WHERE `poster` = '{$t_name}' AND `id` = {$id}";
1531        $get_name = $this->fetch_row ( $this->query ( $sql1, $this->forum_db ) );
1532        if ( $t_name == $get_name [0] ) {
1533            $query = $this->query ( "SELECT `used_ips` FROM `lol_gallery_ratings` WHERE id='{$id}'", $this->forum_db );
1534            $numbers = $this->fetch_row ( $query );
1535            $checkIP = unserialize ( $numbers [0] );
1536            ( ( is_array ( $checkIP ) ) ? array_push ( $checkIP, $t_name ) : $checkIP = array ( $t_name ) );
1537            $insertip = serialize ( $checkIP );
1538            $update = "UPDATE `lol_gallery_ratings` SET used_ips='{$insertip}' WHERE id='{$id}'";
1539            $result = $this->query ( $update, $this->forum_db );
1540            $voted = true;
1541        }
1542        // now draw the rating bar
1543        $rating_width = @number_format ( $current_rating / $count, 2 ); // * $rating_unitwidth;
1544        $rating1 = @number_format ( $current_rating / $count, 1 );
1545        $rating2 = @number_format ( $current_rating / $count, 2 );
1546        if ( $static == 'static' ) {
1547            $static_rater = array ();
1548            $static_rater [ ] .= "\n" . '<div class="ratingblock">';
1549            $static_rater [ ] .= "<div id=\"unit_long{$id}\">";
1550            $t_width = 30; // * $unitspx;
1551            $static_rater [ ] .= "<ul id=\"unit_ul{$id}\" class=\"unit-rating\" style=\"width:{$t_width};\">";
1552            $static_rater [ ] .= "<li class=\"current-rating\" style=\"width:{$rating_width}px;\">Currently {$rating2}/{$units}</li>";
1553            $static_rater [ ] .= '</ul>';
1554            $static_rater [ ] .= "<p class=\"static\">Bewertung: <strong> {$rating1}</strong>/{$units} ({$count} {$tense} abgegeben) <em>Dies ist \"Statisch\".</em></p>";
1555            $static_rater [ ] .= '</div>';
1556            $static_rater [ ] .= '</div>' . "\n\n";
1557            return join ( "\n", $static_rater );
1558        }
1559        else {
1560            $rater = '';
1561            $rater .= '<div class="ratingblock">';
1562            $rater .= '<div id="unit_long' . $id . '">';
1563            $tt_width = 30 * $units;
1564            if ( ! $voted ) {
1565                $rater .= "<ul id=\"unit_ul{$id}\" class=\"unit-rating\" style=\"width:{$tt_width}px;\">";
1566                $rater .= "<li class=\"current-rating\" style=\"width:{$rating_width}px;\">Derzeit {$rating2}/{$units}</li>";
1567                // loop from 1 to the number of units
1568                // if the user hasn't yet voted, draw the voting stars
1569                for ( $ncount = 1; $ncount <= $units; $ncount ++ )
1570                    if ( ! $voted ) $rater .= "<li><a href=\"portal.php?mod=gallery&j={$ncount}&amp;q={$id}&amp;t={$t_name}&amp;c={$units}&hash={$url}\" title=\"{$ncount} von {$units}\" class=\"r{$ncount}-unit rater\" rel=\"nofollow\">{$ncount}</a></li>";
1571                $ncount = 0; // resets the count
1572                $rater .= '  </ul>';
1573            }
1574            elseif ( $voted ) {
1575                $rater .= "<ul class=\"unit-rating\" style=\"width:{$tt_width}px;\">";
1576                $rater .= "<li class=\"current-rating\" style=\"width:width:{$rating_width}px;\">Aktuelle Berwertung.</li>";
1577                $rater .= '<li class="r1-unit">1</li><li class="r2-unit">2</li><li class="r3-unit">3</li><li class="r4-unit">4</li><li class="r5-unit">5</li><li class="r6-unit">6</li><li class="r7-unit">7</li><li class="r8-unit">8</li><li class="r9-unit">9</li><li class="r10-unit">10</li></ul>';
1578            }
1579            $rater .= '  <p';
1580            if ( $voted ) $rater .= ' class="voted"';
1581            $rater .= '>Bewertung: <strong> ' . $rating1 . '</strong>/' . $units . ' (' . $count . ' ' . $tense . ' abgegeben)';
1582            $rater .= '  </p>';
1583            $rater .= '</div>';
1584            $rater .= '</div>';
1585            return $rater;
1586        }
1587    }
1588
1589    /**
1590     * @param $t_name
1591     * @return unknown_type
1592     */
1593    public function gallery_make_ajax_vote ( $t_name )
1594    {
1595        //getting the values
1596        $vote_sent = preg_replace ( "/[^0-9]/", "", $_REQUEST ['j'] );
1597        $id_sent = preg_replace ( "/[^0-9a-zA-Z]/", "", $_REQUEST ['q'] );
1598        $name = $_REQUEST ['t'];
1599        $units = preg_replace ( "/[^0-9]/", "", $_REQUEST ['c'] );
1600        // kill the script because normal users will never see this.
1601        if ( $vote_sent > $units ) $this->close_all ( true, true );
1602        //connecting to the database to get some information
1603        $query = $this->query ( "SELECT total_votes, total_value, used_ips FROM `lol_gallery_ratings` WHERE id='$id_sent' ", $this->forum_db );
1604        $numbers = $this->fetch_assoc ( $query );
1605        $checkIP = unserialize ( $numbers ['used_ips'] );
1606        $count = $numbers ['total_votes']; //how many votes total
1607        $current_rating = $numbers ['total_value']; //total number of rating added together and stored
1608        $sum = $vote_sent + $current_rating; // add together the current vote value and the total vote value
1609        $tense = ( $count == 1 ) ? "Bewertung" : "Bewertungen"; //plural form votes/vote
1610        // checking to see if the first vote has been tallied
1611        // or increment the current number of votes
1612        ( $sum == 0 ? $added = 0 : $added = $count + 1 );
1613        // if it is an array i.e. already has entries the push in another value
1614        ( ( is_array ( $checkIP ) ) ? array_push ( $checkIP, $name ) : $checkIP = array ( $name ) );
1615        $insertip = serialize ( $checkIP );
1616        //IP check when voting
1617        $voted = $this->num_rows ( $this->query ( "SELECT used_ips FROM `lol_gallery_ratings` WHERE used_ips LIKE '%" . $t_name . "%' AND id='" . $id_sent . "' ", $this->forum_db ) );
1618        if ( ! $voted ) { //if the user hasn't yet voted, then vote normally...
1619            if ( ( $vote_sent >= 1 && $vote_sent <= $units ) && ( $t_name == $name ) ) { // keep votes within range, make sure IP matches - no monkey business!
1620                $update = "UPDATE `lol_gallery_ratings` SET total_votes='" . $added . "', total_value='" . $sum . "', used_ips='" . $insertip . "' WHERE id='$id_sent'";
1621                $result = $this->query ( $update, $this->forum_db );
1622            }
1623        } //end for the "if(!$voted)"
1624        // these are new queries to get the new values!
1625        $newtotals = $this->query ( "SELECT total_votes, total_value, used_ips FROM `lol_gallery_ratings` WHERE id='$id_sent'", $this->forum_db );
1626        $numbers = $this->fetch_assoc ( $newtotals );
1627        $count = $numbers ['total_votes']; //how many votes total
1628        $current_rating = $numbers ['total_value']; //total number of rating added together and stored
1629        $tense = ( $count == 1 ) ? "Bewertung" : "Bewertungen"; //plural form votes/vote
1630        // $new_back is what gets 'drawn' on your page after a successful 'AJAX/Javascript' vote
1631        $new_back = array ();
1632        $new_back [ ] .= '<ul class="unit-rating" style="width:' . $units * 30 . 'px;">';
1633        $new_back [ ] .= '<li class="current-rating" style="width:' . @number_format ( $current_rating / $count, 2 ) * 30 . 'px;">Current rating.</li>';
1634        $new_back [ ] .= '<li class="r1-unit">1</li>';
1635        $new_back [ ] .= '<li class="r2-unit">2</li>';
1636        $new_back [ ] .= '<li class="r3-unit">3</li>';
1637        $new_back [ ] .= '<li class="r4-unit">4</li>';
1638        $new_back [ ] .= '<li class="r5-unit">5</li>';
1639        $new_back [ ] .= '<li class="r6-unit">6</li>';
1640        $new_back [ ] .= '<li class="r7-unit">7</li>';
1641        $new_back [ ] .= '<li class="r8-unit">8</li>';
1642        $new_back [ ] .= '<li class="r9-unit">9</li>';
1643        $new_back [ ] .= '<li class="r10-unit">10</li>';
1644        $new_back [ ] .= '</ul>';
1645        $new_back [ ] .= '<p class="voted">Bewertung: <strong>' . @number_format ( $sum / $added, 1 ) . '</strong>/' . $units . ' (' . $count . ' ' . $tense . ' abgegeben) ';
1646        $new_back [ ] .= '<span class="thanks">Danke fürs Bewerten!</span></p>';
1647        $allnewback = join ( "\n", $new_back );
1648        // ========================
1649        //name of the div id to be updated | the html that needs to be changed
1650        $output = "unit_long$id_sent|$allnewback";
1651        $this->do_exit ( $output );
1652    }
1653
1654    /**
1655     * @param $do
1656     * @param $do_it
1657     * @param $id
1658     * @param $name
1659     * @param $hash
1660     * @param $comment
1661     * @param $t_cs
1662     * @param $is_admin
1663     * @param $blacklisted
1664     * @return unknown_type
1665     */
1666    public function gallery_get_set_comments ( $do = 'get', $do_it = false, $id, $name, $hash, $comment = '', $t_cs = 0, $is_admin = false, $blacklisted = false )
1667    {
1668        global $cache;
1669
1670        if ( is_array ( $blacklisted ) && in_array ( strtolower ( $name ), $blacklisted ) && ! $is_admin ) return "<br><font color=\"red\">Du wurdest für die Gallery Gesperrt, du kannst keine Bilder Hochladen, Kommentare machen und Bewertungen abgeben!</font>";
1671        $code = "<table width=\"350\"><tr><td align=\"center\">";
1672        $holder = "";
1673        $smily_main_url = "http://www.smileygarden.de/smilie/";
1674        $smily_search = array ( ":-P", ":D", ":)", ":-*", ";)", "/sign" );
1675        $smily_replace = array ( "<img src=\"{$smily_main_url}Frech/smileymania.at_14568.gif\" />", "<img src=\"{$smily_main_url}Lachend/3.gif\" />", "<img src=\"{$smily_main_url}Lachend/17.gif\" />", "<img src=\"{$smily_main_url}Liebe/38.gif\" />", "<img src=\"{$smily_main_url}Zwinker/73.gif\" />", ">> <i>%s stimmt zu</i><br>" );
1676        if ( $do == 'delete' ) {
1677            $sql = "DELETE FROM `lol_gallery_comments` WHERE `id` = {$id}";
1678            $query_comment = $this->query ( $sql, $this->forum_db );
1679        }
1680        if ( $do == 'edit' ) {
1681            if ( $do_it ) {
1682                $comment = strip_tags ( $comment );
1683                $bad_check = $this->BadWordFilter ( $comment );
1684                if ( $bad_check == 1 ) return "ERROR_WORD";
1685                $new_comm = str_ireplace ( $smily_search, '', $comment, $smily_count );
1686                if ( $smily_count > 3 ) return "ERROR_SMILY";
1687                $sql = "UPDATE `lol_gallery_comments` SET `comment` = '{$comment}' WHERE `name` = '{$name}' AND `id` = {$id}";
1688                $result = $this->query ( $sql, $this->forum_db );
1689            }
1690            $sql = "SELECT `comment` FROM `lol_gallery_comments` WHERE `name` = '{$name}' AND `id` = {$id}";
1691            $query_comment = $this->query ( $sql, $this->forum_db );
1692            if ( ! $query_comment ) return false;
1693            $old_comment = $this->fetch_row ( $query_comment );
1694            if ( ! $old_comment ) return false;
1695            $code = "<table><tr><td><form action=\"portal.php?mod=gallery&m=e&i={$id}&c=yes&hash={$hash}\" method=\"POST\">Noch <span id=\"gallery_comment\">255</span> Zeichen<br><textarea name=\"comment\" cols=\"25\" rows=\"2\"  onkeyup=\"CheckFieldLength(this, 'gallery_comment', 255);\" onkeydown=\"CheckFieldLength(this,'gallery_comment', 255);\" onmouseout=\"CheckFieldLength(this,'gallery_comment', 255);\">{$old_comment[0]}</textarea><br><br><input type=\"submit\" name=\"submit\" value=\"Ändern\" /></form></td></tr></table>";
1696            return $code;
1697        }
1698        if ( $do == 'get' ) {
1699            $sql = "SELECT * FROM `lol_gallery_comments` WHERE `from` = {$id} ORDER BY `id` DESC LIMIT {$t_cs}, 5";
1700            $query_comments = $this->query ( $sql, $this->forum_db );
1701            $count = 1;
1702            $all_comments = $this->num_rows ( $this->query ( "SELECT * FROM `lol_gallery_comments` WHERE `from` = {$id}", $this->forum_db ) );
1703            if ( ! $query_comments ) return false;
1704            while ( $comm = $this->fetch_row ( $query_comments ) ) {
1705                $edit_del = "";
1706                switch ( $count )
1707                {
1708                    case 1:
1709                        $table_color = "9f9f9f";
1710                        break;
1711                    case 2:
1712                        $table_color = "c6c6c6";
1713                        $count = 0;
1714                        break;
1715                    default:
1716                        $table_color = "c6c6c6";
1717                        break;
1718                }
1719                $reported = isset ( $_GET ['report'] ) ? $_GET ['report'] : false;
1720                $reported_show = isset ( $_GET ['report_show'] ) ? $_GET ['report_show'] : false;
1721                if ( ! $reported_show && $reported && $comm [0] == $reported ) $this->gallery_report_comment ( $reported, $t_cs, $hash );
1722                if ( $name == $comm [2] ) $edit_del = "[ <a href=\"portal.php?mod=gallery&m=e&i={$comm[0]}&hash={$hash}\">Bearbeiten</a> ] [ <a href=\"portal.php?mod=gallery&m=d&i={$comm[0]}&hash={$hash}\">Löschen</a> ]";
1723                if ( $is_admin && $name !== $comm [2] ) $edit_del = "[ <a href=\"portal.php?mod=gallery&m=d&i={$comm[0]}&hash={$hash}\">Löschen</a> ]";
1724                $new_comm = str_ireplace ( $smily_search, $smily_replace, $comm [3], $smily_count );
1725                if ( strstr ( $new_comm, '%s stimmt zu' ) ) $new_comm = sprintf ( $new_comm, $comm [2] );
1726                $show_reported = '';
1727                if ( ( $reported && $comm [0] == $reported ) || ( $reported_show && $comm [0] == $reported_show ) ) $show_reported = "<font color=\"red\">Gemeldet</font>";
1728                $holder .= "<table width=\"350\" style=\"background-image:url(http://www.landoflegends.de/images/gallery/{$table_color}.png); -moz-border-radius:10px; -khtml-border-radius:30px;\"><tr><td><div id=\"{$comm[0]}\">{$show_reported}</div></td></tr><tr><td width=\"50\"><b>Von:</b></td><td align=\"left\"><b>{$comm[2]}</b></td></tr><tr><td colspan=\"2\" width=\"200\">{$new_comm}</td></tr><tr><td align=\"center\" colspan=\"2\">{$edit_del} [ <a href=\"portal.php?mod=gallery&report={$comm[0]}&cs={$t_cs}&hash={$hash}#{$comm[0]}\" onmouseover=\"Tip('Bitte nur Kommentare Melden,<br>die nach dem Gallery- / Forumregelwerk unerlaubt sind!<br>Sinnlose Meldungen werden mit Verwarnungen und Ausschluss geahndet!</div>')\" onmouseout=\"UnTip()\">Melden</a> ]</td></tr></table><br>";
1729                $count ++;
1730            }
1731            $holder = ( empty ( $holder ) ) ? "Keine Kommentare Vorhanden!" : $holder;
1732            $c_page = $this->generate_paginationn ( "portal.php?mod=gallery", $all_comments, 5, $t_cs, true, $hash, true );
1733            $code .= "{$holder}</td></tr><tr><td>&nbsp;</td></tr><tr><td align=\"center\" colspan=\"2\"><form action=\"portal.php?mod=gallery&m=n&hash={$hash}\" method=\"POST\">Noch <span id=\"gallery_comment\">255</span> Zeichen<br><textarea name=\"comment\" cols=\"25\" rows=\"2\" onkeyup=\"CheckFieldLength(this, 'gallery_comment', 255);\" onkeydown=\"CheckFieldLength(this,'gallery_comment', 255);\" onmouseout=\"CheckFieldLength(this,'gallery_comment', 255);\"></textarea><br><br><input type=\"submit\" name=\"submit\" value=\"Eintragen\" /></form></td></tr><tr><td colspan=\"2\" align=\"right\">{$c_page}</td></tr></table>";
1734            return $code;
1735        }
1736        if ( $do == 'set' ) {
1737            $comment = strip_tags ( $comment );
1738            $bad_check = $this->BadWordFilter ( $comment );
1739            $bad = '';
1740            if ( $bad_check == 1 ) $bad = "ERROR_WORD";
1741            if ( empty ( $bad ) ) {
1742                $new_comm = str_ireplace ( $smily_search, '', $comment, $smily_count );
1743                if ( $smily_count > 3 ) return "ERROR_SMILY";
1744                $sql = "INSERT INTO `lol_gallery_comments` VALUES ('', {$id}, '{$name}', '{$comment}')";
1745                $result = $this->query ( $sql, $this->forum_db );
1746                if ( ! $result ) return false;
1747            }
1748            else
1749                return $bad;
1750        }
1751    }
1752
1753    private function gallery_report_comment ( $id, $start, $hash )
1754    {
1755        global $user;
1756        if ( ! empty ( $id ) ) {
1757            $subject = "Gallery Kommentarmeldung von {$user->data['username']}";
1758            $message = "Der Benutzer meldet den folgenden Kommentar als nicht zulässig!<br><a href=\"portal.php?mod=gallery&report_show={$id}&cs={$start}&hash={$hash}#{$id}\" target=\"_blank\">Anzeigen</a>";
1759            $this->phpbb_send_pm ( 2, $subject, $message, $user->data ['user_id'] );
1760        }
1761    }
1762
1763    /**
1764     * @return unknown_type
1765     */
1766    private function get_gallery_badwordlist ()
1767    {
1768        $words = array ();
1769        $sql = "SELECT `word` FROM `lol_gallery_badwords`";
1770        $query = $this->query ( $sql, $this->forum_db );
1771        while ( $get = $this->fetch_row ( $query ) )
1772            $words [ ] = $get [0];
1773        return $words;
1774    }
1775
1776    protected function BadWordFilter ( &$text, $replace = 0 )
1777    {
1778        //fill this array with the bad words you want to filter and their replacements
1779        $badwords = $this->get_gallery_badwordlist ( );
1780        foreach ( $badwords as $bword )
1781            $bads [ ] = array ( $bword, "" );
1782        if ( $replace == 1 ) { //we are replacing
1783            $remember = $text;
1784            for ( $i = 0; $i < sizeof ( $bads ); $i ++ ) //go through each bad word
1785                $text = eregi_replace ( $bads [$i] [0], $bads [$i] [1], $text ); //replace it
1786            if ( $remember != $text ) return 1; //if there are any changes, return 1
1787        }
1788        else { //we are just checking
1789            for ( $i = 0; $i < sizeof ( $bads ); $i ++ ) { //go through each bad word
1790                if ( eregi ( $bads [$i] [0], $text ) ) return 1; //if we find any, return 1
1791            }
1792        }
1793    }
1794
1795    /**
1796     * @return unknown_type
1797     */
1798    protected function gallery_get_blacklist ()
1799    {
1800        $blacklist = array ();
1801        $sql = "SELECT `name` FROM `lol_gallery_blacklist`";
1802        $get_blacklist = $this->query ( $sql, $this->forum_db );
1803        if ( ! $get_blacklist ) return array ();
1804        while ( $got = $this->fetch_row ( $get_blacklist ) )
1805            $blacklist [ ] = strtolower($got [0]);
1806        return $blacklist;
1807    }
1808
1809    /**
1810     * @param $requester
1811     * @param $uname
1812     * @param $is_new_reg
1813     * @return unknown_type
1814     */
1815    protected function community_points_reg ( $ugroup = 0, $requester = '', $uname, $is_new_reg = false )
1816    {
1817        if ( ! $this->root_db ) return "<br>Server zur Zeit Offline";
1818        if ( ! $uname ) return "<br>Kein Benutzername zum Registrieren angegeben!";
1819        $uname = strtolower ( $uname );
1820        if ( $is_new_reg ) {
1821            $points = 0;
1822            $tpoints = 0;
1823            if ( $this->point_config ['other'] [2] ) {
1824                $points = 50;
1825                $log = 9;
1826            }
1827            else
1828                $log = false;
1829            if ( $requester != 'donation' ) {
1830                $get_donation_sql = "SELECT `id` FROM `donations` WHERE `name` = '{$uname}'";
1831                $get_donation_query = $this->query ( $get_donation_sql, $this->forum_db );
1832                $get_donation = $this->num_rows ( $get_donation_query );
1833            }
1834            else
1835                $get_donation = 0;
1836            if ( $get_donation > 0 ) {
1837                $chartrans = $this->num_rows ( $this->query ( "SELECT DISTINCT `char` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`char_transfer` WHERE `account` = '{$uname}'", $this->root_db ) );
1838                if ( $chartrans > 0 ) {
1839                    $donated = true;
1840                    $chartrans = ( $chartrans > 3 ) ? 3 : $chartrans;
1841                    $tpoints = $points + $this->point_config ['req'] ['vip'];
1842                    $points = $points + ( $this->point_config ['req'] ['vip'] - ( $this->point_config ['req'] [chartrans] * $chartrans ) );
1843                }
1844                else {
1845                    $donated = true;
1846                    $tpoints = $points + $this->point_config ['req'] ['vip'];
1847                    $points = $points + $this->point_config ['req'] ['vip'];
1848                }
1849            }
1850            else
1851                $tpoints = $points;
1852        }
1853        $sql = "INSERT INTO `lol_points` VALUES (NULL, '{$uname}', {$points}, {$tpoints}, 1)";
1854        $query = $this->query ( $sql, $this->forum_db );
1855        if ( ! $query ) return "<br>Fehler beim Registrieren des Benutzers \"{$uname}\" für ein Punktekonto";
1856        else {
1857            $user_id = $this->sql_nextid ( $this->forum_db );
1858            if ( $log ) {
1859                $date = time ( );
1860                $ins_sql = "INSERT INTO `lol_points_log` VALUES ('', {$user_id}, {$date}, {$this->point_config['get']['welcome']}, {$log}, '', 'SYSTEM')";
1861                $log_query = $this->query ( $ins_sql, $this->forum_db );
1862            }
1863            if ( $donated ) {
1864                $points = ( $this->point_config ['other'] [2] ) ? $points - $this->point_config ['get'] ['welcome'] : $points;
1865                $donated_query = $this->query ( "INSERT INTO `lol_points_log` VALUES ('', {$user_id}, {$date}, {$points}, 10, '', 'SYSTEM')", $this->forum_db );
1866            }
1867            if ( $requester == 'show_profile' ) return $this->community_points_show_profile ( $ugroup, $uname );
1868            return true;
1869        }
1870    }
1871
1872    /**
1873     * @param $uname
1874     * @param $type
1875     * @param $points
1876     * @return unknown_type
1877     */
1878    public function community_points_add_rem ( $uname, $type = '', $points = 0, $from = '', $reason_extra = '' )
1879    {
1880        $uname = strtolower ( $uname );
1881        $points_life = 0;
1882        $plural = ( $points > 1 || $points < - 1 ) ? 'e' : '';
1883        /*
1884         * 1 = Punkte für eine Spende bekommen
1885         * 2 = VIP, weil die in der Konfig eingestellten Punkte Erreicht
1886         * 3 = Punkte für einen Chartransfer eingelöst
1887         * 4 = Punkte für einen Avatar Eingelöst
1888         * 5 = Punkte für die Forenteilname bekommen
1889         * 6 = Punkte für ein Event bekommen
1890         * 7 = Punkte für den Einsatz für die Community/Server
1891         * 8 = Punkte von einem GM bekommen/abgezogen
1892         * 9 = Neue Registrierung
1893         * 10 = Bestandsvipübernahme
1894         * 11 = Eigene Begründung für die Punkte
1895         * 12 = Characterwiederherstellung
1896         * 13 = VIP-Hemd
1897         * 14 = Werbereduzierung
1898         * 15 = Langzeitlöschschutz
1899         * 16 = Rassen-/Fraktionswechsel
1900         * 17 = Upperdeck Eintausch
1901         * 18 = Charakterumbenennung
1902         * 19 = Upperdeck Zeitbonus
1903         * 20 = Punkte fürs Voten
1904         * 21 = VIP-Hemd Premium
1905         * 22 = Kleine LoL-Tasche
1906         * 23 = Große LoL-Tasche
1907         */
1908        switch ( $type )
1909        {
1910            case 'donation':
1911                $points_life = ( strstr ( $points, '-' ) ) ? 0 : $points;
1912                $log = true;
1913                $log_cat = 1;
1914                break;
1915            case 'vip':
1916                $log = true;
1917                $log_cat = 2;
1918                $points = 0;
1919                break;
1920            case 'char':
1921                $log = true;
1922                $log_cat = 3;
1923                break;
1924            case 'avatar':
1925                $log = true;
1926                $log_cat = 4;
1927                break;
1928            case 'forum':
1929                $points_life = ( strstr ( $points, '-' ) ) ? 0 : $points;
1930                $log = true;
1931                $log_cat = 5;
1932                break;
1933            case 'event':
1934                $points_life = ( strstr ( $points, '-' ) ) ? 0 : $points;
1935                $log = true;
1936                $log_cat = 6;
1937                break;
1938            case 'server':
1939                $points_life = ( strstr ( $points, '-' ) ) ? 0 : $points;
1940                $log = true;
1941                $log_cat = 7;
1942                break;
1943            case 'gm':
1944                $points_life = ( strstr ( $points, '-' ) ) ? 0 : $points;
1945                $log = true;
1946                $log_cat = 8;
1947                break;
1948            case 'reason_extra':
1949                $points_life = ( strstr ( $points, '-' ) ) ? 0 : $points;
1950                $log = true;
1951                $log_cat = 11;
1952                $reason_extra = "{$points} Punkt{$plural}: " . $reason_extra;
1953                break;
1954            case 'charrebuild':
1955                $log = true;
1956                $log_cat = 12;
1957                break;
1958            case 'vipshirt':
1959                $log = true;
1960                $log_cat = 13;
1961                break;
1962            case 'adreduction':
1963                $log = true;
1964                $log_cat = 14;
1965                break;
1966            case 'lts':
1967                $log = true;
1968                $log_cat = 15;
1969                break;
1970            case 'rfchange':
1971                $log = true;
1972                $log_cat = 16;
1973                break;
1974            case 'upperdeck':
1975                $log = true;
1976                $log_cat = 17;
1977                break;
1978            case 'nchange':
1979                $log = true;
1980                $log_cat = 18;
1981                break;
1982            case 'timebonus':
1983                $log = true;
1984                $log_cat = 19;
1985                break;
1986            case 'voting':
1987                $points_life = ( strstr ( $points, '-' ) ) ? 0 : $points;
1988                $log = true;
1989                $log_cat = 20;
1990                break;
1991            case 'vipshirt_p':
1992                $log = true;
1993                $log_cat = 21;
1994                break;
1995            case 'lolbag_s':
1996                $log = true;
1997                $log_cat = 22;
1998                break;
1999            case 'lolbag_g':
2000                $log = true;
2001                $log_cat = 23;
2002                break;
2003            default:
2004                $points_life = 0;
2005                $log = false;
2006                $log_cat = 0;
2007                break;
2008        }
2009        $check_sql = "SELECT `activated` FROM `lol_points` WHERE `name` = '{$uname}'";
2010        $check_query = $this->query ( $check_sql, $this->forum_db );
2011        $check = $this->result ( $check_query );
2012        if ( $check == 1 || in_array ( $log_cat, array ( 6, 7, 8, 11 ) ) ) {
2013            $sql = "UPDATE `lol_points` SET `points_cur` = points_cur+({$points}), `points_life` = points_life+({$points_life}) WHERE `name` = '{$uname}'";
2014            $query = $this->query ( $sql, $this->forum_db );
2015            if ( $query ) {
2016                if ( $log ) {
2017                    $from = ( strlen ( $from ) > 0 ) ? $from : 'SYSTEM';
2018                    $get_id = "SELECT `id` FROM `lol_points` WHERE `name` = '{$uname}'";
2019                    $user_id = $this->query ( $get_id, $this->forum_db );
2020                    $user_id = $this->fetch_row ( $user_id );
2021                    $date = time ( );
2022                    $tpoints = $points;
2023                    if ( $log_cat == 2 ) $tpoints = $this->point_config ['req'] ['vip'];
2024                    $sql2 = "INSERT INTO `lol_points_log` VALUES ('', {$user_id[0]}, {$date}, {$tpoints}, {$log_cat}, '{$reason_extra}', '{$from}')";
2025                    $query2 = $this->query ( $sql2, $this->forum_db );
2026                    return true;
2027                }
2028            }
2029        }
2030        elseif ( ! $check || $check < 1 || empty ( $check ) ) {
2031            if ( $type == 'donation' ) $this->community_points_reg ( 0, 'donation', $uname, true );
2032            else $this->community_points_reg ( 0, '', $uname, true );
2033            return $this->community_points_add_rem ( $uname, $type, $points, $from, $reason_extra );
2034        }
2035        else
2036            return false;
2037    }
2038
2039    /**
2040     * @param $uname
2041     * @return unknown_type
2042     */
2043    protected function community_points_show_profile ()
2044    {
2045        global $user;
2046        $uname = strtolower ( $user->data ['username'] );
2047        $ugroup = $user->data ['group_id'];
2048        $code = "";
2049        $limit = request_var ( 'l', false );
2050        $txnid = request_var ( 'txnid', false );
2051        if ( ! $uname || empty ( $uname ) ) return false;
2052        if ( $txnid ) $this->do_exit ( $this->paypal_manual_check ( $txnid ) );
2053        $get_donations_sql = "SELECT `date_creation`,`txn_id`,`mc_gross`,`payment_status` FROM `paypal`.`paypal_payment_info` WHERE `item_name` LIKE '%{$uname}%'";
2054        $get_donations_query = $this->query ( $get_donations_sql, $this->forum_db );
2055        $user_donations_code .= "";
2056        while ( $paypal_da = $this->fetch_row ( $get_donations_query ) ) {
2057            $date = explode ( '-', $paypal_da [0] );
2058            $date = $date [2] . "." . $date [1] . "." . $date [0];
2059            $mon = str_replace ( '.', ',', $paypal_da [2] );
2060            $status = ( $paypal_da [3] != 'Completed' && $paypal_da [3] != 'Denied' ) ? "<div onmouseover=\"Tip('Zum neuen Verifizieren deiner Spende einfach hier Klicken!</div>')\" onmouseout=\"UnTip()\" onclick=\"get_content('points_content','portal.php?mod=points&txnid={$paypal_da[1]}', 'get');return false;\"><a href=\"javascript:void(0);\">{$paypal_da[3]}</a></div>" : "<font color=\"green\">{$paypal_da[3]}</font>";
2061            $user_donations_code .= "<tr><td>{$date}</td><td>{$mon}</td><td>{$status}</td></tr>";
2062        }
2063        if ( empty ( $user_donations_code ) ) $user_donations_code = "<tr><td align=\"center\" colspan=\"3\">Keine Spenden getätigt</td></tr>";
2064        if ( $limit ) {
2065            $limit = "";
2066            $and = "";
2067        }
2068        else {
2069            $limit = " LIMIT 3";
2070            $and = " AND `reason` <> 5";
2071        }
2072        $sql = "SELECT * FROM `lol_points` WHERE `name` = '{$uname}'";
2073        $query = $this->query ( $sql, $this->forum_db );
2074        if ( ! $query ) return "<br>Fehler beim Abfragen deiner Punkte!";
2075        $get = $this->fetch_row ( $query );
2076        if ( $get && $get [0] > 0 ) {
2077            if ( $get [4] == 0 ) $inactive = "<font color=\"red\">Dein LoL-Punktekonto wurde Deaktiviert!</font>";
2078            else $inactive = "&nbsp;";
2079            $code = "<br><center><table><tr><td colspan=\"2\" align=\"center\"><h1><img src=\"images/lol_cop_32x32.png\" /> Punktekonto von {$uname} <img src=\"images/lol_cop_32x32.png\" /></h1></td></tr>
2080            <tr><td colspan=\"2\" align=\"center\"><b>Deine Aktuellen Punkte: {$get[2]}</b></td></tr>
2081            <tr><td colspan=\"2\">{$inactive}</td></tr>
2082            <tr><td colspan=\"2\" align=\"center\"><strong>Kontoaktivität</strong><br><table style=\"border-width: 2px 2px 2px 2px; border-spacing: 2px; border-style: groove groove groove groove; border-color: black black black black; border-collapse: separate; background-color: white;\"><tr><td><div style=\"position:relative; width:555px; height:100px; background-color:#ffffff; overflow:auto;\"><table>";
2083            $sql2 = "SELECT * FROM `lol_points_log` WHERE `user` = {$get[0]}{$and} ORDER BY `id` DESC{$limit}";
2084            $query2 = $this->query ( $sql2, $this->forum_db );
2085            if ( ! $query2 ) return "<br>Fehler beim Abfragen des Punkte Logs!";
2086            if ( $ugroup !== 0 && $this->point_config ['other'] [3] && $get [3] >= $this->point_config ['req'] ['vip'] && ! in_array ( $ugroup, array ( 5, 11, 7, 9, 10, 4 ) ) ) {
2087                $check_already_vip_sql = "SELECT `reason` FROM `lol_points_log` WHERE `user` = {$get[0]} AND `reason` IN (2, 10)";
2088                $check_already_vip_query = $this->query ( $check_already_vip_sql, $this->forum_db );
2089                if ( ! $check_already_vip_query ) return "<br>Fehler beim Abfragen des Punkte Logs!";
2090                $is_vip = $this->num_rows ( $check_already_vip_query );
2091                if ( $is_vip == 0 ) {
2092                    $vip_set = $this->forum_set_vip_status ( $uname, 'add' );
2093                    if ( $vip_set ) {
2094                        $this->community_points_add_rem ( $uname, 'vip', $this->point_config ['req'] ['vip'] );
2095                        $query2 = $this->query ( $sql2, $this->forum_db );
2096                        if ( ! $query2 ) return "<br>Fehler beim Abfragen des Punkte Logs!";
2097                        $f_user = $user->data ['user_id'];
2098                        $gift_code = $this->generate_gift_code ( );
2099                        if ( $f_user > 0 && $gift_code ) {
2100                            $subject = "Du bist VIP...";
2101                            $message = "Hallo {$uname},<br /><br />du hast die {$this->point_config ['req'] ['vip']} Punkte erreicht und bist somit V.I.P. geworden.<br />Dieses tolle Hemd gibt dir in Gruppen die X-fache EP für das Töten von MOB's. ( Bis max lvl 80 )<br />Du hast nun die Möglichkeit den folgenden Code inGame bei unserem NPC einzulösen:<br />{$gift_code}<br /><br />Den NPC findest du in jeder großen Stadt vor oder in einem Auktionshaus! Du kannst den Code einmal für einen deiner Chars dieses Accounts Eintauschen.<br /><br />P.S. Level-UP Anfragen bitte per PM an Kleinerwolf oder Raccoon!<br />MFG<br /><br />Dein LoL-Team";
2102                            $send_pm = $this->phpbb_send_pm ( $f_user, $subject, $message );
2103                        }
2104                        else
2105                            return "<br>Fehler: Keine Benutzer ID oder Code konnte nicht generiert werden.";
2106                    }
2107                }
2108            }
2109            $log_entries = $this->num_rows ( $query2 );
2110            if ( $log_entries > $this->point_config ['other'] [1] ) {
2111                $this->community_points_delete_old_log ( $uname );
2112                $query2 = $this->query ( $sql2, $this->forum_db );
2113                if ( ! $query2 ) return "<br>Fehler beim Abfragen des Punkte Logs!";
2114            }
2115            while ( $got = $this->fetch_row ( $query2 ) ) {
2116                $date = @date ( "d.m.Y - H:m", $got [2] );
2117                $log_txt = ( $got [4] == 11 ) ? $got [5] : ( ( in_array ( $got [4], array ( 16, 18 ) ) ) ? $this->community_points_log_txt ( $got [3], $got [4] ) . $got [5] : $this->community_points_log_txt ( $got [3], $got [4] ) );
2118                if ( ( $got [4] == 21 && time ( ) < strtotime ( "+20 minutes", $got [2] ) ) || $got [4] != 21 ) $code .= "<tr><td width=\"150\">{$date}</td><td>{$log_txt}</td></tr>";
2119            }
2120            $code .= "</table></div></td></tr></table></td></tr><tr><td colspan=\"2\" align=\"center\">[ <a href=\"javascript:void(0);\" onclick=\"get_content('points_content','portal.php?mod=points&l=true&ajax=true', 'get');return false;\">Komplett Anzeigen</a> ] [ <a href=\"javascript:void(0);\" onclick=\"get_content('points_content','portal.php?mod=points&ajax=true', 'get');return false;\">Normal Anzeigen</a> ]</td></tr></table><br>
2121            <strong>PayPal Spenden</strong><br>
2122            <table style=\"border-width: 2px 2px 2px 2px; border-spacing: 2px; border-style: groove groove groove groove; border-color: black black black black; border-collapse: separate; background-color: white;\"><tr><td><div style=\"position:relative; width:555px; height:100px; background-color:#ffffff; overflow:auto;\" id=\"user_donations\">
2123            <table width=\"100%\">
2124            <tr><td><b>Datum</b></td><td><b>Betrag</b></td><td><b>Status</b></td></tr>
2125            {$user_donations_code}
2126            </table>
2127            </div></td></tr></table></center>";
2128            return $code;
2129        }
2130        else
2131            return $this->community_points_reg ( $ugroup, 'show_profile', $uname, true );
2132    }
2133
2134    /**
2135     * @return FAQ HTML-Code
2136     */
2137    protected function community_points_faq ()
2138    {
2139        $code = "<table width=\"550\">
2140        <tr><td align=\"left\" colspan=\"3\"><b>Achtung: Punkte können erst ab der stufe V.I.P. eingetauscht werden!</b><br></td></tr>
2141        <tr><td align=\"left\" colspan=\"3\"><i>Wofür bekomme ich LoL-Punkte und wieviel?</i></td></tr>
2142        <tr><td>-</td><td align=\"left\" width=\"350\">Registrierung bei LandOfLegends</td><td align=\"right\">{$this->point_config['get']['welcome']} Punkte</td></tr>
2143        <tr><td>-</td><td align=\"left\">An der Community Teilnehmen</td><td align=\"right\">{$this->point_config['get']['forum']} Punkt (à {$this->point_config['day']['forum']} pro Tag)</td></tr>
2144        <tr><td>-</td><td align=\"left\">An einem LoL-Event Teilnehmen und vielleicht Gewinnen</td><td align=\"right\">Verschieden</td></tr>
2145        <tr><td>-</td><td align=\"left\">Vom Team für besonderes Einbringen in die Community, usw.</td><td align=\"right\">Verschieden</td></tr>
2146        <tr><td>-</td><td align=\"left\">Für den Server Spenden</td><td align=\"right\">Verschieden</td></tr>
2147        <tr><td>-</td><td align=\"left\">Eine legendäre Sammelkarte Eintauschen</td><td align=\"right\">{$this->point_config['get']['upper_exchange']} Punkte (à {$this->point_config['other'][5]} per Acc)</td></tr>
2148        <tr><td>-</td><td align=\"left\">Für den Server Voten</td><td align=\"right\">{$this->point_config['get']['voting']} Punkte (max 50 pro Tag)</td></tr>
2149        <tr><td colspan=\"3\"></td></tr>
2150        <tr><td align=\"left\" colspan=\"3\"><i>Wofür kann ich die LoL-Punkte Einlösen?</i></td></tr>
2151        <tr><td>-</td><td align=\"left\" width=\"200\">Charaktertransfer</td><td align=\"right\">{$this->point_config['req']['chartrans']} Punkte (à {$this->point_config['other'][0]} per Acc)</td></tr>
2152        <tr><td>-</td><td align=\"left\" width=\"200\">Charkaterwiederherstellung ( max 30 Tage nach Löschen )<br>Nur falls sie vom Spieler Selber gelöscht wurden!<br>Keine Wiederherstellung von ganzen Accounts!<br>Auch nicht für neu angelegte Accounts, nachdem sie gelöscht wurden!</td><td align=\"right\">{$this->point_config['req']['charrebuild']} Punkte</td></tr>
2153        <tr><td>-</td><td align=\"left\">Eigener Forenavatar</td><td align=\"right\">{$this->point_config['req']['avatar']} Punkte</td></tr>
2154        <tr><td>-</td><td align=\"left\">VIP Status ( Wird automatisch beim erreichen der Punkte gesetzt )</td><td align=\"right\">{$this->point_config['req']['vip']} Punkte</td></tr>
2155        <tr><td>-</td><td align=\"left\">Weiteres VIP-Hemd</td><td align=\"right\">{$this->point_config['req']['vipshirt']} Punkte</td></tr>
2156        <tr><td>-</td><td align=\"left\">Upgrade auf VIP-Hemd PREMIUM. Vorraussetzung: Normales VIP-Hemd<br>Achtung: Normales VIP-Hemd wird beim Upgrade gelöscht! Account & Seelengebunden!</td><td align=\"right\">{$this->point_config['req']['vipshirt_p']} Punkte</td></tr>
2157        <tr><td>-</td><td align=\"left\">Erweiterter Löschschutz ( +12 Monate )</td><td align=\"right\">{$this->point_config['req']['lts']} Punkte</td></tr>
2158        <tr><td>-</td><td align=\"left\">Rassen-/ Fraktionswechsel mit Charakter Neugestaltung</td><td align=\"right\">{$this->point_config['req']['rfchange']} Punkte</td></tr>
2159        <tr><td>-</td><td align=\"left\">Charakterumbennenung</td><td align=\"right\">{$this->point_config['req']['nchange']} Punkte</td></tr>
2160        <tr><td>-</td><td align=\"left\">Upperdeck-Generator Cooldown Aussetzung ( 1 mal )</td><td align=\"right\">{$this->point_config['req']['timebonus']} Punkte</td></tr>
2161        <tr><td>-</td><td align=\"left\">Kleine LoL-Tasche ( 30 Plätze )<br>( Achtung: Account, Seelengebunden und einzigartig Anlegbar! )</td><td align=\"right\">{$this->point_config['req']['lolbag_s']} Punkte</td></tr>
2162        <tr><td>-</td><td align=\"left\">Große LoL-Tasche ( 34 Plätze )<br>( Achtung: Account, Seelengebunden und einzigartig Anlegbar! )</td><td align=\"right\">{$this->point_config['req']['lolbag_g']} Punkte</td></tr>
2163        </table>";
2164        return $code;
2165    }
2166
2167    /**
2168     * @param $uname
2169     * @return HTML-CODE
2170     */
2171    protected function community_points_pay_menu ()
2172    {
2173        global $user;
2174       
2175        $check_browser = $this->check_browser ( "pay_menu", "Firefox", 8 );
2176       
2177        if ( is_string ( $check_browser ) ) return $check_browser;
2178       
2179        $uname = strtolower ( $user->data ['username_clean'] );
2180        $sql = "SELECT `points_cur`,`points_life`, `id` as ids, (SELECT `id` FROM `lol_points_VLTS` WHERE `id` = `ids`) as lts,`activated` FROM `lol_points` WHERE `name` = '{$uname}'";
2181        $query = $this->query ( $sql, $this->forum_db );
2182        if ( ! $query ) return "<br>Fehler beim Abfragen deiner Punkte!";
2183        $get = $this->fetch_row ( $query );
2184        $is_good = ( $this->cpu_load_to_high ( ) || ! $this->root_db || ! $this->realm_online [0] ) ? false : true;
2185        $is_code = "<br><font color=\"red\">Server Offline - Kein Eintauschen möglich!</font>";
2186        if ( $is_good ) $is_code = '';
2187        if ( $is_good && $get [4] == 0 ) $is_code = "<br><font color=\"red\">Punktekonto Deaktiviert!</font>";
2188        $code = "<table><tr><td colspan=\"2\" align=\"center\"><b>Punkte Aktuell:</b> {$get[0]}</td><tr><td colspan=\"2\" align=\"center\"><b>Deine Eintauschmöglichkeiten</b>{$is_code}</td></tr>";
2189        if ( $get [1] >= $this->point_config ['req'] ['vip'] || $this->point_config ['other'] [6] != 0 ) {
2190            $points_chartrans = ( $get [0] >= $this->point_config ['req'] ['chartrans'] && $is_good && $get [4] == 1 ) ? "<input type=\"button\" value=\"Punkte Einlösen\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_for&pay_for=char&ajax=true', 'get');return false;\" />" : "<input type=\"button\" value=\"Zu wenig Punkte\" />";
2191            $points_avatar = ( $get [0] >= $this->point_config ['req'] ['avatar'] && $is_good && $get [4] == 1 ) ? "<input type=\"button\" value=\"Punkte Einlösen\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_for&pay_for=ava&ajax=true', 'get');return false;\" />" : "<input type=\"button\" value=\"Zu wenig Punkte\" />";
2192            $points_charrebuild = ( $get [0] >= $this->point_config ['req'] ['charrebuild'] && $is_good && $get [4] == 1 ) ? "<input type=\"button\" value=\"Punkte Einlösen\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_for&pay_for=charr&ajax=true', 'get');return false;\" />" : "<input type=\"button\" value=\"Zu wenig Punkte\" />";
2193            $vipshirt = ( $get [0] >= $this->point_config ['req'] ['vipshirt'] && $is_good && $get [4] == 1 ) ? "<input type=\"button\" value=\"Punkte Einlösen\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_for&pay_for=vipshirt&ajax=true', 'get');return false;\" />" : "<input type=\"button\" value=\"Zu wenig Punkte\" />";
2194            $lts = ( $get [0] >= $this->point_config ['req'] ['lts'] && $is_good && $get [4] == 1 ) ? ( ( $get [3] < 1 ) ? "<input type=\"button\" value=\"Punkte Einlösen\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_for&pay_for=lts&ajax=true', 'get');return false;\" />" : "<input type=\"button\" value=\"Bereits benutzt\" disabled />" ) : "<input type=\"button\" value=\"Zu wenig Punkte\" />";
2195            $rfchange = ( ( ( $get [0] >= $this->point_config ['req'] ['rfchange'] && $is_good ) || ( $this->point_config ['other'] [6] != 0 && $is_good ) ) && $get [4] == 1 ) ? "<input type=\"button\" value=\"Punkte Einlösen\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_for&pay_for=rfchange&ajax=true', 'get');return false;\" />" : "<input type=\"button\" value=\"Zu wenig Punkte\" />";
2196            $uexchange = ( $is_good && $get [4] == 1 ) ? "<input type=\"button\" value=\"Punkte Einlösen\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_for&pay_for=uexchange&ajax=true', 'get');return false;\" />" : "<input type=\"button\" value=\"Zu wenig Punkte\" />";
2197            $nchange = ( $get [0] >= $this->point_config ['req'] ['nchange'] && $is_good && $get [4] == 1 ) ? "<input type=\"button\" value=\"Punkte Einlösen\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_for&pay_for=nchange&ajax=true', 'get');return false;\" />" : "<input type=\"button\" value=\"Zu wenig Punkte\" />";
2198            $timebonus = ( $get [0] >= $this->point_config ['req'] ['timebonus'] && $is_good && $get [4] == 1 ) ? "<input type=\"button\" value=\"Punkte Einlösen\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_for&pay_for=timebonus&ajax=true', 'get');return false;\" />" : "<input type=\"button\" value=\"Zu wenig Punkte\" />";
2199            $vipshirt_p = ( $get [0] >= $this->point_config ['req'] ['vipshirt_p'] && $is_good && $get [4] == 1 ) ? "<input type=\"button\" value=\"Punkte Einlösen\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_for&pay_for=vipshirt_p&ajax=true', 'get');return false;\" />" : "<input type=\"button\" value=\"Zu wenig Punkte\" />";
2200            $lolbag_s = ( $get [0] >= $this->point_config ['req'] ['lolbag_s'] && $is_good && $get [4] == 1 ) ? "<input type=\"button\" value=\"Punkte Einlösen\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_for&pay_for=lolbag_s&ajax=true', 'get');return false;\" />" : "<input type=\"button\" value=\"Zu wenig Punkte\" />";
2201            $lolbag_g = ( $get [0] >= $this->point_config ['req'] ['lolbag_g'] && $is_good && $get [4] == 1 ) ? "<input type=\"button\" value=\"Punkte Einlösen\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_for&pay_for=lolbag_g&ajax=true', 'get');return false;\" />" : "<input type=\"button\" value=\"Zu wenig Punkte\" />";
2202            switch ( $this->point_config ['other'] [6] )
2203            {
2204                case 1:
2205                    $rfchange_campaign_txt = '<br>Kostenloser Transfer Horde auf Allianz (Aktionswoche)';
2206                    break;
2207                case 2:
2208                    $rfchange_campaign_txt = '<br>Kostenloser Transfer Allianz auf Horde (Aktionswoche)';
2209                    break;
2210                case 12:
2211                    $rfchange_campaign_txt = '<br>Kostenloser Transfers (Aktionswoche)';
2212                    break;
2213                default:
2214                    $rfchange_campaign_txt = '';
2215                    break;
2216            }
2217            $menu_array = array ( 'chartrans' => "<tr><td align=\"right\">{$this->point_config['req']['chartrans']}</td><td>Punkte für einen Charaktertransfer Eintauschen</td><td>{$points_chartrans}</td></tr>", 'charrebuild' => "<tr><td align=\"right\">{$this->point_config['req']['charrebuild']}</td><td>Punkte für eine Charakterwiederherstellung Eintauschen, sofern möglich.</td><td>{$points_charrebuild}</td></tr>", 'avatar' => "<tr><td align=\"right\">{$this->point_config['req']['avatar']}</td><td>Punkte für einen Eigenen Forenavatar Eintauschen</td><td>{$points_avatar}</td></tr>", 'vipshirt' => "<tr><td align=\"right\">{$this->point_config['req']['vipshirt']}</td><td>Punkte für ein weiteres VIP-Hemd Eintauschen</td><td>{$vipshirt}</td></tr>", 'lts' => "<tr><td align=\"right\">{$this->point_config['req']['lts']}</td><td>Punkte für den erweiterten Löschschutz ( + 12 Monate )</td><td>{$lts}</td></tr>", 'rfchange' => "<tr><td align=\"right\">{$this->point_config['req']['rfchange']}</td><td>Punkte für einen Rassen-/Fraktionswechsel{$rfchange_campaign_txt}</td><td>{$rfchange}</td></tr>", 'uexchange' => "<tr><td align=\"right\">{$this->point_config['get']['upper_exchange']}</td><td>Punkte für das Eintauschen einer Sammelkarte bekommen</td><td>{$uexchange}</td></tr>", 'nchange' => "<tr><td align=\"right\">{$this->point_config['req']['nchange']}</td><td>Punkte gegen eine Charakterumbenennung Eintauschen</td><td>{$nchange}</td></tr>", 'timebonus' => "<tr><td align=\"right\">{$this->point_config['req']['timebonus']}</td><td>Punkte gegen eine Upperdeck-Generator Cooldownaussetzung Eintauschen.</td><td>{$timebonus}</td></tr>", 'vipshirt_p' => "<tr><td align=\"right\">{$this->point_config['req']['vipshirt_p']}</td><td>Punkte gegen ein premium VIP-Hemd Eintauschen.<br>(Achtung: Account und Seelengebunden! Vorrausetzung: Normales VIP-Hemd, das gelöscht wird!)</td><td>{$vipshirt_p}</td></tr>", 'lolbag_s' => "<tr><td align=\"right\">{$this->point_config['req']['lolbag_s']}</td><td>Punkte gegen eine kleine LoL-Tasche ( 30 Plätze ) Eintauschen.<br>( Achtung: Account, Seelengebunden und einzigartig Anlegbar! )</td><td>{$lolbag_s}</td></tr>", 'lolbag_g' => "<tr><td align=\"right\">{$this->point_config['req']['lolbag_g']}</td><td>Punkte gegen eine große LoL-Tasche ( 34 Plätze ) Eintauschen.<br>( Achtung: Account, Seelengebunden und einzigartig Anlegbar! )</td><td>{$lolbag_g}</td></tr>" );
2218            ksort ( $menu_array );
2219            foreach ( $menu_array as $entry )
2220                $code .= $entry;
2221        }
2222        else
2223            $code .= "<tr><td colspan=\"2\">Leider kannst du erst Punkte Eintauschen, wenn du V.I.P. bist.<br>Dies stellt sicher, dass nicht nur 1-2 €uro gespendet werden, da wir sonst Probleme bekommen könnten.<br>V.I.P. ist man ab {$this->point_config['req']['vip']} Punkte!</td></tr>";
2224        $code .= "</table>";
2225        return $code;
2226    }
2227
2228    /**
2229     * @param $uname
2230     * @param $pay_for
2231     * @return unknown_type
2232     */
2233    protected function community_points_pay_for ( $data )
2234    {
2235        global $user;
2236        if ( $this->cpu_load_to_high ( ) || ! $this->root_db || ! $this->realm_online [0] ) return "Service Temporär wegen hoher Server Belastung nicht verfügbar, bitte versuche es in ein paar Minuten erneut!";
2237        $pay_for = request_var ( 'pay_for', '' );
2238        $url = $this->check_post_data ( $data, 'url', false, '' );
2239        $acc = $this->check_post_data ( $data, 'acc', false, '' );
2240        $char = $this->check_post_data ( $data, 'char', false, '' );
2241        $uname = strtolower ( $user->data ['username'] );
2242        $account = strtolower ( $acc );
2243        $lol_form_salt = $this->check_post_data ( $data, 'lol_form_salt', false, '' );
2244        $code = "";
2245        $ajax = request_var ( 'ajax_f', false );
2246        $sql = "SELECT `points_cur`,`id` FROM `lol_points` WHERE `name` = '{$uname}'";
2247        $query = $this->query ( $sql, $this->forum_db );
2248        if ( ! $query ) return "<br>Fehler beim Abfragen deiner Punkte!";
2249        $get = $this->fetch_row ( $query );
2250        if ( $pay_for == 'ava' ) {
2251            if ( $get [0] < $this->point_config ['req'] ['avatar'] ) return "Leider nicht genug Punkte!";
2252            if ( $ajax ) {
2253                if ( $get [0] < $this->point_config ['req'] ['avatar'] ) return "Leider nicht genug Punkte!";
2254                if ( empty ( $url ) ) return "Fehler: Keine URL angegeben.";
2255                $img_props = @getimagesize ( $url );
2256                if ( $img_props ) {
2257                    $type = explode ( '/', $img_props [mime] );
2258                    $ext = explode ( '.', $url );
2259                    $last_ele = count ( $ext ) - 1;
2260                    if ( ! in_array ( $type [1], array ( "jpeg", "jpg", "png" ) ) || ! in_array ( $ext [$last_ele], array ( "jpeg", "jpg", "png" ) ) ) return "Leider entspricht dein Avatar nicht den erlaubten Imagetypen!<br>Oder er hat einen ungültigen Mimetyp!";
2261                    if ( $img_props [0] > 116 || $img_props [1] > 160 ) return "Dein Avatar ist zu groß.";
2262                    elseif ( $img_props [0] < 50 || $img_props [1] < 50 ) return "Dein Avatar erfüllt nicht die minimale größe.";
2263                    $sql = "UPDATE `phpbb_users` SET `user_avatar` = '{$url}',`user_avatar_type` = '2',`user_avatar_width` = '{$img_props[0]}',`user_avatar_height` = '{$img_props[1]}' WHERE `username_clean` = '{$uname}'";
2264                    $query = $this->query ( $sql, $this->forum_db );
2265                    $check_sql = "SELECT `user_avatar` FROM `phpbb_users` WHERE `username_clean` = '{$uname}'";
2266                    $check = $this->fetch_row ( $this->query ( $check_sql, $this->forum_db ) );
2267                    if ( $check [0] == $url ) $this->community_points_add_rem ( $uname, 'avatar', - $this->point_config ['req'] ['avatar'] );
2268                    else return "Fehler beim Setzen des Avatars.";
2269                    return "Avatar gesetzt:<br><img src=\"{$url}\" {$img_props[3]} />";
2270                }
2271                else
2272                    return "Fehler beim Feststellen des Imagetypes.";
2273            }
2274            $code = "Bitte gebe hier alle erforderlichen Daten für deinen Eigenen Avatar ein.<br /><table><tr><td><form id=\"avatar\"><table><tr><td colspan=\"2\">Avatargröße ist minimal 50 x 50 und maximal 116 x 160 Pixel</td></tr><tr><td colspan=\"2\">Erlaubte Imagetypen: jpeg, jpg, png</td></tr><tr><td>Avatar Url:</td><td><input type=\"text\" name=\"url\" autocomplete=\"off\" /></td></tr><tr><td colspan=\"2\" align=\"center\"><input type=\"button\" value=\"Avatar Setzen\" onclick=\"ajaxUpload(this.form,'portal.php?mod=points&pay_for=ava&action=pay_for&ajax=true&ajax_f=true','points_content2','<center>Avatar wird gesetzt...</center>','<center>Fehler</center>'); return false;\" /></td></tr></table></form></td><td><div id=\"points_content2\"></div></td></tr></table>";
2275        }
2276        if ( $pay_for == 'char' ) {
2277            if ( $get [0] < $this->point_config ['req'] ['chartrans'] ) return "Leider nicht genug Punkte!";
2278            if ( $this->cpu_load_to_high ( ) || ! $this->realm_online [0] ) return "Service Temporär wegen hoher Server Belastung nicht verfügbar, bitte versuche es in ein paar Minuten erneut!";
2279            $idc = $this->get_account_id_name ( $uname );
2280            $check_ban = "SELECT `till` FROM `user_banns` WHERE `gid` = '{$idc}'";
2281            $check_ban2 = $this->fetch_row ( $this->query ( $check_ban, $this->forum_db ) );
2282            if ( $check_ban2 [0] >= time ( ) ) return "<br>Leider wurde dein Account gebannt und es ist dir nicht möglich einen Charakter zu Transferieren!";
2283            if ( $ajax ) {
2284                if ( $get [0] < $this->point_config ['req'] ['chartrans'] ) return "Leider nicht genug Punkte!";
2285                if ( $this->check_lol_form_salt ( $lol_form_salt ) ) $deleted = $this->del_lol_form_salt ( $lol_form_salt );
2286                else return "Fehler: Du hast dieses Formular schon abgesendet!";
2287               
2288                if ( ! empty ( $account ) && ! empty ( $char ) && $char != 0 ) {
2289                    $time = time ( );
2290                    $t_character = explode ( '||', $char );
2291                    $charname = trim ( $t_character [1] );
2292                    if ( empty ( $charname ) || strlen ( $charname ) < 1 ) return "Leider hast du keinen Gültigen Charakter ausgewählt!";
2293                    $acc0 = $this->get_account_id_name ( $uname );
2294                    if ( ! $acc0 || empty ( $acc0 ) ) return "Fehler beim Abfragen der Account-ID deines accounts.";
2295                    $acc1 = $this->get_account_id_name ( $account );
2296                    if ( ! $acc1 || empty ( $acc1 ) ) return "Fehler beim Abfragen der Account-ID des Ziel-accounts. Existiert dieser? ({$acc1})";
2297                    $get_char_data = $this->query ( "SELECT `guid`, (SELECT MAX(`level`) FROM `{$this->lol_conf ['db_pve_live_characters']}`.`characters` WHERE `account` = '{$acc1}') AS max_lvl, (SELECT COUNT(`class`) FROM `{$this->lol_conf ['db_pve_live_characters']}`.`characters` WHERE `class` = 6 AND `account` = '{$acc1}') AS deathnight_count, (SELECT `class` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`characters` WHERE `name` = '{$charname}' AND `account` = '{$acc0}') AS trans_class  FROM `{$this->lol_conf ['db_pve_live_characters']}`.`characters` WHERE `account` = '{$acc1}'", $this->root_db );
2298                    $acc3 = $this->num_rows ( $get_char_data );
2299                    if ( $acc3 == 10 ) return "Leider hat der Ziel Account schon die maximale Anzahl von Charakteren und es ist nicht möglich diesen Charakter dort hin zu Transferieren!";
2300                    $acc4 = $this->fetch_row ( $get_char_data );
2301                    if ( ( $acc4 [2] > 0 || $acc4 [1] < 60 ) && $acc4 [3] == 6 ) return "Leider kannst du deinen Todesritter nicht auf diesen Account Transferieren,<br>da dort entweder kein 60iger Charakter existiert oder du auf diesem Account schon einen Todesritter hast!";
2302                    $quer = $this->query ( "SELECT DISTINCT `char` FROM `{$this->lol_conf ['db_live_accounts']}`.`char_transfer` WHERE `account` = '{$uname}'", $this->root_db );
2303                    $t_quer = array ();
2304                    while ( $t_getchar = $this->fetch_row ( $quer ) )
2305                        $t_quer [ ] = $t_getchar [0];
2306                    $sqll = "INSERT INTO `{$this->lol_conf ['db_live_accounts']}`.`char_transfer` VALUES('0','{$time}','{$uname}','{$account}','{$t_character[1]}','','1')";
2307                    $query = $this->query ( $sqll, $this->root_db );
2308                    $sql = "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`characters` SET `account`= '{$acc1}' WHERE `account` = '{$acc0}' AND `guid` = '{$t_character[0]}'";
2309                    $query2 = $this->query ( $sql, $this->root_db );
2310                    $updated = $this->affected_rows ( $this->root_db );
2311                    if ( $updated > 0 ) {
2312                        $this->community_points_add_rem ( $uname, 'char', - $this->point_config ['req'] ['chartrans'] );
2313                        return "Der Charakter: {$t_character[1]} wurde erfolgreich von<br>Account: {$uname} auf den neuen<br>Account: {$account} Transferiert!";
2314                    }
2315                    else
2316                        return "Leider gab es einen Fehler beim Transferieren des Charakters {$t_character[1]}<br>von Account: {$uname} auf den neuen Account: {$account}!";
2317                }
2318                $code = "Leider hast du nicht alle benötigten Angaben gemacht!";
2319                return $code;
2320            }
2321            $option = $this->get_account_chars ( $uname, $this->root_db );
2322            $code = "Bitte hier alle erforderlichen Daten für den Charaktertransfer Eingeben<br /><form id=\"chartransfer\">
2323            <table><tr><td align=\"center\">
2324            <table>
2325            <tr>
2326            <td align=\"right\">Ziel Account:</td>
2327            <td><span onmouseover=\"Tip('Der Account Name...<br>Alles klein schreiben!</div>')\" onmouseout=\"UnTip()\"><input type=\"text\" size=\"12\" name=\"acc\" maxlength=\"20\" autocomplete=\"off\" /></span></td>
2328            </tr>
2329            <tr>
2330            <td align=\"right\">Char Name:</td>
2331            <td><select name=\"char\">{$option}</select></td>
2332            </tr>
2333            </table>
2334            <br><input type=\"hidden\" name=\"lol_form_salt\" value=\"{$this->gen_lol_form_salt()}\" /><input type=\"button\" value=\"Transferieren\" onclick=\"this.disabled=true;ajaxUpload(this.form,'portal.php?mod=points&pay_for=char&action=pay_for&ajax=true&ajax_f=true','points_content2','<center>Charakter wird transferiert...</center>','<center>Fehler</center>'); return false;\" /></form></td></tr></table><br /><div id=\"points_content2\"></div>";
2335        }
2336        if ( $pay_for == 'charr' ) {
2337            if ( $get [0] < $this->point_config ['req'] ['charrebuild'] ) return "Leider nicht genug Punkte!";
2338            if ( $ajax ) {
2339                if ( $get [0] < $this->point_config ['req'] ['charrebuild'] ) return "Leider nicht genug Punkte!";
2340                if ( $this->check_lol_form_salt ( $lol_form_salt ) ) $deleted = $this->del_lol_form_salt ( $lol_form_salt );
2341                else return "Fehler: Du hast dieses Formular schon abgesendet!";
2342                if ( empty ( $char ) ) return "Fehler: Leider hast du keinen Charakternamen eingegeben.";
2343                $backup = $this->game_backup_check ( $uname, $char );
2344                if ( $backup && stristr ( $backup, 'Backup</b></td><td><b>Charname' ) ) {
2345                    $to = array ( 9859/*, 10003*/ );
2346                    $subject = "Der Spieler \"{$uname}\" bittet um eine Charakterwiederherstellung!";
2347                    $message = "Es folgen die Daten:<br /><br />Account: {$uname}<br />Charakter: {$char}<br /><br />Wurde zuletzt gefunden in folgendem Backup:<br /><br />{$backup}<br /><br />Bitte dem Spieler eine Rückmeldung geben, ob der Charakter wiederhergestellt wird, nachdem alles geprüft wurde.";
2348                    $pm_send = $this->phpbb_send_pm ( $to [array_rand ( $to, 1 )], $subject, $message );
2349                }
2350                if ( $backup && strlen ( $backup ) > 0 ) return $backup . "<br>Falls ein Backup gefunden wurde, ist eine PM an einen Admin versendet worden, bitte die erforderlichen Punkte nicht Ausgeben, da sonst keine Wiederherstellung möglich ist!";
2351                return "Fehler bei der Verarbeitung des Rückgabewertes der Backupsuche!";
2352            }
2353            $code = "Bitte alle erforderlichen Daten für die Charakterwiederherstellung Eingeben!<br />Achtung: Bei Charakteren mit Sonderzeichen kann es zu Problemen kommen!<br />Dann bitte direkt an einen GM Wenden!<br /><form id=\"chartransfer\" onsubmit=\"ajaxUpload(this,'portal.php?mod=points&pay_for=charr&action=pay_for&ajax=true&ajax_f=true','points_content2','<center>Backup wird gesucht...</center>','<center>JavaScript: Fehler?</center>'); return false;\">
2354            <table><tr><td align=\"center\">
2355            <table>
2356            <tr>
2357            <td align=\"right\">Charname:</td>
2358            <td><span onmouseover=\"Tip('Charname, bitte Groß- und Kleinschreibung beachten!')\" onmouseout=\"UnTip()\"><input type=\"text\" size=\"12\" name=\"char\" maxlength=\"20\" autocomplete=\"off\" /></span></td>
2359            </tr>
2360            </table>
2361            <br><input type=\"hidden\" name=\"lol_form_salt\" value=\"{$this->gen_lol_form_salt()}\" /><input type=\"submit\" value=\"Backup Suchen\" /></form></td></tr></table><br /><div id=\"points_content2\"></div>";
2362        }
2363        if ( $pay_for == 'vipshirt' ) {
2364            if ( $get [0] < $this->point_config ['req'] ['vipshirt'] ) return "Leider nicht genug Punkte!";
2365            if ( $ajax ) {
2366                if ( $get [0] < $this->point_config ['req'] ['vipshirt'] ) $this->do_exit ( "Leider nicht genug Punkte!" );
2367                $user_id = $this->get_forum_id ( $uname );
2368                if ( $user_id ) {
2369                    $gift_code = $this->generate_gift_code ( );
2370                    if ( ! $gift_code ) $code = "<br><br>Leider ist ein Fehler beim Generieren des Codes Aufgetreten, bitte DarkMan eine PM Schreiben!";
2371                    else {
2372                        $subject = "Du hast einen LoL-Code erhalten...";
2373                        $message = "Hallo {$account},
2374                        Du hast einen LoL-Code erhalten, weil du ihn gegen {$this->point_config['req']['vipshirt']} LoLCoPs eingetauscht hast und kannst diesen InGame für ein Item Einlösen.
2375                        Suche nach dem CodeBot, dieser steht in jeder Stadt vor oder im Auktionshaus!
2376                       
2377                        Dein persönlicher LoL-Code lautet:
2378                        {$gift_code}
2379                       
2380                        Achtung: Dieser Code ist an deinen Account gebunden, du kannst ihn 1 mal für einen beliebigen Charakter deines Accounts Einlösen!
2381                       
2382                        MFG
2383                       
2384                        Dein LandOfLegends Team";
2385                        $pm = $this->phpbb_send_pm ( $user_id, $subject, $message );
2386                        $code = "<br><br>Dein Code für das Item Lautet: {$gift_code}, diesen kannst du InGame beim Code-Bot Einlösen.<br>Diese Informationen wurden dir auch nochmal per PM gesendet!";
2387                        $this->community_points_add_rem ( $uname, 'vipshirt', - $this->point_config ['req'] ['vipshirt'] );
2388                    }
2389                }
2390                else
2391                    $code = "Es ist ein Fehler beim Abfragen der ID des Forumbenutzers aufgetreten.";
2392                $this->do_exit ( $code );
2393            }
2394            $code = "Möchtest du wirklich {$this->point_config['req']['vipshirt']} Punkte gegen ein weiteres Vip-Hemd eintauschen?<br>
2395            <table><tr><td><input type=\"button\" value=\"Ja\" onclick=\"this.disabled=true;get_content('points_content','portal.php?mod=points&action=pay_for&pay_for=vipshirt&ajax=true&ajax_f=true', 'get');return false;\" /></td><td><input type=\"button\" value=\"Nein\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_menu', 'get');return false;\" /></td></tr></table>";
2396        }
2397        if ( $pay_for == 'vipshirt_p' ) {
2398            if ( $get [0] < $this->point_config ['req'] ['vipshirt_p'] ) return "Leider nicht genug Punkte!";
2399            if ( $ajax ) {
2400                if ( $get [0] < $this->point_config ['req'] ['vipshirt_p'] ) $this->do_exit ( "Leider nicht genug Punkte!" );
2401                if ( $this->check_lol_form_salt ( $lol_form_salt ) ) $deleted = $this->del_lol_form_salt ( $lol_form_salt );
2402                else return "Fehler: Du hast dieses Formular schon abgesendet!";
2403                $user_id = $this->get_forum_id ( $uname );
2404                if ( $user_id ) {
2405                    $t_character = explode ( '||', $char );
2406                   
2407                    $check_vipshirt_sql = "SELECT COUNT(`item`) FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_inventory` WHERE `item` IN (SELECT `guid` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`item_instance` WHERE `itemEntry` = 200000 OR `itemEntry` = 200005) AND `guid` = '{$t_character[0]}'";
2408                    $check_vipshirt_result = $this->result ( $this->query ( $check_vipshirt_sql, $this->root_db ) );
2409                   
2410                    if ( $check_vipshirt_result < 1 ) $this->do_exit ( "Leider hat dieser Charakter kein normales VIP-Hemd und du kannst deswegen keinen Code Generieren, da die Vorraussetzung nicht erfüllt ist." );
2411                   
2412                    $gift_code = $this->generate_gift_code ( 200029, 1, 1, '', $t_character [0] );
2413                    if ( ! $gift_code ) $code = "<br><br>Leider ist ein Fehler beim Generieren des Codes Aufgetreten, bitte DarkMan eine PM Schreiben!";
2414                    else {
2415                        $subject = "Du hast einen LoL-Code erhalten...";
2416                        $message = "Hallo {$uname},
2417                        Du hast einen LoL-Code erhalten, weil du ihn gegen {$this->point_config['req']['vipshirt_p']} LoLCoPs eingetauscht hast und kannst diesen InGame für ein Item Einlösen.
2418                        Suche nach dem CodeBot, dieser steht in jeder Stadt vor oder im Auktionshaus!
2419                       
2420                        Dein persönlicher LoL-Code lautet:
2421                        {$gift_code}
2422                       
2423                        Achtung: Dieser Code ist an deinen Account gebunden, du kannst ihn 1 mal für den Charakter <b>{$t_character[1]}</b> dieses Accounts Einlösen!
2424                       
2425                        MFG
2426                       
2427                        Dein LandOfLegends Team";
2428                        $pm = $this->phpbb_send_pm ( $user_id, $subject, $message );
2429                        $code = "<br><br>Dein Code für das Item Lautet: {$gift_code}, diesen kannst du InGame beim Code-Bot Einlösen.<br>Diese Informationen wurden dir auch nochmal per PM gesendet!<br>Achtung: Dieser Code ist an deinen Account gebunden, du kannst ihn 1 mal für den Charakter <b>{$t_character[1]}</b> dieses Accounts Einlösen!";
2430                        $this->community_points_add_rem ( $uname, 'vipshirt_p', - $this->point_config ['req'] ['vipshirt_p'] );
2431                    }
2432                }
2433                else
2434                    $code = "Es ist ein Fehler beim Abfragen der ID des Forumbenutzers aufgetreten.";
2435                $this->do_exit ( $code );
2436            }
2437           
2438            $chars_select_code = $this->get_account_chars ( $uname, $this->root_db, false, '', false );
2439           
2440            $code = "Möchtest du wirklich {$this->point_config['req']['vipshirt_p']} Punkte gegen ein premium Vip-Hemd eintauschen?<br>Dann wähle jetzt deinen Charakter aus, für den du das premium VIP-Hemd haben möchtest!<br>
2441            <form onsubmit=\"ajaxUpload(this,'portal.php?mod=points&action=pay_for&pay_for=vipshirt_p&ajax=true&ajax_f=true','points_content2','<center>Wird ausgeführt...</center>','<center>Javascript:Fehler?</center>'); return false;\">
2442            <table>
2443            <tr><td colspan=\"2\"><select name=\"char\">{$chars_select_code}</select></td></tr>
2444            <tr><td><input type=\"hidden\" name=\"lol_form_salt\" value=\"{$this->gen_lol_form_salt()}\" /><input type=\"submit\" value=\"Ja\" /></td><td><input type=\"button\" value=\"Nein\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_menu', 'get');return false;\" /></td></tr></table>
2445            </form><br><div id=\"points_content2\"></div>";
2446        }
2447       
2448        if ( $pay_for == 'lts' ) {
2449            if ( $get [0] < $this->point_config ['req'] ['lts'] ) return "Leider nicht genug Punkte!";
2450            if ( $ajax ) {
2451                $set_lts_sql = "INSERT IGNORE INTO `lol_points_VLTS` VALUES ('{$get[1]}')";
2452                $lts_query = $this->query ( $set_lts_sql, $this->forum_db );
2453                $this->community_points_add_rem ( $uname, 'lts', - $this->point_config ['req'] ['lts'] );
2454                return "Der erweiterte Löschschutz wurde erfolgreich gesetzt!";
2455            }
2456            $code = "Möchtest du wirklich {$this->point_config['req']['lts']} Punkte gegen den erweiterten Löschschutz eintauschen?<br>
2457            <table><tr><td><input type=\"button\" value=\"Ja\" onclick=\"this.disabled=true;get_content('points_content','portal.php?mod=points&action=pay_for&pay_for=lts&ajax=true&ajax_f=true', 'get');return false;\" /></td><td><input type=\"button\" value=\"Nein\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_menu', 'get');return false;\" /></td></tr></table>";
2458        }
2459        if ( $pay_for == 'rfchange' ) {
2460            if ( $get [0] < $this->point_config ['req'] ['rfchange'] && $this->point_config ['other'] [6] == 0 ) return "Leider nicht genug Punkte!";
2461            $submit = $this->check_post_data ( $data, 'submit' );
2462            if ( $submit ) {
2463                $c = $this->check_post_data ( $data, 'confirmed', false, 0 );
2464                $char_data = $char;
2465                $name = '';
2466                $guid = 0;
2467                $oldrace = 0;
2468                $newrace = 0;
2469                $class = 0;
2470                if ( $char_data && ! $c && $c != 1 ) {
2471                    $temp_data = explode ( '||', $char_data );
2472                    $name = ucfirst ( $temp_data [1] );
2473                    $guid = $temp_data [0];
2474                    $get_other_data_sql = "SELECT `level`,`race`,`class` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`characters` WHERE `guid` = '{$guid}' AND `name` = '{$name}'";
2475                    $get_other_data_query = $this->query ( $get_other_data_sql, $this->root_db );
2476                    $get_other_data = $this->fetch_row ( $get_other_data_query );
2477                    if ( $this->point_config ['other'] [6] != 0 && $get_other_data [0] <= 10 ) return "Leider ist der Charakter nicht über Level 10 und du kannst deshalb nicht Wechseln!";
2478                    $oldrace = $get_other_data [1];
2479                    $class = $get_other_data [2];
2480                    $newrace = $this->check_post_data ( $data, 'newrace', false, 0 );
2481                    switch ( $this->point_config ['other'] [6] )
2482                    {
2483                        case 1:
2484                        case 2:
2485                        case 12:
2486                            if ( ( $this->isAlliance ( $oldrace ) && $this->isAlliance ( $newrace ) ) || ( ! $this->isAlliance ( $oldrace ) && ! $this->isAlliance ( $newrace ) ) ) {
2487                                if ( $get [0] < $this->point_config ['req'] ['rfchange'] ) return "Leider nicht genug Punkte!";
2488                            }
2489                            break;
2490                    }
2491                    switch ( $this->point_config ['other'] [6] )
2492                    {
2493                        case 1:
2494                            if ( $this->isAlliance ( $oldrace ) && ! $this->isAlliance ( $newrace ) ) {
2495                                if ( $get [0] < $this->point_config ['req'] ['rfchange'] ) return "Leider nicht genug Punkte!";
2496                            }
2497                            break;
2498                        case 2:
2499                            if ( ! $this->isAlliance ( $oldrace ) && $this->isAlliance ( $newrace ) ) {
2500                                if ( $get [0] < $this->point_config ['req'] ['rfchange'] ) return "Leider nicht genug Punkte!";
2501                            }
2502                            break;
2503                    }
2504                    $code = "<form onsubmit=\"ajaxUpload(this,'portal.php?mod=points&action=pay_for&pay_for=rfchange&ajax=true','faction_changer_content2','<center>Wird Abgerufen...</center>','<center>Javascript:Fehler?</center>'); return false;\">
2505                    <table><tr><td>Möchtest du deine Fraktion für den Charakter <b>{$name}</b> wirklich von \"<b>{$this->def['character_race'][$oldrace][0]}</b>\" auf \"<b>{$this->def['character_race'][$newrace][0]}</b>\" Wechseln?</td></tr>
2506                    <tr><td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Ja\" /> <input type=\"button\" value=\"Nein\" /></td></tr></table>
2507                    <input type=\"hidden\" name=\"name\" value=\"{$name}\" />
2508                    <input type=\"hidden\" name=\"guid\" value=\"{$guid}\" />
2509                    <input type=\"hidden\" name=\"oldrace\" value=\"{$oldrace}\" />
2510                    <input type=\"hidden\" name=\"class\" value=\"{$class}\" />
2511                    <input type=\"hidden\" name=\"newrace\" value=\"{$newrace}\" />
2512                    <input type=\"hidden\" name=\"confirmed\" value=\"1\" />
2513                    <input type=\"hidden\" name=\"lol_form_salt\" value=\"{$lol_form_salt}\" />
2514                    </form>";
2515                    return $code;
2516                }
2517                if ( $c && $c == 1 ) {
2518                    if ( $get [0] < $this->point_config ['req'] ['rfchange'] && $this->point_config ['other'] [6] == 0 ) return 'Zu wenig Punkte!';
2519                    if ( $this->check_lol_form_salt ( $lol_form_salt ) ) $deleted = $this->del_lol_form_salt ( $lol_form_salt );
2520                    else return "Fehler: Du hast dieses Formular schon abgesendet!";
2521                    $name = $this->check_post_data ( $data, 'name' );
2522                    $guid = $this->check_post_data ( $data, 'guid', false, 0 );
2523                    $oldrace = $this->check_post_data ( $data, 'oldrace', false, 0 );
2524                    $newrace = $this->check_post_data ( $data, 'newrace', false, 0 );
2525                    $class = $this->check_post_data ( $data, 'class', false, 0 );
2526                    $code = $this->faction_changer ( $name, $newrace, $oldrace, $class, $guid );
2527                    $campaign_points = - $this->point_config ['req'] ['rfchange'];
2528                    $campaign_txt = '';
2529                    if ( $code [0] === true ) {
2530                        switch ( $this->point_config ['other'] [6] )
2531                        {
2532                            case 1:
2533                                if ( ! $this->isAlliance ( $oldrace ) && $this->isAlliance ( $newrace ) ) {
2534                                    $campaign_points = 0;
2535                                    $campaign_txt = " Aktion für einen kostenlosen Transfer";
2536                                }
2537                                break;
2538                            case 2:
2539                                if ( $this->isAlliance ( $oldrace ) && ! $this->isAlliance ( $newrace ) ) {
2540                                    $campaign_points = 0;
2541                                    $campaign_txt = " Aktion für einen kostenlosen Transfer";
2542                                }
2543                                break;
2544                            case 12:
2545                                if ( ( $this->isAlliance ( $oldrace ) && ! $this->isAlliance ( $newrace ) ) || ( ! $this->isAlliance ( $oldrace ) && $this->isAlliance ( $newrace ) ) ) {
2546                                    $campaign_points = 0;
2547                                    $campaign_txt = " Aktion für einen kostenlosen Transfer";
2548                                }
2549                                break;
2550                        }
2551                        $this->community_points_add_rem ( $uname, 'rfchange', $campaign_points, 'SYSTEM', "{$name} ({$guid}) von {$this->def['character_race'][$oldrace][0]} auf {$this->def['character_race'][$newrace][0]} eingetauscht.{$campaign_txt}" );
2552                    }
2553                    return $code [1];
2554                }
2555            }
2556            $select_code = $this->get_account_chars ( $user->data ['username_clean'] );
2557
2558            $code = "<form onsubmit=\"ajaxUpload(this,'portal.php?mod=points&action=pay_for&pay_for=rfchange&ajax=true&submit=true','faction_changer_content','<center>Wird Abgerufen...</center>','<center>Javascript:Fehler?</center>'); return false;\">
2559            <table><tr><td>Charakterauswahl:</td><td><select name=\"char\">{$select_code}</select></td></tr>
2560            <tr><td>Neue Rasse:</td><td><select name=\"newrace\">
2561            <option value=\"1\">Mensch</option>
2562            <option value=\"2\">Orc</option>
2563            <option value=\"3\">Zwerg</option>
2564            <option value=\"4\">Nachtelf</option>
2565            <option value=\"5\">Untoter</option>
2566            <option value=\"6\">Taure</option>
2567            <option value=\"7\">Gnom</option>
2568            <option value=\"8\">Troll</option>
2569            <option value=\"10\">Blutelf</option>
2570            <option value=\"11\">Draenei</option></select></td></tr>
2571            <tr><td colspan=\"2\" align=\"center\"><input type=\"hidden\" name=\"lol_form_salt\" value=\"{$this->gen_lol_form_salt()}\" /><input type=\"submit\" name=\"submit\" value=\"Fraktion Wechseln\" /></td></tr></table>
2572            </form><br><div id=\"faction_changer_content\"></div><br><div id=\"faction_changer_content2\"></div>";
2573        }
2574        if ( $pay_for == 'uexchange' ) {
2575            $submit = $this->check_post_data ( $data, 'submitted' );
2576            if ( $submit ) return $this->upperdeck_achieve ( $data, true );
2577            $code = "<form onsubmit=\"ajaxUpload(this,'portal.php?mod=points&action=pay_for&pay_for=uexchange&ajax=true&submit=true','exchange_show','<center>Wird Ausgeführt...</center>','<center>Javascript:Fehler?</center>'); return false;\">
2578            <table><tr><td>Möchtest du nun alle Legendären Code-Sammelkarten gegen LoLCoP's Eintauschen?</td></tr>
2579            <tr><td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Eintauschen\" /><input type=\"hidden\" name=\"submitted\" value=\"1\" /></td></tr></table>
2580            </form><br><div id=\"exchange_show\"></div>";
2581        }
2582        if ( $pay_for == 'nchange' ) {
2583            if ( $get [0] < $this->point_config ['req'] ['nchange'] ) return "Leider nicht genug Punkte!";
2584            $submit = $this->check_post_data ( $data, 'submit' );
2585            if ( $submit ) {
2586                $c = $this->check_post_data ( $data, 'confirmed', false, 0 );
2587                $char_data = $char;
2588                $name = '';
2589                $guid = 0;
2590                if ( $char_data && ! $c && $c != 1 ) {
2591                    $temp_data = explode ( '||', $char_data );
2592                    $name = ucfirst ( $temp_data [1] );
2593                    $guid = $temp_data [0];
2594                    $check_rename_sql = "SELECT `at_login` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`characters` WHERE `guid`='{$guid}' AND `name` = '{$name}'";
2595                    $check_rename_query = $this->query ( $check_rename_sql, $this->root_db );
2596                    if ( $this->result ( $check_rename_query ) == 1 ) return 'Fehler: Charakterumbennenung ist schon für den nächsten Login aktiv.<br>Achtung! WoW vorher einmal komplett Beenden!';
2597                   
2598                    $code = "<form onsubmit=\"ajaxUpload(this,'portal.php?mod=points&action=pay_for&pay_for=nchange&ajax=true','nchange_status2','<center>Wird Abgerufen...</center>','<center>Javascript:Fehler?</center>'); return false;\">
2599                    <table><tr><td>Möchtest du deinen Charakter <b>{$name}</b> wirklich Umbenennen?</td></tr>
2600                    <tr><td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Ja\" /> <input type=\"button\" value=\"Nein\" /></td></tr></table>
2601                    <input type=\"hidden\" name=\"name\" value=\"{$name}\" />
2602                    <input type=\"hidden\" name=\"guid\" value=\"{$guid}\" />
2603                    <input type=\"hidden\" name=\"confirmed\" value=\"1\" />
2604                    <input type=\"hidden\" name=\"lol_form_salt\" value=\"{$lol_form_salt}\" />
2605                    </form>";
2606                    return $code;
2607                }
2608                if ( $c && $c == 1 ) {
2609                    if ( $get [0] < $this->point_config ['req'] ['nchange'] ) return "Leider nicht genug Punkte!";
2610                    if ( $this->check_lol_form_salt ( $lol_form_salt ) ) $deleted = $this->del_lol_form_salt ( $lol_form_salt );
2611                    else return "Fehler: Du hast dieses Formular schon abgesendet!";
2612                    $name = $this->check_post_data ( $data, 'name' );
2613                    $guid = $this->check_post_data ( $data, 'guid', false, 0 );
2614                    if ( ! empty ( $name ) || $guid == 0 ) $nupdate = $this->query ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`characters` SET `at_login`=1 WHERE `guid`='{$guid}' AND `name` = '{$name}'", $this->root_db );
2615                    else $nupdate = false;
2616                    if ( $nupdate ) {
2617                        $this->community_points_add_rem ( $uname, 'nchange', - $this->point_config ['req'] ['nchange'], 'SYSTEM', "{$name} ({$guid}) eingetauscht" );
2618                        $code = "Charakterumbennenung beim Nächsten Login erfolgreich angelegt.<br>Achtung! WoW vorher einmal komplett Beenden!";
2619                    }
2620                    else
2621                        $code = "Fehler beim Setzen der Charakterumbenennung!";
2622                    return $code;
2623                }
2624            }
2625            $select_code = $this->get_account_chars ( $user->data ['username_clean'] );
2626            $code = "<form onsubmit=\"ajaxUpload(this,'portal.php?mod=points&action=pay_for&pay_for=nchange&ajax=true&submit=true','nchange_status','<center>Wird Abgerufen...</center>','<center>Javascript:Fehler?</center>'); return false;\">
2627            <table><tr><td>Charakterauswahl:</td><td><select name=\"char\">{$select_code}</select></td></tr>
2628            <tr><td colspan=\"2\" align=\"center\"><input type=\"hidden\" name=\"lol_form_salt\" value=\"{$this->gen_lol_form_salt()}\" /><input type=\"submit\" name=\"submit\" value=\"Umbennenung Einlösen\" /></td></tr></table>
2629            </form><br><div id=\"nchange_status\"></div><br><div id=\"nchange_status2\"></div>";
2630        }
2631       
2632        if ( $pay_for == 'timebonus' ) {
2633            if ( $get [0] < $this->point_config ['req'] ['timebonus'] ) return "Leider nicht genug Punkte!";
2634            $submit = $this->check_post_data ( $data, 'submit' );
2635           
2636            $check_timeupdate = "SELECT `x_minutes` FROM `lol_points_upper_timeredu` WHERE `id` = '{$get[1]}'";
2637            $check_timeupdate_query = $this->query ( $check_timeupdate, $this->forum_db );
2638            $timeupdate_r = $this->result ( $check_timeupdate_query );
2639            $timeupdate_checked = $this->num_rows ( $check_timeupdate_query );
2640           
2641            if ( $submit ) {
2642                $c = $this->check_post_data ( $data, 'confirmed', false, 0 );
2643               
2644                if ( $c && $c == 1 ) {
2645                    if ( $get [0] < $this->point_config ['req'] ['timebonus'] ) return "Leider nicht genug Punkte!";
2646                    if ( $this->check_lol_form_salt ( $lol_form_salt ) ) $deleted = $this->del_lol_form_salt ( $lol_form_salt );
2647                    else return "Fehler: Du hast dieses Formular schon abgesendet!";
2648                   
2649                    if ( $timeupdate_checked ) $timeupdate = $this->query ( "UPDATE `lol_points_upper_timeredu` SET `x_minutes` = (x_minutes+168) WHERE `id` = '{$get[1]}'", $this->forum_db );
2650                    else $timeupdate = $this->query ( "INSERT INTO `lol_points_upper_timeredu` VALUES ({$get[1]},168)", $this->forum_db );
2651                    if ( $this->affected_rows ( $this->forum_db ) > 0 ) {
2652                        $this->community_points_add_rem ( $uname, 'timebonus', - $this->point_config ['req'] ['timebonus'], 'SYSTEM', '' );
2653                        $code = "Das Aussetzen des Upperdeck-Generator cooldowns wurde erfolgreich gesetzt.";
2654                    }
2655                    else
2656                        $code = "Fehler beim Setzen der Aussetzung des Upperdeck-Generator Cooldowns!";
2657                    return $code;
2658                }
2659            }
2660           
2661            $bonus = ( $timeupdate_r > 0 ) ? $timeupdate_r : 0;
2662            $code = "<form onsubmit=\"ajaxUpload(this,'portal.php?mod=points&action=pay_for&pay_for=timebonus&ajax=true','timebonus_status','<center>Wird Ausgeführt...</center>','<center>Javascript:Fehler?</center>'); return false;\">
2663                    <table><tr><td>Möchtest du wirklich {$this->point_config ['req'] ['timebonus']} Punkte gegen eine Upperdeck-Generator Cooldownaussetzung Eintauschen?<br>Das aktuelle Aussetzungsguthaben beträgt: {$bonus} Stunden ( 168 Stunden Cooldown pro normaler Generierung )</td></tr>
2664                    <tr><td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Ja\" /> <input type=\"button\" value=\"Nein\" /></td></tr></table>
2665                    <input type=\"hidden\" name=\"confirmed\" value=\"1\" /><input type=\"hidden\" name=\"lol_form_salt\" value=\"{$this->gen_lol_form_salt()}\" />
2666                    </form><br><div id=\"timebonus_status\"></div>";
2667        }
2668       
2669        if ( in_array($pay_for, array('lolbag_s','lolbag_g')) ) {
2670            if ( $get [0] < $this->point_config ['req'] [$pay_for] ) return "Leider nicht genug Punkte!";
2671            if ( $ajax ) {
2672                if ( $get [0] < $this->point_config ['req'] [$pay_for] ) $this->do_exit ( "Leider nicht genug Punkte!" );
2673                if ( $this->check_lol_form_salt ( $lol_form_salt ) ) $deleted = $this->del_lol_form_salt ( $lol_form_salt );
2674                else return "Fehler: Du hast dieses Formular schon abgesendet!";
2675                $user_id = $this->get_forum_id ( $uname );
2676                if ( $user_id ) {
2677                    $t_character = explode ( '||', $char );
2678       
2679                    $check_lolbag_sql = "SELECT COUNT(`item`) FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_inventory` WHERE `item` IN (SELECT `guid` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`item_instance` WHERE `itemEntry` = 200030 OR `itemEntry` = 200031) AND `guid` = '{$t_character[0]}'";
2680                    $check_lolbag_result = $this->result ( $this->query ( $check_lolbag_sql, $this->root_db ) );
2681       
2682                    if ( $check_lolbag_result > 0 ) $this->do_exit ( "Leider hat dieser Charakter schon eine LoL-Tasche und kann deshalb keine weitere Bekommen." );
2683       
2684                    $gift_code = $this->generate_gift_code ( ($pay_for == 'lolbag_s') ? 200030 : 200031, 1, 1, '', $t_character [0] );
2685                    if ( ! $gift_code ) $code = "<br><br>Leider ist ein Fehler beim Generieren des Codes Aufgetreten, bitte DarkMan eine PM Schreiben!";
2686                    else {
2687                        $subject = "Du hast einen LoL-Code erhalten...";
2688                        $message = "Hallo {$uname},
2689                        Du hast einen LoL-Code erhalten, weil du ihn gegen {$this->point_config['req'][$pay_for]} LoLCoPs eingetauscht hast und kannst diesen InGame für ein Item Einlösen.
2690                        Suche nach dem CodeBot, dieser steht in jeder Stadt vor oder im Auktionshaus!
2691       
2692                        Dein persönlicher LoL-Code lautet:
2693                        {$gift_code}
2694       
2695                        Achtung: Dieser Code ist an deinen Account gebunden, du kannst ihn 1 mal für den Charakter <b>{$t_character[1]}</b> dieses Accounts Einlösen!
2696       
2697                        MFG
2698       
2699                        Dein LandOfLegends Team";
2700                        $pm = $this->phpbb_send_pm ( $user_id, $subject, $message );
2701                        $code = "<br><br>Dein Code für das Item Lautet: {$gift_code}, diesen kannst du InGame beim Code-Bot Einlösen.<br>Diese Informationen wurden dir auch nochmal per PM gesendet!<br>Achtung: Dieser Code ist an deinen Account gebunden, du kannst ihn 1 mal für den Charakter <b>{$t_character[1]}</b> dieses Accounts Einlösen!";
2702                        $this->community_points_add_rem ( $uname, $pay_for, - $this->point_config ['req'] [$pay_for] );
2703                        }
2704                    }
2705                    else
2706                        $code = "Es ist ein Fehler beim Abfragen der ID des Forumbenutzers aufgetreten.";
2707                        $this->do_exit ( $code );
2708                    }
2709       
2710                    $chars_select_code = $this->get_account_chars ( $uname, $this->root_db, false, '', false );
2711       
2712                    $bagtext = ($pay_for == 'lolbag_s') ? 'kleine' : 'große';
2713                    $code = "Möchtest du wirklich {$this->point_config['req'][$pay_for]} Punkte gegen eine {$bagtext} LoL-Tasche eintauschen?<br>Dann wähle jetzt deinen Charakter aus, für den du das premium VIP-Hemd haben möchtest!<br>
2714                    <form onsubmit=\"ajaxUpload(this,'portal.php?mod=points&action=pay_for&pay_for={$pay_for}&ajax=true&ajax_f=true','points_content2','<center>Wird ausgeführt...</center>','<center>Javascript:Fehler?</center>'); return false;\">
2715                    <table>
2716                    <tr><td colspan=\"2\"><select name=\"char\">{$chars_select_code}</select></td></tr>
2717                    <tr><td><input type=\"hidden\" name=\"lol_form_salt\" value=\"{$this->gen_lol_form_salt()}\" /><input type=\"submit\" value=\"Ja\" /></td><td><input type=\"button\" value=\"Nein\" onclick=\"get_content('points_content','portal.php?mod=points&action=pay_menu', 'get');return false;\" /></td></tr></table>
2718                    </form><br><div id=\"points_content2\"></div>";
2719        }
2720       
2721        return $code;
2722    }
2723
2724    public function community_points_forum_per_day ()
2725    {
2726        global $user;
2727        $get_points_day_sql = "SELECT `date` FROM `lol_points_log` WHERE `user` = (SELECT `id` FROM `lol_points` WHERE `name` = '{$user->data['username_clean']}') AND `reason` = 5";
2728        $get_points_day = $this->query ( $get_points_day_sql, $this->forum_db );
2729        $points_day = 0;
2730        while ( $time = $this->fetch_row ( $get_points_day ) )
2731            if ( date ( "d.m.Y", time ( ) ) == date ( "d.m.Y", $time [0] ) ) $points_day ++;
2732        return $points_day;
2733    }
2734
2735    protected function community_points_delete_old_log ( $username, $type = 'old' )
2736    {
2737        if ( $type == 'old' ) $sql = "SELECT `id`,`date` FROM `lol_points_log` WHERE `reason` LIKE '%Forenteilnahme%' AND `user` = '{$username}'";
2738        elseif ( $type == 'all' ) $sql = "SELECT `id`,`date` FROM `lol_points_log` WHERE `user` = '{$username}'";
2739        if ( $sql ) {
2740            $entries = array ();
2741            $get_entrys = $this->query ( $sql, $this->forum_db );
2742            while ( $entry = $this->fetch_row ( $get_entrys ) )
2743                if ( date ( "d.m.Y", time ( ) ) !== date ( "d.m.Y", $entry [1] ) ) $entries [ ] = $entry [0];
2744            $deletes = "";
2745            $tot_deletes = count ( $entries ) - 1;
2746            $delete_count = 1;
2747            foreach ( $entries as $delete ) {
2748                $deletes .= $delete;
2749                if ( $delete_count < $tot_deletes ) $deletes .= ", ";
2750            }
2751            $query = $this->query ( "DELETE FROM `lol_points_log` WHERE `id` IN ({$deletes})", $this->forum_db );
2752        }
2753    }
2754
2755    protected function community_points_log_txt ( $points, $type )
2756    {
2757        /*
2758         * 1 = Punkte für eine Spende bekommen
2759         * 2 = VIP, weil die in der Konfig eingestellten Punkte Erreicht
2760         * 3 = Punkte für einen Chartransfer eingelöst
2761         * 4 = Punkte für einen Avatar Eingelöst
2762         * 5 = Punkte für die Forenteilname bekommen
2763         * 6 = Punkte für ein Event bekommen
2764         * 7 = Punkte für den Einsatz für die Community/Server
2765         * 8 = Punkte von einem GM bekommen/abgezogen
2766         * 9 = Neue Registrierung
2767         * 10 = Bestandsspender Übernahme
2768         * 11 = Eigene Begründung
2769         * 12 = Characterwiederherstellung
2770         * 13 = VIP-Hemd
2771         * 14 = Werbereduzierung
2772         * 15 = Langzeitlöschschutz
2773         * 16 = Rassen-/Fraktionswechsel
2774         * 17 = Upperdeck Eintausch
2775         * 18 = Charakterumbenennung
2776         * 19 = Upperdeck Zeitbonus
2777         * 20 = Punkte fürs Voten
2778         * 21 = VIP-Hemd Premium
2779         * 22 = Kleine LoL-Tasche
2780         * 23 = Große LoL-Tasche
2781         */
2782        $plural = ( $points > 1 || $points < - 1 || $points == 0 ) ? 'e' : '';
2783        $tpoints = str_replace ( '-', '', $points );
2784        switch ( $type )
2785        {
2786            case 1:
2787                $txt = "Du hast {$points} Punkt{$plural} für eine Server Spende bekommen";
2788                break;
2789            case 2:
2790                $txt = "Du hast {$points} Punkt{$plural} erreicht und bekommst den VIP-Status";
2791                break;
2792            case 3:
2793                $txt = "Du hast {$tpoints} Punkt{$plural} gegen einen Charaktertransfer eingetauscht";
2794                break;
2795            case 4:
2796                $txt = "Du hast {$tpoints} Punkte gegen einen Avatar eingetauscht";
2797                break;
2798            case 5:
2799                $txt = "{$points} Punkt{$plural} für die Forenteilnahme";
2800                break;
2801            case 6:
2802                $txt = "Für eine Platzierung oder Teilnahme bei einem Event {$points} Punkt{$plural}";
2803                break;
2804            case 7:
2805                $txt = "Für den besonderen Einsatz für die Community {$points} Punkt{$plural}";
2806                break;
2807            case 8:
2808                $txt_ar = ( $points < 0 ) ? "entfernt" : "hinzugefügt";
2809                $txt = "Dir wurden von einem GM {$tpoints} Punkt{$plural} {$txt_ar}";
2810                break;
2811            case 9:
2812                $txt = "{$points} Punkt{$plural} für die Registrierung bei LandOfLegends";
2813                break;
2814            case 10:
2815                $txt = "Du hast schon mindestens einmal gespendet und die {$points} Punkt{$plural} wurden dir gutgeschrieben";
2816                break;
2817            case 12:
2818                $txt = "Du hast {$tpoints} Punkt{$plural} gegen eine Charakterwiederherstellung eingetauscht";
2819                break;
2820            case 13:
2821                $txt = "Du hast {$tpoints} Punkt{$plural} gegen ein weiteres VIP-Hemd eingetauscht";
2822                break;
2823            case 14:
2824                $txt = "Du hast {$tpoints} Punkt{$plural} gegen eine Werbereduzierung eingetauscht";
2825                break;
2826            case 15:
2827                $txt = "Du hast {$tpoints} Punkt{$plural} gegen einen Langzeitlöschschutz ( +12 Monate ) eingetauscht";
2828                break;
2829            case 16:
2830                $txt = "Du hast {$tpoints} Punkt{$plural} gegen einen Rassen-/Fraktionswechsel für den Charakter ";
2831                break;
2832            case 17:
2833                $txt = "Du hast eine legendäre Sammelkarte eingetauscht und bekommst {$tpoints} Punkt{$plural}";
2834                break;
2835            case 18:
2836                $txt = "Du hast {$tpoints} Punkt{$plural} gegen eine Charakterumbenennung für den Charakter ";
2837                break;
2838            case 19:
2839                $txt = "Du hast {$tpoints} Punkt{$plural} gegen eine Upperdeck-Generator Cooldownaussetzung eingetauscht";
2840                break;
2841            case 20:
2842                $txt = "Du hast {$tpoints} Punkt{$plural} für das Voten am heutigen Tag bekommen.";
2843                break;
2844            case 21:
2845                $txt = "Du hast {$tpoints} Punkt{$plural} gegen ein premium VIP-Hemd eingetauscht.";
2846                break;
2847            case 22:
2848                $txt = "Du hast {$tpoints} Punkt{$plural} gegen eine kleine LoL-Tasche eingetauscht.";
2849                break;
2850            case 23:
2851                $txt = "Du hast {$tpoints} Punkt{$plural} gegen eine große LoL-Tasche eingetauscht.";
2852                break;
2853            default:
2854                $txt = "";
2855                break;
2856        }
2857        return $txt;
2858    }
2859
2860    /**
2861     * @param $func
2862     * @param $error_num
2863     * @param $desc
2864     * @param $name
2865     * @return unknown_type
2866     */
2867    protected function webspace_log ( $func, $error_num = '', $desc = '', $status = '', $name = '' )
2868    {
2869        if ( empty ( $func ) ) return false;
2870        $date = time ( );
2871        $name = strtolower ( $name );
2872        $error = $this->quote_smart ( $error, $this->forum_db );
2873        $ele = $desc;
2874        if ( is_array ( $desc ) ) {
2875            $ele = "";
2876            foreach ( $desc as $elem )
2877                $ele = $elem . '\n';
2878        }
2879        $desc = $this->quote_smart ( $ele, $this->forum_db );
2880        $sql = "INSERT INTO `lol_webspace_log` VALUES ('', {$date},'{$func}', '{$error_num}','{$desc}','{$status}','{$name}')";
2881        $webspace_query = $this->query ( $sql, $this->forum_db );
2882        return true;
2883    }
2884
2885    /**
2886     * @param $force
2887     * @param $p
2888     * @param $uname
2889     * @param $na
2890     * @param $idd
2891     * @param $ext
2892     * @return unknown_type
2893     */
2894    protected function gallery_delete ( $force = false, $p, $uname, $na, $idd, $ext )
2895    {
2896        global $user, $phpbb_root_path;
2897        require_once $phpbb_root_path . 'config.php';
2898        if ( $force || $p == $uname ) {
2899            $sql [ ] = "DELETE FROM `lol_gallery_main` WHERE `id` = $idd";
2900            $sql [ ] = "DELETE FROM `lol_gallery_ratings` WHERE `id` = $idd";
2901            $sql [ ] = "DELETE FROM `lol_gallery_comments` WHERE `from` = $idd";
2902            foreach ( $sql as $query )
2903                $gallery_del_query = $this->query ( $query, $this->forum_db );
2904            $unlink [ ] = "{$this->gallery_upload_dir}/norm/{$na}.{$ext}";
2905            $unlink [ ] = "{$this->gallery_upload_dir}/full/{$na}.{$ext}";
2906            $unlink [ ] = "{$this->gallery_upload_dir}/thumb/{$na}.{$ext}";
2907            foreach ( $unlink as $dele )
2908                @unlink ( $dele );
2909            if ( $force ) {
2910                $to = $this->get_forum_id ( $p );
2911                if ( $to > 0 ) {
2912                    $subject = "Dein Bild <strong>{$na}</strong> wurde gelöscht";
2913                    $message = "Hallo <span style=\"font-weight: bold\">{$p}</span>,<br />Dein Bild <strong>{$na}</strong> wurde von einem Gallery Admin gelöscht, da es gegen die Regeln verstoßen hat oder es andere Probleme mit deinem Bild gab.<br><br>MFG<br><br>Dein Land of Legends Team";
2914                    $this->phpbb_send_pm ( $to, $subject, $message );
2915                }
2916                else
2917                    return "Benutzer Forum id war leer";
2918            }
2919            return "Bild wurde erfolgreich gelöscht!<br><br><a href=\"portal.php?mod=gallery\">Zurück zur Gallery</a>";
2920        }
2921        return "Du hast keine berechtigung ein Bild zu löschen!<br><br><a href=\"portal.php?mod=gallery\">Zurück zur Gallery</a>";
2922    }
2923
2924    protected function forum_set_vip_status ( $uname, $type = '' )
2925    {
2926        if ( ! $uname || empty ( $uname ) ) return false;
2927        $uname = strtolower ( $uname );
2928        switch ( $type )
2929        {
2930            case 'add':
2931                $check = $this->fetch_row ( $this->query ( "SELECT `group_id` FROM `phpbb_users` WHERE `username_clean` = '{$uname}'", $this->forum_db ) );
2932                if ( $check && ! empty ( $check [0] ) && $check [0] !== 12 ) {
2933                    $query1 = $this->query ( "UPDATE `phpbb_users` SET `group_id` = '12',`user_rank` = '13',`user_colour` = 'FF6600' WHERE `username_clean` = '{$uname}'", $this->forum_db );
2934                    if ( ! $query1 ) {
2935                        $this->forum_set_vip_status ( $uname, '' );
2936                        return false;
2937                    }
2938                    $query2 = $this->query ( "INSERT IGNORE INTO `phpbb_user_group` VALUES('12',(SELECT `user_id` FROM `phpbb_users` WHERE `username_clean` = '{$uname}'),'0','0')", $this->forum_db );
2939                    if ( ! $query2 ) {
2940                        $this->forum_set_vip_status ( $uname, '' );
2941                        return false;
2942                    }
2943                }
2944                break;
2945            default:
2946                $query1 = $this->query ( "UPDATE `phpbb_users` SET `group_id` = '2',`user_rank` = '',`user_colour` = '' WHERE `username_clean` = '{$uname}'", $this->forum_db );
2947                if ( ! $query1 ) return false;
2948                $query2 = $this->query ( "DELETE FROM `phpbb_user_group` WHERE `user_id` = (SELECT `user_id` FROM `phpbb_users` WHERE `username_clean` = '{$uname}') AND `group_id` = 12", $this->forum_db );
2949                if ( ! $query2 ) return false;
2950                break;
2951        }
2952        return true;
2953    }
2954
2955    protected function gallery_get_categories ()
2956    {
2957        $cat_holder = array ();
2958        $sub_holder = array ();
2959        $sql = "SELECT * FROM `lol_gallery_categories`";
2960        $query = $this->query ( $sql, $this->donda_db );
2961        while ( $d = $this->fetch_row ( $query ) ) {
2962            if ( $d [1] > 0 ) $sub_holder [$d [1]] = array ( $d [0], $d [2], $d [3] );
2963            else $cat_holder [$d [0]] = array ( $d [0], $d [2], $d [3] );
2964        }
2965        return array ( $cat_holder, $sub_holder );
2966    }
2967
2968    protected function binary_multiples ( $size, $praefix = true, $short = true )
2969    {
2970        if ( $praefix === true ) {
2971            if ( $short === true ) $norm = array ( 'B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' );
2972            else $norm = array ( 'Byte', 'Kilobyte', 'Megabyte', 'Gigabyte', 'Terabyte', 'Petabyte', 'Exabyte', 'Zettabyte', 'Yottabyte' );
2973            $factor = 1000;
2974        }
2975        else {
2976            if ( $short === true ) $norm = array ( 'B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB' );
2977            else $norm = array ( 'Byte', 'Kibibyte', 'Mebibyte', 'Gibibyte', 'Tebibyte', 'Pebibyte', 'Exbibyte', 'Zebibyte', 'Yobibyte' );
2978            $factor = 1024;
2979        }
2980        $count = count ( $norm ) - 1;
2981        $x = 0;
2982        while ( $size >= $factor && $x < $count ) {
2983            $size /= $factor;
2984            $x ++;
2985        }
2986        $size = sprintf ( "%01.2f", $size ) . ' ' . $norm [$x];
2987        return $size;
2988    }
2989
2990    protected function game_backup_check ( $account = '', $char = '', $precision = true, $all = false )
2991    {
2992        global $user;
2993        $account = ( $account ) ? strtolower ( $account ) : strtolower ( $user->data ['username'] );
2994        $account = $this->quote_smart ( $account, $this->root_db );
2995        $char = $this->quote_smart ( $char, $this->root_db );
2996        if ( $account ) {
2997            if ( empty ( $char ) ) return "Leider hast du das Charakterfeld nicht ausgefüllt!";
2998            $account_id = $this->get_account_id_name ( $account );
2999            if ( $precision ) {
3000                $precise [0] = "(`%s` = '{$char}' OR `%s` = '{$char}') AND (`account` = {$account_id} OR `deleteInfos_Account` = {$account_id})";
3001                $precise [1] = $precise [0];
3002            }
3003            else {
3004                $precise [0] = "(`%s` LIKE '%%{$char}%%' OR `%s` LIKE '%%{$char}%%') AND (`account` = {$account_id} OR `deleteInfos_Account` = {$account_id})";
3005                $precise [1] = "(`%s` LIKE '%%{$char}%%' OR `%s` LIKE '%%{$char}%%')";
3006                if ( $all ) $precise [0] = $precise [1];
3007            }
3008            $check_account_first_precision = sprintf ( $precise [0], 'name', 'deleteInfos_Name' );
3009            $check_account_first_sql = "SELECT `name`,`deleteInfos_Name`,`guid` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`characters` WHERE {$check_account_first_precision}";
3010            $check_account_first_query = $this->query ( $check_account_first_sql, $this->root_db );
3011            if ( ! $check_account_first_query && ! $all ) return "Fehler beim Checken deines Accounts";
3012            $check_account_first = $this->fetch_row ( $check_account_first_query );
3013            if ( ! $check_account_first && $all ) $check_account_first [0] = '';
3014            if ( is_array ( $check_account_first ) && ( in_array ( $account, $check_account_first ) || $check_account_first [0] == $char ) ) return "Dieser Charakter braucht nicht wiederhergestellt werden,<br />da er noch in deinem Account existiert!";
3015            else {
3016                $get_backup_tables_sql = "SELECT `backupname` FROM `xtdatabase`.`backups` ORDER BY `backupname` DESC";
3017                $get_backup_tables_query = $this->query ( $get_backup_tables_sql, $this->forum_db );
3018                if ( ! $get_backup_tables_query ) return "Fehler beim Abrufen der Backups...";
3019                $backup_tables = array ();
3020                $backup_data = array ();
3021                while ( $data = $this->fetch_row ( $get_backup_tables_query ) )
3022                    $backup_tables [ ] = $data [0];
3023                foreach ( $backup_tables as $backup_table_name ) {
3024                    $table_exists = $this->table_exists ( $backup_table_name, 'xtdatabase', $this->forum_db );
3025                    if ( $table_exists ) {
3026                        $search_back_precision = sprintf ( $precise [1], 'charname', 'charname' );
3027                        $search_back_sql = "SELECT `charname`,`level`,`gold`,`totaltime`,`guid` as pguid,(SELECT `deleteInfos_Name` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`characters` WHERE `guid` = `pguid`) FROM `xtdatabase`.`{$backup_table_name}` WHERE {$search_back_precision} OR `guid` = '{$check_account_first[2]}' ORDER BY `level` DESC";
3028                        $search_back_query = $this->query ( $search_back_sql, $this->forum_db );
3029                        if ( ! $search_back_query ) return 'Fehler bei der Backupsuche';
3030                        while ( $found = $this->fetch_row ( $search_back_query ) )
3031                            $backup_data [ ] = array ( $backup_table_name, ( ( empty ( $found [0] ) ? $found [5] : $found [0] ) ), $found [1], $found [2], $found [3] );
3032                    }
3033                    else
3034                        $backup_data [ ] = array ( $backup_table_name, '<font color="red">Backup fehlerhaft!</font>' );
3035                }
3036                if ( count ( $backup_data ) == 0 ) return "Leider wurde von diesem Charakter kein Backup gefunden.<br />Somit ist ein Wiederherstellen nicht möglich!";
3037                if ( $all ) {
3038                    $start = "<table cellpaddin=\"3\" cellspacing=\"3\"><tr><td align=\"center\"><b>Backup</b></td><td align=\"center\"><b>Charname</b></td><td align=\"center\"><b>Level</b></td><td align=\"center\"><b>Gold</b></td><td align=\"center\">&nbsp;&nbsp;&nbsp;</td><td align=\"center\"><b>Spielzeit</b></td></tr>";
3039                    $middle = "";
3040                    $end = "</table>";
3041                    foreach ( $backup_data as $backup_found ) {
3042                        $g = floor ( $backup_found [3] / 10000 );
3043                        $backup_found [3] -= $g * 10000;
3044                        $s = floor ( $backup_found [3] / 100 );
3045                        $backup_found [3] -= $s * 100;
3046                        $c = $backup_found [3];
3047                        $money = "0 <img src=\"images/gold.gif\" /> 0 <img src=\"images/silver.gif\" /> 0 <img src=\"images/copper.gif\" /> ";
3048                        if ( $backup_found [3] > 0 ) $money = $g . " <img src=\"images/gold.gif\" /> " . $s . " <img src=\"images/silver.gif\" /> " . $c . " <img src=\"images/copper.gif\" /> ";
3049                        $days = floor ( round ( $backup_found [4] / 3600 ) / 24 );
3050                        $hours = round ( $backup_found [4] / 3600 ) - ( $days * 24 );
3051                        $time = "";
3052                        if ( $days > 0 ) {
3053                            $time .= $days;
3054                            $time .= " Tage ";
3055                        }
3056                        if ( $hours > 0 ) {
3057                            $time .= $hours;
3058                            $time .= " Stunden";
3059                        }
3060                        $middle .= "<tr><td>{$backup_found[0]}</td><td>{$backup_found[1]}</td><td>{$backup_found[2]}</td><td>{$money}</td><td>&nbsp;&nbsp;&nbsp;</td><td>{$time}</td></tr>";
3061                    }
3062                    return $start . $middle . $end;
3063                }
3064                else
3065                    return "<table cellpadding=\"1\" cellspacing=\"2\"><tr><td><b>Backup</b></td><td><b>Charname</b></td></tr><tr><td>{$backup_data[0][0]}</td><td>{$backup_data[0][1]}</td></tr><tr><td colspan=\"2\">Es wurde eine PM an einen Admin mit diesen Informationen gesendet!<br>( Bitte gib uns 48 Stunden Zeit, wir haben auch ein RL ^^ )</td></tr></table>";
3066            }
3067        }
3068        return 'Leider war der Account leer!';
3069    }
3070
3071    protected function generate_gift_code ( $item_id = 200000, $num_uses = 1, $quantity = 1, $account = '', $char_guid = 0, $lvlup = 0, $from = 'SYSTEM' )
3072    {
3073        global $user;
3074        $group = $user->data ['group_id'];
3075        $quantity = ( $quantity == 0 ) ? 1 : $quantity;
3076        if ( empty ( $account ) ) $acc_id = $this->get_account_id_name ( $user->data ['username_clean'] );
3077        else {
3078            $acc_id = $this->get_account_id_name ( $account );
3079            if ( ! $acc_id && is_numeric ( $account ) ) $acc_id = $account;
3080        }
3081        if ( $acc_id ) {
3082            $cleanup_sql = "DELETE FROM `{$this->lol_conf ['db_pve_live_characters']}`.`codes` WHERE `uses` = '0'";
3083            $cleanup = $this->query ( $cleanup_sql, $this->root_db );
3084            $code = gen_rand_string ( 12 );
3085            $check_code_ext_sql = "SELECT `npc_id` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`codes` WHERE `code` = '{$code}'";
3086            $check_code_ext_query = $this->query ( $check_code_ext_sql, $this->root_db );
3087            $check_code_ext = $this->num_rows ( $check_code_ext_query );
3088            $code = ( $check_code_ext > 0 ) ? gen_rand_string ( 12 ) : $code;
3089            if ( $char_guid > 0 && $lvlup > 0 ) $item_id = 0;
3090            $insert_to_db_sql = "INSERT INTO `{$this->lol_conf ['db_pve_live_characters']}`.`codes` VALUES('90001','{$code}','{$num_uses}','{$item_id}','{$acc_id}','{$quantity}','{$char_guid}','{$lvlup}')";
3091            $insert_to_db = $this->query ( $insert_to_db_sql, $this->root_db );
3092            $error = $this->error ( $this->root_db );
3093            if ( $insert_to_db && strlen ( $error [0] ) < 1 ) {
3094                $time = time ( );
3095                $create_log_sql = "INSERT INTO `gift_code_log` VALUES('','{$time}','{$acc_id}','{$code}','{$item_id}','{$quantity}','{$num_uses}','{$char_guid}','{$lvlup}','{$from}')";
3096                $gift_log_query = $this->query ( $create_log_sql, $this->forum_db );
3097                return $code;
3098            }
3099        }
3100        return false;
3101    }
3102
3103    protected function check_post_data ( $data, $var, $dbcon = false, $default = false )
3104    {
3105        return ( isset ( $data [$var] ) && ! empty ( $data [$var] ) ) ? ( ( $dbcon ) ? $this->quote_smart ( $data [$var], $dbcon ) : $data [$var] ) : $default;
3106    }
3107
3108    protected function _mysqldump_table_data ( $database, $table, $file = '', $get = false, $what = false )
3109    {
3110        $getwhat = ( $get && $what ) ? " WHERE `{$get}` = '{$what}'" : "";
3111        $sql = "SELECT * FROM `{$database}`.`{$table}`{$getwhat};";
3112        $result = $this->query ( $sql, $this->root_db );
3113        $fileop = NULL;
3114        if ( $file && ! empty ( $file ) ) $fileop = fopen ( $file, 'a+' );
3115        $created_data = '';
3116        if ( $result ) {
3117            $num_rows = $this->num_rows ( $result );
3118            $num_fields = $this->num_fields ( $result );
3119            if ( $num_rows > 0 ) {
3120                $field_type = array ();
3121                $i = 0;
3122                while ( $i < $num_fields ) {
3123                    $meta = $this->fetch_field ( $result, $i );
3124                    array_push ( $field_type, $meta->type );
3125                    $i ++;
3126                }
3127                $start = "INSERT INTO `{$database}`.`{$table}` VALUES ";
3128                if ( $fileop ) fwrite ( $fileop, $start );
3129                $created_data .= $start;
3130                $index = 0;
3131                while ( $row = $this->fetch_row ( $result ) ) {
3132                    if ( $fileop ) fwrite ( $fileop, "(" );
3133                    else $created_data .= "(";
3134                    for ( $i = 0; $i < $num_fields; $i ++ ) {
3135                        if ( is_null ( $row [$i] ) ) {
3136                            if ( $fileop ) fwrite ( $fileop, "NULL" );
3137                            $created_data .= "NULL";
3138                        }
3139                        else {
3140                            switch ( $field_type [$i] )
3141                            {
3142                                case 'int':
3143                                    if ( $fileop ) fwrite ( $fileop, $row [$i] );
3144                                    $created_data .= $row [$i];
3145                                    break;
3146                                case 'string':
3147                                case 'blob':
3148                                default:
3149                                    $defau = $this->quote_smart ( $row [$i], $this->root_db );
3150                                    if ( $fileop ) fwrite ( $fileop, "'$defau'" );
3151                                    $created_data .= "'{$defau}'";
3152                                    break;
3153                            }
3154                        }
3155                        if ( $i < $num_fields - 1 ) {
3156                            if ( $fileop ) fwrite ( $fileop, "," );
3157                            $created_data .= ",";
3158                        }
3159                    }
3160                    if ( $fileop ) fwrite ( $fileop, ")" );
3161                    $created_data .= ")";
3162                    if ( $index < $num_rows - 1 ) {
3163                        if ( $fileop ) fwrite ( $fileop, "," );
3164                        $created_data .= ",";
3165                    }
3166                    else {
3167                        if ( $fileop ) fwrite ( $fileop, ";" );
3168                        $created_data .= ";";
3169                    }
3170                    if ( $fileop ) fwrite ( $fileop, "\n" );
3171                    $created_data .= "\n";
3172                    $index ++;
3173                }
3174                if ( $fileop ) fwrite ( $fileop, "\n" );
3175                $created_data .= "\n";
3176            }
3177        }
3178        if ( $fileop ) {
3179            fclose ( $fileop );
3180            return true;
3181        }
3182        return $created_data;
3183    }
3184
3185    protected function generate_upperdeck_achieve ( $char = false, $item_id = false, $exchange = false )
3186    {
3187        global $user;
3188        $exchanged = false;
3189        if ( ! $this->root_db ) return 'Server Offline oder keine Datenbankverbindung!';
3190        if ( ! $exchange && ( ! $item_id || ! $char ) ) return 'NO Item ID or Charname';
3191        $char_guid = $this->get_account_chars ( $user->data ['username_clean'], $this->root_db, false, $char, false, true );
3192        switch ( $item_id )
3193        {
3194            case 210013:
3195                $group = 121;
3196                break;
3197            case 210014:
3198                $group = 242;
3199                break;
3200            case 210015:
3201                $group = 484;
3202                break;
3203            default:
3204                $group = false;
3205                break;
3206        }
3207        if ( ! $group && ! $exchange ) return 'no group';
3208        if ( ! $exchange ) {
3209            $get_group_item_data_sql = "SELECT * FROM `upper_deck_items` WHERE `group` = {$group} AND `achieved` <> `max_achieve` AND `activated` = 1";
3210            $get_group_item_data_query = $this->query ( $get_group_item_data_sql, $this->forum_db );
3211            if ( ! $get_group_item_data_query ) return print_r ( $this->error ( $this->forum_db ) );
3212            $random_pick = array ();
3213            $random_pick_new = array ();
3214            while ( $got_group_item_data = $this->fetch_row ( $get_group_item_data_query ) )
3215                $random_pick [$got_group_item_data [0]] = $got_group_item_data;
3216            if ( ! $random_pick || empty ( $random_pick ) || ! is_array ( $random_pick ) ) return "NO RANDOM PICK";
3217            foreach ( $random_pick as $item ) {
3218                $temp = array ();
3219                $temp = array_pad ( $temp, $item [4], $item [0] );
3220                $random_pick_new = array_merge ( $random_pick_new, $temp );
3221                shuffle ( $random_pick_new );
3222            }
3223            if ( ! $random_pick_new || empty ( $random_pick_new ) || ! is_array ( $random_pick_new ) ) return false;
3224            $return = $random_pick_new [mt_rand ( 0, count ( $random_pick_new ) )];
3225            $update_achieved_sql = "UPDATE `upper_deck_items` SET `achieved` = `achieved`+1 WHERE `id` = {$random_pick[$return][0]}";
3226            $update_achieved = $this->query ( $update_achieved_sql, $this->forum_db );
3227            if ( ! $update_achieved ) return "Error on Incrementing Achieved Value in DB";
3228            $date = time ( );
3229            $gen_achieve_log_sql = "INSERT INTO `upper_deck_log` VALUES ('{$date}','{$user->data['username']}','{$char}','{$random_pick[$return][0]}')";
3230            $gen_achieve_log = $this->query ( $gen_achieve_log_sql, $this->forum_db );
3231        }
3232        else {
3233            if ( $item_id == 210015 ) {
3234                $get_exchange_count_sql = "SELECT COUNT(`reason`) FROM `lol_points_log` WHERE `user` = (SELECT `id` FROM `lol_points` WHERE `name` = '{$user->data['username_clean']}') AND `reason` = 17";
3235                $get_exchange_count_res = $this->result ( $this->query ( $get_exchange_count_sql, $this->forum_db ) );
3236                if ( $get_exchange_count_res < $this->point_config ['other'] [5] ) {
3237                    $points_added = $this->community_points_add_rem ( $user->data ['username_clean'], 'upperdeck', $this->point_config ['get'] ['upper_exchange'] );
3238                    $exchanged = true;
3239                }
3240            }
3241        }
3242        $upper_item_del = $this->query ( "CALL {$this->lol_conf ['db_pve_live_characters']}.dm_upperdeck_del('{$char_guid}', '{$item_id}')", $this->root_db );
3243        //print_r($this->error($this->root_db));
3244        return $exchanged ? 1 : $random_pick [$return];
3245    }
3246
3247    protected function getHexColors ( $c )
3248    {
3249        $c = preg_replace ( "/[^a-f0-9]/i", "", $c );
3250        return array ( hexdec ( substr ( $c, 0, 2 ) ), hexdec ( substr ( $c, 2, 2 ) ), hexdec ( substr ( $c, 4, 2 ) ) );
3251    }
3252
3253    protected function width ( $txt, $size, $font )
3254    {
3255        $b = ImageTTFBBox ( $size, 0, $font, $txt );
3256        return $b [2];
3257    }
3258
3259    protected function win2uni ( $s )
3260    {
3261        $s = convert_cyr_string ( $s, 'w', 'i' );
3262        for ( $result = '', $i = 0; $i < strlen ( $s ); $i ++ ) {
3263            $charcode = ord ( $s [$i] );
3264            $result .= ( $charcode > 175 ) ? "&#" . ( 1040 + ( $charcode - 176 ) ) . ";" : $s [$i];
3265        }
3266        return $result;
3267    }
3268
3269    protected function getHonorRank ( $honor )
3270    {
3271        if ( $honor <= 0 ) $rank = 0;
3272        else if ( $honor < 500 ) $rank = 1;
3273        else if ( $honor < 1500 ) $rank = 2;
3274        else if ( $honor < 3000 ) $rank = 3;
3275        else if ( $honor < 5000 ) $rank = 4;
3276        else if ( $honor < 7500 ) $rank = 5;
3277        else if ( $honor < 10000 ) $rank = 6;
3278        else if ( $honor < 15000 ) $rank = 7;
3279        else if ( $honor < 20000 ) $rank = 8;
3280        else if ( $honor < 30000 ) $rank = 9;
3281        else if ( $honor < 40000 ) $rank = 10;
3282        else if ( $honor < 50000 ) $rank = 11;
3283        else if ( $honor < 75000 ) $rank = 12;
3284        else $rank = 13;
3285        return $rank;
3286    }
3287
3288    protected function do_exit ( $txt )
3289    {
3290        if ( is_array ( $txt ) ) {
3291            foreach ( $txt as $key => $value )
3292                echo $key . " => " . $value . "<br>";
3293        }
3294        else
3295            echo $txt;
3296        $this->close_all ( true, true );
3297    }
3298
3299    protected function cpu_load_to_high ()
3300    {
3301        require_once ( 'class_CPULoad.php' );
3302        $cpuload = new CPULoad ( );
3303        $cpuload->get_load ( );
3304        if ( $cpuload->load ["cpu"] > 98 ) return true;
3305        else return false;
3306    }
3307
3308    protected function xml2array ( $text )
3309    {
3310        $reg_exp = '/<(.*?)>(.*?)<\/\\1>/s';
3311        preg_match_all ( $reg_exp, $text, $match );
3312        $array = array ();
3313        foreach ( $match [1] as $key => $val )
3314            if ( preg_match ( $reg_exp, $match [2] [$key] ) ) $array [$val] [ ] = $this->xml2array ( $match [2] [$key] );
3315            else $array [$val] = $match [2] [$key];
3316        return $array;
3317    }
3318
3319    public function paypal_donation ( $data )
3320    {
3321        global $user;
3322        $paypal_postback = isset ( $_GET ['pf'] ) ? $_GET ['pf'] : ( isset ( $data ['pf'] ) ? $data ['pf'] : false );
3323        if ( $paypal_postback == 1 ) $this->postback ( $data );
3324        elseif ( $paypal_postback == 2 ) {
3325            $pm_subject = "Deine Spende für Landoflegends";
3326            $pm_message = "Deine Spende wird nun Verifiziert, sofern der status OK ist werden dir die Punkte sofort geadded.<br>Du erhälst noch eine Bestätigung deiner Spende von PayPal an dein E-Mail Postfach!<br>Bitte Lese dir die E-Mail genau durch, um zu sehen ob deine Spende wirklich erfolgreich war!<br><b>Achtung:</b> Bei echeck und anderen Non-Instant Spenden wird keine Benachrichtigung von PayPal an uns gesendet! Somit wird die Spende nicht automatisch gutgeschrieben!<br>Sollte es irgendwelche Probleme geben melde diese bitte, nachdem du mindestens 24 Stunden gewartet hast, im Forum.<br>Für die sofortige Aktivierung deines VIP Status & die PN mit deinem LoL-Code (Kostenloses VIP-Hemd) besuche deine <a href=\"http://www.landoflegends.de/portal.php?mod=points\">Kontoübersicht</a>";
3327            $this->phpbb_send_pm ( $user->data ['user_id'], $pm_subject, $pm_message );
3328            return $pm_message . "<br><br>Eine Kopie dieser Nachricht wurde dir auch per PM gesendet!";
3329        }
3330        elseif ( $paypal_postback == 3 ) return "Leider hast du dich dazu entschieden nicht zu Spenden.<br>Dies stellt nur noch einmal eine Bestätigung dar.";
3331        //return "<img src=\"http://lolpics.se/pics/482.jpg\" /><br>Derweilen deaktiviert, bis zur Klärung eines Problems...<br>Weiteres Info's frühstens Samstag den 27.11.10";
3332        if ( ! $user->data ['is_registered'] ) return "Leider bist du nicht eingeloggt und dir steht diese Funktion nicht zu Verfügung!";
3333        $path = $_SERVER ['DOCUMENT_ROOT'];
3334        include_once $path . "/includes/paypal.inc.php";
3335        $paypal = new paypal ( );
3336        //full web address to IPN script
3337        $paypal->ipn = 'http://www.landoflegends.de/portal.php?mod=paypal&pf=1';
3338        //one-time payment
3339        $paypal->enable_payment ( );
3340        //your paypal email address
3341        $paypal->add ( 'business', 'lol-donation@gmx.de' );
3342        $paypal->add ( 'item_name', "LoL Spende - {$user->data['username']}" );
3343        //$paypal->add ( 'item_number', 'Testspende' );
3344        $paypal->add ( 'quantity', 1 );
3345        $paypal->add ( 'return', 'http://www.landoflegends.de/portal.php?mod=paypal&pf=2' );
3346        $paypal->add ( 'cancel_return', 'http://www.landoflegends.de/portal.php?mod=paypal&pf=3' );
3347        return $paypal->output_form ( );
3348    }
3349
3350    public function get_block_display ()
3351    {
3352        $cookie_data = @$_COOKIE ['portal-block'];
3353        $output = array ();
3354        if ( $cookie_data && ! empty ( $cookie_data ) ) {
3355            $cookie_keys = array_keys ( $cookie_data );
3356            for ( $i = 0; $i < count ( $cookie_data ); $i ++ ) {
3357                $key = strtoupper ( $cookie_keys [$i] );
3358                if ( $cookie_data [$cookie_keys [$i]] == - 1 ) {
3359                    $output [0] [ ] = array ( "S_{$key}" => " style=\"display: none;\"" );
3360                    $output [1] [ ] = array ( "S_IMG_{$key}" => "max" );
3361                }
3362                else
3363                    $output [1] [ ] = array ( "S_IMG_{$key}" => "min" );
3364            }
3365        }
3366        return $output;
3367    }
3368
3369    // Here is my borrowed scripts from "dp92" for the race changer.
3370    protected function isAlliance ( $race )
3371    {
3372        if ( $race == 1 || $race == 3 || $race == 4 || $race == 7 || $race == 11 ) return true;
3373        return false;
3374    }
3375
3376    private function isGood ( $race, $class )
3377    {
3378        switch ( $race )
3379        {
3380            case 1:
3381                if ( in_array ( $class, array ( 1, 2, 4, 5, 6, 8, 9 ) ) ) return true;
3382                break;
3383            case 2:
3384                if ( in_array ( $class, array ( 1, 3, 4, 6, 7, 8, 9 ) ) ) return true;
3385                break;
3386            case 3:
3387                if ( in_array ( $class, array ( 1, 2, 3, 4, 5, 6 ) ) ) return true;
3388                break;
3389            case 4:
3390                if ( in_array ( $class, array ( 1, 3, 4, 5, 6, 11 ) ) ) return true;
3391                break;
3392            case 5:
3393                if ( in_array ( $class, array ( 1, 4, 5, 6, 8, 9 ) ) ) return true;
3394                break;
3395            case 6:
3396                if ( in_array ( $class, array ( 1, 3, 6, 7, 11 ) ) ) return true;
3397                break;
3398            case 7:
3399                if ( in_array ( $class, array ( 1, 4, 6, 8, 9 ) ) ) return true;
3400                break;
3401            case 8:
3402                if ( in_array ( $class, array ( 1, 3, 4, 5, 6, 7, 8 ) ) ) return true;
3403                break;
3404            case 10:
3405                if ( in_array ( $class, array ( 2, 3, 4, 5, 6, 8, 9 ) ) ) return true;
3406                break;
3407            case 11:
3408                if ( in_array ( $class, array ( 1, 2, 3, 5, 6, 7, 8 ) ) ) return true;
3409                break;
3410        }
3411        return false;
3412    }
3413
3414    private function rep ( $race )
3415    {
3416        switch ( $race )
3417        {
3418            case 1:
3419                return 72;
3420                break;
3421            case 2:
3422                return 76;
3423                break;
3424            case 3:
3425                return 47;
3426                break;
3427            case 4:
3428                return 69;
3429                break;
3430            case 5:
3431                return 68;
3432                break;
3433            case 6:
3434                return 81;
3435                break;
3436            case 7:
3437                return 54;
3438                break;
3439            case 8:
3440                return 530;
3441                break;
3442            case 10:
3443                return 911;
3444                break;
3445            case 11:
3446                return 930;
3447                break;
3448        }
3449    }
3450
3451    private function changeMageSpecials ( $oldrace, $newrace, $guid, $fc_id )
3452    {
3453        if ( ( $this->isAlliance ( $newrace ) && ! $this->isAlliance ( $oldrace ) ) || ( ! $this->isAlliance ( $newrace ) && $this->isAlliance ( $oldrace ) ) ) {
3454            //Portals
3455            $pt_spells [ ] = array ( 35717, 33691 );
3456            $pt_spells [ ] = array ( 32267, 32266 );
3457            $pt_spells [ ] = array ( 49361, 49360 );
3458            $pt_spells [ ] = array ( 11417, 10059 );
3459            $pt_spells [ ] = array ( 11418, 11416 );
3460            $pt_spells [ ] = array ( 11420, 11419 );
3461            //Teleports
3462            $pt_spells [ ] = array ( 35715, 33690 );
3463            $pt_spells [ ] = array ( 32272, 32271 );
3464            $pt_spells [ ] = array ( 49358, 49359 );
3465            $pt_spells [ ] = array ( 3567, 3561 );
3466            $pt_spells [ ] = array ( 3563, 3562 );
3467            $pt_spells [ ] = array ( 3566, 3565 );
3468            foreach ( $pt_spells as $pt_change ) {
3469                if ( ! $this->isAlliance ( $newrace ) && $this->isAlliance ( $oldrace ) ) $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`='{$pt_change[0]}' WHERE `spell`='{$pt_change[1]}' AND `guid`='{$guid}'", fc_id );
3470                if ( $this->isAlliance ( $newrace ) && ! $this->isAlliance ( $oldrace ) ) $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`='{$pt_change[1]}' WHERE `spell`='{$pt_change[0]}' AND `guid`='{$guid}'", fc_id );
3471            }
3472        }
3473    }
3474
3475    private function transferMounts ( $oldrace, $newrace, $guid, $fc_id )
3476    {
3477        $trM_querys = array ();
3478        $character_items = array ( array ( 25475, 25471 ), array ( 25474, 25472 ), array ( 44690, 44689 ), array ( 25476, 25470 ), array ( 25532, 25473 ), array ( 25531, 25528 ), array ( 25533, 25529 ), array ( 25477, 25527 ), array ( 34129, 29465 ), array ( 29469, 29467 ), array ( 29470, 29468 ), array ( 29472, 29471 ), array ( 29466, 35906 ), array ( 19029, 19030 ), array ( 44234, 44235 ) );
3479        // Only call this, if faction did change
3480        if ( ( $this->isAlliance ( $newrace ) && ! $this->isAlliance ( $oldrace ) ) || ( ! $this->isAlliance ( $newrace ) && $this->isAlliance ( $oldrace ) ) ) {
3481            /*Allianz PVP Mounts
3482             * item  spell
3483             * 29465 22719 //strider
3484             * 29467 22720 //ram
3485             * 29468 22717 //steed
3486             * 29471 22723 //tiger
3487             * 35906 48027 //elekk
3488             * 19030 23510 //stormpike
3489             * 44235 61425 //Tundra Mammoth*/
3490            /*Horde PVP Mounts
3491             * item  spell
3492             * 29469 22724 //war wolf
3493             * 29470 22722 //warhorse
3494             * 29466 22718 //kodo
3495             * 29472 22721 //raptor
3496             * 34129 35028 //strider
3497             * 19029 23509 //frostwolf
3498             * 44234 61447 //Tundra Mammoth*/
3499            if ( $this->isAlliance ( $oldrace ) ) {
3500                // Transfer alliance to horde
3501                // Transfer gryphon to wyvern
3502                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=32244 WHERE `spell`=32239 AND `guid`='{$guid}' ", $fc_id );
3503                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=32243 WHERE `spell`=32240 AND `guid`='{$guid}' ", $fc_id );
3504                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=61230 WHERE `spell`=61229 AND `guid`='{$guid}' ", $fc_id );
3505                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=32245 WHERE `spell`=32235 AND `guid`='{$guid}' ", $fc_id );
3506                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=32296 WHERE `spell`=32242 AND `guid`='{$guid}' ", $fc_id );
3507                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=32295 WHERE `spell`=32290 AND `guid`='{$guid}' ", $fc_id );
3508                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=32297 WHERE `spell`=32292 AND `guid`='{$guid}' ", $fc_id );
3509                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=32246 WHERE `spell`=32289 AND `guid`='{$guid}' ", $fc_id );
3510                //pvp Mounts
3511                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=35028 WHERE `spell`=22719 AND `guid`='{$guid}' ", $fc_id );
3512                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=22724 WHERE `spell`=22720 AND `guid`='{$guid}' ", $fc_id );
3513                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=22722 WHERE `spell`=22717 AND `guid`='{$guid}' ", $fc_id );
3514                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=22721 WHERE `spell`=22723 AND `guid`='{$guid}' ", $fc_id );
3515                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=22718 WHERE `spell`=48027 AND `guid`='{$guid}' ", $fc_id );
3516                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=23509 WHERE `spell`=23510 AND `guid`='{$guid}' ", $fc_id );
3517                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=61447 WHERE `spell`=61425 AND `guid`='{$guid}' ", $fc_id );
3518                //Transfer items, that summon gryphon to summon wyvern (learn spell) & pvp Mounts
3519                foreach ( $character_items as $item )
3520                    $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`item_instance` SET `ItemEntry`='{$item[0]}' WHERE `guid` IN (SELECT `item` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_inventory` WHERE `guid` = '{$guid}') AND `ItemEntry`='{$item[1]}'", $fc_id );
3521            }
3522            else {
3523                // Transfer horde to alliance
3524                // Transfer wyvern to gryphon
3525                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=32239 WHERE `spell`=32244 AND `guid`='{$guid}' ", $fc_id );
3526                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=32240 WHERE `spell`=32243 AND `guid`='{$guid}' ", $fc_id );
3527                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=61229 WHERE `spell`=61230 AND `guid`='{$guid}' ", $fc_id );
3528                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=32235 WHERE `spell`=32245 AND `guid`='{$guid}' ", $fc_id );
3529                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=32242 WHERE `spell`=32296 AND `guid`='{$guid}' ", $fc_id );
3530                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=32290 WHERE `spell`=32295 AND `guid`='{$guid}' ", $fc_id );
3531                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=32292 WHERE `spell`=32297 AND `guid`='{$guid}' ", $fc_id );
3532                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=32289 WHERE `spell`=32246 AND `guid`='$guid' ", $fc_id );
3533                //pvp Mounts
3534                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=22719 WHERE `spell`=35028 AND `guid`='{$guid}' ", $fc_id );
3535                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=22720 WHERE `spell`=22724 AND `guid`='{$guid}' ", $fc_id );
3536                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=22717 WHERE `spell`=22722 AND `guid`='{$guid}' ", $fc_id );
3537                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=22723 WHERE `spell`=22721 AND `guid`='{$guid}' ", $fc_id );
3538                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=48027 WHERE `spell`=29466 AND `guid`='{$guid}' ", $fc_id );
3539                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=23510 WHERE `spell`=23509 AND `guid`='{$guid}' ", $fc_id );
3540                $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=61425 WHERE `spell`=61447 AND `guid`='{$guid}' ", $fc_id );
3541                //Transfer items, that summon gryphon to summon wyvern (learn spell) & pvp Mounts
3542                foreach ( $character_items as $item )
3543                    $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`item_instance` SET `ItemEntry`='{$item[1]}' WHERE `guid` IN (SELECT `item` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_inventory` WHERE `guid` = '{$guid}') AND `ItemEntry`='{$item[0]}'", $fc_id );
3544            }
3545        }
3546    }
3547
3548    private function delMounts ( $oldrace, $newrace, $fc_id )
3549    {
3550        /**
3551         * 458  Brown Horse
3552         * 470  Black Stallion
3553         * 472  Pinto
3554         * 580  Timber Wolf
3555         * 6648 Chestnut Mare
3556         * 6653 Dire Wolf
3557         * 6654 Brown Wolf
3558         * 6777 Gray Ram
3559         * 6898 White Ram
3560         * 6899 Brown Ram
3561         * 8394 Striped Frostsaber
3562         * 8395 Emerald Raptor
3563         * 10789 Spotted Frostsaber
3564         * 10793 Striped Nightsaber
3565         * 10796 Turquoise Raptor
3566         * 10799 Violet Raptor
3567         * 10873 Red Mechanostrider
3568         * 10969 Blue Mechanostrider
3569         * 17453 Green Mechanostrider
3570         * 17454 Unpainted Mechanostrider
3571         * 17462 Red Skeletal Horse
3572         * 17463 Blue Skeletal Horse
3573         * 17464 Brown Skeletal Horse
3574         * 17465 Green Skeletal Warhorse
3575         * 18989 Gray Kodo
3576         * 18990 Brown Kodo
3577         * 18991 Green Kodo
3578         * 18992 Teal Kodo
3579         * 23219 Swift Mistsaber
3580         * 23221 Swift Frostsaber
3581         * 23222 Swift Yellow Mechanostrider
3582         * 23223 Swift White Mechanostrider
3583         * 23225 Swift Green Mechanostrider
3584         * 23227 Swift Palomino
3585         * 23228 Swift White Steed
3586         * 23229 Swift Brown Steed
3587         * 23238 Swift Brown Ram
3588         * 23239 Swift Gray Ram
3589         * 23240 Swift White Ram
3590         * 23241 Swift Blue Raptor
3591         * 23242 Swift Olive Raptor
3592         * 23243 Swift Orange Raptor
3593         * 23246 Purple Skeletal Warhorse
3594         * 23247 Great White Kodo
3595         * 23248 Great Gray Kodo
3596         * 23249 Great Brown Kodo
3597         * 23250 Swift Brown Wolf
3598         * 23251 Swift Timber Wolf
3599         * 23252 Swift Gray Wolf
3600         * 23338 Swift Stormsaber
3601         * 33660 Swift Pink Hawkstrider
3602         * 34406 Brown Elekk
3603         * 34795 Red Hawkstrider
3604         * 35018 Purple Hawkstrider
3605         * 35020 Blue Hawkstrider
3606         * 35022 Black Hawkstrider
3607         * 35025 Swift Green Hawkstrider
3608         * 35027 Swift Purple Hawkstrider
3609         * 35710 Gray Elekk
3610         * 35711 Purple Elekk
3611         * 35712 Great Green Elekk
3612         * 35713 Great Blue Elekk
3613         * 35714 Great Purple Elekk
3614         * 63232 Stormwind Steed
3615         * 63635 Darkspear Raptor
3616         * 63636 Ironforge Ram
3617         * 63637 Darnassian Nightsaber
3618         * 63638 Gnomeregan Mechanostrider
3619         * 63639 Exodar Elekk
3620         * 63640 Orgrimmar Wolf
3621         * 63641 Thunder Bluff Kodo
3622         * 63642 Silvermoon Hawkstrider
3623         * 63643 Forsaken Warhorse
3624         * 64657 White Kodo
3625         * 64658 Black Wolf
3626         * 64977 Black Skeletal Horse
3627         * 65637 Great Red Elekk
3628         * 65638 Swift Moonsaber
3629         * 65639 Swift Red Hawkstrider
3630         * 65640 Swift Gray Steed
3631         * 65641 Great Golden Kodo
3632         * 65642 Turbostrider
3633         * 65643 Swift Violet Ram
3634         * 65644 Swift Purple Raptor
3635         * 65645 White Skeletal Warhorse
3636         * 65646 Swift Burgundy Wolf
3637         * 66846 Ochre Skeletal Warhorse
3638         * 66847 Striped Dawnsaber
3639         **/
3640        if ( ( $this->isAlliance ( $newrace ) && ! $this->isAlliance ( $oldrace ) ) || ( ! $this->isAlliance ( $newrace ) && $this->isAlliance ( $oldrace ) ) ) {
3641            $this->trans_AddSql ( "DELETE FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` WHERE `guid`='{$guid}' AND `spell` IN (472, 6648, 458, 470, 23229, 23228, 23227, 63232, 65640, 580, 6653, 6654, 64658, 23250, 23252, 23251, 63640, 65646, 6777, 6898, 6899, 23239, 23240, 23238, 63636, 65643, 8394, 10789, 10793, 66847, 23338, 23219, 23221, 63637, 65638, 64977, 17464, 17463, 17462, 17465, 23246, 66846, 63643, 65645, 18990, 18989, 64657, 23249, 23248, 23247, 63641, 65641, 18992, 18991, 8395, 10796, 10799, 23241, 23242, 23243, 63635, 65644, 10969, 17453, 10873, 17454, 23225, 23223, 23222, 63638, 65642, 34406, 35710, 35711, 35713, 35712, 35714, 63639, 65637, 35022, 35020, 34795, 35018, 35025, 35027, 33660, 63642, 65639)", $fc_id );
3642            $this->trans_AddSql ( "DELETE FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_aura` WHERE `guid`='{$guid}'", $fc_id );
3643            $this->trans_AddSql ( "DELETE `{$this->lol_conf ['db_pve_live_characters']}`.`character_inventory`, `{$this->lol_conf ['db_pve_live_characters']}`.`item_instance` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_inventory`, `{$this->lol_conf ['db_pve_live_characters']}`.`item_instance` WHERE `{$this->lol_conf ['db_pve_live_characters']}`.`character_inventory`.item = `{$this->lol_conf ['db_pve_live_characters']}`.`item_instance`.guid AND `{$this->lol_conf ['db_pve_live_characters']}`.`item_instance`.itemEntry IN (2414, 5655, 5656, 2411, 18777, 18778, 18776, 45125, 46752, 1132, 5665, 5668, 46099, 18796, 18798, 18797, 45595, 46749, 5864, 5873, 5872, 18787, 18785, 18786, 45586, 46748, 8631, 8632, 8629, 47100, 18902, 18767, 18766, 45591, 46744, 46308, 13333, 13332, 13331, 13334, 18791, 47101, 45597, 46746, 15290, 15277, 46100, 18794, 18795, 18793, 45592, 46750, 15292, 15293, 8595, 13321, 8563, 13322, 18772, 18773, 18774, 45589, 46747, 8588, 8591, 8592, 18788, 18789, 18790, 45593, 46743, 29221, 29220, 28927, 29222, 29223, 29224, 28936, 45596, 46751, 28481, 29744, 29743, 29745, 29746, 29747, 45590, 46745, ) AND `{$this->lol_conf ['db_pve_live_characters']}`.`character_inventory`.guid = {$guid}", $fc_id );
3644        }
3645    }
3646
3647    private function addMounts ( $guid, $race )
3648    {
3649        switch ( $race )
3650        {
3651            case 1:
3652                $mount1 = 472;
3653                $mount2 = 23229;
3654                break;
3655            case 2:
3656                $mount1 = 580;
3657                $mount2 = 23250;
3658                break;
3659            case 3:
3660                $mount1 = 6777;
3661                $mount2 = 23239;
3662                break;
3663            case 4:
3664                $mount1 = 8394;
3665                $mount2 = 23338;
3666                break;
3667            case 5:
3668                $mount1 = 64977;
3669                $mount2 = 23246;
3670                break;
3671            case 6:
3672                $mount1 = 18990;
3673                $mount2 = 23249;
3674                break;
3675            case 7:
3676                $mount1 = 10969;
3677                $mount2 = 23225;
3678                break;
3679            case 8:
3680                $mount1 = 8395;
3681                $mount2 = 23241;
3682                break;
3683            case 10:
3684                $mount1 = 35022;
3685                $mount2 = 35025;
3686                break;
3687            case 11:
3688                $mount1 = 34406;
3689                $mount2 = 35713;
3690                break;
3691        }
3692        $pop = $this->query ( "SELECT * FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` WHERE `guid`='{$guid}' AND `spell` IN (33388)", $this->root_db );
3693        if ( $this->num_rows ( $pop ) > 0 ) $this->trans_AddSql ( "INSERT IGNORE INTO `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` (`guid`,`spell`,`active`,`disabled`) VALUES ('{$guid}','{$mount1}', 0, 0)", fc_id );
3694       
3695        $pep = $this->query ( "SELECT * FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` WHERE `guid`='{$guid}' AND `spell` IN (33391, 34090, 34091)", $this->root_db );
3696        if ( $this->num_rows ( $pep ) > 0 ) {
3697            $this->trans_AddSql ( "INSERT IGNORE INTO `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` (`guid`,`spell`,`active`,`disabled`) VALUES ('{$guid}','{$mount1}', 0, 0)", fc_id );
3698            $this->trans_AddSql ( "INSERT IGNORE INTO `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` (`guid`,`spell`,`active`,`disabled`) VALUES ('{$guid}','{$mount2}', 0, 0)", fc_id );
3699        }
3700    }
3701
3702    private function check_if_online ( $name )
3703    {
3704        $check_status = $this->query ( "SELECT `online` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`characters` WHERE `name` = '$name'", $this->root_db );
3705        $check_status = $this->result ( $check_status );
3706        if ( in_array ( $check_status, array ( 0, 1 ) ) ) {
3707            return $check_status;
3708        }
3709        else
3710            return - 1;
3711    }
3712
3713    private function check_change_active ( $name )
3714    {
3715        $check_sql = "SELECT `at_login` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`characters` WHERE `name` = '{$name}'";
3716        $check_active = $this->query ( $check_sql, $this->root_db );
3717       
3718        if ( $this->result ( $check_active ) > 0 ) return true;
3719        return false;
3720    }
3721
3722    private function check_guild ( $guid )
3723    {
3724        $checking_query = $this->query ( "SELECT `guildid` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`guild_member` WHERE `guid`='{$guid}'", $this->root_db );
3725        $checking = $this->num_rows ( $checking_query );
3726        return ( $checking > 0 ) ? 1 : ( ( $checking === false ) ? - 1 : 0 );
3727    }
3728
3729    private function changeStanding ( $guid, $newrace, $oldrace, $fc_id )
3730    {
3731        //Stormwind
3732        $aone = $this->result ( $this->query ( "SELECT `standing` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` WHERE `guid`='{$guid}' AND `faction`=72", $this->root_db ) );
3733        //Ironforge
3734        $atwo = $this->result ( $this->query ( "SELECT `standing` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` WHERE `guid`='{$guid}' AND `faction`=47", $this->root_db ) );
3735        //Darnassus
3736        $athree = $this->result ( $this->query ( "SELECT `standing` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` WHERE `guid`='{$guid}' AND `faction`=69", $this->root_db ) );
3737        //Gnomeregan
3738        $afour = $this->result ( $this->query ( "SELECT `standing` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` WHERE `guid`='{$guid}' AND `faction`=54", $this->root_db ) );
3739        //Exodar
3740        $afive = $this->result ( $this->query ( "SELECT `standing` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` WHERE `guid`='{$guid}' AND `faction`=930", $this->root_db ) );
3741        //Kurenai
3742        $akurenai = $this->result ( $this->query ( "SELECT `standing` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` WHERE `guid`='{$guid}' AND `faction`=978", $this->root_db ) );
3743        //Orgrimmar
3744        $hone = $this->result ( $this->query ( "SELECT `standing` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` WHERE `guid`='{$guid}' AND `faction`=76", $this->root_db ) );
3745        //Undercity
3746        $htwo = $this->result ( $this->query ( "SELECT `standing` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` WHERE `guid`='{$guid}' AND `faction`=68", $this->root_db ) );
3747        //Thunder Bluff
3748        $hthree = $this->result ( $this->query ( "SELECT `standing` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` WHERE `guid`='{$guid}' AND `faction`=81", $this->root_db ) );
3749        //Darkspear Trolls
3750        $hfour = $this->result ( $this->query ( "SELECT `standing` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` WHERE `guid`='{$guid}' AND `faction`=530", $this->root_db ) );
3751        //Silvermoon City
3752        $hfive = $this->result ( $this->query ( "SELECT `standing` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` WHERE `guid`='{$guid}' AND `faction`=911", $this->root_db ) );
3753        //The Mag'har
3754        $hmaghar = $this->result ( $this->query ( "SELECT `standing` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` WHERE `guid`='{$guid}' AND `faction`=941", $this->root_db ) );
3755        // If staying the same race, change main reputaion to match new race
3756        $oldrepfunction = $this->rep ( $oldrace );
3757        $newrepfunction = $this->rep ( $newrace );
3758        $oldRep = $this->result ( $this->query ( "SELECT `standing` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` WHERE `guid`='{$guid}' AND `faction`='$oldrepfunction'", $this->root_db ) );
3759        $newRep = $this->result ( $this->query ( "SELECT `standing` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` WHERE `guid`='{$guid}' AND `faction`='$newrepfunction'", $this->root_db ) );
3760       
3761        if ( ( $this->isAlliance ( $newrace ) && $this->isAlliance ( $oldrace ) ) || ( ! $this->isAlliance ( $newrace ) && ! $this->isAlliance ( $oldrace ) ) ) {
3762            $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$oldRep' WHERE `guid`='{$guid}' AND `faction`='$newrepfunction'", $fc_id );
3763            $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$newRep' WHERE `guid`='{$guid}' AND `faction`='$oldrepfunction'", $fc_id );
3764        }
3765        else {
3766            if ( $this->isAlliance ( $newrace ) ) {
3767                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$hone', `flags`=17 WHERE `guid`='{$guid}' AND `faction`=72", $fc_id );
3768                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$htwo', `flags`=17 WHERE `guid`='{$guid}' AND `faction`=47", $fc_id );
3769                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$hthree', `flags`=17 WHERE `guid`='{$guid}' AND `faction`=69", $fc_id );
3770                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$hfour', `flags`=17 WHERE `guid`='{$guid}' AND `faction`=54", $fc_id );
3771                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$hfive', `flags`=17 WHERE `guid`='{$guid}' AND `faction`=930", $fc_id );
3772                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$hmaghar', `flags`=17 WHERE `guid`='{$guid}' AND `faction`=978", $fc_id );
3773                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$akurenai', `flags`=17 WHERE `guid`='{$guid}' AND `faction`=941", $fc_id );
3774                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`=150, `flags`=6 WHERE `guid`='{$guid}' AND `faction`=76", $fc_id );
3775                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`=150, `flags`=6 WHERE `guid`='{$guid}' AND `faction`=68", $fc_id );
3776                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`=150, `flags`=6 WHERE `guid`='{$guid}' AND `faction`=81", $fc_id );
3777                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`=150, `flags`=6 WHERE `guid`='{$guid}' AND `faction`=530", $fc_id );
3778                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`=150, `flags`=6 WHERE `guid`='{$guid}' AND `faction`=911", $fc_id );
3779            }
3780            else {
3781                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$aone', `flags`=17 WHERE `guid`='{$guid}' AND `faction`=76", $fc_id );
3782                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$atwo', `flags`=17 WHERE `guid`='{$guid}' AND `faction`=68", $fc_id );
3783                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$athree', `flags`=17 WHERE `guid`='{$guid}' AND `faction`=81", $fc_id );
3784                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$afour', `flags`=17 WHERE `guid`='{$guid}' AND `faction`=530", $fc_id );
3785                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$afive', `flags`=17 WHERE `guid`='{$guid}' AND `faction`=911", $fc_id );
3786                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$akurenai', `flags`=17 WHERE `guid`='{$guid}' AND `faction`=978", $fc_id );
3787                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`='$hmaghar', `flags`=17 WHERE `guid`='{$guid}' AND `faction`=941", $fc_id );
3788                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`=150, `flags`=6 WHERE `guid`='{$guid}' AND `faction`=72", $fc_id );
3789                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`=150, `flags`=6 WHERE `guid`='{$guid}' AND `faction`=47", $fc_id );
3790                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`=150, `flags`=6 WHERE `guid`='{$guid}' AND `faction`=69", $fc_id );
3791                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`=150, `flags`=6 WHERE `guid`='{$guid}' AND `faction`=54", $fc_id );
3792                $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_reputation` SET `standing`=150, `flags`=6 WHERE `guid`='{$guid}' AND `faction`=930", $fc_id );
3793            }
3794        }
3795    }
3796
3797    private function changeSpells ( $oldrace, $newrace, $guid, $fc_id )
3798    {
3799        $guid = is_numeric ( $guid ) ? $guid : 0;
3800        $get_faction_spells_sql = "SELECT * FROM `{$this->lol_conf ['db_pve_live_world']}`.`player_factionchange_spells`";
3801        $get_faction_spells_query = $this->query ( $get_faction_spells_sql, $this->root_db );
3802        while ( $fspell = $this->fetch_row ( $get_faction_spells_query ) ) {
3803            //Alt Allianz & neu Horde
3804            if ( $this->isAlliance ( $oldrace ) && ! $this->isAlliance ( $newrace ) ) $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`={$fspell[1]} WHERE `guid`={$guid} AND `spell`={$fspell[0]}", $fc_id );
3805            //Alt Horde & neu Allianz
3806            if ( ! $this->isAlliance ( $oldrace ) && $this->isAlliance ( $newrace ) ) $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`={$fspell[0]} WHERE `guid`={$guid} AND `spell`={$fspell[1]}", $fc_id );
3807        }
3808        //Alt Allianz & neu Horde
3809        if ( $this->isAlliance ( $oldrace ) && ! $this->isAlliance ( $newrace ) ) {
3810            //Change Heroism to Bloodlust
3811            $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=2825 WHERE `guid`={$guid} AND `spell`=32182", $fc_id );
3812            //Change Seal of Vengeance to Seal of Corruption
3813            $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=53736 WHERE `guid`={$guid} AND `spell`=31801", $fc_id );
3814            //Pala Mounts
3815            $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=13819 WHERE `guid`={$guid} AND `spell`=34769", $fc_id );
3816            $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=23214 WHERE `guid`={$guid} AND `spell`=34767", $fc_id );
3817            $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=55531 WHERE `guid`={$guid} AND `spell`=60424", $fc_id );
3818            $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=60116 WHERE `guid`={$guid} AND `spell`=60114", $fc_id );
3819        }
3820        //Alt Horde & neu Allianz
3821        if ( ! $this->isAlliance ( $oldrace ) && $this->isAlliance ( $newrace ) ) {
3822            //Change Bloodlust to Heroism
3823            $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=32182 WHERE `guid`={$guid} AND `spell`=2825", $fc_id );
3824            //Change Seal of Corruption to Seal of Vengeance
3825            $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=31801 WHERE `guid`={$guid} AND `spell`=53736", $fc_id );
3826            //Pala Mounts
3827            $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=34769 WHERE `guid`={$guid} AND `spell`=13819", $fc_id );
3828            $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=34767 WHERE `guid`={$guid} AND `spell`=23214", $fc_id );
3829            $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=60424 WHERE `guid`={$guid} AND `spell`=55531", $fc_id );
3830            $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_spell` SET `spell`=60114 WHERE `guid`={$guid} AND `spell`=60116", $fc_id );
3831        }
3832    }
3833
3834    private function changeFactionItems ( $oldrace, $newrace, $guid, $fc_id )
3835    {
3836        $guid = is_numeric ( $guid ) ? $guid : 0;
3837        $get_faction_items_sql = "SELECT * FROM `{$this->lol_conf ['db_pve_live_world']}`.`player_factionchange_items`";
3838        $get_faction_items_query = $this->query ( $get_faction_items_sql, $this->root_db );
3839        while ( $fitem = $this->fetch_row ( $get_faction_items_query ) ) {
3840            //Alt Allianz & neu Horde
3841            if ( $this->isAlliance ( $oldrace ) && ! $this->isAlliance ( $newrace ) ) $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`item_instance` SET `ItemEntry`='{$fitem[4]}' WHERE `guid` IN (SELECT `item` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_inventory` WHERE `guid` ={$guid}) AND `ItemEntry`='{$fitem[1]}'", $fc_id );
3842            //Alt Horde & neu Allianz
3843            if ( ! $this->isAlliance ( $oldrace ) && $this->isAlliance ( $newrace ) ) $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`item_instance` SET `ItemEntry`='{$fitem[1]}' WHERE `guid` IN (SELECT `item` FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_inventory` WHERE `guid` ={$guid}) AND `ItemEntry`='{$fitem[4]}'", $fc_id );
3844        }
3845    }
3846
3847    private function changeAchievements ( $oldrace, $newrace, $guid, $fc_id )
3848    {
3849        $guid = is_numeric ( $guid ) ? $guid : 0;
3850        $get_achievements_sql = "SELECT * FROM `{$this->lol_conf ['db_pve_live_world']}`.`player_factionchange_achievement`";
3851        $get_achievements_query = $this->query ( $get_achievements_sql, $this->root_db );
3852        while ( $achv = $this->fetch_row ( $get_achievements_query ) ) {
3853            //Alt Allianz & neu Horde
3854            if ( $this->isAlliance ( $oldrace ) && ! $this->isAlliance ( $newrace ) ) $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_achievement` SET `achievement`='{$achv[1]}' WHERE `guid`={$guid} AND `achievement`='{$achv[0]}'", $fc_id );
3855            //Alt Horde & neu Allianz
3856            if ( ! $this->isAlliance ( $oldrace ) && $this->isAlliance ( $newrace ) ) $this->trans_AddSql ( "UPDATE IGNORE `{$this->lol_conf ['db_pve_live_characters']}`.`character_achievement` SET `achievement`='{$achv[0]}' WHERE `guid`={$guid} AND `achievement`='{$achv[1]}'", $fc_id );
3857        }
3858    }
3859
3860    private function change_language_skills ( $newrace, $guid, $fc_id )
3861    {
3862        $guid = is_numeric ( $guid ) ? $guid : 0;
3863        //delete all languages
3864        $this->trans_AddSql ( "DELETE FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_skills` WHERE `skill` IN (98, 113, 759, 111, 313, 109, 115, 315, 673, 137) AND `guid`={$guid}", $fc_id );
3865        // now add them back
3866        if ( $this->isAlliance ( $newrace ) ) {
3867            $this->trans_AddSql ( "INSERT IGNORE INTO `{$this->lol_conf ['db_pve_live_characters']}`.`character_skills` (guid, skill, value, max) VALUES ({$guid}, 98, 300, 300)", $fc_id );
3868            switch ( $newrace )
3869            {
3870                case 3:
3871                    $this->trans_AddSql ( "INSERT IGNORE INTO `{$this->lol_conf ['db_pve_live_characters']}`.`character_skills` (guid, skill, value, max) VALUES ({$guid}, 111, 300, 300)", $fc_id );
3872                    break;
3873                case 11:
3874                    $this->trans_AddSql ( "INSERT IGNORE INTO `{$this->lol_conf ['db_pve_live_characters']}`.`character_skills` (guid, skill, value, max) VALUES ({$guid}, 759, 300, 300)", $fc_id );
3875                    break;
3876                case 7:
3877                    $this->trans_AddSql ( "INSERT IGNORE INTO `{$this->lol_conf ['db_pve_live_characters']}`.`character_skills` (guid, skill, value, max) VALUES ({$guid}, 313, 300, 300)", $fc_id );
3878                    break;
3879                case 4:
3880                    $this->trans_AddSql ( "INSERT IGNORE INTO `{$this->lol_conf ['db_pve_live_characters']}`.`character_skills` (guid, skill, value, max) VALUES ({$guid}, 113, 300, 300)", $fc_id );
3881                    break;
3882            }
3883        }
3884        else if ( ! $this->isAlliance ( $newrace ) ) {
3885            $this->trans_AddSql ( "INSERT IGNORE INTO `{$this->lol_conf ['db_pve_live_characters']}`.`character_skills` (guid, skill, value, max) VALUES ({$guid}, 109, 300, 300)", $fc_id );
3886            switch ( $newrace )
3887            {
3888                case 5:
3889                    $this->trans_AddSql ( "INSERT IGNORE INTO `{$this->lol_conf ['db_pve_live_characters']}`.`character_skills` (guid, skill, value, max) VALUES ({$guid}, 673, 300, 300)", $fc_id );
3890                    break;
3891                case 6:
3892                    $this->trans_AddSql ( "INSERT IGNORE INTO `{$this->lol_conf ['db_pve_live_characters']}`.`character_skills` (guid, skill, value, max) VALUES ({$guid}, 115, 300, 300)", $fc_id );
3893                    break;
3894                case 8:
3895                    $this->trans_AddSql ( "INSERT IGNORE INTO `{$this->lol_conf ['db_pve_live_characters']}`.`character_skills` (guid, skill, value, max) VALUES ({$guid}, 315, 300, 300)", $fc_id );
3896                    break;
3897                case 10:
3898                    $this->trans_AddSql ( "INSERT IGNORE INTO `{$this->lol_conf ['db_pve_live_characters']}`.`character_skills` (guid, skill, value, max) VALUES ({$guid}, 137, 300, 300)", $fc_id );
3899                    break;
3900            }
3901        }
3902    }
3903
3904    private function delete_quests ( $oldrace, $newrace, $guid, $fc_id )
3905    {
3906        $guid = is_numeric ( $guid ) ? $guid : 0;
3907        if ( ( $this->isAlliance ( $oldrace ) && ! $this->isAlliance ( $newrace ) ) || ( ! $this->isAlliance ( $oldrace ) && $this->isAlliance ( $newrace ) ) ) $this->trans_AddSql ( "DELETE FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_queststatus` WHERE `status` = 3 AND guid ={$guid}", $fc_id );
3908   
3909
3910     //To Do: Delete records of the faction old completed quests
3911    }
3912
3913    private function delete_friend_list ( $oldrace, $newrace, $guid, $fc_id )
3914    {
3915        $guid = is_numeric ( $guid ) ? $guid : 0;
3916        if ( ( $this->isAlliance ( $oldrace ) && ! $this->isAlliance ( $newrace ) ) || ( ! $this->isAlliance ( $oldrace ) && $this->isAlliance ( $newrace ) ) ) {
3917            $this->trans_AddSql ( "DELETE FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_social` WHERE `guid`={$guid}", $fc_id );
3918            $this->trans_AddSql ( "DELETE FROM `{$this->lol_conf ['db_pve_live_characters']}`.`character_social` WHERE `friend`={$guid}", $fc_id );
3919        }
3920    }
3921
3922    protected function faction_changer ( $name = 0, $newrace = 0, $oldrace = 0, $class = 0, $guid = 0 )
3923    {
3924        //return array ( false, "<center>Kurzzeitig deaktiviert, Datenbankanpassung notwendig!</center>" );
3925        if ( ! $this->root_db || ! $this->realm_online [0] ) return array ( false, "<center>Fehler: Datenbank oder Server Offline!<br>Bitte später nochmal Versuchen!</center>" );
3926        if ( $this->check_change_active ( $name ) ) return array ( false, "<center>Es stehen noch eine oder mehrere Aktionen beim nächsten Login für diesen Charakter aus!<br>Bitte Einloggen und die Aktion(en) für diesen Charakter zuerst Ausführen.<br>Erst dann kannst du die nächsten Durchführen!</center>" );
3927        $online_status = $this->check_if_online ( $name );
3928        $check_guild = $this->check_guild ( $guid );
3929        if ( $newrace > 0 && $newrace < 12 && $newrace != 9 ) {
3930            if ( $newrace != $oldrace ) {
3931                if ( $online_status == 0 ) {
3932                    if ( $this->isGood ( $newrace, $class ) ) {
3933                        $can_change = false;
3934                        if ( $this->isAlliance ( $newrace ) && ! $this->isAlliance ( $oldrace ) && $check_guild == 0 ) $can_change = true;
3935                        if ( ! $this->isAlliance ( $newrace ) && $this->isAlliance ( $oldrace ) && $check_guild == 0 ) $can_change = true;
3936                        if ( $this->isAlliance ( $newrace ) && $this->isAlliance ( $oldrace ) ) $can_change = true;
3937                        if ( ! $this->isAlliance ( $newrace ) && ! $this->isAlliance ( $oldrace ) ) $can_change = true;
3938                        if ( ! $can_change ) return array ( false, "<center>Fehler: Du musst erst deine Gilde Verlassen, bevor du die Fraktion wechseln kannst!</center>" );
3939                       
3940                        //Factionchange Query ID
3941                        $fc_id = mt_rand ( );
3942                       
3943                        //Del & Add Standardmounts
3944                        $this->delMounts ( $oldrace, $newrace, $guid, $fc_id );
3945                        $this->addMounts ( $guid, $newrace, $fc_id );
3946                        //Transfer Mounts
3947                        $this->transferMounts ( $oldrace, $newrace, $guid, $fc_id );
3948                        //Change Spells
3949                        $this->changeSpells ( $oldrace, $newrace, $guid, $fc_id );
3950                        //Change Faction Specific Items
3951                        $this->changeFactionItems ( $oldrace, $newrace, $guid, $fc_id );
3952                        //Change Faction Achievements
3953                        $this->changeAchievements ( $oldrace, $newrace, $guid, $fc_id );
3954                        //Mage Special Spells
3955                        $this->changeMageSpecials ( $oldrace, $newrace, $guid, $fc_id );
3956                        //Change Languages Skills
3957                        $this->change_language_skills ( $newrace, $guid, $fc_id );
3958                        //Delete Quests with status 3
3959                        $this->delete_quests ( $oldrace, $newrace, $guid, $fc_id );
3960                        //Delete Friendlist
3961                        $this->delete_friend_list ( $oldrace, $newrace, $guid, $fc_id );
3962                       
3963                        if ( $this->isAlliance ( $oldrace ) ) $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_achievement_progress` SET `counter`=10500 WHERE `guid`='{$guid}' AND `criteria` IN (2030, 2031, 2032, 2033, 2034)", $fc_id );
3964                        else $achp = $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`character_achievement_progress` SET `counter`=10500 WHERE `guid`='{$guid}' AND `criteria` IN (992, 993, 994, 995, 996)", $fc_id );
3965                        //Horde Start
3966                        if ( $this->isAlliance ( $newrace ) && ! $this->isAlliance ( $oldrace ) ) $spos = $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`characters` SET `position_x` = -8913.23, `position_y` = 554.633, `position_z` = 93.7944, `map` = 0 WHERE `guid`='{$guid}'", $fc_id );
3967                        //Alliance Start
3968                        if ( ! $this->isAlliance ( $newrace ) && $this->isAlliance ( $oldrace ) ) $spos = $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`characters` SET `position_x` = 1440.45, `position_y` = -4422.78, `position_z` = 25.4634, `map` = 1 WHERE `guid`='{$guid}'", $fc_id );
3969                        //Change Standings
3970                        $this->changeStanding ( $guid, $newrace, $oldrace, $fc_id );
3971                        $factionchange_query = $this->trans_AddSql ( "UPDATE `{$this->lol_conf ['db_pve_live_characters']}`.`characters` SET `race`='$newrace' ,`at_login`=8 ,`playerBytes`=1 WHERE `guid`='{$guid}'", $fc_id );
3972                       
3973                        $changed_faction = true;
3974                       
3975                        if ( ! $this->trans_Execute ( $this->root_db, $fc_id ) ) $changed_faction = false;
3976                       
3977                        //Unset Factionchange Array of ID
3978                        unset ( $this->aSql [$fc_id] );
3979                       
3980                        $dk_txt = "<font color='blue'><center>
3981                        Glückwunsch, du hast soeben für deinen Todesritter den Fraktionswechsel freigeschaltet, dieser wird beim nächsten Login vollzogen.<br>
3982                        WICHTIG: Bitte beachte, dass du nach dem Wechsel erneut die lezte Quest der Archerus abschliessen musst, welche dich erneut zu König Wrynn bzw. Thrall führt.<br>
3983                        Andernfalls wirst du nach verlassen der schwarzen Festung \"befriedet\" bis du diese Quest erneut abgeschlossen hast.</center></font>";
3984                       
3985                        if ( $changed_faction ) return array ( true, ( $class == 6 && ! $this->isAlliance ( $newrace ) ) ? $dk_txt : "<font color='blue'><center>Fraktionswechsel beim nächsten Login freigeschaltet!</center></font>" );
3986                        else return array ( false, "<center>Fehler: Es ist ein Fehler beim Fraktionswechseler aufgetreten, bitte schicke DarkMan die folgenden Infos:<br>{$this->all_errors($fc_id)}!</center>" );
3987                    }
3988                    else
3989                        return array ( false, "<center>Fehler: Du kannst nicht auf diese Rasse mit deiner Klasse wechseln!</center>" );
3990                }
3991                else
3992                    return array ( false, "<center>Fehler: Dieser Charakter ist im Spiel eingeloggt! Versuch es später noch einmal!</center>" );
3993            }
3994            else
3995                return array ( false, "<center>Fehler: Die neue und die alte Rasse sind die selbe!</center>" );
3996        }
3997        else
3998            return array ( false, "<center>Fehler: Unbekannte Rasse!</center>" );
3999    }
4000
4001    public function get_forum_disabled_template ()
4002    {
4003        global $phpbb_root_path;
4004        $template_url1 = $_SERVER ['DOCUMENT_ROOT'] . "/darkman/forum_disabled";
4005        $template_url2 = $_SERVER ['DOCUMENT_ROOT'] . "/darkman/forum_disabled_txt";
4006        $template1 = @file_get_contents ( $template_url1 );
4007        $template2 = @file_get_contents ( $template_url2 );
4008        $this->close_all ( );
4009        return ( strlen ( $template1 ) > 0 && strlen ( $template2 ) > 0 ) ? sprintf ( $template1, $template2 ) : false;
4010    }
4011
4012    protected function get_holiday_status ( $username, $self = false, $date = false )
4013    {
4014        $vip_list = array ();
4015        $get_vips = "SELECT `account` FROM `donation_acc`";
4016        $got_vips = $this->query ( $get_vips, $this->forum_db );
4017        while ( $vip = $this->fetch_row ( $got_vips ) )
4018            $vip_list [ ] = $vip [0];
4019        $umod = array ();
4020        $sql = "SELECT * FROM `account_holiday`";
4021        $sql = $this->query ( $sql, $this->root_db );
4022        while ( $r = $this->fetch_row ( $sql ) )
4023            $umod [ ] = array ( $r [0], $r [1] );
4024        $has_umod = false;
4025       
4026        $umod_date = '';
4027       
4028        foreach ( $umod as $uumod ) {
4029            if ( $uumod [0] == $username ) {
4030                $has_umod = true;
4031                $umod_date = date ( "d.m.Y H:i:s", $uumod [1] );
4032                break;
4033            }
4034        }
4035       
4036        $get_last_login_sql = "SELECT `last_login` FROM `account` WHERE `username` = '{$username}'";
4037        $get_last_login_result = $this->result ( $this->query ( $get_last_login_sql, $this->root_db ) );
4038        $times = array ();
4039        if ( in_array ( $username, $vip_list ) ) {
4040            $get_vip_lts_sql = "SELECT `id` FROM `lol_points_VLTS` WHERE `id` = (SELECT `id` FROM `lol_points` WHERE `name` = '{$username}')";
4041            $get_vip_lts_query = $this->query ( $get_vip_lts_sql, $this->forum_db );
4042            $get_vip_lts = $this->num_rows ( $get_vip_lts_query );
4043            if ( $get_vip_lts == 1 ) array_push ( $times, '12' );
4044            array_push ( $times, '12' );
4045            if ( $has_umod ) array_push ( $times, '12' );
4046            else array_push ( $times, '3' );
4047        }
4048        else {
4049            if ( $has_umod ) array_push ( $times, '12' );
4050            else array_push ( $times, '3' );
4051        }
4052        $months = 0;
4053        foreach ( $times as $c_time )
4054            $months = $months + $c_time;
4055        $months = "-{$months} months";
4056        if ( $self ) {
4057            if ( $has_umod && $get_last_login_result != date ( "Y-m-d H:i:s", strtotime ( $months, time ( ) ) ) ) return $date ? array ( true, $umod_date ) : true;
4058            else return $date ? array ( false, $umod_date ) : false;
4059        }
4060        if ( $get_last_login_result < date ( "Y-m-d H:i:s", strtotime ( $months, time ( ) ) ) ) return $date ? array ( false, $umod_date ) : false;
4061        else return $date ? array ( true, $umod_date ) : true;
4062    }
4063
4064    protected function check_mysql_privileges ( $tabledb = '', $db_user, $command )
4065    {
4066        if ( ! $db_user ) return false;
4067        $check_sql1 = "SELECT `GRANTEE` FROM `information_schema`.`TABLE_PRIVILEGES` WHERE `GRANTEE` LIKE '%{$db_user}%' AND `TABLE_NAME` = '{$tabledb}' AND `PRIVILEGE_TYPE` = '{$command}'";
4068        $check_query1 = $this->query ( $check_sql1, $this->root_db );
4069        $check_num1 = $this->num_rows ( $check_query1 );
4070        $check_sql2 = "SELECT `GRANTEE` FROM `information_schema`.`SCHEMA_PRIVILEGES` WHERE `GRANTEE` LIKE '%{$db_user}%' AND `TABLE_SCHEMA` = '{$tabledb}' AND `PRIVILEGE_TYPE` = '{$command}'";
4071        $check_query2 = $this->query ( $check_sql2, $this->root_db );
4072        $check_num2 = $this->num_rows ( $check_query2 );
4073        if ( $check_num1 >= 1 || $check_num2 >= 1 ) return true;
4074        else return false;
4075    }
4076
4077    protected function is_banned ( $accountid = 0 )
4078    {
4079        if ( $accountid == 0 ) return false;
4080        $get_banned_sql = "SELECT `till` FROM `user_banns` WHERE `gid` = '{$accountid}'";
4081        $get_banned_res = $this->result ( $this->query ( $get_banned_sql, $this->forum_db ) );
4082        if ( $get_banned_res >= time ( ) ) return true;
4083        return false;
4084    }
4085
4086    protected function replace_da_shit ( $str, $args, $argr )
4087    {
4088        if ( is_array ( $args ) ) {
4089            for ( $i = 0; $i <= count ( $args ); $i ++ ) {
4090                $str = str_ireplace ( $args [$i], ( is_array ( $argr ) ? $argr [$i] : $argr ), $str );
4091            }
4092        }
4093        else
4094            $str = str_ireplace ( $args, ( is_array ( $argr ) ? $argr [0] : $argr ), $str );
4095        return $str;
4096    }
4097
4098    public function check_wowhead ( $temp )
4099    {
4100        if ( $this->array_search_ext ( $temp, 'wowhead.com', false ) ) {
4101            $url = @parse_url ( 'http://www.wowhead.com/widgets/power.js' );
4102            if ( ! $url ) return false;
4103            $url = array_map ( 'trim', $url );
4104            $url ['port'] = ( ! isset ( $url ['port'] ) ) ? 80 : (int) $url ['port'];
4105            $path = ( isset ( $url ['path'] ) ) ? $url ['path'] : '/';
4106            $path .= ( isset ( $url ['query'] ) ) ? "?$url[query]" : '';
4107            if ( isset ( $url ['host'] ) && $url ['host'] != gethostbyname ( $url ['host'] ) ) {
4108                $fp = @fsockopen ( $url ['host'], $url ['port'], $errno, $errstr, 30 );
4109                if ( ! $fp ) return false; //socket not opened
4110                fputs ( $fp, "HEAD $path HTTP/1.1\r\nHost: $url[host]\r\n\r\n" ); //socket opened
4111                $headers = fread ( $fp, 4096 );
4112                fclose ( $fp );
4113                if ( preg_match ( '#^HTTP/.*\s+[(200|301|302)]+\s#i', $headers ) ) { //matching header
4114                    return true;
4115                }
4116                else
4117                    return false;
4118            }
4119            else
4120                return false;
4121        }
4122        return false;
4123    }
4124
4125    protected function gm_rating_form ()
4126    {
4127        global $user;
4128       
4129        $code = "<form action=\"?mod=gm_rating&gmode=submit\" method=\"POST\"><table width=\"100%\" border=\"0\"><tr><td align=\"center\" width=\"50%\">GM Ausw&auml;hlen:<br /><select name=\"gm\" size=\"1\"><option value=\"\" selected=\"selected\">(Keiner Ausgew&auml;hlt)</option>";
4130       
4131        $next_vote = strtotime ( "-1 week" );
4132        $allready_voted = 0;
4133        $userhash = sha1 ( $user->data ['user_id'] );
4134        $check_uservote_sql = "SELECT `userhash`, `gm_uid`, `date` FROM `lol_gm_rating_user` WHERE `userhash`='{$userhash}' AND `date`>'{$next_vote}'";
4135        $check_uservote_query = $this->query ( $check_uservote_sql, $this->forum_db );
4136       
4137        // Check votet GM and write their userids to $allready_voted
4138        while ( $check_uservote_fetch = $this->fetch_row ( $check_uservote_query ) ) {
4139            if ( $allready_voted == 0 ) $allready_voted = $check_uservote_fetch [1];
4140            else $allready_voted .= ", " . $check_uservote_fetch [1];
4141        }
4142       
4143        $gm_groups = "5, 7, 11, 9, 17, 24"; // Set the GM-Groups
4144        $gm_data_sql = "SELECT `user_id`, `username`,`user_colour` FROM `phpbb_users` WHERE `group_id` IN($gm_groups) AND `user_id` NOT IN($allready_voted) ORDER BY `group_id`";
4145        $gm_data_query = $this->query ( $gm_data_sql, $this->forum_db );
4146        while ( $gm_data = $this->fetch_row ( $gm_data_query ) )
4147            $code .= "<option value=\"{$gm_data [0]}\" style=\"padding: 0.1em;color: #{$gm_data [2]}\">{$gm_data [1]}</option>";
4148       
4149        $code .= "</select></td><td align=\"center\" width=\"50%\">Note w&auml;hlen:<br /><select name=\"rating\" size=\"1\"><option value=\"\" selected=\"selected\">(Keine Ausgew&auml;hlt)</option>";
4150        $description = array ( "1" => "Sehr Gut", "2" => "Gut", "3" => "Befriedigend", "4" => "Ausreichend", "5" => "Mangelhaft", "6" => "Ungen&uuml;gend" );
4151        foreach ( $description as $value => $text )
4152            $code .= "<option value=\"{$value}\" style=\"padding: 0.1em\">{$value} ({$text})</option>";
4153       
4154        $code .= "</select></td></tr><tr><td align=\"center\" width=\"100%\" colspan=\"2\"><br /><br />Einen Kommentar hinzuf&uuml;gen - Noch <span id=\"gm_comment\">600</span> Zeichen:<br><textarea name=\"comment\" cols=\"50\" rows=\"5\" onkeyup=\"CheckFieldLength(this, 'gm_comment', 600);\" onkeydown=\"CheckFieldLength(this,'gm_comment', 600);\" onmouseout=\"CheckFieldLength(this,'gm_comment', 600);\"></textarea><p><input type=\"submit\" value=\"Bewerten\"></p></td></tr></table></form>";
4155       
4156        return $code;
4157    }
4158
4159    protected function gm_rating_submit ( $data )
4160    {
4161        global $user;
4162       
4163        $data ['comment'] = str_replace ( '\r\n', '<br />', $data ['comment'] ); // Zeilenumbr�che einf�gen
4164       
4165
4166
4167        $gm_id = $this->check_post_data ( $data, 'gm', $this->forum_db, '' );
4168        $rating = $this->check_post_data ( $data, 'rating', $this->forum_db, '' );
4169        $comment = $this->check_post_data ( $data, 'comment', $this->forum_db, '' );
4170        $userhash = sha1 ( $user->data ['user_id'] );
4171        $iphash = sha1 ( $user->data ['user_ip'] );
4172       
4173        $date = time ( );
4174        $next_vote = strtotime ( "-1 week" ); // 1 Woche von heute abziehen, um zu prüfen ob dieser GM in den letzten 7 Tagen bereits bewertet wurde
4175       
4176
4177
4178        $check_uservote_sql = "SELECT `userhash`, `gm_uid`, `date` FROM `lol_gm_rating_user` WHERE `userhash`='{$userhash}' AND `gm_uid`='{$gm_id}' AND `date`>'{$next_vote}' ORDER BY `date` DESC";
4179        $check_ipvote_sql = "SELECT `ip_hash`, `gm_uid`, `date` FROM `lol_gm_rating_user` WHERE `ip_hash`='{$iphash}' AND `gm_uid`='{$gm_id}' AND `date`>'{$next_vote}' ORDER BY `date` DESC";
4180        $check_uservote_query = $this->query ( $check_uservote_sql, $this->forum_db );
4181        $check_ipvote_query = $this->query ( $check_ipvote_sql, $this->forum_db );
4182        $num_votes_user = $this->num_rows ( $check_uservote_query );
4183        $num_votes_ip = $this->num_rows ( $check_ipvote_query );
4184        $num_votes = $num_votes_user + $num_votes_ip; // Check ip & account for existing vote
4185       
4186
4187
4188        // Prüfen ob der Benutzer für Bewertungen gesperrt wurde
4189        $check_ban_sql = "SELECT * FROM `lol_gm_rating_ban` WHERE `user_hash`='{$userhash}' LIMIT 1";
4190        $check_ban_query = $this->query ( $check_ban_sql, $this->forum_db );
4191        $check_ban_row = $this->fetch_row ( $check_ban_query );
4192        $num_user_banned = $this->num_rows ( $check_ban_query );
4193       
4194
4195        if ( $num_votes < 1 && ! empty ( $gm_id ) && ! empty ( $rating ) && ! empty ( $comment ) && $num_user_banned < 1 ) {
4196            $gm_user_exist_sql = "SELECT * FROM `lol_gm_rating` WHERE `user_id`='{$gm_id}' LIMIT 1";
4197            $gm_user_exist_query = $this->query ( $gm_user_exist_sql, $this->forum_db );
4198            $gm_user_exist_num = $this->num_rows ( $gm_user_exist_query );
4199           
4200            // Insert a new GM to the Database (if not exist)
4201            if ( $gm_user_exist_num < 1 ) {
4202                $gm_name_sql = "SELECT `user_id`, `username` FROM `phpbb_users` WHERE `user_id`='{$gm_id}'";
4203                $gm_name_query = $this->query ( $gm_name_sql, $this->forum_db );
4204                $gm_name_fetch = $this->fetch_row ( $gm_name_query );
4205                $insert_new_gm_sql = "INSERT INTO `lol_gm_rating` SET `user_id`='{$gm_id}', `gmname`='{$gm_name_fetch['1']}', `rating_total`='0', `votes`='0'";
4206                $insert_new_gm_query = $this->query ( $insert_new_gm_sql, $this->forum_db );
4207                $insert_new_gm_true = $this->affected_rows ( $this->forum_db );
4208            }
4209            else
4210                $insert_new_gm_true = 1;
4211           
4212            $gm_rating_result_sql = "SELECT `rating`, `active` FROM `lol_gm_rating_user` WHERE `gm_uid`='{$gm_id}' AND `active`='1'";
4213            $gm_rating_result_query = $this->query ( $gm_rating_result_sql, $this->forum_db );
4214            $total = 0;
4215            $num_votes_gm = $this->num_rows ( $gm_rating_result_query, $this->forum_db );
4216           
4217            while ( $gm_rating_result_row = $this->fetch_row ( $gm_rating_result_query ) ) {
4218                $total = $total + $gm_rating_result_row ['0'];
4219            }
4220            $votes = $num_votes_gm + 1; // calculate the total votes
4221            $new_rating = ( $total + $rating ) / $votes; // Calculate the average
4222           
4223
4224
4225            $update_gm_user_sql = "UPDATE `lol_gm_rating` SET `rating_total`='{$new_rating}', `votes`='{$votes}' WHERE `user_id`='{$gm_id}'";
4226            $update_gm_user_query = $this->query ( $update_gm_user_sql, $this->forum_db );
4227            $update_gm_user_true = $this->affected_rows ( $this->forum_db );
4228            $update_sql = "INSERT INTO `lol_gm_rating_user` SET `userhash`='{$userhash}', `ip_hash`='{$iphash}', `gm_uid`='{$gm_id}', `rating`='{$rating}', `comment`='{$comment}', `date`='{$date}', `user_id`='{$user->data ['user_id']}', `active`='1'";
4229            $update_query = $this->query ( $update_sql, $this->forum_db );
4230            $update_true = $this->affected_rows ( $this->forum_db );
4231            if ( $update_true && $update_gm_user_true && $insert_new_gm_true ) $code = '<font color="#008800">Deine Bewertung wurde erfasst!</font>';
4232            else $code = '<font color="#880000">Leider gab es einen Fehler bei der &Uuml;bergabe der &Uuml;bermittlung der Daten!</font>';
4233        }
4234        else if ( $num_votes > 0 ) $code = '<font color="#880000">Du hast mit dieser IP bereits diesen GM innerhalb der letzten 7 Tage bewertet!</font>';
4235        else if ( $num_user_banned > 0 ) $code = "<font color='#FF0000'>Benutzer: <i>Anonymous (ID: {$check_ban_row [1]})</i><br /><b>Du wurdest <u>DAUERHAFT</u> von diesen Bewertungen ausgeschlossen, der daf&uuml;r angegebene Grund:<br />\"{$check_ban_row [2]}\".</b></font>";
4236        else $code = '<font color="#880000">Du hast nichts ausgew&auml;hlt oder nicht alle erforderlichen Felder ausgef&uuml;llt!<br />(Erforderliche Felder: "GM Ausw&auml;hlen" & "Note w&auml;hlen" & "Einen Kommentar hinzuf&uuml;gen")</font>';
4237        $code .= "<br /><br />";
4238       
4239        return $code;
4240    }
4241
4242   
4243    protected function explodei ( $separator, $string, $limit = false )
4244    {
4245        $len = strlen ( $separator );
4246        for ( $i = 0;; $i ++ ) {
4247            if ( ( $pos = stripos ( $string, $separator ) ) === false || ( $limit !== false && $i > $limit - 2 ) ) {
4248                $result [$i] = $string;
4249                break;
4250            }
4251            $result [$i] = substr ( $string, 0, $pos );
4252            $string = substr ( $string, $pos + $len );
4253        }
4254        return $result;
4255    }
4256
4257    static public function is_mobile ()
4258    {
4259        $regex_match = "/(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|";
4260        $regex_match .= "htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|";
4261        $regex_match .= "blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|";
4262        $regex_match .= "symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm|";
4263        $regex_match .= "jigs browser|hiptop|^ucweb|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220";
4264        $regex_match .= ")/i";
4265        return isset ( $_SERVER ['HTTP_X_WAP_PROFILE'] ) or isset ( $_SERVER ['HTTP_PROFILE'] ) or preg_match ( $regex_match, strtolower ( $_SERVER ['HTTP_USER_AGENT'] ) );
4266    }
4267
4268    private function gen_lol_form_salt ()
4269    {
4270        global $user;
4271       
4272        $time = time ( );
4273        $salt = $this->gen_hash ( "{$user->data['username_clean']}:{$time}" );
4274        $uid = $user->data ['user_id'];
4275       
4276        $salt_sql = "INSERT IGNORE INTO `lol_form_salt` VALUES('{$uid}','{$salt}')";
4277        $inserted = $this->query ( $salt_sql, $this->forum_db );
4278       
4279        return $salt;
4280    }
4281
4282    private function check_lol_form_salt ( $salt )
4283    {
4284        global $user;
4285       
4286        $uid = $user->data ['user_id'];
4287       
4288        $get_salt_sql = "SELECT `salt` FROM `lol_form_salt` WHERE `uid` = '{$uid}' AND `salt` = '{$salt}'";
4289        $get_salt = $this->query ( $get_salt_sql, $this->forum_db );
4290        $got_salt = $this->num_rows ( $get_salt );
4291       
4292        return $got_salt ? true : false;
4293    }
4294
4295    private function del_lol_form_salt ( $salt )
4296    {
4297        global $user;
4298       
4299        $uid = $user->data ['user_id'];
4300       
4301        $del_salt_sql = "DELETE FROM `lol_form_salt` WHERE `uid` = '{$uid}' AND `salt` = '{$salt}'";
4302        $del_salt = $this->query ( $del_salt_sql, $this->forum_db );
4303        $deleted_salt = $this->num_rows ( $del_salt );
4304       
4305        return $deleted_salt ? true : false;
4306    }
4307
4308    protected function check_browser ( $section, $browser, $min_version )
4309    {
4310       
4311        $browser_array = get_browser ( null, true );
4312
4313        if ( $browser_array ['browser'] != $browser || ($browser_array ['browser'] == $browser && $browser_array ['version'] < 8) ) {
4314            return "<br><br>Leider bieten wir nur für {$browser} ab Version {$min_version} 100% Gewährleistung, dass unsere Funktionen auch benutzt werden können.<br>
4315                    Du solltest dir lieber den Firefox besorgen. <a href=\"http://www.mozilla.org/de/firefox/\" target=\"_blank\">Hol ihn dir!</a><br>
4316                        <div align=\"center\"><table><tr><td>Möchtest du wirklich Fortfahren?</td></tr>
4317                        <tr><td align=\"center\"><input type=\"button\" value=\"Ja\" onclick=\"get_content('points_content','portal.php?mod=points&action={$section}&accepted=true&ajax=true', 'get');return false;\" /> | <input type=\"button\" value=\"Nein\" onclick=\"window.location = 'http://www.landoflegends.de/portal.php/';\" /></td></tr></table></div>";
4318
4319        }
4320       
4321        return false;
4322    }
4323}
4324?>
Note: See TracBrowser for help on using the repository browser.