server()) { metaRefresh("../login.php"); exit; } if(isset($_POST['type'])) { $_GET = $_POST; } if(isset($_GET['abort'])) { unset($_SESSION['currentPDFStructure']); unset($_SESSION['availablePDFFields']); session_unregister('currentPDFStructure'); session_unregister('availablePDFFields'); metarefresh('pdfmain.php'); exit; } elseif(isset($_GET['submit'])) { savePDFStructureDefinitions($_GET['type'],$_GET['pdfname'] . '.xml'); unset($_SESSION['currentPDFStructure']); unset($_SESSION['availablePDFFields']); session_unregister('currentPDFStructure'); session_unregister('availablePDFFields'); metarefresh('pdfmain.php'); exit; } elseif(isset($_GET['add_section'])) { $attributes = array(); if($_GET['section_type'] == 'text') { $attributes['NAME'] = $_GET['section_text']; } elseif($_GET['section_type'] == 'item') { $attributes['NAME'] = '_' . $_GET['section_item']; } $newSectionStart = array('tag' => 'SECTION','type' => 'open','level' => '2','attributes' => $attributes); $newSectionEnd = array('tag' => 'SECTION','type' => 'close','level' => '2'); $_SESSION['currentPDFStructure'][] = $newSectionStart; $_SESSION['currentPDFStructure'][] = $newSectionEnd; } elseif(isset($_GET['add_field'])) { $modules = explode(',',$_GET['modules']); $fields = array(); foreach($modules as $module) { if(isset($_GET[$module])) { foreach($_GET[$module] as $field) { $fields[] = array('tag' => 'ENTRY','type' => 'complete','level' => '3','attributes' => array('NAME' => $module . '_' . $field)); } } } if(count($fields) > 0) { $pos = 0; while($pos < $_GET['section']) { next($_SESSION['currentPDFStructure']); $pos++; } $current = next($_SESSION['currentPDFStructure']); $pos++; while($current && $current['tag'] != 'SECTION' && $current['type'] != 'close') { $current = next($_SESSION['currentPDFStructure']); $pos++; } array_splice($_SESSION['currentPDFStructure'],$pos,0,$fields); } } elseif(isset($_GET['remove'])) { $start = 0; while($start < $_GET['remove']) { next($_SESSION['currentPDFStructure']); $start++; } $remove = current($_SESSION['currentPDFStructure']); if($remove['tag'] == "SECTION") { $end = $start; $current = next($_SESSION['currentPDFStructure']); $end++; while($current && $current['tag'] != 'SECTION' && $current['type'] != 'close') { $current = next($_SESSION['currentPDFStructure']); $end++; } array_splice($_SESSION['currentPDFStructure'],$start,$end - $start + 1); } elseif($remove['tag'] == "ENTRY") { array_splice($_SESSION['currentPDFStructure'],$start,1); } elseif($remove['tag'] == "TEXT") { array_splice($_SESSION['currentPDFStructure'],$start,1); } } elseif(isset($_GET['up'])) { $tmp = $_SESSION['currentPDFStructure'][$_GET['up']]; $prev = $_SESSION['currentPDFStructure'][$_GET['up'] - 1]; if($tmp['tag'] == 'SECTION') { $pos = 0; $borders = array(); $current = current($_SESSION['currentPDFStructure']); if($current['tag'] == 'SECTION') { $borders[$current['type']][] = $pos; } while($pos < $_GET['up']) { $current = next($_SESSION['currentPDFStructure']); $pos++; if($current['tag'] == 'SECTION') { $borders[$current['type']][] = $pos; } } if(count($borders['close']) > 0) { $current = next($_SESSION['currentPDFStructure']); $pos++; while($current && $current['tag'] != 'SECTION' && $current['type'] != 'close') { $current = next($_SESSION['currentPDFStructure']); $pos++; } $borders['close'][] = $pos; $cut_start = $borders['open'][count($borders['open']) - 1]; $cut_count = $borders['close'][count($borders['close']) - 1] - $borders['open'][count($borders['open']) - 1] + 1; $insert_pos = $borders['open'][count($borders['open']) - 2]; $tomove = array_splice($_SESSION['currentPDFStructure'],$cut_start,$cut_count); array_splice($_SESSION['currentPDFStructure'],$insert_pos,0,$tomove); } } elseif($tmp['tag'] == 'ENTRY' && $prev['tag'] == 'ENTRY') { $_SESSION['currentPDFStructure'][$_GET['up']] = $_SESSION['currentPDFStructure'][$_GET['up'] - 1]; $_SESSION['currentPDFStructure'][$_GET['up'] - 1] = $tmp; } elseif($tmp['tag'] == 'TEXT') { if($_GET['up'] != 0) { $tomove = array_splice($_SESSION['currentPDFStructure'],$_GET['up'],1); array_splice($_SESSION['currentPDFStructure'],0,0,$tomove); } } } elseif(isset($_GET['down'])) { $tmp = $_SESSION['currentPDFStructure'][$_GET['down']]; $next = $_SESSION['currentPDFStructure'][$_GET['down'] + 1]; if($tmp['tag'] == 'SECTION') { $pos = 0; $current = current($_SESSION['currentPDFStructure']); while($pos < $_GET['down']) { $current = next($_SESSION['currentPDFStructure']); $pos++; } $borders = array(); $borders[$current['type']][] = $pos; $current = next($_SESSION['currentPDFStructure']); $pos++; while($current && $current['tag'] != 'SECTION' && $current['type'] != 'close') { $current = next($_SESSION['currentPDFStructure']); $pos++; } $borders['close'][] = $pos; $current = next($_SESSION['currentPDFStructure']); $pos++; if($current) { $borders[$current['type']][] = $pos; $current = next($_SESSION['currentPDFStructure']); $pos++; while($current && $current['tag'] != 'SECTION' && $current['type'] != 'close') { if($current['tag'] == 'SECTION') { $borders[$current['type']][] = $pos; } $current = next($_SESSION['currentPDFStructure']); $pos++; } $borders['close'][] = $pos; } if(count($borders['open']) > 1) { $cut_start = $borders['open'][count($borders['open']) - 1]; $cut_count = $borders['close'][count($borders['close']) - 1] - $borders['open'][count($borders['open']) - 1] + 1; $insert_pos = $borders['open'][count($borders['open']) - 2]; $tomove = array_splice($_SESSION['currentPDFStructure'],$cut_start,$cut_count); array_splice($_SESSION['currentPDFStructure'],$insert_pos,0,$tomove); } } elseif($tmp['tag'] == 'ENTRY' && $next['tag'] == 'ENTRY') { $_SESSION['currentPDFStructure'][$_GET['down']] = $_SESSION['currentPDFStructure'][$_GET['down'] + 1]; $_SESSION['currentPDFStructure'][$_GET['down'] + 1] = $tmp; } elseif($tmp['tag'] == 'TEXT') { if($_GET['down'] != (count($_SESSION['currentPDFStructure']) -1)) { $tomove = array_splice($_SESSION['currentPDFStructure'],$_GET['down'],1); array_splice($_SESSION['currentPDFStructure'],count($_SESSION['currentPDFStructure']),0,$tomove); } } } elseif(isset($_GET['add_text'])) { if($_GET['text_type'] == 'config') { $entry = array('tag' => 'TEXT','type' => 'complete','level' => '2','attributes' => array('type' => $_GET['type'])); } else { $entry = array('tag' => 'TEXT','type' => 'complete','level' => '2','value' => $_GET['text_text']); } if($_GET['text_position'] == 'top') { array_splice($_SESSION['currentPDFStructure'],0,0,array($entry)); } else { array_push($_SESSION['currentPDFStructure'],$entry); } } if(!isset($_SESSION['currentPDFStructure'])) { if($_GET['edit']) { $_SESSION['currentPDFStructure'] = loadPDFStructureDefinitions($_GET['type'],$_GET['edit']); } else { $_SESSION['currentPDFStructure'] = loadPDFStructureDefinitions($_GET['type']); } } if(!isset($_SESSION['availablePDFFields'])) { $_SESSION['availablePDFFields'] = getAvailablePDFFields($_GET['type']); } $modules = array(); $section_items = ''; foreach($_SESSION['availablePDFFields'] as $module => $values) { $modules[] = $module; foreach($values as $attribute) { $section_items .= "\t\t\t\t\t\t\t\t\t\t\t\t\n"; } } $modules = join(',',$modules); // print header echo $_SESSION['header']; ?>