$topicpid=0; if($one_amstopic['topic_pid']!=0) { // Search for its the parent if(array_key_exists($one_amstopic['topic_pid'],$ams_news_topics)) { $topicpid=$ams_news_topics[$one_amstopic['topic_pid']]; } } $news_topic = new nw_NewsTopic(); $news_topic->setTopicPid($topicpid); $news_topic->setTopicTitle($one_amstopic['topic_title']); $news_topic->setTopicImgurl($one_amstopic['topic_imgurl']); $news_topic->setMenu(0); $news_topic->setTopicFrontpage(1); $news_topic->Settopic_rssurl(''); $news_topic->setTopicDescription(''); $news_topic->setTopic_color('000000'); $news_topic->store(); echo '<br>- The following topic was imported : '.$news_topic->topic_title(); $ams_topicid = $one_amstopic['topic_id']; $news_topicid = $news_topic->topic_id(); $ams_news_topics[$ams_topicid] = $news_topicid; // Then we insert all its articles $result = $db->query('SELECT * FROM '.$ams_articles.' WHERE topicid='.$ams_topicid.' ORDER BY created'); while ( $article = $db->fetchArray($result) ) { $ams_newsid = $article['storyid']; // We search for the last version $result2 = $db->query('SELECT * FROM '.$ams_text.' WHERE storyid='.$ams_newsid.' AND current=1'); $text_lastversion = $db->fetchArray($result2); // We search for the number of votes
function addTopic() { global $xoopsDB, $xoopsModule, $xoopsModuleConfig; $topicpid = isset($_POST['topic_pid']) ? intval($_POST['topic_pid']) : 0; $xt = new nw_NewsTopic(); if (!$xt->topicExists($topicpid, $_POST['topic_title'])) { $xt->setTopicPid($topicpid); if (empty($_POST['topic_title']) || xoops_trim($_POST['topic_title'])=='') { redirect_header( 'index.php?op=topicsmanager', 2, _AM_NW_ERRORTOPICNAME ); } $xt->setTopicTitle($_POST['topic_title']); //$xt->Settopic_rssurl($_POST['topic_rssfeed']); $xt->setTopic_color($_POST['topic_color']); if (isset($_POST['topic_imgurl'] ) && $_POST['topic_imgurl'] != '') { $xt->setTopicImgurl($_POST['topic_imgurl'] ); } $xt->setMenu(intval($_POST['submenu'])); $xt->setTopicFrontpage(intval($_POST['topic_frontpage'])); if(isset($_SESSION['items_count'])) { $_SESSION['items_count'] = -1; } if(isset($_POST['xoops_upload_file'])) { $fldname = $_FILES[$_POST['xoops_upload_file'][0]]; $fldname = (get_magic_quotes_gpc()) ? stripslashes($fldname['name']) : $fldname['name']; if(xoops_trim($fldname!='')) { $sfiles = new nw_sFiles(); $dstpath = NW_TOPICS_FILES_PATH; $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 _AM_NW_UPLOAD_ERROR . ' ' . $uploader->getErrors(); } } else { echo $uploader->getErrors(); } } } if(isset($_POST['topic_description'])) { $xt->setTopicDescription($_POST['topic_description']); } else { $xt->setTopicDescription(''); } $xt->store(); // Permissions $gperm_handler = &xoops_gethandler('groupperm'); if(isset($_POST['groups_news_can_approve'])) { foreach($_POST['groups_news_can_approve'] as $onegroup_id) { $gperm_handler->addRight('nw_approve', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid')); } } if(isset($_POST['groups_news_can_submit'])) { foreach($_POST['groups_news_can_submit'] as $onegroup_id) { $gperm_handler->addRight('nw_submit', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid')); } } if(isset($_POST['groups_news_can_view'])) { foreach($_POST['groups_news_can_view'] as $onegroup_id) { $gperm_handler->addRight('nw_view', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid')); } } nw_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, _AM_NW_DBUPDATED); } else { redirect_header('index.php?op=topicsmanager', 2, _AM_NW_ADD_TOPIC_ERROR); } exit(); }