function __construct($default = array())
 {
     parent::__construct($default);
     // if no order is used, use the 'date_added' field
     if (strlen($this->filter_order) == 0) {
         $this->filter_order = 'ordering';
         $this->filter_order_Dir = 'ASC';
     }
 }
 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 deleteData()
 {
     $wasDeleted = parent::deleteData();
     // initialize different variables
     if ($wasDeleted) {
         // read the ids of the records seleted for deletion
         $cid = JRequest::getVar('cid', array(), 'post', 'array');
         JArrayHelper::toInteger($cid);
         if (count($cid) > 0) {
             $cids = implode(',', $cid);
         } else {
             $cids = '-1';
         }
         $this->deleteOtherInfo($cids);
     }
     return true;
 }
 function deleteData()
 {
     parent::deleteData();
     // initialize different variables
     $db = JFactory::getDBO();
     // read the ids of the records seleted for deletion
     $cid = JRequest::getVar('cid', array(), 'post', 'array');
     JArrayHelper::toInteger($cid);
     if (count($cid) > 0) {
         $profiles_ids = $cid;
         $cids = implode(',', $cid);
     } else {
         $profiles_ids = null;
         $cids = '-1';
     }
     $query = 'DELETE FROM `#__aicontactsafe_contactinformations` where profile_id IN ( ' . $cids . ' )';
     // delete records
     $db->setQuery($query);
     if (!$db->query()) {
         JError::raiseError(500, $db->getErrorMsg());
         return false;
     }
     if (is_array($profiles_ids)) {
         // import joomla clases to manage file system
         jimport('joomla.filesystem.file');
         foreach ($profiles_ids as $pf_id) {
             $css_file = JPath::clean(JPATH_ROOT . '/' . 'media' . '/' . 'aicontactsafe' . '/' . 'cssprofiles' . '/' . 'profile_css_' . $pf_id . '.css');
             if (JFile::exists($css_file)) {
                 JFile::delete($css_file);
             }
             $mail_file = JPath::clean(JPATH_ROOT . '/' . 'media' . '/' . 'aicontactsafe' . '/' . 'mailtemplates' . '/' . 'mail_' . $pf_id . '.php');
             if (JFile::exists($mail_file)) {
                 JFile::delete($mail_file);
             }
         }
     }
     return true;
 }
 function checkBeforeWrite($postData)
 {
     $postData = parent::checkBeforeWrite($postData);
     $datenow = JFactory::getDate();
     $postData['date_added'] = $datenow->toSQL();
     $postData['last_update'] = $datenow->toSQL();
     return $postData;
 }