function get_unit_pages($unit)
 {
     $pages_num = 1;
     if (!cp_unit_uses_new_pagination($unit->ID)) {
         // Legacy
         $modules = $unit->modules;
         foreach ($modules as $mod) {
             $class_name = $mod->module_type;
             if ('page_break_module' == $class_name) {
                 $pages_num++;
             }
         }
     } else {
         // New unit builder 1.2.3.5+
         $pages_num = Unit::get_page_count($unit->ID);
     }
     return $pages_num;
 }
Ejemplo n.º 2
0
    die(__('You do not have required permissions to access this page.', 'cp'));
}
if (!isset($_POST['force_current_unit_completion'])) {
    $_POST['force_current_unit_completion'] = 'off';
}
if (!isset($_POST['force_current_unit_successful_completion'])) {
    $_POST['force_current_unit_successful_completion'] = 'off';
}
Unit_Module::check_for_modules_to_delete();
if (isset($_GET['unit_id'])) {
    $unit_id = (int) $_GET['unit_id'];
    $unit = new Unit($unit_id);
    $unit_details = $unit->get_unit();
    $force_current_unit_completion = $unit->details->force_current_unit_completion;
    $force_current_unit_successful_completion = $unit->details->force_current_unit_successful_completion;
    $unit_pagination = cp_unit_uses_new_pagination((int) $_GET['unit_id']);
} else {
    $unit = new Unit();
    $unit_id = 0;
    $force_current_unit_completion = 'off';
    $force_current_unit_successful_completion = 'off';
    $unit_pagination = false;
}
if ($unit_id == 0) {
    $unit_id = $unit->create_auto_draft($course_id);
    //create auto draft and get unit id
    //wp_redirect(admin_url('admin.php?page=' . $page . '&tab=units&course_id=' . $course_id . '&action=edit&unit_id=' . $unit_id));
}
if (isset($_POST['action']) && $_POST['action'] == 'update_unit') {
    if (wp_verify_nonce($_REQUEST['_wpnonce'], 'unit_details_overview_' . $user_id)) {
        if (current_user_can('manage_options') || current_user_can('coursepress_create_course_unit_cap') || current_user_can('coursepress_update_course_unit_cap') || current_user_can('coursepress_update_my_course_unit_cap') || current_user_can('coursepress_update_all_courses_unit_cap')) {
        /**
         * Shows the course structure.
         *
         * @since 1.0.0
         */
        function course_structure($atts)
        {
            extract(shortcode_atts(array('course_id' => in_the_loop() ? get_the_ID() : '', 'course' => false, 'free_text' => __('Free', 'cp'), 'free_show' => 'true', 'show_title' => 'no', 'show_label' => 'no', 'label_delimeter' => ': ', 'label_tag' => 'h2', 'show_divider' => 'yes', 'label' => __('Course Structure', 'cp'), 'class' => ''), $atts, 'course_structure'));
            $course_id = (int) $course_id;
            $free_text = sanitize_text_field($free_text);
            $free_show = sanitize_text_field($free_show);
            $free_show = 'true' == $free_show ? true : false;
            $show_title = sanitize_html_class($show_title);
            $show_label = sanitize_html_class($show_label);
            $label_delimeter = sanitize_html_class($label_delimeter);
            $label_tag = sanitize_html_class($label_tag);
            $show_divider = sanitize_html_class($show_divider);
            $label = sanitize_text_field($label);
            $class = sanitize_html_class($class);
            // Saves some overhead by not loading the post again if we don't need to.
            $course = empty($course) ? new Course($course_id) : object_decode($course, 'Course');
            $class = sanitize_html_class($class);
            $label_tag = sanitize_html_class($label_tag);
            $label_delimeter = sanitize_html_class($label_delimeter);
            if ($course->details->course_structure_options == 'on') {
                $content = '';
                $student = new Student(get_current_user_id());
                $existing_student = $student->has_access_to_course($course_id);
                $show_unit = $course->details->show_unit_boxes;
                $preview_unit = $course->details->preview_unit_boxes;
                $show_page = $course->details->show_page_boxes;
                $preview_page = $course->details->preview_page_boxes;
                $current_time = date('Y-m-d', current_time('timestamp', 0));
                $course_start_date = $course->details->course_start_date;
                $enable_links = false;
                if ($current_time >= $course_start_date) {
                    $enable_links = true;
                }
                $units = $course->get_units();
                $content .= '<div class="course-structure-block course-structure-block-' . $course_id . '">';
                if (!empty($label)) {
                    $content .= '<' . $label_tag . ' class="label">' . $label . $label_delimeter . '</' . $label_tag . '>';
                }
                $content .= 'yes' == $show_title ? '<label>' . $this->details->post_title . '</label>' : '';
                if ($units) {
                    ob_start();
                    ?>
					<ul class="tree">
						<li>
							<ul>
								<?php 
                    foreach ($units as $unit) {
                        $unit_class = new Unit($unit->ID);
                        $unit_pagination = cp_unit_uses_new_pagination($unit->ID);
                        if ($unit_pagination) {
                            $unit_pages = coursepress_unit_pages($unit->ID, $unit_pagination);
                        } else {
                            $unit_pages = coursepress_unit_pages($unit->ID);
                        }
                        //$unit_pages	 = $unit_class->get_number_of_unit_pages();
                        //									$modules = Unit_Module::get_modules( $unit->ID );
                        $unit_permalink = Unit::get_permalink($unit->ID);
                        if (isset($show_unit[$unit->ID]) && $show_unit[$unit->ID] == 'on' && $unit->post_status == 'publish') {
                            ?>
										<li>
											<label for="unit_<?php 
                            echo $unit->ID;
                            ?>
" class="course_structure_unit_label <?php 
                            echo $existing_student ? 'single_column' : '';
                            ?>
">
												<?php 
                            $title = '';
                            if ($existing_student && $enable_links) {
                                $title = '<a href="' . $unit_permalink . '">' . $unit->post_title . '</a>';
                            } else {
                                $title = $unit->post_title;
                            }
                            ?>
												<div class="tree-unit-left"><?php 
                            echo $title;
                            ?>
</div>
												<div class="tree-unit-right">

													<?php 
                            if ($course->details->course_structure_time_display == 'on') {
                                ?>
														<span><?php 
                                echo $unit_class->get_unit_time_estimation($unit->ID);
                                ?>
</span>
													<?php 
                            }
                            ?>

													<?php 
                            if (isset($preview_unit[$unit->ID]) && $preview_unit[$unit->ID] == 'on' && $unit_permalink && !$existing_student) {
                                ?>
														<a href="<?php 
                                echo $unit_permalink;
                                ?>
?try" class="preview_option"><?php 
                                echo $free_text;
                                ?>
</a>
													<?php 
                            }
                            ?>
												</div>
											</label>

											<ul>
												<?php 
                            for ($i = 1; $i <= $unit_pages; $i++) {
                                if (isset($show_page[$unit->ID . '_' . $i]) && $show_page[$unit->ID . '_' . $i] == 'on') {
                                    ?>
														<li class="course_structure_page_li <?php 
                                    echo $existing_student ? 'single_column' : '';
                                    ?>
">
															<?php 
                                    $pages_num = 1;
                                    $page_title = $unit_class->get_unit_page_name($i);
                                    ?>

															<label for="page_<?php 
                                    echo $unit->ID . '_' . $i;
                                    ?>
">
																<?php 
                                    $title = '';
                                    if ($existing_student && $enable_links) {
                                        $p_title = isset($page_title) && $page_title !== '' ? $page_title : __('Untitled Page', 'cp');
                                        $title = '<a href="' . trailingslashit($unit_permalink) . trailingslashit('page') . trailingslashit($i) . '">' . $p_title . '</a>';
                                    } else {
                                        $title = isset($page_title) && $page_title !== '' ? $page_title : __('Untitled Page', 'cp');
                                    }
                                    ?>

																<div class="tree-page-left">
																	<?php 
                                    echo $title;
                                    ?>
																</div>
																<div class="tree-page-right">

																	<?php 
                                    if ($course->details->course_structure_time_display == 'on') {
                                        ?>
																		<span><?php 
                                        echo $unit_class->get_unit_page_time_estimation($unit->ID, $i);
                                        ?>
</span>
																	<?php 
                                    }
                                    ?>

																	<?php 
                                    if (isset($preview_page[$unit->ID . '_' . $i]) && $preview_page[$unit->ID . '_' . $i] == 'on' && $unit_permalink && !$existing_student) {
                                        ?>
																		<a href="<?php 
                                        echo $unit_permalink;
                                        ?>
page/<?php 
                                        echo $i;
                                        ?>
?try" class="preview_option"><?php 
                                        echo $free_text;
                                        ?>
</a>
																	<?php 
                                    }
                                    ?>

																</div>
															</label>

															<?php 
                                    ?>
														</li>
													<?php 
                                }
                            }
                            //page visible
                            ?>

											</ul>
										</li>
									<?php 
                        }
                        //unit visible
                    }
                    // foreach
                    ?>
							</ul>
						</li>
					</ul>

					<?php 
                    if ($show_divider == 'yes') {
                        ?>
						<div class="divider"></div>
					<?php 
                    }
                    ?>

					<?php 
                    $content .= trim(ob_get_clean());
                } else {
                }
                $content .= '</div>';
                return $content;
            }
        }
Ejemplo n.º 4
0
 function admin_coursepress_page_course_details()
 {
     wp_enqueue_script('courses-units', $this->plugin_url . 'js/coursepress-courses.js', array(), $this->version);
     wp_enqueue_script('units-slimscroll', $this->plugin_url . 'js/jquery.slimscroll.min.js', array('jquery'), $this->version);
     $unit_pagination = false;
     if (isset($_GET['unit_id'])) {
         $unit_pagination = cp_unit_uses_new_pagination((int) $_GET['unit_id']);
     }
     add_action('admin_footer', array(&$this, 'add_cp2_editor'));
     wp_localize_script('courses-units', 'coursepress_units', array('admin_ajax_url' => admin_url('admin-ajax.php'), 'withdraw_class_alert' => __('Please confirm that you want to withdraw all students from this class?', 'cp'), 'delete_class' => __('Please confirm that you want to permanently delete the class? All students form this class will be moved to the Default class automatically.', 'cp'), 'setup_gateway' => __("You have selected 'This is a Paid Course'.\n In order to continue you must first setup a payment gateway by clicking on 'Setup Payment Gateways'", 'cp'), 'unit_setup_prompt' => __('<div>You have successfully completed your Basic Course Setup.</div><div>This can be changed anytime by clicking on "Course Overview".</div><div>Add and create <strong>Units</strong> for your course and add <strong>Students</strong>.</div><div>You must have at least <strong>one</strong> unit created to publish the course.</div>', 'cp'), 'mp_activated_prompt' => __('<div>Marketpress has been activated successfully.</div>', 'cp'), 'required_course_name' => __('<strong>Course Name</strong> is a required field.', 'cp'), 'required_course_excerpt' => __('<strong>Course Excerpt</strong> is a required field.', 'cp'), 'required_course_description' => __('<strong>Course Description</strong> is a required field.', 'cp'), 'required_course_start' => __('<strong>Course Start Date</strong> is a required field.', 'cp'), 'required_course_end' => __('<strong>Course Start Date</strong> is a required field when "This course has no end date" is <strong>not</strong> selected.', 'cp'), 'required_enrollment_start' => __('<strong>Enrollment Start Date</strong> is a required field when "Users can enroll anytime" is <strong>not</strong> selected.', 'cp'), 'required_enrollment_end' => __('<strong>Enrollment End Date</strong> is a required field when "Users can enroll anytime" is <strong>not</strong> selected.', 'cp'), 'required_course_class_size' => __('Value can not be 0 if "Limit class size" is selected.', 'cp'), 'required_course_passcode' => __('<strong>Pass Code</strong> required when "Anyone with a pass code" is selected', 'cp'), 'required_gateway' => __('<strong>Payment Gateway</strong> needs to be setup before you can sell this course.', 'cp'), 'required_price' => __('<strong>Price</strong> is a required field when "This is a Paid Course" is selected.', 'cp'), 'required_sale_price' => __('<strong>Sale Price</strong> is a required field when "Enable Sale Price" is selected.', 'cp'), 'section_error' => __('There is some information missing or incorrect. Please check your input and try again.', 'cp'), 'cp_editor_style' => $this->plugin_url . 'css/editor_style_fix.css', 'unit_pagination' => $unit_pagination ? 1 : 0, 'admin_ajax_url' => cp_admin_ajax_url()));
     wp_enqueue_style('jquery-ui-admin', $this->plugin_url . 'css/jquery-ui.css');
     wp_enqueue_style('admin_coursepress_page_course_details', $this->plugin_url . 'css/admin_coursepress_page_course_details.css', array(), $this->version);
     wp_enqueue_style('admin_coursepress_page_course_details_responsive', $this->plugin_url . 'css/admin_coursepress_page_course_details_responsive.css', array(), $this->version);
 }
 public static function page_name($unit_id, $page_number)
 {
     $page_titles = get_post_meta($unit_id, 'page_title', true);
     if (cp_unit_uses_new_pagination($unit_id)) {
         return !empty($page_titles['page_' . $page_number]) ? $page_titles['page_' . (int) $page_number] : '';
         //return !empty( $this->details->page_title[ 'page_' . $page_number ] ) ? $this->details->page_title[ 'page_' . (int) $page_number ] : '';
     } else {
         return !empty($page_titles) ? $page_titles[(int) ($page_number - 1)] : '';
     }
     return '';
 }
        public static function get_modules_front($unit_id = 0)
        {
            global $coursepress, $coursepress_modules, $wp, $paged, $_POST;
            if (isset($_GET['resubmit_nonce']) || isset($_GET['resubmit_nonce']) && wp_verify_nonce($_GET['resubmit_nonce'], 'resubmit_answer')) {
                if (isset($_GET['resubmit_answer'])) {
                    $user_id = get_current_user_id();
                    $course_id = (int) $_GET['c'];
                    $unit_id = (int) $_GET['u'];
                    $module_id = (int) $_GET['m'];
                    $response = get_post((int) $_GET['resubmit_answer']);
                    $response_id = false;
                    if (isset($response) && isset($response->post_author) && $response->post_author == get_current_user_ID()) {
                        $response_id = $response->ID;
                        $resubmitted_response = array('ID' => $response_id, 'post_status' => 'private');
                        wp_update_post($resubmitted_response);
                    }
                    Student_Completion::clear_mandatory_answer($user_id, $course_id, $unit_id, $module_id);
                    wp_redirect(add_query_arg(array('resubmitting' => $module_id, 'previous_response' => $response_id), $_GET['resubmit_redirect_to']) . '#module-' . $module_id);
                    exit;
                } else {
                    if (!empty($_GET['resubmit_cancel'])) {
                        $response_id = $_GET['resubmit_cancel'];
                        $response = get_post((int) $response_id);
                        $user_id = get_current_user_id();
                        $course_id = (int) $_GET['c'];
                        $unit_id = (int) $_GET['u'];
                        $module_id = (int) $_GET['m'];
                        if (isset($response) && isset($response->post_author) && $response->post_author == get_current_user_ID()) {
                            $resubmitted_response = array('ID' => $response_id, 'post_status' => 'publish');
                            wp_update_post($resubmitted_response);
                            Student_Completion::record_mandatory_answer($user_id, $course_id, $unit_id, $module_id);
                            wp_redirect($_GET['resubmit_redirect_to'] . '#module-' . $module_id);
                        }
                    }
                }
            }
            $front_save = false;
            $responses = 0;
            $input_modules = 0;
            $paged = isset($wp->query_vars['paged']) ? absint($wp->query_vars['paged']) : 1;
            $unit_pagination = cp_unit_uses_new_pagination((int) $unit_id);
            $modules = self::get_modules($unit_id, $paged);
            $course_id = do_shortcode('[get_parent_course_id]');
            /**
             * @todo: replace with Student_Completion function soon
             */
            cp_set_visited_unit_page($unit_id, $paged, get_current_user_ID(), $course_id);
            //$unit_module_page_number = isset( $_GET['to_elements_page'] ) ? $_GET['to_elements_page'] : 1;
            if (isset($_POST['submit_modules_data_done']) || isset($_POST['submit_modules_data_no_save_done'])) {
                // if( defined('DOING_AJAX') && DOING_AJAX ) { cp_write_log('doing ajax'); }
                if (isset($_POST['submit_modules_data_done'])) {
                    //wp_redirect( cp_full_url( $_SERVER ). '?saved=ok' );
                    if ($_POST['event_origin'] == 'button') {
                        wp_redirect(get_permalink($course_id) . trailingslashit($coursepress->get_units_slug()) . '?saved=ok');
                        exit;
                    } else {
                        wp_redirect(cp_full_url($_SERVER)) . '?saved=ok';
                        exit;
                    }
                } else {
                    if ($_POST['event_origin'] == 'button') {
                        wp_redirect(trailingslashit(get_permalink($course_id)) . trailingslashit($coursepress->get_units_slug()));
                        exit;
                    } else {
                        wp_redirect(cp_full_url($_SERVER));
                        exit;
                    }
                    /* if ( $paged != 1 ) {
                    	  //wp_redirect( cp_full_url( $_SERVER ) );
                    	  wp_redirect(get_permalink($course_id) . trailingslashit($coursepress->get_units_slug()));
                    	  } else {
                    	  wp_redirect(cp_full_url($_SERVER));
                    	  } */
                }
                exit;
            }
            if (isset($_POST['submit_modules_data_save']) || isset($_POST['submit_modules_data_no_save_save'])) {
                // if( defined('DOING_AJAX') && DOING_AJAX ) { cp_write_log('doing ajax'); }
                if (isset($_POST['submit_modules_data_save'])) {
                    //wp_redirect( $_SERVER['REQUEST_URI'] . '?saved=ok' );
                    wp_redirect(cp_full_url($_SERVER) . '?saved=ok');
                    exit;
                    //exit;
                } else {
                    //wp_redirect( get_permalink( $unit_id ) . trailingslashit( 'page' ) . trailingslashit( $unit_module_page_number ) );
                }
            }
            if (isset($_POST['save_student_progress_indication'])) {
                wp_redirect(get_permalink($course_id) . trailingslashit($coursepress->get_units_slug()) . '?saved=progress_ok');
                exit;
            }
            ?>

			<form name="modules_form" id="modules_form" enctype="multipart/form-data" method="post" action="<?php 
            echo trailingslashit(get_permalink($unit_id));
            //strtok( $_SERVER["REQUEST_URI"], '?' );
            ?>
" onSubmit="return check_for_mandatory_answers();">
				<!--#submit_bottom-->
				<input type="hidden" id="go_to_page" value=""/>

				<?php 
            if ($unit_pagination) {
                foreach ($modules as $mod) {
                    $class_name = $mod->module_type;
                    if (class_exists($class_name)) {
                        call_user_func($class_name . '::front_main', $mod);
                        if (constant($class_name . '::FRONT_SAVE')) {
                            $front_save = true;
                            if (method_exists($class_name, 'get_response')) {
                                $response = call_user_func($class_name . '::get_response', get_current_user_id(), $mod->ID);
                                if (count($response) > 0) {
                                    $responses++;
                                }
                                $input_modules++;
                            }
                        }
                    }
                }
            } else {
                $pages_num = 1;
                foreach ($modules as $mod) {
                    $class_name = $mod->module_type;
                    if (class_exists($class_name)) {
                        if ($class_name == 'page_break_module') {
                            $pages_num++;
                        } else {
                            if ($pages_num == $paged) {
                                call_user_func($class_name . '::front_main', $mod);
                                if (constant($class_name . '::FRONT_SAVE')) {
                                    $front_save = true;
                                    if (method_exists($class_name, 'get_response')) {
                                        $response = call_user_func($class_name . '::get_response', get_current_user_id(), $mod->ID);
                                        if (count($response) > 0) {
                                            $responses++;
                                        }
                                        $input_modules++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            wp_nonce_field('modules_nonce');
            if ($unit_pagination) {
                $pages_num = coursepress_unit_pages($unit_id, $unit_pagination);
            }
            $is_last_page = coursepress_unit_module_pagination($unit_id, $pages_num, true);
            //check if current unit page is last page
            if (!$coursepress->is_preview($unit_id)) {
                if ($front_save) {
                    if ($input_modules !== $responses) {
                        ?>
							<div class="mandatory_message"><?php 
                        _e('All questions marked with "* Mandatory" require your input.', 'cp');
                        ?>
</div>
							<div class="clearf"></div>
							<input type="hidden" name="unit_id" value="<?php 
                        echo $unit_id;
                        ?>
"/>
							<a id="submit_bottom"></a>
							<?php 
                        if (isset($_POST['submit_modules_data'])) {
                            $form_message = __('The module data has been submitted successfully.', 'coursepress');
                        }
                        if (isset($form_message)) {
                            ?>
<p class="form-info-regular"><?php 
                            echo $form_message;
                            ?>
</p>
							<?php 
                        }
                        ?>


							<input type="submit" class="apply-button-enrolled submit-elements-data-button" name="submit_modules_data_<?php 
                        echo $is_last_page ? 'done' : 'save';
                        ?>
" value="<?php 
                        echo $is_last_page ? __('Done', 'cp') : __('Next', 'cp');
                        ?>
">
							<?php 
                    } else {
                        ?>
							<input type="submit" class="apply-button-enrolled submit-elements-data-button" name="submit_modules_data_no_save_<?php 
                        echo $is_last_page ? 'done' : 'save';
                        ?>
" value="<?php 
                        echo $is_last_page ? __('Done', 'cp') : __('Next', 'cp');
                        ?>
">
							<?php 
                    }
                } else {
                    ?>
						<input type="submit" class="apply-button-enrolled submit-elements-data-button" name="submit_modules_data_no_save_<?php 
                    echo $is_last_page ? 'done' : 'save';
                    ?>
" value="<?php 
                    echo $is_last_page ? __('Done', 'cp') : __('Next', 'cp');
                    ?>
">
						<?php 
                }
            }
            coursepress_unit_module_pagination($unit_id, $pages_num);
            ?>
				<div class="fullbox"></div>
				<?php 
            if (!isset($_GET['try'])) {
                ?>
					<a href="" id="save_student_progress" class="save_progress"><?php 
                _e('Save Progress & Exit', 'cp');
                ?>
</a>
				<?php 
            }
            ?>
			</form>

			<?php 
        }
            _e('There are currently no units to display', 'cp');
            ?>
</label>
																					</li>
																				</ol>
																			<?php 
        } else {
            ?>
																				<ol>
																					<?php 
            // Cheking for inhertited "show" status and forces a save.
            $section_dirty = false;
            foreach ($units as $unit) {
                $unit_class = new Unit($unit->ID);
                $unit_pages = $unit_class->get_number_of_unit_pages();
                $unit_pagination = cp_unit_uses_new_pagination($unit->ID);
                if ($unit_pagination) {
                    $unit_pages = coursepress_unit_pages($unit->ID, $unit_pagination);
                } else {
                    $unit_pages = coursepress_unit_pages($unit->ID);
                }
                $modules = Unit_Module::get_modules($unit->ID);
                ?>

																						<li class="<?php 
                echo $unit->post_status == 'publish' ? 'enabled_unit' : 'disabled_unit';
                ?>
">

																							<label for="unit_<?php 
                echo $unit->ID;