[virtualcommons-svn] SF.net SVN: virtualcommons:[15] vcweb/trunk/virtualcommons/experiment
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2008-07-30 18:48:23
|
Revision: 15 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=15&view=rev Author: alllee Date: 2008-07-30 18:48:28 +0000 (Wed, 30 Jul 2008) Log Message: ----------- merging studentgroup and teacher_experiments modules into experiment core Added Paths: ----------- vcweb/trunk/virtualcommons/experiment/core/ vcweb/trunk/virtualcommons/experiment/core/experiment.info vcweb/trunk/virtualcommons/experiment/core/experiment.install vcweb/trunk/virtualcommons/experiment/core/experiment.module Removed Paths: ------------- vcweb/trunk/virtualcommons/experiment/studentgroup/ vcweb/trunk/virtualcommons/experiment/teacher_experiments/ Added: vcweb/trunk/virtualcommons/experiment/core/experiment.info =================================================================== --- vcweb/trunk/virtualcommons/experiment/core/experiment.info (rev 0) +++ vcweb/trunk/virtualcommons/experiment/core/experiment.info 2008-07-30 18:48:28 UTC (rev 15) @@ -0,0 +1,6 @@ +; $Id$ +name = Experiment Core +description = Provides core essential experiment functionality and metadata +package=Virtual Commons +version = "$Rev$" + Added: vcweb/trunk/virtualcommons/experiment/core/experiment.install =================================================================== --- vcweb/trunk/virtualcommons/experiment/core/experiment.install (rev 0) +++ vcweb/trunk/virtualcommons/experiment/core/experiment.install 2008-07-30 18:48:28 UTC (rev 15) @@ -0,0 +1,292 @@ +<?php +// vim:sts=2:sw=2:filetype=php +// $Id$ +/** + * Implementation of hook_install(). + */ +function experiment_install() { + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + db_query("CREATE TABLE {virtualcommons_student} + ( + id varchar(14) NOT NULL, + group_no int NOT NULL, + virtualcommons_conducts_id int NOT NULL, + start_flag BOOL default false, + turn_no varchar(1) NOT NULL, + + PRIMARY KEY(id), + + FOREIGN KEY(virtualcommons_conducts_id) REFERENCES virtualcommons_conducts(id) + ON DELETE CASCADE + + ) TYPE=InnoDB /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + db_query("CREATE TABLE {virtualcommons_forestry_common_resource_pool} + ( + id int NOT NULL AUTO_INCREMENT, + virtualcommons_student_group_no int NOT NULL, + common_resource_pool int NOT NULL, + harvest_decision int NOT NULL, + virtualcommons_conducts_id int NOT NULL, + max_harvest_decision int NOT NULL, + + + + PRIMARY KEY(id), + FOREIGN KEY(virtualcommons_student_group_no) REFERENCES virtualcommons_student(group_no) + ON DELETE CASCADE, + + FOREIGN KEY(virtualcommons_conducts_id) REFERENCES virtualcommons_conducts(id) + ON DELETE CASCADE + + + + ) /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + + + + db_query("CREATE TABLE {virtualcommons_forestry_group_information} + ( + id int NOT NULL AUTO_INCREMENT, + round_no int NOT NULL, + virtualcommons_conducts_id int NOT NULL, + virtualcommons_student_group_no int NOT NULL, + total_harvest_decision int NOT NULL, + resources_before int NOT NULL, + resources_after int NOT NULL, + virtualcommons_stage_no int NOT NULL, + virtualcommons_rules_no int(1), + dice int(1) , + + + PRIMARY KEY(id), + FOREIGN KEY(virtualcommons_student_group_no) REFERENCES virtualcommons_student(group_no) + ON DELETE CASCADE, + + FOREIGN KEY(virtualcommons_conducts_id) REFERENCES virtualcommons_conducts(id) + ON DELETE CASCADE, + + FOREIGN KEY(virtualcommons_stage_no) REFERENCES virtualcommons_stage(stage_no) + ON DELETE CASCADE, + + FOREIGN KEY(virtualcommons_rules_no) REFERENCES virtualcommons_rules(rule_no) + ON DELETE CASCADE + + + ) /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + //Forestry Game Harvest Tables. + db_query("CREATE TABLE {virtualcommons_forestry_5player_harvest_table} ( + id int NOT NULL AUTO_INCREMENT, + min_resource_level int NOT NULL, + max_resource_level int NOT NULL, + individual_harvest_level int NOT NULL, + + PRIMARY KEY(id) + + ) /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + + db_query("Insert into {virtualcommons_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(25,100,5)"); + db_query("Insert into {virtualcommons_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(20,24,4)"); + db_query("Insert into {virtualcommons_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(15,19,3)"); + db_query("Insert into {virtualcommons_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(10,14,2)"); + db_query("Insert into {virtualcommons_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(5,9,1)"); + db_query("Insert into {virtualcommons_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(0,4,0)"); + + + + db_query("CREATE TABLE {virtualcommons_forestry_4player_harvest_table} ( + id int NOT NULL AUTO_INCREMENT, + min_resource_level int NOT NULL, + max_resource_level int NOT NULL, + individual_harvest_level int NOT NULL, + + PRIMARY KEY(id) + + ) /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + + db_query("Insert into {virtualcommons_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(20,80,5)"); + db_query("Insert into {virtualcommons_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(16,19,4)"); + db_query("Insert into {virtualcommons_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(12,15,3)"); + db_query("Insert into {virtualcommons_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(8,11,2)"); + db_query("Insert into {virtualcommons_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(4,7,1)"); + db_query("Insert into {virtualcommons_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(0,3,0)"); + + db_query("CREATE TABLE {virtualcommons_forestry_3player_harvest_table} ( + id int NOT NULL AUTO_INCREMENT, + min_resource_level int NOT NULL, + max_resource_level int NOT NULL, + individual_harvest_level int NOT NULL, + + PRIMARY KEY(id) + + ) /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + db_query("Insert into {virtualcommons_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(15,60,5)"); + db_query("Insert into {virtualcommons_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(12,14,4)"); + db_query("Insert into {virtualcommons_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(9,11,3)"); + db_query("Insert into {virtualcommons_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(6,8,2)"); + db_query("Insert into {virtualcommons_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(3,5,1)"); + db_query("Insert into {virtualcommons_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(0,2,0)"); + + // old teacher_experiment install + db_query("CREATE TABLE {virtualcommons_conducts} ( + id int NOT NULL AUTO_INCREMENT, + users_id int NOT NULL, + virtualcommons_experiments_id int NOT NULL, + date DATE NOT NULL, + no_of_students int NOT NULL, + virtualcommons_stage_no int default 1, + virtualcommons_rule_no int default 0, + + PRIMARY KEY(id), + + FOREIGN KEY(users_id) REFERENCES users(id) + ON DELETE CASCADE, + + FOREIGN KEY(virtualcommons_experiments_id) REFERENCES virtualcommons_experiments(id) + ON DELETE CASCADE, + + FOREIGN KEY(virtualcommons_stage_no) REFERENCES virtualcommons_stage(stage_no) + ON DELETE CASCADE, + + FOREIGN KEY(virtualcommons_rule_no) REFERENCES virtualcommons_rules(rule_no) + ON DELETE CASCADE + + + ) /*!40100 DEFAULT CHARACTER SET UTF8 */"); + $flag=TRUE; + + break; + case 'pgsql': + db_query("CREATE TABLE {virtualcommons_student} ( + + id varchar(14) NOT NULL, + group_no int NOT NULL, + virtualcommons_conducts_id int NOT NULL, + + PRIMARY KEY(id), + + FOREIGN KEY(virtualcommons_conducts_id) REFERENCES virtualcommons_conducts(id) + ON DELETE CASCADE + )"); + + //Forestry Game Harvest Tables. + db_query("CREATE TABLE {virtualcommons_forestry_5player_harvest_table} ( + id int NOT NULL AUTO_INCREMENT, + min_resource_level int NOT NULL, + max_resource_level int NOT NULL, + individual_harvest_level int NOT NULL, + + PRIMARY KEY(id) + + ) /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + + db_query("Insert into {virtualcommons_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(25,100,5)"); + db_query("Insert into {virtualcommons_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(20,24,4)"); + db_query("Insert into {virtualcommons_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(15,19,3)"); + db_query("Insert into {virtualcommons_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(10,14,2)"); + db_query("Insert into {virtualcommons_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(5,9,1)"); + db_query("Insert into {virtualcommons_forestry_5player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(0,4,0)"); + + + + db_query("CREATE TABLE {virtualcommons_forestry_4player_harvest_table} ( + id int NOT NULL AUTO_INCREMENT, + min_resource_level int NOT NULL, + max_resource_level int NOT NULL, + individual_harvest_level int NOT NULL, + + PRIMARY KEY(id) + + ) /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + + db_query("Insert into {virtualcommons_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(20,80,5)"); + db_query("Insert into {virtualcommons_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(16,19,4)"); + db_query("Insert into {virtualcommons_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(12,15,3)"); + db_query("Insert into {virtualcommons_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(8,11,2)"); + db_query("Insert into {virtualcommons_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(4,7,1)"); + db_query("Insert into {virtualcommons_forestry_4player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(0,3,0)"); + + + + + db_query("CREATE TABLE {virtualcommons_forestry_3player_harvest_table} ( + id int NOT NULL AUTO_INCREMENT, + min_resource_level int NOT NULL, + max_resource_level int NOT NULL, + individual_harvest_level int NOT NULL, + + PRIMARY KEY(id) + + ) /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + db_query("Insert into {virtualcommons_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(15,60,5)"); + db_query("Insert into {virtualcommons_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(12,14,4)"); + db_query("Insert into {virtualcommons_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(9,11,3)"); + db_query("Insert into {virtualcommons_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(6,8,2)"); + db_query("Insert into {virtualcommons_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(3,5,1)"); + db_query("Insert into {virtualcommons_forestry_3player_harvest_table} (min_resource_level,max_resource_level,individual_harvest_level) values(0,2,0)"); + + //assign the students turn for stage 2 of forestry + db_query("CREATE TABLE {virtualcommons_forestry_student_turn} ( + id int NOT NULL AUTO_INCREMENT, + virtualcommons_student_id varchar(14) NOT NULL, + virtualcommons_stage_id int NOT NULL, + virtualcommons_student_group_no int NOT NULL, + + + PRIMARY KEY(id), + + FOREIGN KEY(virtualcommons_student_id) REFERENCES virtualcommons_student(id) + ON DELETE CASCADE, + + FOREIGN KEY(virtualcommons_stage_id) REFERENCES virtualcommons_stage(id) + ON DELETE CASCADE, + + FOREIGN KEY(virtualcommons_student_group_no) REFERENCES virtualcommons_student(group_no) + ON DELETE CASCADE + + + ) /*!40100 DEFAULT CHARACTER SET UTF8 */"); + + + + $flag=TRUE; + + + + break; + default: + drupal_set_message(t('Unsupported Database')); + } + if($flag) + { + drupal_set_message(t('Student database is successfully created.')); + } + else + { + drupal_set_message(t('Student database is NOT successfully created.'),'error'); + } +} + +/** + * Implementation of hook_uninstall(). + */ +function experiment_uninstall() { + db_query("DROP TABLE {virtualcommons_student}"); + db_query("DROP TABLE {virtualcommons_forestry_common_resource_pool}"); + db_query("DROP TABLE {virtualcommons_forestry_3player_harvest_table}"); + db_query("DROP TABLE {virtualcommons_forestry_4player_harvest_table}"); + db_query("DROP TABLE {virtualcommons_forestry_5player_harvest_table}"); + db_query("DROP TABLE {virtualcommons_forestry_group_information}"); + db_query("DROP TABLE {virtualcommons_conducts}"); + drupal_set_message(t('Experiment core tables were successfully deleted from the database. We hope.')); +} Added: vcweb/trunk/virtualcommons/experiment/core/experiment.module =================================================================== --- vcweb/trunk/virtualcommons/experiment/core/experiment.module (rev 0) +++ vcweb/trunk/virtualcommons/experiment/core/experiment.module 2008-07-30 18:48:28 UTC (rev 15) @@ -0,0 +1,494 @@ +<?php +// vim:sts=2:sw=2:filetype=php +// $Id$ + +//$path=drupal_get_filename('module', 'virtualcommons'); +//include('teacher.php'); // or require etc. +//include('sites/all/modules/virtualcommons/teacher_experiments/class_files/teacher.php'); + +/** + * implements the _user hook. + **/ + + + +function teacher_experiments_perm() +{ + return array('Only Teachers'); + +} + +// $Id$ +/** + * Implementation of hook_menu(). + */ +function teacher_experiments_menu($may_cache) { + $items = array(); + if ($may_cache) { + $items[] = array( + 'path' => 'teacher_experiments', + 'title' => t('Experiments'), + 'callback' => 'teacher_experiments_page', + 'type'=>MENU_CALLBACK, + 'access' => user_access('Only Teachers') + ); + $items[] = array( + 'path' => 'studentgroup', + 'title' => t('Student Information'), + 'callback' => 'drupal_get_form', + 'callback arguments'=>array(studentgroup), + 'type'=>MENU_CALLBACK, + 'access' => user_access('Only Teachers') + ); + $items[]=array( 'path' => 'game_start', + // 'title' => t('Forestry Game - Stage 1'), + 'callback'=>'game_start', + // 'callback argument' => array('forestry_game_stage1_part2'), + 'type'=>MENU_CALLBACK, + 'access' => user_access('Only Teachers') + ); + } + return $items; +} +/** + * Called when user goes to example.com/?q=teacher_experiments + */ +function teacher_experiments_page() { + $output = t('Please submit the following form in order to conduct the experiments in the class.'); + // Return the HTML generated from the $form data structure. + $output .= drupal_get_form('teacher_experiments_nameform'); + return $output; +} +/** + * Defines a form. + */ +function teacher_experiments_nameform() { + + $form['#method']='post'; + //+$form['#action']='http://localhost/drupal/?q=studentgroup'; + $form['#id']='teacher_experiments'; + $form['no_student'] = array( + '#title' => t('How many Students are participating'), + '#type' => 'textfield', + '#description' => t('Depending on the number of students groups will be formed.'), + '#required'=>TRUE + + ); + + $form['games']=array( + '#type'=>'select', + '#title'=>'Select the Game from the following experiments', + '#default_value'=>variable_get('games',0), + '#options'=> array(t('Choose One '),t('Fishery Game'),t('Forestry Game'),t('Water Irrigation Game')), + '#required'=>TRUE + + ); + + + $form['terms_usage']=array( + '#type'=>'fieldset', + //'#title'=>t('Terms of Usage') + ); + + + $form['terms_usage']['info']=array( + + '#type'=>'item', + '#title'=>t('Terms and conditions'), + '#description'=>t('<p>Material on this site is used only for educational purpose. None of the material on this site may be used for any other purpose. <br/>All rights reserved and granted by Dr Marco Janssen.</p>') + ); + + + $form['terms_usage']['agree'] = array( + '#type' => 'radios', + '#options' => array(t('I Agree'),t('I Disagree')), + '#title'=>t('By selecting the "I Agree" option, you certifiy that you are agree above terms of use'), + '#default_value'=>variable_get('agree',1), + + + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + + + + return $form; +} +/** + * Validate the form. + */ +function teacher_experiments_nameform_validate($form_id, $form_values) +{ + + // We notify the form API that this field has failed validation. + if ($form_values['games'] == 0) + { + form_set_error('games', + t('Please choose the game.')); + } + if($form_values['agree']==1) + { + form_set_error('agree',t('You have to agree the terms before you play any game.')); + } + + //To Check for numbers. + if(preg_match('/[^0-9]+/',$form_values['no_student'])) + { + form_set_error('no_student',t('Number of experiments can not be alphabets. ')); + } + +} +/** + * Handle post-validation form submission. + */ +function teacher_experiments_nameform_submit($form_id, $form_values) +{ + $teacher_id=$GLOBALS['user']->uid; + $game_name=$form_values['games']; + $no_student=$form_values['no_student']; + if(!isset($_SESSION['no_of_student'])) + { + $_SESSION['no_student']=$no_student; + } + + + if(!isset($_SESSION['game_name'])) + { + $_SESSION['game_name']=$game_name; + } + + + //Fishery + if($game_name==1) + { + $result=db_result(db_query("Select id from {virtualcommons_experiments} where exp_name LIKE '%%Fishery%%' ")); + } + //Forestry + else if($game_name==2) + { + $result=db_result(db_query("Select id from {virtualcommons_experiments} where exp_name LIKE '%%Forestry%%' ")); + } + + //Water Irrigation + else if($game_name==3) + { + $result=db_result(db_query("Select id from {virtualcommons_experiments} where exp_name LIKE '%%Water%%' ")); + } + + /*$teacher=new Teacher($result,'talele'); + $fname=$teacher->getfname(); + $lname=$teacher->getlname();*/ + + + drupal_set_message(t('Thanks for filling out the form. Your Game will start soon. ')); + + db_query("Insert into {virtualcommons_conducts} (users_id, virtualcommons_experiments_id ,date, no_of_students ) values(%d,%d,NOW(),%d)",$teacher_id,$result,$no_student); + //echo 'Thanks for filling out the form. Your Game will start soon,'. $fname; + return 'studentgroup'; +} + +/** Old studentgroup module code cut'n'paste job */ +/** + * Called when user goes to example.com/?q=studentgroup + */ + +function studentgroup() +{ + + $form['#id']='studentgroup'; + $exp_name=$_SESSION['game_name']; + $no=$_SESSION['no_student']; + //unset($_SESSION['game_name']); + unset($_SESSION['no_student']); + + //drupal_set_message(t('Game name is %exp_name .<br> No of Students are %no',array('%exp_name'=>$exp_name,'%no'=>$no))); + if($exp_name==1) + $exp_name="Fishery Game"; + else if($exp_name==2) + $exp_name="Forestry Game"; + else if($exp_name==3) + $exp_name="Water Irrigation Game"; + + //$no=$_POST['no_student']; + $no_of_student=(int)$no; + $no_of_groups=0; + $groups_3=0; + $groups_4=0; + $groups_5=0; + $header = array('Group ID', 'Student ID'); + + //no of groups + $groups_5=((int)($no_of_student/5)); + + $x= $no_of_student%5; + + if($x==0) + { + $no_of_groups=$groups_5; + } + else if($x==1) + { + $groups_5=$groups_5-1; + $groups_3=2; + $no_of_groups=$groups_5 + $groups_3; + } + + else if($x==2) + { + $groups_5=$groups_5-1; + $groups_3=1; + $groups_4=1; + $no_of_groups=$groups_5 + $groups_3 + $groups_4; + } + else if($x==3) + { + + $groups_3=1; + $no_of_groups=$groups_3 + $groups_5; + } + + else if($x==4) + { + + $groups_4=1; + $no_of_groups=$groups_4 + $groups_5; + } + + $no_student5=5*$groups_5; + $no_student4=4*$groups_4; + $no_student3=3*$groups_3; + + $var=10; + $group_no=1; + + if($groups_5 <> 0) + { + for($i=0;$i<$groups_5;$i++) + { + for($j=0;$j<5;$j++) + { + $stud_id=uniqid(rand(0,9), false); + $row[]=array('Group '.$group_no,$stud_id); + $row_submit[]=array($group_no,$stud_id); + + } + + $group_no++; + } + } + if($groups_4 <> 0) + { + for($i=0;$i<$groups_4;$i++) + { + for($j=0;$j<4;$j++) + { + $stud_id=uniqid(rand(0,9),false); + $row[]=array('Group '.$group_no,$stud_id); + $row_submit[]=array($group_no,$stud_id); + + } + + $group_no++; + } + } + if($groups_3 <> 0) + { + for($i=0;$i<$groups_3;$i++) + { + for($j=0;$j<3;$j++) + { + $stud_id=uniqid(rand(0,9), false); + $row[]=array('Group '.$group_no,$stud_id); + $row_submit[]=array($group_no,$stud_id); + } + $group_no++; + } + } + + + if(!isset($_SESSION['student_info'])) + { + $_SESSION['student_info']=$row_submit; + /*foreach ($_SESSION['student_info'] as $key=>$value) + { + drupal_set_message(t('Key is: %key<br>',array('%key'=>$key))); + foreach ($value as $key=>$value) + { + drupal_set_message(t('Key inner is: %key<br> Value inner is: %value',array('%key'=>$key,'%value'=>$value))); + } + }*/ + } + + + $form['game_info']=array( + '#type'=>'fieldset', + '#title'=>t('Experiment Information'), + '#tree' => TRUE + ); + + + $form['game_info']['info']=array( + '#title'=>t('Please note the following information carefully.'), + '#type'=>'item', + '#description'=>t('<h3>Name of Experiments: '.$exp_name.'<br/>No of Students: '.$no_of_student.'<br/>No of Groups: '.$no_of_groups.'</h3>') + ); + + $form['group_info']=array( + '#type'=>'fieldset', + '#title'=>t('Group Information'), + '#tree' => TRUE + ); + + $form['group_info']['info1']=array( + '#title'=>t('Please assign the following Student IDs to the students.Please do not tell Group IDs to them. After assigning Student IDs, you can tell students to sign using Student Login Page.'), + '#description'=>t('<h3>Number of group of 3 Students: '.$groups_3.'<br/>Number of group of 4 Students: '.$groups_4.'<br/>Number of group of 5 Students: '.$groups_5.'</h3>'), + '#type'=>'item' + + ); + + $form['group_info']['table_info']=array( + + '#type'=>'markup', + '#value'=>theme('table',$header,$row) + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Start Game!!!') + ); + + return $form; +} + + + +function studentgroup_submit($form_id, $form_values) +{ + //put it in the database student + + $id=$GLOBALS['user']->uid; + $table=$_SESSION['student_info']; + $virtual_conduct_id=db_result(db_query("select max(id),users_id from {virtualcommons_conducts} where users_id=%d group by users_id",$id)); + $turn=array('1','2','3','4','5'); + $prev_group_no=0; + $temp=-1; + $i=0; + foreach ($table as $key=>$value) + { + + drupal_set_message(t('Key is: %key<br>',array('%key'=>$i))); + foreach ($value as $key=>$value) + { + + if($key==0) + { + $group_no=$value; + if($temp <> $group_no) + { + $temp=$group_no; + $i=0; + } + + + } + else if($key==1) + { + $stud_id=$value; + drupal_set_message(t('Group Id is %group Student id is: %value Turn id is %turn',array('%turn'=>$turn[$i],'%value'=>$stud_id,'%group'=>$group_no))); + db_query("Insert into {virtualcommons_student} (id,group_no,virtualcommons_conducts_id,start_flag,turn_no) values('%s',%d,%d,false,%d)",$stud_id,$group_no,$virtual_conduct_id,$turn[$i]); + + + /* db_query("insert into {virtualcommons_forestry_student_turn} + (turn_no,virtualcommons_student_id,virtualcommons_stage_id,virtualcommons_student_group_no) + values('%s','%s',2,%d)",$turn[$i],$stud_id,$group_no);*/ + + $i++; + + } + + } + } + + //depending upon the experiment game, assign the resource table to each group. + $exp_name=$_SESSION['game_name']; + if($exp_name==1) + { + //$exp_name="Fishery Game"; + + } + + else if($exp_name==2) + { + //$exp_name="Forestry Game"; + $result_group=db_query("select count(group_no) AS cnt,group_no from {virtualcommons_student} where virtualcommons_conducts_id= %d group by group_no",$virtual_conduct_id); + + while($data=db_fetch_object($result_group)) + { + $no_of_student=$data->cnt; + $group_no=$data->group_no; + //drupal_set_message(t($no_of_student.' '. $group_no)); + if($no_of_student == 5) + { + db_query("Insert into {virtualcommons_forestry_common_resource_pool} (virtualcommons_student_group_no,common_resource_pool,virtualcommons_conducts_id, harvest_decision,max_harvest_decision) + values(%d,%d,%d,%d,%d)",$group_no,100,$virtual_conduct_id,0,100); + + } + + else if($no_of_student == 4) + { + db_query("Insert into {virtualcommons_forestry_common_resource_pool} (virtualcommons_student_group_no,common_resource_pool,virtualcommons_conducts_id, harvest_decision,max_harvest_decision) + values(%d,%d,%d,%d,%d)",$group_no,80,$virtual_conduct_id,0,80); + } + + + else if($no_of_student == 3) + { + db_query("Insert into {virtualcommons_forestry_common_resource_pool} (virtualcommons_student_group_no,common_resource_pool,virtualcommons_conducts_id, harvest_decision,max_harvest_decision) values(%d,%d,%d,%d,%d)",$group_no,60,$virtual_conduct_id,0,60); + } + + } + + } + else if($exp_name==3) + { + $exp_name="Water Irrigation Game"; + } + + unset($_SESSION['student_info']); + unset($_SESSION['game_name']); + + return 'game_start'; + +} + + + + +function game_start() +{ + $output=t('Please click the Start Game button.'); + $output.=drupal_get_form('game_start_form'); + return $output; +} + + +function game_start_form() +{ + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Start Game!!!') + ); + return $form; +} + +function game_start_form_submit($form_id,$form_values) +{ + $teacher_id=$GLOBALS['user']->uid; + $virtual_conduct_id=db_result(db_query("select max(id),users_id from {virtualcommons_conducts} where users_id=%d group by users_id",$teacher_id)); + + db_query("update virtualcommons_student set start_flag=true where virtualcommons_conducts_id=%d",$virtual_conduct_id); + return 'teacher_dashboard'; +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |