function checkBeforeWrite($postData)
 {
     // check if a name was entered
     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_FIELD'));
     } else {
         $postData['name'] = $this->onlyLettersAndNumbers($this->revert_specialchars(str_replace(' ', '_', $postData['name'])));
         if (substr($postData['name'], 0, 5) != 'aics_') {
             $postData['name'] = 'aics_' . $postData['name'];
         }
         if ($this->nameUsed(trim($postData['name']), $postData['id'])) {
             $this->_app->_session->set('isOK:' . $this->_sTask, false);
             $this->_app->_session->set('errorMsg:' . $this->_sTask, JText::_('COM_AICONTACTSAFE_THIS_NAME_WAS_USED_ON_ANOTHER_FIELD_PLEASE_USE_A_DIFFERENT_ONE'));
         } else {
             $postData = parent::checkBeforeWrite($postData);
         }
     }
     $postData['field_values'] = JRequest::getVar('field_values', '', 'post', 'string', JREQUEST_ALLOWRAW);
     if (array_key_exists('field_values', $postData) && substr(trim($postData['field_values']), -1, 1) == ';') {
         $postData['field_values'] = substr(trim($postData['field_values']), 0, -1);
     }
     $postData['field_label'] = JRequest::getVar('field_label', '', 'post', 'string', JREQUEST_ALLOWHTML);
     $postData['field_label'] = $this->replace_specialchars($postData['field_label']);
     $postData['label_parameters'] = $this->replace_specialchars($postData['label_parameters']);
     $postData['field_label_message'] = JRequest::getVar('field_label_message', '', 'post', 'string', JREQUEST_ALLOWHTML);
     $postData['field_label_message'] = $this->replace_specialchars($postData['field_label_message']);
     $postData['label_message_parameters'] = $this->replace_specialchars($postData['label_message_parameters']);
     $postData['field_parameters'] = $this->replace_specialchars($postData['field_parameters']);
     $postData['field_sufix'] = $this->replace_specialchars($postData['field_sufix']);
     $postData['field_prefix'] = $this->replace_specialchars($postData['field_prefix']);
     $postData['label_after_field'] = array_key_exists('label_after_field', $postData) && $postData['label_after_field'] ? 1 : 0;
     $postData['send_message'] = array_key_exists('send_message', $postData) && $postData['send_message'] ? 1 : 0;
     $postData['field_required'] = array_key_exists('field_required', $postData) && $postData['field_required'] ? 1 : 0;
     $postData['field_in_message'] = array_key_exists('field_in_message', $postData) && $postData['field_in_message'] ? 1 : 0;
     $postData['published'] = array_key_exists('published', $postData) && $postData['published'] ? 1 : 0;
     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:
             // check if a name was entered
             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']);
             }
             // read the order of each field that can be selected
             $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);
     $datenow = JFactory::getDate();
     $postData['date_added'] = $datenow->toSQL();
     $postData['last_update'] = $datenow->toSQL();
     return $postData;
 }