'_is-lepress-assignment', 'meta_value' => 1); $gotsome = get_posts($args); } else { $gotsome = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM ".$studentWidget->getAssignmentsTable())); } if ( $gotsome ) { $cache[ $key ] = ''; wp_cache_set( 'get_calendar', $cache, 'lepress-calendar' ); return; } } if ( isset($_GET['w']) ) $w = ''.intval($_GET['w']); // week_begins = 0 stands for Sunday $week_begins = intval(get_option('start_of_week')); // Let's figure out when we are if ( !empty($monthnum) && !empty($year) ) { $thismonth = ''.zeroise(intval($monthnum), 2); $thisyear = ''.intval($year); } elseif ( !empty($w) ) { // We need to get the month from MySQL $thisyear = ''.intval(substr($m, 0, 4)); $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')"); } elseif ( !empty($m) ) { $thisyear = ''.intval(substr($m, 0, 4)); if ( strlen($m) < 6 ) $thismonth = '01'; else $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2); } else { $thisyear = gmdate('Y', current_time('timestamp')); $thismonth = gmdate('m', current_time('timestamp')); } $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); $last_day = date('t', $unixmonth); $previous = false; $next = false; $gotsome_assignments = array(); $sorted = array(); //Raw assignments data $student_raw_assignments = array(); if($role == 'teacher') { if(is_int($cat_ID) && $cat_ID > 0) { $args = array('meta_key' => '_is-lepress-assignment', 'meta_value' => 1, 'category' => $cat_ID, 'numberposts' => -1); $gotsome_assignments = get_posts($args); } //Add assignments to array with key = assignment_end_date => $post foreach($gotsome_assignments as $post) { $assignment_end = get_post_meta($post->ID, '_lepress-assignment-end-date', true); $sorted[strtotime($assignment_end)][] = $post; } //Get prev link krsort($sorted); foreach($sorted as $end_time => $post) { if($end_time < strtotime($thisyear.'-'.$thismonth.'-01')) { $previous = (object) 'lepress_prev'; $previous->year = gmdate('Y', $end_time); $previous->month = gmdate('n', $end_time); break; } } //Get next link ksort($sorted); foreach($sorted as $end_time => $post) { if($end_time > strtotime($thisyear.'-'.$thismonth.'-'.$last_day.' 23:59:59')) { $next = (object) 'lepress_next'; $next->year = gmdate('Y', $end_time); $next->month = gmdate('n', $end_time); break; } } } elseif ($role == 'student') { //Student previous month $previous = $wpdb->get_row("SELECT MONTH(end_date) AS month, YEAR(end_date) AS year " ."FROM ".$studentWidget->getAssignmentsTable()." " ."WHERE end_date < '{$thisyear}-{$thismonth}-01 00:00:00' " ."AND course_id = '".esc_sql($cat_ID)."' ORDER BY end_date DESC LIMIT 1"); $next = $wpdb->get_row("SELECT MONTH(end_date) AS month, YEAR(end_date) AS year " ."FROM ".$studentWidget->getAssignmentsTable()." " ."WHERE end_date > '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' " ."AND course_id = '".esc_sql($cat_ID)."' ORDER BY end_date ASC LIMIT 1"); $gotsome_assignments = $wpdb->get_results("SELECT ID, post_id, title, url, start_date, end_date, DAYOFMONTH(end_date) as dom " ."FROM ".$studentWidget->getAssignmentsTable()." " ."WHERE end_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' " ."AND end_date >= '{$thisyear}-{$thismonth}-01 00:00:00' " ."AND course_id = '".esc_sql($cat_ID)."'"); //Get all assgiments, for assigmnetn list on the sidebar widget $student_raw_assignments = $wpdb->get_results("SELECT ID, post_id, title, url, start_date, end_date, DAYOFMONTH(end_date) as dom " ."FROM ".$studentWidget->getAssignmentsTable()." " ."WHERE course_id = '".esc_sql($cat_ID)."'"); } //THERES a bug in PHP < 5.3, that causes error in +1 month if day of month is 31 // http://bugs.php.net/bug.php?id=44073 //prev and next link if(!$previous && $thismonth > gmdate('n')) { $previous = (object) 'lepress_prev'; $current_month = gmdate('Y-n-d', strtotime($thisyear.'-'.$thismonth.'-01 +1 month')); $previous->year = gmdate('Y', strtotime($current_month)); $previous->month = gmdate('n', strtotime($current_month)); } if(!$next && $thismonth < gmdate('n')) { $next = (object) 'lepress_prev'; $current_month = gmdate('Y-n-d', strtotime($thisyear.'-'.$thismonth.'-01 +1 month')); $next->year = gmdate('Y', strtotime($current_month)); $next->month = gmdate('n', strtotime($current_month)); } /* translators: Calendar caption: 1: month name, 2: 4-digit year */ $calendar_caption = _x('%1$s %2$s', 'calendar caption'); $calendar_output = '
'; $calendar_output .= '
'; $calendar_output .= ''; $myweek = array(); for ( $wdcount=0; $wdcount<=6; $wdcount++ ) { $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7); } foreach ( $myweek as $wd ) { $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd); $wd = esc_attr($wd); $calendar_output .= "\n\t\t"; } $calendar_output .= ' '; if ( $previous ) { $calendar_output .= "\n\t\t".''; } else { $calendar_output .= "\n\t\t".''; } $calendar_output .= "\n\t\t".''; if ( $next ) { $calendar_output .= "\n\t\t".''; } else { $calendar_output .= "\n\t\t".''; } $calendar_output .= ' '; $dayswithposts = array(); // Get days with posts //Get the real end date of our assignment foreach($gotsome_assignments as $post) { if($role == 'teacher') { $day_of_post_query = get_post_meta($post->ID, '_lepress-assignment-end-date', true); $tstamp = strtotime($day_of_post_query); //Check if post/assignment is on current month if($thismonth == gmdate('n', $tstamp)) { $day_of_post = gmdate('j', $tstamp); $dayswithposts[] = $day_of_post; } } elseif ($role == 'student') { $dayswithposts[] = $post->dom; } } $daywithpost = array(); if ( $dayswithposts ) { foreach ( (array) $dayswithposts as $daywith ) { $daywithpost[] = $daywith; } } else { $daywithpost = array(); } if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false) $ak_title_separator = "\n"; else $ak_title_separator = ', '; $ak_titles_for_day = array(); if ( $gotsome_assignments ) { foreach ( (array) $gotsome_assignments as $ak_post_title ) { if($role == "teacher") { $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) ); //Get assignment end date as dom (day of month), so it will be displayed on end date not on start date $day_of_post_query = get_post_meta($ak_post_title->ID, '_lepress-assignment-end-date', true); $dom = gmdate('j', strtotime($day_of_post_query)); $url = get_permalink($ak_post_title->ID); } else { $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->title, $ak_post_title->ID ) ); $dom = $ak_post_title->dom; $url = $ak_post_title->url; } if ( empty($ak_titles_for_day["$dom"]) ) $ak_titles_for_day["$dom"] = ''; if ( empty($ak_titles_for_day["$dom"]) ) // first one $ak_titles_for_day["$dom"][] = array('post_id' => ($role == 'teacher' ? $ak_post_title->ID : $ak_post_title->post_id), 'post_title' => $post_title, 'url' => $url); else $ak_titles_for_day["$dom"][] = array('post_id' => ($role == 'teacher' ? $ak_post_title->ID : $ak_post_title->post_id), 'post_title' => $post_title, 'url' => $url); } } // See how much we should pad in the beginning $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins); if ( 0 != $pad ) $calendar_output .= "\n\t\t".''; $daysinmonth = intval(date('t', $unixmonth)); for ( $day = 1; $day <= $daysinmonth; ++$day ) { if ( isset($newrow) && $newrow ) $calendar_output .= "\n\t\n\t\n\t\t"; $newrow = false; if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) ) $calendar_output .= ''; if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) ) $newrow = true; } $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins); if ( $pad != 0 && $pad != 7 ) $calendar_output .= "\n\t\t".''; $calendar_output .= "\n\t\n\t\n\t
' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '
$day_name
« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '  ' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' » 
 
'; else $calendar_output .= ''; if ( in_array($day, $daywithpost)) { // any posts today? //Let's display assignments on calendar $title_str = ''; //echo $day." - ".$ak_titles_for_day[$day]; Student had some sort of bug here ? if(is_array($ak_titles_for_day[$day])) { foreach($ak_titles_for_day[$day] as $post_data) { $title_str .= $post_data['post_title']."\n"; } } if($title_str == '') { $calendar_output .= $day; } else { $calendar_output .= ''; foreach($ak_titles_for_day[$day] as $post_data) { $draft = false; if($role == 'student') { if(is_user_logged_in()) { $status = $studentWidget->subscriptions->getAssignmentStatus($post_data['post_id']); if($status) { $title = __('Work submitted', lepress_textdomain); $calendar_output .= ''.$title.''; } else { $post_id = $studentWidget->subscriptions->getAssignmentStatus($post_data['post_id'], true); $post = get_post($post_id); if($post && ($post->post_status == "draft" || $post->post_status == "future")) { $title = __('Edit work', lepress_textdomain); $calendar_output .= ''; $draft = true; } else { $title = __('Submit work', lepress_textdomain); $calendar_output .= ''; } $calendar_output .= ''.$title.''; } } if(!isSet($title)) { $calendar_output .= ''; } $calendar_output .= $post_data['post_title'].''.($draft ? ' - '.__('draft', lepress_textdomain) : '').'
'; } elseif($role == 'teacher') { $calendar_output .= ' '.$post_data['post_title'].'
'; if(is_user_logged_in()) { $course_meta = new CourseMeta($cat_ID); if($course_meta->getIsCourse()) { $calendar_output .= '
    '; $display_name_order = $LePress->getDisplayNames(); foreach($course_meta->getApprovedSubscriptions() as $subscription) { $name = $display_name_order == 1 ? $subscription->first_name.' '.$subscription->last_name : $subscription->last_name.' '.$subscription->first_name; $comment = $LePress->fetchComment($post_data['post_id'], $subscription->email, 'LePressStudent'); $meta_data = get_post_meta($post_data['post_id'], '_lepress-student-'.md5($post_data['post_id'].$subscription->email), true); $calendar_output .= '
  • '; if($comment) { if(!$meta_data['feedback']) { $title = __('Send feedback', lepress_textdomain); $feedback_link_img = ''.$title.''; } else { //Feedback given $title = __('Change feedback', lepress_textdomain); $feedback_link_img = ''.$title.''; } $calendar_output .= ''.$feedback_link_img; } else { $calendar_output .= ''.__('Not accomplished', lepress_textdomain).''; } if($meta_data['post_url']) { $calendar_output .= $name.'
  • '; } else { $calendar_output .= $name.''; } } $calendar_output .= '
'; } } } } $calendar_output .= '
'; $calendar_output .= ''.$day.''; } } else { $calendar_output .= $day; } $calendar_output .= '
 
"; //Add some more data, assignments, participants //Easy subscribe form, if teacher if($role == "teacher") { $course_meta = new CourseMeta($cat_ID); if($course_meta->getIsCourse()) { $calendar_output .= getEasySubscribeForm($cat_ID); } } //Teachers if($role == 'student') { $calendar_output .= getTeachers($cat_ID, $studentWidget); } //Participants $calendar_output .= getParticipantsList($cat_ID, $role, $teacherWidget, $studentWidget); //Assignments $assignments = ($role == 'teacher') ? $sorted : $student_raw_assignments; $calendar_output .= getAssignmentsList($assignments, $thismonth, $thisyear, $last_day, $role, $cat_ID, $studentWidget); // Have to pass $sorted array of assignments //Add division end $calendar_output .= '
'; $cache[ $key ] = $calendar_output; wp_cache_set( 'get_calendar', $cache, 'lepress-calendar' ); if ( $echo ) echo apply_filters( 'get_calendar', $calendar_output ); else return apply_filters( 'get_calendar', $calendar_output ); } /** * Get assignments list * * This method outputs assignments list * * @return string html */ function getAssignmentsList($assignments, $thismonth, $thisyear, $last_day, $role, $cat_ID, $studentWidget = false) { global $LePress, $widget_instance; if(isSet($_GET['c'])) { $query_params = array('c' => $_GET['c']); } $class = ''; if($widget_instance['collapse_assignments'] && $role == 'teacher') { $class = 'class="lepress-hidden"'; } /* These parameters come with AJAX call */ if(isSet($_GET['a'])) { if($_GET['a'] != 1) { $class = 'class="lepress-hidden"'; } } $output = '

'.apply_filters('widget_title', __('Assignments', lepress_textdomain)).' '.getExpandCollapseIMG($class).'

'; $output .= '
'; //Iterate through all the assignments foreach($assignments as $end_time_key => $post) { if($role == 'student') { $end_time_key = strtotime($post->end_date); $start_ts = strtotime($post->start_date); } elseif($role == 'teacher') { $start_ts = strtotime(get_post_meta($post->ID, '_lepress-assignment-start-date', true)); } $assignment_added = true; if(is_array($post)) { foreach($post as $post) { $post_title = ($role == 'teacher' ? $post->post_title : $post->title); if($role == 'student') { $start_ts = strtotime($post->start_date); } elseif($role == 'teacher') { $start_ts = strtotime(get_post_meta($post->ID, '_lepress-assignment-start-date', true)); } $output .= convertToEventhCard($post_title, $start_ts, $end_time_key); $output .= ' '.$post_title.' ('.$LePress->date_i18n_lepress($end_time_key).')
'; if(is_user_logged_in()) { $course_meta = new CourseMeta($cat_ID); if($course_meta->getIsCourse()) { $output .= ''; } } } } else { $post_title = ($role == 'teacher' ? $post->post_title : $post->title); $output .= convertToEventhCard($post_title, $start_ts, $end_time_key); if($role == 'student') { $draft = false; if(is_user_logged_in()) { $status = $studentWidget->subscriptions->getAssignmentStatus($post->post_id); if($status) { $title = __('Work submitted', lepress_textdomain); $output .= ''.$title.''; } else { $post_id = $studentWidget->subscriptions->getAssignmentStatus($post->post_id, true); $post_student = get_post($post_id); if($post_student && ($post_student->post_status == "draft" || $post_student->post_status == "future")) { $title = __('Edit work', lepress_textdomain); $output .= ''; $draft = true; } else { $title = __('Submit work', lepress_textdomain); $output .= ''; } $output .= ''.$title.''; } $output .= $post->title.' ('.$LePress->date_i18n_lepress($end_time_key).')'.($draft ? ' - '.__('draft', lepress_textdomain) : '').'
'; } else { $output .= ''.$post->title.' ('.$LePress->date_i18n_lepress($end_time_key).')
'; } } } } if(!isSet($assignment_added)){ $output .= __('There are no assignments in this month.', lepress_textdomain); } //Add collapse - expand wrapper div end $output .= '
'; if($role == 'student') { $output .= '

'.apply_filters('widget_title', __('Graduation', lepress_textdomain)).'

'; $output .= '
'.__('My progress', lepress_textdomain).'
'; } return $output; } /** * Convert assignments into hCard events * * @return string html */ function convertToEventhCard($post_title, $start_date_ts, $end_date_ts) { global $LePress; $end_date_8601 = date('Y-m-d', $end_date_ts)."T23:59:59+03:00"; $start_date_8601 = date('Y-m-d', $start_date_ts)."T00:00+03:0000"; $output = ''; return $output; } /** * Output collapse/expand images * * @return string html */ function getExpandCollapseIMG($class) { $out = ''.__('Expand', lepress_textdomain).''; $out .= ''.__('Collapse', lepress_textdomain).''; return $out; } /** * Get participants list * * This method outputs participants list * * @return string html */ function getParticipantsList($cat_ID, $role, $teacherWidget, $studentWidget) { global $widget_instance,$LePress; $class = ''; if($widget_instance['collapse_participants']) { $class = 'class="lepress-hidden"'; } /* These parameters come with AJAX call */ if(isSet($_GET['p'])) { if($_GET['p'] != 1) { $class = 'class="lepress-hidden"'; } } $output = '

'.apply_filters('widget_title', __('Participants', lepress_textdomain)).' '.getExpandCollapseIMG($class).'

'; $output .= '
'; $display_name_order = $LePress->getDisplayNames(); //If teacher role if($role == 'teacher') { $course_meta = new CourseMeta($cat_ID); if($course_meta->getIsCourse()) { foreach($course_meta->getApprovedSubscriptions() as $subscription) { $name = $display_name_order == 1 ? $subscription->first_name.' '.$subscription->last_name : $subscription->last_name.' '.$subscription->first_name; $output .= '
'; $output .= ''; $output .= ''; $output .= ''.$name.''; $output .= '
'; } } } elseif($role == 'student') { //If student role $mates = $studentWidget->getClassmates($cat_ID); foreach($mates as $subscription) { $name = $display_name_order == 1 ? $subscription->firstname.' '.$subscription->lastname : $subscription->lastname.' '.$subscription->firstname; $output .= '
'; $output .= ''; $output .= ''; $output .= ''.$name.''; $output .= '
'; } } //Oops, not participants found if(!isSet($subscription)){ $output .= __('There are no participants in this course.', lepress_textdomain); } //Add collapse - expand wrapper div end $output .= '
'; return $output; } /** * Get teachers / student widget * * This method outputs teachers list,only called on student side of widget * * @return string html */ function getTeachers($cat_ID, $studentWidget) { global $LePress; $output = '

'.apply_filters('widget_title', __('Teacher(s)', lepress_textdomain)).'

'; $teachers = $studentWidget->getTeachers($cat_ID); $display_name_order = $LePress->getDisplayNames(); $output .= '
'; foreach($teachers as $teacher) { $name = $display_name_order == 1 ? $teacher->firstname.' '.$teacher->lastname : $teacher->lastname.' '.$teacher->firstname; $output .= '
'; if(!empty($teacher->organization)) { $output .= ''; } $output .= ''; $output .= ''; $output .= ''; $output .= '
'; } if( count( $teachers ) == 0 ){ $output .= __('Oops, teacher(s) missing...', lepress_textdomain); } $output .= '
'; return $output; } /** * Output easy subscribe form * * This method outputs easy subscription form, depending on if user is logged in or not. * If user is not logged in, simple URL textbox is printed otherwise AJAX handler and auto discovered * blog data * * @return string html */ function getEasySubscribeForm($cat_ID) { $found_blog = false; if(is_user_logged_in()) { $current_user = wp_get_current_user(); $course_meta = new CourseMeta($cat_ID); global $LePress; if($course_meta->getStudentSubscriptionByEmail($current_user->user_email) || $LePress->getBlogOwnerUser()->ID == $current_user->ID) { return ''; } if(is_multisite()) { $user_blogs = get_blogs_of_user($current_user->ID); foreach($user_blogs as $blog) { /* Iterate through blogs and find one with active LePress plugin */ $switched = switch_to_blog($blog->userblog_id, true); if($switched) { global $LePress; $student_features_enabled = $LePress->isStudentFeatures(); if($student_features_enabled) { $found_blog = $blog; break; } } } //revert back to current blog restore_current_blog(); } } $output = '

'.apply_filters('widget_title', __('Subscribe', lepress_textdomain)).' '.getExpandCollapseIMG(true).'

'; $output .= '
'; $output .= '
'; $output .= ''; $output .= ''; if(!$found_blog) { $output .= ''.__('Enter your blog URL (http://www.example.com/blog)', lepress_textdomain).':'; $output .= ''; } else { $output .= __('We have discovered your first active blog with LePress student roll enabled.', lepress_textdomain); $output .= '
'.$found_blog->blogname.'
'; $output .= __('By clicking "Subscribe", you will be subscribed to the course using found blog.', lepress_textdomain); $output .= ''; $output .= ''; } $output .= '
'; $output .= ''; $output .= ''; $output .= '
'; $output .= '
'; return $output; } ?>