Skip to content
Snippets Groups Projects
Commit 91041a5d authored by Jared Hancock's avatar Jared Hancock
Browse files

forms: Use new upload widget for FAQ articles

parent 24c7f7b8
No related branches found
No related tags found
No related merge requests found
...@@ -171,7 +171,7 @@ class FAQ { ...@@ -171,7 +171,7 @@ class FAQ {
$this->updateTopics($vars['topics']); $this->updateTopics($vars['topics']);
//Delete removed attachments. //Delete removed attachments.
$keepers = $vars['files']?$vars['files']:array(); $keepers = $vars['files'];
if(($attachments = $this->attachments->getSeparates())) { if(($attachments = $this->attachments->getSeparates())) {
foreach($attachments as $file) { foreach($attachments as $file) {
if($file['id'] && !in_array($file['id'], $keepers)) if($file['id'] && !in_array($file['id'], $keepers))
...@@ -179,9 +179,8 @@ class FAQ { ...@@ -179,9 +179,8 @@ class FAQ {
} }
} }
//Upload new attachments IF any. // Upload new attachments IF any.
if($_FILES['attachments'] && ($files=AttachmentFile::format($_FILES['attachments']))) $this->attachments->upload($keepers);
$this->attachments->upload($files);
// Inline images (attached to the draft) // Inline images (attached to the draft)
$this->attachments->deleteInlines(); $this->attachments->deleteInlines();
......
...@@ -92,14 +92,14 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); ...@@ -92,14 +92,14 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
<div class="error"><?php echo $errors['files']; ?></div> <div class="error"><?php echo $errors['files']; ?></div>
</div> </div>
<?php <?php
if($canned && ($files=$canned->attachments->getSeparates())) { $attachments = $canned_form->getField('attachments');
$attachments = $canned_form->getField('attachments'); if ($canned && ($files=$canned->attachments->getSeparates())) {
$ids = array(); $ids = array();
foreach ($files as $f) foreach ($files as $f)
$ids[] = $f['id']; $ids[] = $f['id'];
$attachments->value = $ids; $attachments->value = $ids;
print $attachments->render(); }
} ?> print $attachments->render(); ?>
<br/> <br/>
</td> </td>
</tr> </tr>
......
...@@ -96,24 +96,20 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); ...@@ -96,24 +96,20 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
</tr> </tr>
<tr> <tr>
<td colspan=2> <td colspan=2>
<div><b><?php echo __('Attachments');?></b> (<?php echo __('optional');?>) <font class="error">&nbsp;<?php echo $errors['files']; ?></font></div> <div><h3><?php echo __('Attachments');?>
<span class="faded">(<?php echo __('optional');?>)</span></h3>
<div class="error"><?php echo $errors['files']; ?></div>
</div>
<?php <?php
if($faq && ($files=$faq->attachments->getSeparates())) { $attachments = $faq_form->getField('attachments');
echo '<div class="faq_attachments"><span class="faded">'.__('Uncheck to delete the attachment on submit').'</span><br>'; if ($faq && ($files=$faq->attachments->getSeparates())) {
foreach($files as $file) { $ids = array();
$hash=$file['key'].md5($file['id'].session_id().strtolower($file['key'])); foreach ($files as $f)
echo sprintf('<label><input type="checkbox" name="files[]" id="f%d" value="%d" checked="checked"> $ids[] = $f['id'];
<a href="file.php?h=%s">%s</a>&nbsp;&nbsp;</label>&nbsp;', $attachments->value = $ids;
$file['id'], $file['id'], $hash, $file['name']);
}
echo '</div><br>';
} }
?> print $attachments->render(); ?>
<div class="faded"><?php echo __('Select files to upload.');?></div> <br/>
<div class="uploads"></div>
<div class="file_input">
<input type="file" class="multifile" name="attachments[]" size="30" value="" />
</div>
</td> </td>
</tr> </tr>
<?php <?php
......
...@@ -45,7 +45,7 @@ if($_POST && $thisstaff->canManageCannedResponses()) { ...@@ -45,7 +45,7 @@ if($_POST && $thisstaff->canManageCannedResponses()) {
__('this canned response')); __('this canned response'));
//Delete removed attachments. //Delete removed attachments.
//XXX: files[] shouldn't be changed under any circumstances. //XXX: files[] shouldn't be changed under any circumstances.
$keepers = $_POST['files']?$_POST['files']:array(); $keepers = $canned_form->getField('attachments')->getClean();
$attachments = $canned->attachments->getSeparates(); //current list of attachments. $attachments = $canned->attachments->getSeparates(); //current list of attachments.
foreach($attachments as $k=>$file) { foreach($attachments as $k=>$file) {
if($file['id'] && !in_array($file['id'], $keepers)) { if($file['id'] && !in_array($file['id'], $keepers)) {
...@@ -53,8 +53,7 @@ if($_POST && $thisstaff->canManageCannedResponses()) { ...@@ -53,8 +53,7 @@ if($_POST && $thisstaff->canManageCannedResponses()) {
} }
} }
//Upload NEW attachments IF ANY - TODO: validate attachment types?? //Upload NEW attachments IF ANY - TODO: validate attachment types??
$attachments = $canned_form->getField('attachments')->getClean(); if ($keepers)
if ($attachments)
$canned->attachments->upload($attachments); $canned->attachments->upload($attachments);
// Attach inline attachments from the editor // Attach inline attachments from the editor
...@@ -85,8 +84,9 @@ if($_POST && $thisstaff->canManageCannedResponses()) { ...@@ -85,8 +84,9 @@ if($_POST && $thisstaff->canManageCannedResponses()) {
$msg=sprintf(__('Successfully added %s'), Format::htmlchars($_POST['title'])); $msg=sprintf(__('Successfully added %s'), Format::htmlchars($_POST['title']));
$_REQUEST['a']=null; $_REQUEST['a']=null;
//Upload attachments //Upload attachments
if($_FILES['attachments'] && ($c=Canned::lookup($id)) && ($files=AttachmentFile::format($_FILES['attachments']))) $keepers = $canned_form->getField('attachments')->getClean();
$c->attachments->upload($files); if ($keepers && ($c=Canned::lookup($id)))
$c->attachments->upload($keepers);
// Attach inline attachments from the editor // Attach inline attachments from the editor
if (isset($_POST['draft_id']) if (isset($_POST['draft_id'])
......
...@@ -23,8 +23,16 @@ if($_REQUEST['id'] && !($faq=FAQ::lookup($_REQUEST['id']))) ...@@ -23,8 +23,16 @@ if($_REQUEST['id'] && !($faq=FAQ::lookup($_REQUEST['id'])))
if($_REQUEST['cid'] && !$faq && !($category=Category::lookup($_REQUEST['cid']))) if($_REQUEST['cid'] && !$faq && !($category=Category::lookup($_REQUEST['cid'])))
$errors['err']=sprintf(__('%s: Unknown or invalid'), __('FAQ category')); $errors['err']=sprintf(__('%s: Unknown or invalid'), __('FAQ category'));
$faq_form = new Form(array(
'attachments' => new FileUploadField(array('id'=>'attach',
'configuration'=>array('extensions'=>false,
'size'=>$cfg->getMaxFileSize())
)),
));
if($_POST): if($_POST):
$errors=array(); $errors=array();
$_POST['files'] = $faq_form->getField('attachments')->getClean();
switch(strtolower($_POST['do'])) { switch(strtolower($_POST['do'])) {
case 'create': case 'create':
case 'add': case 'add':
...@@ -108,5 +116,6 @@ $ost->addExtraHeader('<meta name="tip-namespace" content="' . $tip_namespace . ' ...@@ -108,5 +116,6 @@ $ost->addExtraHeader('<meta name="tip-namespace" content="' . $tip_namespace . '
"$('#content').data('tipNamespace', '".$tip_namespace."');"); "$('#content').data('tipNamespace', '".$tip_namespace."');");
require_once(STAFFINC_DIR.'header.inc.php'); require_once(STAFFINC_DIR.'header.inc.php');
require_once(STAFFINC_DIR.$inc); require_once(STAFFINC_DIR.$inc);
print $faq_form->getMedia();
require_once(STAFFINC_DIR.'footer.inc.php'); require_once(STAFFINC_DIR.'footer.inc.php');
?> ?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment