News Module sub-categories "hack"/workaround?

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   News Module sub-categories "hack"/workaround?
ChaosCreator
CZ Newbie
ChaosCreator has been a member for over 16 year's 16 Year Member
usa.gif northcarolina.gif
Occupation: Self-Employed
Age: 43
Gender: Male
Website:
Status: Offline
Joined: Apr 03, 2008
0.00 posts per day
Posts: 3
Points: 0
   
Okay, basically, what I'm trying to do is limit the selectable catetories on the Submit_News page by passing a variable from the last viewed category page.

Here's what I've done:

1) I created a link in the News Module's index.php file that passes the variable $new_topic, which contains the numeric category ID of the last viewed category to the Submit_News module:

<a href=\"modules.php?name=Submit_News&new_topic=$new_topic\">Submit an Article</a>


2) I modified the defaultDisplay function of the Submit_News module's index.php file to the following:


function defaultDisplay() {
    global $AllowableHTML, $prefix, $user, $cookie, $anonymous, $currentlang, $multilingual, $db, $module_name, $nuke_editor;
    $new_topic = $HTTP_GET_VARS['new_topic'];
    include ("header.php");
    OpenTable();
    echo "<center><font class="title"><b>"._SUBMITNEWS."</b></font>";
    CloseTable();
    echo "<br>";
    info_box("caution", _SUBMITADVICE);
    //OpenTable();
    //echo "<br><center><img src="images/system/caution.gif" border="0" alt="" title=""><br><br><font class="content"><i>"._SUBMITADVICE."</i></font></center><br>";
    //CloseTable();
    echo "<br>";
    OpenTable();
    if (is_user($user)) getusrinfo($user);
    echo "<table border="0" widht="100%">";
    echo "<tr><td><form action="modules.php?name=$module_name" method="post">"
        ."<b>"._YOURNAME.":</b></td><td>";
    if (is_user($user)) {
        cookiedecode($user);
        echo "<a href="modules.php?name=Your_Account">$cookie[1]</a> <font class="content">[ <a href="modules.php?name=Your_Account&op=logout">"._LOGOUT."</a> ]</font>";
    } else {
        echo "$anonymous <font class="content">[ <a href="modules.php?name=Your_Account">"._NEWUSER."</a> ]</font>";
    }
    echo "</td></tr>"
        ."<tr><td colspan="2">&nbsp;</td></tr>"
        ."<tr><td><b>"._SUBTITLE.":</b></td><td>"
        ."<input type="text" name="subject" size="50" maxlength="80"><br>("._BEDESCRIPTIVE.")</td></tr>"
        ."<tr><td colspan="2">&nbsp;</td></tr>"
        ."<tr><td><b>"._TOPIC.":</b></td><td><select name="topic">";
    $category1 = $db->sql_query("SELECT 'topicid','topictext' FROM ".$prefix."_topics WHERE topicid='32,33,34' ORDER BY topictext");
    $category2 = $db->sql_query("SELECT topicid, topictext FROM ".$prefix."_topics WHERE topicid='10,11,12,13,14,15,9,39' ORDER BY topictext");
    $category3 = $db->sql_query("SELECT topicid, topictext FROM ".$prefix."_topics WHERE topicid='16,17,18,19,20' ORDER BY topictext");
    $category4 = $db->sql_query("SELECT topicid, topictext FROM ".$prefix."_topics WHERE topicid='21,22,23,24,25' ORDER BY topictext");
    $category5 = $db->sql_query("SELECT topicid, topictext FROM ".$prefix."_topics WHERE topicid='27,28' ORDER BY topictext");
    $category6 = $db->sql_query("SELECT topicid, topictext FROM ".$prefix."_topics WHERE topicid='35,36,37' ORDER BY topictext");
    if ($new_topic == 10||11||12||13||14||15||9||39) {
    echo "<option value="">"._SELECTTOPIC."</option>n";
    while ($row = $db->sql_fetchrow($category2)) {
        $topicid = intval($row['topicid']);
        $topics = filter($row['topictext'], "nohtml");
        }
}
    if ($new_topic == 32||33||34) {
    echo "<option value="">"._SELECTTOPIC."</option>n";
    while ($row = $db->sql_fetchrow($category1)) {
        $topicid = intval($row['topicid']);
        $topics = filter($row['topictext'], "nohtml");
        }
}
if ($new_topic == 16||17||18||19||20) {
    echo "<option value="">"._SELECTTOPIC."</option>n";
    while ($row = $db->sql_fetchrow($category3)) {
        $topicid = intval($row['topicid']);
        $topics = filter($row['topictext'], "nohtml");
        }
}
if ($new_topic == 21||22||23||24||25) {
    echo "<option value="">"._SELECTTOPIC."</option>n";
    while ($row = $db->sql_fetchrow($category4)) {
        $topicid = intval($row['topicid']);
        $topics = filter($row['topictext'], "nohtml");
        }
}
if ($new_topic == 27||28) {
    echo "<option value="">"._SELECTTOPIC."</option>n";
    while ($row = $db->sql_fetchrow($category5)) {
        $topicid = intval($row['topicid']);
        $topics = filter($row['topictext'], "nohtml");
        }
}
if ($new_topic == 35||36||37) {
    echo "<option value="">"._SELECTTOPIC."</option>n";
    while ($row = $db->sql_fetchrow($category6)) {
        $topicid = intval($row['topicid']);
        $topics = filter($row['topictext'], "nohtml");
        }
}
        if ($topicid == $topic) {
            $sel = "selected ";
        }
        echo "<option $sel value="$topicid">$topics</option>n";
        $sel = "";
    echo "</select></td></tr>";
    if ($multilingual == 1) {
        echo "<tr><td colspan="2">&nbsp;</td></tr>";
        echo "<tr><td><b>"._LANGUAGE.":</b></td><td>"
            ."<select name="alanguage">";
        $handle=opendir('language');
        while ($file = readdir($handle)) {
            if (preg_match("/^lang-(.+).php/", $file, $matches)) {
                $langFound = $matches[1];
                $languageslist .= "$langFound ";
            }
        }
        closedir($handle);
        $languageslist = explode(" ", $languageslist);
        sort($languageslist);
        for ($i=0; $i < sizeof($languageslist); $i++) {
            if(!empty($languageslist[$i])) {
                echo "<option value="$languageslist[$i]" ";
                if($languageslist[$i]==$currentlang) echo "selected";
                echo ">".ucfirst($languageslist[$i])."</option>n";
            }
        }
        echo "</select></td></tr>";
    } else {
        echo "<input type="hidden" name="alanguage" value="$language">";
    }
    echo "<tr><td colspan="2">&nbsp;</td></tr>";
    echo "<tr><td><b>"._STORYTEXT.":</b></td><td>"
    ."<textarea cols="70" rows="15" name="story"></textarea></td></tr>"
    ."<tr><td colspan="2">&nbsp;</td></tr>"
    ."<tr><td><b>"._EXTENDEDTEXT.":</b></td><td>"
    ."<textarea cols="70" rows="15" name="storyext"></textarea><br>"
    ."<font class="content">("._AREYOUSURE.")<br>";
    if ($nuke_editor == 0) {
        echo "<font class="content">"._ALLOWEDHTML."<br>";
        while (list($key,) = each($AllowableHTML)) echo " &lt;".$key."&gt;";
        echo "</font>";
    } else {
        echo ""._HTMLNOTALLOWED."</font>";
    }
    echo "</td></tr>";
    echo "<tr><td colspan="2">&nbsp;</td></tr>";
    echo "<tr><td>&nbsp;</td><td><hr noshade size="1"></td></tr>";
    echo "<tr><td colspan="2">&nbsp;</td></tr>";
    echo "<tr><td>&nbsp;</td><td><input type="submit" name="op" value=""._PREVIEW.""> ("._SUBPREVIEW.")</font></form>";
    echo "</td></tr></table>";
    CloseTable();
    include ('footer.php');
}


Now, I get no error messages, or anything, but something is wrong with my code. The topic selection drop-down menu populates with 5 'Select Topics' (with one selected) and one 'Events' category. The Events category is actually one of my modules (though, it should even show up unless I go through the music categories), so I know I'm on the right track. I just can't figure out the rest.
Should I add $new_topic to the list of global variables? Is my syntax pruned up?

Any suggestions at all?


Back to top Reply with quote
#2   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,440
   
What are you trying to limit? Only select topics in that category? Its a little confusing because i'm not sure if your refering to News Categories or News Topics. Please try to explain what it will do overall.

There are a few errors in your code:

1.) Your MYSQL query will only return the first result in your comma delimited topicid. You should use the MYSQL IN command when searching for more then one. Example:


$category1 = $db->sql_query("SELECT topicid, topictext FROM ".$prefix."_topics WHERE topicid IN (32,33,34) ORDER BY topictext");


2.) Your if statments need to be seperated also. Example:


if ($new_topic == 32 || $new_topic == 33 || $new_topic == 34) {


You may alsowant to just pull all the data in one query and put it into an array. Then you can work with the array throughout the page and save on the queries. It would also be easier for checking items because you can use PHP's in_array() function.



_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#3   re: News Module sub-categories "hack"/workaround?
ChaosCreator
CZ Newbie
ChaosCreator has been a member for over 16 year's 16 Year Member
usa.gif northcarolina.gif
Occupation: Self-Employed
Age: 43
Gender: Male
Website:
Status: Offline
Joined: Apr 03, 2008
0.00 posts per day
Posts: 3
Points: 0
   
Yay! Thanks for the quick reply!

I suppose I'm working on the News Topics, since I can click on the 'Topics' module and see all of my categories.

Here's how my website is laid out:

I have a navigation treemenu that provides links to individual news topics. Click on "Gaming" and it drops down, revealing the links 'Game Reviews', 'Games', and 'New Releases'. Each one of the sub-categories links directly to that topic (i.e., the 'Games' link points to [ Register or login to view links on this board. ]
Now, when you visit the 'Games' Topic page, I have the link I cited in my first post, that passes the topic ID number to the actual submission page when the user clicks it to add an article.
Then, on the submission page itself, depending on the value of the variable, the Topic drop-down menu should only populate the related sections (i.e., 'Games', 'Game Reviews', etc., and not the full list of 30-something topics that I have).
So, basically, I'm kind of hiding the full topic list, and bypassing the need to go to the Topics page, since all the links are available in my treemenu.

Here's the link to my website, if you want to see the way everything is set up...
[ Register or login to view links on this board.]

Thanks for the syntax corrections! I'm going to go test a few things right now!

P.S. - I love your signature quote. Pulp Fiction rules.



Back to top Reply with quote
#4   re: News Module sub-categories "hack"/workaround?
ChaosCreator
CZ Newbie
ChaosCreator has been a member for over 16 year's 16 Year Member
usa.gif northcarolina.gif
Occupation: Self-Employed
Age: 43
Gender: Male
Website:
Status: Offline
Joined: Apr 03, 2008
0.00 posts per day
Posts: 3
Points: 0
   
Well, I made the changes you suggested, and things got worse. The drop-down didn't even populate any categories.

*sigh*

I guess I'm stuck using a huge drop-down list...




_________________
"When a man lies, he murders a part of the world. These are the pale deaths which men miscall their lives. All of this I cannot bear to witness any longer. Cannot the Kingdom of Salvation take me home?" -To Live Is To Die, Metallica-
Back to top Reply with quote
#5   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,440
   
Try this one:


function defaultDisplay() {
       global $AllowableHTML, $prefix, $user, $cookie, $anonymous, $currentlang, $multilingual, $db, $module_name, $nuke_editor;
       $new_topic = $_GET['new_topic'];
       include ("header.php");
       OpenTable();
       echo "<center><font class="title"><b>"._SUBMITNEWS."</b></font>";
       CloseTable();
       echo "<br>";
       info_box("caution", _SUBMITADVICE);
       echo "<br>";
       OpenTable();
       if (is_user($user)) getusrinfo($user);
       echo "<table border="0" widht="100%">";
       echo "<tr><td><form action="modules.php?name=$module_name" method="post">"
           ."<b>"._YOURNAME.":</b></td><td>";
       if (is_user($user)) {
           cookiedecode($user);
           echo "<a href="modules.php?name=Your_Account">$cookie[1]</a> <font class="content">[ <a href="modules.php?name=Your_Account&op=logout">"._LOGOUT."</a> ]</font>";
       } else {
           echo "$anonymous <font class="content">[ <a href="modules.php?name=Your_Account">"._NEWUSER."</a> ]</font>";
       }
       echo "</td></tr>"
           ."<tr><td colspan="2">&nbsp;</td></tr>"
           ."<tr><td><b>"._SUBTITLE.":</b></td><td>"
           ."<input type="text" name="subject" size="50" maxlength="80"><br>("._BEDESCRIPTIVE.")</td></tr>"
           ."<tr><td colspan="2">&nbsp;</td></tr>"
           ."<tr><td><b>"._TOPIC.":</b></td><td><select name="topic">";
       $category1 = $db->sql_query("SELECT topicid, topictext FROM ".$prefix."_topics WHERE topicid IN (32,33,34) ORDER BY topictext");
       $category2 = $db->sql_query("SELECT topicid, topictext FROM ".$prefix."_topics WHERE topicid IN (10,11,12,13,14,15,9,39) ORDER BY topictext");
       $category3 = $db->sql_query("SELECT topicid, topictext FROM ".$prefix."_topics WHERE topicid IN (16,17,18,19,20) ORDER BY topictext");
       $category4 = $db->sql_query("SELECT topicid, topictext FROM ".$prefix."_topics WHERE topicid IN (21,22,23,24,25) ORDER BY topictext");
       $category5 = $db->sql_query("SELECT topicid, topictext FROM ".$prefix."_topics WHERE topicid IN (27,28) ORDER BY topictext");
       $category6 = $db->sql_query("SELECT topicid, topictext FROM ".$prefix."_topics WHERE topicid IN (35,36,37) ORDER BY topictext");
       if ($new_topic == 10 || $new_topic == 11 || $new_topic == 12 || $new_topic == 13 || $new_topic == 14 || $new_topic == 15 || $new_topic == 9 || $new_topic == 39) {
          echo "<option value="">"._SELECTTOPIC."</option>n";
          while ($row = $db->sql_fetchrow($category2)) {
              $topicid = intval($row['topicid']);
              $topics = filter($row['topictext'], "nohtml");
              echo "<option value="$topicid">$topics</option>\n";
           }
   } else if ($new_topic == 32 || $new_topic == 33 || $new_topic == 34) {
          echo "<option value="">"._SELECTTOPIC."</option>n";
          while ($row = $db->sql_fetchrow($category1)) {
              $topicid = intval($row['topicid']);
              $topics = filter($row['topictext'], "nohtml");
              echo "<option value="$topicid">$topics</option>\n"; 
           }
   } else if ($new_topic == 16 || $new_topic == 17 || $new_topic == 18 || $new_topic == 19 || $new_topic == 20) {
          echo "<option value="">"._SELECTTOPIC."</option>n";
          while ($row = $db->sql_fetchrow($category3)) {
              $topicid = intval($row['topicid']);
              $topics = filter($row['topictext'], "nohtml");
              echo "<option value="$topicid">$topics</option>\n";
           }
   } else if ($new_topic == 21 || $new_topic == 22 || $new_topic == 23 || $new_topic == 24 || $new_topic == 25) {
          echo "<option value="">"._SELECTTOPIC."</option>n";
          while ($row = $db->sql_fetchrow($category4)) {
              $topicid = intval($row['topicid']);
              $topics = filter($row['topictext'], "nohtml");
              echo "<option value="$topicid">$topics</option>\n";
           }
   } else if ($new_topic == 27 || $new_topic == 28) {
          echo "<option value="">"._SELECTTOPIC."</option>n";
          while ($row = $db->sql_fetchrow($category5)) {
              $topicid = intval($row['topicid']);
              $topics = filter($row['topictext'], "nohtml");
              echo "<option value="$topicid">$topics</option>\n";
           }
   } else if ($new_topic == 35 || $new_topic == 36 || $new_topic == 37) {
          echo "<option value="">"._SELECTTOPIC."</option>n";
          while ($row = $db->sql_fetchrow($category6)) {
              $topicid = intval($row['topicid']);
              $topics = filter($row['topictext'], "nohtml");
              echo "<option value="$topicid">$topics</option>\n";
           }
   }
       echo "</select></td></tr>";
       if ($multilingual == 1) {
           echo "<tr><td colspan="2">&nbsp;</td></tr>";
           echo "<tr><td><b>"._LANGUAGE.":</b></td><td>"
               ."<select name="alanguage">";
           $handle=opendir('language');
           while ($file = readdir($handle)) {
               if (preg_match("/^lang-(.+).php/", $file, $matches)) {
                   $langFound = $matches[1];
                   $languageslist .= "$langFound ";
               }
           }
           closedir($handle);
           $languageslist = explode(" ", $languageslist);
           sort($languageslist);
           for ($i=0; $i < sizeof($languageslist); $i++) {
               if(!empty($languageslist[$i])) {
                   echo "<option value="$languageslist[$i]" ";
                   if($languageslist[$i]==$currentlang) echo "selected";
                   echo ">".ucfirst($languageslist[$i])."</option>n";
               }
           }
           echo "</select></td></tr>";
       } else {
          echo "<input type="hidden" name="alanguage" value="$language">";
       }
       echo "<tr><td colspan="2">&nbsp;</td></tr>";
       echo "<tr><td><b>"._STORYTEXT.":</b></td><td>"
          ."<textarea cols="70" rows="15" name="story"></textarea></td></tr>"
          ."<tr><td colspan="2">&nbsp;</td></tr>"
          ."<tr><td><b>"._EXTENDEDTEXT.":</b></td><td>"
          ."<textarea cols="70" rows="15" name="storyext"></textarea><br>"
          ."<font class="content">("._AREYOUSURE.")<br>";
       if ($nuke_editor == 0) {
           echo "<font class="content">"._ALLOWEDHTML."<br>";
           while (list($key,) = each($AllowableHTML)) echo " &lt;".$key."&gt;";
           echo "</font>";
       } else {
           echo ""._HTMLNOTALLOWED."</font>";
       }
       echo "</td></tr>";
       echo "<tr><td colspan="2">&nbsp;</td></tr>";
       echo "<tr><td>&nbsp;</td><td><hr noshade size="1"></td></tr>";
       echo "<tr><td colspan="2">&nbsp;</td></tr>";
       echo "<tr><td>&nbsp;</td><td><input type="submit" name="op" value=""._PREVIEW.""> ("._SUBPREVIEW.")</font></form>";
       echo "</td></tr></table>";
       CloseTable();
       include ('footer.php');
}


The idea way to do this is to make another database table and store all the topics there with a main topic for each set of topics and pull the info from that.

Your also going to have to add into the preview function or once they select preview it will list all of the topics again.



_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#6   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,440
   
Well what happened? Did you get it sorted?




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum