Skip to content
This repository has been archived by the owner on Dec 6, 2019. It is now read-only.

Commit

Permalink
VMS-313 #close fixed, PIREP submit and API cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nabeel Shahzad committed May 25, 2010
1 parent f8cdd65 commit e8db250
Show file tree
Hide file tree
Showing 15 changed files with 359 additions and 119 deletions.
131 changes: 129 additions & 2 deletions admin/modules/Import/Import.php
Expand Up @@ -25,9 +25,11 @@ function HTMLHead()
case '':
default:
case 'processimport':

$this->set('sidebar', 'sidebar_import.tpl');

break;

case 'importaircraft':
$this->set('sidebar', 'sidebar_aircraft.tpl');
break;
}
}
Expand All @@ -42,6 +44,131 @@ public function export()
$this->render('export_form.tpl');
}

public function exportaircraft()
{
$allaircraft = OperationsData::getAllAircraft(false);

# Get the column headers
$headers = array();
$dbcolumns = DB::get_cols();
foreach($dbcolumns as $col)
{
if($col->name == 'id' || $col->name == 'minrank' || $col->name == 'ranklevel')
continue;

$headers[] = $col->name;
}

header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="aircraft.csv"');

$fp = fopen('php://output', 'w');

# Write out the header which is the columns
fputcsv($fp, $headers, ',');

# Then write out all of the aircraft
foreach($allaircraft as $aircraft)
{
unset($aircraft->id);
unset($aircraft->minrank);
unset($aircraft->ranklevel);

$aircraft = (array) $aircraft;

fputcsv($fp, $aircraft, ',');
}

fclose($fp);
}

public function importaircraft()
{

if(!file_exists($_FILES['uploadedfile']['tmp_name']))
{
$this->render('import_aircraftform.tpl');
return;
}

echo '<h3>Processing Import</h3>';

# Get the column headers
$allaircraft = OperationsData::getAllAircraft(false);
$headers = array();
$dbcolumns = DB::get_cols();
foreach($dbcolumns as $col)
{
if($col->name == 'id' || $col->name == 'minrank' || $col->name == 'ranklevel')
continue;

$headers[] = $col->name;
}

# Open the import file
$fp = fopen($_FILES['uploadedfile']['tmp_name'], 'r');
if(isset($_POST['header'])) $skip = true;

$added = 0;
$updated = 0;
$total = 0;
echo '<div style="overflow: auto; height: 400px;
border: 1px solid #666; margin-bottom: 20px;
padding: 5px; padding-top: 0px; padding-bottom: 20px;">';

while($fields = fgetcsv($fp, 1000, ','))
{
// Skip the first line
if($skip == true)
{
$skip = false;
continue;
}

# Map the read in values to the columns
$aircraft = array();
$aircraft = @array_combine($headers, $fields);

if(empty($aircraft))
continue;

# Enabled or not
if($aircraft['enabled'] == '1')
{
$aircraft['enabled'] = true;
}
else
{
$aircraft['enabled'] = false;
}

# Get the rank ID
$rank = RanksData::getRankByName($aircraft['rank']);
$aircraft['minrank'] = $rank->rankid;
unset($aircraft['rank']);

# Does this aircraft exist?
$ac_info = OperationsData::getAircraftByReg($aircraft['registration']);
if($ac_info)
{
echo "Editing {$aircraft['name']} - {$aircraft['registration']}<br>";
$aircraft['id'] = $ac_info->id;
OperationsData::editAircraft($aircraft);
$updated++;
}
else
{
echo "Adding {$aircraft['name']} - {$aircraft['registration']}<br>";
OperationsData::addAircraft($aircraft);
$added++;
}

$total ++;
}

echo "The import process is complete, added {$added} aircraft, updated {$updated}, for a total of {$total}<br />";
}

public function processexport()
{
$export='';
Expand Down
2 changes: 1 addition & 1 deletion admin/modules/Operations/Operations.php
Expand Up @@ -726,7 +726,7 @@ protected function add_aircraft_post()
'enabled'=>$this->post->enabled
);

OperationsData::AddAircaft($data);
OperationsData::AddAircraft($data);

if(DB::errno() != 0)
{
Expand Down
13 changes: 12 additions & 1 deletion admin/templates/sidebar_aircraft.tpl
@@ -1,7 +1,18 @@
<h3>Tasks</h3>
<ul class="filetree treeview-famfamfam">
<li><span class="file">
<a href="<?php echo SITE_URL?>/admin/index.php/operations/addaircraft">Add an aircraft</a>
<a href="<?php echo adminurl('/operations/aircraft');?>">View aircraft</a>
</span></li>

<li><span class="file">
<a href="<?php echo adminurl('/operations/addaircraft');?>">Add an aircraft</a>
</span></li>

<li><span class="file">
<a href="<?php echo adminaction('/import/exportaircraft'); ?>">Export Aircraft</a>
</span></li>
<li><span class="file">
<a href="<?php echo adminurl('/import/importaircraft');?>">Import Aircraft</a>
</span></li>
</ul>
<h3>Help</h3>
Expand Down
8 changes: 8 additions & 0 deletions core/classes/ezdb/ezdb.class.php
Expand Up @@ -459,6 +459,14 @@ public static function query($query)

return $ret; //self::$insert_id;
}

/**
* Return all of the columns
*/
public static function get_cols()
{
return self::$DB->get_cols();
}

/**
* Get information about a column
Expand Down
12 changes: 12 additions & 0 deletions core/classes/ezdb/ezdb_base.class.php
Expand Up @@ -865,6 +865,18 @@ public function get_results($query=null, $output = '')
}
}
}

/**
* Return all of the columns
*
* @return array Column information
*/
public function get_cols()
{

return $this->col_info;

}

/**
* Get metadata regarding a column, about a column in the last query
Expand Down
81 changes: 62 additions & 19 deletions core/common/OperationsData.class.php
Expand Up @@ -372,7 +372,7 @@ public static function editAirline($id, $code, $name, $enabled=true)
'maxcargo'=>$this->post->maxcargo,
'enabled'=>$this->post->enabled);
*/
public static function addAircaft($data)
public static function addAircraft($data)
{
/*$data = array('icao'=>$this->post->icao,
'name'=>$this->post->name,
Expand Down Expand Up @@ -401,29 +401,36 @@ public static function addAircaft($data)
$data['maxpax'] = str_replace(',', '', $data['maxpax']);
$data['maxcargo'] = str_replace(',', '', $data['maxcargo']);

if($data['enabled'] === true)
if($data['enabled'] === true || $data['enabled'] == '1')
$data['enabled'] = 1;
else
$data['enabled'] = 0;

if($data['minrank'] > 0)
{
$rank_level = RanksData::getRankLevel($data['minrank']);
$data['ranklevel'] = RanksData::getRankLevel($data['minrank']);
}
else
{
$rank_level = 0;
$data['ranklevel'] = '0';
}

$sql = "INSERT INTO ".TABLE_PREFIX."aircraft (
`icao`, `name`, `fullname`, `registration`, `downloadlink`,
`imagelink`, `range`, `weight`, `cruise`,
`maxpax`, `maxcargo`, `minrank`, `ranklevel`, `enabled`)
VALUES (
'{$data['icao']}', '{$data['name']}', '{$data['fullname']}', '{$data['registration']}',
'{$data['downloadlink']}', '{$data['imagelink']}', '{$data['range']}', '{$data['weight']}',
'{$data['cruise']}', '{$data['maxpax']}', '{$data['maxcargo']}', {$data['minrank']},
{$rank_level}, {$data['enabled']})";
$cols = array();
$col_values = array();

foreach($data as $key => $value)
{
$cols[] = "`{$key}`";

$value = DB::escape($value);
$col_values[] = "'{$value}'";
}

$cols = implode(', ', $cols);
$col_values = implode(', ', $col_values);

$sql = "INSERT INTO ".TABLE_PREFIX."aircraft
({$cols}) VALUES ({$col_values})";

$res = DB::query($sql);

Expand Down Expand Up @@ -462,27 +469,31 @@ public static function editAircraft($data)
$data['minrank'] = 0;
}

if($data['enabled'] === true)
if($data['enabled'] === true || $data['enabled'] == '1')
$data['enabled'] = 1;
else
$data['enabled'] = 0;

if($data['minrank'] > 0)
{
$rank_level = RanksData::getRankLevel($data['minrank']);
$data['ranklevel'] = RanksData::getRankLevel($data['minrank']);
}
else
{
$rank_level = 0;
$data['ranklevel'] = 0;
}

$sql = "UPDATE " . TABLE_PREFIX."aircraft
$sql = "UPDATE " . TABLE_PREFIX."aircraft SET ";
$sql .= DB::build_update($data);
$sql .= " WHERE `id`={$data['id']}";

/*$sql = "UPDATE " . TABLE_PREFIX."aircraft
SET `icao`='{$data['icao']}', `name`='{$data['name']}', `fullname`='{$data['fullname']}',
`registration`='{$data['registration']}', `downloadlink`='{$data['downloadlink']}',
`imagelink`='{$data['imagelink']}', `range`='{$data['range']}', `weight`='{$data['weight']}',
`cruise`='{$data['cruise']}', `maxpax`='{$data['maxpax']}', `maxcargo`='{$data['maxcargo']}',
`minrank`={$data['minrank']}, `ranklevel`={$rank_level}, `enabled`={$data['enabled']}
WHERE `id`={$data['id']}";
WHERE `id`={$data['id']}";*/

$res = DB::query($sql);

Expand All @@ -496,6 +507,28 @@ public static function editAircraft($data)

return true;
}

/**
* This is method deleteAircraft
*
* @param mixed $aircraft_id This is a description
* @return mixed This is the return value description
*
*/
public static function deleteAircraft($aircraft_id)
{
$sql = 'DELETE FROM '.TABLE_PREFIX.'aircraft
WHERE `id`='.$aircraft_id;

DB::query($sql);

CodonCache::delete('all_aircraft');
CodonCache::delete('all_aircraft_enabled');
CodonCache::delete('all_aircraft_search');
CodonCache::delete('all_aircraft_search_enabled');

return true;
}

public static function updateAircraftRankLevels()
{
Expand Down Expand Up @@ -556,6 +589,11 @@ public static function addAirport($data)
if($data['fuelprice'] == '')
$data['fuelprice'] = 0;

if(!isset($data['chartlink']))
{
$data['chartlink'] = '';
}

$sql = "INSERT INTO " . TABLE_PREFIX ."airports
( `icao`, `name`, `country`, `lat`, `lng`, `hub`, `chartlink`, `fuelprice`)
VALUES (
Expand Down Expand Up @@ -709,6 +747,11 @@ public static function RetrieveAirportInfo($icao)
elseif(isset($reader->airports))
{
$apt = $reader->airports[0];
}

if(!isset($apt->jeta))
{
$apt->jeta = '';
}

// Add the AP
Expand All @@ -722,7 +765,7 @@ public static function RetrieveAirportInfo($icao)
'fuelprice' => $apt->jeta
);

OperationsData::AddAirport($data);
OperationsData::addAirport($data);
}

return self::GetAirportInfo($icao);
Expand Down

0 comments on commit e8db250

Please sign in to comment.