public function editAction() { $id = $this->_getParam('id'); $preview = false; $preview = $this->_getParam('preview'); //echo "diana==>".base64_encode(85); $this->view->id = $id; $this->view->preview = $preview; $page = new Application_Model_Advice(); $page = $page->find($id); $options = array('categoryId' => $page->getCategoryId(), 'title' => $page->getTitle(), 'identifire' => $page->getIdentifire(), 'name' => $page->getName(), 'content' => $page->getContent(), 'synopsis' => $page->getSynopsis(), 'metaTitle' => $page->getMetaTitle(), 'metaDescription' => $page->getMetaDescription(), 'metaKeyword' => $page->getMetaKeyword(), 'status' => $page->getStatus(), 'name' => $page->getName(), 'userId' => $page->getUserId()); $request = $this->getRequest(); $form = new Admin_Form_Advice(); //clear form element decorators $elements = $form->getElements(); $form->clearDecorators(); foreach ($elements as $element) { $element->removeDecorator('label'); $element->removeDecorator('td'); $element->removeDecorator('tr'); $element->removeDecorator('row'); $element->removeDecorator('HtmlTag'); $element->removeDecorator('class'); $element->removeDecorator('placement'); $element->removeDecorator('data'); } //$this->view->type = $page->getType(); $this->view->imgName = $page->getName(); $form->populate($options); if ($request->isPost()) { $options = $request->getPost(); if (trim($options['identifire']) == "") { $sanitize = new Base_Sanitize(); $options['identifire'] = $options['title']; } if (trim($options['identifire']) != "") { $sanitize = new Base_Sanitize(); $options['identifire'] = $sanitize->clearInputs($options['identifire']); $options['identifire'] = $sanitize->sanitize($options['identifire']); //update seo url table $seo_url_title = $options['identifire']; $adviceM = new Application_Model_Advice(); $advice = $adviceM->find($id); $seo_url = ""; $actual_url = "/advice/detail/id/{$id}"; if (false !== $advice) { $sanitizeM = new Base_Sanitize(); //$category_id = $advice->getCategoryId(); $category_id = $options['categoryId']; $categoryM = new Application_Model_Category(); $category = $categoryM->find($category_id); if (false !== $category) { $seo_url = "/advice/" . $sanitizeM->sanitize($category->getName()) . "/" . $seo_url_title; } } $seoUrlM = new Application_Model_SeoUrl(); $soeUrl = $seoUrlM->fetchRow("actual_url='{$actual_url}'"); if (false !== $soeUrl) { if ($seo_url != "") { $soeUrl->setSeoUrl($seo_url); $soeUrl->save(); } } else { if ($seo_url != "") { $seoUrl = new Application_Model_SeoUrl(); $seoUrl->setActualUrl($actual_url); $seoUrl->setSeoUrl($seo_url); $seoUrl->save(); } } } //save data if ($form->isValid($options)) { //set previous image name if not uploaded new one $options['name'] = $page->getName(); /*------------------------------ Image Upload START ---------------------------*/ $upload = new Zend_File_Transfer_Adapter_Http(); if ($upload->isValid()) { $upload->setDestination("images/advice/"); try { $upload->receive(); } catch (Zend_File_Transfer_Exception $e) { $msg = $e->getMessage(); } //unlink previous uploaded image files unlink("images/advice/" . $page->getName()); unlink("images/advice/thumb_" . $page->getName()); $upload->setOptions(array('useByteString' => false)); $file_name = $upload->getFileName('name'); $cardImageTypeArr = explode(".", $file_name); $ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]); $target_file_name = "advice_" . time() . ".{$ext}"; $targetPath = 'images/advice/' . $target_file_name; $targetPathThumb = 'images/advice/thumb_' . $target_file_name; $filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true)); $filterFileRename->filter($file_name); $thumb = Base_Image_PhpThumbFactory::create($targetPath); $thumb->resize(128, 84); $thumb->save($targetPathThumb); // file name $options['name'] = $target_file_name; } /*------------------------------ Image Upload END ---------------------------*/ $options['status'] = $page->getStatus(); if ($options["saveUnpublish"] == "Save and Unpublish") { $options['status'] = 0; } if ($options["savePublish"] == "Save and Publish") { $options['status'] = 1; } $page->setOptions($options); $page->save(); //return $this->_helper->redirector('index','advice',"admin",Array('msg'=>base64_encode("'{$page->getTitle()}' has been updated successfully!"))); if ($options["savePublish"] == "Save and Publish") { $_SESSION['errorMsg'] = "Article has been saved & published successfully."; $this->_helper->redirector('index', 'advice', 'admin'); } else { if ($options["saveUnpublish"] == "Save and Unpublish") { $_SESSION['errorMsg'] = "Article has been saved successfully."; $this->_helper->redirector('index', 'advice', 'admin'); } else { $this->_helper->redirector('edit', 'advice', 'admin', array('id' => $id, 'preview' => 'true')); } } } else { $form->reset(); $form->populate($options); } } $this->view->form = $form; }
public function addAction() { $request = $this->getRequest(); $form = new Admin_Form_Articles(); //clear form element decorators $elements = $form->getElements(); $form->clearDecorators(); foreach ($elements as $element) { $element->removeDecorator('label'); $element->removeDecorator('td'); $element->removeDecorator('tr'); $element->removeDecorator('row'); $element->removeDecorator('HtmlTag'); $element->removeDecorator('class'); $element->removeDecorator('placement'); $element->removeDecorator('data'); } $model = new Application_Model_Articles(); $page_id = $this->_getParam('id'); $this->view->msg = ""; if ($this->_getParam('m') == 's') { $this->view->msg = "Article has been saved successfully."; } //select logged in user as default seleted for Author $usersNs = new Zend_Session_Namespace("members"); $author = array('userId' => $usersNs->userId); $form->populate($author); /*-----------------------------------------*/ if ($this->getRequest()->isPost()) { $options = $request->getPost(); if (trim($options['identifire']) == "") { $options['identifire'] = $options['title']; } if (trim($options['identifire']) != "") { $sanitize = new Base_Sanitize(); $options['identifire'] = $sanitize->clearInputs($options['identifire']); $options['identifire'] = $sanitize->sanitize($options['identifire']); } if ($form->isValid($options)) { /*------------------------------Image Upload ---------------------------*/ $upload = new Zend_File_Transfer_Adapter_Http(); $target_file_name = ""; if ($upload->isValid()) { $upload->setDestination("images/articles/"); try { $upload->receive(); } catch (Zend_File_Transfer_Exception $e) { $msg = $e->getMessage(); } $upload->setOptions(array('useByteString' => false)); $file_name = $upload->getFileName('image'); $cardImageTypeArr = explode(".", $file_name); $ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]); $target_file_name = "art_" . time() . ".{$ext}"; $targetPath = 'images/articles/' . $target_file_name; $targetPathThumb = 'images/articles/thumb_' . $target_file_name; $filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true)); $filterFileRename->filter($file_name); $thumb = Base_Image_PhpThumbFactory::create($targetPath); $thumb->resize(100, 64); $thumb->save($targetPathThumb); } //end if /*------------------------------Image Upload ---------------------------*/ $params = $options; $params['status'] = 1; if ($options["savePublish"] != "Save and Publish") { $params['status'] = 0; } //commented by mahipal on 29-dec-2010 and replaced with user dropdown list //$usersNs = new Zend_Session_Namespace("members"); //$params['userId'] = $usersNs->userId; $params['image'] = $target_file_name; // file name $model = new Application_Model_Articles($params); $id = $page_id = $model->save(); $seo_url_title = $options['identifire']; $articleM = new Application_Model_Articles(); $article = $articleM->find($id); $seo_url = ""; $actual_url = "/work-study-volunteer/article-detail/id/{$id}"; if (false !== $article) { $sanitizeM = new Base_Sanitize(); $category_id = $article->getCategoryId(); $categoryM = new Application_Model_Category(); $category = $categoryM->find($category_id); if (false !== $category) { //$seo_url="/work-study-volunteer/".$category->getType()."/".$sanitizeM->sanitize($category->getName())."/".$seo_url_title; $seo_url = "/work-study-volunteer/" . $sanitizeM->sanitize($category->getName()) . "/" . $seo_url_title; } } $seoUrlM = new Application_Model_SeoUrl(); $seoUrl = $seoUrlM->fetchRow("actual_url='{$actual_url}'"); if (false !== $seoUrl) { if ($seo_url != "") { $seoUrl->setSeoUrl($seo_url); $seoUrl->save(); } } else { if ($seo_url != "") { $seoUrl = new Application_Model_SeoUrl(); $seoUrl->setActualUrl($actual_url); $seoUrl->setSeoUrl($seo_url); $seoUrl->save(); } } //$this->_helper->redirector('add','articles','admin',array('id'=>$page_id,'m'=>'s')); if ($options["savePublish"] == "Save and Publish") { $_SESSION['errorMsg'] = "Article has been saved & published successfully."; $this->_helper->redirector('index', 'articles', 'admin'); } else { if ($options["saveUnpublish"] == "Save and Unpublish") { $_SESSION['errorMsg'] = "Article has been saved successfully."; $this->_helper->redirector('index', 'articles', 'admin'); } else { $this->_helper->redirector('edit', 'articles', 'admin', array('id' => $page_id, 'preview' => 'true')); } } } //end if } //end if $this->view->form = $form; }
public function seggessionPopupAction() { $this->_helper->layout->disableLayout(); $catid = $this->_getParam('category'); $category = ""; $category_id = 0; if ($catid > 0) { $Category = new Application_Model_Category(); $object = $Category->find($catid); if ($object) { $category = $object->getName(); $category_id = $object->getId(); } } $this->view->category = $category; $this->view->catid = $category_id; $this->view->search1 = ucwords($this->_getParam('search1')); }
public function articleDetailAction() { //$this->_helper->viewRenderer->setNoRender(true); $blockM = new Base_View_Block(); $path = "/layouts/scripts/page/blocks/work-study-volunteer"; $blockM->removeBlock("work-study-volunteer-categories", 'work-study-volunteer'); $params = $this->getRequest()->getParams(); $article_id = $params['id']; $preview = false; $preview = $this->_getParam("preview"); $categoryM = new Application_Model_Category(); $articleM = new Application_Model_Articles(); $data = $articleM->find($article_id); if (false != $data) { $this->view->article = $data; $this->view->preview = $preview; $this->view->categoryId = $categoryId = $data->getCategoryId(); $this->view->categoryM = $categoryM->find($categoryId); $allarticles = $articleM->fetchAll("category_id = {$categoryId} and id != {$article_id}"); /** * @Added By: Mahipal Adhikari * @Added On: 29-Dec-2010 * @Description: get Article user information to display as Author */ $userM = new Application_Model_User(); $userRes = $userM->find($data->getUserId()); $Author = "Admin"; if (false !== $userRes) { $Author = $userRes->getFirstName() . " " . $userRes->getLastName(); $this->view->author = $Author; $this->view->author_username = $userRes->getUsername(); } if (count($allarticles) > 0) { $this->view->allarticles = $allarticles; $blocks = array("name" => "work-study-volunteer-articles", "order" => "8", "path" => $path); $blockM->addBlock($blocks, 'work-study-volunteer'); } } }
/** * @Created By : Mahipal Singh Adhikari * @Created On : 5-Jan-2011 * @Description: This function used to delete user(simply change user status as 'deleted') */ public function deleteAction() { $id = $this->_getParam('id'); $type = $this->_getParam('type'); $catM = new Application_Model_Category(); //$catM->delete("id={$id}"); $catRes = $catM->find($id); if ($catRes) { $catRes->setStatus('deleted'); $catRes->save(); //delete all data associated with category $catM->deleteCategoryData($id); //set message $msg = "Category has been deleted successfully!"; } else { $msg = "Invalid request, no category found!"; } //set mesage in session and redirect user to index $_SESSION['errorMsg'] = $msg; $this->_helper->redirector('index', 'category', "admin", array('type' => $type)); }
/** * @Created By : Mahipal Singh Adhikari * @Created On : 10-Feb-2011 * Description : Search advice */ public function searchAction() { $params = $this->getRequest()->getParams(); $where = "status='1'"; $order = "addedon DESC"; $categoryM = new Application_Model_Category(); //search by keyword if (isset($params['search-strg'])) { if ($params['search-strg'] != '' && $params['search-strg'] != 'Search by Keyword') { $keyword = $params['search-strg']; $where .= " AND (title LIKE '%{$keyword}%' OR content LIKE '%{$keyword}%' OR synopsis LIKE '%{$keyword}%')"; $this->view->searchstr = $keyword; } } //search by category if (isset($params['category_id']) && $params['category_id'] != '') { $this->view->category_id = $category_id = $params['category_id']; $categorydata = $categoryM->find($category_id); $category_id = $categorydata->getId(); $this->view->categoryName = $categorydata->getName(); $where .= " AND category_id = {$category_id}"; } $adviceM = new Application_Model_Advice(); //$settings = new Admin_Model_GlobalSettings(); //$page_size = $settings->settingValue('pagination_size'); //$page_size = 1; //$page = $this->_getParam('page',1); //$pageObj = new Base_Paginator(); //$paginator = $pageObj->fetchPageData($adviceM, $page, $page_size, $where); //$this->view->total = $pageObj->getTotalCount(); //$this->view->advices = $paginator; $adviceRes = $adviceM->fetchAll($where, $order); $this->view->total = count($adviceRes); $this->view->advices = $adviceRes; $this->view->categoryM = $categoryM; }