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:($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);

}

a month later

Works! Now I can see attachments in the control panel, good mod!

a month later

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

11 days later

../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?

a year later

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:($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(www.labor-c.net)

11 days later

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. :

Here is the solution:

(View Image Attachment in osTicket v1.6 RC5)

Hope it helps you.

Sincerely,

Masino Sinaga

4 days later

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

@[deleted],

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 :)))

2 years later

nice one

but if you want to keep the upload folder,

modified this line :

$attachstr.= "$name ()  ";

by this line :

$attachstr.= "         $name ()  ";

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

5 days later

Lightbox and date on folder issue

@[deleted]

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;

$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:($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 alt="blank" src="js/jquery.js"></IMG></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](https://forum.osticket.com/assets/files/migrated/e/70f0563b3b7fba41ab0f59f218c5e8a.zip)

@[deleted]

Thank you kind sir :)

Works as it should now, i even installed the lightbox option.

Thank you so much.

11 days later

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

6 days later

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?