public function __construct($module) { parent::__construct(); $this->assign('__action', 'add'); $tpl = Mreg::get('tpl'); $tpl->concat('adminTitle', ' :: ' . $this->moduloptions['title'] . ' :: ' . __('Add record')); $mopts = PEAR::getStaticProperty('m_office', 'options'); $mopt = $mopts['modules'][$module]; $table = $mopt['table']; $do = M_Office_Util::doForModule($module); $this->append('subActions', '<a href="' . M_Office_Util::getQueryParams(array(), array('record', 'doSingleAction')) . '">' . __('Go to the %s list', array($mopt['title'])) . '</a>'); $formBuilder =& MyFB::create($do); // linkNewValue creates an issue if some linked elements are put in predefgroups // $formBuilder->linkNewValue = true; $form = new MyQuickForm('editRecord', 'POST', M_Office_Util::getQueryParams(array(), array(), false), '_self', null, true); $form->addElement('hidden', 'submittedNewRecord', 1); if (isset($_REQUEST['filterField'])) { $form->addElement('hidden', 'filterField', $_REQUEST['filterField']); $form->addElement('hidden', 'filterValue', $_REQUEST['filterValue']); $do->{$_REQUEST['filterField']} = $_REQUEST['filterValue']; } $links = $do->links(); if (key_exists($_REQUEST['filterField'], $links)) { $linfo = explode(':', $links[$_REQUEST['filterField']]); $form->addElement('static', 'mod', '', __('Add record with %s = %s', array($_REQUEST['filterField'], $_REQUEST['filterValue'])) . '. ' . '<a href="' . M_Office_Util::getQueryParams(array('table' => $linfo[0], 'record' => $_REQUEST['filterValue']), array('addRecord', 'filterField', 'filterValue')) . '">' . __('Back to main record') . '</a>'); } $formBuilder->useForm($form); $formBuilder->getForm(); if ($this->getOption('createAnother', $table)) { $form->addElement('static', ' ', ' '); $form->addElement('checkbox', 'returnHere', __('Create another record')); if (isset($_REQUEST['returnHere']) && $_REQUEST['returnHere']) { $form->setDefaults(array('returnHere' => true)); } } M_Office_Util::addHiddenFields($form); if ($form->validate()) { if (PEAR::isError($ret = $form->process(array(&$formBuilder, 'processForm'), false))) { $this->append('error', __('An error occured while inserting record') . ' : ' . $ret->getMessage()); } else { $pk = DB_DataObject_FormBuilder::_getPrimaryKey($do); $this->say(__('New record was successfully created. Its identifier is : %s', array($do->{$pk}))); if ($this->getOption('createAnother', $table) && isset($_REQUEST['returnHere']) && $_REQUEST['returnHere']) { M_Office_Util::refresh(M_Office_Util::getQueryParams(array('returnHere' => $_REQUEST['returnHere']), array(), false)); } else { $pk = DB_DataObject_FormBuilder::_getPrimaryKey($do); M_Office_Util::refresh(M_Office_Util::getQueryParams(array('record' => $do->{$pk}), array('returnHere', 'addRecord'), false)); } } } elseif ($form->isSubmitted()) { } $this->assign('addForm', $form); $this->assign('do', $do); }
public function loginForm($table) { $form = new MyQuickForm('loginform', 'POST', M_Office_Util::getQueryParams(array(), array(), false), '_self', null, true); $authDO = DB_DataObject::factory($table); $authDO->prepareForLogin(false, false); $authFB = MyFB::create($authDO); $authFB->useForm($form); $authFB->getForm(); if ($form->validate()) { M_Office_Util::refresh($_SERVER['REQUEST_URI']); } M_Office::$dsp = 'login'; $this->assign('loginForm', $form); }
public function __construct($do, $delete) { parent::__construct(); foreach ($delete as $deleteId) { $deldo = DB_DataObject::factory($do->tableName()); $deldo->get($deleteId); if ($deldo->delete()) { $this->say(__('Record # %s was deleted', array($deleteId))); } unset($deldo); } $this->say(__('The selected records were deleted')); M_Office_Util::refresh(M_Office::URL($this->_initRequest($_POST))); return; }
public function doExecList() { $this->table = $table; if (!$this->getConfig('view', $table)) { M_Office_Util::refresh(ROOT_ADMIN_URL . ROOT_ADMIN_SCRIPT); } $do =& $this->doForTable($table); if ($this->getOption('search', $table)) { $doSearch =& $this->doForTable($table); $searchForm =& M_Office_Util::getSearchForm($doSearch); $this->assign('search', $searchForm); if (isset($_REQUEST['searchSubmit'])) { $do = $this->getSearchDO($searchForm); } } if ($this->getAndProcessActions(clone $do, $table)) { return; } if (isset($_REQUEST['record']) && ($this->getOption('edit', $table) || $this->getOption('view', $table))) { $subController = new M_Office_EditRecord($table, $_REQUEST['record']); $this->assign('__action', 'edit'); return; } if ($this->getOption('view', $do->tableName()) === TRUE) { $dg =& new M_Office_View_DOPaging($this); $this->assign('__listview', 'dopaging'); } else { $class = 'M_Office_View_' . $this->getOption('view', $do->tableName()); $dg = new $class($this); $this->assign('__listview', $this->getOption('view', $do->tableName())); } $dg->prepare($do, true, isset($searchWhere) ? $paginate ? true : false : true); $this->assign('dg', $dg); $this->assign('total', $total); $this->assign('pager', $dg->getPaging()); $this->assign('fields', $dg->getFields()); $this->assign('__action', 'showtable'); $deleteForm = new MyQuickForm('showTableForm', 'post', M_Office_Util::getQueryParams(array(), array(), false), '_self', null, true); M_Office_Util::addHiddenFields($deleteForm, array(), true); }
/** * Redirects to the next page depending on $result status * @param $result M_Office_Actionresult */ public function redirectTo(M_Office_Actionresult $result) { $toRemoveParams = array('__actionscope', 'doSingleAction', 'glaction', 'doaction', '__start', '__actionchain'); switch ($result->status) { case 'error': $this->say(__('An error occured while applying action')); switch ($this->target) { case 'list': M_Office_Util::refresh(M_Office::URL(array(), $toRemoveParams)); break; default: M_Office_Util::refresh(M_Office::URL(array(), $toRemoveParams)); } break; case 'complete': switch ($this->target) { case 'list': $this->say(__('Action applied successfully')); M_Office_Util::refresh(M_Office::URL(array(), $toRemoveParams)); break; case 'nextaction': $next = array_shift($this->nextactions); M_Office_Util::postRedirect(M_Office::URL(array($this->typeval => $next, '__actionchain' => implode(',', $this->nextactions)), array('__start')), array('__actionscope' => $this->scope, 'selected' => $this->getSelectedIds())); break; default: $this->say(__('Action applied successfully')); M_Office_Util::refresh(M_Office::URL(array(), $toRemoveParams)); } break; case 'partial': $this->nextStep($result); break; } }
public function run() { $this->ajaxAuth = true; if ($this->getOption('auth')) { $this->ajaxAuth = false; $subController = new M_Office_Auth($_REQUEST['database']); if (!key_exists('adminPrivileges', $_SESSION) || key_exists('logout', $_REQUEST)) { $this->assign('username', User::getInstance('office')->getProperty('username')); $this->ajaxAuth = true; } elseif (!User::getInstance('office')->isLoggedIn()) { $this->ajaxAuth = false; } else { $subController->initOptions(); $this->assign('username', User::getInstance('office')->getProperty('username')); } } $not = Notifier::getInstance(); $not->addListener($this); if ($this->getOption('auth') && !User::getInstance('office')->isLoggedIn()) { if (self::isAjaxRequest()) { $this->assign('__action', 'ajaxlogin'); } return; } if (key_exists('updateSuccess', $_REQUEST)) { $this->say(__('Record was successfully updated')); M_Office_Util::clearRequest(array('updateSuccess' => 1)); } if (isset($_REQUEST['module'])) { $info = M_Office_Util::getModuleInfo($_REQUEST['module']); $module = $_REQUEST['module']; if (!$info) { if (strpos($_REQUEST['module'], ':')) { $info = array('type' => 'dyn', 'title' => 'Plugin'); $module = $tab[1]; } elseif (preg_match('`^(.+)helper$`', $_REQUEST['module'], $tab)) { $info = array('type' => 'dyn', 'title' => __("modules.{$tab[1]}helper.title")); $module = $_REQUEST['module']; } else { throw new NotFoundException(__('error.module_not_found', array($_REQUEST['module']))); } } } if ($this->isAjaxRequest() && $this->ajaxAuth && $info['type'] != 'dyn') { $this->output = ''; unset($this->localOutput); } if (isset($_REQUEST['debug']) && MODE == 'development') { $debug = (int) $_REQUEST['debug'] % 3; DB_DataObject::debugLevel($debug); ini_set('display_errors', 1); } if ($_REQUEST['livesearch']) { $aj = new M_Office_livesearch($_REQUEST['searchtext'], $_REQUEST['expand']); $this->output = $aj->processRequest(); return; } elseif ($_REQUEST['treesort']) { $aj = new M_Office_treesort(); $this->output = $aj->processRequest(); return; } elseif ($_REQUEST['liveedit']) { $aj = new M_Office_liveedit($_REQUEST['liveedit']); $this->output = $aj->processRequest(); return; } elseif (key_exists('ajaxfromtable', $_REQUEST)) { $table = $_REQUEST['module']; $do = DB_DataObject::factory($table); $do->get($_REQUEST['filterField'], $_REQUEST['filterValue']); $aj = new M_Office_ajaxFromTable($do, $_REQUEST['module'], $_REQUEST['module'], $_REQUEST['filterField'], $_REQUEST['filterValue']); $this->output = $aj->processRequest(); return; } if (isset($_REQUEST['module'])) { if (!$info) { $info = M_Office_Util::getModuleInfo($_REQUEST['module']); } switch ($info['type']) { case 'db': // TODO ajouter ce path en avant-dernier et non en dernier Mreg::get('tpl')->addPath(APP_ROOT . 'app/' . APP_NAME . '/templates/' . $info['table'] . '/', 'after'); Mreg::get('tpl')->addPath(APP_ROOT . 'app/' . APP_NAME . '/templates/' . $_REQUEST['module'] . '/', 'after'); $subController = new M_Office_ShowTable($_REQUEST['module'], $filter); break; case 'dyn': // home module = available for everyone $allowAccess = $_REQUEST['module'] == 'home' || M_Office_Util::getGlobalOption('view', 'showtable', $_REQUEST['module']); if (!$allowAccess) { Log::warn('User is NOT allowed to access ' . $_REQUEST['module']); M_Office_Util::refresh(M_Office::URL(array(), array_keys($_REQUEST))); } else { Log::info('User is allowed to access ' . $_REQUEST['module']); } $subController = Module::factory($_REQUEST['module'], M::getPaths('module')); $subController->executeAction($_REQUEST['action'] ? $_REQUEST['action'] : 'index'); $this->assign('__action', 'dyn'); $layout = $subController->getConfig('layout', $_REQUEST['action'] ? $_REQUEST['action'] : 'index'); if ($layout == '__self') { M_Office::$dsp = '__defaut/ajaxindex'; } elseif ($layout) { M_Office::$dsp = $layout; } $this->assign('output', $subController->output(null, '__self')); break; } $this->assign('currentmodule', $_REQUEST['module']); } else { $subController = new M_Office_FrontEndHome(); } }
public function run() { $this->do = $this->getRecord(); deny_unless_can('read', $this->do); $this->assign('__action', 'edit'); $this->append('subActions', '<a href="' . M_Office_Util::getQueryParams(array(), array('record', 'doSingleAction', '__record_ref')) . '">' . __('< Back to list') . '</a>'); $tpl = Mreg::get('tpl'); $tpl->concat('adminTitle', $this->do->__toString() . ' :: ' . $this->moduloptions['title']); $tpl->assign('adminHeader', $this->do->__toString()); $database = $this->do->database(); /** * * Actions * **/ if (isset($_REQUEST['doSingleAction']) && $this->getGlobalOption('actions', 'showtable', $this->module)) { $subController = new M_Office_Actions($this->getOptions()); $subController->run($this->do, $_REQUEST['doSingleAction'], 'single'); if ($subController->hasOutput()) { return; } } $this->createActions(); $formBuilder = MyFB::create($this->do); if (!can('update', $this->module)) { $formBuilder->userEditableFields = array('__fakefield'); } $editopts = PEAR::getStaticProperty('m_office_editrecord', 'options'); if (!empty($editopts['tableOptions'][$this->module]['fields'])) { $formBuilder->fieldsToRender = $editopts['tableOptions'][$this->module]['fields']; } $form = new MyQuickForm('editRecord', 'POST', M_Office_Util::doURL($this->do, $this->module, array()), '_self', null, true); $formBuilder->elementTypeAttributes = array('longtext' => array('cols' => 50, 'rows' => 10)); $formBuilder->useForm($form); if ($this->getOption('edit', $this->module)) { $this->assign('editable', true); } else { $doFreeze = true; } $form = $formBuilder->getForm(); if (PEAR::isError($form)) { throw new Exception($form->getMessage() . ' ' . print_r($form->getUserInfo(), true)); } if ($doFreeze) { $form->freeze(); $submit = $form->getElement('__submit__'); if (!PEAR::isError($submit)) { $form->removeElement('__submit__'); } } if ($form->validate()) { $ret = $form->process(array($formBuilder, 'processForm'), false); if (PEAR::isError($ret)) { $this->append('errors', __('An error occured while updating record') . ' : ' . $ret->getMessage()); $this->assign('__action', 'error'); return; } else { $params_to_remove = array(); $values = $form->exportValues(); if ($values['__backtolist__']) { $params_to_remove[] = 'record'; } if (!key_exists('debug', $_REQUEST)) { $this->say(__('Record saved !')); M_Office_Util::refresh(M_Office_Util::doURL($this->do, $this->module, array(), $params_to_remove)); } } } $this->assign('editForm', $form); if ($linkFromTables = $this->getOption('linkFromTables', $this->table)) { $ajaxFrom = $this->getOption('ajaxLinksFromTable', $this->table); if (!is_array($ajaxFrom)) { $ajaxFrom = array(); } foreach ($this->do->reverseLinks() as $linkFromTable => $field) { list($linkTab, $linkField) = explode(':', $linkFromTable); switch (true) { case !$this->getGlobalOption('view', 'showtable', $linkTab): break; case key_exists($linkTab, $ajaxFrom): $fromfield = $ajaxFrom[$linkFromTable]['fromfield']; if ($fromfield == $linkField || !$fromfield) { $info = $ajaxFrom[$linkTab]; $aja = new M_Office_ajaxFromTable($this->do, $this->module, $linkTab, $linkField, $this->do->{$field}); if ($info['position'] == 'before') { $ajaxLinksBefore[] = $aja->getBlock(); } else { $ajaxLinksAfter[] = $aja->getBlock(); } } break; case $linkFromTables === TRUE || is_array($linkFromTables) && in_array($linkTab, $linkFromTables): if ($linkInfo = $this->getLinkFromTableItem($linkTab, $linkField, $field)) { $linkFromTableArray[] = $linkInfo; } break; } } } M::hook($this->do->tableName(), 'alterLinkFromTables', array(&$linkFromTableArray, $this->do)); $this->assign('linkFromTables', $linkFromTableArray); $this->assign('ajaxFrom', array('before' => $ajaxLinksBefore, 'after' => $ajaxLinksAfter)); $related = ''; if (($linkToTables = $this->getOption('linkToTables', $this->table)) && is_array($links = $this->do->links())) { foreach ($links as $linkField => $link) { list($linkTab, $linkRec) = explode(':', $link); if ((!is_array($linkToTables) || in_array($linkTab, $linkToTables)) && $this->getOption('view', $linkTab)) { $linkDo = $this->do->getLink($linkField); if ($linkDo) { $this->append('linkToTables', array('table' => $linkTab, 'link' => M_Office_Util::DoUrl($linkDo, $linkTab, array(), array('page')))); } } } } $this->assign('related', $related); $this->assign('do', $this->do); }
function __construct($module) { parent::__construct(); $this->assign('module', $module); $this->module = $module; deny_unless_can('read', $module); if ((isset($_REQUEST['record']) || isset($_REQUEST['__record_ref'])) && ($this->getOption('edit', $module) || $this->getOption('view', $module))) { $subController = new M_Office_EditRecord($module, $_REQUEST['record'], $additionalFilter); $subController->__record_ref = $_REQUEST['__record_ref']; $subController->run(); return; } if (isset($_REQUEST['addRecord']) && $this->getOption('add', $module)) { deny_unless_can('create', $module); $subController = new M_Office_AddRecord($module); $subController->run(); return; } $opts = PEAR::getStaticProperty('m_office', 'options'); $this->moduloptions = $opts['modules'][$module]; $this->table = $this->moduloptions['table']; if (!$this->getOption('view', $module)) { M_Office_Util::refresh(ROOT_ADMIN_URL . ROOT_ADMIN_SCRIPT); } if ($this->getOption('search', $module)) { // 1. Url curation if needed // if(!key_exists('_c_',$_REQUEST) && !M_Office::isAjaxRequest()) { // M_Office_Util::refresh(M_Office::cleanURL(array('_c_'=>1),array('searchSubmit','__submit__'))); // } // 2. Process search $doSearch = M_Office_Util::doForModule($this->module); $searchForm = M_Office_Util::getSearchForm($doSearch, $this->module); $this->assign('search', $searchForm); $searchValues = $searchForm->exportValues(); } else { $searchValues = array(); } $do = $this->getSearchDO($searchValues); if (isset($_REQUEST['doaction']) && $this->getOption('actions', $module)) { $order = trim($_REQUEST['_ps'] . ' ' . $_REQUEST['_pd']); if ($order) { $do->orderBy(); $do->orderBy($order); } $subController = new M_Office_Actions($this->getOptions()); $subController->run($do, $_REQUEST['doaction'], 'batch'); if ($subController->has_output) { return; } } elseif (isset($_REQUEST['glaction']) && $this->getOption('actions', $module)) { $subController = new M_Office_Actions($this->getOptions()); $subController->run($do, $_REQUEST['glaction'], 'global'); if ($subController->has_output) { return; } } if ($this->getAndProcessActions(clone $do, $module)) { return; } if ($this->getOption('view', $this->module) === TRUE) { $dg = new M_Office_View_DOPaging($this); $this->assign('__listview', 'dopaging'); } else { $class = 'M_Office_View_' . $this->getOption('view', $this->module); $dg = new $class($this); $this->assign('__listview', $this->getOption('view', $this->module)); } $tpl = Mreg::get('tpl'); $do_before_fetch = clone $do; $tpl->assign('do_before_fetch', $do_before_fetch); $tpl->concat('adminTitle', $this->moduloptions['title'] . ' :: Listing'); $tpl->assign('adminHeader', $this->moduloptions['title']); $pagination = $this->paginate === false ? false : true; $dg->prepare($do, $this->module, $pagination); $this->assign('dg', $dg); $this->assign('total', $total); $this->assign('pager', $dg->getPaging()); $this->assign('fields', $dg->getFields()); $this->assign('__action', 'showtable'); $deleteForm = new MyQuickForm('showTableForm', 'post', M_Office_Util::getQueryParams(array(), array()), '_self', null, true); M_Office_Util::addHiddenFields($deleteForm, array(), true); }