1 | <? |
---|
2 | /******************************************** |
---|
3 | * Import kills from a csv formatted text |
---|
4 | * Used together with export tool! |
---|
5 | * |
---|
6 | * *****************************************/ |
---|
7 | |
---|
8 | require_once( "class.page.php" ); |
---|
9 | require_once( "globals.php" ); |
---|
10 | require_once( "class.parser.php" ); |
---|
11 | require_once( "class.killlist.php" ); |
---|
12 | |
---|
13 | $page = new Page( "Administration - Killmail import" ); |
---|
14 | $page->setAdmin(); |
---|
15 | |
---|
16 | if ( !$_POST['killmail'] ) { |
---|
17 | $html .= "<b>Killmails in same format as export (Comma Seperated - csv):</b><br>"; |
---|
18 | $html .= "<form id=postform name=postform class=f_killmail method=post action=\"?a=kill_import_csv\">"; |
---|
19 | $html .= "<textarea class=killmail id=killmail name=killmail cols=\"55\" rows=\"35\"></textarea><br><br>"; |
---|
20 | $html .= " <input id=submit name=submit type=submit value=\"Process !\"></input>"; |
---|
21 | $html .= "</form>"; |
---|
22 | } else { |
---|
23 | |
---|
24 | |
---|
25 | // Set delimiter |
---|
26 | $splitter=',\n\n'; |
---|
27 | $killmail = $_POST['killmail']; |
---|
28 | // Replace double quotes with single |
---|
29 | $killmail = str_replace('""', "'", $killmail); |
---|
30 | // Replace \ with nothing |
---|
31 | $killmail = str_replace('\\', "", $killmail); |
---|
32 | // Explodes to array |
---|
33 | $getstrings = explode('"', $splitter.$killmail.$splitter); |
---|
34 | // Set lenght of delimiter |
---|
35 | $delimlen = strlen($splitter); |
---|
36 | // Default |
---|
37 | $instring = 0; |
---|
38 | |
---|
39 | // String magic :) |
---|
40 | while (list($arg, $val) = each($getstrings)) { |
---|
41 | if ($instring==1) { |
---|
42 | $result[] = $val; |
---|
43 | $instring = 0; |
---|
44 | } else { |
---|
45 | if ((strlen($val)-$delimlen-$delimlen) >= 1) { |
---|
46 | $temparray = split($splitter, substr($val, $delimlen, strlen($val)-$delimlen-$delimlen ) ); |
---|
47 | while(list($iarg, $ival) = each($temparray)) { |
---|
48 | $result[] = trim($ival); |
---|
49 | } |
---|
50 | } |
---|
51 | $instring = 1; |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | // Parses killmails one by one. |
---|
56 | foreach($result as $killmail) { |
---|
57 | $parser = new Parser( $killmail ); |
---|
58 | $killid = $parser->parse( true ); |
---|
59 | // Make response |
---|
60 | if ( $killid == 0 ) $html .= "Killmail is malformed.<br>"; |
---|
61 | if ( $killid == -1 ) $html .= "That killmail has already been posted <a href=\"?a=kill_detail&kll_id=".$parser->dupeid_."\">here</a>.<br>"; |
---|
62 | if ( $killid == -2 ) $html .= "You are not authorized to post this killmail.<br>"; |
---|
63 | if ( $killid >= 1 ) $html .= "Killmail imported succesfully <a href=\"?a=kill_detail&kll_id=".$parser->dupeid_."\">here</a>.<br>"; |
---|
64 | unset($killid); |
---|
65 | unset($parser); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | |
---|
71 | $page->setContent( $html ); |
---|
72 | $page->generate(); |
---|
73 | ?> |
---|