function smartsection_upload_file($another = false, $withRedirect = true, &$itemObj) { include_once SMARTSECTION_ROOT_PATH . "class/uploader.php"; global $smartsection_isAdmin, $xoopsModuleConfig, $smartsection_item_handler, $smartsection_file_handler, $xoopsUser; $itemid = isset($_POST['itemid']) ? intval($_POST['itemid']) : 0; $uid = is_object($xoopsUser) ? $xoopsUser->uid() : 0; $session = SmartsectionSession::singleton(); $session->set('smartsection_file_filename', isset($_POST['name']) ? $_POST['name'] : ''); $session->set('smartsection_file_description', isset($_POST['description']) ? $_POST['description'] : ''); $session->set('smartsection_file_status', $_POST['status']); $session->set('smartsection_file_uid', $uid); $session->set('smartsection_file_itemid', $itemid); if (!is_object($itemObj)) { $itemObj = $smartsection_item_handler->get($itemid); } $max_size = $xoopsModuleConfig['maximum_filesize']; $max_imgwidth = $xoopsModuleConfig['maximum_image_width']; $max_imgheight = $xoopsModuleConfig['maximum_image_height']; $fileObj = $smartsection_file_handler->create(); $fileObj->setVar('name', isset($_POST['name']) ? $_POST['name'] : ''); $fileObj->setVar('description', isset($_POST['description']) ? $_POST['description'] : ''); $fileObj->setVar('status', isset($_POST['file_status']) ? intval($_POST['file_status']) : 1); $fileObj->setVar('uid', $uid); $fileObj->setVar('itemid', $itemObj->getVar('itemid')); // Get available mimetypes for file uploading /* $hMime =& xoops_getmodulehandler('mimetype'); if ($smartsection_isAdmin) { $crit = new Criteria('mime_admin', 1); } else { $crit = new Criteria('mime_user', 1); } $mimetypes =& $hMime->getObjects($crit); // TODO : display the available mimetypes to the user */ if ($xoopsModuleConfig['allowupload'] && is_uploaded_file($_FILES['userfile']['tmp_name'])) { if (!($ret = $fileObj->checkUpload('userfile', $allowed_mimetypes, $errors))) { $errorstxt = implode('<br />', $errors); $message = sprintf(_SMARTSECTION_MESSAGE_FILE_ERROR, $errorstxt); if ($withRedirect) { redirect_header("file.php?op=mod&itemid=" . $itemid, 5, $message); } else { return $message; } } } // Storing the file if (!$fileObj->store($allowed_mimetypes)) { if ($withRedirect) { redirect_header("file.php?op=mod&itemid=" . $fileObj->itemid(), 3, _AM_SSECTION_FILEUPLOAD_ERROR . smartsection_formatErrors($fileObj->getErrors())); exit; } else { return _AM_SSECTION_FILEUPLOAD_ERROR . smartsection_formatErrors($fileObj->getErrors()); } } if ($withRedirect) { $redirect_page = $another ? 'file.php' : 'item.php'; redirect_header($redirect_page . "?op=mod&itemid=" . $fileObj->itemid(), 2, _AM_SSECTION_FILEUPLOAD_SUCCESS); } else { return true; } }
function _clearEditSessionVars($id) { $id = intval($id); $session = SmartsectionSession::singleton(); $session->del("smartsection_editMime_{$id}"); $session->del("smartsection_editMimeErr_{$id}"); }