public function init() { $mainMenu = new Showcase_Admin_Menus(); $this->view->assign('mainMenu', $mainMenu->mainMenu); $this->_jobId = $this->_getParam('jobId'); $this->_clientId = $this->_getParam('clientId'); //load the job $job = new Showcase_Controller_Action_Helper_Jobs(); $this->_job = $job->loadJob($this->_clientId, $this->_jobId, 'NULL', 'get_job_all_status'); //list of status $this->_status = Showcase_Admin::getStatus(); //get the list of clients $this->_clients = $this->_helper->Job->loadClient(1); //fetch the name of the client from the id $this->_clientName = Showcase_Admin::seekName($this->_clients, $this->_clientId); }
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'); } } }