function form($object)
 {
     if (!defined('SYS_FORMS')) {
         include_once BASE . 'subsystems/forms.php';
     }
     exponent_forms_initialize();
     $form = new form();
     if (!isset($object->id)) {
         $object->name = '';
         $object->affiliate_id = 0;
         $object->url = 'http://';
     } else {
         $form->meta('id', $object->id);
         global $db;
         $file = $db->selectObject('file', 'id=' . $object->file_id);
         $form->register(uniqid(''), '', new htmlcontrol('<img src="' . $file->directory . '/' . $file->filename . '"/>'));
     }
     $i18n = exponent_lang_loadFile('datatypes/banner_ad.php');
     $affiliates = BannerModule::listAffiliates();
     $form->register('name', $i18n['name'], new textcontrol($object->name));
     $submit = new buttongroupcontrol($i18n['save'], '', $i18n['cancel']);
     if (count($affiliates)) {
         $form->register('affiliate_id', $i18n['affiliate_id'], new dropdowncontrol($object->affiliate_id, $affiliates));
     } else {
         $form->registerBefore('name', null, '', new htmlcontrol('<div class="error">' . $i18n['no_affiliates'] . '</div>'));
         $submit->disabled = 1;
     }
     $form->register('url', $i18n['url'], new texteditorcontrol($object->url, 2, 40));
     $form->register('submit', '', $submit);
     return $form;
 }
 function show($view, $loc, $title = '')
 {
     global $db;
     $template = new template('BannerModule', $view, $loc);
     $template->assign('title', $title);
     $viewconfig = array('type' => 'default', 'number' => 1);
     if (is_readable($template->viewdir . "/{$view}.config")) {
         $viewconfig = (include $template->viewdir . "/{$view}.config");
     }
     if ($viewconfig['type'] == 'affiliates') {
         $af = $db->selectObjects('banner_affiliate');
         for ($i = 0; $i < count($af); $i++) {
             $af[$i]->bannerCount = $db->countObjects('banner_ad', 'affiliate_id=' . $af[$i]->id);
             $af[$i]->contact_info = str_replace("\n", "<br />", $af[$i]->contact_info);
         }
         if (!defined('SYS_SORTING')) {
             require_once BASE . 'subsystems/sorting.php';
         }
         usort($af, 'exponent_sorting_byNameAscending');
         $template->assign('affiliates', $af);
     } else {
         if (!defined('SYS_FILES')) {
             require_once BASE . 'subsystems/files.php';
         }
         $directory = 'files/BannerModule/' . $loc->src;
         if (!file_exists(BASE . $directory)) {
             $err = exponent_files_makeDirectory($directory);
             if ($err != SYS_FILES_SUCCESS) {
                 $template->assign('noupload', 1);
                 $template->assign('uploadError', $err);
             }
         }
         $all = $db->selectObjects('banner_ad', "location_data='" . serialize($loc) . "'");
         if ($viewconfig['type'] == 'allbanners') {
             $bfiles = $db->selectObjectsIndexedArray('file', "directory='" . $directory . "'");
             $template->assign('affiliates', BannerModule::listAffiliates());
             $template->assign('files', $bfiles);
             $template->assign('banners', $all);
         } else {
             $num = $viewconfig['number'];
             shuffle($all);
             $banners = array_slice($all, 0, $num);
             for ($i = 0; $i < count($banners); $i++) {
                 $banners[$i]->file = $db->selectObject('file', 'id=' . $banners[$i]->file_id);
             }
             $template->assign('banners', $banners);
         }
     }
     $template->register_permissions(array('administrate', 'manage', 'manage_af'), $loc);
     $template->output();
 }