Пример #1
0
 public function step1()
 {
     // Authentication check
     $this->_checkSession();
     if (!isset($_POST['projectFormSubmit'])) {
         header('Location: /project/newproject');
     }
     // check CSRF token
     $this->_checkCsrf($_POST['token']);
     $errors = array();
     $check = true;
     $inputDesc = isset($_POST['inputDesc']) ? trim($_POST['inputDesc']) : NULL;
     $inputName = isset($_POST['inputName']) ? trim($_POST['inputName']) : NULL;
     $inputVersion = isset($_POST['inputVersion']) ? trim($_POST['inputVersion']) : NULL;
     if (empty($inputName)) {
         $check = false;
         array_push($errors, "Project name is required!");
     }
     if (empty($inputVersion)) {
         $check = false;
         array_push($errors, "Version is required!");
     }
     if (!$check) {
         $this->_setView('newproject');
         $this->_view->set('title', 'Security Knowledge Framework:: Invalid form data!');
         $this->_view->set('menuActiveProject', "class='active'");
         $this->_view->set('menuActiveProjectNew', "class='active'");
         $this->_view->set('errors', $errors);
         $this->_view->set('formData', $_POST);
         return $this->_view->output();
     }
     try {
         $project = new ProjectModel();
         $project->setProjectDescription($inputDesc);
         $project->setProjectName($inputName);
         $project->setProjectVersion($inputVersion);
         $project->storeProject();
         $this->_setView('success');
         $this->_view->set('title', 'Security Knowledge Framework::  Project is stored!');
         $this->_view->set('menuActiveProject', "class='active'");
         $this->_view->set('menuActiveProjectNew', "class='active'");
     } catch (Exception $e) {
         $this->_setView('newproject');
         $this->_view->set('title', 'Security Knowledge Framework:: There was an error saving the data!');
         $this->_view->set('menuActiveProject', "class='active'");
         $this->_view->set('menuActiveProjectNew', "class='active'");
         $this->_view->set('formData', $_POST);
         $this->_view->set('saveError', $e->getMessage());
     }
     return $this->_view->output();
 }