@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 3 | 3 | exit('NO direct script access allowed'); |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -58,12 +58,12 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | |
| 61 | - public function __construct( $routing = TRUE ) { |
|
| 62 | - require_once( EE_MODELS . 'EEM_Question.model.php' ); |
|
| 63 | - require_once( EE_MODELS . 'EEM_Question_Group.model.php' ); |
|
| 64 | - $this->_question_model= EEM_Question::instance(); |
|
| 65 | - $this->_question_group_model=EEM_Question_Group::instance(); |
|
| 66 | - parent::__construct( $routing ); |
|
| 61 | + public function __construct($routing = TRUE) { |
|
| 62 | + require_once(EE_MODELS.'EEM_Question.model.php'); |
|
| 63 | + require_once(EE_MODELS.'EEM_Question_Group.model.php'); |
|
| 64 | + $this->_question_model = EEM_Question::instance(); |
|
| 65 | + $this->_question_group_model = EEM_Question_Group::instance(); |
|
| 66 | + parent::__construct($routing); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | |
| 99 | 99 | protected function _set_page_routes() { |
| 100 | - $qst_id = ! empty( $this->_req_data['QST_ID'] ) ? $this->_req_data['QST_ID'] : 0; |
|
| 100 | + $qst_id = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
| 101 | 101 | $this->_page_routes = array( |
| 102 | 102 | 'default' => array( |
| 103 | 103 | 'func' => '_questions_overview_list_table', |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | 'update_question' => array( |
| 120 | 120 | 'func' => '_insert_or_update_question', |
| 121 | - 'args' => array('new_question' => FALSE ), |
|
| 121 | + 'args' => array('new_question' => FALSE), |
|
| 122 | 122 | 'capability' => 'ee_edit_question', |
| 123 | 123 | 'obj_id' => $qst_id, |
| 124 | 124 | 'noheader' => TRUE, |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | 'filename' => 'registration_form_questions_overview_views_bulk_actions_search' |
| 154 | 154 | ) |
| 155 | 155 | ), |
| 156 | - 'help_tour' => array( 'Registration_Form_Questions_Overview_Help_Tour'), |
|
| 156 | + 'help_tour' => array('Registration_Form_Questions_Overview_Help_Tour'), |
|
| 157 | 157 | 'require_nonce' => FALSE, |
| 158 | 158 | 'qtips' => array( |
| 159 | 159 | 'EE_Registration_Form_Tips' |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | 'filename' => 'registration_form_question_groups' |
| 173 | 173 | ), |
| 174 | 174 | ), |
| 175 | - 'help_tour' => array( 'Registration_Form_Question_Groups_Help_Tour'), |
|
| 175 | + 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
| 176 | 176 | 'require_nonce' => FALSE |
| 177 | 177 | ), |
| 178 | 178 | |
@@ -181,16 +181,16 @@ discard block |
||
| 181 | 181 | 'label' => __('Edit Question', 'event_espresso'), |
| 182 | 182 | 'order' => 15, |
| 183 | 183 | 'persistent' => FALSE, |
| 184 | - 'url' => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id'] ), $this->_current_page_view_url ) : $this->_admin_base_url |
|
| 184 | + 'url' => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']), $this->_current_page_view_url) : $this->_admin_base_url |
|
| 185 | 185 | ), |
| 186 | - 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array('_publish_post_box' ) ), |
|
| 186 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 187 | 187 | 'help_tabs' => array( |
| 188 | 188 | 'registration_form_edit_question_group_help_tab' => array( |
| 189 | 189 | 'title' => __('Edit Question', 'event_espresso'), |
| 190 | 190 | 'filename' => 'registration_form_edit_question' |
| 191 | 191 | ), |
| 192 | 192 | ), |
| 193 | - 'help_tour' => array( 'Registration_Form_Edit_Question_Help_Tour'), |
|
| 193 | + 'help_tour' => array('Registration_Form_Edit_Question_Help_Tour'), |
|
| 194 | 194 | 'require_nonce' => FALSE |
| 195 | 195 | ), |
| 196 | 196 | ); |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | //none of the below group are currently used for Event Categories |
| 219 | 219 | protected function _add_feature_pointers() {} |
| 220 | 220 | public function load_scripts_styles() { |
| 221 | - wp_register_style( 'espresso_registration', REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION ); |
|
| 221 | + wp_register_style('espresso_registration', REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 222 | 222 | wp_enqueue_style('espresso_registration'); |
| 223 | 223 | } |
| 224 | 224 | public function admin_init() {} |
@@ -234,20 +234,20 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | public function load_scripts_styles_add_question() { |
| 236 | 236 | $this->load_scripts_styles_forms(); |
| 237 | - wp_register_script( 'espresso_registration_form_single', REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 238 | - wp_enqueue_script( 'espresso_registration_form_single' ); |
|
| 237 | + wp_register_script('espresso_registration_form_single', REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 238 | + wp_enqueue_script('espresso_registration_form_single'); |
|
| 239 | 239 | } |
| 240 | 240 | public function load_scripts_styles_edit_question() { |
| 241 | 241 | $this->load_scripts_styles_forms(); |
| 242 | - wp_register_script( 'espresso_registration_form_single', REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 243 | - wp_enqueue_script( 'espresso_registration_form_single' ); |
|
| 242 | + wp_register_script('espresso_registration_form_single', REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 243 | + wp_enqueue_script('espresso_registration_form_single'); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | |
| 247 | 247 | |
| 248 | 248 | |
| 249 | 249 | public function recaptcha_info_help_tab() { |
| 250 | - $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
| 250 | + $template = REGISTRATION_FORM_TEMPLATE_PATH.'recaptcha_info_help_tab.template.php'; |
|
| 251 | 251 | EEH_Template::display_template($template, array()); |
| 252 | 252 | } |
| 253 | 253 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | ) |
| 280 | 280 | ); |
| 281 | 281 | |
| 282 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_questions', 'espresso_registration_form_trash_questions' ) ) { |
|
| 282 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', 'espresso_registration_form_trash_questions')) { |
|
| 283 | 283 | $this->_views['trash'] = array( |
| 284 | 284 | 'slug' => 'trash', |
| 285 | 285 | 'label' => __('Trash', 'event_espresso'), |
@@ -297,9 +297,9 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | protected function _questions_groups_preview() { |
| 299 | 299 | $this->_admin_page_title = __('Question Groups (Preview)', 'event_espresso'); |
| 300 | - $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__( 'Preview Question Groups Overview List Table screenshot', 'event_espresso' ) . '" />'; |
|
| 301 | - $this->_template_args['preview_text'] = '<strong>'.__( 'Question Groups is a feature that is only available in the Caffeinated version of Event Espresso. With the Question Groups feature you are able to: create new question groups, edit existing question groups, and also create and edit new questions and add them to question groups.', 'event_espresso' ).'</strong>'; |
|
| 302 | - $this->display_admin_caf_preview_page( 'question_groups_tab' ); |
|
| 300 | + $this->_template_args['preview_img'] = '<img src="'.REGISTRATION_FORM_ASSETS_URL.'caf_reg_form_preview.jpg" alt="'.esc_attr__('Preview Question Groups Overview List Table screenshot', 'event_espresso').'" />'; |
|
| 301 | + $this->_template_args['preview_text'] = '<strong>'.__('Question Groups is a feature that is only available in the Caffeinated version of Event Espresso. With the Question Groups feature you are able to: create new question groups, edit existing question groups, and also create and edit new questions and add them to question groups.', 'event_espresso').'</strong>'; |
|
| 302 | + $this->display_admin_caf_preview_page('question_groups_tab'); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | |
@@ -310,58 +310,58 @@ discard block |
||
| 310 | 310 | * @param \EEM_Base $model |
| 311 | 311 | * @return array where each key is the name of a model's field/db column, and each value is its value. |
| 312 | 312 | */ |
| 313 | - protected function _set_column_values_for(EEM_Base $model){ |
|
| 314 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 315 | - $set_column_values=array(); |
|
| 313 | + protected function _set_column_values_for(EEM_Base $model) { |
|
| 314 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 315 | + $set_column_values = array(); |
|
| 316 | 316 | |
| 317 | 317 | //some initial checks for proper values. |
| 318 | 318 | //if QST_admin_only, then no matter what QST_required is we disable. |
| 319 | - if ( !empty( $this->_req_data['QST_admin_only'] ) ) { |
|
| 319 | + if ( ! empty($this->_req_data['QST_admin_only'])) { |
|
| 320 | 320 | $this->_req_data['QST_required'] = 0; |
| 321 | 321 | } |
| 322 | - foreach($model->field_settings() as $fieldName=>$settings){ |
|
| 322 | + foreach ($model->field_settings() as $fieldName=>$settings) { |
|
| 323 | 323 | // basically if QSG_identifier is empty or not set |
| 324 | - if ( $fieldName == 'QSG_identifier' && ( isset( $this->_req_data['QSG_identifier'] ) && empty( $this->_req_data['QSG_identifier'] ) )) { |
|
| 325 | - $QSG_name = isset( $this->_req_data['QSG_name'] ) ? $this->_req_data['QSG_name'] : '' ; |
|
| 326 | - $set_column_values[$fieldName] = sanitize_title($QSG_name ) . '-' . uniqid(); |
|
| 324 | + if ($fieldName == 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
|
| 325 | + $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
|
| 326 | + $set_column_values[$fieldName] = sanitize_title($QSG_name).'-'.uniqid(); |
|
| 327 | 327 | // dd($set_column_values); |
| 328 | 328 | } |
| 329 | 329 | //if the admin label is blank, use a slug version of the question text |
| 330 | - else if ( $fieldName == 'QST_admin_label' && ( isset( $this->_req_data['QST_admin_label'] ) && empty( $this->_req_data['QST_admin_label'] ) )) { |
|
| 331 | - $QST_text = isset( $this->_req_data['QST_display_text'] ) ? $this->_req_data['QST_display_text'] : '' ; |
|
| 332 | - $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text,10)); |
|
| 330 | + else if ($fieldName == 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
|
| 331 | + $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
|
| 332 | + $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
| 336 | - else if ( $fieldName == 'QST_admin_only' && ( !isset( $this->_req_data['QST_admin_only'] ) ) ) { |
|
| 336 | + else if ($fieldName == 'QST_admin_only' && ( ! isset($this->_req_data['QST_admin_only']))) { |
|
| 337 | 337 | $set_column_values[$fieldName] = 0; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - else if ( $fieldName == 'QST_max' ) { |
|
| 340 | + else if ($fieldName == 'QST_max') { |
|
| 341 | 341 | $qst_system = EEM_Question::instance()->get_var( |
| 342 | 342 | array( |
| 343 | 343 | array( |
| 344 | - 'QST_ID' => $this->_req_data[ 'QST_ID' ] |
|
| 344 | + 'QST_ID' => $this->_req_data['QST_ID'] |
|
| 345 | 345 | ) |
| 346 | 346 | ), |
| 347 | 347 | 'QST_system' ); |
| 348 | - $max_max = EEM_Question::instance()->max_max_for_system_question( $qst_system ); |
|
| 349 | - if( empty( $this->_req_data[ 'QST_max' ] ) || |
|
| 350 | - $this->_req_data[ 'QST_max' ] > $max_max ) { |
|
| 351 | - $set_column_values[ $fieldName ] = $max_max; |
|
| 348 | + $max_max = EEM_Question::instance()->max_max_for_system_question($qst_system); |
|
| 349 | + if (empty($this->_req_data['QST_max']) || |
|
| 350 | + $this->_req_data['QST_max'] > $max_max) { |
|
| 351 | + $set_column_values[$fieldName] = $max_max; |
|
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | |
| 356 | 356 | //only add a property to the array if it's not null (otherwise the model should just use the default value) |
| 357 | - if( |
|
| 358 | - ! isset( $set_column_values[ $fieldName ] ) && |
|
| 359 | - isset($this->_req_data[$fieldName] ) ){ |
|
| 360 | - $set_column_values[$fieldName]=$this->_req_data[$fieldName]; |
|
| 357 | + if ( |
|
| 358 | + ! isset($set_column_values[$fieldName]) && |
|
| 359 | + isset($this->_req_data[$fieldName]) ) { |
|
| 360 | + $set_column_values[$fieldName] = $this->_req_data[$fieldName]; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | } |
| 364 | - return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
| 364 | + return $set_column_values; //validation fo this data to be performed by the model before insertion. |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | |
@@ -379,30 +379,30 @@ discard block |
||
| 379 | 379 | /** |
| 380 | 380 | * @param string $action |
| 381 | 381 | */ |
| 382 | - protected function _edit_question( $action= 'add' ) { |
|
| 383 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 384 | - $ID=isset( $this->_req_data['QST_ID'] ) && ! empty( $this->_req_data['QST_ID'] ) ? absint( $this->_req_data['QST_ID'] ) : FALSE; |
|
| 382 | + protected function _edit_question($action = 'add') { |
|
| 383 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 384 | + $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : FALSE; |
|
| 385 | 385 | |
| 386 | - $this->_admin_page_title = ucwords( str_replace( '_', ' ', $this->_req_action )); |
|
| 386 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 387 | 387 | // add PRC_ID to title if editing |
| 388 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
| 389 | - if($ID){ |
|
| 390 | - $question=$this->_question_model->get_one_by_ID($ID); |
|
| 391 | - $additional_hidden_fields=array('QST_ID'=>array('type'=>'hidden','value'=>$ID)); |
|
| 388 | + $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title; |
|
| 389 | + if ($ID) { |
|
| 390 | + $question = $this->_question_model->get_one_by_ID($ID); |
|
| 391 | + $additional_hidden_fields = array('QST_ID'=>array('type'=>'hidden', 'value'=>$ID)); |
|
| 392 | 392 | $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
| 393 | - }else{ |
|
| 394 | - $question= EE_Question::new_instance(); |
|
| 393 | + } else { |
|
| 394 | + $question = EE_Question::new_instance(); |
|
| 395 | 395 | $question->set_order_to_latest(); |
| 396 | 396 | $this->_set_add_edit_form_tags('insert_question'); |
| 397 | 397 | } |
| 398 | - $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category( $question->type() ) : $this->_question_model->allowed_question_types(); |
|
| 399 | - $this->_template_args['QST_ID']=$ID; |
|
| 400 | - $this->_template_args['question']=$question; |
|
| 401 | - $this->_template_args['question_types']= $question_types; |
|
| 402 | - $this->_template_args['max_max'] = EEM_Question::instance()->max_max_for_system_question( $question->system_ID() ); |
|
| 398 | + $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types(); |
|
| 399 | + $this->_template_args['QST_ID'] = $ID; |
|
| 400 | + $this->_template_args['question'] = $question; |
|
| 401 | + $this->_template_args['question_types'] = $question_types; |
|
| 402 | + $this->_template_args['max_max'] = EEM_Question::instance()->max_max_for_system_question($question->system_ID()); |
|
| 403 | 403 | |
| 404 | - $this->_set_publish_post_box_vars( 'id', $ID ); |
|
| 405 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', $this->_template_args, TRUE ); |
|
| 404 | + $this->_set_publish_post_box_vars('id', $ID); |
|
| 405 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_TEMPLATE_PATH.'questions_main_meta_box.template.php', $this->_template_args, TRUE); |
|
| 406 | 406 | |
| 407 | 407 | // the details template wrapper |
| 408 | 408 | $this->display_admin_page_with_sidebar(); |
@@ -414,58 +414,58 @@ discard block |
||
| 414 | 414 | * @param bool|true $new_question |
| 415 | 415 | * @throws \EE_Error |
| 416 | 416 | */ |
| 417 | - protected function _insert_or_update_question( $new_question = TRUE) { |
|
| 418 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 419 | - $set_column_values=$this->_set_column_values_for($this->_question_model); |
|
| 420 | - if($new_question){ |
|
| 421 | - $ID=$this->_question_model->insert($set_column_values); |
|
| 417 | + protected function _insert_or_update_question($new_question = TRUE) { |
|
| 418 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 419 | + $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
| 420 | + if ($new_question) { |
|
| 421 | + $ID = $this->_question_model->insert($set_column_values); |
|
| 422 | 422 | $success = $ID ? true : false; |
| 423 | 423 | $action_desc = 'added'; |
| 424 | - }else{ |
|
| 425 | - $ID=absint($this->_req_data['QST_ID']); |
|
| 426 | - $pk=$this->_question_model->primary_key_name(); |
|
| 427 | - $wheres=array($pk=>$ID); |
|
| 424 | + } else { |
|
| 425 | + $ID = absint($this->_req_data['QST_ID']); |
|
| 426 | + $pk = $this->_question_model->primary_key_name(); |
|
| 427 | + $wheres = array($pk=>$ID); |
|
| 428 | 428 | unset($set_column_values[$pk]); |
| 429 | - $success= $this->_question_model->update($set_column_values,array($wheres)); |
|
| 430 | - $action_desc='updated'; |
|
| 429 | + $success = $this->_question_model->update($set_column_values, array($wheres)); |
|
| 430 | + $action_desc = 'updated'; |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - if ($ID){ |
|
| 433 | + if ($ID) { |
|
| 434 | 434 | //save the related options |
| 435 | 435 | //trash removed options, save old ones |
| 436 | 436 | //get list of all options |
| 437 | 437 | /** @type EE_Question $question */ |
| 438 | - $question=$this->_question_model->get_one_by_ID($ID); |
|
| 439 | - $options=$question->options(); |
|
| 440 | - if(! empty($options)){ |
|
| 441 | - foreach($options as $option_ID=>$option){ |
|
| 442 | - $option_req_index=$this->_get_option_req_data_index($option_ID); |
|
| 443 | - if($option_req_index!==FALSE){ |
|
| 438 | + $question = $this->_question_model->get_one_by_ID($ID); |
|
| 439 | + $options = $question->options(); |
|
| 440 | + if ( ! empty($options)) { |
|
| 441 | + foreach ($options as $option_ID=>$option) { |
|
| 442 | + $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
| 443 | + if ($option_req_index !== FALSE) { |
|
| 444 | 444 | $option->save($this->_req_data['question_options'][$option_req_index]); |
| 445 | - }else{ |
|
| 445 | + } else { |
|
| 446 | 446 | //not found, remove it |
| 447 | 447 | $option->delete(); |
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | } |
| 451 | 451 | //save new related options |
| 452 | - foreach($this->_req_data['question_options'] as $index=>$option_req_data){ |
|
| 453 | - if( empty($option_req_data['QSO_ID'] ) && ( ( isset( $option_req_data['QSO_value'] ) && $option_req_data['QSO_value'] !== '' ) || ! empty( $option_req_data['QSO_desc'] ) ) ) {//no ID! save it! |
|
| 454 | - if( ! isset( $option_req_data['QSO_value'] ) || $option_req_data['QSO_value'] === '' ){ |
|
| 455 | - $option_req_data['QSO_value']=$option_req_data['QSO_desc']; |
|
| 452 | + foreach ($this->_req_data['question_options'] as $index=>$option_req_data) { |
|
| 453 | + if (empty($option_req_data['QSO_ID']) && ((isset($option_req_data['QSO_value']) && $option_req_data['QSO_value'] !== '') || ! empty($option_req_data['QSO_desc']))) {//no ID! save it! |
|
| 454 | + if ( ! isset($option_req_data['QSO_value']) || $option_req_data['QSO_value'] === '') { |
|
| 455 | + $option_req_data['QSO_value'] = $option_req_data['QSO_desc']; |
|
| 456 | 456 | } |
| 457 | - $new_option=EE_Question_Option::new_instance( array( 'QSO_value' => $option_req_data['QSO_value'], 'QSO_desc' => $option_req_data['QSO_desc'], 'QSO_order' => $option_req_data['QSO_order'], 'QST_ID' => $question->ID())); |
|
| 457 | + $new_option = EE_Question_Option::new_instance(array('QSO_value' => $option_req_data['QSO_value'], 'QSO_desc' => $option_req_data['QSO_desc'], 'QSO_order' => $option_req_data['QSO_order'], 'QST_ID' => $question->ID())); |
|
| 458 | 458 | $new_option->save(); |
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | - $query_args = array( 'action' => 'edit_question', 'QST_ID' => $ID ); |
|
| 463 | - if ( $success !== FALSE ) { |
|
| 464 | - $msg = $new_question ? sprintf( __('The %s has been created', 'event_espresso'), $this->_question_model->item_name() ) : sprintf( __('The %s has been updated', 'event_espresso' ), $this->_question_model->item_name() ); |
|
| 465 | - EE_Error::add_success( $msg ); |
|
| 462 | + $query_args = array('action' => 'edit_question', 'QST_ID' => $ID); |
|
| 463 | + if ($success !== FALSE) { |
|
| 464 | + $msg = $new_question ? sprintf(__('The %s has been created', 'event_espresso'), $this->_question_model->item_name()) : sprintf(__('The %s has been updated', 'event_espresso'), $this->_question_model->item_name()); |
|
| 465 | + EE_Error::add_success($msg); |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - $this->_redirect_after_action( FALSE, '', $action_desc, $query_args, TRUE); |
|
| 468 | + $this->_redirect_after_action(FALSE, '', $action_desc, $query_args, TRUE); |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | |
@@ -478,10 +478,10 @@ discard block |
||
| 478 | 478 | * @param int $ID of the question option to find |
| 479 | 479 | * @return int index in question_options array if successful, FALSE if unsuccessful |
| 480 | 480 | */ |
| 481 | - protected function _get_option_req_data_index($ID){ |
|
| 482 | - $req_data_for_question_options=$this->_req_data['question_options']; |
|
| 483 | - foreach($req_data_for_question_options as $num=>$option_data){ |
|
| 484 | - if(array_key_exists('QSO_ID',$option_data) && intval($option_data['QSO_ID'])==$ID){ |
|
| 481 | + protected function _get_option_req_data_index($ID) { |
|
| 482 | + $req_data_for_question_options = $this->_req_data['question_options']; |
|
| 483 | + foreach ($req_data_for_question_options as $num=>$option_data) { |
|
| 484 | + if (array_key_exists('QSO_ID', $option_data) && intval($option_data['QSO_ID']) == $ID) { |
|
| 485 | 485 | return $num; |
| 486 | 486 | } |
| 487 | 487 | } |
@@ -503,25 +503,25 @@ discard block |
||
| 503 | 503 | * @param int $current_page |
| 504 | 504 | * @return array lik EEM_Base::get_all's $query_params parameter |
| 505 | 505 | */ |
| 506 | - protected function get_query_params($model, $per_page=10,$current_page=10){ |
|
| 506 | + protected function get_query_params($model, $per_page = 10, $current_page = 10) { |
|
| 507 | 507 | $query_params = array(); |
| 508 | - $offset=($current_page-1)*$per_page; |
|
| 509 | - $query_params['limit']=array($offset,$per_page); |
|
| 510 | - $order = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] )) ? $this->_req_data['order'] : 'ASC'; |
|
| 508 | + $offset = ($current_page - 1) * $per_page; |
|
| 509 | + $query_params['limit'] = array($offset, $per_page); |
|
| 510 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
| 511 | 511 | $orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order'; |
| 512 | 512 | $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
| 513 | - $query_params['order_by']=array( $field_to_order_by => $order ); |
|
| 514 | - $search_string = array_key_exists('s',$this->_req_data) ? $this->_req_data['s'] : null; |
|
| 515 | - if(! empty($search_string)){ |
|
| 516 | - if($model instanceof EEM_Question_Group){ |
|
| 517 | - $query_params[0]=array( |
|
| 513 | + $query_params['order_by'] = array($field_to_order_by => $order); |
|
| 514 | + $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
|
| 515 | + if ( ! empty($search_string)) { |
|
| 516 | + if ($model instanceof EEM_Question_Group) { |
|
| 517 | + $query_params[0] = array( |
|
| 518 | 518 | 'OR'=>array( |
| 519 | - 'QSG_name'=>array('LIKE',"%$search_string%"), |
|
| 520 | - 'QSG_desc'=>array('LIKE',"%$search_string%")) |
|
| 519 | + 'QSG_name'=>array('LIKE', "%$search_string%"), |
|
| 520 | + 'QSG_desc'=>array('LIKE', "%$search_string%")) |
|
| 521 | 521 | ); |
| 522 | - }else{ |
|
| 523 | - $query_params[0]=array( |
|
| 524 | - 'QST_display_text'=>array('LIKE',"%$search_string%") |
|
| 522 | + } else { |
|
| 523 | + $query_params[0] = array( |
|
| 524 | + 'QST_display_text'=>array('LIKE', "%$search_string%") |
|
| 525 | 525 | ); |
| 526 | 526 | } |
| 527 | 527 | } |
@@ -569,13 +569,13 @@ discard block |
||
| 569 | 569 | * @param bool|false $count |
| 570 | 570 | * @return \EE_Soft_Delete_Base_Class[]|int |
| 571 | 571 | */ |
| 572 | - public function get_questions( $per_page=10, $current_page = 1, $count = FALSE ) { |
|
| 572 | + public function get_questions($per_page = 10, $current_page = 1, $count = FALSE) { |
|
| 573 | 573 | $QST = EEM_Question::instance(); |
| 574 | 574 | $query_params = $this->get_query_params($QST, $per_page, $current_page); |
| 575 | - if ($count){ |
|
| 576 | - $where = isset( $query_params[0] ) ? array( $query_params[0] ) : array(); |
|
| 575 | + if ($count) { |
|
| 576 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 577 | 577 | $results = $QST->count($where); |
| 578 | - }else{ |
|
| 578 | + } else { |
|
| 579 | 579 | $results = $QST->get_all($query_params); |
| 580 | 580 | } |
| 581 | 581 | return $results; |
@@ -590,10 +590,10 @@ discard block |
||
| 590 | 590 | * @param bool|false $count |
| 591 | 591 | * @return \EE_Soft_Delete_Base_Class[]|int |
| 592 | 592 | */ |
| 593 | - public function get_trashed_questions( $per_page, $current_page = 1, $count = FALSE ) { |
|
| 594 | - $query_params =$this->get_query_params( EEM_Question::instance(), $per_page, $current_page); |
|
| 595 | - $where = isset( $query_params[0] ) ? array($query_params[0]) : array(); |
|
| 596 | - $questions =$count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params); |
|
| 593 | + public function get_trashed_questions($per_page, $current_page = 1, $count = FALSE) { |
|
| 594 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
| 595 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
| 596 | + $questions = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params); |
|
| 597 | 597 | return $questions; |
| 598 | 598 | } |
| 599 | 599 | |
@@ -605,11 +605,11 @@ discard block |
||
| 605 | 605 | * @param bool|false $count |
| 606 | 606 | * @return \EE_Soft_Delete_Base_Class[] |
| 607 | 607 | */ |
| 608 | - public function get_question_groups( $per_page, $current_page = 1, $count = FALSE ) { |
|
| 608 | + public function get_question_groups($per_page, $current_page = 1, $count = FALSE) { |
|
| 609 | 609 | /** @type EEM_Question_Group $questionGroupModel */ |
| 610 | - $questionGroupModel=EEM_Question_Group::instance(); |
|
| 611 | - $query_params=$this->get_query_params( $questionGroupModel, $per_page, $current_page ); |
|
| 612 | - $questionGroups=$questionGroupModel->get_all($query_params);//note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 610 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
| 611 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
| 612 | + $questionGroups = $questionGroupModel->get_all($query_params); //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
| 613 | 613 | return $questionGroups; |
| 614 | 614 | } |
| 615 | 615 | |
@@ -626,36 +626,36 @@ discard block |
||
| 626 | 626 | |
| 627 | 627 | $this->_template_args['values'] = $this->_yes_no_values; |
| 628 | 628 | |
| 629 | - $this->_template_args['use_captcha'] = isset( EE_Registry::instance()->CFG->registration->use_captcha ) ? EE_Registry::instance()->CFG->registration->use_captcha : FALSE; |
|
| 630 | - $this->_template_args['show_captcha_settings'] = $this->_template_args['use_captcha'] ? 'style="display:table-row;"': ''; |
|
| 629 | + $this->_template_args['use_captcha'] = isset(EE_Registry::instance()->CFG->registration->use_captcha) ? EE_Registry::instance()->CFG->registration->use_captcha : FALSE; |
|
| 630 | + $this->_template_args['show_captcha_settings'] = $this->_template_args['use_captcha'] ? 'style="display:table-row;"' : ''; |
|
| 631 | 631 | |
| 632 | - $this->_template_args['recaptcha_publickey'] = isset( EE_Registry::instance()->CFG->registration->recaptcha_publickey ) ? stripslashes( EE_Registry::instance()->CFG->registration->recaptcha_publickey ) : ''; |
|
| 633 | - $this->_template_args['recaptcha_privatekey'] = isset( EE_Registry::instance()->CFG->registration->recaptcha_privatekey ) ? stripslashes( EE_Registry::instance()->CFG->registration->recaptcha_privatekey ) : ''; |
|
| 634 | - $this->_template_args['recaptcha_width'] = isset( EE_Registry::instance()->CFG->registration->recaptcha_width ) ? absint( EE_Registry::instance()->CFG->registration->recaptcha_width ) : 500; |
|
| 632 | + $this->_template_args['recaptcha_publickey'] = isset(EE_Registry::instance()->CFG->registration->recaptcha_publickey) ? stripslashes(EE_Registry::instance()->CFG->registration->recaptcha_publickey) : ''; |
|
| 633 | + $this->_template_args['recaptcha_privatekey'] = isset(EE_Registry::instance()->CFG->registration->recaptcha_privatekey) ? stripslashes(EE_Registry::instance()->CFG->registration->recaptcha_privatekey) : ''; |
|
| 634 | + $this->_template_args['recaptcha_width'] = isset(EE_Registry::instance()->CFG->registration->recaptcha_width) ? absint(EE_Registry::instance()->CFG->registration->recaptcha_width) : 500; |
|
| 635 | 635 | |
| 636 | 636 | $this->_template_args['recaptcha_theme_options'] = array( |
| 637 | - array('id' => 'red','text'=> __('Red', 'event_espresso')), |
|
| 638 | - array('id' => 'white','text'=> __('White', 'event_espresso')), |
|
| 639 | - array('id' => 'blackglass','text'=> __('Blackglass', 'event_espresso')), |
|
| 640 | - array('id' => 'clean','text'=> __('Clean', 'event_espresso')) |
|
| 637 | + array('id' => 'red', 'text'=> __('Red', 'event_espresso')), |
|
| 638 | + array('id' => 'white', 'text'=> __('White', 'event_espresso')), |
|
| 639 | + array('id' => 'blackglass', 'text'=> __('Blackglass', 'event_espresso')), |
|
| 640 | + array('id' => 'clean', 'text'=> __('Clean', 'event_espresso')) |
|
| 641 | 641 | ); |
| 642 | - $this->_template_args['recaptcha_theme'] = isset( EE_Registry::instance()->CFG->registration->recaptcha_theme ) ? EE_Registry::instance()->CFG->registration->get_pretty( 'recaptcha_theme' ) : 'clean'; |
|
| 642 | + $this->_template_args['recaptcha_theme'] = isset(EE_Registry::instance()->CFG->registration->recaptcha_theme) ? EE_Registry::instance()->CFG->registration->get_pretty('recaptcha_theme') : 'clean'; |
|
| 643 | 643 | |
| 644 | 644 | $this->_template_args['recaptcha_language_options'] = array( |
| 645 | - array('id' => 'en','text'=> __('English', 'event_espresso')), |
|
| 646 | - array('id' => 'es','text'=> __('Spanish', 'event_espresso')), |
|
| 647 | - array('id' => 'nl','text'=> __('Dutch', 'event_espresso')), |
|
| 648 | - array('id' => 'fr','text'=> __('French', 'event_espresso')), |
|
| 649 | - array('id' => 'de','text'=> __('German', 'event_espresso')), |
|
| 650 | - array('id' => 'pt','text'=> __('Portuguese', 'event_espresso')), |
|
| 651 | - array('id' => 'ru','text'=> __('Russian', 'event_espresso')), |
|
| 652 | - array('id' => 'tr','text'=> __('Turkish', 'event_espresso')) |
|
| 645 | + array('id' => 'en', 'text'=> __('English', 'event_espresso')), |
|
| 646 | + array('id' => 'es', 'text'=> __('Spanish', 'event_espresso')), |
|
| 647 | + array('id' => 'nl', 'text'=> __('Dutch', 'event_espresso')), |
|
| 648 | + array('id' => 'fr', 'text'=> __('French', 'event_espresso')), |
|
| 649 | + array('id' => 'de', 'text'=> __('German', 'event_espresso')), |
|
| 650 | + array('id' => 'pt', 'text'=> __('Portuguese', 'event_espresso')), |
|
| 651 | + array('id' => 'ru', 'text'=> __('Russian', 'event_espresso')), |
|
| 652 | + array('id' => 'tr', 'text'=> __('Turkish', 'event_espresso')) |
|
| 653 | 653 | ); |
| 654 | - $this->_template_args['recaptcha_language'] = isset( EE_Registry::instance()->CFG->registration->recaptcha_language ) ? EE_Registry::instance()->CFG->registration->recaptcha_language : 'en'; |
|
| 654 | + $this->_template_args['recaptcha_language'] = isset(EE_Registry::instance()->CFG->registration->recaptcha_language) ? EE_Registry::instance()->CFG->registration->recaptcha_language : 'en'; |
|
| 655 | 655 | |
| 656 | - $this->_set_add_edit_form_tags( 'update_reg_form_settings' ); |
|
| 657 | - $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
| 658 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( REGISTRATION_FORM_TEMPLATE_PATH . 'reg_form_settings.template.php', $this->_template_args, TRUE ); |
|
| 656 | + $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
| 657 | + $this->_set_publish_post_box_vars(NULL, FALSE, FALSE, NULL, FALSE); |
|
| 658 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_TEMPLATE_PATH.'reg_form_settings.template.php', $this->_template_args, TRUE); |
|
| 659 | 659 | $this->display_admin_page_with_sidebar(); |
| 660 | 660 | } |
| 661 | 661 | |
@@ -1,6 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
| 2 | +if (!defined('EVENT_ESPRESSO_VERSION') ) { |
|
| 3 | 3 | exit('NO direct script access allowed'); |
| 4 | +} |
|
| 4 | 5 | |
| 5 | 6 | /** |
| 6 | 7 | * Event Espresso |
@@ -330,14 +331,9 @@ discard block |
||
| 330 | 331 | else if ( $fieldName == 'QST_admin_label' && ( isset( $this->_req_data['QST_admin_label'] ) && empty( $this->_req_data['QST_admin_label'] ) )) { |
| 331 | 332 | $QST_text = isset( $this->_req_data['QST_display_text'] ) ? $this->_req_data['QST_display_text'] : '' ; |
| 332 | 333 | $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text,10)); |
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - else if ( $fieldName == 'QST_admin_only' && ( !isset( $this->_req_data['QST_admin_only'] ) ) ) { |
|
| 334 | + } else if ( $fieldName == 'QST_admin_only' && ( !isset( $this->_req_data['QST_admin_only'] ) ) ) { |
|
| 337 | 335 | $set_column_values[$fieldName] = 0; |
| 338 | - } |
|
| 339 | - |
|
| 340 | - else if ( $fieldName == 'QST_max' ) { |
|
| 336 | + } else if ( $fieldName == 'QST_max' ) { |
|
| 341 | 337 | $qst_system = EEM_Question::instance()->get_var( |
| 342 | 338 | array( |
| 343 | 339 | array( |
@@ -390,7 +386,7 @@ discard block |
||
| 390 | 386 | $question=$this->_question_model->get_one_by_ID($ID); |
| 391 | 387 | $additional_hidden_fields=array('QST_ID'=>array('type'=>'hidden','value'=>$ID)); |
| 392 | 388 | $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
| 393 | - }else{ |
|
| 389 | + } else{ |
|
| 394 | 390 | $question= EE_Question::new_instance(); |
| 395 | 391 | $question->set_order_to_latest(); |
| 396 | 392 | $this->_set_add_edit_form_tags('insert_question'); |
@@ -421,7 +417,7 @@ discard block |
||
| 421 | 417 | $ID=$this->_question_model->insert($set_column_values); |
| 422 | 418 | $success = $ID ? true : false; |
| 423 | 419 | $action_desc = 'added'; |
| 424 | - }else{ |
|
| 420 | + } else{ |
|
| 425 | 421 | $ID=absint($this->_req_data['QST_ID']); |
| 426 | 422 | $pk=$this->_question_model->primary_key_name(); |
| 427 | 423 | $wheres=array($pk=>$ID); |
@@ -442,7 +438,7 @@ discard block |
||
| 442 | 438 | $option_req_index=$this->_get_option_req_data_index($option_ID); |
| 443 | 439 | if($option_req_index!==FALSE){ |
| 444 | 440 | $option->save($this->_req_data['question_options'][$option_req_index]); |
| 445 | - }else{ |
|
| 441 | + } else{ |
|
| 446 | 442 | //not found, remove it |
| 447 | 443 | $option->delete(); |
| 448 | 444 | } |
@@ -519,7 +515,7 @@ discard block |
||
| 519 | 515 | 'QSG_name'=>array('LIKE',"%$search_string%"), |
| 520 | 516 | 'QSG_desc'=>array('LIKE',"%$search_string%")) |
| 521 | 517 | ); |
| 522 | - }else{ |
|
| 518 | + } else{ |
|
| 523 | 519 | $query_params[0]=array( |
| 524 | 520 | 'QST_display_text'=>array('LIKE',"%$search_string%") |
| 525 | 521 | ); |
@@ -575,7 +571,7 @@ discard block |
||
| 575 | 571 | if ($count){ |
| 576 | 572 | $where = isset( $query_params[0] ) ? array( $query_params[0] ) : array(); |
| 577 | 573 | $results = $QST->count($where); |
| 578 | - }else{ |
|
| 574 | + } else{ |
|
| 579 | 575 | $results = $QST->get_all($query_params); |
| 580 | 576 | } |
| 581 | 577 | return $results; |