/** * Upload file document page action * * @param void * @return void */ function upload_file() { $this->wireframe->print_button = false; if (!Document::canAdd($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $file = $_FILES['file']; $file_data = $this->request->post('file'); if (!is_array($file_data)) { $file_data = array('category_id' => $this->active_document_category->getId()); } // if require_once SMARTY_PATH . '/plugins/modifier.filesize.php'; $this->smarty->assign(array('file_data' => $file_data, 'max_upload_size' => smarty_modifier_filesize(get_max_upload_size()))); if ($this->request->isSubmitted()) { db_begin_work(); $this->active_document->setAttributes($file_data); if (is_array($file)) { $destination_file = get_available_uploads_filename(); if (move_uploaded_file($file['tmp_name'], $destination_file)) { if (FIX_UPLOAD_PERMISSION !== false) { @chmod($destination_file, FIX_UPLOAD_PERMISSION); } // if $this->active_document->setName($file['name']); $this->active_document->setBody(basename($destination_file)); $this->active_document->setMimeType($file['type']); } // if } // if $this->active_document->setCreatedBy($this->logged_user); $this->active_document->setType('file'); $save = $this->active_document->save(); if ($save && !is_error($save)) { $notify_user_ids = $this->request->post('notify_users'); if (is_foreachable($notify_user_ids)) { $notify_users = Users::findByIds($notify_user_ids); $owner_company = get_owner_company(); if (is_foreachable($notify_users)) { ApplicationMailer::send($notify_users, 'documents/new_upload_file_document', array('document_name' => $this->active_document->getName(), 'created_by_name' => $this->active_document->getCreatedByName(), 'created_by_url' => $this->logged_user->getViewUrl(), 'document_url' => $this->active_document->getViewUrl(), 'owner_company_name' => $owner_company->getName()), $this->active_document); } // if } // if db_commit(); flash_success('Document ":document_name" has been uploaded', array('document_name' => $this->active_document->getName())); $this->redirectTo('documents'); } else { db_rollback(); $this->smarty->assign('errors', $save); } // if } // if }