function handleFormData($edit_submit = false) { global $template, $WebBaseDir, $i18n, $TimeOption, $ActiveOption, $AddIP, $userid, $group_ids, $ClassDir, $UploadDir; $apf_schedule = DB_DataObject::factory('ApfSchedule'); if ($edit_submit) { $apf_schedule->get($apf_schedule->escape($_POST['ID'])); $do_action = "updatesubmit"; } else { $do_action = "addsubmit"; } $apf_schedule->setTitle(stripslashes(trim($_POST['title']))); $apf_schedule->setDescription(stripslashes(trim($_POST['description']))); $apf_schedule->setPublishDate(DB_DataObject_Cast::date(stripslashes(trim($_POST['publish_date'])))); $apf_schedule->setPublishStarttime(DB_DataObject_Cast::time(stripslashes(trim($_POST['publish_starttime'])))); $apf_schedule->setPublishEndtime(DB_DataObject_Cast::time(stripslashes(trim($_POST['publish_endtime'])))); $apf_schedule->setImage(stripslashes(trim($_POST['image']))); $apf_schedule->setActive(stripslashes(trim($_POST['active']))); $apf_schedule->setAddIp($AddIP); $apf_schedule->setGroupid($group_ids); $apf_schedule->setUserid($userid); if ($_POST['image_del'] == 'Y') { unlink($UploadDir . $_POST['image_old']); $apf_schedule->setImage(""); $_POST['image_old'] = ""; } if ($_POST['upload_temp']) { $apf_schedule->setImage($_POST['upload_temp']); } $allow_upload_file = TRUE; if ($_FILES['image']['name']) { require_once $ClassDir . "FileHelper.class.php"; $upload_data = FileHelper::uploadFile("schedule"); $allow_upload_file = $upload_data["upload_state"]; if ($allow_upload_file) { $images_arr = $upload_data["upload_msg"]; if ($image_pic = $images_arr['image']) { $apf_schedule->setImage($image_pic); $_POST['upload_temp'] = $image_pic; } } else { $upload_error_msg = $upload_data["upload_msg"]; } } $val = $apf_schedule->validate(); if ($val === TRUE && $allow_upload_file === TRUE) { if ($edit_submit) { $apf_schedule->setUpdateAt(DB_DataObject_Cast::dateTime()); $apf_schedule->update(); $log_string = $i18n->_("Update") . $i18n->_("Schedule") . "\t{$_POST['title']}=>{$_POST['ID']}"; logFileString($log_string); $this->forward("schedule/apf_schedule/list/" . $_POST['ID'] . "/ok/?y=" . $_REQUEST['y'] . "&m=" . $_REQUEST['m'] . "&d=" . $_REQUEST['d'] . ""); } else { $apf_schedule->setCreatedAt(DB_DataObject_Cast::dateTime()); $apf_schedule->insert(); $log_string = $i18n->_("Create") . $i18n->_("Schedule") . "\t{$_POST['title']}"; logFileString($log_string); $this->forward("schedule/apf_schedule/list/?y=" . $_REQUEST['y'] . "&m=" . $_REQUEST['m'] . "&d=" . $_REQUEST['d'] . ""); } } else { $template->setFile(array("MAIN" => "apf_schedule_list.html")); $template->setBlock("MAIN", "edit_block"); if ($_REQUEST['y'] && $_REQUEST['m'] && $_REQUEST['d']) { $select_y = $_REQUEST['y']; $select_m = $_REQUEST['m']; $select_d = $_REQUEST['d']; } else { $next_week_time = $this->getDefaultDate(); $select_y = date("Y", $next_week_time); $select_m = date("m", $next_week_time); $select_d = date("d", $next_week_time); } $used_hours_arr = array(); $CalDailyView = $this->renderDayView($select_y, $select_m, $select_d, $used_hours_arr); $un_use_hour_arr = array_diff($TimeOption, $used_hours_arr); array_shift($ActiveOption); $template->setVar(array("WEBDIR" => $WebBaseDir, "IMAGES_FILE" => fileTag('image', $_POST['upload_temp'] ? $_POST['upload_temp'] : $_POST['image_old']), "STATUS_FIELD" => selectTag('status', $ActiveOption, $_POST['status']), "LEFT_CALENDAR" => $this->renderMonthView(), "DAY_VIEW" => $CalDailyView, "PUBLISH_STARTTIME_OPTION" => selectTag('publish_starttime', $un_use_hour_arr, $_POST['publish_starttime']), "PUBLISH_ENDTIME_OPTION" => selectTag('publish_endtime', $un_use_hour_arr, $_POST['publish_endtime']), "DOACTION" => $do_action, "PUBLISH_DATE" => "{$select_y}-{$select_m}-{$select_d}", "Y" => $select_y, "M" => $select_m, "D" => $select_d)); if (is_array($val)) { foreach ($val as $k => $v) { if ($v == false) { $template->setVar(array(strtoupper($k) . "_ERROR_MSG" => " ↓ Please check here ↓ ")); } } } 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'], "TITLE" => $_POST['title'], "DESCRIPTION" => $_POST['description'], "PUBLISH_DATE" => $_POST['publish_date'], "PUBLISH_STARTTIME" => $_POST['publish_starttime'], "PUBLISH_ENDTIME" => $_POST['publish_endtime'], "IMAGE" => $_POST['image'], "ACTIVE" => $_POST['active'], "ADD_IP" => $_POST['add_ip'], "CREATED_AT" => $_POST['created_at'], "UPDATE_AT" => $_POST['update_at'])); } }