Пример #1
0
 /**
  * Renderiza o objeto para uma string html
  */
 public function render(&$profileName = '')
 {
     $name = '';
     $itens = '';
     foreach ($this->_options as $value => $config) {
         $class = '';
         if ($value == $this->_value) {
             $name = $config['nome'];
             $class = 'focus';
         }
         $itens .= '<li onclick="setProfile(this.value,\'' . $this->_object . '\');" value = "' . $value . '" class="link ' . $class . '">' . $config['nome'] . '</li>';
     }
     if (ZendT_Acl::getInstance()->isAllowed('object-view', 'profile')) {
         $urlAdmin = ZendT_Url::getBaseUrl() . '/profile/object-view/list-config/objeto/' . $this->_object . '/tipo/' . $this->_type . '/id/' . $this->_value;
         $itens .= '<li role = "separator" class = "divider"></li>';
         $itens .= '<li>';
         $itens .= '   <a href="' . $urlAdmin . '" target="_new" class="ui-helper-clearfix">';
         $itens .= '      ' . _i18n('Administrar');
         $itens .= '   </a>';
         $itens .= '</li>';
     }
     if ($name) {
         $profileName = $name;
     }
     $xhtml = '<div style="height: 30px; float:left;" class="default ui-button ui-no-radius-bottom " id="title-profile-' . $this->_name . '">';
     $xhtml .= '   <span class="ui-icon ui-icon-transfer-e-w" />';
     $xhtml .= '   <ul role="title-profile-' . $this->_name . '" align="left" class="dropdown-menu position ui-helper-clearfix ui-no-radius-tr">';
     $xhtml .= $itens;
     $xhtml .= '   </ul>';
     $xhtml .= '</div>';
     return $xhtml;
 }
Пример #2
0
 /**
  * Configura as opções do ACL
  * 
  * @return array|null
  */
 public function configAcl()
 {
     if (null === $this->_defaultOptions) {
         $this->_defaultOptions = $this->getOptions();
         ZendT_Acl::setOptions($this->_defaultOptions);
     }
     return $this->_defaultOptions;
 }
Пример #3
0
 protected function _getWhere($postData)
 {
     $where = false;
     if (ZendT_Acl::getInstance()->restriction('restringe-empresa', 'auth')) {
         $where = new ZendT_Db_Where('AND');
         $where->addFilter('empresa.hierarquia', Auth_Session_User::getInstance()->getHierarquiaEmpresa(), '?%');
     }
     return $where;
 }
Пример #4
0
 /**
  * Busca o role do usuário
  * @todo codificar
  */
 private function isAllowed($token, $action)
 {
     $userRow = ZendT_Acl::getInstance()->getUserRow($token);
     $module = Zend_Controller_Front::getInstance()->getParam('module');
     $controller = Zend_Controller_Front::getInstance()->getParam('controller');
     if (!ZendT_Acl::getInstance()->isAllowed($action, $module . '.' . $controller, $userRow->getRole())) {
         throw new ZendT_Exception_Alert('Usuário não tem permissão de acesso');
     }
     return true;
 }
Пример #5
0
 public function gridAction()
 {
     parent::gridAction();
     if ($this instanceof ZendT_Controller_ActionCrud && ZendT_Acl::getInstance()->isAllowed('efetivar', $this->_resourceBase)) {
         $btnId = 'btn_efetivar_' . $this->getGrid()->getID();
         $_efetivar = new ZendT_Grid_Button_Ajax($idbt);
         $_efetivar->setIdGrid($this->getGrid()->getID())->setButtonIcon('ui-icon-check')->setUrl(ZendT_Url::getUri(true) . '/efetivar')->setTitle('Efetivar');
         $this->view->hotkeys()->add('btn_efetivar', 'ctrl+t', '$("#' . $btnId . '").click();');
         $this->getGrid()->addToolbarButton('btn_efetivar', $_efetivar, 'btn_efetiva');
     }
     if ($this instanceof ZendT_Controller_ActionCrud && ZendT_Acl::getInstance()->isAllowed('cancelar', $this->_resourceBase)) {
         $btnId = 'btn_cancelar_' . $this->getGrid()->getID();
         $_efetivar = new ZendT_Grid_Button_Ajax($idbt);
         $_efetivar->setIdGrid($this->getGrid()->getID())->setButtonIcon('ui-icon-cancel')->setUrl(ZendT_Url::getUri(true) . '/cancelar')->setTitle('Cancelar');
         $this->view->hotkeys()->add('btn_cancelar', 'ctrl+r', '$("#' . $btnId . '").click();');
         $this->getGrid()->addToolbarButton('btn_cancelar', $_efetivar, 'btn_cancelar');
     }
 }
Пример #6
0
 public function loadResources($module, $session = 'development')
 {
     $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
     $applicationConfigResource = $this->_loadedProfile->search('ApplicationConfigFile');
     if (!$applicationConfigResource) {
         throw new Zend_Tool_Project_Exception('A project with an application config file is required to use this provider.');
     }
     $zf = $applicationConfigResource->getAsZendConfig($session);
     foreach ($zf->resources->multidb as $name => $config) {
         //$this->_print($name);
         Zend_Registry::set('db.' . $name, $config);
     }
     $optionsAcl = $zf->resources->acl->toArray();
     ZendT_Acl::setOptions($optionsAcl);
     $pathBase = $this->_loadedProfile->getAttribute('projectDirectory');
     ZendT_Tool_Crud_MakeResources::make($pathBase, $module);
     $this->_print('Recursos carregados para o banco de dados');
 }
Пример #7
0
 public function saveAction()
 {
     $id = $this->getRequest()->getParam('id');
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $json = new ZendT_Json_Result();
     try {
         if ($id) {
             if (ZendT_Acl::getInstance()->isAllowed('update', $this->_resourceBase)) {
                 $this->updateAction();
             } else {
                 throw new ZendT_Exception_Alert('Acesso não autorizado para realizar alteração!');
             }
         } else {
             if (ZendT_Acl::getInstance()->isAllowed('insert', $this->_resourceBase)) {
                 $this->updateAction();
             } else {
                 throw new ZendT_Exception_Alert('Acesso não autorizado para realizar inclusão!');
             }
         }
     } catch (Exception $Ex) {
         $json->setException($Ex);
         echo $json->render();
     }
 }
Пример #8
0
 /**
  * Configura as opções de adaptadores
  * Essas informações devem vir do arquivo de configuração
  * 
  * @param array $options 
  */
 public static function setOptions($options)
 {
     self::$_options = $options;
 }
Пример #9
0
 public function enableAdd($url)
 {
     list($module, $controller) = explode('/', substr($url, 1));
     if (!ZendT_Acl::getInstance()->isAllowed('insert', $module . '.' . $controller)) {
         return $this;
     }
     $button = new ZendT_Form_Element_Button('btn_add');
     //$button->setTitle(_i18n('Adicionar'));
     $button->setIcon('ui-icon-plus');
     $button->setAttrib('url', ZendT_Url::getBaseUrl() . $url);
     $this->setAttrib('btn_add', $button);
     return $this;
 }
Пример #10
0
 public static function getResources()
 {
     $resources = array();
     $modules = self::getModules();
     $idx = 0;
     foreach ($modules as $module) {
         $resources[$idx]['name'] = $module;
         $resources[$idx]['parent'] = '';
         $resources[$idx]['type'] = 'MODULE';
         $resources[$idx]['module'] = $module;
         $idx++;
         $controllers = self::getControllers($module);
         foreach ($controllers as $controller) {
             $resources[$idx]['name'] = $module . '.' . $controller['className'];
             $resources[$idx]['parent'] = $module;
             $resources[$idx]['type'] = 'CONTROLLER';
             $resources[$idx]['module'] = $module;
             $idx++;
             $controllers = self::getControllers($module);
             require_once $controller['path'] . $controller['fileName'];
             $className = str_replace('.php', '', $controller['fileName']);
             if ($module != 'default') {
                 $className = $module . '_' . $className;
             }
             $actions = self::getActions($className);
             foreach ($actions as $action) {
                 $resources[$idx]['name'] = $module . '.' . $controller['className'] . '.' . $action;
                 $resources[$idx]['parent'] = $module . '.' . $controller['className'];
                 $resources[$idx]['type'] = 'ACTION';
                 $resources[$idx]['module'] = $module;
                 $idx++;
             }
         }
         ZendT_Acl::getInstance()->clearCache($module);
     }
     return $resources;
 }
Пример #11
0
 /**
  * Pega o objeto grid pré-configurado para
  * manipulação.
  *
  * @return ZendT_Grid
  */
 public function configGrid()
 {
     $module = $this->getRequest()->getModuleName();
     $controller = $this->getRequest()->getControllerName();
     $params = $this->getRequest()->getParams();
     $profileKey = '';
     if (isset($params['profile_key'])) {
         $profileKey = $params['profile_key'];
     }
     $urlFilter = '?q=1';
     if (isset($params['filter_json'])) {
         $urlFilter .= '&filter_json=' . $params['filter_json'];
     }
     if (isset($params['mapper_view'])) {
         $urlFilter .= '&mapper_view=' . $params['mapper_view'];
     }
     if ($this->_mapper instanceof ZendT_Db_View) {
         $where = $this->getMapper()->getColumns()->getWhere($params);
         if ($where) {
             $params['postData'] = $where->toJsonPostData($params['postData']);
         }
     }
     if ($params['postData'] != '') {
         $autoFilter = true;
     } else {
         $autoFilter = false;
     }
     $type = 'G';
     #Grid
     $mapperName = get_class($this->_mapper);
     $profile = ZendT_Profile::get($mapperName, $type);
     $profileId = '';
     if (isset($profile['id'])) {
         $profileId = $profile['id'];
     }
     $profiles = ZendT_Profile::listProfile($mapperName, $type);
     $this->getGrid()->setUrl(ZendT_Url::getBaseUrl() . '/' . $module . '/' . $controller . '/grid-data/profile/' . $profileId . $urlFilter)->setDataType('json')->setMType('POST')->setRowNum(30)->setRowList(array(30, 60, 90))->setPager("#pager-" . $this->getGrid()->getID())->setViewRecords('true')->setToolbar(array('true', 'top'))->setMType('POST')->setWidth(960)->setAutoFilter($autoFilter)->setShrinkToFit(false)->setPostData(urldecode($params['postData']))->setBeforeRequest("function(){ gridResize('" . $this->getGrid()->getID() . "'); }")->setGridComplete(" function(){ jQuery.gridAtivaNavKey({ idGrid:'" . $this->getGrid()->getID() . "' }); }");
     /**
      * Analisa Parâmetros
      */
     $newPostData = array();
     foreach ($params as $name => $value) {
         $param = $this->getMapper()->paramName($name);
         if ($param) {
             $newPostData[$param] = $value;
         }
     }
     if (count($newPostData) > 0) {
         $this->getGrid()->setPostData($newPostData);
     }
     if ($this->getRequest()->getParam('seekerAjax')) {
         $objectRetrieve = 'TSeeker';
         if ($this->getRequest()->getParam('objectRetrive')) {
             $objectRetrieve = $this->getRequest()->getParam('objectRetrive');
         }
         $this->view->headScript()->appendFile(ZendT_Url::getBaseDiretoryPublic() . '/scripts/jquery/widget/' . $objectRetrieve . '.js');
         $seekerName = $this->getRequest()->getParam('seekerName');
         $seekerAccess = 'window.opener.jQuery';
         $seekerClose = 'window.close();';
         if ($params['typeModal'] == 'AJAX') {
             $seekerAccess = 'jQuery';
             $seekerClose = 'seeker.TSeeker(\'divClose\');';
             $functionResize = "function(){\n                                            var grid = jQuery('#" . $this->getGrid()->getID() . "');\n                                            var seeker = " . $seekerAccess . "('#" . $seekerName . "');\n                                            var div  = seeker.TSeeker('option','elements').div;\n                                            grid.setGridHeight(250);\n                                            grid.setGridWidth(700);\n                                        }";
         } else {
             $functionResize = "function(){\n                                            \$.gridResize({\n                                                idGrid: '" . $this->getGrid()->getID() . "'\n                                            });\n                                            \$(window).resize(function(){\n                                                \$.gridResize({\n                                                    idGrid: '" . $this->getGrid()->getID() . "'\n                                                });\n                                            });\n                                        }";
         }
         $functionRetorno = "function(){\n                                        var grid  = jQuery('#" . $this->getGrid()->getID() . "');\n                                        if( grid.jqGrid('getGridParam','multiselect') ){\n                                            var id = grid.jqGrid('getGridParam','selarrrow');\n                                        }else{\n                                            var id = grid.jqGrid('getGridParam','selrow');\n                                        }\n                                        var seeker = " . $seekerAccess . "('#" . $seekerName . "');\n                                        try{\n                                            seeker.{$objectRetrieve}('retrieve',{value: id});\n                                            {$seekerClose}\n                                        }catch(err){\n                                            {$seekerClose}\n                                        }\n                                    }";
         $this->getGrid()->setOndblClickRow($functionRetorno)->setBeforeRequest($functionResize)->setGridComplete("function(){\n                                                \$.gridAtivaNavKey({\n                                                    idGrid: '" . $this->getGrid()->getID() . "',\n                                                    functionEnter: " . $functionRetorno . "\n                                                });\n                                            }");
     }
     if ($params['callback']) {
         $functionCallback = base64_decode($params['callback']);
         $this->getGrid()->setOndblClickRow($functionCallback)->setGridComplete("function(){\n                                                \$.gridAtivaNavKey({\n                                                    idGrid: '" . $this->getGrid()->getID() . "',\n                                                    functionEnter: " . $functionCallback . "\n                                                });\n                                            }");
     }
     if ($params['multiple']) {
         $this->getGrid()->setMultiSelect(true);
         $idbt = 'selectGrid' . $this->getGrid()->getID();
         $multiSelect = new ZendT_Grid_Button($idbt);
         $multiSelect->setIdGrid($this->getGrid()->getID())->setButtonIcon("ui-icon-check")->setTitle("Selecionar")->setCaption("Selecionar")->setOnClick($functionRetorno);
         $this->view->hotkeys()->add('btMultiSelect', 'ctrl+s', '$("#' . $idbt . '").click();');
         $this->getGrid()->addToolbarButton("multiSel", $multiSelect);
     }
     $idbt = 'refreshGrid' . $this->getGrid()->getID();
     $refresh = new ZendT_Grid_Button_Refresh($idbt);
     $refresh->setIdGrid($this->getGrid()->getID())->setButtonIcon("ui-icon-refresh")->setTitle("Atualizar");
     $this->view->hotkeys()->add('btRefresh', 'ctrl+r', '$("#' . $idbt . '").click();');
     $this->getGrid()->addToolbarButton("refresh", $refresh, 'grid');
     /* $clearFiltro = new ZendT_Grid_Button();
        $clearFiltro->setIdGrid($this->getGrid()->getID())
        ->setButtonIcon('ui-icon ui-icon-arrowreturnthick-1-s')
        ->setOnClick('function(){$(\'#' . $this->getGrid()->getID() . '\')[0].clearToolbar();}')
        ->setTitle('Limpar Filtro');
        $this->getGrid()->addToolbarButton('clearFilter', $clearFiltro, 'grid'); */
     $autoFiltro = new ZendT_Grid_Button();
     $autoFiltro->setIdGrid($this->getGrid()->getID())->setButtonIcon('ui-icon  ui-icon-pin-s')->setOnClick('function(){$(\'#' . $this->getGrid()->getID() . '\')[0].toggleToolbar();}')->setTitle('Filtro');
     $this->getGrid()->addToolbarButton('autofiltro', $autoFiltro, 'grid');
     $_profile = new ZendT_View_Profile('selProfile', $profile['id'], $profiles, $type, $mapperName);
     $screenName = $this->view->screenName;
     $this->view->profileMenu = $_profile->render($screenName);
     $this->view->screenName = $screenName;
     $this->view->placeholder('title')->set($screenName);
     $navigator = '';
     if ($navigator) {
         $this->getGrid()->getNavigator()->addCommand('navigatorGrid', $navigator);
     }
     /**
      * Botão de adição de registro e
      * suas configurações vitais
      */
     if ($this instanceof ZendT_Controller_ActionCrud && ZendT_Acl::getInstance()->isAllowed('insert', $this->_resourceBase)) {
         $filterJson = $this->getRequest()->getParam('filter_json');
         $idbt = 'addGrid' . $this->getGrid()->getID();
         $add = new ZendT_Grid_Button_Add($idbt);
         $add->setIdGrid($this->getGrid()->getID())->setButtonIcon('ui-icon-plus')->setUrl(ZendT_Url::getBaseUrl() . '/' . $module . '/' . $controller . '/form?filter_json=' . $filterJson . '&profile_key=' . $profileKey)->setWindowWidth(860)->setWindowHeight(520)->setTitle('Adicionar');
         $this->view->hotkeys()->add('btInsert', 'ctrl+a', '$("#' . $idbt . '").click();');
         $this->getGrid()->addToolbarButton('add', $add, 'edit');
     }
     /**
      * Botão de edição de linha e
      * suas configurações vitais
      */
     if ($this instanceof ZendT_Controller_ActionCrud && ZendT_Acl::getInstance()->isAllowed('update', $this->_resourceBase)) {
         $idbt = 'editGrid' . $this->getGrid()->getID();
         $edit = new ZendT_Grid_Button_Edit($idbt);
         $edit->setIdGrid($this->getGrid()->getID())->setButtonIcon('ui-icon-pencil')->setUrl(ZendT_Url::getBaseUrl() . '/' . $module . '/' . $controller . '/form' . '?profile_key=' . $profileKey)->setUrlRetrieve(ZendT_Url::getBaseUrl() . '/' . $module . '/' . $controller . '/retrive')->setWindowWidth(860)->setWindowHeight(520)->setTitle('Editar');
         $this->view->hotkeys()->add('btEdit', 'ctrl+e', '$("#' . $idbt . '").click();');
         $this->getGrid()->addToolbarButton('edit', $edit, 'edit');
         if (!$this->getRequest()->getParam('seekerAjax')) {
             $this->getGrid()->setOndblClickRow("function(){jQuery('#" . $idbt . "').click();}");
         }
     }
     #Button - Delete
     if ($this instanceof ZendT_Controller_ActionCrud && ZendT_Acl::getInstance()->isAllowed('delete', $this->_resourceBase)) {
         $idbt = 'delGrid' . $this->getGrid()->getID();
         $del = new ZendT_Grid_Button_Delete($idbt);
         $del->setIdGrid($this->getGrid()->getID())->setButtonIcon('ui-icon-trash')->setUrl(ZendT_Url::getBaseUrl() . '/' . $module . '/' . $controller . '/delete')->setWindowWidth(800)->setWindowHeight(520)->setTitle('Excluir');
         $this->view->hotkeys()->add('btDelete', 'ctrl+d', '$("#' . $idbt . '").click();');
         $this->getGrid()->addToolbarButton('del', $del, 'edit');
     }
     if ($this instanceof ZendT_Controller_ActionCrud && ZendT_Acl::getInstance()->isAllowed('log', $this->_resourceBase) && method_exists($this->_mapper, 'isLogger') && $this->_mapper->isLogger()) {
         $log = new ZendT_Grid_Button_Window();
         $log->setIdGrid($this->getGrid()->getID())->setButtonIcon('ui-icon-info')->setUrl(ZendT_Url::getBaseUrl() . '/' . $module . '/' . $controller . '/log')->setWindowWidth(650)->setWindowHeight(450)->setTitle('Log');
         $this->getGrid()->addToolbarButton('Log', $log, 'edit');
     }
     $this->view->typeModal = $params['typeModal'];
     if ($params['typeModal'] == 'AJAX') {
         Zend_Layout::getMvcInstance()->setLayout('ajax');
     } else {
         if ($params['typeModal'] == 'WINDOW') {
             $this->view->onLoad = stripslashes(urldecode($params['afterLoad']));
             $this->view->onClose = stripslashes(urldecode($params['onClose']));
             Zend_Layout::getMvcInstance()->setLayout('window');
         }
     }
 }