function handleFormData($edit_submit = false) { global $template, $WebBaseDir, $i18n, $ActiveOption; $apf_news_category = DB_DataObject::factory('ApfNewsCategory'); if ($edit_submit) { $apf_news_category->get($apf_news_category->escape($_POST['ID'])); $do_action = "updatesubmit"; } else { $do_action = "addsubmit"; } $apf_news_category->setPid(stripslashes(trim($_POST['pid']))); $apf_news_category->setCategoryName(stripslashes(trim($_POST['category_name']))); $apf_news_category->setActive(stripslashes(trim($_POST['active']))); $apf_news_category->setAddIp(stripslashes(trim($_POST['add_ip']))); $val = $apf_news_category->validate(); if ($val === TRUE) { if ($edit_submit) { $apf_news_category->setUpdateAt(DB_DataObject_Cast::dateTime()); $apf_news_category->update(); $this->forward("news/apf_news_category/update/" . $_POST['ID'] . "/ok"); } else { $apf_news_category->setCreatedAt(DB_DataObject_Cast::dateTime()); $insert_id = $apf_news_category->insert(); $apf_news_category->get($insert_id); $apf_news_category->setOrderid($insert_id); $apf_news_category->update(); $this->forward("news/apf_news_category/list/" . $_POST['pid']); } } else { $template->setFile(array("MAIN" => "apf_news_category_edit.html")); $template->setBlock("MAIN", "edit_block"); $category_arr = array("0" => $i18n->_("None")) + ApfNews::getCategory(); unset($category_arr[$apf_news_category->getId()]); array_shift($ActiveOption); $template->setVar(array("WEBDIR" => $WebBaseDir, "CATEGORYOPTION" => selectTag("pid", $category_arr, $_POST['pid']), "ACTIVEOPTION" => radioTag("active", $ActiveOption, $_POST['active']), "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'], "PID" => $_POST['pid'], "CATEGORY_NAME" => $_POST['category_name'], "ORDERID" => $_POST['orderid'], "ACTIVE" => $_POST['active'], "ADD_IP" => $_POST['add_ip'], "CREATED_AT" => $_POST['created_at'], "UPDATE_AT" => $_POST['update_at'])); } }
function getCategory($pid = "", $patten = "-") { $patten .= $patten; $apf_news_category = DB_DataObject::factory('ApfNewsCategory'); $apf_news_category->orderBy('orderid ASC'); if ($pid) { $apf_news_category->setPid($pid); } else { $apf_news_category->setPid(0); } $apf_news_category->find(); $myData = array(); while ($apf_news_category->fetch()) { $myData[$apf_news_category->getId()] = $patten . $apf_news_category->getCategoryName(); $myData += ApfNews::getCategory($apf_news_category->getId(), $patten); } return $myData; }