View Single Post
  #3  
Old 03-16-2013, 12:56 PM
Isura Isura is offline
Member
 
Join Date: Jun 2011
Posts: 38
Gender: Female
Credits: 8,132
Isura is on a distinguished road
Default

The file 'abstract_appcontroller.php' is in the classes/abstract folder.

Here is the code from the adopt.php (I didn't change anything):

PHP Code:
<?php

class ACPadopt extends AppController{

    public static 
$param "type";
    private 
$actions = array("index""add""edit""delete");
    private 
$flags;
    private 
$subController;
    
    public function 
__construct(){
        
parent::__construct();
        
$mysidia Registry::find("mysidia");
        if(
$mysidia->usergroup->getpermission("canmanageadopts") != "yes"){
            throw new 
NoPermissionException("You do not have permission to manage adoptables.");
        }
        elseif(!
in_array($mysidia->input->action(), $this->actions)){
            throw new 
InvalidActionException("Invalid Action.");
        }        
    }

    public function 
index(){
        
// The default action for ACPadopt controller.
        
$mysidia Registry::find("mysidia");
        
$mysidia->page->settitle($mysidia->lang->default_title);
        
$mysidia->page->addcontent($mysidia->lang->default);        
    }

    public function 
add(){
        
// The action of creating a new adoptable!
        
$mysidia Registry::find("mysidia");
        
        if(
$mysidia->input->post("submit")){
            
// The form has been submitted, it's time to validate data and add a record to database.
            
if($mysidia->session->fetch("acpAdopt") != "add"){
                
$mysidia->displayerror("session");
                return 
FALSE;
            }
            
            if(!
$mysidia->input->post("type")) $this->flags $mysidia->lang->type;
            elseif(!
$mysidia->input->post("class")) $this->flags $mysidia->lang->class;
            elseif(!
$mysidia->input->post("imageurl") and $mysidia->input->post("existingimageurl") == "none"$this->flags $mysidia->lang->image;
            elseif(
$mysidia->input->post("imageurl") and $mysidia->input->post("existingimageurl") != "none"$this->flags $mysidia->lang->image2;
            elseif(!
$mysidia->input->post("cba")) $this->flags $mysidia->lang->condition;
            
            if(
$mysidia->input->post("cba") == "conditions"){
                if(
$mysidia->input->post("freqcond") == "enabled" and !is_numeric($mysidia->input->post("number"))) $this->flags $mysidia->lang->condition_freq;
                if(
$mysidia->input->post("datecond") == "enabled" and !$mysidia->input->post("date")) $this->flags $mysidia->lang->condition_date;
                if(
$mysidia->input->post("adoptscond") == "enabled"){
                   if(!
$mysidia->input->post("moreless") or !is_numeric($mysidia->input->post("morelessnum")) or !$mysidia->input->post("levelgrle") or !is_numeric($mysidia->input->post("grlelevel"))) $this->flags $mysidia->lang->condition_moreandlevel;
                }

                if(
$mysidia->input->post("maxnumcond") == "enabled" and !is_numeric($mysidia->input->post("morethannum"))) $this->flags $mysidia->lang->maxnum;
                if(
$mysidia->input->post("usergroupcond") == "enabled" and !is_numeric($mysidia->input->post("usergroups"))) $this->flags $mysidia->lang->group;
            }

            if(
$mysidia->input->post("alternates") == "enabled") {
                if(!
is_numeric($mysidia->input->post("altoutlevel")) or !is_numeric($mysidia->input->post("altchance"))) $this->flags $mysidia->lang->alternate;
            }
            
$type_exist $mysidia->db->select("adoptables", array("type"), "type = '{$name}'")->fetchColumn();
            if(
$type_exist$this->flags $mysidia->lang->exist;
            if(
$this->flags){
                
$mysidia->page->addcontent($this->flags);
                
header("Refresh:3; URL='index'");
                return 
FALSE;
            }    
            
            
$eggimage = ($mysidia->input->post("imageurl") and $mysidia->input->post("existingimageurl") == "none")?$mysidia->input->post("imageurl"):$mysidia->input->post("existingimageurl");
            
// insert into table adoptables
            
$mysidia->db->insert("adoptables", array("id" => NULL"type" => $mysidia->input->post("type"), "class" => $mysidia->input->post("class"), "description" => $mysidia->input->post("description"), "eggimage" => $eggimage"whenisavail" => $mysidia->input->post("cba"),
                                                     
"alternates" => $mysidia->input->post("alternates"), "altoutlevel" => $mysidia->input->post("altoutlevel"), "altchance" => $mysidia->input->post("altchance"), "shop" => $mysidia->input->post("shop"), "cost" => $mysidia->input->post("cost")));
                
            
// insert into table adoptables_conditions    
            
$mysidia->db->insert("adoptables_conditions", array("id" => NULL"type" => $mysidia->input->post("type"), "whenisavail" => $mysidia->input->post("cba"), "freqcond" => $mysidia->input->post("freqcond"), "number" => $mysidia->input->post("numbwe"), "datecond" => $mysidia->input->post("datecond"),
                                                                
"date" => $mysidia->input->post("date"), "adoptscond" => $mysidia->input->post("adoptscond"), "moreless" => $mysidia->input->post("maxnumcond"), "morelessnum" => $mysidia->input->post("morethannum"), "levelgrle" => $mysidia->input->post("usergroupcond"), "grlelevel" => $mysidia->input->post("usergroups")));
                
            
// insert our level thing
            
$mysidia->db->insert("levels", array("lvid" => NULL"adoptiename" => $mysidia->input->post("type"), "thisislevel" => 0"requiredclicks" => 0,
                                                 
"primaryimage" => $eggimage"alternateimage" => NULL"rewarduser" => NULL"promocode" => NULL));
            
$mysidia->session->terminate("acpAdopt");
            
$mysidia->page->settitle($mysidia->lang->added_title);
            
$mysidia->page->addcontent($mysidia->lang->added);
            return 
TRUE;
        }
        
$mysidia->session->assign("acpAdopt""add"TRUE);    
        
$mysidia->page->settitle($mysidia->lang->add_title);
        
$mysidia->page->addcontent($mysidia->lang->add);        
        
$dynimages getadmimages();
        
        
$addform_basic "<form name='form1' method='post' action='add'>
                          <p><u><strong>Create A New Adoptable:</strong></u></p>
                          <fieldset><legend>Basic Information</legend> 
                          <p>Adoptable Name: <input name='type' type='text' id='type'><br />
                          (This may contain only letters, numbers and spaces)
                          </p><p>Adoptable Class:<input name='class' type='text' id='class'>
                          <br />(The adoptable class is a category that determines if two adoptables can interbreed or not)</p>
                          <p>Adoptable Description:</p><p>
                          <textarea name='description' cols='45' rows='4' id='description'></textarea></p>                          
                          <p>Adoptable's Egg (First) Image: <input name='imageurl' type='text' id='imageurl'><br />
                          (Use a full image path, beginning with http://)</p>
                          <p>OR select an existing image: 
                          <select name='existingimageurl' id='existingimageurl'><option value='none' selected>No Existing Image</option>
{$dynimages}</select></fieldset>";
        
        
$addform_shop "<fieldset><legend>Shop Settings</legend><p>Shop:
                         <select name='shop' id='shop'><option value='none' selected>No Shop Selected</option>"
;  
        
$stmt $mysidia->db->select("shops", array(), "shoptype = 'adoptshop'");
        while(
$shop $stmt->fetchObject()){
            
$addform_shop .= "<option value='{$shop->shopname}'>{$shop->shopname}</option>";    
        }
        
$addform_shop .= "</select></p><p>Price: <input name='cost' type='text' id='cost' value='0'></p></fieldset>";
        
        
$addform_condition "</p><fieldset><legend>Adoption Conditions</legend> 
                              <p>When can this adoptable be adopted?</p><p>
                              <input name='cba' type='radio' value='always'>Always available<br />
                              <input name='cba' type='radio' value='promo'>Only when users use promo code: (Admins can create promocodes for users through ACP) <br />
                              <input name='cba' type='radio' value='conditions'>Only when the following conditions are met: (Check the check box next to a condition to enable it)</p>
                              <p><input name='freqcond' type='checkbox' id='freqcond' value='enabled'>The adoptable has not been adopted more than 
                              <input name='number' type='text' id='number' size='6' maxlength='6'>times.</p>
                              <p><input name='datecond' type='checkbox' id='datecond' value='enabled'>The date is: 
                              <input name='date' type='text' id='date'>(For the date, use this format: Year-Month-Day. So, as an example: 2009-06-28)</p>
                              <p><input name='maxnumcond' type='checkbox' id='maxnumcond' value='enabled'>The user does not have more than 
                              <input name='morethannum' type='text' id='morethannum' size='5' maxlength='5'>of this type of adoptable</p>
                              <p><input name='usergroupcond' type='checkbox' id='usergroupcond' value='enabled'>The user is a member of the following usergroup: 
                              <select name='usergroups' id='usergroups'><option value='none' selected>No Group Selected</option>"
;
        
$stmt $mysidia->db->select("groups", array());
        while(
$group $stmt->fetchObject()){
            
$addform_condition .= "<option value='{$group->gid}'>{$group->groupname}</option>";    
        }
        
$addform_condition .= "</select></p></fieldset>";
        
        
$addform_miscellaneous "<fieldset><legend>Alternative Outcomes</legend>
                                  <p>This section allows you to set if you want to enable alternate outcomes. 
                                   This setting allows you to specify what the chances are of a user getting an alternate or special version of this adoptable. 
                                   Check the checkbox below to enable this feature and then fill out the information below.. </p>
                                   <p><strong><input name='alternates' type='checkbox' id='alternates' value='enabled'>
                                   Enable Alternate Outcomes</strong></p>
                                   <p> Alternate Outcomes Selection Information:</p><p>
                                   Start using the alternate outcome at level number: <input name='altoutlevel' type='text' id='altoutlevel' size='6' maxlength='6'>
                                   <br />(Use Level 0 to have the alternate outcome be used from birth. This will not affect the first / egg image.)</p>
                                   <p>The alternate outcome has a chance of 1 in <input name='altchance' type='text' id='altchance' size='6' maxlength='6'>of being selected.<br />
                                   (Here you can select the chance that the alternate images for this adoptable are used. 
                                   So, for an equal chance of using say male or female images, put 2 in the box to have a 1 out of 2 or 50% chance of using the alternate image. 
                                   If you want to have the alternate images be rare images, use a higher number, 
                                   like 100 for a 1 out of 100 chance of using the alternates.)</p></fieldset>
                                   <p><input name='page' type='hidden' id='page' value='adopt'>
                                   <input name='action' type='hidden' id='action' value='add'>
                                   <input type='submit' name='submit' value='Create This Adoptable'></p></form>"
;                                   
        
$mysidia->page->addcontent($addform_basic.$addform_shop.$addform_condition.$addform_miscellaneous);
    }

    public function 
edit(){
        
$mysidia Registry::find("mysidia");
        if(!
$mysidia->input->post("choose")){
            
$mysidia->page->settitle($mysidia->lang->edit_title);
            
$mysidia->page->addcontent($mysidia->lang->edit);
            
$editform "<form name='form1' method='post' action='edit'><p>
                         <select name='type' id='type'><option value='select' selected>Select an Adoptable...</option>"
;

            
//Now we select from the database and get a list of all the adoptables we have created thus far...
            
$stmt $mysidia->db->select("adoptables", array());
            while(
$row $stmt->fetchObject()){
                
$editform .= "<option value='{$row->type}'>{$row->type}</option>";    
            }

            
$editform .= "</select></p><p><input name='page' type='hidden' id='page' value='adopt'>
                          <input name='action' type='hidden' id='action' value='edit'>
                          <input type='submit' name='choose' value='Choose'></p></form>"
;
            
$mysidia->page->addcontent($editform);              
        }
        elseif(
$mysidia->input->post("submit")){
            
// A form has been submitted, time to carry out out action.
            
if($mysidia->session->fetch("acpAdopt") != "edit"){
                
$mysidia->displayerror("session");
                return 
FALSE;
            }
            elseif(
$mysidia->input->post("delete") == "yes"){
                switch(
$mysidia->input->post("deltype")){
                    case 
"freeze":
                        
$mysidia->db->update("adoptables", array("whenisavail" => "promo"), "type='{$mysidia->input->post("type")}'");
                        
$mysidia->db->update("adoptables_conditions", array("whenisavail" => "promo"), "type='{$mysidia->input->post("type")}'");
                        break;
                    case 
"soft":
                         
$mysidia->db->update("owned_adoptables", array("currentlevel" => 1), "type='{$mysidia->input->post("type")}' AND currentlevel='0'");
                        
$mysidia->db->delete("adoptables""type='{$mysidia->input->post("type")}'");
                        
$mysidia->db->delete("adoptables_conditions""type='{$mysidia->input->post("type")}'");    
                        break;
                    case 
"hard":
                        
$mysidia->db->delete("owned_adoptables""type='{$mysidia->input->post("type")}'");
                        
$mysidia->db->delete("levels""adoptiename='{$mysidia->input->post("type")}'");
                        
$mysidia->db->delete("adoptables""type='{$mysidia->input->post("type")}'");
                        
$mysidia->db->delete("adoptables_conditions""type='{$mysidia->input->post("type")}'");
                        break;
                    default:
                        throw new 
Exception("database error.");
                }
                
$contentvar $mysidia->input->post("deltype");
                
$titlevar "{$contentvar}_title";
                
$mysidia->page->settitle($mysidia->lang->{$titlevar});
                
$mysidia->page->addcontent($mysidia->lang->{$contentvar});
            }
            else{
                if(
$mysidia->input->post("select") != "" and $mysidia->input->post("select") != "nochange"){
                    
// We are updating the adoptable's image in the database...
                    
$mysidia->db->update("adoptables", array("eggimage" => $mysidia->input->post("select")), "type='{$mysidia->input->post("type")}'");
                }
                if(
$mysidia->input->post("resetconds") == "yes"){
                    
// Let's remove all of the restrictions from this adoptable
                    
$mysidia->db->update("adoptables", array("whenisavail" => 'always'), "type='{$mysidia->input->post("type")}'");
                    
$mysidia->db->update("adoptables_conditions", array("whenisavail" => 'always'), "type='{$mysidia->input->post("type")}'");
                }
                if(
$mysidia->input->post("resetdate") == "yes" and $mysidia->input->post("date")){
                    
// We are resetting only the adoption based date restriction...
                    
$mysidia->db->update("adoptables", array("whenisavail" => "conditions"), "type='{$mysidia->input->post("type")}'");
                    
$mysidia->db->update("adoptables_conditions", array("whenisavail" => "conditions""datecond" => "enabled""date" => $mysidia->input->post("date")), "type='{$mysidia->input->post("type")}'");
                }
                
$mysidia->page->settitle($mysidia->lang->edited_title);
                
$mysidia->page->addcontent($mysidia->lang->edited);
            }
        }
        else{
            
$stmt $mysidia->db->select("adoptables", array(), "type='{$mysidia->input->post("type")}'");                        
            if(
$row $stmt->fetchObject()){
                
$mysidia->session->assign("acpAdopt""edit"TRUE);            
                if(
$row->whenisavail != "always" and $row->whenisavail != ""$availtxt "<b>This adoptable currently has adoption restrictions on it.</b>";
                else 
$availtxt "This adoptable currently does not have adoption restrictions on it.";
                
$dynimages getadmimages();

                
$mysidia->page->settitle($mysidia->lang->edit_adopt);
                
$editform "<img src='{$row->eggimage}'><br />This page allows you to edit {$mysidia->input->post("type")}.  Use the form below to edit (or delete) {$more}.<br />
                             <form name='form1' method='post' action='edit'>
                             <p><u><strong>Egg Image: </strong></u></p>
                             <p>If you wish to change the egg image for this adoptable, you may do so below. </p>
                             <p>Select a New Egg Image: 
                             <select name='select'><option value='nochange' selected>Do Not Change</option>
{$dynimages}</select></p>
                             <p><u><strong>Adoptable Freeze and Delete Settings: </strong></u></p>
                             <p><input name='delete' type='checkbox' id='delete' value='yes'>
                             <strong>I want to delete or freeze this adoptable </strong></p>
                             <p>What sort of delete do you wish to perform for this adoptable?</p>
                             <p><input name='deltype' type='radio' value='freeze'> 
                                    Freeze Deletion - This will not delete the adoptable, 
                                    but will freeze it to all new adoptions by members of your site. 
                                    You can undo this by checking the <em>Remove all adoption conditions from this adoptable</em> 
                                    checkbox the next time you edit this adoptable. </p>
                            <p><input name='deltype' type='radio' value='soft'> 
                                    Soft Delete (Adoptable Retirement) - This option will do a 
                                    soft delete of this adoptable from your system. 
                                    Selecting this option will remove the egg image level for this adoptable from your system. 
                                    Any users who have this type of adoptable as an egg will have them automatically 
                                    leveled up to Level 1 for this adoptable type. 
                                    This option closes the adoptable to new adoptions, but will not affect 
                                    users who already adopted this creature. 
                                    Note that once you do a soft delete you will no longer be able to edit 
                                    the levels associated with that adoptable, 
                                    so think about this carefully. </p>
                            <p><input name='deltype' type='radio' value='hard'>
                                    Hard Deletion (Purge) - This option will permanentally delete this adoptable from your site. 
                                    Any users currently using this adoptable will have it deleted by the system. 
                                    All levels for this adoptable will be purged. <strong>This cannot be undone! </strong></p>
                            <p><u><strong>Adoptable Adoption Conditions: </strong></u></p><p>
{$availtxt}</p>
                            <p><input name='resetconds' type='checkbox' id='resetconds' value='yes'> 
                                <strong>Remove all adoption conditions from this adoptable. </strong>
                                    - This will remove all restrictions on the adoption of this creature, including promo codes.</p>
                            <p><input name='resetdate' type='checkbox' id='resetdate' value='yes'>Reset only the date condition for this adoptable to the following value:</p>
                            <p><input name='date' type='text' id='date'>(Ex: 2009-06-28)</p>
                            <p>This setting allows you to change the date that an adoptable is available to a new date. 
                            This is handy if you only want the adoptable to be available certain times in a given year.
                            <input name='page' type='hidden' id='page' value='adopt'><input name='action' type='hidden' id='action' value='edit'>
                            <input name='choose' type='hidden' value='Choose'><input name='type' type='hidden' id='type' value='
{$row->type}'></p>
                            <p><input type='submit' name='submit' value='Submit Changes'></p></form>"
;
                
$mysidia->page->addcontent($editform);            
            }
            else{
                
// Adoptable doesn't exist...
                
$mysidia->page->settitle($mysidia->lang->notexist_title);
                
$mysidia->page->addcontent($mysidia->lang->notexist);
            }
        }
    }

    public function 
delete(){
        
// leave blank for now.
    
}    
}
?>
__________________
Reply With Quote