/** * Public function to add a document. * * @param HTTP::procedure_id the procedure id * @return unknown_type */ public function add() { // Get target ids $procedure_id = intval(phpgw::get_var('procedure_id')); $data = array(); // Check permissions if procedure id is set if (isset($procedure_id) && $procedure_id > 0) { //Load procedure $procedure = $this->so_procedure->get_single($procedure_id); } // If no contract or party is loaded if (!isset($procedure)) { $data['error'] = lang('error_no_procedure'); $this->render('permission_denied.php', $data); return; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!$this->add && !$this->edit) { phpgwapi_cache::message_set('No access', 'error'); $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uidocument.show', 'procedure_id' => $procedure->get_id(), 'tab' => 'documents')); } //Create a document object $document = new controller_document(); $document->set_title(phpgw::get_var('document_title')); $document->set_name($_FILES["file_path"]["name"]); $document->set_type_id(phpgw::get_var('document_type')); $desc = phpgw::get_var('document_description', 'html'); $desc = str_replace(" ", " ", $desc); $document->set_description($desc); $document->set_procedure_id($procedure_id); //Retrieve the document properties $document_properties = $this->get_type_and_id($document); // Move file from temporary storage to vfs $result = $this->so->write_document_to_vfs($document_properties['document_type'], $_FILES["file_path"]["tmp_name"], $document_properties['id'], $_FILES["file_path"]["name"]); if ($result) { if ($this->so->store($document)) { if (isset($procedure)) { $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uidocument.show', 'procedure_id' => $procedure->get_id(), 'tab' => 'documents')); } } else { // Handle failure on storing document $this->redirect($document, $document_propeties, '', ''); } } else { //Handle vfs failure to store document $this->redirect($document, $document_propeties, '', ''); } } }
function populate(int $document_id, &$document) { $document_id = (int) $document_id; if ($document == null) { $document = new controller_document($document_id); $document->set_title($this->unmarshal($this->db->f('document_title', true), 'string')); $document->set_description($this->unmarshal($this->db->f('description', true), 'string')); $document->set_name($this->unmarshal($this->db->f('name', true), 'string')); $document->set_type($this->unmarshal($this->db->f('type_title', true), 'string')); $document->set_procedure_id($this->unmarshal($this->db->f('procedure_id'), 'int')); } return $document; }