Changeset 698 for trunk/app/controllers

Show
Ignore:
Timestamp:
08/06/08 12:32:50 (4 months ago)
Author:
aarkerio
Message:

Validate arrayas

Location:
trunk/app/controllers
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/controllers/catglossaries_controller.php

    r540 r698  
    4040        $this->set('data', $this->Catglossary->findAll($conditions, $fields, $order)); 
    4141         
    42         /*Edublog*/ 
     42        /*Edublog stuff*/ 
    4343        $this->layout    = $this->Edublog->layout($user_id); 
    4444         
     
    6363 } 
    6464  
    65   
    66  /***  
    67  ===== ADMIM METHODS ===== 
    68  ***/ 
     65 /*** ===== ADMIN METHODS ===== ***/ 
    6966 public function admin_listing() 
    7067 {       
    7168        $this->layout    = 'admin'; 
    7269         
    73         $this->pageTitle = 'Glossaries'; 
     70        $this->pageTitle = __('Glossaries', true); 
    7471         
    7572        $conditions = array('Catglossary.user_id' => $this->Auth->user('id')); 
    7673     
    7774        $fields     = array('Catglossary.id', 'Catglossary.title', 'Catglossary.description', 'Catglossary.created', 'Catglossary.status'); 
    78          
    79         $this->set('data', $this->Catglossary->findAll($conditions, $fields)); 
     75        $order      = 'Catglossary.title'; 
     76        $this->set('data', $this->Catglossary->findAll($conditions, $fields, $order)); 
    8077 } 
    8178  
     
    8986     
    9087    $fields     = array('Catglossary.id', 'Catglossary.title', 'Catglossary.user_id', 'Catglossary.user_id', 'User.id', 'User.username'); 
    91         //debug($this->Catglossary->find($conditions, $fields));exit(); 
    9288        $this->set('data', $this->Catglossary->find($conditions, $fields)); 
    9389 } 
     
    9591 public function admin_add() 
    9692 {   
    97     $this->layout = 'admin'; 
    98          
    99     // adds new classroom to database 
    100     if (!empty($this->data['Catglossary'])) 
    101     { 
     93  $this->layout = 'admin';   
     94   
     95  if (!empty($this->data['Catglossary'])): 
    10296        $this->Sanitize = new Sanitize; 
    10397         
    104         $this->Sanitize->clean($this->data["Catglossary"]); 
     98        $this->Sanitize->clean($this->data['Catglossary']); 
    10599         
    106         $this->data["Catglossary"]["user_id"] = $this->Auth->user('id'); 
     100        $this->data['Catglossary']['user_id'] = (int) $this->Auth->user('id'); 
    107101           
    108         $this->Catglossary->create(); 
    109          
    110         if ($this->Catglossary->save($this->data["Catglossary"])) 
    111     { 
    112              $this->msgFlash('Category Glossary saved.','/admin/catglossaries/listing'); 
    113         } 
    114      }     
     102    if ($this->Catglossary->save($this->data)): 
     103              $this->msgFlash('Category Glossary saved.','/admin/catglossaries/listing'); 
     104        endif;   
     105  endif;      
    115106 } 
    116107 
    117 public function admin_edit($id=null) 
     108public function admin_edit($catglossary_id=null) 
    118109{ 
    119      $this->layout    = 'admin'; 
     110 $this->layout    = 'admin'; 
    120111      
    121      if ( empty( $this->data["Catglossary"] ) ) 
    122      { 
    123          $this->Catglossary->id  = $id; 
    124           
    125          $this->data      = $this->Catglossary->read(); 
    126      } 
    127      else 
    128      {    
     112  if ( empty( $this->data['Catglossary'] ) ):        
     113         $this->data      = $this->Catglossary->read(null, $catglossary_id); 
     114  else: 
     115         
    129116         $this->Sanitize = new Sanitize; 
    130117          
    131          $this->Sanitize->html($this->data["Catglossary"]["title"]); 
     118         $this->Sanitize->html($this->data['Catglossary']['title']); 
    132119          
    133          $this->Sanitize->html($this->data["Catglossary"]["description"]); 
     120         $this->Sanitize->html($this->data['Catglossary']['description']); 
    134121          
    135          if ($this->Catglossary->save($this->data["Catglossary"])) 
    136          {   
    137             $this->msgFlash('Your category has been saved!', '/admin/catglossaries/edit/'.$this->data["Catglossary"]["id"]); 
    138          } 
    139      } 
     122         if ($this->Catglossary->save($this->data)):   
     123            $this->msgFlash(__('Data saved', true), '/admin/catglossaries/edit/'.$this->data['Catglossary']['id']); 
     124         endif; 
     125  endif; 
    140126 } 
    141127  
    142  public function admin_delete($id) 
     128 // change status published/draft 
     129 public function admin_change($status, $catglossary_id) 
     130 {   
     131    if ( !is_numeric($status)  ||  !intval($catglossary_id) ):  
     132        $this->redirect('/'); 
     133        return false; 
     134    endif; 
     135     
     136    $this->data['Catglossary']['status'] = ($status == 0 ) ? 1 : 0; 
     137      
     138    $this->data['Catglossary']['id']     = (int) $catglossary_id; 
     139      
     140    if ($this->Catglossary->save($this->data, array('validate'=>false))): 
     141    $this->msgFlash(__('Status modified', true), '/admin/catglossaries/listing'); 
     142    endif; 
     143 } 
     144 
     145 public function admin_delete($catglossary_id) 
    143146 { 
    144      if ($this->Catglossary->del($id)) 
    145     { 
    146         $this->msgFlash('Category deleted', '/admin/catglossaries/listing'); 
    147     } 
     147   if ($this->Catglossary->del($$catglossary_id)): 
     148          $this->msgFlash(__('Data removed', true), '/admin/catglossaries/listing'); 
     149   endif; 
    148150 } 
    149151} 
  • trunk/app/controllers/glossaries_controller.php

    r540 r698  
    2727        $this->pageTitle = 'Glossaries'; 
    2828         
    29         $user_id = $this->Glossary->User->field('id', array("username"=>$username)); 
     29        $user_id = $this->Glossary->User->field('id', array('username'=>$username)); 
    3030         
    31         $conditions = array("user_id"=>$user_id, "status"=>1); 
     31        $conditions = array('user_id'=>$user_id, 'status'=>1); 
    3232         
    3333        $fields     = array("id", "item", "definition"); 
    3434         
    35         $order      = "item ASC"; 
     35        $order      = 'item ASC'; 
    3636         
    3737        $this->set('data', $this->Glossary->findAll($conditions, $fields, $order)); 
    3838         
    39         /*Edublog*/ 
     39        /*Edublog stuff */ 
    4040        $this->layout    = $this->Edublog->layout($user_id); 
    4141         
     
    4343 } 
    4444      
    45  /***  
    46  ===== ADMIM METHODS ===== 
    47  ***/ 
     45 /*** ===== ADMIM METHODS ===== ***/ 
    4846  
    4947 public function admin_new($catglossary_id) 
     
    5452 } 
    5553  
    56  public function admin_edit($id = null) 
     54 public function admin_edit($glossary_id = null) 
    5755 {   
    5856    $this->layout = 'admin'; 
    5957     
    60     if (empty($this->data["Glossary"])) 
    61     {    
    62         $this->Glossary->id = $id; 
    63          
    64         $this->data = $this->Glossary->read(); 
    65     } 
    66     else 
    67     { 
     58    if (empty($this->data['Glossary'])):         
     59        $this->data = $this->Glossary->read(null, $glossary_id); 
     60    
     61    else: 
     62     
    6863        $this->Sanitize = new Sanitize; 
    6964         
    70         $this->Sanitize->clean($this->data["Glossary"]);  
     65        $this->Sanitize->clean($this->data['Glossary']);  
    7166         
    72         if ($this->Glossary->save($this->data['Glossary'])) 
    73         { 
    74             $this->msgFlash('Glossary has been updated.','/admin/catglossaries/items/'.$this->data['Glossary']['catglossary_id']); 
    75         } 
    76     } 
     67        if ($this->Glossary->save($this->data)): 
     68            $this->msgFlash(__('Data saved', true),'/admin/catglossaries/items/'.$this->data['Glossary']['catglossary_id']); 
     69    endif; 
     70    endif; 
    7771 } 
    7872 
     
    8074 { 
    8175    $this->layout = 'admin'; 
    82      
    83     if (!empty($this->data['Glossary'])) 
    84     { 
     76       
     77    if (!empty($this->data['Glossary'])): 
     78 
    8579        $this->Sanitize = new Sanitize; 
    8680         
    8781        $this->Sanitize->clean($this->data['Glossary']);  
    8882         
    89     $this->data["Glossary"]["user_id"] = $this->Auth->user('id'); 
     83    $this->data['Glossary']['user_id'] = (int) $this->Auth->user('id'); 
    9084           
    91     $this->Glossary->create(); 
    92            
    93         if ($this->Glossary->save($this->data["Glossary"])) 
    94     { 
    95            $this->msgFlash('Item has been saved.','/admin/catglossaries/items/'.$this->data["Glossary"]["catglossary_id"]); 
    96      } 
    97      } 
     85        if ($this->Glossary->save($this->data)): 
     86           $this->msgFlash(__('Data saved', true),'/admin/catglossaries/items/'.$this->data['Glossary']['catglossary_id']); 
     87    endif;  
     88    endif; 
    9889 } 
    9990    
    100  public function admin_delete($id, $catglossary_id) 
     91 public function admin_delete($glossary_id, $catglossary_id) 
    10192 { 
    102     $this->Glossary->del($id); 
    103     $this->msgFlash('Glossary has been deleted.', '/admin/catglossaries/items/'.$catglossary_id); 
    104  } 
     93   if ( $this->Glossary->del($glossary_id) ): 
     94       $this->msgFlash(__('Data removed', true), '/admin/catglossaries/items/'.$catglossary_id); 
     95   endif; 
     96 }  
    10597} 
    10698?>