diff --git a/include/staff/cannedresponse.inc.php b/include/staff/cannedresponse.inc.php index e3cb5f84d6f82255845df47fcba1096aa43c31e8..0b6a81ccd95bacc68ae9485ef4a770aa9bae521f 100644 --- a/include/staff/cannedresponse.inc.php +++ b/include/staff/cannedresponse.inc.php @@ -87,31 +87,20 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); data-draft-object-id="<?php if (isset($canned)) echo $canned->getId(); ?>" style="width:98%;" class="richtext draft"><?php echo $info['response']; ?></textarea> - <br><br> - <div><b><?php echo __('Canned Attachments'); ?></b> <?php echo __('(optional)'); ?> - <i class="help-tip icon-question-sign" href="#canned_attachments"></i> - <font class="error"><?php echo $errors['files']; ?></font></div> - <?php - if($canned && ($files=$canned->attachments->getSeparates())) { - echo '<div id="canned_attachments"><span class="faded">'.__('Uncheck to delete the attachment on submit').'</span><br>'; - foreach($files as $file) { - $hash=$file['key'].md5($file['id'].session_id().strtolower($file['key'])); - echo sprintf('<label><input type="checkbox" name="files[]" id="f%d" value="%d" checked="checked"> - <a href="file.php?h=%s">%s</a> </label> ', - $file['id'], $file['id'], $hash, $file['name']); - } - echo '</div><br>'; - - } - //Hardcoded limit... TODO: add a setting on admin panel - what happens on tickets page?? - if(count($files)<10) { - ?> - <div> - <input type="file" name="attachments[]" value=""/> + <div><h3><?php echo __('Canned Attachments'); ?> <?php echo __('(optional)'); ?> + <i class="help-tip icon-question-sign" href="#canned_attachments"></i></h3> + <div class="error"><?php echo $errors['files']; ?></div> </div> <?php - }?> - <div class="faded"><?php echo __('You can upload up to 10 attachments per canned response.');?></div> + if($canned && ($files=$canned->attachments->getSeparates())) { + $attachments = $canned_form->getField('attachments'); + $ids = array(); + foreach ($files as $f) + $ids[] = $f['id']; + $attachments->value = $ids; + print $attachments->render(); + } ?> + <br/> </td> </tr> <tr> diff --git a/scp/canned.php b/scp/canned.php index b9a1ea3c346b251dc98154e57012718271ba63a4..57a51fb0f755b39733879283890af491e1d11c62 100644 --- a/scp/canned.php +++ b/scp/canned.php @@ -28,6 +28,13 @@ $canned=null; if($_REQUEST['id'] && !($canned=Canned::lookup($_REQUEST['id']))) $errors['err']=sprintf(__('%s: Unknown or invalid ID.'), __('canned response')); +$canned_form = new Form(array( + 'attachments' => new FileUploadField(array('id'=>'attach', + 'configuration'=>array('extensions'=>false, + 'size'=>$cfg->getMaxFileSize()) + )), +)); + if($_POST && $thisstaff->canManageCannedResponses()) { switch(strtolower($_POST['do'])) { case 'update': @@ -46,8 +53,9 @@ if($_POST && $thisstaff->canManageCannedResponses()) { } } //Upload NEW attachments IF ANY - TODO: validate attachment types?? - if($_FILES['attachments'] && ($files=AttachmentFile::format($_FILES['attachments']))) - $canned->attachments->upload($files); + $attachments = $canned_form->getField('attachments')->getClean(); + if ($attachments) + $canned->attachments->upload($attachments); // Attach inline attachments from the editor if (isset($_POST['draft_id']) @@ -169,5 +177,6 @@ $ost->addExtraHeader('<meta name="tip-namespace" content="' . $tip_namespace . ' "$('#content').data('tipNamespace', '".$tip_namespace."');"); require(STAFFINC_DIR.'header.inc.php'); require(STAFFINC_DIR.$page); +print $canned_form->getMedia(); include(STAFFINC_DIR.'footer.inc.php'); ?> diff --git a/scp/js/scp.js b/scp/js/scp.js index a4ca3146db75201008c6c1904ae08330c540e57b..5f2ff747cab99b563227feb3dfbedb0543ebb6fe 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -229,8 +229,9 @@ var scp_prep = function() { redactor.observeStart(); } //Canned attachments. - if(canned.files && $('.canned_attachments',fObj).length) { - var fdb = $('#filedrop-attach .dropzone').data('dropbox'); + var ca = $('.canned_attachments', fObj); + if(canned.files && ca.length) { + var fdb = ca.parent().find('.dropzone').data('dropbox'); $.each(canned.files,function(i, j) { fdb.addNode(j); }); diff --git a/scp/tickets.php b/scp/tickets.php index 944a12e31c754b167143fabc9cb1f4e2e40dc22c..a6b2c9d4c09d634018599baeb76da35a5c778172 100644 --- a/scp/tickets.php +++ b/scp/tickets.php @@ -182,7 +182,7 @@ if($_POST && !$errors): break; case 'postnote': /* Post Internal Note */ $vars = $_POST; - $attachments = $response_form->getField('attachments')->getClean(); + $attachments = $note_form->getField('attachments')->getClean(); $vars['cannedattachments'] = array_merge( $vars['cannedattachments'] ?: array(), $attachments);