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

Commit

Permalink
Installer fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nabeel Shahzad committed Mar 23, 2011
1 parent a3aa87a commit 6d288e0
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 102 deletions.
42 changes: 38 additions & 4 deletions core/common/PilotGroups.class.php
Expand Up @@ -18,6 +18,7 @@
*/

class PilotGroups extends CodonData {

/**
* Get all of the groups
*/
Expand All @@ -39,7 +40,8 @@ public static function getAllGroups() {
/**
* Add a group
*/
public static function AddGroup($groupname, $permissions) {
public static function addGroup($groupname, $permissions) {

$sql = "INSERT INTO " . TABLE_PREFIX . "groups
(`name`, `permissions`) VALUES ('$groupname', $permissions)";

Expand All @@ -60,7 +62,7 @@ public static function AddGroup($groupname, $permissions) {
* @param mixed $permissions
* @return
*/
public static function EditGroup($groupid, $groupname, $permissions) {
public static function editGroup($groupid, $groupname, $permissions) {

$groupid = intval($groupid);
$groupname = DB::escape($groupname);
Expand Down Expand Up @@ -122,7 +124,7 @@ public static function getGroupID($groupname) {
* @param mixed $groupidorname
* @return
*/
public static function AddUsertoGroup($pilotid, $groupidorname) {
public static function addUsertoGroup($pilotid, $groupidorname) {

if ($groupidorname == '') {
return false;
Expand All @@ -138,9 +140,10 @@ public static function AddUsertoGroup($pilotid, $groupidorname) {
}

$sql = 'INSERT INTO '.TABLE_PREFIX.'groupmembers (pilotid, groupid)
VALUES (' . $pilotid . ', ' . $groupidorname . ')';
VALUES ('.$pilotid.', '.$groupidorname.')';

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

if (DB::errno() != 0) {
return false;
Expand All @@ -149,7 +152,25 @@ public static function AddUsertoGroup($pilotid, $groupidorname) {
return true;
}

/**
* See if any group in the list has a certain permission
*
* @param array $grouplist
* @param int $perm
* @return bool
*/
public static function group_has_perm($grouplist, $perm) {
return self::groupHasPermission($grouplist, $perm);
}

/**
* See if any group in the list has a certain permission
*
* @param array $grouplist
* @param int $perm
* @return bool
*/
public static function groupHasPermission($grouplist, $perm) {

if (!is_array($grouplist) || count($grouplist) == 0) {
return false;
Expand Down Expand Up @@ -183,6 +204,19 @@ public static function group_has_perm($grouplist, $perm) {
*
*/
public static function check_permission($set, $perm) {
return self::checkPermission($set, $perm);
}

/**
* Check permissions against integer set
* (bit compare, ($set & $perm) === $perm)
*
* @param int $set Permission set &
* @param int $perm Permission (intval)
* @return bool Whether it's set or not
*
*/
public static function checkPermission($set, $perm) {
if (($perm & $set) === $perm) {
return true;
}
Expand Down
28 changes: 20 additions & 8 deletions core/common/RanksData.class.php
Expand Up @@ -43,11 +43,12 @@ public static function getRankByName($name) {
* on each rank
*/
public static function getAllRanks() {

$allranks = CodonCache::read('all_ranks');

if ($allranks === false) {
$sql = 'SELECT r.*, (SELECT COUNT(*) FROM ' . TABLE_PREFIX .
'pilots WHERE rank=r.rank) as totalpilots
$sql = 'SELECT r.*,
(SELECT COUNT(*) FROM ' . TABLE_PREFIX .'pilots WHERE rank=r.rank) as totalpilots
FROM ' . TABLE_PREFIX . 'ranks r
ORDER BY r.minhours ASC';

Expand All @@ -68,13 +69,16 @@ public static function getRankImage($rank) {
* Get the level the passed rank is in the list
*/
public static function getRankLevel($rankid) {

if ($rankid == 0) {
return 0;
}

$all_ranks = self::getAllRanks();

$i = 0;
foreach ($all_ranks as $rank) {

$i++;

if ($rank->rankid == $rankid) {
Expand All @@ -100,11 +104,12 @@ public static function getNextRank($hours) {
* CalculatePilotRanks() at the end
*/
public static function addRank($title, $minhours, $imageurl, $payrate) {

$minhours = intval($minhours);
$payrate = floatval($payrate);

$sql = "INSERT INTO " . TABLE_PREFIX .
"ranks (rank, rankimage, minhours, payrate)
"ranks (rank, rankimage, minhours, payrate)
VALUES('$title', '$imageurl', '$minhours', $payrate)";

$ret = DB::query($sql);
Expand All @@ -115,7 +120,7 @@ public static function addRank($title, $minhours, $imageurl, $payrate) {
}

CodonCache::delete('all_ranks');
self::CalculatePilotRanks();
self::calculatePilotRanks();

return true;
}
Expand All @@ -124,6 +129,7 @@ public static function addRank($title, $minhours, $imageurl, $payrate) {
* Update a certain rank
*/
public static function updateRank($rankid, $title, $minhours, $imageurl, $payrate) {

$minhours = intval($minhours);
$payrate = floatval($payrate);

Expand All @@ -137,7 +143,7 @@ public static function updateRank($rankid, $title, $minhours, $imageurl, $payrat

CodonCache::delete('all_ranks');

self::CalculatePilotRanks();
self::calculatePilotRanks();
return true;
}

Expand All @@ -146,8 +152,8 @@ public static function updateRank($rankid, $title, $minhours, $imageurl, $payrat
*/

public static function deleteRank($rankid) {
$sql = 'DELETE FROM ' . TABLE_PREFIX . 'ranks
WHERE rankid=' . $rankid;

$sql = 'DELETE FROM ' . TABLE_PREFIX . 'ranks WHERE rankid=' . $rankid;

DB::query($sql);

Expand All @@ -165,6 +171,7 @@ public static function deleteRank($rankid) {
* end, update that
*/
public static function calculatePilotRanks() {

/* Don't calculate a pilot's rank if this is set */
if (Config::Get('RANKS_AUTOCALCULATE') === false) {
return;
Expand Down Expand Up @@ -202,6 +209,7 @@ public static function calculatePilotRanks() {
}

public static function calculateUpdatePilotRank($pilotid) {

/* Don't calculate a pilot's rank if this is set */
if (Config::Get('RANKS_AUTOCALCULATE') == false) {
return;
Expand All @@ -227,7 +235,11 @@ public static function calculateUpdatePilotRank($pilotid) {
}
}

$update = array('rankid' => $last_rankid, 'rank' => $last_rank, 'ranklevel' => $rank_level, );
$update = array(
'rankid' => $last_rankid,
'rank' => $last_rank,
'ranklevel' => $rank_level,
);

PilotData::updateProfile($pilot->pilotid, $update);
}
Expand Down
94 changes: 46 additions & 48 deletions install/Installer.class.php
Expand Up @@ -155,41 +155,40 @@ public static function AddTables() {
return false;
}

if(!DB::select($_POST['DBASE_NAME']))
{
if(!DB::select($_POST['DBASE_NAME'])) {
self::$error = DB::$error;
return false;
}

DB::$throw_exceptions = false;

echo '<h2>Writing Tables...</h2>';

$sqlLines = self::readSQLFile(SITE_ROOT.'/install/install.sql');
foreach($sqlLines as $tablename => $sql) {
foreach($sqlLines as $sql) {

DB::query($sql);

if(DB::errno() != 0)
$divid = 'error';
else
$divid = 'success';

echo '<div id="'.$divid.'" style="text-align: left;">Writing "'.$tablename.'" table... ';

DB::query($sql['sql']);

if(DB::errno() != 0) {
#echo 'failed - manually run this query: <br /><br />"'.$sql.'"';
echo '<div id="error" style="text-align: left;">Writing "'.$sql['table'].'" table... ';
echo "<br /><br />".DB::error();
} else {
echo 'success';
echo '</div>';
}

echo '</div>';


$sql = '';
}


echo '<h2>Populating Initial Data...</h2>';
$sqlLines = self::readSQLFile(SITE_ROOT.'/install/fixtures.sql');
foreach($sqlLines as $sql) {
DB::query($sql);
DB::query($sql['sql']);
if(DB::errno() != 0) {
echo '<div id="error" style="text-align: left;">Writing to "'.$sql['table'].'" table... ';
echo "<br /><br />".DB::error();
echo '</div>';
}
}

return true;
Expand Down Expand Up @@ -236,7 +235,11 @@ public static function readSQLFile($file_name) {
# Any variable replacements
$sql = str_replace('##REVISION##', $revision, $sql);

$sqlLines[$tablename] = $sql;
$sqlLines[] = array(
'table' => $tablename,
'sql' => $sql
);

$sql = '';

} else {
Expand All @@ -247,33 +250,25 @@ public static function readSQLFile($file_name) {
return $sqlLines;
}

public static function SiteSetup()
{
/**
* Installer::SiteSetup()
*
* @return
*/
public static function SiteSetup() {

/*$_POST['SITE_NAME'] == '' || $_POST['firstname'] == '' || $_POST['lastname'] == ''
|| $_POST['email'] == '' || $_POST['password'] == '' || $_POST['vaname'] == ''
|| $_POST['vacode'] == ''*/

// first add the airline

$_POST['vacode'] = strtoupper($_POST['vacode']);
if(!OperationsData::AddAirline($_POST['vacode'], $_POST['vaname'])) {
self::$error = DB::$error;
if(!OperationsData::addAirline($_POST['vacode'], $_POST['vaname'])) {
self::$error = __FILE__.' '.__LINE__.' '.DB::$error;
return false;
}

// Add an initial airport/hub, because I love KJFK so much
$data = array(
'icao' => 'KJFK',
'name' => 'Kennedy International',
'country' => 'USA',
'lat' => '40.6398',
'lng' => '-73.7787',
'hub' => false,
'fuelprice' => 0
);

$ret = OperationsData::AddAirport($data);


// Add the user
$data = array(
'firstname' => $_POST['firstname'],
Expand All @@ -286,20 +281,17 @@ public static function SiteSetup()
'confirm' => true
);

if(!RegistrationData::AddUser($data)) {
self::$error = DB::$error;
if(!RegistrationData::addUser($data)) {
self::$error = __FILE__.' '.__LINE__.' '.DB::$error;
return false;
}


// Add a rank
RanksData::updateRank(1, 'New Hire', 0, fileurl('/lib/images/ranks/newhire.jpg'), 18.00);
RanksData::calculatePilotRanks();

# Add to admin group
$pilotdata = PilotData::GetPilotByEmail($_POST['email']);

if(!PilotGroups::AddUsertoGroup($pilotdata->pilotid, 'Administrators')) {
self::$error = DB::$error;
$pilotdata = PilotData::getPilotByEmail($_POST['email']);
if(!PilotGroups::addUsertoGroup($pilotdata->pilotid, 'Administrators')) {
self::$error = __FILE__.' '.__LINE__.' '.DB::$error;
return false;
}

Expand All @@ -312,8 +304,14 @@ public static function SiteSetup()

}

public static function sql_file_update($filename)
{
/**
* Installer::sql_file_update()
*
* @param mixed $filename
* @return
*/
public static function sql_file_update($filename) {

if(isset($_GET['test']))
return true;

Expand Down
7 changes: 4 additions & 3 deletions install/fixtures.sql
Expand Up @@ -3,12 +3,13 @@
INSERT INTO `phpvms_news` (`subject`,`body`,`postdate`,`postedby`)
VALUES ('Welcome to phpVMS!', 'Thanks for installing and using phpVMS!<br /> Check out the <a href="http://docs.phpvms.net/" target="_new">docs</a> for help and information on getting started on your VA.<br /><br />This is just a starter skin - customize yours completely. This is just a basic, barebones example of what a skin is and how it works. Check out the crystal folder in the lib/skins directory. Make your own copy and fiddle around. For help, check out the forum, and skinning docs. Also, be sure to check out the <a href="http://www.phpvms.net/tutorials" target="_blank">skinning tutorials</a> for a quick primer. The <a href="http://forum.phpvms.net" target="_blank">forums</a> are also filled with plenty of helpful people for any questions you may have.<br /><br />Good luck!', NOW(), 'phpVMS Installer');

INSERT INTO `phpvms_airports` (`id`, `icao`, `name`, `country`, `lat`, `lng`, `hub`, `fuelprice`, `chartlink`) VALUES
(1, 'KJFK', 'Kennedy International', 'USA', 40.6398, -73.7787, 0, 0, '');

INSERT INTO `phpvms_ranks` VALUES(1, 'New Hire','', 0, 18.0);
INSERT INTO `phpvms_ranks` VALUES(1, 'New Hire', '', 0, 18.0);

INSERT INTO `phpvms_groups` (`name`, `permissions`) VALUES ('Administrators', '35651519');
INSERT INTO `phpvms_groups` (`name`) VALUES ('Active Pilots');

INSERT INTO `phpvms_groups` (`name`, `permissions`) VALUES ('Active Pilots', '0');

INSERT INTO `phpvms_settings` VALUES(NULL , 'phpVMS Version', 'PHPVMS_VERSION', '0', 'phpVMS Version', 1);
INSERT INTO `phpvms_settings` VALUES(NULL, 'Virtual Airline Name', 'SITE_NAME', 'PHPVMS', 'The name of your site. This will show up in the browser title bar.', 1);
Expand Down

0 comments on commit 6d288e0

Please sign in to comment.