/**
  * 	process
  *
  * 	Applies the form entry data to db
  *
  * @param int $ownerid
  * 	User who owns the results
  */
 function process($ownerid = NULL)
 {
     $form = EasyContactFormsClassLoader::getObject('CustomForms', true, $this->get('CustomForms'));
     if (!class_exists('EasyContactFormsT')) {
         $l_locale = get_locale();
         $tag = strtolower(str_replace('_', '-', $l_locale));
         require_once 'easy-contact-forms-strings.php';
         if (!@(include_once 'easy-contact-forms-resources_' . $tag . '.php')) {
             require_once 'easy-contact-forms-resources_en-gb.php';
         }
     }
     if (is_null($ownerid)) {
         $ownerid = $form->get('ObjectOwner');
     }
     $content = $this->get('Content');
     $xml = simplexml_load_string($content);
     $userid = (string) $xml->attributes()->userid;
     $userid = empty($userid) ? NULL : intval($userid);
     if (is_null($userid)) {
         $users = EasyContactFormsClassLoader::getObject('Users');
         $user = $users->getEmptyObject(array());
         $user->set('ObjectOwner', $ownerid);
         $siteuserid = $this->get('SiteUser');
         $siteuserid = empty($siteuserid) ? NULL : $siteuserid;
         if (!is_null($siteuserid)) {
             $usrquery = "SELECT\n\t\t\t\t\t\t\tuser_login AS username,\n\t\t\t\t\t\t\tuser_email AS email,\n\t\t\t\t\t\t\tdisplay_name AS name\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t#wp__users\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tID='{$siteuserid}'";
             $susr = EasyContactFormsDB::getObjects($usrquery);
             $susr = $susr[0];
             $susrname = !empty($susr->name) ? $susr->name : $susr->username;
             if (!empty($susrname)) {
                 $user->set('Description', $susrname);
             }
             if (!empty($susr->email)) {
                 $user->set('email', $susr->email);
             }
             $user->set('CMSId', $siteuserid);
         }
     } else {
         $user = EasyContactFormsClassLoader::getObject('Users', true, $userid);
         $user->set('Role', NULL);
     }
     $fields = EasyContactFormsClassLoader::getObject('CustomFormFields');
     foreach ($xml->children() as $xmlfld) {
         $value = (string) $xmlfld->h1;
         unset($xmlfld->h1);
         if (empty($value)) {
             continue;
         }
         $fldid = (string) $xmlfld->attributes()->id;
         $fldid = intval($fldid);
         $settings = $fields->getValue('Settings', $fldid);
         if (empty($settings)) {
             continue;
         }
         $settings = simplexml_load_string($settings);
         $link = (string) $settings->LinkToAppField;
         if (!empty($link)) {
             $link = explode('_', $link);
             if (count($link) > 1) {
                 $user->set($link[1], $value);
             }
         }
     }
     $content = $xml->asXML();
     $user->set('History', $content . '<br /><br />' . $user->get('History'));
     $user->save();
     $this->set('Date', EasyContactFormsUtils::getDate($this->get('Date'), false, true, true));
     $this->set('Users', $user->get('id'));
     $this->save();
     $form->set('TotalProcessedEntries', $form->get('TotalProcessedEntries') + 1);
     $form->save();
 }
    /**
     * 	getMainForm
     *
     * 	prepares the view data and finally passes it to the html template
     *
     * @param array $formmap
     * 	request data
     */
    function getMainForm($formmap)
    {
        $fields = array();
        $fields[] = 'id';
        $fields[] = 'Description';
        $fields[] = 'ContactType';
        $fields[] = 'Role';
        $fields[] = 'Name';
        $fields[] = 'CMSId';
        $fields[] = 'Notes';
        $fields[] = 'ContactField3';
        $fields[] = 'ContactField4';
        $fields[] = 'Birthday';
        $fields[] = 'Country';
        $fields[] = 'City';
        $fields[] = 'State';
        $fields[] = 'Zip';
        $fields[] = 'Address';
        $fields[] = 'email';
        $fields[] = 'email2';
        $fields[] = 'Cell';
        $fields[] = 'Phone1';
        $fields[] = 'Phone2';
        $fields[] = 'Phone3';
        $fields[] = 'SkypeId';
        $fields[] = 'Website';
        $fields[] = 'Comment';
        $fields[] = 'History';
        $obj = $this->formInit($formmap, $fields);
        $obj->set('Description', htmlspecialchars($obj->get('Description'), ENT_QUOTES));
        $obj->set('Name', htmlspecialchars($obj->get('Name'), ENT_QUOTES));
        $obj->CMSId = (object) array();
        $obj->CMSId->view = $obj;
        $obj->CMSId->field = 'CMSId';
        $obj->CMSId->config['t'] = 'Users';
        $obj->CMSId->config['m2'] = 'getEUserASList';
        $obj->CMSId->inpstyle = " style='width:100%'";
        $obj->set('Notes', htmlspecialchars($obj->get('Notes')));
        $obj->set('ContactField3', htmlspecialchars($obj->get('ContactField3')));
        $obj->set('ContactField4', htmlspecialchars($obj->get('ContactField4')));
        $obj->Birthday = EasyContactFormsUtils::getDate($obj->get('Birthday'));
        $obj->set('Country', htmlspecialchars($obj->get('Country'), ENT_QUOTES));
        $obj->set('City', htmlspecialchars($obj->get('City'), ENT_QUOTES));
        $obj->set('State', htmlspecialchars($obj->get('State'), ENT_QUOTES));
        $obj->set('Zip', htmlspecialchars($obj->get('Zip'), ENT_QUOTES));
        $obj->set('Address', htmlspecialchars($obj->get('Address')));
        $obj->set('email', htmlspecialchars($obj->get('email'), ENT_QUOTES));
        $obj->set('email2', htmlspecialchars($obj->get('email2'), ENT_QUOTES));
        $obj->set('Cell', htmlspecialchars($obj->get('Cell'), ENT_QUOTES));
        $obj->set('Phone1', htmlspecialchars($obj->get('Phone1'), ENT_QUOTES));
        $obj->set('Phone2', htmlspecialchars($obj->get('Phone2'), ENT_QUOTES));
        $obj->set('Phone3', htmlspecialchars($obj->get('Phone3'), ENT_QUOTES));
        $obj->set('SkypeId', htmlspecialchars($obj->get('SkypeId'), ENT_QUOTES));
        $obj->set('Website', htmlspecialchars($obj->get('Website'), ENT_QUOTES));
        $obj->set('Comment', htmlspecialchars($obj->get('Comment')));
        ?>
		<input type='hidden' class='ufostddata' id='t' value='<?php 
        echo $obj->type;
        ?>
'>
		<input type='hidden' class='ufostddata' id='oid' value='<?php 
        echo $obj->getId();
        ?>
'>
		<?php 
        require_once 'views/easy-contact-forms-usersmainform.php';
    }
 /**
  * 	fillInTemplate
  *
  * 	fills the template with object data
  *
  * @param object $template
  * 	email template
  * @param string $object
  * 	object type
  *
  * @return object
  * 	the filled template
  */
 function fillInTemplate($template, $object)
 {
     if (!is_object($object)) {
         $template->body = str_replace('{messagebody}', $object, $template->body);
     } else {
         $fields = get_object_vars($object);
         foreach ($fields as $fname => $fvalue) {
             $value = (EasyContactFormsUtils::endsWith($fname, 'date') || EasyContactFormsUtils::endsWith($fname, 'deadline')) && is_numeric($fvalue) ? EasyContactFormsUtils::getDate($fvalue) : $fvalue;
             if (isset($template->ishtml) && $template->ishtml) {
                 $value = nl2br('' . $value);
             }
             if (isset($template->body)) {
                 $fldcheck = EasyContactFormsBackOffice::fldTemplateReplace($template->body, $fname, $value);
                 if (!$fldcheck) {
                     $template->body = str_replace('{' . $fname . '}', $value, $template->body);
                 } else {
                     $template->body = $fldcheck;
                 }
             }
             if (isset($template->subject)) {
                 $fldcheck = EasyContactFormsBackOffice::fldTemplateReplace($template->subject, $fname, $value);
                 if (!$fldcheck) {
                     $template->subject = str_replace('{' . $fname . '}', $value, $template->body);
                 } else {
                     $template->subject = $fldcheck;
                 }
             }
         }
     }
     return $template;
 }
 /**
  * 	processEntry
  *
  * @param  $map
  * 
  *
  * @return
  * 
  */
 function processEntry($map)
 {
     $currentuser = isset($map['easycontactusr']) ? $map['easycontactusr'] : NULL;
     if (is_null($currentuser)) {
         return;
     }
     $newobjectmap = array();
     $newobjectmap['easycontactusr'] = $currentuser;
     $id = intval($map['oid']);
     if ($id == 0) {
         return;
     }
     $entry = EasyContactFormsClassLoader::getObject('CustomFormsEntries', TRUE, $id);
     $content = $entry->get('Content');
     $xml = simplexml_load_string($content);
     $userid = (string) $xml->attributes()->userid;
     $userid = empty($userid) ? NULL : intval($userid);
     if (empty($userid)) {
         $users = EasyContactFormsClassLoader::getObject('Users');
         $user = $users->getEmptyObject($newobjectmap);
         $siteuserid = $entry->get('SiteUser');
         $siteuserid = empty($siteuserid) ? NULL : $siteuserid;
         if (!is_null($siteuserid)) {
             $usrquery = "SELECT\n\t\t\t\t\t\t\tuser_login AS username,\n\t\t\t\t\t\t\tuser_email AS email,\n\t\t\t\t\t\t\tdisplay_name AS name\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t#wp__users\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tID='{$siteuserid}'";
             $susr = EasyContactFormsDB::getObjects($usrquery);
             $susr = $susr[0];
             $susrname = !empty($susr->name) ? $susr->name : $susr->username;
             if (empty($susrname)) {
                 $user->set('Description', $susrname);
             }
             if (empty($susr->email)) {
                 $user->set('email', $susr->email);
             }
             $user->set('CMSId', $siteuserid);
         }
     } else {
         $user = EasyContactFormsClassLoader::getObject('Users', true, $userid);
         $user->user = $currentuser;
     }
     $user->save();
     $entry->set('Date', EasyContactFormsUtils::getDate($entry->get('Date'), false, true, true));
     $entry->set('Users', $user->get('id'));
     $entry->save();
     $form = EasyContactFormsClassLoader::getObject('CustomForms', true, $entry->get('CustomForms'));
     $form->set('TotalProcessedEntries', $form->get('TotalProcessedEntries') + 1);
     $form->save();
     unset($map['oid']);
     unset($map['n']);
     $mn = isset($map['a']) ? 'viewDetailed' : 'view';
     $map['m'] = $mn;
     EasyContactFormsRoot::processEvent($map);
 }
 /**
  * 	getEmptyObject. Overrides EasyContactFormsBase::getEmptyObject()
  *
  * 	creates and initializes a new CustomFormEntryFile
  *
  * @param array $map
  * 	request data
  * @param array $fields
  * 	a field array
  *
  * @return object
  * 	the initialized instance
  */
 function getEmptyObject($map, $fields = NULL)
 {
     $fields = (object) array();
     $fields->Date = EasyContactFormsUtils::getDate(NULL, TRUE);
     $fields->CustomFormsEntries = EasyContactFormsDB::getFirst('CustomFormsEntries');
     return parent::getEmptyObject($map, $fields);
 }