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

view image attachments

small mod for viewing image attachments (often screenshots) in the admin panel

ive changed the existing function getAttachmentStr
to whats below,

    
function getAttachmentStr($refid,$type){
$sql ='SELECT attach_id,file_size,file_name,file_key FROM '.TICKET_ATTACHMENT_TABLE.
' WHERE deleted=0 AND ticket_id='.db_input($this->getId()).' AND ref_id='.db_input($refid).' AND ref_type='.db_input($type);
$res=db_query($sql);
if($res && db_num_rows($res)){
while(list($id,$size,$name,$key)=db_fetch_row($res)){
$hash=MD5($this->getId()*$refid.session_id());
$size=Format::file_size($size);
$ext = substr(strrchr($name, '.'), 1);
$image = (in_array($ext,array('jpg','png','gif'))) ? '<img src=\"/support/attachments/'.$key.'_'.$name.'\" />' : '';
$attachstr.= \"<a class='Icon file' href='attachment.php?id=$id&ref=$hash' target='_blank'><b>$name</b></a>&nbsp;(<i>$size</i>)&nbsp;&nbsp;\" . $image;
}
}
return ($attachstr);
}

Comments

  • Works! Now I can see attachments in the control panel, good mod!
  • Umm thanks for letting us know which file to edit :)
  • Ok works perfect! But, today all people use screenshot with big resolution. How we can establish the resolution for show 60x480? Because if show a 1024x768 maeby the aspect is terrible.

    Where we can establish the width and height?

    Regards

    Eduardo
  • ../include/class.ticket.php
  • So instead of trying to download and then open the attachment in the default program, it will open it in the browser? Is that what it will do?
  • show images clickable - open in new window

    I just changed the function so the images are clickable and will be shown in a new window.

         function getAttachmentStr($refid,$type){
    $sql ='SELECT attach_id,file_size,file_name,file_key FROM '.TICKET_ATTACHMENT_TABLE.
    ' WHERE deleted=0 AND ticket_id='.db_input($this->getId()).' AND ref_id='.db_input($refid).' AND ref_type='.db_input($type);
    $res=db_query($sql);
    if($res && db_num_rows($res)){
    while(list($id,$size,$name,$key)=db_fetch_row($res)){
    $hash=MD5($this->getId()*$refid.session_id());
    $size=Format::file_size($size);
    $ext = substr(strrchr($name, '.'), 1);
    $image = (in_array($ext,array('jpg','png','gif'))) ? '<a target=_blank href=\"/support/attachments/'.$key.'_'.$name.'\"><img width=550 src=\"/support/attachments/'.$key.'_'.$name.'\" /></a>' : '';
    $attachstr.= \"<a class='Icon file' href='attachment.php?id=$id&ref=$hash' target='_blank'><b>$name</b></a>&nbsp;(<i>$size</i>)&nbsp;&nbsp;\" . $image;
    }
    }
    return ($attachstr);
    }


    osTicket is really awesome.
    Thanks
    Mario
    www.labor-c.net
  • Is it possible to display it inside of the ticket but if the image is bigger than the width of the osTicket template layout it should be resized to this size and after a click on it you can view it in a new window in 100%?
  • DaSilva,

    Yes, it is. There is always a possibility to do that. :rolleyes:

    Here is the solution:
    View Image Attachment in osTicket v1.6 RC5

    Hope it helps you.

    Sincerely,
    Masino Sinaga
  • Great, thanks a lot!
  • masino_sinaga;11048 said:
    DaSilva,

    Here is the solution:
    View Image Attachment in osTicket v1.6 RC5

    Hi!
    Nice mod, but it doesnt work in my system :(

    The image-urls are broken. It wants to open
    website.com/subfolder/osticket//9B035B6BFA28A00_screenshot2.JPG

    but the url should be

    website.com/subfolder/osticket/upload/9B035B6BFA28A00_screenshot2.JPG

    My upload dir is

    /var/www/virtual/website.com/htdocs/subfolder/osticket/upload/
  • Solution

    @royale,

    Please change your upload directory setting from Admin Panel -> Attachments -> Attachment Folder, from:
    /var/www/virtual/website.com/htdocs/subfolder/osticket/upload/


    become:
    /var/www/virtual/website.com/htdocs/subfolder/osticket/upload


    In other words, make sure you do not add the slash at the end of it.

    Sincerely,
    Masino Sinaga
  • Thanks, now it works great :)))
  • nice one :D

    but if you want to keep the upload folder,
    modified this line :
    $attachstr.= "$name ($size)  ";


    by this line :

    $attachstr.= "image
    &nbsp &nbsp &nbsp &nbsp &nbsp$name
     ($size)  ";
  • hi
    Thanks for the MOD

    In my uploads folder, there is another folder called "1011"
    this is where my uploads are in. i am not sure why it is there but i assume its for "Oct 2011" hence 1011.

    If i move my uploads out of this folder the mod works fine. at the moment htey do not.

    Any ideas why the 1011 folder has appeared and how to prevent it forming.

    Thanks
    Peter
  • Lightbox and date on folder issue

    @thunderstorm

    Here is the code with the date issue resolved. I also added the "lightbox" class to the URL to have the images pop up in a lightbox rather than a blank page. If you want them to appear in a blank page just add the "target=_blank" to the URL.




    // Modified by Masino Sinaga, last updated: November 5, 2009
    // in order to display image properly inside the ticket area
    // especially if the image's width greater than 820 px, then
    // resize the image's width maximum to 820 px.
    //Ed Barahona Ed@newmediahaus.com 10/28/2011 updates:
    //Fixed the Date issue with URlS
    //Added JQuery-lightbox class to URL's

    function getAttachmentStr($refid,$type){
    global $cfg;
    $helpdesk_url=$cfg->getUrl();
    $dir=$cfg->getUploadDir();
    $dir = preg_replace(\"/\\\\/\",\"/\",$dir);
    $dir = explode('/', $dir);
    $arrDir = array_reverse($dir);
    $dir = $arrDir[0];
    $sql ='SELECT attach_id,file_size,file_name,file_key FROM '.TICKET_ATTACHMENT_TABLE.
    ' WHERE deleted=0 AND ticket_id='.db_input($this->getId()).' AND ref_id='.db_input($refid).' AND ref_type='.db_input($type);
    $res=db_query($sql);
    if($res && db_num_rows($res)){
    while(list($id,$size,$name,$key)=db_fetch_row($res)){
    $month=date('my',strtotime($this->getCreateDate()));
    $hash=MD5($this->getId()*$refid.session_id());
    $size=Format::file_size($size);
    $ext = strtolower(substr(strrchr($name, '.'), 1));
    $fullfilename = $helpdesk_url.$dir.'/'.$month.'/'.$key.'_'.$name;
    if (in_array($ext,array('jpg', 'png', 'gif', 'bmp'))) {
    list($width, $height, $type, $attr) = getimagesize($fullfilename);
    if ($width > 820) {
    $attachstr.= '<p align=\"center\"><a class=\"lightbox\" href=\"'.$fullfilename.'\"><img src=\"'.$fullfilename.'\" width=\"820\"/></a></p><br />';
    } else {
    $attachstr.= '<p align=\"center\"><a class=\"lightbox\" href=\"'.$fullfilename.'\"><img src=\"'.$fullfilename.'\" /></a></p><br />';
    }
    }
    $attachstr.= \"<a class='Icon file' href='attachment.php?id=$id&ref=$hash'><b>$name</b></a>&nbsp;(<i>$size</i>)&nbsp;&nbsp;\";
    }
    }
    return ($attachstr);
    }



    In order to use the lightbox you will need to add the following in the section of header.inc.php in the Includes/Staff folder:

    <link rel=\"stylesheet\" type=\"text/css\" href=\"css/jquery.lightbox-0.5.css\" media=\"screen\" />
    <script type=\"text/javascript\" src=\"js/jquery.js\"></script>
    <script type=\"text/javascript\" src=\"js/jquery.lightbox-0.5.js\"></script>

    <script type=\"text/javascript\">
    $(function() {
    // Add the link classes that you would like to use with lightbox.
    $('a.lightbox').lightBox();
    });
    </script>


    You will also need to download the jquery lightbox folder that I've attached. Drop the files in their corresponding folders in the SCP directory (images in the image folder, .js in the js folder and .css in the css folder).
    Jqery_lightbox.zip
    17K
  • @EdAllMighty

    Thank you kind sir :)
    Works as it should now, i even installed the lightbox option.
    Thank you so much.
  • Date Issue

    Please, F1!

    For some reason I've got uploaded images going to the /attachments folder instead of going into /attachments/(MMYY). Images show up only when I create folder manually.

    I used the code with LightBox for my install of osTicket.

    Also, I can't get LightBox to work. Am I doing something wrong? I copied:
    CSS into /SCP/CSS
    JS into /SCP/JS
    and images into /SCP/IMAGES
  • That's strange. I've got images to upload and show up properly by removing
    .$month.
    from
    $fullfilename = $helpdesk_url.$dir.'/'.$month.'/'.$key.'_'.$name;
    but today I checked back into it and my images did not work. so I inserted that variable back, and now everything is ok.

    Just had to fix image locations.

    On the other hand, I still cannot get your lightBox mod to work :(. can you verify the location where files need to be copied to?
  • i also cant make it work.

    whats wrong?
  • ozkr;24289 said:
    i also cant make it work.

    whats wrong?
    For those that can not get it to work.
    The zip file did not contain the file "jquery.js"

    But you can link to the one on google api site.

    https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.js

    like so

    <link rel=\"stylesheet\" type=\"text/css\" href=\"css/jquery.lightbox-0.5.css\" media=\"screen\" />
    <script type=\"text/javascript\" src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.js\"></script>
    <script type=\"text/javascript\" src=\"js/jquery.lightbox-0.5.js\"></script>

    <script type=\"text/javascript\">
    $(function() {
    // Add the link classes that you would like to use with lightbox.
    $('a.lightbox').lightBox();
    });
    </script>


    Or just copy jquery.js into the JS folder from somewhere.

    Hope this helps
    Peter
  • This helped indeed.

    Sweet. Thank you very much.
  • Hi all :)

    I wanted to display attached images in the ticket thread so I tried the differents codes above and the result was not totally good for me.
    For example, wrong URL of the attachment, lightbox was not running, file name at the left.

    So I search for get these problems fixed and here is the code I finally got :

    In include/class.ticket.php :

        function getAttachmentStr($refid,$type){
    global $cfg;
    $helpdesk_url=$cfg->getUrl();
    $dir=$cfg->getUploadDir();
    $dir = preg_replace(\"/\\\\/\",\"/\",$dir);
    $dir = explode('/', $dir);
    $arrDir = array_reverse($dir);
    $dir = $arrDir[0];
    $sql ='SELECT attach_id,file_size,file_name,file_key FROM '.TICKET_ATTACHMENT_TABLE.
    ' WHERE deleted=0 AND ticket_id='.db_input($this->getId()).' AND ref_id='.db_input($refid).' AND ref_type='.db_input($type);
    $res=db_query($sql);
    if($res && db_num_rows($res)){
    while(list($id,$size,$name,$key)=db_fetch_row($res)){
    $month=date('my',strtotime($this->getCreateDate()));
    $hash=MD5($this->getId()*$refid.session_id());
    $size=Format::file_size($size);
    $ext = strtolower(substr(strrchr($name, '.'), 1));
    $fullfilename = '../'.$dir.'/'.$month.'/'.$key.'_'.$name;
    $attachstr.= \"<p align=center><a class='Icon file' href='attachment.php?id=$id&ref=$hash'><b>$name</b></a>&nbsp;(<i>$size</i>)</p>\";
    if (in_array($ext,array('jpg', 'png', 'gif', 'bmp'))) {
    list($width, $height, $type, $attr) = getimagesize($fullfilename);
    if ($width > 100) {
    $attachstr.= '<div id=\"gallery\"><p align=\"center\"><a href=\"'.$fullfilename.'\"><img src=\"'.$fullfilename.'\" width=\"100\"/></a></p></div>';
    } else {
    $attachstr.= '<div id=\"gallery\"><p align=\"center\"><a href=\"'.$fullfilename.'\"><img src=\"'.$fullfilename.'\" width=\"100\"/></a></p></div>';
    }
    }
    }
    }
    return ($attachstr);
    }


    In the HEAD section of include/staff/header.inc.php :

    <link rel=\"stylesheet\" type=\"text/css\" href=\"css/jquery.lightbox-0.5.css\" media=\"screen\" />
    <script type=\"text/javascript\" src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.js\"></script>
    <script type=\"text/javascript\" src=\"js/jquery.lightbox-0.5.js\"></script>
    <script type=\"text/javascript\">
    $(function() {
    $('#gallery a').lightBox();
    });
    </script>


    And placed jquery files in the /scp/ folder (and of course, js, css, images subfolders).

    And here is the nice result :

    image

    image

    But I would get the same feature for ticket client view, but I get only file names, without thumbs. I don't understand because it seems to use the same class.ticket configuration file. So perhaps there is a rule to display images (like if User=Staff display=yes ) , but I don't find it.

    Also, I would have the file name written centered under the lightboxed window (between Image x of y and Close X) , but the codes I tried to had was breaking the site lol

    If some one have an idea :)

    Thanks
    Couin
    attachments.jpg
    848 x 649 - 73K
    zoom attachment.jpg
    858 x 732 - 84K
  • Hi :)

    Any idea for client image view ?

    Thanks :)
  • Issue with path

    I tried the mod here:

    http://www.openscriptsolution.com/ticket-system/osticket/viewing-image-attachment-in-osticket-v1-6-rc5/

    My issue came up with the path not auto detecting. What happened was when I tested two tickets, the uploaded files ended up in my attachment path with /0213 folder inside, then the attachments.

    So I had to edit the script:

    $fullfilename = $helpdesk_url.$dir.'/0213/'.$key.'_'.$name;

    I don't know what the 0213 folder is and if it will change periodically or not.
  • Also in 1.7

    Hi!

    Is there also an implementation in ver 1.7 possible?

    Thanks in advance...

    Greetings, Syn
  • edited October 2013
    This is my solution for the file name issue. It was using the already existing function getCreateDate().

    Sorry this text editor is screwing with me. function getAttachmentStr($refid,$type){
    global $cfg;
    $helpdesk_url=$cfg->getUrl();
    $dir=$cfg->getUploadDir();
    $dir = preg_replace("/\\\\/","/",$dir);
    $dir = explode('/', $dir);
    $arrDir = array_reverse($dir);
    $dir = $arrDir[0];
    $sql ='SELECT attach_id,file_size,file_name,file_key FROM '.TICKET_ATTACHMENT_TABLE.
    ' WHERE deleted=0 AND ticket_id='.db_input($this->getId()).' AND ref_id='.db_input($refid).' AND ref_type='.db_input($type);
    $res=db_query($sql);
    if($res && db_num_rows($res)){
    while(list($id,$size,$name,$key)=db_fetch_row($res)){
    $hash=MD5($this->getId()*$refid.session_id());
    $size=Format::file_size($size);
    $ext = strtolower(substr(strrchr($name, '.'), 1));

    //Get month for filename path
    $month=date('my',strtotime($this->getCreateDate()));

    $ext = strtolower(substr(strrchr($name, '.'), 1));

    //Insert .$month. for correct full filename.
    $fullfilename = $helpdesk_url.$dir.'/'.$month.'/'.$key.'_'.$name;

    if (in_array($ext,array('jpg', 'png', 'gif', 'bmp'))) {
    list($width, $height, $type, $attr) = getimagesize($fullfilename);
    if ($width > 820) {
    $attachstr.= ''.$fullfilename.'" target="_blank">image'.$fullfilename.'" width="820"/>
    ';

    } else {
    $attachstr.= ''.$fullfilename.'" target="_blank">image'.$fullfilename.'" />
    ';

    }
    }
    $attachstr.= "$id&ref=$hash' target='_blank'>$name ($size)  ";
    }
    }
    return ($attachstr);
    }

Sign In or Register to comment.