Jump to content

Recommended Posts

Hi Folks

 

There is a bit of code I am struggling to grasp. It is used to print a range of data based on a custom date range.

function print_log_selector_form_range($selectedfromdate='today', $selectedtodate='today', $logformat='showashtml') {

    global $USER, $CFG;

    $strftimedate = get_string("strftimedate");

    $strftimedaydate = get_string("strftimedaydate");

    // Prepare the list of action options.

    $actions = array(

        'view' => get_string('view'),

        'add' => get_string('add'),

        'update' => get_string('update'),

        'delete' => get_string('delete'),

        '-view' => get_string('allchanges')

    );


    // Get all the possible dates

    // Note that we are keeping track of real (GMT) time and user time

    // User time is only used in displays - all calcs and passing is GMT

    $timenow = time(); // GMT

    //echo "<br />";    

    // What day is it now for the user, and when is midnight that day (in GMT).

    $timemidnight = $today = usergetmidnight($timenow);

    //echo "<br />";    

    // Put today up the top of the list

    $dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) );

    $numdates = 1;

    while ($timemidnight > $COURSE->startdate and $numdates < 365) {

        $timemidnight = $timemidnight - 86400;

        $timenow = $timenow - 86400;

        $dates["$timemidnight"] = userdate($timenow, $strftimedaydate);

        $numdates++;

    }

    if ($selecteddate == "today") {

        $selecteddate = $today;

    }

    echo "<form class=\"logselectform\" action=\"$CFG->wwwroot/admin/report/mentorprogress/index.php\" method=\"get\">\n";

    echo "<div>\n";

    echo "<input type=\"hidden\" name=\"chooselog\" value=\"1\" />\n";
    

  // echo html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);

//choose_from_menu ($dates, "fromdate", $selectedfromdate, get_string("alldays"));

//~ print "<pre>";

//~ print_r($dates);

//~ print "</pre>";

    echo $selectedfromdate;

    echo "<br />";    

    echo $selectedtodate;

    echo "<br />";    

  echo  html_writer::select($dates, "fromdate",$selectedfromdate, get_string("alldays"));

   // choose_from_menu ($dates, "todate", $selectedtodate, get_string("alldays"));

   echo html_writer::select($dates,"todate",$selectedtodate, get_string("alldays"));

    $logformats = array('showashtml' => get_string('displayonpage'),

                        'downloadasexcel' => get_string('downloadexcel'));

    //choose_from_menu ($logformats, 'logformat', $logformat, false);

   echo html_writer::select($logformats, 'logformat', $logformat, false);

    echo '<input type="submit" value="'.get_string('gettheselogs').'" />';

    echo '</div>';

    echo '</form>';

}

This function above is in lib.php, and is called from index.php via this function:

//echo $fromdate;
//echo $todate;
 
print_log_selector_form_range($fromdate, $todate, $logformat);
 
//echo $fromdate;
//echo $todate; 

if($logformat == 'showashtml'){
            
        print_overview_table($users, $fromdate, $todate);
        
    } 

I check the dates before and after this function is called and the dates remain at zero, even after selecting valid date ranges. By printing the array to screen I can see that the $dates array has valid entries.

 

The function "print_overview_table" below "print_log_selector_form_range" is supposed to print the valid range to the screen.

function print_overview_table($users, $fromdate, $todate){

    //check data

    if(!$users){

        die('No Records To Display.');

    }   

    //$users = get_mentor_users($DB, $fromdate, $todate, $sumpcat);

    //~ print "<pre>";

    //~ print_r($users);

    //~ print "</pre>";
     

    //start table

    echo '<br><br><table class="logtable generalbox boxaligncenter" width="95%" border="1" cellspacing="0" cellpadding="5" style="padding:2px;">';

    //add report name

    echo '<tr><td colspan="5">Admin Report - Mentor Marking Progress</td></tr>';

    //add report headings

    echo '<tr>

    <th>Mentor</th>

    <th>Total Summative marked</th>

    <th>Competent</th>

    <th>Not Yet Competent</th>

      </tr>';
  
    //populate
   
    //foreach($users as $user){

    foreach($users as $key => $user)

    {
       
/*[id] => 2

            [totalmarked] => 1

            [totalcommarked] => 1

            [totalsummarked] => 0

            [markedcompetent] => 1

            [markedincompetent] => 0

 *

 */
      

        echo '<tr>';
      
        //echo "<td><a href=\"viewdash.php?mentor=$user->id&todate=$todate&fromdate=$fromdate\">", get_mentor_name($DB, $users[$key]->id),"</a></td>";

        echo "<td><a href=\"viewdash.php?mentor=$user->id&todate=$todate&fromdate=$fromdate\">", $users[$key]->firstname ,' ',$users[$key]->lastname,"</a></td>";
       
        echo "<td>",$users[$key]->totalsummarked,"</td>";

        echo "<td>",$users[$key]->markedcompetent,"</td>";

        echo "<td>",$users[$key]->markedincompetent,"</td>";

        echo '</tr>';
       
    }
   
    //end table

    echo '</table><br><br>';

}

When a user submits the date ranges the page goes blank.

 

Can anyone give me some pointers to fix this.

Link to comment
https://forums.phpfreaks.com/topic/287408-form-usage-in-php/
Share on other sites

Right off the top, I don't see where you're declaring $selecteddate. You've got $selectedfromdate and $selectedtodate as parameters of print_log_selector_form_range(), but there's a content check on $selecteddate that doesn't exist. I don't see where else it's used in the function either, but I haven't had my third cup of coffee yet this morning.

 

Add error_reporting(-1); to the top of your index page and see what it has to say.

Link to comment
https://forums.phpfreaks.com/topic/287408-form-usage-in-php/#findComment-1474492
Share on other sites

Inserted the following at the top of both index.php and lib.php.

error_reporting(E_ALL | E_STRICT);

  ini_set("display_errors", 1);

No errors pop up when submitting values but page still goes blank.

 

SIDE NOTE: If no values are input, the report shows all mentors and how far they have marked, but as soon as date ranges are set, and submitted, the page goes blank.

 

NOTE: $selecteddate can safely be ignored, since it is not used in index.php or lib.php.

 

After selecting date range and clicking "Get these logs", the page url shows:

http://"something.com"/admin/report/mentorprogress/index.php?chooselog=1&fromdate=1394748000&todate=1396216800&logformat=showashtml 

Then on the page


	Not Found
The requested URL /admin/report/mentorprogress/index.php was not found on this server.


	Apache Server at "something.com" Port 80

Only thing is that index.php does exist. Full code for both files included.

 

mentor.zip

Link to comment
https://forums.phpfreaks.com/topic/287408-form-usage-in-php/#findComment-1474512
Share on other sites

Only manually while testing. I have printed the entire date array to screen, and I get valid results as below. If there is a better way to check, would appreciate some pointers.

Array
(
    [1396735200] => Today, 6 April 2014
    [1396648800] => Saturday, 5 April 2014
    [1396562400] => Friday, 4 April 2014
    [1396476000] => Thursday, 3 April 2014
    [1396389600] => Wednesday, 2 April 2014
    [1396303200] => Tuesday, 1 April 2014
    [1396216800] => Monday, 31 March 2014
    [1396130400] => Sunday, 30 March 2014
    [1396044000] => Saturday, 29 March 2014
    [1395957600] => Friday, 28 March 2014
    [1395871200] => Thursday, 27 March 2014
    [1395784800] => Wednesday, 26 March 2014
    [1395698400] => Tuesday, 25 March 2014
    [1395612000] => Monday, 24 March 2014
    [1395525600] => Sunday, 23 March 2014
    [1395439200] => Saturday, 22 March 2014
    [1395352800] => Friday, 21 March 2014
    [1395266400] => Thursday, 20 March 2014
    [1395180000] => Wednesday, 19 March 2014
    [1395093600] => Tuesday, 18 March 2014
    [1395007200] => Monday, 17 March 2014
    [1394920800] => Sunday, 16 March 2014
    [1394834400] => Saturday, 15 March 2014
    [1394748000] => Friday, 14 March 2014
    [1394661600] => Thursday, 13 March 2014
    [1394575200] => Wednesday, 12 March 2014
    [1394488800] => Tuesday, 11 March 2014
    [1394402400] => Monday, 10 March 2014
    [1394316000] => Sunday, 9 March 2014
    [1394229600] => Saturday, 8 March 2014
    [1394143200] => Friday, 7 March 2014
    [1394056800] => Thursday, 6 March 2014
    [1393970400] => Wednesday, 5 March 2014
    [1393884000] => Tuesday, 4 March 2014
    [1393797600] => Monday, 3 March 2014
    [1393711200] => Sunday, 2 March 2014
    [1393624800] => Saturday, 1 March 2014
    [1393538400] => Friday, 28 February 2014
    [1393452000] => Thursday, 27 February 2014
    [1393365600] => Wednesday, 26 February 2014
    [1393279200] => Tuesday, 25 February 2014
    [1393192800] => Monday, 24 February 2014
    [1393106400] => Sunday, 23 February 2014
    [1393020000] => Saturday, 22 February 2014
    [1392933600] => Friday, 21 February 2014
    [1392847200] => Thursday, 20 February 2014
    [1392760800] => Wednesday, 19 February 2014
    [1392674400] => Tuesday, 18 February 2014
    [1392588000] => Monday, 17 February 2014
    [1392501600] => Sunday, 16 February 2014
    [1392415200] => Saturday, 15 February 2014
    [1392328800] => Friday, 14 February 2014
    [1392242400] => Thursday, 13 February 2014
    [1392156000] => Wednesday, 12 February 2014
    [1392069600] => Tuesday, 11 February 2014
    [1391983200] => Monday, 10 February 2014
    [1391896800] => Sunday, 9 February 2014
    [1391810400] => Saturday, 8 February 2014
    [1391724000] => Friday, 7 February 2014
    [1391637600] => Thursday, 6 February 2014
    [1391551200] => Wednesday, 5 February 2014
    [1391464800] => Tuesday, 4 February 2014
    [1391378400] => Monday, 3 February 2014
    [1391292000] => Sunday, 2 February 2014
    [1391205600] => Saturday, 1 February 2014
    [1391119200] => Friday, 31 January 2014
    [1391032800] => Thursday, 30 January 2014
    [1390946400] => Wednesday, 29 January 2014
    [1390860000] => Tuesday, 28 January 2014
    [1390773600] => Monday, 27 January 2014
    [1390687200] => Sunday, 26 January 2014
    [1390600800] => Saturday, 25 January 2014
    [1390514400] => Friday, 24 January 2014
    [1390428000] => Thursday, 23 January 2014
    [1390341600] => Wednesday, 22 January 2014
    [1390255200] => Tuesday, 21 January 2014
    [1390168800] => Monday, 20 January 2014
    [1390082400] => Sunday, 19 January 2014
    [1389996000] => Saturday, 18 January 2014
    [1389909600] => Friday, 17 January 2014
    [1389823200] => Thursday, 16 January 2014
    [1389736800] => Wednesday, 15 January 2014
    [1389650400] => Tuesday, 14 January 2014
    [1389564000] => Monday, 13 January 2014
    [1389477600] => Sunday, 12 January 2014
    [1389391200] => Saturday, 11 January 2014
    [1389304800] => Friday, 10 January 2014
    [1389218400] => Thursday, 9 January 2014
    [1389132000] => Wednesday, 8 January 2014
    [1389045600] => Tuesday, 7 January 2014
    [1388959200] => Monday, 6 January 2014
    [1388872800] => Sunday, 5 January 2014
    [1388786400] => Saturday, 4 January 2014
    [1388700000] => Friday, 3 January 2014
    [1388613600] => Thursday, 2 January 2014
    [1388527200] => Wednesday, 1 January 2014
    [1388440800] => Tuesday, 31 December 2013
    [1388354400] => Monday, 30 December 2013
    [1388268000] => Sunday, 29 December 2013
    [1388181600] => Saturday, 28 December 2013
    [1388095200] => Friday, 27 December 2013
    [1388008800] => Thursday, 26 December 2013
    [1387922400] => Wednesday, 25 December 2013
    [1387836000] => Tuesday, 24 December 2013
    [1387749600] => Monday, 23 December 2013
    [1387663200] => Sunday, 22 December 2013
    [1387576800] => Saturday, 21 December 2013
    [1387490400] => Friday, 20 December 2013
    [1387404000] => Thursday, 19 December 2013
    [1387317600] => Wednesday, 18 December 2013
    [1387231200] => Tuesday, 17 December 2013
    [1387144800] => Monday, 16 December 2013
    [1387058400] => Sunday, 15 December 2013
    [1386972000] => Saturday, 14 December 2013
    [1386885600] => Friday, 13 December 2013
    [1386799200] => Thursday, 12 December 2013
    [1386712800] => Wednesday, 11 December 2013
    [1386626400] => Tuesday, 10 December 2013
    [1386540000] => Monday, 9 December 2013
    [1386453600] => Sunday, 8 December 2013
    [1386367200] => Saturday, 7 December 2013
    [1386280800] => Friday, 6 December 2013
    [1386194400] => Thursday, 5 December 2013
    [1386108000] => Wednesday, 4 December 2013
    [1386021600] => Tuesday, 3 December 2013
    [1385935200] => Monday, 2 December 2013
    [1385848800] => Sunday, 1 December 2013
    [1385762400] => Saturday, 30 November 2013
    [1385676000] => Friday, 29 November 2013
    [1385589600] => Thursday, 28 November 2013
    [1385503200] => Wednesday, 27 November 2013
    [1385416800] => Tuesday, 26 November 2013
    [1385330400] => Monday, 25 November 2013
    [1385244000] => Sunday, 24 November 2013
    [1385157600] => Saturday, 23 November 2013
    [1385071200] => Friday, 22 November 2013
    [1384984800] => Thursday, 21 November 2013
    [1384898400] => Wednesday, 20 November 2013
    [1384812000] => Tuesday, 19 November 2013
    [1384725600] => Monday, 18 November 2013
    [1384639200] => Sunday, 17 November 2013
    [1384552800] => Saturday, 16 November 2013
    [1384466400] => Friday, 15 November 2013
    [1384380000] => Thursday, 14 November 2013
    [1384293600] => Wednesday, 13 November 2013
    [1384207200] => Tuesday, 12 November 2013
    [1384120800] => Monday, 11 November 2013
    [1384034400] => Sunday, 10 November 2013
    [1383948000] => Saturday, 9 November 2013
    [1383861600] => Friday, 8 November 2013
    [1383775200] => Thursday, 7 November 2013
    [1383688800] => Wednesday, 6 November 2013
    [1383602400] => Tuesday, 5 November 2013
    [1383516000] => Monday, 4 November 2013
    [1383429600] => Sunday, 3 November 2013
    [1383343200] => Saturday, 2 November 2013
    [1383256800] => Friday, 1 November 2013
    [1383170400] => Thursday, 31 October 2013
    [1383084000] => Wednesday, 30 October 2013
    [1382997600] => Tuesday, 29 October 2013
    [1382911200] => Monday, 28 October 2013
    [1382824800] => Sunday, 27 October 2013
    [1382738400] => Saturday, 26 October 2013
    [1382652000] => Friday, 25 October 2013
    [1382565600] => Thursday, 24 October 2013
    [1382479200] => Wednesday, 23 October 2013
    [1382392800] => Tuesday, 22 October 2013
    [1382306400] => Monday, 21 October 2013
    [1382220000] => Sunday, 20 October 2013
    [1382133600] => Saturday, 19 October 2013
    [1382047200] => Friday, 18 October 2013
    [1381960800] => Thursday, 17 October 2013
    [1381874400] => Wednesday, 16 October 2013
    [1381788000] => Tuesday, 15 October 2013
    [1381701600] => Monday, 14 October 2013
    [1381615200] => Sunday, 13 October 2013
    [1381528800] => Saturday, 12 October 2013
    [1381442400] => Friday, 11 October 2013
    [1381356000] => Thursday, 10 October 2013
    [1381269600] => Wednesday, 9 October 2013
    [1381183200] => Tuesday, 8 October 2013
    [1381096800] => Monday, 7 October 2013
    [1381010400] => Sunday, 6 October 2013
    [1380924000] => Saturday, 5 October 2013
    [1380837600] => Friday, 4 October 2013
    [1380751200] => Thursday, 3 October 2013
    [1380664800] => Wednesday, 2 October 2013
    [1380578400] => Tuesday, 1 October 2013
    [1380492000] => Monday, 30 September 2013
    [1380405600] => Sunday, 29 September 2013
    [1380319200] => Saturday, 28 September 2013
    [1380232800] => Friday, 27 September 2013
    [1380146400] => Thursday, 26 September 2013
    [1380060000] => Wednesday, 25 September 2013
    [1379973600] => Tuesday, 24 September 2013
    [1379887200] => Monday, 23 September 2013
    [1379800800] => Sunday, 22 September 2013
    [1379714400] => Saturday, 21 September 2013
    [1379628000] => Friday, 20 September 2013
    [1379541600] => Thursday, 19 September 2013
    [1379455200] => Wednesday, 18 September 2013
    [1379368800] => Tuesday, 17 September 2013
    [1379282400] => Monday, 16 September 2013
    [1379196000] => Sunday, 15 September 2013
    [1379109600] => Saturday, 14 September 2013
    [1379023200] => Friday, 13 September 2013
    [1378936800] => Thursday, 12 September 2013
    [1378850400] => Wednesday, 11 September 2013
    [1378764000] => Tuesday, 10 September 2013
    [1378677600] => Monday, 9 September 2013
    [1378591200] => Sunday, 8 September 2013
    [1378504800] => Saturday, 7 September 2013
    [1378418400] => Friday, 6 September 2013
    [1378332000] => Thursday, 5 September 2013
    [1378245600] => Wednesday, 4 September 2013
    [1378159200] => Tuesday, 3 September 2013
    [1378072800] => Monday, 2 September 2013
    [1377986400] => Sunday, 1 September 2013
    [1377900000] => Saturday, 31 August 2013
    [1377813600] => Friday, 30 August 2013
    [1377727200] => Thursday, 29 August 2013
    [1377640800] => Wednesday, 28 August 2013
    [1377554400] => Tuesday, 27 August 2013
    [1377468000] => Monday, 26 August 2013
    [1377381600] => Sunday, 25 August 2013
    [1377295200] => Saturday, 24 August 2013
    [1377208800] => Friday, 23 August 2013
    [1377122400] => Thursday, 22 August 2013
    [1377036000] => Wednesday, 21 August 2013
    [1376949600] => Tuesday, 20 August 2013
    [1376863200] => Monday, 19 August 2013
    [1376776800] => Sunday, 18 August 2013
    [1376690400] => Saturday, 17 August 2013
    [1376604000] => Friday, 16 August 2013
    [1376517600] => Thursday, 15 August 2013
    [1376431200] => Wednesday, 14 August 2013
    [1376344800] => Tuesday, 13 August 2013
    [1376258400] => Monday, 12 August 2013
    [1376172000] => Sunday, 11 August 2013
    [1376085600] => Saturday, 10 August 2013
    [1375999200] => Friday, 9 August 2013
    [1375912800] => Thursday, 8 August 2013
    [1375826400] => Wednesday, 7 August 2013
    [1375740000] => Tuesday, 6 August 2013
    [1375653600] => Monday, 5 August 2013
    [1375567200] => Sunday, 4 August 2013
    [1375480800] => Saturday, 3 August 2013
    [1375394400] => Friday, 2 August 2013
    [1375308000] => Thursday, 1 August 2013
    [1375221600] => Wednesday, 31 July 2013
    [1375135200] => Tuesday, 30 July 2013
    [1375048800] => Monday, 29 July 2013
    [1374962400] => Sunday, 28 July 2013
    [1374876000] => Saturday, 27 July 2013
    [1374789600] => Friday, 26 July 2013
    [1374703200] => Thursday, 25 July 2013
    [1374616800] => Wednesday, 24 July 2013
    [1374530400] => Tuesday, 23 July 2013
)
Edited by huck
Link to comment
https://forums.phpfreaks.com/topic/287408-form-usage-in-php/#findComment-1475108
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.