Changeset 422

Show
Ignore:
Timestamp:
04/23/08 19:07:23 (9 months ago)
Author:
aarkerio
Message:

Tests answers

Location:
trunk/app
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/controllers/components/edublog.php

    r416 r422  
    118118 
    119119   $vclassrooms = $this->Vclassroom->chkVclassrooms($user_id); // check model, what classrooms this student belongs? 
    120  
     120    
    121121   if ($vclassrooms != null) 
    122122   { 
  • trunk/app/controllers/messages_controller.php

    r342 r422  
    8585            
    8686           if ($this->Message->save($this->data["Message"])) 
    87            { 
    88                 $this->sendMail($this->data["Message"]["user_id"], $this->data["Message"]["username"], $this->data["Message"]["title"]); 
     87       { 
     88             $this->__sendMail($this->data["Message"]["user_id"], $this->data["Message"]["username"], $this->data["Message"]["title"]); 
    8989                 
    9090                if ( isset($this->data["Message"]["admin"])) 
     
    9595                { 
    9696                    $this->render('sent', 'ajax'); 
    97                 } 
     97        } 
    9898        } 
    9999     } 
    100100 } 
    101   private function sendMail($user_id, $username, $title)  
    102    { 
    103         $this->User = new User; 
    104          
    105         $fields = array('email', 'username'); 
    106          
    107         $data = $this->User->find(array("User.id"=>$user_id), $fields); 
    108         //exit($data["User"]["email"]); 
    109         $this->Email->sender    = '::MonoNeurona.org::'; 
    110         $this->Email->to        = $data["User"]["email"]; 
    111         $this->Email->subject   = '::MonoNeurona.org:: New message from '. $username; 
    112         $this->Email->sendAs    = 'html'; 
    113         $this->Email->template  = null; 
    114         $this->Email->from      = 'noreply@mononeurona.org'; 
    115         //$this->set('foo', 'Cake tastes good today');  
    116         //Set the body of the mail as we send it. 
    117         //Note: the text can be an array, each element will appear as a 
    118         //seperate line in the message body. 
    119         $url   = '<img src="http://www.mononeurona.org/img/admin/new_user.jpg" alt="MonoNeurona" title="MonoNeurona" /><br />'; 
    120         $url  .= '<h2>'.$data["User"]["username"].'</h2><p>You have a new message from '. $username; 
    121         $url  .= '<a href="http://'.$_SERVER['SERVER_NAME'].'/admin/messages/listing/">'.$title.'</a></p>'; 
    122          
    123         //die($url); 
    124          
    125         if ( $this->Email->send($url) )  
    126         { 
    127             return true;  
    128         }  
    129         else  
    130         { 
    131              
    132             exit("Error!!"); 
    133         } 
     101 
     102  /* == PRIVATE == **/ 
     103  private function __sendMail($email) 
     104  {    
     105    $this->layout          = 'default'; 
     106    $this->Email->to       = $email; 
     107 
     108    // this could be just a string too 
     109    $this->Email->subject  = 'Karamelo e-Learning:: New message'; 
     110    $this->Email->replyTo  = 'support@karamelo.org'; 
     111    $this->Email->from     = 'Chipotle-software.com'; 
     112    $this->Email->template = 'message';  
     113    $this->Email->sendAs   = 'text'; // because we like to send pretty mail 
     114    //Do not pass any args to send() 
     115    if ( $this->Email->send() ) 
     116    { 
     117              return true; 
     118    } 
     119    else 
     120    { 
     121                return false; 
     122    } 
    134123 } 
    135124  
     
    178167           
    179168          if ($this->Message->save($this->data["Message"])) 
    180           { 
     169      { 
    181170             $j++; 
    182           } 
     171      } 
    183172          else 
    184173          { 
     
    187176        } 
    188177        $this->msgFlash($j . ' messages sent', '/admin/messages/listing'); 
    189       } 
     178     } 
    190179 } 
    191180  
     
    225214 public function admin_add() 
    226215 {     
    227         $this->layout    = 'admin'; 
    228          
    229         if (!empty($this->data["Message"])) 
    230         { 
    231           $this->Sanitize = new Sanitize; 
    232            
    233           $this->Sanitize->html($this->data["Message"]["title"]); 
    234            
    235           $this->Sanitize->html($this->data["Message"]["body"]); 
    236            
    237           if ( isset( $this->data["Message"]["message_id"] ) ) 
    238           { 
     216   $this->layout    = 'admin'; 
     217         
     218   if (!empty($this->data["Message"])) 
     219   { 
     220     $this->Sanitize = new Sanitize; 
     221           
     222     $this->Sanitize->html($this->data["Message"]["title"]); 
     223           
     224     $this->Sanitize->html($this->data["Message"]["body"]); 
     225           
     226     if ( isset( $this->data["Message"]["message_id"] ) ) 
     227     { 
    239228              $this->change($this->data["Message"]["message_id"], 2); 
    240           } 
    241            
    242           $this->Message->create(); 
    243            
    244           if ($this->Message->save($this->data["Message"])) 
    245           { 
     229     } 
     230           
     231     $this->Message->create(); 
     232           
     233     if ($this->Message->save($this->data["Message"])) 
     234     { 
    246235            $this->sendMail($this->data["Message"]["user_id"], $this->data["Message"]["username"], $this->data["Message"]["title"]); 
    247236            $this->render('send','ajax'); 
    248           } 
    249        } 
     237     } 
    250238   } 
     239 } 
    251240    
    252    public function admin_display($message_id) 
    253    { 
     241 public function admin_display($message_id) 
     242 { 
    254243      $this->pageTitle = 'Message'; 
    255244       
     
    291280        } 
    292281    } 
    293 } 
    294    
    295   public function admin_delete($id=null) 
    296   { 
    297         if ( isset($this->data["Message"]["several"]) ) 
    298         {    
     282 } 
     283 
     284 public function admin_write($user_id) 
     285 {     
     286        $this->layout    = 'admin'; 
     287         
     288        $this->pageTitle = 'Write Message'; 
     289 
     290        $this->set('user_id', $user_id); 
     291 } 
     292 
     293 public function admin_deliver() 
     294 {   
     295    if (!empty($this->data['Message'])) 
     296    { 
     297      $this->Sanitize = new Sanitize; 
     298            
     299      $this->Sanitize->html($this->data['Message']['title']); 
     300            
     301      $this->Sanitize->html($this->data['Message']['body']); 
     302 
     303      $this->data['Message']['sender'] = $this->Auth->user('id'); 
     304      //die(debug($this->data)); 
     305      $this->Message->create(); 
     306            
     307      if ($this->Message->save($this->data['Message'])) 
     308      { 
     309      $email = $this->Message->User->field('email', array('id'=>$this->data['Message']['user_id'])); 
     310      if ( $this->__sendMail($email) ) 
     311      { 
     312               $this->msgFlash('Message sent','/admin/messages/listing'); 
     313      } 
     314      } 
     315    } 
     316 } 
     317  
     318 public function admin_delete($id=null) 
     319 { 
     320   if ( isset($this->data["Message"]["several"]) ) 
     321   {    
    299322            //exit(print_r($this->data["Message"]["id"])); 
    300323            foreach ($this->data["Message"]["id"] as $v) 
     
    307330             
    308331            $this->msgFlash('The message has been deleted.','/admin/messages/listing'); 
    309         } 
    310         else 
    311         { 
     332   } 
     333   else 
     334   { 
    312335           if ( isset( $this->data["Message"]["id"] ) ) 
    313336           { 
     
    315338           } 
    316339            
    317              $this->Message->del($id); 
    318         } 
    319         $this->msgFlash('Message has been deleted.','/admin/messages/listing'); 
     340       $this->Message->del($id); 
     341  } 
     342     $this->msgFlash('Message has been deleted.','/admin/messages/listing'); 
    320343  } 
    321344} 
  • trunk/app/controllers/results_controller.php

    r421 r422  
    1212uses('sanitize'); 
    1313 
    14 class EntriesController extends AppController { 
     14class ResultsController extends AppController { 
    1515  
    1616  public $helpers       = array('Ajax', 'Fck', 'Gags'); 
     
    3737 
    3838  public function result() 
    39   {    
    40     $this->layout    = 'rss'; 
     39  {  
     40    die(debug($this->data)); 
     41 
     42    $this->pageTitle = 'Results'; 
     43                
     44    $this->layout    = $this->Edublog->layout($user_id); 
     45          
     46    $this->Edublog->blog($user_id); // set edublog components 
     47          
     48    
     49    $answers = $this->Resukts->Question->findAll($conditions, $fields, $order); 
    4150       
    4251    $conditions      = array("Result.status"=>1, "Result.user_id"=>$user_id); 
  • trunk/app/controllers/tests_controller.php

    r419 r422  
    6666  public function view($test_id, $user_id) 
    6767  { 
    68      // the student alredy answer? 
     68     // the student alredy answered this test? 
    6969     $already = $this->Test->Result->field('Result.id', array("Result.user_id"=>$this->Auth->user('id'), "Result.test_id"=>$test_id)); 
    7070 
     
    7878    if ( $this->Auth->user() && $this->Auth->user('group_id') == 3) 
    7979    { 
    80        $user_id = (int) $this->Auth->user('id'); 
    81            $this->Edublog->setSession($user_id); 
     80       $student_id = (int) $this->Auth->user('id'); 
     81           $this->Edublog->setSession($student_id); //check if user belongs to class 
    8282    } 
    8383 
     
    9090    $conditions = array("Test.id"=>$test_id, "Test.status"=>1); 
    9191 
    92     $this->set('data', $this->Test->find($conditions, null, null, 2)); 
     92    $fields = null; // array('Test.id', 'Test.title', 'Question.id'); 
     93 
     94    $order  = null; 
     95 
     96    $this->set('data', $this->Test->find($conditions, $fields, $order, 2)); 
    9397  } 
    9498 
     
    109113      $this->Sanitize->clean($this->data['Result']);   
    110114     
    111       $this->data['Result']['results']   = $this->getResults($this->data['Result']);  
     115      $this->data['Result']['results']   = $this->Test->($this->data['Result']);  
    112116 
    113117      $this->data['Result']['test_id'] =  $this->data['Question']['test_id']; 
     
    126130    { 
    127131      echo "Caught my exception\n" . $e; 
    128     } 
    129      
    130 } 
    131  
    132  private function chk($user_id) 
     132    }    
     133 } 
     134 
     135 private function chk($user_id) // preview tests before send 
    133136 { 
    134137    try { 
     
    152155 } 
    153156 
    154  private function get_results($questions) 
    155  { 
    156     $this->Test->unbindModel(array('belongsTo'=>array('User'))); //just few data 
    157      
    158     $result = 0; 
    159      
    160     foreach($questions as $q_id => $a_id)  // question id and answer id 
    161     { 
    162          $correct_answer = $this->Test->Question->Answer->field('Answer.correct', array('Answer.id'=>$a_id));   // answer was correct? 
    163           
    164          if ($correct_answer == 1) 
    165          { 
    166               $worth   = $this->Test->Question->field('Question.worth', array('Question.id'=>$q_id));         // how many points 
    167               $result += $worth; 
    168          } 
    169     } 
    170     //exit('Result was:' . $result); 
    171     return $result;  
    172   } 
    173157   
    174158 /**   === ADMIN METHODS ====  **/ 
  • trunk/app/models/test.php

    r373 r422  
    7474 
    7575    return $vclassrooms; 
     76 } 
     77 
     78 private function chkAnswers($answers) 
     79 { 
     80    $this->Test->unbindModel(array('belongsTo'=>array('User'))); //just few data 
     81     
     82    $result = 0; 
     83     
     84    foreach($questions as $q_id => $a_id)  // question id and answer id 
     85    { 
     86         $correct_answer = $this->Test->Question->Answer->field('Answer.correct', array('Answer.id'=>$a_id));   // answer was correct? 
     87          
     88         if ($correct_answer == 1) 
     89         { 
     90              $worth   = $this->Test->Question->field('Question.worth', array('Question.id'=>$q_id));         // how many points 
     91              $result += $worth; 
     92         } 
     93    } 
     94    //exit('Result was:' . $result); 
     95    return $result;  
    7696  } 
    7797} 
  • trunk/app/views/questions/admin_answers.ctp

    r363 r422  
    11<?php 
     2//die(debug($data)); 
    23 echo $html->addCrumb('Control Tools', '/admin/entries/start'); 
    34 echo $html->addCrumb('Tests', '/admin/tests/listing'); 
     5 echo $html->addCrumb($data['Test']['title'], '/admin/tests/questions/'.$data['Test']['id']); 
    46 echo $html->getCrumbs(' / ');  
    57 
  • trunk/app/views/tests/admin_questions.ctp

    r421 r422  
    1010</div> 
    1111<?php 
    12  echo $html->para(null, $html->link('Edit', '/admin/tests/edit/'.$data['Test']['id'])) . '&nbsp;&nbsp;'; 
    13  echo $data['Test']['title'] . "  " . $data['Test']['description']; 
     12 echo $html->para(null, $html->link('Edit', '/admin/tests/edit/'.$data['Test']['id']).'&nbsp;&nbsp;'.$html->link('Assign to class', '/admin/tests/vclassrooms/'.$data['Test']['id'])); 
     13 
     14 echo '<b>Description:</b> '. $data['Test']['title'] . "  " . $data['Test']['description']; 
    1415 echo "  ". count($data["Question"]) . " questions"; 
    1516 
  • trunk/app/views/tests/view.ctp

    r420 r422  
    11<?php 
    2 //die(debug($data)); 
     2// die(debug($data)); 
    33 
    44$auth = false; 
    5   
     5 
    66if ( $session->check('vclassrooms') ): 
    77   foreach($data['Vclassroom'] as $v): 
    8        $auth = ( in_array($v['id'], $session->read('vclassrooms'))) ? true : false;  // students belongs this vclass ? 
     8       if ( in_array($v['id'], $session->read('vclassrooms'))): 
     9              $auth = true; 
     10          break; 
     11       endif; 
    912   endforeach; 
    1013endif; 
     
    2427       //exit(var_dump($val)); 
    2528       echo '<div>'; 
    26           echo $html->div(null, $val['question'] .' '. $val['worth'], array('style'=>'font-size:14pt;margin:5px 0 6px 0'));  
    2729        
    2830          $options = array(); // to build options radio buttons 
     
    3234          endforeach; 
    3335 
    34           echo $form->radio('Result.'.$val['id'], $options); 
     36          echo $form->radio('Result.'. $val['worth'] .' points, '.$val['question'], $options); 
    3537 
    3638          echo $html->para(null, $val['hint']); 
  • trunk/app/views/vclassrooms/admin_listing.ctp

    r396 r422  
    1010<?php 
    1111 
    12 $th = array ('Edit', 'Virtual classroom', 'View students', 'Status', 'Delete'); 
     12$th = array ('Edit', 'Virtual classroom', 'Status'); 
    1313echo $html->tableHeaders($th);   
    1414foreach ($data as $val) 
    1515{        
    16   $st = ( $val['Vclassroom']['status'] == 1 ) ? 'Active' : 'Filed';      
     16  $st = ( $val['Vclassroom']['status'] == 1 ) ? 'Enabled' : 'Filed';      
    1717       $tr = array ( 
    1818        $gags->sendEdit($val['Vclassroom']['id'], 'vclassrooms'), 
    19         $html->link($val['Vclassroom']['name'], '/admin/ecourses/vclassrooms/'.$val['Vclassroom']['id']) . ' <span class="petit">'.$val['Ecourse']['title'].'</span>', 
    20         $html->link('View students','/admin/vclassrooms/start/'.$val['Vclassroom']['id']), 
    21         $html->link('File','/admin/vclassrooms/change/'.$val['Vclassroom']['id'].'/'.$val['Vclassroom']['status']), 
    22         $gags->confirmDel($val['Vclassroom']['id'], 'vclassrooms') 
     19        $html->link($val['Vclassroom']['name'], '/admin/vclassrooms/members/'.$val['Vclassroom']['id']) . ' <span class="petit">'.$val['Ecourse']['title'].'</span>', 
     20        $html->link($st,'/admin/vclassrooms/change/'.$val['Vclassroom']['id'].'/'.$val['Vclassroom']['status']) 
     21        //$gags->confirmDel($val['Vclassroom']['id'], 'vclassrooms') 
    2322        ); 
    2423        
  • trunk/app/views/vclassrooms/admin_members.ctp

    r375 r422  
    4141} 
    4242 
    43 foreach ($data['User'] as $val) 
    44 { 
    45   // die(debug($val)); 
    46    $tmp  = '<b>Name</b>: '    . $val['name'] . '  ' . '<b> Username</b>:' . $val['username']                . '<br />'; 
    47    $tmp .= 'Email: '   . $html->link($val['email'], 'mailto:'.$val['email']) . '<br />'; 
    48    $tmp .= $html->div('butonright', $gags->confirmDel($val['id'], 'Vclassroom')); 
    49    
    50    echo $html->div('divgray', $tmp); 
    51 } 
    52  
     43echo '<table class="tbadmin">'; 
     44//die(print_r($data)); 
     45  
     46$th = array ('Name', 'Username', 'Send Message', 'Email', 'Undettach'); 
     47echo $html->tableHeaders($th);  
     48foreach ($data['User'] as $val): 
     49         $tr = array ( 
     50             $val['name'], 
     51             $val['username'], 
     52             $html->link($val['email'], 'mailto:'.$val['email']), 
     53                 $html->link('Compose', '/admin/messages/write/'.$val['id']), 
     54         $html->link('Undetach', '/admin/vclassroom/unlink/'.$val['id'].'/'.$data['Vclassroom']['id']) 
     55             ); 
     56      
     57     echo $html->tableCells($tr, array("class"=>"altRow", "onmouseover"=>"this.className='highlight'", "onmouseout"=>"this.className='altRow'"), array('class'=>'evenRow',"onmouseover"=>"this.className='highlight'", "onmouseout"=>"this.className='evenRow'")); 
     58endforeach; 
    5359?> 
     60</table> 
  • trunk/app/views/webquests/view.ctp

    r419 r422  
    22//die(debug($data)); 
    33$auth = false; 
    4   
     4 
    55if ( $session->check('vclassrooms') ): 
    66   foreach($data['Vclassroom'] as $v): 
    7        $auth = ( in_array($v['id'], $session->read('vclassrooms'))) ? true : false;  // students belongs this vclass ? 
     7       if ( in_array($v['id'], $session->read('vclassrooms'))): 
     8              $auth = true; 
     9          break; 
     10       endif; 
    811   endforeach; 
    912endif; 
     
    3740echo '</div>'; 
    3841 
     42echo $form->create('Result', array('onsubmit'=>'return chkForm()')); 
     43 
     44echo $form->label('Result.answer', 'Answer:').'<br />'; 
     45echo $form->textarea('Result.answer', array('cols'=>60, 'rows'=>20)); 
     46echo $form->end('Send'); 
     47 
    3948else: 
    4049     echo $html->link('Login to join this group', '/users/login');