Пример #1
0
 function paraToSql($rel, $path, $para)
 {
     global $sql, $para_nr, $category_id;
     if (isset($para['edit'])) {
         $para_id = $para_nr++;
         $para_path = '';
         if (strstr($para['path'], '-') === false) {
             // Change a paragraph
             $sql .= "insert into referendum_type_law (referendum, id, add, path, title, text)\n\t       select\n\t\tcurrval('referendum_id_seq'),\n\t\t'{$para_id}',\n\t\t'{$para['edit']['add']}',\n\t\t'{$para['path']}',\n\t\t'{$para['edit']['title']}',\n\t\t'{$para['edit']['text']}';\n\t     ";
         } else {
             if ($rel === false) {
                 $sql .= "insert into referendum_type_law (referendum, id, add, path, title, text)\n\t       select\n\t\tcurrval('referendum_id_seq'),\n\t\t'{$para_id}',\n\t\t'{$para['edit']['add']}',\n\t\tlaw_next_paragraph({$category_id}, '{$path}'),\n\t\t'{$para['edit']['title']}',\n\t\t'{$para['edit']['text']}';\n\t     ";
             } else {
                 $sql .= "insert into referendum_type_law (referendum, id, add, path, title, text)\n\t       select\n\t\tcurrval('referendum_id_seq'),\n\t\t'{$para_id}',\n\t\t'{$para['edit']['add']}',\n\t\tlaw_next_paragraph({$category_id},\n\t\t\t\t   law_paragraph_combine(path, 0, '{$path}')),\n\t\t'{$para['edit']['title']}',\n\t\t'{$para['edit']['text']}'\n\t       from\n\t\treferendum_type_law\n\t       where     referendum = currval('referendum_id_seq')\n\t\t     and id = '{$rel}';\n\t     ";
             }
         }
     } else {
         if (strstr($para['path'], '-') !== false) {
             if ($rel === false) {
                 $sql .= "insert into referendum_type_law (referendum, id, add, path, title, text)\n\t       select\n\t\tcurrval('referendum_id_seq'),\n\t\t'{$para_id}',\n\t\t'false',\n\t\tlaw_next_paragraph({$category_id}, '{$path}'),\n\t\t'',\n\t\t'';\n\t     ";
             } else {
                 $sql .= "insert into referendum_type_law (referendum, id, add, path, title, text)\n\t       select\n\t\tcurrval('referendum_id_seq'),\n\t\t'{$para_id}',\n\t\t'false',\n\t\tlaw_next_paragraph({$category_id},\n\t\t\t\t   law_paragraph_combine(path, 0, '{$path}')),\n\t\t'',\n\t\t''\n\t       from\n\t\treferendum_type_law\n\t       where     referendum = currval('referendum_id_seq')\n\t\t     and id = '{$rel}';\n\t     ";
             }
         } else {
             $para_id = false;
             $para_path = $para['path'];
         }
     }
     $lastrel = $para_id;
     $lastpath = pathCombine($para_path, 0, "0");
     foreach ($para['sub'] as $key => $sub) {
         if ($key != '0') {
             list($lastrel, $lastpath) = paraToSql($lastrel, $lastpath, $sub);
         }
     }
     return array($para_id, $para_path);
 }
Пример #2
0
 function paraToSql($para)
 {
     global $sql, $category_id;
     if ($para['type'] == 'add') {
         if ($para['relative'] === false) {
             $sql .= "insert into referendum_type_law (referendum, id, add, path, title, text)\n\t\tselect\n\t\t currval('referendum_id_seq'),\n\t\t '{$para['id']}',\n\t\t true,\n\t\t law_next_paragraph({$category_id}, '{$para['path']}'),\n\t\t '{$para['title']}',\n\t\t '{$para['text']}';\n\t      ";
         } else {
             $sql .= "insert into referendum_type_law (referendum, id, add, path, title, text)\n\t\tselect\n\t\t currval('referendum_id_seq'),\n\t\t '{$para['id']}',\n\t\t true,\n\t\t law_next_paragraph({$category_id},\n\t\t\t\t    law_paragraph_combine(path, 0, '{$para['path']}')),\n\t\t '{$para['title']}',\n\t\t '{$para['text']}'\n\t\tfrom\n\t\t referendum_type_law\n\t\twhere     referendum = currval('referendum_id_seq')\n\t\t      and id = '{$para['relative']}';\n\t      ";
         }
     } else {
         if ($para['type'] == 'change') {
             $sql .= "insert into referendum_type_law (referendum, id, add, path, title, text)\n\t       select\n\t\tcurrval('referendum_id_seq'),\n\t\t'{$para['id']}',\n\t\ttrue,\n\t\t'{$para['path']}',\n\t\t'{$para['title']}',\n\t\t'{$para['text']}';\n\t     ";
         } else {
             if ($para['type'] == 'delete') {
                 $sql .= "insert into referendum_type_law (referendum, id, add, path)\n\t       select\n\t\tcurrval('referendum_id_seq'),\n\t\t'{$para['id']}',\n\t\tfalse,\n\t\t'{$para['path']}';\n\t     ";
             }
         }
     }
     foreach (array_reverse($para['sub']) as $sub) {
         paraToSql($sub);
     }
     foreach (array_reverse($para['next']) as $next) {
         paraToSql($next);
     }
 }