Example #1
0
 public function ExtractPost($disp)
 {
     $this->_disp = $disp;
     $this->_go_flag = 1;
     $tid = $disp->GetLast(DInfo::FLD_TID);
     $tbl = DTblDef::GetInstance()->GetTblDef($tid);
     $extracted = new CNode(CNode::K_EXTRACTED, '', CNode::T_KB);
     $attrs = $tbl->Get(DTbl::FLD_DATTRS);
     foreach ($attrs as $attr) {
         if ($attr->bypassSavePost()) {
             continue;
         }
         $needCheck = $attr->extractPost($extracted);
         if ($needCheck) {
             if ($attr->_type == 'sel1' || $attr->_type == 'sel2') {
                 if ($this->_disp->Get(DInfo::FLD_ACT) == 'c') {
                     $needCheck = false;
                     // for changed top category
                 } else {
                     $attr->SetDerivedSelOptions($disp->GetDerivedSelOptions($tid, $attr->_minVal, $extracted));
                 }
             }
             $dlayer = $extracted->GetChildren($attr->GetKey());
             if ($needCheck) {
                 $this->validateAttr($attr, $dlayer);
             }
             if (($tid == 'V_TOPD' || $tid == 'V_BASE') && $attr->_type == 'vhname') {
                 $vhname = $dlayer->Get(CNode::FLD_VAL);
                 $disp->Set(DInfo::FLD_ViewName, $vhname);
             }
         }
     }
     $res = $this->validatePostTbl($tbl, $extracted);
     $this->setValid($res);
     // if 0 , make it always point to curr page
     if ($this->_go_flag <= 0) {
         $extracted->SetErr('Input error detected. Please resolve the error(s). ');
     }
     $this->_disp = NULL;
     return $extracted;
 }
Example #2
0
 protected function process_config()
 {
     //init here
     $this->_disp->InitConf();
     $this->loadConfig();
     $confdata = $this->getConfData($this->_disp);
     $needTrim = 0;
     $tblDef = DTblDef::GetInstance();
     $disp_act = $this->_disp->Get(DInfo::FLD_ACT);
     if ($disp_act == 's') {
         $validator = new ConfValidation();
         $extracted = $validator->ExtractPost($this->_disp);
         if ($extracted->HasErr()) {
             $this->_disp->Set(DInfo::FLD_ACT, 'S');
             $this->_disp->Set(DInfo::FLD_TopMsg, $extracted->Get(CNode::FLD_ERR));
             return $extracted;
         } else {
             $confdata->SavePost($extracted, $this->_disp);
             $this->setChanged(true);
             $needTrim = 2;
         }
     } elseif ($disp_act == 'a') {
         $added = new CNode(CNode::K_EXTRACTED, '');
         return $added;
     } elseif ($disp_act == 'c' || $disp_act == 'n') {
         // 'c': change, 'n': next
         $validator = new ConfValidation();
         $extracted = $validator->ExtractPost($this->_disp);
         if ($disp_act == 'n') {
             $this->_disp->SwitchToSubTid($extracted);
         }
         return $extracted;
     } elseif ($disp_act == 'D') {
         $confdata->DeleteEntry($this->_disp);
         $needTrim = 1;
     } elseif ($disp_act == 'I') {
         if ($this->instantiateTemplate()) {
             $needTrim = 1;
         }
     } elseif ($disp_act == 'd' || $disp_act == 'i') {
         if ($disp_act == 'd') {
             $actions = 'DC';
             $mesg = DMsg::UIStr('note_confirm_delete');
         } else {
             $actions = 'IC';
             $mesg = DMsg::UIStr('note_confirm_instantiate');
         }
         $adata = $this->_disp->GetActionData($actions);
         $mesg = '<p>' . $mesg . '</p>' . UI::GetActionButtons($adata, 'text');
         $this->_disp->Set(DInfo::FLD_TopMsg, $mesg);
     }
     $ctxseq = UIBase::GrabGoodInputWithReset('ANY', 'ctxseq', 'int');
     if ($ctxseq != 0) {
         if ($this->_curOne->ChangeContextSeq($ctxseq)) {
             $needTrim = 1;
         }
     }
     if ($needTrim) {
         $this->_disp->TrimLastId();
         // need reload
         $this->loadConfig();
         $confdata = $this->getConfData($this->_disp);
     }
     return $confdata;
 }
Example #3
0
 public function SwitchToSubTid($extracted)
 {
     if (($pos = strrpos($this->_tid, '`')) !== FALSE) {
         $tid0 = substr($this->_tid, 0, $pos + 1);
         $tid = substr($this->_tid, $pos + 1);
     } else {
         $tid0 = '';
         $tid = $this->_tid;
     }
     $tbl = DTblDef::getInstance()->GetTblDef($tid);
     $subtbls = $tbl->Get(DTbl::FLD_SUBTBLS);
     $newkey = $extracted->GetChildVal($subtbls[0]);
     $subtid = '';
     if ($newkey != NULL) {
         if ($newkey == '0' || !isset($subtbls[$newkey])) {
             $subtid = $subtbls[1];
         } else {
             $subtid = $subtbls[$newkey];
         }
     }
     $this->_tid = $tid0 . $subtid;
 }
Example #4
0
 private function print_tbl($tid, $dlayer, $disp)
 {
     $tbl = DTblDef::getInstance()->GetTblDef($tid);
     $tbl->PrintHtml($dlayer, $disp);
     if (($linked = $tbl->Get(DTbl::FLD_LINKEDTBL)) != NULL) {
         if ($this->_linked_tbls == NULL) {
             $this->_linked_tbls = $linked;
         } else {
             $this->_linked_tbls = array_merge($this->_linked_tbls, $linked);
         }
     }
 }
Example #5
0
 private function convert_tbl($tid, $srcnode, $dstnode)
 {
     $tbl = DTblDef::GetInstance()->GetTblDef($tid);
     $attrs = $tbl->Get(DTbl::FLD_DATTRS);
     $index = $tbl->Get(DTbl::FLD_INDEX);
     foreach ($attrs as $attr) {
         if ($attr->_type == 'action' || $attr->IsFlagOn(DAttr::BM_NOFILE)) {
             continue;
         }
         $key = $attr->GetKey();
         $layerpos = strpos($key, ':');
         if ($layerpos > 0) {
             $layer = substr($key, 0, $layerpos);
             $key = substr($key, $layerpos + 1);
             $snode = $srcnode->LocateLayer($layer);
             if ($snode == NULL) {
                 //echo "attr layer loc $layer return NULL\n";
                 continue;
             }
             $dnode = $dstnode->AllocateLayerNode($layer);
         } else {
             $snode = $srcnode;
             $dnode = $dstnode;
         }
         $from = $snode->GetChildren($key);
         if ($from == NULL) {
             $val = $key == $index ? $snode->Get(CNode::FLD_VAL) : '';
             if ($val == '' && !$attr->IsFlagOn(DAttr::BM_NOTNULL)) {
                 continue;
             }
             $from = new CNode($key, $val);
         } else {
             $snode->RemoveChild($key);
         }
         if (is_array($from)) {
             foreach ($from as $fnode) {
                 $fnode->Set(CNode::FLD_PRINTKEY, $key);
                 $dnode->AddChild($fnode);
             }
         } else {
             $from->Set(CNode::FLD_PRINTKEY, $key);
             $dnode->AddChild($from);
             if ($key == $index) {
                 $from->AddFlag(CNode::BM_IDX);
                 $dnode->SetVal($from->Get(CNode::FLD_VAL));
             }
         }
     }
     if (($subtid = $tbl->GetSubTid($dstnode)) != NULL) {
         $this->convert_tbl($subtid, $srcnode, $dstnode);
     }
     if (!$srcnode->HasDirectChildren()) {
         $srcnode->RemoveFromParent();
     }
 }