Changeset 333

Show
Ignore:
Timestamp:
03/23/08 20:16:44 (10 months ago)
Author:
aarkerio
Message:

Forums fixes

Location:
trunk/app
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/app_controller.php

    r331 r333  
    1717     $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login'); 
    1818     $this->Auth->loginRedirect = array('controller' => 'news', 'action' => 'display'); 
    19      $this->Auth->logoutRedirect = '/'; 
     19     $this->Auth->logoutRedirect = '/news/display'; 
    2020     $this->Auth->loginError = 'Invalid e-mail / password combination. Please try again'; 
    2121     $this->Auth->authorize = 'controller';   
  • trunk/app/config/core.php

    r330 r333  
    7575 * 
    7676 */ 
    77     Configure::write('Session.save', 'cake'); 
     77    Configure::write('Session.save', 'database'); 
    7878/** 
    7979 * The name of the table used to store CakePHP database sessions. 
     
    120120 * 'Security.level' is set to 'high'. 
    121121 */ 
    122     Configure::write('Security.level', 'low'); 
     122    Configure::write('Security.level', 'medium'); 
    123123/** 
    124124 * A random string used in security hashing methods. 
  • trunk/app/config/sql/karamelo_postgres.sql

    r331 r333  
    237237 status int NOT NULL DEFAULT 1 
    238238); 
     239 
     240CREATE TABLE visitors ( --save user id visitors on topics  
     241  id serial PRIMARY KEY, 
     242  user_id   int NOT NULL REFERENCES users(id) ON DELETE CASCADE, 
     243  topic_id int NOT NULL REFERENCES topics(id) ON DELETE CASCADE, 
     244  UNIQUE (user_id, topic_id)  -- constraint 
     245);  
     246 
    239247-- ** Forums tables ends ** 
    240248 
  • trunk/app/controllers/forums_controller.php

    r331 r333  
    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  
     
    3535         
    3636        $this->pageTitle = $data['Catforum']['title'] . ' Forum'; 
    37         //die(debug($data)); 
     37         
    3838        $this->set('data', $data); 
    3939         
    40         $this->layout    = $this->Edublog->layout($data['Forum']['user_id']); 
     40        $this->layout    = $this->Edublog->layout($data['Forum']['user_id']); 
    4141         
    4242        $this->Edublog->blog($data['Forum']['user_id']); // blogger elements 
    4343 } 
    4444  
    45  public function discussion($user_id, $forum_id, $topic_id)  
     45 public function discussion($user_id, $forum_id, $topic_id) 
    4646 {       
    4747        $conditions = array("Topic.id = $topic_id OR Topic.topic_id=$topic_id"); 
     
    4949        $fields     = null; //array("Forum.title", "Forum.id", "Forum.user_id", "Forum.description", "Forum.catforum_id"); 
    5050  
    51         $this->Forum->Topic->User->unbindModel(array('belongsTo'=>array('Group'),'hasMany'=>array('Lesson', 'Entry', 'Comment', 'Bookmark', 'Podcast', 'Quote', 'Test', 'Webquest', 'Ecourse', 'Vclassroom', 'Acquaintance','Confirm'))); 
     51        $this->Forum->Topic->User->unbindModel($this->Forum->User->notNow); 
    5252         
    5353        $data = $this->Forum->Topic->findAll($conditions, $fields); 
    54         //die(debug($data)); 
     54         
    5555        $this->pageTitle = $data[0]['Forum']['title'] . ' Forum'; 
    5656         
    5757        $this->set('data', $data); 
    5858         
    59         $this->layout    = $this->Edublog->layout($user_id); 
     59    $this->layout    = $this->Edublog->layout($user_id); 
    6060         
    6161        $this->Edublog->blog($user_id); // blogger elements 
     
    7474        $this->set('data', $this->Forum->find($conditions, $fields, null, 2)); 
    7575         
    76         $this->layout    = $this->Edublog->layout($user_id); 
     76    $this->layout    = $this->Edublog->layout($user_id); 
    7777         
    7878        $this->Edublog->blog($user_id); // blogger elements 
  • trunk/app/controllers/replies_controller.php

    r326 r333  
    6464 **/ 
    6565  
    66  public function admin_listing() 
    67  { 
    68         $this->layout = 'admin'; 
    69         $this->pageTitle = 'Forums'; 
    70          
    71         $conditions = array("user_id"=>$this->Auth->user('id')); 
    72         $fields     = array("id", "title", "description", "status"); 
    73          
    74         $this->set('data', $this->Reply->findAll($conditions, $fields));      
    75  } 
    76   
    7766 public function admin_edit($id = null) 
    7867 { 
     
    8776        if ($this->Reply->save($this->data['Reply'])) 
    8877        { 
    89             $this->flash('Your virtual classroom  has been updated.','/vclassrooms'); 
     78            $this->flash('Reply updated.','/admin/topics/listing/'.$topic_id); 
    9079        } 
    9180    } 
     
    9382 
    9483 // change status published/draft 
    95  public function admin_change($id, $status, $forum_id) 
     84 public function admin_change($topic_id, $status, $reply_id) 
    9685 {   
    97    //   die(' el intvade del status es '. intval($status)); 
    98     if ( !intval($id) ||  !is_numeric($status)  ||  !intval($forum_id) ) 
    99     {  
    100       $this->redirect('/'); 
    101     } 
    102      
    10386    $this->data['Reply']['status'] = ($status == 0 ) ? 1 : 0; 
    10487      
    105     $this->data['Reply']['id']     = $id; 
     88    $this->data['Reply']['id']     = $reply_id; 
    10689      
    10790    if ($this->Reply->save($this->data['Reply'])) 
    10891    { 
    109        $this->msgFlash('Reply status changed', '/admin/forums/topics/'.$forum_id); 
     92       $this->msgFlash('Reply status changed', '/admin/topics/listing/'.$topic_id); 
    11093    } 
    11194 } 
    11295 
    113  public function admin_delete($topic_id, $forum_id) 
     96 public function admin_delete($topic_id, $reply_id) 
    11497 { 
    115      if ( $this->Reply->del($topic_id) ) 
     98     if ( $this->Reply->del($reply_id) ) 
    11699     { 
    117         $this->msgFlash('','/admin/forums/topics/'.$forum_id); 
     100        $this->msgFlash('Reply deleted','/admin/topics/listing/'.$topic_id); 
    118101     } 
    119  }   
     102 } 
    120103} 
  • trunk/app/controllers/topics_controller.php

    r331 r333  
    2828 public function display($user_id, $forum_id, $topic_id) 
    2929 {   
    30      $this->pageTitle = 'Discussion'; 
     30   $this->pageTitle = 'Discussion'; 
    3131      
    32      $this->layout    = $this->Edublog->layout($user_id); 
     32   $this->layout    = $this->Edublog->layout($user_id); 
    3333      
    34      $this->Edublog->blog($user_id); 
     34   $this->Edublog->blog($user_id); 
    3535      
    36      $conditions = array("Topic.status"=>1, "Topic.id"=>$topic_id); 
    37      $fields     = null; 
    38      $order      = "Topic.created DESC"; 
     36   $conditions = array("Topic.status"=>1, "Topic.id"=>$topic_id); 
     37   $fields     = null; 
     38   $order      = "Topic.created DESC"; 
    3939      
    40      $this->Topic->User->unbindModel(array('hasMany'=>array('Category', 'Faq', 'Lesson', 'Entry', 'Acquaintance', 'Vclassroom'))); 
    41      $this->Topic->Forum->unbindModel(array('hasMany'=>array('Topic'))); 
    42      $this->set('data', $this->Topic->find($conditions, $fields, $order, 2)); 
     40   $this->Topic->User->unbindModel(array('hasMany'=>array('Category', 'Faq', 'Lesson', 'Entry', 'Acquaintance', 'Vclassroom'))); 
     41   $this->Topic->Forum->unbindModel(array('hasMany'=>array('Topic'))); 
     42   $data =  $this->Topic->find($conditions, $fields, $order, 2); 
     43   $this->set('data',$data); 
     44 
     45   if ( $this->Auth->user('id') ) 
     46   {  
     47        $this->Topic->addVisitor($data['Visitor'],  $this->Auth->user('id'), $data['Topic']['id']); 
     48   } 
    4349 } 
    4450   
  • trunk/app/controllers/users_controller.php

    r330 r333  
    302302 public function logout()  
    303303 { 
    304      $this->Session->setFlash("You've successfully logged out."); 
    305      $this->redirect($this->Auth->logout()); 
    306  } 
    307  public function admin_login()  
    308  { 
    309     $this->redirect('/users/login');  
    310  } 
     304   $this->Cookie->del('User'); 
     305    
     306   $this->Session->setFlash('Logout'); 
     307 
     308   $this->redirect($this->Auth->logout()); 
     309 } 
     310 
    311311 public function register() 
    312312 { 
     
    445445  } 
    446446   
    447  /** === ADMIN SECTION ==***/ 
    448     /*** 
    449     ===== ADMIN METHODS==== 
    450     ****/ 
    451     public function admin_edit()  
    452     { 
     447 /***    ===== ADMIN METHODS====   ****/ 
     448 public function admin_login()  
     449 { 
     450    $this->redirect('/users/login');  
     451 } 
     452 
     453 public function admin_edit()  
     454 { 
    453455     
    454456    $this->layout    = 'admin'; 
  • trunk/app/models/topic.php

    r326 r333  
    2222                                     array('className'  => 'Reply',  
    2323                                           'foreignkey' => 'topic_id', 
    24                                            'order'      => 'created ASC' 
    25                                            )); 
    26                                             
    27  public $validate = array( 
     24                           'order'      => 'created ASC' 
     25                       ), 
     26                         'Visitor' =>  
     27                                     array('className'  => 'Visitor',  
     28                                           'foreignkey' => 'topic_id', 
     29                           'order'      => null 
     30                       ), 
     31      ); 
     32  /* public $hasAndBelongsToMany = array( 
     33        'Topic' => 
     34    array('className'            => 'Topic', 
     35          'joinTable'              => 'topics_users', 
     36          'foreignKey'             => 'topic_id', 
     37          'associationForeignKey'  => 'user_id', 
     38          'conditions'             => '', 
     39          'order'                  => '', 
     40          'limit'                  => '', 
     41          'uniq'                   => true, 
     42          'finderQuery'              => '', 
     43          'deleteQuery'            => '', 
     44                'insertQuery'             => '' 
     45          ) 
     46        ); */ 
     47 
     48  public function addVisitor($users = array(), $user_id, $topic_id)   
     49  { // this is just to set a flag to indicate user is visiting topic for first time 
     50     
     51    $ids = array(); 
     52    //die(var_dump( $users  )); 
     53    foreach ($users as $v) 
     54    {  
     55       array_push($ids, $v['id']); 
     56    } 
     57     
     58    if ( in_array($user_id, $ids) ) 
     59    { 
     60      return false; 
     61    } 
     62    else 
     63    { 
     64        $this->data['Visitor']['topic_id'] = $topic_id;  
     65        $this->data['Visitor']['user_id']  = $user_id; 
     66        $this->Visitor->create(); 
     67 
     68        if ( $this->Visitor->save( $this->data['Visitor'] ) ) 
     69        { 
     70          return true; 
     71        } 
     72        else 
     73        { 
     74          die('Error on addVisitor function'); 
     75        } 
     76    } 
     77    return true; 
     78  } 
     79 
     80  public $validate = array( 
    2881      'subject' => VALID_NOT_EMPTY, 
    2982      'message' => VALID_NOT_EMPTY, 
  • trunk/app/views/forums/display.ctp

    r327 r333  
    11<?php 
    2 //die(print_r($data)); 
     2//die(debug($data)); 
    33echo $html->para(null,  
    44                 'Foro: '.$html->link($data["Catforum"]["title"],  
     
    77               ); 
    88 
    9  echo '<div style="padding:6px;border:1px dotted gray;margin:15px 0 15px 0">'; 
    10    echo '<div style="padding:6px;border:1px solid orange;font-size:17pt;color:orange;font-weight:bold">'.$data["Forum"]["title"].'</div>'; 
    11     echo '<span ="font-size:pt">'. $data["Forum"]["description"] . "</span>";        
    12     echo '<div style="width:100px;margin-top:15px">'; 
     9    echo  $html->div('titentry', $data["Forum"]["title"]); 
     10    echo  $html->para(null, $data["Forum"]["description"]); 
    1311 
    14     echo $html->div('space',  
     12    echo $html->div(null,  
    1513                    $html->link($html->image('static/new_post.gif', array("alt"=>"Add new topic", "title"=>"Add new topic")),  
    1614                      '/topics/add/'.$blog["User"]["username"].'/'.$data["Forum"]["id"],  
     
    1816              ); 
    1917   
    20           
    2118    //Topics 
    2219    echo '<table style="border-collapse:collapse;width:100%">'; 
     
    3431      foreach ($data["Topic"] as $val) 
    3532      { 
    36          $tr = array ( 
     33         
     34       $tr = array ( 
    3735         $html->image('static/folder.gif'),  
    3836         $html->link($val['subject'], '/topics/display/'.$data['Forum']['user_id'].'/'.$val['forum_id'].'/'.$val['id']), 
    39                    count($data["Topic"]), 
     37                   count($val['Reply']), 
    4038                   $val["User"]["username"], 
    4139                   $val['views'], 
     
    4947               
    5048       echo '</table>';  
    51        echo '</div>'; 
    52   
    53   
    54  echo '<div style="text-align:center;width:50%;padding:6px">'; 
    5549  
    5650 if ( ! isset( $cU ) )  
    5751 { 
    58             echo $this->renderElement('login'); 
     52         echo $html->div(null, $this->renderElement('login')); 
    5953 } 
    60  echo '</div>'; 
     54 
     55echo $html->para(null, 'Leyenda del Tema'); 
     56 
     57$tmp  = $html->image('static/board.gif', array("alt"=>"Tema normal", "title"=>"Tema normal")) . ' Tema normal <br />'; 
     58$tmp .= $html->image('static/locked.gif', array("alt"=>"Tema bloqueado", "title"=>"Tema bloqueado")) . ' Tema bloqueado<br />'; 
     59$tmp .= $html->image('static/new.gif', array("alt"=>"Comentario nuevo", "title"=>"Comentario nuevo")). ' Comentario nuevo<br />'; 
     60 
     61echo $html->para(null, $tmp); 
    6162?> 
    62  
    63 <p style="padding:3px;border:1px dotted gray;font-size:9pt;font-weight:bold">Leyenda del Tema:</p> 
    64 <p>  
    65 <?php echo $html->image('static/board.gif', array("alt"=>"Tema normal", "title"=>"Tema normal")); ?>    Tema normal<br /> 
    66 <?php echo $html->image('static/locked.gif', array("alt"=>"Tema bloqueado", "title"=>"Tema bloqueado")); ?>       Tema bloqueado<br /> 
    67 <?php echo $html->image('static/new.gif', array("alt"=>"Comentario nuevo", "title"=>"Comentario nuevo")); ?>      Comentario nuevo<br /> 
    68 </p> 
  • trunk/app/views/lessons/admin_add.ctp

    r312 r333  
    11<?php 
    2 echo $javascript->link('myfunctions'); 
    3 echo $javascript->link('fckeditor/fckeditor');  
     2 echo $javascript->link('myfunctions'); 
     3 echo $javascript->link('fckeditor/fckeditor');  
     4 echo $form->create('Lesson');  
    45?> 
    56 
    6 <?php echo $html->formTag('/admin/lessons/add/','post'); ?> 
    77<fieldset> 
    88<legend>Add Lesson</legend> 
    99<table> 
    1010<tr><td> 
    11   <?php  
    12      echo $form->labelTag( 'Lesson/title', 'Title:' ); 
    13      echo $html->input('Lesson/title', array("size" => 50, "maxlength" => 120, "class"=>"formas")); 
    14      echo $html->tagErrorMsg('Lesson/title', 'Title is required.');  
     11  <?php 
     12     echo $form->input('Lesson.title', array("size" => 50, "maxlength" => 120)); 
     13     echo $form->error('Lesson.title', 'Title is required.');  
    1514  ?> 
    1615  </td> 
     
    2221  <td colspan="2"> 
    2322  <?php  
    24       echo $form->labelTag( 'Lesson/body', 'Body:' ); 
    25       echo $html->textarea('Lesson/body', array("class"=>"formas", "cols"=>80, "rows"=>45)); 
    26       echo $fck->load('Lesson/body', 'Karamelo'); 
    27       echo $html->tagErrorMsg('Lesson/body', 'Body is required.');  
     23      echo $form->label('Lesson.body', 'Body:' ); 
     24      echo $form->textarea('Lesson.body', array("cols"=>80, "rows"=>45)); 
     25      echo $fck->load('LessonBody', 'Karamelo'); 
     26      echo $form->error('Lesson.body', 'Body is required.');  
    2827  ?> 
    2928  </td></tr> 
    3029  <tr><td> 
    3130  <?php  
    32      echo $form->labelTag( 'Lesson/status', 'Published:' ); 
    33      echo $html->checkbox('Lesson/status');  
     31     echo $form->label('Lesson.status', 'Published:' ); 
     32     echo $form->checkbox('Lesson.status', array('value'=>1));  
    3433  ?> 
    3534  </td><td> 
    36   <?php  
    37       echo $form->labelTag( 'Lesson/disc', 'Comments allowed to this Lesson:' ); 
    38       echo $html->checkbox('Lesson/disc');  
     35  <?Php  
     36      Echo $form->label('Lesson.disc', 'Comments allowed to this Lesson:' ); 
     37      echo $form->checkbox('Lesson.disc', array('value'=>1));  
    3938  ?> 
    4039  </td></tr> 
    41   <tr><td colspan="2">  
    42   <?php echo $html->submit('Save'); ?> 
     40  <tr><td colspan="2"> </fieldset> 
     41  <?php echo $form->end('Save'); ?> 
    4342</td></tr> 
    4443</table> 
    45 </fieldset> 
    46 </form> 
  • trunk/app/views/topics/admin_listing.ctp

    r331 r333  
    77{ 
    88   $st  = ($val['status'] == 1) ? 'Published' : 'Hidden'; 
    9    $stl = $html->link($st, '/admin/replies/change/'.$val['id'].'/'.$val['status']); 
     9   $stl = $html->link($st, '/admin/replies/change/'.$val['topic_id'].'/'.$val['status'].'/'.$val['id']); 
    1010   $tmp  = $val['User']['username'] . $html->image('avatars/'.$val['User']['avatar'], array('alt'=>$val['User']['username'], 'title'=>$val['User']['username'])); 
    1111   $tmp .= $html->para(null, $val['reply']); 
    1212   $tmp .= $html->para('news_date', $val['created']); 
    13    $tmp .= $html->link('Delete', '/admin/replies/delete/'.$val['id']) . ' ' . $stl . ' '. $html->link('Edit', '/admin/replies/edit/'.$val['id']); 
     13   $tmp .= $html->link('Delete', '/admin/replies/delete/'.$val['topic_id'].'/'.$val['id']).'  '; 
     14   $tmp .= $stl. ' '. $html->link('Edit', '/admin/replies/edit/'.$val['id']); 
    1415   echo $html->div('adminblock', $tmp); 
    1516}