                       <?php
/*================================================================+\
|| # PHPRetro - An extendable virtual hotel site and management
|+==================================================================
|| # Copyright (C) 2009 Yifan Lu. All rights reserved.
|| # http://www.yifanlu.com
|| # Parts Copyright (C) 2009 Meth0d. All rights reserved.
|| # http://www.meth0d.org
|| # All images, scripts, and layouts
|| # Copyright (C) 2009 Sulake Ltd. All rights reserved.
|+==================================================================
|| # PHPRetro is provided "as is" and comes without
|| # warrenty of any kind. PHPRetro is free software!
|| # License: GNU Public License 3.0
|| # http://opensource.org/licenses/gpl-license.php
\+================================================================*/

$page['allow_guests'] = true;
require_once('./includes/core.php');
require_once('./includes/session.php');
$lang->addLocale("credits.credits");

$page['id'] = "jobs_create";
$page['name'] = "Edit Business";
$page['bodyid'] = "home";
$page['cat'] = "bussiness";

require_once('./templates/community_header.php');
?>

<style type="text/css">
input[type="text"], input[type="password"] {
  background-color: #F1F1F1;
  border: 1px solid #999999;
  width: 175px;
  padding: 5px;
  font-family: verdana;
  font-size: 10px;
  color: #666666;
}
input[type="submit"] {
  background-color: #F1F1F1;
  border: 1px solid #999999;
  padding: 5px;
  font-family: verdana;
  font-size: 10px;
  color: #666666;
}
select {
  background-color: #F1F1F1;
  border: 1px solid #999999;
  padding: 5px;
  font-family: verdana;
  font-size: 10px;
  color: #666666;
}
</style>

<?php
if($user->name == "Guest"){
  header("Location: ".PATH);
}

$CorpID = $input->FilterText($_GET['id']);
$check_user_query = mysql_query("SELECT * FROM jobs_corps WHERE owner = '".$user->id."' && id = '".$CorpID."';");
if(mysql_num_rows($check_user_query) == 0){
  header("Location: ".PATH."/jobs_create");
}

$get_corp_info = mysql_query("SELECT * FROM jobs_corps WHERE owner = '".$user->id."' && id = '".$CorpID ."';");
$corp_info = mysql_fetch_array($get_corp_info);

if(isset($_POST['rank_submit'])){
  $rank_motto = strip_tags($input->FilterText($_POST['rank_motto']));
  $rank_payout = $_POST['rank_payout'];
  if($rank_motto == NULL || $rank_payout == NULL){
    $error_message = '<font color="red"><strong>Oops, it appears that you have left a field blank.</strong></font><br /><br />';
  }else{
    if(!is_numeric($rank_payout)){
      $error_message = '<font color="red"><strong>Nice try, but the payout must be a number.</strong></font><br /><br />';
    }else{
      if($rank_payout < 0 ||$rank_payout > 100) {
        $error_message = '<font color="red"><strong>The payout must be between 0 and 100 credits.</strong></font><br /><br />';
      }else{
        $ranks_num = mysql_query("SELECT * FROM jobs_ranks WHERE corp_id = '".$CorpID."';");
        $new_rank = mysql_num_rows($ranks_num) + 1;
        if($new_rank == 11){
          $error_message = '<font color="red"><strong>You can not create more then ten ranks.</strong></font><br /><br />';
        }else{
          mysql_query("INSERT into jobs_ranks (id, corp_id, job_rank, motto, pay) VALUES (NULL, '".$CorpID ."', '".$new_rank."', '".$rank_motto."', '".$rank_payout."');");
          $error_message = '<font color="green"><strong>You have successfully created '.$rank_motto.'.</strong></font><br /><br />';
        }
      }
    }
  }
}

if(isset($_POST['business_delete'])){
  mysql_query("UPDATE users SET corp_id = '0', job_rank = '0', secure_id = '0' WHERE corp_id = '".$CorpID."'");
  mysql_query("UPDATE users SET credits = credits + '".$corp_info['corp_balance']."' WHERE id = '".$corp_info['owner']."'");
  mysql_query("DELETE FROM jobs_ranks WHERE corp_id = '".$CorpID."'");
  mysql_query("DELETE FROM jobs_rooms WHERE corp_id = '".$CorpID."'");
  mysql_query("DELETE FROM jobs_corps WHERE id = '".$CorpID."'");
  header("Location: ".PATH."/jobs_create");
}
?>
<div id="container">
	<div id="content" style="position: relative" class="clearfix">
    <div id="column1" class="column">

				<div class="habblet-container ">
						<div class="cbb clearfix blue ">
							<h2 class="title"><?php echo $corp_info['corp_name']; ?>
							</h2>
<p class="credits-countries-select">
<strong>Company</strong>: <?php echo $corp_info['corp_name']; ?><br />
<strong>Balance</strong>: <?php echo $corp_info['corp_balance']; ?>
</p>

					</div>
						<div class="cbb clearfix blue ">
							<h2 class="title">Business Ranks
							</h2>
<p class="credits-countries-select">
<?php
$get_ranks_query = mysql_query("SELECT * FROM jobs_ranks WHERE corp_id = '".$corp_info['id']."' ORDER BY job_rank ASC;");
while($get_rank = mysql_fetch_array($get_ranks_query)){
  echo '[<a href="'.PATH.'/jobs_ranks?id='.$get_rank['id'].'">Edit</a>] '.$get_rank['motto'].'<br />';
}
?>
</p>
					</div>
						<div class="cbb clearfix blue ">
							<h2 class="title">Create Rank
							</h2>
<p class="credits-countries-select">
<center>
<?php
$ranks_num = mysql_query("SELECT * FROM jobs_ranks WHERE corp_id = '".$CorpID."';");
$new_rank = mysql_num_rows($ranks_num) + 1;
echo $error_message;
?>
<table width="180px" border="0">
<tr>
<td>
<form action="" method="post">
Rank Motto:<br />
<input type="text" name="rank_motto" value="<?php echo $rank_motto; ?>" /><br /><br />
Payout:<br />
<input type="text" name="rank_payout" value="<?php echo $rank_payout; ?>" /><br /><br />
Rank:<br />
<input type="text" value="<?php echo $new_rank; ?>" disabled="disabled" /><br /><br />
<center><input type="submit" name="rank_submit" value="Create Rank" /></center>
</form>
</td>
</tr>
</table>
</center>
</p>

					</div>
<div class="cbb clearfix blue ">
							<h2 class="title">Delete Business
							</h2>
<p class="credits-countries-select">
<center>
<?php
$ranks_num = mysql_query("SELECT * FROM jobs_ranks WHERE corp_id = '".$CorpID."';");
$new_rank = mysql_num_rows($ranks_num) + 1;
echo $error_message;
?>
You will be fully refunded.<br /><br />
<form action="" method="post">
<center><input type="submit" name="business_delete" value="Delete Business" /></center>
</form>
</center>
</p>

					</div>
				</div>
</div>
<div id="column2" class="column">
				<div class="habblet-container ">
						<div class="cbb clearfix blue ">

							<h2 class="title">My Business
							</h2>
						<div id="purse-habblet">

<div class="box-content">
<img src="http://www.habbosolutions.org/resources/images/habbocharacters/newsletter_editor.gif" align="right">
<?php
$getinfo = mysql_query("SELECT * FROM users WHERE name = '".$user->name."'");
$info = mysql_fetch_array($getinfo);
$getevenmoreinfo = mysql_query("SELECT * FROM jobs_corps WHERE owner = '".$info['id']."'");
$corpcount = mysql_num_rows($getevenmoreinfo);
if($corpcount > 0) {
      while($s = mysql_fetch_array($getevenmoreinfo)) {
            echo '<a href="jobs_edit?id='.$s['id'].'">'.$s['corp_name'].'</a><br />';
      }
}else{
      echo 'Sorry, but you do not have any corps.<br />';
}
?>
<br />
<a href="<?php echo PATH; ?>/jobs_create">Create Business</a></div>
</div>


					</div>
				</div
</div>

<?php require_once('./templates/community_footer.php'); ?>
