<h1><?php echo $lang['common_projects']; ?> </h1> <?php $projectInst = new project(); if (!$loginInst->isCustomer()) { ####################################################################### ## perform action $status = 1; if (tool::securePost('action') == "save" && tool::securePost('id')) { # fill project with submitted data $projectInst->id = tool::securePost('id'); $projectInst->fill(tool::securePostAll()); $status = $projectInst->update(); } elseif (tool::securePost('action') == "save") { $projectInst->fill(tool::securePostAll()); $status = $projectInst->insert(); } if (tool::securePost('action') == "delete") { $projectInst->id = tool::securePost('id'); $projectInst->delete(); } if (tool::securePost('action') == "edit") { $status = 0; $projectInst->activate(tool::securePost('id')); } ####################################################################### ## make edit / new form
} } if ($_POST['question_t2_answer']) { // Update tariffs with new end date if ($_POST['projects_end_date'] > $administration_project->end_date && $administration_project->end_date != 0 || $_POST['projects_end_date'] == 0) { $tariffs_array = $administration_project->has_tariffs('tariffs_end_date', '=', tep_strftime(DATE_FORMAT_DATABASE, $administration_project->end_date)); } else { $tariffs_array = $administration_project->has_tariffs('tariffs_start_date', '<=', tep_strftime(DATE_FORMAT_DATABASE, $_POST['projects_end_date']), 'AND', 'tariffs_end_date', '>', tep_strftime(DATE_FORMAT_DATABASE, $_POST['projects_end_date'])); } for ($index = 0; $index < sizeof($tariffs_array); $index++) { $tariffs_array[$index]->end_date = $_POST['projects_end_date']; $tariffs_array[$index]->save(); } } // Finally save the project $administration_project->fill($_POST['projects_name'], $_POST['projects_description'], $_POST['projects_customers_contact_name'], $_POST['projects_customers_reference'], $_POST['projects_start_date'], $_POST['projects_end_date'], $_POST['projects_calculated_hours'], $_POST['projects_calculated_hours_period'], $_POST['projects_business_units_id'], $_POST['projects_customers_id']); $administration_project->save(); // Clear all values except mPath foreach ($_POST as $key => $value) { if ($key != 'mPath') { unset($_POST[$key]); } } } } } } } } break; case 'delete_entry':
# new_project.php # 1. logic AUTH::kickout('login'); $projects = new Projects_Collection(); $projects->where(['deleted' => '0']); $projects->where(['user_id' => AUTH::user_id()]); $projects->get(); if (Input::posted()) { $slug = Input::get('project_name'); $slug = strtolower($slug); $slug = explode(" ", $slug); $slug = implode("-", $slug); $deadline = Input::get('deadline'); $deadline = intval($deadline); $project = new project(); $project->fill(Input::all()); $project->date = date('Y-m-d H:i:s'); $project->slug = $slug; $project->user_id = Auth::user_id(); if (Input::get('project_name') != "" || Input::get('project_description') != "") { $project->save(); URL::redirect('/' . $project->slug); } URL::redirect('/new_project'); } $title = 'New Project'; # 2. views include VIEWS . 'header.php'; include VIEWS . 'new_project.php'; include VIEWS . 'footer.php';
/** * Create a new project * * @param array $input * @return array */ public static function create_project($input) { $rules = array('name' => 'required|max:250'); $validator = \Validator::make($input, $rules); if (!$validator->valid()) { return array('success' => false, 'errors' => $validator); } $fill = array('name' => $input['name']); $project = new project(); $project->fill($fill); $project->save(); /* Assign selected users to the project */ if (isset($input['user']) && count($input['user']) > 0) { foreach ($input['user'] as $id) { $project->assign_user($id); } } return array('project' => $project, 'success' => true); }