/**
  * 	newEntry
  *
  * @param  $map
  * 
  *
  * @return
  * 
  */
 function newEntry($map)
 {
     if ($this->processSpam(!isset($map['ufo-sign']), $map)) {
         return;
     }
     $sign = isset($map['ufo-sign']) ? $map['ufo-sign'] : '';
     $time = substr($sign, 32);
     if ($this->processSpam(md5(EasyContactFormsSecurityManager::getServerPwd() . '' . $time) . '' . $time != $sign, $map)) {
         return;
     }
     $delta = time() - intval($time);
     $mintime = EasyContactFormsApplicationSettings::getInstance()->get('FormCompletionMinTime');
     $maxtime = EasyContactFormsApplicationSettings::getInstance()->get('FormCompletionMaxTime');
     if ($this->processSpam(!empty($mintime) && $delta < $mintime, $map)) {
         return;
     }
     if ($this->processSpam(!empty($maxtime) && $delta > $maxtime, $map)) {
         return;
     }
     $fldvalues = array();
     foreach ($map as $key => $value) {
         if (!EasyContactFormsUtils::beginsWith($key, 'id-')) {
             continue;
         }
         $fldid = intval(EasyContactFormsUtils::cutPrefix($key, 'id-'));
         $value = stripslashes($value);
         $fldvalues[$fldid] = htmlspecialchars($value, ENT_QUOTES);
     }
     if ($this->processSpam(count($fldvalues) == 0, $map)) {
         return;
     }
     $formid = $this->get('id');
     if ($this->processSpam(!isset($formid) || empty($formid), $map)) {
         return;
     }
     $s = implode(',', array_keys($fldvalues));
     $query = "SELECT\n\t\t\t\tCustomFormFields.id\n\t\t\tFROM\n\t\t\t\t#wp__easycontactforms_customformfields AS CustomFormFields\n\t\t\tWHERE\n\t\t\t\tCustomFormFields.CustomForms='{$formid}'\n\t\t\t\tAND CustomFormFields.id IN ({$s})";
     $fields = EasyContactFormsDB::getObjects($query);
     if ($this->processSpam(count($fields) == 0, $map)) {
         return;
     }
     $cfe = EasyContactFormsClassLoader::getObject('CustomFormsEntries', true);
     $cfe->set('Date', date(DATE_ATOM));
     $cfe->set('CustomForms', $formid);
     if (isset($map['form-pagename'])) {
         $cfe->set('PageName', $map['form-pagename']);
         $fpstat = EasyContactFormsClassLoader::getObject('CustomFormEntryStatistics');
         $fpstat->increaseConversions($formid, $map['form-pagename']);
     }
     $map['_new_entry_id'] = $cfe->get('id');
     $query = "SELECT\n\t\t\t\tCustomFormFields.id,\n\t\t\t\tCustomFormFields.Settings,\n\t\t\t\tCustomFormFieldTypes.id AS tid,\n\t\t\t\tCustomFormFieldTypes.Description,\n\t\t\t\tCustomFormFieldTypes.ValueField\n\t\t\tFROM\n\t\t\t\t#wp__easycontactforms_customformfields AS CustomFormFields\n\t\t\tINNER JOIN\n\t\t\t\t#wp__easycontactforms_customformfieldtypes AS CustomFormFieldTypes\n\t\t\t\t\tON\n\t\t\t\t\t\tCustomFormFields.Type=CustomFormFieldTypes.id\n\t\t\tWHERE\n\t\t\t\tCustomFormFields.CustomForms='{$formid}'\n\t\t\tORDER BY\n\t\t\t\tCustomFormFields.ListPosition";
     $fields = EasyContactFormsDB::getObjects($query);
     $text = new EasyContactFormsSimpleXML('<div/>');
     $clientid = 0;
     if (!isset($map['ufo-preview'])) {
         if (isset($map['easycontactusr']) && isset($map['easycontactusr']->id) && !empty($map['easycontactusr']->id)) {
             $clientid = intval($map['easycontactusr']->id);
             $text->addAttribute('userid', $clientid);
         }
         global $current_user;
         $siteuserid = $current_user->ID;
         if (!empty($siteuserid)) {
             $siteuserid = intval($siteuserid);
         }
     }
     $clientemail = '';
     $emessagedata = (object) array();
     $attachments = (object) array();
     $attachments->confirmation = array();
     $attachments->notification = array();
     foreach ($fields as $fld) {
         $process = $fld->ValueField || $fld->tid == 14;
         if (!$process) {
             continue;
         }
         $value = isset($fldvalues[$fld->id]) ? $fldvalues[$fld->id] : '';
         $xml = simplexml_load_string($fld->Settings);
         $default = $this->getFieldValue($xml, true, 'DefaultValue', 'SetDefaultValue');
         $required = (string) $xml->Required;
         $required = $required == 'on';
         $spam = $required && $fld->tid == 14 && $value != $default;
         if ($this->processSpam($spam, $map)) {
             return;
         }
         $spam = !$required && $fld->tid == 14 && $value != '';
         if ($this->processSpam($spam, $map)) {
             return;
         }
         if ($fld->tid == 14) {
             continue;
         }
         $validate = isset($xml->Validate) && (string) $xml->Validate == 'on';
         if ($clientemail == '' && $fld->tid == 5 && $validate) {
             $clientemail = $value;
         }
         $fldlabel = (string) $xml->Label;
         $fldlabel = $fldlabel == '' ? $fld->Description : $fldlabel;
         $displayvalue = $value;
         $displayxmlvalue = null;
         $fld = EasyContactFormsClassLoader::getObject('CustomFormFields', true, $fld->id);
         $phase = (object) array('index' => 6);
         include $fld->getTMPFileName('proc');
         $d = $this->getTemplateTag($fld->get('Description'), $fld->get('id'));
         $d = trim($d, '{}');
         $emessagedata->{$d} = $displayvalue;
         $fldlabel = $text->prepare($fldlabel);
         $displayvalue = $text->prepare($displayvalue);
         $value = $text->prepare($value);
         $iddiv = $text->addChild('div');
         $iddiv->addAttribute('id', $fld->get('id'));
         $h1 = $iddiv->addChild('h1', $value);
         $h1->addAttribute('style', 'display:none');
         $ldiv = $iddiv->addChild('div');
         $label = $ldiv->addChild('label', $fldlabel);
         $label->addAttribute('class', 'ufo-cform-label');
         if (is_null($displayxmlvalue)) {
             $iddiv->addChild('div', $displayvalue);
         } else {
             $div = $iddiv->addChild('div');
             EasyContactFormsSimpleXML::mergeXML($div, $displayxmlvalue);
         }
     }
     $cfe->set('Content', $text->asXML());
     if (!empty($siteuserid)) {
         $cfe->set('SiteUser', $siteuserid);
     }
     $cfe->save();
     unset($text->attributes()->userid);
     foreach ($text->children() as $child) {
         unset($child->attributes()->id);
         unset($child->h1);
     }
     $text->addAttribute('class', 'ufo-form-envelope');
     $this->doEmailing($text->asCHTML(), $emessagedata, $clientemail, $clientid, $attachments);
     $this->set('TotalEntries', $this->get('TotalEntries') + 1);
     $this->save();
 }