Example #1
0
 /**
  * Handler method for confirming file deleting for the requested file
  *
  * @param string $handler_id Name of the used handler
  * @param mixed $args Array containing the variable arguments passed to the handler
  * @param mixed &$data Data passed to the show method
  * @return boolean Indicating successful request
  */
 public function _handler_delete($handler_id, array $args, array &$data)
 {
     $this->_object = midcom::get('dbfactory')->get_object_by_guid($args[0]);
     $this->_object->require_do('midgard:update');
     $this->_object->require_do('midgard:attachments');
     midcom::get('auth')->require_user_do('midgard.admin.asgard:manage_objects', null, 'midgard_admin_asgard_plugin');
     $data['filename'] = $args[1];
     $this->_file = $this->_get_file($data['filename']);
     if (!$this->_file) {
         throw new midcom_error_notfound("Attachment '{$data['filename']}' of object {$this->_object->guid} was not found.");
     }
     // Require delete privilege
     $this->_file->require_do('midgard:delete');
     if (isset($_POST['f_cancel'])) {
         midcom::get('uimessages')->add(midcom::get('i18n')->get_string('midgard.admin.asgard', 'midgard.admin.asgard'), midcom::get('i18n')->get_string('delete cancelled', 'midgard.admin.asgard'));
         return new midcom_response_relocate("__mfa/asgard/object/attachments/{$this->_object->guid}/{$data['filename']}/");
     }
     if (isset($_POST['f_confirm'])) {
         if ($this->_file->delete()) {
             midcom::get('uimessages')->add(midcom::get('i18n')->get_string('midgard.admin.asgard', 'midgard.admin.asgard'), sprintf(midcom::get('i18n')->get_string('file %s deleted', 'midgard.admin.asgard'), $data['filename']));
             return new midcom_response_relocate("__mfa/asgard/object/attachments/{$this->_object->guid}/");
         }
     }
     midgard_admin_asgard_plugin::bind_to_object($this->_object, $handler_id, $data);
 }
Example #2
0
 public static function render_and_attach_pdf(org_openpsa_invoices_invoice_dba $invoice)
 {
     if ($invoice->date == 0 || $invoice->deliverydate == 0) {
         $time = time();
         if ($invoice->date == 0) {
             $invoice->date = $time;
         }
         if ($invoice->deliverydate == 0) {
             $invoice->deliverydate = $time;
         }
         $invoice->update();
     }
     // renders the pdf and attaches it to the invoice
     $client_class = midcom_baseclasses_components_configuration::get('org.openpsa.invoices', 'config')->get('invoice_pdfbuilder_class');
     if (!class_exists($client_class)) {
         debug_add('Could not find PDF renderer, aborting silently', MIDCOM_LOG_INFO);
         return false;
     }
     $pdf_builder = new $client_class($invoice);
     // tmp filename
     $tmp_dir = $GLOBALS["midcom_config"]["midcom_tempdir"];
     $title = str_replace("#", "", $invoice->get_label());
     $tmp_file = $tmp_dir . "/" . $title . ".pdf";
     // render pdf to tmp filename
     $render = $pdf_builder->render($tmp_file);
     // cleanup old attachments
     $pdf_files = org_openpsa_helpers::get_attachment_urls($invoice, "pdf_file");
     if (count($pdf_files) > 0) {
         foreach ($pdf_files as $guid => $url) {
             $attachment = new midcom_db_attachment($guid);
             $attachment->delete();
         }
     }
     $attachment = $invoice->create_attachment($title . '.pdf', $title, "application/pdf");
     if (!$attachment) {
         debug_add("Failed to create invoice attachment for pdf", MIDCOM_LOG_ERROR);
         return false;
     }
     $copy = $attachment->copy_from_file($tmp_file);
     if (!$copy) {
         debug_add("Failed to copy pdf from " . $tmp_file . " to attachment", MIDCOM_LOG_ERROR);
         return false;
     }
     // set parameter for datamanager to find the pdf
     if (!$invoice->set_parameter("midcom.helper.datamanager2.type.blobs", "guids_pdf_file", $attachment->guid . ":" . $attachment->guid) || !$attachment->set_parameter('org.openpsa.invoices', 'auto_generated', md5_file($tmp_file))) {
         debug_add("Failed to create attachment parameters, last midgard error was: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR);
         return false;
     }
     return true;
 }