root/dev/mods/value_editor/value_editor.php @ 291

Revision 225, 3.7 KB (checked in by ralle030583, 13 years ago)

- new Mod :

value editor and eve_central value sync from Shailo
( http://www.eve-dev.net/e107_plugins/forum/forum_viewtopic.php?4544)

Line 
1<?php
2require_once('common/admin/admin_menu.php');
3require_once('mods/value_editor/eve_central_sync.php');
4/**
5*       Item Value Editor version 0.01a
6*       Author: Duncan Hill <evedev@cricalix.net>
7*
8*       Licence: Do what you like with it, credit me as the original author
9*                Not warrantied for anything, might eat your cat.  Your responsibility.
10*/
11$eve_central_exists = true;
12
13
14$page = new Page();
15$page->setAdmin();
16$page->setTitle('Administration - Item Values');
17
18// On a POST, we're probably updating a value, as the search funtion uses GET
19if ('POST' == $_SERVER['REQUEST_METHOD'] AND isset($_POST['update_value'])) {
20        $item = $_POST['itm_id'];
21        $value = $_POST['value'];
22        $query = "UPDATE kb3_items SET itm_value='$value' WHERE itm_id=$item";
23        $qry = new DBQuery();
24        $qry->execute($query);
25        $smarty->assign('success', 'Manual update of item price was successful.');
26}
27
28// On a get, we might be doing an EVE Central update
29// The $eve_central_exists test is redundant, but acts as a safety-net.
30if ('GET' == $_SERVER['REQUEST_METHOD'] AND isset($_GET['d']) AND 'eve_central' == $_GET['d'] AND $eve_central_exists) {
31        if (ec_update_value($_GET['itm_id'])) {
32                $smarty->assign('success', 'EVE Central synchronise was successful.');
33        } else {
34                $smarty->assign('success', 'EVE Central synchronise was not successful.  This could be because you do not have allow_fopen_url, or EVE Central returned invalid data for an item value.');
35        }
36}
37
38// Scan the items table for the internal ID, name and value.
39$sql = "SELECT itm_id, itm_name, itm_value FROM kb3_items WHERE ";
40// Filter it if there's a search phrase
41if (isset($_REQUEST['searchphrase']) && $_REQUEST['searchphrase'] != "" && strlen($_REQUEST['searchphrase']) >= 3) {
42        $smarty->assign('search', true);
43        $where[] = "itm_name like '%" . slashfix($_REQUEST['searchphrase']) ."%'";
44}
45// If a particular type was requested, filter on that type
46(isset($_REQUEST['item_type'])) ? $type = $_REQUEST['item_type'] : $type = 25; // Default to frigates
47$where[] = "itm_type = $type";
48$where = join (' AND ', $where);
49// And make it alphabetical
50$sql .= $where . " ORDER BY itm_name";
51
52$qry = new DBQuery();
53$qry->execute($sql);
54
55while ($row = $qry->getRow())
56{
57    $results[] = array('id' => $row['itm_id'], 'name' => $row['itm_name'], 'value' => $row['itm_value']);
58}
59$smarty->assign_by_ref('results', $results);
60
61// Stuff we don't want to display.
62// There's a lot more than this, but the item DB has quite a few items and I haven't filtered it all out yet.
63$bad_ids = array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,23,24,32,94,95,186,190,226,227,332);
64$bad_ids = join(',', $bad_ids);
65$bad_likes = array('itt_name not like "asteroid%"', 
66                'itt_name not like "mission%"', 
67                'itt_name not like "deadspace%"',
68                'itt_name not like "concord%"',
69                'itt_name not like "corvet%"',
70                );
71$bad_likes = join(' AND ', $bad_likes);
72
73// Query for the item types to fill in the top dropdown
74$query_types = "SELECT itt_id, itt_name FROM kb3_item_types WHERE itt_id not in ($bad_ids) AND $bad_likes ORDER BY itt_name";
75
76$qry->execute($query_types);
77
78while ($row = $qry->getRow())
79{
80        $types[$row['itt_id']] = $row['itt_name'];
81}
82
83// Chuck it all at smarty
84$smarty->assign_by_ref('item_types', $types);
85$smarty->assign('mod', 'value_editor');
86$smarty->assign_by_ref('eve_central_exists', $eve_central_exists);
87$smarty->assign_by_ref('type', $type);
88
89$page->addContext($menubox->generate());
90// override the smarty path, get the mod template, set it back.
91$smarty->template_dir = './mods/value_editor';
92$page->setContent($smarty->fetch(get_tpl('value_editor')));
93$smarty->template_dir = './templates';
94$page->generate();
95print $sql . "<br>";
96?>
Note: See TracBrowser for help on using the browser.