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

/openconstructor/data/event/edit.php

http://openconstructor.googlecode.com/
PHP | 289 lines | 267 code | 1 blank | 21 comment | 30 complexity | a825687fc5216a4208004607197dc4c0 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: edit.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.'/languagesets/'.LANGUAGE.'/editors._wc');
  26. if(!isset($_GET['ds_id'])||!isset($_GET['id'])) die();
  27. require_once($_SERVER['DOCUMENT_ROOT'].WCHOME.'/include/toolbar._wc');
  28. require_once(LIBDIR.'/dsmanager._wc');
  29. $dsm = new DSManager();
  30. $_ds = &$dsm->load($_GET['ds_id']);
  31. if($_GET['id']!='new') {
  32. $_doc = $_ds->get_record($_GET['id']);
  33. assert($_doc !== null);
  34. if($_doc['id']!= $_doc['real_id']) {
  35. $_ds = &$dsm->load($_doc['realDsId']);
  36. $_doc = &$_ds->get_record($_doc['real_id']);
  37. }
  38. } else {
  39. $_doc['date'] = $_doc['end_date'] = time();
  40. $_doc['real_id'] = null;
  41. }
  42. $m = array();
  43. preg_match_all('~<([A-Z0-9]+)~', strtoupper($_ds->allowedTags), $m, PREG_PATTERN_ORDER);
  44. $allowed = (array) @$m[1];
  45. $sDoc = $_ds->wrapDocument($_doc);
  46. ?>
  47. <html>
  48. <head>
  49. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  50. <title><?=$_ds->name?> | <?=$_GET['id']=='new'?CREATE_EVENT:htmlspecialchars($_doc['header'], ENT_COMPAT, 'UTF-8').' | '.EDIT_EVENT.($_doc['id']!=$_doc['real_id']?DOCUMENT_IS_ALIAS:'')?></title>
  51. <link href="<?=WCHOME.'/'.SKIN?>.css" type=text/css rel=stylesheet>
  52. <script>
  53. var
  54. host='<?=$_host?>',
  55. skin='<?=SKIN?>'
  56. ;
  57. function sendData()
  58. {
  59. if(content.source) {theHTML=content;editsource();}
  60. if(introcontent.source) {theHTML=introcontent;editsource();}
  61. repairHRefs(content);
  62. repairHRefs(introcontent);
  63. f.html.value=content.document.body.innerHTML;
  64. f.intro.value=introcontent.document.body.innerHTML;
  65. f.place.value=eventplace.document.body.innerHTML;
  66. content.document.body.disabled=true;
  67. content.document.designMode="Off";
  68. introcontent.document.body.disabled=true;
  69. introcontent.document.designMode="Off";
  70. eventplace.document.body.disabled=true;
  71. eventplace.document.designMode="Off";
  72. disableButton(btn_save,'<?=WCHOME?>/i/e/save_.gif');
  73. f.header.onpropertychange='';
  74. f.submit();
  75. }
  76. function deleteimg(type)
  77. {
  78. if(!mopen("../../confirm.php?q=<?=urlencode(CONFIRM_REMOVE_IMAGE_Q)?>?"+"&skin="+skin,350,150)) return;
  79. var d=new Date();
  80. if(!mopen("../deleteimg.php?ds=<?=$_ds->ds_id?>&id=<?=$_doc['real_id']?>&type="+type+'&j='+Math.ceil(d.getTime()/1000),350,150)) return;
  81. disableButton(document.all('btn_delimg'+type),"<?=WCHOME?>/i/default/e/deleteimg_.gif");
  82. document.all('ref_showimg'+type).outerHTML=document.all('ref_showimg'+type).innerHTML;
  83. }
  84. </script>
  85. <script src="../editor.js"></script>
  86. </head>
  87. <body style="border:groove;border-width:2;margin:10;" ondrag="return false">
  88. <table cellpadding="0" cellspacing="0" border="0" width="100%" height="99%">
  89. <tr><td style="padding-bottom:5px" colspan=2>
  90. <form method="POST" style="margin:0;padding:0;" enctype="multipart/form-data" name="f" action="i_event.php">
  91. <textarea name="html" style="display:none"><?=$_GET['id']=='new'?'':htmlspecialchars($_doc['content'], ENT_COMPAT, 'UTF-8')?></textarea>
  92. <textarea name="intro" style="display:none"><?=$_GET['id']=='new'?'':htmlspecialchars($_doc['intro'], ENT_COMPAT, 'UTF-8')?></textarea>
  93. <textarea name="place" style="display:none"><?=$_GET['id']=='new'?'':htmlspecialchars($_doc['place'], ENT_COMPAT, 'UTF-8')?></textarea>
  94. <input type=hidden name="action" value="<?=$_GET['id']=='new'?'create':'edit'?>_event">
  95. <input type=hidden name="id" value="<?=$_doc['real_id']?>">
  96. <input type="hidden" name="ds_id" value="<?=$_ds->ds_id?>">
  97. <input type="hidden" name="hybridid" value="<?=@$_GET['hybridid']?>">
  98. <input type="hidden" name="fieldid" value="<?=@$_GET['fieldid']?>">
  99. <input type="hidden" name="callback" value="<?=@$_GET['callback']?>">
  100. <input type="hidden" name="autointro" value="false">
  101. <?=F_EVENT_HEADER?>:<input type="button" accesskey="s" onclick="if(!document.all('btn_save').dbtn) sendData()" value="save" style="width:0px;height:0px;"><br>
  102. <textarea style="width:100%" name="header" rows=2 cols=85 onpropertychange="if(!this.value.match(new RegExp('[^\\s]','gi'))) disableButton(btn_save,'<?=WCHOME?>/i/default/e/save_.gif'); else disableButton(btn_save,false)"><?=htmlspecialchars(@$_doc['header'], ENT_COMPAT, 'UTF-8')?></textarea>
  103. <table cellspacing="0" cellpadding="0" style="margin-top:3px;" width="100%">
  104. <tr><td nowrap style="padding-right:15px" valign="top"><?=F_DATE_TIME_BEGIN?>:<br>
  105. <?php
  106. list($day, $month, $year) = explode('/', date('d/m/Y', $_doc['date']));
  107. echo '<input type="text" name="day" size="3" maxlength="2" value="'.$day.'">';
  108. echo '<select size=1 name="month">';
  109. for($i=1;$i<=12;$i++)
  110. {
  111. echo '<option value='.$i;
  112. if($i==$month) echo ' selected';
  113. echo '>'.constant('MONTH_'.$i);
  114. }
  115. echo '</select>';
  116. echo '<select size=1 name="year">';
  117. for($i=1999;$i<=2010;$i++)
  118. {
  119. echo '<option value='.$i;
  120. if($i==$year) echo ' selected';
  121. echo '>'.$i;
  122. }
  123. echo '</select>';
  124. ?>&nbsp;<input type="text" name="time" size="8" maxlength="8" value="<?=date('H:i:s', $_doc['date'])?>"></td>
  125. <td nowrap colspan=2 style="padding-right:0px" valign="top"><?=F_DATE_TIME_END?>:<br>
  126. <?php
  127. list($day, $month, $year) = explode('/', date('d/m/Y', $_doc['end_date']));
  128. echo '<input type="text" name="end_day" size="3" maxlength="2" value="'.$day.'">';
  129. echo '<select size=1 name="end_month">';
  130. for($i=1;$i<=12;$i++)
  131. {
  132. echo '<option value='.$i;
  133. if($i==$month) echo ' selected';
  134. echo '>'.constant('MONTH_'.$i);
  135. }
  136. echo '</select>';
  137. echo '<select size=1 name="end_year">';
  138. for($i=1999;$i<=2010;$i++)
  139. {
  140. echo '<option value='.$i;
  141. if($i==$year) echo ' selected';
  142. echo '>'.$i;
  143. }
  144. echo '</select>';
  145. ?>&nbsp;<input type="text" name="end_time" size="8" maxlength="8" value="<?=date('H:i:s', $_doc['end_date'])?>">
  146. <input type=checkbox <?=@$_doc['published']?' checked':''?> <?=!WCS::decide($_ds, 'publishdoc')||$_GET['id']=='new'?'disabled':''?> name="published" value="true"> <?=F_IS_PUBLISHED?></td>
  147. </tr>
  148. <?php if($_GET['id']!='new') {
  149. if(@$_ds->images['main']||$_ds->images['intro']) echo '<tr><td colspan=3><hr style="margin:0px;padding:0px;"></td></tr>';
  150. ?>
  151. <tr><td nowrap valign="top">
  152. <?php if(@$_ds->images['main']) {
  153. if(@file_exists($_SERVER['DOCUMENT_ROOT'].FILES.$_ds->imagepath.($_doc['real_id']?$_doc['real_id']:$_doc['id']).'.'.$_doc['img_type']))
  154. {
  155. list($w,$h)=explode(',',preg_replace('/(.*width=")(\d*)(".*height=")(\d*)(".*)/mi','\\2,\\4',$_doc['img_main']));
  156. echo '<a href="#" name="ref_showimgmain" onclick="window.open(\''.FILES.$_ds->imagepath.($_doc['real_id']?$_doc['real_id']:$_doc['id']).'.'.$_doc['img_type'].'\',\'\',\'resizable=yes, scrollbars=no, status=no, height='.($h+30).', width='.($w+20).'\');return false" title="'.TT_SHOW_CURRENT_IMAGE.'">'.F_IMAGEMAIN.'</a>';
  157. }
  158. else
  159. echo F_IMAGEMAIN;?>:<br>
  160. <input type="file" name="image">&nbsp;&nbsp;<a href="javascript:deleteimg('main')" class="tool1"><img src="<?=WCHOME?>/i/default/e/deleteimg.gif" align=absmiddle alt="<?=BTN_REMOVE_IMAGE?>" name="btn_delimgmain"></a>
  161. <?php }?></td>
  162. <td nowrap valign="top" style="padding-left:5px;">
  163. <?php if(@$_ds->images['intro']) {
  164. echo '<input type="checkbox" name="manual_img" value="true" checked onclick="f.image_intro.disabled=!this.checked" align="bottom" style="margin:-1px 1px 0px"></td><td width="100%">';
  165. if(@file_exists($_SERVER['DOCUMENT_ROOT'].FILES.$_ds->imagepath.($_doc['real_id']?$_doc['real_id']:$_doc['id']).'_.'.$_doc['img_type']))
  166. {
  167. list($w,$h)=explode(',',preg_replace('/(.*width=")(\d*)(".*height=")(\d*)(".*)/mi','\\2,\\4',$_doc['img_intro']));
  168. echo '<a href="#" name="ref_showimgintro" onclick="window.open(\''.FILES.$_ds->imagepath.($_doc['real_id']?$_doc['real_id']:$_doc['id']).'_.'.$_doc['img_type'].'\',\'\',\'resizable=yes, scrollbars=no, status=no, height='.($h+30).', width='.($w+20).'\');return false" title="'.TT_SHOW_CURRENT_IMAGE.'">'.F_IMAGEINTRO.'</a>';
  169. }
  170. else
  171. echo F_IMAGEINTRO;?>:<br>
  172. <input type="file" name="image_intro">&nbsp;&nbsp;<a href="javascript:deleteimg('intro')" class="tool1"><img src="<?=WCHOME?>/i/default/e/deleteimg.gif" align=absmiddle alt="<?=BTN_REMOVE_IMAGE?>" name="btn_delimgintro"></a>
  173. <?php }?>
  174. </td>
  175. </tr>
  176. <script>if(!document.all('ref_showimgmain')&&f.image) disableButton(f.btn_delimgmain,"<?=WCHOME?>/i/default/e/deleteimg_.gif");if(!document.all('ref_showimgintro')&&f.image_intro) disableButton(f.btn_delimgintro,"<?=WCHOME?>/i/default/e/deleteimg_.gif");</script>
  177. <?php }?>
  178. </table>
  179. </form>
  180. <hr size="2">
  181. <table width="100%" cellpadding="0" cellspacing="0" border="0" height="24"><tr><td align="left">
  182. <nobr>
  183. <?php
  184. $save = @$_GET['hybridid'] > 0 || ($_GET['id'] == 'new' ? WCS::decide($_ds, 'createdoc') : WCS::decide($_ds, 'editdoc') || WCS::decide($sDoc, 'editdoc'));
  185. toolbar(array(
  186. BTN_NEW_DOCUMENT=>array('pic'=>'newdocument','action'=>'window.location.assign("?id=new&ds_id='.$_GET['ds_id'].'")'),
  187. BTN_SAVE=>array('pic'=>'save','action'=> $save ? 'sendData()' : ''),
  188. 'separator',
  189. BTN_CUT=>array('pic'=>'cut','action'=>'excmd("Cut")'),
  190. BTN_COPY=>array('pic'=>'copy','action'=>'excmd("Copy")'),
  191. BTN_PASTE=>array('pic'=>'paste','action'=>'excmd("Paste")'),
  192. BTN_REMOVE_FORMAT=>array('pic'=>'unformat','action'=>'excmd("RemoveFormat")'),
  193. BTN_REMOVE_STYLES=>array('pic'=>'removecss','action'=>'removeCSS()'),
  194. 'separator',
  195. BTN_INSERT_IMAGE=>array('pic'=>'image','action'=>array_search('IMG',$allowed)!==false?'insertImage()':''),
  196. BTN_INSERT_LINK=>array('pic'=>'link','action'=>'excmd("CreateLink")'),
  197. 'separator',
  198. BTN_BOLD=>array('pic'=>'bold','action'=>'excmd("Bold")'),
  199. BTN_ITALIC=>array('pic'=>'italic','action'=>'excmd("Italic")'),
  200. 'separator',
  201. BTN_ALIGN_LEFT=>array('pic'=>'left','action'=>'excmd("JustifyLeft")'),
  202. BTN_ALIGN_CENTER=>array('pic'=>'center','action'=>'excmd("JustifyCenter")'),
  203. BTN_ALIGN_RIGHT=>array('pic'=>'right','action'=>'excmd("JustifyRight")'),
  204. 'separator',
  205. BTN_INDENT=>array('pic'=>'indent','action'=>'excmd("Indent")'),
  206. BTN_OUTDENT=>array('pic'=>'outdent','action'=>'excmd("Outdent")'),
  207. 'separator',
  208. BTN_INSERT_UL=>array('pic'=>'ulist','action'=>'excmd("InsertUnorderedList")'),
  209. BTN_INSERT_OL=>array('pic'=>'olist','action'=>'excmd("InsertOrderedList")'),
  210. 'separator',
  211. BTN_EDIT_STYLE=>array('pic'=>'style','action'=>'editStyle()'),
  212. BTN_EDIT_TAG_PROPS=>array('pic'=>'attribute','action'=>'editProps()'),
  213. BTN_EDIT_SOURCE=>array('pic'=>'editsrc','action'=>'editsource()'),
  214. BTN_IMPORT_TABLE=>array('pic'=>'importtbl','action'=>'editTable()')
  215. ));
  216. ?><IMG SRC="<?=WCHOME?>/i/default/e/separator.gif" align="top"> <SELECT size=1 id="tagID" align="absmiddle"><?php
  217. foreach(explode(',','H1,H2,H3,H4,DIV,SPAN,NOBR') as $tag)
  218. if(array_search($tag,$allowed)!==false)
  219. echo '<OPTION value="'.$tag.'">&lt;'.$tag.'&gt;';
  220. ?></SELECT> <input align="top" type="button" value="<?=BTN_INSERT_TAG?>" onclick="if(tagID.options.length) intoTags(tagID.options(tagID.selectedIndex).value)" style="width:80px;margin-top:0px;">
  221. </nobr>
  222. </td></tr></table>
  223. <?=$_GET['id']!='new'?'':'<script>disableButton(btn_save,"'.WCHOME.'/i/default/e/save_.gif");</script>'?>
  224. </td></tr><tr height="75%" valign="top"><td colspan=2>
  225. <iframe name="content" style="border:none" width="100%" style="margin:0 0" height="100%" onfocus="theHTML=content"></iframe>
  226. </td></tr><tr><td style="padding:2px 0px">
  227. <nobr><input type="checkbox" name="autointro" onclick="if(this.checked){f.autointro.value='true'}else{f.autointro.value='false'}"> <?=F_AUTOGENERATE_INTRO?></nobr>
  228. </td><td style="padding:2px 0px">
  229. <nobr><?=F_EVENT_PLACE?>: </nobr>
  230. </td></tr><tr height="25%" valign="top"><td width="50%" style="padding: 0px 10px 0px 0px;">
  231. <iframe name="introcontent" style="border:none" width="100%" style="margin:0" height="100%" onfocus="theHTML=introcontent"></iframe>
  232. </td><td width="50%">
  233. <iframe name="eventplace" style="border:none" width="100%" style="margin:0" height="100%" onfocus="theHTML=eventplace"></iframe>
  234. </td></tr><table>
  235. <script defer>
  236. theHTML=content;
  237. content.document.designMode="On";
  238. introcontent.document.designMode="On";
  239. eventplace.document.designMode="On";
  240. window.inter=window.setInterval(setcontent,500);
  241. function setcontent(a)
  242. {
  243. if(content.document.body)
  244. {
  245. window.clearInterval(window.inter);
  246. content.document.body.innerHTML=f.html.value;
  247. content.document.body.onkeypress=new Function('',"if(window.content.event.keyCode==28) {window.parent.editsource()}");
  248. content.focus();
  249. head=content.document.childNodes(0).childNodes(0);
  250. link=content.document.createElement('<link href="http://<?=$_host?>/css/content.css" type=text/css rel=stylesheet>');
  251. head.appendChild(link);
  252. content.document.body.style.background='white';
  253. content.document.body.style.margin='5px';
  254. }
  255. }
  256. window.inter1=window.setInterval(setcontent1,500);
  257. function setcontent1(a)
  258. {
  259. if(introcontent.document.body)
  260. {
  261. window.clearInterval(window.inter1);
  262. introcontent.document.body.innerHTML=f.intro.value;
  263. introcontent.document.body.onkeypress=new Function('',"if(window.introcontent.event.keyCode==28) {window.parent.editsource()}");
  264. head=introcontent.document.childNodes(0).childNodes(0);
  265. link=introcontent.document.createElement('<link href="http://<?=$_host?>/css/content.css" type=text/css rel=stylesheet>');
  266. head.appendChild(link);
  267. introcontent.document.body.style.background='white';
  268. introcontent.document.body.style.margin='5px';
  269. }
  270. }
  271. window.inter2=window.setInterval(setcontent2,500);
  272. function setcontent2(a)
  273. {
  274. if(eventplace.document.body)
  275. {
  276. window.clearInterval(window.inter2);
  277. eventplace.document.body.innerHTML=f.place.value;
  278. eventplace.document.body.onkeypress=new Function('',"if(window.eventplace.event.keyCode==28) {window.parent.editsource()}");
  279. head=eventplace.document.childNodes(0).childNodes(0);
  280. link=eventplace.document.createElement('<link href="http://<?=$_host?>/css/content.css" type=text/css rel=stylesheet>');
  281. head.appendChild(link);
  282. eventplace.document.body.style.background='white';
  283. eventplace.document.body.style.margin='5px';
  284. }
  285. }
  286. </script>
  287. </body>
  288. </html>