Add Attachment on Internal Note in osTicket v1.6 ST (Stable)

Since there are a little bit differences code in /scp/tickets.php file between osTicket v1.6 RC5 and osTicket v1.6 ST (Stable; the last version while I am writing this article), and also there is a new request to me from this post in osTicket Discussion Forums, then this following modification I made to be intended to those of you who want to implement the Attachment on Internal Note in osTicket v1.6 ST.

  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, Februari 26, 2010, attachment on Internal Notes osTicket v1.6 ST ?>
                <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:

    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());
     
                if(!$errors && $ticket->postNote($_POST['title'],$_POST['note'])){
                    $msg='Internal note posted';
                    if(isset($_POST['ticket_status']) && $_POST['ticket_status']){
                        if($ticket->setStatus($_POST['ticket_status']) && $ticket->reload()){
                            $msg.=' and status set to '.($ticket->isClosed()?'closed':'open');
                            if($ticket->isClosed())
                                $page=$ticket=null; //Going back to main listing.
                        }
                    }
                }elseif(!$errors['err']) {
                    $errors['err']='Error(s) occured. Unable to post the note.';
                }
                break;

    then replace with this following code:

    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    
            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, February 26, 2010 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, February 26, 2010 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']){
                        if($ticket->setStatus($_POST['ticket_status']) && $ticket->reload()){
                            $msg.=' and status set to '.($ticket->isClosed()?'closed':'open');
                            if($ticket->isClosed())
                                $page=$ticket=null; //Going back to main listing.
                        }
                    } 
                    // Added by Masino Sinaga, February 26, 2010, 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. I have tested it, and everything seemed okay. Have a nice code!

Share

3,463 viewsPrint This Post Print This Post

Comments

  1. steve says:

    can someone point me to a tutorial on how to do this?
    ———-
    alter the ticket_attachment table by adding a new enum value, that is: “N” into ref_type field
    ——-

    thanks!

  2. steve says:

    figured it out – you can change this by editing the re_type row under the ‘structure’ tab in the ticket_attachment table using phpMyAdmin.

  3. Brett says:

    Fantastic!

  4. Mads Kikkenborg says:

    Hi,

    After this implement, then I can’t see the internal notes “Closed by…”

    Can anyone help me?

  5. bebo says:

    thanks for the codes needed help on my website

  6. Curcio says:

    @Mads Kikkenborg
    First of all, congratulations Mr. Sinaga for your great work.

    To solve the closed by problem, you have to invest the last part of the code, like this:

         case 'postnote':
                $fields=array();
                $fields['title']    = array('type'=>'string',   'required'=>1, 'error'=>'Titulo necessário');
                $fields['note']     = array('type'=>'string',   'required'=>1, 'error'=>'Mensagem necessária');
                $params = new Validator($fields);
                if(!$params->validate($_POST))
                    $errors=array_merge($errors,$params->errors());
     
                // Added by Masino Sinaga, February 26, 2010 for attachment on Internal Notes
                //Check attachments restrictions.  
                if($_FILES['attachment'] && $_FILES['attachment']['size']) {
                    if(!$_FILES['attachment']['name'] || !$_FILES['attachment']['tmp_name'])
                        $errors['attachment']='anexo invalido';
                    elseif(!$cfg->canUploadFiles()) //TODO: saved vs emailed attachments...admin config??
                        $errors['attachment']='Diretorio upload invalido. Contate admin.';
                    elseif(!$cfg->canUploadFileType($_FILES['attachment']['name']))
                        $errors['attachment']='Tipo de arquivo invalido';
                }
     
                // Added by Masino Sinaga, February 26, 2010 attachment on Internal Notes
                if(!$errors && ($noteID=$ticket->postNote($_POST['title'],$_POST['note'],$_POST['alert_assigned'],''))) {  
                    $msg='Nota interna postada';
                       //Finally upload attachment if any
                    if($_FILES['attachment'] && $_FILES['attachment']['size']){
                        $ticket->uploadAttachment($_FILES['attachment'],$noteID,'N');
                    }
     
    		if(isset($_POST['ticket_status']) && $_POST['ticket_status']){
                        if($ticket->setStatus($_POST['ticket_status']) && $ticket->reload()){
                            $msg.=' e status alterado para '.($ticket->isClosed()?'aberto':'fechado');
                            if($ticket->isClosed())
                                $page=$ticket=null; //Going back to main listing.
                        }
                    } 
                    // Added by Masino Sinaga, February 26, 2010, attachment on Internal Notes
     
     
                }else{
                    $errors['err']=$errors['err']?$errors['err']:'Erro(s) ocorrido(s)! Tente novamente..';
                }
                break;
  7. if someone have problems with this mood and email to all with internal notes (Not sending mails)

    in the line code:

    if(!$errors && ($noteID=$ticket->postNote($_POST['title'],$_POST['note'],$_POST['alert_assigned'],''))) {

    change for

    if(!$errors && ($noteID=$ticket->postNote($_POST['title'],$_POST['note']))){
  8. the mod not work to mail to all

    when i change for:

    if(!$errors && ($noteID=$ticket->postNote($_POST['title'],$_POST['note']))){

    the attachment not upload, but when i write:

    if(!$errors && ($noteID=$ticket->postNote($_POST['title'],$_POST['note'],$_POST['alert_assigned'],''))) {

    Attachment succesfull upload but not mail to all

Speak Your Mind

*


*