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 getLinkFromTableItem($linkTab, $linkField, $field) { $linkDo = DB_DataObject::factory($linkTab); if (PEAR::isError($linkDo)) { throw new Exception($linkTab . ' is not defined'); } $info = M_Office_Util::getModuleInfo($linkTab); if (!$info && !$linkDo->isNtable()) { return; } if ($nfield = $linkDo->isNtable()) { $nFields = $linkDo->links(); $ntableArray = explode(':', $nFields[$nfield]); $nDo = DB_DataObject::factory($ntableArray[0]); $linkDo->{$linkField} = $this->do->{$field}; $nDo->joinAdd($linkDo); $nbLinkedRecords = $nDo->count(); $parameters = array('module' => $nDo->tableName(), 'filternField' => $linkField, 'filternTable' => $linkTab, 'filternValue' => $this->do->{$field}); $removed = array('module', 'filternValue', 'filternField', 'record', '__record_ref'); $link = M_Office_Util::getQueryParams($parameters, $removed); $add = false; $tableName = __("modules.{$ntableArray['0']}.frontname") . ' <small>(n-n)</small>'; } else { $linkDo->{$linkField} = $this->do->{$field}; $nbLinkedRecords = $linkDo->count(); $parameters = array('module' => $linkTab, 'filterField' => $linkField, 'filterValue' => $this->do->{$field}); $removed = array('module', 'filterValue', 'filterField', 'record', '__record_ref'); if ($nbLinkedRecords == 1) { $keys = $linkDo->keys(); $key = $keys[0]; $linkDo->find(true); $link = M_Office_Util::doURL($linkDo, $linkTab, array('filterField' => $linkField, 'filterValue' => $this->do->{$field})); } else { $link = M_Office_Util::getQueryParams($parameters, $removed); } $tableName = __("modules.{$linkTab}.frontname"); $add = $this->getGlobalOption('add', 'showtable', $linkTab) ? true : false; } return array('table' => $linkTab, 'linkField' => $linkField, 'field' => $field, 'link' => $link, 'nb' => $nbLinkedRecords, 'tablename' => $tableName, 'add' => $add); }