Esempio n. 1
0
 function correct($k, &$v)
 {
     if ($this->_key === 'field') {
         $t = $v;
         $v = new Zkernel_Config_Control(array('stype' => '', 'editoptions' => '', 'required' => false, 'type' => 'text', 'align' => '', 'width' => '', 'description' => '', 'sortable' => false, 'active' => $k != 'lang' && $k != 'parentid' && $k != 'orderid' && $k != 'id' && !preg_match('/^ml\\_[^\\_]+\\_[\\d]+$/i', $k), 'name' => $k, 'title' => $k == 'title' ? 'Название' : $k, 'hidden' => false, 'live' => false, 'formatter' => '', 'formatoptions' => '', 'param' => array(), 'order' => 1000));
         $v->set($t);
     } else {
         if ($this->_key === 'button_top' || $this->_key === 'button_bottom') {
             if (is_string($v)) {
                 $action = 'ctl' . $v;
                 $default = 0;
                 $inner = 0;
                 $confirm = (int) ($v == 'delete');
                 $param = '';
                 $field = '';
                 $cl = 't';
             } else {
                 $action = $v->action;
                 $default = (int) $v->default;
                 $inner = (int) $v->inner;
                 $confirm = (int) $v->confirm;
                 $param = $v->param;
                 $cl = @$v->cl ? $v->cl : 't';
                 $controller = $v->controller;
                 $field = $v->field;
             }
             if (!@$controller) {
                 $controller = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
             }
             if (is_object($v) && $v->title) {
                 $title = $v->title;
             } else {
                 switch ($action) {
                     case 'ctladd':
                         $title = '_lang_add';
                         break;
                     case 'ctledit':
                         $title = '_lang_edit';
                         break;
                     case 'ctldelete':
                         $title = '_lang_delete';
                         break;
                 }
             }
             $v = new Zkernel_Config_Control(array('cl' => $cl, 'title' => @$title, 'controller' => $controller, 'action' => $action, 'param' => $param, 'default' => $default, 'inner' => $inner, 'confirm' => $confirm, 'field' => $field));
         } else {
             if ($k === 'static_field' && $v) {
                 $t = $v;
                 $v = new Zkernel_Config_Control(array('field_src' => 'title', 'field_dst' => 'stitle', 'unique' => true, 'length' => 20));
                 if ($t instanceof Zkernel_Config_Control) {
                     $v->set($t);
                 }
             }
         }
     }
 }
Esempio n. 2
0
 public function buildForm()
 {
     $id = $this->config->param['id'];
     $form = new Zkernel_Form(array('accept-charset' => 'utf-8', 'onsubmit' => 'return c.submit()', 'id' => 'c_form'));
     if ($this->config->field) {
         $d = array();
         $d1 = $this->config->field->toArray();
         foreach ($d1 as $k => $v) {
             $d[$k] = @$v['order'];
             unset($this->config->field->{$k});
         }
         array_multisort($d, SORT_ASC, SORT_NUMERIC, $d1);
         $this->config->field->set($d1);
         $fields = $this->config->field;
         if ($this->config->zk_meta) {
             $fields['meta_title'] = array('title' => 'Title', 'description' => $this->config->control_lang_current['meta_title'], 'order' => 2000);
             $fields['meta_keywords'] = array('title' => 'Keywords', 'description' => $this->config->control_lang_current['meta_keywords'], 'order' => 2001);
             $fields['meta_description'] = array('title' => 'Description', 'description' => $this->config->control_lang_current['meta_description'], 'order' => 2002);
             /*$fields['meta_show_title'] = array(
             			'title' => $this->config->control_lang_current['meta_show_title_title'],
             			'description' => $this->config->control_lang_current['meta_show_title'],
             			'type' => 'select',
             			'param' => array(
             				'multiOptions' => array('1' => 'Да', '0' => 'Нет')
             			),
             			'order' => 2003
             		);*/
         }
         foreach ($fields as $el) {
             if (!$el->active) {
                 continue;
             }
             if (@(int) $this->config->post['sposted'] && !array_key_exists($el->name, $this->config->post->toArray())) {
                 continue;
             }
             $p = new Zkernel_Config_Control($el->param, array('label' => $el->title, 'description' => $el->description, 'required' => $el->required ? true : false, 'validators' => $el->validators ? $el->validators : array()));
             if ($el->unique) {
                 $select = $this->config->model->getAdapter()->select()->where('`id` != ?', $id);
                 if (isset($el->unique->where)) {
                     $select->where($el->unique->where);
                 }
                 $p->validators[] = array('validator' => 'Db_NoRecordExists', 'options' => array($this->config->model->info('name'), $el->name, implode(' ', $select->getPart(Zend_Db_Select::WHERE))));
             }
             if ($el->type == 'textarea') {
                 $p->rows = 10;
             }
             if ($el->type == 'editarea') {
                 $p->rows = 15;
             }
             if ($el->type == 'uploadify') {
                 if (!isset($p->button)) {
                     $p->button = $this->config->control_lang_current['button'];
                 }
                 if (!isset($p->destination)) {
                     $p->destination = PUBLIC_PATH . '/upload/' . $this->config->controller . '_' . $el->name;
                 }
                 /*if (!isset($p->fn)) {
                 			$where = $this->config->where ? $this->config->where->toArray() : array();
                 			$where['`id` = ?'] = $id;
                 			if ($this->config->use_db) $p->fn = $this->config->model->fetchOne($el->name, $where);
                 		}*/
             }
             if ($el->type == 'mce') {
                 if (!isset($p->lang)) {
                     $p->lang = $this->config->control_lang;
                 }
             }
             if ($el->type == 'select') {
                 $p->class = 'c_select';
             } else {
                 if ($el->type == 'textarea') {
                     $p->class = 'ui-state-default ui-corner-all c_textarea';
                 } else {
                     $p->class = 'ui-state-default ui-corner-all c_input';
                 }
             }
             $form->addElement($el->type, $el->name, $p->toArray());
         }
         if ($this->config->zk_meta && !@(int) $this->config->post['sposted']) {
             $form->addDisplayGroup(array('meta_title', 'meta_keywords', 'meta_description', 'meta_show_title'), 'meta', array('legend' => $this->config->control_lang_current['more'], 'class' => 'c_collapse'));
         }
     }
     $form->addElement('submit', 'oac_ok', array('label' => $this->config->oac_ok_title, 'class' => 'c_button'));
     $oac_array = array('oac_ok');
     if ($this->config->oac_cancel) {
         $oac_array[] = 'oac_cancel';
         $form->addElement('submit', 'oac_cancel', array('label' => $this->config->control_lang_current['cancel'], 'onclick' => 'return c.go("' . $this->config->request_cancel->controller . '", "' . $this->config->request_cancel->action . '", ' . Zend_Json::encode(Zkernel_Common::url2array($this->config->request_cancel->param)) . ')', 'class' => 'c_button'));
     }
     if ($this->config->oac_apply) {
         $oac_array[] = 'oac_apply';
         $form->addElement('submit', 'oac_apply', array('label' => $this->config->control_lang_current['submit'], 'onclick' => 'return c.submit(1)', 'class' => 'c_button'));
     }
     $form->addDisplayGroup($oac_array, 'oac');
     return $form;
 }