def_order_by = 'company';
$DB_List->insertColLast('sponsor', array(
'title' => 'Sponsor',
'order_by' => 'sponsor',
'width' => 70,
'values' => array('y' => 'Yes', 'n' => 'No'),
'url' => BASE_URL . '/' . CURR_PAGE . '/?action=chopt&opt=sponsor&id=',
'tpl' => DB_LIST_CELL_LINK_ENUM,
'params' => array('sponsor', 'id'),
));
$DB_List->insertColLast('company', array(
'title' => 'Company',
'order_by' => 'company',
'width' => 220,
'tpl' => DB_LIST_CELL_TEXT,
'params' => array('company'),
));
$DB_List->insertColLast('contact_name', array(
'title' => 'Contact Name',
'order_by' => 'contact_name',
'width' => 170,
'tpl' => DB_LIST_CELL_TEXT,
'params' => array('contact_name'),
));
$DB_List->insertColLast('statictics', array(
'title' => 'Statistics',
'width' => 200,
'tpl' => SiteMap::getPath('FeaturedProperty/tpl/statistics.tpl'),
'params' => array('statistics'),
));
$DB_List->insertColLast('active', array(
'title' => 'Active',
'order_by' => 'active',
'width' => 80,
'tpl' => DB_LIST_CELL_TEXT_CENTER,
'params' => array('active')
));
$DB_List->insertColLast('options', array(
'title' => 'Options',
'tpl' => DB_LIST_CELL_EDIT_DEL,
'edit_link' => BASE_URL . '/' . CURR_PAGE . '?action=edit&id=',
'del_link' => BASE_URL . '/' . CURR_PAGE . '?action=del&id=',
'params' => array('id'),
));
$DB_List->bind();
return true;
}
function addLink()
{
return false;
}
function addLink2()
{
$link = BASE_URL . '/' . CURR_PAGE;
$addLink = array(
'tpl' => 'center_link.tpl',
'link_list' => array(
array('title' => 'Click here to add a new ' . $this->DBObj->itemName, 'link' => $link . '?action=new'),
//array('title' => 'Click here to reorder ' . $this->DBObj->itemsName, 'link' => $link . '?action=reorder'),
),
);
$this->Doc->addContent($addLink);
}
function formCreateAdvcheckboxList(&$form, $name, $list)
{
if (!is_array($list) || empty($list)) {
return false;
}
$elList = array();
foreach ($list as $id => $title) {
$elList[$id] = $form->createElement('advcheckbox', $name.'['.$id.']', '', $title, null, array('0', $id));
}
return $elList;
}
function _bindFormFields($form)
{
$calendarOptions = array(
'language' => 'en',
'format' => 'dMY',
'minYear' => 2010,
'maxYear' => (int) date('Y') + 5,
'addEmptyOption' => true,
'emptyOptionValue' => '',
'emptyOptionText' => ' ',
'optionIncrement' => array('i' => 1, 's' => 1)
);
$elementOptions = array('onchange' => 'featuredPropertyForm.updateStatus();');
$form->addElement('calendar', 'start_date', 'Start Date', $calendarOptions, $elementOptions);
$form->addElement('calendar', 'end_date', 'End Date', $calendarOptions, $elementOptions);
$form->addElement('static', 'active', 'Active', '
undefined
');
$form->addElement('advcheckbox', 'sponsor', 'Sponsor', null, null, array('n', 'y'));
$form->addElement('text', 'company', 'Company');
$form->addElement('text', 'contact_name', 'Contact Name');
$form->addElement('text', 'property_name', 'Property Name');
$form->addElement('text', 'property_address', 'Property Address');
$form->addElement('text', 'property_city', 'Property City');
$form->addElement('text', 'property_state', 'Property State');
$form->addElement('text', 'property_zip', 'Property Zip');
$form->addElement('text', 'property_type', 'Property Type');
//$form->addElement('text', 'brokerage', 'Brokerage');
$form->addElement('select', 'id_availability', 'Availability', array('' => 'Select One') + $this->DBObj->get4Select('DFeaturedPropertyAvailability'));
//$form->addElement('text', 'price', 'Price/Rates');
//$form->addElement('text', 'square_feet', 'Square Feet');
$img =& $form->createElement('img_db', 'photo', 'Photo', null, '');
$img->titles['last'] = 'Preferred image size ' . $this->DBObj->photoWidth . 'x' . $this->DBObj->photoHeigth . ' pixels';
$form->addElement($img);
$form->addRule('photo', 'Photo is required', 'required');
//$form->addElement('extended_text', 'be_seen_url', 'Be Seen Here URL', null, null, 'Example: http://google.com
');
$form->addElement('extended_text', 'url', 'URL', null, null, 'Example: http://google.com
');
$form->addRuleRequired(array(
'start_date',
'end_date',
'company',
'contact_name',
'property_name',
'property_address',
'property_city',
'property_state',
'property_zip',
'property_type',
'id_availability',
//'price',
//'square_feet',
'url',
));
$regex = '/^((http|https|ftp):\/\/)(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i';
//$form->addRule('be_seen_url', 'Be Seen Here URL is in wrong format', 'regex', $regex);
//$form->addRule('be_seen_url', 'Be Seen Here URL is in wrong format', 'regex', $regex, 'client');
$form->addRule('url', 'URL is in wrong format', 'regex', $regex);
$form->addRule('url', 'URL is in wrong format', 'regex', $regex, 'client');
$form->addFormRule(array($this, 'validForm'));
return $form;
}
function validForm($data, $files)
{
$errors = array();
if (!empty($files['photo']['tmp_name']['file'])) {
if (strncmp($files['photo']['type']['file'], 'image', 5) != 0) {
$errors['photo'] = 'File format is wrong';
} else {
//list($width, $height, $type, $attr) = getimagesize($files['photo']['tmp_name']['file']);
//if ($width != $this->DBObj->photoWidth || $height != $this->DBObj->photoHeigth) {
// $errors['photo'] = 'Photo size must be equal ' . $this->DBObj->photoWidth . 'x' . $this->DBObj->photoHeigth . ' pixels';
//}
}
} elseif (empty($data['photo']['file_name'])) {
$errors['photo'] = 'Photo is required';
}
$check = true;
if (!$this->DBObj->checkCalendarDate($data['start_date'])) {
$errors['start_date'] = 'Date is wrong';
$check = false;
}
if (!$this->DBObj->checkCalendarDate($data['end_date'])) {
$errors['end_date'] = 'Date is wrong';
$check = false;
}
if ($check) {
if ($this->DBObj->formaCalendartDate($data['start_date']) > $this->DBObj->formaCalendartDate($data['end_date'])) {
$errors['end_date'] = "End Date must be after Start Date";
}
}
return (empty($errors)) ? true : $errors;
}
function doNew()
{
$form = $this->_getNewForm();
$form->addRule('photo', 'Photo is required', 'uploadedfile');
$this->setFormTitle($form, 'Add ' . $this->DBObj->itemName);
$data = array(
'start_date' => date('Y-m-d'),
'end_date' => date('Y-m-d', strtotime('+1 month')),
);
$form->setDefaults($data);
$this->renderForm($form);
}
function doEdit()
{
$this->DBObj->initFromDB();
$form = $this->_getEditForm();
$form->setDefaults($this->DBObj->getData());
$this->renderForm($form);
}
function renderForm($form)
{
$this->Doc->addItemProp('JSs', 'js/featuredProperty_functions.js');
$this->Doc->addContent(array('tpl' => 'text.tpl', 'text' => ''));
$form->exec();
}
function getFilterForm()
{
$form = new Form($this->Doc, 'form_search_featured_property', 'get', '', '_self', array('class' => 'form form_search_featured_property'));
$form->tpl = SiteMap::getPath('FeaturedProperty/tpl/filter.tpl');
$form->setRendType(FORM_RENDERER_ARRAY_SMARTY);
$form->addElement('select', 'id_availability', 'Availability', array('' => 'All') + $this->DBObj->get4Select('DFeaturedPropertyAvailability'), array('onchange' => 'this.form.submit();'));
$form->addElement('select', 'active', 'Active', array('' => 'All', 'y' => 'Yes', 'n' => 'No'), array('onchange' => 'this.form.submit();'));
$form->addElement('text', 'query', 'Search For', array('style' => 'width:400px;'));
$form->addElement('submit', 'submit_btn', 'Search', array('class' => 'btn'));
$form->addElement('button', 'cancel_btn', 'Cancel', array('class' => 'btn', 'onclick' => "document.location.href='" . Constant::get('BASE_URL') . '/' . CURR_PAGE . "'"));
return $form;
}
function doList()
{
$this->addLink2();
$filterForm = $this->getFilterForm();
$this->DBObj->setFilter($filterForm->exportValues());
$filterForm->exec();
return parent::doList();
}
}