View Single Post
  #41  
Old 03-18-2016, 12:39 PM
Ittermat's Avatar
Ittermat Ittermat is offline
The awesomesauce
 
Join Date: Feb 2016
Location: in front of my laptop
Posts: 272
Gender: Female
Credits: 33,605
Ittermat is on a distinguished road
Default

hey maybe you can help me..Im trying to use this mod- but everytime I try I keep getting errors... Im putting everything in as you say to...but it still wont work...Im not sure whats wrong.. maybe you can help?

this is my Itemshop.php code.

Quote:
<?php

use Resource\Collection\LinkedList;

class Itemshop extends Model{

public $sid;
public $category;
public $shopname;
public $shoptype;
public $description;
public $imageurl;
public $status;
public $restriction;
public $salestax;
public $items;
protected $total = 0;

public function __construct($shopname){
// Fetch the database info into object property
$mysidia = Registry::get("mysidia");
$row = $mysidia->db->select("shops", array(), "shopname ='{$shopname}'")->fetchObject();
if(!is_object($row)) throw new Exception("Invalid Shopname specified");

// loop through the anonymous object created to assign properties
foreach($row as $key => $val){
$this->$key = $val;
}
$this->items = $this->getitemnames();
$this->total = (is_array($this->items))?count($this->items):0;
}

public function getcategory(){
$mysidia = Registry::get("mysidia");
$stmt = $mysidia->db->select("shops", array(), "category ='{$this->category}'");
$cate_exist = ($row = $stmt->fetchObject())?TRUE:FALSE;
return $cate_exist;
}

public function getshop(){
$mysidia = Registry::get("mysidia");
if(empty($this->shopname)) $shop_exist = FALSE;
else{
$stmt = $mysidia->db->select("shops", array(), "shopname ='{$this->shopname}'");
$shop_exist = ($row = $stmt->fetchObject())?TRUE:FALSE;
}
return $shop_exist;
}

public function getitemnames(){
if(!$this->items){
$mysidia = Registry::get("mysidia");
$stmt = $mysidia->db->select("items", array("itemname"), "shop ='{$this->shopname}'");
$items = array();

while($item = $stmt->fetchColumn()){
$items[] = $item;
}
return $items;
}
else return $this->items;
}

public function gettotal(){
return $this->total;
}
public function display(){
$mysidia = Registry::get("mysidia");
$document = $mysidia->frame->getDocument();
$document->addLangvar($mysidia->lang->select_item);

if($this->gettotal() == 0){
$document->addLangvar($mysidia->lang->empty);
return FALSE;
}

# Choose the NPC image based on the name of the shop
switch ($this->shopname) {
case "Bookstore":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/646f59544e20a3ba433292c85fa7cd68.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Arent books wonderful??"; break;
case 2: $npc_text = "Nothing like traveling to a whole new world with a book!"; break;
case 3: $npc_text = "Welcome to {$this->shopname}!"; break;
case 4: $npc_text = "Off to see the wizard?"; break;
case 5: $npc_text = "Once I was covered in books, and I thought I was in heaven!"; break;
case 6: $npc_text = "Promise you'll tell me how it ends!!"; }
break;
case "Caratrises candy":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/2d0485231a263b02740ce1ea57b926d1.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "All candy is made by me!"; break;
case 2: $npc_text = "Cavities Guaranteed!"; break;
case 3: $npc_text = "Welcome to {$this->shopname}!"; break;
case 4: $npc_text = "Okay...but im not going to pay for your dental bills."; break;
case 5: $npc_text = "If you come back on a holiday I'll have special candy for you!"; break;
case 6: $npc_text = "I wont tell if you dont tell."; }
break;
case "Catari Necessities":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/fc29ee5d45ec433a1faf8fc9ff75c408.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "My favorite toy is the Teaser!"; break;
case 2: $npc_text = "Dont forget to get your Catari some treats!"; break;
case 3: $npc_text = "Welcome to {$this->shopname}!"; break;
case 4: $npc_text = "You're right! I should stock some live mice."; break;
case 5: $npc_text = "Catari are pretty easy to please"; break;
case 6: $npc_text = "Have you been to the Shrine yet? If so Tell Eyre I said hi!"; }
break;

case "Catfucious stall":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/36a5e23916c437d13755cef4e28a95ee.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Please browse as long as you need my child."; break;
case 2: $npc_text = "The first step to tranquility is not paying attention to anyone but yourself."; break;
case 3: $npc_text = "I am not here to make money my child..I am here to spread love."; break;
case 4: $npc_text = "I hope that I can help you improve your life"; break;
case 5: $npc_text = "Dont ask for too much...only want what is needed"; break;
case 6: $npc_text = "There is more to life than money...Happiness is golden"; }
break;

case "Delilahs drinks":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/24e509b16d94ee2becfa134eb335cbac.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Hi there Sweetie! I make everything myself!"; break;
case 2: $npc_text = "I'll sell holiday exclusive items, so please check back during a holiday!"; break;
case 3: $npc_text = "All you need is love!"; break;
case 4: $npc_text = "You're so adorable! Thank you for coming in!"; break;
case 5: $npc_text = "Even if I dont have something you want now- I might later!"; break;
case 6: $npc_text = "Yes, Habibi is my Brother...why do you ask?"; }
break;


case "Eyres treasury":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/a01f278da98365994ea4c1dd4e0d8212.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Im not giving my things up that easily..."; break;
case 2: $npc_text = "You know if you arent going to buy anything? you can go away..."; break;
case 3: $npc_text = "I am NOT Cute"; break;
case 4: $npc_text = "............."; break;
case 5: $npc_text = "I dont do trades...I want cold hard cash!"; break;
case 6: $npc_text = "Havent you left yet?"; }
break;

case "Feesh Fundamentals":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/9a50351b442506040eac15e7bf0589aa.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Blub blub...blub,,"; break;
case 2: $npc_text = "Blub..."; break;
case 3: $npc_text = "Blubb blub,,,"; break;
case 4: $npc_text = "............."; break;
case 5: $npc_text = "Blub..."; break;
case 6: $npc_text = "*sound of bubbles* "; }
break;

case "Glidera Goodies":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/1f3616733a28da078a709e93f3a2914a.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Glidera are wonderfully loyal pets!"; break;
case 2: $npc_text = "Cinnamon here has been with me for a really long time!"; break;
case 3: $npc_text = "Welcome to {$this->shopname}!; break;
case 4: $npc_text = "Have you tried giving your Glidera a mealworm yet?"; break;
case 5: $npc_text = "I hope you find everything you're looking for"; break;
case 6: $npc_text = "If you need help just let me know! "; }
break;

case "Habibis Holiday":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/5f47dde45fffa266ba4b26594034bc4a.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "I love holidays.."; break;
case 2: $npc_text = "I hope you're having a good time.."; break;
case 3: $npc_text = "Welcome to {$this->shopname}!; break;
case 4: $npc_text = "Its a lovely day isnt it?"; break;
case 5: $npc_text = "I hope you find everything you're looking for"; break;
case 6: $npc_text = "If you need help just let me know! "; }
break;

case "Hounda essentials":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/7e50a54e67ea07f33274ddbd55f4c681.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "I love Toys!"; break;
case 2: $npc_text = "I hope you're having a good time.."; break;
case 3: $npc_text = "Welcome to {$this->shopname}!; break;
case 4: $npc_text = "Please dont throw the ball...I need to stay behind the counter!"; break;
case 5: $npc_text = "I hope you find everything you're looking for"; break;
case 6: $npc_text = "If you need help just let me know! "; }
break;

case "Supermarket":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/5306b4da3d1c288c80f4ff1709e3580a.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Yea...what you're looking for is around here somewhere..."; break;
case 2: $npc_text = "Thats nice....."; break;
case 3: $npc_text = "Welcome to the {$this->shopname}...; break;
case 4: $npc_text = "With this price gun, I am invincible..."; break;
case 5: $npc_text = "I hope you find everything you're looking for...I guess.."; break;
case 6: $npc_text = "If you need help just let me know..or dont, because I dont care..."; }
break;

case "Camerons toys":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/29ebda897900480c07a5e1a9bc1c1994.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Hewwo!.."; break;
case 2: $npc_text = "Mummy says Im the bestest at selling toys!....."; break;
case 3: $npc_text = "Welcome to {$this->shopname}!; break;
case 4: $npc_text = "Can we be Fwiends?..."; break;
case 5: $npc_text = "If you need help, tell me!!.."; break;
case 6: $npc_text = "Pwease come back again!..."; }
break;

case "Caseys Crafts":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/bef6477cc0e7308db3ea9a88f841c956.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Hello! What are you going to make today?"; break;
case 2: $npc_text = "My son Cameron is next door!"; break;
case 3: $npc_text = "Welcome to {$this->shopname}!; break;
case 4: $npc_text = "I cant wait to see what you make!"; break;
case 5: $npc_text = "If you need help, Just let me know!!"; break;
case 6: $npc_text = "Please come back again!"; }
break;


case "Pet paints":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/e053750b18df3ab752793c365bfd61ec.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Hello! We have a bunch of cool colors!"; break;
case 2: $npc_text = "When im not here, I'm usually painting!"; break;
case 3: $npc_text = "Welcome to {$this->shopname}!; break;
case 4: $npc_text = "I cant wait to see your new pet!"; break;
case 5: $npc_text = "If you need help, Just let me know!!"; break;
case 6: $npc_text = "Please come back again!"; }
break;

case "Premium pet paints":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/e053750b18df3ab752793c365bfd61ec.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Hello! We have a bunch of cool colors!"; break;
case 2: $npc_text = "These Paints are only for the specialist of members!!"; break;
case 3: $npc_text = "Welcome to {$this->shopname}!; break;
case 4: $npc_text = "I cant wait to see your new pet!"; break;
case 5: $npc_text = "If you need help, Just let me know!!"; break;
case 6: $npc_text = "Please come back again!"; }
break;

case "Potters Potions":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/6bdb9f184918c39f01114ca8736331eb.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "Oh wait....those two things arent supposed to be mixed..."; break;
case 2: $npc_text = "I make everything here myself."; break;
case 3: $npc_text = "Welcome to {$this->shopname}!; break;
case 4: $npc_text = "Dont be alarmed...its only smoke."; break;
case 5: $npc_text = "If you need help, Just let me know.."; break;
case 6: $npc_text = "Please come back again!"; }
break;

case "Account upgrades":
$npc_img = "http://atrocity.mysidiahost.com/picuploads/png/1dd6406902d48dafb229ca6d74ed3365.png";
#Based on the random number, sets a quote for $npc_text
$num = Rand (1,6);
switch ($num) {
case 1: $npc_text = "If you want to change something on your account this is the place to go!."; break;
case 2: $npc_text = "Only premium members can be here!."; break;
case 3: $npc_text = "Welcome to {$this->shopname}!; break;
case 4: $npc_text = "I know we dont have much...."; break;
case 5: $npc_text = "If you need help, Just let me know.."; break;
case 6: $npc_text = "Please come back again!"; }
break;
default;
$npc_img = "http://placekitten.com/g/200/500";
$npc_text = "Welcome to {$this->shopname}!";
break;
}

# let's begin rendering the page
$document->add(new Comment("
<style>
.s_top {
overflow:hidden;
display: block;
}
.sc_npc_text{
width: 300px;
float: left;
position: relative;
height: 70px;
padding: 15px;
margin: 10px;
margin-top: 180px;
font-family: 'Trebuchet MS', Helvetica, sans-serif;
overflow: auto;
}
.sc_npc_img{
width: 40%;
float: left;
}

.sc_item {
display: inline-table;
padding: 5px;
text-align: center;
font-family: 'Trebuchet MS', Helvetica, sans-serif;
font-size: 14px;
margin-bottom: 3px;
}
.s_panel {
border-radius: 2px;
border: 1px solid #CCC;
background-color: #FBFDF2;
}
</style>
<!-- START Container for Text and NPC -->
<div class='s_top s_container'>
<div class='s_panel sc_npc_text'>{$npc_text}</div>
<div class='sc_npc_img'><img src='{$npc_img}' height='300'></div>
</div>
<!-- END Container for Text and NPC -->
<!-- START Container for Items -->
<div class='s_container'>
", FALSE));

# Now render each item the store has
foreach($this->items as $stockitem){
$item = $this->getitem($stockitem);

#descriptions of the item functions
switch ($item->function) {
case "Click1": $usage = "<br/><b>use:</b> Feed a pet to give them {$item->value} EXP."; break;
case "Click2": $usage = "<br/><b>use:</b> Feed a pet to set their EXP to {$item->value}."; break;
case "Click3": $usage = "<br/><b>use:</b> Resets EXP earned today to 0."; break;
case "Level1": $usage = "<br/><b>use:</b> Raises the Level of your pet by {$item->value}."; break;
case "Level2": $usage = "<br/><b>use:</b> Sets the Level of your pet to {$item->value}."; break;
case "Level3": $usage = "<br/><b>use:</b> Makes your pet Level 0 again!"; break;
case "Gender": $usage = "<br/><b>use:</b> Swaps the gender of your pet to its opposite!"; break;
default;
$usage = "";
break;
}

# Now let's render each item icon, name, price and tooltip
$document->add(new Comment("
<div class=\"s_panel sc_item\">
<img rel=\"tooltip\" title=\"{$item->description} <em>{$usage}</em>\" src=\"{$item->imageurl}\"/><br/>
<b>{$item->itemname}</b>
<br/>
{$item->price} {$mysidia->settings->cost}<br/>
", FALSE));


# Building the Buy form
$buyForm = new FormBuilder("buyform", "../purchase/{$mysidia->input->get("shop")}", "post");
$buyForm->setLineBreak(FALSE);
$buyForm->buildPasswordField("hidden", "action", "purchase")
->buildPasswordField("hidden", "itemname", $item->itemname)
->buildPasswordField("hidden", "shopname", $shop->shopname)
->buildPasswordField("hidden", "shoptype", "itemshop")
->buildPasswordField("hidden", "salestax", $shop->salestax);
$quantity = new TextField("quantity", "1");
$quantity->setSize(3);
$quantity->setMaxLength(3);
$quantity->setLineBreak(FALSE);
$buy = new Button("Buy", "buy", "buy");
$buy->setLineBreak(FALSE);
$buyForm->add($quantity);
$buyForm->add($buy);

# Actually adding in the Quantity field Buy button now
$document->add($buyForm);

# Now we finish off the item by closing its div
$document->add(new Comment("</div>", FALSE));
}

# And that's a wrap
$document->add(new Comment("</div><!-- END Container for Items -->", FALSE));

} #END display function


public function getitem($itemname){
return new StockItem($itemname);
}

public function purchase(Item $item){
$mysidia = Registry::get("mysidia");
if($item->owner != $mysidia->user->username) Throw new NoPermissionException('Something is very very wrong, please contact an admin asap.');
else{
$item->quantity = $mysidia->input->post("quantity");
$cost = $item->getcost($this->salestax, $item->quantity);
$moneyleft = $mysidia->user->money - $cost;
if($moneyleft >= 0 and $item->quantity > 0){
$purchase = $item->append($item->quantity, $item->owner);
$mysidia->db->update("users", array("money" => $moneyleft), "username = '{$item->owner}'");
$status = TRUE;
}
else throw new InvalidActionException($mysidia->lang->money);
}
return $status;
}

public function rent($item, $period){

}

public function execute($action){

}

protected function save($field, $value){
$mysidia = Registry::get("mysidia");
$mysidia->db->update("shops", array($field => $value), "sid='{$this->sid}' and shoptype = 'adoptshop'");
}
}
?>
Please and thank you
Reply With Quote