Esempio n. 1
0
 public function routeShow()
 {
     $menu_model = new Default_Model_Cmenu();
     $menu = $menu_model->fetchRow(array('`controller` = ?' => $this->config->controller));
     if ($this->config->post['nd']) {
         $rows = array();
         $where = $this->config->where ? $this->config->where->toArray() : array();
         if (count($this->config->param->search)) {
             foreach ($this->config->param->search as $k => $v) {
                 if (isset($this->config->field[$k])) {
                     if ($this->config->field[$k]->stype == 'select') {
                         $where['`' . $k . '` = ?'] = $v;
                     } else {
                         if (strlen($v) == 10 && strtotime($v)) {
                             $where['DATE(`' . $k . '`) = DATE(?)'] = date('Y-m-d', strtotime($v));
                         } else {
                             if (strlen($v) == 23) {
                                 $p = explode(' - ', $v);
                                 if (strtotime($p[0]) && strtotime($p[1])) {
                                     $where['DATE(`' . $k . '`) >= DATE("' . date('Y-m-d', strtotime($p[0])) . '") AND DATE(`' . $k . '`) <= DATE("' . date('Y-m-d', strtotime($p[1])) . '")'] = '';
                                 }
                             } else {
                                 $w = '';
                                 $v = explode(',', $v);
                                 foreach ($v as $el) {
                                     $el = trim(str_replace(array('"', '*', '?'), array('', '%', '_'), $el));
                                     $w .= ($w ? ' OR ' : '') . '(`' . $k . '` LIKE "%' . $el . '%")';
                                 }
                                 $where[] = $w;
                             }
                         }
                     }
                 }
             }
         }
         if ($this->config->tree) {
             $parentid = (string) $this->config->post['nodeid'];
             if ($parentid) {
                 $s = new Zend_Session_Namespace();
                 $oids = Zkernel_Common::getOuterIds(array('model' => $this->config->model, 'id' => $parentid));
                 if (!in_array($parentid, $oids)) {
                     $s->control['history'][$this->config->controller]['oid'] = $parentid;
                 }
             }
             $level = $this->config->post['n_level'];
             $level = strlen($level) > 0 ? $level + 1 : 0;
             $where['`' . $this->config->tree_field . '` = ?'] = $parentid;
             $parentid = $parentid == 0 ? null : $parentid;
         }
         if ($this->config->param['cid'] && isset($this->config->field->{$this->config->field_link})) {
             $where['`' . $this->config->field_link . '` = ?'] = $this->config->param['cid'];
         }
         /*if ($this->config->data) {
         			if (!$this->config->data_cnt) $this->config->data_cnt = count($this->config->data);
         		}
         		else {*/
         $rd = $this->config->model->fetchControlList($where, $this->config->orderby . ' ' . $this->config->orderdir, $this->config->pager_perpage ? $this->config->pager_perpage : null, $this->config->pager_perpage ? ($this->config->pager_page - 1) * $this->config->pager_perpage : null);
         $data = $rd->toArray();
         $this->config->data_cnt = $this->config->model->fetchCount($where);
         if ($this->config->tree && $data && $this->config->field) {
             foreach ($data as &$el) {
                 $el['_level'] = $level;
                 $el['_count'] = (int) $this->config->model->fetchCount(array('`' . $this->config->tree_field . '` = ?' => (string) $el['id']));
             }
         }
         $this->config->data = $this->view->override($data, $this->config->controller);
         //}
     } else {
         if ($this->config->button_top_ex) {
             $menus = $menu_model->fetchAll(array('`parentid` = ?' => @(int) $menu->id, '`show_it` = 0', 'orderid'));
             if ($menus) {
                 foreach ($menus as $num => $el) {
                     if (!$this->view->user()->isAllowed($this->view->user('role'), $el->resource)) {
                         continue;
                     }
                     $cl_0 = stripos($el->param, 'cl=0');
                     $cl_1 = stripos($el->param, 'cl=1');
                     $this->config->button_top[] = array('inner' => $num == 0 ? 1 : 0, 'controller' => $el->controller, 'action' => $el->action ? $el->action : 'ctlshow', 'field' => 'cid', 'title' => $el->title, 'cl' => $cl_0 !== false ? 'f' : ($cl_1 !== false ? 'a' : 't'));
                 }
             }
         }
         $menu = $menu_model->fetchRow(array('`id` = ?' => @(int) $menu->parentid));
         if ($menu) {
             if (strlen($this->config->param['cid']) && !$this->config->param['cid']) {
                 $this->config->stop_frame = 1;
                 $this->view->inlineScript('script', 'c.go("' . $menu->controller . '", "' . $menu->action . '");');
                 $this->config->info[] = $this->config->control_lang_current['no_sel'];
             } else {
                 $s = new Zend_Session_Namespace();
                 $s->control['history'][$menu->controller]['oid'] = $this->config->param['cid'];
                 if ($menu->controller) {
                     $cl_0 = stripos($menu->param, 'cl=0');
                     $this->config->button_bottom[] = array('controller' => $menu->controller, 'action' => $menu->action ? $menu->action : 'ctlshow', 'title' => $this->config->control_lang_current['back'], 'cl' => $cl_0 !== false ? 'f' : 't');
                 }
             }
         }
     }
     $this->config->pre_view;
     echo $this->view->render($this->config->view);
     return $this;
 }