'doNew',
'cancel' => 'doBack',
'insert' => 'doInsert',
'edit' => 'doEdit',
'update' => 'doUpdate',
'del' => 'doDelete',
);
function _bindFormFields($form)
{
$this->Doc->addItemProp('JSs', 'js/admin_member_form.js');
$this->Doc->addItemProp('initFuncsEx', array('name'=>'initCompanyForm', 'params'=>array(
$form->_attributes['id'],
intval($this->DBObj->getData('id'))
)));
$form->addElement('hidden', 'redirect_url');
$form->addElement('hidden', 'id_individual', $this->DBObj->id_individual);
// GENERAL COMPANY INFORMATION
$form->addElement('header', 'header_general_company_information', 'GENERAL COMPANY INFORMATION');
$form->addElement('select', 'status', 'Company Status', array('normal'=>'Normal', 'deleted'=>'Deteled'));
$form->addElement('text', 'name', 'Company Name');
$form->addRuleRequired(array('name'));
$form->addElement('select', 'id_type', 'Company Type', (array)$this->DBObj->getDCompanyType4Select() + array(0=>'Other'));
$form->addElement('extended_text', 'website', 'Company Web Site', array('class'=>'inp_website'), 'http://');
// KEY INDIVIDUAL SETTINGS
$form->addElement('header', 'header_key_individual_settings', 'KEY INDIVIDUAL SETTINGS');
$form->addElement('advmultiselect', 'ids_individual', array('Individuals with permission set
company information', 'No Permission Given', 'Those With Permission'), $this->DBObj->getIndividuals4Select(), array('style'=>'width:250px'));
$this->Doc->addItemProp('JSs', 'js/jquery.bginput.js');
$this->Doc->addItemProp('initFuncs', 'bginput_init');
// COMPANY NOTES
$form->addElement('header', 'header_company_notes', 'COMPANY NOTES');
$form->addElement('textarea', 'note', null, array('cols'=>5, 'style'=>'width:100%'));
return $form;
}
function _getNewForm()
{
$form = $this->_getBaseForm();
$form = $this->_bindFormFields($form);
$form->removeElements('id_html_individual', 'id_realtor', 'header_key_individual_settings');
$this->setFormTitle($form, 'Add '.$this->DBObj->itemName);
$form->addElement('hidden', 'action', 'insert') ;
return $form;
}
function doNew()
{
$form = $this->_getNewForm();
$this->renderForm($form);
}
function doEdit()
{
$this->DBObj->initFromDB();
$data = $this->DBObj->getData();
$form = $this->_getEditForm();
$id = $form->createElement('static', 'company_id', 'Company ID', $data['id']);
$form->insertElementAfter($id, 'header_general_company_information');
$changed = &$form->createElement('static', 'changed', 'Last Updated');
$form->insertElementBefore($changed, 'status');
$added = &$form->createElement('static', 'added', 'Date Created');
$form->insertElementBefore($added, 'status');
$static_location_cnt = $form->createElement('static', 'static_location_cnt', '# of locations within this company',
''.(int)$this->DBObj->getData('location_cnt').''
.' | Click to add an location'
);
$form->insertElementBefore($static_location_cnt, 'status');
$static_individual_cnt = $form->createElement('static', 'static_individual_cnt', '# of individuals within this company',
''.(int)$this->DBObj->getData('individual_cnt').''
.' | Click to add an individual'
);
$form->insertElementBefore($static_individual_cnt, 'status');
$form->setDefaults($data);
$this->renderForm($form);
}
function doInsert()
{
$form = $this->_getNewForm();
if ($form->validate()){
$this->DBObj->initFromForm($form );
$this->DBObj->insert();
$this->initTabRedirect();
if (empty($this->DBObj->_data['redirect_url'])) {
Session::setData(CURR_PAGE_FULL, 'msg', $this->DBObj->itemName.' added');
}
$this->doBack();
}else {
$this->renderForm($form);
}
return true;
}
function doUpdate()
{
$form = $this->_getEditForm();
if ($form->validate()){
$this->DBObj->initFromDB();
$this->DBObj->setOldData($this->DBObj->getData());
$this->DBObj->initFromForm($form);
$this->DBObj->update();
$this->initTabRedirect();
if (empty($this->DBObj->_data['redirect_url'])) {
Session::setData(CURR_PAGE_FULL, 'msg', $this->DBObj->itemName.' updated');
}
$this->doBack();
}else {
$this->renderForm($form);
}
return true;
}
function renderForm(&$form)
{
$linkItem = array(
'tpl' => 'center_link.tpl',
'link' => Constant::get('BASE_URL').'/'.CURR_PAGE.'?action=cancel'.(($this->DBObj->id_individual)?'&id_individual='.$this->DBObj->id_individual:''),
'title' => '<< Back to list'
);
$this->Doc->addContent($linkItem);
$this->addTabHeader();
$form->exec();
$this->addTabFooter();
}
function getBackUrl()
{
if ($this->DBObj->id_individual) {
return parent::getBackUrl();
} else {
$url = Session::getData('admin/location', 'query_string');
if (empty($url)) {
$url = BASE_URL.'/admin/location';
}
return $url;
}
}
function getTabs()
{
$tabs = array();
$tabs[] = array('alias'=>'admin/member?action=edit&id='.$this->DBObj->id_individual, 'title'=>'Individual Information');
$tabs[] = array('alias'=>'admin/member?action=edit_location&id='.$this->DBObj->id_individual, 'title'=>'Location Information');
$tabs[] = array('alias'=>'#', 'title'=>'Company Information', 'current'=>1);
return $tabs;
}
function addTabHeader()
{
if (!$this->DBObj->id_individual) {
return;
}
$item = array();
$item['tpl'] = 'Member/tab_header.tpl';
$item['tabs'] = $this->getTabs();
$this->Doc->addContent($item);
}
function addTabFooter()
{
if (!$this->DBObj->id_individual) {
return;
}
$item = array();
$item['tpl'] = 'Member/tab_footer.tpl';
$this->Doc->addContent($item);
}
function initTabRedirect()
{
if (!empty($this->DBObj->_data['redirect_url'])) {
$this->setBackUrl($this->DBObj->_data['redirect_url']);
} else {
$url = BASE_URL.'/'.CURR_PAGE_FULL.'?action=edit&id='.$this->DBObj->id;
if ($this->DBObj->id_individual) {
$url .= '&id_individual='.$this->DBObj->id_individual;
}
$this->setBackUrl($url);
}
}
}