function schedule()
 {
     $this->output->secure();
     $f = $this->input->f;
     $uid = $_SESSION['user']['id'];
     $tpl = new XTemplate("templates/ad_daypart.html");
     if ($_SESSION['user']['admin'] == 3) {
         $xad = $this->db->getsql("SELECT userid FROM adrev_ads WHERE zid=?", array($f['id']));
         $uid = $xad['0']['userid'];
     }
     // Loadup the ad
     $ad = $this->db->getsql("SELECT a.*,b.rate_type FROM adrev_ads a, adrev_zones b\r\n\t\t\t\t\t\t\t\t\tWHERE a.zid=? AND a.userid=? AND a.zone=b.id", array($f['id'], $uid));
     // Update the ad
     if ($f['submit'] && $ad['0']['id']) {
         // Compute the days
         $f['startdate'] = 0;
         $f['expires'] = 0;
         if ($f['start_month'] && $f['start_day'] && $f['start_year']) {
             $f['startdate'] = strtotime("{$f['start_month']}/{$f['start_day']}/{$f['start_year']} 00:00:01");
         }
         if ($f['expire_month'] && $f['expire_day'] && $f['expire_year']) {
             $f['expires'] = strtotime("{$f['expire_month']}/{$f['expire_day']}/{$f['expire_year']} 23:59:59");
         }
         $i = array();
         $i['daypart_days'] = lib_options($f['daypart_days']);
         $i['daypart_hours'] = lib_options($f['daypart_hours']);
         $i['startdate'] = $f['startdate'];
         $i['expires'] = $f['expires'];
         $i['units'] = $f['units'];
         $i['spend_limit'] = $f['spend_limit'];
         $this->db->update("adrev_ads", "zid", $f['id'], $i);
         $this->output->redirect(lib_lang("Daypart options were updated"), "index.php?section=ads&action=schedule&f[id]={$f['id']}", 1);
         exit;
     }
     // Show the form
     $tpl = new XTemplate("templates/ad_daypart.html");
     // Days
     $f['daypart_days'] = lib_bit_options($ad['0']['daypart_days']);
     for ($day = 0; $day < 7; $day++) {
         $tpl->assign("DAY", $day);
         if (in_array($day, $f['daypart_days'])) {
             $tpl->assign("DAYPART_DAY", "CHECKED");
         } else {
             $tpl->assign("DAYPART_DAY", "");
         }
         $tpl->parse("main.days");
     }
     // Hours
     $f['daypart_hours'] = lib_bit_options($ad['0']['daypart_hours']);
     for ($hour = 0; $hour < 24; $hour++) {
         $tpl->assign("HOUR_TITLE", $hour);
         $tpl->parse("main.hour_title");
         $tpl->assign("HOUR", $hour);
         if (in_array($hour, $f['daypart_hours'])) {
             $tpl->assign("DAYPART_HOUR", "CHECKED");
         } else {
             $tpl->assign("DAYPART_HOUR", "");
         }
         $tpl->parse("main.hours");
     }
     $tpl->assign("ID", $f['id']);
     $tpl->assign("TZ", date("T"));
     $tpl->assign("STARTDATE", lib_dateinput("start", $ad['0']['startdate'], date("Y"), 4));
     $tpl->assign("ENDDATE", lib_dateinput("expire", $ad['0']['expires'], date("Y"), 4));
     $tpl->assign("UNITS", $ad['0']['units']);
     $tpl->assign("TOTAL_UNITS", $ad['0']['total_units']);
     $tpl->assign('SPEND_LIMIT', $ad['0']['spend_limit']);
     if ($ad['0']['rate_type'] == "CPC") {
         $tpl->assign("SUNITS", "@@Clicks@@");
     } elseif ($ad['0']['rate_type'] == "CPM") {
         $tpl->assign("SUNITS", "@@Impressions@@");
     } elseif ($ad['0']['rate_type'] == "CPD") {
         $tpl->assign("SUNITS", "@@Days@@");
     } elseif ($ad['0']['rate_type'] == "CPA") {
         $tpl->assign("SUNITS", "@@Orders@@");
     }
     $tpl->assign("ADS_MENU", $this->menu($_REQUEST['f']['id']));
     $tpl->parse("main");
     $this->title = lib_lang("Scheduling");
     $this->content = $tpl->text("main");
     $this->display();
     $this->printpage();
     exit;
 }
 function zone_daypart()
 {
     $this->output->admin();
     $f = $this->input->f;
     // Loadup the zone
     $z = $this->db->getsql("SELECT * FROM adrev_zones WHERE id=?", array($f['id']));
     if (!$z[0][id]) {
         $this->output->redirect(lib_lang("The zone could not be found"), "index.php?section=zone", 3);
         exit;
     }
     // Update the zone
     if ($f[submit]) {
         $i = array();
         $i[daypart_enable] = $f[daypart_enable] ? 1 : 0;
         $i[daypart_days] = lib_options($f[daypart_days]);
         $i[daypart_hours] = lib_options($f[daypart_hours]);
         $this->db->update("adrev_zones", "id", $f[id], $i);
         $this->output->redirect(lib_lang("Daypart options were updated"), "index.php?section=zone&action=zone_daypart&f[id]={$f['id']}", 1);
         exit;
     }
     // Show the form
     $tpl = new XTemplate("templates/zone_daypart.html");
     // Days
     $f[daypart_days] = lib_bit_options($z[0][daypart_days]);
     for ($day = 0; $day < 7; $day++) {
         $tpl->assign("DAY", $day);
         if (in_array($day, $f[daypart_days])) {
             $tpl->assign("DAYPART_DAY", "CHECKED");
         } else {
             $tpl->assign("DAYPART_DAY", "");
         }
         $tpl->parse("main.days");
     }
     // Hours
     $f[daypart_hours] = lib_bit_options($z[0][daypart_hours]);
     for ($hour = 0; $hour < 24; $hour++) {
         $tpl->assign("HOUR_TITLE", $hour);
         $tpl->parse("main.hour_title");
         $tpl->assign("HOUR", $hour);
         if (in_array($hour, $f[daypart_hours])) {
             $tpl->assign("DAYPART_HOUR", "CHECKED");
         } else {
             $tpl->assign("DAYPART_HOUR", "");
         }
         $tpl->parse("main.hours");
     }
     $tpl->assign("ID", $f[id]);
     $tpl->assign("TZ", date("T"));
     $tpl->assign("DAYPART_ENABLE", $z[0][daypart_enable] ? "CHECKED" : "");
     $tpl->assign("ZONE_MENU", $this->zone_menu($f[id]));
     $tpl->parse("main");
     $this->title = lib_lang("Manage") . "[" . stripslashes($z[0][name]) . "] : " . lib_lang("Dayparting");
     $this->content = $tpl->text("main");
     $this->display();
     $this->printpage();
     exit;
 }