<?php

/***************************************************************************

 m_userdata.php
 ---------------
 copyright : (C) 2002-2003 The ezContents Development Team

 ***************************************************************************/

/***************************************************************************
 The ezContents Development Team offers no warranties on this script.
 The owner/licensee of the script is solely responsible for any problems
 caused by installation of the script or use of the script.

 All copyright notices regarding ezContents must remain intact on the
 scripts and in the HTML for the scripts.

 For more info on ezContents,
 visit http://www.ezcontents.org/

/***************************************************************************

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the License which can be found within the
 *   zipped package.
 *
 ***************************************************************************/

include_once ("rootdatapath.php");
require_once ($GLOBALS["rootdp"]."include/config.php");
require_once ($GLOBALS["rootdp"]."include/db.php");
require_once ($GLOBALS["rootdp"]."include/session.php");

include ($GLOBALS["rootdp"]."include/access.php");

$GLOBALS["form"] = 'userdata';
$GLOBALS["validaccess"] = VerifyAdminLogin();


include ($GLOBALS["rootdp"]."include/settings.php");
include ($GLOBALS["rootdp"]."include/functions.php");
include ("adminfunctions.php");
include ("adminbutton.php");
includeLanguageFiles('admin','userdata');


force_page_refresh();
frmUserdata();


function frmUserdata()
{
   global $HTTP_GET_VARS;

   adminheader();
   admintitle(4,$GLOBALS["tFormTitle"]);
   adminbuttons('','',$GLOBALS["tToggleUserdata"],'');
   $GLOBALS["iToggle"] = lsimagehtmltag($GLOBALS["icon_home"],'rel_button.gif',$GLOBALS["gsLanguage"],$GLOBALS["tToggleUserdata"],0);

   $lRecCount = 0;
   $strQuery = "SELECT * FROM ".$GLOBALS["eztbUserdata"];
   $result = dbRetrieve($strQuery,true,0,0);
   while ($rs = dbFetch($result)) {
      $userdatavar     = $rs["userdatavar"];
      $userdatatype    = $rs["userdatatype"];
      $userdatavalue   = $rs["userdatavalue"];
      if (($userdatavar != '') && ($userdatatype != '')) {
         switch ($userdatatype) {
            case '!='  : if ($GLOBALS[$userdatavar] != $userdatavalue) { $lRecCount++; }
                         break;
            case '=='  :
            default    : if ($GLOBALS[$userdatavar] == $userdatavalue) { $lRecCount++; }
                         break;
         }
      } else { $lRecCount++; }
   }
   dbFreeResult($result);

   $nCurrentPage = 0;
   if ($HTTP_GET_VARS["page"] != "") { $nCurrentPage = $HTTP_GET_VARS["page"]; }
   if ($HTTP_GET_VARS["sort"] == '') { $HTTP_GET_VARS["sort"] = 1; }
   $nPages = intval(($lRecCount - 0.5) / $GLOBALS["RECORDS_PER_PAGE"]) + 1;
   if ($nCurrentPage >= $nPages) { $nCurrentPage = 0; }
   $lStartRec = $nCurrentPage * $GLOBALS["RECORDS_PER_PAGE"];

   adminHdFt('userdata',4,$nCurrentPage,$nPages,'');
   ?>
   <tr class="teaserheadercontent">
       <?php
       adminlistitem(10,$GLOBALS["tEdit"],'c');
       adminlistitem(70,$GLOBALS["tUserdataname"],'');
       adminlistitem(15,$GLOBALS["tEnabled"],'c');
       adminlistitem(5,'&nbsp;','');
       ?>
   </tr>
   <?php

   $count = 0;
   $pcount = 0;
   $strQuery = "SELECT * FROM ".$GLOBALS["eztbUserdata"]." ORDER BY userdataorderid";
   $result = dbRetrieve($strQuery,true,0,0);
   while ($rs = dbFetch($result)) {
      $count++;
      $userdatavar     = $rs["userdatavar"];
      $userdatatype    = $rs["userdatatype"];
      $userdatavalue   = $rs["userdatavalue"];
      $userdatadisplay = True;
      if (($userdatavar != '') && ($userdatatype != '')) {
         $userdatadisplay = False;
         switch ($userdatatype) {
            case '!='  : if ($GLOBALS[$userdatavar] != $userdatavalue) { $userdatadisplay = True; }
                         break;
            case '=='  :
            default    : if ($GLOBALS[$userdatavar] == $userdatavalue) { $userdatadisplay = True; }
                         break;
         }
      }
      if (($userdatadisplay) && ($count > $lStartRec) && ($pcount < $GLOBALS["RECORDS_PER_PAGE"])) {
         $pcount++;
         ?>
         <tr class="teasercontent">
            <td align="center" valign="top" class="content">
                <?php
                  $fLink = BuildLink('m_userdatatoggle.php').'&UserdataName='.$rs["userdataname"].'&page='.$HTTP_GET_VARS["page"];
                  if ($GLOBALS["canedit"] == True) {
                     ?>
                     <a href="<?php echo $fLink; ?>" <?php echo BuildLinkMouseOver($GLOBALS["tToggleUserdata"]); ?>>
                     <?php echo $GLOBALS["iToggle"]; ?></a><?php
                  } else {
                     // No privileges
                     echo $GLOBALS["iBlank"];
                  }
                  ?>
            </td>
            <td valign="top" class="content">
                <?php echo $GLOBALS["td".$rs["userdataname"]]; ?>
            </td>
            <td valign="top" align="center" class="content">
                <?php
                if ($rs["userdataenabled"] == '1') { echo $GLOBALS["tYes"];
                } else { echo $GLOBALS["tNo"]; }
                ?>
            </td>
            <td valign="top" class="content">
                <?php adminmovecheck('up','UserdataMove','UserdataName',$rs["userdataname"]); ?>
                <?php adminmovecheck('down','UserdataMove','UserdataName',$rs["userdataname"]); ?>
            </td>
         </tr>
         <?php
      }
   }
   dbFreeResult($result);

   adminHdFt('userdata',4,$nCurrentPage,$nPages,'');
   ?>
   </table>
   </body>
   </html>
   <?php
} // function frmUserdata()

?>
<script language="Javascript" type="text/javascript">
    <!-- Begin
    function UserdataMove(sParams) {
       location.href='<?php echo BuildLink('m_userdatamove.php'); ?>&' + sParams;
    }
    //  End -->
</script>
