<?php
//***************//
// START SCRIPT //
//***************//
$mysidia->user->getstatus();
if(!$mysidia->user->isloggedin){
// The user is not logged in, show generic login error message
$mysidia->displayerror("guest");
}
else
if($mysidia->user->status->canshop == "no"){
// The user's permission to browse shops is banned, show error message
$mysidia->page->settitle($lang->global_guest_title);
$mysidia->page->addcontent($lang->denied);
}
elseif(!$mysidia->input->get("shopname")){
// The user has yet to enter a shop, so we may as well list the shop
$mysidia->page->settitle($lang->access);
$mysidia->page->addcontent($lang->type);
$shoplist = new Shoplist($mysidia->input->post("shoptype"));
$shoplist->display();
}
elseif(!$mysidia->input->get("itemname") and !$mysidia->input->get("adopttype")){
// The user has entered a shop but not yet specified the item or adoptables to purchase
$shoptype = $mysidia->db->select("shops", array("shoptype"), "shopname = '{$mysidia->input->get(shopname)}'")->fetchColumn();
$shoplist = new Shoplist($shoptype);
$shop = $shoplist->createshop($mysidia->input->get("shopname"));
$mysidia->page->settitle($lang->welcome);
$shop->display();
}
elseif($mysidia->input->get("itemname") and !$mysidia->input->get("adopttype")){
// The user has specified an item to purchase, let's process this request
$shop = new Itemshop($mysidia->input->get("shopname"));
$item = $shop->getitem($mysidia->input->get("itemname"));
$item->assign($mysidia->user->username);
$oldquantity = $item->getoldquantity();
$newquantity = $oldquantity + $mysidia->input->post("quantity");
if(!is_numeric($mysidia->input->post("quantity"))){
$mysidia->page->settitle($lang->global_action_title);
$mysidia->page->addcontent($lang->invalid_quantity);
}
elseif($newquantity > $item->cap){
$mysidia->page->settitle($lang->global_error);
$mysidia->page->addcontent($lang->full_quantity);
}
elseif($shop->purchase($item)){
// The item is purchased successfully, now let's process the request
$mysidia->page->addcontent("{$lang->purchase_item}{$item->getcost($shop->salestax)} {$mysidia->settings->cost}");
}
else{
$mysidia->page->settitle($lang->global_error);
$mysidia->page->addcontent($lang->money);
}
}
elseif(!$mysidia->input->get("itemname") and $mysidia->input->get("adopttype")){
// The user has specified an adoptable to purchase, let's process this request
$shop = new Adoptshop($mysidia->input->get("shopname"));
$adopt = $shop->getadopt($mysidia->input->get("adopttype"));
$adopt->assign($mysidia->user->username);
if($shop->purchase($adopt)){
// The adoptable is purchased successfully, now let'ss process the request
$mysidia->page->addcontent("{$lang->purchase_adopt}{$adopt->getcost($shop->salestax)} {$mysidia->settings->cost}");
}
else{
$mysidia->page->settitle($lang->global_error);
$mysidia->page->addcontent($lang->money);
}
}
else{
// Invalid action specified, show generic error message
$mysidia->displayerror("action");
}
//***************//
// OUTPUT PAGE //
//***************//
$mysidia->output();
?>