diff -Naur moodle/admin/roles/tabs.php moodle-conditionals/admin/roles/tabs.php
--- moodle/admin/roles/tabs.php	2009-05-05 01:06:52.000000000 +0100
+++ moodle-conditionals/admin/roles/tabs.php	2009-09-16 13:38:34.000000000 +0100
@@ -190,6 +190,24 @@
                         true);
     }
 
+    /// START COMMENTS
+    if ($context->contextlevel == CONTEXT_MODULE && has_capability('moodle/local:assigncomments', $context)) {
+        $toprow[] = new tabobject('info',
+            $CFG->wwwroot.'/course/conditional/activityinfo.php?id='.$cm->id,
+            get_string('activityinfo', 'conditional'),
+            '', true);
+    }
+    /// END COMMENTS
+
+    /// START CONDITIONALS
+    if ($context->contextlevel == CONTEXT_MODULE && has_capability('moodle/local:createconditionals', $context)) {
+        $toprow[] = new tabobject('locks',
+            $CFG->wwwroot.'/course/conditional/conditions.php?id='.$cm->id,
+            get_string('activitylocks', 'conditional'),
+            '', true);
+    }
+    /// END CONDITIONALS
+
 }
 
 /// Here other core tabs should go (always calling tabs.php files)
diff -Naur moodle/backup/backuplib.php moodle-conditionals/backup/backuplib.php
--- moodle/backup/backuplib.php	2009-05-08 01:06:38.000000000 +0100
+++ moodle-conditionals/backup/backuplib.php	2009-09-16 13:38:34.000000000 +0100
@@ -730,6 +730,15 @@
             fwrite ($bf,full_tag("ENROLENDDATE",3,false,$course->enrolenddate));
             fwrite ($bf,full_tag("ENROLPERIOD",3,false,$course->enrolperiod));
 
+            /// START COMMENTS
+            fwrite ($bf,full_tag("USELABEL",3,false,$course->uselabel));
+            fwrite ($bf,full_tag("PERSONALIZEDLABEL",3,false,$course->personalizedlabel));
+            /// END COMMENTS
+
+            /// START CONDITIONALS
+            fwrite ($bf,full_tag("USECONDITIONALS",3,false,$course->useconditionals));
+            /// END CONDITIONALS
+
             /// write local course overrides here?
             write_role_overrides_xml($bf, $context, 3);
             /// write role_assign code here
@@ -1242,6 +1251,35 @@
                fwrite ($bf,full_tag("GROUPINGID",6,false,$course_module->groupingid));
                fwrite ($bf,full_tag("GROUPMEMBERSONLY",6,false,$course_module->groupmembersonly));
                fwrite ($bf,full_tag("IDNUMBER",6,false,$course_module->idnumber));
+
+               /// START COMMENTS
+               fwrite ($bf,full_tag("INFO",6,false,$course_module->info));
+               /// END COMMENTS
+
+               /// START CONDITIONALS
+               if ($conditional = get_record('conditional', 'moduleid', $tok)) {
+                   fwrite ($bf,start_tag('CONDITIONAL',6,true));
+                   fwrite ($bf,full_tag("DETAILS",7,false,$conditional->details));
+                   fwrite ($bf,full_tag("INUSE",7,false,$conditional->inuse));
+                   if ($conditions = get_records('conditional_member', 'conditionalid', $conditional->id)) {
+                       fwrite ($bf,start_tag('CONDITIONS',7,true));
+                       foreach ($conditions as $condition) {
+                           fwrite ($bf,start_tag('CONDITION',8,true));
+                           fwrite ($bf,full_tag("ID",9,false,$condition->id));
+                           fwrite ($bf,full_tag("TYPE",9,false,$condition->type));
+                           fwrite ($bf,full_tag("SUBTYPE",9,false,$condition->subtype));
+                           fwrite ($bf,full_tag("INSTANCE",9,false,$condition->instance));
+                           fwrite ($bf,full_tag("OP",9,false,$condition->op));
+                           fwrite ($bf,full_tag("VALUE",9,false,$condition->value));
+                           fwrite ($bf,full_tag("TABLEID",9,false,$condition->tableid));
+                           fwrite ($bf,end_tag("CONDITION",8,true));
+                       }
+                       fwrite ($bf,end_tag("CONDITIONS",7,true));
+                   }
+                   fwrite ($bf,end_tag("CONDITIONAL",6,true));
+               }
+               /// END CONDITIONALS
+
                // get all the role_capabilities overrides in this mod
                write_role_overrides_xml($bf, $context, 6);
                /// write role_assign code here
diff -Naur moodle/backup/restorelib.php moodle-conditionals/backup/restorelib.php
--- moodle/backup/restorelib.php	2009-05-11 01:06:30.000000000 +0100
+++ moodle-conditionals/backup/restorelib.php	2009-09-16 13:38:34.000000000 +0100
@@ -232,20 +232,20 @@
         }
 
         // For each block, call its encode_content_links method
-        static $blockobjects = null; 
-        if (!isset($blockobjects)) { 
-            $blockobjects = array(); 
-            if ($blocks = get_records('block', 'visible', 1)) { 
-                foreach ($blocks as $block) { 
+        static $blockobjects = null;
+        if (!isset($blockobjects)) {
+            $blockobjects = array();
+            if ($blocks = get_records('block', 'visible', 1)) {
+                foreach ($blocks as $block) {
                     if ($blockobject = block_instance($block->name)) {
-                        $blockobjects[] = $blockobject; 
+                        $blockobjects[] = $blockobject;
                     }
                 }
             }
         }
-        
-        foreach ($blockobjects as $blockobject) { 
-            $content = $blockobject->decode_content_links($content,$restore); 
+
+        foreach ($blockobjects as $blockobject) {
+            $content = $blockobject->decode_content_links($content,$restore);
         }
 
         return $content;
@@ -847,6 +847,16 @@
                 $course->theme = '';
             }
 
+            /// START COMMENTS
+            $course->uselabel = isset($course_header->course_uselabel) ? addslashes($course_header->course_uselabel) : 0;
+            $course->personalizedlabel = isset($course_header->course_personalizedlabel) ? addslashes($course_header->course_personalizedlabel) : '';
+
+            /// END COMMENTS
+
+            /// START CONDITIONALS
+            $course->useconditionals = isset($course_header->course_useconditionals) ? addslashes($course_header->course_useconditionals) : 0;
+            /// END CONDITIONALS
+
             //Now insert the record
             $newid = insert_record("course",$course);
             if ($newid) {
@@ -1024,7 +1034,7 @@
 
                     // This will only be set if we come from 1.7 and above backups
                     //  Also, must do this before insert (insert_record unsets id)
-                    if (!empty($instance->id)) { 
+                    if (!empty($instance->id)) {
                         $oldid = $instance->id;
                     } else {
                         $oldid = 0;
@@ -1195,6 +1205,11 @@
                                             $course_module->groupingid = 0;
                                         }
                                         $course_module->groupmembersonly = $mod->groupmembersonly;
+
+                                        /// START COMMENTS
+                                        $course_module->info = backup_todb($mod->info);
+                                        /// END COMMENTS
+
                                         $course_module->instance = 0;
                                         //NOTE: The instance (new) is calculated and updated in db in the
                                         //      final step of the restore. We don't know it yet.
@@ -1215,6 +1230,23 @@
                                                           $keym,$newidmod,$mod->instance);
 
                                             $restore->mods[$mod->type]->instances[$mod->instance]->restored_as_course_module = $newidmod;
+
+                                            /// START CONDITIONALS
+                                            if ($mod->conditional) {
+                                                $conditional->moduleid = $newidmod;
+                                                $conditional->details = $mod->conditional->details;
+                                                $conditional->inuse = $mod->conditional->inuse;
+                                                $newidconditional = insert_record('conditional', $conditional);
+                                                if (isset($mod->conditional->conditions)) {
+                                                    foreach ($mod->conditional->conditions as $condition) {
+                                                        $tempcondition = $condition;
+                                                        $tempcondition->conditionalid = $newidconditional;
+                                                        insert_record('conditional_member', $tempcondition);
+                                                    }
+                                                }
+                                            }
+                                            /// END CONDITIONALS
+
                                         } else {
                                             $status = false;
                                         }
@@ -1922,7 +1954,7 @@
                                 $oldoutcome = backup_todb($info['GRADE_ITEM']['#']['OUTCOMEID']['0']['#']);
                                 if (empty($outcomes[$oldoutcome])) {
                                     continue; // error!
-                                } 
+                                }
                                 if (empty($outcomes[$oldoutcome]->id)) {
                                     $outcomes[$oldoutcome]->insert('restore');
                                     $outcomes[$oldoutcome]->use_in($restore->course_id);
@@ -2025,7 +2057,7 @@
 
 
         if ($status and !$importing and $restore_histories) {
-            /// following code is very inefficient 
+            /// following code is very inefficient
 
             $gchcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_categories_history');
             $gghcount = count_records ('backup_ids', 'backup_code', $restore->backup_unique_code, 'table_name', 'grade_grades_history');
@@ -2058,7 +2090,7 @@
                                 //traverse_xmlize($info);                            //Debug
                                 //print_object ($GLOBALS['traverse_array']);         //Debug
                                 //$GLOBALS['traverse_array']="";                     //Debug
-    
+
                                 $oldobj = backup_getid($restore->backup_unique_code,"grade_categories", backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['OLDID']['0']['#']));
                                 if (empty($oldobj->new_id)) {
                                     // if the old object is not being restored, can't restoring its history
@@ -2069,12 +2101,12 @@
                                 $dbrec->action = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['ACTION']['0']['#']);
                                 $dbrec->source = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['SOURCE']['0']['#']);
                                 $dbrec->timemodified = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['TIMEMODIFIED']['0']['#']);
-    
+
                                 // loggeduser might not be restored, e.g. admin
                                 if ($oldobj = backup_getid($restore->backup_unique_code,"user", backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['LOGGEDUSER']['0']['#']))) {
                                     $dbrec->loggeduser = $oldobj->new_id;
                                 }
-    
+
                                 // this item might not have a parent at all, do not skip it if no parent is specified
                                 if (backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['PARENT']['0']['#'])) {
                                     $oldobj = backup_getid($restore->backup_unique_code,"grade_categories", backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['PARENT']['0']['#']));
@@ -2106,15 +2138,15 @@
                                 $dbrec->aggregation = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['AGGRETGATION']['0']['#']);
                                 $dbrec->keephigh = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['KEEPHIGH']['0']['#']);
                                 $dbrec->droplow = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['DROPLOW']['0']['#']);
-                                
+
                                 $dbrec->aggregateonlygraded = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['AGGREGATEONLYGRADED']['0']['#']);
                                 $dbrec->aggregateoutcomes = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['AGGREGATEOUTCOMES']['0']['#']);
                                 $dbrec->aggregatesubcats = backup_todb($info['GRADE_CATEGORIES_HISTORY']['#']['AGGREGATESUBCATS']['0']['#']);
-    
+
                                 $dbrec->courseid = $restore->course_id;
                                 insert_record('grade_categories_history', $dbrec);
                                 unset($dbrec);
-    
+
                             }
                             //Increment counters
                             $counter++;
@@ -2132,7 +2164,7 @@
                     }
                 }
             }
-    
+
             // process histories
             if ($gghcount && $status) {
                 if (!defined('RESTORE_SILENTLY')) {
@@ -2156,7 +2188,7 @@
                                 //traverse_xmlize($info);                            //Debug
                                 //print_object ($GLOBALS['traverse_array']);         //Debug
                                 //$GLOBALS['traverse_array']="";                     //Debug
-    
+
                                 $oldobj = backup_getid($restore->backup_unique_code,"grade_grades", backup_todb($info['GRADE_GRADES_HISTORY']['#']['OLDID']['0']['#']));
                                 if (empty($oldobj->new_id)) {
                                     // if the old object is not being restored, can't restoring its history
@@ -2170,7 +2202,7 @@
                                 if ($oldobj = backup_getid($restore->backup_unique_code,"user", backup_todb($info['GRADE_GRADES_HISTORY']['#']['LOGGEDUSER']['0']['#']))) {
                                     $dbrec->loggeduser = $oldobj->new_id;
                                 }
-                                
+
                                 $oldobj = backup_getid($restore->backup_unique_code,"grade_items", backup_todb($info['GRADE_GRADES_HISTORY']['#']['ITEMID']['0']['#']));
                                 $dbrec->itemid = $oldobj->new_id;
                                 if (empty($dbrec->itemid)) {
@@ -2185,12 +2217,12 @@
                                 if ($oldobj = backup_getid($restore->backup_unique_code,"user", backup_todb($info['GRADE_GRADES_HISTORY']['#']['USERMODIFIED']['0']['#']))) {
                                     $dbrec->usermodified = $oldobj->new_id;
                                 }
-                                
+
                                 if (backup_todb($info['GRADE_GRADES_HISTORY']['#']['RAWSCALEID']['0']['#'])) {
                                     $scale = backup_getid($restore->backup_unique_code,"scale",backup_todb($info['GRADE_GRADES_HISTORY']['#']['RAWSCALEID']['0']['#']));
                                     $dbrec->rawscaleid = $scale->new_id;
                                 }
-                                
+
                                 $dbrec->finalgrade = backup_todb($info['GRADE_GRADES_HISTORY']['#']['FINALGRADE']['0']['#']);
                                 $dbrec->hidden = backup_todb($info['GRADE_GRADES_HISTORY']['#']['HIDDEN']['0']['#']);
                                 $dbrec->locked = backup_todb($info['GRADE_GRADES_HISTORY']['#']['LOCKED']['0']['#']);
@@ -2202,10 +2234,10 @@
                                 $dbrec->feedbackformat = backup_todb($info['GRADE_TEXT_HISTORY']['#']['FEEDBACKFORMAT']['0']['#']);
                                 $dbrec->information = backup_todb($info['GRADE_TEXT_HISTORY']['#']['INFORMATION']['0']['#']);
                                 $dbrec->informationformat = backup_todb($info['GRADE_TEXT_HISTORY']['#']['INFORMATIONFORMAT']['0']['#']);
-    
+
                                 insert_record('grade_grades_history', $dbrec);
                                 unset($dbrec);
-    
+
                             }
                             //Increment counters
                             $counter++;
@@ -2223,9 +2255,9 @@
                     }
                 }
             }
-    
+
             // process histories
-    
+
             if ($gihcount && $status) {
                 if (!defined('RESTORE_SILENTLY')) {
                     echo '<li>'.get_string('gradeitemshistory','grades').'</li>';
@@ -2248,8 +2280,8 @@
                                 //traverse_xmlize($info);                            //Debug
                                 //print_object ($GLOBALS['traverse_array']);         //Debug
                                 //$GLOBALS['traverse_array']="";                     //Debug
-    
-    
+
+
                                 $oldobj = backup_getid($restore->backup_unique_code,"grade_items", backup_todb($info['GRADE_ITEM_HISTORY']['#']['OLDID']['0']['#']));
                                 if (empty($oldobj->new_id)) {
                                     // if the old object is not being restored, can't restoring its history
@@ -2270,31 +2302,31 @@
                                     $counter++;
                                     continue; // category not restored
                                 }
-    
+
                                 $dbrec->itemname= backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMNAME']['0']['#']);
                                 $dbrec->itemtype = backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMTYPE']['0']['#']);
                                 $dbrec->itemmodule = backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMMODULE']['0']['#']);
-    
+
                                 // code from grade_items restore
                                 $iteminstance = backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMINSTANCE']['0']['#']);
                                 // do not restore if this grade_item is a mod, and
                                 if ($dbrec->itemtype == 'mod') {
-    
+
                                     if (!restore_userdata_selected($restore,  $dbrec->itemmodule, $iteminstance)) {
                                         // module instance not selected when restored using granular
                                         // skip this item
                                         $counter++;
                                         continue;
                                     }
-    
+
                                     // iteminstance should point to new mod
-    
+
                                     $mod = backup_getid($restore->backup_unique_code,$dbrec->itemmodule, $iteminstance);
                                     $dbrec->iteminstance = $mod->new_id;
-    
+
                                 } else if ($dbrec->itemtype == 'category') {
                                     // the item instance should point to the new grade category
-    
+
                                     // only proceed if we are restoring all grade items
                                     if ($restoreall) {
                                         $category = backup_getid($restore->backup_unique_code,'grade_categories', $iteminstance);
@@ -2309,16 +2341,16 @@
                                         // TODO any special code needed here to restore course item without duplicating it?
                                         // find the course category with depth 1, and course id = current course id
                                         // this would have been already restored
-    
+
                                         $cat = get_record('grade_categories', 'depth', 1, 'courseid', $restore->course_id);
                                         $dbrec->iteminstance = $cat->id;
-    
+
                                     } else {
                                         $counter++;
                                         continue;
                                     }
                                 }
-    
+
                                 $dbrec->itemnumber = backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMNUMBER']['0']['#']);
                                 $dbrec->iteminfo = backup_todb($info['GRADE_ITEM_HISTORY']['#']['ITEMINFO']['0']['#']);
                                 $dbrec->idnumber = backup_todb($info['GRADE_ITEM_HISTORY']['#']['IDNUMBER']['0']['#']);
@@ -2345,10 +2377,10 @@
                                 $dbrec->locked = backup_todb($info['GRADE_ITEM_HISTORY']['#']['LOCKED']['0']['#']);
                                 $dbrec->locktime = backup_todb($info['GRADE_ITEM_HISTORY']['#']['LOCKTIME']['0']['#']);
                                 $dbrec->needsupdate = backup_todb($info['GRADE_ITEM_HISTORY']['#']['NEEDSUPDATE']['0']['#']);
-    
+
                                 insert_record('grade_items_history', $dbrec);
                                 unset($dbrec);
-    
+
                             }
                             //Increment counters
                             $counter++;
@@ -2366,7 +2398,7 @@
                     }
                 }
             }
-    
+
             // process histories
             if ($gohcount && $status) {
                 if (!defined('RESTORE_SILENTLY')) {
@@ -2390,7 +2422,7 @@
                                 //traverse_xmlize($info);                            //Debug
                                 //print_object ($GLOBALS['traverse_array']);         //Debug
                                 //$GLOBALS['traverse_array']="";                     //Debug
-    
+
                                 $oldobj = backup_getid($restore->backup_unique_code,"grade_outcomes", backup_todb($info['GRADE_OUTCOME_HISTORY']['#']['OLDID']['0']['#']));
                                 if (empty($oldobj->new_id)) {
                                     // if the old object is not being restored, can't restoring its history
@@ -2410,10 +2442,10 @@
                                 $oldobj = backup_getid($restore->backup_unique_code,"scale", backup_todb($info['GRADE_OUTCOME_HISTORY']['#']['SCALEID']['0']['#']));
                                 $dbrec->scaleid = $oldobj->new_id;
                                 $dbrec->description = backup_todb($info['GRADE_OUTCOME_HISTORY']['#']['DESCRIPTION']['0']['#']);
-    
+
                                 insert_record('grade_outcomes_history', $dbrec);
                                 unset($dbrec);
-    
+
                             }
                             //Increment counters
                             $counter++;
@@ -3342,7 +3374,7 @@
     function restore_group_getid($restore, $groupid) {
         //We have to recode the groupid field
         $group = backup_getid($restore->backup_unique_code, 'groups', $groupid);
-        
+
         if ($restore->groups == RESTORE_GROUPS_NONE or $restore->groups == RESTORE_GROUPINGS_ONLY) {
             $group->new_id = 0;
         }
@@ -3356,7 +3388,7 @@
     function restore_grouping_getid($restore, $groupingid) {
         //We have to recode the groupid field
         $grouping = backup_getid($restore->backup_unique_code, 'groupings', $groupingid);
-        
+
         if ($restore->groups != RESTORE_GROUPS_GROUPINGS and $restore->groups != RESTORE_GROUPINGS_ONLY) {
             $grouping->new_id = 0;
         }
@@ -3489,7 +3521,7 @@
             //We have to recode the userid field
             if (!$user = backup_getid($restore->backup_unique_code,"user",$group_member->userid)) {
                 debugging("group membership can not be restored, user id $group_member->userid not present in backup");
-                // do not not block the restore 
+                // do not not block the restore
                 continue;
             }
 
@@ -3572,7 +3604,7 @@
         // now fix the defaultgroupingid in course
         $course = get_record('course', 'id', $restore->course_id);
         if ($course->defaultgroupingid) {
-            if ($grouping = restore_grouping_getid($restore, $course->defaultgroupingid)) { 
+            if ($grouping = restore_grouping_getid($restore, $course->defaultgroupingid)) {
                 set_field('course', 'defaultgroupingid', $grouping->new_id, 'id', $course->id);
             } else {
                 set_field('course', 'defaultgroupingid', 0, 'id', $course->id);
@@ -3824,7 +3856,7 @@
 
         $counter = 0;
 
-        // 'users' is the old users folder, 'user' is the new one, with a new hierarchy. Detect which one is here and treat accordingly 
+        // 'users' is the old users folder, 'user' is the new one, with a new hierarchy. Detect which one is here and treat accordingly
         //in CFG->dataroot
         $dest_dir = $CFG->dataroot."/user";
         $status = check_dir_exists($dest_dir,true);
@@ -3832,7 +3864,7 @@
         //Now, we iterate over "user_files" records to check if that user dir must be
         //copied (and renamed) to the "users" dir.
         $rootdir = $CFG->dataroot."/temp/backup/".$restore->backup_unique_code."/user_files";
-        
+
         //Check if directory exists
         $userlist = array();
 
@@ -3849,7 +3881,7 @@
                 }
             }
 
-            foreach ($userlist as $olduserid => $backup_location) { 
+            foreach ($userlist as $olduserid => $backup_location) {
                 //Look for dir like username in backup_ids
                 //If that user exists in backup_ids
                 if ($user = backup_getid($restore->backup_unique_code,"user",$olduserid)) {
@@ -4516,6 +4548,63 @@
                             $module->instance = $instance->new_id;
                             //print_object ($module);                             //Debug
                             $status = update_record("course_modules",$module);
+                            /// START CONDITIONALS
+                            $conditional = get_record('conditional','moduleid',$module->id);
+                            $conditions = get_records('conditional_member', 'conditionalid', $conditional->id);
+                            foreach ($conditions as $condition) {
+                                if ($condition->instance) {
+
+                                    $conditioninstance = backup_getid($restore->backup_unique_code,$condition->type,$condition->instance);
+                                    if ($conditioninstance) {
+                                        $condition->instance = $conditioninstance->new_id;
+                                        update_record('conditional_member',$condition);
+                                    }
+
+                                    if ($condition->type == 'choice' && $condition->subtype == 'particularanswer') {
+                                        $choiceanswer = backup_getid($restore->backup_unique_code,'choice_options',$condition->value);
+                                        $condition->value = $choiceanswer->new_id;
+                                        update_record('conditional_member',$condition);
+
+                                    } elseif ($condition->type == 'lesson' && $condition->subtype != 'grade') {
+                                        $lessonpage =  backup_getid($restore->backup_unique_code,'lesson_pages',$condition->subtype);
+                                        $condition->subtype = $lessonpage->new_id;
+                                        if ($page = get_record('lesson_pages', 'id', $condition->subtype) ) {
+                                            switch($page->qtype) {
+                                                case 1: /// short answer
+                                                case 2: /// true/false
+                                                case 3: /// multichoice
+                                                    $lessonanswer = backup_getid($restore->backup_unique_code,'lesson_answers',$condition->value);
+                                                    $condition->value = $lessonanswer->new_id;
+                                                    break;
+                                                default:
+                                                    break;
+                                            }
+                                        }
+                                        update_record('conditional_member',$condition);
+
+                                    } elseif ($condition->type == 'quiz' && $condition->subtype != 'grade') {
+
+                                        $quizquestioninstance =  backup_getid($restore->backup_unique_code,'quiz_question_instances',$condition->subtype);
+                                        $condition->subtype = $quizquestioninstance->new_id;
+                                        $questioninstance = get_record('quiz_question_instances', 'id', $condition->subtype);
+                                        if ($question = get_record('question', 'id', $questioninstance->question)) {
+                                            switch($question->qtype) {
+                                                case 'shortanswer':
+                                                case 'truefalse':
+                                                case 'multichoice':
+                                                case 'calculated':
+                                                    $questionanswers =  backup_getid($restore->backup_unique_code,'question_answers',$condition->value);
+                                                    $condition->value = $questionanswers->new_id;
+                                                    break;
+                                                default:
+                                                    break;
+                                            }
+                                        }
+                                        update_record('conditional_member',$condition);
+                                    }
+                                }
+                            }
+                            /// END CONDITIONALS
                         } else {
                             $status = false;
                         }
@@ -4530,7 +4619,7 @@
                                            FROM {$CFG->prefix}course_modules
                                            WHERE id = '$cm_module->new_id' AND
                                                  instance = '0'");
-                                                 
+
                     if($course_modules_inst_zero){ // Clean up the invalid instances
                          foreach($course_modules_inst_zero as $course_modules_inst){
                              delete_records('course_modules', 'id',$course_modules_inst->id);
@@ -5548,6 +5637,22 @@
                         case "ENROLPERIOD":
                             $this->info->course_enrolperiod = $this->getContents();
                             break;
+
+                        /// START COMMENTS
+                        case "USELABEL":
+                            $this->info->course_uselabel = $this->getContents();
+                            break;
+                        case "PERSONALIZEDLABEL":
+                            $this->info->course_personalizedlabel = $this->getContents();
+                            break;
+                        /// END COMMENTS
+
+                        /// START CONDITIONALS
+                        case "USECONDITIONALS":
+                            $this->info->course_useconditionals = $this->getContents();
+                            break;
+                        /// END CONDITIONALS
+
                     }
                 }
                 if ($this->tree[4] == "CATEGORY") {
@@ -5674,7 +5779,7 @@
                 if (!isset($this->temp)) {
                     $this->temp = "";
                 }
-                $this->temp .= htmlspecialchars(trim($this->content))."</".$tagName.">";    
+                $this->temp .= htmlspecialchars(trim($this->content))."</".$tagName.">";
 
                 //Dependig of different combinations, do different things
                 if ($this->level == 4) {
@@ -5689,7 +5794,7 @@
                             $xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->temp;
                             //Call to xmlize for this portion of xml data (one BLOCK)
                             //echo "-XMLIZE: ".strftime ("%X",time()),"-";                                                //Debug
-                            $data = xmlize($xml_data,0);         
+                            $data = xmlize($xml_data,0);
                             //echo strftime ("%X",time())."<p>";                                                          //Debug
                             //traverse_xmlize($data);                                                                     //Debug
                             //print_object ($GLOBALS['traverse_array']);                                                  //Debug
@@ -5699,7 +5804,7 @@
                                 //Get old id
                                 $oldid = $data['BLOCK']['#']['ID']['0']['#'];
                                 //Get instancedata
-                                
+
                                 if ($data = $data['BLOCK']['#']['INSTANCEDATA']['0']['#']) {
                                     //Restore code calls this multiple times - so might already have the newid
                                     if ($newid = backup_getid($this->preferences->backup_unique_code,'block_instance',$oldid)) {
@@ -5924,6 +6029,16 @@
                             $this->info->tempsection->mods[$this->info->tempmod->id]->idnumber =
                                 $this->info->tempmod->idnumber;
 
+                            /// START COMMENTS
+                            $this->info->tempsection->mods[$this->info->tempmod->id]->info =
+                                $this->info->tempmod->info;
+                            /// END COMMENTS
+
+                            /// START CONDITIONALS
+                            $this->info->tempsection->mods[$this->info->tempmod->id]->conditional =
+                                $this->info->tempmod->conditional;
+                            /// END CONDITIONALS
+
                             unset($this->info->tempmod);
                     }
                 }
@@ -5962,11 +6077,75 @@
                         case "IDNUMBER":
                             $this->info->tempmod->idnumber = $this->getContents();
                             break;
+
+                        /// START COMMENTS
+                        case "INFO":
+                            $this->info->tempmod->info = $this->getContents();
+                            break;
+                        /// END COMMENTS
+
                         default:
                             break;
                     }
                 }
 
+                /// START CONDITIONALS
+                if ($this->level == 8) {
+                    switch ($tagName) {
+                        case "DETAILS":
+                            $this->info->tempmod->conditional->details = $this->getContents();
+                            break;
+                        case "INUSE":
+                            $this->info->tempmod->conditional->inuse = $this->getContents();
+                            break;
+                    }
+                }
+                if ($this->level == 9) {
+                    switch ($tagName) {
+                        case "CONDITION":
+                            $this->info->tempmod->conditional->conditions[$this->info->
+                                tempcondition->id]->type = $this->info->tempcondition->type;
+                            $this->info->tempmod->conditional->conditions[$this->info->
+                                tempcondition->id]->subtype = $this->info->tempcondition->subtype;
+                            $this->info->tempmod->conditional->conditions[$this->info->
+                                tempcondition->id]->instance = $this->info->tempcondition->instance;
+                            $this->info->tempmod->conditional->conditions[$this->info->
+                                tempcondition->id]->op = $this->info->tempcondition->op;
+                            $this->info->tempmod->conditional->conditions[$this->info->
+                                tempcondition->id]->value = $this->info->tempcondition->value;
+                            $this->info->tempmod->conditional->conditions[$this->info->
+                                tempcondition->id]->tableid = $this->info->tempcondition->tableid;
+                            unset($this->info->tempcondition);
+                            break;
+                    }
+                }
+                if ($this->level == 10) {
+                    switch ($tagName) {
+                        case "ID":
+                            $this->info->tempcondition->id = $this->getContents();
+                            break;
+                        case "TYPE":
+                            $this->info->tempcondition->type = $this->getContents();
+                            break;
+                        case "SUBTYPE":
+                            $this->info->tempcondition->subtype = $this->getContents();
+                            break;
+                        case "INSTANCE":
+                            $this->info->tempcondition->instance = $this->getContents();
+                            break;
+                        case "OP":
+                            $this->info->tempcondition->op = $this->getContents();
+                            break;
+                        case "VALUE":
+                            $this->info->tempcondition->value = $this->getContents();
+                            break;
+                        case "TABLEID":
+                            $this->info->tempcondition->tableid = $this->getContents();
+                            break;
+                    }
+                }
+                /// END CONDITIONALS
+
                 if (isset($this->tree[7]) && $this->tree[7] == "ROLES_ASSIGNMENTS") {
 
                     if ($this->level == 9) {
@@ -6208,7 +6387,7 @@
                     //Reset temp
                     unset($this->temp);
                 }
-                
+
                 if (($this->level == 5) and ($tagName == "GRADE_LETTER")) {
                     //Prepend XML standard header to info gathered
                     $xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".$this->temp;
@@ -6387,7 +6566,7 @@
                     $preference_id = $data["GRADE_PREFERENCE"]["#"]["ID"]["0"]["#"];
                     $this->counter++;
                     //Save to db
-                    $status = backup_putid($this->preferences->backup_unique_code, 'grade_preferences', $preference_id, 
+                    $status = backup_putid($this->preferences->backup_unique_code, 'grade_preferences', $preference_id,
                                            null,$data);
                     //Create returning info
                     $this->info = $this->counter;
@@ -6410,7 +6589,7 @@
                     $letter_id = $data["GRADE_LETTER"]["#"]["ID"]["0"]["#"];
                     $this->counter++;
                     //Save to db
-                    $status = backup_putid($this->preferences->backup_unique_code, 'grade_letter' ,$letter_id, 
+                    $status = backup_putid($this->preferences->backup_unique_code, 'grade_letter' ,$letter_id,
                                            null,$data);
                     //Create returning info
                     $this->info = $this->counter;
@@ -7539,12 +7718,12 @@
             // MDL-9290 performance improvement on reading large xml
             $lasttime = time(); // crmas
             while ($data = fread($fp, 8192) and !$moodle_parser->finished) {
-             
+
                 if ((time() - $lasttime) > 5) {
                     $lasttime = time();
                     backup_flush(1);
                 }
-             
+
                 xml_parse($xml_parser, $data, feof($fp))
                         or die(sprintf("XML error: %s at line %d",
                         xml_error_string(xml_get_error_code($xml_parser)),
diff -Naur moodle/course/conditional/activityinfo.php moodle-conditionals/course/conditional/activityinfo.php
--- moodle/course/conditional/activityinfo.php	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/course/conditional/activityinfo.php	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,71 @@
+<?php
+
+    require_once('../../config.php');
+    require_once("$CFG->dirroot/course/lib.php");
+
+    require_login();
+
+    $id = optional_param('id', 0, PARAM_INT);
+    $activityinfo = optional_param('activityinfo', NULL);
+    $createconditional = optional_param('createconditional', NULL);
+    $info = optional_param('info', NULL);
+
+    if (! $cm = get_record("course_modules", "id", $id)) {
+        print_error('invalidcoursemodule');
+    }
+
+    if (! $course = get_record("course", "id", $cm->course)) {
+        print_error('invalidcourse');
+    }
+
+    require_login($course);
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+    require_capability('moodle/local:assigncomments', $context);
+
+    if (! $module = get_record("modules", "id", $cm->module)) {
+        print_error('cmunknown');
+    }
+
+    if (! $activity = get_record($module->name, "id", $cm->instance)) {
+        print_error('cmunknown');
+    }
+
+    if(isset($activityinfo) || isset($createconditional)) {
+        if(isset($info)) {
+            $cm->info = $info;
+            update_record('course_modules', $cm);
+        }
+        if (isset($activityinfo)) {
+            redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id", get_string("changessaved"), 1);
+        } else if (isset($createconditional)) {
+            redirect("conditions.php?id=$cm->id", get_string("changessaved"), 1);
+        }
+    }
+
+    $overridableroles = get_overridable_roles($context);
+    $assignableroles  = get_assignable_roles($context);
+    $currenttab = 'info';
+    include_once($CFG->dirroot.'/'.$CFG->admin.'/roles/tabs.php');
+
+    print_heading_with_help(get_string('activityinfocreation', 'conditional', $activity->name), 'activityinfocreation', 'conditional');
+
+    echo "<form name='activityinfoform' method='POST' action='activityinfo.php?id=".$cm->id."'>";
+    echo '<center>';
+
+    //$usehtmleditor = can_use_html_editor();
+    //print_textarea($usehtmleditor, 10, 50, 660, 200, "info", $cm->info);
+    print_textarea(0, 10, 50, 660, 200, "info", $cm->info);
+    //if ($usehtmleditor) {
+    //    use_html_editor("info");
+    //}
+
+    echo '<br>';
+    echo '<br>';
+
+    echo '<input type="submit" name="activityinfo" value="'.get_string('savechanges').'">';
+    echo '<input type="submit" name="createconditional" value="'.get_string('createconditional', 'conditional').'">';
+
+    echo '</center>';
+    echo '</form>';
+
+?>
\ No hay ningún carácter de nueva línea al final del fichero
diff -Naur moodle/course/conditional/conditioncreation.php moodle-conditionals/course/conditional/conditioncreation.php
--- moodle/course/conditional/conditioncreation.php	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/course/conditional/conditioncreation.php	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,71 @@
+<?php
+
+    require_once("../../config.php");
+    require_once("$CFG->dirroot/course/lib.php");
+    require_once("conditionslib.php");
+
+    require_login();
+
+    $id = required_param('id', PARAM_INT);
+    $action = optional_param('action', NULL);
+    $conditionid = optional_param('conditionid', NULL, PARAM_INT);
+    $conditionalinstance = optional_param('instance', NULL, PARAM_INT);
+    $conditiontype = optional_param('conditiontype', NULL);
+    $subtype = optional_param('subtype', NULL);
+    $op = optional_param('op', NULL, PARAM_RAW);
+    $value = optional_param('value', NULL);
+    $day = optional_param('day', NULL);
+    $month = optional_param('month', NULL);
+    $year = optional_param('year', NULL);
+    // If noscript we must expect that params
+    $cancelconditioncreation = optional_param('cancelconditioncreation', NULL);
+
+    if (! $cm = get_record("course_modules", "id", $id)) {
+        print_error('invalidcoursemodule');
+    }
+
+    if (! $course = get_record("course", "id", $cm->course)) {
+        print_error('invalidcourse');
+    }
+
+    require_login($course);
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+    require_capability('moodle/local:createconditionals', $context);
+
+    if (! $module = get_record("modules", "id", $cm->module)) {
+        print_error('cmunknown');
+    }
+
+    if (! $activity = get_record($module->name, "id", $cm->instance)) {
+        print_error('cmunknown');
+    }
+
+    if(isset($conditiontype) and ($action=='cancel' || $cancelconditioncreation)) {
+        redirect("conditions.php?id=$cm->id");
+    }
+
+    if(isset($conditiontype) and $action=='save') {
+        conditional_save($cm->id, $conditiontype, $conditionalinstance, $subtype, $op, $value, $year, $month, $day, $conditionid);
+        redirect("conditions.php?id=$cm->id");
+    }
+
+    $overridableroles = get_overridable_roles($context);
+    $assignableroles  = get_assignable_roles($context);
+    $currenttab = 'locks';
+    include_once($CFG->dirroot.'/'.$CFG->admin.'/roles/tabs.php');
+
+    print_heading_with_help(get_string('conditioncreation', 'conditional', $activity->name), 'conditionalcreation', 'conditional');
+
+    if (!$action) {
+        conditional_define_condition($cm->id, $course->id, $conditionid);
+    } elseif($conditiontype and $action=='createstep1') {
+        conditional_define_condition_step1($cm->id, $conditiontype, $course, $module, $conditionid);
+    } elseif($conditiontype and $action=='createstep2') {
+        conditional_define_condition_step2($cm->id, $conditiontype, $course, $module, $conditionalinstance, $subtype, $op, $value, $conditionid);
+    } elseif($conditiontype and $action=='createstep3') {
+        conditional_define_condition_step3($cm->id, $conditiontype, $conditionalinstance, $subtype, $op, $value, $conditionid);
+    }
+
+    print_footer($course);
+
+?>
\ No hay ningún carácter de nueva línea al final del fichero
diff -Naur moodle/course/conditional/conditionslib.php moodle-conditionals/course/conditional/conditionslib.php
--- moodle/course/conditional/conditionslib.php	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/course/conditional/conditionslib.php	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,889 @@
+<?php
+
+function conditional_delete_condition($cmid, $conditionid, $inuse) {
+    delete_records('conditional_member', 'id', $conditionid);
+    if ($inuse) {
+        $conditional = get_record('conditional', 'moduleid', $cmid);
+        $conditional->details = '';
+        update_record('conditional', $conditional);
+    }
+}
+
+function  conditional_activate($cmid) {
+    $conditional = get_record('conditional', 'moduleid', $cmid);
+    $conditional->inuse = true;
+    update_record('conditional', $conditional);
+}
+
+function  conditional_deactivate($cmid) {
+    $conditional = get_record('conditional', 'moduleid', $cmid);
+    $conditional->inuse = false;
+    update_record('conditional', $conditional);
+}
+
+function conditional_save($cmid, $conditiontype, $conditionalinstance=NULL, $subtype=NULL, $op=NULL, $value=NULL, $year=NULL, $month=NULL, $day=NULL, $conditionid=NULL) {
+    if($conditional = get_record('conditional', 'moduleid', $cmid)) {
+        $conditionalid = $conditional->id;
+    } else {
+        $data = new stdClass();
+        $data->moduleid = $cmid;
+        $conditionalid = insert_record('conditional', $data);
+        unset($data);
+    }
+
+    $data = new stdClass();
+    $data->conditionalid = $conditionalid;
+    $data->type = $conditiontype;
+    if(isset($subtype)) {
+        $data->subtype = $subtype;
+    }
+    if ($conditiontype == 'date') {
+        if (isset($day) && isset($month) && isset($year)) {
+            $conditionalinstance = make_timestamp($year, $month, $day);
+        }
+    }
+    if(isset($conditionalinstance)) {
+        $data->instance = $conditionalinstance;
+    }
+    if(isset($op)) {
+        $data->op = "$op";
+    }
+    if(isset($value)) {
+        $data->value = $value;
+    }
+    if ($conditions = get_records('conditional_member', 'conditionalid', $conditionalid, 'tableid desc')) {
+        $condition = current($conditions);
+        $data->tableid = $condition->tableid + 1;
+    } else {
+        $data->tableid = 1;
+    }
+    if ($conditionid) {
+        $data->id = $conditionid;
+        $data->tableid = $conditions[$conditionid]->tableid;
+        update_record('conditional_member', $data);
+    } else {
+        insert_record('conditional_member', $data);
+    }
+}
+
+function conditional_agrupate($courseid, $cmid, $details='', &$agrupateconditionalerror, $return) {
+    global $CFG;
+
+    $conditional = get_record('conditional', 'moduleid', $cmid);
+    $conditions = get_records('conditional_member', 'conditionalid', $conditional->id, 'tableid desc');
+    $detailsprobe = $details;
+    if ($details) {
+        foreach ($conditions as $condition) {
+            $detailsprobe = str_replace($condition->tableid, '', $detailsprobe);
+        }
+        $detailsprobe = str_replace('not', '', $detailsprobe);
+        $detailsprobe = str_replace('and', '', $detailsprobe);
+        $detailsprobe = str_replace('or', '', $detailsprobe);
+        $detailsprobe = str_replace('(', '', $detailsprobe);
+        $detailsprobe = str_replace(')', '', $detailsprobe);
+    }
+    if(str_replace(' ', '', $detailsprobe) != '') {
+        $agrupateconditionalerror = true;
+    } else {
+        $detailsprobe = $details;
+        foreach ($conditions as $condition) {
+            $detailsprobe = str_replace($condition->tableid, 'true', $detailsprobe);
+        }
+        $detailsprobe = str_replace('not', '!', $detailsprobe);
+        if( (str_replace(' ', '', $detailsprobe) == '') || eval('return (('.$detailsprobe.' == true) or ('.$detailsprobe.' == false));') == true) {
+            $conditional->details = $details;
+            update_record('conditional', $conditional);
+            if ($return) {
+                redirect("$CFG->wwwroot/course/view.php?id=$courseid", get_string("changessaved"), 1);
+            } else {
+                redirect("conditions.php?id=$cmid");
+            }
+        } else {
+            $agrupateconditionalerror = true;
+        }
+    }
+}
+
+function conditional_define_condition($cmid, $courseid, $conditionid=NULL) {
+    $modules = get_records_select('modules', 'visible = "1" and (name = "assignment" or name = "chat" or name = "choice" or name = "forum" or name = "glossary" or name = "lesson" or name = "quiz" or name = "resource" or name = "wiki" or name = "workshop" or name = "book" or name = "conditionalbook" or name = "dialogue")', 'id asc');
+
+    foreach ($modules as $eachmodule) {
+        if(count_records_select('course_modules', "id <> $cmid and course = $courseid and module = $eachmodule->id") > 0) {
+            $options["$eachmodule->name"] = get_string("modulename", $eachmodule->name);
+        }
+    }
+
+    $options['role'] = get_string('role', 'conditional');
+    $options['lang'] = get_string('studentlang', 'conditional');
+    $options['country'] = get_string('studentcountry', 'conditional');
+    $options['picture'] = get_string('picture', 'conditional');
+    $options['enrolment'] = get_string('enrolment', 'conditional');
+    $options['startdate'] = get_string('startdate', 'conditional');
+    $options['date'] = get_string('date', 'conditional');
+
+    echo '<center>';
+    echo "<form name='createconditionform' method='POST' action='conditioncreation.php?id=".$cmid."'>";
+    print_string('selectactivitytype', 'conditional');
+    choose_from_menu($options, 'conditiontype', '', '');
+    echo '<br><br>';
+    echo '<input type="submit" name="createconditional" value="'.get_string('continue').'">';
+    echo '<input type="hidden" name="action" value="createstep1">';
+    echo '<input type="submit" name="cancelconditioncreation" value="'.get_string('cancel').'" onclick="document.createconditionform.action.value = \'cancel\';"/>';
+    echo '<input type="hidden" name="conditionid" value="'.$conditionid.'">';
+    echo '</form>';
+    echo '</center>';
+}
+
+function conditional_define_condition_step1($cmid, $conditiontype, $course, $module, $conditionid=NULL) {
+    global $CFG;
+
+    echo "<form name='createconditionform' method='POST' action='conditioncreation.php?id=".$cmid."'>";
+    echo '<center>';
+
+    $conditionalmodule = get_record('modules', 'name', $conditiontype);
+
+    switch($conditiontype) {
+
+        case 'assignment':
+            $options = array('submit'=>get_string('assignmentsubmit', 'conditional'), 'grade'=>get_string('assignmentgrade', 'conditional'));
+            choose_from_menu($options, 'subtype', '', '');
+            echo '<br><br>';
+            echo '<input type="submit" name="createconditional2" value="'.get_string('continue').'">';
+            echo '<input type="hidden" name="action" value="createstep2">';
+            break;
+        case 'book';
+            $options = array('>'=>get_string('bookparticipanthasaccess', 'conditional'), '=='=>get_string('bookparticipanthasntaccess', 'conditional'));
+            choose_from_menu($options, 'op', '', '');
+            unset($options);
+            $books = get_all_instances_in_course($conditiontype, $course);
+            foreach ($books as $eachbook) {
+                if ($conditionalmodule->id == $module->id) {
+                    $cmconditional = get_record('course_modules', 'course', $course->id, 'module', $module->id, 'instance', $eachbook->id);
+                    if ( $cmconditional->id != $cmid ) {
+                        $options[$eachbook->id] = $eachbook->name;
+                    }
+                } else {
+                    $options[$eachbook->id] = $eachbook->name;
+                }
+            }
+            choose_from_menu($options, 'instance', '', '');
+            echo '<br><br>';
+            echo '<input type="hidden" name="value" value="0">';
+            echo '<input type="hidden" name="subtype" value="access">';
+            echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+            echo '<input type="hidden" name="action" value="save">';
+            break;
+        case 'chat':
+            $options = array('say'=>get_string('chatstudenthasparticipated', 'conditional'), 'notsay'=>get_string('chatstudenthasntparticipated', 'conditional'));
+            choose_from_menu($options, 'subtype', '', '');
+            unset($options);
+            $chats = get_all_instances_in_course($conditiontype, $course);
+            foreach ($chats as $eachchat) {
+                if ($conditionalmodule->id == $module->id) {
+                    $cmconditional = get_record('course_modules', 'course', $course->id, 'module', $module->id, 'instance', $eachchat->id);
+                    if ( $cmconditional->id != $cmid ) {
+                        $options[$eachchat->id] = $eachchat->name;
+                    }
+                } else {
+                    $options[$eachchat->id] = $eachchat->name;
+                }
+            }
+            choose_from_menu($options, 'instance', '', '');
+            echo '<br><br>';
+            echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+            echo '<input type="hidden" name="action" value="save">';
+            break;
+        case 'choice':
+            $options = array('anyanswer'=>get_string('choiceanyanswer', 'conditional'), 'particularanswer'=>get_string('choiceparticularanswer', 'conditional'));
+            choose_from_menu($options, 'subtype', '', '');
+            echo '<br><br>';
+            echo '<input type="submit" name="createconditional2" value="'.get_string('continue').'">';
+            echo '<input type="hidden" name="action" value="createstep2">';
+            break;
+        case 'conditionalbook';
+            $options = array('>'=>get_string('conditionalbookparticipanthasaccess', 'conditional'), '=='=>get_string('conditionalbookparticipanthasntaccess', 'conditional'));
+            choose_from_menu($options, 'op', '', '');
+            unset($options);
+            $conditionalbooks = get_all_instances_in_course($conditiontype, $course);
+            foreach ($conditionalbooks as $eachconditionalbook) {
+                if ($conditionalmodule->id == $module->id) {
+                    $cmconditional = get_record('course_modules', 'course', $course->id, 'module', $module->id, 'instance', $eachconditionalbook->id);
+                    if ( $cmconditional->id != $cmid ) {
+                        $options[$eachconditionalbook->id] = $eachconditionalbook->name;
+                    }
+                } else {
+                    $options[$eachconditionalbook->id] = $eachconditionalbook->name;
+                }
+            }
+            choose_from_menu($options, 'instance', '', '');
+            echo '<br><br>';
+            echo '<input type="hidden" name="value" value="0">';
+            echo '<input type="hidden" name="subtype" value="access">';
+            echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+            echo '<input type="hidden" name="action" value="save">';
+            break;
+        case 'dialogue':
+            $options = array('conversations'=>get_string('dialogueconversations', 'conditional'));
+            choose_from_menu($options, 'subtype', '', '');
+            unset($options);
+            $dialogues = get_all_instances_in_course($conditiontype, $course);
+            foreach ($dialogues as $eachdialogue) {
+                if ($conditionalmodule->id == $module->id) {
+                    $cmconditional = get_record('course_modules', 'course', $course->id, 'module', $module->id, 'instance', $eachdialogue->id);
+                    if ( $cmconditional->id != $cmid ) {
+                        $options[$eachdialogue->id] = $eachdialogue->name;
+                    }
+                } else {
+                    $options[$eachdialogue->id] = $eachdialogue->name;
+                }
+            }
+            choose_from_menu($options, 'instance', '', '');
+            echo '<br><br>';
+            echo '<input type="submit" name="createconditional2" value="'.get_string('continue').'">';
+            echo '<input type="hidden" name="action" value="createstep2">';
+            break;
+        case 'forum':
+            $forums = get_all_instances_in_course($conditiontype, $course);
+            foreach ($forums as $eachforum) {
+                if ($conditionalmodule->id == $module->id) {
+                    $cmconditional = get_record('course_modules', 'course', $course->id, 'module', $module->id, 'instance', $eachforum->id);
+                    if ( $cmconditional->id != $cmid ) {
+                        $options[$eachforum->id] = $eachforum->name;
+                    }
+                } else {
+                    $options[$eachforum->id] = $eachforum->name;
+                }
+            }
+            choose_from_menu($options, 'instance', '', '');
+            echo '<br><br>';
+            echo '<input type="submit" name="createconditional2" value="'.get_string('continue').'">';
+            echo '<input type="hidden" name="action" value="createstep2">';
+            break;
+        case 'glossary':
+            $options = array('entries'=>get_string('glossaryentries', 'conditional'), 'comments'=>get_string('glossarycomments', 'conditional'));
+            choose_from_menu($options, 'subtype', '', '');
+            unset($options);
+            $glossarys = get_all_instances_in_course($conditiontype, $course);
+            foreach ($glossarys as $eachglossary) {
+                if ($conditionalmodule->id == $module->id) {
+                    $cmconditional = get_record('course_modules', 'course', $course->id, 'module', $module->id, 'instance', $eachglossary->id);
+                    if ( $cmconditional->id != $cmid ) {
+                        $options[$eachglossary->id] = $eachglossary->name;
+                    }
+                } else {
+                    $options[$eachglossary->id] = $eachglossary->name;
+                }
+            }
+            choose_from_menu($options, 'instance', '', '');
+            echo '<br><br>';
+            echo '<input type="submit" name="createconditional2" value="'.get_string('continue').'">';
+            echo '<input type="hidden" name="action" value="createstep2">';
+            break;
+        case 'lesson':
+            $options = array('grade'=>get_string('lessongrade', 'conditional'), 'answer'=>get_string('lessonanswer', 'conditional'));
+            choose_from_menu($options, 'subtype', '', '');
+            unset($options);
+            $lessons = get_all_instances_in_course($conditiontype, $course);
+            foreach ($lessons as $eachlesson) {
+                if ($conditionalmodule->id == $module->id) {
+                    $cmconditional = get_record('course_modules', 'course', $course->id, 'module', $module->id, 'instance', $eachlesson->id);
+                    if ( $cmconditional->id != $cmid ) {
+                        $options[$eachlesson->id] = $eachlesson->name;
+                    }
+                } else {
+                    $options[$eachlesson->id] = $eachlesson->name;
+                }
+            }
+            choose_from_menu($options, 'instance', '', '');
+            echo '<br><br>';
+            echo '<input type="submit" name="createconditional2" value="'.get_string('continue').'">';
+            echo '<input type="hidden" name="action" value="createstep2">';
+            break;
+        case 'quiz':
+            $options = array('grade'=>get_string('quizgrade', 'conditional'), 'answer'=>get_string('quizanswer', 'conditional'));
+            choose_from_menu($options, 'subtype', '', '');
+            unset($options);
+            $quizs = get_all_instances_in_course($conditiontype, $course);
+            foreach ($quizs as $eachquiz) {
+                if ($conditionalmodule->id == $module->id) {
+                    $cmconditional = get_record('course_modules', 'course', $course->id, 'module', $module->id, 'instance', $eachquiz->id);
+                    if ( $cmconditional->id != $cmid ) {
+                        $options[$eachquiz->id] = $eachquiz->name;
+                    }
+                } else {
+                    $options[$eachquiz->id] = $eachquiz->name;
+                }
+            }
+            choose_from_menu($options, 'instance', '', '');
+            echo '<br><br>';
+            echo '<input type="submit" name="createconditional2" value="'.get_string('continue').'">';
+            echo '<input type="hidden" name="action" value="createstep2">';
+            break;
+        case 'resource';
+            $options = array('>'=>get_string('resourcestudenthasaccess', 'conditional'), '=='=>get_string('resourcestudenthasntaccess', 'conditional'));
+            choose_from_menu($options, 'op', '', '');
+            unset($options);
+            $resources = get_all_instances_in_course($conditiontype, $course);
+            foreach ($resources as $eachresource) {
+                if ($conditionalmodule->id == $module->id) {
+                    $cmconditional = get_record('course_modules', 'course', $course->id, 'module', $module->id, 'instance', $eachresource->id);
+                    if ( $cmconditional->id != $cmid ) {
+                        $options[$eachresource->id] = $eachresource->name;
+                    }
+                } else {
+                    $options[$eachresource->id] = $eachresource->name;
+                }
+            }
+            choose_from_menu($options, 'instance', '', '');
+            echo '<br><br>';
+            echo '<input type="hidden" name="value" value="0">';
+            echo '<input type="hidden" name="subtype" value="access">';
+            echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+            echo '<input type="hidden" name="action" value="save">';
+            break;
+        case 'wiki':
+            print_string('wiki', 'conditional');
+            $wikis = get_all_instances_in_course($conditiontype, $course);
+            foreach ($wikis as $eachwiki) {
+                if ($conditionalmodule->id == $module->id) {
+                    $cmconditional = get_record('course_modules', 'course', $course->id, 'module', $module->id, 'instance', $eachwiki->id);
+                    if ( $cmconditional->id != $cmid ) {
+                        $options[$eachwiki->id] = $eachwiki->name;
+                    }
+                } else {
+                    $options[$eachwiki->id] = $eachwiki->name;
+                }
+            }
+            choose_from_menu($options, 'instance', '', '');
+            print_string('wikiis', 'conditional');
+            $options = array('>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+            choose_from_menu($options, 'op', '', '');
+            unset($options);
+            for($i=0; $i<=100 ;$i++) {
+                $options[$i] = $i;
+            }
+            choose_from_menu($options, 'value', '', '');
+            echo '<br><br>';
+            echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+            echo '<input type="hidden" name="action" value="save">';
+            break;
+        case 'workshop':
+            print_string('workshop', 'conditional');
+            $workshops = get_all_instances_in_course($conditiontype, $course);
+            foreach ($workshops as $eachworkshop) {
+                if ($conditionalmodule->id == $module->id) {
+                    $cmconditional = get_record('course_modules', 'course', $course->id, 'module', $module->id, 'instance', $eachworkshop->id);
+                    if ( $cmconditional->id != $cmid ) {
+                        $options[$eachworkshop->id] = $eachworkshop->name;
+                    }
+                } else {
+                    $options[$eachworkshop->id] = $eachworkshop->name;
+                }
+            }
+            choose_from_menu($options, 'instance', '', '');
+            print_string('workshopis', 'conditional');
+            $options = array('=='=>'=', '!='=>'<>', '>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+            choose_from_menu($options, 'op', '', '');
+            unset($options);
+            for($i=0; $i<=100 ;$i++) {
+                $options[$i] = $i.' %';
+            }
+            choose_from_menu($options, 'value', '', '');
+            echo '<br><br>';
+            echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+            echo '<input type="hidden" name="action" value="save">';
+            break;
+        case 'role':
+            $allroles = array();
+            if ($roles = get_all_roles()) {
+                foreach ($roles as $role) {
+                    $rolename = strip_tags(format_string($role->name, true));
+                    $allroles[$role->shortname] = $rolename;
+                }
+            }
+            print_string('userrole', 'conditional');
+            $options = array('=='=>'=', '!='=>'<>');
+            choose_from_menu($options, 'op', '', '');
+            choose_from_menu($allroles, 'value', '', '');
+            echo '<br><br>';
+            echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+            echo '<input type="hidden" name="action" value="save">';
+            break;
+        case 'lang':
+            print_string('studentlang', 'conditional');
+            $options = array('=='=>'=', '!='=>'<>');
+            choose_from_menu($options, 'op', '', '');
+            choose_from_menu(get_list_of_languages(), 'value', current_language(), '');
+            echo '<br><br>';
+            echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+            echo '<input type="hidden" name="action" value="save">';
+            break;
+        case 'country':
+            print_string('studentcountry', 'conditional');
+            $options = array('=='=>'=', '!='=>'<>');
+            choose_from_menu($options, 'op', '', '');
+            choose_from_menu(get_list_of_countries(), 'value', $CFG->country, '');
+            echo '<br><br>';
+            echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+            echo '<input type="hidden" name="action" value="save">';
+            break;
+        case 'picture':
+            $options = array('>' => get_string('picturehaschanged', 'conditional'), '==' => get_string('picturehasnotchanged', 'conditional'));
+            choose_from_menu($options, 'op', '', '');
+            echo '<br><br>';
+            echo '<input type="hidden" name="value" value="0">';
+            echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+            echo '<input type="hidden" name="action" value="save">';
+            break;
+        case 'enrolment':
+            print_string('enrolmenttimedifference', 'conditional');
+            $options = array('>'=>'>', '<'=>'<');
+            choose_from_menu($options, 'op', '', '');
+            unset($options);
+            for ($i=0; $i <= 1000; $i++) {
+                $options[$i] = $i;
+            }
+            choose_from_menu($options, 'value', '', '');
+            echo '<br><br>';
+            echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+            echo '<input type="hidden" name="action" value="save">';
+            break;
+        case 'startdate':
+            print_string('starttimedifference', 'conditional');
+            $options = array('>'=>'>', '<'=>'<');
+            choose_from_menu($options, 'op', '', '');
+            unset($options);
+            for ($i=0; $i <= 1000; $i++) {
+                $options[$i] = $i;
+            }
+            choose_from_menu($options, 'value', '', '');
+            echo '<br><br>';
+            echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+            echo '<input type="hidden" name="action" value="save">';
+            break;
+        case 'date':
+            print_string('datetimedifference', 'conditional');
+            print_date_selector('day', 'month', 'year');
+            print_string('wikiis', 'conditional');
+            $options = array('>'=>'>', '<'=>'<');
+            choose_from_menu($options, 'op', '', '');
+            unset($options);
+            for ($i=0; $i <= 1000; $i++) {
+                $options[$i] = $i;
+            }
+            choose_from_menu($options, 'value', '', '');
+            echo '<br><br>';
+            echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+            echo '<input type="hidden" name="action" value="save">';
+            break;
+    }
+    echo '<input type="hidden" name="conditiontype" value="'.$conditiontype.'">';
+    echo '<input type="hidden" name="conditionid" value="'.$conditionid.'">';
+    echo '<input type="submit" name="cancelconditioncreation" value="'.get_string('cancel').'" onclick="document.createconditionform.action.value = \'cancel\';"/>';
+    echo '</center>';
+    echo '</form>';
+}
+
+function conditional_define_condition_step2($cmid, $conditiontype, $course, $module, $conditionalinstance=NULL, $subtype=NULL, $op=NULL, $value=NULL, $conditionid=NULL) {
+    echo "<form name='createconditionform' method='POST' action='conditioncreation.php?id=".$cmid."'>";
+    echo '<center>';
+
+    $conditionalmodule = get_record('modules', 'name', $conditiontype);
+
+    switch($conditiontype) {
+        case 'assignment':
+            $assignments = get_all_instances_in_course($conditiontype, $course);
+            if($subtype == 'submit') {
+                $options = array('>'=>get_string('assignmentstudenthassubmit', 'conditional'), '=='=>get_string('assignmentstudenthasntsubmit', 'conditional'));
+                choose_from_menu($options, 'op', '', '');
+
+                unset($options);
+                foreach ($assignments as $eachassignment) {
+                    if ($conditionalmodule->id == $module->id) {
+                        $cmconditional = get_record('course_modules', 'course', $course->id, 'module', $module->id, 'instance', $eachassignment->id);
+                        if ( ($eachassignment->assignmenttype != 'offline') and ($cmconditional->id != $cmid) ) {
+                            $options[$eachassignment->id] = $eachassignment->name;
+                        }
+                    } else {
+                        if ( $eachassignment->assignmenttype != 'offline' ) {
+                            $options[$eachassignment->id] = $eachassignment->name;
+                        }
+                    }
+                }
+                choose_from_menu($options, 'instance', '', '');
+
+                echo '<input type="hidden" name="value" value="0">';
+                echo '<br><br>';
+                echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+                echo '<input type="hidden" name="action" value="save">';
+            } elseif($subtype == 'grade') {
+                print_string('assignmentgradeselect', 'conditional');
+
+                foreach ($assignments as $eachassignment) {
+                    if ($conditionalmodule->id == $module->id) {
+                        $cmconditional = get_record('course_modules', 'course', $course->id, 'module', $module->id, 'instance', $eachassignment->id);
+                        if ( ($eachassignment->grade != 0) and ($cmconditional->id != $cmid) ) {
+                            $options[$eachassignment->id] = $eachassignment->name;
+                        }
+                    } else {
+                        if ($eachassignment->grade != 0) {
+                            $options[$eachassignment->id] = $eachassignment->name;
+                        }
+                    }
+                }
+                if (isset($options)) {
+                    choose_from_menu($options, 'instance', '', '');
+                } else {
+                    choose_from_menu("", 'instance', '', '');
+                }
+                echo '<br><br>';
+                echo '<input type="submit" name="createconditional3" value="'.get_string('continue').'">';
+                echo '<input type="hidden" name="action" value="createstep3">';
+            }
+            echo '<input type="hidden" name="subtype" value="'.$subtype.'">';
+            break;
+        case 'choice':
+            print_string('choiceselect', 'conditional');
+            $choices = get_all_instances_in_course($conditiontype, $course);
+            foreach ($choices as $eachchoice) {
+                if ($conditionalmodule->id == $module->id) {
+                    $cmconditional = get_record('course_modules', 'course', $course->id, 'module', $module->id, 'instance', $eachchoice->id);
+                    if ( $cmconditional->id != $cmid ) {
+                        $options[$eachchoice->id] = $eachchoice->name;
+                    }
+                } else {
+                    $options[$eachchoice->id] = $eachchoice->name;
+                }
+            }
+            choose_from_menu($options, 'instance', '', '');
+            echo '<br><br>';
+            echo '<input type="hidden" name="subtype" value="'.$subtype.'">';
+            if ($subtype == 'anyanswer') {
+                echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+                echo '<input type="hidden" name="action" value="save">';
+            } elseif ($subtype == 'particularanswer') {
+                echo '<input type="submit" name="createconditional3" value="'.get_string('continue').'">';
+                echo '<input type="hidden" name="action" value="createstep3">';
+            }
+            break;
+        case 'dialogue':
+            $dialogue = get_record('dialogue', 'id', $conditionalinstance);
+            print_string('dialogueparticularconversations', 'conditional', $dialogue->name);
+            $options = array('>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+            choose_from_menu($options, 'op', '>', '');
+            unset($options);
+            for($i=0; $i<=100 ;$i++) {
+                $options[$i] = $i;
+            }
+            choose_from_menu($options, 'value', '0', '');
+            echo '<br><br>';
+            echo '<input type="hidden" name="instance" value="'.$conditionalinstance.'">';
+            echo '<input type="hidden" name="subtype" value="'.$subtype.'">';
+            echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+            echo '<input type="hidden" name="action" value="save">';
+            break;
+        case 'forum':
+            $forum = get_record('forum', 'id', $conditionalinstance);
+            $options['messages'] = get_string('forummessages', 'conditional');
+            $options['discussions'] = get_string('forumdiscussions', 'conditional');
+            $options['success'] = get_string('forumsuccess', 'conditional');
+            $options['answers'] = get_string('forumanswers', 'conditional');
+            if ($forum->assessed && $forum->scale) {
+                $options['grade'] = get_string('forumgrade', 'conditional');
+            }
+            choose_from_menu($options, 'subtype', '', '');
+            p($forum->name);
+            echo '<br><br>';
+            echo '<input type="submit" name="createconditional3" value="'.get_string('continue').'">';
+            echo '<input type="hidden" name="action" value="createstep3">';
+            echo '<input type="hidden" name="instance" value="'.$conditionalinstance.'">';
+            break;
+        case 'glossary':
+            $glossary = get_record('glossary', 'id', $conditionalinstance);
+            if($subtype == 'entries') {
+                print_string('glossaryparticularentries', 'conditional', $glossary->name);
+            } else {
+                print_string('glossaryparticularcomments', 'conditional', $glossary->name);
+            }
+            $options = array('>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+            choose_from_menu($options, 'op', '', '');
+            unset($options);
+            for($i=0; $i<=100 ;$i++) {
+                $options[$i] = $i;
+            }
+            choose_from_menu($options, 'value', '', '');
+            echo '<br><br>';
+            echo '<input type="hidden" name="instance" value="'.$conditionalinstance.'">';
+            echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+            echo '<input type="hidden" name="action" value="save">';
+            echo '<input type="hidden" name="subtype" value="'.$subtype.'">';
+            break;
+        case 'quiz':
+            $quiz = get_record('quiz', 'id', $conditionalinstance);
+            if($subtype == 'grade') {
+                print_string('quizparticulargrade', 'conditional', $quiz->name);
+                $options = array('=='=>'=', '!='=>'<>', '>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+                choose_from_menu($options, 'op', '', '');
+                unset($options);
+                for($i=0; $i<=100 ;$i++) {
+                    $options[$i] = $i.' %';
+                }
+                choose_from_menu($options, 'value', '', '');
+                echo '<br><br>';
+                echo '<input type="hidden" name="instance" value="'.$conditionalinstance.'">';
+                echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+                echo '<input type="hidden" name="action" value="save">';
+                echo '<input type="hidden" name="subtype" value="'.$subtype.'">';
+            } else {
+                print_string('quizselectquestion', 'conditional', $quiz->name);
+                $questions = get_records('quiz_question_instances', 'quiz', $quiz->id);
+                foreach ($questions as $eachquestion) {
+                    $question = get_record('question', 'id', $eachquestion->question);
+                    $options[$eachquestion->id] = $question->name;
+                }
+                choose_from_menu($options, 'subtype', '', '');
+                echo '<br><br>';
+                echo '<input type="hidden" name="instance" value="'.$conditionalinstance.'">';
+                echo '<input type="submit" name="createconditional3" value="'.get_string('continue').'">';
+                echo '<input type="hidden" name="action" value="createstep3">';
+            }
+            break;
+        case 'lesson':
+            $lesson = get_record('lesson', 'id', $conditionalinstance);
+            if($subtype == 'grade') {
+                print_string('lessonparticulargrade', 'conditional', $lesson->name);
+                $options = array('=='=>'=', '!='=>'<>', '>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+                choose_from_menu($options, 'op', '', '');
+                unset($options);
+                for($i=0; $i<=100 ;$i++) {
+                    $options[$i] = $i.' %';
+                }
+                choose_from_menu($options, 'value', '', '');
+                echo '<br><br>';
+                echo '<input type="hidden" name="instance" value="'.$conditionalinstance.'">';
+                echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+                echo '<input type="hidden" name="action" value="save">';
+                echo '<input type="hidden" name="subtype" value="'.$subtype.'">';
+            } else {
+                print_string('lessonselectquestion', 'conditional', $lesson->name);
+                $pages = get_records('lesson_pages', 'lessonid', $lesson->id, 'id asc');
+                foreach ($pages as $eachpage) {
+                    $options[$eachpage->id] = $eachpage->title;
+                }
+                choose_from_menu($options, 'subtype', '', '');
+                echo '<br><br>';
+                echo '<input type="hidden" name="instance" value="'.$conditionalinstance.'">';
+                echo '<input type="submit" name="createconditional3" value="'.get_string('continue').'">';
+                echo '<input type="hidden" name="action" value="createstep3">';
+            }
+            break;
+    }
+    echo '<input type="hidden" name="conditiontype" value="'.$conditiontype.'">';
+    echo '<input type="hidden" name="conditionid" value="'.$conditionid.'">';
+    echo '<input type="submit" name="cancelconditioncreation" value="'.get_string('cancel').'" onclick="document.createconditionform.action.value = \'cancel\';"/>';
+    echo '</center>';
+    echo '</form>';
+}
+
+function conditional_define_condition_step3($cmid, $conditiontype, $conditionalinstance=NULL, $subtype=NULL, $op=NULL, $value=NULL, $conditionid=NULL) {
+    echo "<form name='createconditionform' method='POST' action='conditioncreation.php?id=".$cmid."'>";
+    echo '<center>';
+    switch($conditiontype) {
+        case 'assignment':
+            $assignment = get_record('assignment', 'id', $conditionalinstance);
+            print_string('assignmentparticulargrade', 'conditional', $assignment->name);
+            $options = array('=='=>'=', '!='=>'<>', '>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+            choose_from_menu($options, 'op', '', '');
+            unset($options);
+            if($assignment->grade > 0) {
+                for($i=0; $i<=$assignment->grade ;$i++) {
+                    $options[$i] = $i;
+                }
+            } elseif($assignment->grade < 0) {
+                $scale = get_record('scale', 'id', abs($assignment->grade));
+                $scalevalues = explode(',', $scale->scale);
+                $i=1;
+                foreach ($scalevalues as $scalevalue) {
+                    $options[$i] = $scalevalue;
+                    $i++;
+                }
+            } else {
+                $options = "";
+            }
+            choose_from_menu($options, 'value', '', '');
+            break;
+        case 'choice':
+            $choice = get_record('choice', 'id', $conditionalinstance);
+            print_string('choiceparticularansweris', 'conditional', $choice->name);
+            $options = array('=='=>'=', '!='=>'<>');
+            choose_from_menu($options, 'op', '', '');
+            unset($options);
+            $choiceoptions = get_records('choice_options', 'choiceid', $conditionalinstance);
+            foreach($choiceoptions as $choiceoption){
+                $options[$choiceoption->id] = $choiceoption->text;
+            }
+            choose_from_menu($options, 'value', '', '');
+            break;
+        case 'forum':
+            $forum = get_record('forum', 'id', $conditionalinstance);
+            if ($subtype == 'discussions') {
+                print_string('forumparticulardiscussions', 'conditional', $forum->name);
+                $options = array('>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+            } elseif ($subtype == 'messages') {
+                print_string('forumparticularmessages', 'conditional', $forum->name);
+                $options = array('>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+            } elseif ($subtype == 'success') {
+                print_string('forumparticularsuccess', 'conditional', $forum->name);
+                $options = array('>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+            } elseif ($subtype == 'answers') {
+                print_string('forumparticularanswers', 'conditional', $forum->name);
+                $options = array('>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+            } elseif ($subtype == 'grade') {
+                print_string('forumparticulargrade', 'conditional', $forum->name);
+                $options = array('>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=', '=='=>'=', '!='=>'<>');
+            }
+            choose_from_menu($options, 'op', '>=', '');
+            unset($options);
+            if ($subtype == 'grade') {
+                if($forum->scale > 0) {
+                    for($i=0; $i<=$forum->scale ;$i++) {
+                        $options[$i] = $i;
+                    }
+                } elseif($forum->scale < 0) {
+                    $scale = get_record('scale', 'id', abs($forum->scale));
+                    $scalevalues = explode(',', $scale->scale);
+                    $i=1;
+                    foreach ($scalevalues as $scalevalue) {
+                        $options[$i] = $scalevalue;
+                        $i++;
+                    }
+                } else {
+                    $options = "";
+                }
+            } else {
+                for($i=0; $i<=100 ;$i++) {
+                    $options[$i] = $i;
+                }
+            }
+            choose_from_menu($options, 'value', '', '');
+            break;
+        case 'quiz':
+            $questioninstance = get_record('quiz_question_instances', 'id', $subtype);
+            $question = get_record('question', 'id', $questioninstance->question);
+            switch($question->qtype) {
+                case 'shortanswer':
+                case 'truefalse':
+                case 'multichoice':
+                    print_string('quizquestionanswer', 'conditional', $question->name);
+                    $options = array('=='=>'=', '!='=>'<>');
+                    choose_from_menu($options, 'op', '', '');
+                    unset($options);
+                    $answers = get_records('question_answers', 'question', $question->id);
+                    foreach ($answers as $eachanswer) {
+                        $options[$eachanswer->id] = $eachanswer->answer;
+                    }
+                    choose_from_menu($options, 'value', '', '');
+                    break;
+                case 'numerical':
+                    print_string('quizquestionanswer', 'conditional', $question->name);
+                    $options = array('=='=>'=', '!='=>'<>', '>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+                    choose_from_menu($options, 'op', '', '');
+                    $answer = get_record('question_answers', 'question', $question->id);
+                    echo '<input type="text" name="value" value="'.$answer->answer.'">';
+                    break;
+                case 'match':
+                    print_string('quizmatchs', 'conditional', $question->name);
+                    $options = array('=='=>'=', '!='=>'<>', '>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+                    choose_from_menu($options, 'op', '', '');
+                    unset($options);
+                    $matchsnum = count_records('question_match_sub', 'question', $question->id);
+                    for($i=0; $i<=$matchsnum; $i++) {
+                        $options[$i] = $i;
+                    }
+                    choose_from_menu($options, 'value', '', '');
+                    break;
+                case 'calculated':
+                    print_string('quizquestionanswer', 'conditional', $question->name);
+                    $options = array('=='=>'=', '!='=>'<>', '>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+                    choose_from_menu($options, 'op', '', '');
+                    unset($options);
+                    $answers = get_records('question_answers', 'question', $question->id);
+                    foreach ($answers as $eachanswer) {
+                        $options[$eachanswer->id] = $eachanswer->answer;
+                    }
+                    choose_from_menu($options, 'value', '', '');
+                    break;
+                case 'randomsamatch':
+                    print_string('quizmatchs', 'conditional', $question->name);
+                    $options = array('=='=>'=', '!='=>'<>', '>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+                    choose_from_menu($options, 'op', '', '');
+                    unset($options);
+                    $randomsamatch = get_record('question_randomsamatch', 'question', $question->id);
+                    for($i=0; $i<=$randomsamatch->choose; $i++) {
+                        $options[$i] = $i;
+                    }
+                    choose_from_menu($options, 'value', '', '');
+                    break;
+            }
+            break;
+        case 'lesson':
+            $page = get_record('lesson_pages', 'id', $subtype);
+            switch($page->qtype) {
+                case 1: /// short answer
+                case 2: /// true/false
+                case 3: /// multichoice
+                    print_string('lessonquestionanswer', 'conditional', $page->title);
+                    $options = array('=='=>'=', '!='=>'<>');
+                    choose_from_menu($options, 'op', '', '');
+                    unset($options);
+                    $answers = get_records('lesson_answers', 'pageid', $page->id, 'id asc');
+                    foreach ($answers as $eachanswer) {
+                        $options[$eachanswer->id] = $eachanswer->answer;
+                    }
+                    choose_from_menu($options, 'value', '', '');
+                    break;
+                case 8: /// numerical
+                    print_string('lessonquestionanswer', 'conditional', $page->title);
+                    $options = array('=='=>'=', '!='=>'<>', '>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+                    choose_from_menu($options, 'op', '', '');
+                    $answer = get_record('lesson_answers', 'pageid', $page->id);
+                    echo '<input type="text" name="value" value="'.$answer->answer.'">';
+                    break;
+                case 5: /// match
+                    print_string('lessonmatchs', 'conditional', $page->title);
+                    $options = array('=='=>'=', '!='=>'<>', '>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+                    choose_from_menu($options, 'op', '', '');
+                    unset($options);
+                    $matchsnum = (count_records('lesson_answers', 'pageid', $page->id) - 2);
+                    for($i=0; $i<=$matchsnum; $i++) {
+                        $options[$i] = $i;
+                    }
+                    choose_from_menu($options, 'value', '', '');
+                    break;
+                case 10: /// essay
+                    print_string('lessonessaygrade', 'conditional', $page->title);
+                    $options = array('=='=>'=', '!='=>'<>', '>'=>'>', '<'=>'<', '<='=>'<=', '>='=>'>=');
+                    choose_from_menu($options, 'op', '', '');
+                    unset($options);
+                    $answer = get_record('lesson_answers', 'pageid', $page->id);
+                    for($i=0; $i<=$answer->score; $i++) {
+                        $options[$i] = $i;
+                    }
+                    choose_from_menu($options, 'value', '', '');
+                    break;
+            }
+            break;
+    }
+    echo '<br><br>';
+    echo '<input type="submit" name="saveconditional" value="'.get_string('savecondition', 'conditional').'">';
+    echo '<input type="hidden" name="action" value="save">';
+    echo '<input type="hidden" name="conditiontype" value="'.$conditiontype.'">';
+    echo '<input type="hidden" name="subtype" value="'.$subtype.'">';
+    echo '<input type="hidden" name="instance" value="'.$conditionalinstance.'">';
+    echo '<input type="hidden" name="conditionid" value="'.$conditionid.'">';
+    echo '<input type="submit" name="cancelconditioncreation" value="'.get_string('cancel').'" onclick="document.createconditionform.action.value = \'cancel\';"/>';
+    echo '</center>';
+    echo '</form>';
+}
+
+?>
diff -Naur moodle/course/conditional/conditions.php moodle-conditionals/course/conditional/conditions.php
--- moodle/course/conditional/conditions.php	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/course/conditional/conditions.php	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,527 @@
+<?php
+
+    require_once("../../config.php");
+    require_once("$CFG->dirroot/course/lib.php");
+    require_once("conditionslib.php");
+
+    require_login();
+
+    $id = optional_param('id', 0, PARAM_INT);
+    $conditiontype = optional_param('conditiontype', NULL);
+    $deleteconditional = optional_param('deleteconditional', NULL);
+    $addconector = optional_param('addconector', NULL);
+    $addid = optional_param('addid', NULL);
+    $details = optional_param('details', NULL);
+    $subtype = optional_param('subtype', NULL);
+    $conditionalinstance = optional_param('instance', NULL, PARAM_INT);
+    $isused = optional_param('isused', NULL);
+    $conditionid = optional_param('conditionid', NULL, PARAM_INT);
+    $action = optional_param('action', NULL);
+    // If noscript we must expect that params
+    $activateconditional = optional_param('activateconditional', NULL);
+    $deactivateconditional = optional_param('deactivateconditional', NULL);
+    $agrupate = optional_param('agrupate', NULL);
+    $agrupateandreturn = optional_param('agrupateandreturn', NULL);
+
+
+    if (! $cm = get_record("course_modules", "id", $id)) {
+        print_error('invalidcoursemodule');
+    }
+
+    if (! $course = get_record("course", "id", $cm->course)) {
+        print_error('invalidcourse');
+    }
+
+    require_login($course);
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+    require_capability('moodle/local:createconditionals', $context);
+
+    if (! $module = get_record("modules", "id", $cm->module)) {
+        print_error('cmunknown');
+    }
+
+    if (! $activity = get_record($module->name, "id", $cm->instance)) {
+        print_error('cmunknown');
+    }
+
+    if(isset($deleteconditional)) {
+        conditional_delete_condition($cm->id, $deleteconditional, $isused);
+    }
+
+    if($action == 'activate' || $activateconditional) {
+        conditional_activate($cm->id);
+    }
+
+    if($action == 'deactivate' || $deactivateconditional) {
+        conditional_deactivate($cm->id);
+    }
+
+    if( ($action == 'agrupate' || $agrupate ) and isset($details)) {
+        conditional_agrupate($course->id, $cm->id, $details, $agrupateconditionalerror, false);
+    } elseif(($action == 'agrupateandreturn'  || $agrupateandreturn ) and isset($details)) {
+        conditional_agrupate($course->id, $cm->id, $details, $agrupateconditionalerror, true);
+    }
+
+    // Print the tabs
+    $overridableroles = get_overridable_roles($context);
+    $assignableroles  = get_assignable_roles($context);
+    $currenttab = 'locks';
+    include_once($CFG->dirroot.'/'.$CFG->admin.'/roles/tabs.php');
+
+    // Print the conditions table zone
+    $members = array();
+    if ($conditional = get_record('conditional', 'moduleid', $cm->id)) {
+        $members = get_records('conditional_member', 'conditionalid', $conditional->id, 'tableid asc');
+    }
+
+    if (isset($addconector)) {
+        $details .= ' '.$addconector;
+    } elseif (isset($addid)) {
+        $details = str_replace('_', ' ', $details);
+        $details .= ' '.$addid;
+    } elseif ($conditional && !isset($agrupateconditionalerror) && !isset($deactivateconditional) && !isset($activateconditional)) {
+        $details = $conditional->details;
+    }
+
+    print_heading_with_help(get_string('createdconditions', 'conditional', $activity->name), 'conditionaltable', 'conditional');
+    if($members) {
+        $table = new stdClass();
+        $table->head = array(get_string('used', 'conditional'), get_string('condition', 'conditional'), get_string('id', 'conditional'), get_string('edit', 'conditional'), get_string('delete', 'conditional'));
+        $table->align = array('center', 'left', 'center', 'center', 'center');
+        $table->data = array();
+
+        $conditionaldetail = $conditional->details;
+        $membersdesc = get_records('conditional_member', 'conditionalid', $conditional->id, 'id desc');
+        $imgused = '<img src="'.$CFG->pixpath.'/i/tick_green_big.gif">';
+        $imgnotused = '<img src="'.$CFG->pixpath.'/i/cross_red_big.gif">';
+        $pixdelete = $CFG->pixpath.'/t/delete.gif';
+        $strdelete = get_string('delete', 'conditional');
+        $pixedit = $CFG->pixpath.'/t/edit.gif';
+        $stredit = get_string('edit', 'conditional');
+        $used = array();
+        foreach ($membersdesc as $memberdesc) {
+            if (strstr($conditionaldetail, "$memberdesc->tableid")) {
+                $conditionaldetail = str_replace($memberdesc->tableid, '', $conditionaldetail);
+                $used[$memberdesc->tableid] = $imgused;
+            } else {
+                $used[$memberdesc->tableid] = $imgnotused;
+            }
+        }
+
+        foreach ($members as $member) {
+            unset($condition);
+            switch($member->type) {
+                case 'assignment':
+                    $conditionalinstance = get_record($member->type, 'id', $member->instance);
+                    if ($member->subtype == 'submit') {
+                        if ($member->op == '>') {
+                            $text = get_string('assignmentparticularhassubmit', 'conditional', $conditionalinstance->name);
+                        } else {
+                            $text = get_string('assignmentparticularhasntsubmit', 'conditional', $conditionalinstance->name);
+                        }
+                    } elseif ($member->subtype == 'grade') {
+                        $condition->instance = $conditionalinstance->name;
+                        $condition->op = operator_to_string($member->op);
+                        $text = get_string('assignmentstudentgrade', 'conditional', $condition);
+                        if ($conditionalinstance->grade > 0) {
+                            $text .= $member->value;
+                        } elseif ($conditionalinstance->grade < 0) {
+                            $scale = get_record('scale', 'id', abs($conditionalinstance->grade));
+                            $scalevalues = explode(',', $scale->scale);
+                            $text .= $scalevalues[$member->value - 1];
+                        }
+                    }
+                    break;
+                case 'book':
+                    $conditionalinstance = get_record($member->type, 'id', $member->instance);
+                    $condition = $conditionalinstance->name;
+                    if ($member->op == '>') {
+                        $text = get_string('bookparticipanthasaccessdisplay', 'conditional', $condition);
+                    } else {
+                        $text = get_string('bookparticipanthasntaccessdisplay', 'conditional', $condition);
+                    }
+                    break;
+                case 'chat':
+                    $conditionalinstance = get_record($member->type, 'id', $member->instance);
+                    if($member->subtype == 'say') {
+                        $text = get_string('chatparticularhasparticipated', 'conditional', $conditionalinstance->name);
+                    } elseif($member->subtype == 'notsay') {
+                        $text = get_string('chatparticularhasntparticipated', 'conditional', $conditionalinstance->name);
+                    }
+                    break;
+                case 'choice':
+                    $conditionalinstance = get_record($member->type, 'id', $member->instance);
+                    $option = get_record('choice_options', 'id', $member->value);
+                    $condition->instance = $conditionalinstance->name;
+                    if($member->subtype == 'anyanswer') {
+                        $text = get_string('choiceanyanswerdisplay', 'conditional', $condition);
+                    } elseif ($member->subtype == 'particularanswer') {
+                        $condition->op = operator_to_string($member->op);
+                        $condition->text = $option->text;
+                        $text = get_string('choiceparticularanswerdisplay', 'conditional', $condition);
+                    }
+                    break;
+                case 'conditionalbook':
+                    $conditionalinstance = get_record($member->type, 'id', $member->instance);
+                    $condition = $conditionalinstance->name;
+                    if ($member->op == '>') {
+                        $text = get_string('conditionalbookparticipanthasaccessdisplay', 'conditional', $condition);
+                    } else {
+                        $text = get_string('conditionalbookparticipanthasntaccessdisplay', 'conditional', $condition);
+                    }
+                    break;
+                case 'dialogue':
+                    $conditionalinstance = get_record($member->type, 'id', $member->instance);
+                    $condition->instance = $conditionalinstance->name;
+                    $condition->op = operator_to_string($member->op);
+                    $condition->value = $member->value;
+                    $text = get_string('dialogueparticipantconversations', 'conditional', $condition);
+                    break;
+                case 'forum':
+                    $conditionalinstance = get_record($member->type, 'id', $member->instance);
+                    $condition->instance = $conditionalinstance->name;
+                    $condition->op = operator_to_string($member->op);
+                    $condition->value = $member->value;
+                    if ($member->subtype == 'discussions') {
+                        $text = get_string('forumconditionparticulardiscussions', 'conditional', $condition);
+                    } elseif($member->subtype == 'messages') {
+                        $text = get_string('forumconditionparticularmessages', 'conditional', $condition);
+                    } elseif($member->subtype == 'success') {
+                        $text = get_string('forumconditionparticularsuccess', 'conditional', $condition);
+                    } elseif($member->subtype == 'answers') {
+                        $text = get_string('forumconditionparticularanswers', 'conditional', $condition);
+                    } elseif($member->subtype == 'grade') {
+                        $text = get_string('forumconditionparticulargrade', 'conditional', $condition);
+                        if ($conditionalinstance->scale > 0) {
+                            $text .= $member->value;
+                        } elseif ($conditionalinstance->scale < 0) {
+                            $scale = get_record('scale', 'id', abs($conditionalinstance->scale));
+                            $scalevalues = explode(',', $scale->scale);
+                            $text .= $scalevalues[$member->value - 1];
+                        }
+                    }
+                    break;
+                case 'glossary':
+                    $conditionalinstance = get_record($member->type, 'id', $member->instance);
+                    $condition->instance = $conditionalinstance->name;
+                    $condition->op = operator_to_string($member->op);
+                    $condition->value = $member->value;
+                    if($member->subtype == 'entries') {
+                        $text = get_string('glossaryconditionparticularentries', 'conditional', $condition);
+                    } elseif($member->subtype == 'comments') {
+                        $text = get_string('glossaryconditionparticularcomments', 'conditional', $condition);
+                    }
+                    break;
+                case 'lesson':
+                    $conditionalinstance = get_record($member->type, 'id', $member->instance);
+                    if($member->subtype == 'grade') {
+                        $condition->instance = $conditionalinstance->name;
+                        $condition->op = operator_to_string($member->op);
+                        $condition->value = $member->value;
+                        $text = get_string('lessonconditiongrade', 'conditional', $condition);
+                    } else {
+                        $page = get_record('lesson_pages', 'id', $member->subtype);
+
+                        $condition->question = $page->title;
+                        $condition->instance = $conditionalinstance->name;
+                        $condition->op = operator_to_string($member->op);
+
+                        switch($page->qtype) {
+                            case 1: /// short answer
+                            case 2: /// true/false
+                            case 3: /// multichoice
+                                $answer = get_record('lesson_answers', 'id', $member->value);
+                                $condition->answer = $answer->answer;
+                                $text = get_string('lessonquestionshort', 'conditional', $condition);
+                                break;
+                            case 8: /// numerical
+                                $condition->value = $member->value;
+                                $text = get_string('lessonquestionnumerical', 'conditional', $condition);
+                                break;
+                            case 5: /// match
+                                $condition->value = $member->value;
+                                $text = get_string('lessonquestionmatch', 'conditional', $condition);
+                                break;
+                            case 10: /// essay
+                                $condition->value = $member->value;
+                                $text = get_string('lessonquestionessay', 'conditional', $condition);
+                                break;
+                        }
+                    }
+                    break;
+                case 'quiz':
+                    $conditionalinstance = get_record($member->type, 'id', $member->instance);
+                    if($member->subtype == 'grade') {
+                        $condition->instance = $conditionalinstance->name;
+                        $condition->op = operator_to_string($member->op);
+                        $condition->value = $member->value;
+                        $text = get_string('quizconditiongrade', 'conditional', $condition);
+                    } else {
+                        $questioninstance = get_record('quiz_question_instances', 'id', $member->subtype);
+                        $question = get_record('question', 'id', $questioninstance->question);
+
+                        $condition->question = $question->name;
+                        $condition->instance = $conditionalinstance->name;
+                        $condition->op = operator_to_string($member->op);
+
+                        switch($question->qtype) {
+                            case 'shortanswer':
+                            case 'truefalse':
+                            case 'multichoice':
+                            case 'calculated':
+                                $answer = get_record('question_answers', 'id', $member->value);
+                                $condition->answer = $answer->answer;
+                                $text = get_string('quizquestionshort', 'conditional', $condition);
+                                break;
+                            case 'numerical':
+                                $condition->value = $member->value;
+                                $text = get_string('quizquestionnumerical', 'conditional', $condition);
+                                break;
+                            case 'match':
+                                $condition->value = $member->value;
+                                $text = get_string('quizquestionmatch', 'conditional', $condition);
+                                break;
+                            case 'randomsamatch':
+                                $condition->value = $member->value;
+                                $text = get_string('quizquestionrandom', 'conditional', $condition);
+                                break;
+                        }
+                    }
+                    break;
+                case 'resource':
+                    $conditionalinstance = get_record($member->type, 'id', $member->instance);
+                    $condition = $conditionalinstance->name;
+                    if ($member->op == '>') {
+                        $text = get_string('resourcestudenthasaccessdisplay', 'conditional', $condition);
+                    } else {
+                        $text = get_string('resourcestudenthasntaccessdisplay', 'conditional', $condition);
+                    }
+                    break;
+                case 'wiki':
+                    $conditionalinstance = get_record($member->type, 'id', $member->instance);
+                    $condition->instance = $conditionalinstance->name;
+                    $condition->op = operator_to_string($member->op);
+                    $condition->value = $member->value;
+                    $text = get_string('wikiparticular', 'conditional', $condition);
+                    break;
+                case 'workshop':
+                    $conditionalinstance = get_record($member->type, 'id', $member->instance);
+                    $condition->instance = $conditionalinstance->name;
+                    $condition->op = operator_to_string($member->op);
+                    $condition->value = $member->value;
+                    $text = get_string('workshopparticular', 'conditional', $condition);
+                    break;
+                case 'role':
+                    $condition->op = operator_to_string($member->op);
+                    $condition->value = $member->value;
+                    $text = get_string('roleparticular', 'conditional', $condition);
+                    break;
+                case 'lang':
+                    $condition->op = operator_to_string($member->op);
+                    $condition->value = $member->value;
+                    $text = get_string('studentlangparticular', 'conditional', $condition);
+                    break;
+                case 'country':
+                    $condition->op = operator_to_string($member->op);
+                    $condition->value = $member->value;
+                    $text = get_string('studentcountryparticular', 'conditional', $condition);
+                    break;
+                case 'picture':
+                    if ($member->op == '>') {
+                        $text = get_string('picturehaschanged', 'conditional');
+                    } elseif ($member->op == '==') {
+                        $text = get_string('picturehasnotchanged', 'conditional');
+                    }
+                    break;
+                case 'enrolment':
+                    $condition->op = operator_to_string($member->op);
+                    $condition->days = $member->value;
+                    $text = get_string('enrolmenttimedifferencedisplay', 'conditional', $condition);
+                    break;
+                case 'startdate':
+                    $condition->op = operator_to_string($member->op);
+                    $condition->days = $member->value;
+                    $text = get_string('starttimedifferencedisplay', 'conditional', $condition);
+                    break;
+                case 'date':
+                    $condition->date = userdate($member->instance);
+                    $condition->op = operator_to_string($member->op);
+                    $condition->days = $member->value;
+                    $text = get_string('datetimedifferencedisplay', 'conditional', $condition);
+                    break;
+            }
+
+            if (strstr($conditional->details, "$member->tableid")) {
+                $detailsprobe = $conditional->details;
+                $tableidlength = strlen("$member->tableid");
+                $isused = false;
+                while ( strstr($detailsprobe, "$member->tableid") and !$isused) {
+                    $position = strpos($detailsprobe, "$member->tableid");
+                    $isused = true;
+                    if ( ($position > 0) and strstr('0123456789', substr($detailsprobe, $position - 1, 1))) {
+                        $isused = false;
+                    }
+                    if ( (($position + $tableidlength) < strlen($detailsprobe) ) and strstr('0123456789', substr($detailsprobe, $position + $tableidlength, 1))) {
+                        $isused = false;
+                    }
+                    if (!$detailsprobe = substr($detailsprobe, $position + $tableidlength + 1)) {
+                        $detailsprobe = '';
+                    }
+                }
+            } else {
+                $isused = false;
+            }
+
+            $deleteurl = 'conditions.php?id='.$cm->id.'&amp;deleteconditional='.$member->id.'&amp;isused='.$isused.'#labelconditional';
+
+            $delete = "<noscript><a href='$deleteurl' title='$strdelete'><img src='$pixdelete' align='absmiddle' border=0></a></noscript><script><!--
+                document.write(\"<a href='#labelconditional'  title='$strdelete' onClick=checkdeletecondition('$isused','$deleteurl');><img src='$pixdelete' align='absmiddle' border=0></a>\");
+                --></script>";
+
+
+            $edit = '<a href=conditioncreation.php?id='.$cm->id.'&amp;conditionid='.$member->id." title=\"$stredit\">"."<img src=\"$pixedit\"></a>";
+
+            $identifier = "<noscript><input type='submit' name='addconector' value='$member->tableid'></noscript><script><!--
+                document.write(\"<input type=button value='$member->tableid' title='".get_string('addcondition', 'conditional', $member->tableid)."' onClick=addconector('$member->tableid');>\");
+                --></script>";
+
+            array_push($table->data, array($used[$member->tableid], $text, $identifier, $edit, $delete));
+        }
+
+        echo "<noscript><form name='agrupateconditionsform' method='POST' action='conditions.php?id=".$cm->id."#labelagrupateconditional'></noscript>";
+        print_table($table);
+        echo "<noscript><input type='hidden' name='details' value='$details'></form></noscript>";
+
+?>
+
+        <script>
+        <!-- // BEGIN
+
+            function checkdeletecondition(isinagregation, url) {
+                if (isinagregation) {
+                    if (confirm("<?php print_string('deleteusedcondition', 'conditional') ?>")) {
+                        window.location = url;
+                    }
+                } else {
+                    window.location = url;
+                }
+            }
+
+        // END -->
+        </script>
+
+<?php
+
+    } else {
+        echo "<center>";
+        print_string('nocreatedconditions', 'conditional');
+        echo "</center>";
+    }
+
+    echo "<br>";
+    echo "<center>";
+    echo "<form name='createconditionform' method='POST' action='conditioncreation.php?id=".$cm->id."'>";
+    echo '<input type="submit" name="createcondition" value="'.get_string('createcondition', 'conditional').'">';
+    helpbutton('conditionalcreation', get_string('createcondition', 'conditional'), 'conditional');
+    echo "</form>";
+    echo "</center>";
+
+    // Agrupate conditions zone
+    if ($members) {
+
+        // Print heading and advisory text
+        echo '<br><br>';
+        echo '<a name="labelagrupateconditional"></a>';
+        print_heading_with_help(get_string('agrupateconditions', 'conditional'), 'conditionalgrouping', 'conditional');
+        echo '<center>';
+        echo "<form name='agrupateconditionsform' method='POST' action='conditions.php?id=".$cm->id."#labelagrupateconditional'>";
+        echo '<input type="hidden" name="action">';
+        print_string('agregateconditionswarning', 'conditional');
+        echo '<br><br>';
+
+        // Print conectors buttons
+?>
+        <script>
+        <!-- // BEGIN
+
+            function addconector(conector) {
+                document.agrupateconditionsform.details.value = document.agrupateconditionsform.details.value + " " + conector;
+            }
+
+            document.write("<input type=button value='(' onClick=addconector(\"(\");>");
+            document.write("<input type=button value=')' onClick=addconector(\")\");>");
+            document.write("<input type=button value='not' onClick=addconector(\"not\");>");
+            document.write("<input type=button value='and' onClick=addconector(\"and\");>");
+            document.write("<input type=button value='or' onClick=addconector(\"or\");>");
+
+        // END -->
+        </script>
+
+        <noscript>
+            <input type="submit" name="addconector" value="(">
+            <input type="submit" name="addconector" value=")">
+            <input type="submit" name="addconector" value="not">
+            <input type="submit" name="addconector" value="and">
+            <input type="submit" name="addconector" value="or">
+        </noscript>
+
+<?php
+        // Print the rest of the agrupate conditions zone
+        echo '<br><br>';
+        print_string('conditionscombination', 'conditional');
+        echo '<input type="text" name="details" value="'.$details.'" size="60">';
+
+        if ($conditional->inuse) {
+            echo '<input type="submit" name="deactivateconditional" value="'.get_string('deactivateconditional', 'conditional').'" onclick="document.agrupateconditionsform.action.value = \'deactivate\';">';
+        } else {
+            echo '<input type="submit" name="activateconditional" value="'.get_string('activateconditional', 'conditional').'" onclick="document.agrupateconditionsform.action.value = \'activate\';">';
+            echo '<br><br>';
+            echo '<FONT color=red>'.get_string('conditionaldisabled', 'conditional').'</FONT>';
+        }
+
+        if( ($action == 'agrupate' || $action == 'agrupateandreturn' || $agrupate || $agrupateandreturn) and isset($agrupateconditionalerror)) {
+            echo '<br><br>';
+            echo '<FONT color=red>'.get_string('invalidsyntax', 'conditional').'</FONT>';
+        }
+
+?>
+        <br><br>
+        <input type="submit" name="agrupate" value="<?php print_string('savechanges') ?>" onclick="document.agrupateconditionsform.action.value = 'agrupate';">
+        <input type="submit" name="agrupateandreturn" value="<?php print_string('savechangesandreturntocourse') ?>" onclick="document.agrupateconditionsform.action.value = 'agrupateandreturn';">
+
+<?php
+
+        echo '</form>';
+        echo '</center>';
+
+    }
+    print_footer($course);
+
+    function operator_to_string($operator) {
+        switch($operator) {
+            case '==':
+                $text = get_string('equal', 'conditional');
+                break;
+            case '!=':
+                $text = get_string('distinct', 'conditional');
+                break;
+            case '>':
+                $text = get_string('greater', 'conditional');
+                break;
+            case '<':
+                $text = get_string('less', 'conditional');
+                break;
+            case '>=':
+                $text = get_string('greaterequal', 'conditional');
+                break;
+            case '<=':
+                $text = get_string('lessequal', 'conditional');
+                break;
+            default:
+                $text = '';
+                break;
+        }
+        return $text;
+    }
+
+?>
\ No hay ningún carácter de nueva línea al final del fichero
diff -Naur moodle/course/edit_form.php moodle-conditionals/course/edit_form.php
--- moodle/course/edit_form.php	2009-02-13 23:06:00.000000000 +0000
+++ moodle-conditionals/course/edit_form.php	2009-09-16 13:38:34.000000000 +0100
@@ -170,6 +170,33 @@
             $mform->setHelpButton('nometacourse', array('metacourse', get_string('metacourse')), true);
         }
 
+        /// START COMMENTS
+        $uselabeloptions = array();
+        $uselabeloptions[0] = get_string('no');
+        $uselabeloptions[1] = get_string('yes', 'conditional');
+        $uselabeloptions[2] = get_string('personalized', 'conditional');
+        $mform->addElement('select', 'uselabel', get_string('courseuselabel', 'conditional'), $uselabeloptions);
+        $mform->setHelpButton('uselabel', array('courseuselabel', get_string('courseuselabel', 'conditional'), 'conditional'), true);
+        $mform->setDefault('uselabel', 0);
+
+        $mform->addElement('text','personalizedlabel', get_string('personalizedlabel', 'conditional'),'maxlength="50" size="50"');
+        $mform->setHelpButton('personalizedlabel', array('personalizedlabel', get_string('personalizedlabel', 'conditional'), 'conditional'), true);
+        $mform->setType('personalizedlabel', PARAM_MULTILANG);
+        $mform->disabledIf('personalizedlabel', 'uselabel', 'neq', 2);
+        /// END COMMENTS
+
+        /// START CONDITIONALS
+        $useconditionalsoptions = array();
+        $useconditionalsoptions[0] = get_string('no');
+        $useconditionalsoptions[1] = get_string('yes');
+        $mform->addElement('select', 'useconditionals', get_string('useconditionals', 'conditional'), $useconditionalsoptions);
+        $mform->setDefault('useconditionals', 0);
+        if ($course and !has_capability('moodle/local:useconditionals', $coursecontext)) {
+            $mform->hardFreeze('useconditionals');
+            $mform->setConstants('useconditionals', $course->useconditionals);
+        }
+        /// END CONDITIONALS
+
 //--------------------------------------------------------------------------------
         $mform->addElement('header','enrolhdr', get_string('enrolments'));
 
diff -Naur moodle/course/lib.php moodle-conditionals/course/lib.php
--- moodle/course/lib.php	2009-05-15 10:10:34.000000000 +0100
+++ moodle-conditionals/course/lib.php	2009-09-16 13:38:34.000000000 +0100
@@ -23,7 +23,7 @@
 define('MOD_CLASS_ACTIVITY', 0);
 define('MOD_CLASS_RESOURCE', 1);
 
-if (!defined('MAX_MODINFO_CACHE_SIZE')) { 
+if (!defined('MAX_MODINFO_CACHE_SIZE')) {
     define('MAX_MODINFO_CACHE_SIZE', 10);
 }
 
@@ -1117,6 +1117,16 @@
     // If we haven't already preloaded contexts for the course, do it now
     preload_course_contexts($course->id);
 
+    /// START CONDITIONALS
+    require_once("$CFG->libdir/conditional.php");
+    if(!isset($course->useconditionals)) {
+        $course->useconditionals = 0;
+    }
+    if ($course->useconditionals) {
+        $conditionalvisibilities = conditional_user_course_visibility($course->id, $userid);
+    }
+    /// END CONDITIONALS
+
     foreach ($info as $mod) {
         if (empty($mod->name)) {
             // something is wrong here
@@ -1149,8 +1159,12 @@
 
         $modcontext = get_context_instance(CONTEXT_MODULE,$cm->id);
 
-        if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', 
-            $modcontext, $userid)) {
+        /// START CONDITIONALS
+        //if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities',
+        //    $modcontext, $userid)) {
+        if ((($course->useconditionals && !$conditionalvisibilities[$cm->id]) || !$cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $modcontext, $userid)) {
+        /// END CONDITIONALS
+
             $cm->uservisible = false;
 
         } else if (!empty($CFG->enablegroupings) and !empty($cm->groupmembersonly)
@@ -1422,12 +1436,48 @@
                     $altname = get_accesshide(' '.$altname);
                 }
 
+                /// START COMMENTS
+                $novelty = false;
+                if ($mod->info or $course->uselabel) {
+                    $novelty = evaluate_novelty($USER->id, $course->id, $mod->id);
+                }
+                if($novelty and $mod->info) {
+                    echo $mod->info;
+                    echo '<br>';
+                    if ($mod->indent) {
+                        print_spacer(12, 20 * $mod->indent, false);
+                    }
+                }
+                /// END COMMENTS
+
                 $linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
                 echo '<a '.$linkcss.' '.$extra.        // Title unnecessary!
                      ' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.
                      '<img src="'.$icon.'" class="activityicon" alt="" /> <span>'.
                      $instancename.$altname.'</span></a>';
 
+                /// START COMMENTS
+                if (!$novelty && $mod->info) {
+                    $url = '/help.php?text='. s(urlencode($mod->info));
+                    $tooltip = get_string('helpprefix2', '', trim(get_string('activityinfo', 'conditional'), ". \t")) .' ('.get_string('newwindow').')';
+                    $linkobject = '<img class="iconhelp" alt="'.s(strip_tags($tooltip)).'" src="'.
+                        $CFG->pixpath .'/help.gif" />';
+                    $link = '<span class="helplink">'.
+                        link_to_popup_window ($url, 'popup', $linkobject, 400, 500, $tooltip, 'none', true).
+                    	'</span>';
+                    echo $link;
+                } elseif($novelty && $course->uselabel) {
+                    echo ' ';
+                    echo '<span class="highlight" title="'.get_string('newtitle', 'conditional').'">';
+                    if ($course->uselabel == 1) {
+                        print_string('new', 'conditional');
+                    } elseif (($course->uselabel == 2) && ($course->personalizedlabel)) {
+                        p($course->personalizedlabel);
+                    }
+                    echo '</span>';
+                }
+                /// END COMMENTS
+
                 if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                     if (!isset($groupings)) {
                         $groupings = groups_get_all_groupings($course->id);
@@ -1458,6 +1508,17 @@
                     $mod->groupmode = false;
                 }
                 echo '&nbsp;&nbsp;';
+
+                /// START CONDITIONALS
+                if ($course->useconditionals) {
+                    if ($conditional = get_record('conditional', 'moduleid', $mod->id)) {
+                        if ( ($conditional->details <> '') && ($conditional->inuse) ) {
+                            print_string('locked', 'conditional');
+                        }
+                    }
+                }
+                /// END CONDITIONALS
+
                 echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
             }
             echo "</li>\n";
diff -Naur moodle/lang/en_utf8/conditional.php moodle-conditionals/lang/en_utf8/conditional.php
--- moodle/lang/en_utf8/conditional.php	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/lang/en_utf8/conditional.php	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,153 @@
+<?php
+$string['activateconditional'] = 'Activate conditional';
+$string['activities'] = 'Activities';
+$string['activityinfo'] = 'Activity information';
+$string['activityinfocreation'] = 'Creation of activity information for $a';
+$string['activitylocks'] = 'Conditionals';
+$string['addcondition'] = 'Add $a to grouping of members';
+$string['agregateconditionswarning'] = 'You must fill at least one condition next in order to this activity will be locked.';
+$string['agrupateconditions'] = 'Combine the different conditions using logic operators';
+$string['assignmentgrade'] = 'mark obtained in the assignment';
+$string['assignmentgradeselect'] = 'mark obtained in the assignment: ';
+$string['assignmentparticulargrade'] = 'mark obtained in the assignment <B>$a</B> ';
+$string['assignmentparticularhasntsubmit'] = 'The student has not sent the assignment <B>$a</B> ';
+$string['assignmentparticularhassubmit'] = 'The student has sent the assignment <B>$a</B> ';
+$string['assignmentstudentgrade'] = 'The mark obtained in <B>$a->instance</B> is $a->op ';
+$string['assignmentstudenthasntsubmit'] = 'The student has not sent the assignment';
+$string['assignmentstudenthassubmit'] = 'The student has sent the assignment';
+$string['assignmentsubmit'] = 'assignment shipment';
+$string['bookparticipanthasaccess'] = 'Student has access to book ';
+$string['bookparticipanthasaccessdisplay'] = 'Student has access to book <B>$a</B> ';
+$string['bookparticipanthasntaccess'] = 'Student has not access to book ';
+$string['bookparticipanthasntaccessdisplay'] = 'Student has not access to book <B>$a</B> ';
+$string['chatparticularhasntparticipated'] = 'The student has not participated in <B>$a</B> ';
+$string['chatparticularhasparticipated'] = 'The student has participated in <B>$a</B> ';
+$string['chatstudenthasntparticipated'] = 'The student has not participated in the chat';
+$string['chatstudenthasparticipated'] = 'The student has participated in the chat';
+$string['choiceanyanswer'] = 'The student has answered to the choice';
+$string['choiceanyanswerdisplay'] = 'The student has answered to the choice <B>$a->instance</B>';
+$string['choiceparticularanswer'] = 'Answer given to the choice';
+$string['choiceparticularanswerdisplay'] = 'Answer given to <B>$a->instance</B> is $a->op $a->text';
+$string['choiceparticularansweris'] = 'Answer given to the choice <B>$a</B> is ';
+$string['choiceselect'] = 'Choose the choice: ';
+$string['conditionalbookparticipanthasaccess'] = 'Student has access to conditional book ';
+$string['conditionalbookparticipanthasaccessdisplay'] = 'Student has access to conditional book <B>$a</B> ';
+$string['conditionalbookparticipanthasntaccess'] = 'Student has not access to conditional book ';
+$string['conditionalbookparticipanthasntaccessdisplay'] = 'Student has not access to conditional book <B>$a</B> ';
+$string['conditionaldisabled'] = '<b>Warning:</b> this conditional is deactivated and therefore it will not be used in the course. If you want to activate it click in the button \"Activate conditional\"';
+$string['conditioncreation'] = 'Creation of conditions for $a';
+$string['condition'] = 'Condition';
+$string['conditions'] = 'Conditions';
+$string['conditionscombination'] = 'Conditions combination: ';
+$string['courseuselabel'] = 'To stand out new activities';
+$string['createconditional'] = 'Save changes and create conditional';
+$string['createconditionalandfinish'] = 'Create conditional and Finish buttons';
+$string['createcondition'] = 'Create new condition';
+$string['createdconditions'] = 'Created conditions for $a';
+$string['date'] = 'Date';
+$string['datetimedifference'] = 'Time passed (in days) since date ';
+$string['datetimedifferencedisplay'] = 'Time passed since date $a->date is $a->op $a->days days';
+$string['deactivateconditional'] = 'Deactivate conditional';
+$string['delete'] = 'Delete';
+$string['deleteusedcondition'] = 'An used condition is going to be deleted. So Conditions combination (at the bottom of this page) will be deleted and this activity will not be locked. Therefore you will have to fill Conditions combination again to turn this activity locked. Continue anyway?';
+$string['dialogueconversations'] = 'Number of started dialogues';
+$string['dialogueparticularconversations'] = 'Number of started dialogues in <B>$a</B> is ';
+$string['dialogueparticipantconversations'] = 'Number of started dialogues in <B>$a->instance</B> is $a->op $a->value';
+$string['distinct'] = 'different from';
+$string['edit'] = 'Edit';
+$string['editingactivityinfo'] = 'Editing activity info';
+$string['editingconditionals'] = 'Editing conditionals';
+$string['editingview'] = 'Editing course view';
+$string['enrolment'] = 'Enrolment';
+$string['enrolmenttimedifference'] = 'Time passed (in days) since student enrolment date in course is ';
+$string['enrolmenttimedifferencedisplay'] = 'Time passed since student enrolment date in course is $a->op $a->days days';
+$string['equal'] = 'equal to';
+$string['errormarkst'] = 'There are no tests available!';
+$string['forumanswers'] = 'Number of different discussions in which the student has posted';
+$string['forumdiscussions'] = 'Discussions initiated by the student in the forum';
+$string['forumgrade'] = 'Grade obtained by the student in the forum';
+$string['forummessages'] = 'Messages of the student in the forum';
+$string['forumconditionparticularanswers'] = 'The number of discussions been posted in <B>$a->instance</B> is $a->op $a->value';
+$string['forumconditionparticulardiscussions'] = 'The number of discussions initiated in <B>$a->instance</B> is $a->op $a->value';
+$string['forumconditionparticulargrade'] = 'The grade obtained in <B>$a->instance</B> is $a->op ';
+$string['forumconditionparticularmessages'] = 'The number of messages placed in <B>$a->instance</B> is $a->op $a->value';
+$string['forumconditionparticularsuccess'] = 'The number of answers obtained in <B>$a->instance</B> is $a->op $a->value';
+$string['forumparticularanswers'] = 'The number of discussions been posted in the forum <B>$a</B> is: ';
+$string['forumparticulardiscussions'] = 'The number of discussions initiated in the forum <B>$a</B> is: ';
+$string['forumparticulargrade'] = 'The student grade obtained in the forum <B>$a</B> is: ';
+$string['forumparticularmessages'] = 'The number of messages placed in the forum <B>$a</B> is: ';
+$string['forumparticularsuccess'] = 'The number of answers obtained in the forum <B>$a</B> is: ';
+$string['forumsuccess'] = 'Number of replies to student\'s messages';
+$string['finish'] = 'Finish';
+$string['general'] = 'General';
+$string['glossarycomments'] = 'Commentaries added to the glossary by the student';
+$string['glossaryconditionparticularcomments'] = 'The number of commentaries added to <B>$a->instance</B> is $a->op $a->value';
+$string['glossaryconditionparticularentries'] = 'The number of entries added to <B>$a->instance</B> is $a->op $a->value';
+$string['glossaryentries'] = 'Entries added to the glossary by the student';
+$string['glossaryparticularcomments'] = 'The number of commentaries done to terms of the glossary <B>$a</B> is ';
+$string['glossaryparticularentries'] = 'The number of entries added to the glossary <B>$a</B> is ';
+$string['greater'] = 'greater than';
+$string['greaterequal'] = 'greater or equal than';
+$string['id'] = 'To use';
+$string['invalidsyntax'] = '<b>There is an error:</b> probably the introduced syntax is not valid or any identifier number is not valid. You must check the conditions combination';
+$string['less'] = 'less than';
+$string['lessequal'] = 'less or equal than';
+$string['lessonanswer'] = 'Answer given to a question of the lesson';
+$string['lessonconditiongrade'] = 'The grade obtained in <B>$a->instance</B>, in percentage of the possible highest mark, is $a->op $a->value';
+$string['lessonessaygrade'] = 'The score obtained in the question <B>$a</B> is ';
+$string['lessongrade'] = 'Mark obtained in the lesson';
+$string['lessonmatchs'] = 'The number of correct matches in the question <B>$a</B> is ';
+$string['lessonparticulargrade'] = 'Grade obtained in the lesson <B>$a</B>, in percentage of the possible highest mark, is ';
+$string['lessonquestionanswer'] = 'The answer given to the question <B>$a</B> is ';
+$string['lessonquestionessay'] = 'The obtained score in the question <B>$a->question</B> of <B>$a->instance</B> is $a->op $a->value';
+$string['lessonquestionmatch'] = 'The number of correct matches in the question <B>$a->question</B> of <B>$a->instance</B> is $a->op $a->value';
+$string['lessonquestionnumerical'] = 'The answer given to the question <B>$a->question</B> of <B>$a->instance</B> is $a->op $a->value';
+$string['lessonquestionshort'] = 'The answer given to the question <B>$a->question</B> of <B>$a->instance</B> is $a->op $a->answer';
+$string['lessonselectquestion'] = 'Choose the due question of the lesson <B>$a</B>: ';
+$string['locked'] = '(Locked) ';
+$string['new'] = 'NEW';
+$string['newtitle'] = 'You have not seen this course element';
+$string['nocreatedconditions'] = 'Conditions have not been created yet';
+$string['notuseconditionals'] = 'Don\'t use Conditionals';
+$string['personalized'] = 'Yes - personalized label';
+$string['personalizedlabel'] = 'Personalized label';
+$string['picture'] = 'Participant picture';
+$string['picturehaschanged'] = 'Participant has changed his picture';
+$string['picturehasnotchanged'] = 'Participant has not changed his picture';
+$string['quizanswer'] = 'Answer given to a question of the quiz';
+$string['quizconditiongrade'] = 'The mark obtained in <B>$a->instance</B>, in percentage of the possible highest mark, is $a->op $a->value';
+$string['quizgrade'] = 'Mark obtained in the quiz';
+$string['quizmatchs'] = 'The number of successes in the question <B>$a</B> is ';
+$string['quizparticulargrade'] = 'The mark obtained in the quiz <B>$a</B>, in percentage of the possible highest mark, is ';
+$string['quizquestionanswer'] = 'The answer given to the question <B>$a</B> is ';
+$string['quizquestionmatch'] = 'The number of correct matches in the question <B>$a->question</B> of <B>$a->instance</B> is $a->op $a->value';
+$string['quizquestionnumerical'] = 'The answer given to the question <B>$a->question</B> of <B>$a->instance</B> is $a->op $a->value';
+$string['quizquestionrandom'] = 'The number of successes in the question <B>$a->question</B> of <B>$a->instance</B> is $a->op $a->value';
+$string['quizquestionshort'] = 'The answer given to the question <B>$a->question</B> of <B>$a->instance</B> is $a->op $a->answer';
+$string['quizselectquestion'] = 'Choose the wished question of the quiz <B>$a</B>: ';
+$string['resourcestudenthasaccess'] = 'Student has access to resource ';
+$string['resourcestudenthasaccessdisplay'] = 'Student has access to resource <B>$a</B> ';
+$string['resourcestudenthasntaccess'] = 'Student has not access to resource ';
+$string['resourcestudenthasntaccessdisplay'] = 'Student has not access to resource <B>$a</B> ';
+$string['role'] = 'Participant role';
+$string['roleparticular'] = 'The <B>role</B> of the user is $a->op $a->value';
+$string['savecondition'] = 'Save condition';
+$string['selectactivitytype'] = 'Choose type of item to apply condition to: ';
+$string['startdate'] = 'Course start';
+$string['starttimedifference'] = 'Time passed (in days) since course start date is ';
+$string['starttimedifferencedisplay'] = 'Time passed since course start date is $a->op $a->days days';
+$string['studentlang'] = 'Student language ';
+$string['studentlangparticular'] = 'The <B>language</B> of the student is $a->op $a->value';
+$string['studentcountry'] = 'Student country ';
+$string['studentcountryparticular'] = 'The <B>country</B> of the student is $a->op $a->value';
+$string['useconditionals'] = 'Use conditionals';
+$string['used'] = 'In use';
+$string['userrole'] = 'The role of the user is ';
+$string['wiki'] = 'The number of times that the student has published the wiki ';
+$string['wikiis'] = ' is ';
+$string['wikiparticular'] = 'The number of times that the student has published <B>$a->instance</B> is $a->op $a->value';
+$string['workshop'] = 'The grade (in percentage of the possible highest mark) obtained in the workshop ';
+$string['workshopis'] = ' is ';
+$string['workshopparticular'] = 'The grade obtained in <B>$a->instance</B>, in percentage of the possible highest mark, is $a->op $a->value';
+$string['yes'] = 'Yes - NEW label';
+?>
diff -Naur moodle/lang/en_utf8/help/conditional/activityinfocreation.html moodle-conditionals/lang/en_utf8/help/conditional/activityinfocreation.html
--- moodle/lang/en_utf8/help/conditional/activityinfocreation.html	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/lang/en_utf8/help/conditional/activityinfocreation.html	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,3 @@
+<P ALIGN=CENTER><B>Activity info creation</B></P>
+
+<P>From this page any kind of information related to an activity can be defined. This information will appear to the student in the course main page and above of the activity name until student click on the activity. Once the student has acceded to the activity it will be possible accede to this information by means of the help button that appears next to the name of the activity.</P>
diff -Naur moodle/lang/en_utf8/help/conditional/conditionalcreation.html moodle-conditionals/lang/en_utf8/help/conditional/conditionalcreation.html
--- moodle/lang/en_utf8/help/conditional/conditionalcreation.html	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/lang/en_utf8/help/conditional/conditionalcreation.html	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,78 @@
+<P ALIGN=CENTER><B>Creation of conditional activities</B></P>
+
+<P>From this section it is possible to create conditionals to manage to establish an itinerary or rate of customized learning for each student of the course. The activities or resources will be shown to each student according to their interaction with the course. That is to say, thanks to conditionals, the activities or resources will not appear all together, but at the suitable moment, the tutor not worrying to hide them or making them visible according to the established programming.</P> 
+
+<P>The appearance or not appearance of any activity can be conditioned to one or several of the described conditions described below.</P>
+
+<P>The process requires two steps:</P>
+ 
+<ul>1.- create one or several conditions choosing between the different options that appear</ul>
+<ul>2.- combine the created conditions using logic operators</ul>
+  
+<P>The result is that this activity or resource will not be shown to a certain student until the conditions combination previously defined is not fulfilled for this student.</P>
+
+<P>The available conditions types are the following ones:</P>
+
+<P><B>Assignment</B></P>
+<UL>It is possible to be conditioned to that the student has or not sent a determined assignment of the course.</UL>
+<UL>It is possible to be conditioned to that the grade obtained by the student in a determined assignment of the course is equal, different, greater, smaller, greater or equal or smaller or equal as any possible grade for this assignment, being this a numerical value or one customized scale.</UL>
+
+<P><B>Chat</B></P>
+<UL>It is possible to be conditioned to that the student has opened or not a determined chat window in the course.</UL>
+
+<P><B>Choice</B></P>
+<UL>It is possible to be conditioned to that the student has answered or not a determined choice of the course.</UL>
+<UL>It is possible to be conditioned to that the answer given by the student to a determined choice of the course is equal or different from any of the options of the choice.</UL>
+
+<P><B>Forum</B></P>
+<UL>It is possible to be conditioned to that the number of discussions (threads) initiated by the student in a determined forum of the course is equal, different, greater, smaller, greater or equal or smaller or equal than a number from 0 to 100.</UL>
+<UL>It is possible to be conditioned to that the total number of messages (the beginnings of discussions or threads also consider messages) sent by the student to a determined forum of the course is equal, different, greater, smaller, greater or equal or smaller or equal than a number from 0 to 100.</UL>
+<UL>It is possible to be conditioned to the number of answers that the discussions initiated by a student obtain (all the messages will be counted as answer messages being children, grandsons, greats-grandchild... of the discussions initiated by the student). This one can be equal, different, greater, smaller, greater or equal or smaller or equal than a number from 0 to 100, considering that the messages of answer sent by the own student are also counted.</UL>
+<UL>It is possible to be conditioned to that the grade obtained by the student in a determined forum of the course is equal, different, greater, smaller, greater or equal or smaller or equal as any possible grade for this forum, being this a numerical value or one customized scale.</UL>
+
+<P><B>Glossary</B></P>
+<UL>It is possible to be conditioned to that the incoming number of entries added by the student to a determined glossary of the course is equal, different, greater, smaller, greater or equal or smaller or equal than a number from 0 to 100.</UL>
+<UL>It is possible to be conditioned to that the number of comments done by the student to terms of a determined glossary of the course is equal, different, greater, smaller, greater or equal or smaller or equal than a number from 0 to 100.</UL>
+
+<P><B>Lesson</B></P>
+<UL>It is possible to be conditioned to that the grade obtained by the student in a determined lesson of the course is equal, different, greater, smaller, greater or equal or smaller or equal than a percentage of the highest possible grade.</UL>
+<UL>It is possible to be conditioned to that the answer given by the student to a "multiple option" question of a determined lesson of the course is equal or different from any of the possible options.</UL>
+<UL>It is possible to be conditioned to that the answer given by the student to a "true/false" question of a determined lesson of the course is equal or different from any of the two possible options.</UL>
+<UL>It is possible to be conditioned to that the answer given by the student to a "short answer" question of a determined lesson of the course is equal or different from any of the possible answers.</UL>
+<UL>It is possible to be conditioned to that the answer given by the student to a "numerical" question of a determined lesson of the course is equal, different, greater, smaller, greater or equal or smaller or equal than a given number.</UL>
+<UL>It is possible to be conditioned to that the number of correct matches done by the student in a "matching" question of a determined lesson of the course is equal, different, greater, smaller, greater or equal or smaller or equal than a number between 0 and the number of total matches.</UL>
+<UL>It is possible to be conditioned to that the mark obtained by the student in a "essay" question of a determined lesson of the course is equal, different, greater, smaller, greater or equal or smaller or equal than a number between 0 and the highest possible mark.</UL>
+
+<P><B>Quiz</B></P>
+<UL>It is possible to be conditioned to that the grade obtained by the student in a determined quiz of the course is equal, different, greater, smaller, greater or equal or smaller or equal than a percentage of the highest possible grade.</UL>
+<UL>It is possible to be conditioned to that the answer given by the student to a "short answer" question of a determined quiz of the course is equal or different from any of the possible answers.</UL>
+<UL>It is possible to be conditioned to that the answer given by the student to a "true/false" question of a determined quiz of the course is equal or different from any of the two possible options.</UL>
+<UL>It is possible to be conditioned to that the answer given by the student to a "multiple option" question of a determined quiz of the course is equal or different from any of the possible options.</UL>
+<UL>It is possible to be conditioned to that the number of correct matches done by the student in a "matching" question of a determined quiz of the course is equal, different, greater, smaller, greater or equal or smaller or equal than a number between 0 and the number of total matches.</UL>
+<UL>It is possible to be conditioned to that the number of successes of the student in a type question "random short-answer matching" of a determined quiz of the course is equal, different, greater, smaller, greater or equal or smaller or equal than a number between 0 and the number of total short answers.</UL>
+<UL>It is possible to be conditioned to that the answer given by the student to a "numerical" question of a determined quiz of the course is equal, different, greater, smaller, greater or equal or smaller or equal than a given number.</UL>
+<UL>It is possible to be conditioned to that the answer given by the student to a "calculated" question of a determined quiz of the course is equal, different, greater, smaller, greater or equal or smaller or equal than the correct answer.</UL>
+
+<P><B>Wiki</B></P>
+<UL>It is possible to be conditioned to that the number of times that the student has edited a determined wiki of the course is equal, different, greater, smaller, greater or equal or smaller or equal than a number from 0 to 100.</UL>
+
+<P><B>Workshop</B></P>
+<UL>It is possible to be conditioned to that the grade obtained by the student in a determined workshop of the course is equal, different, greater, smaller, greater or equal or smaller or equal than a percentage of the highest possible grade.</UL>
+
+<P><B>Resource</B></P>
+<UL>It is possible to be conditioned to that the student has access to a resource of different type that label.</UL>
+
+<P><B>Student language</B></P>
+<UL>It is possible to be conditioned to that the student language is different or equal to any of the list of languages.</UL>
+
+<P><B>Student country</B></P>
+<UL>It is possible to be conditioned to that the student country is different or equal to any of the list of countries.</UL>
+
+<P><B>Enrolment date (first click)</B></P>
+<UL>It is possible to be conditioned to that the time passed since student's first click in the course is greater or smaller than a number of days.</UL>
+
+<P><B>Course start date</B></P>
+<UL>It is possible to be conditioned to that the time passed since course start date is greater or smaller than a number of days.</UL>
+
+<P><B>Date</B></P>
+<UL>It is possible to be conditioned to that the time passed since determined date in course is greater or smaller than a number of days.</UL>
diff -Naur moodle/lang/en_utf8/help/conditional/conditionalgrouping.html moodle-conditionals/lang/en_utf8/help/conditional/conditionalgrouping.html
--- moodle/lang/en_utf8/help/conditional/conditionalgrouping.html	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/lang/en_utf8/help/conditional/conditionalgrouping.html	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,12 @@
+<P ALIGN=CENTER><B>Conditions combination</B></P>
+
+<P>In this part it is in where the conditions are grouped in the wished way. It can be done in two different ways:</P>
+
+<ul>1.- Introducing the text directly to create a logical sequence of conditions respecting the syntax as shown in the examples at the end.</ul>
+<ul>2.- Clicking, sequencially, in the identifiers associated to each condition and that appear to the left of each of them in the list of "Created conditions", in the parentheses or the logical connectors "and" (logical "and"), "or" (logical "Or") and "not" (logical "Negation"). Note that, at any time, you will be able to modify the created Conditions combination using the keyboard.</ul>
+
+<P>Next, we will see some examples with the purpose of clarifying the used syntax:</P>
+
+<P><B>1 and 2 and 3</B></P>
+<P><B>(1 and 2) or 3</B></P>
+<P><B>((1 or 2) and 3) or not 1</B></P>
\ No hay ningún carácter de nueva línea al final del fichero
diff -Naur moodle/lang/en_utf8/help/conditional/conditionaltable.html moodle-conditionals/lang/en_utf8/help/conditional/conditionaltable.html
--- moodle/lang/en_utf8/help/conditional/conditionaltable.html	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/lang/en_utf8/help/conditional/conditionaltable.html	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,3 @@
+<P ALIGN=CENTER><B>Created conditions table</B></P>
+
+<P>In the following table are the conditions that have been created until this moment. These conditions will not work until they are not grouped combining them in the section "Combining the different conditions using logic operators" below in the same page. In the first column of the table there will be a mark indicating if each condition have been grouped (green tick) or haven't been grouped (red cross) yet. In the second column is the condition itself. In the third column there is a number that identifies each condition in order to group them (see "Combine the different conditions using logic operators" help for more information). When you click in any of the identifiers, this it is added at the end of the text box "Conditions combination". And the next two columns are used to edit and remove each of the conditions.</P>
diff -Naur moodle/lang/en_utf8/help/conditional/courseuselabel.html moodle-conditionals/lang/en_utf8/help/conditional/courseuselabel.html
--- moodle/lang/en_utf8/help/conditional/courseuselabel.html	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/lang/en_utf8/help/conditional/courseuselabel.html	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,3 @@
+<P ALIGN=CENTER><B>To stand out new activities</B></P>
+
+<P>If you choose the option <b>Yes - NEW label</b>, the word <b>NEW</b> will appear highlighted next to the name of those activities never acceded by the student. And if you choose the option <b>Yes - personalized label</b> the text introduced in the field <b>Personalized label</b> (next in this course settings page) will appear highlighted next to the name of those activities never acceded by the student.</P>
diff -Naur moodle/lang/en_utf8/help/conditional/personalizedlabel.html moodle-conditionals/lang/en_utf8/help/conditional/personalizedlabel.html
--- moodle/lang/en_utf8/help/conditional/personalizedlabel.html	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/lang/en_utf8/help/conditional/personalizedlabel.html	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,3 @@
+<P ALIGN=CENTER><B>Personalized label</B></P>
+
+<P>If you introduce a text in this field and you choose the option <b>Yes - personalized label</b> in the field <b>To stand out new activities</b> (back in this course settings page) the text introduced will appear highlighted next to the name of those activities never acceded by the student.</P>
diff -Naur moodle/lang/en_utf8/help/index.html moodle-conditionals/lang/en_utf8/help/index.html
--- moodle/lang/en_utf8/help/index.html	2007-08-17 03:04:11.000000000 +0100
+++ moodle-conditionals/lang/en_utf8/help/index.html	2009-09-16 13:38:34.000000000 +0100
@@ -82,3 +82,15 @@
   <li><a href="help.php?file=richtext.html">Using the Richtext HTML editor</a></li>
   <li><a href="help.php?file=emoticons.html">Using Smilies (emoticons)</a></li>
 </ul>
+
+<!-- START CONDITIONALS -->
+<h2>Courses with conditional activities</h2>
+<ul>
+  <li><a href="help.php?file=conditional/conditionalcreation.html">Creation of conditions</a></li>
+  <li><a href="help.php?file=conditional/conditionalgrouping.html">Combination of conditions</a></li>
+  <li><a href="help.php?file=conditional/conditionaltable.html">Table of created conditions</a></li>
+  <li><a href="help.php?file=conditional/courseuselabel.html">To stand out new activities</a></li>
+  <li><a href="help.php?file=conditional/personalizedlabel.html">Personalized label</a></li>
+  <li><a href="help.php?file=conditional/activityinfocreation.html">Activity info creation</a></li>
+</ul>
+<!-- END CONDITIONALS -->
diff -Naur moodle/lib/conditional.php moodle-conditionals/lib/conditional.php
--- moodle/lib/conditional.php	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/lib/conditional.php	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,666 @@
+<?php
+
+function evaluate_novelty($userid, $courseid, $cmid) {
+    return !record_exists('log', 'userid', $userid, 'course', $courseid, 'cmid', $cmid);
+}
+
+/*function conditional_user_sections_visibility($courseid, $userid=0) {
+}*/
+
+function conditional_user_section_visible($sectionid, $userid=0) {
+
+    global $USER;
+
+    if (empty($userid)) {
+        $userid = $USER->id;
+    }
+
+}
+
+function conditional_user_course_visibility($courseid, $userid=0) {
+
+    global $USER;
+
+    if (empty($userid)) {
+        $userid = $USER->id;
+    }
+
+    $activities = get_array_of_activities($courseid);
+    $conditionalvisibilities = array();
+    foreach ($activities as $activity) {
+        $conditionalvisibilities[$activity->cm] = conditional_user_module_visible($activity->cm, $userid);
+    }
+    return $conditionalvisibilities;
+
+}
+
+function conditional_user_module_visible($modid, $userid=0) {
+
+    global $USER, $CFG;
+
+    if (empty($userid)) {
+        $userid = $USER->id;
+    }
+
+    $coursemodule = get_record('course_modules', 'id', $modid);
+
+    $course = get_record('course', 'id', $coursemodule->course);
+    if (!$course->useconditionals) {
+        return $coursemodule->visible;
+    }
+
+    if (!$coursemodule->visible) {
+        return false;
+    }
+
+    $context = get_context_instance(CONTEXT_COURSE, $coursemodule->course);
+    if ( has_capability('moodle/course:viewhiddenactivities', $context) ) {
+        return true;
+    }
+
+    $conditional = get_record('conditional', 'moduleid', $modid);
+
+    if( $conditional ) {
+        if( $conditional->details && $conditional->inuse ) {
+            $members = get_records('conditional_member', 'conditionalid', $conditional->id, 'id desc');
+            if( count($members) == 0 ) {
+                return true;
+            }
+        } else {
+            return true;
+        }
+    } else {
+        return true;
+    }
+
+    $expression = str_replace('not', '!', $conditional->details);
+
+    foreach($members as $member) {
+
+        if(strstr($expression, $member->tableid)) {
+
+            switch($member->type) {
+
+                case 'assignment':
+                    if (!$instance = get_record($member->type, 'id', $member->instance)) {
+                        $expression = str_replace($member->tableid, 'false', $expression);
+                    } else {
+                        if ($member->subtype == 'submit') {
+                            $submission = count_records('assignment_submissions', 'assignment', $instance->id, 'userid', $userid);
+                            if( eval('return '.$submission.' '.$member->op.' '.$member->value.' ;') ) {
+                                $expression = str_replace($member->tableid, 'true', $expression);
+                            } else {
+                                $expression = str_replace($member->tableid, 'false', $expression);
+                            }
+
+                        } elseif ($member->subtype == 'grade') {
+                            if($instance->grade > 0) {
+                                require_once("$CFG->dirroot/mod/assignment/lib.php");
+                                $grades = assignment_get_user_grades($instance, $userid);
+                                if ($grades) {
+                                    $grade = array_pop($grades);
+                                    if (isset($grade->rawgrade)) {
+                                        if( eval('return '.round($grade->rawgrade).' '.$member->op.' '.$member->value.' ;') ) {
+                                            $expression = str_replace($member->tableid, 'true', $expression);
+                                        } else {
+                                            $expression = str_replace($member->tableid, 'false', $expression);
+                                        }
+                                    } else {
+                                        return false;
+                                    }
+                                } else {
+                                    return false;
+                                }
+                            } elseif($instance->grade < 0) {
+                                require_once("$CFG->dirroot/mod/assignment/lib.php");
+                                $grades = assignment_get_user_grades($instance, $userid);
+                                if ($grades) {
+                                    $grade = array_pop($grades);
+                                    if (isset($grade->rawgrade)) {
+                                        if( eval('return '.round($grade->rawgrade).' '.$member->op.' '.$member->value.' ;') ) {
+                                            $expression = str_replace($member->tableid, 'true', $expression);
+                                        } else {
+                                            $expression = str_replace($member->tableid, 'false', $expression);
+                                        }
+                                    } else {
+                                        return false;
+                                    }
+                                } else {
+                                    return false;
+                                }
+                            } else {
+                                return false;
+                            }
+                        }
+                    }
+                    break;
+                case 'book':
+                    $togetmoduleid = get_record('modules', 'name', 'book');
+                    if ($module = get_record('course_modules', 'module', $togetmoduleid->id, 'instance', $member->instance)) {
+                        $select = "userid = '$userid' AND module = 'book' AND action = 'view' AND cmid = '$module->id'";
+                        $accessnum = count_records_select('log', $select);
+                        if( eval('return '.$accessnum.' '.$member->op.' '.$member->value.' ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    } else {
+                        return false;
+                    }
+                    break;
+                case 'chat':
+                    $participationsnum = count_records('chat_messages', 'chatid', $member->instance, 'userid', $userid);
+                    if($member->subtype == 'say') {
+                        if( eval('return '.$participationsnum.' > 0 ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    } elseif($member->subtype == 'notsay') {
+                        if( eval('return '.$participationsnum.' == 0 ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    }
+                    break;
+                case 'choice':
+                    if ($answer = get_record('choice_answers', 'choiceid', $member->instance, 'userid', $userid)) {
+                        if ($member->subtype == 'anyanswer') {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } elseif ($member->subtype == 'particularanswer') {
+                            if( eval('return '.$answer->optionid.' '.$member->op.' '.$member->value.' ;') ) {
+                                $expression = str_replace($member->tableid, 'true', $expression);
+                            } else {
+                                $expression = str_replace($member->tableid, 'false', $expression);
+                            }
+                        }
+                    } else {
+                        $expression = str_replace($member->tableid, 'false', $expression);
+                    }
+                    break;
+                case 'conditionalbook':
+                    $togetmoduleid = get_record('modules', 'name', 'conditionalbook');
+                    if ($module = get_record('course_modules', 'module', $togetmoduleid->id, 'instance', $member->instance)) {
+                        $select = "userid = '$userid' AND module = 'conditionalbook' AND action = 'view' AND cmid = '$module->id'";
+                        $accessnum = count_records_select('log', $select);
+                        if( eval('return '.$accessnum.' '.$member->op.' '.$member->value.' ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    } else {
+                        return false;
+                    }
+                    break;
+                case 'dialogue':
+                    $conversationsnum = count_records('dialogue_conversations', 'dialogueid', $member->instance, 'userid', $userid);
+                    if( eval('return '.$conversationsnum.' '.$member->op.' '.$member->value.' ;') ) {
+                        $expression = str_replace($member->tableid, 'true', $expression);
+                    } else {
+                        $expression = str_replace($member->tableid, 'false', $expression);
+                    }
+                    break;
+                case 'forum':
+                    if ($member->subtype == 'discussions') {
+                        $participationsnum = count_records('forum_discussions', 'forum', $member->instance, 'userid', $userid);
+                        if( eval('return '.$participationsnum.' '.$member->op.' '.$member->value.' ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    } elseif ($member->subtype == 'messages') {
+                        $discussions = get_records('forum_discussions', 'forum', $member->instance, 'id asc');
+                        $participationsnum = 0;
+                        foreach ($discussions as $discussion) {
+                            $participationsnum += count_records('forum_posts', 'discussion', $discussion->id, 'userid', $userid);
+                        }
+                        if( eval('return '.$participationsnum.' '.$member->op.' '.$member->value.' ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    } elseif( $member->subtype == 'success') {
+                        $discussions = get_records_select('forum_discussions', "forum = $member->instance and userid = $userid", 'id  asc');
+                        $responsesnum = 0;
+                        foreach ($discussions as $discussion) {
+                            $responsesnum += (count_records('forum_posts', 'discussion', $discussion->id) - 1);
+                        }
+                        if( eval('return '.$responsesnum.' '.$member->op.' '.$member->value.' ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    } elseif( $member->subtype == 'answers') {
+                        $discussions = get_records('forum_discussions', 'forum', $member->instance, 'id asc');
+                        $participationsnum = 0;
+                        foreach ($discussions as $discussion) {
+                            if ( ($discussion->userid == $userid) || record_exists('forum_posts', 'discussion', $discussion->id, 'userid', $userid) ) {
+                                $participationsnum++;
+                            }
+                        }
+                        if( eval('return '.$participationsnum.' '.$member->op.' '.$member->value.' ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    } elseif( $member->subtype == 'grade' ) {
+                        if (!$instance = get_record($member->type, 'id', $member->instance)) {
+                            return false;
+                        }
+                        if($instance->scale > 0) {
+                            require_once("$CFG->dirroot/mod/forum/lib.php");
+                            $grades = forum_get_user_grades($instance, $userid);
+                            if ($grades) {
+                                $grade = array_pop($grades);
+                                if (isset($grade->rawgrade)) {
+                                    if( eval('return '.round($grade->rawgrade).' '.$member->op.' '.$member->value.' ;') ) {
+                                        $expression = str_replace($member->tableid, 'true', $expression);
+                                    } else {
+                                        $expression = str_replace($member->tableid, 'false', $expression);
+                                    }
+                                } else {
+                                    return false;
+                                }
+                            } else {
+                                return false;
+                            }
+                        } elseif($instance->scale < 0) {
+                            require_once("$CFG->dirroot/mod/forum/lib.php");
+                            $grades = forum_get_user_grades($instance, $userid);
+                            if ($grades) {
+                                $grade = array_pop($grades);
+                                if (isset($grade->rawgrade)) {
+                                    if( eval('return '.round($grade->rawgrade).' '.$member->op.' '.$member->value.' ;') ) {
+                                        $expression = str_replace($member->tableid, 'true', $expression);
+                                    } else {
+                                        $expression = str_replace($member->tableid, 'false', $expression);
+                                    }
+                                } else {
+                                    return false;
+                                }
+                            } else {
+                                return false;
+                            }
+                        } else {
+                            return false;
+                        }
+                    }
+                    break;
+                case 'glossary':
+                    if( $member->subtype == 'entries') {
+                        $entriesnum = count_records('glossary_entries', 'glossaryid', $member->instance, 'userid', $userid);
+                        if( eval('return '.$entriesnum.' '.$member->op.' '.$member->value.' ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    } elseif( $member->subtype == 'comments') {
+                        $entries = get_records('glossary_entries', 'glossaryid', $member->instance, 'id asc');
+                        $commentsnum = 0;
+                        foreach ($entries as $entry) {
+                            $commentsnum += count_records('glossary_comments', 'entryid', $entry->id, 'userid', $userid);
+                        }
+                        if( eval('return '.$commentsnum.' '.$member->op.' '.$member->value.' ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    }
+                    break;
+                case 'lesson':
+                    if( $member->subtype == 'grade') {
+                        $lesson = get_record('lesson', 'id', $member->instance);
+                        require_once("$CFG->dirroot/mod/lesson/lib.php");
+                        if ($grades = lesson_get_user_grades($lesson, $userid)) {
+                           $grade = array_pop($grades);
+                           if (isset($grade->rawgrade)) {
+                                if( eval('return '.$grade->rawgrade.' '.$member->op.' '.$member->value.' ;') ) {
+                                    $expression = str_replace($member->tableid, 'true', $expression);
+                                } else {
+                                    $expression = str_replace($member->tableid, 'false', $expression);
+                                }
+                            } else {
+                                $expression = str_replace($member->tableid, 'false', $expression);
+                            }
+
+                        } else {
+                            return false;
+                        }
+                    } else {
+                        $page = get_record('lesson_pages', 'id', $member->subtype);
+                        $attempt = get_record('lesson_attempts', 'lessonid', $member->instance, 'pageid', $member->subtype, 'userid', $userid);
+                        switch($page->qtype) {
+                            case 1: /// short answer
+                            case 2: /// true/false
+                            case 3: /// multichoice
+                                if (!isset($attempt->answerid)) {
+                                    $expression = str_replace($member->tableid, 'false', $expression);
+                                } else {
+                                    if( eval('return '.$attempt->answerid.' '.$member->op.' '.$member->value.' ;') ) {
+                                        $expression = str_replace($member->tableid, 'true', $expression);
+                                    } else {
+                                        $expression = str_replace($member->tableid, 'false', $expression);
+                                    }
+                                }
+                                break;
+                            case 8: /// numerical
+                                if (!isset($attempt->useranswer)) {
+                                    $expression = str_replace($member->tableid, 'false', $expression);
+                                } else {
+                                    if( eval('return '.$attempt->useranswer.' '.$member->op.' '.$member->value.' ;') ) {
+                                        $expression = str_replace($member->tableid, 'true', $expression);
+                                    } else {
+                                        $expression = str_replace($member->tableid, 'false', $expression);
+                                    }
+                                }
+                                break;
+                            case 5: /// match
+                                $useranswers = explode(',', $attempt->useranswer);
+                                $answers = get_records_select('lesson_answers', "pageid = $member->subtype and response <> ''", 'id asc');
+                                $j = 0;
+                                $acertsnum = 0;
+                                foreach ($answers as $answer) {
+                                    if ($answer->id == $useranswers[$j]) {
+                                        $acertsnum++;
+                                    }
+                                    $j++;
+                                }
+                                if( eval('return '.$acertsnum.' '.$member->op.' '.$member->value.' ;') ) {
+                                    $expression = str_replace($member->tableid, 'true', $expression);
+                                } else {
+                                    $expression = str_replace($member->tableid, 'false', $expression);
+                                }
+                                break;
+                            case 10: /// essay
+                                if (!isset($attempt->useranswer)) {
+                                    $expression = str_replace($member->tableid, 'false', $expression);
+                                } else {
+                                    $essayinfo = unserialize($attempt->useranswer);
+                                    if( eval('return '.$essayinfo->score.' '.$member->op.' '.$member->value.' ;') ) {
+                                        $expression = str_replace($member->tableid, 'true', $expression);
+                                    } else {
+                                        $expression = str_replace($member->tableid, 'false', $expression);
+                                    }
+                                }
+                                break;
+                            default:
+                                $expression = str_replace($member->tableid, 'false', $expression);
+                                break;
+                        }
+                    }
+                    break;
+                case 'quiz':
+                    if( $member->subtype == 'grade') {
+                        $quiz = get_record('quiz', 'id', $member->instance);
+                        require_once("$CFG->dirroot/mod/quiz/lib.php");
+                        if ($grades = quiz_get_user_grades($quiz, $userid)) {
+                            $grade = array_pop($grades);
+                            if (!isset($grade->rawgrade)) {
+                                $expression = str_replace($member->tableid, 'false', $expression);
+                            } else {
+                                if( eval('return '.$grade->rawgrade.' '.$member->op.' '.($quiz->grade/100*$member->value).' ;') ) {
+                                    $expression = str_replace($member->tableid, 'true', $expression);
+                                } else {
+                                    $expression = str_replace($member->tableid, 'false', $expression);
+                                }
+                            }
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    } else {
+                        $questioninstance = get_record('quiz_question_instances', 'id', $member->subtype);
+                        $question = get_record('question', 'id', $questioninstance->question);
+                        $attempts = get_records_select('quiz_attempts', "quiz = $member->instance AND userid = $userid", 'attempt desc', '*', '0', '1');
+                        if ($attempts) {
+                            $attempt = current($attempts);
+                            $neweststate = get_record('question_sessions', 'attemptid', $attempt->id, 'questionid', $question->id);
+                            $state = get_record('question_states', 'id', $neweststate->newest);
+                            if ($state->answer == '') {
+                                $expression = str_replace($member->tableid, 'false', $expression);
+                            } else {
+                                switch($question->qtype) {
+                                    case 'shortanswer':
+                                        $quizanswer = get_record('question_answers', 'id', $member->value);
+                                        $shortanswer = get_record('question_shortanswer', 'question', $question->id);
+                                        if($shortanswer->usecase) {
+                                            if( eval('return '.$state->answer.' '.$member->op.' '.$quizanswer->answer.' ;') ) {
+                                                $expression = str_replace($member->tableid, 'true', $expression);
+                                            } else {
+                                                $expression = str_replace($member->tableid, 'false', $expression);
+                                            }
+                                        } else {
+                                            if( eval('return '.strtolower($state->answer).' '.$member->op.' '.strtolower($quizanswer->answer).' ;') ) {
+                                                $expression = str_replace($member->tableid, 'true', $expression);
+                                            } else {
+                                                $expression = str_replace($member->tableid, 'false', $expression);
+                                            }
+                                        }
+                                    case 'truefalse':
+                                        if( eval('return '.$state->answer.' '.$member->op.' '.$member->value.' ;') ) {
+                                            $expression = str_replace($member->tableid, 'true', $expression);
+                                        } else {
+                                            $expression = str_replace($member->tableid, 'false', $expression);
+                                        }
+                                        break;
+                                    case 'multichoice':
+                                        $answer = explode(':', $state->answer);
+                                        if($answer[1] == '') {
+                                            $expression = str_replace($member->tableid, 'false', $expression);
+                                        } else {
+                                            $givenanswers = explode(',', $answer[1]);
+                                            $multichoice = false;
+                                            foreach ($givenanswers as $givenanswer) {
+                                                if( (!$multichoice) && eval('return '.$givenanswer.' '.$member->op.' '.$member->value.' ;') ) {
+                                                    $expression = str_replace($member->tableid, 'true', $expression);
+                                                    $multichoice = true;
+                                                }
+                                            }
+                                            if (!$multichoice) {
+                                                $expression = str_replace($member->tableid, 'false', $expression);
+                                            }
+                                        }
+                                        break;
+                                    case 'numerical':
+                                        if( eval('return '.$state->answer.' '.$member->op.' '.$member->value.' ;') ) {
+                                            $expression = str_replace($member->tableid, 'true', $expression);
+                                        } else {
+                                            $expression = str_replace($member->tableid, 'false', $expression);
+                                        }
+                                        break;
+                                    case 'match':
+                                        $answers = explode(',', $state->answer);
+                                        $acertsnum = 0;
+                                        foreach ($answers as $eachanswer) {
+                                            $answer = explode('-', $eachanswer);
+                                            $questionmatchsub = get_record('question_match_sub', 'question', $question->id, 'code', $answer[1]);
+                                            if($answer[0] == $questionmatchsub->id) {
+                                                $acertsnum++;
+                                            }
+                                        }
+                                        if( eval('return '.$acertsnum.' '.$member->op.' '.$member->value.' ;') ) {
+                                            $expression = str_replace($member->tableid, 'true', $expression);
+                                        } else {
+                                            $expression = str_replace($member->tableid, 'false', $expression);
+                                        }
+                                        break;
+                                    case 'calculated':
+                                        $useranswers = explode('-', $state->answer);
+                                        if($useranswers[1] == '') {
+                                            $expression = str_replace($member->tableid, 'false', $expression);
+                                        } else {
+                                            $datasetnum = str_replace('dataset', '', $useranswers[0]);
+                                            $datasetitems = get_records('question_dataset_items', 'itemnumber', $datasetnum, 'id asc');
+                                            $answer = get_record('question_answers', 'question', $question->id);
+                                            foreach ($datasetitems as $datasetitem) {
+                                                $datasetdefinition = get_record('question_dataset_definitions', 'id', $datasetitem->definition);
+                                                $answer->answer = str_replace('{'.$datasetdefinition->name.'}', $datasetitem->value, $answer->answer);
+                                            }
+                                            $result = eval('return '.$answer->answer.' ;');
+                                            if( eval('return '.$useranswers[1].' '.$member->op.' '.$result.' ;') ) {
+                                                $expression = str_replace($member->tableid, 'true', $expression);
+                                            } else {
+                                                $expression = str_replace($member->tableid, 'false', $expression);
+                                            }
+                                        }
+                                        break;
+                                    /*case 9: /// cloze
+                                        break;*/
+                                    case 'randomsamatch':
+                                        $answers = explode(',', $state->answer);
+                                        $acertsnum = 0;
+                                        foreach ($answers as $eachanswer) {
+                                            $answer = explode('-', $eachanswer);
+                                            if(count_records('question_answers', 'id', $answer[1], 'question', $answer[0], 'fraction', 1)) {
+                                                $acertsnum++;
+                                            }
+                                        }
+                                        if( eval('return '.$acertsnum.' '.$member->op.' '.$member->value.' ;') ) {
+                                            $expression = str_replace($member->tableid, 'true', $expression);
+                                        } else {
+                                            $expression = str_replace($member->tableid, 'false', $expression);
+                                        }
+                                        break;
+                                    default:
+                                        $expression = str_replace($member->tableid, 'false', $expression);
+                                        break;
+                                }
+                            }
+
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    }
+                    break;
+                case 'resource':
+                    $togetmoduleid = get_record('modules', 'name', 'resource');
+                    $module = get_record('course_modules', 'module', $togetmoduleid->id, 'instance', $member->instance);
+                    $select = "userid = '$userid' AND module = 'resource' AND action = 'view' AND cmid = '$module->id'";
+                    $accessnum = count_records_select('log', $select);
+                    if( eval('return '.$accessnum.' '.$member->op.' '.$member->value.' ;') ) {
+                        $expression = str_replace($member->tableid, 'true', $expression);
+                    } else {
+                        $expression = str_replace($member->tableid, 'false', $expression);
+                    }
+                    break;
+                case 'wiki':
+                    $entries = get_records('wiki_entries', 'wikiid', $member->instance, 'id asc');
+                    $participationsnum = 0;
+                    foreach ($entries as $entry) {
+                        $participationsnum += count_records('wiki_pages', 'wiki', $entry->id, 'userid', $userid);
+                    }
+                    if( eval('return '.$participationsnum.' '.$member->op.' '.$member->value.' ;') ) {
+                        $expression = str_replace($member->tableid, 'true', $expression);
+                    } else {
+                        $expression = str_replace($member->tableid, 'false', $expression);
+                    }
+                    break;
+                case 'workshop':
+                    require_once("$CFG->dirroot/mod/workshop/lib.php");
+                    $grades = workshop_grades($member->instance);
+                    if (!isset($grades->grades[$userid])) {
+                        $expression = str_replace($member->tableid, 'false', $expression);
+                    } else {
+                        if( eval('return '.$grades->grades[$userid].' '.$member->op.' '.$member->value.' ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    }
+                    break;
+                case 'role':
+                    $userinformation = get_user_roles($context, $userid);
+                    if (!$userinformation) {
+                        $expression = str_replace($member->tableid, 'false', $expression);
+                    } else {
+                        $shortname = $userinformation[key($userinformation)]->shortname;
+                        $switchrole  = optional_param('switchrole',-1, PARAM_INT);
+                        if ($switchrole <> -1) {
+                            $roles = get_all_roles();
+                            $shortname = $roles[$switchrole]->shortname;
+                        }
+                        if( eval('return "'.$shortname.'" '.$member->op.' "'.$member->value.'" ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    }
+                    break;
+                case 'lang':
+                    $userinformation = get_record('user', 'id', $userid);
+                    if (!$userinformation->lang) {
+                        $expression = str_replace($member->tableid, 'false', $expression);
+                    } else {
+                        if( eval('return "'.$userinformation->lang.'" '.$member->op.' "'.$member->value.'" ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    }
+                    break;
+                case 'country':
+                    $userinformation = get_record('user', 'id', $userid);
+                    if (!$userinformation->country) {
+                        $expression = str_replace($member->tableid, 'false', $expression);
+                    } else {
+                        if( eval('return "'.$userinformation->country.'" '.$member->op.' "'.$member->value.'" ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    }
+                    break;
+                case 'picture':
+                    $userinformation = get_record('user', 'id', $userid);
+                    if (isset($userinformation->picture)) {
+                        if( eval('return "'.$userinformation->picture.'" '.$member->op.' "'.$member->value.'" ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    } else {
+                        $expression = str_replace($member->tableid, 'false', $expression);
+                    }
+                    break;
+                case 'enrolment':
+                    if ($userlogs = get_records_select('log', 'userid="'.$userid.'" and course="'.$course->id.'"', 'time ASC', 'id,time', 0, 1)) {
+                        $firstlog = current($userlogs);
+                        $enrolmentdate = (time() - $firstlog->time);
+                        if( ($enrolmentdate >= 0) && eval('return "'.$enrolmentdate.'" '.$member->op.' "'.($member->value*86400).'" ;') ) {
+                            $expression = str_replace($member->tableid, 'true', $expression);
+                        } else {
+                            $expression = str_replace($member->tableid, 'false', $expression);
+                        }
+                    } else {
+                        $expression = str_replace($member->tableid, 'false', $expression);
+                    }
+                    break;
+                case 'startdate':
+                    $timedifference = (time() - $course->startdate);
+                    if( ($timedifference >= 0) && eval('return "'.$timedifference.'" '.$member->op.' "'.($member->value*86400).'" ;') ) {
+                        $expression = str_replace($member->tableid, 'true', $expression);
+                    } else {
+                        $expression = str_replace($member->tableid, 'false', $expression);
+                    }
+                    break;
+                case 'date':
+                    $date = time() - $member->instance;
+                    if( ($date >= 0) && eval('return "'.$date.'" '.$member->op.' "'.($member->value*86400).'" ;') ) {
+                        $expression = str_replace($member->tableid, 'true', $expression);
+                    } else {
+                        $expression = str_replace($member->tableid, 'false', $expression);
+                    }
+                    break;
+                default:
+                    $expression = str_replace($member->tableid, 'false', $expression);
+                    break;
+            }
+        }
+    }
+
+    $conditionalresult = eval('return '.$expression.';');
+    return $conditionalresult;
+
+}
+
+?>
diff -Naur moodle/lib/datalib.php moodle-conditionals/lib/datalib.php
--- moodle/lib/datalib.php	2009-01-14 23:06:56.000000000 +0000
+++ moodle-conditionals/lib/datalib.php	2009-09-16 13:38:34.000000000 +0100
@@ -1822,7 +1822,10 @@
  * @return bool
  */
 function coursemodule_visible_for_user($cm, $userid=0) {
-    global $USER;
+    /// START CONDITIONALS
+    //global $USER;
+    global $USER, $CFG;
+    /// END CONDITIONALS
 
     if (empty($cm->id)) {
         debugging("Incorrect course module parameter!", DEBUG_DEVELOPER);
@@ -1831,7 +1834,14 @@
     if (empty($userid)) {
         $userid = $USER->id;
     }
-    if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) {
+
+    /// START CONDITIONALS
+    //if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) {
+    require_once("$CFG->libdir/conditional.php");
+    $conditionalvisible = conditional_user_module_visible($cm->id, $userid);
+    if ((!$cm->visible || !$conditionalvisible) and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id), $userid)) {
+    /// END CONDITIONALS
+
         return false;
     }
     return groups_course_module_visible($cm, $userid);
diff -Naur moodle/lib/grade/grade_item.php moodle-conditionals/lib/grade/grade_item.php
--- moodle/lib/grade/grade_item.php	2009-04-23 01:07:33.000000000 +0100
+++ moodle-conditionals/lib/grade/grade_item.php	2009-09-16 13:38:34.000000000 +0100
@@ -563,7 +563,22 @@
      * @return boolean hidden state
      */
     function is_hidden() {
-        return ($this->hidden == 1 or ($this->hidden != 0 and $this->hidden > time()));
+
+        /// START CONDITIONALS
+        //return ($this->hidden == 1 or ($this->hidden != 0 and $this->hidden > time()));
+        global $CFG, $USER;
+
+        if ($this->itemtype == 'mod') {
+            $mod = get_record('modules', 'name', $this->itemmodule);
+            $cm = get_record('course_modules', 'course', $this->courseid, 'module',  $mod->id, 'instance', $this->iteminstance);
+            require_once("$CFG->libdir/conditional.php");
+            $conditionalvisibility = conditional_user_module_visible($cm->id, $USER->id);
+            return (!$conditionalvisibility or $this->hidden == 1 or ($this->hidden != 0 and $this->hidden > time()));
+        } else {
+            return ($this->hidden == 1 or ($this->hidden != 0 and $this->hidden > time()));
+        }
+        /// END CONDITIONALS
+
     }
 
     /**
diff -Naur moodle/lib/moodlelib.php moodle-conditionals/lib/moodlelib.php
--- moodle/lib/moodlelib.php	2009-05-15 10:14:16.000000000 +0100
+++ moodle-conditionals/lib/moodlelib.php	2009-09-16 13:38:34.000000000 +0100
@@ -1991,10 +1991,24 @@
             print_error('nocontext');
         }
     }
+
+    /// START CONDITIONALS
+    $conditionalvisible = true;
+    if(!empty($cm) && isset($cm->id)) {
+        require_once($CFG->libdir."/conditional.php");
+        $conditionalvisible = conditional_user_module_visible($cm->id, $USER->id);
+    }
+    /// END CONDITIONALS
+
     if ($COURSE->id == SITEID) {
         /// Eliminate hidden site activities straight away
-        if (!empty($cm) && !$cm->visible
-            && !has_capability('moodle/course:viewhiddenactivities', $cm->context)) {
+
+        /// START CONDITIONALS
+        //if (!empty($cm) && !$cm->visible
+        //    && !has_capability('moodle/course:viewhiddenactivities', $cm->context)) {
+        if (!empty($cm) && (!$cm->visible || !$conditionalvisible) && !has_capability('moodle/course:viewhiddenactivities', $cm->context)) {
+        /// END CONDITIONALS
+
             redirect($CFG->wwwroot, get_string('activityiscurrentlyhidden'));
         }
         user_accesstime_log($COURSE->id); /// Access granted, update lastaccess times
@@ -2040,7 +2054,12 @@
                         print_header_simple();
                         notice(get_string('guestsnotallowed', '', format_string($COURSE->fullname)), "$CFG->wwwroot/login/index.php");
                     }
-                    if (!empty($cm) and !$cm->visible) { // Not allowed to see module, send to course page
+
+                    /// START CONDITIONALS
+                    //if (!empty($cm) and !$cm->visible) { // Not allowed to see module, send to course page
+                    if (!empty($cm) and (!$cm->visible || !$conditionalvisible)) { // Not allowed to see module, send to course page
+                    /// END CONDITIONALS
+
                         redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course,
                                  get_string('activityiscurrentlyhidden'));
                     }
@@ -2085,7 +2104,11 @@
 
         /// Make sure they can read this activity too, if specified
 
-            if (!empty($cm) && !$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $cm->context)) {
+            /// START CONDITIONALS
+            //if (!empty($cm) && !$cm->visible && !has_capability('moodle/course:viewhiddenactivities', $cm->context)) {
+            if (!empty($cm) and (!$cm->visible || !$conditionalvisible) and !has_capability('moodle/course:viewhiddenactivities', $cm->context)) {
+            /// END CONDITIONALS
+
                 redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course, get_string('activityiscurrentlyhidden'));
             }
             user_accesstime_log($COURSE->id); /// Access granted, update lastaccess times
diff -Naur moodle/local/db/access.php moodle-conditionals/local/db/access.php
--- moodle/local/db/access.php	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/local/db/access.php	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,36 @@
+<?php
+
+$local_capabilities = array(
+
+    'moodle/local:useconditionals' => array(
+        'riskbitmask' => RISK_CONFIG,
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_COURSE,
+        'legacy' => array(
+            'editingteacher' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    ),
+
+    'moodle/local:createconditionals' => array(
+        'riskbitmask' => RISK_CONFIG,
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_COURSE,
+        'legacy' => array(
+            'editingteacher' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    ),
+
+    'moodle/local:assigncomments' => array(
+        'riskbitmask' => RISK_XSS,
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_COURSE,
+        'legacy' => array(
+            'editingteacher' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    ),
+);
+
+?>
diff -Naur moodle/local/db/install.xml moodle-conditionals/local/db/install.xml
--- moodle/local/db/install.xml	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/local/db/install.xml	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<XMLDB PATH="local/db" VERSION="20090901" COMMENT="XMLDB file for Moodle local"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
+>
+  <TABLES>
+    <TABLE NAME="conditional" COMMENT="Store activities's conditionals" NEXT="conditional_member">
+      <FIELDS>
+        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="moduleid"/>
+        <FIELD NAME="moduleid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="issection"/>
+        <FIELD NAME="issection" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="moduleid" NEXT="details"/>
+        <FIELD NAME="details" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="issection" NEXT="inuse"/>
+        <FIELD NAME="inuse" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="details"/>
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+      </KEYS>
+    </TABLE>
+    <TABLE NAME="conditional_member" COMMENT="Store conditionals's conditions" PREVIOUS="conditional">
+      <FIELDS>
+        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="true" ENUM="false" NEXT="conditionalid"/>
+        <FIELD NAME="conditionalid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="type"/>
+        <FIELD NAME="type" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="conditionalid" NEXT="subtype"/>
+        <FIELD NAME="subtype" TYPE="char" LENGTH="16" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="type" NEXT="instance"/>
+        <FIELD NAME="instance" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="subtype" NEXT="op"/>
+        <FIELD NAME="op" TYPE="char" LENGTH="2" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="instance" NEXT="value"/>
+        <FIELD NAME="value" TYPE="char" LENGTH="100" NOTNULL="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="op" NEXT="tableid"/>
+        <FIELD NAME="tableid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="value"/>
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+      </KEYS>
+    </TABLE>
+  </TABLES>
+</XMLDB>
\ No hay ningún carácter de nueva línea al final del fichero
diff -Naur moodle/local/db/upgrade.php moodle-conditionals/local/db/upgrade.php
--- moodle/local/db/upgrade.php	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/local/db/upgrade.php	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,60 @@
+<?php
+
+function xmldb_local_upgrade($oldversion=0) {
+    //global $CFG, $db;
+ 
+    $result = true;
+
+    if ($result && $oldversion < 2009032400) {
+        $result = $result && install_from_xmldb_file(dirname(__FILE__).'/install.xml');
+
+        /// Define field info to be added to course_modules
+        $table = new XMLDBTable('course_modules');
+        $field = new XMLDBField('info');
+        $field->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, 'groupmembersonly');
+        $result = $result && add_field($table, $field);
+        unset($field);
+        unset($table);
+    
+        /// Define field useconditionals to be added to course
+        $table = new XMLDBTable('course');
+        $field = new XMLDBField('useconditionals');
+        $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'defaultrole');
+        $result = $result && add_field($table, $field);
+        unset($field);
+        unset($table);
+
+        /// Define field uselabel to be added to course
+        $table = new XMLDBTable('course');
+        $field = new XMLDBField('uselabel');
+        $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'useconditionals');
+        $result = $result && add_field($table, $field);
+        unset($field);
+        unset($table);
+
+        /// Define field personalizedlabel to be added to course
+        $table = new XMLDBTable('course');
+        $field = new XMLDBField('personalizedlabel');
+        $field->setAttributes(XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null, null, null, 'uselabel');
+        $result = $result && add_field($table, $field);
+        unset($field);
+        unset($table);
+
+    }
+
+    if ($result && $oldversion < 2009090100) {
+
+        /// Define field issection to be added to conditional
+        $table = new XMLDBTable('conditional');
+        $field = new XMLDBField('issection');
+        $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'moduleid');
+
+        /// Launch add field issection
+        $result = $result && add_field($table, $field);
+
+    }
+
+    return $result;
+}
+
+?>
diff -Naur moodle/local/lang/en_utf8/local.php moodle-conditionals/local/lang/en_utf8/local.php
--- moodle/local/lang/en_utf8/local.php	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/local/lang/en_utf8/local.php	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,7 @@
+<?php
+
+$string['local:useconditionals'] = 'Enable/disable conditionals';
+$string['local:createconditionals'] = 'Create conditionals';
+$string['local:assigncomments'] = 'Assign activity info';
+
+?>
diff -Naur moodle/local/lang/es_utf8/local.php moodle-conditionals/local/lang/es_utf8/local.php
--- moodle/local/lang/es_utf8/local.php	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/local/lang/es_utf8/local.php	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,7 @@
+<?php
+
+$string['local:useconditionals'] = 'Activar/desactivar condicionales';
+$string['local:createconditionals'] = 'Crear condicionales';
+$string['local:assigncomments'] = 'Asignar información de actividad';
+
+?>
diff -Naur moodle/local/version.php moodle-conditionals/local/version.php
--- moodle/local/version.php	1970-01-01 00:00:00.000000000 +0000
+++ moodle-conditionals/local/version.php	2009-09-16 13:38:34.000000000 +0100
@@ -0,0 +1,5 @@
+<?php
+
+$local_version = 2009090100;
+
+?>
\ No hay ningún carácter de nueva línea al final del fichero
