From ee65d4c4d69ec366f239254d42bb15120a4a2465 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Wed, 27 Aug 2014 16:50:47 -0500
Subject: [PATCH] forms: Remove old attachment config settings

---
 include/ajax.config.php                |  6 --
 include/class.config.php               | 49 ----------------
 include/class.forms.php                |  6 +-
 include/class.mailparse.php            |  3 +-
 include/client/view.inc.php            |  4 +-
 include/staff/settings-tickets.inc.php | 79 +++++---------------------
 include/staff/ticket-open.inc.php      |  4 --
 include/staff/ticket-view.inc.php      |  9 ---
 open.php                               |  7 ++-
 tickets.php                            |  6 +-
 10 files changed, 28 insertions(+), 145 deletions(-)

diff --git a/include/ajax.config.php b/include/ajax.config.php
index 74ee115f0..1cff41842 100644
--- a/include/ajax.config.php
+++ b/include/ajax.config.php
@@ -27,10 +27,8 @@ class ConfigAjaxAPI extends AjaxController {
 
         $config=array(
               'lock_time'       => ($cfg->getLockTime()*3600),
-              'max_file_uploads'=> (int) $cfg->getStaffMaxFileUploads(),
               'html_thread'     => (bool) $cfg->isHtmlThreadEnabled(),
               'date_format'     => ($cfg->getDateFormat()),
-              'allow_attachments' => (bool) $cfg->allowAttachments(),
               'lang'            => $lang,
               'short_lang'      => $sl,
         );
@@ -44,10 +42,6 @@ class ConfigAjaxAPI extends AjaxController {
         list($sl, $locale) = explode('_', $lang);
 
         $config=array(
-            'allow_attachments' => (bool) $cfg->allowOnlineAttachments(),
-            'file_types'      => $cfg->getAllowedFileTypes(),
-            'max_file_size'   => (int) $cfg->getMaxFileSize(),
-            'max_file_uploads'=> (int) $cfg->getClientMaxFileUploads(),
             'html_thread'     => (bool) $cfg->isHtmlThreadEnabled(),
             'lang'            => $lang,
             'short_lang'      => $sl,
diff --git a/include/class.config.php b/include/class.config.php
index 78284e49d..8a7d5eebd 100644
--- a/include/class.config.php
+++ b/include/class.config.php
@@ -152,9 +152,6 @@ class OsticketConfig extends Config {
         'pw_reset_window' =>    30,
         'enable_html_thread' => true,
         'allow_attachments' =>  true,
-        'allow_email_attachments' => true,
-        'allow_online_attachments' => true,
-        'allow_online_attachments_onlogin' => false,
         'name_format' =>        'full', # First Last
         'auto_claim_tickets'=>  true,
         'system_language' =>    'en_US',
@@ -809,28 +806,10 @@ class OsticketConfig extends Config {
         return ($this->get('allow_attachments'));
     }
 
-    function allowOnlineAttachments() {
-        return ($this->allowAttachments() && $this->get('allow_online_attachments'));
-    }
-
-    function allowAttachmentsOnlogin() {
-        return ($this->allowOnlineAttachments() && $this->get('allow_online_attachments_onlogin'));
-    }
-
-    function allowEmailAttachments() {
-        return ($this->allowAttachments() && $this->get('allow_email_attachments'));
-    }
-
     function getSystemLanguage() {
         return $this->get('system_language');
     }
 
-    //TODO: change db field to allow_api_attachments - which will include  email/json/xml attachments
-    //       terminology changed on the UI
-    function allowAPIAttachments() {
-        return $this->allowEmailAttachments();
-    }
-
     /* Needed by upgrader on 1.6 and older releases upgrade - not not remove */
     function getUploadDir() {
         return $this->get('upload_dir');
@@ -959,27 +938,6 @@ class OsticketConfig extends Config {
                 $errors['enable_captcha']=__('PNG support is required for Image Captcha');
         }
 
-        if($vars['allow_attachments']) {
-
-            if(!ini_get('file_uploads'))
-                $errors['err']=__('The "file_uploads" directive is disabled in php.ini');
-
-            if(!is_numeric($vars['max_file_size']))
-                $errors['max_file_size']=__('Maximum file size required');
-
-            if(!$vars['allowed_filetypes'])
-                $errors['allowed_filetypes']=__('Allowed file extentions required');
-
-            if(!($maxfileuploads=ini_get('max_file_uploads')))
-                $maxfileuploads=DEFAULT_MAX_FILE_UPLOADS;
-
-            if(!$vars['max_user_file_uploads'] || $vars['max_user_file_uploads']>$maxfileuploads)
-                $errors['max_user_file_uploads']=sprintf(__('Invalid selection. Must be less than %d'),$maxfileuploads);
-
-            if(!$vars['max_staff_file_uploads'] || $vars['max_staff_file_uploads']>$maxfileuploads)
-                $errors['max_staff_file_uploads']=sprintf(__('Invalid selection. Must be less than %d'),$maxfileuploads);
-        }
-
         if ($vars['default_help_topic']
                 && ($T = Topic::lookup($vars['default_help_topic']))
                 && !$T->isActive()) {
@@ -1012,15 +970,8 @@ class OsticketConfig extends Config {
             'hide_staff_name'=>isset($vars['hide_staff_name'])?1:0,
             'enable_html_thread'=>isset($vars['enable_html_thread'])?1:0,
             'allow_client_updates'=>isset($vars['allow_client_updates'])?1:0,
-            'allow_attachments'=>isset($vars['allow_attachments'])?1:0,
-            'allowed_filetypes'=>strtolower(preg_replace("/\n\r|\r\n|\n|\r/", '',trim($vars['allowed_filetypes']))),
             'max_file_size'=>$vars['max_file_size'],
-            'max_user_file_uploads'=>$vars['max_user_file_uploads'],
-            'max_staff_file_uploads'=>$vars['max_staff_file_uploads'],
             'email_attachments'=>isset($vars['email_attachments'])?1:0,
-            'allow_email_attachments'=>isset($vars['allow_email_attachments'])?1:0,
-            'allow_online_attachments'=>isset($vars['allow_online_attachments'])?1:0,
-            'allow_online_attachments_onlogin'=>isset($vars['allow_online_attachments_onlogin'])?1:0,
         ));
     }
 
diff --git a/include/class.forms.php b/include/class.forms.php
index b994c738f..68175ed43 100644
--- a/include/class.forms.php
+++ b/include/class.forms.php
@@ -995,10 +995,14 @@ class ThreadEntryField extends FormField {
         return array(
             'attachments' => new BooleanField(array(
                 'label'=>__('Enable Attachments'),
-                'default'=>$cfg->allowOnlineAttachments(),
+                'default'=>$cfg->allowAttachments(),
                 'configuration'=>array(
                     'desc'=>__('Enables attachments on tickets, regardless of channel'),
                 ),
+                'validators' => function($self, $value) {
+                    if (!ini_get('file_uploads'))
+                        $self->addError(__('The "file_uploads" directive is disabled in php.ini'));
+                }
             )),
         )
         + $attachments->getConfigurationOptions();
diff --git a/include/class.mailparse.php b/include/class.mailparse.php
index efcff356c..c2d0cac78 100644
--- a/include/class.mailparse.php
+++ b/include/class.mailparse.php
@@ -672,8 +672,7 @@ class EmailDataParser {
                 $data['reply-to-name'] = trim($replyto->personal, " \t\n\r\0\x0B\x22");
         }
 
-        if($cfg && $cfg->allowEmailAttachments())
-            $data['attachments'] = $parser->getAttachments();
+        $data['attachments'] = $parser->getAttachments();
 
         return $data;
     }
diff --git a/include/client/view.inc.php b/include/client/view.inc.php
index cc7a2f84e..3d81f7900 100644
--- a/include/client/view.inc.php
+++ b/include/client/view.inc.php
@@ -184,11 +184,11 @@ if($ticket->getThreadCount() && ($thread=$ticket->getClientThread())) {
             </td>
         </tr>
         <?php
-        if($cfg->allowOnlineAttachments()) { ?>
+        if ($messageField->isAttachmentsEnabled()) { ?>
         <tr>
             <td colspan="2">
 <?php
-            print $response_form->getField('attachments')->render(true);
+            print $attachments->render(true);
 ?>
             </td>
         </tr>
diff --git a/include/staff/settings-tickets.inc.php b/include/staff/settings-tickets.inc.php
index 9f4b30673..a9ede1b5d 100644
--- a/include/staff/settings-tickets.inc.php
+++ b/include/staff/settings-tickets.inc.php
@@ -214,61 +214,20 @@ if(!($maxfileuploads=ini_get('max_file_uploads')))
             </th>
         </tr>
         <tr>
-            <td width="180"><?php echo __('Allow Attachments');?>:</td>
+            <td width="180"><?php echo __('Ticket Attachment Settings');?>:</td>
             <td>
-              <input type="checkbox" name="allow_attachments" <?php echo
-              $config['allow_attachments']?'checked="checked"':''; ?>> <b><?php echo __('Allow Attachments'); ?></b>
-              &nbsp; <em>(<?php echo __('Global Setting'); ?>)</em>
-                &nbsp;<font class="error">&nbsp;<?php echo $errors['allow_attachments']; ?></font>
-            </td>
-        </tr>
-        <tr>
-            <td width="180"><?php echo __('Emailed/API Attachments');?>:</td>
-            <td>
-                <input type="checkbox" name="allow_email_attachments" <?php echo $config['allow_email_attachments']?'checked="checked"':''; ?>> <?php echo __('Accept emailed files');?>
-                    &nbsp;<font class="error">&nbsp;<?php echo $errors['allow_email_attachments']; ?></font>
-            </td>
-        </tr>
-        <tr>
-            <td width="180"><?php echo __('Online/Web Attachments');?>:</td>
-            <td>
-                <input type="checkbox" name="allow_online_attachments" <?php echo $config['allow_online_attachments']?'checked="checked"':''; ?> >
-                    <?php echo __('Allow web upload');?> &nbsp;&nbsp;&nbsp;&nbsp;
-                <input type="checkbox" name="allow_online_attachments_onlogin" <?php echo $config['allow_online_attachments_onlogin'] ?'checked="checked"':''; ?> >
-                    <?php echo __('Limit to authenticated users only. <em>(User must be logged in to upload files)</em>');?>
-                    <font class="error">&nbsp;<?php echo $errors['allow_online_attachments']; ?></font>
-            </td>
-        </tr>
-        <tr>
-            <td><?php echo __('Maximum User File Uploads');?>:</td>
-            <td>
-                <select name="max_user_file_uploads">
-                    <?php
-                    for($i = 1; $i <=$maxfileuploads; $i++) {
-                        ?>
-                        <option <?php echo $config['max_user_file_uploads']==$i?'selected="selected"':''; ?> value="<?php echo $i; ?>">
-                            <?php echo sprintf(_N('%d file', '%d files', $i), $i); ?></option>
-                        <?php
-                    } ?>
-                </select>
-                <em><?php echo __('(Number of files the user is allowed to upload simultaneously)');?></em>
-                &nbsp;<font class="error">&nbsp;<?php echo $errors['max_user_file_uploads']; ?></font>
-            </td>
-        </tr>
-        <tr>
-            <td><?php echo __('Maximum Agent File Uploads');?>:</td>
-            <td>
-                <select name="max_staff_file_uploads">
-                    <?php
-                    for($i = 1; $i <=$maxfileuploads; $i++) {
-                        ?>
-                        <option <?php echo $config['max_staff_file_uploads']==$i?'selected="selected"':''; ?> value="<?php echo $i; ?>">
-                            <?php echo sprintf(_N('%d file', '%d files', $i), $i); ?></option>
-                        <?php
-                    } ?>
-                </select>
-                <em><?php echo __('(Number of files an agent is allowed to upload simultaneously)');?></em>
-                &nbsp;<font class="error">&nbsp;<?php echo $errors['max_staff_file_uploads']; ?></font>
+<?php
+                $tform = TicketForm::objects()->one()->getForm();
+                $f = $tform->getField('message');
+?>
+                <a class="action-button field-config" style="float:none;overflow:inherit"
+                    href="#ajax.php/form/field-config/<?php
+                        echo $f->get('id'); ?>"
+                    onclick="javascript:
+                        $.dialog($(this).attr('href').substr(1), [201]);
+                        return false;
+                    "><i class="icon-edit"></i> <?php echo __('Config'); ?></a>
+                <i class="help-tip icon-question-sign" href="#attachment_settings"></i>
             </td>
         </tr>
         <tr>
@@ -330,18 +289,6 @@ if(!($maxfileuploads=ini_get('max_file_uploads')))
             </td>
         </tr>
         <?php } ?>
-        <tr>
-            <th colspan="2">
-                <em><strong><?php echo __('Accepted File Types');?></strong>: <?php echo __('Limit the type of files users are allowed to submit.');?>
-                <font class="error">&nbsp;<?php echo $errors['allowed_filetypes']; ?></font></em>
-            </th>
-        </tr>
-        <tr>
-            <td colspan="2">
-                <em><?php echo __('Enter allowed file extensions separated by a comma. e.g .doc, .pdf. To accept all files enter wildcard <b><i>.*</i></b>&nbsp;i.e dotStar (NOT Recommended).');?></em><br>
-                <textarea name="allowed_filetypes" cols="21" rows="4" style="width: 65%;" wrap="hard" ><?php echo $config['allowed_filetypes']; ?></textarea>
-            </td>
-        </tr>
     </tbody>
 </table>
 <p style="padding-left:250px;">
diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php
index ea43caa96..138d7c6c2 100644
--- a/include/staff/ticket-open.inc.php
+++ b/include/staff/ticket-open.inc.php
@@ -302,15 +302,11 @@ if ($_POST)
                     placeholder="<?php echo __('Initial response for the ticket'); ?>"
                     name="response" id="response" cols="21" rows="8"
                     style="width:80%;"><?php echo $info['response']; ?></textarea>
-                <?php
-                if($cfg->allowAttachments()) { ?>
                     <div class="attachments">
 <?php
 print $response_form->getField('attachments')->render();
 ?>
                     </div>
-                <?php
-                } ?>
 
                 <table border="0" cellspacing="0" cellpadding="2" width="100%">
             <tr>
diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php
index 0c66a9859..5da914258 100644
--- a/include/staff/ticket-view.inc.php
+++ b/include/staff/ticket-view.inc.php
@@ -577,15 +577,11 @@ $tcount+= $ticket->getNumNotes();
                         rows="9" wrap="soft"
                         class="richtext ifhtml draft draft-delete"><?php
                         echo $info['response']; ?></textarea>
-            <?php
-            if($cfg->allowAttachments()) { ?>
                 <div id="reply_form_attachments" class="attachments">
 <?php
 print $response_form->getField('attachments')->render();
 ?>
                 </div>
-            <?php
-            }?>
                 </td>
             </tr>
             <tr>
@@ -686,8 +682,6 @@ print $response_form->getField('attachments')->render();
                         <span class="error"><?php echo $errors['note']; ?></span>
                 </td>
             </tr>
-            <?php
-            if($cfg->allowAttachments()) { ?>
             <tr>
                 <td width="120">
                     <label for="attachment"><?php echo __('Attachments');?>:</label>
@@ -698,9 +692,6 @@ print $note_form->getField('attachments')->render();
 ?>
                 </td>
             </tr>
-            <?php
-            }
-            ?>
             <tr><td colspan="2">&nbsp;</td></tr>
             <tr>
                 <td width="120">
diff --git a/open.php b/open.php
index 93d74c262..2311bc2bc 100644
--- a/open.php
+++ b/open.php
@@ -29,9 +29,10 @@ if ($_POST) {
             $errors['captcha']=__('Invalid - try again!');
     }
 
-    $tform = TicketForm::objects()->one()->getForm($create_vars);
-    $attachments = $tform->getField('message')->getWidget()->getAttachments();
-    if (!$errors && $cfg->allowOnlineAttachments())
+    $tform = TicketForm::objects()->one()->getForm($vars);
+    $messageField = $tform->getField('message');
+    $attachments = $messageField->getWidget()->getAttachments();
+    if (!$errors && $messageField->isAttachmentsEnabled())
         $vars['cannedattachments'] = $attachments->getClean();
 
     // Drop the draft.. If there are validation errors, the content
diff --git a/tickets.php b/tickets.php
index 593c337f3..7adb4029f 100644
--- a/tickets.php
+++ b/tickets.php
@@ -35,9 +35,9 @@ if($_REQUEST['id']) {
 if (!$ticket && $thisclient->isGuest())
     Http::redirect('view.php');
 
-$response_form = new Form(array(
-    'attachments' => new FileUploadField(array('id'=>'attach'))
-));
+$tform = TicketForm::objects()->one();
+$messageField = $tform->getField('message');
+$attachments = $messageField->getWidget()->getAttachments();
 
 //Process post...depends on $ticket object above.
 if($_POST && is_object($ticket) && $ticket->getId()):
-- 
GitLab