Example #1
0
 public function profilesavesearch()
 {
     $sectionid = profilef::profilesectionid();
     $user = JFactory::getUser();
     $uid = intval($user->id);
     if ($uid > 0) {
         $db =& JFactory::getDBO();
         $db->setQuery("SELECT nid,fid FROM #__sobipro_field WHERE section=" . $sectionid);
         $rows = $db->loadAssocList();
         $namefieldid = 0;
         $catfieldid = 0;
         $searchfieldid = 0;
         //a:1:{i:0;s:4:"1255";}
         foreach ($rows as $row) {
             if ($row['nid'] == 'field_name') {
                 $namefieldid = intval($row['fid']);
             }
             if ($row['nid'] == 'field_category') {
                 $catfieldid = intval($row['fid']);
             }
             if ($row['nid'] == 'field_searchdata') {
                 $searchfieldid = intval($row['fid']);
             }
         }
         if ($namefieldid > 0 && $catfieldid > 0 && $searchfieldid > 0 && $sectionid > 0) {
             $catid = 1404;
             $catstring = $catid . '';
             $catstring = base64_encode('a:1:{i:0;s:' . strlen($catstring) . ':"' . $catstring . '";}');
             $searchstr = intval($_REQUEST['state']) . ';' . intval($_REQUEST['council']) . ';' . intval($_REQUEST['scheme']) . ';' . intval($_REQUEST['zone']) . ';';
             $overlays = $_REQUEST['overlays'];
             if (empty($overlays)) {
                 $overlays = array(0);
             } else {
                 if (!is_array($overlays)) {
                     $overlays = array(intval($overlays));
                 } else {
                     foreach ($overlays as $okey => $oval) {
                         $overlays[$okey] = intval($oval);
                     }
                 }
             }
             $searchstr .= implode(',', $overlays) . ';' . intval($_REQUEST['plan']) . ';';
             $ref = trim($_REQUEST['reference']);
             $db->setQuery("INSERT INTO #__sobipro_object SET name='" . $db->escape($ref) . "', oType='entry'");
             $db->execute();
             $oid = intval($db->insertid());
             if ($oid > 0) {
                 $ip = $db->escape($_SERVER['REMOTE_ADDR']);
                 $db->setQuery("UPDATE #__sobipro_object SET nid=CONCAT('pdsearch-',id), approved=1, confirmed=1, createdTime=NOW(), updatedTime=NOW(), validSince=NOW(), owner=" . $uid . ", updater=" . $uid . ", ownerIP='" . $ip . "', updaterIP='" . $ip . "', state=1, version=1 WHERE id=" . $oid);
                 $db->execute();
                 $db->setQuery("INSERT INTO #__sobipro_relations SET id=" . $oid . ", pid=" . $catid . ", oType='entry', validSince=NOW(), position=0, validUntil='0000-00-00 00:00:00'");
                 $db->execute();
                 $db->setQuery("INSERT INTO #__sobipro_field_data (fid,sid,section,baseData) VALUES (" . $namefieldid . "," . $oid . "," . $sectionid . ",'" . $db->escape($ref) . "'), (" . $catfieldid . "," . $oid . "," . $sectionid . ",'" . $db->escape($catstring) . "'), (" . $searchfieldid . "," . $oid . "," . $sectionid . ",'" . $db->escape($searchstr) . "')");
                 $db->execute();
                 $db->setQuery("UPDATE #__sobipro_field_data SET lang='en-GB',enabled=1,approved=1,createdTime=NOW(), updatedTime=NOW(), createdBy=" . $uid . ", updatedBy=" . $uid . ", createdIP='" . $ip . "', updatedIP='" . $ip . "' WHERE sid=" . $oid);
                 $db->execute();
                 profilef::profileexpiresinglesearch();
             }
             return $oid;
         }
     }
     return 0;
 }