actions['reoder_form'] = 'doReoderForm';
$this->actions['reoder_save'] = 'doReoderSave';
$this->actions['add_item_by_type_pre'] = 'doAddItemByTypePre';
$this->actions['add_item_by_type_post'] = 'doAddItemByTypePost';
$this->actions['edit_item_by_val_pre'] = 'doEditItemByValPre';
$this->actions['edit_item_by_val_post'] = 'doEditItemByValPost';
$this->_options = $options;
$this->DB_Grid($Page, $DBObj);
}
function doEditItemByValPre()
{
$form = $this->_getEditItemByValFrom();
$types = $this->DBObj->getItemNames();
require_once SiteMap::getPath('CMS/Doc/DocItem.php');
list($type, $name) = explode(DocItem::getDelimiter(), $form->getElementValue('item_val') );
if ( key_exists($type, $this->DBObj->getItemNames()) ){
$docItem = SiteMap::getObj(Doc:: getClassPath($type));
if (!is_null($docItem)) {
$docItem->gotoFormEdit($name);
}
}else {
$this->_AddItemByTypeShowError();
}
}
function doEditItemByValPost()
{
$this->Doc->addContent(array('tpl' => 'text.tpl', 'text' => '
' ));
return true;
}
function _getEditItemByValFrom()
{
$form = $this->_getBaseForm('get');
$form->addElement('text', 'item_val');
return $form;
}
function _getAddItemByTypeFrom()
{
$form = $this->_getBaseForm('get');
$form->addElement('text', 'type');
return $form;
}
function _AddItemByTypeShowError()
{
$this->Doc->addContent(array('tpl' => 'text.tpl', 'text' => '
Invalid type
' ));
return true;
}
function doAddItemByTypePost()
{
$this->Doc->addContent(array('tpl' => 'text.tpl', 'text' => '
' ));
return true;
}
function doAddItemByTypePre()
{
$form = $this->_getAddItemByTypeFrom();
$types = $this->DBObj->getItemNames();
if ( key_exists($form->getElementValue('type'), $this->DBObj->getItemNames()) ){
$docItem = SiteMap::getObj(Doc::getClassPath($form->getElementValue('type')));
if (!is_null($docItem)) {
$docItem->gotoFormNew();
return true;
}
}
$this->_AddItemByTypeShowError();
return false;
}
function _getReorderFrom()
{
$form = $this->_getBaseForm();
$list = array();
$list4Grid = $this->DBObj->getList4Grid(array('order_by' => 'sorter'));
foreach ($list4Grid['list'] as $val) {
$list[$val['id']] = $val['title'];
}
$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_parent', $this->DBObj->id_parent);
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();
}
function validAlias($fields)
{
if ($this->DBObj->isAliasUnique($fields['alias'])){
return true;
}else {
return array('alias' => 'The alias must be unique');
}
}
function _bindFormFields($form)
{
$id_parent =& Form::createElement('select', 'id_parent', 'Parent Page', $this->DBObj->getPagentPages4Sel());
$id_parent->setValue($this->DBObj->id_parent);
$form->addElement($id_parent);
$form = parent::_bindFormFields($form);
$form->addFormRule(array(&$this, 'validAlias') );
$form->removeElement('sorter');
$form->addRule('alias', 'Alias is requied', 'required', null, 'client');
$form->addRule('alias', 'Alias is requied', 'required');
$form->addRule('alias', 'Invalid Alias', 'alias', null, 'client');
$form->addRule('alias', 'Invalid Alias', 'alias');
$form->removeElement('handler');
$handler = new HTML_QuickForm_select('handler', 'Page Type', $this->DBObj->getTypes() );
$handler->setValue( $this->DBObj->getData('handler') );
$form->addElement($handler);
$final =& $form->getElement('final');
$final = Form::createElement('advcheckbox', 'final', 'Final', null, null, array('n', 'y') );
if (isset($_POST['final'])){
$finalVal = $_POST['final'];
}else {
$finalVal = $this->DBObj->getData('final');
}
$final->setValue($finalVal);
$system =& $form->getElement('system');
$system = HTML_QuickForm::CreateElement('advcheckbox', 'system', 'System', null, null, array('n', 'y'));
if (isset($_POST['system'])){
$systemVal = $_POST['system'];
}else {
$systemVal = $this->DBObj->getData('system');
}
$system->setValue($systemVal);
require_once 'class/DB/Lang/DLang.php';
$DLang = new DLang();
$langList = $DLang->getList();
if ( 1 == $this->_options['showSEO_Fields']){
if (count($langList) > 1){
$form->addElement('header', 'keyword_header', 'Keywords');
}
foreach ($langList as $lang){
$name = "keyword[{$lang['name']}]";
if (count($langList) == 1){
$title = 'Keywords';
}else{
$title = $lang['title'];
}
$textarea = Form::createElement('textarea', $name, $title,array('cols' => '35', 'rows' => '3'));
$textarea->setValue($this->DBObj->getData($name));
$form->addElement($textarea);
}
if (count($langList) > 1){
$form->addElement('header', 'description_header', 'Description');
}
foreach ($langList as $lang){
$name = "description[{$lang['name']}]";
if (count($langList) == 1){
$title = 'Description';
}else{
$title = $lang['title'];
}
$textarea = Form::createElement('textarea', $name, $title,array('cols' => '35', 'rows' => '3'));
$textarea->setValue($this->DBObj->getData($name));
$form->addElement($textarea);
}
}
if (count($langList) > 1){
$form->addElement('header', 'title_header', 'Title');
}
foreach ($langList as $lang){
$name = "title[{$lang['name']}]";
if (count($langList) == 1){
$title_error = 'Title is required';
$title = 'Title';
}else{
$title_error = $lang['title'] . ' title is required';
$title = $lang['title'];
}
$form->addElement('text', $name, $title, array('value' => $this->DBObj->getData($name)) );
$form->addRule($name, $title_error, 'required');
$form->addRule($name, $title_error, 'required', null, 'client');
}
if (isset($_POST['items'])){
$itemsVal = $this->DBObj->getItemsList4Post($_POST['items']);
}else {
$itemsVal = $this->DBObj->getData('items');
}
$items = new HTML_QuickForm_selectEdit('items', 'Items', $itemsVal );
$function = "
function selectEdit_editOption(where)
{
var sel = document.getElementsByName('_'+where)[0];
for(var i = 0; i < sel.options.length; i++){
if (sel.options[i].selected){
AddItem_editSelectedItem(sel.options[i].value, i)
return true;
}
}
return false;
}" ;
$items->setAction('edit', null, $function);
$items->delAction('add');
$form->addElement($items );
$form->addElement(new HTML_QuickForm_AddItem('add_item', 'Add item', $this->DBObj->getItemNames(), 'items') );
return $form;
}
function addLink()
{
$addLink = array(
'tpl' => 'center_link.tpl',
'link_list' =>
array(
array('link' => Constant::get('BASE_URL').'/'.CURR_PAGE.'?action=reoder_form&id_parent='.$this->DBObj->id_parent, 'title' => 'Reorder '.$this->DBObj->itemName.'s', ),
array('link' => Constant::get('BASE_URL').'/'.CURR_PAGE.'?action=new&id_parent='.$this->DBObj->id_parent, 'title' => 'Add new '.$this->DBObj->itemName, ),
),
);
$this->Doc->addContent($addLink);
}
function doList()
{
$this->_saveBackUrl();
$this->addLink();
require_once('class/DB/List/List.php');
$DB_List = new DB_List($this->Doc, $this->DBObj, $this->functionalFields);
$DB_List->def_order_by = 'sorter';
$DB_List->insertColLast('title', array('title' => 'Title',
'width' => 150,
'order_by' => 'title',
'tpl' => DB_LIST_CELL_TEXT,
'params' => array('title'),
));
$DB_List->insertColLast('alias', Array ( 'title' => 'Alias',
'order_by' => 'alias',
'width' => 150,
'tpl' => DB_LIST_CELL_TEXT,
'params' => Array('alias'), ) );
$DB_List->insertColLast('handler', Array ( 'title' => 'Handler',
'order_by' => 'DocHandler.title',
'width' => 150,
'tpl' => DB_LIST_CELL_TEXT,
'params' => Array('handler'),
));
$DB_List->insertColLast('editonly', array(
'title'=>'Edit Only',
'order_by'=>'editonly',
'width'=>80,
'values'=> array('y'=>'Yes', 'n'=>'No'),
'tpl' => DB_LIST_CELL_LINK_ENUM,
'url' => BASE_URL.'/'.CURR_PAGE.'/?action=chopt&opt=editonly&id=',
'params'=> array('editonly', 'id')
));
$DB_List->insertColLast('sub_pages', array('title' => 'Sub pages',
'width' => 100,
'tpl' => DB_LIST_CELL_LINK,
'params' => array('id'),
'empty_title' => 'Sub pages',
'url' => CURR_PAGE.'?id_parent='
));
$DB_List->insertColLast('options', array('title' => 'Options',
'width' => 100,
'tpl' => DB_LIST_CELL_EDIT_DEL,
'params' => array('id'),
'edit_link' => CURR_PAGE.'?action=edit&id=',
'del_link' => CURR_PAGE.'?action=del&id=',
) );
$DB_List->urlVarNames[] = 'id_parent';
$DB_List->bind();
$DB_List->exec();
return true;
}
function exec()
{
$list = $this->DBObj->getIdPath();
if (count($list)) {
$path = array(
'tpl' => 'center_link.tpl',
'separator' => '>',
'link_list' => array( array('link' => CURR_PAGE.'?id_parent=0', 'title' => 'Root', ), )
);
foreach ($this->DBObj->getIdPath() as $value) {
$path['link_list'][] = array('title' => $value['title'], 'link' => CURR_PAGE.'?id_parent='.$value['id']);
}
$this->Doc->addContent($path);
}
require_once 'class/Session.php';
Session::clearData('admin_sect', 'tplLite' );
parent::exec();
}
}
?>