products_attributes_add_a.php

来自「全新且完善的强大网上商店系统」· PHP 代码 · 共 275 行

PHP
275
字号
<?php
/*
  [SOOBIC!] admin/products_attributes_add_a.php 

	Version: 1.5
	Author: Soolan (soolan@qq.com)
	Copyright: soolan (www.soobic.com)
	Last Modified: 2005/4/3 10:00

*/
if(!defined('IN_SOOBIC')) {
        exit('Access Denied');
}

require('admin/languages/'.$language.'/products_attributes.php');

cpheader();
$languages = tep_get_languages();

if (tep_not_null($action)) {
    $page_info = '';
    if (isset($HTTP_GET_VARS['option_page'])) $page_info .= 'option_page=' . $HTTP_GET_VARS['option_page'] . '&';
    if (isset($HTTP_GET_VARS['value_page'])) $page_info .= 'value_page=' . $HTTP_GET_VARS['value_page'] . '&';
    if (isset($HTTP_GET_VARS['attribute_page'])) $page_info .= 'attribute_page=' . $HTTP_GET_VARS['attribute_page'] . '&';
    if (tep_not_null($page_info)) {
        $page_info = substr($page_info, 0, -1);
    }

    switch ($action) {
      case 'add_product_options':
         $option_name_array = $option_name;

         for ($i=0, $n=sizeof($languages); $i<$n; $i ++) {
            $option_name = ($option_name_array[$languages[$i]['id']]);

            $db->query("insert into $table_products_options (products_options_id, products_options_name, language_id) values ('" . (int)$products_options_id . "', '" . ($option_name) . "', '" . (int)$languages[$i]['id'] . "')");
         }
         tep_redirect(tep_href_link('admincp.php', 'act=products_attributes_add_a&'.$page_info));
      break;
      case 'update_option_name':
         $option_name_array = $HTTP_POST_VARS['option_name'];
         $option_id = tep_db_prepare_input($HTTP_POST_VARS['option_id']);

         for ($i=0, $n=sizeof($languages); $i<$n; $i ++) {
            $option_name = tep_db_prepare_input($option_name_array[$languages[$i]['id']]);

             $db->query("update $table_products_options set products_options_name = '" . ($option_name) . "' where products_options_id = '" . (int)$option_id . "' and language_id = '" . (int)$languages[$i]['id'] . "'");
         }

         tep_redirect(tep_href_link('admincp.php', 'act=products_attributes_add_a&'.$page_info));
      break;
      case 'delete_option':
         $db->query("delete from $table_products_options where products_options_id = '" . (int)$option_id . "'");

         tep_redirect(tep_href_link('admincp.php', 'act=products_attributes_add_a&'.$page_info));
      break;
   }
}elseif (tep_not_null($type)) {
   
	 switch($type){
      case 'update_option':
         $query = $db->query("select * from $table_products_options where language_id = '" . (int)$languages_id . "' and products_options_id='$option_id' order by $option_order_by ");
         $options_values = $db->fetch_array($query);
				 $inputs = '';
         for ($i = 0, $n = sizeof($languages); $i < $n; $i ++) {
             $option_name = $db->query("select products_options_name from $table_products_options where products_options_id = '" . $options_values['products_options_id'] . "' and language_id = '" . $languages[$i]['id'] . "'");
             $option_name = $db->fetch_array($option_name);
             $inputs .= $languages[$i]['code'] . ':&nbsp;<input type="text" name="option_name[' . $languages[$i]['id'] . ']" size="20" value="' . $option_name['products_options_name'] . '">&nbsp;<br>';
         }
?>
<form name="options" action="<?=tep_href_link('admincp.php', 'act=products_attributes_add_a&action=update_option_name&option_page=' . $option_page, 'NONSSL')?>" method="post">
<table cellspacing="0" cellpadding="0" border="0" width="95%" align="center">
<tr><td bgcolor="<?=BORDERCOLOR?>">
<table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%">
						  <tr class="header">
                <td >&nbsp;<?php echo TABLE_HEADING_ID; ?>&nbsp;</td>
                <td >&nbsp;<?php echo TABLE_HEADING_OPT_NAME; ?>&nbsp;</td>
              </tr>
						  <tr bgcolor="<?=ALTBG2?>">
                <td align="center">&nbsp;<?php echo $options_values['products_options_id']; ?><input type="hidden" name="option_id" value="<?php echo $options_values['products_options_id']; ?>">&nbsp;</td>
                <td ><?php echo $inputs; ?></td>
</tr></table></td></tr></table>
<br>
<center><?php echo tep_image_submit('button_update.gif', IMAGE_UPDATE); ?>&nbsp;<?php echo '<a href="' . tep_href_link('admincp.php', 'act=products_attributes', 'NONSSL') . '">'; ?><?php echo tep_image_button('button_cancel.gif', IMAGE_CANCEL); ?></a></center>
</form>
<?php
      break;
      case 'delete_product_option':
         $options = $db->query("select products_options_id, products_options_name from $table_products_options where products_options_id = '" . (int)$HTTP_GET_VARS['option_id'] . "' and language_id = '" . (int)$languages_id . "'");
         $options_values = $db->fetch_array($options);
?>
<table cellspacing="0" cellpadding="0" border="0" width="95%" align="center">
<tr><td bgcolor="<?=BORDERCOLOR?>">
<table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%">
<tr bgcolor="<?=ALTBG2?>"><td>选项名称:<?php echo $options_values['products_options_name']; ?></td>
</tr>
</table></td></tr></table>
<br>
<?php
         $products = $db->query("select p.products_id, pd.products_name, pov.products_options_values_name from $table_products p, $table_products_options_values pov, $table_products_attributes pa, $table_products_description pd where pd.products_id = p.products_id and pov.language_id = '" . (int)$languages_id . "' and pd.language_id = '" . (int)$languages_id . "' and pa.products_id = p.products_id and pa.options_id='" . (int)$HTTP_GET_VARS['option_id'] . "' and pov.products_options_values_id = pa.options_values_id order by pd.products_name");
         if ($db->num_rows($products)) {
?>
<table cellspacing="0" cellpadding="0" border="0" width="95%" align="center">
<tr><td bgcolor="<?=BORDERCOLOR?>">
<table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%">
                  <tr class="header">
                    <td align="center">&nbsp;<?php echo TABLE_HEADING_ID; ?>&nbsp;</td>
                    <td>&nbsp;<?php echo TABLE_HEADING_PRODUCT; ?>&nbsp;</td>
                    <td>&nbsp;<?php echo TABLE_HEADING_OPT_VALUE; ?>&nbsp;</td>
                  </tr>
<?php
             $rows = 0;
             while ($products_values = $db->fetch_array($products)) {
                $rows++;
?>
                  <tr bgcolor="<?=ALTBG2?>">
                    <td align="center">&nbsp;<?php echo $products_values['products_id']; ?>&nbsp;</td>
                    <td>&nbsp;<?php echo $products_values['products_name']; ?>&nbsp;</td>
                    <td>&nbsp;<?php echo $products_values['products_options_values_name']; ?>&nbsp;</td>
                  </tr>
<?php
             }
?>
</table></td></tr></table><br>
<table cellspacing="0" cellpadding="0" border="0" width="95%" align="center">
<tr><td bgcolor="<?=BORDERCOLOR?>">
<table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%">
<tr class="header"><td colspan="7">Soobic! 提示</td></tr>
                  <tr bgcolor="<?=ALTBG2?>">
                    <td align="center"><br><?php echo TEXT_WARNING_OF_DELETE; ?><br><br><br><br><?php echo '<a href="' . tep_href_link('admincp.php', 'act=products_attributes_add_a&'.(isset($HTTP_GET_VARS['value_page']) ? 'value_page=' . $HTTP_GET_VARS['value_page'] . '&' : '') . (isset($HTTP_GET_VARS['attribute_page']) ? 'attribute_page=' . $HTTP_GET_VARS['attribute_page'] : ''), 'NONSSL') . '">'; ?><?php echo tep_image_button('button_cancel.gif', ' cancel '); ?></a></td>
                  </tr>
</table></td></tr></table>
<?php
         } else {
?>
<br>
<table cellspacing="0" cellpadding="0" border="0" width="95%" align="center">
<tr><td bgcolor="<?=BORDERCOLOR?>">
<table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%">
<tr class="header"><td colspan="7">Soobic! 提示</td></tr>
                  <tr bgcolor="<?=ALTBG2?>">
                    <td align="center"><br><?php echo TEXT_OK_TO_DELETE; ?><br><br><br><br><?php echo '<a href="' . tep_href_link('admincp.php', 'act=products_attributes_add_a&action=delete_option&option_id=' . $HTTP_GET_VARS['option_id'], 'NONSSL') . '">'; ?><?php echo tep_image_button('button_delete.gif', ' delete '); ?></a>&nbsp;&nbsp;&nbsp;<?php echo '<a href="' . tep_href_link('admincp.php', 'act=products_attributes_add_a&'.(isset($HTTP_GET_VARS['order_by']) ? 'order_by=' . $HTTP_GET_VARS['order_by'] . '&' : '') . (isset($HTTP_GET_VARS['page']) ? 'page=' . $HTTP_GET_VARS['page'] : ''), 'NONSSL') . '">'; ?><?php echo tep_image_button('button_cancel.gif', ' cancel '); ?></a></td>
                  </tr>
</table></td></tr></table>  

<?php
         }
         break;
    }
}else{
?>
<script language="javascript"><!--
function go_option() {
  if (document.option_order_by.selected.options[document.option_order_by.selected.selectedIndex].value != "none") {
    location = "<?php echo tep_href_link('admincp.php', 'act=products_attributes_add_a&option_page=' . ($HTTP_GET_VARS['option_page'] ? $HTTP_GET_VARS['option_page'] : 1)); ?>&option_order_by="+document.option_order_by.selected.options[document.option_order_by.selected.selectedIndex].value;
  }
}
//--></script>
<?

    if (isset($HTTP_GET_VARS['option_order_by'])) {
        $option_order_by = $HTTP_GET_VARS['option_order_by'];
    } else {
        $option_order_by = 'products_options_id';
    }
?>
<table cellspacing="0" cellpadding="0" border="0" width="95%" align="center">
<tr><td bgcolor="<?=BORDERCOLOR?>">
<table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%">
<tr bgcolor="<?=ALTBG2?>"><td>&nbsp;<?php echo HEADING_TITLE_OPT; ?>&nbsp;</td><td align="center"><form name="option_order_by" action="<?=tep_href_link('admincp.php','act=products_attributes_add_a')?>"><select name="selected" onChange="go_option()"><option value="products_options_id"<?php if ($option_order_by == 'products_options_id') { echo ' SELECTED'; } ?>><?php echo TEXT_OPTION_ID; ?></option><option value="products_options_name"<?php if ($option_order_by == 'products_options_name') { echo ' SELECTED'; } ?>><?php echo TEXT_OPTION_NAME; ?></option></select></form></td>
</tr></table></td></tr></table>
<br>             
<table cellspacing="0" cellpadding="0" border="0" width="95%" align="center">
<tr><td bgcolor="<?=BORDERCOLOR?>">
<table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%">
						 
						  <tr bgcolor="<?=ALTBG2?>">
                <td>
<?php
    $per_page = MAX_ROW_LISTS_OPTIONS;
    $options = "select * from $table_products_options where language_id = '" . (int)$languages_id . "' order by " . $option_order_by;
    if (!isset($option_page)) {
        $option_page = 1;
    }
    $prev_option_page = $option_page - 1;
    $next_option_page = $option_page + 1;

    $option_query = $db->query($options);

    $option_page_start = ($per_page * $option_page) - $per_page;
    $num_rows = $db->num_rows($option_query);

    if ($num_rows <= $per_page) {
        $num_pages = 1;
    } else if (($num_rows % $per_page) == 0) {
        $num_pages = ($num_rows / $per_page);
    } else {
        $num_pages = ($num_rows / $per_page) + 1;
    }
    $num_pages = (int) $num_pages;

    $options = $options . " LIMIT $option_page_start, $per_page";

    if ($prev_option_page)  {
        echo '<a href="' . tep_href_link('acmincp.php', 'act=products_attributes&option_page=' . $prev_option_page) . '"> &lt;&lt; </a> | ';
    }

    for ($i = 1; $i <= $num_pages; $i++) {
        if ($i != $option_page) {
            echo '<a href="' . tep_href_link('acmincp.php', 'act=products_attributes&option_page=' . $i) . '">' . $i . '</a> | ';
        } else {
            echo '<b><font color=red>' . $i . '</font></b> | ';
        }
    }
    if ($option_page != $num_pages) {
        echo '<a href="' . tep_href_link('acmincp.php', 'act=products_attributes&option_page=' . $next_option_page) . '"> &gt;&gt; </a>';
    }
?>
                </td>
              </tr>
</tr></table></td></tr></table>
<br>
<?php
    echo '<form name="options" action="' . tep_href_link('admincp.php', 'act=products_attributes_add_a&action=add_product_options&option_page=' . $option_page, 'NONSSL') . '" method="post">';
?>
<table cellspacing="0" cellpadding="0" border="0" width="95%" align="center">
<tr><td bgcolor="<?=BORDERCOLOR?>">
<table border="0" cellspacing="<?=BORDERWIDTH?>" cellpadding="<?=TABLESPACE?>" width="100%">
						<tr class="header">
                <td >&nbsp;<?php echo TABLE_HEADING_ID; ?>&nbsp;</td>
                <td >&nbsp;<?php echo TABLE_HEADING_OPT_NAME; ?>&nbsp;</td>
                <td align="center">&nbsp;<?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
              </tr>
<?php
    $next_id = 1;
    $rows = 0;
    $options = $db->query($options);
    while ($options_values = $db->fetch_array($options)) {
?>
              <tr bgcolor="<?=ALTBG2?>">
                <td align="center">&nbsp;<?php echo $options_values["products_options_id"]; ?>&nbsp;</td>
                <td >&nbsp;<?php echo $options_values["products_options_name"]; ?>&nbsp;</td>
                <td align="center">&nbsp;<?php echo '<a href="' . tep_href_link('admincp.php', 'act=products_attributes_add_a&type=update_option&option_id=' . $options_values['products_options_id'] . '&option_order_by=' . $option_order_by . '&option_page=' . $option_page, 'NONSSL') . '">'; ?><?=IMAGE_UPDATE?></a>&nbsp;&nbsp;<?php echo '<a href="' . tep_href_link('admincp.php', 'act=products_attributes_add_a&type=delete_product_option&option_id=' . $options_values['products_options_id'], 'NONSSL') , '">'; ?><?=IMAGE_DELETE?></a>&nbsp;</td>
              </tr>
<?php
    }
?>
<?php
    $max_options_id_query = $db->query("select max(products_options_id) + 1 as next_id from $table_products_options");
    $max_options_id_values = $db->fetch_array($max_options_id_query);
    $next_id = $max_options_id_values['next_id'];
?>
              <tr bgcolor="<?=ALTBG2?>">
<?php
    $inputs = '';
    for ($i = 0, $n = sizeof($languages); $i < $n; $i ++) {
        $inputs .= $languages[$i]['code'] . ':&nbsp;<input type="text" name="option_name[' . $languages[$i]['id'] . ']" size="20">&nbsp;<br>';
    }
?>
                <td align="center" ><input type="hidden" name="products_options_id" value="<?=$next_id?>"><?php echo $next_id; ?></td>
                <td ><?php echo $inputs; ?></td>
                <td align="center">&nbsp;</td>
<?php
?>
              </tr>
</table></td></tr></table>

<br>
<center><?php echo tep_image_submit('button_insert.gif', IMAGE_INSERT); ?></center>

</form>
<?php
}
?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?