// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   ProductAction.java

package com.keyshop.shop.product.controller;

import com.keyshop.pub.bo.PubHibernate;
import com.keyshop.pub.controller.PubAction;
import com.keyshop.pub.controller.PubForm;
import com.keyshop.pub.model.PubBean;
import com.keyshop.pub.util.*;
import com.keyshop.pub.util.image.ImageUtil;
import com.keyshop.shop.product.bo.*;
import com.keyshop.shop.product.model.*;
import com.keyshop.shop.product.util.ProductHelper;
import com.keyshop.shop.system.manager.SystemManager;
import com.keyshop.shop.system.model.MailConfig;
import com.keyshop.shop.system.model.ViewConfig;
import com.keyshop.shop.user.bo.UserLevelBO;
import com.keyshop.shop.user.model.UserLevel;
import com.keyshop.shop.util.ShopZipPmg;
import java.io.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
import org.apache.struts.upload.MultipartRequestHandler;

// Referenced classes of package com.keyshop.shop.product.controller:
//            ProductForm, ProductCategoryForm

public class ProductAction extends PubAction
{

    public static final String QIANTAILIST = "qiantailist";
    public boolean isRedirect;

    public ProductAction()
    {
        isRedirect = false;
    }

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
return null;
    }

    public final ActionForward performSendmessages(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        
        return null;
    }

    public String getSelectSQL()
    {
        return getSelectSQL(false);
    }

    public final ActionForward performEmail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
       
        return null;
    }

    public String getSelectSQL(boolean isfg)
    {
        
        return null;
    }

    public void initClassName()
    {

    }

    public ActionForward performEdit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
       
        return mapping.findForward("add");
    }

    public ActionForward performChannel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
      
        return mapping.findForward("channel");
    }

    public ActionForward performUpdateindex(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
       
        return super.performList(mapping, form, request, response);
    }

    public ActionForward performAdd(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
       
        return mapping.findForward("add");
    }

    public ActionForward performQiantailist(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        
        return mapping.findForward("list");
    }

    public ActionForward performQiantaiview(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
      
        return mapping.findForward("view");
    }

    private void vaildateImage()
    {
        
    }

    public ActionForward performSave(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
       
        return mapping.findForward("add");
    }

    public ActionForward performUpdate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
       
        return mapping.findForward("edit");
    }

    private void updateChilds(String productId)
        throws Exception
    {
        

    }

    private void updateImage()
        throws Exception
    {
        
    }

    public ActionForward performChangetemplate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        return mapping.findForward("add");
    }

    public ActionForward performAddchild(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
       
        return map.findForward("add");
    }

    public ActionForward performSavechild(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {

        return map.findForward("add");
    }

    public ActionForward performRemove(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        try
        {
            if(isRedirect)
                return null;
            ProductForm pform = (ProductForm)form;
            String selected[] = pform.getSelected();
            ProductBO bo = new ProductBO();
            if(selected != null && selected.length > 0)
            {
                for(int i = 0; i < selected.length; i++)
                {
                    String sel = selected[i];
                    try
                    {
                        bo.deleteById(sel);
                        bo.delete("from TemplateTextField field where field.productId='" + sel + "'");
                        bo.delete("from TemplateBlobField field where field.productId='" + sel + "'");
                        bo.delete("from ProductCategoryRelation relation where relation.productId='" + sel + "'");
                        bo.delete("from ProductRelation relation where relation.productId='" + sel + "' or relation.reproductId='" + sel + "'");
                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                    }
                }

            }
            return performList(mapping, form, request, response);
        }
        catch(Exception e)
        {
            generalError(request, e);
        }
        return mapping.findForward("fail");
    }

    protected boolean isObjectExisted(PubBean bean)
    {
        return false;
    }

    private void updateBlobField(Product bean, HttpServletRequest request, TemplateBlobFieldBO bo, TemplateBlobField field, Hashtable files)
    {
        try
        {
            field.setProductId(bean.getId());
            String removePhoto = request.getParameter("removephoto" + field.getFieldId());
            if(removePhoto != null && removePhoto.equals("true"))
            {
                try
                {
                    FileUtil.deleteFile(request.getRealPath(field.getFieldValue()));
                }
                catch(Exception ex)
                {
                    ex.printStackTrace();
                }
                field.setFieldValue(null);
                if(!StringUtil.isEmpty(field.getId()))
                {
                    bo.updateBean(field);
                    return;
                }
            }
            FormFile formFile = (FormFile)files.get(field.getFieldId());
            if(formFile != null && formFile.getFileData() != null && formFile.getFileData().length > 0)
            {
                String fileName = updateAdElement(formFile, field.getFieldValue(), field.getId());
                field.setFieldValue(fileName);
                if(StringUtil.isEmpty(field.getId()))
                    bo.addBean(field);
                else
                    bo.updateBean(field);
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }

  

    private void updateTemplateFieldsData(HttpServletRequest request, ActionForm form, Product bean)
        throws Exception
    {
        if(bean.getTemplate() == null)
            return;
        TemplateTextFieldBO templateTextFieldBo = new TemplateTextFieldBO();
        TemplateBlobFieldBO templateBlobFieldBo = new TemplateBlobFieldBO();
        Hashtable files = null;
        if(form.getMultipartRequestHandler() != null)
            files = form.getMultipartRequestHandler().getFileElements();
        List templateCategorys = ProductHelper.getTemplateCategorys();
        if(templateCategorys != null && templateCategorys.size() > 0)
        {
            for(int i = 0; i < templateCategorys.size(); i++)
            {
                TemplateCategory category = (TemplateCategory)templateCategorys.get(i);
                List fieldDatas = bean.getFieldsData(category.getId(), category.getType());
                for(Iterator it = fieldDatas.iterator(); it.hasNext();)
                    if("img".equals(category.getType()) && files != null && files.size() > 0)
                    {
                        TemplateBlobField blobField = (TemplateBlobField)it.next();
                        updateBlobField(bean, request, templateBlobFieldBo, blobField, files);
                    } else
                    {
                        TemplateTextField textField = (TemplateTextField)it.next();
                        updateTextField(bean, request, templateTextFieldBo, textField, files);
                    }

            }

        }
    }

    private List getRelationProducts(String productId)
    {
      
        return null;
    }

    private List convertProductList(List searchResult)
    {

        List rlist = new ArrayList();
      
        return rlist;
    }

    private String updateAdElement(FormFile file, String oldFileName, String type)
    {
      
        return "";
    }

    public ActionForward performImportdata(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        String filePath = request.getParameter("filepath");
        String zipfilename = request.getParameter("zipfilename");
        String zipRootPath = filePath;
        File cFrom = new File(zipRootPath + "/" + zipfilename);
        System.out.println("zipRootPath = " + zipRootPath + "/" + zipfilename);
        String strXlsParent = cFrom.getParent();
        shopResource = ResourceBundle.getBundle("resources.shopapplication", new Locale("", ""));
        String fileRoot = shopResource.getString("product.file.root");
        String targetPath = httpRequest.getRealPath(fileRoot);
        ExcelFileUtil.importData(cFrom, strXlsParent, targetPath, fileRoot);
        return null;
    }

    private void updateUserLevelPrice(Product bean)
        throws Exception
    {
      
    }
}
