Plugin Directory

Changeset 1538047


Ignore:
Timestamp:
11/22/2016 03:48:12 AM (9 years ago)
Author:
david273
Message:

version 0.22, improved contract management and bug fixes

Location:
dojo/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • dojo/trunk/dojo.php

    r1526448 r1538047  
    77Text Domain: dojo
    88License: GPLv2 or later
    9 Version: 0.21
     9Version: 0.22
    1010*/
    1111
  • dojo/trunk/extensions/class-dojo-extension-manager.php

    r1526323 r1538047  
    1717        $this->register_action_handlers( array (
    1818            array( 'plugins_loaded', 1, 0 ),
    19             array( 'upgrader_process_complete', 10, 2 ),
     19//          array( 'upgrader_process_complete', 10, 2 ),
    2020        ) );
    2121
     
    252252    }
    253253
     254    public function ajax_install_extension_cred() {
     255        if ( ! current_user_can( 'update_plugins' ) ) {
     256            return 'Access denied';
     257        }
     258
     259        if ( ! class_exists( 'WP_Upgrader' ) ) {
     260            require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     261        }
     262
     263        $extension = $_GET['dojo-install'];
     264
     265        $result = $this->install_extension( $extension );
     266        if ( 'process_success' == $result ) {
     267            wp_redirect( admin_url( 'admin.php?page=dojo-settings' ) );
     268            return;
     269        }
     270        return $result;
     271    }
     272
    254273    public function ajax_activate_extension() {
    255274        if ( ! current_user_can( 'activate_plugins' ) ) {
     
    274293        if ( ! current_user_can( 'update_plugins' ) ) {
    275294            return 'Access denied';
    276         }
    277 
    278         if ( ! class_exists( 'WP_Upgrader' ) ) {
    279             require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    280295        }
    281296
     
    338353
    339354    private function remove_folder( $path ) {
    340         $files = array_diff( scandir( $path ), array( '.', '..' ) );
    341         foreach ( $files as $file ) {
    342             ( is_dir( "$path/$file" ) ) ? $this->remove_folder( "$path/$file" ) : unlink( "$path/$file" );
    343         }
    344         return rmdir( $path );
     355        if ( file_exists( $path ) ) {
     356            $files = array_diff( scandir( $path ), array( '.', '..' ) );
     357            foreach ( $files as $file ) {
     358                ( is_dir( "$path/$file" ) ) ? $this->remove_folder( "$path/$file" ) : unlink( "$path/$file" );
     359            }
     360            return rmdir( $path );
     361        }
    345362    }
    346363
    347364    private function install_extension( $extension ) {
     365        if ( ! class_exists( 'WP_Upgrader' ) ) {
     366            require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     367        }
     368
    348369        $response = $this->call_dojosource( 'get_extension', array(
    349370            'extension'  => $extension,
     
    357378        $destination = Dojo_Loader::plugin_path() . '/dojo-' . $extension;
    358379        $this->remove_folder( $destination );
     380
     381
     382        // capture credential form output if necessary
     383        $form = '';
     384        $url = $this->ajax( 'install_extension_cred' ) . '&dojo-install=' . urlencode( $extension );
     385        ob_start();
     386        // set up credentials to access the file system
     387        if ( false === ( $creds = request_filesystem_credentials( $url, '', false, false, array() ) ) ) {
     388            // no credentials to be found, a credential form has been generated
     389            $form = ob_get_clean();
     390        }  elseif ( ! WP_Filesystem( $creds ) ) {
     391            // credentials did not check out, generate the form with errors
     392            request_filesystem_credentials( $url, '', true, false, array() );
     393            $form = ob_get_clean();
     394        } else {
     395            ob_get_clean();
     396        }
     397
     398        // if we need to prompt the user with a credential form for file access
     399        if ( '' != $form ) {
     400
     401            // append script to prevent form from submitting the outer settings form
     402            $form .= "
     403            <script>
     404                jQuery(function($) {
     405                    $('.request-filesystem-credentials-action-buttons .button').click(function(ev) {
     406                        ev.preventDefault();
     407                        $(this).closest('form').submit();
     408                    });
     409                });
     410            </script>";
     411            return $form;
     412        }
    359413
    360414        // use built-in upgrader
  • dojo/trunk/extensions/dojo-membership/class-dojo-membership.php

    r1526323 r1538047  
    405405    }
    406406
     407    public function ajax_change_student_contract( $is_logged_in ) {
     408        $this->require_admin();
     409
     410        if ( isset( $_POST['student'] ) && isset( $_POST['contract'] ) ) {
     411            // get student
     412            $student = $this->model()->get_student( $_POST['student'] );
     413            if ( null == $student ) {
     414                return 'Student not found';
     415            }
     416
     417            // get current membership for given student
     418            $membership = $this->model()->get_student_membership( $_POST['student'] );
     419            if ( null === $membership ) {
     420                return 'Student does not have an active membership';
     421            }
     422
     423            // validate contract we are switching to
     424            $contract = $this->model()->get_contract( $_POST['contract'] );
     425            if ( ! $this->is_valid_student_contract( $student, $membership, $contract ) ) {
     426                return 'Invalid contract for this student';
     427            }
     428
     429            // good to go, update the membership
     430            $this->model()->update_membership( $membership->ID, array(
     431                'contract_id' => $_POST['contract'],
     432            ) );
     433            return 'success';
     434        }
     435
     436        return 'Invalid request';
     437    }
     438
    407439    public function ajax_save_student( $is_logged_in ) {
    408440        if ( ! $is_logged_in ) {
     
    10931125                    $this->selected_student->contract = $this->model()->get_contract( $this->selected_student->contract_id );
    10941126                    $this->rank_types = $this->model()->get_rank_types();
     1127                    $this->contracts = $this->get_contracts();
    10951128                    foreach ( $this->rank_types as $index => $rank_type ) {
    10961129                        $ranks = $this->model()->get_ranks( $rank_type->ID );
     
    14951528
    14961529    /**
     1530     * Verify contract is active and student meets contract requirements.
     1531     * Also checks programs available from contract and if no programs exist with compatible age
     1532     * requirements then will consider the contract invalid for the student.
     1533     *
     1534     * @param $student Student record
     1535     * @param $current_membership record
     1536     * @param $contract record
     1537     *
     1538     * @return bool
     1539     */
     1540    public function is_valid_student_contract( $student, $current_membership, $contract ) {
     1541        if ( null === $contract ) {
     1542            return false;
     1543        }
     1544
     1545        if ( $current_membership->contract_id === $contract->ID ) {
     1546            return true;
     1547        }
     1548
     1549        // make sure contract is active
     1550        if ( ! $contract->is_active ) {
     1551            return false;
     1552        }
     1553
     1554        // check contract membership restrictions
     1555        if ( $this->is_status_past_submitted( $current_membership->status ) && $contract->new_memberships_only ) {
     1556            return false;
     1557        }
     1558        if ( ! $this->is_status_past_submitted( $current_membership->status ) && $contract->continuing_memberships_only ) {
     1559            return false;
     1560        }
     1561
     1562        // get contract programs
     1563        $programs = $this->model()->get_contract_programs( $contract->ID );
     1564
     1565        // check age limits of programs to see if student qualifies for at least one
     1566        $age = $this->dob_to_age( $student->dob );
     1567        $does_qualify = false;
     1568        foreach ( $programs as $program ) {
     1569            if ( null !== $program->min_age && 0 !== $program->min_age ) {
     1570                if ( $age < $program->min_age ) {
     1571                    continue;
     1572                }
     1573            }
     1574            if ( null != $program->max_age && 0 != $program->max_age ) {
     1575                if ( $age > $program->max_age ) {
     1576                    continue;
     1577                }
     1578            }
     1579            $does_qualify = true;
     1580            break;
     1581        }
     1582        if ( ! $does_qualify ) {
     1583            return false;
     1584        }
     1585
     1586        return true;
     1587    }
     1588
     1589    /**
    14971590     * Check if given status is active in the sense that the student may continue to participate
    14981591     *
     
    15361629            self::MEMBERSHIP_PENDING    != $status &&
    15371630            self::MEMBERSHIP_ENDED      != $status
     1631            ;
     1632    }
     1633
     1634    /**
     1635     * Check if status is past a submitted state, includes ended.
     1636     *
     1637     * @param $status
     1638     * @return bool
     1639     */
     1640    public function is_status_past_submitted( $status ) {
     1641        return
     1642            self::MEMBERSHIP_NA         != $status &&
     1643            self::MEMBERSHIP_PENDING    != $status &&
     1644            self::MEMBERSHIP_SUBMITTED  != $status
    15381645            ;
    15391646    }
     
    17521859    }
    17531860
     1861    /**
     1862     * Convert date of birth to age
     1863     *
     1864     * @param string $dob
     1865     * @return int
     1866     */
     1867    public function dob_to_age( $dob ) {
     1868        $dob  = strtotime( $dob );
     1869        $dob_month = (int) $this->date( 'n', $dob );
     1870        $dob_day   = (int) $this->date( 'j', $dob );
     1871        $dob_year  = (int) $this->date( 'Y', $dob );
     1872
     1873        $time = time();
     1874        $month = (int) $this->date( 'n', $time );
     1875        $day   = (int) $this->date( 'j', $time );
     1876        $year  = (int) $this->date( 'Y', $time );
     1877
     1878        $age = $year - $dob_year;
     1879        if ( $month < $dob_month || ( $month == $dob_month && $day < $dob_day) ) {
     1880            $age --;
     1881        }
     1882
     1883        return $age;
     1884    }
     1885
    17541886    public function get_charge_date( $day )
    17551887    {
  • dojo/trunk/extensions/dojo-membership/views/students-edit.php

    r1526323 r1538047  
    2424        <?php echo apply_filters( 'dojo_membership_admin_student_application', $this->render( 'admin-student-application' ), $student ) ?>
    2525    </div>
    26     <?php elseif (Dojo_Membership::MEMBERSHIP_DUE == $student->status || Dojo_Membership::MEMBERSHIP_CANCELED_DUE == $student->status ) : ?>
     26    <?php elseif ( $this->is_status_active( $student->status ) ) : ?>
    2727    <div class="dojo-block">
    28         <h2>Membership Alert</h2>
    29         <p>Membership: <strong><?php echo esc_html( $student->contract->title ) ?></strong></p>
    30         <?php echo apply_filters( 'dojo_membership_admin_student_due', $this->render( 'admin-student-due' ), $student ) ?>
     28        <?php echo apply_filters( 'dojo_membership_admin_student_contract', $this->render( 'admin-student-contract' ), $student ) ?>
    3129    </div>
    3230    <?php endif; ?>
  • dojo/trunk/extensions/dojo-membership/views/user-enroll.php

    r1526323 r1538047  
    3737                        <option value="">Please Select</option>
    3838                        <?php foreach ( $contracts as $contract ) : ?>
    39                         <option value="<?php echo esc_attr( $contract->ID ) ?>" <?php selected( $student->membership->contract_id, $contract->ID ) ?>><?php echo esc_html( $contract->title ) ?></option>
     39                            <?php if ( ! $this->is_valid_student_contract( $student, $student->membership, $contract ) ) { continue; } ?>
     40                            <option value="<?php echo esc_attr( $contract->ID ) ?>" <?php selected( $student->membership->contract_id, $contract->ID ) ?>><?php echo esc_html( $contract->title ) ?></option>
    4041                        <?php endforeach; ?>
    4142                    </select>
  • dojo/trunk/extensions/views/manage-extensions.php

    r1526443 r1538047  
    3030}
    3131
    32 
     32$install_extension = '';
     33if ( isset( $_GET['dojo-install'] ) ) {
     34    $install_extension = $_GET['dojo-install'];
     35}
    3336
    3437?>
     
    4649
    4750<?php foreach ( $installed_extensions as $extension_id => $extension ) : ?>
    48 <div class="dojo-extension-block" data-extension="<?php echo esc_attr( $extension_id ) ?>">
     51<div class="dojo-extension-block<?php echo $install_extension == $extension_id ? ' .dojo-do-update' : '' ?>" data-extension="<?php echo esc_attr( $extension_id ) ?>">
    4952    <div class="dojo-large-icon dojo-left">
    5053        <?php if ( isset( $info['icons'][ $extension_id ] ) ) : ?>
     
    118121
    119122<?php foreach ( $available_extensions as $extension_id => $extension_title ) : ?>
    120 <div class="dojo-extension-block" data-extension="<?php echo esc_attr( $extension_id ) ?>">
     123<div class="dojo-extension-block<?php echo $install_extension == $extension_id ? ' dojo-do-install' : '' ?>" data-extension="<?php echo esc_attr( $extension_id ) ?>">
    121124    <div class="dojo-large-icon dojo-left">
    122125        <span class="dashicons dashicons-<?php echo $info['icons'][ $extension_id ] ?>"></span>
     
    189192        }
    190193    });
     194
     195    $('.dojo-do-install .dojo-install').click();
     196    $('.dojo-do-update .dojo-update').click();
    191197});
    192198</script>
     199
  • dojo/trunk/readme.txt

    r1527102 r1538047  
    55Requires at least: 4.0
    66Tested up to: 4.6.1
    7 Stable tag: 0.21
     7Stable tag: 0.22
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7272= Why am I not seeing the member page at /members? =
    7373
    74 Make sure your permalinks settings at Settings -> Permalinks are not set to, "Plain".
     74Make sure your permalinks settings at Settings -> Permalinks are **NOT** set to, "Plain".
    7575
    7676= How do I get the free Invoices add-on from Dojo Source? =
     
    9090== Changelog ==
    9191
     92= 0.22 =
     93* Added option to change existing contract for a student.
     94* No longer displaying contract options for students that are not applicable to that student.
     95* Fixed issues with downloading add-ons.
     96
    9297= 0.21 =
    93 * Fixed issue with nonces messing up add-on loading
     98* Fixed special cases where nonces in ajax calls were causing it to break.
    9499
    95100= 0.20 =
Note: See TracChangeset for help on using the changeset viewer.