Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

Subtopics on v1.10

Hi everyone im trying to edit the code on open.inc.php file, where the help topics display but i cannot create properly a new dropdown list when i find a sub topic. What I do is to find by strtok() function the slashes '/' and add a new dropdown but im not very good at coding. When i choose the subtopic dropdown my ticket creates with the 'father' topic id.
This is my code so far. Can anybody help me explain what does the sprint codeline do? or help me implement the request? my osTicket version is the latest release

<td colspan="2">
            <select id="topicId" name="topicId" onchange="javascript:
                    var data = $(':input[name]', '#dynamic-form').serialize();
                    $.ajax(
                      'ajax.php/form/help-topic/' + this.value,
                      {
                        data: data,
                        dataType: 'json',
                        success: function(json) {
                          $('#dynamic-form').empty().append(json.html);
                          $(document.head).append(json.media);
                        }
                      });">
                <option value="" selected="selected">&mdash; <?php echo __('Select a Help Topic');?> &mdash;</option>
                <?php
                if($topics=Topic::getPublicHelpTopics()) {
                    foreach($topics as $id =>$name) {

                        if ((10%$id ==10)&&($id%10!==0)) { //only show the subtopics on new select tag
                            $token =$name;
                            $token=strtok($name, '/');
                                echo sprintf('</select><select>');
                            while ($token!==false) {//show all subtopics
                                echo sprintf('<option value="%d" %s>%s</option>',
                                $id, ($info['topicId']==$id)?'selected="selected"':'', $token);
                                $token=strtok('/');
                            }
                            echo sprintf('</select>');
                        }else{//no subtopics, normal topics printing on option tag
                            echo sprintf('<option value="%d" %s>%s</option>',
                            $id, ($info['topicId']==$id)?'selected="selected"':'', $name);
                            echo sprintf('</select>');
                        }
                    }
                } else { ?>
                    <option value="0" ><?php echo __('General Inquiry');?></option>
                <?php
                } echo sprintf('</select>');?>
           
            <font class="error">*&nbsp;<?php echo $errors['topicId']; ?></font>
        </td>


Thanks!

Comments

  • I found a post from another user on Dec. 2014
    here
    @Suntas had already found the solution, the problem is that is developed on several past versions ( 1.9.4) so I will try to fix the code in order to find a solution update for the new version of osticket.
    Greetings!
    (Any help would be very useful).
    This was his code in case its down the link, its all @Suntas work, not mine and if you try it, other pages on the system will not be visible so be careful on file management.
    osticket1602.zip
    9K
  • The sprintf() command takes the first parameter and inserts the values of the additional parameters into it. In this case,

    sprintf(
        '<option value="%d" %s>%s</option>',
        $id,
        ($info['topicId'] == $id) ? 'selected="selected"' : '',
        $token
    )

    (I've modified the formatting to make it easier for me to read and emphasize the individual parameters.)

    • replaces the %d in the value attribute with the value of $id
    • replaces %s in the option element's opening tag with 'selected="selected"' if $info['topicId'] is equal to $id (otherwise it replaces it with an empty string)
    • replaces the %s between the opening and closing tag of the option element with the value of $token

    %d indicates that $id is presented as an integer, while %s indicates that the other values are presented as strings.

  • Thanks @mwhitney i figured out how to achieve the task, so new fields can be added as the front end of the page detects sub topics just by adapting the @Suntas work on the new version and it works awesome!
    I'll leave the screenshot of what im talking about, if anyone needs more information, please feel free to ask me
    Greetings!
    osticket.PNG
    843 x 704 - 31K
  • Looking at the code you posted earlier, in case you used any of it directly, note that the getHelpTopicsTicket() method in the Topic class appears to be ignoring the $publicOnly and $disabled arguments. The added $niveles variable stores the data retrieved from the database, but isn't modified in the loop that applies the filters before the data is returned. (Plus, this means the method is doing all of that work to apply the filters for no reason.)

    I am interested in a solution to do something like this. So far, this has been helpful in pointing me in the right direction.
Sign In or Register to comment.