actions['export_to_csv'] = 'doExportCSV';
$this->actions['export_to_xls'] = 'doExportXLS';
$this->DB_Grid($Page, $DBObj);
}
function doEdit()
{
$this->Doc->addContent(array(
'tpl' => SiteMap::getPath('FormMail/tpl/admin/see_req_retails.tpl'),
'mail' => $this->DBObj->getFromDB($this->DBObj->id),
'back' => CURR_PAGE.'?action=cancel'
)
);
}
/*
function fieldValid($fields)
{
$errorMsgs = array();
$isValidValid = true;
switch ($fields['type']) {
case 'header':
if (count($fields['valid'])){
$isValidValid = false;
}
break;
case 'select':
case 'checkboxes':
case 'radioboxes':
if (!isset($fields['value'])){
$errorMsgs['value'] = 'The options are required for this field type';
}
case 'file':
case 'checkbox':
if (in_array('email', (array)$fields['valid']) ){
$isValidValid = false;
}
break;
default:
break;
}
if (!$isValidValid){
$errorMsgs['valid'] = 'This field type cannot be validated in this way';
}
if (count($errorMsgs)){
return $errorMsgs;
}else {
return true;
}
}
function _bindFormReqs($form)
{
$form = parent::_bindFormReqs($form);
$form->addFormRule(array(&$this, 'fieldValid') );
$form->removeElement('sorter');
$form->removeElement('type');
// $form->addElement('header', 'label', 'Label');
require_once 'class/DB/Lang/DLang.php';
$DLang = new DLang();
$langList = $DLang->getList();
if (count($langList) > 1){
$form->addElement('header', 'title_header', 'Label');
}
foreach ($langList as $lang){
if (count($langList) == 1){
$title_error = 'Label is required';
$title = 'Label';
}else{
$title_error = $lang['title'] . ' label is required';
$title = $lang['title'];
}
$name = "label[{$lang['name']}]";
$form->addElement('text', $name, $title, array('value' => $this->DBObj->getData($name)) );
$form->addRule($name, $title_error, 'required');
}
$type = Form::createElement('select', 'type', 'Type', $this->DBObj->getTypes() );
$type->setValue($this->DBObj->getData('type'));
$form->addElement($type);
$valid = Form::createElement('advmultiselect', 'valid', 'Validation', $this->DBObj->getValidators(), array('size' => 7) );
$template = '
{javascript}
{label_2} |
| {label_3} |
{unselected} |
{add} {remove}
{moveup} {movedown}
|
{selected} |
';
$valid->setElementTemplate($template);
// $valid->setValue(array('one_of_set', 'email'));
if (is_array($this->DBObj->getData('valid'))){
$valid->setValue((array)$this->DBObj->getData('valid'));
}
$form->addElement($valid);
$form->removeElement('id_fm');
$form->addElement('hidden', 'id_fm', $this->DBObj->id_fm);
// $value = SiteMap::getObj('FormMail/Req/Grid/multiVal.php', 'value', 'Options', $DLang->getList(), $this->DBObj->getData('value') );
$form->addElement('grid', 'value', 'Options', $DLang->getList(), $this->DBObj->getData('value') );
return $form;
}
*/
function addLink()
{
$filtFrm = $this->getFilterForm();
$addLink = array(
'tpl' => 'center_link.tpl',
'link_list' => array(
array('link' => Session::getData(PARENT_PAGE, 'back_path'), 'title' => '<< Back to Form Mail'),
array(
'link' => Constant::get('BASE_URL').'/'.CURR_PAGE.'?action=export_to_xls&id_fm='.$this->DBObj->id_fm.
'&query='.urlencode($filtFrm->getElementValue('query')),
'title' => 'Export to Excel', ),
array('link' => Constant::get('BASE_URL').'/'.CURR_PAGE.'?action=export_to_csv&id_fm='.$this->DBObj->id_fm.
'&query='.urlencode($filtFrm->getElementValue('query')),
'title' => 'Export to CSV', ),
),
);
$this->Doc->addContent($addLink);
}
function getFilterForm()
{
$form = parent::getFilterForm();
$form->addElement('hidden', 'id_fm', $this->DBObj->id_fm );
$form->updateElementAttr('cancel', array('onclick' => "document.location.href='".Constant::get('BASE_URL').'/'.CURR_PAGE."?id_fm=".$this->DBObj->id_fm."'" ) );
return $form;
}
function doList()
{
$filtFrm = $this->getFilterForm();
$this->DBObj->setFilter($filtFrm->getElementValue('query'));
$filtFrm->exec();
parent::doList();
}
function &_getDataGrid4Export()
{
require_once 'Structures/DataGrid.php';
$datagrid =& new Structures_DataGrid();
$datagrid->addColumn(new Structures_DataGrid_Column('Added', 'added', 'added'));
$flds = $this->_getFlds();
foreach ($flds as $fld){
$datagrid->addColumn(new Structures_DataGrid_Column($fld['label'], 'f_'.$fld['id']));
}
$filtFrm = $this->getFilterForm();
$this->DBObj->setFilter($filtFrm->getElementValue('query'));
$data = $this->DBObj->getlist4Grid(array('order_by' => 'added DESC'));
$out = array();
foreach ($data['list'] AS $key => $row){
$out[$key] = array('added' => $row['added'], 'ip' => $row['ip'], );
foreach ($flds as $fld){
$out[$key]['f_'.$fld['id']] = (string)$row[$fld['id']];
}
}
$test = $datagrid->bind($out);
if (PEAR::isError($test)) {
echo $test->getMessage();
}
return $datagrid;
}
function doExportXLS()
{
$datagrid = $this->_getDataGrid4Export();
$datagrid->setRenderer(DATAGRID_RENDER_XLS, array('filename' => 'Form_Mail_export.xls'));
$datagrid->render();
exit();
return true;
}
function doExportCSV()
{
$datagrid = $this->_getDataGrid4Export();
$datagrid->setRenderer(DATAGRID_RENDER_CSV, array('filename' => 'Form_Mail_export.csv'));
$datagrid->render();
exit();
return true;
}
function _getFlds()
{
$Field = SiteMap::getObj('FormMail/Field/Field.php', $this->DBObj->id_fm);
$fields = $Field->getList4Grid(array('order_by' => 'sorter'));
return $fields['list'];
}
function _doListBind(&$DB_List)
{
$DB_List->def_order_by = "{$this->DBObj->tableName}.added DESC";
$DB_List->urlVarNames[] = 'id_fm';
foreach ($this->_getFlds() as $fld){
if ('y' == $fld['show_in_list']){
$param = array('title' => $fld['label'],
'order_by' => false,
'width' => '150',
'tpl' => DB_LIST_CELL_TEXT_CENTER,
'default_text' => "-",
'params' => array($fld['id']),
);
if ('file' == $fld['type_name']){
$param['empty_title'] = '-';
$param['tpl'] = DB_LIST_CELL_LINK;
$param['url'] = FILE_DB_URL.'/';
$param['params'][] = $fld['id'];
}
$DB_List->insertColLast($fld['id'], $param);
}
$DB_List->insertColLast('options', array('title' => 'Options',
'width' => '150',
'tpl' => DB_LIST_CELL_EDIT_DEL,
'edit_title' => 'More',
'edit_link' => Constant::get('BASE_URL').'/'.CURR_PAGE.'?action=edit&id=',
'del_link' => Constant::get('BASE_URL').'/'.CURR_PAGE.'?action=del&id=',
'params' => array('id'),
));
}
//vdie($fld);
/*
$DB_List->insertColLast('label', array('title' => ucwords('Label'),
'order_by' => 'label',
'width' => '150',
'tpl' => DB_LIST_CELL_TEXT,
'default_text' => "empty label",
'params' => array('label'),
));
$DB_List->insertColLast('type', array('title' => ucwords('Type'),
'order_by' => 'type',
'width' => '150',
'tpl' => DB_LIST_CELL_TEXT,
'default_text' => "empty type",
'params' => array('type'),
));
$DB_List->insertColLast('options', array('title' => 'Options',
'width' => '150',
'tpl' => DB_LIST_CELL_EDIT_DEL,
'edit_link' => Constant::get('BASE_URL').'/'.CURR_PAGE.'?action=edit&id=',
'del_link' => Constant::get('BASE_URL').'/'.CURR_PAGE.'?action=del&id=',
'params' => array('id'),
));
*/
$DB_List->bind();
return true;
}
/*
function _getReorderFrom()
{
$form = $this->_getBaseForm();
$list = array();
$list4Grid = $this->DBObj->getList4Grid(array('order_by' => 'sorter'));
foreach ($list4Grid['list'] as $val) {
$list[$val['id']] = $val['label'];
}
$orderList = Form::createElement('select_edit', 'order_list', false, $list);
$orderList->delAction('add');
$orderList->delAction('del');
$orderList->delAction('edit');
$form->addElement($orderList) ;
$form->addElement('hidden', 'id_fm', $this->DBObj->id_fm);
return $form;
}
function doReoderForm()
{
$form = $this->_getReorderFrom();
$form->setTitle('Reorder '.$this->DBObj->itemName.'s');
$form->addElement('hidden', 'action', 'reoder_save') ;
$form->exec();
}
function doReoderSave()
{
$form = $this->_getReorderFrom();
$this->DBObj->reorder( $form->getElementValue('order_list') );
$this->doBack();
}
*/
}
?>