function mz_mindbody_section_text()
{
    require_once MZ_MINDBODY_SCHEDULE_DIR . '/lib/functions.php';
    $globals = new Global_Strings();
    $global_strings = $globals->translate_them();
    $password = $global_strings['password'];
    $login_url = $global_strings['login_url'];
    $logout_url = $global_strings['logout_url'];
    $create_account_url = $global_strings['create_account_url'];
    ?>
		<div style="max-width:60%">
		<p><?php 
    _e('Enter your mindbody credentials below.', 'mz-mindbody-api');
    ?>
</p>
		<p><?php 
    printf(__('If you do not have them yet, visit the %1$s MindBodyOnline developers website %2$s 
		and register for developer credentials.', 'mz-mindbody-api'), '<a href="https://api.mindbodyonline.com/Home/LogIn">', '</a>');
    ?>
		(<a href="http://www.mzoo.org/creating-your-mindbody-credentials/"><?php 
    _e('Detailed instructions here', 'mz-mindbody-api');
    ?>
</a>.)</p>
		<h3>Shortcodes</h3>
		<p>
		<?php 
    _e('Add to page or post with shortcode:', 'mz-mindbody-api');
    echo '&nbsp;';
    printf('[%1$s], [%2$s], [%3$s], [%4$s %5$s=%6$s %7$s=1 %8$s=-99]', 'mz_mindbody_show_schedule', 'mz_mindbody_show_events', 'mz_mindbody_staff_list', 'mz_mindbody_show_schedule', 'type', 'day', 'location', 'account');
    echo '<br/>(' . __('-99 is the MBO sandbox/testing account', 'mz-mindbody-api') . ')</font></p>';
    echo '<p>';
    echo __('Grid and Filter can be added like this:', 'mz-mindbody-api') . '<br/>';
    printf('[%1$s %2$s=1 %3$s=1]<br/>', 'mz-mindbody-show-schedule', 'grid', 'filter');
    echo '</p>';
    echo '<p>' . __('To remove hide any of the following elements from grid calendar:', 'mz-mindbody-api') . '&nbsp; hide="teacher, signup, duration"';
    ?>
		
		<p><?php 
    _e('Additional shortcodes:', 'mz-mindbody-api');
    echo '&nbsp;[mz-mindbody-signup], [mz-mindbody-login], [mz-mindbody-logout]';
    ?>
</p>

		<p><?php 
    _e('In order for these to work correctly, the permalinks for those pages need to be:', 'mz-mindbody-api');
    echo '&nbsp;<em>create-account</em>, <em>login</em> and <em>logout</em>.';
    ?>

		</div>
	<?php 
}
 public function mZ_mindbody_show_events($atts, $account = 0)
 {
     add_action('wp_loaded', function () {
         require_once MZ_MINDBODY_SCHEDULE_DIR . 'inc/mz_mbo_init.inc';
         $mz_mbo = new MZ_MBO_Init();
     });
     //global $add_mz_ajax_script;
     //$add_mz_ajax_script = true;
     // optionally pass in a type parameter. Defaults to week.
     $atts = shortcode_atts(array('location' => '1', 'account' => '0'), $atts);
     $location = $atts['location'];
     $account = $atts['account'];
     $options = get_option('mz_mindbody_options');
     // grab session type IDs for events
     $mz_sessions = array($options['mz_mindbody_eventID']);
     $return = '';
     $mz_date = empty($_GET['mz_date']) ? date_i18n('Y-m-d') : mz_validate_date($_GET['mz_date']);
     // only make API call if we have sessions set
     if (!empty($mz_sessions) && $mz_sessions[0] != 0) {
         $mz_timeframe = array_slice(mz_getDateRange($mz_date, $mz_event_calendar_duration), 0, 1);
         //While we still need to support php 5.2 and can't use [0] on above
         $mz_timeframe = array_pop($mz_timeframe);
         $mz_timeframe = array_merge($mz_timeframe, array('SessionTypeIDs' => $mz_sessions));
         // START caching configuration
         $mz_events_cache = "mz_events_cache";
         $mz_cache_reset = isset($options['mz_mindbody_clear_cache']) ? "on" : "off";
         if ($mz_cache_reset == "on") {
             delete_transient($mz_events_cache);
         }
         $mz_event_data = get_transient($mz_events_cache);
         if (false === $mz_event_data) {
             $mb = instantiate_mbo_API();
             if ($account == 0) {
                 $mz_schedule_data = $mb->GetClasses($mz_timeframe);
             } else {
                 $mb->sourceCredentials['SiteIDs'][0] = $account;
                 $mz_schedule_data = $mb->GetClasses($mz_timeframe);
             }
             $mz_event_data = $mb->GetClasses($mz_timeframe);
         }
         //Cache the mindbody call for 1 hour
         // TODO make cache timeout configurable.
         set_transient($mz_events_cache, $mz_event_data, 60 * 60);
         // END caching configuration
         // keep this here
         //$return .= $mb->debug();
         if (!empty($mz_event_data['GetClassesResult']['Classes']['Class'])) {
             $classes = $this->makeNumericArray($mz_event_data['GetClassesResult']['Classes']['Class']);
             $classes = sortClassesByDate($classes, $time_format);
             $number_of_events = count($classes);
             $return .= '<p>' . $mz_event_calendar_duration . ' ' . __('Day Event Calendar');
             $return .= ' ' . date_i18n($date_format, strtotime($mz_timeframe['StartDateTime']));
             $return .= ' - ';
             $return .= date_i18n($date_format, strtotime($mz_timeframe['EndDateTime'])) . '</p>';
             if ($number_of_events >= 1) {
                 //TODO Make this work - displaying number 20 with one event (correct on first page with 5 events).
                 //$return .= ': ' . $number_of_events . ' '.__('event(s)').'</p>';
                 $return .= mz_mbo_schedule_nav($mz_date, "Events", $mz_event_calendar_duration);
                 $return .= '<div class="mz_mindbody_events">';
                 $return .= '<table class="table mz_mindbody_events">';
                 $globals = new Global_Strings();
                 $global_strings = $globals->translate_them();
                 foreach ($classes as $classDate => $classes) {
                     foreach ($classes as $class) {
                         if (!($class['IsCanceled'] == 'TRUE' && $class['HideCancel'] == 'TRUE')) {
                             $sDate = date_i18n('m/d/Y', strtotime($class['StartDateTime']));
                             $sLoc = $class['Location']['ID'];
                             $studioid = $class['Location']['SiteID'];
                             $sclassid = $class['ID'];
                             // why is this hardcoded?
                             $sType = -7;
                             $isAvailable = $class['IsAvailable'];
                             if (empty($class['ClassDescription']['ImageURL'])) {
                                 $image = '';
                             } else {
                                 $image = '<img class="mz_mindbody_events_img" src="' . $class['ClassDescription']['ImageURL'] . '">';
                             }
                             $sTG = $class['ClassDescription']['Program']['ID'];
                             $eventLinkURL = "https://clients.mindbodyonline.com/ws.asp?sDate={$sDate}&amp;sLoc={$sLoc}&amp;sTG={$sTG}&amp;sType={$sType}&amp;sclassid={$sclassid}&amp;studioid={$studioid}";
                             $className = $class['ClassDescription']['Name'];
                             $startDateTime = date_i18n($date_format . ' ' . $time_format, strtotime($class['StartDateTime']));
                             $classDescription = $class['ClassDescription']['Description'];
                             $endDateTime = date_i18n($date_format . ' ' . $time_format, strtotime($class['EndDateTime']));
                             $staffName = $class['Staff']['Name'];
                             $ItemType = $class['ClassDescription']['Program']['Name'];
                             $enrolmentType = $class['ClassDescription']['Program']['ScheduleType'];
                             $day_and_date = date_i18n("D F d", strtotime($classDate));
                             $return .= '<tr class="mz_description_holder"><td>';
                             $return .= "<h3>{$className}</h3>";
                             $clientID = isset($_SESSION['GUID']) ? $_SESSION['client']['ID'] : '';
                             $add_to_class_nonce = wp_create_nonce('mz_MBO_add_to_class_nonce');
                             if ($clientID == '') {
                                 $return .= $isAvailable ? '<br/><a class="btn mz_add_to_class" href="' . home_url() . '/login">' . __('Login to Sign-up', 'mz-mindbody-api') . '</a>' : '';
                             } else {
                                 $return .= $isAvailable ? '<br/><a id="mz_add_to_class" class="btn mz_add_to_class"' . ' data-nonce="' . $add_to_class_nonce . '" data-classID="' . $sclassid . '" data-clientID="' . $clientID . '">' . '<span class="signup">' . $global_strings['sign_up'] . '</span><span class="count" style="display:none">0</span></a>' : '';
                             }
                             $return .= '<br/><div id="visitMBO" class="btn visitMBO" style="display:none">';
                             $return .= '<a href="' . $eventLinkURL . '" target="_blank">Manage on MindBody Site</a></div>';
                             $return .= '<p class="mz_event_staff_name">' . $global_strings['with'] . $staffName . '</p>';
                             $return .= '<h4 class="mz_event_staff">' . $day_and_date . ', ' . date_i18n('g:i a', strtotime($startDateTime)) . ' - ';
                             $return .= date_i18n('g:i a', strtotime($endDateTime)) . '</h4>';
                             $return .= '<div class="mz_mindbody_event_description">';
                             $return .= $image;
                             $return .= "<p>{$classDescription}</p>";
                             $return .= "</div>";
                             $return .= '</td></tr>';
                         }
                     }
                 }
                 $return .= '</table></div>';
             } else {
                 $return .= '<h3>' . __('No events published this period.', 'mz-mindbody-api') . '</h3>';
             }
         } else {
             if (!empty($mz_event_data['GetClassesResult']['Message'])) {
                 $return .= $mz_event_data['GetClassesResult']['Message'];
             } else {
                 $return .= '<p>' . sprintf(_n('%1$s Day Event Calendar', '%1$s Day Event Calendar', 'mz-mindbody-api'), $mz_event_calendar_duration);
                 $return .= ' ' . date_i18n($mz_date_display, strtotime($mz_timeframe['StartDateTime']));
                 $return .= ' - ';
                 $return .= date_i18n($mz_date_display, strtotime($mz_timeframe['EndDateTime']));
                 $return .= '<h3>' . __('No events published', 'mz-mindbody-api') . '. </h3>';
                 //$return .= '<pre>'.print_r($mz_event_data,1).'</pre>';
             }
         }
         //EOF If Results/Else
     } else {
         $return .= '<h2>' . __('Error: MBO Event Type IDs must be set in Admin Panel', 'mz-mindbody-api') . '</h2>';
     }
     $return .= mz_mbo_schedule_nav($mz_date, _n("Event", "Events", 'mz-mindbody-api'), $mz_event_calendar_duration);
     return $return;
 }
    public function mZ_mindbody_signup()
    {
        require_once MZ_MINDBODY_SCHEDULE_DIR . 'inc/mz_mbo_init.inc';
        if (!empty($_POST['website_url'])) {
            echo '<h1>' . __('Die Robot Spam!', 'mz-mindbody-api') . '</h1>';
            die;
        }
        if (!empty($_POST['data']['Client'])) {
            //mz_pr($_POST['data']['Client']['MobilePhone']);
            if (isset($_POST['data']['Client']['BirthDate'])) {
                $_POST['data']['Client']['BirthDate'] = date('c', strtotime($_POST['data']['Client']['BirthDate']));
            }
            $options = array('Clients' => array('Client' => $_POST['data']['Client']));
            $signupData = $mb->AddOrUpdateClients($options);
            if ($signupData['AddOrUpdateClientsResult']['Clients']['Client']['Action'] == 'Added') {
                $validateLogin = $mb->ValidateLogin(array('Username' => $_POST['data']['Client']['Username'], 'Password' => $_POST['data']['Client']['Password']));
                if (!empty($validateLogin['ValidateLoginResult']['GUID'])) {
                    $_SESSION['GUID'] = $validateLogin['ValidateLoginResult']['GUID'];
                    $_SESSION['client'] = $validateLogin['ValidateLoginResult']['Client'];
                }
                echo '<h3>' . __('Congratulations. You are now logged in with your new Mindbody account.', 'mz-mindbody-api') . '</h3>';
                echo '<h2>' . __('Sign-up for some classes.', 'mz-mindbody-api') . '</h2>';
                //header('location:index.php');
            }
        }
        $requiredFields = $mb->GetRequiredClientFields();
        if (!empty($requiredFields['GetRequiredClientFieldsResult']['RequiredClientFields']['string'])) {
            $requiredFields = $this->makeNumericArray($requiredFields['GetRequiredClientFieldsResult']['RequiredClientFields']['string']);
        } else {
            $requiredFields = false;
        }
        $requiredFieldsInputs = '';
        if (!empty($requiredFields)) {
            // Force single element $requiredFields into array form
            if (!is_array($requiredFields)) {
                $requiredFields = array($requiredFields);
            }
            foreach ($requiredFields as $field) {
                $requiredFieldsInputs .= "<label for='{$field}'>{$field} </label><input type='text' name='data[Client][{$field}]' id='{$field}' placeholder='{$field}' required /><br />";
            }
        }
        if (!empty($signupData['AddOrUpdateClientsResult']['Clients']['Client']['Action']) && $signupData['AddOrUpdateClientsResult']['Clients']['Client']['Action'] == 'Failed' && !empty($signupData['AddOrUpdateClientsResult']['Clients']['Client']['Messages'])) {
            foreach ($signupData['AddOrUpdateClientsResult']['Clients']['Client']['Messages'] as $message) {
                echo "<pre>" . print_r($message, 1) . '</pre><br />';
            }
        }
        $globals = new Global_Strings();
        $global_strings = $globals->translate_them();
        $password = $global_strings['password'];
        $username = $global_strings['username'];
        $antispam = __('Leave this empty-slash-blank', 'mz-mindbody-api');
        $firstname = __('First Name', 'mz-mindbody-api');
        $lastname = __('Last Name', 'mz-mindbody-api');
        $sign_up = __('Sign up', 'mz-mindbody-api');
        return <<<EOD
\t<form  class="mz_mbo_signup" method="POST">
\t\t<p class="website_url" style="display:none">{$antispam}<input type="text" name="website_url" /></p>
\t\t<label for="Username"> {$username}</label><input type="text" name="data[Client][Username]" id="Username" placeholder="{$username}" required /><br />
\t\t<br/><label for="Password"> {$password}</label><input type="password" name="data[Client][Password]" id="Password" placeholder="{$password}" required /><br />
\t\t<br/><label for="FirstName"> {$firstname}</label><input type="text" name="data[Client][FirstName]" id="FirstName" placeholder="{$firstname}" required /><br />
\t\t<br/><label for="LastName"> {$lastname}</label><input type="text" name="data[Client][LastName]" id="LastName" placeholder="{$lastname}" required /><br />
\t\t{$requiredFieldsInputs}
\t\t<button type="submit">{$sign_up}</button>
\t</form>
EOD;
    }