~mparic/+junk/openauctionlive

« back to all changes in this revision

Viewing changes to app/controllers/bidders_controller.php

  • Committer: Michael Paric
  • Date: 2012-01-07 20:21:14 UTC
  • Revision ID: mparic@compbizsolutions.com-20120107202114-6q89jiel6y3rbwgc
Updated validation rules to prevent duplicate Bid and Bidder entries; updated return message color for successful form entry to differentiate from error; added simlink in img/ for image to be used in reports - just change what auction_logo.jpg points to instead of changing View code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
        var $name = 'Bidders';
5
5
  
6
 
  var $components = array('DataHandler','ForceDownload');
 
6
        var $components = array('DataHandler','ForceDownload');
7
7
 
8
8
        function index() {
9
 
          $event = $this->Bidder->Event->find('first',array('conditions' => array('Event.id' => $this->Session->read('event_id'))));
 
9
                $event = $this->Bidder->Event->find('first',array('conditions' => array('Event.id' => $this->Session->read('event_id'))));
10
10
                $this->Bidder->recursive = 0;
11
 
    $this->paginate = array('conditions' => array('Bidder.event_id' => $this->Session->read('event_id')),
12
 
                            'order' => array('Bidder.last_name' => 'asc'));
13
 
    $bidders = $this->paginate('Bidder');
14
 
    $this->set(compact('bidders','event'));
 
11
            $this->paginate = array('conditions' => array('Bidder.event_id' => $this->Session->read('event_id')),
 
12
                                    'order' => array('Bidder.last_name' => 'asc'));
 
13
            $bidders = $this->paginate('Bidder');
 
14
            $this->set(compact('bidders','event'));
15
15
        }
16
16
 
17
17
        function view($id = null) {
19
19
                        $this->Session->setFlash(__('Invalid bidder', true));
20
20
                        $this->redirect(array('action' => 'index'));
21
21
                }
22
 
    $this->Bidder->unbindModel(
23
 
        array('belongsTo' => array('Event'))
24
 
    );
 
22
        $this->Bidder->unbindModel(array('belongsTo' => array('Event')));
25
23
    
26
 
    $this->Bidder->recursive = 2;
27
 
    $bidder = $this->Bidder->read(null, $id);
28
 
    if (!$bidder) {
29
 
      $this->Session->setFlash(__('Invalid Bidder ID', true));
30
 
      $this->redirect(array('action' => 'index'));
31
 
    }
32
 
    //pr($bidder);exit();
 
24
            $this->Bidder->recursive = 2;
 
25
            $bidder = $this->Bidder->read(null, $id);
 
26
            if (!$bidder) {
 
27
              $this->Session->setFlash(__('Invalid Bidder ID', true));
 
28
              $this->redirect(array('action' => 'index'));
 
29
            }
 
30
            //pr($bidder);exit();
33
31
                $this->set('bidder', $bidder);
34
32
        }
35
33
 
36
34
        function add() {
37
35
                if (!empty($this->data)) {
38
 
                  $this->data['Bidder']['event_id'] = $this->Session->read('event_id');
39
 
      $this->data['Bidder']['phone'] = preg_replace('/[[:punct:]]|[[:space:]]/','',$this->data['Bidder']['phone']);
 
36
                        $this->data['Bidder']['event_id'] = $this->Session->read('event_id');
 
37
                $this->data['Bidder']['phone'] = preg_replace('/[[:punct:]]|[[:space:]]/','',$this->data['Bidder']['phone']);
40
38
                        $this->Bidder->create();
41
39
                        if ($this->Bidder->save($this->data)) {
42
 
                                $this->Session->setFlash(__('The bidder has been saved - ' . $this->data['Bidder']['first_name'] . ' ' . $this->data['Bidder']['last_name'] . ' ID: ' . $this->Bidder->id, true));
43
 
        $this->data = null;
 
40
                                $this->Session->setFlash(__('The bidder has been saved - ' . $this->data['Bidder']['first_name'] . ' ' . 
 
41
                                                                                $this->data['Bidder']['last_name'] . ' ID:      ' . $this->Bidder->id, true),'default', array('class'=>'info-message'));
 
42
                        $this->data = null;
44
43
                                $this->redirect(array('action' => 'add'));
45
44
                        } else {
46
45
                                $this->Session->setFlash(__('The bidder could not be saved. Please, try again.', true));
47
46
                        }
48
47
                }
49
 
    $event = $this->Bidder->Event->find('first',array('conditions' => array('Event.id' => $this->Session->read('event_id'))));
50
 
    $this->set(compact('event'));
 
48
        $event = $this->Bidder->Event->find('first',array('conditions' => array('Event.id' => $this->Session->read('event_id'))));
 
49
        $this->set(compact('event'));
51
50
        }
52
51
 
53
52
        function edit($id = null) {
57
56
                }
58
57
                if (!empty($this->data)) {
59
58
                  $this->data['Bidder']['phone'] = preg_replace('/[[:punct:]]|[[:space:]]/','',$this->data['Bidder']['phone']);
60
 
      if ($this->Bidder->save($this->data)) {
61
 
                                $this->Session->setFlash(__('The bidder has been saved', true));
 
59
        if ($this->Bidder->save($this->data)) {
 
60
                                $this->Session->setFlash(__('The bidder has been saved', true),'default', array('class'=>'success-message'));
62
61
                                $this->redirect(array('action' => 'index'));
63
62
                        } else {
64
63
                                $this->Session->setFlash(__('The bidder could not be saved. Please, try again.', true));
69
68
                }
70
69
        }
71
70
 
72
 
  function check_out() {
73
 
    if (!empty($this->data)) {
74
 
      $this->redirect(array('action' => 'view',$this->data['Bidder']['bidder_id']));
75
 
    }
76
 
  }
 
71
        function check_out() {
 
72
        if (!empty($this->data)) {
 
73
                $this->redirect(array('action' => 'view',$this->data['Bidder']['bidder_id']));
 
74
        }
 
75
        }
77
76
 
78
77
        function delete($id = null) {
79
78
          $this->isAuthorized();
82
81
                        $this->redirect(array('action'=>'index'));
83
82
                }
84
83
                if ($this->Bidder->delete($id)) {
85
 
                        $this->Session->setFlash(__('Bidder deleted', true));
 
84
                        $this->Session->setFlash(__('Bidder deleted', true),'default', array('class'=>'success-message'));
86
85
                        $this->redirect(array('action'=>'index'));
87
86
                }
88
87
                $this->Session->setFlash(__('Bidder was not deleted', true));
89
88
                $this->redirect(array('action' => 'index'));
90
89
        }
91
90
 
92
 
  function print_receipt($id = null) {
93
 
    if (!$id) {
94
 
      $this->Session->setFlash(__('Invalid bidder', true));
95
 
      $this->redirect(array('action' => 'index'));
96
 
    }
 
91
        function print_receipt($id = null) {
 
92
        if (!$id) {
 
93
                $this->Session->setFlash(__('Invalid bidder', true));
 
94
                $this->redirect(array('action' => 'index'));
 
95
        }
97
96
    
98
 
    $this->Bidder->unbindModel(
99
 
        array('belongsTo' => array('Event'))
100
 
    );    
101
 
    $this->Bidder->recursive = 2;
102
 
    $bidder = $this->Bidder->read(null, $id);
103
 
    if (!$bidder) {
104
 
      $this->Session->setFlash(__('Invalid Bidder ID', true));
105
 
      $this->redirect(array('action' => 'index'));
106
 
    }
107
 
    $this->Bidder->Event->recursive = -1;
108
 
    $event = $this->Bidder->Event->findById($bidder['Bidder']['event_id']);
109
 
 
110
 
    $this->set(compact('bidder','event'));
111
 
    $this->render('print_receipt', 'minimal');
112
 
  }
 
97
            $this->Bidder->unbindModel(
 
98
                array('belongsTo' => array('Event'))
 
99
            );    
 
100
            $this->Bidder->recursive = 2;
 
101
            $bidder = $this->Bidder->read(null, $id);
 
102
            if (!$bidder) {
 
103
              $this->Session->setFlash(__('Invalid Bidder ID', true));
 
104
              $this->redirect(array('action' => 'index'));
 
105
            }
 
106
            $this->Bidder->Event->recursive = -1;
 
107
            $event = $this->Bidder->Event->findById($bidder['Bidder']['event_id']);
 
108
        
 
109
            $this->set(compact('bidder','event'));
 
110
            $this->render('print_receipt', 'minimal');
 
111
        }
113
112
  
114
 
  function export_csv() {
115
 
    
116
 
    $this->Bidder->recursive = -1;
117
 
    $params = array('conditions' => array('Bidder.event_id' => $this->Session->read('event_id')),
118
 
                            'order' => array('Bidder.last_name' => 'asc'));
119
 
    $bidders = $this->Bidder->find('all',$params);
120
 
    
121
 
    $fieldNames = array_keys($bidders[0]['Bidder']);
122
 
    $csv_data = $this->DataHandler->createCSV($bidders,$fieldNames);
123
 
    $this->ForceDownload->forceDownloadStream($csv_data,'csv','bidder_list.csv');
124
 
    exit();
125
 
  }
 
113
        function export_csv() {
 
114
    
 
115
            $this->Bidder->recursive = -1;
 
116
            $params = array('conditions' => array('Bidder.event_id' => $this->Session->read('event_id')),
 
117
                                    'order' => array('Bidder.last_name' => 'asc'));
 
118
            $bidders = $this->Bidder->find('all',$params);
 
119
            
 
120
            $fieldNames = array_keys($bidders[0]['Bidder']);
 
121
            $csv_data = $this->DataHandler->createCSV($bidders,$fieldNames);
 
122
            $this->ForceDownload->forceDownloadStream($csv_data,'csv','bidder_list.csv');
 
123
            exit();
 
124
        }
126
125
}
127
126
?>
 
 
b'\\ No newline at end of file'