예제 #1
0
 /**
  * Funkce pro úpravu AllowedRange
  */
 function editRange()
 {
     require_once JPATH_COMPONENT . DS . 'models' . DS . 'bkef.php';
     $model = new BkefModel();
     if ($_POST['potvrzeni'] == 'interval' || $_POST['potvrzeni'] == 'enumeration') {
         //skutecne smazeme
         $xml = $model->load(JRequest::getInt('article'));
         $maId = intval(JRequest::getInt('maId', -1));
         $fId = intval(JRequest::getInt('fId', -1));
         $format = $xml->MetaAttributes[0]->MetaAttribute[$maId]->Formats[0]->Format[$fId];
         //smazeme puvodni hodnoty
         $allowedRange = $format->AllowedRange[0];
         unset($allowedRange->Interval[0]);
         unset($allowedRange->Enumeration[0]);
         unset($allowedRange);
         $format->addChild('AllowedRange');
         $allowedRange = $format->AllowedRange[0];
         if ($_POST['potvrzeni'] == 'interval') {
             /*------------------------------------------------------*/
             //ulozime interval
             $interval = $allowedRange->addChild('Interval');
             $leftBound = $interval->addChild('LeftBound');
             $leftBound['type'] = JRequest::getString('leftBoundType');
             $leftBound['value'] = checknumber(JRequest::getString('leftBoundValue'));
             $rightBound = $interval->addChild('RightBound');
             $rightBound['type'] = JRequest::getString('rightBoundType');
             $rightBound['value'] = checknumber(JRequest::getString('rightBoundValue'));
             /*------------------------------------------------------*/
             /*zkontrolujeme, jestli to neni v rozporu s collation*/
             if (isset($format->Collation[0])) {
                 if ($format->Collation[0]['type'] == 'Enumeration') {
                     unset($format->Collation[0]);
                 }
             }
             /*------------------------------------------------------*/
         } else {
             /*------------------------------------------------------*/
             //ulozime vycet prvku
             $enumArr = split("\n", JRequest::getString('enumeration'));
             $rangeArr = array();
             $enumeration = $allowedRange->addChild('Enumeration');
             if (count($enumArr) > 0) {
                 foreach ($enumArr as $value) {
                     if (trim($value) != '') {
                         $enumeration->addChild('Value', trim($value));
                         $rangeArr[] = trim($value);
                     }
                 }
             }
             /*------------------------------------------------------*/
             if (isset($format->Collation[0])) {
                 $collation = $format->Collation[0];
                 if ($collation['type'] == 'Enumeration') {
                     $valuesArr = array();
                     /*musime zkontrolovat, jestli allowed range odpovida collation*/
                     if (count($collation->Value) > 0) {
                         $delArr = array();
                         $vId = 0;
                         foreach ($collation->Value as $value) {
                             $valStr = (string) $value;
                             if (!in_array($valStr, $rangeArr)) {
                                 $delArr[] = $vId;
                             } else {
                                 $valuesArr[] = $valStr;
                                 // echo 'pridavam hodnotu'.$value.'<br /><br />';
                             }
                             $vId++;
                         }
                         for ($dId = count($delArr) - 1; $dId >= 0; $dId--) {
                             $deleteId = $delArr[$dId];
                             unset($format->Collation[0]->Value[$deleteId]);
                         }
                     }
                     if (count($rangeArr) > 0) {
                         foreach ($rangeArr as $value) {
                             if (!in_array($value, $valuesArr)) {
                                 $collation->addChild('Value', $value);
                             }
                         }
                     }
                 }
             }
             /*------------------------------------------------------*/
         }
         $model->save(JRequest::getInt('article'), $xml->asXML());
         $this->_redirect = 'index.php?option=com_bkef&task=format&article=' . JRequest::getInt('article') . '&maId=' . $maId . '&fId=' . $fId . '#basicSettings';
     } else {
         //zobrazime dotaz
         require_once JPATH_COMPONENT . DS . 'views' . DS . 'iframe' . DS . 'editRange.html.php';
         $view = new BkefViewEditRange();
         $view->xml = $model->load(JRequest::getInt('article'));
         $view->h1 = JText::_('ALLOWED_RANGE_EDITATION');
         $view->article = JRequest::getInt('article');
         $view->maId = JRequest::getInt('maId');
         $view->fId = JRequest::getInt('fId', -1);
         $view->display();
     }
 }
예제 #2
0
 /**
  * Funkce pro úpravu Range
  */
 function editRange()
 {
     /*DONE_X*/
     require_once JPATH_COMPONENT . DS . 'models' . DS . 'bkef.php';
     $model = new BkefModel();
     if ($_POST['potvrzeni'] == 'interval' || $_POST['potvrzeni'] == 'enumeration' || $_POST['potvrzeni'] == 'regex') {
         //skutecne pracujeme
         $xml = $model->load(JRequest::getInt('article'));
         $maId = intval(JRequest::getInt('maId', -1));
         $fId = intval(JRequest::getInt('fId', -1));
         $format = $xml->MetaAttributes[0]->MetaAttribute[$maId]->Formats[0]->Format[$fId];
         //ulozime cas zmeny
         ///BKEF
         $xml->Header[0]->LastModified[0]->Author = $this->getUserName();
         $xml->Header[0]->LastModified[0]->Timestamp = date('c');
         ///metaattribute
         $xml->MetaAttributes[0]->MetaAttribute[$maId]->LastModified[0]->Timestamp = date('c');
         $xml->MetaAttributes[0]->MetaAttribute[$maId]->LastModified[0]->Author = $this->getUserName();
         ///format
         $format->LastModified[0]->Timestamp = date('c');
         $format->LastModified[0]->Author = $this->getUserName();
         //najdeme cilene elementy
         if (!isset($format->Collation)) {
             $collation = $format->addChild('Collation');
         } else {
             $collation = $format->Collation[0];
         }
         if (!isset($format->Range)) {
             $range = $format->addChild('Range');
         } else {
             $range = $format->Range[0];
         }
         //smazeme puvodni hodnoty
         $range['type'] = '';
         if (count($range->Interval) > 0) {
             for ($rId = 0; $rId < count($range->Interval); $i++) {
                 unset($range->Interval[$rId]);
             }
         }
         if (count($range->Value) > 0) {
             for ($rId = 0; $rId < count($range->Value); $i++) {
                 unset($range->Value[$rId]);
             }
         }
         if (count($range->Regex) > 0) {
             for ($rId = 0; $rId < count($range->Regex); $i++) {
                 unset($range->Regex[$rId]);
             }
         }
         //ulozime hodnoty do Range
         if ($_POST['potvrzeni'] == 'interval') {
             /*------------------------------------------------------*/
             //ulozime interval
             $range['type'] = 'Interval';
             $interval = $range->addChild('Interval');
             $closure = '';
             if (JRequest::getString('leftBoundType') == "closed") {
                 $closure .= 'closed';
             } else {
                 $closure .= 'open';
             }
             if (JRequest::getString('rightBoundType') == "closed") {
                 $closure .= 'Closed';
             } else {
                 $closure .= 'Open';
             }
             $interval['closure'] = $closure;
             $interval['leftMargin'] = checknumber(JRequest::getString('leftBoundValue'));
             $interval['rightMargin'] = checknumber(JRequest::getString('rightBoundValue'));
             /*------------------------------------------------------*/
             /*zkontrolujeme, jestli to neni v rozporu s collation*/
             if (isset($format->Collation[0])) {
                 if ($format->Collation[0]['type'] == 'Enumeration') {
                     unset($format->Collation[0]);
                 }
             }
             /*------------------------------------------------------*/
         } elseif ($_POST['potvrzeni'] == 'regex') {
             $range['type'] = 'Regex';
             $range->addChild('Regex', JRequest::getString('regex'));
         } else {
             /*------------------------------------------------------*/
             //ulozime vycet prvku
             $enumArr = split("\n", JRequest::getString('enumeration'));
             $rangeArr = array();
             $range['type'] = 'Enumeration';
             if (count($enumArr) > 0) {
                 foreach ($enumArr as $value) {
                     if (trim($value) != '') {
                         $range->addChild('Value', trim($value));
                         $rangeArr[] = trim($value);
                     }
                 }
             }
             /*------------------------------------------------------*/
         }
         //ulozime Collation
         $collation['type'] = JRequest::getString('collation_type');
         $collation['sense'] = JRequest::getString('collation_sense');
         //save
         $model->save(JRequest::getInt('article'), $xml->asXML());
         $this->_redirect = 'index.php?option=com_bkef&task=format&article=' . JRequest::getInt('article') . '&maId=' . $maId . '&fId=' . $fId . '#basicSettings';
     } else {
         //zobrazime dotaz
         require_once JPATH_COMPONENT . DS . 'views' . DS . 'iframe' . DS . 'editRange.html.php';
         $view = new BkefViewEditRange();
         $view->xml = $model->load(JRequest::getInt('article'));
         $view->h1 = JText::_('ALLOWED_RANGE_EDITATION');
         $view->article = JRequest::getInt('article');
         $view->maId = JRequest::getInt('maId');
         $view->fId = JRequest::getInt('fId', -1);
         $view->display();
     }
 }