Location: PHPKode > projects > phpBannerEx > adm_var.php
<?
#################################################################################################
#
#  project              : phpBannerEx
#  filename             : .php
#  last modified by     : 
#  e-mail               : hide@address.com
#  purpose              :
#
#################################################################################################

#  Include Configs & Variables
#################################################################################################
require("admin/config.php");
require("library.php");

db_connect();
ReadConfig();

$user = authorize();

if($user[ur_id] != 1) {
  unauthorize();
  print "<script> document.location=document.location; </script>";
  exit;
}


function main_list() {
  global $show_languages,$lang;

  echo "<center>\n";
  echo "<form name=\"frmVarAdm\" method=post>\n";

  echo "<h1>".get_msg("variables",$lang)."</h1>\n";
  echo "<table class=list>\n";
  echo "  <tr>\n";
  echo "    <th class=list>".get_msg('variable', $lang)."</th>\n";
  echo "    <th class=list>".get_msg("value",$lang)."</th>\n";
  echo "  </tr>\n";

  # scalars
  $sql = "SELECT * FROM var LEFT JOIN msg ON (concat('var_',vr_name) = ms_kw AND ms_lang_ref = '$lang') WHERE vr_type='Scalar' ORDER BY vr_name"; $res = db_query($sql);
  while($row = mysql_fetch_array($res)) {
    if($row[ms_text]) {
      $descr = $row[ms_text];
    } else {
      $descr = $row[vr_name];
    }
    echo "  <tr>\n";
    echo "    <td class=list align=left>$descr:</td>\n";
    echo "    <td class=list><input type=text name=\"var[$row[vr_id]]\" value=\"$row[vr_value]\" size=40></td>\n";
    echo "   </tr>\n";
  }

  # arrays
  $sql = "SELECT * FROM var LEFT JOIN msg ON (concat('var_',vr_name) = ms_kw AND ms_lang_ref = '$lang') WHERE vr_type='Array' ORDER BY vr_name"; $res = db_query($sql);
  while($row = mysql_fetch_array($res)) {
    if($row[ms_text]) {
      $descr = $row[ms_text];
    } else {
      $descr = $row[vr_name];
    }
    echo "  <tr>\n";
    echo "    <td class=list align=left>$descr:</td>\n";
    echo "    <td class=list>\n";
    $sql = "SELECT * FROM var_d WHERE vd_var_ref = '$row[vr_id]'"; $res_d = db_query($sql);
    $i = 0;
    while ($row_d = mysql_fetch_array($res_d)) {
      echo "      <input type=text name=\"arr[$row[vr_id]_$i]\" value=\"$row_d[vd_value]\" size=40><br>\n";
      $i++;
    }
    for($j=1;$j<=3;$j++) {
      echo "      <input type=text name=\"arr[$row[vr_id]_$i]\" value=\"$row_d[vd_value]\" size=40><br>\n";
      $i++;
    }

    echo "    </td>\n";
    echo "  </tr>\n";
  }

  echo "</table>\n";
  echo "<input type=hidden name=lang value=\"$lang\">";
  echo "<input type=hidden name=act value=var_change>";
  echo "<input type=submit value=\"".get_msg(save,$lang)." ".get_msg(variables,$lang)."\">\n";
  echo "<input type=reset value=\"".get_msg(reset,$lang)." ".get_msg(variables,$lang)."\">\n";
  echo "<input type=button value=\"".get_msg(goback,$lang)."\" onClick=\"javascript:document.location='adm.php';\">\n";
  echo "</form>\n";
}

function var_change() {
  global $lang, $var, $arr;

  while(list($key, $val) = each($var)) {
    db_query("UPDATE var SET vr_value='$val' WHERE vr_id='$key'");
  }

  db_query("DELETE FROM var_d");
  while(list($key, $val) = each($arr)) {
    if ($val) {
      list($vr_id, $vd_id) = split("_", $key);
      db_query("INSERT INTO var_d (vd_var_ref, vd_value) VALUES ('$vr_id', '$val')");
    }
  }

  main_list();
}

include($addheader);

include("adm_menu.inc");

if(!$act) { main_list(); }

if($act == "var_change") { var_change(); }

include("$addfooter");


?>
Return current item: phpBannerEx