/**
  * Update multiple tickets
  *
  * @param void
  * @return null
  */
 function mass_edit()
 {
     if (!$this->request->isSubmitted()) {
         $this->httpError(HTTP_ERR_BAD_REQUEST);
     }
     // if
     $action = $this->request->post('with_selected');
     if (trim($action) == '') {
         flash_error('Please select what you want to do with selected tickets');
         $this->redirectToReferer($this->smarty->get_template_vars('files_url'));
     }
     // if
     $files_ids = $this->request->post('files');
     $object_types = $this->request->post('object_types');
     if ($object_types == 'files') {
         $files = Files::findByIds($files_ids, STATE_VISIBLE, $this->logged_user->getVisibility());
         $redirect_url = $this->smarty->get_template_vars('files_url');
     } else {
         if ($object_types == 'attachments') {
             $files = Attachments::findbyids($files_ids, STATE_VISIBLE, $this->logged_user->getVisibility());
             $redirect_url = $this->smarty->get_template_vars('attachments_url');
         } else {
             $files = array();
             $redirect_url = $this->smarty->get_template_vars('files_url');
         }
     }
     // if
     if (!is_foreachable($files)) {
         flash_error('Please select files that you would like to update');
         $this->redirectToReferer($this->smarty->get_template_vars('files_url'));
     }
     // if
     $updated = 0;
     if ($action == 'delete') {
         // delete attachments
         $message = lang(':count attachments deleted');
         foreach ($files as $file) {
             if ($file->canDelete($this->logged_user)) {
                 $delete = $file->delete();
                 if ($delete && !is_error($delete)) {
                     $updated++;
                 }
                 // if
             }
             // if
         }
         // foreach
     } else {
         if ($action == 'move_to_trash') {
             // move files to trash
             $message = lang(':count files moved to trash');
             foreach ($files as $file) {
                 if ($file->canDelete($this->logged_user)) {
                     $delete = $file->moveToTrash();
                     if ($delete && !is_error($delete)) {
                         $updated++;
                     }
                     // if
                 }
                 // if
             }
             // foreach
         } else {
             if (str_starts_with($action, 'move_to_category')) {
                 // chage files category
                 $message = lang(':count files updated');
                 if ($action == 'move_to_category') {
                     $category_id = 0;
                 } else {
                     $category_id = (int) substr($action, 17);
                 }
                 // if
                 $category = $category_id ? Categories::findById($category_id) : null;
                 foreach ($files as $file) {
                     if ($file->canEdit($this->logged_user)) {
                         $file->setParent($category, false);
                         $save = $file->save();
                         if ($save && !is_error($save)) {
                             $updated++;
                         }
                         // if
                     }
                 }
                 // foreach
             } else {
                 // invalid action
                 $this->httpError(HTTP_ERR_BAD_REQUEST);
             }
         }
     }
     flash_success($message, array('count' => $updated));
     $this->redirectToReferer($redirect_url);
 }