PageRenderTime 26ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/www/devel/schema.php

https://github.com/yabba/openx
PHP | 252 lines | 199 code | 21 blank | 32 comment | 71 complexity | 0346a6a3199c98d412a67b6df242ed19 MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v${RELEASE_MAJOR_MINOR} |
  5. | =======${RELEASE_MAJOR_MINOR_DOUBLE_UNDERLINE} |
  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. define('OX_CORE', '/etc/');
  34. define('OX_PLUG', $pluginPath.'%s/etc/');
  35. if (array_key_exists('btn_changeset_archive', $_POST))
  36. {
  37. header('Location: archive.php');
  38. exit;
  39. }
  40. require_once 'lib/schema.inc.php';
  41. if (array_key_exists('clear_cookies', $_POST))
  42. {
  43. setcookie('schemaPath', '');
  44. setcookie('schemaFile', '');
  45. }
  46. else if ( array_key_exists('xml_file', $_REQUEST) && (!empty($_REQUEST['xml_file'])) )
  47. {
  48. $schemaPath = dirname($_REQUEST['xml_file']);
  49. $schemaFile = basename($_REQUEST['xml_file']);
  50. if ($schemaFile==$_COOKIE['schemaFile'])
  51. {
  52. $schemaPath = $_COOKIE['schemaPath'];
  53. }
  54. $_POST['table_edit'] = '';
  55. }
  56. else if ( array_key_exists('schemaFile', $_COOKIE) && (!empty($_COOKIE['schemaFile'])))
  57. {
  58. $schemaPath = $_COOKIE['schemaPath'];
  59. $schemaFile = $_COOKIE['schemaFile'];
  60. }
  61. if (empty($schemaPath) || empty($schemaFile))
  62. {
  63. $schemaPath = ''; //OX_CORE;
  64. $schemaFile = 'tables_core.xml';
  65. }
  66. // ensure correct directory format. $schemaPath requires trailing '/'. Using trailing DIRECTORY_SEPARATOR fails on Windows for reasons unknown
  67. if (isset($schemaPath) && $schemaPath!='')
  68. {
  69. $schemaPath=OX::realPathRelative(urldecode($schemaPath)) ;
  70. $schemaPath.='/' ;
  71. }
  72. setcookie('schemaPath', $schemaPath);
  73. setcookie('schemaFile', $schemaFile);
  74. global $oaSchema;
  75. $oaSchema = & new Openads_Schema_Manager($schemaFile, '', $schemaPath);
  76. if (is_array($aErrs = OX_DevToolbox::checkFilePermissions(array(PATH_DEV, PATH_VAR, MAX_PATH.$pluginPath))))
  77. {
  78. setcookie('schemaFile', '');
  79. setcookie('schemaPath', '');
  80. $errorMessage =
  81. join("<br />\n", $aErrs['errors']) . "<br /><br ><hr /><br />\n" .
  82. 'To fix, please execute the following commands:' . "<br /><br >\n" .
  83. join("<br />\n", $aErrs['fixes']);
  84. die($errorMessage);
  85. }
  86. require_once PATH_DEV.'/lib/xajax.inc.php';
  87. if (array_key_exists('btn_copy_final', $_POST))
  88. {
  89. $oaSchema->createTransitional();
  90. }
  91. else if (array_key_exists('btn_schema_new', $_POST))
  92. {
  93. $oaSchema->createNew($_POST['new_schema_name']);
  94. }
  95. else if (array_key_exists('btn_delete_trans', $_POST))
  96. {
  97. $oaSchema->deleteTransitional();
  98. }
  99. else if (array_key_exists('btn_compare_schemas', $_POST))
  100. {
  101. setcookie('changesetFile', '');
  102. if ($oaSchema->createChangeset($oaSchema->changes_trans, $_POST['comments']))
  103. {
  104. header('Content-Type: application/xhtml+xml; charset=ISO-8859-1');
  105. readfile($oaSchema->changes_trans);
  106. exit();
  107. }
  108. }
  109. else if (array_key_exists('btn_changeset_delete', $_POST))
  110. {
  111. $oaSchema->deleteChangesTrans();
  112. }
  113. else if (array_key_exists('btn_commit_final', $_POST))
  114. {
  115. $oaSchema->commitFinal($_POST['comments'], $_POST['version']);
  116. }
  117. else if (array_key_exists('btn_generate_dbo_final', $_POST))
  118. {
  119. $oaSchema->setWorkingFiles();
  120. $oaSchema->parseWorkingDefinitionFile();
  121. $oaSchema->_generateDataObjects($oaSchema->changes_final,$oaSchema->_getBasename());
  122. }
  123. else if (array_key_exists('btn_generate_dbo_trans', $_POST))
  124. {
  125. $oaSchema->setWorkingFiles();
  126. $oaSchema->parseWorkingDefinitionFile();
  127. $oaSchema->_generateDataObjects($oaSchema->changes_trans,$oaSchema->_getBasename());
  128. }
  129. $oaSchema->setWorkingFiles();
  130. if (array_key_exists('table_edit', $_POST) && $_POST['table_edit'])
  131. {
  132. $table = $_POST['table_edit'];
  133. if (array_key_exists('btn_field_save', $_POST) && $_POST['field_name'])
  134. {
  135. $field_name_old = $_POST['field_name'];
  136. $field_name_new = $_POST['fld_new_name'];
  137. $field_type_old = $_POST['field_type'];
  138. $field_type_new = $_POST['fld_new_type'];
  139. $oaSchema->fieldSave($table, $field_name_old, $field_name_new, $field_type_old, $field_type_new);
  140. }
  141. else if (array_key_exists('btn_field_add', $_POST) && $_POST['field_add'])
  142. {
  143. $field_name = $_POST['field_add'];
  144. $dd_field_name = $_POST['sel_field_add'];
  145. $oaSchema->fieldAdd($table, $field_name, $dd_field_name);
  146. }
  147. else if (array_key_exists('btn_field_del', $_POST) && $_POST['field_name'])
  148. {
  149. $field = $_POST['field_name'];
  150. $oaSchema->fieldDelete($table, $field);
  151. }
  152. else if (array_key_exists('btn_index_del', $_POST) && $_POST['index_name'])
  153. {
  154. $index = $_POST['index_name'];
  155. $oaSchema->indexDelete($table, $index);
  156. }
  157. else if (array_key_exists('btn_index_add', $_POST) && $_POST['idx_fld_add'] && $_POST['index_add'])
  158. {
  159. $index_fields = $_POST['idx_fld_add'];
  160. $index_name = $_POST['index_add'];
  161. $sort_desc = $_POST['idx_fld_desc'];
  162. $unique = $_POST['idx_unique'];
  163. $primary = $_POST['idx_primary'];
  164. $oaSchema->indexAdd($table, $index_name, $index_fields, $primary, $unique, $sort_desc);
  165. }
  166. else if (array_key_exists('btn_index_save', $_POST) && $_POST['index_name'])
  167. {
  168. $index_name = $_POST['index_name'];
  169. $index_no = $_POST['index_no'];
  170. $index_def = $_POST['idx'][$index_no];
  171. $oaSchema->indexSave($table, $index_name, $index_def);
  172. }
  173. else if (array_key_exists('btn_link_del', $_POST) && $_POST['link_name'])
  174. {
  175. $link_name = $_POST['link_name'];
  176. $oaSchema->linkDelete($table, $link_name);
  177. }
  178. else if (array_key_exists('btn_link_add', $_POST) && $_POST['link_add'] && $_POST['link_add_target'])
  179. {
  180. $link_add = $_POST['link_add'];
  181. $link_add_target = $_POST['link_add_target'];
  182. $oaSchema->linkAdd($table, $link_add, $link_add_target);
  183. }
  184. else if (array_key_exists('btn_table_save', $_POST) && $_POST['tbl_new_name'])
  185. {
  186. $table_name_new = $_POST['tbl_new_name'];
  187. $ok = $oaSchema->tableSave($table, $table_name_new);
  188. if ($ok) {
  189. $table = $table_name_new;
  190. }
  191. }
  192. else if (array_key_exists('btn_table_delete', $_POST))
  193. {
  194. $oaSchema->tableDelete($table);
  195. unset($table);
  196. }
  197. else if (array_key_exists('btn_table_cancel', $_POST))
  198. {
  199. $table = '';
  200. }
  201. }
  202. else if (array_key_exists('btn_table_new', $_POST) && isset($_POST['new_table_name']))
  203. {
  204. $table = $_POST['new_table_name'];
  205. $oaSchema->tableNew($table);
  206. unset($table);
  207. }
  208. else if (array_key_exists('btn_table_edit', $_POST))
  209. {
  210. $table = $_POST['btn_table_edit'];
  211. }
  212. if (!$table)
  213. {
  214. header('Content-Type: application/xhtml+xml; charset=ISO-8859-1');
  215. readfile($oaSchema->working_file_schema);
  216. // echo $before.' - '.$after ;
  217. exit();
  218. }
  219. else
  220. {
  221. $oaSchema->parseWorkingDefinitionFile();
  222. $aDD_definition = $oaSchema->aDD_definition;
  223. $aDB_definition = $oaSchema->aDB_definition;
  224. $aTbl_definition = $oaSchema->aDB_definition['tables'][$table];
  225. $aLinks = $oaSchema->readForeignKeys($table);
  226. $aTbl_links = $aLinks[$table];
  227. $aLink_targets = $oaSchema->getLinkTargets();
  228. include 'templates/schema_edit.html';
  229. exit();
  230. }
  231. ?>