function handleFormData($edit_submit = false)
 {
     global $template, $WebBaseDir, $i18n, $ActiveOption;
     $apf_product_category = DB_DataObject::factory('ApfProductCategory');
     if ($edit_submit) {
         $apf_product_category->get($apf_product_category->escape($_POST['ID']));
         $do_action = "updatesubmit";
     } else {
         $do_action = "addsubmit";
     }
     $apf_product_category->setPid(stripslashes(trim($_POST['pid'])));
     $apf_product_category->setCategoryName(stripslashes(trim($_POST['category_name'])));
     $apf_product_category->setActive(stripslashes(trim($_POST['active'])));
     $apf_product_category->setAddIp(stripslashes(trim($_POST['add_ip'])));
     $val = $apf_product_category->validate();
     if ($val === TRUE) {
         if ($edit_submit) {
             $apf_product_category->setUpdateAt(DB_DataObject_Cast::dateTime());
             $apf_product_category->update();
             $this->forward("product/apf_product_category/update/" . $_POST['ID'] . "/ok");
         } else {
             $apf_product_category->setCreatedAt(DB_DataObject_Cast::dateTime());
             $insert_id = $apf_product_category->insert();
             $apf_product_category->get($insert_id);
             $apf_product_category->setOrderid($insert_id);
             $apf_product_category->update();
             $this->forward("product/apf_product_category/");
         }
     } else {
         $template->setFile(array("MAIN" => "apf_product_category_edit.html"));
         $template->setBlock("MAIN", "edit_block");
         $category_arr = array("0" => $i18n->_("None")) + ApfProduct::getCategory();
         unset($category_arr[$_POST['ID']]);
         array_shift($ActiveOption);
         $template->setVar(array("CATEGORYOPTION" => selectTag("pid", $category_arr, $_POST['pid']), "ACTIVEOPTION" => radioTag("active", $ActiveOption, $_POST['active']), "WEBDIR" => $WebBaseDir, "DOACTION" => $do_action));
         foreach ($val as $k => $v) {
             if ($v == false) {
                 $template->setVar(array(strtoupper($k) . "_ERROR_MSG" => " ↓ " . $i18n->_("Please check here") . " ↓ "));
             }
         }
         $template->setVar(array("ID" => $_POST['id'], "CATEGORY_NAME" => $_POST['category_name'], "ACTIVE" => $_POST['active'], "ADD_IP" => $_POST['add_ip'], "CREATED_AT" => $_POST['created_at'], "UPDATE_AT" => $_POST['update_at']));
     }
 }
 function executeDetail()
 {
     global $template, $ModuleDir, $ClassDir, $WebTemplateDir, $WebBaseDir, $controller, $i18n, $ActiveOption, $WebTemplateFullPath, $GenderOption, $CurrencyFormat;
     include_once $ClassDir . "URLHelper.class.php";
     require_once 'I18N/Currency.php';
     require_once $ModuleDir . 'contact/ApfContact.class.php';
     require_once $ModuleDir . 'product/ApfProduct.class.php';
     $template->setFile(array("MAIN" => "apf_company_detail.html"));
     $template->setBlock("MAIN", "detail_block");
     $apf_company = DB_DataObject::factory('Apfcompany');
     $apf_company->get($apf_company->escape($controller->getID()));
     $template->setVar(array("ID" => $apf_company->getId(), "NAME" => $apf_company->getName(), "ADDREES" => $apf_company->getAddrees(), "PHONE" => $apf_company->getPhone(), "FAX" => $apf_company->getFax(), "EMAIL" => $apf_company->getEmail(), "PHOTO" => imageTag($apf_company->getPhoto()), "HOMEPAGE" => $apf_company->getHomepage(), "EMPLOYEE" => $apf_company->getEmployee(), "BANKROLL" => $apf_company->getBankroll(), "LINK_MAN" => $apf_company->getLinkMan(), "INCORPORATOR" => $apf_company->getIncorporator(), "INDUSTRY" => $apf_company->getIndustry(), "PRODUCTS" => $apf_company->getProducts(), "MEMO" => $apf_company->getMemo(), "ACTIVE" => $apf_company->getActive(), "ADD_IP" => $apf_company->getAddIp(), "CREATED_AT" => $apf_company->getCreatedAt(), "UPDATE_AT" => $apf_company->getUpdateAt()));
     //		related contact
     $contact_category_arr = array("" => $i18n->_("All")) + ApfContact::getCategory();
     $apf_company_contact = DB_DataObject::factory('ApfCompanyContact');
     $apf_company_contact->whereAdd(" apf_company_contact.company_id = '" . $apf_company->getId() . "'  ");
     $apf_company_contact->orderBy("apf_contact.id desc");
     $apf_company_contact->buildContactJoin();
     //		$apf_company_contact->debugLevel(4);
     $apf_company_contact->find();
     $template->setBlock("MAIN", "contact_list", "contact_list_block");
     $i = 0;
     while ($apf_company_contact->fetch()) {
         $data = $apf_company_contact->toArray();
         $i % 2 == 0 ? $list_td_class = "admin_row_0" : ($list_td_class = "admin_row_1");
         $template->setVar(array("LIST_TD_CLASS" => $list_td_class));
         //			Var_Dump::display($data);
         $template->setVar(array("C_ID" => $data['id'], "C_CATEGORY" => $contact_category_arr[$data['category']], "C_NAME" => $data['name'], "C_GENDER" => $GenderOption[$data['gender']], "C_BIRTHDAY" => $data['birthday'], "C_ADDREES" => $data['addrees'], "C_OFFICE_PHONE" => $data['office_phone'], "C_PHONE" => $data['phone'], "C_FAX" => $data['fax'], "C_MOBILE" => $data['mobile'], "C_EMAIL" => $data['email'], "C_ACTIVE" => $data['active']));
         $template->parse("contact_list_block", "contact_list", TRUE);
         $i++;
     }
     $contact_total = $i;
     //		related product
     $currency = new I18N_Currency($CurrencyFormat);
     $product_category_arr = array("" => $i18n->_("All")) + ApfProduct::getCategory();
     $apf_company_product = DB_DataObject::factory('ApfCompanyProduct');
     $apf_company_product->orderBy("apf_product.id desc");
     $apf_company_product->whereAdd(" apf_company_product.company_id = '" . $apf_company->getId() . "'  ");
     $apf_company_product->buildProductJoin();
     //		$apf_company_product->debugLevel(4);
     $apf_company_product->find();
     $template->setBlock("MAIN", "product_list", "product_list_block");
     $i = 0;
     while ($apf_company_product->fetch()) {
         $data = $apf_company_product->toArray();
         //			get the last product price
         $apf_product_price = DB_DataObject::factory('ApfProductPrice');
         $apf_product_price->whereAdd("company_id ='" . $apf_company->getId() . "' ");
         $apf_product_price->whereAdd("product_id ='{$data['id']}' ");
         $apf_product_price->orderBy('created_at desc');
         //			$apf_product_price->debugLevel(4);
         $apf_product_price->find();
         $apf_product_price->fetch();
         $data['price'] = $apf_product_price->getPrice() ? $apf_product_price->getPrice() : $data['price'];
         $i % 2 == 0 ? $list_td_class = "admin_row_0" : ($list_td_class = "admin_row_1");
         $template->setVar(array("LIST_TD_CLASS" => $list_td_class));
         //			Var_Dump::display($data);
         $template->setVar(array("P_ID" => $data['id'], "P_CATEGORY" => $product_category_arr[$data['category']], "P_COMPANY_ID" => $data['company_id'], "P_NAME" => $data['name'], "P_PRICE" => "<div ondblclick=\"editPrice('" . $data['id'] . "','" . $apf_company->getId() . "','" . $data['price'] . "')\" >" . $currency->format($data['price']) . "</div>", "P_PHOTO" => imageTag($data['photo']), "P_MEMO" => $data['memo'], "P_ACTIVE" => $data['active']));
         $template->parse("product_list_block", "product_list", TRUE);
         $i++;
     }
     $product_total = $i;
     $template->setVar(array("WEBDIR" => $WebBaseDir, "WEBTEMPLATEDIR" => URLHelper::getWebBaseURL() . $WebTemplateDir, "C_TOLTAL_NUM" => $contact_total, "P_TOLTAL_NUM" => $product_total, "WEBDIR" => $WebBaseDir, "COMID" => $apf_company->getId()));
 }
 function getCategory($pid = "", $patten = "-")
 {
     $patten .= $patten;
     $apf_product_category = DB_DataObject::factory('ApfProductCategory');
     $apf_product_category->orderBy('orderid ASC');
     if ($pid) {
         $apf_product_category->setPid($pid);
     } else {
         $apf_product_category->setPid(0);
     }
     $apf_product_category->find();
     $myData = array();
     while ($apf_product_category->fetch()) {
         $myData[$apf_product_category->getId()] = $patten . $apf_product_category->getCategoryName();
         $myData += ApfProduct::getCategory($apf_product_category->getId(), $patten);
     }
     return $myData;
 }