english/administrator/components/com_aicontactsafe/models/profiles.php
// function to check/add/modify different fields before writing them to the database
function to check/add/modify different fields before writing them to the database
function to check / add / modify different fields before writing them to the database
function checkBeforeWrite($postData) {
		$postData = parent::checkBeforeWrite($postData);
		switch( true ) {
			case $this->_task == 'save_contact' or $this->_task == 'apply_contact' :
				$postData['contact_info'] = JRequest::getVar('contact_info', '', 'post', 'string', JREQUEST_ALLOWRAW);
				$postData['contact_info'] = $this->replace_specialchars($postData['contact_info']);
				$postData['plg_contact_info'] = (array_key_exists('plg_contact_info',$postData) && $postData['plg_contact_info'])?1:0;
				break;
			case $this->_task == 'save_css' or $this->_task == 'apply_css' :
				$postData['use_message_css'] = (array_key_exists('use_message_css',$postData) && $postData['use_message_css'])?1:0;
				$postData['profile_css_code'] = JRequest::getVar('profile_css_code', '', 'post', 'string', JREQUEST_ALLOWRAW);
				break;
			case $this->_task == 'save_email' or $this->_task == 'apply_email' :
				$postData['use_mail_template'] = (array_key_exists('use_mail_template',$postData) && $postData['use_mail_template'])?1:0;
				$postData['mail_template'] = JRequest::getVar('mail_template', '', 'post', 'string', JREQUEST_ALLOWRAW);
				break;
			default :
				if (strlen(trim($postData['name'])) == 0) {
					$this->_app->_session->set( 'isOK:' . $this->_sTask, false );
					$this->_app->_session->set( 'errorMsg:' . $this->_sTask, JText::_('COM_AICONTACTSAFE_PLEASE_ENTER_THE_NAME_OF_THE_PROFILE') );
				}
				$postData['use_ajax'] = (array_key_exists('use_ajax',$postData) && $postData['use_ajax'])?1:0;
				$postData['captcha_backgroundTransparent'] = (array_key_exists('captcha_backgroundTransparent',$postData) && $postData['captcha_backgroundTransparent'])?1:0;
				$postData['always_send_to_email_address'] = (array_key_exists('always_send_to_email_address',$postData) && $postData['always_send_to_email_address'])?1:0;
				$postData['record_message'] = (array_key_exists('record_message',$postData) && $postData['record_message'])?1:0;
				$postData['record_fields'] = (array_key_exists('record_fields',$postData) && $postData['record_fields'])?1:0;
				if ($postData['record_fields']) {
					$postData['record_message'] = 1;
				}
				$postData['use_random_letters'] = (array_key_exists('use_random_letters',$postData) && $postData['use_random_letters'])?1:0;
				$postData['required_field_mark'] = JRequest::getVar('required_field_mark', '', 'post', 'string', JREQUEST_ALLOWHTML);
				$postData['required_field_mark'] = $this->replace_specialchars($postData['required_field_mark']);
				$postData['published'] = (array_key_exists('published',$postData) && $postData['published'])?1:0;
				$postData['set_default'] = (array_key_exists('set_default',$postData) && $postData['set_default'])?1:0;
				if ( $postData['set_default'] == 1 ) {
					$postData['published'] = 1;
					$this->resetDefaultProfile();
				} else {
					$postData['set_default'] = $this->checkDefaultProfile( $postData['id'] );
				}
				if ( array_key_exists('all_fields',$postData) && $postData['all_fields'] ) {
					$postData['active_fields'] = 0;
				} else {
					$fieldError = false;
					if ( $postData['name_field_id'] >0 && array_search($postData['name_field_id'],$postData['select_fields']) === false ) {
						$postData['select_fields'][] = $postData['name_field_id'];
						$fieldError = true;
					}
					if ( $postData['email_field_id'] > 0 && array_search($postData['email_field_id'],$postData['select_fields']) === false ) {
						$postData['select_fields'][] = $postData['email_field_id'];
						$fieldError = true;
					}
					if ( $postData['subject_field_id'] > 0 && array_search($postData['subject_field_id'],$postData['select_fields']) === false ) {
						$postData['select_fields'][] = $postData['subject_field_id'];
						$fieldError = true;
					}
					if ( $postData['send_to_sender_field_id'] > 0 && array_search($postData['send_to_sender_field_id'],$postData['select_fields']) === false ) {
						$postData['select_fields'][] = $postData['send_to_sender_field_id'];
						$fieldError = true;
					}
					if ( $fieldError ) {
						$this->_app->enqueueMessage(JText::_('COM_AICONTACTSAFE_SELECTED_FIELDS_ERROR'), 'error');
					}
					$postData['active_fields'] = implode(',', $postData['select_fields']);
				}
				$fields_id = array();
				$select_fields_count = $postData['select_fields_count'];
				for($i=0;$i<$select_fields_count;$i++) {
					$fields_id[$postData['order_field_id_'.$i]] = $postData['order_field_'.$i];
				}
				asort($fields_id);
				foreach($fields_id as $key=>$order) {
					$fields_id[$key] = $key;
				}
				$postData['fields_order'] = implode(',',$fields_id);
				break;
		}
		return $postData;
	}
function checkBeforeWrite ( $ postData ) { $ postData = parent :: checkBeforeWrite ( $ postData ) ; switch ( true ) { case $ this -> _task == 'save_contact' or $ this -> _task == 'apply_contact' : $ postData [ 'contact_info' ] = JRequest :: getVar ( 'contact_info' , '' , 'post' , 'string' , JREQUEST_ALLOWRAW ) ; $ postData [ 'contact_info' ] = $ this -> replace_specialchars ( $ postData [ 'contact_info' ] ) ; $ postData [ 'plg_contact_info' ] = ( array_key_exists ( 'plg_contact_info' , $ postData ) && $ postData [ 'plg_contact_info' ] ) ? 1 : 0 ; break ; case $ this -> _task == 'save_css' or $ this -> _task == 'apply_css' : $ postData [ 'use_message_css' ] = ( array_key_exists ( 'use_message_css' , $ postData ) && $ postData [ 'use_message_css' ] ) ? 1 : 0 ; $ postData [ 'profile_css_code' ] = JRequest :: getVar ( 'profile_css_code' , '' , 'post' , 'string' , JREQUEST_ALLOWRAW ) ; break ; case $ this -> _task == 'save_email' or $ this -> _task == 'apply_email' : $ postData [ 'use_mail_template' ] = ( array_key_exists ( 'use_mail_template' , $ postData ) && $ postData [ 'use_mail_template' ] ) ? 1 : 0 ; $ postData [ 'mail_template' ] = JRequest :: getVar ( 'mail_template' , '' , 'post' , 'string' , JREQUEST_ALLOWRAW ) ; break ; default : if ( strlen ( trim ( $ postData [ 'name' ] ) ) == 0 ) { $ this -> _app -> _session -> set ( 'isOK:' . $ this -> _sTask , false ) ; $ this -> _app -> _session -> set ( 'errorMsg:' . $ this -> _sTask , JText :: _ ( 'COM_AICONTACTSAFE_PLEASE_ENTER_THE_NAME_OF_THE_PROFILE' ) ) ; } $ postData [ 'use_ajax' ] = ( array_key_exists ( 'use_ajax' , $ postData ) && $ postData [ 'use_ajax' ] ) ? 1 : 0 ; $ postData [ 'captcha_backgroundTransparent' ] = ( array_key_exists ( 'captcha_backgroundTransparent' , $ postData ) && $ postData [ 'captcha_backgroundTransparent' ] ) ? 1 : 0 ; $ postData [ 'always_send_to_email_address' ] = ( array_key_exists ( 'always_send_to_email_address' , $ postData ) && $ postData [ 'always_send_to_email_address' ] ) ? 1 : 0 ; $ postData [ 'record_message' ] = ( array_key_exists ( 'record_message' , $ postData ) && $ postData [ 'record_message' ] ) ? 1 : 0 ; $ postData [ 'record_fields' ] = ( array_key_exists ( 'record_fields' , $ postData ) && $ postData [ 'record_fields' ] ) ? 1 : 0 ; if ( $ postData [ 'record_fields' ] ) { $ postData [ 'record_message' ] = 1 ; } $ postData [ 'use_random_letters' ] = ( array_key_exists ( 'use_random_letters' , $ postData ) && $ postData [ 'use_random_letters' ] ) ? 1 : 0 ; $ postData [ 'required_field_mark' ] = JRequest :: getVar ( 'required_field_mark' , '' , 'post' , 'string' , JREQUEST_ALLOWHTML ) ; $ postData [ 'required_field_mark' ] = $ this -> replace_specialchars ( $ postData [ 'required_field_mark' ] ) ; $ postData [ 'published' ] = ( array_key_exists ( 'published' , $ postData ) && $ postData [ 'published' ] ) ? 1 : 0 ; $ postData [ 'set_default' ] = ( array_key_exists ( 'set_default' , $ postData ) && $ postData [ 'set_default' ] ) ? 1 : 0 ; if ( $ postData [ 'set_default' ] == 1 ) { $ postData [ 'published' ] = 1 ; $ this -> resetDefaultProfile ( ) ; } else { $ postData [ 'set_default' ] = $ this -> checkDefaultProfile ( $ postData [ 'id' ] ) ; } if ( array_key_exists ( 'all_fields' , $ postData ) && $ postData [ 'all_fields' ] ) { $ postData [ 'active_fields' ] = 0 ; } else { $ fieldError = false ; if ( $ postData [ 'name_field_id' ] > 0 && array_search ( $ postData [ 'name_field_id' ] , $ postData [ 'select_fields' ] ) === false ) { $ postData [ 'select_fields' ] [ ] = $ postData [ 'name_field_id' ] ; $ fieldError = true ; } if ( $ postData [ 'email_field_id' ] > 0 && array_search ( $ postData [ 'email_field_id' ] , $ postData [ 'select_fields' ] ) === false ) { $ postData [ 'select_fields' ] [ ] = $ postData [ 'email_field_id' ] ; $ fieldError = true ; } if ( $ postData [ 'subject_field_id' ] > 0 && array_search ( $ postData [ 'subject_field_id' ] , $ postData [ 'select_fields' ] ) === false ) { $ postData [ 'select_fields' ] [ ] = $ postData [ 'subject_field_id' ] ; $ fieldError = true ; } if ( $ postData [ 'send_to_sender_field_id' ] > 0 && array_search ( $ postData [ 'send_to_sender_field_id' ] , $ postData [ 'select_fields' ] ) === false ) { $ postData [ 'select_fields' ] [ ] = $ postData [ 'send_to_sender_field_id' ] ; $ fieldError = true ; } if ( $ fieldError ) { $ this -> _app -> enqueueMessage ( JText :: _ ( 'COM_AICONTACTSAFE_SELECTED_FIELDS_ERROR' ) , 'error' ) ; } $ postData [ 'active_fields' ] = implode ( ',' , $ postData [ 'select_fields' ] ) ; } $ fields_id = array ( ) ; $ select_fields_count = $ postData [ 'select_fields_count' ] ; for ( $ i = 0 ; $ i < $ select_fields_count ; $ i ++ ) { $ fields_id [ $ postData [ 'order_field_id_' . $ i ] ] = $ postData [ 'order_field_' . $ i ] ; } asort ( $ fields_id ) ; foreach ( $ fields_id as $ key => $ order ) { $ fields_id [ $ key ] = $ key ; } $ postData [ 'fields_order' ] = implode ( ',' , $ fields_id ) ; break ; } return $ postData ; }
function to check/add/modify different fields before writing them to the database
function to check / add / modify different fields before writing them to the database
// check if a name was entered // read the order of each field that can be selected