Changeset 342

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

eCourses fixes

Location:
trunk/app
Files:
7 added
21 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/config/sql/karamelo_postgres.sql

    r340 r342  
    2222    modified timestamp(0) with time zone DEFAULT now() NOT NULL, 
    2323    code varchar(7) NOT NULL DEFAULT 'f78Z67', 
     24    active smallint NOT NULL DEFAULT 1,  -- active/desactive group 
    2425    CHECK ( length(code)  > 6  ) 
    2526); 
  • trunk/app/controllers/ecourses_controller.php

    r340 r342  
    3636       $this->layout = 'admin'; 
    3737        
    38              
    3938       $conditions   =  array("user_id"=>$this->Auth->user('id')); 
    4039       $fields       =  array('id', 'title', 'access',  'status', 'description'); 
    4140       $order        =  "Ecourse.title DESC"; 
    42              
     41        
    4342       $this->set('data', $this->Ecourse->findAll($conditions, $fields, $order)); 
    4443  } 
     
    6766        $this->set('data', $this->Ecourse->find($conditions, $fields)); 
    6867  } 
    69   
    70   public function admin_add()  
    71   {    
    72     $this->layout    = 'admin';  
    73      
    74     if (!empty($this->data['Ecourse'])) 
    75     { 
    76         $this->Sanitize = new Sanitize; 
    77          
    78         $this->Sanitize->clean($this->data["Ecourse"]); 
    79    
    80         $this->data['Ecourse']['user_id'] = $this->Auth->user('id'); 
    81  
    82         $this->Ecourse->create(); 
    83     
    84         if ($this->Ecourse->save($this->data['Ecourse'])) 
    85         { 
    86                 $this->msgFlash('Course saved', '/admin/ecourses/listing'); 
    87         } 
    88     } 
    89     else 
    90     { 
    91   
    92      $this->set('subjects', Set::combine($this->Ecourse->Subject->find('all', array('order' => 'title')), "{n}.Subject.id","{n}.Subject.title")); 
    93  
    94      $this->set('langs', Set::combine($this->Ecourse->Lang->find('all', array('order' => 'lang')), "{n}.Lang.id","{n}.Lang.lang")); 
    95  
    96     } 
    97   } 
    9868   
    9969  public function admin_change($id, $status) 
     
    11282        } 
    11383    } 
     84  public function admin_add()  
     85  {    
     86    $this->layout    = 'admin';  
     87     
     88    $this->set('subjects', Set::combine($this->Ecourse->Subject->find('all', array('order' => 'title')), "{n}.Subject.id","{n}.Subject.title")); 
     89     
     90    $this->set('langs', Set::combine($this->Ecourse->Lang->find('all', array('order' => 'lang')), "{n}.Lang.id","{n}.Lang.lang")); 
     91     
     92    if (!empty($this->data['Ecourse'])) 
     93    { 
     94        $this->Sanitize = new Sanitize; 
     95         
     96        $this->Sanitize->clean($this->data["Ecourse"]); 
     97         
     98        $this->data['Ecourse']['user_id'] = $this->Auth->user('id'); 
     99         
     100        $this->Ecourse->create(); 
     101         
     102        if ($this->Ecourse->save($this->data['Ecourse'])) 
     103        { 
     104                $this->msgFlash('Course saved', '/admin/ecourses/listing'); 
     105        } 
     106    } 
     107  } 
    114108   
    115109  public function admin_edit($id = null) 
    116110  { 
    117       
    118     if (empty($this->data['Ecourse'])) 
     111    $this->set('subjects', Set::combine($this->Ecourse->Subject->find('all', array('order' => 'title')), "{n}.Subject.id","{n}.Subject.title")); 
     112     
     113    $this->set('langs', Set::combine($this->Ecourse->Lang->find('all', array('order' => 'lang')), "{n}.Lang.id","{n}.Lang.lang")); 
     114     
     115    if ( empty($this->data['Ecourse']) ) 
    119116    { 
    120117        $this->layout = 'admin'; 
     
    124121        $this->Subject     = new Subject; 
    125122         
    126         $this->set('subjects', $this->Ecourse->Subject->generateList(null, 'title'));        
    127      
    128         $this->set('langs', $this->Ecourse->Lang->generateList(null, 'lang', null, '{n}.Lang.id', '{n}.Lang.lang')); 
    129          
    130123        $this->data = $this->Ecourse->read(); 
     124         
    131125    } 
    132126    else 
     
    135129         
    136130        $this->Sanitize->html($this->data["Ecourse"]['description']); 
    137  
     131         
    138132        if ($this->Ecourse->save($this->data['Ecourse'])) 
    139133        { 
  • 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 { 
  • trunk/app/controllers/users_controller.php

    r339 r342  
    5555      
    5656     $limit      = 20; 
    57          
     57      
    5858     $this->set('data', $this->User->Entry->findAll($conditions, $fields, $order, $limit));  
    59          
     59      
    6060     $this->layout    = $this->Edublog->layout($user_id); 
    61          
     61      
    6262     $this->Edublog->blog($user_id); 
    6363 } 
     
    393393 public function admin_edit()  
    394394 { 
    395      
    396     $this->layout    = 'admin'; 
    397      
    398     $this->set('Groups', $this->User->Group->generateList());        
    399      
    400     if (empty($this->data)) 
    401     { 
    402         $this->User->id = $this->Auth->user('id'); 
    403         $this->data = $this->User->read(); 
     395    if ( empty($this->data['User']) ) 
     396    { 
     397        $this->layout    = 'admin'; 
     398         
     399        $this->set('Groups', Set::combine($this->User->Group->find('all', array('order' => 'name')), "{n}.Group.id","{n}.Group.name")); 
     400         
     401        $this->User->unbindModel($this->User->notNow); 
     402             
     403        $this->data = $this->User->read(null, $this->Auth->user('id')); 
    404404    } 
    405405    else 
     
    480480     } 
    481481 } 
    482  
    483   /*** DELETE  **/  
    484   public function delete($id) 
    485   { 
    486     $this->User->del($id); 
    487     $this->msgFlash('User has been deleted.', '/admin/users/listing'); 
    488   } 
    489    
    490   /*** List user's blog entries  **/  
    491   public function blogs($order = null) 
    492   { 
    493    
    494     $conditions = array("active" => 1 ); 
    495      
    496     $data = $this->User->findAll($conditions, $order); 
    497      
    498     $this->set('data', $data); 
    499     
    500   } 
    501  
     482  
     483 /*** DELETE  **/  
     484 public function admin_delete($id) 
     485 { 
     486    if ($this->User->del($id)) 
     487    { 
     488       $this->msgFlash('User has been deleted.', '/admin/users/listing'); 
     489    } 
     490 } 
     491  
    502492 /****   AVATAR   ***/ 
    503493 public function admin_avatar()  
     
    573563    } 
    574564         
    575     $extension   = $this->get_extension($type); 
     565    $extension   = $this->Adds->get_extension($type); 
    576566     
    577567    $Name        = $this->Auth->user('username') . "_avatar" . $extension; 
     
    607597    
    608598   } 
    609 } 
    610  
    611 public function admin_delete($id) 
    612 { 
    613     if ( $this->User->del($id) ) 
    614     { 
    615         $this->msgFlash('User has been deleted','/admin/users/listing'); 
    616     } 
    617599} 
    618600 
  • trunk/app/models/ecourse.php

    r282 r342  
    33*  Karamelo E-Learning Platform 
    44*  Chipotle Software 2002-2008 
    5 *  GPLv3 manuel<at>mononeurona<dot>org 
     5*  GPLv3 manuel<arroba>mononeurona<punto>org 
    66*/ 
    77//File: /app/models/ecourse.php 
    88 
    99class Ecourse extends AppModel { 
    10  
     10   
    1111  public $name = 'Ecourse'; 
    12     
     12   
    1313  public $belongsTo = array('User', 'Subject', 'Lang'); 
    14  
     14   
    1515  public $hasMany   = array('Vclassroom'); 
    16  
     16   
    1717  public $validate = array( 
    18         'title'       => VALID_NOT_EMPTY, 
    19         'access'      => VALID_NOT_EMPTY, 
    20             'description' => VALID_NOT_EMPTY,  
    21         'lang_id'     => VALID_NOT_EMPTY 
    22       ); 
     18        'title' => array( 
     19            'alphanumeric' => array( 
     20                'rule' => array('minLength', 4), 
     21                'required' => true, 
     22                'allowEmpty' => false, 
     23                'message' => 'Mimimum 4 characters long in title' 
     24                ) 
     25        ), 
     26        'description' => array( 
     27            'rule' => array('minLength', 20), 
     28            'allowEmpty' => false, 
     29            'message' => 'Mimimum 8 characters long' 
     30        ), 
     31        'code' => array( 
     32            'rule' => array('minLength', 4), 
     33            'allowEmpty' => false, 
     34            'message' => 'Mimimum 4 characters long' 
     35        ), 
     36        'lang_id' => array( 
     37            'rule' => 'numeric', 
     38            'message' => 'Enter a valid lang', 
     39            'allowEmpty' => true 
     40        ) 
     41    ); 
    2342} 
    2443?> 
  • trunk/app/models/group.php

    r282 r342  
    33*  Chipotle Software TM 
    44*  Manuel Montoya 2002-2008 
    5 *  GPLv3 manuel<at>mononeurona<dot>org 
     5*  GPLv3 manuel<arroba>mononeurona<punto>org 
    66*/ 
    77class Group extends AppModel 
     
    1010 
    1111  public $hasMany = 'User'; 
     12   
     13  public $validate = array( 
     14    'code' => array( 
     15        'required'  => true, 
     16        'rule'      => array('minLength', 5),   
     17        'message'   => 'Code must be at least 5 characters long.'  
     18       ) 
     19  ); 
    1220 
    1321} 
  • trunk/app/models/message.php

    r331 r342  
    33*  Karamelo eLearning Platform 
    44*  Chipotle Software 2002-2008  
    5 *  GPLv3 manuel<arroba>mononeurona<punto>org ASMO 
     5*  GPLv3 manuel<arroba>mononeurona<punto>org 
    66**/  
    77 
  • trunk/app/views/ecourses/admin_add.ctp

    r340 r342  
    1 <?php echo $form->create('Ecourse', array('onsubmit'=>'return chkForm()'));  ?> 
     1<?php  
     2   echo $javascript->link('fckeditor/fckeditor'); 
     3   echo $form->create('Ecourse', array('onsubmit'=>'return chkForm()'));  
     4?> 
    25<fieldset> 
    36  <legend>New Course</legend> 
    4 <p>By default, your course is accessible to everybody. If you want some confidentiality, the simplest way is to open registration during one week, ask the students to register themselves, then close registration and check for possible intruders in the user list.</p> 
    57<?php  
    6  echo $form->input('Ecourse.title', array("size" => 30, "maxlength" => 90)) . ' e.g. History of Literature'; 
    7  echo $form->error('Ecourse.title', 'A FAQ title is required.'); 
     8  
     9 echo $form->input('Ecourse.title', array("size" => 30, "maxlength" => 90, 'title'=>' e.g. History of Literature')); 
    810 
    911 echo $form->label('Ecourse.description', 'Description:'); 
    1012 echo $form->textarea('Ecourse.description', array("cols" => 40, "rows" =>4)); 
    11  
    12  echo $form->input('Ecourse.code', array("size" => 12, "maxlenght" => 12))  . ' max. 12 characters, ie.ROM2121'; 
    13  echo $form->error('Ecourse.code', 'A category description is required.'); 
     13 echo $fck->load('EcourseDescription', 'Default'); 
     14 echo $form->error('Ecourse.description', 'You must describe course '); 
     15  
     16 echo $form->input('Ecourse.code', array("size" => 12, "maxlenght" => 12, 'title'=>' max. 12 characters. Example: ROM2121', 'error'=>'Code is required')); 
    1417  
    1518 echo $form->label('Ecourse.subject_id', 'Subject:'); 
     
    1821 echo $form->label('Ecourse.lang_id', 'Lang:'); 
    1922 echo $form->select('Ecourse.lang_id', $langs, null, null, null, false); 
     23  
     24 echo $form->label('Ecourse.status', 'Enabled:' ); 
     25 echo $form->checkbox('Ecourse.status', array("value"=>1, 'title'=>'Enabled course'));  
    2026?> 
    21  
    22   <div style="clear:both"></div> 
     27</fieldset> 
    2328  <br /> 
    2429  <?php echo $form->end('Save'); ?> 
    25 </fieldset> 
    2630 
    2731<script type="text/javascript"> 
  • trunk/app/views/ecourses/admin_edit.ctp

    r340 r342  
    11<?php  
    2 echo $form->create('Ecourse',array("onsubmit"=>"return chkForm();"));  
    3 echo $form->hidden('Ecourse.id'); 
     2