/modules/products/add_products.php
PHP | 302 lines | 286 code | 16 blank | 0 comment | 6 complexity | a8dbecf5add1a69caf22e255e0957c0d MD5 | raw file
- <div class="page">
- <div class="menu" style="margin-top:-50px;">
- <?php include('modules/members/dashboard.php');?>
- </div>
- <div class="products" style="margin-left: 40px;">
- <?php if($_GET['ad_by_upload']){ ?>
- <div class="add-products-header" style="width:570px;overflow:hidden;margin:0 auto;padding:10px;">
- <form action="?m=products&p=add_products&ad_by_upload=true&process=true" method="post" enctype="multipart/form-data">
- <h2>???????????????? CSV ????????</h2>
- <p style="text-indent:30px;color:blue;margin-bottom:15px;">?????????????????????? Excel(.xls) ???? CSV(.csv) ??????????? <span style="color:red;">(???????????????????????????? .xls ??? ??????????? .xls ?????????????????????????????? windows server ???? IIS ??? server ?????????????? MS Office ????????) </span></p>
- <h3>???????????????????????</h3>
- <table border="1" cellpadding="0" cellspacing="0">
- <tr align="center">
- <td width="150">????????????</td>
- <td width="150">???? / ?????</td>
- <td width="150">??????????????</td>
- <td width="150">????????</td>
- </tr>
- </table>
- <div class="clear" style="margin: 20px;"></div>
- <div align="center">
- <input type="file" name="products_file" id="products_file" size="50" align="middle"/>
- <div class="clear" style="margin-top:20px;"></div>
- <input type="submit" value="?????????" />
- </div>
- </form>
- </div>
- <?php if($_GET['process']){ ?>
- <div style="width:570px;overflow:hidden;margin:0 auto;padding:10px;">
- <?php
- copy($_FILES["products_file"]["tmp_name"],'uploads/'.$_FILES["products_file"]["name"]);
-
- $csvfile = 'uploads/'.$_FILES["products_file"]["name"];
- $databasetable = "products";
- $fieldseparator = ",";
- $lineseparator = "\n";
- $addauto = 1;
- $has_id = 1;
- $save = 0;
- $lines = 0;
- $queries = "";
- $linearray = array();
- $first_loop = false;
-
- $u = mysql_query('SELECT * FROM units');
-
- if(!file_exists($csvfile)) {
- echo "?????????.\n";
- exit;
- }
-
- $file = fopen($csvfile,"r");
-
- if(!$file) {
- echo "Error ????????????????????.\n";
- exit;
- }
-
- $size = filesize($csvfile);
-
- if(!$size) {
- echo "???????????????.\n";
- exit;
- }
-
- $csvcontent = fread($file,$size);
-
- fclose($file);
-
- foreach(split($lineseparator,$csvcontent) as $line) {
-
- $lines++;
-
- $line = trim($line," \t");
-
- $line = str_replace("\r","",$line);
-
- $line = str_replace("'","\'",$line);
-
- $linearray = explode($fieldseparator,$line);
- $arr = explode('/',$linearray[1]);
- $count = count($linearray)+4;
- $j=false;
- $k=true;
- $newarray = array();
- foreach($linearray as $value){
- if($j){
- $newarray[] = $arr[0];
- $newarray[] = $arr[1];
- $newarray[] = 0;
- $k= false;
- $j= false;
- }else{
- $newarray[] = $value;
- if($k) $j = true;
- }
-
- }
-
- mysql_data_seek($u,0);
- while($r = mysql_fetch_assoc($u)){
- $unit = iconv('tis-620','utf-8', $newarray[2]);
- if($r['name'] == $unit){
- $newarray[2] = $r['id'];
- }
- }
-
- $linemysql = implode("','",$newarray);
-
- for($i=$count;$i<12;$i++){
- $linemysql .= "','";
- }
-
- if($addauto == 1 && $has_id == 1)
- if($first_loop){
- $query = "insert into $databasetable values(NULL,'$lines".date('dmYHms',time())."','".iconv('tis-620','utf-8',$linemysql)."');";
- }else{
- $lines = 0;
- $first_loop = true;
- }
-
- elseif($addauto == 1 && $has_id == 0)
- $query = "insert into $databasetable values(NULL,'".iconv('tis-620','utf-8',$linemysql)."');";
- elseif($first_loop && $linemysql != "" && $has_id == 1)
- $query = "insert into $databasetable values('$lines".date('dmYHms',time())."','".iconv('tis-620','utf-8',$linemysql)."');";
- elseif($first_loop && $linemysql != "" && $has_id == 0)
- $query = "insert into $databasetable values('".iconv('tis-620','utf-8',$linemysql)."');";
- else
- $first_loop = true;
-
- $queries .= $query . "\n<br/>";
- if($newarray[0] != "" && $query != "") mysql_query($query)or die(mysql_error());
- //echo "??????????????? $lines records <br/>";
- //if($query != "") mysql_query($query)or die(mysql_error());
- }
- //echo $queries;
- //mysql_close($con);
-
- if($save) {
- if(!is_writable($outputfile)) {
- echo "?????????????????????????????????\n";
- }else {
- $file2 = fopen($outputfile,"w");
-
- if(!$file2) {
- echo "?????????????????????.\n";
- }else {
- fwrite($file2,$queries);
- fclose($file2);
- }
- }
-
- }
-
- echo "????????????????????????? $lines records ??????? ".substr($csvfile,strrpos($csvfile,'/')+1)."\n";
- ?>
- </div>
- <?php }?>
- <?php }else{?>
- <p style="margin-left: 60px;margin-top:0px;float:right;" id="button">
- <a href="?m=products&p=add_products&ad_by_upload=true" class="btn" style="font-size:25px;" id="add_by_upload"><span>?????????????????????????</span></a>
- </p>
- <div class="clear"></div>
- <div class="add-products-header">
- <span class="header">????????????</span>
- <span class="header" style="margin-left:55px;">????</span>
- <span class="header" style="margin-left:40px;margin-right:-11px;">?????</span>
- <span class="header" >?????</span>
- <span class="header" style="margin-left:23px;">??????????????</span>
- <span class="header" style="margin-left:40px;">????????</span>
- </div>
- <form action="#" method="POST" id="add_product_form">
- <div class="products-group">
- <div class="products-input-template">
- <input type="text" name="name" id="pname" value="" style="width:155px;height:20px;"/>
- <input type="text" name="price" id="pprice" value="" style="width:80px;height:20px;"/>
- <select name="unit" id="unit" style="margin-right:10px;">
- <?php
- $sql = 'SELECT * FROM units';
- $q = $db->select_query($sql);
- while($rs = $db->fetch($q)){
- ?>
- <option value="<?php echo $rs['id'];?>"><?php echo $rs['name'];?></option>
- <?php } ?>
- </select>
- <input type="text" name="num" id="pnum" value="" style="width:80px;height:20px;"//>
- <input type="text" name="promotion" id="ppromotion" value="" style="width:155px;height:20px;"//>
- <input type="text" name="detail" id="pdetail" value="" style="width:155px;height:20px;"//>
- <input type="hidden" name="code" id="pcode" value="<?php echo genStr(); ?>" />
- <!--<a href="#" onClick="return false;" id="del_row">
- <img src="css/images/delete.png" alt="?????" />
- </a>-->
- </div>
- </div>
- </form>
- </div>
- <p style="margin-left: 60px;margin-top:25px;" id="button">
- <a href="#" class="btn" style="font-size:25px;" id="add_products" onClick="return false;"><span>???????????</span></a>
- <span class="loading"></span>
- </p>
- <div class="clear"></div>
- <form action="#" method="POST" id="add_product_form" style="margin-left: 40px; height: 200px;margin-bottom: 20px;overflow: hidden;">
- <div class="products-group">
- <h2>5 ??????????????????</h2>
- <table id="products_list" width="100%">
- <thead>
- <tr>
- <th width="40">ID</th>
- <th>????????????</th>
- <th>????</th>
- <th>?????</th>
- <th>???????</th>
- <th>??????????????</th>
- <th>????????</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $sql = 'SELECT
- `products`.*
- , `units`.`name` AS unit
- FROM
- `posterth_store`.`units`
- INNER JOIN `posterth_store`.`products`
- ON (`units`.`id` = `products`.`unit_id`)
- ORDER BY `products`.`id` DESC
- LIMIT 0,5';
- $q = mysql_query($sql);
- while($rs = mysql_fetch_assoc($q)){?>
- <tr>
- <td align="center"><?php echo $rs["id"];?></td>
- <td>
- <a href="?m=products&p=order_products&pedit=true&code=<?php echo $rs['code'];?>">
- <?php echo $rs["name"];?>
- </a>
- </td>
- <td><?php echo $rs["price"];?></td>
- <td><?php echo $rs["unit"];?></td>
- <td><?php echo $rs["num"];?></td>
- <td><?php echo $rs["promotion"];?></td>
- <td><?php echo $rs["annotation"];?></td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
- </div>
- </form>
- <?php } ?>
- </div>
- <div class="products-template" style="display:none;">
- <div class="products-input-template">
- <input type="text" name="name" id="pname" value="" style="width:155px;height:20px;"/>
- <input type="text" name="price" id="pprice" value="" style="width:80px;height:20px;"/>
- <select name="unit" id="unit" style="margin-right:10px;">
- <?php
- $sql = 'SELECT * FROM units';
- $q = $db->select_query($sql);
- while($rs = $db->fetch($q)){
- ?>
- <option value="<?php echo $rs['id'];?>"><?php echo $rs['name'];?></option>
- <?php } ?>
- </select>
- <input type="text" name="num" id="pnum" value="" style="width:80px;height:20px;"//>
- <input type="text" name="promotion" id="ppromotion" value="" style="width:155px;height:20px;"//>
- <input type="text" name="detail" id="pdetail" value="" style="width:155px;height:20px;"//>
- <input type="hidden" name="code" id="pcode" value="" />
- <!--<a href="#" onClick="return false;" id="del_row">
- <img src="css/images/delete.png" alt="?????" />
- </a>-->
- </div>
- </div>
- <style type="text/css">
- .ui-state-default .ui-icon {
- float:right;
- }
- </style>
- <script type="text/javascript">
- $(function(){
- $('#products_list').dataTable({
- "bJQueryUI": true,
- "sDom": 't',
- "aaSorting": [[ 0, "desc" ]],
- "aoColumns": [
- null,
- null,
- null,
- null,
- null,
- null,
- null
- ],
- "iDisplayLength": 5
- });
-
- $('input[name=detail]').bind('keypress', function(e) {
- if(e.keyCode==13){
- $('a#add_products').click();
- }
- });
- });
- </script>
-