root/dev/common/admin/admin_sync.php @ 207

Revision 207, 6.3 KB (checked in by ralle030583, 15 years ago)

- added system search
- added 12 new ship Signatures (thx to Arthur Ffrub)
- removed again some not needed includes

Line 
1<?php
2require_once('common/includes/class.contract.php');
3require_once('common/includes/class.http.php');
4
5$page = new Page();
6$page->setAdmin();
7$page->setTitle('Administration - Synchronization');
8
9if ($_REQUEST['do'] == 'sync')
10{
11    $http = new http_request(KB_SYNCURL);
12    $fp = $http->connect();
13    if (!$fp)
14    {
15        $html .= 'Could not connect to Server:<br/>'."\n";
16        $html .= $http->getError();
17
18        $page->addContext($menubox->generate());
19        $page->setContent($html);
20        $page->generate();
21        return;
22    }
23
24    $content_file = 'DATA_START';
25    $qry = new DBQuery();
26    $qry->execute("select plt_name, plt_externalid from kb3_pilots where plt_externalid != 0");
27    while ($data = $qry->getRow())
28    {
29        $content_file .= '!'.$data['plt_name'].'|'.$data['plt_externalid'].'-';
30    }
31
32    if (isset($_REQUEST['itm_update']))
33    {
34        $content_file .= 'ITEMS_START';
35    }
36    /*
37    $qry->execute("select itm_name, itm_externalid, itm_value from kb3_items where itm_value != 0");
38    while ($data = $qry->getRow())
39    {
40        $content_file .= 'ï¿œ'.$data['itm_name'].'|'.$data['itm_externalid'].'|'.$data['itm_value'].'-';
41    }
42    */
43
44    $content_file = gzdeflate($content_file);
45
46    $http->set_postdata('data', $content_file);
47    $http->set_useragent('EVE-KB SYNC (VER '.KB_VERSION.')');
48    $http->set_header('X-KBHost: '.base64_encode(KB_HOST));
49
50    // wait 30s for processed answer
51    $http->setSockettimeout(30);
52    $file = $http->get_content();
53    $header = $http->get_header();
54
55    preg_match('/X-KBVersion: (.*)/', $header, $match);
56    $version = explode('.', trim($match[1]));
57    $recv = $http->get_recv();
58    $sended = $http->get_sent();
59
60    // the response ($file) contains ids new to us
61    $data = @gzinflate($file);
62    if ($data == false)
63    {
64        if ($http->status['timed_out'] == 1)
65        {
66            $html .= "Socket request timed out<br/>\n";
67            $html .= 'This could mean that the server is not available or overloaded, please try again later<br/>';
68        }
69        else
70        {
71            $html .= "getting compressed data failed, server response was:<br><pre>\n";
72            $html .= $file."</pre>\n";
73            $html .= 'Sent '.round($sended/1024, 2)." kB and received ".round($recv/1024, 2)." kB of data.<br>\n";
74        }
75    }
76    else
77    {
78        unset($file);
79
80        // get all names we'll find
81        preg_match_all('^!(.*?)\|(.*?)-^', $data, $matches);
82        $results = count($matches[1]);
83        $update = new DBQuery();
84        $new = 0;
85        for ($i = 0; $i<$results; $i++)
86        {
87            $update->execute("update kb3_pilots set plt_externalid='".addslashes($matches[2][$i])."' where plt_name='".addslashes($matches[1][$i])."' limit 1");
88            if (mysql_affected_rows() == 1)
89            {
90                $new++;
91            }
92        }
93        $html .= "Synchronization complete, got $new new ids and ".($results - $new)." unknown pilots from server running version ".$version[0].'.'.$version[1].'.'.$version[2].'.<br/>';
94
95        if (isset($_REQUEST['itm_update']))
96        {
97            preg_match_all('^ï¿œ(.*?)\|(.*?)\|(.*?)-^', $data, $matches);
98            unset($data);
99            $results = count($matches[1]);
100            if (isset($_REQUEST['itm_overwrite']))
101            {
102                $add_qrystr = '';
103            }
104            else
105            {
106                $add_qrystr = ' AND itm_value=0';
107            }
108
109            for ($i = 0; $i<$results; $i++)
110            {
111                $update->execute("update kb3_items set itm_externalid='".addslashes($matches[2][$i])."', itm_value='".addslashes($matches[3][$i])."' where itm_name='".addslashes($matches[1][$i])."'".$add_qrystr." limit 1");
112            }
113            if ($results == 0)
114            {
115                $html .= 'No items fetched, itm_sync_module may be offline.<br/>';
116            }
117            else
118            {
119                $html .= $results.' item prices have been fetched.<br/>';
120            }
121        }
122
123        $html .= "Sent ".round($sended/1024, 2)." kB and received ".round($recv/1024, 2)." kB of data.<br>\n";
124        $html .= '<a href="?a=admin_sync">Back</a>';
125
126        // check for updates here
127        // we might move this to a new/second point some time
128        $ownversion = explode('.', KB_VERSION);
129        if ($version[1] > $ownversion[1] && $version[1] % 2 == 1)
130        {
131            // test for new minor updates below the dev-version
132            if ($version[1]-1 > $ownversion[1])
133            {
134                $upgrade = true;
135            }
136        }
137        elseif ($version[1] > $ownversion[1] && $version[1] % 2 == 0)
138        {
139            // we get here in case there is a new minor version thats not a dev
140            $upgrade = true;
141        }
142        if ($version[0] > $ownversion[0] || $upgrade)
143        {
144            $html .= "Looks like your Killboard version is pretty old, perhaps you want to upgrade it ?<br/>\n";
145            $html .= "Check the <a href='http://www.eve-dev.net/forums/viewforum.php?f=2'>EVE-Dev Forums</a> for new releases and additional information<br>\n";
146        }
147    }
148}
149else
150{
151    $html .= 'You can synchronize your external characterids for the portrait generation with the EVE-Dev.org-Server here.<br>';
152    $html .= 'Your Server will try to contact <i>"'.KB_SYNCURL.'"</i> to exchange the data.<br>';
153    $html .= 'One synchronization every one or two weeks should be enough.<br>';
154    $html .= 'Please don\'t abuse this free service!<br>';
155    $html .= '<form id="options" name="options" method="post" action="?a=admin_sync">';
156    $html .= "<table class=kb-subtable>";
157    $html .= "<tr><td width=120><b>Update item values</b></td><td><input type=checkbox name=itm_update id=itm_update";
158    $html .= " ></td></tr>";
159    $html .= "<tr><td width=120><b>Overwrite local values</b></td><td><input type=checkbox name=itm_overwrite id=itm_overwrite";
160    $html .= " >(If disabled only values with 0 will be overwritten)</td></tr>";
161    $html .= '<input type="hidden" name="do" value="sync">';
162    $html .= '<tr><td width=120></td><td><input type=submit name=submit value="Synchronize now"></td></tr></table></form>';
163}
164$page->addContext($menubox->generate());
165$page->setContent($html);
166$page->generate();
167?>
Note: See TracBrowser for help on using the browser.