function saveconfigurationAction()
 {
     $categoryModel = $this->getModel("CategoryOperations");
     $jobsModel = $this->jobsModel;
     $currentCategories = $jobsModel->fetchCategories();
     $data = stripslashes($_POST['categoriesObject']);
     $categories = Zend_Json::decode($data);
     $mustReload = false;
     $foundCategories = array();
     $db = $categoryModel->getAdapter();
     $orderDirector = array();
     foreach ($categories as $index => $category) {
         $existing = explode("_", $category["existing"]);
         if ($existing[0] == "existing") {
             $id = $existing[1];
             $foundCategories[] = $id;
             if ($currentCategories->getCategory($id)) {
                 ////////////////////////////////////////////
                 // CATEGORY EXISTS - REORDERED || RENAMED
                 ////////////////////////////////////////////
                 if ($category['name'] != $currentCategories->getCategory($id)->getProperty("name") || $index != $currentCategories->getCategory($id)->getProperty("orderindex")) {
                     $orderIndex = $index;
                     $categoryNameBackup = $category['name'];
                     $category['name'] = preg_replace('%[^\\w\\.-\\s]%', '', $category['name']);
                     if ($category['name'] != $categoryNameBackup) {
                         $mustReload = true;
                     }
                     $data = array("orderindex" => $orderIndex, "name" => $category['name'], "link" => $this->view->MakeLink($category['name']));
                     $where = $db->quoteInto('id = ?', $id);
                     $categoryModel->update($data, $where);
                 }
             }
         } else {
             ///////////////////
             // CREATE CATEGORY
             ///////////////////
             $orderIndex = $index;
             //				$category['name'] = preg_replace('%[^\w\.-\s]%', '', $category['name']);
             $categoryModel->insert(array("name" => $category['name'], "orderindex" => $orderIndex, "link" => $this->view->MakeLink($category['name'])));
             $mustReload = true;
         }
     }
     /////////////////////
     // DELETE CATEGORIES
     /////////////////////
     $foundCategories[] = 1;
     // Uncategorized category
     $mustDelete = array_diff(array_keys($currentCategories->toArray()), $foundCategories);
     foreach ($mustDelete as $categoryID) {
         if ($categoryID > 1) {
             $where = $db->quoteInto('id = ?', $categoryID);
             $db->update(Zend_Registry::get("conf")->db->prefix . Zend_Registry::get("conf")->dbtables->postings, array("categoryid" => 1), 'categoryid = ' . $categoryID);
             $categoryModel->delete($where);
         }
     }
     Joobsbox_Helpers_Cache::clearAllCache();
     echo json_encode(array("mustReload" => $mustReload));
     die;
 }
 private function validateForm()
 {
     $form = $this->form;
     $publishNamespace = new Zend_Session_Namespace('PublishJob');
     $values = $form->getValues();
     if ($form->isValid($_POST)) {
         $form = $this->_helper->filter('publish_form_submit', $this->form);
         $jobOperations = new Joobsbox_Model_JobOperations();
         $searchModel = new Joobsbox_Model_Search();
         $values = $form->getValues();
         $hash = md5(implode("", $values));
         if (isset($publishNamespace->jobHash) && $publishNamespace->jobHash == $hash) {
             throw new Exception($this->view->translate("You are not allowed to add the same job multiple times."));
         }
         if (isset($publishNamespace->editJobId)) {
             // We have to modify it, nothing more to discuss
             try {
                 $where = $jobOperations->getAdapter()->quoteInto('id = ?', $publishNamespace->editJobId);
                 $values['id'] = $publishNamespace->editJobId;
                 $jobOperations->update(array('categoryid' => $values['category'], 'title' => $values['title'], 'description' => $this->_helper->filter("purify_html", $values['description']), 'toapply' => $values['application'], 'company' => $values['company'], 'location' => $values['location'], 'changeddate' => date("Y-m-d"), 'expirationdate' => strtotime($values['expirationdate']), 'public' => 1), $where);
                 $this->view->editSuccess = 1;
                 $searchModel->addJob($values);
                 unset($publishNamespace->editJobId);
                 $this->_helper->event("job_edited", $values);
                 $publishNamespace->jobHash = $hash;
                 Joobsbox_Helpers_Cache::clearAllCache();
             } catch (Exception $e) {
                 throw new Exception($this->view->translate("An error occured while saving the job. Please try again."));
             }
         } else {
             // Ok, here we go: insert the job into the database --- bombs away!
             $values = $form->getValues();
             try {
                 // Needs posting_ttl configuration directive
                 $this->_conf = Zend_Registry::get("conf");
                 $values['id'] = $jobOperations->insert(array('categoryid' => $values['category'], 'title' => $values['title'], 'description' => $this->_helper->filter("purify_html", $values['description']), 'toapply' => $values['application'], 'company' => $values['company'], 'location' => $values['location'], 'changeddate' => date("Y-m-d"), 'postedat' => date("Y-m-d"), 'expirationdate' => strtotime("+" . $this->_conf->general->posting_ttl . " days"), 'public' => 0));
                 $this->view->addSuccess = 1;
                 $this->_helper->event("job_posted", $values);
                 $publishNamespace->jobHash = $hash;
             } catch (Exception $e) {
                 throw new Exception($this->view->translate("An error occured while saving the job. Please try again."));
             }
         }
     } else {
         $values = $form->getValues();
         $messages = $form->getMessages();
         $form->populate($values);
         $this->form = $form;
         $this->view->form = $this->form->render();
     }
 }
Exemple #3
0
 private function acceptAction()
 {
     $this->jobOperationsModel = $this->getModel("JobOperations");
     $this->searchModel = $this->getModel("Search");
     foreach ($_POST['job'] as $job => $a) {
         $job = (int) $job;
         Zend_Registry::get("EventHelper")->fireEvent("job_accepted", $job);
         $x = $this->jobOperationsModel->update(array('public' => 1, 'changeddate' => date("Y-m-d")), $this->jobOperationsModel->getAdapter()->quoteInto('id = ?', $job));
         $this->searchModel->addJob($this->jobsModel->fetchJobById($job));
         // Rebuild cache
         Joobsbox_Helpers_Cache::clearAllCache();
     }
     echo "ok";
     die;
 }