public/wordpress/wp-content/plugins/wishlist-member-addon-for-wp-courseware/class_members.inc.php
/**
		 * Show the form for editing the specific courses a user can access based on what level that they have access to.
		 * @param PageBuilder $page The page rendering object.
		 * @param Array $levelDetails The list of level details
		 */
Show the form for editing the specific courses a user can access based on what level that they have access to.
@param PageBuilder $page The page rendering object.
@param Array $levelDetails The list of level details
Show the form for editing the specific courses a user can access based on what level that they have access to . @param PageBuilder $page The page rendering object . @param Array $levelDetails The list of level details
private function showMembershipMappingLevels_specificLevel($page, $levelDetails)
		{
			printf('<div id="wpcw_member_level_name_title">%s</div>', 
				sprintf(__('Editing permissions for <b>%s</b> level with <b>%s</b>:', 'wp_courseware'), $levelDetails['name'], $this->extensionName)
			);
			$courses = WPCW_courses_getCourseList(false);
			$courseListInDB = $this->getCourseAccessListForLevel($levelDetails['id']);
			$summaryURL = admin_url('admin.php?page=' . $this->extensionID);			
			$form = new FormBuilder('wpcw_member_levels_edit');
			$form->setSubmitLabel(__('Save Changes', 'wp_courseware'));
			$elem = new FormElement('level_courses', __('Courses user can access with this level', 'wp_courseware'), false);
			$elem->setTypeAsCheckboxList($courses);
			$elem->checkboxListCols = 2;
			$form->addFormElement($elem);
			$elem = new FormElement('retroactive_assignment', __('Do you want to retroactively assign these courses to current customers?', 'wp_courseware'), true);
			$elem->setTypeAsRadioButtons(array(
		'Yes'				=> __('Yes', 'wp_courseware'),
		'No'				=> __('No', 'wp_courseware'),	
		));
			$form->addFormElement($elem);
			$form->setDefaultValues(array(
			'retroactive_assignment' => 'No'
			));
			if ($form->formSubmitted())
			{
				if ($form->formValid())
				{
					$mapplingList = $form->getValue('level_courses');
					global $wpdb, $wpcwdb;
					$wpdb->show_errors();
					$wpdb->query($wpdb->prepare("
						DELETE 
						FROM $wpcwdb->map_member_levels 
						WHERE member_level_id = %s
					", $levelDetails['id']));
					if ($mapplingList && count($mapplingList) > 0)
					{
						foreach ($mapplingList as $courseID => $itemState)
						{
							$wpdb->query($wpdb->prepare("
								INSERT INTO $wpcwdb->map_member_levels 
								(course_id, member_level_id)  
								VALUES (%d, %s)
							", $courseID, $levelDetails['id']));
						}
					}
					$retroactive_assignment = $form->getValue('retroactive_assignment');	
					if ($retroactive_assignment == 'Yes' && count($mapplingList) >= 0){
						$level_ID = $levelDetails['id'];
						$this->retroactive_assignment($level_ID);
					}					
					$page->showMessage(
						__('Level and course permissions successfully updated.', 'wp_courseware') . '<br/><br/>' .
						sprintf(__('Want to return to the <a href="%s">Course Access Settings summary</a>?', 'wp_courseware'), $summaryURL) 
					);
				} 
			} 
			else {
				$form->setDefaultValues(array('level_courses' => $courseListInDB));
			}
			echo $form->toString();
			printf('<a href="%s" class="button-secondary">%s</a>', $summaryURL, __('&laquo; Return to Course Access Settings summary', 'wp_courseware'));
		}
private function showMembershipMappingLevels_specificLevel ( $ page , $ levelDetails ) { printf ( '<div id="wpcw_member_level_name_title">%s</div>' , sprintf ( __ ( 'Editing permissions for <b>%s</b> level with <b>%s</b>:' , 'wp_courseware' ) , $ levelDetails [ 'name' ] , $ this -> extensionName ) ) ; $ courses = WPCW_courses_getCourseList ( false ) ; $ courseListInDB = $ this -> getCourseAccessListForLevel ( $ levelDetails [ 'id' ] ) ; $ summaryURL = admin_url ( 'admin.php?page=' . $ this -> extensionID ) ; $ form = new FormBuilder ( 'wpcw_member_levels_edit' ) ; $ form -> setSubmitLabel ( __ ( 'Save Changes' , 'wp_courseware' ) ) ; $ elem = new FormElement ( 'level_courses' , __ ( 'Courses user can access with this level' , 'wp_courseware' ) , false ) ; $ elem -> setTypeAsCheckboxList ( $ courses ) ; $ elem -> checkboxListCols = 2 ; $ form -> addFormElement ( $ elem ) ; $ elem = new FormElement ( 'retroactive_assignment' , __ ( 'Do you want to retroactively assign these courses to current customers?' , 'wp_courseware' ) , true ) ; $ elem -> setTypeAsRadioButtons ( array ( 'Yes' => __ ( 'Yes' , 'wp_courseware' ) , 'No' => __ ( 'No' , 'wp_courseware' ) , ) ) ; $ form -> addFormElement ( $ elem ) ; $ form -> setDefaultValues ( array ( 'retroactive_assignment' => 'No' ) ) ; if ( $ form -> formSubmitted ( ) ) { if ( $ form -> formValid ( ) ) { $ mapplingList = $ form -> getValue ( 'level_courses' ) ; global $ wpdb , $ wpcwdb ; $ wpdb -> show_errors ( ) ; $ wpdb -> query ( $ wpdb -> prepare ( " 
						DELETE 
						FROM  $ wpcwdb -> map_member_levels  
						WHERE member_level_id = %s
					 " , $ levelDetails [ 'id' ] ) ) ; if ( $ mapplingList && count ( $ mapplingList ) > 0 ) { foreach ( $ mapplingList as $ courseID => $ itemState ) { $ wpdb -> query ( $ wpdb -> prepare ( " 
								INSERT INTO  $ wpcwdb -> map_member_levels  
								(course_id, member_level_id)  
								VALUES (%d, %s)
							 " , $ courseID , $ levelDetails [ 'id' ] ) ) ; } } $ retroactive_assignment = $ form -> getValue ( 'retroactive_assignment' ) ; if ( $ retroactive_assignment == 'Yes' && count ( $ mapplingList ) >= 0 ) { $ level_ID = $ levelDetails [ 'id' ] ; $ this -> retroactive_assignment ( $ level_ID ) ; } $ page -> showMessage ( __ ( 'Level and course permissions successfully updated.' , 'wp_courseware' ) . '<br/><br/>' . sprintf ( __ ( 'Want to return to the <a href="%s">Course Access Settings summary</a>?' , 'wp_courseware' ) , $ summaryURL ) ) ; } } else { $ form -> setDefaultValues ( array ( 'level_courses' => $ courseListInDB ) ) ; } echo $ form -> toString ( ) ; printf ( '<a href="%s" class="button-secondary">%s</a>' , $ summaryURL , __ ( '&laquo; Return to Course Access Settings summary' , 'wp_courseware' ) ) ; }
Show the form for editing the specific courses a user can access based on what level that they have access to.
Show the form for editing the specific courses a user can access based on what level that they have access to .
// Show a nice summary of what level is being edited. // Get a list of course IDs that exist // Get list of courses already associated with level. // Create the summary URL to return // Update form... // Create list of courses using checkboxes (max of 2 columns) // Create retroactive option // Normally would check for errors too, but there's not a lot to check here. // Remove all previous level mappings (as some will have been removed) // Add all of the new mappings the user has chosen. // Get retroactive selection // Call the retroactive assignment function passing the member level ID  //$page->showMessage(__('All members were successfully retroactively enrolled into the selected courses.', 'wp_courseware')); // Show a success message. // if ($form->formValid()) // if ($form->formSubmitted() // Show the defaults that already exist in the database. // Show the form