示例#1
0
function event_espresso_form_builder_edit()
{
    global $wpdb;
    $question_id = $_REQUEST['question_id'];
    $questions = espresso_get_user_questions(null, $question_id);
    if (count($questions) > 0) {
        foreach ($questions as $question) {
            $question_id = $question->id;
            $question_name = stripslashes($question->question);
            $question_values = stripslashes($question->response);
            $question_type = stripslashes($question->question_type);
            $required = stripslashes($question->required);
            $sequence = $question->sequence;
            $required_text = $question->required_text;
            $admin_only = $question->admin_only;
            $system_name = $question->system_name;
            if ($question->system_name != '') {
                $system_question = true;
            } else {
                $system_question = false;
            }
            $wp_user = $question->wp_user;
            if (function_exists('espresso_member_data')) {
                if (function_exists('espresso_is_admin')) {
                    // If the user doesn't have admin access get only user's own question groups
                    if (!espresso_is_admin()) {
                        if (espresso_member_data('id') != $wp_user) {
                            echo '<h2>' . __('Sorry, you do not have permission to edit this question.', 'event_espresso') . '</h2>';
                            return;
                        }
                    }
                }
            }
            ?>

<div class="metabox-holder">
  <div class="postbox">
		<div class="handlediv" title="Click to toggle"><br>
		</div>
		<h3 class="hndle">
	  <?php 
            _e('Edit Question', 'event_espresso');
            ?>
		</h3>
	  <div class="inside">
			<form id="edit-new-question-form" name="newquestion" method="post" action="<?php 
            echo $_SERVER["REQUEST_URI"];
            ?>
">
			<p class="intro"> <?php 
            _e('Edit the question using the form below.  By default all participants will be asked for their first name, last name, and email address.', 'event_espresso');
            ?>
</p>
					<?php 
            if ($system_question == true) {
                echo '<p class="inform">' . __('Attention: This is a "System Question", some settings may be disabled.', 'event_espresso') . '</p>';
            }
            ?>

			<table class="form-table">
				<tbody>
					<tr>
						<th>
		  				<label for="question"><?php 
            _e('Question', 'event_espresso');
            ?>
</label>
						</th>
						<td>
		  				<input name="question" id="question" size="50" value="<?php 
            echo htmlspecialchars($question_name, ENT_QUOTES, 'UTF-8');
            ?>
" type="text">
						</td>
					</tr>
					<tr>
				  	<th id="question-type-select">
		  				<label for="question_type"><?php 
            _e('Type', 'event_espresso');
            ?>
</label>
						</th>
						<td>
		 				<?php 
            $q_values = array(array('id' => 'TEXT', 'text' => __('Text', 'event_espresso')), array('id' => 'TEXTAREA', 'text' => __('Text Area', 'event_espresso')), array('id' => 'SINGLE', 'text' => __('Radio Button', 'event_espresso')), array('id' => 'DROPDOWN', 'text' => __('Drop Down', 'event_espresso')), array('id' => 'MULTIPLE', 'text' => __('Checkbox', 'event_espresso')));
            if ($system_question == true) {
                $q_values = array(array('id' => 'TEXT', 'text' => __('Text', 'event_espresso')));
            }
            echo select_input('question_type', $q_values, $question_type, 'id="question_type"');
            ?>
					</td>
				</tr>
				<tr id="add-question-values">
					<th>
		  			<label for="values"><?php 
            _e('Values', 'event_espresso');
            ?>
</label>
					</th>
					<td>
		  			<input name="values" id="values" size="50" value="<?php 
            echo htmlspecialchars($question_values, ENT_QUOTES, 'UTF-8');
            ?>
" type="text" />
					<br />
						<span class="description"><?php 
            _e('A comma seperated list of values. Eg. black, blue, red', 'event_espresso');
            ?>
</span>
					</td>
				</tr>
				<tr>
					<th>
						<label for="required"><?php 
            _e('Required', 'event_espresso');
            ?>
</label>
					</th>
					<td>
		  		<?php 
            $values = array(array('id' => 'Y', 'text' => __('Yes', 'event_espresso')), array('id' => 'N', 'text' => __('No', 'event_espresso')));
            if ($system_question == true && ($system_name == 'fname' || $system_name == 'lname' || $system_name == 'email')) {
                $values = array(array('id' => 'Y', 'text' => __('Yes', 'event_espresso')));
            }
            echo select_input('required', $values, $required);
            ?>
<br />
						<span class="description"><?php 
            _e('Mark this question as required.', 'event_espresso');
            ?>
</span>
					</td>
				</tr>
				<tr>
					<th>
		  			<label for="admin_only">
							<?php 
            _e('Admin View Only', 'event_espresso');
            ?>
		  			</label>
					</th>
					<td>						
					<?php 
            $values = array(array('id' => 'Y', 'text' => __('Yes', 'event_espresso')), array('id' => 'N', 'text' => __('No', 'event_espresso')));
            if ($system_question == true && ($system_name == 'fname' || $system_name == 'lname' || $system_name == 'email')) {
                $values = array(array('id' => 'N', 'text' => __('No', 'event_espresso')));
            }
            echo select_input('admin_only', $values, $admin_only);
            ?>
<br />
						<span class="description"><?php 
            _e('Only the administrator can see this field.', 'event_espresso');
            ?>
</span>
					</td>
				</tr>
				<tr>
					<th>
						<label for="required_text">
							<?php 
            _e('Required Text', 'event_espresso');
            ?>
						</label>
					</th>
					<td>
						<input name="required_text" id="required_text" size="50" value="<?php 
            echo htmlspecialchars($required_text, ENT_QUOTES, 'UTF-8');
            ?>
" type="text" /><br />
						<span class="description"><?php 
            _e('Text displayed if not completed.', 'event_espresso');
            ?>
</span>
					</td>
				</tr>
				<tr>
					<th>
		  			<label for="sequence">
							<?php 
            _e('Order/Sequence', 'event_espresso');
            ?>
						</label>
					</th>
					<td>
		  			<input name="sequence" id="sequence" size="50" value="<?php 
            echo $sequence;
            ?>
" type="text" />
					</td>
				</tr>
			</tbody>
		</table>
		<p class="submit-footer">
			<input name="edit_action" value="update" type="hidden">
			<input type="hidden" name="action" value="edit_question">
			<input name="question_id" value="<?php 
            echo $question_id;
            ?>
" type="hidden">
			<input class="button-primary" name="Submit" value="Update Question" type="submit">
			<?php 
            wp_nonce_field('espresso_form_check', 'edit_question');
            ?>
		</p>
	</form>
	</div>
 </div>
</div>
<?php 
        }
    } else {
        _e('Nothing found!', 'event_espresso');
    }
}
示例#2
0
function event_espresso_questions_config_mnu()
{
    global $wpdb;
    //Update the questions when re-ordering
    if (!empty($_REQUEST['update_sequence'])) {
        $rows = explode(",", $_POST['row_ids']);
        for ($i = 0; $i < count($rows); $i++) {
            $wpdb->query("UPDATE " . EVENTS_QUESTION_TABLE . " SET sequence=" . $i . " WHERE id='" . $rows[$i] . "'");
        }
        die;
    }
    // get counts
    $total_questions = count(espresso_get_user_questions(null, null, false));
    $total_self_questions = count(espresso_get_user_questions(get_current_user_id(), null, true, true));
    ?>
	<div class="wrap">
		<div id="icon-options-event" class="icon32"> </div>
		<h2><?php 
    echo _e('Manage Questions', 'event_espresso');
    ?>
			<?php 
    if (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'edit_question' && $_REQUEST['action'] != 'new_question') {
        echo '<a href="admin.php?page=form_builder&action=new_question" class="button add-new-h2" style="margin-left: 20px;">' . __('Add New Question', 'event_espresso') . '</a>';
    }
    ?>
		</h2>
		<?php 
    ob_start();
    if (function_exists('espresso_is_admin') && espresso_is_admin() == true) {
        ?>
			<div style="margin-bottom: 10px;">
				<ul class="subsubsub" style="margin-bottom: 0;clear:both;">
					<li><strong><?php 
        _e('Questions', 'event_espresso');
        ?>
: </strong> </li>
					<li><a <?php 
        echo !isset($_REQUEST['self']) && !isset($_REQUEST['all']) || isset($_REQUEST['self']) && $_REQUEST['self'] == 'true' ? ' class="current" ' : '';
        ?>
 href="admin.php?page=form_builder&self=true"><?php 
        _e('My Questions', 'event_espresso');
        ?>
 <span class="count">(<?php 
        echo $total_self_questions;
        ?>
)</span> </a> | </li>
					<li><a <?php 
        echo isset($_REQUEST['all']) && $_REQUEST['all'] == 'true' ? ' class="current" ' : '';
        ?>
 href="admin.php?page=form_builder&all=true"><?php 
        _e('All Questions', 'event_espresso');
        ?>
 <span class="count">(<?php 
        echo $total_questions;
        ?>
)</span> </a></li>
				</ul>
				<div class="clear"></div>
			</div>
		<?php 
    }
    ?>

		<div class="meta-box-sortables ui-sortables">
			<?php 
    //Update the question
    if (isset($_REQUEST['edit_action']) && $_REQUEST['edit_action'] == 'update') {
        require_once "questions/update_question.php";
        event_espresso_form_builder_update();
    }
    $button_style = 'button-primary';
    //Figure out which view to display
    if (isset($_REQUEST['action'])) {
        switch ($_REQUEST['action']) {
            case 'insert':
                if (file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/form-builder/questions/insert_question.php')) {
                    require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/form-builder/questions/insert_question.php';
                    event_espresso_form_builder_insert();
                } else {
                    require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/pricing_table.php';
                }
                break;
            case 'new_question':
                if (file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/form-builder/questions/new_question.php')) {
                    require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/form-builder/questions/new_question.php';
                    event_espresso_form_builder_new();
                } else {
                    require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/pricing_table.php';
                }
                $button_style = 'button-secondary';
                break;
            case 'edit_question':
                require_once "questions/edit_question.php";
                event_espresso_form_builder_edit();
                $button_style = 'button-secondary';
                break;
            case 'delete_question':
                if (file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/form-builder/questions/delete_question.php')) {
                    require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/admin-files/form-builder/questions/delete_question.php';
                    event_espresso_form_builder_delete();
                } else {
                    ?>
							<div id="message" class="updated fade">
								<p><strong>
										<?php 
                    _e('This function is not available in the free version of Event Espresso.', 'event_espresso');
                    ?>
									</strong></p>
							</div>
							<?php 
                }
                break;
        }
    }
    ?>
		</div>

		<form id="form1" name="form1" method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
			<table id="table" class="widefat manage-questions">

				<thead>
					<tr>
						<th class="manage-column" id="cb" scope="col" ><input type="checkbox"></th>

						<th class="manage-column column-title" id="values" scope="col" title="Click to Sort" style="width:25%;">
							<?php 
    _e('Question', 'event_espresso');
    ?>
						</th>
						<th class="manage-column column-title" id="values" scope="col" title="Click to Sort" style="width:15%;">
							<?php 
    _e('Values', 'event_espresso');
    ?>
						</th>
						<?php 
    if (function_exists('espresso_is_admin') && espresso_is_admin() == true) {
        ?>
							<th class="manage-column column-creator" id="creator" scope="col" title="Click to Sort" style="width:15%;">
								<?php 
        _e('Creator', 'event_espresso');
        ?>
							</th>
						<?php 
    }
    ?>

						<th class="manage-column column-title" id="values" scope="col" title="Click to Sort"  style="width:10%;">
							<?php 
    _e('Type', 'event_espresso');
    ?>
						</th>
						<th class="manage-column column-title" id="values" scope="col" title="Click to Sort" style="width:10%;">
							<?php 
    _e('Required', 'event_espresso');
    ?>
						</th>
						<th class="manage-column column-title" id="values" scope="col" title="Click to Sort" style="width:10%;">
							<?php 
    _e('Admin Only', 'event_espresso');
    ?>
						</th>

					</tr>
				</thead>
				<tbody>
					<?php 
    $questions = espresso_get_user_questions(get_current_user_id());
    if (count($questions) > 0) {
        foreach ($questions as $question) {
            $question_id = $question->id;
            $question_name = stripslashes($question->question);
            $values = stripslashes($question->response);
            $question_type = stripslashes($question->question_type);
            $required = stripslashes($question->required);
            $system_name = $question->system_name;
            $sequence = $question->sequence;
            $admin_only = $question->admin_only;
            $wp_user = $question->wp_user == 0 ? 1 : $question->wp_user;
            ?>
							<tr style="cursor: move" id="<?php 
            echo $question_id;
            ?>
">
								<td class="checkboxcol"><input name="row_id" type="hidden" value="<?php 
            echo $question_id;
            ?>
" />
									<?php 
            if ($system_name == '') {
                ?>
										<input  style="margin:7px 0 22px 8px; vertical-align:top;" name="checkbox[<?php 
                echo $question_id;
                ?>
]" type="checkbox"  title="Delete <?php 
                echo wp_strip_all_tags($question_name);
                ?>
">
									<?php 
            } else {
                ?>
										<span><?php 
                echo '<img style="margin:7px 0 22px 8px; vertical-align:top;" src="' . EVENT_ESPRESSO_PLUGINFULLURL . 'images/icons/lock.png" alt="System Questions" title="System Questions" />';
                ?>
</span>
									<?php 
            }
            ?>
								</td>

								<td class="post-title page-title column-title"><strong><a href="admin.php?page=form_builder&amp;action=edit_question&amp;question_id=<?php 
            echo $question_id;
            ?>
"><?php 
            echo wp_strip_all_tags($question_name);
            ?>
</a></strong>
									<div class="row-actions">
										<span class="edit"><a href="admin.php?page=form_builder&amp;action=edit_question&amp;question_id=<?php 
            echo $question_id;
            ?>
"><?php 
            _e('Edit', 'event_espresso');
            ?>
</a> | </span>
										<?php 
            if ($system_name == '') {
                ?>
<span class="delete"><a onclick="return confirmDelete();" class="submitdelete"  href="admin.php?page=form_builder&amp;action=delete_question&amp;question_id=<?php 
                echo $question_id;
                ?>
"><?php 
                _e('Delete', 'event_espresso');
                ?>
</a></span><?php 
            }
            ?>
									</div>
								</td>
								<td class="author column-author"><?php 
            echo $values;
            ?>
</td>
								<?php 
            if (function_exists('espresso_is_admin') && espresso_is_admin() == true) {
                ?>
									<td><?php 
                echo espresso_user_meta($wp_user, 'user_firstname') != '' ? espresso_user_meta($wp_user, 'user_firstname') . ' ' . espresso_user_meta($wp_user, 'user_lastname') . ' (<a href="user-edit.php?user_id=' . $wp_user . '">' . espresso_user_meta($wp_user, 'user_nicename') . '</a>)' : espresso_user_meta($wp_user, 'display_name') . ' (<a href="user-edit.php?user_id=' . $wp_user . '">' . espresso_user_meta($wp_user, 'user_nicename') . '</a>)';
                ?>
</td>
								<?php 
            }
            ?>
								<td class="author column-author"><?php 
            echo $question_type;
            ?>
</td>
								<td class="author column-author"><?php 
            echo $required;
            ?>
</td>
								<td class="author column-author"><?php 
            echo $admin_only;
            ?>
</td>
							</tr>
							<?php 
        }
    }
    ?>
				</tbody>
			</table>

			<div>
				<p><input type="checkbox" name="sAll" onclick="selectAll(this)" />
					<strong>
						<?php 
    _e('Check All', 'event_espresso');
    ?>
					</strong>
					<input type="hidden" name="action" value="delete_question" />
					<input name="delete_question" type="submit" class="button-secondary" id="delete_question" value="<?php 
    _e('Delete Question', 'event_espresso');
    ?>
" style="margin-left:10px 0 0 10px;" onclick="return confirmDelete();">
					<a  style="margin-left:5px"class="button-secondary" href="admin.php?page=form_groups"><?php 
    _e('Question Groups', 'event_espresso');
    ?>
</a>
					<a style="margin-left:5px"class="button-secondary thickbox" href="#TB_inline?height=400&width=500&inlineId=question_info">Help</a>
					<a  style="margin-left:5px"class="<?php 
    echo $button_style;
    ?>
" href="admin.php?page=form_builder&amp;action=new_question"><?php 
    _e('Add New Question', 'event_espresso');
    ?>
</a>
				</p>
			</div>
		</form>
		<?php 
    $main_post_content = ob_get_clean();
    espresso_choose_layout($main_post_content, event_espresso_display_right_column());
    ?>
							

	</div>
	<div id="question_info" class="pop-help" style="display:none">
		<div class="TB-ee-frame">
			<h2><?php 
    _e('Manage Questions Overview', 'event_espresso');
    ?>
</h2>
			<p><?php 
    _e('The <code>Questions</code> page shows your list of available questions to add to your registration forms for events', 'event_espresso');
    ?>
</p>
			<p><?php 
    _e('Use the add new question button at the top of the page to create a new question to add to the list ', 'event_espresso');
    ?>
<a href="admin.php?page=form_builder&amp;action=new_question"><?php 
    _e('Add New Question', 'event_espresso');
    ?>
</a></p>
			<p><?php 
    _e('Once you have a built a list of questions you may further organize your questions into <code>Groups.</code> These', 'event_espresso');
    ?>
 <a href="admin.php?page=form_groups"><?php 
    _e('Question Groups ', 'event_espresso');
    ?>
</a><?php 
    _e('allow you to easily and conveniently add a group to a registration that will have a pre populated set of questions, this is especially handy when creating many registration forms, saving time, by being able to re-use specific groups of questions repetedly.', 'event_espresso');
    ?>
</p>
		</div>
	</div>



	<script type="text/javascript">
		jQuery(document).ready(function($) {

			/* show the table data */
			var mytable = $('#table').dataTable( {
				"bStateSave": true,
				"sPaginationType": "full_numbers",

				"oLanguage": {	"sSearch": "<strong><?php 
    _e('Live Search Filter', 'event_espresso');
    ?>
:</strong>",
					"sZeroRecords": "<?php 
    _e('No Records Found!', 'event_espresso');
    ?>
" },
				"aoColumns": [
					{ "bSortable": true },
					null,
					null,
					null,
					null,
	<?php 
    echo function_exists('espresso_is_admin') && espresso_is_admin() == true ? 'null,' : '';
    ?>
					null

				]

			} );

			var startPosition;
			var endPosition;
			$("#table tbody").sortable({
				cursor: "move",
				start:function(event, ui){
					startPosition = ui.item.prevAll().length + 1;
				},
				update: function(event, ui) {
					endPosition = ui.item.prevAll().length + 1;
					//alert('Start Position: ' + startPosition + ' End Position: ' + endPosition);
					var row_ids="";
					$('#table tbody input[name="row_id"]').each(function(i){
						row_ids= row_ids + ',' + $(this).val();
					});
					$.post(EEGlobals.ajaxurl, { action: "update_sequence", row_ids: row_ids, update_sequence: "true"} );
				}
			});
			postboxes.add_postbox_toggles('form_builder');
		} );
						
		// Remove li parent for input 'values' from page if 'text' box or 'textarea' are selected
		var selectValue = jQuery('#question_type option:selected').val();
		//alert(selectValue + ' - this is initial value');
		// hide values field on initial page view
		if( selectValue == 'SINGLE' || selectValue == 'DROPDOWN' || selectValue == 'MULTIPLE' ) {
			jQuery('#question-values').attr("name","values") 
		} else {
			jQuery('#add-question-values').hide();
			jQuery('#add-price-modifier').hide();
			jQuery('#set-price-mod-qty').hide();
			jQuery('#set-price-mod-available').hide();
			// we don't want the values field trying to validate if not displayed, remove its name
			jQuery('#question-values').attr("name","question_values") 
		}
			
					
		jQuery('#question_type').on('change', function() {
			var selectValue = jQuery('#question_type option:selected').val();
				  
			if ( selectValue == 'SINGLE' || selectValue == 'DROPDOWN' || selectValue == 'MULTIPLE' ) {
				jQuery('#add-price-modifier').fadeIn('fast');
				jQuery('#set-price-mod-qty').fadeIn('fast');
				jQuery('#set-price-mod-available').fadeIn('fast');
				jQuery('#add-question-values').fadeIn('fast');
				jQuery('#question-values').attr("name","values");
			} else {
				jQuery('#add-question-values').fadeOut('fast');
				jQuery('#add-price-modifier').fadeOut('fast');
				jQuery('#set-price-mod-qty').fadeOut('fast');
				jQuery('#set-price-mod-available').fadeOut('fast');
				jQuery('#question-values').attr("name","question_values");
			}
		});


		// Add new question or question group form validation
		jQuery(function(){
			jQuery('#new-question-form').validate({
				rules: {
					question: "required",
					values: "required"
				},
				messages: {
					question: "Please add a title for your question",
					values: "Please add a list of answer options for your question"
				}
			});
						
		});				
	</script>

	<?php 
}
function event_espresso_form_group_new()
{
    ?>
<div id="add-edit-new-group" class="metabox-holder">
 <div class="postbox">
	<div title="Click to toggle" class="handlediv"><br /></div>
   <h3 class="hndle"><?php 
    _e('Add New Group', 'event_espresso');
    ?>
</h3>
    <div class="inside">
    <form id="add-new-group" name="newgroup" method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
 		<p class="intro"><?php 
    _e('Add new group using the form below.', 'event_espresso');
    ?>
</p>   
			<table id="table-add-group" class="ee-tables" border="0">
      <tr>
       <td class="a" valign="top">
        <fieldset id="general-group-info">
         <legend><?php 
    _e('Group Information', 'event_espresso');
    ?>
</legend>				 
          <ul>
           <li>
             <label for="group_name"><?php 
    _e('Group Name:', 'event_espresso');
    ?>
<em title="<?php 
    _e('This field is required', 'event_espresso');
    ?>
"> *</em></label>
             <input class="group-name" name="group_name" id="group_name" size="50" value="" type="text" />
           </li>
				
           <li>
             <label for="group_order"><?php 
    _e('Group Order:', 'event_espresso');
    ?>
</label>
             <input name="group_order" id="group_order" size="6" value="" type="text" />
           </li>
    
           <li>
             <label for="group_description"><?php 
    _e('Description:', 'event_espresso');
    ?>
</label>
             <textarea name="group_description" cols="40" rows="5"></textarea>
           </li>
				
           <li>
             <label for="show_group_name"><?php 
    _e('Show group name on registration page?', 'event_espresso');
    ?>
</label>
             <input type="checkbox" name="show_group_name" id="show_group_name" value="1" checked="checked" />
           </li>
				
          <li>
            <label for="show_group_description"><?php 
    _e('Show group description on registration page?', 'event_espresso');
    ?>
</label>
            <input type="checkbox" name="show_group_description" id="show_group_description" value="1" checked="checked" />
          </li>
        </ul>
       </fieldset>
      </td>
  
      <td class="b"  valign="top">
				 <fieldset id="questions-for-group">
				  <legend><?php 
    _e('Add questions', 'event_espresso');
    ?>
</legend>
        <ul id="add-quest">	
          <li><p><?php 
    _e('Select questions to add to group:', 'event_espresso');
    ?>
</p></li>
  
            <?php 
    //first we need to get all system questions (make sure that the user actually has some);
    $questions = espresso_get_user_questions(get_current_user_id());
    if (count($questions) > 0) {
        foreach ($questions as $question) {
            echo '<li><label><input type="checkbox" name="question_id[]" value="' . $question->id . '" id="question_id_' . $question->id . '" />' . stripslashes($question->question) . '</label></li>';
        }
    }
    ?>
          </ul>
						</fieldset>
        </td>
      </tr>
    </table>
    <p>
      <input name="action" value="insert_group" type="hidden">
      <input class="button-primary" name="Submit" value="Add Group" type="submit">
    </p>
   </form>
  </div>
 </div>
</div>
<?php 
}