Changeset 246

Show
Ignore:
Timestamp:
02/22/08 13:58:35 (8 months ago)
Author:
aarkerio
Message:

Changes on users and entries

Location:
trunk/app
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/app_controller.php

    r242 r246  
    11<?php 
    2 /** Manuel Montoya GPL v3 */ 
     2/** 
     3*     Karamelo eLearning Platform 
     4*     Chipotle Software 2002-2008 
     5*     GPLv3 manuel<arroba>mononeurona<punto>org 
     6**/ 
    37 
    48class AppController extends Controller { 
     
    1014 public function beforeFilter() 
    1115 { 
    12      $this->Auth->fields = array('username' => 'username', 'password' => 'password'); 
     16     $this->Auth->fields = array('username' => 'username', 'password' => 'pwd'); 
    1317     $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login'); 
    1418     $this->Auth->loginRedirect = array('controller' => 'news', 'action' => 'display'); 
     
    1620     $this->Auth->loginError = 'Invalid e-mail / password combination. Please try again'; 
    1721     $this->Auth->authorize = 'controller';   
    18      $this->Auth->allow( array('display', 'view', 'register', 'recover') ); 
     22     $this->Auth->allow( array('display', 'view', 'register', 'recover', 'sendmail') ); 
    1923 
    20      $this->set('cU', $this->Auth->user());  // $cU current user 
     24     $this->set('cU', $this->Auth->user());  // $cU current user array to use in the views if user logged 
     25 } 
     26 
     27 public function msgFlash($msg, $to) 
     28 { 
     29     $this->Session->setFlash($msg); // http://manual.cakephp.org/chapter/session 
     30          
     31     $this->redirect($to); 
     32        
     33     exit; 
    2134 } 
    2235} 
  • trunk/app/config/core.php

    r242 r246  
    1414 * In development mode, you need to click the flash message to continue. 
    1515 */ 
    16     Configure::write('debug', 1); 
     16    Configure::write('debug', 2); 
    1717/** 
    1818 * Application wide charset encoding 
  • trunk/app/controllers/commentnews_controller.php

    r77 r246  
    11<?php 
    22/**  
    3 Chipotle Software  
    4 GPL v3 
     3*   Chipotle Software 2002-2008 
     4*   GPLv3  manuel<arroba>mononeurona<punto>org  
    55**/ 
    66//File: /app/controllers/comentnews_controller.php 
    77 
    88uses('sanitize'); 
    9 loadModel('News'); 
    10 loadModel('User'); 
    119 
    1210class CommentnewsController extends AppController 
    1311{ 
    14     public $name       = 'Commentnews'; 
     12 public $name       = 'Commentnews'; 
    1513     
    16     public $helpers    = array('Form', 'Javascript', 'Ajax', 'Time', 'Gags'); 
     14 public $helpers    = array('Javascript', 'Ajax', 'Time', 'Gags'); 
    1715     
    18     public $components = array('Security', 'Captcha', 'Email'); 
     16 public $components = array('Security', 'Captcha', 'Email'); 
     17 
     18 public function isAuthorized()  
     19 { 
     20   if ( $this->Auth->user('group') != 1 )  
     21   { 
     22     $this->Auth->deny(array('admin_delete', 'admin_listing', 'admin_edit')); 
     23   } 
     24   if ( $this->Auth->user() ) 
     25   { 
     26     $this->Auth->allow(array('newcomment')); 
     27   } 
     28  return true; 
     29 } 
    1930     
    20  public function add() 
    21  {       
    22         if ( ! empty($this->data["Commentnews"]) ) 
    23          { 
    24            $this->Sanitize = new Sanitize; 
     31 public function newcomment() 
     32 { 
     33   die('sadsadasdsa');   
     34   die(var_dump($this->data)); 
     35 
     36   if ( !empty($this->data["Commentnews"]) ) 
     37   { 
     38     $this->Sanitize = new Sanitize; 
    2539            
    26            $this->Sanitize->cleanArray($this->data); 
     40     $this->Sanitize->cleanArray($this->data); 
    2741            
    28            $this->data["Commentnews"]["comment"] = nl2br($this->data["Commentnews"]["comment"]); 
     42     $this->data["Commentnews"]["comment"] = nl2br($this->data["Commentnews"]["comment"]); 
    2943            
    30            if ( $this->othAuth->user('id') ) 
    31            { 
    32               $this->data["Commentnews"]["user_id"] = $this->othAuth->user('id'); 
    33            } 
    34            else 
    35            { 
    36                if ($this->data["Commentnews"]["captcha"] != $this->Session->read('captcha') || strlen($this->data["Commentnews"]["captcha"]) < 3) 
    37                { 
    38                   $this->flash('Code incorrect, please pulse back button', '/news/display/'.$this->data["Commentnews"]["new_id"], 20);  //    wrong captcha, spambot ?? 
    39                   exit(); 
    40                } 
     44     if ( $this->Auth->user('id') ) 
     45     { 
     46              $this->data["Commentnews"]["user_id"] = $this->Auth->user('id'); 
     47     } 
     48     else 
     49     { 
     50       if ($this->data["Commentnews"]["captcha"] != $this->Session->read('captcha') || strlen($this->data["Commentnews"]["captcha"]) < 3) 
     51       { 
     52         $this->flash('Code incorrect, please pulse back button', '/news/view/'.$this->data["Commentnews"]["new_id"], 6);  // wrong captcha, spambot ?? 
     53         exit(); 
     54       } 
    4155                 
    42                 $this->data["Commentnews"]["user_id"] = 0; 
    43            } 
     56         $this->data["Commentnews"]["user_id"] = 0; 
     57     } 
    4458             
    45           if ( $this->Commentnews->save($this->data["Commentnews"]) ) //save the comment 
    46           { 
    47                 $this->News = new News; 
     59      if ( $this->Commentnews->save($this->data["Commentnews"]) ) //save the comment 
     60      { 
     61          $this->News = new News; 
    4862                 
    49                 $user_id  = $this->News->field('user_id', array("News.id"=>$this->data["Commentnews"]["new_id"])); 
     63          $user_id  = $this->News->field('user_id', array("News.id"=>$this->data["Commentnews"]["new_id"])); 
    5064                 
    51                 $this->sendMail($user_id, $this->data["Commentnews"]["new_id"]); 
     65          $this->sendMail($user_id, $this->data["Commentnews"]["new_id"]); 
    5266                 
    53                 $this->redirect('/news/display/'.$this->data["Commentnews"]["new_id"].'#cnews'); 
    54           } 
     67          $this->redirect('/news/view/'.$this->data["Commentnews"]["new_id"].'#cnews'); 
    5568       } 
     69    } 
    5670 } 
    5771  
     
    7084        $data = $this->User->find(array("User.id"=>$user_id), $fields); 
    7185        //exit($data["User"]["email"]); 
    72         $this->Email->sender    = '::MonoNeurona.org::'; 
     86        $this->Email->sender    = '::Karamelo::'; 
    7387        $this->Email->to        = $data["User"]["email"]; 
    74         $this->Email->subject   = '::MonoNeurona.org:: New comment on your front-page New'; 
     88        $this->Email->subject   = '::Karamelo:: New comment on your front-page New'; 
    7589        $this->Email->sendAs    = 'html'; 
    7690        $this->Email->template  = null; 
     
    8094        //Note: the text can be an array, each element will appear as a 
    8195        //seperate line in the message body. 
    82         $url   = '<img src="http://www.mononeurona.org/img/admin/new_user.jpg" alt="MonoNeurona" title="MonoNeurona" /><br />'; 
     96        $url   = 'Karamelo<br />'; 
    8397        $url  .= '<h2>'.$data["User"]["username"].'</h2><p>You have a new comment in your new: '; 
    84         $url  .= '<a href="http://'.$_SERVER['SERVER_NAME'].'/news/display/'.$new_id.'">'; 
    85         $url  .= 'http://'.$_SERVER['SERVER_NAME'].'/news/display/'.$new_id.'</a></p>'; 
     98        $url  .= '<a href="http://'.$_SERVER['SERVER_NAME'].'/news/view/'.$new_id.'">'; 
     99        $url  .= 'http://'.$_SERVER['SERVER_NAME'].'/news/view/'.$new_id.'</a></p>'; 
    86100         
    87101        //die($url); 
     
    101115 public function admin_listing($limit=20) 
    102116 { 
    103       $this->layout    = 'admin'; 
    104       $this->pageTitle = 'Comments on Blogs'; 
     117   $this->layout    = 'admin'; 
     118 
     119   $this->pageTitle = 'Comments on Blogs'; 
    105120       
    106       $conditions      = null; 
    107       $fields          = array("Commentnews.id", "News.title", "Commentnews.id", "Commentnews.comment", "Commentnews.created", "Commentnews.name", "Commentnews.user_id"); 
    108       $order           = "Commentnews.id DESC"; 
     121   $conditions  = null; 
     122 
     123   $fields = array("Commentnews.id", "News.title", "Commentnews.id", "Commentnews.comment", "Commentnews.created", "Commentnews.name", "Commentnews.user_id"); 
     124   $order           = "Commentnews.id DESC"; 
    109125        
    110       $this->set('data', $this->Commentnews->findAll($conditions, $fields, $order, $limit, null, 2)); 
     126   $this->set('data', $this->Commentnews->findAll($conditions, $fields, $order, $limit, null, 2)); 
    111127 } 
    112128  
     
    136152 public function admin_delete($id) 
    137153 { 
    138         // deletes task from database 
    139         $this->Commentnews->del($id); 
    140         $this->msgFlash('Comment deleted', '/admin/commentnews/listing'); 
     154    // deletes comment on database 
     155    $this->Commentnews->del($id); 
     156    $this->msgFlash('Comment deleted', '/admin/commentnews/listing'); 
    141157  } 
    142158} 
  • trunk/app/controllers/entries_controller.php

    r177 r246  
    22/** 
    33*  Karamelo E-Learning Platform 
    4 *  Manuel Montoya 2002-2007  
    5 *  GPL manuel<at>mononeurona.org 
     4*  Manuel Montoya 2002-2008  
     5*  GPL manuel<at>mononeurona<punto>org 
    66*/  
    77 
    88uses('sanitize'); 
    9 loadModel('User'); 
    10 loadModel('Category'); 
    119 
    1210class EntriesController extends AppController { 
    1311  
    14  public $helpers       = array('Ajax', 'Form', 'Fck', 'Gags'); 
     12 public $helpers       = array('Ajax', 'Fck', 'Gags'); 
    1513  
    16  public $components    = array('Edublog', 'Portal', 'Search', 'Mypagination'); 
     14  //public $components    = array('Edublog', 'Portal', 'Search', 'Mypagination'); 
     15  public function isAuthorized()  
     16  { 
     17    if ($this->action == 'admin_listing')  
     18    { 
     19    if ($this->Auth->user('group_id') == 1)  
     20        { 
     21        return true; 
     22        }  
     23    else  
     24        { 
     25        return false; 
     26        } 
     27    } 
    1728  
     29    return true; 
     30 } 
     31 
    1832 public function results($string)  
    1933 { 
     
    94108 public function admin_start($order = null) 
    95109 { 
    96         if (!$this->othAuth->user('id')) 
     110        if (!$this->Auth->user('id')) 
    97111        { 
    98112            die($this->redirect('/users/general')); // Get Out!!! 
     
    111125   public function admin_listing($page=1, $order = null)  
    112126   { 
    113        $order = ($order == null) ? 'Entry.id DESC': 'Entry.'.$order; 
    114         
    115127       $this->layout    = 'admin'; 
    116128        
    117        //pagination 
    118        $total_rows = $this->Entry->findCount(array("Entry.user_id"=>$this->othAuth->user('id')));  
    119         
    120        $lmt        = 25; // limit news 
    121         
    122        $targetpage = "/admin/entries/listing/"; 
    123         
    124        $pagination = $this->Mypagination->init($total_rows, $page, $lmt, $targetpage); //Pagination 
    125         
    126        $this->set('pagination', $pagination); 
    127         
    128        $conditions = array("Entry.user_id"=>$this->othAuth->user('id')); 
     129       $conditions = array("Entry.user_id"=>$this->Auth->user('id')); 
    129130        
    130131       $fields     = null; 
    131132        
    132        $offset     = (($page * $lmt) - $lmt); 
     133       $limit      = 20; 
    133134        
    134        $limit      = $lmt . " OFFSET " . $offset; 
    135         
    136        $data       = $this->Entry->findAll($conditions, $fields, $order, $limit); 
    137         
    138        $this->set('data', $data); 
     135       $this->set('data', $this->Entry->findAll($conditions, $fields, $order, $limit)); 
    139136  } 
    140137   
  • trunk/app/controllers/users_controller.php

    r244 r246  
    331331 { 
    332332    $this->layout    = 'portal'; 
    333      
    334     //$this->Group = new Group; 
     333  
    335334    $conditions = array("id"=>'>1', "id"=>"<5"); 
    336     // old: $this->set('groups', $this->User->Group->generateList($conditions, 'name', null, '{n}.Group.id', '{n}.Group.name')); 
    337335 
    338336    $this->set('groups', Set::combine($this->User->Group->find('all'), "{n}.Group.id","{n}.Group.name")); 
    339     //$this->set('Element', $this->Portal->statics()); // Using Portal component 
     337    //$this->set('Element', $this->Portal->statics()); // Using Portal components 
    340338     
    341339 } 
  • trunk/app/models/commentnews.php

    r77 r246  
    1515                         ) 
    1616                  ); 
     17 
     18  public $validate = array( 
     19                      'username' => array( 
     20                     'rule' => array('minLength', 6),   
     21                                          'message' => 'Usernames must be at least 6 characters long.' 
     22                     )  
     23              ); 
    1724} 
    1825?> 
  • trunk/app/views/elements/login.ctp

    r241 r246  
    44<legend> Login</legend> 
    55  <?php  
    6    echo  $form->input('User.username', array('id' => 'user_username', 'size' => '15', 'maxlength'=>'30')). '<br />'; 
    7    echo  $form->input('User.passwd', array('id' => 'user_passwd', 'size' => '9', 'type'=>'password')); 
    8    ?><br /> 
    9   Remember me: <?php echo  $form->checkbox("User.remember_me");?><br /> 
    10   
    11  <?php echo $form->end('Login'); ?> 
    12 </fieldset> 
     6   echo  $form->input('User.username', array('id' => 'user_username', 'size' => 15, 'maxlength'=> 30)) . '<br />'; 
     7   echo  $form->label('User.pwd', 'Password: '); 
     8   echo  $form->password('User.pwd', array('id' => 'user_pwd', 'size' => 9, 'maxlength' => 9)); 
     9   echo  $form->label('User.remember_me', 'Remember me: '); 
     10   echo  $form->checkbox('User.remember_me'); 
     11   echo  $form->end('Login');  
     12 ?> 
     13 </fieldset> 
    1314 
    14  <p><?php echo $html->link('Join us!', '/users/register'); ?></p> 
    15  <p><?php echo $html->link('forgot your password?', '/users/recover'); ?></p> 
    16 </div> 
     15 <?php  
     16   echo $html->para(null, $html->link('Join us!', '/users/register'));  
     17   echo $html->para(null, $html->link('forgot your password?', '/users/recover'));  
     18 ?> 
     19 </div> 
  • trunk/app/views/elements/login_hide.ctp

    r242 r246  
    1919<legend>Login</legend> 
    2020  <?php  
    21    echo  $form->label( 'User.username', 'Username:') . "<br />";   
     21   echo  $form->label('User.username', 'Username:') . "<br />";   
    2222   echo  $form->input('User.username', array('size' => 15, 'maxlength'=>30)) . "<br />"; 
    2323 
    2424    
    25    echo  $form->label('User.password', 'Password:') . "<br />"; 
    26    echo  $form->password('User.password', array('size' => 9, 'maxlength'=>9)); 
     25   echo  $form->label('User.pwd', 'Password:') . "<br />"; 
     26   echo  $form->password('User.pwd', array('size' => 9, 'maxlength' => 9)); 
    2727   ?><br /> 
    2828  Remember me: <?php echo  $form->checkbox("User.cokie", null, array("value" => 1));?><br /> 
  • trunk/app/views/layouts/portal.ctp

    r241 r246  
    3131   echo $cU['User']['username'] .'</b></span>'.$html->link('(Logout)', '/users/logout') . ' | ';  
    3232 
    33         if ( $othAuth->user('group_id') < 3 ) // the logged user is teacher or admin? 
     33        if (  $cU['User']['group_id'] < 3 ) // the logged user is teacher or admin? 
    3434        { 
    3535           echo $html->link('Admin', '/admin/entries/start') . ' | '; 
     
    100100 if ( !isset( $cU['User']) ) 
    101101 { 
    102             echo $this->renderElement('login_hide'); 
     102     echo $this->renderElement('login_hide');   //login javascript popup 
    103103 } 
    104104 
  • trunk/app/views/news/view.ctp

    r242 r246  
    4242echo $news->socialNets($data['News']['id'], $data['News']['title']); // Social nets buttons 
    4343     
    44 if ( $data['News']['comments'] == 1 )  // comments are actived ?? 
     44if ( $data['News']['comments'] == 1 )  // comments in this new are actived ?? 
    4545{ 
    4646  $i = 1; 
    4747  echo '<div id="cnews">'; 
    4848  foreach($data["Commentnews"] as $v) 
    49     { 
     49  { 
    5050      $bg = ($i%2==0) ? "#e2e2e2" : "#fff"; 
    5151               
     
    5555      echo "</div>"; 
    5656      $i++; 
    57     } 
     57  } 
    5858  echo "</div>"; 
    5959?> 
    6060<p> 
    6161<?php  
    62    echo $form->create('Commentnews',array("action"=>"add","onsubmit"=>"return validateNew()")); 
     62   echo $form->create('Commentnews',array("action"=>"newcomment","onsubmit"=>"return validateNew()")); 
    6363   echo $form->hidden('Commentnews.new_id', $data['News']['id']);  
    6464   echo $form->hidden('Commentnews.level', 1); 
     
    6969 
    7070  <?php  
    71    if ( isset( $cUser['User']['id'] ) )  
     71   if ( isset( $cU['User']['id'] ) )  
    7272   { 
    73        echo $form->hidden('Commentnews.user_id', $cUser['User']['id']); 
    74        echo $form->hidden('Commentnews.name', $cUser['User']['username']); 
    75        echo '<b>'. $cUser['User']['username'] . '</b>  writes. '; 
     73       echo $form->hidden('Commentnews.user_id', $cU['User']['id']); 
     74       echo $form->hidden('Commentnews.name', $cU['User']['username']); 
     75       echo '<b>'. $cU['User']['username'] . '</b>  writes. '; 
    7676  } 
    7777  else 
  • trunk/app/views/users/login.ctp

    r245 r246  
    33echo $form->create('User', array('action' => 'login')); 
    44echo $form->input('username'); 
    5 echo $form->input('password'); 
     5echo $form->label('pwd', 'Password:'); 
     6echo $form->password('pwd') . '<br />'; 
    67echo $form->label('remember_me', 'Remember me:'); 
    78echo $form->checkbox('remember_me');