Changeset 441

Show
Ignore:
Timestamp:
04/29/08 17:56:48 (8 months ago)
Author:
aarkerio
Message:

Treasure hunts

Location:
trunk/app
Files:
3 added
10 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/config/sql/postgresql/treasures.sql

    r436 r441  
    33  "id" serial PRIMARY KEY, 
    44  "title" varchar(150) NOT NULL, 
     5  "points" smallint NOT NULL DEFAULT 3,  
     6  "secret" varchar(15) NOT NULL,  -- secret word, stop   
    57  "instructions" text NOT NULL DEFAULT '', 
    68  "user_id" int NOT NULL REFERENCES users(id) ON DELETE CASCADE, 
  • trunk/app/controllers/treasures_controller.php

    r438 r441  
    1616  
    1717 public $components  = array('Edublog'); 
     18 
     19 public function beforeFilter() 
     20 { 
     21      $this->Auth->allow(array('view', 'chksw')); 
     22      parent::beforeFilter(); 
     23 } 
    1824 
    1925 public function isAuthorized()  
     
    2834    return false;  // go away !! 
    2935 } 
     36 public function  chksw() 
     37 { 
     38   $this->layout    = 'ajax'; 
     39 
     40   if ( !empty($this->data['ResultTreasure']) ) 
     41   { 
     42      $this->Sanitize = new Sanitize; 
     43            
     44      $this->Sanitize->clean($this->data['ResultTreasure']); 
     45 
     46      $secret = $this->Treasure->field('secret', array('status'=>1,'id'=>$this->data['ResultTreasure']['treasure_id'])); 
     47                  
     48      if ( $this->data['ResultTreasure']['secret'] ==  $secret ) 
     49      { 
     50        $this->data['ResultTreasure']['user_id'] = $this->Auth->user('id'); 
     51       
     52    $this->Treasure->ResultTreasure->save($this->data['ResultTreasure']); 
     53 
     54        $this->set('msg', 'Cool!, the '. $this->data['ResultTreasure']['points'] .' points are yours'); 
     55        $this->render('chksw', 'ajax'); 
     56      } 
     57      else 
     58      { 
     59          $this->set('msg', 'Sorry, word is incorrect'); 
     60      $this->render('chksw', 'ajax'); 
     61      }  
     62   } 
     63 } 
    3064                                                           
    3165 public function display($username) 
     
    5589 } 
    5690 
    57  public function view($username, $treasure_id) 
     91 public function view($treasure_id) 
    5892 {     
    5993      $conditions      = array("Treasure.status"=>1, "Treasure.id"=>$treasure_id); 
    6094       
    61       if ($username != null) 
    62       { 
    63             $user_id    = $this->Treasure->User->field('id', array("username"=>$username)); 
     95      $data            = $this->Treasure->find($conditions); 
     96     
     97      $this->layout    = $this->Edublog->layout($data['Treasure']['user_id']); 
     98       
     99      $this->pageTitle = 'Treasure Hunt'; 
     100       
     101      $this->Edublog->blog($data['Treasure']['user_id']); // blogger elements 
    64102             
    65             $conditions["user_id"] = $user_id; 
    66       } 
    67       else 
    68       { 
    69           $this->redirect('/');  // go away 
    70       } 
    71        
    72       $this->layout    = $this->Edublog->layout($user_id); 
    73        
    74       $this->Edublog->blog($user_id); // blogger elements 
    75        
    76       $this->pageTitle = $username . '\'s Treasures'; 
    77        
    78       $this->set('data', $this->Treasure->find($conditions));  
     103      $this->set('data', $data);  
    79104 } 
    80105 
  • trunk/app/controllers/users_controller.php

    r434 r441  
    2222    parent::beforeFilter(); 
    2323 
    24     if ( !empty($this->data['User']) ) 
     24    if ( !empty($this->data['User']['pwd']) ) 
    2525    { 
    2626        if ( strlen($this->data['User']['pwd']) < 5)   // only if pwd is big enough 
  • trunk/app/models/treasure.php

    r438 r441  
    1212   public $belongsTo = 'User'; 
    1313    
    14     public $hasAndBelongsToMany = array('Vclassroom' => 
     14  public $hasMany = array( 
     15                  'ResultTreasure' => 
     16                           array('className'     => 'ResultTreasure', 
     17                         'conditions'    => null, 
     18                     'foreignKey'    => 'treasure_id' 
     19                         ) 
     20                               ); 
     21 
     22   public $hasAndBelongsToMany = array('Vclassroom' => 
    1523                       array('className'             => 'Vclassroom', 
    1624                         'joinTable'             => 'treasures_vclassrooms', 
  • trunk/app/models/vclassroom.php

    r388 r441  
    6464                         'finderQuery'           => '', 
    6565                         'deleteQuery'           => '' 
     66                         ), 
     67                                        'Treasure' => 
     68                       array('className'             => 'Treasure', 
     69                         'joinTable'             => 'treasures_vclassrooms', 
     70                         'foreignKey'            => 'vclassroom_id', 
     71                         'associationForeignKey' => 'treasure_id', 
     72                         'conditions'            => '', 
     73                         'order'                 => '', 
     74                         'limit'                 => '', 
     75                         'unique'                => true, 
     76                         'finderQuery'           => '', 
     77                         'deleteQuery'           => '' 
    6678                         ) 
    6779                       ); 
  • trunk/app/views/treasures/admin_add.ctp

    r437 r441  
    1010<table style="width:100%;"> 
    1111<tr> 
    12 <td colspan="2"> 
     12 <td> 
    1313   <?php echo $form->input('Treasure.title', array("size" => 40, "maxlength" => 120)); ?> 
     14 </td> 
     15<td> 
     16   <?php 
     17    echo $form->label('Treasure.points', 'Points:');  
     18    echo $form->select('Treasure.points', array(1=>1,2=>2,3=>3,4=>4,5=>5,6=>6,7=>7,8=>8,9=>9,10=>10), 5, null, false);  
     19   ?> 
    1420 </td> 
    1521<td> 
     
    2531 
    2632</td></tr> 
     33<tr><td colspan="3"> 
     34   <?php echo $form->input('Treasure.secret', array('size'=>15, 'maxlength'=>15, 'between'=>': ')); ?> 
     35  </td> 
     36</tr> 
     37 
    2738<tr><td colspan="2"> 
    2839           <?php  
  • trunk/app/views/treasures/admin_edit.ctp

    r438 r441  
    1010<table> 
    1111<tr> 
    12 <td colspan="2"> 
     12<td> 
    1313  <?php echo $form->input('Treasure.title', array('size' => 40, 'maxlength' => 120)); ?> 
    1414</td> 
     15<td> 
     16   <?php 
     17    echo $form->label('Treasure.points', 'Points:');  
     18    echo $form->select('Treasure.points', array(1=>1,2=>2,3=>3,4=>4,5=>5,6=>6,7=>7,8=>8,9=>9,10=>10));  
     19   ?> 
     20 </td> 
    1521<td> 
    1622  <?php echo $html->link($html->image('admin/myimages.jpg', array("alt"=>"My Images", "title"=>"My Images")), '#', array("onclick"=>"javascript:window.open('/admin/images/listing/set', 'blank', 'toolbar=no, scrollbars=yes,width=700,height=500')"), null, false); ?> 
     
    1925 
    2026<tr><td colspan="3"> 
    21   <?php echo $form->label('Treasure.intructions', 'Instructions:');?><br /> 
    22   <?php echo $form->textarea('Treasure.instructions', array("cols"=>80, "rows"=>25)) ?> 
    23   <?php echo $fck->load('TreasureInstructions', 'Karamelo'); ?>  
     27  <?php  
     28   echo $form->label('Treasure.intructions', 'Instructions:'); 
     29   echo $form->textarea('Treasure.instructions', array("cols"=>80, "rows"=>25)); 
     30   echo $fck->load('TreasureInstructions', 'Karamelo');  
     31  ?>  
    2432</td></tr> 
     33 
     34<tr><td colspan="3"> 
     35   <?php echo $form->input('Treasure.secret', array('size'=>15, 'maxlength'=>15, 'between'=>': ')); ?> 
     36  </td> 
     37</tr> 
     38 
    2539<tr><td colspan="2"> 
    2640       <?php  
  • trunk/app/views/treasures/view.ctp

    r253 r441  
    1 <h2><?php echo $blog['User']['username']; ?>'s Treasures</h2> 
     1<?php 
     2//die(debug($data)); 
    23 
    3 <?php 
    4 echo '<div class="eport">';  
    5    echo '<div class="port_title">'             . $data['Treasure']['title']        . '</div>'; 
    6    echo '<div class="port_body">'              . $data['Treasure']['instructions'] . '</div>'; 
    7    echo '<div class="port_created"> Created: ' . $data['Treasure']['created']      . '</div>'; 
    8 echo '</div>'; 
     4$auth = false; 
     5 
     6if ( $session->check('vclassrooms') ): 
     7   foreach($data['Vclassroom'] as $v): 
     8       if ( in_array($v['id'], $session->read('vclassrooms'))): 
     9              $auth = true; 
     10              $vclassroom_id = $v['id'];  
     11          break; 
     12       endif; 
     13   endforeach; 
     14endif; 
     15  
     16if ( $auth === true ): 
     17  echo $html->para(null, 'hi! '.$cU['User']['username'], array('style'=>'font-weight:bold;font-size:12pt;')); 
     18  echo $html->div('title', $blog['User']['username'] .'s Treasure Hunt'); 
     19 
     20 
     21  echo '<h1>'. $data['Treasure']['title']  . '</h1>'; 
     22  echo $html->div(null, '<b>Points:</b> '.$data['Treasure']['points']); 
     23  echo $html->div(null, $data['Treasure']['instructions']); 
     24 
     25  // ajax beggins 
     26echo $ajax->div('loading',array('style'=>'display:none')).$html->image("static/loading.gif",array("alt"=>"Loading")).$ajax->divEnd('loading');  
     27   
     28  echo $ajax->form(); 
     29      
     30  echo $form->hidden('ResultTreasure.vclassroom_id', array('value'=>$vclassroom_id) ); 
     31  echo $form->hidden('ResultTreasure.treasure_id', array('value'=>$data['Treasure']['id'])); 
     32  echo $form->hidden('ResultTreasure.points', array('value'=>$data['Treasure']['points'])); 
     33  echo $form->input('ResultTreasure.secret', array('size' => 15, 'maxlength'=>15, 'title'=>'Secret code', 'between'=>': ')); 
     34  echo $ajax->submit('Send secret word '.$cU['User']['username'], array("url" => "/treasures/chksw/",  
     35                                         "update"=>"updater", 
     36                                         "loading" => "Element.show('loading');Element.hide('updater')", 
     37                                         "complete" => "Element.hide('loading');Effect.Appear('updater')" 
     38        )); 
     39 
     40  // empty ajax div 
     41  echo $ajax->div('updater') . $ajax->divEnd('updater'); 
     42  // ajax ends  
     43 
     44else: 
     45   echo $html->para(null, 'You must be logged in and belong to this class to see this page'); 
     46endif; 
     47 
    948?> 
     49 
     50<script type="text/javascript"> 
     51 
     52function chkTest() 
     53{ 
     54 
     55  var answer = confirm("Are you sure?") 
     56 
     57  if (answer) 
     58      return true 
     59  else 
     60      return false 
     61   
     62  return true; 
     63} 
     64</script> 
  • trunk/app/views/users/admin_edit.ctp

    r342 r441  
    11<?php  
     2//die( var_dump( $this->data ) );  
    23 
    34echo $javascript->link('myfunctions');  
    45 
    5 //die( var_dump( $this->data ) );  
    66if ($this->data["User"]["id"] != $cU['User']['id']) 
    77{ 
     
    3939  endif;  
    4040   
    41   echo $form->input('User.website', array("size"=>35, "maxlength"=>50));  
    42    
    4341  echo $form->label('User.layout', 'Layout:' );  
    44    
    4542  $designs = array('rubyx'=>'Rubyx', 'school'=>'School', 'paris'=>'Paris'); 
    46   echo $form->select('User.layout', $designs, null, null, null, false, false); 
     43  echo $form->select('User.layout', $designs, null, null, false); 
    4744   
    4845  echo $form->label('User.cv', 'Profile:' ); 
    49   echo $form->textarea('User.cv', array("cols" => 45, "rows" => 5)); 
    50   echo $form->error('User.cv', 'CV is required.'); 
     46  echo $form->textarea('User.cv', array("cols" => 70, "rows" => 7)); 
    5147   
    52   echo $form->input('User.quote', array("size" => 40, "maxlength" => 150)); 
    53   echo $form->error('User.quote', 'A name is required.');  
     48  echo $form->input('User.quote', array("size" => 70, "maxlength" => 150)); 
    5449   
    5550  echo $form->input('User.name_blog', array("size" => 45, "maxlength" => 150));  
    56   echo $form->error('User.name_blog', 'A name_blog is required.'); 
    57    
     51    
    5852  echo $form->label('User.newsletter', 'Subscribe to newsletter:' ); 
    5953  echo $form->checkbox('User.newsletter', array("value" => 1));  
    6054   
    61   echo '</fieldset>'; 
    6255  echo $form->end('Save');  
    6356 ?> 
    64  
     57</fieldset> 
    6558</div> 
    6659 
  • trunk/app/views/vclassrooms/show.ctp

    r419 r441  
    5050       } 
    5151     } 
     52 
     53     if ( count($data['Treasure']) > 0) 
     54     { 
     55       echo $html->div('titentry', 'Treasure Hunts'); 
     56 
     57       foreach($data['Treasure'] as $t) 
     58       { 
     59         echo $html->para(null, $html->link($t['title'], '/treasures/view/'.$t['id'])); 
     60       } 
     61     } 
    5262  } 
    5363