Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
EiNE FRAGE !!
#5
PHP Code:
<?php /* * Version * Thread-Url */ $version = '0.2'; $thread_url = 'http://dslan.gfx-dose.de/thread-1390.html'; /* * Neue Klasse: groups */ class groups { /* * Datenbank-Verbindung */ var $db; /* * Template-System */ var $tpl; /* * User-ID */ var $uid; /* * Datenbanktyp */ var $db_type = 1; /* * Aktuelle Version */ var $version; /* * In PHP 5 waere das __construct */ function construct($db, $tpl, $userid, $version) { $this->db = $db; $this->tpl = $tpl; $this->uid = $userid; $this->version = $version; } /* * Neue Gruppe erstellen */ function new_group($name) { $this->db->query('INSERT INTO groups (userid, name) VALUES (\''.$this->uid.'\', \''.$name.'\')'); } /* * Gruppe bearbeiten */ function edit_group($gid, $name) { $this->db->query('UPDATE groups SET name=\''.$name.'\' WHERE id=\''.$gid.'\' LIMIT 1'); } /* * Gruppe loeschen */ function del_group($gid){ $this->db->query('DELETE FROM groups WHERE id=\''.$gid.'\' LIMIT 1'); } /* * Aktuelle Gruppe holen */ function get_aktu_group() { $query = $this->db->query('SELECT aktu_group FROM users WHERE id=\''.$this->uid.'\''); $row = $this->db->fetch($query); return $row['aktu_group']; } /* * Alle Gruppen vom User holen */ function get_groups() { $groups_sql = $this->db->query('SELECT * FROM groups WHERE userid=\''.$this->uid.'\''); while ($row = $this->db->fetch($groups_sql)) { $groups_array[] = $row; } return $groups_array; } /* * Alle Gruppen fuer ein Dorf holen */ function get_groups_for_village($vid, $for_user = true) { $group = array(); $groups_sql = $this->db->query('SELECT groups FROM villages WHERE id=\''.$vid.'\' LIMIT 1'); $row = $this->db->fetch($groups_sql); if ($row != '') { $exploded = explode(';', $row['groups']); foreach ($exploded as $key => $value) { if ($value != '') { if ($for_user === true) { $query = $this->db->query('SELECT * FROM groups WHERE id=\''.$value.'\' AND userid=\''.$this->uid.'\''); } else { $query = $this->db->query('SELECT * FROM groups WHERE id=\''.$value.'\''); } $group[] = $this->db->fetch($query); } } } return $group; } /* * Alle Gruppen vom User holen, mit Dorf-Gruppen-Info */ function get_groups_with_village($vid) { $user_groups = $this->get_groups(); $village_groups = $this->get_groups_for_village($vid); echo '<br /><br /><br />'; foreach ($user_groups as $key => $value) { foreach ($village_groups as $key2 => $value2) { if ($value['id'] == $value2['id']) { $user_groups[$key]['group_of_village'] = true; break; } } } return $user_groups; } /* * Alle Dörfer von der Gruppe holen */ function get_villages_of_group($gid, $only_id = true) { if ($only_id === true) { $query = $this->db->query('SELECT id FROM villages WHERE groups like \'%;'.$gid.';%\''); } else { $query = $this->db->query('SELECT * FROM villages WHERE groups like \'%;'.$gid.';%\''); } while ($row = $this->db->fetch($query)) { $villages['id_'.$row['id']] = $row; } return $villages; } /* * Haupt-Info ueber ein Dorf */ function get_village_main_info($vid) { $query = $this->db->query('SELECT name, x, y FROM villages WHERE id=\''.$_GET['village_id'].'\' LIMIT 1'); $row = $this->db->fetch($query); $row['name'] = entparse($row['name']); return $row; } /* * Check, ob die Gruppe, dem User gehoert */ function check_group($gid) { $group = false; $groups_sql = $this->db->query('SELECT * FROM groups WHERE userid=\''.$this->uid.'\' AND id=\''.$gid.'\''); while ($row = $this->db->fetch($groups_sql)) { $group = true; } return $group; } /* * Check, ob das Dorf dem User gehoert */ function check_village($vid) { $query = $this->db->query('SELECT id FROM villages WHERE id=\''.$vid.'\' AND userid=\''.$this->uid.'\' LIMIT 1'); $row = $this->db->fetch($query); if (isset($row['id'])) { return true; } return false; } /* * Check, ob das Dorf in der Gruppe ist */ function check_village_in_group($vid, $gid) { $query = $this->db->query('SELECT id FROM villages WHERE id=\''.$vid.'\' AND groups LIKE \'%;'.$gid.';%\''); $row = $this->db->fetch($query); if (isset($row['id'])) { return true; } return false; } /* * Holt die UID mithilfe von hkey */ function get_uid_by_hkey($hkey) { $query = $this->db->query('SELECT userid FROM sessions WHERE hkey=\''.$hkey.'\' LIMIT 1'); $row = $this->db->fetch($query); if (isset($row['userid'])) { $this->uid = $row['userid']; return true; } return false; } /* * Holt den aktuellen Mode bei overview_villages */ function get_mode() { if (isset($_GET['mode']) and $_GET['mode'] != '') { return $_GET['mode']; } else { $query = $this->db->query('SELECT villages_mode FROM users WHERE id=\''.$this->uid.'\' LIMIT 1'); $row = $this->db->fetch($query); return $row['villages_mode']; } } function get_next_village($vid, $gid, $villages_array = array()) { $query = $this->db->query('SELECT id FROM villages WHERE userid=\''.$this->uid.'\' AND groups LIKE \'%;'.$gid.';%\' ORDER BY name'); $last_vid = ''; $break = false; $village_array = $villages_array; $villages_array = array(); while ($row = $this->db->fetch($query)) { if (!isset($a)) { $villages_array['first_link'] = str_replace($village_array['next'], $row['id'], $village_array['next_link']); $villages_array['first'] = $row['id']; $a = 0; } if ($break == true) { $villages_array['next_link'] = str_replace($village_array['next'], $row['id'], $village_array['next_link']); $villages_array['next'] = $row['id']; break; } if ($vid == $row['id']) { $villages_array['last_link'] = str_replace($village_array['last'], $last_vid, $village_array['last_link']); $villages_array['last'] = $last_vid; $break = true; } $last_vid = $row['id']; } return $villages_array; } /* * Gruppen setzten */ function set_groups_of_village($vid, $groups = array()) { $gruppen = ''; if (isset($groups[0])) { foreach ($groups as $key => $value) { if (!isset($a)) { $a = 0; $gruppen .= ';'; } $gruppen .= $value.';'; } } $this->db->query('UPDATE villages SET groups=\''.$gruppen.'\' WHERE id=\''.$vid.'\' LIMIT 1'); } /* * Aktuelle Gruppe setzten */ function set_aktu_group($gid) { $this->db->query('UPDATE users SET aktu_group=\''.$gid.'\' WHERE id=\''.$this->uid.'\' LIMIT 1'); } /* * Sortiert aus $villages, die in $sort nicht gennannten Doerfer aus */ function sort_out_villages_by_group($villages, $sort, $type = 1) { if ($type == 1) { foreach ($villages as $key => $value) { if (!isset($sort['id_'.$key])) { unset($villages[$key]); } } } elseif ($type == 2) { if (isset($villages[0])) { foreach ($villages as $key => $value) { if (!isset($sort['id_'.$value['to_village']])) { unset($villages[$key]); } } } } elseif ($type == 3) { /* * Funktioniert nicht, kein Plan warum :'( */ if (isset($villages[0])) { foreach ($villages as $key => $value) { if (!isset($sort['id_'.$value['homevillageid']])) { unset($villages[$key]); } } } } return $villages; } /* * Checked nach einem Update */ function check_nach_update($tool) { $lines = file('http://philipp1993.bplaced.net/dslan/info/'.$tool.'/version.txt'); if (!$lines) { return 'no connection'; } if ($lines[0] != $this->version) { return 'update_'.$lines[0]; } return true; } /* * Holt Informationen */ function echo_update_info($tool, $tool_name, $version, $url) { $info = file('http://philipp1993.bplaced.net/dslan/info/'.$tool.'/change_'.$this->version.'_'.$version.'.txt'); if (!$info) { $info = array(''); } $ausgabe = '<p style="color: green; text-align: center;">Ein Update f&uuml;r das Addon '.$tool_name.' (&copy; Copyright by <a href="http://dslan.gfx-dose.de/user-11.html">Philipp Ranft</a>) verf&uuml;gbar!<br /><a href="#" onClick="document.getElementsByName(\'infos\')[0].style.display=\'block\';">Mehr Infos/&Auml;nderungen</a></p><span name="infos" style="display: none; text-align: center;">'; foreach ($info as $key => $value) { $ausgabe .= $value.'<br />'; } $ausgabe .= '</span><p style="text-align: center;"><a href="'.$url.'">Download/Update-Info</a></p>'; echo $ausgabe; } } /* * Klasse oeffnen */ $groups = new groups; $groups->construct($db, $tpl, $user['id'], $version); /* * Versions-Check */ $check = $groups->check_nach_update('groups'); if ($check !== true) { $version_new = explode('_', $check); if ($version_new[0] == 'update') { $groups->echo_update_info('groups', '(D&ouml;rfer-)Gruppen', $version_new[1], $thread_url); } } /* * Gruppen */ /* * Aktu_group */ if ($_GET['screen'] == 'overview_villages') { if (isset($_GET['mode'])) { if ($_GET['mode'] == 'groups') { $db->query('UPDATE users SET villages_mode=\'groups\' WHERE id=\''.$user['id'].'\''); } } if (isset($_GET['group'])) { if ($_GET['group'] != '') { if ($groups->check_group($_GET['group']) or $_GET['group'] == 0) { $groups->set_aktu_group($_GET['group']); } } } } if ($action === 'overview_villages') { /* * Action */ if (isset($_GET['action'])) { /* * new_group */ if ($_GET['action'] == 'new_group') { if (isset($_POST['group_name']) and $_POST['group_name'] != '') { $groups->new_group($_POST['group_name']); $tpl->assign('done', 'new_group'); } else { $tpl->assign('fehler', 'no_name'); } } /* * edit_group: * - edit_group(); * - del_group(); */ if ($_GET['action'] == 'edit_group' and isset($_GET['id'])) { if ($groups->check_group($_GET['id']) === true) { if (isset($_POST['del'])) { $groups->del_group($_GET['id']); $tpl->assign('done', 'del_group'); } else { if ($_POST['group_name_'.$_GET['id']] != '') { $groups->edit_group($_GET['id'], $_POST['group_name_'.$_GET['id']]); $tpl->assign('done', 'edit_group'); } else { $tpl->assign('fehler', 'no_name'); } } } else { $tpl->assign('fehler', 'wrong_id'); } } } /* * groups */ $tpl->assign('gruppen', $groups->get_groups()); $aktu_group = $groups->get_aktu_group(); $tpl->assign('aktu_group', $aktu_group); if ($aktu_group != 0) { if ($groups->get_mode() != 'incomings' and $groups->get_mode() != 'commands') { $tpl->assign('villages', $groups->sort_out_villages_by_group($villages, $groups->get_villages_of_group($aktu_group))); } elseif ($groups->get_mode() == 'incomings') { $tpl->assign('other_movements', $groups->sort_out_villages_by_group($other_movements, $groups->get_villages_of_group($aktu_group), 2)); } elseif ($groups->get_mode() == 'commands') { $tpl->assign('other_movements', $groups->sort_out_villages_by_group($my_movements, $groups->get_villages_of_group($aktu_group), 3)); } $tpl->assign('villages_of_group', $groups->get_villages_of_group($aktu_group)); } } elseif ($action == 'overview') { $tpl->assign('gruppen', $groups->get_groups_for_village($_GET['village'])); } $aktu_group = $groups->get_aktu_group(); if ($aktu_group != 0) { $tpl->assign('aktu_group', $aktu_group); $tpl->assign('village_array', $village_array = $groups->get_next_village($_GET['village'], $aktu_group, $village_array)); $tpl->assign('village_in_group', $groups->check_village_in_group($_GET['village'], $aktu_group)); } ?>
Reply


Messages In This Thread
EiNE FRAGE !! - by Leoplayer - 07.05.2009, 07:44
RE: EiNE FRAGE !! - by Leandros - 07.05.2009, 08:17
RE: EiNE FRAGE !! - by Leoplayer - 07.05.2009, 09:57
RE: EiNE FRAGE !! - by Leandros - 07.05.2009, 10:50
RE: EiNE FRAGE !! - by Leoplayer - 07.05.2009, 10:56
RE: EiNE FRAGE !! - by Leandros - 07.05.2009, 11:03
RE: EiNE FRAGE !! - by Leoplayer - 07.05.2009, 11:05
RE: EiNE FRAGE !! - by Leandros - 07.05.2009, 11:08
RE: EiNE FRAGE !! - by Leoplayer - 07.05.2009, 11:09
RE: EiNE FRAGE !! - by Leandros - 07.05.2009, 11:10
RE: EiNE FRAGE !! - by Philipp Ranft - 07.05.2009, 13:39
RE: EiNE FRAGE !! - by Yannici - 07.05.2009, 13:53



Users browsing this thread: 1 Guest(s)