PageRenderTime 27ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins_repo/openXDeveloperToolbox/www/admin/plugins/oxSchema/oxSchema-frame.php

https://bitbucket.org/valmy/openx
PHP | 245 lines | 181 code | 14 blank | 50 comment | 66 complexity | e05cc811d0fffc97d4a578133eef4923 MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v2.8 |
  5. | ========== |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. /**
  25. * OpenX Schema Management Utility
  26. *
  27. * @author Monique Szpak <monique.szpak@openx.org>
  28. *
  29. * $Id$
  30. *
  31. */
  32. require_once '../../../../init.php';
  33. if (array_key_exists('btn_changeset_archive', $_POST))
  34. {
  35. header('Location: oxSchema-archive.php');
  36. exit;
  37. }
  38. if (array_key_exists('clear_cookies', $_POST))
  39. {
  40. setcookie('schemaPath', '');
  41. setcookie('schemaFile', '');
  42. }
  43. else if ( array_key_exists('xml_file', $_REQUEST) && (!empty($_REQUEST['xml_file'])) )
  44. {
  45. $schemaPath = dirname($_REQUEST['xml_file']);
  46. if (!empty($schemaPath))
  47. {
  48. $schemaPath.= DIRECTORY_SEPARATOR;
  49. }
  50. $schemaFile = basename($_REQUEST['xml_file']);
  51. if ($schemaFile==$_COOKIE['schemaFile'])
  52. {
  53. $schemaPath = $_COOKIE['schemaPath'];
  54. }
  55. $_POST['table_edit'] = '';
  56. }
  57. else if ( array_key_exists('schemaFile', $_COOKIE) && (!empty($_COOKIE['schemaFile'])))
  58. {
  59. $schemaPath = $_COOKIE['schemaPath'];
  60. $schemaFile = $_COOKIE['schemaFile'];
  61. }
  62. if (empty($schemaPath) || empty($schemaFile))
  63. {
  64. $schemaPath = '';
  65. $schemaFile = 'tables_core.xml';
  66. }
  67. setcookie('schemaPath', $schemaPath);
  68. setcookie('schemaFile', $schemaFile);
  69. require_once 'lib/oxSchema.inc.php';
  70. global $oSchema;
  71. $oSchema = & new openXSchemaEditor($schemaFile, '', $schemaPath);
  72. require_once 'lib/oxAjax.inc.php';
  73. if (array_key_exists('btn_copy_final', $_POST))
  74. {
  75. $oSchema->createTransitional();
  76. }
  77. else if (array_key_exists('btn_schema_new', $_POST))
  78. {
  79. $oSchema->createNew($_POST['new_schema_name']);
  80. }
  81. else if (array_key_exists('btn_delete_trans', $_POST))
  82. {
  83. $oSchema->deleteTransitional();
  84. }
  85. else if (array_key_exists('btn_compare_schemas', $_REQUEST))
  86. {
  87. setcookie('changesetFile', '');
  88. if ($oSchema->createChangeset($oSchema->changes_trans, $_POST['comments']))
  89. {
  90. setcookie('changesetFile', $oSchema->changes_trans);
  91. header('Pragma: no-cache');
  92. header('Cache-Control: private, max-age=0, no-cache');
  93. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  94. header('Content-Type: application/xhtml+xml; charset=ISO-8859-1');
  95. readfile($oSchema->changes_trans);
  96. exit();
  97. }
  98. }
  99. else if (array_key_exists('btn_changeset_delete', $_POST))
  100. {
  101. $oSchema->deleteChangesTrans();
  102. }
  103. else if (array_key_exists('btn_commit_final', $_POST))
  104. {
  105. $oSchema->commitFinal($_POST['comments'], $_POST['version']);
  106. }
  107. $oSchema->setWorkingFiles();
  108. if (array_key_exists('table_edit', $_POST) && $_POST['table_edit'])
  109. {
  110. $table = $_POST['table_edit'];
  111. if (array_key_exists('btn_field_save', $_POST) && $_POST['field_name'])
  112. {
  113. $field_name_old = $_POST['field_name'];
  114. $field_name_new = $_POST['fld_new_name'];
  115. $field_type_old = $_POST['field_type'];
  116. $field_type_new = $_POST['fld_new_type'];
  117. $oSchema->fieldSave($table, $field_name_old, $field_name_new, $field_type_old, $field_type_new);
  118. }
  119. else if (array_key_exists('btn_field_add', $_POST) && $_POST['field_add'])
  120. {
  121. $field_name = $_POST['field_add'];
  122. $dd_field_name = $_POST['sel_field_add'];
  123. $oSchema->fieldAdd($table, $field_name, $dd_field_name);
  124. }
  125. else if (array_key_exists('btn_field_del', $_POST) && $_POST['field_name'])
  126. {
  127. $field = $_POST['field_name'];
  128. $oSchema->fieldDelete($table, $field);
  129. }
  130. else if (array_key_exists('btn_index_del', $_POST) && $_POST['index_name'])
  131. {
  132. $index = $_POST['index_name'];
  133. $oSchema->indexDelete($table, $index);
  134. }
  135. else if (array_key_exists('btn_index_add', $_POST) && $_POST['idx_fld_add'] && $_POST['index_add'])
  136. {
  137. $index_fields = $_POST['idx_fld_add'];
  138. $index_name = $_POST['index_add'];
  139. $sort_desc = $_POST['idx_fld_desc'];
  140. $unique = $_POST['idx_unique'];
  141. $primary = $_POST['idx_primary'];
  142. $oSchema->indexAdd($table, $index_name, $index_fields, $primary, $unique, $sort_desc);
  143. }
  144. else if (array_key_exists('btn_index_save', $_POST) && $_POST['index_name'])
  145. {
  146. $index_name = $_POST['index_name'];
  147. $index_no = $_POST['index_no'];
  148. $index_def = $_POST['idx'][$index_no];
  149. $oSchema->indexSave($table, $index_name, $index_def);
  150. }
  151. else if (array_key_exists('btn_link_del', $_POST) && $_POST['link_name'])
  152. {
  153. $link_name = $_POST['link_name'];
  154. $oSchema->linkDelete($table, $link_name);
  155. }
  156. else if (array_key_exists('btn_link_add', $_POST) && $_POST['link_add'] && $_POST['link_add_target'])
  157. {
  158. $link_add = $_POST['link_add'];
  159. $link_add_target = $_POST['link_add_target'];
  160. $oSchema->linkAdd($table, $link_add, $link_add_target);
  161. }
  162. else if (array_key_exists('btn_table_save', $_POST) && $_POST['tbl_new_name'])
  163. {
  164. $table_name_new = $_POST['tbl_new_name'];
  165. $ok = $oSchema->tableSave($table, $table_name_new);
  166. if ($ok) {
  167. $table = $table_name_new;
  168. }
  169. }
  170. else if (array_key_exists('btn_table_delete', $_POST))
  171. {
  172. $oSchema->tableDelete($table);
  173. unset($table);
  174. }
  175. else if (array_key_exists('btn_table_cancel', $_POST))
  176. {
  177. $table = '';
  178. }
  179. }
  180. else if (array_key_exists('btn_table_new', $_POST) && $_POST['new_table_name'])
  181. {
  182. if (array_key_exists('new_table_name', $_POST))
  183. {
  184. $table = $_POST['new_table_name'];
  185. $oSchema->tableNew($table);
  186. unset($table);
  187. }
  188. }
  189. else if (array_key_exists('btn_table_edit', $_POST))
  190. {
  191. $table = $_POST['btn_table_edit'];
  192. }
  193. if (!$table)
  194. {
  195. header('Content-Type: application/xhtml+xml; charset=ISO-8859-1');
  196. readfile($oSchema->working_file_schema);
  197. exit();
  198. }
  199. else
  200. {
  201. $oSchema->parseWorkingDefinitionFile();
  202. $aDD_definition = $oSchema->aDD_definition;
  203. $aDB_definition = $oSchema->aDB_definition;
  204. $aTbl_definition = $oSchema->aDB_definition['tables'][$table];
  205. $aLinks = $oSchema->readForeignKeys($table);
  206. $aTbl_links = $aLinks[$table];
  207. $aLink_targets = $oSchema->getLinkTargets();
  208. include 'templates/schema_edit.html';
  209. exit();
  210. }
  211. /* using XSLT class to display the xml inside html
  212. $xmlfile = $oSchema->working_file_schema;
  213. $xslfile = 'xsl/mdb2_schema.xsl';
  214. // Load the XML source
  215. $xml = new DOMDocument;
  216. $ok = $xml->load($xmlfile);
  217. $xsl = new DOMDocument;
  218. $ok = $xsl->load($xslfile);
  219. // Configure the transformer
  220. $proc = new XSLTProcessor;
  221. $ok = $proc->hasExsltSupport();
  222. $proc->importStyleSheet($xsl); // attach the xsl rules
  223. $i = $proc->transformToUri($xml, MAX_PATH.'/var/templates_compiled/schema.html');
  224. $xslt = file_get_contents(MAX_PATH.'/var/templates_compiled/schema.html');
  225. $oTpl->assign('xslt', $xslt);*/
  226. ?>