Show
Ignore:
Timestamp:
03/25/08 01:03:27 (8 months ago)
Author:
aarkerio
Message:

eCourses fixes

Files:
1 modified

Legend:

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

    r331 r342  
    33*  Chipotle Software TM 
    44*  Manuel Montoya 2002-2008  
    5 *  GPLv3 manuel<arroba>mononeurona<punto>org ASMO 
     5*  GPLv3 manuel<arroba>mononeurona<punto>org 
    66*/  
    77 
     
    1212 public $helpers       = array('Javascript', 'Ajax', 'Fck', 'Time'); 
    1313  
    14  public $components    = array('Portal', 'Security', 'Email', 'Session'); 
    15   
     14 public $components    = array('Portal', 'Security', 'Email', 'Session', 'Edublog'); 
     15  
     16  public function beforeFilter()  
     17 { 
     18    $this->Auth->allow(array('message', 'deliver')); 
     19    parent::beforeFilter(); 
     20 } 
     21 
    1622 public function isAuthorized()  
    1723 {   
     
    2531    return false;  // go away !! 
    2632 } 
    27     
    28  public function show($username, $id) 
    29  {    
    30         $this->pageTitle = 'Classrooms'; 
    31         $this->layout    = 'berlin'; //$this->Blog->field; 
    32          
    33         $conditions      = array("Subject.status"=>1, "Subject.id"=>$id); 
    34         $fields          = array("Subject.id", "Subject.name", "Subject.program_id", "Subject.created"); 
    35         $order           = "Subject.name DESC"; 
    36          
    37         $this->set('blog', $this->Edublog->blog($username)); 
    38          
    39         $this->set('data', $this->Message->findAll($conditions, $fields, $order, null, null, 2, 2)); 
    40    } 
    41     
    42    public function message($user_id)  
    43    {     
     33  
     34 public function message($username) // show form to send message to teacher 
     35 {       
    4436        $this->pageTitle = 'Contact'; 
    4537         
     38        $user_id = $this->Message->User->field('id', array('username'=>$username)); 
     39         
    4640        $this->layout    = $this->Edublog->layout($user_id); 
    4741         
    48         $this->set('blog', $this->Edublog->blog($user_id)); 
    49          
    50         $this->set('user_id', $user_id);  
    51    } 
    52      
    53    public function contact() 
    54    { 
     42        $this->Edublog->blog($user_id); 
     43 } 
     44  
     45 public function contact() 
     46 { 
    5547        $this->layout    = 'portal'; 
    5648         
    5749        $this->pageTitle = 'Contact'; 
    5850         
    59         $this->set('Element', $this->Portal->statics());      // Using Portal component 
    60    } 
    61     
    62    public function compose() 
    63    {     
     51        $this->Portal->statics();      // Using Portal component 
     52 } 
     53  
     54 public function compose() 
     55 {     
    6456        $this->layout    = 'portal'; 
    6557         
    6658        $this->pageTitle = 'Write Message'; 
    6759         
    68         $this->set('Element', $this->Portal->statics());      // Using Portal component 
    69    } 
    70     
    71    public function search() 
    72    {     
    73         $this->layout    = 'ajax'; 
    74          
    75         $this->pageTitle = 'Write Message'; 
    76          
    77         $conditions      = array("User.username ~* '".'ad' ."'"); 
    78          
    79         $fields          = array("User.username", "User.id"); 
    80          
    81         $order           = "User.username"; 
    82          
    83         $this->Message->User->unbindModel($this->Message->User->notNow); 
    84          
    85         $limit = 15; 
    86          
    87         $this->set('data', $this->Message->User->findAll($conditions, $fields, $order, $limit));  
    88          
    89         $this->render('search', 'ajax'); 
    90    } 
    91     
    92    public function chat($nick='mononeuron') 
    93    { 
     60        $this->Portal->statics();      // Using Portal component 
     61 } 
     62  
     63 public function chat($nick='mononeuron') 
     64 { 
    9465      $this->pageTitle = 'IRC Chat'; 
    9566       
     
    9768       
    9869      $this->set('nick', $nick); 
    99    } 
    100     
    101    public function deliver() 
    102    { 
     70 } 
     71  
     72 public function deliver() 
     73 { 
    10374    $this->layout = 'ajax'; 
    10475     
    105      if (!empty($this->data["Message"])) 
    106      { 
     76    if (!empty($this->data["Message"])) 
     77    { 
    10778           $this->Sanitize = new Sanitize; 
    10879            
     
    12394                else 
    12495                { 
    125                     $this->render('send', 'ajax'); 
     96                    $this->render('sent', 'ajax'); 
    12697                } 
    12798        } 
    12899     } 
    129    } 
    130  
    131  /**=== ADMIN METHODS ===**/   
    132  public function admin_general() 
    133  { 
    134    if ($this->Auth->user('group_id') != 1) 
    135    { 
    136         $this->redirect('/admin/messages/listing'); 
    137    } 
    138      
    139    $this->layout = 'admin'; 
    140      
    141    if (!empty($this->data["Message"])) 
    142    { 
    143      $this->Sanitize = new Sanitize; 
    144          
    145      $this->Sanitize->html($this->data["Message"]["title"]); 
    146          
    147      $this->Sanitize->html($this->data["Message"]["body"]); 
    148          
    149      $this->Message->User->unbindModel( 
    150                                  array( 
    151                                        "hasMany"=>array( 
    152                                                         "Entry", "News", "Category", "Lesson", "Podcast", "Bookmark"))); 
    153          
    154         $conditions = array("active"=>1); 
    155          
    156         $fields     = array("id"); 
    157          
    158         $data = $this->User->findAll($conditions, $fields); 
    159          
    160         $j = 0; //counter 
    161          
    162         $this->data["Message"]["sender_id"] = $this->Auth->user('id'); 
    163          
    164         //exit(print_r($data)); 
    165          
    166         foreach($data as $val) 
    167         {  
    168           $this->Message->create(); 
    169            
    170           //exit(print_r($val)); 
    171            
    172           $this->data["Message"]["user_id"] = $val["User"]["id"]; 
    173            
    174           if ($this->Message->save($this->data["Message"])) 
    175           { 
    176              $j++; 
    177           } 
    178           else 
    179           { 
    180              exit('error on save'); 
    181           } 
    182         } 
    183         $this->msgFlash($j . ' messages sent', '/admin/messages/listing'); 
    184       } 
    185     } 
    186     
    187    private function sendMail($user_id, $username, $title)  
     100 } 
     101  private function sendMail($user_id, $username, $title)  
    188102   { 
    189103        $this->User = new User; 
     
    218132            exit("Error!!"); 
    219133        } 
    220  }   
    221  
     134 } 
     135  
     136 /**=== ADMIN METHODS ===**/   
     137 public function admin_general()  // send a general message to all commnunity 
     138 { 
     139   if ($this->Auth->user('group_id') != 1) 
     140   { 
     141        $this->redirect('/admin/messages/listing'); 
     142   } 
     143     
     144   $this->layout = 'admin'; 
     145     
     146   if (!empty($this->data["Message"])) 
     147   { 
     148     $this->Sanitize = new Sanitize; 
     149         
     150     $this->Sanitize->html($this->data["Message"]["title"]); 
     151         
     152     $this->Sanitize->html($this->data["Message"]["body"]); 
     153         
     154     $this->Message->User->unbindModel( 
     155                                 array( 
     156                                       "hasMany"=>array( 
     157                                                        "Entry", "News", "Category", "Lesson", "Podcast", "Bookmark"))); 
     158         
     159        $conditions = array("active"=>1); 
     160         
     161        $fields     = array("id"); 
     162         
     163        $data = $this->User->findAll($conditions, $fields); 
     164         
     165        $j = 0; //counter 
     166         
     167        $this->data["Message"]["sender_id"] = $this->Auth->user('id'); 
     168         
     169        //exit(print_r($data)); 
     170         
     171        foreach($data as $val) 
     172        {  
     173          $this->Message->create(); 
     174           
     175          //exit(print_r($val)); 
     176           
     177          $this->data["Message"]["user_id"] = $val["User"]["id"]; 
     178           
     179          if ($this->Message->save($this->data["Message"])) 
     180          { 
     181             $j++; 
     182          } 
     183          else 
     184          { 
     185             exit('error on save'); 
     186          } 
     187        } 
     188        $this->msgFlash($j . ' messages sent', '/admin/messages/listing'); 
     189      } 
     190 } 
     191  
    222192 public function admin_change($message_id, $message_status) 
    223193 {