public function perform_action() { $input = FWS_Props::get()->input(); $db = FWS_Props::get()->db(); $functions = FWS_Props::get()->functions(); $locale = FWS_Props::get()->locale(); $title = $input->get_var('entry_title', 'post', FWS_Input::STRING); $description = $input->get_var('entry_description', 'post', FWS_Input::STRING); $entry_info_link = $input->get_var('entry_info_link', 'post', FWS_Input::STRING); $category = $input->get_var('category', 'post', FWS_Input::INTEGER); $start_version = $input->get_var('start_version', 'post', FWS_Input::STRING); $fixed_version = $input->get_var('fixed_version', 'post', FWS_Input::STRING); $status = $input->correct_var('status', 'post', FWS_Input::STRING, array('open', 'running', 'fixed', 'not_tested', 'not_reproducable', 'need_info'), 'open'); $type = $input->correct_var('type', 'post', FWS_Input::STRING, array('bug', 'feature', 'improvement', 'test'), 'bug'); $priority = $input->correct_var('priority', 'post', FWS_Input::STRING, array('current', 'next', 'anytime'), 'anytime'); @(list($start_project_id, $start_version_id) = explode(',', $start_version)); $time = time(); // create entry $entry = new TDL_Objects_Entry(TDL_TB_ENTRIES); $entry->set_project_id($start_project_id); $entry->set_entry_title($title); $entry->set_entry_description($description); $entry->set_entry_category($category); $entry->set_entry_start_date($time); $entry->set_entry_start_version($start_version_id); $entry->set_entry_changed_date($time); $entry->set_entry_status($status); $entry->set_entry_info_link($entry_info_link); $entry->set_entry_type($type); $entry->set_entry_priority($priority); // determine fixed-inputs $fixed_version_id = 0; if ($fixed_version == 0 || $status != 'fixed') { $entry->set_entry_fixed_date(0); $entry->set_entry_fixed_version(0); } else { @(list(, $fixed_version_id) = explode(',', $fixed_version)); $entry->set_entry_fixed_date($time); $entry->set_entry_fixed_version($fixed_version_id); } // check for errors if (!$entry->check('create')) { return $entry->errors(); } // create the object $entry->create(); // update config $db->update(TDL_TB_CONFIG, ' WHERE is_selected = 1', array('last_start_version' => $start_version_id, 'last_fixed_version' => $fixed_version_id, 'last_category' => $category, 'last_type' => $type, 'last_priority' => $priority, 'last_status' => $status)); $url = new TDL_URL(); $this->add_link($locale->_('Back'), $url->set(TDL_URL_ACTION, 'view_entries')); $this->set_success_msg('Der Eintrag wurde erfolgreich erstellt!'); $this->set_redirect(true, TDL_URL::get_entry_url()); $this->set_action_performed(true); return ''; }
/** * @see FWS_Module::run() */ public function run() { $input = FWS_Props::get()->input(); $functions = FWS_Props::get()->functions(); $cfg = FWS_Props::get()->cfg(); $db = FWS_Props::get()->db(); $versions = FWS_Props::get()->versions(); $cats = FWS_Props::get()->cats(); $tpl = FWS_Props::get()->tpl(); $mode = $input->correct_var(TDL_URL_MODE, 'get', FWS_Input::STRING, array('add', 'edit'), 'add'); $id = $input->get_predef(TDL_URL_IDS, 'get'); if ($id === null && $mode == 'edit') { $this->report_error(); return; } $multiple = false; $base_url = TDL_URL::get_entry_url(); $entries = array(); $data = array('project_id' => $cfg['project_id'], 'entry_title' => '', 'entry_description' => '', 'entry_info_link' => '', 'entry_status' => $cfg['last_status'], 'entry_category' => $cfg['last_category'], 'entry_start_version' => $cfg['last_start_version'], 'entry_fixed_version' => $cfg['last_fixed_version'], 'entry_type' => $cfg['last_type'], 'entry_priority' => $cfg['last_priority']); $this->request_formular(); if ($mode == 'edit') { $ids = FWS_Array_Utils::advanced_explode(',', $id); if (!FWS_Array_Utils::is_numeric($ids)) { $this->report_error(); return; } $multiple = count($ids) > 1; if ($multiple) { $selected_entries = array(); $rows = $db->get_rows('SELECT id,entry_title FROM ' . TDL_TB_ENTRIES . ' WHERE id IN (' . implode(',', $ids) . ')'); foreach ($rows as $row) { $selected_entries[] = $row['id']; $entries[] = $row; } if (count($selected_entries) == 0) { $this->report_error(); return; } } else { $id = (int) $id; if ($id <= 0) { $this->report_error(); return; } $data = $db->get_row('SELECT * FROM ' . TDL_TB_ENTRIES . ' WHERE id = ' . $id); if ($data['id'] == '') { $this->report_error(); return; } } $target_url = clone $base_url; $target_url->set(TDL_URL_ACTION, 'edit_entry'); $target_url->set(TDL_URL_MODE, 'edit'); $target_url->set(TDL_URL_IDS, $id); $action_type = TDL_ACTION_EDIT_ENTRY; } else { $target_url = clone $base_url; $target_url->set(TDL_URL_ACTION, 'edit_entry'); $target_url->set(TDL_URL_MODE, 'add'); $action_type = TDL_ACTION_NEW_ENTRY; } $version_options = array(' '); if ($cfg['project_id'] != 0) { $v_rows = $versions->get_elements_with(array('project_id' => $cfg['project_id'])); } else { $v_rows = $versions->get_elements_with(array()); } usort($v_rows, array($functions, 'sort_versions_by_name_callback')); foreach ($v_rows as $row) { $version_options[$row['project_id'] . ',' . $row['id']] = $row['project_name'] . ' ' . $row['version_name']; } $category_options = array(' '); if ($cfg['project_id'] != 0) { $cat_rows = $cats->get_elements_with(array('project_id' => $cfg['project_id'])); } else { $cat_rows = $cats->get_elements_with(array()); } foreach ($cat_rows as $row) { $project = $versions->get_element_with(array('project_id' => $row['project_id'])); $category_options[$row['id']] = $project['project_name_short'] . ' :: ' . $row['category_name']; } $tpl->add_variables(array('not_multiple_edit' => !$multiple, 'mode' => $mode, 'selected_entries' => $entries, 'target_url' => $target_url->to_url(), 'action_type' => $action_type, 'def_title' => $data['entry_title'], 'def_description' => $data['entry_description'], 'def_info_link' => $data['entry_info_link'], 'start_version_combo' => $this->_get_combobox($multiple, 'start_version', $version_options, $data['project_id'] . ',' . $data['entry_start_version']), 'fixed_version_combo' => $this->_get_combobox($multiple, 'fixed_version', $version_options, $data['project_id'] . ',' . $data['entry_fixed_version']), 'category_combo' => $this->_get_combobox($multiple, 'category', $category_options, $data['entry_category']), 'status_combo' => $this->_get_combobox($multiple, 'status', $functions->get_states(false), $data['entry_status']), 'type_combo' => $this->_get_combobox($multiple, 'type', $functions->get_types(false), $data['entry_type']), 'priority_combo' => $this->_get_combobox($multiple, 'priority', $functions->get_priorities(false), $data['entry_priority']), 'back_url' => $base_url->to_url())); }
public function perform_action() { $input = FWS_Props::get()->input(); $functions = FWS_Props::get()->functions(); $locale = FWS_Props::get()->locale(); // check id $id = $input->get_predef(TDL_URL_IDS, 'get'); if ($id == null) { return TDL_GENERAL_ERROR; } $ids = FWS_Array_Utils::advanced_explode(',', $id); if (count($ids) == 0) { return TDL_GENERAL_ERROR; } $multiple = count($ids) > 1; $time = time(); if (!$multiple) { $title = $input->get_var('entry_title', 'post', FWS_Input::STRING); $description = $input->get_var('entry_description', 'post', FWS_Input::STRING); $info_link = $input->get_var('entry_info_link', 'post', FWS_Input::STRING); } $category = $input->get_var('category', 'post', FWS_Input::INTEGER); $start_version = $input->get_var('start_version', 'post', FWS_Input::STRING); $fixed_version = $input->get_var('fixed_version', 'post', FWS_Input::STRING); $status = $input->correct_var('status', 'post', FWS_Input::STRING, array('open', 'running', 'fixed', 'not_tested', 'not_reproducable', 'need_info'), 'open'); $type = $input->correct_var('type', 'post', FWS_Input::STRING, array('bug', 'feature', 'improvement', 'test'), 'bug'); $priority = $input->correct_var('priority', 'post', FWS_Input::STRING, array('current', 'next', 'anytime'), 'anytime'); if ($multiple) { if (!$input->isset_var('use_start_version', 'post')) { $start_version = 0; } if (!$input->isset_var('use_fixed_version', 'post')) { $fixed_version = 0; } if (!$input->isset_var('use_category', 'post')) { $category = 0; } } if (!$multiple || $input->isset_var('use_start_version', 'post')) { @(list($start_project_id, $start_version_id) = explode(',', $start_version)); } if ($fixed_version == 0 || $status != 'fixed') { $fixed_date = 0; $fixed_version_id = 0; } else { @(list(, $fixed_version_id) = explode(',', $fixed_version)); $fixed_date = $time; } // update entries foreach ($ids as $id) { $entry = new TDL_Objects_Entry(TDL_TB_ENTRIES); $entry->set_id($id); if (isset($start_project_id)) { $entry->set_project_id($start_project_id); } if (!$multiple) { $entry->set_entry_title($title); $entry->set_entry_description($description); $entry->set_entry_info_link($info_link); } if (!$multiple || $input->isset_var('use_start_version', 'post')) { $entry->set_entry_start_version($start_version_id); } if (!$multiple || $input->isset_var('use_fixed_version', 'post')) { $entry->set_entry_fixed_version($fixed_version_id); $entry->set_entry_fixed_date($fixed_date); } if (!$multiple || $input->isset_var('use_category', 'post')) { $entry->set_entry_category($category); } if (!$multiple || $input->isset_var('use_status', 'post')) { $entry->set_entry_status($status); } if (!$multiple || $input->isset_var('use_type', 'post')) { $entry->set_entry_type($type); } if (!$multiple || $input->isset_var('use_priority', 'post')) { $entry->set_entry_priority($priority); } if (!$multiple || $input->get_var('change_lastchange_date', 'post', FWS_Input::INT_BOOL) == 1) { $entry->set_entry_changed_date($time); } if (!$entry->check('update')) { return $entry->errors(); } $entry->update(); } if ($multiple) { $msg = $locale->_('The entries have been edited successfully'); } else { $msg = $locale->_('The entry has been edited successfully'); } $this->set_success_msg($msg); $this->set_redirect(true, TDL_URL::get_entry_url()); $this->set_action_performed(true); return ''; }