Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
List Sections?
  • Posted: 19.02.2003, 02:37
     
    JahToasted
    rank:
    Freshman Freshman
    registered:
     February 2003
    Status:
    offline
    last visit:
    21.05.03
    Posts:
    8
    Hi everybody,
    The site I'm working on needs to have the Sections listed along the top in the banner. When the user clicks one of te Sections the articles within it should be listed below it like so:

    Section1 *Section2* Section3 Section4
    Section2: Article1 Article2 Article3 ....

    Problem is I'm kinda stuck as to where to go from here. I checked modules/Sections/index.php and there is a listsections() and listarticles() but I can't access them.

    So... how do I list Sections and the Articles contained within them?

    Peace!
  • Posted: 20.02.2003, 00:39
     
    JahToasted
    rank:
    Freshman Freshman
    registered:
     February 2003
    Status:
    offline
    last visit:
    21.05.03
    Posts:
    8
    ok, I've managed to get something working... in case anyone else has the same problem here is some code (mostly stolen from modules/Sections/index.php):

    Code

    <?php

        list($dbconn) = pnDBGetConn();
        $pntable = pnDBGetTables();

        if (!pnSecAuthAction(0, 'Sections::Section', '::', ACCESS_OVERVIEW)) {
            echo _SECTIONSNOAUTH;
            return;
        }

        $column = &$pntable['sections_column'];
        $result = $dbconn->Execute("SELECT $column[secid], $column[secname], $column[image]
                                  FROM $pntable[sections] ORDER BY $column[secname]"
    );

        $sitename = pnConfigGetVar('sitename');
       
        $count = 0;
        while(list($secid, $secname, $image) = $result->fields) {

            $result->MoveNext() ;
            if (pnSecAuthAction(0, 'Sections::Section', "$secname::$secid", ACCESS_READ)) {
                echo "<a href=\"modules.php?op=modload&amp;name=Sections&amp;file=index&amp;req=listarticles&amp;secid=$secid\">\n"
                    ."$secname\n"
                    ."</a> \n" ;
                $count++;
            }
        }
        $result->Close();

    ?>


    My next problem is listing the articles underneath the section buttons depending on which button was clicked. to do that I need to know which section is currently being viewed... anyone out there know how to do this?
  • Posted: 20.02.2003, 21:32
     
    JahToasted
    rank:
    Freshman Freshman
    registered:
     February 2003
    Status:
    offline
    last visit:
    21.05.03
    Posts:
    8
    I got a list of articles in the banner... here is what I did:

    Code

    <?php

      $secid = pnVarCleanFromInput('secid');

      if ( $secid ) {

        list($dbconn) = pnDBGetConn();
        $pntable = pnDBGetTables();

        $currentlang = pnUserGetLang();

        if (pnConfigGetVar('multilingual') == 1) {
            $column = &$pntable['seccont_column'];
            $querylang = "AND ($column[slanguage]='$currentlang' OR $column[slanguage]='')"; /* the OR is needed to display stories who are posted to ALL languages */
        } else {
        $querylang = "";
        }

        $column = &$pntable['sections_column'];
        $result = $dbconn->Execute("SELECT $column[secname]
                                  FROM $pntable[sections]
                                  WHERE $column[secid]="
    .pnVarPrepForStore($secid)."");
        list($secname) = $result->fields;
        $result->Close();

        if (!pnSecAuthAction(0, 'Sections::Section', "$secname::$secid", ACCESS_READ)) {
            echo _SECTIONSARTICLENOAUTH;
            return;
        }

        $column = &$pntable['seccont_column'];
        $result = $dbconn->Execute("SELECT $column[artid], $column[secid], $column[title],
                                    $column[content], $column[counter]
                                  FROM $pntable[seccont]
                                  WHERE $column[secid]="
    .pnVarPrepForStore($secid)." $querylang");
        $column = &$pntable['sections_column'];
        $result2 = $dbconn->Execute("SELECT $column[image]
                                   FROM $pntable[sections]
                                   WHERE $column[secid]="
    .pnVarPrepForStore($secid)."");
        list($image) = $result2->fields;

        if ( ($image == "") or ($image == "none") )  {
          $image = "transparent.gif";
        }

        while(list($artid, $secid, $title, $content, $counter) = $result->fields) {

            $result->MoveNext();
            if (pnSecAuthAction(0, 'Sections::Article', "$title:$secname:$artid", ACCESS_READ)
                && $secname != $title ) {

                echo "        <a class=\"sublink\" href=\"modules.php?op=modload&amp;name=".$GLOBALS['name']."&amp;file=index&amp;req=viewarticle&amp;artid=$artid&amp;page=1&amp;secid=$secid\">\n"
                    ."        ".pnVarPrepForDisplay($title)."\n</a>\n"
                    ."        &nbsp&nbsp\n" ;

            }
        }
        $result->Close();
      }
    ?>


    Now the only catch is that you have to put "&secid=$secid" at the end of all the links to the articles... so the original code for the section links above needs to be altered. Also you gotta hack modules/Sections/index.php to make it work there too.

    I also altered my original section buttons code so that if there is an article with the same name as the section it will link to that instead of the article listing:

    Code

    <?php

        list($dbconn) = pnDBGetConn();
        $pntable = pnDBGetTables();

        if (!pnSecAuthAction(0, 'Sections::Section', '::', ACCESS_OVERVIEW)) {
            echo _SECTIONSNOAUTH;
            return;
        }

        $column = &$pntable['sections_column'];
        $result = $dbconn->Execute("SELECT $column[secid], $column[secname], $column[image]
                                  FROM $pntable[sections] ORDER BY $column[secname]"
    );

        $sitename = pnConfigGetVar('sitename');


        echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\n<tr>\n";

        $count = 0;
        while(list($secid, $secname, $image) = $result->fields) {

          $result->MoveNext() ;

          // if we can't find an article with the same name as the section
          // then we should list the articles
          $sectionlink = "<a class=\"button\"  href=\"modules.php?op=modload&amp;name=Sections&amp;file=index&amp;req=listarticles&amp;secid=$secid\">" ;
             
          // check to make sure we are allowed to access the articles
          if (pnSecAuthAction(0, 'Sections::Section', "$secname::$secid", ACCESS_READ)) {

            // some language stuff
            $currentlang = pnUserGetLang();
            if (pnConfigGetVar('multilingual') == 1) {
              $column = &$pntable['seccont_column'];
              $querylang = "AND ($column[slanguage]='$currentlang' OR $column[slanguage]='')"; /* the OR is needed to display stories who are posted to ALL languages */
            } else {
              $querylang = "";
            }

            $column = &$pntable['sections_column'];
            $articleresult = $dbconn->Execute("SELECT $column[secname]
                                               FROM $pntable[sections]
                                               WHERE $column[secid]="
    .pnVarPrepForStore($secid)."");
            list($secname) = $articleresult->fields;
            $articleresult->Close();
     

            $column = &$pntable['seccont_column'];
            $articleresult = $dbconn->Execute("SELECT $column[artid], $column[secid], $column[title],
                                               $column[content], $column[counter]
                                               FROM $pntable[seccont]
                                               WHERE $column[secid]="
    .pnVarPrepForStore($secid)." $querylang");
            $column = &$pntable['sections_column'];

            while(list($artid, $secid, $title, $content, $counter) = $articleresult->fields) {

              $articleresult->MoveNext() ;
              if (pnSecAuthAction(0, 'Sections::Article', "$title:$secname:$artid", ACCESS_READ)
                  && $secname == $title ) {

                // found it! set the section link to the article            
                $sectionlink = "<a class=\"button\" href=\"modules.php?op=modload&amp;name=Sections&amp;file=index&amp;req=viewarticle&amp;artid=$artid&amp;page=1&amp;secid=$secid\">" ;
                break;
              }

            } // end while(list($artid, $secid, $title $content, $counter) = $articleresult->fields ...

            $articleresult->Close();

          } // end if (pnSecAuthAction(0, 'Sections::Section', "$secname::$secid", ACCESS_READ))

          echo "  <td>\n"
              ."    <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n"
              ."    <tr>\n"
              ."      <td>\n"
              ."        $pill_left\n"
              ."      </td>\n"
              ."      <td style=\"$pill_middle\" align=\"center\">\n"
              ."        $sectionlink\n"
              ."        $secname\n"
              ."        </a>\n"
              ."      </td>\n"
              ."      <td>\n"
              ."        $pill_right\n"
              ."      </td>\n"
              ."    </tr>\n</table>\n"
              ."  </td>\n" ;
          $count++;
         
        } // end while(list($secid, $secname, $image) = $result->fields)

        $result->Close();

        echo "</tr>\n</table>";


    ?>


    I didn't bother taking out my site specific code (the button images).

    Of course if anyone sees a problem in my code let me know, okay?

    Peace out

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula