function print_filter(&$mform) {
        global $DB, $CFG,$USER;

        $filter_zone = optional_param('filter_zone', '', PARAM_RAW);

        $reportclassname = 'report_' . $this->report->type;
        $reportclass = new $reportclassname($this->report);
  
        

        if ($this->report->type != 'sql') {
            $components = cr_unserialize($this->report->components);
            $conditions = $components['conditions'];

            $zonelist = $reportclass->elements_by_conditions($conditions);
        } else {
            $zonelist = array_keys($DB->get_records_sql("select zone_code, zone from {local_userdata} group by zone_code"));
        }

        $zonelistoptions = array();
        $zonelistoptions[0] = get_string('filter_all', 'block_cobalt_reports');

          if (!empty($zonelist)) {
        //  list($usql, $params) = $remoteDB->get_in_or_equal($zonelist);
          // $sql="SELECT * from {local_costcenter} lc JOIN {local_userdata} lu ON lu.costcenterid=lc.id where lu.userid={$USER->id}";
           
         if(is_siteadmin() || is_ast_nh()){
             //$costcenters = $remoteDB->get_records_select('local_costcenter', "id $usql", $params);
			 $zones = $DB->get_records_sql("select id,zone_code, zone from {local_userdata} group by zone_code");
         }
         else {
			
			//if(is_hod() || is_zht())
			if(isset($USER->id) && $USER->id)
			 $zones=$DB->get_records_sql("select id, zone_code, zone from {local_userdata} where userid={$USER->id} ");
           //  $costcenters = $remoteDB->get_records_sql($sql, $params);
         }


            foreach ($zones as $record) {
                $zonelistoptions[$record->zone_code] = format_string($record->zone);
            }
   }

        $mform->addElement('select', 'filter_zone', get_string('filterzone', 'block_cobalt_reports'), $zonelistoptions);
        $mform->setType('filter_zone', PARAM_RAW);
    }
Example #2
0
    </style>
    <?php echo $OUTPUT->standard_head_html() ?>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	   <link href="<?php echo $CFG->wwwroot ?>/theme/clean/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="<?php echo $CFG->wwwroot ?>/theme/clean/css/simple-sidebar.css" rel="stylesheet">
</head>

<body <?php echo $OUTPUT->body_attributes(); ?>>
<?php echo $OUTPUT->standard_top_of_body_html(); 
global $DB,$USER, $CFG;
require_once $CFG->dirroot.'/local/lib.php';
	//$superviourrole= new assign_smanager(); 
	$newsuper = is_supervisor_dashboard();
	$is_ast_nh = is_ast_nh($USER->id);
	$is_zht = is_zht($USER->id);
	$is_hod = is_hod($USER->id);
	$is_instructor = is_instructor($USER->id);
	$is_trainers = is_trainers($USER->id);
	$is_bt = is_bt($USER->id);
	$is_ct = is_ct($USER->id);
	$is_zh = is_zh($USER->id);
	$is_rh = is_rh($USER->id);
?>
    <div id="wrapper" class="">

        <!-- Sidebar -->
        <div id="sidebar-wrapper">
           <?php
		
Example #3
0
/**
 *get a record to the facetoface ace2face table script
 * @param integer $userid 
*/
function view_session_face2face_sql($userid,$sessiontype,$requestData,$filter_starttime=0,$filter_endtime=0,$batchid=0){//*This function for face2face sql*//		
    global $DB, $OUTPUT,$USER,$CFG;
  

    if(!is_siteadmin()){
       
			$usercategory=$DB->get_field('local_userdata','lms_category',array('userid'=>$USER->id));
			if($usercategory=="")
				$usercategory="";
			else 
				$usercategory=$usercategory;
			
            
    }
   
    $sql ="SELECT a.*
        FROM {facetoface} as a
        JOIN {user} as u ON  u.id=a.trainerid where 1=1 ";
  
    /* 
	 * Filtering
	 * NOTE this does not match the built-in DataTables filtering which does it
	 * word by word on any field. It's possible to do here, but concerned about efficiency
	 * on very large tables, and MySQL's regex functionality is very limited
	 */

	if ( $requestData['sSearch'] != "" )
	{
			
		$sql .= " and ((a.name LIKE '%".$requestData['sSearch']."%') or (concat(u.firstname,u.lastname) LIKE '%".$requestData['sSearch']."%') ) ";
   
    }
    if($filter_starttime!=0){
        $sql .= " AND a.startdate >='$filter_starttime' ";

    }
     if($filter_endtime!=0){
         $sql .= " AND a.enddate <='$filter_endtime' ";
    }
     if($batchid!=0){
                $sql.= " AND a.id =$batchid";
     }
   
if(!is_siteadmin() && is_ast_nh()){
	if($sessiontype>=0){
	    $sql .="  and a.course=1 and a.category='$usercategory'  and a.active={$sessiontype} order by a.id DESC";
	}else{
		$sql .=" and a.course=1 and a.category='$usercategory' order by a.id DESC";

	}	

	
}else if(is_instructor() || is_trainers()){
	if($sessiontype>=0){
	   $sql .="  and a.trainerid={$USER->id} and a.course=1  and a.active={$sessiontype} order by a.id DESC";
	}else{
	   $sql .="  and a.trainerid={$USER->id} and a.course=1 order by a.id DESC";

	}	

	
}
elseif(!is_siteadmin()){
    
	if($sessiontype>=0){
		$sql .="  and a.course=1  and a.active={$sessiontype} order by a.id DESC"; 
	}else{
	    $sql .="  and a.course=1 order by a.id DESC"; 
	}
}
else if(is_siteadmin()){
	if($sessiontype>=0){
		$sql .="  and a.category='' and a.active={$sessiontype} order by a.id DESC"; 
	}else{
	    $sql .="  and a.category='' order by a.id DESC"; 
	}
}
//// /* 
////	 * Paging
////	 */
	if ( isset( $requestData['iDisplayStart'] ) && $requestData['iDisplayLength'] != '-1' )
	{
		 $sql .="  LIMIT ".$requestData['iDisplayStart'] .", ".$requestData['iDisplayLength'];
	}
    //echo $sql;
    //exit;
	$f2f_records = $DB->get_records_sql($sql);

   	if ( $requestData['sSearch'] != "" )
	{ 
            $sql1 ="SELECT a.*
            FROM {facetoface} as a
            JOIN {local_batch_courses} as lbc ON lbc.batchid=a.id
            JOIN {course} AS c ON c.id=lbc.courseid
            WHERE c.fullname LIKE '%".$requestData['sSearch']."%' ";
  
            /* 
             * Filtering
             * NOTE this does not match the built-in DataTables filtering which does it
             * word by word on any field. It's possible to do here, but concerned about efficiency
             * on very large tables, and MySQL's regex functionality is very limited
             */
        
            if($filter_starttime!=0){
                $sql1 .= " AND a.startdate >='$filter_starttime' ";
        
            }
             if($filter_endtime!=0){
                 $sql1 .= " AND a.enddate <='$filter_endtime' ";
            }
            if($batchid!=0){
                $sql1 .= " AND a.id =$batchid";
            }
           
        if(!is_siteadmin() && is_ast_nh()){
            if($sessiontype>=0){
                $sql1 .="  and a.course=1 and a.category='$usercategory'  and a.active={$sessiontype} order by a.id DESC";
            }else{
                $sql1 .=" and a.course=1 and a.category='$usercategory' order by a.id DESC";
        
            }	
        
            
        }else if(is_instructor() || is_trainers()){
            if($sessiontype>=0){
               $sql1 .="  and a.trainerid={$USER->id} and a.course=1  and a.active={$sessiontype} order by a.id DESC";
            }else{
               $sql1 .="  and a.trainerid={$USER->id} and a.course=1 order by a.id DESC";
        
            }	
        
            
        }
        elseif(!is_siteadmin()){
            
            if($sessiontype>=0){
                $sql1 .="  and a.course=1  and a.active={$sessiontype} order by a.id DESC"; 
            }else{
                $sql1 .="  and a.course=1 order by a.id DESC"; 
            }
        }
        else if(is_siteadmin()){
            if($sessiontype>=0){
                $sql1 .="  and a.category='' and a.active={$sessiontype} order by a.id DESC"; 
            }else{
                $sql1 .="  and a.category='' order by a.id DESC"; 
            }
        }
        //// /* 
        ////	 * Paging
        ////	 */
            if ( isset( $requestData['iDisplayStart'] ) && $requestData['iDisplayLength'] != '-1' )
            {
                 $sql1 .="  LIMIT ".$requestData['iDisplayStart'] .", ".$requestData['iDisplayLength'];
            }
            
            $f2fg_records = $DB->get_records_sql($sql1);
            foreach($f2fg_records as $f2fg_record){
                $f2f_records[$f2fg_record->id]=$f2fg_record;
            }
    }      
    
   
    return $f2f_records;
}
Example #4
0
//if (has_capability('mod/feedback:viewreports', $context)) {
    //if ($feedback->course == SITEID) {
//        $url_params = array('id'=>$usedid, 'courseid'=>$courseid, 'do_show'=>'analysis');
    //       $analysisurl = new moodle_url('/local/evaluations/analysis_course.php', $url_params);
    //      $row[] = new tabobject('analysis',
    //                             $analysisurl->out(),
    //                            get_string('analysis', 'local_evaluations'));
    //  } else {
    if (has_capability('local/evaluations:addinstance', context_system::instance())) {
        $url_params = array('id' => $id, 'clid' => $classid, 'do_show' => 'analysis');
        $analysisurl = new moodle_url('/local/evaluations/analysis.php', $url_params);
     //   $row[] = new tabobject('analysis', $analysisurl->out(), get_string('analysis', 'local_evaluations'));
    }
    //}
    if(is_siteadmin() || is_ast_nh()){
        if (has_capability('local/evaluations:addinstance', context_system::instance())) {
            $url_params = array('id' => $id, 'clid' => $classid, 'do_show' => 'showentries');
            $reporturl = new moodle_url('/local/evaluations/show_entries.php', $url_params);
            $row[] = new tabobject('showentries', $reporturl->out(), get_string('show_entries', 'local_evaluations'));
       }
    }
    


    // if ($feedback->anonymous == FEEDBACK_ANONYMOUS_NO AND $feedback->course != SITEID) {
    //$nonrespondenturl = new moodle_url('/local/evaluations/show_nonrespondents.php', array('id'=>$usedid));
    //$row[] = new tabobject('nonrespondents',
    //                        $nonrespondenturl->out(),
    //                        get_string('show_nonrespondents', 'local_evaluations'));
    //}
Example #5
0
			}
			$user_toggle .="</div>";
			echo $user_toggle;
			
		}elseif(empty($assigned_courses)){
			$user_toggle .= "<div id='dialoguser$id'>";
			$user_toggle .= "<p class='empty_data' >No courses are assigned to this batch.Please assign courses.</p>";
			$user_toggle .="</div>";
			echo $user_toggle;
		}
     /*==========================Started by rajut for dispaly assigned users and assigne users (date:16-11-2015)==========*/       
      
    break;
	 case 5:
	  
	   if(is_trainers()|| is_siteadmin() || is_instructor() || is_ast_nh()){
       echo $output->cost_list($id);
	  echo html_writer::script('function costsubmit(id){
		var form=$("#formcost"+id);
        $.ajax({
			url: "costsubmit.php",
            type: "POST",
            data: form.serialize(),
            beforeSend: function(){
				$("#result").html("Sending....");
				
            },
            success: function(data){
                $("#result").html("Cost is Updated");
            }
        });
Example #6
0
require_once ('lib.php');
global $CFG;
require_once $CFG->dirroot.'/mod/facetoface/lib.php';
$site = get_site ();
$systemcontext = context_system::instance();

$id = required_param ( 'id', PARAM_INT ); // course id
$enrolid = required_param ( 'enrolid', PARAM_INT ); // course id
$course = $DB->get_record ( 'course', array ('id' => $id ), '*', MUST_EXIST );
$context =  context_course::instance($course->id, MUST_EXIST);
global $USER,$DB;
//require_login ( $course );
//require_capability ( 'moodle/course:enrolreview', $context );
$is_teammanager=$DB->record_exists('local_userdata',array('supervisorid'=>$USER->id));

if(!is_siteadmin() && empty($is_teammanager) && !is_ast_nh()) {
	throw new moodle_exception('nopermission');
}

$PAGE->set_url ( '/enrol/apply.php', array ('id' => $course->id ) );
//$PAGE->set_context($systemcontext);
$PAGE->set_pagelayout ( 'admin' );
$PAGE->set_heading ( $course->fullname );

$PAGE->navbar->add ( get_string ( 'confirmusers', 'enrol_apply' ) );
$PAGE->set_title ( "$site->shortname: " . get_string ( 'confirmusers', 'enrol_apply' ) );

if (isset ( $_POST ['enrolid'] )) {
	if ($_POST ['enrolid']) {
		if ($_POST ['type'] == 'confirm') {
			confirmEnrolment ( $_POST ['enrolid'] );
	$row[]='No Batches are assigned';
	$data[] = $row;
}
$f2f_table->head = array('','');
$f2f_table->data = $data;
if($userid != $USER->id){
    echo html_writer::link(new moodle_url('/local/teammanager/myteam.php'),'Back');
    $user_object = $DB->get_record('user',array('id'=>$userid));
    echo "<h3>".get_string('memberilt', 'facetoface',$user_object)."</h3>";
}else{
	if($userid10==''){
	 
    //rajesh has written this code
	
	 $iconimage=html_writer::empty_tag('img', array('src'=>$CFG->wwwroot.'/theme/clean/pix/small/manage_batches_small.png','size'=>'15px'));     
		if($is_manager || is_siteadmin() || is_teammanager() || is_instructor() || is_ast_nh() || is_trainers())
	     echo "<h2 class='tmhead2'><div class='iconimage'>".$iconimage."</div>".get_string('manageilt','facetoface')."</h3>";
	 
	 //code end here
	
	}
   else{ 
   $iconimage=html_writer::empty_tag('img', array('src'=>$CFG->wwwroot.'/theme/clean/pix/small/my_sessions_small.png','size'=>'15px'));     
    echo "<h2 class='tmhead2'><div class='iconimage'>".$iconimage."</div>".get_string('viewilt','facetoface')."</h2>";
   }
}
// if(is_siteadmin() || is_instructor() || is_ast_nh() || is_trainers()){
	if($userid10==''){
	if (has_capability('mod/facetoface:addinstance', $context) || is_siteadmin()) {
	echo '<style>#page-mod-facetoface-view_sessions .tmhead2 {
    color: #FFF;
//get the admin layout
$PAGE->set_pagelayout('admin');
$PAGE->requires->jquery();
$PAGE->requires->jquery_plugin('ui');

$PAGE->requires->js('/mod/facetoface/js/jquery.dataTables.min.js');//*This js and css files for data grid of batches*//
$PAGE->requires->css('/mod/facetoface/css/jquery.dataTables.css');
//check the context level of the user and check weather the user is login to the system or not
$PAGE->set_context($systemcontext);
$PAGE->set_url('/local/aprove_enroll/aprove_learners.php');
$PAGE->set_title(get_string('aprove_learners', 'local_aprove_enroll'));
$PAGE->set_heading(get_string('aprove_learners', 'local_aprove_enroll'));
$PAGE->navbar->add(get_string('requested_courses', 'local_aprove_enroll'));

require_login();
if(is_siteadmin($USER->id) || is_supervisor_dashboard() || is_ast_nh()){
echo $OUTPUT->header();
$noreqcourses = "<h2 style='text-align: center;'>".get_string('norequested_courses', 'local_aprove_enroll')."</h2>";
// for draft courses
$userdepartment=$DB->get_record('local_userdata',array('userid'=>$USER->id));
$sql="SELECT en.*,c.category FROM {enrol} as en
                                  JOIN {course} as c ON c.id=en.courseid
                                  JOIN {course_categories} as cat ON cat.id=c.category
                                  WHERE en.enrol = 'apply' and en.status=0";
if($userdepartment){
    switch($userdepartment->lms_category){
                case "AST":
                    $sql.= " AND cat.idnumber='AST'";
                    
                    break;
                
Example #9
0
function getAllEnrolment($id = null,$enrolid=null){
	global $DB,$USER,$CFG;
	    $newsuper = is_supervisor_dashboard();
		$is_ast_nh = is_ast_nh($USER->id);
		$is_zht = is_zht($USER->id);
		$is_hod = is_hod($USER->id);
		$is_instructor = is_instructor($USER->id);
		$is_trainers = is_trainers($USER->id);
		$is_bt = is_bt($USER->id);
		$is_ct = is_ct($USER->id);
		$is_zh = is_zh($USER->id);
		$is_rh = is_rh($USER->id);
         $userdepartment=$DB->get_record('local_userdata',array('userid'=>$USER->id));
	
		  $sql="select ue.userid,ue.id,c.fullname as course,ue.timecreated from {user_enrolments} as ue join {enrol} as e on ue.enrolid=e.id  join {course} as c on e.courseid=c.id,{local_userdata} ud where ue.userid=ud.userid AND ue.status=1 and e.courseid=$id and e.id=$enrolid ";
		
		if (is_siteadmin()||$is_ast_nh||$is_hod||$is_instructor||$is_zht||$is_trainers) {
		
		}else if($newsuper) {
			 $sql.= " AND ud.supervisorid=$USER->id";
		}
		//if(is_supervisor_dashboard()){
		//	$sql.= " AND ud.supervisorid=$USER->id";
		//}
		if($userdepartment){ 
			switch($userdepartment->lms_category){
				   case "AST":
					   $sql.= " AND (ud.lms_category='AST')";
					   
					   break;
				   
				   case "AST-EXT":
					   
						$sql.= " AND (ud.lms_category='AST-EXT')";
						 
					 break;
			 
			}
		}
		//echo $sql;
        //if(!$userdepartment->lms_category !=' ' || is_ast_nh()){
        //    $userdepartment_lms_category=0;
        //  $sql="select ue.userid,ue.id,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated from {user_enrolments} as ue left join {user} as u on ue.userid=u.id left join {enrol} as e on ue.enrolid=e.id left join {course} as c on e.courseid=c.id JOIN {local_userdata} ud ON u.id=ud.userid where ue.status=1 and e.courseid={$id} AND u.deleted=0 AND u.suspended=0 AND (ud.lms_category='AST' OR ud.lms_category='NON AST')";
        //}else{
        //    $userdepartment_lms_category=$userdepartment->lms_category;
        //     $sql="select ue.userid,ue.id,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated from {user_enrolments} as ue left join {user} as u on ue.userid=u.id left join {enrol} as e on ue.enrolid=e.id left join {course} as c on e.courseid=c.id JOIN {local_userdata} ud ON u.id=ud.userid where ue.status=1 and e.courseid={$id}";
        //
        //}

	if($id){
		$userenrolments = $DB->get_records_sql($sql);
	}else{
		$userenrolments = $DB->get_records_sql($sql);
	}
	//print_object($userenrolments);
	return $userenrolments;
}
Example #10
0
public function view_session_tabs($frecord,$userid,$sessiontype=-1){//*This function returns Sessions list of Tabs based on there capabilities*//
    global $DB, $OUTPUT,$USER,$CFG;
    
    $extrainfo = '';
    $extrainfo .= '<div id="face2face' . $frecord->id . '">
            <ul>';
            
     if(is_siteadmin() || is_instructor() || is_ast_nh() || is_trainers()){
             
             $extrainfo .= '<li><a href="' . $CFG->wwwroot . '/mod/facetoface/ajax.php?page=3&id=' . $frecord->id .'">'.get_string('course', 'facetoface').'</a></li>
                            <li><a href="' . $CFG->wwwroot . '/mod/facetoface/ajax.php?page=4&id=' . $frecord->id . '&sessiontype='.$sessiontype.'">'.get_string('users', 'facetoface').'</a></li>
                            <li><a href="' . $CFG->wwwroot . '/mod/facetoface/ajax.php?page=1&id=' . $frecord->id . '">'.get_string('view_sessions', 'facetoface').'</a></li>
							<li><a href="' . $CFG->wwwroot . '/mod/facetoface/ajax.php?page=2&id=' . $frecord->id . '">'.get_string('feedback', 'facetoface').'</a></li>
							<li><a href="' . $CFG->wwwroot . '/mod/facetoface/ajax.php?page=5&id=' . $frecord->id . '">Cost</a></li>';
	
    }else if(is_supervisor_dashboard()){
        
            $extrainfo .= '<li><a href="' . $CFG->wwwroot . '/mod/facetoface/ajax.php?page=1&id=' . $frecord->id . '">'.get_string('view_sessions', 'facetoface').'</a></li>';
        if($userid!=$USER->id){
            $extrainfo .= 	'<li><a href="' . $CFG->wwwroot . '/mod/facetoface/ajax.php?page=2&id=' . $frecord->id . '&userid='.$userid.'">'.get_string('feedback', 'facetoface').'</a></li>';												
        }
            
	}
	else{
		$extrainfo .= '<li><a href="' . $CFG->wwwroot . '/mod/facetoface/ajax.php?page=1&id=' . $frecord->id . '">'.get_string('view_sessions', 'facetoface').'</a></li>';
	}
    $extrainfo .=' </ul>
            </div>';
    $extrainfo .= face2face_tab_script($frecord);        
    $extrainfo .= " <style>
                    .ui-tabs-vertical {	width: 100% !important; float: left; margin-top: 0px !important; }
                    .ui-tabs-vertical .ui-tabs-nav { padding: 5px 0px 0px 0px; float: left; width: 12% !important; }
                    .ui-tabs-vertical .ui-tabs-nav li { clear: left; width: 100%; border-bottom-width: 1px !important; border-right-width: 0 !important; margin: 0 -1px .2em 0; }
                    .ui-tabs-vertical .ui-tabs-nav li a { display:block; }
                    .ui-tabs-vertical .ui-tabs-nav li.ui-tabs-active { padding-bottom: 0; padding-right: .1em; border-right-width: 1px; }
                    .ui-tabs-vertical .ui-tabs-panel { padding: 1em; margin: 5px 0px; float: right; width: 88% !important;background-color: #b5e8f5;min-height: 228px;}
                    </style>";/*.ui-tabs-vertical .ui-tabs-panel{width: 85%; changed by hameed on 28 dec}*/  
    $assigned_users_status=$DB->get_record_sql("SELECT * FROM {local_batch_courses} where batchid=$frecord->id");
    $extrainfo .='<script>
                    $(document).ready(function(){
                           $("#show'.$frecord->id.'").click(function(){
                              $("#'.$frecord->id.'").popup({
                              autozindex:true
                              });
                           });
                           
                             $("#show'.$frecord->id.$assigned_users_status->courseid.$assigned_users_status->testid.'").click(function(){
                              $("#'.$frecord->id.$assigned_users_status->courseid.$assigned_users_status->testid.'").popup({
                                 autozindex:true
                             });
                           });
                           
                           
                            });
                    </script>';	 
      return $extrainfo;
        
}
Example #11
0
/**
 * Generates the HTML for a miniature calendar
 *
 * @param array $courses list of course to list events from
 * @param array $groups list of group
 * @param array $users user's info
 * @param int|bool $calmonth calendar month in numeric, default is set to false
 * @param int|bool $calyear calendar month in numeric, default is set to false
 * @param string|bool $placement the place/page the calendar is set to appear - passed on the the controls function
 * @param int|bool $courseid id of the course the calendar is displayed on - passed on the the controls function
 * @param int $time the unixtimestamp representing the date we want to view, this is used instead of $calmonth
 *     and $calyear to support multiple calendars
 * @return string $content return html table for mini calendar
 */
function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyear = false, $placement = false,
    $courseid = false, $time = 0) {
   global $DB, $PAGE,$USER,$CFG,$OUTPUT;
  require_once $CFG->dirroot.'/local/lib.php';

    // Get the calendar type we are using.
    $calendartype = \core_calendar\type_factory::get_calendar_instance();

    $display = new stdClass;

    // Assume we are not displaying this month for now.
    $display->thismonth = false;

    $content = '';

    // Do this check for backwards compatibility. The core should be passing a timestamp rather than month and year.
    // If a month and year are passed they will be in Gregorian.
    if (!empty($calmonth) && !empty($calyear)) {
        // Ensure it is a valid date, else we will just set it to the current timestamp.
        if (checkdate($calmonth, 1, $calyear)) {
            $time = make_timestamp($calyear, $calmonth, 1);
        } else {
            $time = time();
        }
        $date = usergetdate($time);
        if ($calmonth == $date['mon'] && $calyear == $date['year']) {
            $display->thismonth = true;
        }
        // We can overwrite date now with the date used by the calendar type, if it is not Gregorian, otherwise
        // there is no need as it is already in Gregorian.
        if ($calendartype->get_name() != 'gregorian') {
            $date = $calendartype->timestamp_to_date_array($time);
        }
    } else if (!empty($time)) {
        // Get the specified date in the calendar type being used.
        $date = $calendartype->timestamp_to_date_array($time);
        $thisdate = $calendartype->timestamp_to_date_array(time());
        if ($date['month'] == $thisdate['month'] && $date['year'] == $thisdate['year']) {
            $display->thismonth = true;
            // If we are the current month we want to set the date to the current date, not the start of the month.
            $date = $thisdate;
        }
    } else {
        // Get the current date in the calendar type being used.
        $time = time();
        $date = $calendartype->timestamp_to_date_array($time);
        $display->thismonth = true;
    }

    list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display.

    // Get Gregorian date for the start of the month.
    $gregoriandate = $calendartype->convert_to_gregorian($date['year'], $date['mon'], 1);

    // Store the gregorian date values to be used later.
    list($gy, $gm, $gd, $gh, $gmin) = array($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'],
        $gregoriandate['hour'], $gregoriandate['minute']);

    // Get the max number of days in this month for this calendar type.
    $display->maxdays = calendar_days_in_month($m, $y);
    // Get the starting week day for this month.
    $startwday = dayofweek(1, $m, $y);
    // Get the days in a week.
    $daynames = calendar_get_days();
    // Store the number of days in a week.
    $numberofdaysinweek = $calendartype->get_num_weekdays();

    // Set the min and max weekday.
    $display->minwday = calendar_get_starting_weekday();
    $display->maxwday = $display->minwday + ($numberofdaysinweek - 1);

    // These are used for DB queries, so we want unixtime, so we need to use Gregorian dates.
    $display->tstart = make_timestamp($gy, $gm, $gd, $gh, $gmin, 0);
    $display->tend = $display->tstart + ($display->maxdays * DAYSECS) - 1;

    // Align the starting weekday to fall in our display range
    // This is simple, not foolproof.
    if ($startwday < $display->minwday) {
        $startwday += $numberofdaysinweek;
    }

    // Get the events matching our criteria. Don't forget to offset the timestamps for the user's TZ!
    $events = calendar_get_events($display->tstart, $display->tend, $users, $groups, $courses);

    // Set event course class for course events
    if (!empty($events)) {
        foreach ($events as $eventid => $event) {
            if (!empty($event->modulename)) {
                $cm = get_coursemodule_from_instance($event->modulename, $event->instance);
                if (!\core_availability\info_module::is_user_visible($cm, 0, false)) {
                    unset($events[$eventid]);
                }
            }
        }
    }

    // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after
    // possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month
    // will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra
    // arguments to this function.
    $hrefparams = array();
    if(!empty($courses)) {
        $courses = array_diff($courses, array(SITEID));
        if(count($courses) == 1) {
            $hrefparams['course'] = reset($courses);
        }
    }

    // We want to have easy access by day, since the display is on a per-day basis.
    calendar_events_by_day($events, $m, $y, $eventsbyday, $durationbyday, $typesbyday, $courses);

    // Accessibility: added summary and <abbr> elements.
    $summary = get_string('calendarheading', 'calendar', userdate($display->tstart, get_string('strftimemonthyear')));
    $content .= '<table class="minicalendar calendartable" summary="'.$summary.'">'; // Begin table.
    if (($placement !== false) && ($courseid !== false)) {
        $content .= '<caption>'. calendar_top_controls($placement, array('id' => $courseid, 'time' => $time)) .'</caption>';
    }
    $content .= '<tr class="weekdays">'; // Header row: day names

    // Print out the names of the weekdays.
    for ($i = $display->minwday; $i <= $display->maxwday; ++$i) {
        $pos = $i % $numberofdaysinweek;
        $content .= '<th scope="col"><abbr title="'. $daynames[$pos]['fullname'] .'">'.
            $daynames[$pos]['shortname'] ."</abbr></th>\n";
    }

    $content .= '</tr><tr>'; // End of day names; prepare for day numbers

    // For the table display. $week is the row; $dayweek is the column.
    $dayweek = $startwday;

    // Paddding (the first week may have blank days in the beginning)
    for($i = $display->minwday; $i < $startwday; ++$i) {
        $content .= '<td class="dayblank">&nbsp;</td>'."\n";
    }

    $weekend = CALENDAR_DEFAULT_WEEKEND;
    if (isset($CFG->calendar_weekend)) {
        $weekend = intval($CFG->calendar_weekend);
    }

    // Now display all the calendar
    $daytime = strtotime('-1 day', $display->tstart);
    for($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) {
        $daytime = strtotime('+1 day', $daytime);
        if($dayweek > $display->maxwday) {
            // We need to change week (table row)
            $content .= '</tr><tr>';
            $dayweek = $display->minwday;
        }

        // Reset vars.
        if ($weekend & (1 << ($dayweek % $numberofdaysinweek))) {
            // Weekend. This is true no matter what the exact range is.
            $class = 'weekend day';
        } else {
            // Normal working day.
            $class = 'day';
        }

        // Special visual fx if an event is defined
        if(isset($eventsbyday[$day])) {

            
            $popupcontent = '';
            foreach($eventsbyday[$day] as $eventid) {
                
               $class .= ' hasevent';
                $hrefparams['view'] = 'day';
                 global $DB,$CFG;
                    $instance_facetoface=$events[$eventid];
                
                if($instance_facetoface->modulename=='facetoface'){
                    $face=$DB->get_record('facetoface',array('id'=>$instance_facetoface->instance));
                    if(is_siteadmin() || is_ast_nh() || is_instructor() || is_trainers()){
                        
                       if(($DB->get_record_sql("SELECT * FROM {local_batch_users} where f2fid=$face->id and userid=$USER->id")&&($face->trainerid!=$USER->id))){
                        
                         $dayhref =$CFG->wwwroot.'/mod/facetoface/my_sessions.php?batchid='.$face->id.'&sessiontype='.$face->active.''; 
                       
                       }else{
                         $dayhref =$CFG->wwwroot.'/mod/facetoface/view_sessions.php?batchid='.$face->id.'&sessiontype='.$face->active.'';       
                       }
                      
                    }else{
                        $dayhref =$CFG->wwwroot.'/mod/facetoface/my_sessions.php?batchid='.$face->id.'&sessiontype='.$face->active.''; 
                    }
                   /*end here*/
                   
                }else{
                $dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', $hrefparams), 0, 0, 0, $daytime);
                }
               
                
                
                if (!isset($events[$eventid])) {
                    continue;
                }
                $event = new calendar_event($events[$eventid]);
                $popupalt  = '';
                $component = 'moodle';
                if (!empty($event->modulename)) {
                    $popupicon = 'icon';
                    $popupalt  = $event->modulename;
                    $component = $event->modulename;
                } else if ($event->courseid == SITEID) { // Site event.
                    $popupicon = 'i/siteevent';
                } else if ($event->courseid != 0 && $event->courseid != SITEID && $event->groupid == 0) { // Course event.
                    $popupicon = 'i/courseevent';
                } else if ($event->groupid) { // Group event.
                    $popupicon = 'i/groupevent';
                } else { // Must be a user event.
                    $popupicon = 'i/userevent';
                }

               // $dayhref->set_anchor('event_'.$event->id);

                $popupcontent .= html_writer::start_tag('div');
                //$popupcontent .= $OUTPUT->pix_icon($popupicon, $popupalt, $component);
                if($instance_facetoface->modulename=='facetoface'){
                    $lms_category=$DB->get_record_sql("SELECT * FROM {local_userdata} where userid=$USER->id");
                    if((is_siteadmin())){
                       if($face->category=='')
                        $name = format_string($event->name, true);
                    }
                    elseif(($face->trainerid==$USER->id)&&(is_ast_nh() || is_instructor() || is_trainers())){
                         if($lms_category->lms_category==$face->category)
                         $name = format_string($event->name, true);
                    }elseif($DB->get_record_sql("SELECT * FROM {local_batch_users} where f2fid=$face->id and userid=$USER->id")){
                        $name = format_string($event->name, true);
                    }else{
                        $name="";
                    }
                }else{
                     $name = format_string($event->name, true);
                }
               
                // Show ical source if needed.
                if (!empty($event->subscription) && $CFG->calendar_showicalsource) {
                    $a = new stdClass();
                    $a->name = $name;
                    $a->source = $event->subscription->name;
                    $name = get_string('namewithsource', 'calendar', $a);
                }
                $popupcontent .= html_writer::link($dayhref, $name);
                $popupcontent .= html_writer::end_tag('div');
            }

            //Accessibility: functionality moved to calendar_get_popup.
            if($display->thismonth && $day == $d) {
                $popupid = calendar_get_popup(true, $events[$eventid]->timestart, $popupcontent);
            } else {
                $popupid = calendar_get_popup(false, $events[$eventid]->timestart, $popupcontent);
            }

            // Class and cell content
            if(isset($typesbyday[$day]['startglobal'])) {
                $class .= ' calendar_event_global';
            } else if(isset($typesbyday[$day]['startcourse'])) {
                $class .= ' calendar_event_course';
            } else if(isset($typesbyday[$day]['startgroup'])) {
                $class .= ' calendar_event_group';
            } else if(isset($typesbyday[$day]['startuser'])) {
                $class .= ' calendar_event_user';
            }
            $cell = html_writer::link($dayhref, $day, array('id' => $popupid));
        } else {
            $cell = $day;
        }

        $durationclass = false;
        if (isset($typesbyday[$day]['durationglobal'])) {
            $durationclass = ' duration_global';
        } else if(isset($typesbyday[$day]['durationcourse'])) {
            $durationclass = ' duration_course';
        } else if(isset($typesbyday[$day]['durationgroup'])) {
            $durationclass = ' duration_group';
        } else if(isset($typesbyday[$day]['durationuser'])) {
            $durationclass = ' duration_user';
        }
        if ($durationclass) {
            $class .= ' duration '.$durationclass;
        }

        // If event has a class set then add it to the table day <td> tag
        // Note: only one colour for minicalendar
        if(isset($eventsbyday[$day])) {
            foreach($eventsbyday[$day] as $eventid) {
                if (!isset($events[$eventid])) {
                    continue;
                }
                $event = $events[$eventid];
                if (!empty($event->class)) {
                    $class .= ' '.$event->class;
                }
                break;
            }
        }

        // Special visual fx for today
        //Accessibility: hidden text for today, and popup.
        if($display->thismonth && $day == $d) {
            $class .= ' today';
            $today = get_string('today', 'calendar').' '.userdate(time(), get_string('strftimedayshort'));

            if(! isset($eventsbyday[$day])) {
                $class .= ' eventnone';
                $popupid = calendar_get_popup(true, false);
                $cell = html_writer::link('#', $day, array('id' => $popupid));
            }
            $cell = get_accesshide($today.' ').$cell;
        }

        // Just display it
        if(!empty($class)) {
            $class = ' class="'.$class.'"';
        }
        $content .= '<td'.$class.'>'.$cell."</td>\n";
    }

    // Paddding (the last week may have blank days at the end)
    for($i = $dayweek; $i <= $display->maxwday; ++$i) {
        $content .= '<td class="dayblank">&nbsp;</td>';
    }
    $content .= '</tr>'; // Last row ends

    $content .= '</table>'; // Tabular display of days ends

    return $content;
}