2009-01-12 21:13:18 -08:00
|
|
|
<?php
|
|
|
|
|
class CountriesController extends AppController {
|
|
|
|
|
|
|
|
|
|
var $name = 'Countries';
|
|
|
|
|
var $helpers = array('Html', 'Form');
|
|
|
|
|
|
2011-10-24 00:14:07 -07:00
|
|
|
var $paginate = array(
|
|
|
|
|
'limit' => 400,
|
|
|
|
|
'Enquiry' => array('order' => array('Enquiry.id' => 'asc'))
|
|
|
|
|
);
|
2009-02-09 14:25:49 -08:00
|
|
|
|
2009-01-12 21:13:18 -08:00
|
|
|
function index() {
|
|
|
|
|
$this->Country->recursive = 0;
|
|
|
|
|
$this->set('countries', $this->paginate());
|
2011-10-24 00:14:07 -07:00
|
|
|
//$this->set('countries', $this->Country->find('all'));
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function view($id = null) {
|
|
|
|
|
if (!$id) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid Country.', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
$this->set('country', $this->Country->read(null, $id));
|
2009-02-09 14:25:49 -08:00
|
|
|
$this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.country_id' => $id)));
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function add() {
|
|
|
|
|
$this->set('currencies', $this->Country->Currency->find('list', array('fields'=>array('Currency.id', 'Currency.name'))));
|
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
|
|
|
|
|
|
$this->Country->create();
|
|
|
|
|
|
|
|
|
|
if ($this->Country->save($this->data)) {
|
|
|
|
|
$this->Session->setFlash(__('The Country has been saved', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The Country could not be saved. Please, try again.', true));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function edit($id = null) {
|
|
|
|
|
if (!$id && empty($this->data)) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid Country', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
|
if ($this->Country->save($this->data)) {
|
|
|
|
|
$this->Session->setFlash(__('The Country has been saved', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
} else {
|
|
|
|
|
$this->Session->setFlash(__('The Country could not be saved. Please, try again.', true));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (empty($this->data)) {
|
|
|
|
|
$this->data = $this->Country->read(null, $id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delete($id = null) {
|
|
|
|
|
if (!$id) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid id for Country', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
if ($this->Country->del($id)) {
|
|
|
|
|
$this->Session->setFlash(__('Country deleted', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-10 15:32:00 -08:00
|
|
|
|
|
|
|
|
function completeCountry() {
|
|
|
|
|
$query = strtolower($_GET["term"]);
|
|
|
|
|
|
|
|
|
|
if($query == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
App::import('Core', 'Sanitize');
|
|
|
|
|
|
|
|
|
|
$query = Sanitize::clean($query);
|
|
|
|
|
|
2011-03-28 18:47:50 -07:00
|
|
|
$countries = $this->Country->find('list', array(
|
2010-03-10 15:32:00 -08:00
|
|
|
'conditions' => array(
|
|
|
|
|
'Country.name LIKE' => '%'.$query.'%'
|
2011-03-28 18:47:50 -07:00
|
|
|
),'fields' => array('Country.id', 'Country.name'), 'order' =>array('Country.name ASC')
|
2010-03-10 15:32:00 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
2011-03-28 18:47:50 -07:00
|
|
|
//print_r($countries);
|
2010-03-10 15:32:00 -08:00
|
|
|
|
2011-03-28 18:47:50 -07:00
|
|
|
foreach ($countries as $id => $country) {
|
|
|
|
|
|
|
|
|
|
$country_list[] = array('id'=> $id, 'label' => $country);
|
2010-03-10 15:32:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-03-28 18:47:50 -07:00
|
|
|
//$countries_json = json_encode($country_list);
|
|
|
|
|
|
|
|
|
|
$countries_json = json_encode($country_list);
|
2010-03-10 15:32:00 -08:00
|
|
|
|
|
|
|
|
$this->set('countries_json', $countries_json);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->layout = 'ajax';
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 21:13:18 -08:00
|
|
|
}
|
|
|
|
|
?>
|