'.__('You don\'t have enough privileges to view this section').''); } /* RECORD OPERATION */ if (isset($_POST['saveData']) AND $can_read AND $can_write) { // check form validity $holDesc = trim($dbs->escape_string(strip_tags($_POST['holDesc']))); if (empty($holDesc)) { utility::jsAlert('Holiday description can\'t be empty!'); exit(); } else { $data['holiday_date'] = trim(preg_replace('@\s[0-9]{2}:[0-9]{2}:[0-9]{2}$@i', '', $_POST['holDate'])); $holiday_start_date = $data['holiday_date']; $data['holiday_dayname'] = date('D', strtotime($data['holiday_date'])); $data['description'] = $holDesc; // create sql op object $sql_op = new simbio_dbop($dbs); if (isset($_POST['updateRecordID'])) { /* UPDATE RECORD MODE */ // filter update record ID $updateRecordID = (integer)$_POST['updateRecordID']; if ($sql_op->update('holiday', $data, 'holiday_id='.$updateRecordID)) { utility::jsAlert(__('Holiday Data Successfully updated')); // update holiday_dayname session $_SESSION['holiday_date'][$data['holiday_date']] = $data['holiday_date']; echo ''; exit(); } else { utility::jsAlert(__('Holiday FAILED to update. Please Contact System Administrator')."\n".$sql_op->error); } } else { /* INSERT RECORD MODE */ // insert the data if ($sql_op->insert('holiday', $data)) { utility::jsAlert(__('New Holiday Successfully Saved')); // update holiday_dayname session $_SESSION['holiday_date'][$data['holiday_date']] = $data['holiday_date']; // date range insert if (isset($_POST['holDateEnd'])) { $holiday_end_date = trim(preg_replace('@\s[0-9]{2}:[0-9]{2}:[0-9]{2}$@i', '', $_POST['holDateEnd'])); // check if holiday end date is more than holiday start date if (simbio_date::compareDates($holiday_start_date, $holiday_end_date) == $holiday_end_date) { $guard = 365; $d = 1; while ($holiday_start_date != $holiday_end_date) { if ($d == $guard) { break; } $holiday_start_date = simbio_date::getNextDate(1, $holiday_start_date); list($date_year, $date_month, $date_date) = explode('-', $holiday_start_date); $data['holiday_date'] = $holiday_start_date; $data['holiday_dayname'] = date('D', mktime(0, 0, 0, $date_month, $date_date, $date_year)); @$sql_op->insert('holiday', $data); $_SESSION['holiday_date'][$holiday_start_date] = $holiday_start_date; $d++; } } } echo ''; exit(); } else { utility::jsAlert(__('Holiday FAILED to Save. Please Contact System Administrator')."\n".$sql_op->error); } } } exit(); } else if (isset($_POST['itemID']) AND !empty($_POST['itemID']) AND isset($_POST['itemAction'])) { if (!($can_read AND $can_write)) { die(); } /* DATA DELETION PROCESS */ $sql_op = new simbio_dbop($dbs); $failed_array = array(); $error_num = 0; if (!is_array($_POST['itemID'])) { // make an array $_POST['itemID'] = array((integer)$_POST['itemID']); } // loop array foreach ($_POST['itemID'] as $itemID) { $itemID = (integer)$itemID; // get info about this holiday $rec_q = $dbs->query('SELECT holiday_date FROM holiday WHERE holiday_id='.$itemID); $rec_d = $rec_q->fetch_row(); if (!$sql_op->delete('holiday', 'holiday_id='.$itemID)) { $error_num++; } else { // remove session for this holiday unset($_SESSION['holiday_date'][$rec_d[0]]); } } // error alerting if ($error_num == 0) { utility::jsAlert(__('All Data Successfully Deleted')); echo ''; } else { utility::jsAlert(__('Some or All Data NOT deleted successfully!\nPlease contact system administrator')); echo ''; } exit(); } /* RECORD OPERATION */ ?>
query('SELECT * FROM holiday WHERE holiday_id='.$itemID); $rec_d = $rec_q->fetch_assoc(); // create new instance $form = new simbio_form_table_AJAX('mainForm', $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'], 'post'); $form->submit_button_attr = 'name="saveData" value="'.__('Save').'" class="btn btn-default"'; // form table attributes $form->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"'; $form->table_header_attr = 'class="alterCell" style="font-weight: bold;"'; $form->table_content_attr = 'class="alterCell2"'; // edit mode flag set if ($rec_q->num_rows > 0) { $form->edit_mode = true; // record ID for delete process $form->record_id = $itemID; // form record title $form->record_title = $rec_d['description']; // submit button attribute $form->submit_button_attr = 'name="saveData" value="'.__('Update').'" class="btn btn-default"'; } /* Form Element(s) */ // holiday date start $form->addDateField('holDate', __('Holiday Date Start'), $rec_d['holiday_date']); // holiday date end if (!$form->edit_mode) { $form->addDateField('holDateEnd', __('Holiday Date End'), $rec_d['holiday_date']); } // holiday description $form->addTextField('text', 'holDesc', __('Holiday Description').'*', $rec_d['description'], 'style="width: 100%;"'); // edit mode messagge if ($form->edit_mode) { echo '