function _default()
 {
     $this->output->secure();
     $f = $this->input->f;
     if ($f[email] && $f[password] && $f[name] && $f[url]) {
         if ($_SESSION[user][admin] == 3) {
             $this->db->update("adrev_users", "id", $_REQUEST[id], $f);
             $this->output->redirect(lib_lang("The profile was updated"), "index.php?section=" . $_REQUEST[redir], 1);
         } else {
             $this->db->update("adrev_users", "id", $_SESSION[user][id], $f);
             $this->output->redirect(lib_lang("Your profile was updated"), "index.php?section=profile", 1);
         }
         exit;
     }
     if ($_SESSION[user][admin] == 3 && $_REQUEST[id]) {
         $id = $_REQUEST[id];
     } else {
         $id = $_SESSION[user][id];
     }
     $rec = $this->db->getsql("SELECT * FROM adrev_users WHERE id=?", array($id));
     $f = $rec[0];
     // Grab the list of language modules
     $modules = array();
     if ($handle = opendir("lang")) {
         while (FALSE !== ($file = readdir($handle))) {
             if (preg_match('/^(.*?)\\.lng/i', $file, $match)) {
                 $modules[$match[1]] = $match[1];
             }
         }
         closedir($handle);
     }
     $form = new formgen();
     $form->input("<b>" . lib_lang("Email") . "</b>", "f[email]", stripslashes($f[email]), 40);
     $form->input("<b>" . lib_lang("Password") . "</b>", "f[password]", stripslashes($f[password]), 20);
     $form->input("<b>" . lib_lang("Name") . "</b>", "f[name]", stripslashes($f[name]), 40);
     $form->input(lib_lang("Organization"), "f[organization]", stripslashes($f[organization]), 40);
     $form->dropdown(lib_lang("Country"), "f[country]", lib_htlist_array($this->default[country], $f[country]));
     $form->input(lib_lang("Street"), "f[street]", stripslashes($f[street]), 40);
     $form->input(lib_lang("City"), "f[city]", stripslashes($f[city]), 20);
     $form->input(lib_lang("State"), "f[state]", stripslashes($f[state]), 10);
     $form->input(lib_lang("Zip"), "f[postalcode]", stripslashes($f[postalcode]), 10);
     $form->input("<b>" . lib_lang("Url") . "</b>", "f[url]", stripslashes($f[url]), 50);
     $form->dropdown(lib_lang("Language"), "f[lang]", lib_htlist_array($modules, $f[lang]));
     $form->hidden("section", "profile");
     $form->hidden("id", $id);
     $form->hidden("redir", $_REQUEST[redir]);
     $this->title = lib_lang("Edit Profile");
     $this->content = $form->generate("post", lib_lang("Save Profile"));
     $this->display();
     $this->printpage();
     exit;
 }
 function payment_form()
 {
     // Show the form
     $month = array(1 => "01", 2 => "02", 3 => "03", 4 => "04", 5 => "05", 6 => "06", 7 => "07", 8 => "08", 9 => "09", 10 => "10", 11 => "11", 12 => "12");
     $year = array(date("Y"), date("Y") + 1, date("Y") + 2, date("Y") + 3, date("Y") + 4, date("Y") + 5, date("Y") + 6, date("Y") + 7, date("Y") + 8);
     $cards = array('Visa' => lib_lang('Visa'), 'MC' => lib_lang('Mastercard'), 'AMEX' => lib_lang('American Express'), 'Discover' => lib_lang('Discover'));
     $form = new formgen();
     $form->comment(lib_lang("Your Billing Information"));
     $form->input("<b>" . lib_lang("First Name") . "</b>", "f[first_name]", $f[first_name], 30);
     $form->input("<b>" . lib_lang("Last Name") . "</b>", "f[last_name]", $f[last_name], 30);
     $form->dropdown("<b>" . lib_lang("Card Type") . "</b>", "f[cardtype]", lib_htlist_array($cards, $f[cardtype]));
     $form->dropdown("<b>" . lib_lang("Expire Month") . "</b>", "f[last_name]", lib_htlist_array($month, $f[month]));
     $form->dropdown("<b>" . lib_lang("Expire Year") . "</b>", "f[last_year]", lib_htlist_array($year, $f[year]));
     $form->input("<b>" . lib_lang("Card Number") . "</b>", "f[cardnumber]", $f[cardnumber], 20);
     $form->line();
     $form->comment("<font size=3><b>" . lib_lang("Billing Address") . "</b></font>");
     $form->dropdown(lib_lang("Country"), "f[country]", lib_htlist_array($this->default[country], $f[country]));
     $form->input("<b>" . lib_lang("Address 1") . "</b>", "f[address1]", $f[address1], 50);
     $form->input("<b>" . lib_lang("Address 2") . "</b>", "f[address2]", $f[address2], 50);
     $form->input("<b>" . lib_lang("City") . "</b>", "f[city]", $f[city], 25);
     if ($this->default[adrevenue][country] == "US") {
         $form->dropdown(lib_lang("US State"), "f[state]", lib_htlist_array($this->default[states], $f[state]));
     } else {
         $form->input("<b>" . lib_lang("State") . "</b>", "f[state]", $f[state], 20);
     }
     $form->input("<b>" . lib_lang("Phone") . "</b>", "f[phone]", $f[phone], 25);
     $form->input("<b>" . lib_lang("Email") . "</b>", "f[email]", $f[email], 25);
     $form->hidden("section", "pay");
     $form->hidden("action", "form");
     $form->hidden("f[amount]", $f[amount]);
     $this->output->title = lib_lang("Edit Your Profile");
     $this->output->content = $form->generate("post", lib_lang("Save Profile"));
     $this->output->display();
     $this->output->printpage();
     exit;
 }
 function register()
 {
     global $DEFAULT;
     $f = $this->input->f;
     if ($f[email] && $f[name] && $f[password] && $f[postalcode] && $f[city] && $f[state] && $f[country]) {
         // Check email for duplication
         $em = $this->db->getsql("SELECT id FROM adrev_users WHERE email=?", array($f['email']));
         if ($em[0][id]) {
             $errormsg .= "<li> " . lib_lang("That email address was already used");
         }
         if (!lib_checkemail($f[email])) {
             $errormsg .= "<li> " . lib_lang("Invalid Email Address Entered");
         }
         if (!$f[postalcode]) {
             $errormsg .= "<li> " . lib_lang("Please enter your Postal/Zip Code");
         }
         if (!$f[country]) {
             $errormsg .= "<li> " . lib_lang("Please choose a country");
         }
         if (!$errormsg) {
             $i = array();
             $i[email] = trim(strtolower($f[email]));
             $i[country] = $f[country] ? $f[country] : "US";
             $i[password] = $f[password];
             $i[name] = $f[name];
             $i[organization] = $f[organization];
             $i[country] = $f[country];
             $i[street] = $f[street];
             $i[city] = $f[city];
             $i[state] = $f[state];
             $i[postalcode] = $f[postalcode];
             $i[url] = $f[url];
             $i[admin] = $_REQUEST[t] == "pub" ? 2 : 1;
             $i[zid] = uniqid("");
             $i['date'] = time();
             $i[ip] = $_SERVER['REMOTE_ADDR'];
             $i[status] = $this->default[adrevenue][confirm_registration] ? 0 : 1;
             $i[ref] = $f[ref];
             $this->db->insert("adrev_users", $i);
             // Notify us about new signups
             $d = array();
             reset($i);
             while (list($key, $val) = each($i)) {
                 $d[] = strtoupper($key) . '=' . $val;
             }
             $data = implode("\n", $d);
             mail($this->default[adrevenue][email], lib_lang('New Advertiser Signup'), lib_lang('A new advertiser signed up') . "\n", $data);
             // Send a confirmation email
             if ($this->default[adrevenue][confirm_registration]) {
                 $tpl = new XTemplate("templates/user_confirm.txt");
                 $tpl->assign("ZID", $i[zid]);
                 $tpl->parse("main");
                 $msg = $tpl->text("main");
                 mail($i[email], "[" . $this->default[adrevenue][name] . "] - " . lib_lang("Welcome - confirm your registration!"), $msg, "From: <" . $this->default[adrevenue][email] . ">");
                 $this->output->redirect(lib_lang("Please check your email for confirmation instructions"), "index.php?section=user&action=login", 5);
             } else {
                 $this->output->redirect(lib_lang("Saving your registration"), "index.php?section=user&action=login", 2);
             }
             exit;
         }
     }
     // Set default country
     if (!$f[country]) {
         $f[country] = "US";
     }
     $form = new formgen();
     $adname = "Advertiser";
     if ($_REQUEST[t] == "pub") {
         $adname = lib_lang("Publisher Registration");
     } else {
         $adname = lib_lang("Advertiser Registration");
     }
     $form->comment(lib_lang("Welcome! Please enter your information below."));
     if ($this->default[adrevenue][confirm_registration]) {
         $form->comment(lib_lang("Please enter a valid email address, since you will receive account activation instructions there."));
     }
     $form->comment("<font color=red>{$errormsg}</font>");
     $form->input("<b>" . lib_lang("Email") . "</b>", "f[email]", stripslashes($f[email]), 40, lib_lang("Your email will also be your login name"));
     $form->input("<b>" . lib_lang("Password") . "</b>", "f[password]", stripslashes($f[password]), 20);
     $form->input("<b>" . lib_lang("Name") . "</b>", "f[name]", stripslashes($f[name]), 40);
     $form->input(lib_lang("Organization"), "f[organization]", stripslashes($f[organization]), 40);
     $form->dropdown("<b>" . lib_lang("Country") . "</b>", "f[country]", lib_htlist_array($this->default[country], $f[country]));
     $form->input("<b>" . lib_lang("Street") . "</b>", "f[street]", stripslashes($f[street]), 40);
     $form->input("<b>" . lib_lang("City") . "</b>", "f[city]", stripslashes($f[city]), 20);
     $form->input("<b>" . lib_lang("State") . "</b>", "f[state]", stripslashes($f[state]), 10);
     $form->input("<b>" . lib_lang("Zip/Postal Code") . "</b>", "f[postalcode]", stripslashes($f[postalcode]), 10);
     $form->input(lib_lang("Url"), "f[url]", stripslashes($f[url]), 50);
     $form->input(lib_lang("Referrer"), "f[ref]", stripslashes($f[ref]), 30);
     $form->hidden("section", "user");
     $form->hidden("action", "register");
     $form->hidden("t", $_REQUEST[t]);
     $this->title = $adname;
     $this->content = $form->generate("post", lib_lang("Register"));
     $this->display();
     $this->printpage();
     exit;
 }
 }
 if (!$f[country]) {
     $f[country] = "US";
 }
 if (!$f[currency]) {
     $f[currency] = "USD";
 }
 if (!$f[organization]) {
     $f[organization] = "My Advertising Portal";
 }
 $dbs = array("mysql" => "MySQL");
 if ($errormsg) {
     $form->comment("<font color=red>{$errormsg}</font>");
 }
 $form->comment("<font size=3><b>Enter your database settings:</b></font>");
 $form->dropdown("<b>DB Type</b>", "f[engine]", lib_htlist_array($dbs, $f[engine]), "Choose the kind of database server you have");
 $form->input("<b>Hostname</b>", "f[host]", stripslashes($f[host]), 40, "The Domain Name or IP Address for your Database Server");
 $form->input("<b>Username</b>", "f[user]", stripslashes($f[user]), 20, "Database Login");
 $form->input("Password", "f[password]", stripslashes($f[password]), 20, "Database Password");
 $form->input("<b>DB Name</b>", "f[database]", stripslashes($f[database]), 20, "The name of the database where Revsense Data will live. You should have already created this.");
 $form->comment("<hr size=1><b><font size=3>Enter your Site Settings:</font></b><br>");
 $form->input("<b>Admin&nbsp;Email</b>", "f[email]", stripslashes($f[email]), 30);
 $form->input("<b>Admin&nbsp;Password</b>", "f[admin_password]", stripslashes($f[admin_password]), 20);
 $form->input("<b>Site Name</b>", "f[organization]", stripslashes($f[organization]), 30);
 $form->input("<b>URL</b>", "f[url]", stripslashes($f[url]), 50, "The URL where Revsense is installed. (It must have the trailing slash \"/\" at the end).");
 $form->dropdown("<b>Country</b>", "f[country]", lib_htlist_array($DEFAULT[country], $f[country]));
 $form->input("<b>Currency</b>", "f[currency]", $f[currency], 5, "Your currency code -- eg: USD");
 $out = $form->generate("post", "Create Revsense Installation") . "<p>&nbsp;";
 $tpl->assign("BODY", $out);
 $tpl->assign("TITLE", "INSTALLATION STEP 2: Database Settings");
 $tpl->parse("main");
 function form()
 {
     // Secured
     $this->output->secure();
     $f = $this->input->f;
     $parts = explode(" ", $_SESSION[user][name]);
     if (!$f[country]) {
         $f[country] = "US";
     }
     if (!$f[email]) {
         $f[email] = $_SESSION[user][email];
     }
     if (!$f[first_name]) {
         $f[first_name] = trim($parts[0]);
     }
     if (!$f[last_name]) {
         $f[last_name] = trim($parts[1]);
     }
     if (!$f[city]) {
         $f[city] = $_SESSION[user][city];
     }
     if (!$f[state]) {
         $f[state] = $_SESSION[user][state];
     }
     if (!$f[zip]) {
         $f[zip] = $_SESSION[user][postalcode];
     }
     if (!$f[address]) {
         $f[address] = $_SESSION[user][street];
     }
     if (!$f[amount]) {
         $f[amount] = $f[amount];
     }
     // Setup a form
     $form = new formgen();
     if ($f[errormsg]) {
         $form->comment("<li> <font color=red><b>{$f['errormsg']}</b></font>");
     }
     $form->comment("<i>@@Please fill all applicable fields@@</i><br>&nbsp;");
     $form->comment("<b>@@Address Information@@</b>");
     $form->input("@@First Name@@", "f[first_name]", $f[first_name], 30);
     $form->input("@@Last Name@@", "f[last_name]", $f[last_name], 30);
     $form->input("@@Telephone@@", "f[phone]", $f[phone], 15);
     $form->input("@@Email@@", "f[email]", $f[email], 30);
     $form->input("@@Address@@", "f[address]", $f[address], 50);
     $form->input("@@City@@", "f[city]", $f[city], 20);
     $form->input("@@State@@", "f[state]", $f[state], 20);
     $form->input("@@Zip@@", "f[zip]", $f[zip], 10);
     $form->dropdown("@@Country@@", "f[country]", lib_htlist_array($this->default[country], $f[country]));
     // You can comment out these sections or add new fields as necessary
     $form->comment("<b>@@Billing Information@@</b>");
     $form->input("@@CardNumber@@", "f[card_num]", $f[card_num], 30);
     $form->input("@@ExpireDate@@", "f[exp_date]", $f[exp_date], 10, "@@Format should be MM/YYYY@@");
     $form->input("@@Card Code@@", "f[card_code]", $f[card_code], 5, "@@3 or 4 digit number on the back of your card@@");
     $form->hidden("f[amount]", $f[amount]);
     $form->hidden("section", "pay");
     $form->hidden("action", "process");
     $this->title = lib_lang("Enter your Credit Card Information");
     $this->content = $form->generate("post", lib_lang("Submit"));
     $this->display();
     $this->printpage();
     exit;
 }
 function _default()
 {
     $this->output->admin();
     $f = $this->input->f;
     // Save Settings
     if (count($f) > 0) {
         // set defaults for checkboxes
         if (!$f[confirm_registration]) {
             $f[confirm_registration] = 0;
         }
         if (!$f[approve_ads]) {
             $f[approve_ads] = 0;
         }
         reset($f);
         while (list($key, $val) = each($f)) {
             $this->save($key, $val);
         }
         $this->output->redirect("The site settings were updated", "index.php?section=settings", 1);
         exit;
     }
     // Loadup stuff
     $settings = $this->db->getsql("SELECT * FROM adrev_settings");
     $set = array();
     foreach ($settings as $rec) {
         $set[$rec[name]] = stripslashes($rec[value]);
     }
     // Grab list of payment modules
     $modules = array();
     if ($handle = opendir("modules")) {
         while (FALSE !== ($file = readdir($handle))) {
             if (preg_match('/pay\\.(.*?)\\.php/i', $file, $match)) {
                 $modules[$match[1]] = lib_lang(ucfirst($match[1]));
             }
         }
         closedir($handle);
     }
     $form = new formgen();
     $form->comment("<font size=3><b>" . lib_lang("Site Properties") . "</b></font>");
     $form->input(lib_lang("Site Name"), "f[name]", stripslashes($set[name]), 40);
     $form->input(lib_lang("URL"), "f[url]", stripslashes($set[url]), 50);
     $form->input(lib_lang("Email"), "f[email]", stripslashes($set[email]), 30);
     $form->input(lib_lang("Language"), "f[language]", stripslashes($set[language]), 5);
     $form->input(lib_lang("P3P Header"), "f[p3p]", stripslashes($set[p3p]), 60, lib_lang('Compact Privacy Policy Header') . '. <a href="http://www.w3.org/P3P/usep3p.html" target="_new">@@More about P3P@@</a>');
     $form->input(lib_lang("Caching"), "f[cache]", stripslashes($set[cache]), 5, lib_lang("Caching time in seconds"));
     $form->checkbox(lib_lang("Registrations must be confirmed by email"), "f[confirm_registration]", 1, iif($set[confirm_registration] == 1, "CHECKED", ""));
     $form->line();
     $form->comment("<font size=3><b>" . lib_lang("Fraud Protection") . "</b></font>");
     $form->input(lib_lang("Duplicate Clicks"), "f[dup_clicks]", stripslashes($set[dup_clicks]), 5, lib_lang("This is the duplicate clicks threshold seconds."));
     $form->input(lib_lang("Duplicate Impressions"), "f[dup_impressions]", stripslashes($set[dup_impressions]), 5, lib_lang("This is the duplicate impressions threshold seconds."));
     $form->line();
     $form->comment("<font size=3><b>" . lib_lang("Ad Settings") . "</b></font>");
     $form->checkbox(lib_lang("Automatically approve ads."), "f[approve_ads]", 1, iif($set[approve_ads], "CHECKED", ""));
     $form->input(lib_lang("Min Bid"), "f[min_bid]", stripslashes($set[min_bid]), 10);
     $form->input(lib_lang("Max Bid"), "f[max_bid]", stripslashes($set[max_bid]), 10);
     $form->input(lib_lang("Min Payment"), "f[min_payment]", stripslashes($set[min_payment]), 10);
     $form->input(lib_lang("Currency"), "f[currency]", stripslashes($set[currency]), 5);
     $form->input(lib_lang("Symbol"), "f[currency_symbol]", stripslashes($set[currency_symbol]), 5);
     $form->input(lib_lang("Default Redir"), "f[default_redir]", stripslashes($set[default_redir]), 40, lib_lang("This is the URL that ads will go to if the url in the ad fails."));
     if ($set[payment_module]) {
         $modlink = "<a href=?section=settings&action=pay_settings>@@Edit Payment Module Settings@@</a>";
     }
     $form->dropdown(lib_lang("Payment Module"), "f[payment_module]", lib_htlist_array($modules, $set[payment_module]), $modlink);
     $form->line();
     $form->comment("<font size=3><b>" . lib_lang("Content") . "</b></font>");
     $form->comment("<font size=2>" . lib_lang("You can use HTML and images in any of the content fields below") . "</font>");
     $form->textarea(lib_lang("Terms and Conditions"), "f[terms]", $set[terms], 6, 60, lib_lang("Enter your terms and conditions"));
     $form->textarea(lib_lang("Frontpage Content"), "f[frontpage]", $set[frontpage], 6, 60, lib_lang("This content will appear to users who are not logged in."));
     $form->textarea(lib_lang("Advertiser Welcome Page"), "f[content_adv_login]", $set[content_adv_login], 6, 60, lib_lang("This content will appear to logged in advertisers"));
     $form->textarea(lib_lang("Publisher Welcome Page"), "f[content_pub_login]", $set[content_pub_login], 6, 60, lib_lang("This content will appear to logged in publishers"));
     $form->textarea(lib_lang("FAQ"), "f[faq]", $set[faq], 6, 60, lib_lang("Your FAQ"));
     $form->hidden("section", "settings");
     $this->title = lib_lang("Edit AdRevenue Settings");
     $this->content = $form->generate("post", lib_lang("Save Settings"));
     $this->display();
     $this->printpage();
     exit;
 }