_binary From 68e324a81aca351dde8328344c995513f4d233d2 Mon Sep 17 00:00:00 2001
From: Pushkar Umaranikar <pushkar.umaranikar@sjsu.edu>
Date: Mon, 1 Dec 2014 19:30:33 -0800
Subject: [PATCH] Issue 0000160,Configuration settings for advertisement server
 are added to Yioop. , a=chris

---
 controllers/components/system_component.php |  94 +++---
 css/search.css                              | 496 ++++++++++++++++++----------
 models/profile_model.php                    |  14 +-
 scripts/server_settings.js                  |  84 +++++
 views/elements/serversettings_element.php   |  78 ++++-
 views/search_view.php                       |  51 ++-
 6 files changed, 577 insertions(+), 240 deletions(-)
 create mode 100644 scripts/server_settings.js

diff --git a/controllers/components/system_component.php b/controllers/components/system_component.php
index 07e9028..bf2ad9a 100755
--- a/controllers/components/system_component.php
+++ b/controllers/components/system_component.php
@@ -80,7 +80,9 @@ class SystemComponent extends Component
             8 => 8,
             16 => 16
         );
+
         $tmp = tl('system_component_select_machine');
+
         if(!isset($_REQUEST["has_queue_server"]) ||
             isset($_REQUEST['is_replica'])) {
             $_REQUEST["has_queue_server"] = false;
@@ -103,22 +105,10 @@ class SystemComponent extends Component
         foreach($request_fields as $field => $type) {
             if(isset($_REQUEST[$field])) {
                 $r[$field] = $parent->clean($_REQUEST[$field], $type);
-                if($type == "string") {
-                    $r[$field] = trim($r[$field]);
-                    if($r[$field] == "" && $field != "parent") {
-                        $allset = false;
-                    }
-                }
-                if($field == "url") {
-                    if(isset($r[$field][strlen($r[$field])-1]) &&
-                        $r[$field][strlen($r[$field])-1] != "/") {
-                        $r[$field] .= "/";
-                    }
-                    $r[$field] = UrlParser::canonicalLink($r[$field],
-                        NAME_SERVER);
-                    if(!$r[$field]) {
-                        $allset = false;
-                    }
+                if($field == "url" && isset($r[$field][strlen($r[$field])-1]) &&
+                    $r[$field][strlen($r[$field])-1]
+                    != "/") {
+                    $r[$field] .= "/";
                 }
             } else {
                 $allset = false;
@@ -147,6 +137,7 @@ class SystemComponent extends Component
                         $machine_model->addMachine(
                             $r["name"], $r["url"], $r["has_queue_server"],
                             $r["num_fetchers"], $r["parent"]);
+
                         $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
                             tl('system_component_machine_added').
                             "</h1>');";
@@ -176,9 +167,7 @@ class SystemComponent extends Component
                         $service_in_use = false;
                         foreach($machines as $machine) {
                             if($machine['NAME'] == $r["name"]) {
-                                if(isset($machine['STATUSES']) &&
-                                    is_array($machine['STATUSES']) &&
-                                    $machine['STATUSES'] != array()) {
+                                if($machine['STATUSES'] != array()) {
                                     $service_in_use = true;
                                     break;
                                 } else {
@@ -364,41 +353,28 @@ class SystemComponent extends Component
             in_array($_REQUEST['arg'], $possible_arguments)) {
             $clean_fields = array('localename', 'localetag', 'writingmode',
                 'selectlocale', 'active');
-            $incomplete = false;
-            $required = array('localename', 'localetag');
             foreach($clean_fields as $field) {
                 $$field = "";
                 if($field == 'active') {
                     $active = 0;
                 }
                 if(isset($_REQUEST[$field])) {
-                    $tmp = trim($parent->clean($_REQUEST[$field], "string"));
+                    $tmp = $parent->clean($_REQUEST[$field], "string");
                     if($field == "writingmode" && ($tmp == -1 ||
                         !isset($data['WRITING_MODES'][$tmp]))) {
                         $tmp = "lr-tb";
                     }
-                    if($tmp == "" && in_array($field, $required)) {
-                        $incomplete = true;
-                    }
                     $$field = $tmp;
-                } else if (in_array($field, $required)) {
-                    $incomplete = true;
                 }
             }
             switch($_REQUEST['arg'])
             {
                 case "addlocale":
-                    if($incomplete) {
-                        $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
-                            tl('system_component_locale_missing_info').
-                            "</h1>')";
-                    } else {
-                        $locale_model->addLocale(
-                            $localename, $localetag, $writingmode, $active);
-                        $locale_model->extractMergeLocales();
-                        $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
-                            tl('system_component_locale_added')."</h1>')";
-                    }
+                    $locale_model->addLocale(
+                        $localename, $localetag, $writingmode, $active);
+                    $locale_model->extractMergeLocales();
+                    $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                        tl('system_component_locale_added')."</h1>')";
                 break;
 
                 case "deletelocale":
@@ -536,6 +512,22 @@ class SystemComponent extends Component
      */
     function serverSettings()
     {
+       
+        $_REQUEST['SIDE_ADSCRIPT'] = 
+        str_replace("(","&#40;",$_REQUEST['SIDE_ADSCRIPT']);
+        $_REQUEST['SIDE_ADSCRIPT'] = 
+        str_replace(")","&#41;",$_REQUEST['SIDE_ADSCRIPT']);
+
+        $_REQUEST['TOP_ADSCRIPT'] = 
+        str_replace("(","&#40;",$_REQUEST['TOP_ADSCRIPT']);
+        $_REQUEST['TOP_ADSCRIPT'] = 
+        str_replace(")","&#41;",$_REQUEST['TOP_ADSCRIPT']);
+
+        $_REQUEST['GLOBAL_ADSCRIPT'] = 
+        str_replace("(","&#40;",$_REQUEST['GLOBAL_ADSCRIPT']);
+        $_REQUEST['GLOBAL_ADSCRIPT'] = 
+        str_replace(")","&#41;",$_REQUEST['GLOBAL_ADSCRIPT']);
+
         $parent = $this->parent;
         $profile_model = $parent->model("profile");
         $data = array();
@@ -544,17 +536,25 @@ class SystemComponent extends Component
         if(isset($_REQUEST['arg'])) {
             $arg = $_REQUEST['arg'];
         }
+        if (!isset($data["INCLUDE_SCRIPTS"])) {
+            $data["INCLUDE_SCRIPTS"] = array();
+        }
+        $data["INCLUDE_SCRIPTS"][] = "server_settings";
         $data['SCRIPT'] = "";
         $data["ELEMENT"] = "serversettings";
+        $data["ADLOCATION"] =array ("top" => e(tl('ad_element_top')),
+        "side" => e(tl('ad_element_side')),"both" => e(tl('ad_element_both')),
+        "none" => e(tl('ad_element_none'))); 
         switch($arg)
         {
             case "update":
                 $parent->updateProfileFields($data, $profile,
                     array('USE_FILECACHE', 'USE_MEMCACHE', 'USE_MAIL_PHP',
-                        'USE_PROXY'));
+                        'USE_PROXY','ADLOCATION'));
                 $old_profile =
                     $profile_model->getProfile(WORK_DIRECTORY);
                 $db_problem = false;
+
                 if((isset($profile['DBMS']) &&
                     $profile['DBMS'] != $old_profile['DBMS']) ||
                     (isset($profile['DB_NAME']) &&
@@ -575,6 +575,18 @@ class SystemComponent extends Component
                         $db_problem = true;
                     }
                 }
+                if(isset($profile['AD_LOCATION']) &&
+                $profile['AD_LOCATION'] != $old_profile['AD_LOCATION']) {
+                    $data['AD_LOCATION'] = $old_profile['AD_LOCATION'];
+                }
+                if(isset($profile['TOP_ADSCRIPT']) &&
+                $profile['TOP_ADSCRIPT'] != $old_profile['TOP_ADSCRIPT']){
+                    $data['TOP_ADSCRIPT'] = $old_profile['TOP_ADSCRIPT'];
+                }
+                if(isset($profile['SIDE_ADSCRIPT']) &&
+                $profile['SIDE_ADSCRIPT'] != $old_profile['SIDE_ADSCRIPT']){
+                $data['SIDE_ADSCRIPT'] = $old_profile['SIDE_ADSCRIPT'];
+                }
                 if($db_problem) {
                     $data['MESSAGE'] =
                         tl('system_component_configure_no_change_db');
@@ -586,6 +598,7 @@ class SystemComponent extends Component
                     $data['DB_HOST'] = $old_profile['DB_HOST'];
                     $data['DB_USER'] = $old_profile['DB_USER'];
                     $data['DB_PASSWORD'] = $old_profile['DB_PASSWORD'];
+
                     break;
                 }
                 if($profile_model->updateProfile(
@@ -674,6 +687,7 @@ EOD;
     setDisplay('memcache', (elt('use-memcache').checked) ? true : false);
 EOD;
         }
+         
         return $data;
     }
     /**
@@ -1059,7 +1073,7 @@ EOD;
                     foreach($profile as $key => $value) {
                         $data[$key] = $value;
                         if(in_array($key, array('BACKGROUND_IMAGE',
-                            'LOGO', 'M_LOGO', 'FAVICON', 'SEARCHBAR_PATH') )
+                            'LOGO', 'M_LOGO', 'FAVICON', 'SEARCHBAR_PATH') ) 
                             && $old_profile[$key] != "") {
                             $resource_name = APP_DIR ."/resources/".
                                 $old_profile[$key];
diff --git a/css/search.css b/css/search.css
index 5f63c4e..e667575 100755
--- a/css/search.css
+++ b/css/search.css
@@ -48,174 +48,160 @@ p
     padding: 0;
     width: 8.25in;
 }
+
 .mobile p
 {
     width: 300px;
 }
-.mobile pre
-{
-   white-space:pre-wrap;
-}
+
 .echo-link
 {
     color: green;
 }
+
 .hidden
 {
     visibility: hidden;
 }
+
 .left
 {
     float: left;
 }
+
 .right
 {
     float: right;
 }
+
 .clear
 {
     clear:both;
 }
+
 .none
 {
     display:none;
 }
+
 .no-margin
 {
     margin: 0;
 }
-.inline div,
-.inline form,
-.inline p
-{
-    display:inline-block;
-}
+
 .inline ul,
 .inline li
 {
     display:inline;
     list-style-type: none;
-}
-.inline li
-{
     border-right: 2px solid black;
-    padding:.05in;
 }
 .inline li:first-child
 {
     border-left: 2px solid black;
-    padding:.03in;
 }
 .indent
 {
     text-indent: 0.25in;
 }
+
 span.indent1
 {
     margin-left: 0.25in;
 }
+
 span.indent2
 {
     margin-left: 0.5in;
 }
+
 span.indent3
 {
     margin-left: 0.75in;
 }
+
 span.indent4
 {
     margin-left: 1in;
 }
+
 span.indent5
 {
     margin-left: 1.25in;
 }
+
 .mobile .indent
 {
     text-indent: 10px;
 }
+
 .mobile span.indent1
 {
     margin-left: 10px;
 }
+
 .mobile span.indent2
 {
     margin-left: 20px;
 }
+
 .mobile span.indent3
 {
     margin-left: 30px;
 }
+
 .mobile span.indent4
 {
     margin-left: 40px;
 }
+
 .mobile span.indent5
 {
     margin-left: 50px;
 }
+
 .html-ltr .float-opposite
 {
     float: right;
 }
+
 .html-rtl .float-opposite
 {
     float: left;
 }
+
 .html-ltr .float-same
 {
     float: left;
 }
+
 .html-rtl .float-same
 {
     float: right;
 }
+
 .align-right
 {
     text-align: right;
 }
+
 .align-left
 {
     text-align: left;
 }
-.align-center
-{
-    text-align: center;
-}
+
 .blockquote
 {
     margin-left: 0.3in;
     margin-right: 0.3in;
 }
+
 .mobile .blockquote
 {
     margin-left: 25px;
     margin-right: 25px;
 }
-.small-font
-{
-    font-size:12pt;
-}
-.medium-font
-{
-    font-size:16pt;
-}
-.big-font
-{
-    font-size:20pt;
-}
-.mobile .small-font
-{
-    font-size:10pt;
-}
-.mobile .medium-font
-{
-    font-size:12pt;
-}
-.mobile .big-font
-{
-    font-size:14pt;
-}
+
 .red
 {
     color: red;
@@ -224,74 +210,75 @@ span.indent5
 {
     color: green;
 }
+
 .highlight,
 .back-red
 {
     background-color: red;
 }
+
 .back-green
 {
     background-color: green;
 }
+
 .back-gray
 {
     background-color: lightgray;
 }
+
 .gray
 {
     color: gray;
 }
+
 .light-gray
 {
     color: #BBB;
 }
+
 .back-dark-gray
 {
     background-color: #CCC;
 }
+
 .gray-link
 {
     color: gray;
     text-decoration: none;
 }
+
 .gray-link:hover
 {
     text-decoration: underline;
 }
+
 a.echo-link
 {
     text-decoration: none;
 }
+
 a.echo-link:hover
 {
     text-decoration: underline;
 }
+
 .back-yellow
 {
     background-color: yellow;
 }
+
 .clear
 {
     clear: both;
 }
-.width-half
-{
-    width:50%;
-}
-.width-three-quarter
-{
-    width:75%;
-}
-.width-half img,
-.width-three-quarter img
-{
-    width:100%;
-}
+
 .frame
 {
     border: 1px solid #ccc;
     position: relative;
 }
+
 .solid-border {
     border: 1px solid #ccc;
     border-radius: 8px;
@@ -300,44 +287,54 @@ a.echo-link:hover
     border: 1px dashed #ccc;
     border-radius: 8px;
 }
+
 .name-table
 {
     padding: 5px;
 }
+
 .very-narrow-field
 {
     width: 1in;
     font-size:10pt;
     height:25px;
 }
+
 .mobile .very-narrow-field
 {
     width: 80px;
 }
+
 .narrow-field
 {
     width: 2in;
 }
+
 .mobile .narrow-field
 {
     width: 100px;
 }
+
 .wide-field
 {
     width: 3in;
 }
+
 .mobile .wide-field
 {
     width: 150px;
 }
+
 .extra-wide-field
 {
     width: 5in;
 }
+
 .mobile .extra-wide-field
 {
     width: 200px;
 }
+
 .tall-text-area
 {
     height: 4in;
@@ -348,69 +345,92 @@ a.echo-link:hover
     height: 2.5in;
     width: 100%;
 }
+
 .mobile .tall-text-area
 {
     width: 90%;
 }
+
 .medium-text-area
 {
     height: 2.5in;
     width: 100%;
 }
+
 .mobile .medium-text-area
 {
     width: 90%;
 }
+
 .short-text-area
 {
     width: 100%;
     height: 1in;
 }
+
 .mobile .short-text-area
 {
     width: 90%;
 }
+
 .center
 {
     text-align: center;
 }
+
 .bold
 {
     font-weight: bold;
 }
+
+.mobile .center
+{
+    left: -40px;
+    position: relative;
+    right: -40px;
+    top: 10px;
+}
+
 .sides-margin
 {
     margin-left:0.6in;
     margin-right:0.6in;
 }
+
 .reduce-top
 {
     position: relative;
     top: -.1in;
 }
+
 .top-margin
 {
     margin-top: .2in;
 }
+
 .no-margin
 {
     margin: 0;
 }
+
 .box
 {
     border: 1px ridge #ccc;
     padding: 3px;
 }
+
 .black-box
 {
     border:2px ridge black;
     padding:5px;
 }
+
 .light-gray-box
 {
     border:2px ridge #BBB;
     padding:5px;
 }
+
 .slight-pad
 {
     padding: 0.1in;
@@ -428,67 +448,82 @@ a.echo-link:hover
 {
     vertical-align: top;
 }
+
 fieldset
 {
     border-color:black;
 }
+
 /* set up prefixes for left-to-right, right-to-left and vertical text support*/
 .html-tb
 {
     -ms-block-progression: tb;
 }
+
 .html-rl
 {
     -ms-block-progression: rl;
     -moz-transform: rotate(90deg) translate(2in);
     -webkit-transform: rotate(90deg) translate(2in);
 }
+
 .html-lr
 {
     -ms-block-progression: lr;
     -moz-transform: rotate(90deg);
     -webkit-transform: rotate(90deg);
 }
+
 .html-rtl
 {
     direction: rtl;
     text-align:right;
 }
+
 .html-ltr
 {
     direction: ltr;
     text-align: left;
 }
+
 body.html-ltr
 {
     margin-left: 0.5in;
 }
+
 body.html-rtl
 {
     margin-right: 0.5in;
 }
+
 body.html-rl-tb
 {
     writing-mode: rl-tb;
 }
+
 body.html-lr-tb
 {
     writing-mode: lr-tb;
 }
+
 body.html-tb-rl
 {
     writing-mode: tb-rl;
+
 }
+
 body.html-tb-lr
 {
     writing-mode: tb-lr;
 }
+
 /* set up global font preferences */
 body
 {
     font-family: Arial, Helvetica, sans-serif;
     min-height: 16in;
 }
+
 /* .mobile is used for phone devices -- an attempt has been made to
    make the default non-mobile version of the page work with tablets
 */
@@ -502,6 +537,7 @@ body.mobile
     top: 0;
     width: 320px;
 }
+
 /* bar on which web, images, video subsearches and sign-in stuff live
    for many of the below things we need to handle them different on the landing
    page from pages where search results appear
@@ -515,6 +551,7 @@ body.mobile
     right: 0;
     top: -12px;
 }
+
 .landing-top-bar
 {
     height: 45px;
@@ -524,6 +561,7 @@ body.mobile
     top: -12px;
     width: 100%;
 }
+
 .mobile .top-bar,
 .mobile .landing-top-bar
 {
@@ -537,6 +575,7 @@ body.mobile
     z-index: 1;
 }
 
+
 /* this is for informational messages when settings are changed or admin stuff
    done
  */
@@ -550,12 +589,14 @@ body.mobile
     width: 8.5in;
     z-index: 3;
 }
+
 .mobile #message
 {
     left: 20px;
     right: 20px;
     width: 320px;
 }
+
 /*
    for the sign-in, settings, admin, logout links on the top-bar
  */
@@ -567,14 +608,17 @@ body.mobile
     padding:0;
     text-align: right;
 }
+
 .html-rtl .user-nav
 {
+
     margin:0 0 0 0.55in;
     min-width: 9.5in;
     max-width: 10.5in;
     padding:0;
     text-align: left;
 }
+
 .html-ltr .user-nav ul li
 {
     display: inline;
@@ -582,6 +626,7 @@ body.mobile
     padding-left: 20px;
 }
 
+
 .html-rtl .user-nav ul li
 {
     display:inline;
@@ -589,8 +634,10 @@ body.mobile
     padding-right: 20px;
 }
 
+
 .mobile .user-nav
 {
+
     font-size:11pt;
     left:0px;
     min-width: 0;
@@ -599,11 +646,15 @@ body.mobile
     right:0px;
     top: -10px;
     width:320px;
+
 }
+
 .mobile .user-nav ul li
 {
+
     padding:1px;
 }
+
 /*
    For the web, images, video links on the top-bar
  */
@@ -611,19 +662,23 @@ body.mobile
 {
     float:left;
 }
+
 ul.out-list li.outer
 {
     display: inline;
     list-style-type: none;
 }
+
 .html-ltr .subsearch ul.out-list li.outer
 {
     padding-left: 20px;
 }
+
 #more-menu
 {
     display:none;
 }
+
 #more-on b
 {
     background-color: white;
@@ -636,14 +691,17 @@ ul.out-list li.outer
     z-index: 4;
 }
 
+
 #more-on
 {
     display: none;
 }
+
 #more-on
 {
     background-color: gray;
 }
+
 li.outer div
 {
     background-color: gray;
@@ -652,20 +710,24 @@ li.outer div
     width:1.25in;
     z-index:3;
 }
+
 .html-ltr li.outer div
 {
     left: 1.85in;
     position: relative;
 }
+
 .html-rtl li.outer div
 {
     right: 1.85in;
     position: relative;
 }
+
 .mobile .subsearch ul.out-list li.outer
 {
     padding-left: 3px;
 }
+
 .mobile li.outer div
 {
     left: 2px;
@@ -673,15 +735,18 @@ li.outer div
     right: 2px;
     width: 80px;
 }
+
 ul.in-list
 {
     background-color: white;
 }
+
 .mobile ul.in-list
 {
     padding-left:2px;
     margin-left:0;
 }
+
 ul.in-list li
 {
     list-style-type: none;
@@ -693,16 +758,19 @@ ul.in-list li
     padding-bottom: 2px;
     padding-top: 2px;
 }
+
 .html-rtl .subsearch ul
 {
     float: right;
 }
+
 .html-rtl .subsearch ul li
 {
     display: inline;
     list-style-type: none;
     padding-left: 20px;
 }
+
 .mobile .subsearch
 {
     left: -40px;
@@ -713,16 +781,19 @@ ul.in-list li
     width: 220px;
     z-index:1;
 }
+
 .mobile .subsearch ul li
 {
     font-size: 11pt;
     padding-left: 3px;
     padding-right: 3px;
 }
+
 .landing-spacer
 {
     height: 6in;
 }
+
 .tall-landing-spacer
 {
     height: 10in;
@@ -737,27 +808,33 @@ ul.in-list li
     position: absolute;
     top: 1.5in;
 }
+
 .html-rtl .landing
 {
     clear: both;
     position: absolute;
     right: 1in;
     top: 1.5in;
+
 }
+
 .small-top
 {
     position: relative;
     top:-.8in;
 }
+
 .medium-top
 {
     position: relative;
     top:-.4in;
 }
+
 .square-list
 {
     list-style-type: square;
 }
+
 .mobile .landing
 {
     clear: both;
@@ -767,11 +844,13 @@ ul.in-list li
     right: 10px;
     top: 10px;
 }
+
 .mobile .small-top
 {
     position: relative;
     top:0in;
 }
+
 /*
    Style tweaks for blog, privacy, bot, settings, and admin pages
  */
@@ -782,11 +861,13 @@ ul.in-list li
     right: -10px;
     top: 10px;
 }
+
 .mobile .non-search .logo
 {
     position: relative;
     top: 20px;
 }
+
 /*
    Styles to control logo (image + adjacent text) on various pages
  */
@@ -800,7 +881,6 @@ ul.in-list li
 {
     position:relative;
     top:10px;
-    height:0;
 }
 .admin-heading,
 .group-heading
@@ -808,6 +888,7 @@ ul.in-list li
     position: relative;
     top: 30px;
 }
+
 .group-heading small
 {
     position: relative;
@@ -828,6 +909,7 @@ ul.in-list li
     position: relative;
     top: 0px;
 }
+
 .landing .logo
 {
     min-width: 6in;
@@ -835,15 +917,18 @@ ul.in-list li
     text-align: center;
     top: 0;
 }
+
 .mobile .landing .logo
 {
     min-width: 0px;
 }
+
 .logo img
 {
     border: 0;
     width:2in;
 }
+
 .mobile .logo img
 {
     left: 0px;
@@ -851,11 +936,13 @@ ul.in-list li
     top: 15px;
     width: 50px;
 }
+
 .landing .logo img
 {
     border: 0;
     width:3in;
 }
+
 .mobile .landing .logo img
 {
     position: relative;
@@ -864,6 +951,7 @@ ul.in-list li
     width: 200px;
 }
 
+
 .mobile .admin-heading img
 {
     left: 80px;
@@ -872,12 +960,14 @@ ul.in-list li
     top: 30px;
     width: 50px;
 }
+
 .logo span
 {
     position: relative;
     top: -.3in;
 }
 
+
 .mobile .admin-heading span
 {
     left: 70px;
@@ -885,6 +975,7 @@ ul.in-list li
     right: 70px;
     top: 20px;
 }
+
 .mobile .non-search .logo span
 {
     left: 20px;
@@ -892,6 +983,7 @@ ul.in-list li
     right: 20px;
     width: 200px;
 }
+
 .mobile .non-search .logo img
 {
     left: 20px;
@@ -900,9 +992,11 @@ ul.in-list li
     top: -20px;
     width: 50px;
 }
+
 /*
    Styles for footers on various pages
  */
+
 .landing-footer,
 .setting-footer,
 .signin-exit
@@ -912,12 +1006,14 @@ ul.in-list li
     min-width:8.5in;
     text-align: center;
 }
+
 .mobile .landing-footer,
 .mobile .setting-footer,
 .mobile .signin-exit
 {
     min-width:0;
 }
+
 .mobile .landing-footer
 {
     left: 0;
@@ -928,6 +1024,7 @@ ul.in-list li
     top: 0;
     width: 320px;
 }
+
 .mobile .landing .landing-footer,
 .mobile .setting-footer,
 .mobile .signin-exit
@@ -941,46 +1038,54 @@ ul.in-list li
     top: -20px;
     width: 320px;
 }
+
 .html-ltr .signin-exit li
 {
     text-align:left;
     list-style-type: square;
     margin-left:2.5in;
 }
+
 .html-rtl ul .signin-exit
 {
     text-align:right;
     list-style-type: square;
     margin-right:2.5in;
 }
+
 .mobile .signin-exit li
 {
     margin-left:25%;
     margin-right:25%;
 }
+
 /*
    If query information is available then web_layout will
    render statistics about all the SQL and search engine
    queries that were executed for a page. These styles
    control how this diagnostic info renders
  */
+
 .query-statistics
 {
     border-top: 2px solid gray;
     color: gray;
     margin-top: 0.4in;
 }
+
 .mobile .query-statistics
 {
     position: relative;
     top: 200px;
 }
+
 .query
 {
     border: 1px solid gray;
     margin: 0.1in;
     padding: 0.05in;
 }
+
 /*
    Styles for the login, settings, and register pages
  */
@@ -988,10 +1093,12 @@ ul.in-list li
 {
     text-align: right;
 }
+
 .html-rtl .cancel
 {
     text-align: left;
 }
+
 .html-ltr .login,
 .html-ltr .settings
 {
@@ -999,12 +1106,14 @@ ul.in-list li
     left: 1.25in;
     position: relative;
 }
+
 .html-ltr .register
 {
     font-size: 16pt;
     left: .75in;
     position: relative;
 }
+
 .html-rtl .login,
 .html-rtl .settings
 {
@@ -1012,18 +1121,22 @@ ul.in-list li
     position: relative;
     right: 1.25in;
 }
+
 .html-rtl .register
 {
     font-size: 16pt;
     right: .75in;
     position: relative;
 }
+
 .login input,
 .register input
 {
     font-size: 16pt;
     margin: 5px;
+
 }
+
 .mobile .login,
 .mobile .register,
 .mobile .settings,
@@ -1034,6 +1147,7 @@ ul.in-list li
     position: relative;
     right: 10px;
 }
+
 .login button,
 .register button,
 .settings button,
@@ -1041,6 +1155,7 @@ ul.in-list li
 {
     font-size:16pt;
 }
+
 .register select
 {
     font-size:14pt;
@@ -1056,6 +1171,7 @@ ul.in-list li
 {
     font-size:12pt;
 }
+
 .user-icon
 {
     width: 1.4in;
@@ -1117,6 +1233,7 @@ ul.in-list li
     top: -10px;
     width: 200px;
 }
+
 .mobile .stats img
 {
     left: 0px;
@@ -1124,9 +1241,11 @@ ul.in-list li
     top: 0px;
     width: 50px;
 }
+
 /*
   Styles for search and search result pages
  */
+
 .html-ltr .serp
 {
     left: 2.2in;
@@ -1134,6 +1253,7 @@ ul.in-list li
     top: -0.9in;
     width: 8in;
 }
+
 .html-ltr .serp-results
 {
     left: 0.5in;
@@ -1148,6 +1268,7 @@ ul.in-list li
     top: -1.7in;
     width: 8in;
 }
+
 .html-rtl .thesaurus-serp-results
 {
     right: 2.2in;
@@ -1155,6 +1276,7 @@ ul.in-list li
     top: -1.7in;
     width: 8in;
 }
+
 .html-rtl .serp
 {
     position: relative;
@@ -1163,6 +1285,7 @@ ul.in-list li
     width: 8in;
 }
 
+
 .html-rtl .serp-results
 {
     position: relative;
@@ -1170,6 +1293,7 @@ ul.in-list li
     top: -0.8in;
     width: 8in;
 }
+
 .html-ltr .serp-stats
 {
     color: #666;
@@ -1180,6 +1304,7 @@ ul.in-list li
     position: relative;
     top: -1in;
 }
+
 .html-rtl .serp-stats
 {
     color: #666;
@@ -1214,47 +1339,55 @@ ul.in-list li
 {
     clear: both;
 }
+
 .word-cloud-spacer
 {
     margin-left:1em;
     font-weight: bold;
     color : gray;
 }
+
 .word-cloud-1
 {
     font-size: 16pt;
     color: #080;
     text-decoration: none;
 }
+
 .word-cloud-2
 {
     font-size: 15pt;
     color: #090;
     text-decoration: none;
 }
+
 .word-cloud-3
 {
     font-size: 14pt;
     color: #0A0;
     text-decoration: none;
 }
+
 .word-cloud-4
 {
     font-size: 13pt;
     color: #0B0;
     text-decoration: none;
 }
+
 .word-cloud-5
 {
     font-size: 12pt;
     color: #0C0;
     text-decoration: none;
 }
+
 .word-cloud:hover
 {
     text-decoration: underline;
 }
 
+
 .access-result
 {
     box-shadow: 0px 0px 3px 3px #ccc;
@@ -1262,15 +1395,20 @@ ul.in-list li
     padding: 5px;
     margin:10px;
 }
+
+
+
 .group-result
 {
     box-shadow: 0px 0px 3px 3px #ccc;
     padding: .1in .1in .25in .1in;
 }
+
 .button-group-result
 {
     padding: .1in .1in .25in .1in;
 }
+
 .button-group-result h2,
 .result h2,
 .group-result h2
@@ -1278,22 +1416,20 @@ ul.in-list li
     font-size: 14pt;
     font-weight: normal;
 }
+
 div.button-group-result,
 div.group-result
 {
     font-size: 12pt;
     width:97%;
 }
-.mobile div.group-result
-{
-    margin: auto;
-    width:90%;
-}
+
 .serp-links-score
 {
     clear: both;
     color: #666;
 }
+
 .mobile .serp
 {
     left: 50px;
@@ -1302,6 +1438,7 @@ div.group-result
     top: -70px;
     width: 300px;
 }
+
 .mobile .serp-results
 {
     left: 3px;
@@ -1311,6 +1448,7 @@ div.group-result
     width: 300px;
     font-size:10pt;
 }
+
 .html-ltr .spell
 {
     color: #666;
@@ -1320,6 +1458,7 @@ div.group-result
     top: -0.6in;
     z-index: 1;
 }
+
 .html-rtl .spell
 {
     color: #666;
@@ -1474,7 +1613,7 @@ div.group-result
     position:static;
     width:1.95in;
 }
-.medium-search-box
+.medium-search-box 
 {
     margin:4px;
     position:static;
@@ -1513,6 +1652,7 @@ div.group-result
     position:relative;
     right:-4px;
 }
+
 .mobile .search-button
 {
     left:-4px;
@@ -1520,6 +1660,7 @@ div.group-result
     right:-4px;
     width:50px;
 }
+
 /*
    Styles for the word suggest drop down on search pages
  */
@@ -1543,17 +1684,21 @@ div.group-result
     position: relative;
     top: 0.20in;
     width: 5.6in;
+
 }
+
 .landing .dropdown
 {
     position: relative;
     top:0;
     width: 8in;
 }
+
 .mobile .dropdown
 {
     display: none;
 }
+
 .suggest-list
 {
     border: 0;
@@ -1594,10 +1739,12 @@ div.group-result
     text-decoration: none;
     z-index: 5;
 }
+
 .mobile .suggest-list
 {
     display: none;
 }
+
 /*
    Styles for the bottom of search results links to additional
    pages of search results
@@ -1607,6 +1754,7 @@ div.group-result
     margin-bottom: 8px;
     margin-top: 8px;
 }
+
 .html-ltr .pagination ul,
 .html-ltr .pagination ul li
 {
@@ -1615,6 +1763,7 @@ div.group-result
     padding-left: 0;
     padding-right: 8px;
 }
+
 .html-rtl .pagination ul,
 .html-rtl .pagination ul li
 {
@@ -1623,6 +1772,7 @@ div.group-result
     padding-left: 8px;
     padding-right: 0;
 }
+
 .html-ltr .pagination ul li a.item
 {
     border-color: blue;
@@ -1638,6 +1788,7 @@ div.group-result
     text-decoration: none;
     width: 25px;
 }
+
 .html-rtl .pagination ul li a.item
 {
     border-color: blue;
@@ -1653,12 +1804,14 @@ div.group-result
     text-decoration: none;
     width: 25px;
 }
+
 .micro-pagination ul li a.item:hover,
 .pagination ul li a.item:hover
 {
     background-color: #88F;
     color: white;
 }
+
 .html-ltr .pagination ul li span.item
 {
     border-color: black;
@@ -1674,6 +1827,7 @@ div.group-result
     top: -1px;
     width: 25px;
 }
+
 .html-rtl .pagination ul li span.item
 {
     border-color: black;
@@ -1688,6 +1842,7 @@ div.group-result
     top: -1px;
     width: 25px;
 }
+
 .html-ltr .pagination ul li span.end
 {
     display:block;
@@ -1739,12 +1894,15 @@ div.group-result
     height: 90px;
     padding-top: 0.05in;
     width: 128px;
+
 }
+
 .video-link .thumb
 {
     height: 80px;
     width: 120px;
 }
+
 .html-ltr .video-play
 {
     height: 30px;
@@ -1753,6 +1911,7 @@ div.group-result
     top: -60px;
     width: 40px;
 }
+
 .html-rtl .video-link
 {
     float: right;
@@ -1761,6 +1920,7 @@ div.group-result
     padding-top: 0.05in;
     width: 128px;
 }
+
 .html-rtl .video-play
 {
     height: 30px;
@@ -1769,6 +1929,7 @@ div.group-result
     top: -60px;
     width: 40px;
 }
+
 /*
    Styles for image subsearch page
  */
@@ -1778,12 +1939,14 @@ div.group-result
     margin-right: 10%;
     margin-top: 10px;
 }
+
 .image-list img
 {
     width:1in;
     height:1in;
     padding: 5px;
 }
+
 .mobile .image-list
 {
     margin-left: 2px;
@@ -1792,12 +1955,14 @@ div.group-result
     position: relative;
     top: 5px;
 }
+
 .mobile .image-list img
 {
     height: 50px;
     width: 50px;
     padding:2px;
 }
+
 /*
    Styles for tables on login, settings, and admin pages
  */
@@ -1805,18 +1970,22 @@ div.group-result
 {
     width: 190px;
 }
+
 .mobile .table-input input
 {
     width: 150px;
 }
+
 .html-ltr .table-label
 {
     text-align: right;
 }
+
 .html-ltr .table-input
 {
     text-align: left;
 }
+
 .html-rtl .table-label
 {
     text-align: left;
@@ -1825,6 +1994,7 @@ div.group-result
 {
     text-align: right;
 }
+
 /*
     Styles for different admin page elements
  */
@@ -1839,6 +2009,7 @@ div.group-result
     position: relative;
     width: 8in;
 }
+
 .mobile .content
 {
     clear: both;
@@ -1849,11 +2020,13 @@ div.group-result
     top: 0;
     width: 320px;
 }
+
 .content p,
 .content div
 {
     padding-bottom: 8px;
 }
+
 .html-ltr .button-box
 {
     color: black;
@@ -1867,6 +2040,7 @@ div.group-result
     top: 0.015in;
 }
 
+
 .html-rtl .button-box
 {
     color: black;
@@ -1879,6 +2053,7 @@ div.group-result
     text-decoration: none;
     top: 0.015in;
 }
+
 .mobile .button-box
 {
     font-size: 12pt;
@@ -1887,22 +2062,26 @@ div.group-result
     margin-right: 0;
     margin-bottom: 1px;
 }
+
 .tiny-button-box
 {
     font-size: 12pt;
     margin:1px;
     padding:1px;
 }
+
 .html-ltr .component-container
 {
     float: left;
     width: 2.6in;
 }
+
 .html-rtl .component-container
 {
     float: right;
     width: 2.6in;
 }
+
 .html-ltr .activity-menu,
 .html-rtl .activity-menu
 {
@@ -1913,6 +2092,7 @@ div.group-result
     width: 2.5in;
     margin-bottom:.1in;
 }
+
 .mobile .activity-menu
 {
     border: 0;
@@ -1921,6 +2101,7 @@ div.group-result
     top: 100px;
     width:320px;
 }
+
 .activity-menu h2
 {
     border-top-right-radius: 8px;
@@ -1930,15 +2111,18 @@ div.group-result
     margin: 0;
     padding: .01in .05in .01in .05in;
 }
+
 .mobile .activity-menu h2
 {
     display: none;
 }
+
 .mobile .activity-menu select
 {
     font-size:16pt;
     width:320px;
 }
+
 .activity-menu li
 {
     list-style-position: inside;
@@ -1946,20 +2130,24 @@ div.group-result
     margin: 0;
     padding: 0.05in;
 }
+
 .activity-menu li.bottom-border
 {
     border-bottom: 1px solid #ccc;
 }
+
 .activity-menu li a
 {
     color: #222;
     text-decoration: none;
 }
+
 .activity-menu li a:hover
 {
     color: #222;
     text-decoration: underline;
 }
+
 .activity-menu ul
 {
     border-radius: 8px;
@@ -1978,13 +2166,14 @@ div.group-result
     font-size: 16pt;
     max-width: 9in;
     min-height: 6.5in;
-    min-width: 8in;
+    min-width: 9in;
     padding-left: 0.1in;
     padding-right: 0.1in;
     padding-bottom: 0.1in;
     position: relative;
     top: 30px;
 }
+
 .html-ltr .current-activity
 {
     margin-left: 2.75in;
@@ -2019,6 +2208,7 @@ div.group-result
     position: relative;
     top: 30px;
 }
+
 .mobile .current-activity,
 .mobile .small-margin-current-activity
 {
@@ -2045,6 +2235,7 @@ div.group-result
     margin-top: 0.05in;
     padding-top: 0.05in;
 }
+
 .current-activity input,
 .small-margin-current-activity input
 {
@@ -2052,6 +2243,7 @@ div.group-result
     position: relative;
     top: 2px;
 }
+
 .current-activity object,
 .small-margin-current-activity object
 {
@@ -2059,21 +2251,25 @@ div.group-result
     min-width: 6in;
     width: 8in;
 }
+
 .current-activity select,
-.small-margin-current-activity select
+.small-margin-current-activity slect
 {
     font-size: 16pt;
 }
+
 .mobile .current-activity select,
 .small-margin-current-activity select
 {
     font-size: 12pt;
 }
+
 .current-activity pre,
 .small-margin-current-activity pre
 {
     font-size: 10pt;
 }
+
 .table-margin
 {
     font-size:14pt;
@@ -2091,6 +2287,7 @@ div.group-result
     padding:1px;
     top: 0.1in;
 }
+
 .html-rtl .table-margin
 {
     position:relative;
@@ -2098,6 +2295,7 @@ div.group-result
     padding:1px;
     top: 0.1in;
 }
+
 .role-table,
 .locale-table
 {
@@ -2111,6 +2309,7 @@ div.group-result
     margin-left: 0.1in;
     padding: 1px;
 }
+
 .html-rtl .role-table,
 .html-rtl .role-table td,
 .html-rtl .role-table th
@@ -2126,6 +2325,7 @@ div.group-result
     padding:0;
     margin:0;
 }
+
 .html-ltr .locale-table,
 .html-ltr .locale-table td,
 .html-ltr .locale-table th
@@ -2133,6 +2333,7 @@ div.group-result
     border: 1px ridge black;
     margin-left: 0.2in;
 }
+
 .html-rtl .locale-table,
 .html-rtl .locale-table td,
 .html-rtl .locale-table th
@@ -2140,6 +2341,7 @@ div.group-result
     border: 1px ridge black;
     margin-right: 0.2in;
 }
+
 .tab-menu-list
 {
     border-bottom: 2px solid black;
@@ -2147,11 +2349,13 @@ div.group-result
     padding: 0px;
     z-index: 1;
 }
+
 .tab-menu-list li
 {
     display: inline;
     list-style-type: none;
 }
+
 .tab-menu-list a
 {
     background-color:#EEE;
@@ -2162,11 +2366,13 @@ div.group-result
     padding: 5px 5px 0px 5px;
     text-decoration: none;
 }
+
 .tab-menu-list a.active
 {
     background-color: white;
     border-bottom: 3px solid white;
 }
+
 .tab-menu-content
 {
     border: 1px solid black;
@@ -2174,6 +2380,7 @@ div.group-result
     padding: 10px;
     z-index: 2;
 }
+
 .crawls-table,
 .crawls-table td,
 .crawls-table th,
@@ -2194,10 +2401,12 @@ div.group-result
     border: 1px ridge black;
     padding: 2px;
 }
+
 .mixes-table td
 {
     font-size:12pt;
 }
+
 .html-ltr .file-types-table,
 .html-ltr .file-types-all td,
 .html-ltr .classifiers-table,
@@ -2208,6 +2417,7 @@ div.group-result
    margin-left: 0.3in;
    vertical-align: top;
 }
+
 .html-rtl .file-types-table,
 .html-rtl .file-types-all td,
 .html-rtl .search-page-table,
@@ -2216,6 +2426,7 @@ div.group-result
    margin-right: 0.3in;
    vertical-align: top;
 }
+
 .mobile .file-types-table,
 .mobile .file-types-all td,
 .mobile .search-page-table,
@@ -2225,14 +2436,17 @@ div.group-result
    margin-right: 2px;
    vertical-align: top;
 }
+
 .html-ltr .weights-table th
 {
     text-align: right;
 }
+
 .html-rtl .weights-table th
 {
     text-align: left;
 }
+
 .machine-table,
 .machine-table td,
 .machine-table th
@@ -2241,11 +2455,13 @@ div.group-result
     margin: 2px;
     padding: 3px;
 }
+
 .toggle-table,
 .toggle-table td
 {
     border: 1px ridge black;
 }
+
 .file-types-table td,
 .translate-table,
 .translate-table td,
@@ -2253,17 +2469,20 @@ div.group-result
 {
     border: 1px ridge black;
 }
+
 .classifiers-table td.check
 {
     padding: 0;
     text-align: center;
 }
+
 .indexing-plugin-table
 {
     margin-left: 0.3in;
     margin-right: 0.3in;
     padding: 3px;
 }
+
 .indexing-plugin-table,
 .indexing-plugin-table td,
 .indexing-plugin-table th
@@ -2271,20 +2490,24 @@ div.group-result
     border: 1px ridge black;
     text-align: center;
 }
+
 .indexing-plugin-table th
 {
     padding: 0.04in;
 }
+
 .html-ltr .indexing-plugin-table td.check
 {
     padding: 0.1in;
     text-align: left;
 }
+
 .html-rtl .indexing-plugin-table td.check
 {
     padding: 0.1in;
     text-align: left;
 }
+
 .indexing-plugin-lightbox, .share-lightbox
 {
     background-color:gray;
@@ -2298,6 +2521,7 @@ div.group-result
     width:100%;
     z-index:100;
 }
+
 .mobile .indexing-plugin-lightbox
 {
     left: 0px;
@@ -2318,6 +2542,7 @@ div.group-result
     position: absolute;
     width: 60%;
     z-index:101;
+
 }
 .indexing-plugin-lightbox .light-content
 {
@@ -2380,14 +2605,14 @@ div.group-result
 table.wikitable
 {
     background:white;
-    border:1px #AAA solid;
+    border:1px #aaa solid;
     border-collapse: collapse;
     margin:1em 0;
 }
 table.wikitable > tr > th,table.wikitable > tr > td,
 table.wikitable > * > tr > th,table.wikitable > * > tr > td
 {
-    border:1px #AAA solid;
+    border:1px #aaa solid;
     padding:0.2em;
 }
 table.wikitable > tr > th,
@@ -2418,6 +2643,7 @@ table.wikitable > caption
 {
     color: gray;
 }
+
 #label-docs-form th,
 #label-docs-queue .actions
 {
@@ -2425,31 +2651,38 @@ table.wikitable > caption
     padding: 0.1in 0.2in 0.1in 0in;
     width: 1.0in;
 }
+
 #label-docs-queue .actions
 {
     padding: 0.1in;
 }
+
 #label-docs-queue
 {
     font-size: 11pt;
 }
+
 #label-docs-queue td
 {
     vertical-align: top;
     padding-top: 10px;
 }
+
 #label-docs-queue .labelled td
 {
     background-color: #f0f0f0;
 }
+
 #label-docs-queue .notinclass td
 {
     background-color: #FFE0E0;
 }
+
 #label-docs-queue .inclass td
 {
     background-color: #F0FFF0;
 }
+
 #label-docs-queue tr.inclass a.inclass,
 #label-docs-queue tr.notinclass a.notinclass,
 #label-docs-queue tr.skip a.skip
@@ -2459,23 +2692,28 @@ table.wikitable > caption
     font-weight: bold;
     text-decoration: none;
 }
+
 #label-docs-queue p
 {
     width: auto;
     margin: 3px 0px;
 }
+
 #label-docs-queue .info
 {
     padding-left: 7px;
 }
+
 #label-docs-queue .description
 {
     color: #666;
 }
+
 #label-docs-queue .description b
 {
     color: black;
 }
+
 #transfer
 {
     background-color: black;
@@ -2491,116 +2729,20 @@ table.wikitable > caption
     width: 100%;
     z-index: 200;
 }
-.html-ltr #help
-{
-    border-radius: 8px;
-    float: left;
-    width: 4.0in;
-    position: absolute;
-    left: 11.5in;
-    top: 135px;
-}
-.html-rtl #help
-{
-    border-radius: 8px;
-    float: left;
-    width: 4.0in;
-    position: absolute;
-    right: 11.5in;
-    top: 135px;
-}
-.html-ltr #small-margin-help
-{
-    border-radius: 8px;
-    float: left;
-    width: 4.0in;
-    position: absolute;
-    left: 11.5in;
-    top: 135px;
-}
-.html-rtl #small-margin-help
-{
-    border-radius: 8px;
-    float: left;
-    width: 4.0in;
-    position: absolute;
-    right: 9.5in;
-    top: 135px;
-}
-.html-ltr #mobile-help
-{
-    float: left;
-    width: 3in;
-    position: absolute;
-    top: 142px;
-}
-.html-rtl #mobile-help
-{
-    float: left;
-    width: 3in;
-    position: absolute;
-    top: 142px;
-}
-.help-pane
-{
-    display : none;
-    width: 320px;
-    border:2px solid #0094ff;
-}
-.small-margin-help-pane
-{
-    display: none;
-    width: 380px;
-    border: 2px solid #0094ff;
-    left: -1in;
-    top: 1in;
-}
-.help-title
-{
-    background:#0094ff;
-    color:white;
-    font-size: 16pt;
-    margin: 0;
-    padding: .05in;
-}
-.help-pane p
-{
-    color:#333;
-    padding:10px;
-}
-.wiki-resource-image
-{
-    max-width:100%;
-}
-.help-button
-{
-    bottom: 50px;
-    cursor: pointer;
-    border: 1px solid #2d2bdb;
-    font-size: 20px;
-    line-height: 0.5px;
-    padding: 10px 3px;
-}
-button.default
-{
-    background: #d3d3d3;
-    color: black;
-}
-.close
-{
-    cursor: pointer;
-    font-weight: bold;
-    line-height: 0.5px;
-    padding: 5px 0px 4px 4px;
-}
-#help-close {
-    color: #F5F5F5;
-}
-.sidebar
+/*
+  Styles for Adevertisement banners on
+  search results page
+ */
+.top-adscript
 {
-    top : 180px;
+    left: 0.5in;
+    position: relative;
+    top: -0.9in;
+
 }
-.new-thread-icon
+.side-adscript
 {
-    margin-bottom : -5px;
-}
+    float: right;
+    margin-top: -50px;
+    margin-right: 180px;
+}
\ No newline at end of file
diff --git a/models/profile_model.php b/models/profile_model.php
index 7b8def7..66dc236 100755
--- a/models/profile_model.php
+++ b/models/profile_model.php
@@ -67,8 +67,8 @@ class ProfileModel extends Model
         'SUBSEARCH_LINK', 'TIMEZONE', 'TITLE_WEIGHT', 'TOPBAR_COLOR',
         'TOR_PROXY',
         'USE_FILECACHE', 'USE_MAIL_PHP', 'USE_MEMCACHE', 'USE_PROXY',
-        'USER_AGENT_SHORT', 'WEB_URI', 'WEB_ACCESS', 'WORD_SUGGEST'
-        );
+        'USER_AGENT_SHORT', 'WEB_URI', 'WEB_ACCESS', 'WORD_SUGGEST',
+        'AD_LOCATION','TOP_ADSCRIPT','GLOBAL_ADSCRIPT','SIDE_ADSCRIPT');
     /**
      * Associative array (table_name => SQL statement to create that table)
      * List is alphabetical and contains all Yioop tables. List is only
@@ -109,7 +109,7 @@ class ProfileModel extends Model
             "ACTIVITY" => "CREATE TABLE ACTIVITY (ACTIVITY_ID $serial
                 PRIMARY KEY $auto_increment, TRANSLATION_ID INTEGER,
                 METHOD_NAME VARCHAR(".LONG_NAME_LEN."))",
-            "ACTIVITY_TRANSLATION_ID_INDEX" => "CREATE INDEX
+            "ACTIVITY_TRANSLATION_ID_INDEX" => "CREATE INDEX 
                 ACTIVITY_TRANSLATION_ID_INDEX ON ACTIVITY (TRANSLATION_ID)",
             "CRAWL_MIXES" => "CREATE TABLE CRAWL_MIXES (TIMESTAMP NUMERIC(".
                 TIMESTAMP_LEN.")
@@ -222,7 +222,7 @@ class ProfileModel extends Model
                 TRANSLATION VARCHAR(".MAX_GROUP_POST_LEN."),
                 PRIMARY KEY(TRANSLATION_ID, LOCALE_ID))",
             "USERS" => "CREATE TABLE USERS(USER_ID $serial PRIMARY KEY
-                $auto_increment, FIRST_NAME VARCHAR(".NAME_LEN."),
+                $auto_increment, FIRST_NAME VARCHAR(".NAME_LEN."), 
                 LAST_NAME VARCHAR(".NAME_LEN."), USER_NAME VARCHAR(".NAME_LEN
                 .") UNIQUE, EMAIL VARCHAR(".LONG_NAME_LEN."),
                 PASSWORD VARCHAR(".LONG_NAME_LEN."), STATUS INTEGER,
@@ -489,7 +489,7 @@ EOT;
                 $table_or_index, $test_dbm)) {return false;}
         }
         if(stristr($dbinfo["DB_HOST"], "pgsql") !== false) {
-            /* For postgres count initial values of SERIAL sequences
+            /* For postgres count initial values of SERIAL sequences 
                will be screwed up unless do
              */
             $auto_tables = array("ACTIVITY" =>"ACTIVITY_ID",
@@ -564,7 +564,7 @@ EOT;
                 $dbinfo[$field] = constant($field);
             }
         }
-        $host = $dbinfo['DB_HOST'];
+        $host = $dbinfo['DB_HOST']; 
             // for postgress database needs to already exists
         $host = str_ireplace("database=".$dbinfo['DB_NAME'],"",
             $host); // informix, ibm (use connection string DSN)
@@ -661,4 +661,4 @@ EOT;
     }
 
 }
-?>
\ No newline at end of file
+?>
diff --git a/scripts/server_settings.js b/scripts/server_settings.js
new file mode 100644
index 0000000..f5b1fae
--- /dev/null
+++ b/scripts/server_settings.js
@@ -0,0 +1,84 @@
+/**
+ * SeekQuarry/Yioop --
+ * Open Source Pure PHP Search Engine, Crawler, and Indexer
+ *
+ * Copyright (C) 2009 - 2014  Chris Pollett chris@pollett.org
+ *
+ * LICENSE:
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * END LICENSE
+ *
+ * @author Pushkar Umaranikar (edited Chris Pollett)
+ * @package seek_quarry
+ * @subpackage javascript
+ * @license http://www.gnu.org/licenses/ GPL3
+ * @link http://www.seekquarry.com/
+ * @copyright 2014
+ * @filesource
+ */
+/**
+ * This script shows or blocks the textarea for including ad script on respective 
+ * location depending upon the ad location that user has selected.
+ */
+window.onload = function()
+{
+    showHideScriptdiv();
+}
+/**
+ * Method to show/block div including text area depending upon location selected for 
+ * the advertisement to display on search results page.
+ */
+function showHideScriptdiv()
+{
+     /*
+      * Get the radio button list represnting location for the 
+      * advertisement.
+     */
+    var adserverconfig = document.getElementsByName('AD_LOCATION');
+
+    /*
+     * Show/ block div with text area depending upon the radio
+     * button value.
+     */
+    if(adserverconfig[0].checked)
+    {
+        elt( 'top-adscript-config' ).style.display = 'block';
+        elt( 'global-adscript-config' ).style.display = 'block';
+
+        elt( 'side-adscript-config' ).style.display = 'none';
+    }
+    if(adserverconfig[1].checked)
+        {
+        elt( 'side-adscript-config' ).style.display = 'block';
+        elt( 'global-adscript-config' ).style.display = 'block';
+
+        elt( 'top-adscript-config' ).style.display = 'none';
+    }
+    if(adserverconfig[2].checked)
+    {
+        elt( 'top-adscript-config' ).style.display = 'block';
+        elt( 'global-adscript-config' ).style.display = 'block';
+
+        elt( 'side-adscript-config' ).style.display = 'block';
+    }
+    if(adserverconfig[3].checked)
+    {
+        elt( 'top-adscript-config' ).style.display = 'none';
+        elt( 'global-adscript-config' ).style.display = 'none';
+
+        elt( 'side-adscript-config' ).style.display = 'none';
+    }
+}
diff --git a/views/elements/serversettings_element.php b/views/elements/serversettings_element.php
index 9e5fdf7..c9d692d 100644
--- a/views/elements/serversettings_element.php
+++ b/views/elements/serversettings_element.php
@@ -50,9 +50,10 @@ class ServersettingsElement extends Element
      */
     function render($data)
     {
-    ?>
+    ?>  <!--<script type="text/javascript" src="http://code.jquery.com/jquery.js" ></script>
+        <script type="text/javascript" src="./scripts/server_settings.js" ></script>  -->
         <div class="current-activity">
-        <form id="serverSettingsForm" method="post">
+        <form id="serverSettingsForm" method="post" action=''>
         <input type="hidden" name="c" value="admin" />
         <input type="hidden" name="<?php e(CSRF_TOKEN); ?>" value="<?php
             e($data[CSRF_TOKEN]); ?>" />
@@ -107,10 +108,7 @@ class ServersettingsElement extends Element
             </div>
             <div class="top-margin">
             <fieldset><legend><?php
-                e(tl('configure_element_database_setup'));
-                e("&nbsp;" .$this->view->helper("helpbutton")->render(
-                        "Database Setup", $data[CSRF_TOKEN]));?>
-                </legend>
+                e(tl('configure_element_database_setup'))?></legend>
                 <div ><label for="database-system"><b><?php
                     e(tl('serversettings_element_database_system'));
                     ?></b></label>
@@ -153,8 +151,6 @@ class ServersettingsElement extends Element
                 <legend><label
                 for="account-registration"><?php
                 e(tl('serversettings_element_account_registration'));
-                e("&nbsp;" .$this->view->helper("helpbutton")->render(
-                        "Account Registration", $data[CSRF_TOKEN]));
                 ?>
                 </label></legend>
                     <?php $this->view->helper("options")->render(
@@ -183,7 +179,8 @@ class ServersettingsElement extends Element
                         class="wide-field" />
                 </div>
                 <div class="top-margin"><b><label for="mail-serverport"><?php
-                    e(tl('serversettings_element_mail_serverport'))?></label></b>
+                    e(tl('serversettings_element_mail_serverport'));
+                        ?></label></b>
                     <input type="text" id="mail-port" name="MAIL_SERVERPORT"
                         value="<?php e($data['MAIL_SERVERPORT']); ?>"
                         class="wide-field" />
@@ -213,12 +210,9 @@ class ServersettingsElement extends Element
             </div>
             <div class="top-margin">
             <fieldset><legend><?php
-                e(tl('serversettings_element_proxy_title'));
-                e("&nbsp;" .$this->view->helper("helpbutton")->render(
-                        "Proxy server", $data[CSRF_TOKEN]));
-                ?></legend>
+                e(tl('serversettings_element_proxy_title'))?></legend>
                 <div ><b><label for="tor-proxies"><?php
-                    e(tl('serversettings_element_tor_proxy'));?></label></b>
+                    e(tl('serversettings_element_tor_proxy'))?></label></b>
                     <input type="text" id="tor-proxies" name="TOR_PROXY"
                         value="<?php e($data['TOR_PROXY']); ?>"
                         class="wide-field" />
@@ -241,6 +235,62 @@ class ServersettingsElement extends Element
                     ?></textarea>
                 </div>
             </fieldset>
+            <fieldset><legend><?php
+                e(tl('serversettings_element_adserver_configuration'))?></legend>
+                <div><b><label><?php e(tl('serversettings_element_align'))?></label>
+                </b><br><input type = 'radio' name = 'AD_LOCATION' 
+                value = "<?php e(tl('ad_element_top')); ?>" 
+                onchange = "showHideScriptdiv(this);"
+                <?php e(($data['AD_LOCATION']) == tl('ad_element_top')?'checked':'')
+                ?>/><?php e(tl('ad_element_top'))?>
+                
+                <input type = 'radio' name = 'AD_LOCATION'
+                value = "<?php e(tl('ad_element_side'));?>"
+                onclick = "showHideScriptdiv(this);"
+                <?php e(($data['AD_LOCATION']) == tl('ad_element_side')?'checked':'')
+                ?>/><?php e(tl('ad_element_side'))?>
+
+                <input type = 'radio' name = 'AD_LOCATION' 
+                value = "<?php e(tl('ad_element_both')); ?>"
+                onclick = "showHideScriptdiv(this);"
+                <?php e(($data['AD_LOCATION']) == tl('ad_element_both')?'checked':'')
+                ?>/><?php e(tl('ad_element_both'))?>
+                
+                <input type = 'radio' name = 'AD_LOCATION'
+                value = "<?php e(tl('ad_element_none'));?>"
+                onclick = "showHideScriptdiv(this);"
+                <?php e(($data['AD_LOCATION']) == tl('ad_element_none')?'checked':'')
+                ?>/><?php e(tl('ad_element_none')) ?>
+                </div>
+                
+                <div id = "global-adscript-config">
+                <label for = "global-adscript"><b>
+                <?php e(tl('serversettings_element_global_adscript'));
+                ?></b></label>
+            
+                <textarea class = "short-text-area" id = "global-adscript"
+                name = "GLOBAL_ADSCRIPT">
+                <?php e(html_entity_decode($data['GLOBAL_ADSCRIPT'],ENT_QUOTES))?>
+                </textarea> </div>
+                    
+                <div id = "top-adscript-config"><label for = "top-adscript"
+                ><b><?php e(tl('serversettings_element_top_adscript'));
+                ?></b></label>
+                     
+                <textarea class = "short-text-area" id = "top-adscript"
+                name = "TOP_ADSCRIPT">
+                 <?php e(html_entity_decode($data['TOP_ADSCRIPT'],ENT_QUOTES))?>
+                </textarea></div>
+                 
+                <div id = "side-adscript-config"><label for = "side-adscript"
+                ><b><?php e(tl('serversettings_element_side_adscript'));
+                ?></b></label>
+
+                <textarea class = "short-text-area" id = "side-adscript"
+                name="SIDE_ADSCRIPT">
+                <?php e(html_entity_decode($data['SIDE_ADSCRIPT'],ENT_QUOTES))?>
+                </textarea></div>
+            </fieldset>
             </div>
             <div class="top-margin center">
             <button class="button-box" type="submit"><?php
diff --git a/views/search_view.php b/views/search_view.php
index d85f606..76e481d 100755
--- a/views/search_view.php
+++ b/views/search_view.php
@@ -63,6 +63,7 @@ class SearchView extends View implements CrawlConstants
      */
     function renderView($data)
     {
+        //echo ($data['AD_LOCATION']);
         $data['LAND'] = (!isset($data['PAGES'])) ? 'landing-' : '';
         if(SIGNIN_LINK || SUBSEARCH_LINK) {?>
         <div class="<?php e($data['LAND']);?>top-bar"><?php
@@ -70,6 +71,7 @@ class SearchView extends View implements CrawlConstants
             $this->element("signin")->render($data);
             ?>
         </div>
+        
         <?php
         }
         $logged_in = isset($data["ADMIN"]) && $data["ADMIN"];
@@ -123,7 +125,7 @@ class SearchView extends View implements CrawlConstants
                 alt='<?php e(tl('search_view_search')); ?>'/></button>
             </p>
             </form>
-        </div>
+        </div>        
         <div id="suggest-dropdown">
             <ul id="suggest-results" class="suggest-list">
             </ul>
@@ -177,6 +179,7 @@ class SearchView extends View implements CrawlConstants
      */
     function renderSearchResults($data)
     {
+        $is_landing = (!isset($data['PAGES']) && !isset($data['MORE']));
         $logged_in = isset($data["ADMIN"]) && $data["ADMIN"];
         $token_string = ($logged_in) ? CSRF_TOKEN."=".$data[CSRF_TOKEN]."&":"";
         $token_string_amp = ($logged_in) ?
@@ -197,6 +200,50 @@ class SearchView extends View implements CrawlConstants
                 $data['TOTAL_ROWS']));
             }
         ?></h2>
+
+        <!-- Code changes to add advertisement on search results page - STRAT -->
+         <?php if((!$is_landing) && ($data['AD_LOCATION']=='Top' ||
+        $data['AD_LOCATION'] == 'Both')) { ?>
+        <div class="top-adscript">
+        <?php
+          $str = html_entity_decode($data['TOP_ADSCRIPT'],ENT_QUOTES);
+          
+            $i = 1;
+            while (($offset = strpos($str, "&#40;")) !== false) {
+            $str = substr_replace($str, "(", $offset, strlen("&#40;"));
+            }
+
+            $i = 1;
+            while (($offset = strpos($str, "&#41;")) !== false) {
+            $str = substr_replace($str, ")", $offset, strlen("&#41;"));
+            }
+          eval(e($str));
+
+        ?>
+        </div>
+        <?php } ?>
+
+        <?php if((!$is_landing) && ($data['AD_LOCATION'] == 'Side' ||
+        $data['AD_LOCATION'] == 'Both')) { ?>
+        <div class="side-adscript">
+        <?php 
+          $str = html_entity_decode($data['SIDE_ADSCRIPT'],ENT_QUOTES);
+          
+            $i = 1;
+            while (($offset = strpos($str, "&#40;")) !== false) {
+            $str = substr_replace($str, "(", $offset, strlen("&#40;"));
+            }
+
+            $i = 1;
+            while (($offset = strpos($str, "&#41;")) !== false) {
+            $str = substr_replace($str, ")", $offset, strlen("&#41;"));
+            }
+          eval(e($str));
+        ?>
+        </div>
+        <?php } ?>
+        <!-- Code changes to add advertisement on search results page - END -->
+
         <?php
         $similar_words = $data['THESAURUS_VARIANTS'];
         $use_thesaurus = WORD_SUGGEST && count($similar_words) > 0 && !MOBILE;
@@ -207,7 +254,7 @@ class SearchView extends View implements CrawlConstants
                 foreach ($similar_words as $word) {
                     e("<br />");
                     ?><span><a href="?<?php e($token_string_amp);
-                    ?>its=<?php e($data['its']);?>&amp;q=<?php
+                    ?>its=<?php e($data['its']);?>&amp;q=<?php 
                         e($word);?>"><?php e($word); ?></a></span>
                     <?php
                 }
-- 
1.9.4.msysgit.1

