/**
  * screen_handler( $action_vars )
  *
  * Assignment screens handler.
  * Handles uris like groups/ID/courseware/assignments/args
  */
 function screen_handler($action_vars)
 {
     if (reset($action_vars) == 'new_assignment') {
         $this->current_course = BPSP_Courses::is_course();
         //Load editor
         add_action('bp_head', array(&$this, 'load_editor'));
         do_action('courseware_list_assignments_screen');
         do_action('courseware_new_assignment_screen');
         add_filter('courseware_group_template', array(&$this, 'new_assignment_screen'));
     } elseif (reset($action_vars) == 'assignment') {
         $current_assignment = BPSP_Assignments::is_assignment($action_vars[1]);
         if (isset($action_vars[1]) && null != $current_assignment) {
             $this->current_assignment = $current_assignment;
         } else {
             wp_redirect(wp_redirect(get_option('siteurl')));
         }
         if (isset($action_vars[2]) && 'edit' == $action_vars[2]) {
             // Try to serve the form data
             if (isset($_GET['get_form_data'])) {
                 $this->get_form_data();
             }
             add_action('bp_head', array(&$this, 'load_editor'));
             do_action('courseware_edit_assignment_screen');
             add_filter('courseware_group_template', array(&$this, 'edit_assignment_screen'));
         } elseif (isset($action_vars[2]) && 'delete' == $action_vars[2]) {
             add_filter('courseware_group_template', array(&$this, 'delete_assignment_screen'));
         } elseif (isset($action_vars[2]) && 'enable_forum' == $action_vars[2]) {
             do_action('courseware_bibliography_screen');
             add_filter('courseware_group_template', array(&$this, 'enable_forum_assignment_screen'));
         } else {
             do_action('courseware_bibliography_screen');
             do_action('courseware_assignment_screen');
             add_filter('courseware_group_template', array(&$this, 'single_assignment_screen'));
         }
         do_action('courseware_assignment_screen_handler', $action_vars);
     } elseif (reset($action_vars) == 'assignments') {
         do_action('courseware_list_assignments_screen');
         add_filter('courseware_group_template', array(&$this, 'list_assignments_screen'));
     }
 }
 /**
  * screen_handler( $action_vars )
  *
  * Response screens handler.
  * Handles uris like groups/ID/courseware/response/args
  */
 function screen_handler($action_vars)
 {
     $this->current_assignment = BPSP_Assignments::is_assignment($action_vars[1]);
     // Check if we got a valid parent assignment
     if (!$this->current_assignment) {
         wp_redirect(wp_redirect(get_option('siteurl')));
     }
     if ($action_vars[2] == 'add_response') {
         //Load editor
         add_action('bp_head', array(&$this, 'load_editor'));
         add_filter('courseware_group_template', array(&$this, 'new_response_screen'));
     } elseif ($action_vars[2] == 'response') {
         $current_response = $this->is_response($action_vars[3]);
         if (isset($action_vars[3]) && !empty($current_response)) {
             $this->current_response = $current_response;
         } else {
             wp_redirect(wp_redirect(get_option('siteurl')));
         }
         if (isset($action_vars[4]) && 'delete' == $action_vars[4]) {
             add_filter('courseware_group_template', array(&$this, 'delete_response_screen'));
         } else {
             add_filter('courseware_group_template', array(&$this, 'single_response_screen'));
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * gradebook_screen( $vars )
  *
  * Hooks into screen_handler
  * Adds a UI to assignments for gradebook management.
  *
  * @param Array $vars a set of variables received for this screen template
  * @return Array $vars a set of variable passed to this screen template
  */
 function gradebook_screen($vars)
 {
     global $bp;
     $nonce_name = 'gradebook_nonce';
     $nonce_import_name = 'gradebook_import_nonce';
     $nonce_clear_name = 'gradebook_clear_nonce';
     if (!$this->has_gradebook_caps($bp->loggedin_user->id) && !is_super_admin()) {
         $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to manage gradebook.', 'bpsp');
         return $vars;
     }
     $students = BP_Groups_Member::get_all_for_group($bp->groups->current_group->id);
     if (isset($_POST['_nxtnonce'])) {
         $is_nonce = nxt_verify_nonce($_POST['_nxtnonce'], $nonce_name);
     }
     if (isset($_POST['_nxtnonce']) && true != $is_nonce) {
         $vars['die'] = __('BuddyPress Courseware Nonce Error while updating gradebook.', 'bpsp');
         return $vars;
     }
     $gradebook_id = $this->has_gradebook($this->current_assignment);
     if (!$gradebook_id) {
         $vars['die'] = __('BuddyPress Courseware Error while creating gradebook.', 'bpsp');
         return $vars;
     }
     if (!empty($_POST['grade'])) {
         foreach ($_POST['grade'] as $grade) {
             if (!empty($grade) && !empty($grade['uid']) && !empty($grade['value'])) {
                 # If grade was added or updated!
                 $status = $this->save_grade($gradebook_id, $grade);
                 if ($status !== null) {
                     $data = array('grade' => $grade, 'teacher' => $bp->loggedin_user->userdata, 'assignment' => $this->current_assignment);
                     if ($status == true) {
                         do_action('courseware_grade_added', $data);
                     } else {
                         do_action('courseware_grade_updated', $data);
                     }
                 }
             }
         }
         $vars['message'] = __('Gradebook saved.', 'bpsp');
     }
     $vars['name'] = 'gradebook';
     $vars['students'] = $students['members'];
     if (empty($vars['grades'])) {
         $vars['grades'] = $this->load_grades($gradebook_id, true);
     }
     $vars['bpsp_gradebook_format'] = get_option('bpsp_gradebook_format');
     $vars['assignment'] = BPSP_Assignments::is_assignment($this->current_assignment);
     $vars['gradebook_permalink'] = $vars['assignment_permalink'] . '/gradebook';
     $vars['clear_gradebook_permalink'] = add_query_arg('_nxtnonce', nxt_create_nonce($nonce_clear_name), $vars['gradebook_permalink'] . '/clear');
     $vars['import_gradebook_nonce'] = nxt_nonce_field($nonce_import_name, '_nxtnonce', true, false);
     $vars['nonce'] = nxt_nonce_field($nonce_name, '_nxtnonce', true, false);
     return $vars;
 }
Ejemplo n.º 4
0
 /**
  * edit_bib_screen( $vars )
  *
  * Handles screen for editing the bibliographies
  * @param Array $vars, an array of variables
  * @return Array $vars modified
  */
 function edit_bib_screen($vars)
 {
     $nonce_name = 'edit_bib';
     $nonce_delete_name = 'delete_bib';
     $nonce_edit_name = $nonce_name;
     if (!$this->has_bib_caps($bp->loggedin_user->id) && !is_super_admin()) {
         $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to edit bibliography.', 'bpsp');
         return $vars;
     }
     if (isset($_POST['_nxtnonce']) && isset($_GET['bhash'])) {
         if (!nxt_verify_nonce($_POST['_nxtnonce'], $nonce_name)) {
             $vars['die'] = __('BuddyPress Courseware Nonce Error while editing bibliography.', 'bpsp');
             return $vars;
         }
     }
     $data = explode(',', sanitize_text_field($_GET['bhash']));
     $bhash = $data[0];
     $new_bhash = null;
     $post_id = null;
     if (isset($data[1]) && !empty($data[1])) {
         $post_id = $data[1];
         // Get the permalink for parent
         if (BPSP_Assignments::is_assignment($post_id)) {
             $vars['back_uri'] = $vars['nav_options'][__('Home', 'bpsp')] . '/assignment/' . $post_id;
         }
         if (BPSP_Courses::is_course($post_id)) {
             $vars['back_uri'] = $vars['nav_options'][__('Home', 'bpsp')] . '/course/' . $post_id;
         }
     } else {
         $bibdb_def = array('post_title' => 'BIBSDB', 'post_status' => 'draft', 'post_type' => 'bib');
         $bibdb_post = get_posts($bibdb_def);
         $post_id = $bibdb_post[0]->ID;
     }
     if ($post_id) {
         $old_bib = $this->get_bib($bhash, $post_id);
         if ($old_bib != null && isset($_POST['bib'])) {
             $new_bhash = $this->update_bib($_POST['bib'], true, $post_id, $old_bib);
             if (null != $new_bhash) {
                 $bhash = $new_bhash;
                 // Update for the next query
                 $vars['message'] = __('Entry updated.', 'bpsp');
             } else {
                 $vars['error'] = __('Entry could not be updated. Or nothing changed.', 'bpsp');
             }
         } elseif (!$old_bib && isset($_POST['bib'])) {
             $vars['error'] = __('Entry could not be found.', 'bpsp');
         }
     } else {
         $vars['error'] = __('No Bibliography database was created.', 'bpsp');
     }
     $vars['name'] = 'edit_bibliography';
     $vars['bib'] = shortcode_parse_atts($this->get_bib($bhash, $post_id));
     $vars['has_bibs'] = true;
     $vars['post_id'] = null;
     $vars['has_bib_caps'] = $this->has_bib_caps($bp->loggedin_user->id);
     $vars['bibs'] = $this->load_bibs(true);
     $vars['bibs_delete_permalink'] = $vars['current_uri'] . '/delete_bibliography';
     $vars['bibs_delete_uri'] = add_query_arg('_nxtnonce', nxt_create_nonce($nonce_delete_name), $vars['bibs_delete_permalink']);
     $vars['bibs_edit_uri'] = $vars['current_uri'] . '/edit_bibliography';
     $vars['bibs_form_uri'] = add_query_arg('bhash', $bhash . ',' . $post_id, $vars['bibs_edit_uri']);
     $vars['bibs_nonce'] = nxt_nonce_field($nonce_name, '_nxtnonce', true, false);
     $vars['trail'] = array(__('Editing Bibliography: ', 'bpsp') . $vars['bib']['title'] => '');
     return $vars;
 }