ATutor

Learning Management Tools







Pages:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15


Putting a Preview link on the question editing pages


  • 2009-05-23 00:21:48

    Putting a Preview link on the question editing pages

    Hello. I have 1.6.2 installed and I'm trying to edit the question editing pages to put a "Preview" link there.

    I have this code so far, but I can't seem to get it to take the question ID w/ it. Any ideas?

    Code....
    <a href="<?php echo AT_BASE_HREF.'tools/tests/preview_question.php?$qid='.$ids; ?>" > Preview</a>


    Thanks!

  • 2009-05-23 07:57:25

    Re: Putting a

    Hi,

    Try using

    [purple]$this->row['question_id'][/purple]

    instead of

    [purple]$ids[/purple]

  • 2009-05-23 08:01:44

    Re: Putting a

    Or [purple]$qid[/purple].

  • 2009-05-23 12:50:46

    Re: Putting a

    Indie,

    Thanks for responding

    Using...

    <a href="<?php echo AT_BASE_HREF.'tools/tests/preview_question.php?$qid='.$this->row['question_id']; ?>" > Preview</a>

    Produced this error...

    <a href="
    Fatal error: Using $this when not in object context in /hermes/bosweb/web142/b1426/ez.liveonlinemathnet/ATutor/tools/tests/edit_question_multi.php on line 174


    Using...

    <a href="<?php echo AT_BASE_HREF.'tools/tests/preview_question.php?$qid='.$qid; ?>" > Preview</a>

    Produced this error...

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web142/b1426/ez.liveonlinemathnet/ATutor/tools/tests/preview_question.php on line 42


    However, using the $qid method did "take the question ID into the address bar". I'm not a programmer so I don't know how to say it. For example, basically it routed me to...

    http://www.liveonlinemath.com/ATutor/tools/tests/preview_question.php?$qid=9

    whereas without the $qid I was routed to...

    http://www.liveonlinemath.com/ATutor/tools/tests/preview_question.php?$qid=


    Any other ideas?

    Thanks.

  • 2009-05-23 17:58:26

    Re: Putting a

    Just noticed: you have and extra dollar sign in the address bar.
    The code fragment should look like
    [green]<a href="<?php echo AT_BASE_HREF.'tools/tests/preview_question.php?qid='.$qid; ?>" > Preview</a>[/green]
    instead of
    [red]<a href="<?php echo AT_BASE_HREF.'tools/tests/preview_question.php?[b]$[/b]qid='.$qid; ?>" > Preview</a>[/red]

  • 2009-05-23 20:01:32

    Perfect!

    Thanks Indie!

    I worked around the code a little more and your solution worked perfectly. Now I have a "Preview" button on the quesiton editing page.

    I've attached the edit_question_multi.php file if you'd like to see how I did it, or incorporate it into your own ATutor software.

    Thanks again.

  • 2009-05-23 20:01:51

    Re: Perfect!

    If you are asking for help, provide lots of detail so problems can be reproduced.

    Things to describe:
    Operating system ATutor is installed on -
    ATutor version -
    Patch #s applied -
    ATutor theme name -
    PHP version -
    MySQL version -
    Webserver & version -
    Copies of error messages -
    Changes to default settings -
    Web browser being used -
    ...and anything else relevant -

  • 2009-05-24 00:25:21

    One more thing.....

    I'm trying to create the same effect in create_question_multi.php. When I change "question_db.php" to anything else in:

    $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
    header('Location: question_db.php');
    exit;

    I get:

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web142/b1426/ez.liveonlinemathnet/ATutor/tools/tests/preview_question.php on line 42


    Any ideas on this one?

    Thanks again for the help.

  • 2009-05-24 02:49:14

    Re: One more thing.....

    You're welcome.

    As to the last post, it's most likely that the $qid variable is not set yet at the point where you try to use it.
    Assuming the changes are the same as in edit_question_multi.php, it may be fixed by adding the line
    [green]$qid = mysql_insert_id($db);[/green]
    after
    [purple]$result = mysql_query($sql, $db);[/purple]

  • 2009-05-24 18:52:31

    Re: One more thing... (again)

    Indie,

    Thanks for your help so far. Your suggestion worked perfectly!

    The final piece of what I want to do is, after previewing the question, easily get back to editing it. I've thought of two ways to do this, but I haven't been successful in either.......

    1.) Add a "Edit" button to preview_question.php that would take you to the proper edit_question_XXX.php page. I tried inserting...

    } else if (isset($_GET['edit'])) {
    $id = current($_GET['questions']);
    $num_selected = count($id);

    if ($num_selected == 1) {
    $ids = explode('|', $id[0], 2);
    $o = TestQuestions::getQuestion($ids[1]);
    if ($name = $o->getPrefix()) {
    header[red] ('Location: '.AT_BASE_HREF.'tools/tests/edit_question_'.$name.'.php?qid='.intval($ids[0])) [/red];
    exit;
    } else {
    header('Location: '.AT_BASE_HREF.'tools/tests/index.php');
    exit;
    }
    }

    from question_db.php, but I couldn't get it to work.


    2.) Add a "back" button to preview_question.php. However, that wil only take you back to create_question_xxx.php. My idea is to add code to create_question_xxx.php (with a button to activate it) that mirrors the code from edit_question_xxx.php that posts the information to the database.

    Any further ideas on either of these? I think #1 would probably be easier, but I just couldn't get it to work.

    Thanks again for the help.

  • 2009-05-25 05:45:34

    Re: One more thing... (again)

    Hi,

    Yeah, I expected that to be the next question. :)
    You might try something like this:
    [green]<input type="button" name="back" value="Back" onclick="history.back(1);" />[/green]

  • 2009-05-25 11:37:00

    Re: One more thing... (again)

    Great minds think alike? :D

    I actually already did that. The problem is that it takes you back to the create_question_xxx.php file instead of edit_question_xxx.php.

    The more I think about it, the more it seems that option 1 (that I listed above) would be easier. I just can't get the syntax to work.

    Does what I have in option 1 look reasonable to you?

    Thanks again.

  • 2009-05-25 17:36:28

    Re: One more thing... (again)

    Right, going back client-side won't do it.

    The fragment in option 1 doesn't work because you copied it from a different file with completely different data structures. That's why there's no such thing as $_GET['questions'] there -- consequently, it doesn't work.
    Try to figure out which data you have available in each case and how they differ -- that's a good first step when making such changes.

    In preview_question.php you should be using the object stored in $obj variable inside the loop. So, the right starting point would be:
    [green]
    if ($name = $obj->getPrefix()) {
    header('Location: '.AT_BASE_HREF.'tools/tests/edit_question_'.$name.'.php?qid='.$row['question_id'];
    exit;
    }
    [/green]
    You'll probably need a separate "Edit" button near each question, so you'll have to edit the code accordingly; however, the general approach to getting the right URL remains the same.

  • 2009-05-26 00:28:48

    Re: One more thing... (again)

    Ok. I'm not good at PHP as all, and I'm not a programmer, so I'm trying to follow what you're saying but I'm just not getting it.

    Here's what I tried and it didn't work (I got a 500 internal server error).

    In preview_question.php, under:

    if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
    $content_base_href = 'get.php/';
    } else {
    $content_base_href = 'content/' . $_SESSION['course_id'] . '/';
    }


    I put:

    //Added for "Edit Question" button

    if (isset($_GET['edit'])) {
    $msg->addError('NO_ITEM_SELECTED');
    } else if ($name = $obj->getPrefix()) {
    header('Location: '.AT_BASE_HREF.'tools/tests/edit_question_'.$name.'.php?qid='.$row['question_id'];
    exit;
    }

    //End added


    And above:

    <div class="row buttons"><input type="submit" name="submit" value="<?php echo _AT('back'); ?>"/></div>

    I put:

    <div class="row buttons"><input type="submit" name="edit" value="Edit Question"/></div>


    If you're tired of weighing in on this, I understand. And if I'm not even close, then don't worry about it.

    Thanks for your continued help.

  • 2009-05-27 02:48:57

    Re: One more thing... (again)

    I'm always glad to help getting the most out of ATutor. Just got too little time for that lately.

    You're moving in the right direction. Unfortunately, it seems it would be easier to write the working code than to explain all of the details, and right now I haven't got time for that. I guess you could seek for someone else's assistance; or, I believe I'll be available again in mid-June.

    I'm sorry for that. The change is not all too complex, I believe you'll easily find someone to make it if you need it right now.

  • 2009-05-27 09:50:23

    Re: One more thing... (again)

    No worries Indie. There's no rush on this.

    I'll reply to this post again in mid-June and I would greatly appreciate help with getting this implemented.

  • 2009-06-16 11:33:48

    Re: One more thing... (again)

    Indie,

    Just wondering if you had time to pick this up again.

    If not, then no problem.

    Thanks!

  • 2009-06-18 16:48:32

    Re: One more thing... (again)

    Hi,

    Sorry to say that, but summer seems to really be the hottest season this year -- got to embark on a third trip in a row.
    So right now I can't may any predictions as to when I'll be available again.