JezK
Edit File: PagesController.php
<?php /** * Static content controller. * * This file will render views from views/pages/ * * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * * Licensed under The MIT License * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project * @package app.Controller * @since CakePHP(tm) v 0.2.9 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ App::uses('AppController', 'Controller'); App::uses('File', 'Utility'); App::uses('CakeEmail', 'Network/Email'); /** * Static content controller * * Override this controller by placing a copy in controllers directory of an application * * @package app.Controller * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html */ class PagesController extends AppController { /** * This controller does not use a model * * @var array */ public $uses = array(); /** * Displays a view * * @param mixed What page to display * @return void * @throws NotFoundException When the view file could not be found * or MissingViewException in debug mode. */ public function index() { if ($this->request->is('post')) { echo "test"; exit; $message = 'Name: '.$this->request->data['name'].' Email: '.$this->request->data['email'].' Phone number:'.$this->request->data['phoneNo'].' Message :'.$this->request->data['message']; $email = 'prasanthi@krify.net'; $Email = new CakeEmail(); $Email->transport($this->emailSettype); if($this->emailSettype == "Smtp") { $Email->config($this->emailSettingsArr); } $Email->from(array($this->siteEmail => $this->siteName)); $Email->to($email); $Email->template('default'); $Email->emailFormat('html'); $Email->subject('NPTE contact us'); $Email->send($message); $this->Session->setFlash(__('message submitted successfully'), 'flash', array('alert' => 'success')); } $this->redirect(array('controller' => '')); } public function display() { $path = func_get_args(); $count = count($path); if (!$count) { return $this->redirect('/'); } $page = $subpage = $title_for_layout = null; if (!empty($path[0])) { $page = $path[0]; } if (!empty($path[1])) { $subpage = $path[1]; } if (!empty($path[$count - 1])) { $title_for_layout = Inflector::humanize($path[$count - 1]); } $this->set(compact('page', 'subpage', 'title_for_layout')); if ($this->frontLeaderBoard == 1) { //////////////////// CUSTOM QUERY START /////////////////////// $this->loadModel('Leaderboard'); $scoreboard = $this->Leaderboard->query("SELECT `points`,`student_id`,`exam_given`,`name`,`rank` FROM (SELECT ROUND(SUM(`percent`)/((SELECT COUNT( `id` ) FROM `exam_results` WHERE `student_id` = `ExamResult`.`student_id` AND `finalized_time` IS NOT NULL)),2) AS `points` ,`student_id`,(SELECT COUNT( `id` ) FROM `exam_results` WHERE `student_id` = `ExamResult`.`student_id` AND `finalized_time` IS NOT NULL) AS `exam_given`, `Student`.`name`,FIND_IN_SET((SELECT ROUND(SUM(`percent`)/((SELECT COUNT( `id` ) FROM `exam_results` WHERE `student_id` = `ExamResult`.`student_id` AND `finalized_time` IS NOT NULL)),2)),(SELECT GROUP_CONCAT(cast(`total` as char)) FROM (SELECT DISTINCT(ROUND(SUM(`percent`)/(SELECT COUNT( `id` ) FROM `exam_results` WHERE `student_id` = `ExamResult`.`student_id` AND `finalized_time` IS NOT NULL),2)) `total` FROM `exam_results` AS `ExamResult` GROUP BY `student_id` ORDER BY 1 DESC) as avg_percent)) AS `rank` FROM `exam_results` AS `ExamResult` INNER JOIN `students` AS `Student` ON `ExamResult`.`student_id` = `Student`.`id` WHERE `finalized_time` IS NOT NULL GROUP BY `student_id`) `Selection` ORDER BY `points` DESC LIMIT 10"); //////////////////// CUSTOM QUERY END /////////////////////// $this->set('scoreboard', $scoreboard); } $this->loadModel('Package'); $showPackageTypeArr = array(); if ($this->showPackageType == 0) { $showPackageTypeArr = array('Package.package_type <>' => 'F'); } $Package_response = $this->Package->find('all', array('conditions' => array('Package.status' => 'Active', $showPackageTypeArr), 'order' => array('Package.id' => 'DESC'),'limit'=>'8')); $this->set('Package', $Package_response); $this->loadModel('Homesection'); $Homesection_response = $this->Homesection->find('all', array('order' => array('Homesection.id' => 'ASC'))); $this->set('Homesection', $Homesection_response); $news = array(); $slides = array(); $this->loadModel('Advertisement'); $this->loadModel('Testimonial'); $this->loadModel('Student'); $this->loadModel('Exam'); $this->loadModel('Slide'); $this->loadModel('News'); $this->set('students', $this->Student->find('count')); $this->set('exams', $this->Exam->find('count')); // $this->set('testimonials', $this->Testimonial->find('all', array('conditions' => array('status' => 'Active'), 'order' => array('ordering' => 'ASC')))); $this->set('testimonials', $this->Testimonial->findAllByStatus('Active')); $this->set('advertisements', $this->Advertisement->findAllByStatus('Active')); $slides = $this->Slide->find('all', array('conditions' => array('status' => 'Active'), 'order' => array('ordering' => 'DESC'))); $news = $this->News->find('all', array('conditions' => array('status' => 'Active'), 'order' => 'id desc')); $this->set('slides', $slides); $this->set('news', $news); $file = new File(TMP . 'visitors.txt', false); $visitors = $file->read(true); $file->close(); $file = new File(TMP . 'visitors.txt', false); $visitors++; $file->write($visitors); $file->close(); $this->set('visitors', $visitors); try { $this->render(implode('/', $path)); } catch (MissingViewException $e) { if (Configure::read('debug')) { throw $e; } throw new NotFoundException(); } } }