public function newAction() { $this->view->assign('requestUri', $this->getRequest()->getRequestUri()); $this->view->assign('jobId', $this->_jobId); $this->view->assign('title', 'Add a phase'); //fetch all the status available in the db $this->view->assign('status', $this->_status); //if save is submitted if ($this->getRequest()->isPost()) { if ($post = $this->getRequest()->getPost('addContent')) { //put the files into the main post if ($_FILES['image']) { $post['image'] = $_FILES['image']; $post['image']['description'] = $post['description']; unset($post['imageAlt']); } // jobId and clientId in the post $post['jobId'] = $this->_jobId; $post['clientId'] = $this->_clientId; //Turn client into an array with id and name $clientName = Showcase_Admin::seekName($this->_clients, $post['clientId']); $post['client'] = array('name' => $clientName, 'id' => $post['clientId']); unset($post['clientId']); //specify the operation type $post['operationType'] = 'save'; //validate, upload and saveDB $oContent = new Showcase_Admin_Content($post); $return = $oContent->processContent(); //print errors if (isset($return['Error'])) { $this->view->assign('errorMessages', $return['Error']); $this->view->assign('posted', $return['post']); return false; } //if successful $this->_redirect('/admin/content/success'); } $this->view->assign('errorMessage', 'There was a problem with your form, please submit again.'); } }
public function editAction() { $title = 'Edit a Job'; $this->view->assign('title', $title); //populate the list of clients $this->view->assign('clients', $this->_clients); // if the form has come back... if ($this->getRequest()->isPost()) { //After selecting the client if ($client = $this->getRequest()->getPost('selectClient')) { // if the user sets an empty user if ($client == '') { $this->view->assign('errorMessages', array('Please select a client.')); return false; } //set the action and error $this->view->assign('requestUri', $this->getRequest()->getRequestUri()); $this->view->assign('errorMessages', array()); //Turn client into an array with id and name $clientName = Showcase_Admin::seekName($this->_clients, $client['client']); $posted = array('client' => array('name' => $clientName, 'id' => $client['client'])); //keeping the selected client open correctly $this->view->assign('posted', $client); //then load and update the jobNumber list $jobNumbers = $this->_helper->Job->getJobsNumbers($posted['client']['id']); //open the second select in the form and populate with jobs $this->view->assign('selectJob', 1); $this->view->assign('errorMessages', array()); $this->view->assign('jobNumbers', $jobNumbers); } // after selecting a job number if ($posted = $this->getRequest()->getPost('selectJob')) { //print_r($posted); die; //Turn client into an array with id and name $clientName = Showcase_Admin::seekName($this->_clients, $posted['client']); $posted['client'] = array('name' => $clientName, 'id' => $posted['client']); //load and update the jobNumber list $this->_jobNumbers = $this->_helper->Job->getJobsNumbers($posted['client']['id']); $this->view->assign('jobNumbers', $this->_jobNumbers); //fetch all the status available in the db $this->view->assign('status', $this->_status); //keep the job number selection form open $this->view->assign('selectJob', 1); //open the 3rd and last form $this->view->assign('jobChosen', $posted['jobId']); //get job using a already built frontend helper with a twist //that we pass the name for a similar proc without the status requirement $dbJob = new Showcase_Controller_Action_Helper_Jobs(); $posted['job'] = $dbJob->loadJob($posted['client']['id'], $posted['jobId'], 'NULL', 'get_job_all_status'); //instantiate the job object $oJob = new Showcase_Admin_Job($posted); //strip the old frontend object for admin $posted = $oJob->prepareObject($posted); //populate the form $this->view->assign('posted', $posted); //print_r($posted); die; } //if it was SUBMITTED for update if ($posted = $this->getRequest()->getPost('editJob')) { //print_r($posted); die; //Turn client into an array with id and name $clientName = Showcase_Admin::seekName($this->_clients, $posted['client']); $posted['client'] = array('name' => $clientName, 'id' => $posted['client']); if (!empty($_FILES['image']['name']) || !empty($_FILES['thumb']['name'])) { //put the files into the main post $this->getFilesIntoPost('image', $posted, 'images', 'imageAlt'); $this->getFilesIntoPost('thumb', $posted, 'thumbs', 'thumbAlt'); } if (!empty($_FILES['document']['name'])) { $this->getFilesIntoPost('document', $posted, 'documents', 'docdescription'); } //go! $oJob = new Showcase_Admin_Job($posted); $return = $oJob->updateJob(); //print the errors returned with the sanitized post if (isset($return['Error'])) { //keep the job number selection form open $this->view->assign('selectJob', 1); //open the 3rd and last form $this->view->assign('jobChosen', $posted['jobId']); // TODO: should be an array of messages $this->view->assign('errorMessages', $return['Error']); $this->view->assign('posted', $return['post']); return false; } $this->_redirect('/admin/job/success'); } } }