root/dev/common/admin/admin_standings.php @ 190

Revision 190, 4.3 KB (checked in by exi, 16 years ago)

This is a big update...
Moved all admin scripts to common/admin.
Moved all includes and classes to common/includes.
Edited all include-paths to reflect the movement.
Fixed a bug with the session system allowing every registered user to access admin pages.
Replaced calls to date() to use a wrapper so gmdate can be used.
Replaced some calls to $config with calls to the static object.
Fixed a big which caused the portrait_grab to not download a new picute.
Added a classified-state to kills.
Removed the sync_server server script in this tree.
Added code to help modules find the includes to index.php.

Line 
1<?php
2require_once('common/includes/class.page.php');
3require_once('common/includes/class.corp.php');
4require_once('common/includes/class.alliance.php');
5require_once('common/admin/admin_menu.php');
6
7$page = new Page();
8$page->setAdmin();
9$page->setTitle('Administration - Standings');
10
11if ($_REQUEST['searchphrase'] != "" && strlen($_REQUEST['searchphrase']) >= 3)
12{
13    switch ($_REQUEST['searchtype'])
14    {
15        case 'corp':
16            $sql = "select crp.crp_id, crp.crp_name, ali.all_name
17                    from kb3_corps crp, kb3_alliances ali
18                    where lower( crp.crp_name ) like lower( '%".slashfix($_REQUEST['searchphrase'])."%' )
19                    and crp.crp_all_id = ali.all_id
20                    order by crp.crp_name";
21            break;
22        case 'alliance':
23            $sql = "select ali.all_id, ali.all_name
24                    from kb3_alliances ali
25                    where lower( ali.all_name ) like lower( '%".slashfix($_REQUEST['searchphrase'])."%' )
26                    order by ali.all_name";
27            break;
28    }
29
30    $qry = new DBQuery();
31    $qry->execute($sql);
32
33    while ($row = $qry->getRow())
34    {
35        switch ($_REQUEST['searchtype'])
36        {
37            case 'corp':
38                $typ = 'Corporation';
39                $link = 'c'.$row['crp_id'];
40                $descr = $row['crp_name'].', member of '.$row['all_name'];
41                break;
42            case 'alliance':
43                $typ = 'Alliance';
44                $link = 'a'.$row['all_id'];
45                $descr = $row['all_name'];
46                break;
47        }
48        $results[] = array('descr' => $descr, 'link' => $link, 'typ' => $typ);
49    }
50    $smarty->assign_by_ref('results', $results);
51    $smarty->assign('search', true);
52}
53if ($val = $_REQUEST['standing'])
54{
55    $fields = array();
56    if (CORP_ID)
57    {
58        $fromtyp = 'c';
59        $fields[] = CORP_ID;
60    }
61    else
62    {
63        $fromtyp = 'a';
64        $fields[] = ALLIANCE_ID;
65    }
66    $fields[] = intval(substr($_REQUEST['sta_id'], 1));
67    $fields[] = $fromtyp;
68    $fields[] = substr($_REQUEST['sta_id'], 0, 1);
69    $fields[] = str_replace(',', '.', $val);
70    $fields[] = slashfix($_REQUEST['comment']);
71
72    $qry = new DBQuery();
73    $qry->execute('INSERT INTO kb3_standings VALUES (\''.join("','", $fields).'\')');
74}
75if ($_REQUEST['del'])
76{
77    if (CORP_ID)
78    {
79        $fromtyp = 'c';
80        $fromid = CORP_ID;
81    }
82    else
83    {
84        $fromtyp = 'a';
85        $fromid = ALLIANCE_ID;
86    }
87    $totyp = substr($_REQUEST['del'], 0, 1);
88    $toid = intval(substr($_REQUEST['del'], 1));
89
90    $qry = new DBQuery();
91    $qry->execute('DELETE FROM kb3_standings WHERE sta_from='.$fromid.' AND sta_from_type=\''.$fromtyp.'\'
92                                             AND sta_to='.$toid.' AND sta_to_type=\''.$totyp.'\' LIMIT 1');
93}
94
95$qry = new DBQuery();
96if (CORP_ID)
97{
98    $qry->execute('SELECT * FROM kb3_standings WHERE sta_from='.CORP_ID.' AND sta_from_type=\'c\' ORDER BY sta_value DESC');
99}
100else
101{
102    $qry->execute('SELECT * FROM kb3_standings WHERE sta_from='.ALLIANCE_ID.' AND sta_from_type=\'a\' ORDER BY sta_value DESC');
103}
104
105$permt = array();
106while ($row = $qry->getRow())
107{
108    $typ = $row['sta_to_type'];
109    $val = sprintf("%01.1f", $row['sta_value']);
110    $id = $typ.$row['sta_to'];
111    if ($typ == 'a')
112    {
113        $alliance = new Alliance($row['sta_to']);
114        $text = $alliance->getName();
115        $link = '?a=admin_standings&del='.$typ.$row['sta_to'];
116        $permt[$typ][] = array('text' => $text, 'link' => $link, 'value' => $val, 'comment' => $row['sta_comment'], 'id' => $id);
117    }
118    if ($typ == 'c')
119    {
120        $corp = new Corporation($row['sta_to']);
121        $text = $corp->getName();
122        $link = '?a=admin_standings&del='.$typ.$row['sta_to'];
123        $permt[$typ][] = array('text' => $text, 'link' => $link, 'value' => $val, 'comment' => $row['sta_comment'], 'id' => $id);
124    }
125}
126$perm = array();
127if ($permt['a'])
128{
129    $perm[] = array('name' => 'Alliances', 'list' => $permt['a']);
130}
131if ($permt['c'])
132{
133    $perm[] = array('name' => 'Corporations', 'list' => $permt['c']);
134}
135
136$smarty->assign_by_ref('standings', $perm);
137
138$page->addContext($menubox->generate());
139$page->setContent($smarty->fetch(get_tpl('admin_standings')));
140$page->generate();
141?>
Note: See TracBrowser for help on using the browser.