function addTopic() { global $xoopsDB, $xoopsModule, $xoopsModuleConfig; $topicpid = isset($_POST['topic_pid']) ? intval($_POST['topic_pid']) : 0; $xt = new AmsTopic($xoopsDB->prefix("ams_topics")); if (!$xt->topicExists($topicpid, $_POST['topic_title'])) { $xt->setTopicPid($topicpid); if (empty($_POST['topic_title']) || trim($_POST['topic_title']) == '') { redirect_header("index.php?op=topicsmanager", 2, _AMS_AM_ERRORTOPICNAME); } $xt->setTopicTitle($_POST['topic_title']); if (isset($_POST['topic_imgurl']) && $_POST['topic_imgurl'] != "") { $xt->setTopicImgurl($_POST['topic_imgurl']); } if (isset($_POST['xoops_upload_file'])) { $fldname = $_FILES[$_POST['xoops_upload_file'][0]]; $fldname = get_magic_quotes_gpc() ? stripslashes($fldname['name']) : $fldname['name']; if (trim($fldname != '')) { $sfiles = new sFiles(); $dstpath = XOOPS_ROOT_PATH . "/modules/" . $xoopsModule->dirname() . '/images/topics'; $destname = $sfiles->createUploadName($dstpath, $fldname, true); $permittedtypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'); $uploader = new XoopsMediaUploader($dstpath, $permittedtypes, $xoopsModuleConfig['maxuploadsize']); $uploader->setTargetFileName($destname); if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { if ($uploader->upload()) { $xt->setTopicImgurl(basename($destname)); } else { echo _AMS_AM_UPLOAD_ERROR; } } else { echo $uploader->getErrors(); } } } $xt->banner_inherit = isset($_POST['banner_inherit']) ? 1 : 0; $xt->banner = $_POST['banner']; $xt->forum_id = isset($_POST['forum_id']) ? intval($_POST['forum_id']) : 0; if ($xt->store()) { //This will set default audience global $xoopsModule; $allTopics = $xt->getAllTopics(); $totaltopics = count($allTopics); if ($totaltopics = 1) { //Make sure xoopsModule is AMS. if (!isset($xoopsModule) || $xoopsModule->getVar('dirname') != "AMS") { $mod_handler =& xoops_gethandler('module'); $amsModule =& $mod_handler->getByDirname('AMS'); } else { $amsModule =& $xoopsModule; } // Check audience, and set default value if not yet exist if (!ams_isaudiencesetup($amsModule->getVar('mid'))) { $gperm_handler =& xoops_gethandler('groupperm'); $member_handler =& xoops_gethandler('member'); $group_id_ref =& $member_handler->getGroups(null, true); //insert all groups into default audience foreach (array_keys($group_id_ref) as $i) { $gperm_handler->addRight("ams_audience", 1, intval($group_id_ref[$i]->getVar('groupid')), intval($amsModule->getVar('mid'))); } } } //Added in AMS 2.50 Final. Use News 1.62 permission style // Permissions $gperm_handler =& xoops_gethandler('groupperm'); if (isset($_POST['groups_AMS_can_approve'])) { foreach ($_POST['groups_AMS_can_approve'] as $onegroup_id) { $gperm_handler->addRight('ams_approve', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid')); } } if (isset($_POST['groups_AMS_can_submit'])) { foreach ($_POST['groups_AMS_can_submit'] as $onegroup_id) { $gperm_handler->addRight('ams_submit', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid')); } } if (isset($_POST['groups_AMS_can_view'])) { foreach ($_POST['groups_AMS_can_view'] as $onegroup_id) { $gperm_handler->addRight('ams_view', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid')); } } AMS_updateCache(); $notification_handler =& xoops_gethandler('notification'); $tags = array(); $tags['TOPIC_NAME'] = $_POST['topic_title']; $notification_handler->triggerEvent('global', 0, 'new_category', $tags); redirect_header('index.php?op=topicsmanager', 1, _AMS_AM_DBUPDATED); exit; } } else { redirect_header('index.php?op=topicsmanager', 2, _AMS_AM_ADD_TOPIC_ERROR); exit; } }