| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- Lib::loadClass('RouteBase');
- /*
- ## Url Actions (to replace Typespecial's):
- - new Zasob type: 'URL_ACTION'
- ## Config in Zasoby tree (TODO: upload from gui xml file or php):
- [100] - TYPESPECIALS
- [110] - URL_ACTION ProjektyKosztyWstepnychRobot
- [111] - PARAM_IN ID_PROJECT
- [200] - TABELA IN7_MK_BAZA_DYSTRYBUCJI Projekty
- [210] - KOMORKA ID
- [220] - (ALIAS to [110]) URL_ACTION action name/label
- [221] - (ALIAS to [210]) PARAM_IN ID_PROJECT
- class Route_UrlAction_ProjektyKosztyWstepnychRobot extends RouteBase {
- public function defaultAction() {
- $args = array();
- $args['ID_PROJECT'] = V::get('ID_PROJECT', '', $_REQUEST);// [111]
- }
- }
- ## Process - Create:
- - 1. define action name in Zasoby tree (URL_ACTION) and expected args (PARAM_IN) - `ActionDefinition`
- - 2. create action alias inside TABLE - `ActionInstance`
- - 3. set perms for `ActionInstance`
- ## Process - Install ActionDefinitio's:
- - class UrlActionBase :: installZasobAction
- - create required Zasoby in Zasob Tree if not exists
- */
- class Route_UrlAction extends RouteBase {// TODO: UrlActionBase
- public function handleAuth() {
- if (!User::logged()) {
- throw new HttpException('Unauthorized', 401);
- }
- }
- public function defaultAction() {
- SE_Layout::gora();
- ?>
- <div class="container">
- <h1>UrlActions system</h1>
- ...
- </div>
- <?php
- SE_Layout::dol();
- }
- public function getArgsList() {
- $args = array();
- return $args;
- }
- public function reinstallAction() {
- $jsonData = new stdClass();
- $jsonData->type = 'success';
- $jsonData->msg = 'Gotowe';
- try {
- $this->reinstall();
- } catch (Exception $e) {
- $jsonData->type = 'danger';
- $jsonData->msg = $e->getMessage();
- }
- echo json_encode($jsonData);
- }
- public function reinstall() {
- $sqlList = array();
- // alter table enum add URL_ACTION
- //$sqlList['RemoveTable'] = "DROP TABLE IF EXISTS `CRM_UI_MSGS`";
- $pdo = DB::getPDO();
- foreach ($sqlList as $sqlName => $sql) {
- $pdo->exec($sql);
- }
- }
- /*
- 636 TABELA IN7_MK_BAZA_DYSTRYBUCJI Projekty
- 763 KOMORKA ID Nr
- 22332 22317 URL_ACTION ProjektyKosztyWstepnychRobot
- 22335 763 PARAM_IN ID_PROJECT
- 25 TYPESPECIALS TYPESPECIALS Powiązania tabel
- 22317 URL_ACTION ProjektyKosztyWstepnychRobot
- 22324 PARAM_IN ID_PROJECT
- */
- public static function fetchTableFunctions($idTbl, $idRecord) {
- $sth = DB::getPDO()->prepare("
- select z.ID as ID
- , z.`DESC_PL` as fun_label
- , za.`DESC` as fun_name
- , zp.ALIAS_ID as param_in_to_cell_id
- , zp.DESC as param_in_name
- from CRM_LISTA_ZASOBOW z
- join CRM_LISTA_ZASOBOW za on(za.ID = z.ALIAS_ID)
- left join CRM_LISTA_ZASOBOW zp on(zp.PARENT_ID = z.ID and zp.`TYPE` = 'PARAM_IN')
- left join CRM_LISTA_ZASOBOW zpa on(zpa.ID = zp.ALIAS_ID and zpa.`TYPE` = 'PARAM_IN' and zpa.`DESC` = zp.`DESC`)
- where z.PARENT_ID = :id_zasob
- and z.`TYPE` = 'URL_ACTION'
- ");
- $sth->bindValue(':id_zasob', $idTbl, PDO::PARAM_STR);
- $sth->execute();
- return $sth->fetchAll();
- }
- public static function fetchTableFunctionsForUser($idTbl, $idRecord, $usrLogin) {
- $sth = DB::getPDO()->prepare("
- select z.ID as ID
- , z.`DESC_PL` as fun_label
- , za.`DESC` as fun_name
- , zp.ALIAS_ID as param_in_to_cell_id
- , zp.DESC as param_in_name
- , param.`DESC` as link_param
- from CRM_LISTA_ZASOBOW z
- join CRM_LISTA_ZASOBOW za on(za.ID = z.ALIAS_ID)
- left join CRM_LISTA_ZASOBOW zp on(zp.PARENT_ID = z.ID and zp.`TYPE` = 'PARAM_IN')
- left join CRM_LISTA_ZASOBOW zpa on(zpa.ID = zp.ALIAS_ID and zpa.`TYPE` = 'PARAM_IN' and zpa.`DESC` = zp.`DESC`)
- join CRM_WSKAZNIK w on(w.ID_ZASOB = z.ID)
- -- join CRM_PROCES p on(p.ID = w.ID_PROCES)
- join CRM_PROCES_idx_USER_to_PROCES_VIEW upv on(upv.ID_PROCES = w.ID_PROCES)
- left join CRM_LISTA_ZASOBOW param on(param.PARENT_ID = z.ID and param.`TYPE` = 'DANE')
- where z.PARENT_ID = :id_zasob
- and z.`TYPE` = 'URL_ACTION'
- and upv.ADM_ACCOUNT = :usr_login
- group by z.ID
- ");
- $sth->bindValue(':id_zasob', $idTbl, PDO::PARAM_STR);
- $sth->bindValue(':usr_login', $usrLogin, PDO::PARAM_STR);
- $sth->execute();
- return $sth->fetchAll();
- }
- public static function getTableFunctions($idTbl, $idRecord, $tblName = '', $usrLogin = null) {
- $rows = array();
- if (!empty($usrLogin)) {
- $rows = self::fetchTableFunctionsForUser($idTbl, $idRecord, $usrLogin);
- } else {
- $rows = self::fetchTableFunctions($idTbl, $idRecord);
- }
- DBG::_('DBG', '>1', 'rows', $rows, __CLASS__, __FUNCTION__, __LINE__);
- $functions = array();
- foreach ($rows as $row) {
- // TODO: Router::getRoute("UrlAction_{$row['fun_name']}")->isRecordAllowed($idTbl, $idRecord, $tblName);
- if (!array_key_exists($row['ID'], $functions)) {
- $fun = array();
- $fun['label'] = $row['fun_label'];
- $fun['name'] = $row['fun_name'];
- $fun['baseLink'] = "index.php?_route=UrlAction_{$row['fun_name']}";
- $fun['ico'] = "glyphicon glyphicon-share";
- $fun['cell_id_params'] = array();
- $fun['link_target'] = '_blank';// LINK_TARGET_SELF
- $functions[ $row['ID'] ] = $fun;
- }
- $funParams = $functions[ $row['ID'] ]['cell_id_params'];
- if ($row['param_in_to_cell_id'] > 0 && !empty($row['param_in_name'])) {
- $funParams[ $row['param_in_to_cell_id'] ] = $row['param_in_name'];
- $functions[ $row['ID'] ]['cell_id_params'] = $funParams;
- }
- if ('LINK_TARGET_SELF' == $row['link_param']) {
- unset($functions[ $row['ID'] ]['link_target']);
- }
- }
- DBG::_('DBG', '>1', 'functions', $functions, __CLASS__, __FUNCTION__, __LINE__);
- return $functions;
- }
- }
|