Changeset 361

Show
Ignore:
Timestamp:
04/02/08 13:19:24 (9 months ago)
Author:
aarkerio
Message:

Locale and test improvements

Location:
trunk/app
Files:
4 added
11 modified

Legend:

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

    r339 r361  
    33*  Karamelo E-Learning Platform 
    44*  Chipotle Software 2002-2008  
    5 *  GPL manuel<at>mononeurona<punto>org 
     5*  GPLv3 manuel<arroba>mononeurona<punto>org 
    66*/  
    77//File: /app/controllers/quotes_controller.php 
     
    4545         
    4646        if ( $this->Answer->save($this->data['Answer']) )  
    47          { 
     47    { 
    4848                    $conditions = array("Answer.question_id" => $this->data['Answer']['question_id']); 
    4949                    $fields     = array("Answer.id", "Answer.answer", "Answer.correct"); 
     
    112112        $this->set('data', $this->Answer->findAll($conditions, $fields, $order)); 
    113113  } 
     114 
     115  public function admin_change($answer_id, $correct, $question_id) 
     116  {   
     117     $this->data['Answer']['correct'] = ($correct == 0 ) ? 1 : 0; 
     118      
     119     $this->data['Answer']['id']      = $answer_id; 
     120     
     121     if ($this->Answer->save($this->data['Answer']))  
     122     { 
     123        $this->msgFlash('Answer updated', '/admin/question/listing/'.$question_id); 
     124     } 
     125  } 
    114126   
    115    
    116   public function admin_delete($id, $question_id)  
     127  public function admin_delete($answer_id, $question_id)  
    117128  { 
    118129      // deletes from database 
    119130       
    120       if ( $this->Answer->del($id) ) 
     131      if ( $this->Answer->del($answer_id) ) 
    121132      { 
    122133            $this->msgFlash('Answer deleted', '/admin/questions/answers/'.$question_id); 
  • trunk/app/controllers/newsletters_controller.php

    r346 r361  
    11<?php 
    2 /** 
     2/**  
    33*   Karamelo E-Learning Platform 
    44*   Manuel Montoya 2002-2008 
  • trunk/app/controllers/podcasts_controller.php

    r360 r361  
    2929           { 
    3030            return true; 
    31        }  
     31           }  
    3232    }  
    33         return false;  // go away !! 
     33    return false;  // go away !! 
    3434 } 
    3535 
     
    4444   $conditions = array("Podcast.status"=>1); 
    4545         
    46    $fields     = array('Podcast.id','Podcast.title','Podcast.description','Podcast.created','Podcast.filename','Podcast.length','Podcast.duration', 'User.username'); 
     46   $fields     = array('Podcast.id','Podcast.title', 'Podcast.description','Podcast.created','Podcast.filename', 'Podcast.length','Podcast.duration', 'User.username'); 
    4747      
    4848   $order      = 'Podcast.id DESC'; 
     
    6464    $this->Podcast->User->unbindModel(array('hasMany'=>array('Entry', 'Lesson', 'Category', 'Vclassroom', 'Faq', 'Acquaintance'))); 
    6565 
    66     $User =  $this->Podcast->User->find(array("User.username"=>$username)); 
    67     //die(debug($User)); 
    68     $this->set('User', $User); 
    69  
    70     // die(debug($User)); 
    71  
    7266    $conditions = array("status"=>1, "user_id"=>$User['User']['id']); 
    7367     
     
    8377 public function show($user_id, $id) 
    8478 {    
    85         $this->layout    = $this->Edublog->layout($user_id); 
    86          
    87         $this->set('blog', $this->Edublog->blog($user_id)); 
    88          
    89         $this->pageTitle = 'Podcast'; 
    90          
    91         $conditions = array("Podcast.id"=>$id, "Podcast.status"=>1); 
    92          
    93         $fields     = array("id", "title", "description", "created", "filename", "length", "size", "duration"); 
    94          
    95         $this->set('data', $this->Podcast->findAll($conditions, $fields)); 
    96     } 
     79    $this->layout    = $this->Edublog->layout($user_id); 
     80         
     81    $this->set('blog', $this->Edublog->blog($user_id)); 
     82         
     83    $this->pageTitle = 'Podcast'; 
     84         
     85    $conditions = array("Podcast.id"=>$id, "Podcast.status"=>1); 
     86         
     87    $fields     = array("id", "title", "description", "created", "filename", "length", "size", "duration"); 
     88         
     89    $this->set('data', $this->Podcast->findAll($conditions, $fields)); 
     90 } 
    9791     
    9892/******    ====ADMIN METHODS==== ***/     
     
    10094 public function admin_listing() 
    10195 {    
    102         $this->pageTitle = $this->Auth->user('username') . '\'s Podcasts'; 
    103          
    104         $this->layout = 'admin'; 
    105          
    106         $conditions   = array("Podcast.user_id"=>$this->Auth->user('id')); 
    107         $fields       = array('id', 'title', 'description', 'created', 'length', 'status', 'filename'); 
    108         $order        = "Podcast.id DESC"; 
    109         $limit        = 12; 
    110          
    111         $this->set('data', $this->Podcast->findAll($conditions, $fields, $order, $limit, null, 1));  
     96    $this->pageTitle = $this->Auth->user('username') . '\'s Podcasts'; 
     97         
     98    $this->layout = 'admin'; 
     99         
     100    $conditions   = array("Podcast.user_id"=>$this->Auth->user('id')); 
     101    $fields       = array('id', 'title', 'description', 'created', 'length', 'status', 'filename'); 
     102    $order        = "Podcast.id DESC"; 
     103    $limit        = 12; 
     104         
     105    $this->set('data', $this->Podcast->findAll($conditions, $fields, $order, $limit, null, 1));  
    112106 } 
    113107     
  • trunk/app/controllers/questions_controller.php

    r328 r361  
    1515  public function isAuthorized() 
    1616  { 
    17              if (isset($this->params[Configure::read('Routing.admin')])) 
    18                     { 
    19                              if ($this->Auth->user('group_id') != 1) 
    20                                       { 
    21                                                    return false; 
    22                                                              } 
    23                                                             } 
    24                                                                return true; 
     17      if (isset($this->params[Configure::read('Routing.admin')])) 
     18      { 
     19          if ($this->Auth->user('group_id') != 1) 
     20          { 
     21               return false; 
     22          } 
     23      } 
     24  return true; 
    2525  }                                                         
    2626 
    27   /*** 
    28   ===   ADMIN METHODS 
    29   ***/   
    30   public function admin_add()  
    31   { 
    32     // adds new vote to database 
    33     if (!empty($this->data["Question"])) 
    34     {   
    35         //die(print_r($this->data)); 
     27 /***  ===   ADMIN METHODS ===  ***/   
     28 public function admin_add()  
     29 { 
     30  // adds new vote to database 
     31  if (!empty($this->data["Question"])) 
     32  {   
     33   //die(print_r($this->data)); 
    3634         
    37         $this->Sanitize = new Sanitize; 
     35   $this->Sanitize = new Sanitize; 
    3836         
    39         $this->Sanitize->clean($this->data['Question']); 
     37   $this->Sanitize->clean($this->data['Question']); 
    4038         
    41         $this->data["Question"]['user_id'] = $this->Auth->user('id'); 
     39   $this->data["Question"]['user_id'] = $this->Auth->user('id'); 
    4240 
    43         $this->Question->create(); 
     41   $this->Question->create(); 
    4442         
    45         if ( $this->Question->save( $this->data['Question'] ) )  
    46     { 
    47                     $conditions = array("Question.test_id" => $this->data['Question']['test_id']); 
    48                     $fields     = array("Question.id", "Question.question", "Question.hint", "Question.worth", "Question.explanation"); 
    49                     $order      = "Question.id"; 
     43   if ( $this->Question->save( $this->data['Question'] ) )  
     44   { 
     45     $conditions = array("Question.test_id" => $this->data['Question']['test_id']); 
     46     $fields     = array("Question.id", "Question.question", "Question.hint", "Question.worth", "Question.explanation"); 
     47     $order      = "Question.id"; 
    5048                     
    51                     $this->set('data', $this->Question->findAll($conditions, $fields, $order)); 
     49     $this->set('data', $this->Question->findAll($conditions, $fields, $order)); 
    5250                     
    53                     $this->render('questions', 'ajax'); 
     51     $this->render('questions', 'ajax'); 
    5452    } 
    5553    else 
    5654    { 
    57                 echo "Ajax error, check with the company's computer guy..."; 
     55            echo "Ajax error, check with the company's computer guy..."; 
    5856    } 
    59      } 
    6057  } 
     58 } 
    6159 
    62   public function admin_edit($question_id=null)  
    63   { 
    64         $this->layout = 'admin'; 
     60 public function admin_edit($question_id=null)  
     61 { 
     62    $this->layout = 'admin'; 
    6563    // adds new vote to database 
    66     if (!empty($this->data["Question"])) 
    67     {   
    68          
     64    if ( !empty($this->data["Question"]) ) 
     65    {          
    6966        $this->Sanitize = new Sanitize; 
    7067         
     
    7269                 
    7370         if ( $this->Question->save( $this->data['Question'] ) )  
    74      { 
     71         { 
    7572              $this->msgFlash('Question saved', '/admin/tests/questions/'.$this->data["Question"]["test_id"]); 
    76      } 
    77      else 
    78      { 
     73         } 
     74         else 
     75         { 
    7976                echo "Ajax error, check with the company's computer guy..."; 
    80      } 
    81         } 
    82         else 
    83         { 
    84              $this->Question->id = $question_id; 
    85            
    86              $this->data = $this->Question->read(); 
    87         } 
     77         } 
     78     } 
     79     else 
     80     {   
     81        $this->data = $this->Question->read(null, $question_id); 
     82     } 
    8883  } 
    8984   
  • trunk/app/controllers/tests_controller.php

    r358 r361  
    88 
    99uses('Sanitize'); 
     10uses('L10n'); 
    1011 
    1112class TestsController extends AppController 
     
    1516 public $components = array('Edublog'); 
    1617  
     18 public $paginate = array( 
     19                          'limit' => 25, 
     20                          'order' => array( 
     21                                           'Test.title' => 'asc' 
     22                                          ) 
     23                         ); 
     24  
    1725 public function beforeFilter()  
    1826 { 
    1927    $this->Auth->allow(array('view', 'display')); 
    2028    parent::beforeFilter(); 
     29     
     30    // L10n 
     31    $this->L10n = new L10n(); 
     32    $this->L10n->get("en"); 
     33  
     34    Configure::write('Config.language', "en"); 
    2135 } 
    2236  
     
    151165  } 
    152166   
    153   /** 
    154    === ADMIN METHODS ==== 
    155   **/ 
     167 /**   === ADMIN METHODS ====  **/ 
    156168 /** Select classroom to link*/ 
    157169 public function admin_vclassrooms() 
     
    168180      $this->set('data', $this->Test->findAll($conditions));  
    169181 } 
    170  
    171       
    172   public function admin_listing() 
    173   {    
    174        $this->layout    = 'admin'; 
    175          
    176        $this->pageTitle = 'Tests'; 
    177          
    178        $conditions = array("Test.user_id"=>$this->Auth->user('id')); 
    179          
    180        $fields     = array("Test.id", "Test.user_id", "Test.title", "Test.description", "Test.status"); 
    181          
    182        $order = "Test.id DESC"; 
    183          
    184        $this->set('data', $this->Test->findAll($conditions, $fields, $order)); 
    185   } 
    186    
    187   public function admin_questions($test_id) 
    188   { 
    189        $this->layout    = 'admin'; 
    190          
    191        $this->pageTitle = 'Tests'; 
    192          
    193        $conditions = array("Test.user_id"=>$this->Auth->user('id'), "Test.id"=>$test_id); 
    194          
    195        $fields     = array("Test.id", "Test.user_id", "Test.title", "Test.description"); 
    196  
    197        $this->Test->unbindModel(array("belongsTo"=>array("User"))); 
    198          
    199        $this->set('data', $this->Test->find($conditions, $fields, null, 2)); 
    200   } 
    201  
    202   public function admin_add()  
    203   { 
     182     
     183 public function admin_listing() 
     184 {    
     185      $this->layout    = 'admin'; 
     186         
     187      $this->pageTitle = 'Tests'; 
     188         
     189      $conditions = array("Test.user_id"=>$this->Auth->user('id')); 
     190         
     191      $fields     = array("Test.id", "Test.user_id", "Test.title", "Test.description", "Test.status"); 
     192         
     193      $order = "Test.id DESC"; 
     194         
     195      $this->set('data', $this->Test->findAll($conditions, $fields, $order)); 
     196 } 
     197 public function admin_add()  
     198 { 
    204199       $this->layout    = 'admin'; 
    205200       // add to database 
     
    223218          } 
    224219       } 
    225   } 
    226   public function admin_edit($test_id=null)  
    227   { 
     220 } 
     221  
     222 public function admin_edit($test_id=null)  
     223 { 
    228224       $this->layout    = 'admin'; 
    229225        
     
    242238       else 
    243239       { 
    244         $this->Test->id = $test_id; 
    245            
    246         $this->data = $this->Test->read(); 
     240          $this->data = $this->Test->read(null, $test_id); 
    247241       } 
    248242  } 
     
    260254    } 
    261255 } 
     256  
     257 public function admin_questions($test_id) 
     258 { 
     259       $this->layout    = 'admin'; 
     260         
     261       $this->pageTitle = 'Tests'; 
     262         
     263       $conditions = array("Test.user_id"=>$this->Auth->user('id'), "Test.id"=>$test_id); 
     264         
     265       $fields     = array("Test.id", "Test.user_id", "Test.title", "Test.description"); 
     266 
     267       $this->Test->unbindModel(array("belongsTo"=>array("User"))); 
     268         
     269       $this->set('data', $this->Test->find($conditions, $fields, null, 2)); 
     270  } 
    262271 
    263272 public function admin_delete($id)  
  • trunk/app/views/podcasts/admin_add.ctp

    r359 r361  
    3131  echo $form->select('Podcast.subject_id', $subjects, null, null, null, false); 
    3232 
    33   
    3433  echo $form->input('Podcast.title', array("size" => 25, "maxlength" => 50));  
    3534 
  • trunk/app/views/questions/admin_answers.ctp

    r269 r361  
    11<?php 
    2 // die(print_r($data)); 
    3   if ( isset($javascript) ): 
    4       echo $html->charsetTag('UTF-8'); 
    5       echo $javascript->link('prototype'); 
    6       echo $javascript->link('scriptaculous.js?load=effects'); 
    7   endif; 
    8   
    9   echo $html->addCrumb('Control Tools', '/admin/entries/start'); 
    10   echo $html->addCrumb('Tests', '/admin/tests/listing'); 
    11   echo $html->getCrumbs(' / ');  
     2 echo $html->addCrumb('Control Tools', '/admin/entries/start'); 
     3 echo $html->addCrumb('Tests', '/admin/tests/listing'); 
     4 echo $html->getCrumbs(' / ');  
     5 
     6 echo $html->div('title_section', 'Answers to ' . $data['Question']['question']); 
    127?> 
    13  
    14 <div class="title_section">Answers to <?php echo $data['Question']['question']; ?></div> 
    158 
    169<div id="loading" style="display: none;"> 
     
    2518 
    2619<?php  
    27    echo $ajax->form(null,'post'); 
    28    echo $html->hiddenTag('Answer/question_id', $data['Question']['id']); 
     20   echo $ajax->form(); 
     21   echo $form->hidden('Answer.question_id', array('value'=>$data['Question']['id'])); 
    2922 ?> 
    30 <fieldset> 
    31 <legend>New answer</legend> 
    32  
    33 <div class="required"> 
    34   <?php echo $form->labelTag('Answer/answer', 'Answer:' ); ?> 
    35   <?php echo $html->input('Answer/answer', array("size" => 55, "maxlength" => 120)); ?> 
    36   <?php echo $html->tagErrorMsg('Answer/answer', 'Answer is required.'); ?> 
    37 </div> 
    38 <div class="required"> 
    39   <?php echo $form->labelTag('Answer/correct', 'Answer is correct:' ); ?> 
    40   <?php echo $html->checkbox('Answer/correct', null, array("value" => 1)); ?> 
    41 </div> 
    42 <div> 
     23<fieldset><legend>New answer</legend> 
    4324<?php 
    44     echo $ajax->submit('Save', array("url" => "/admin/answers/add", 
     25 echo $html->div('required',$form->input('Answer.answer', array("size" => 55, "maxlength" => 120)));  
     26 echo $html->div('required',$form->label('Answer.correct','Answer is correct:').$form->checkbox('Answer.correct', array("value" => 1)));  
     27 echo $ajax->submit('Save', array("url" => "/admin/answers/add", 
    4528                                         "update"=>"questions", 
    4629                                         "loading" => "Element.hide('questions');Element.hide('addquestion');Element.show('loading')", 
     
    4831            ));  
    4932 ?> 
    50 </div> 
    5133</fieldset> 
    52  
    5334</div> 
    5435 
     
    5839{ 
    5940  $st = ($val["correct"]==1) ? 'Yes' : 'No';       
    60     echo '<div style="padding:5px;border:1px dotted gray;margin:4px;">'; 
    61        echo '<div class="butonright">' . $html->link('Delete', '/admin/answers/delete/'.$val['id'].'/'.$val['question_id'])   . '</div>'; 
    62        echo '<div class="butonright">' . $html->link('Edit',   '/admin/answers/edit/'  .$val['id']) . '</div>'; 
    63        echo "Answer: "      . $val["answer"]      . "<br />"; 
    64        echo "Correct: "     . $st                  . "<br />"; 
    65     echo '</div>'; 
     41  $tmp  = $html->div(null, $html->link('Delete', '/admin/answers/delete/'.$val['id'].'/'.$val['question_id'])); 
     42  $tmp .= $html->div(null, $html->link('Edit',   '/admin/answers/edit/'  .$val['id'])); 
     43  $tmp .= "Answer:  "     . $val["answer"]          . "<br />"; 
     44  $tmp .= "Correct: "     . $html->link($st, '/admin/answers/changed/'.$val['id'].'/'.$val['question_id']) . "<br />"; 
     45 
     46  echo $html->div('adminblock', $tmp); 
    6647} 
    6748?> 
  • trunk/app/views/questions/admin_edit.ctp

    r269 r361  
    1 <?php echo $html->addCrumb('Control Tools', '/admin/entries/start'); ?>  
    2 <?php echo $html->addCrumb('Test', '/admin/tests/listing'); ?>  
    3 <?php echo $html->getCrumbs(' / '); ?> 
    4  
    51<?php  
    6    echo $html->formTag('/admin/questions/edit','post', array("onsubmit"=>"return validateNew()"));  
    7    echo $html->hidden('Question/test_id'); 
     2   echo $html->addCrumb('Control Tools', '/admin/entries/start'); 
     3   echo $html->addCrumb('Test', '/admin/tests/listing');  
     4   echo $html->getCrumbs(' / ');  
     5  
     6   echo $form->create('Question', array("onsubmit"=>"return validateNew()"));  
     7   echo $form->hidden('Question.id'); 
     8   echo $form->hidden('Question.test_id', array('value'=>$this->data['Question']['test_id'])); 
    89?> 
    910<fieldset> 
    1011<legend>Edit question</legend> 
    11 <div class="required"> 
    12   <?php  
    13       echo $form->labelTag('Question/question', 'Question:' );  
    14       echo $html->input('Question/question', array("size" => 40, "maxlength" => 120));  
    15       echo $html->tagErrorMsg('Question/question', 'Question is required.');  
    16    ?> 
    17 </div> 
     12<?php 
     13 echo $html->div('required',$form->input('Question.question', array("size" => 40, "maxlength" => 120)));  
     14   
     15 echo $html->div('required',$form->input('Question.hint', array("size" => 40, "maxlength" => 120)));  
     16     
     17 $tmp  = $form->label('Question.explanation', 'Explanation:');  
     18 $tmp .= $form->textarea('Question.explanation', array("cols" => 50, "rows" => 5));  
    1819 
    19 <div class="required"> 
    20   <?php  
    21      echo $form->labelTag('Question/hint', 'Hint:' ); 
    22      echo $html->input('Question/hint', array("size" => 40, "maxlength" => 120));  
    23      echo $html->tagErrorMsg('Question/hint', 'Hint is required.');  
    24    ?> 
    25 </div> 
     20 echo $html->div('required',$tmp); 
     21  
     22 $t  = $form->label('Question.worth', 'Worth:'); 
     23 $t .= $form->select('Question.worth', array(1,2,3,4,5,6,7,8,9,10), null, null, false, false); 
     24 echo $html->div('required',$t); 
     25?> 
     26</fieldset> 
     27<?php echo $form->end('Save'); ?>  
    2628 
    27 <div class="required"> 
    28 <?php  
    29    echo $form->labelTag('Question/explanation', 'Explanation:' );  
    30    echo $html->textarea('Question/explanation', array("cols" => 50, "rows" => 5));  
    31    echo $html->tagErrorMsg('Question/explanation', 'Description is required.'); 
    32 ?> 
    33 </div> 
    34  
    35 <div class="required"> 
    36 <?php  
    37     echo $form->labelTag( 'Question/status', 'Published:' ); 
    38     $options = array(1,2,3,4,5,6,7,8,9,10); 
    39     echo $html->selectTag('Question/value', $options, null, null, false, false); 
    40 ?> 
    41 </div> 
    42  
    43 <div> 
    44     <?php echo $html->submit('Save'); ?> </form> 
    45 </div> 
    46 </fieldset> 
  • trunk/app/views/tests/admin_edit.ctp

    r264 r361  
    1 <?php echo $html->addCrumb('Control Tools', '/admin/entries/start'); ?>  
    2 <?php echo $html->addCrumb('Test', '/admin/tests/listing'); ?>  
    3 <?php echo $html->getCrumbs(' / '); ?> 
    4  
    51<?php  
    6    echo $html->formTag('/admin/tests/edit','post', array("onsubmit"=>"return validateNew()"));  
    7    echo $html->hidden('Test/id'); 
     2 echo $html->addCrumb('Control Tools', '/admin/entries/start'); 
     3 echo $html->addCrumb('Test', '/admin/tests/listing');  
     4 echo $html->getCrumbs(' / ');  
     5  
     6 echo $form->create('Test', array("onsubmit"=>"return validateNew()"));  
     7 echo $form->hidden('Test.id'); 
    88?> 
    99<fieldset> 
    1010<legend>Edit test</legend> 
    11 <div class="required"> 
    12   <?php  
    13       echo $form->labelTag('Test/title', 'Title:' );  
    14       echo $html->input('Test/title', array("size" => 40, "maxlength" => 120));  
    15       echo $html->tagErrorMsg('Test/title', 'Test is required.');  
    16    ?> 
    17 </div> 
     11<?php  
     12 echo $html->div('required', $form->input('Test.title', array("size" => 40, "maxlength" => 120)));  
     13    
     14 echo $html->div('required', $form->label('Test.description', 'Description:') . $form->textarea('Test.description', array("cols" => 50, "rows" => 5)));  
     15    
     16 echo $html->div('required', $form->label('Test.status', 'Published:' ) . $form->checkbox('Test.status', array('value'=>1))); 
     17  
     18 echo $form->end('Save');  
     19?>  
     20</fieldset> 
    1821 
    19 <div class="required"> 
    20 <?php  
    21    echo $form->labelTag('Test/explanation', 'Explanation:' );  
    22    echo $html->textarea('Test/explanation', array("cols" => 50, "rows" => 5));  
    23    echo $html->tagErrorMsg('Test/explanation', 'Description is required.'); 
    24 ?> 
    25 </div> 
    26 <div> 
    27 <?php 
    28    echo $form->labelTag('Test/status', 'Published:' ); 
    29     echo $html->checkbox('Test/status', null); 
    30 ?> 
    31 </div> 
    32 <div> 
    33     <?php echo $html->submit('Save'); ?> </form> 
    34 </div>