[geeklog-cvs] geeklog-1.3/public_html/admin poll.php,1.37,1.38

dhaun at iowaoutdoors.org dhaun at iowaoutdoors.org
Sat Jul 17 14:03:28 EDT 2004


Update of /var/cvs/geeklog-1.3/public_html/admin
In directory www:/tmp/cvs-serv20074/public_html/admin

Modified Files:
	poll.php 
Log Message:
The list of polls is now sorted by date (newest first). Also added parameter filtering, google paging, and a row number.


Index: poll.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/public_html/admin/poll.php,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** poll.php	18 Jan 2004 14:41:22 -0000	1.37
--- poll.php	17 Jul 2004 18:03:25 -0000	1.38
***************
*** 38,47 ****
  $_POLL_VERBOSE = false;
  
! require_once('../lib-common.php');
! require_once('auth.inc.php');
  
  $display = '';
  
! if (!SEC_hasRights('poll.edit')) {
      $display .= COM_siteHeader ('menu');
      $display .= COM_startBlock ($MESSAGE[30], '',
--- 38,50 ----
  $_POLL_VERBOSE = false;
  
! require_once ('../lib-common.php');
! require_once ('auth.inc.php');
! 
! // number of polls to list per page
! define ('POLLS_PER_PAGE', 50);
  
  $display = '';
  
! if (!SEC_hasRights ('poll.edit')) {
      $display .= COM_siteHeader ('menu');
      $display .= COM_startBlock ($MESSAGE[30], '',
***************
*** 50,54 ****
      $display .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
      $display .= COM_siteFooter ();
!     COM_accessLog("User {$_USER['username']} tried to illegally access the poll administration screen.");
      echo $display;
      exit;
--- 53,57 ----
      $display .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
      $display .= COM_siteFooter ();
!     COM_accessLog ("User {$_USER['username']} tried to illegally access the poll administration screen.");
      echo $display;
      exit;
***************
*** 65,87 ****
  * Saves a poll question and potential answers to the database
  *
! * @qid              string          Question ID
! * @display          int             Flag to indicate if poll appears on homepage
! * @question         string          The text for the question
! * @voters           int             Number of votes
! * @statuscode       int             (unused)
! * @commentcode      int             Indicates if users can comment on poll
! * @A                array           Array of possible answers
! * @V                array           Array of vote per each answer 
! * @owner_id         int             ID of poll owner
! * @group_id         int             ID of group poll belongs to
! * @perm_owner       int             Permissions the owner has on poll
! * @perm_grup        int             Permissions the group has on poll
! * @perm_members     int             Permissions logged in members have on poll
! * @perm_anon        int             Permissions anonymous users have on poll
  *
  */
! function savepoll($qid,$mainpage,$question,$voters,$statuscode,$commentcode,$A,$V,$owner_id,$group_id,$perm_owner,$perm_group,$perm_members,$perm_anon) 
  {
!     global $_TABLES, $LANG21, $LANG25, $_CONF, $MESSAGE, $_POLL_VERBOSE;
  
      // Convert array values to numeric permission values
--- 68,91 ----
  * Saves a poll question and potential answers to the database
  *
! * @param    string  $qid            Question ID
! * @param    int     $display        Flag to indicate if poll appears on homepage
! * @param    string  $question       The text for the question
! * @param    int     $voters         Number of votes
! * @param    int     $statuscode     (unused)
! * @param    int     $commentcode    Indicates if users can comment on poll
! * @param    array   $A              Array of possible answers
! * @param    array   $V              Array of vote per each answer 
! * @param    int     $owner_id       ID of poll owner
! * @param    int     $group_id       ID of group poll belongs to
! * @param    int     $perm_owner     Permissions the owner has on poll
! * @param    int     $perm_grup      Permissions the group has on poll
! * @param    int     $perm_members   Permissions logged in members have on poll
! * @param    int     $perm_anon      Permissions anonymous users have on poll
! * @return   string                  HTML redirect or error message
  *
  */
! function savepoll ($qid, $mainpage, $question, $voters, $statuscode, $commentcode, $A, $V, $owner_id, $group_id, $perm_owner, $perm_group, $perm_members, $perm_anon) 
  {
!     global $_CONF, $_TABLES, $LANG21, $LANG25, $MESSAGE, $_POLL_VERBOSE;
  
      // Convert array values to numeric permission values
***************
*** 125,129 ****
          }
  
!         if (empty($voters)) { 
              $voters = '0'; 
          }
--- 129,133 ----
          }
  
!         if (empty ($voters)) { 
              $voters = '0'; 
          }
***************
*** 136,144 ****
          }
  
!         DB_delete($_TABLES['pollquestions'],'qid',$qid);
!         DB_delete($_TABLES['pollanswers'],'qid',$qid);
  
          $question = addslashes ($question);
!         $sql = "'$qid','$question',$voters,'" . date("Y-m-d H:i:s");
  
          if ($mainpage == 'on') { 
--- 140,148 ----
          }
  
!         DB_delete ($_TABLES['pollquestions'], 'qid', $qid);
!         DB_delete ($_TABLES['pollanswers'], 'qid', $qid);
  
          $question = addslashes ($question);
!         $sql = "'$qid','$question',$voters,'" . date ('Y-m-d H:i:s');
  
          if ($mainpage == 'on') { 
***************
*** 190,199 ****
  * Diplays the poll editor form
  *
! * @qid      string      ID of poll to edit
  *
  */
! function editpoll($qid='')
  {
!     global $_TABLES, $LANG25, $_CONF, $_USER, $LANG_ACCESS;
  
      $retval = '';
--- 194,204 ----
  * Diplays the poll editor form
  *
! * @param    string  $qid    ID of poll to edit
! * @return   string          HTML for poll editor form
  *
  */
! function editpoll ($qid = '')
  {
!     global $_CONF, $_TABLES, $_USER, $LANG25, $LANG_ACCESS;
  
      $retval = '';
***************
*** 250,254 ****
      $poll_templates->set_var('poll_question', htmlspecialchars ($Q['question']));
      $poll_templates->set_var('lang_mode', $LANG25[1]);
!     $poll_templates->set_var('status_options', COM_optionList($_TABLES['statuscodes'],'code,name',$Q['statuscode'])); 
      $poll_templates->set_var('comment_options', COM_optionList($_TABLES['commentcodes'],'code,name',$Q['commentcode']));
      $poll_templates->set_var('lang_appearsonhomepage', $LANG25[8]);
--- 255,259 ----
      $poll_templates->set_var('poll_question', htmlspecialchars ($Q['question']));
      $poll_templates->set_var('lang_mode', $LANG25[1]);
!     $poll_templates->set_var ('status_options', COM_optionList ($_TABLES['statuscodes'], 'code,name', $Q['statuscode'])); 
      $poll_templates->set_var('comment_options', COM_optionList($_TABLES['commentcodes'],'code,name',$Q['commentcode']));
      $poll_templates->set_var('lang_appearsonhomepage', $LANG25[8]);
***************
*** 312,327 ****
  * lists existing polls
  *
  */
! function listpoll() 
  {
!     global $_TABLES, $_CONF, $LANG25, $LANG_ACCESS;
  
      $retval = '';
  
      $retval .= COM_startBlock ($LANG25[18], '',
                                 COM_getBlockTemplate ('_admin_block', 'header'));
  
!     $poll_templates = new Template($_CONF['path_layout'] . 'admin/poll');
!     $poll_templates->set_file(array('list'=>'polllist.thtml','row'=>'listitem.thtml'));
      $poll_templates->set_var('site_url', $_CONF['site_url']);
      $poll_templates->set_var('site_admin_url', $_CONF['site_admin_url']);
--- 317,340 ----
  * lists existing polls
  *
+ * @param    int     $page   page to display
+ * @return   string          HTML with the list of polls
+ *
  */
! function listpolls ($page = 1) 
  {
!     global $_CONF, $_TABLES, $LANG25, $LANG_ACCESS;
  
      $retval = '';
  
+     if ($page < 1) {
+         $page = 1;
+     }
+ 
      $retval .= COM_startBlock ($LANG25[18], '',
                                 COM_getBlockTemplate ('_admin_block', 'header'));
  
!     $poll_templates = new Template ($_CONF['path_layout'] . 'admin/poll');
!     $poll_templates->set_file (array ('list' => 'polllist.thtml',
!                                       'row'  => 'listitem.thtml'));
      $poll_templates->set_var('site_url', $_CONF['site_url']);
      $poll_templates->set_var('site_admin_url', $_CONF['site_admin_url']);
***************
*** 336,344 ****
      $poll_templates->set_var('lang_appearsonhomepage', $LANG25[8]);
   
!     $result = DB_query("SELECT * FROM {$_TABLES['pollquestions']}");
!     $nrows = DB_numRows($result);
      for ($i = 0; $i < $nrows; $i++) {
!         $A = DB_fetchArray($result);
!         $access = SEC_hasAccess($A['owner_id'],$A['group_id'],$A['perm_owner'],$A['perm_group'],$A['perm_members'],$A['perm_anon']);
          if ($access > 0) {
              if ($access == 3) {
--- 349,361 ----
      $poll_templates->set_var('lang_appearsonhomepage', $LANG25[8]);
   
!     $limit = (POLLS_PER_PAGE * $page) - POLLS_PER_PAGE;
!     $result = DB_query ("SELECT * FROM {$_TABLES['pollquestions']}" . COM_getPermSQL () . " ORDER BY date DESC LIMIT $limit," . POLLS_PER_PAGE);
!     $nrows = DB_numRows ($result);
      for ($i = 0; $i < $nrows; $i++) {
!         $pcount = (POLLS_PER_PAGE * ($page - 1)) + $i + 1;
!         $A = DB_fetchArray ($result);
!         $access = SEC_hasAccess ($A['owner_id'], $A['group_id'],
!                                  $A['perm_owner'], $A['perm_group'],
!                                  $A['perm_members'], $A['perm_anon']);
          if ($access > 0) {
              if ($access == 3) {
***************
*** 347,351 ****
                  $access = $LANG_ACCESS['readonly'];
              }
!             $curtime = COM_getUserDateTimeFormat($A["date"]); 
              if ($A['display'] == 1) {
                  $A['display'] = $LANG25[25];
--- 364,368 ----
                  $access = $LANG_ACCESS['readonly'];
              }
!             $curtime = COM_getUserDateTimeFormat ($A['date']); 
              if ($A['display'] == 1) {
                  $A['display'] = $LANG25[25];
***************
*** 353,367 ****
                  $A['display'] = $LANG25[26];
              }
!             $poll_templates->set_var('question_id', $A['qid']);
!             $poll_templates->set_var('poll_question', $A['question']);
!             $poll_templates->set_var('poll_access', $access);
!             $poll_templates->set_var('poll_votes', $A['voters']);
!             $poll_templates->set_var('poll_createdate', $curtime[0]);
!             $poll_templates->set_var('poll_homepage', $A['display']);
!             $poll_templates->parse('poll_row','row',true);
          }
      }
!     $poll_templates->parse('output', 'list');
!     $retval .= $poll_templates->finish($poll_templates->get_var('output'));
      $retval .= COM_endBlock (COM_getBlockTemplate ('_admin_block', 'footer'));
  
--- 370,398 ----
                  $A['display'] = $LANG25[26];
              }
!             $poll_templates->set_var ('question_id', $A['qid']);
!             $poll_templates->set_var ('poll_question', $A['question']);
!             $poll_templates->set_var ('poll_access', $access);
!             $poll_templates->set_var ('poll_votes', $A['voters']);
!             $poll_templates->set_var ('poll_createdate', $curtime[0]);
!             $poll_templates->set_var ('poll_homepage', $A['display']);
!             $poll_templates->set_var ('row_num', $pcount);
!             $poll_templates->parse ('poll_row', 'row', true);
          }
      }
! 
!     $result = DB_query ("SELECT COUNT(*) AS count FROM {$_TABLES['pollquestions']}" . COM_getPermSQL ());
!     $A = DB_fetchArray ($result);
!     $numpolls = $A['count'];
!     if ($numpolls > POLLS_PER_PAGE) {
!         $baseurl = $_CONF['site_admin_url'] . '/poll.php';
!         $numpages = ceil ($numpolls / POLLS_PER_PAGE);
!         $poll_templates->set_var ('google_paging',
!                 COM_printPageNavigation ($baseurl, $page, $numpages));
!     } else {
!         $poll_templates->set_var ('google_paging', '');
!     }
! 
!     $poll_templates->parse ('output', 'list');
!     $retval .= $poll_templates->finish ($poll_templates->get_var ('output'));
      $retval .= COM_endBlock (COM_getBlockTemplate ('_admin_block', 'footer'));
  
***************
*** 372,375 ****
--- 403,409 ----
  * Delete a poll
  *
+ * @param    string  $qid    ID of poll to delete
+ * @return   string          HTML redirect
+ *
  */
  function deletePoll ($qid)
***************
*** 396,412 ****
  $display = '';
  
  if ($mode == 'edit') {
      $display .= COM_siteHeader ('menu');
!     $display .= editpoll ($qid);
      $display .= COM_siteFooter ();
  } else if (($mode == $LANG25[14]) && !empty ($LANG25[14])) { // save
      if (!empty ($qid)) {
          $voters = 0;
!         for ($i = 0; $i < sizeof ($answer); $i++) {
!             $voters = $voters + $votes[$i];
          }
!         $display .= savepoll ($qid, $mainpage, $question, $voters, $statuscode,
!                         $commentcode, $answer, $votes, $owner_id, $group_id,
!                         $perm_owner, $perm_group, $perm_members, $perm_anon);
      } else {
          $display .= COM_siteHeader ('menu');
--- 430,461 ----
  $display = '';
  
+ if (isset ($HTTP_POST_VARS['mode'])) {
+     $mode = $HTTP_POST_VARS['mode'];
+ } else {
+     $mode = $HTTP_GET_VARS['mode'];
+ }
+ 
  if ($mode == 'edit') {
      $display .= COM_siteHeader ('menu');
!     $display .= editpoll (COM_applyFilter ($HTTP_GET_VARS['qid']));
      $display .= COM_siteFooter ();
  } else if (($mode == $LANG25[14]) && !empty ($LANG25[14])) { // save
+     $qid = COM_applyFilter ($HTTP_POST_VARS['qid']);
      if (!empty ($qid)) {
          $voters = 0;
!         for ($i = 0; $i < sizeof ($HTTP_POST_VARS['answer']); $i++) {
!             $voters = $voters + $HTTP_POST_VARS['votes'][$i];
          }
!         $display .= savepoll ($qid, $HTTP_POST_VARS['mainpage'],
!                         $HTTP_POST_VARS['question'], $voters,
!                         COM_applyFilter ($HTTP_POST_VARS['statuscode'], true),
!                         COM_applyFilter ($HTTP_POST_VARS['commentcode'], true),
!                         $HTTP_POST_VARS['answer'], $HTTP_POST_VARS['votes'],
!                         $HTTP_POST_VARS['owner_id'],
!                         $HTTP_POST_VARS['group_id'],
!                         $HTTP_POST_VARS['perm_owner'],
!                         $HTTP_POST_VARS['perm_group'],
!                         $HTTP_POST_VARS['perm_members'],
!                         $HTTP_POST_VARS['perm_anon']);
      } else {
          $display .= COM_siteHeader ('menu');
***************
*** 419,424 ****
      }
  } else if (($mode == $LANG25[16]) && !empty ($LANG25[16])) { // delete
      if (!isset ($qid) || empty ($qid)) {
!         COM_errorLog ('Attempted to delete poll qid=' . $qid);
          $display .= COM_refresh ($_CONF['site_admin_url'] . '/poll.php');
      } else {
--- 468,474 ----
      }
  } else if (($mode == $LANG25[16]) && !empty ($LANG25[16])) { // delete
+     $qid = COM_applyFilter ($HTTP_POST_VARS['qid']);
      if (!isset ($qid) || empty ($qid)) {
!         COM_errorLog ('Attempted to delete poll qid=' . $HTTP_POST_VARS['qid']);
          $display .= COM_refresh ($_CONF['site_admin_url'] . '/poll.php');
      } else {
***************
*** 426,435 ****
      }
  } else { // 'cancel' or no mode at all
!     $display .= COM_siteHeader('menu');
!     if (isset ($msg)) {
!         $display .= COM_showMessage($msg);
      }
!     $display .= listpoll();
!     $display .= COM_siteFooter();
  }
  
--- 476,495 ----
      }
  } else { // 'cancel' or no mode at all
!     $display .= COM_siteHeader ('menu');
!     if (isset ($HTTP_POST_VARS['msg'])) {
!         $msg = COM_applyFilter ($HTTP_POST_VARS['msg'], true);
!     } else {
!         $msg = COM_applyFilter ($HTTP_GET_VARS['msg'], true);
      }
!     if (isset ($msg) && ($msg > 0)) {
!         $display .= COM_showMessage ($msg);
!     }
!     if (isset ($HTTP_POST_VARS['page'])) {
!         $page = $HTTP_POST_VARS['page'];
!     } else {
!         $page = $HTTP_GET_VARS['page'];
!     }
!     $display .= listpolls ($page);
!     $display .= COM_siteFooter ();
  }
  




More information about the geeklog-cvs mailing list