• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: PHP i User Defined Tag
PostPosted: Sun Jul 24, 2011 11:57 am 
Offline
Forum Members
Forum Members

Joined: Sat Jun 23, 2007 6:23 pm
Posts: 40
Jag har till och från provat att skapa en UDT med innehållande php kod men har endast lyckats med en test echo.

Jag har en spel relaterad "kalkylator" som fungerar i självständig fil. Men så fort jag stoppar in koden i en UDT (utan <?php ?>) så syns inte ett skit. Jag provade även med att kalla på filen genom en include(), med full URL. Fungerar inte heller.

Vad kan jag göra för att använda php med detta cms?


Top
 Profile  
 
 Post subject: Re: PHP i User Defined Tag
PostPosted: Sun Jul 24, 2011 7:13 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Sun Jun 22, 2008 5:33 am
Posts: 315
Location: Sweden
Hallilådär!

Det ska fungera att posta din fil i UDT för att sedan anropa den via {din_udt}

Skulle du kunna posta din fil här?

/Coldman

_________________
Important How To Submit a Question So You'll Actually Get Help
Why don't use CMSMS Docs or search?
Do you read Help?
Admin for Swedish Translations Team
Moderator Swedish Forum
After your problem is solved add [Solved] in the subject


Top
 Profile  
 
 Post subject: Re: PHP i User Defined Tag
PostPosted: Mon Jul 25, 2011 3:51 pm 
Offline
Forum Members
Forum Members

Joined: Sat Jun 23, 2007 6:23 pm
Posts: 40
Hej!
Jag klistrade in följande kod. Jag upptäckte dock ett mindre fel som dock bara märks om man skickar formuläret utan data. Felmeddelandet vill inte alltid synas. Men det är mitt minsta problem just nu.

Code:
/*

Created: 18 July 2011

*/

// If the form hasn't been submitted the form is displayed.
if ($_SERVER['REQUEST_METHOD'] != 'POST')
{
   $notSent = $_SERVER['PHP_SELF'];
   include('../database/php_oop/view/jadinko_calcform.htm');
}
else
{
   $sent = $_POST;
   $object = new Jadinko();
   $object->calculation($sent);
}

// Here starts the Jadinko class.
class Jadinko
{
   // A multidimensional array storing name of jadinkos, experience and levels.
   private $jadinko = array
   (
      array( Name => "Common", Exp => 350, Lvl => 70),
      array( Name => "Shadow", Exp => 475, Lvl => 71),
      array( Name => "Igneous", Exp => 465, Lvl => 74),
      array( Name => "Cannibal", Exp => 475, Lvl => 75),
      array( Name => "Aquatic", Exp => 475, Lvl => 76),
      array( Name => "Amphibian", Exp => 485, Lvl => 77),
      array( Name => "Carrion", Exp => 505, Lvl => 78),
      array( Name => "Diseased", Exp => 580.5, Lvl => 78),
      array( Name => "Camoflaged", Exp => 600, Lvl => 79),
      array( Name => "Draconic", Exp => 525, Lvl => 80),
      array( Name => "Saradomin", Exp => 600, Lvl => 81),
      array( Name => "Guthix", Exp => 600, Lvl => 81),
      array( Name => "Zamorak", Exp => 600, Lvl => 81)
   );

   // Level array with experience.
   private $exp = array
   (
      "70"=>737627, "71"=>814445, "72"=>899257, "73"=>992895, "74"=>1096278, "75"=>1210421, "76"=>1336443, "77"=>1475581, "78"=>1629200, "79"=>1798808,
      "80"=>1986068, "81"=>2192818, "82"=>2421087, "83"=>2673114, "84"=>2951373, "85"=>3258594, "86"=>3597792, "87"=>3972294, "88"=>4385776, "89"=>4842295,
      "90"=>5346332, "91"=>5902831, "92"=>6517253, "93"=>7195629, "94"=>7944614, "95"=>8771558, "96"=>9684577, "97"=>10692629, "98"=>11805606, "99"=>13034431
   );
   
   // Lists the array contents in a dropdown menu.
   public function listLevels()
   {
      echo '<option value="">Level</option>';

      foreach ($this->exp as $num => $value)
      {
         echo '<option value="' . $value . '">' . $num . '</option>';
      }
   }
   
   // The form values are checked for numeric values. If they are not, an error message is printed.
   // If the values are numeric, they are checked for
   public function calculation($var)
   {
      $currExp = stripslashes($var['currentxp']);
      $currLevel = stripslashes($var['currentlvl']);
      $goalExp = stripslashes($var['goalxp']);
      $goalLevel = stripslashes($var['goallvl']);
      
      // If nothing has been added to the form, an error message is echoed.
      if (!(isset($currExp) && isset($currLevel) && isset($goalExp) && isset($goalLevel)))
      {
         include('../database/php_oop/view/jadinko_calcform.htm');
         echo '<p>You have to make a choice for the calculator to work.</p>';
      }
      // If current exp and goal exp has been filled in, data is sent to corresponding function.
      elseif ($currExp && $goalExp)
      {
         $this->currExpGoalExp($currExp, $goalExp);
      }
      // ...else, if current exp and goal level has been filled in, data is sent to corresponding function.
      elseif ($currExp && $goalLevel)
      {
         $this->currExpGoalLvl($currExp, $goalLevel);
      }
      // ...else, if current level and goal exp has been filled in, data is sent to corresponding function.
      elseif ($currLevel && $goalExp)
      {
         $this->currLvlGoalExp($currLevel, $goalExp);
      }
      // ...else, if current level and goal level has been filled in, data is sent to corresponding function.
      elseif (($currLevel != null) && ($goalLevel != null))
      {
         $this->currLvlGoalLvl($currLevel, $goalLevel);
      }
   }
   
   // Loops through the multidim. jadinko array and prints name, level and $difference divided by jadinko xp.
   // The result is rounded down to two decimals.
   public function forLoopWithTable($leftover)
   {
      include('../database/php_oop/view/jadinko_calcform.htm');
      echo '<p></p><table><tr><td>Type</td><td>Level</td><td>Iterations</td></tr>';
      
      for ($row = 0; $row < count($this->jadinko); $row++)
      {
         echo '<tr><td>', $this->jadinko[$row]["Name"], '</td><td>', $this->jadinko[$row]["Lvl"], '</td><td>', round($leftover / $this->jadinko[$row]["Exp"], 2), '</td></tr>';
      }
      echo '</table>';
   }
   
   // Current xp and goal xp are collected, the difference is calculated and is sent to forLoopWithTable().
   public function currExpGoalExp($varCurrExp, $varGoalExp)
   {
      $difference = $varGoalExp - $varCurrExp;
      $this->forLoopWithTable($difference);
   }
   
   // Current xp and goal level are collected, the difference is calculated and is sent to forLoopWithTable().
   public function currExpGoalLvl($varCurrExp, $varGoalLvl)
   {
      $difference = $varGoalLvl - $varCurrExp;
      $this->forLoopWithTable($difference);
   }
   
   // Current level and goal xp are collected, the difference is calculated and is sent to forLoopWithTable().
   public function currLvlGoalExp($varCurrLvl, $varGoalExp)
   {
      $difference = $varGoalExp - $varCurrLvl;
      $this->forLoopWithTable($difference);
   }
   
   // Current level and goal level are collected, the difference is calculated and is sent to forLoopWithTable().
   public function currLvlGoalLvl($varCurrLvl, $varGoalLvl)
   {
      $difference = $varGoalLvl - $varCurrLvl;
      $this->forLoopWithTable($difference);
   }
}


Top
 Profile  
 
 Post subject: Re: PHP i User Defined Tag
PostPosted: Mon Jul 25, 2011 6:12 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Sun Jun 22, 2008 5:33 am
Posts: 315
Location: Sweden
Kan det vara så enkelt att du behöver ange hela sökvägen till includefilen och inte bara

Code:
include('../database/php_oop/view/jadinko_calcform.htm');

_________________
Important How To Submit a Question So You'll Actually Get Help
Why don't use CMSMS Docs or search?
Do you read Help?
Admin for Swedish Translations Team
Moderator Swedish Forum
After your problem is solved add [Solved] in the subject


Top
 Profile  
 
 Post subject: Re: PHP i User Defined Tag
PostPosted: Fri Jul 29, 2011 8:30 pm 
Offline
Forum Members
Forum Members

Joined: Sat Jun 23, 2007 6:23 pm
Posts: 40
Jag har provat att både ändra alla URLer i den kod som klistrades in, och att endast använda en include() med full URL som kallar på filen men inget fungerar.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting