PageRenderTime 100ms CodeModel.GetById 36ms RepoModel.GetById 8ms app.codeStats 0ms

/openconstructor/data/phpsource/i_phpsource.php

http://openconstructor.googlecode.com/
PHP | 104 lines | 73 code | 7 blank | 24 comment | 13 complexity | aad6ac0b663dfa4a85e32d8189c1a4fa MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Copyright 2003 - 2007 eSector Solutions, LLC
  4. *
  5. * All rights reserved.
  6. *
  7. * This file is part of Open Constructor (http://www.openconstructor.org/).
  8. *
  9. * Open Constructor is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * Open Constructor is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * The GNU General Public License can be found at
  19. * http://www.gnu.org/copyleft/gpl.html
  20. *
  21. * $Id: i_phpsource.php,v 1.9 2007/03/02 10:06:41 sanjar Exp $
  22. */
  23. require_once($_SERVER['DOCUMENT_ROOT'].'/openconstructor/lib/wccommons._wc');
  24. WCS::requireAuthentication();
  25. require_once(LIBDIR.'/dsmanager._wc');
  26. $dsm = new DSManager();
  27. switch(@$_POST['action'])
  28. {
  29. case 'create_source':
  30. assert(trim(@$_POST['header']) != '');
  31. $_ds = &$dsm->load(@$_POST['ds_id']);
  32. $result=$_ds->add($_POST['header'], @$_POST['html']);
  33. if($result) {
  34. echo '<script>try{window.opener.location.href=window.opener.location.href;}catch(RuntimeException){}';
  35. echo 'window.location.href="edit.php?ds_id='.$_POST['ds_id'].'&id='.$result.'&caret='.@$_POST['caret'].'";</script>';
  36. }
  37. break;
  38. case 'edit_source':
  39. assert(@$_POST['id'] > 0);
  40. assert(trim(@$_POST['header']) != '');
  41. $_ds = &$dsm->load(@$_POST['ds_id']);
  42. $result=$_ds->update($_POST['id'], $_POST['header'], @$_POST['html']);
  43. if($result) {
  44. $ref = $_SERVER['HTTP_REFERER'];
  45. if(@$_POST['caret']) {
  46. if(strpos($ref, '&caret=') !== false || strpos($ref, '?caret=') !== false)
  47. $ref = preg_replace('/(\\?|&)caret=\\d+/', '$1caret='.$_POST['caret'], $ref);
  48. else
  49. $ref = $ref.(utf8_strpos($ref, '?') === false ? '?' : '&').'caret='.$_POST['caret'];
  50. }
  51. header('Location: '.$ref);
  52. }
  53. break;
  54. case 'delete_source':
  55. if(isset($_POST['ds_id']))
  56. {
  57. $_ds = &$dsm->load($_POST['ds_id']);
  58. $_ds->delete(implode(',',@$_POST['ids']));
  59. }
  60. // header('Location: '.$_SERVER['HTTP_REFERER']);
  61. die('<meta http-equiv="Refresh" content="0; URL='.$_SERVER['HTTP_REFERER'].'">');
  62. break;
  63. case 'remove_ds':
  64. if(isset($_POST['ds_id']))
  65. {
  66. $_ds = &$dsm->load($_POST['ds_id']);
  67. $_ds->remove();
  68. }
  69. // header('Location: http://'.$_host.WCHOME.'/data/');
  70. die('<meta http-equiv="Refresh" content="0; URL=http://'.$_host.WCHOME.'/data/">');
  71. break;
  72. case 'move_documents':
  73. assert(@$_POST['ds_id'] > 0 && @$_POST['dest_ds_id'] > 0);
  74. if(isset($_POST['ids'])) {
  75. assert($_ds = &$dsm->load($_POST['ds_id']));
  76. assert($_dest_ds = &$dsm->load($_POST['dest_ds_id']));
  77. assert($_ds->ds_id != $_dest_ds->ds_id);
  78. $_dest_ds->moveDocuments($_ds, $_POST['ids']);
  79. }
  80. // header('Location: '.$_SERVER['HTTP_REFERER']);
  81. die('<meta http-equiv="Refresh" content="0; URL='.$_SERVER['HTTP_REFERER'].'">');
  82. break;
  83. case 'view_detail':
  84. foreach((array) @$_COOKIE['vd'] as $key => $val){
  85. if(!array_key_exists($key, (array) @$_POST['vdetail']))
  86. setcookie('vd['.$key.']', '', time() - 3600, WCHOME.'/data/');
  87. }
  88. foreach($_POST['vdetail'] as $key => $val)
  89. setcookie('vd['.$key.']', $key, 0, WCHOME.'/data/');
  90. setcookie('pagesize', $_POST['pagesize'], 0, WCHOME.'/data/');
  91. setcookie('vd[_touched]', '_touched', 0, WCHOME.'/data/');
  92. header('Location: '.$_SERVER['HTTP_REFERER']);
  93. break;
  94. default:
  95. break;
  96. }
  97. ?>