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

List All Attachments Tab 1.7RC5

I have modified/created a list all attachments associated with thread [Tab] for 1.7RC5. If anyone is interested I can post the code.

Right now the [View Attachments] tab is with the control tabs at the bottom of the thread. I would like to see it moved to be with the [Ticket Thread] and [Internal Notes] tabs. I looked at doing this but there is a lot more work involved. If anyone has created a tab there please let me know, it would speed things up a lot.

Comments

  • Here is the code and screenshot

    #### Changes to include/class.ticket.php ####

    Add the following code after:

    function getAttachmentsLinks(){}


    Around line 650:

    //--- MOD: List All Attachments Tab, for 1.7RC5. by Tristan Novak, tbjnovak@gmail.com, 2-21-13 ---

    function getAllAttachments() {

    //XXX: inner join the file table instead?
    $sql='SELECT a.attach_id, f.id as file_id, f.size, f.hash as file_hash, f.name '
    .' FROM '.FILE_TABLE.' f '
    .' INNER JOIN '.TICKET_ATTACHMENT_TABLE.' a ON(f.id=a.file_id) '
    .' WHERE a.ticket_id='.db_input($this->getId());

    $attachments = array();
    if(($res=db_query($sql)) && db_num_rows($res)) {
    while($rec=db_fetch_array($res))
    $attachments[] = $rec;
    }

    return $attachments;
    }


    function getAllAttachmentsLinks($separator='<br>',$target='') {

    $str='';
    foreach($this->getAllAttachments() as $attachment ) {
    /* The has here can be changed but must match validation in attachment.php */
    $hash=md5($attachment['file_id'].session_id().$attachment['file_hash']);
    if($attachment['size'])
    $size=sprintf('<em>(%s)</em>', Format::file_size($attachment['size']));

    $str.=sprintf('<a class=\"Icon file\" href=\"attachment.php?id=%d&h=%s\" target=\"%s\">%s</a>%s&nbsp;%s',
    $attachment['attach_id'], $hash, $target, Format::htmlchars($attachment['name']), $size, $separator);
    }

    return $str;
    }
    //--- MOD: List All Attachments Tab, for 1.7RC5. by Tristan Novak, tbjnovak@gmail.com, 2-21-13 ---



    #### Changes to scp/ticket-view.inc.php ####

    Add after:

            if($thisstaff->canAssignTickets()) { ?>
    <li><a id=\"assign_tab\" href=\"#assign\"><?php echo $ticket->isAssigned()?'Reassign Ticket':'Assign Ticket'; ?></a></li>
    <?php
    } ?>


    Around line 377:

    // --- MOD: List All Attachments Tab, for 1.7RC5. by Tristan Novak, tbjnovak@gmail.com, 2-21-13 ---
    <?php
    if($ticket->checkAttachments()) {?>
    <li><a id=\"toggle_attachments_tab\" href=\"#\">View Attachments</a></li>
    <?php
    } ?>
    // --- MOD: List All Attachments Tab, for 1.7RC5. by Tristan Novak, tbjnovak@gmail.com, 2-21-13 ---


    Add after:

            </table>
    <p style=\"padding-left:165px;\">
    <input class=\"btn_sm\" type=\"submit\" value=\"<?php echo $ticket->isAssigned()?'Reassign':'Assign'; ?>\">
    <input class=\"btn_sm\" type=\"reset\" value=\"Reset\">
    </p>
    </form>
    <?php
    } ?>


    Around line 780:

    // --- MOD: List All Attachments Tab, for 1.7RC5. by Tristan Novak, tbjnovak@gmail.com, 2-21-13 ---
    <form id=\"attachments\" action=\"tickets.php?id=<?php echo $ticket->getId(); ?>#attachments\" name=\"attachments\" method=\"post\" enctype=\"multipart/form-data\">
    <?php csrf_token(); ?>
    <?php
    if($links=$ticket->getAllAttachmentsLinks()) {?>
    <tr>
    <td class=\"info\" colspan=\"2\"><?php echo $links; ?></td>
    </tr>
    <?php
    }?>
    </form>
    // --- MOD: List All Attachments Tab, for 1.7RC5. by Tristan Novak, tbjnovak@gmail.com, 2-21-13 ---
    view_attach.jpg
    1087 x 155 - 25K
    view_attach_2.jpg
    1019 x 451 - 57K
  • @tristannovak - With due respect, I think making mods for v1.7 RCx, at the moment, is a waste of time and effort. The code base is still in active development and may be substantially changed before it's packaged for a stable release. Case point is this particular mod - it won't work at all with the upcoming release candidate.

    If you're interested in contributing to osTicket development - I'll recommend doing so via gitHub or at least use a git repo so you can merge changes from upstream. I'm not guaranteeing that all pull requests will be accepted into the main repo - but at least you can get the conversation and ideas from other developers.
  • Have you tested this mod with 1.7.0? It's exactly what I've been looking for.

    Tyler
  • I have not tested this MOD with any other versions, I have only tested it with 1.7RC5. I'm sure it could be easily modified to work with other versions.
  • Alright I'll start playing with it and see what I can see. Thanks for the quick response.
  • edited November 2013
    Here's my version, only needs four changes to the view page, should work with all versions.. might even work with 1.8.. dunno, haven't tried.

    Basically, it is real simple:
    • Create an array
    • Put in the html that is already being generated by the thread (you can choose to NOT display it at the logical insertion point.. could be handy),
    • Simply add another heading for the tab
    • Display the contents of the array into the form as a table, using the exact generated html that osTicket uses for the inline attachments.


    Tab's display is dependant on the thread actually having attachments.


    diff --git a/osTicket1.7/upload/include/staff/ticket-view.inc.php b/osTicket1.7/upload/include/staff/ticket-view.inc.php
    index 1c10e98..a7f654b 100644
    --- a/osTicket1.7/upload/include/staff/ticket-view.inc.php
    +++ b/osTicket1.7/upload/include/staff/ticket-view.inc.php
    @@ -399,6 +399,8 @@
    }?>
    </div>
    <?php
    +/** MOD ATTACHMENTS TAB INITIALIZER */
    +$mod_attachments_tab = array();
    } ?>
    <div id=\"ticket_thread\">
    <?php
    @@ -429,7 +431,10 @@
    <?php
    if($entry['attachments']
    && ($tentry=$ticket->getThreadEntry($entry['id']))
    - && ($links=$tentry->getAttachmentsLinks())) {?>
    + && ($links=$tentry->getAttachmentsLinks())) {
    + /** MOD ATTACHMENTS TAB AGGREGATOR */
    + $mod_attachments_tab[] = $links;
    +?>
    <tr>
    <td class=\"info\" colspan=3><?php echo $links; ?></td>
    </tr>
    @@ -474,7 +479,11 @@
    if($thisstaff->canAssignTickets()) { ?>
    <li><a id=\"assign_tab\" href=\"#assign\"><?php echo $ticket->isAssigned()?'Reassign Ticket':'Assign Ticket'; ?></a></li>
    <?php
    - } ?>
    + }
    + if(count($mod_attachments_tab)>0){?>
    + <li><a id=\"attach_tab\" href=\"#attach\">Show Attachments</a></li>
    + <?php
    + }?>
    </ul>
    <?php
    if($thisstaff->canPostReply()) { ?>
    @@ -859,7 +868,21 @@
    </p>
    </form>
    <?php
    - } ?>
    + }
    + //MOD Attachments Tab START ------------------------- (well, see the array initializer above)
    + ?><form id=\"attach\" style=\"display:none;\">
    + <table border=\"0\" cellspacing=\"0\" cellpadding=\"3\">
    + <tr><td><h3>Attachments found in the thread: <?php echo count($mod_attachments_tab);?></h3></td></tr>
    +
    + <?php foreach ($mod_attachments_tab as $atm){
    + echo <<<MODATTACHMENTSTAB
    + <tr>
    + <td class=\"info\" colspan=3>$atm</td>
    + </tr>
    +MODATTACHMENTSTAB;
    + }?>
    + </table></form>
    + <?php //Mod Attachments tab END ----------------------------------------------------?>
    </div>
    <div style=\"display:none;\" class=\"dialog\" id=\"print-options\">
    <h3>Ticket Print Options</h3>


    Tested, works, YMMV

    From what I can tell, 1.8 generates the attachments in the same way, so this should still work.
    https://github.com/osTicket/osTicket-1.8/blob/develop/include/staff/ticket-view.inc.php
  • Where is the above code being added?
Sign In or Register to comment.