<?php

function getTopicIds($channelInfoKey) {
 global $channelInfoNew;

 $myChans=made("", "getDialogIds()", -1);
 $channelOnPeerDatabase=CheckMyChannels($myChans, $channelInfoNew[$channelInfoKey]["chanid"]);

 if (!isset($channelOnPeerDatabase)) { 
  $returnMsg="<b>not on channel</b> (".$channelInfoNew[$channelInfoKey]["chanid"].") use: <code>channelstatus</code><br>";
  return $returnMsg;
 }

 $peerID=$channelInfoNew[$channelInfoKey]["peerid"];

 $out=made("messages", "getPeerDialogs", array("peers" => array($channelInfoNew[$channelInfoKey]["peerid"])));

 usleep(200000); //0,2 Sekunden
 $returnMsg="";

 if ($out['chats'][0]['forum']==1) { // channel is theme channel
  $forumTopics=made("channels", "getForumTopics", array("channel" => $channelInfoNew[$channelInfoKey]["peerid"], "limit" => 100));
  $returnMsg.="- topics on channel: <b>".htmlspecialchars($channelInfoNew[$channelInfoKey]["name"])."</b>:<br>";
  foreach ($forumTopics['topics'] as $forum) {
   $titel=$forum['title'];
   $id=$forum['id'];
   $returnMsg.="[<code>".$id."</code>] - ".htmlspecialchars($titel)."<br>";
  }
 } else {
  $returnMsg="no topics on channel: <b>".htmlspecialchars($channelInfoNew[$channelInfoKey]["name"])."</b>(<code>".$channelInfoNew[$channelInfoKey]["chanid"]."</code>)<br>";
 }
  return $returnMsg;
} // function end

function getTopicName($chanid, $topic_id) {

 $peerid="-100".$chanid;
 $out=made("messages", "getPeerDialogs", array("peers" => array($peerid)));

 usleep(200000); //0,2 Sekunden
 $returnMsg="";
 if ($out['chats'][0]['forum']==1) { // channel is theme channel
  $forumTopics=made("channels", "getForumTopics", array("channel" => $peerid, "limit" => 100));
  foreach ($forumTopics['topics'] as $forum) {
   $id=$forum['id'];
   if ($id==$topic_id) {
    $titel=$forum['title'];
    $returnMsg=cleanupString($titel);
   }
  }
 } else {
  $returnMsg="no topics on channel(".$chanid.")";
 }
  return $returnMsg;
} // function end
