Home > osTicket > Add Attachment on Internal Note in osTicket v1.6 RC5

Add Attachment on Internal Note in osTicket v1.6 RC5

This following article will show you how to add attachment on Internal Note in osTicket v1.6 RC5. If you want to implement this on v1.6 RC4, please read the similar article I wrote two days ago: Attachment on Internal Notes in osTicket v1.6 RC4 .

  1. First of all, alter the ticket_attachment table by adding a new enum value, that is: “N” into ref_type field, besides the existing value: M and R. The N value means: Note or Internal Note in this case. And make sure you don’t miss this step!
  2. Open \include\staff\viewticket.inc.php file, and find this code:

    219
    
                <tr><td><?=Format::display($row['note'])?></td></tr>

    after the last line of that code above, please add this following code:

    220
    221
    222
    223
    
                <?php // added by Masino Sinaga, October 10, 2009, attachment on Internal Notes ?>
                <tr class="header">
                  <td><?php echo $ticket->getAttachmentStr($row['note_id'],'N')?></td>
                </tr>
  3. Find again this code:

    363
    364
    365
    366
    367
    
                            <div style="margin-top: 3px;">
                                <label for="note" valign="top">Enter note content.
                                    <font class="error">*&nbsp;<?=$errors['note']?></font></label><br/>
                                <textarea name="note" id="note" cols="80" rows="7" wrap="soft" style="width:90%"><?=$info['note']?></textarea>
                            </div>

    after the last line of the code above, please add this following code:

    368
    369
    370
    371
    372
    373
    374
    
                            <?php if($cfg->canUploadFiles()){ //TODO: may be allow anyways and simply email out attachment?? ?>
                            <div style="margin-top: 3px;">
                                <label for="attachment" >Attach File:</label>
                                <input type="file" name="attachment" id="attachment2" size=30px value="<?php echo $info['attachment']; ?>" /> 
                                    <font class="error">&nbsp;<?php echo $errors['attachment']; ?></font>
                            </div>
                            <?php }?>
  4. Open \scp\tickets.php file and find this code:

    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    
            case 'postnote':
                $fields=array();
                $fields['title']    = array('type'=>'string',   'required'=>1, 'error'=>'Title required');
                $fields['note']     = array('type'=>'string',   'required'=>1, 'error'=>'Note message required');
                $params = new Validator($fields);
                if(!$params->validate($_POST))
                    $errors=array_merge($errors,$params->errors());
     
                if(!$errors && $ticket->postNote($_POST['title'],$_POST['note'])){
                    $msg='Internal note posted';
                    if(isset($_POST['ticket_status']) && $_POST['ticket_status'])
                        $ticket->setStatus($_POST['ticket_status']);
                }else{
                    $errors['err']=$errors['err']?$errors['err']:'Error(s) occured. Unable to post the note.';
                }
                break;

    then replace with this following code:

    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    
            case 'postnote':
                $fields=array();
                $fields['title']    = array('type'=>'string',   'required'=>1, 'error'=>'Title required');
                $fields['note']     = array('type'=>'string',   'required'=>1, 'error'=>'Note message required');
                $params = new Validator($fields);
                if(!$params->validate($_POST))
                    $errors=array_merge($errors,$params->errors());
     
                // Added by Masino Sinaga, October 10, 2009 for attachment on Internal Notes
                //Check attachments restrictions.  
                if($_FILES['attachment'] && $_FILES['attachment']['size']) {
                    if(!$_FILES['attachment']['name'] || !$_FILES['attachment']['tmp_name'])
                        $errors['attachment']='Invalid attachment';
                    elseif(!$cfg->canUploadFiles()) //TODO: saved vs emailed attachments...admin config??
                        $errors['attachment']='upload dir invalid. Contact admin.';
                    elseif(!$cfg->canUploadFileType($_FILES['attachment']['name']))
                        $errors['attachment']='Invalid file type';
                }
     
                // Added by Masino Sinaga, October 10, 2009, attachment on Internal Notes
                if(!$errors && ($noteID=$ticket->postNote($_POST['title'],$_POST['note'],$_POST['alert_assigned'],''))) {  
                    $msg='Internal note posted';
                    if(isset($_POST['ticket_status']) && $_POST['ticket_status'])
                        $ticket->setStatus($_POST['ticket_status']);
     
                    // Added by Masino Sinaga, October 10, 2009, attachment on Internal Notes
                    //Finally upload attachment if any
                    if($_FILES['attachment'] && $_FILES['attachment']['size']){
                        $ticket->uploadAttachment($_FILES['attachment'],$noteID,'N');
                    }
     
                }else{
                    $errors['err']=$errors['err']?$errors['err']:'Error(s) occured. Unable to post the note.';
                }
                break;

That’s all. Have a nice code!

  • Share/Bookmark
328 views Print This Post Print This Post

  1. October 11th, 2009 at 11:12 | #1

    Thanks a bunch!

  2. October 12th, 2009 at 08:50 | #2

    You’re welcome.

  3. Rob
    February 26th, 2010 at 08:18 | #3

    Thanks Masino! I would like to implement this code in the recent 1.6 stable (and I tried) but it would appear that there were some minor changes to the scp/tickets.php that I just can’t get this working. Think you could assist?

    Thanks again

  4. February 26th, 2010 at 21:14 | #4

    @Rob

    Sure. Get the answer from here: Add Attachment on Internal Note in osTicket v1.6 ST (Stable). Hope it helps. :-)

  1. No trackbacks yet.