Announcement

Collapse
No announcement yet.

Showing PHP widget

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [CMS] Showing PHP widget

    Hi People.

    I run a website for microlight (ultralight pilots) and I have had written a PHP script for adding up times in a logbook.

    Please can someone spell out how I put it into a widget because I've just tried to configure one and it shows nothing in the page once enabled. Here is the code for the calculator.

    Please can you tell me what I need to do inside a widget to get it to work. I simply pasted the code below but that's obviously not right seeing that it doesn't work.

    On behalf of all the members, thanks in advance.

    PHP Code:
    <?php 
    /*  
    Name: Add Times Calculator 
    URI: http://dynainternet.com/logged.php 
    Description: Add multiple hours and minutes using whole or decimal numbers 
    Version: 2.4 
    Author: Jay Przekop (aka:Quick) 
    Author URI: http://dynainternet.com 
    License: GPL 
    */ 

    $hours $_POST['hour']; 
    $minutes $_POST['minute']; 

    if(
    $hours != '' || $minutes != '') { 

    $allhours array_sum(array_filter($hours)); 
    $explode_hours explode(".",$allhours); 
    $collect_hours $explode_hours['0']; 
    $collect_hours_decimal $explode_hours['1']; 
    $collect_hours_decimal substr(round($collect_hours_decimal,2),0,2); 
    if (
    $collect_hours_decimal != '') { 
    if(
    strlen($collect_hours_decimal) <= 1){ 
    $collect_hours_decimal $collect_hours_decimal *10

    $hours_dec_convert_minutes substr($collect_hours_decimal*60/100,0,2); 
    } else { 
    $hours_dec_convert_minutes 00


    $allminutes array_sum(array_filter($minutes));  

    $explode_minutes explode(".",$allminutes); 
    $collect_minutes_zero $explode_minutes['0']; 
    $collect_minutes_one $explode_minutes['1']; 

    $explode_seconds explode(".",$collect_minutes_one); 
    $collect_seconds_zero $explode_seconds['0']; 
    if(
    $collect_seconds_zero != ''){ 
    if(
    strlen($collect_seconds_zero) <= 1){ 
    $collect_seconds_zero $collect_seconds_zero *10

    $seconds_dec_convert_seconds substr($collect_seconds_zero 60/100,0,2); 
    } else { 
    $seconds_dec_convert_seconds $collect_seconds_zero


    $collect_minutes_one $seconds_dec_convert_seconds $collect_minutes_one

    if(
    $collect_minutes_one != ''){ 
    if(
    strlen($collect_minutes_one) <= 1){ 
    $collect_minutes_one $collect_minutes_one *10

    $minutes_dec_convert_minutes substr($collect_minutes_one*60/100,0,2); 
    } else { 
    $minutes_dec_convert_minutes $collect_minutes_one

    $add_allminutes $hours_dec_convert_minutes $collect_minutes_zero

    $hoursfromminutes floor($add_allminutes 60); 
    $deduct_amount 60 $hoursfromminutes
    $totalminutes $add_allminutes $deduct_amount
    $totalhours $collect_hours $hoursfromminutes


    ?> 

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <title>Add Times Calculator</title> 

    </head> 

    <body> 
    <h1>Logbook Calculator</h1><br />
    Put your figures into the boxes and click the Add button.<br />
    Now works if you put 0.75 into an hour box it adds it as 45 minutes.

    <form action="" method="post" enctype="multipart/form-data"> 
    <table style="color: #000000; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #c7f6d2;" width="501" border="1" cellspacing="5" cellpadding="5"> 

    <?php 
    //set this for how many input fields you want 
    $how_many_fields 12

    $input_field_array range(0,$how_many_fields -1); 

    foreach (
    $input_field_array as $input_number) { 
    echo 
    "<tr> 
        <td width='150'> 
        <input type='int' name='hour[]' value='
    $hours[$input_number]' size='20' maxlength='10' />  
          Hrs</td> 
        <td width='150'> 
        <input type='int' name='minute[]' value='
    $minutes[$input_number]' size='20' maxlength='10' />  
          Mins</td> 
      </tr> 
      <tr>"


    ?> 
       
      <tr> 
        <td><input style="height: 50px; width: 100px; color: #000000; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #34f325;" size="15" type="submit" name="submit" value="Add" />    <input type="button" style="height: 50px; width: 100px; color: #000000; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #87f87e;" size="100" value="Reset" onClick="location.href='<?php echo filter_var($_SERVER["SCRIPT_NAME"], FILTER_SANITIZE_STRING);?>'"></td> 
        <td><input value="<?php echo $totalhours;?>" type="int" size="20" maxlength="10" /> 
          Hrs 
          <input type="int" value="<?php echo $totalminutes;?>" size="20" maxlength="10" /> 
          Mins</td> 
      </tr> 
    </table> 
    <tr></tr> 
    </form>  
    </body> 
    </html>
     
    <!--/*<?php highlight_file('logged.php');?>*/ -->
    Regards
    Vince Gledhill
    Forum Administrator
    Microlight Forum

  • #2
    I rewrote some PHP for another guy last week, I might be able to help you out in the next day or two. One thing to mention, though, is that it has to be entirely PHP, and don't include the <?php and the beginning, or ?> at the end. Also, everything needs to be in a single $output at the end, so you'll need to build the output throughout the entire script, and then display it at the end. I should be able to get to it tonight after work, but that won't be for 14 hrs or so... If you do a search for my username and PHP evaluation, you will probably find the one I did last week as a go-by if you want to tackle it yourself.

    EDIT: Here, I'll save you the hassle of searching: http://www.vbulletin.com/forum/showt...-PHP-Eval-Page!

    Comment


    • #3
      Thanks bszopi

      I really am clueless. I looked at the thread you posted but can't see the wood for the trees. Me and my members would really appreciate a "fix"

      Thanks in advance.
      Regards
      Vince Gledhill
      Forum Administrator
      Microlight Forum

      Comment


      • #4
        I started looking at the code some, but haven't gotten too far. Just been looking during breaks at work. Seemed pretty straight forward until I got down to the form part. That may be simple as well, but until I can get it on my site and tested out, I can't be sure.

        Comment


        • #5
          Ok, I did this in a PHP Eval page instead of a widget, but see if it works for you in the widget. You may need to alter the file path for the log file as well. I haven't actually tested it, but the output on screen looks correct. For all I know, I doesn't function worth a damn, though. Anyway, let me know and I'll mess with it more if needed. Lunch break is over, so back to work!

          PHP Code:
          /*  
          Name: Add Times Calculator 
          URI: http://dynainternet.com/logged.php 
          Description: Add multiple hours and minutes using whole or decimal numbers 
          Version: 2.4 
          Author: Jay Przekop (aka:Quick) 
          Author URI: http://dynainternet.com 
          License: GPL 
          */ 

          $hours $_POST['hour']; 
          $minutes $_POST['minute']; 

          if(
          $hours != '' || $minutes != '') { 

          $allhours array_sum(array_filter($hours)); 
          $explode_hours explode(".",$allhours); 
          $collect_hours $explode_hours['0']; 
          $collect_hours_decimal $explode_hours['1']; 
          $collect_hours_decimal substr(round($collect_hours_decimal,2),0,2); 
          if (
          $collect_hours_decimal != '') { 
          if(
          strlen($collect_hours_decimal) <= 1){ 
          $collect_hours_decimal $collect_hours_decimal *10

          $hours_dec_convert_minutes substr($collect_hours_decimal*60/100,0,2); 
          } else { 
          $hours_dec_convert_minutes 00


          $allminutes array_sum(array_filter($minutes));  

          $explode_minutes explode(".",$allminutes); 
          $collect_minutes_zero $explode_minutes['0']; 
          $collect_minutes_one $explode_minutes['1']; 

          $explode_seconds explode(".",$collect_minutes_one); 
          $collect_seconds_zero $explode_seconds['0']; 
          if(
          $collect_seconds_zero != ''){ 
          if(
          strlen($collect_seconds_zero) <= 1){ 
          $collect_seconds_zero $collect_seconds_zero *10

          $seconds_dec_convert_seconds substr($collect_seconds_zero 60/100,0,2); 
          } else { 
          $seconds_dec_convert_seconds $collect_seconds_zero


          $collect_minutes_one $seconds_dec_convert_seconds $collect_minutes_one

          if(
          $collect_minutes_one != ''){ 
          if(
          strlen($collect_minutes_one) <= 1){ 
          $collect_minutes_one $collect_minutes_one *10

          $minutes_dec_convert_minutes substr($collect_minutes_one*60/100,0,2); 
          } else { 
          $minutes_dec_convert_minutes $collect_minutes_one

          $add_allminutes $hours_dec_convert_minutes $collect_minutes_zero

          $hoursfromminutes floor($add_allminutes 60); 
          $deduct_amount 60 $hoursfromminutes
          $totalminutes $add_allminutes $deduct_amount
          $totalhours $collect_hours $hoursfromminutes



          $string "<h1>Logbook Calculator</h1><br />";
          $string .= "Put your figures into the boxes and click the Add button.<br />";
          $string .= "Now works if you put 0.75 into an hour box it adds it as 45 minutes.";

          $string .= "<form action='' method='post' enctype='multipart/form-data'>";

          $string .= "<table style='color: #000000; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #c7f6d2;' width='501' border='1' cellspacing='5' cellpadding='5'>";

          //set this for how many input fields you want 
          $how_many_fields 12

          $input_field_array range(0,$how_many_fields -1); 

          foreach (
          $input_field_array as $input_number) { 
          $string .= "<tr>";
          $string .= "<td width='150'>"
          $string .= "<input type='int' name='hour[]' value='$hours[$input_number]' size='20' maxlength='10' /> Hrs</td>"
          $string .= "<td width='150'>"
          $string .= "<input type='int' name='minute[]' value='$minutes[$input_number]' size='20' maxlength='10' /> Mins</td>";
          $string .= "</tr>"
          $string .= "<tr>"

             
          $string .= "<tr>"
          $string .= "<td><input style='height: 50px; width: 100px; color: #000000; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #34f325;' size='15' type='submit' name='submit' value='Add' />";
          $string .= "<input type='button' style='height: 50px; width: 100px; color: #000000; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #87f87e;' size='100' value='Reset' onClick='location.href=" filter_var($_SERVER["SCRIPT_NAME"], FILTER_SANITIZE_STRING) . "'></td>";
          $string .= "<td><input type='int' size='20' maxlength='10' value=" $totalhours "> Hrs";
          $string .= "<input type='int' size='20' maxlength='10' value=" $totalminutes "> Mins</td>";
          $string .= "</tr>"
          $string .= "</table>"
          $string .= "<tr></tr>";

          $string .= "</form>";
           
          highlight_file('logged.php');
          $output $string

          Comment


          • #6
            Thanks for your work bszopi.

            It shows up in the widget now but when I click the button to do the adding up I get the following error message...

            Your submission could not be processed because a security token was missing.

            If this occurred unexpectedly, please inform the administrator and describe the action you performed before you received this error.
            Regards
            Vince Gledhill
            Forum Administrator
            Microlight Forum

            Comment


            • #7
              Ok, after some searching, I solved the security token issue.

              FIND
              PHP Code:
              $string .= "</form>";
               
              highlight_file('logged.php');
              $output $string
              BEFORE, Insert the following:
              PHP Code:
              $string .= "<input type='hidden' name='securitytoken' value=" $securitytoken vb::$vbulletin->userinfo['securitytoken'] . ">"
              It still doesn't seem to be doing anything for me, but that might be because I don't have the logged.php file. Anyway, check that out and let me know how it goes again.

              Comment


              • #8
                Hi bszopi.

                Thanks again for your input. I'm not getting the error anymore, but the calculator doesn't work. I put my figures in the boxes and click "add" and it clears it out instead of adding it up. The highlight_file('logged.php'); can be removed altogether. This was so that it outputted the whole of itself (as code) after you clicked add. It was put in there by the original writer of the script for me to copy and paste.

                See here clicking the add simply re-sets it.
                Regards
                Vince Gledhill
                Forum Administrator
                Microlight Forum

                Comment


                • #9
                  Yeah, I noticed that, just wasn't sure if it had anything to do with the logged.php file. With that said, I'll look at it some more...

                  Comment


                  • #10
                    Thanks mate, I really do appreciate it. I'll be glad when I can tell the users it works. :-)
                    Regards
                    Vince Gledhill
                    Forum Administrator
                    Microlight Forum

                    Comment


                    • #11
                      This may take a better programmer than I to get to work. Since everything is being rendered via the $output, I'm not sure it can actually do the addition of the hours inside of the widget. In order to get the form to display, you need to render it (via $output), but that is the last bit of the widget. I just don't see a way to get it to display everything, and then go back and do the calculation, then display everything again.

                      Still looking though...

                      Comment


                      • #12
                        Why can't the "php" widget work with "php" that's stupid.
                        Regards
                        Vince Gledhill
                        Forum Administrator
                        Microlight Forum

                        Comment


                        • #13
                          The php widget processes php, you're already in another application (vBulletin). For more help with modifications please see vbulletin.org

                          Comment


                          • #14
                            I wouldn't really consider trying to use PHP inside a PHP widget as being a modification. You'd think there would be a way to have a form that returns something after user input using this method, but perhaps not. I'm not done looking yet, though.

                            Comment


                            • #15
                              It is a modification in the sense that is not default code. We don't support third party proudcts/plugins/code as a whole. This includes: html, css, php, javascript, etc modifications to the code.

                              Comment

                              widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                              Working...
                              X