Source for file layout-editor-defs.php

Documentation is available at layout-editor-defs.php

  1. <?php
  2. /* ******************************************************************** */
  3. /* CATALYST PHP Source Code */
  4. /* -------------------------------------------------------------------- */
  5. /* This program is free software; you can redistribute it and/or modify */
  6. /* it under the terms of the GNU General Public License as published by */
  7. /* the Free Software Foundation; either version 2 of the License, or */
  8. /* (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU General Public License for more details. */
  14. /* */
  15. /* You should have received a copy of the GNU General Public License */
  16. /* along with this program; if not, write to: */
  17. /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
  18. /* Boston, MA 02111-1307 USA */
  19. /* -------------------------------------------------------------------- */
  20. /* */
  21. /* Filename: layout-editor-defs.php */
  22. /* Author: Paul Waite */
  23. /* Description: Definitions for content layout editing in webpages. */
  24. /* */
  25. /* ******************************************************************** */
  26. /** @package cm */* Layouteditor
  27. * A layouteditor is a utility class. It contains all of the methods
  28. * required to edit a layout, so that the layout class can concentrate
  29. * on the basics of layout acquisition and display. The constructor
  30. * of a layouteditor must be passed a reference to the layout it is
  31. * going to be providing editing services for.
  32. * @package cm
  33. */
  34. class layouteditor extends RenderableObject {
  35. // Public
  36. // Private
  37. /** The layout we are providing
  38. editing services for
  39. @access private */
  40. var $layout;
  41. // ....................................................................
  42. /**
  43. * Constructor
  44. * Create a new layouteditor object.
  45. * @param reference $layout A reference to the layout being edited
  46. */
  47. function layouteditor(&$layout) {
  48. $this->layout = $layout;
  49. } // layouteditor
  50. // ....................................................................
  51. /**
  52. * Replicate the hosted layout as a new layout. Creates a brand new
  53. * layout in the database, with same data as this one. The end result
  54. * is that this current object becomes the new layout, and a duplicate
  55. * set of layout records exist in the database. The layout ID of this
  56. * new layout is, of course, updated to being a brand new one.
  57. * NOTES: The layout name is normally left null, which keeps the layout
  58. * in the same 'family' of layout versions. You can force the layout
  59. * name to be different, and this will create a new 'layout_set'
  60. * record of that name for you, if required.
  61. * @param string $layoutname New layout name. If null, keeps same name.
  62. */
  63. function replicate($layoutname="") {
  64. if ($this->layout->exists) {
  65. // If a layout name is specified make sure layout set exists..
  66. if ($layoutname != "") {
  67. $this->layout->layout_name = $layoutname;
  68. $q = "SELECT * FROM ax_layout_set";
  69. $q .= " WHERE layout_name='" . addslashes($layoutname) . "'";
  70. $chkset = dbrecordset($q);
  71. if ($chkset->rowcount == 0) {
  72. $LSin = new dbinsert("ax_layout_set");
  73. $LSin->set("layout_name", $layoutname);
  74. $LSin->execute();
  75. }
  76. }
  77.  
  78. // Save replicated layout as a brand new one..
  79. $orig_layid = $this->layout->layoutid;
  80. $this->layout->layoutid = get_next_sequencevalue("seq_layout_id", "ax_layout", "layout_id");
  81. $this->layout->exists = false;
  82. $this->layout->put();
  83.  
  84. // Replicate all the blocks and adjust layout table references..
  85. $Blq = dbrecordset("SELECT block_id FROM ax_block WHERE layout_id=$orig_layid");
  86. if ($Blq->hasdata) {
  87. do {
  88. // Replicate block/blocklets into new block
  89. $blockid = $Blq->field("block_id");
  90. $b = new block($blockid);
  91. $b->layoutid = $this->layout->layoutid;
  92. $b->replicate();
  93. // Fix up the layout table block reference..
  94. reset($this->layout->layout_blocks);
  95. while (list($rowcol, $old_blockid) = each($this->layout->layout_blocks)) {
  96. if ($old_blockid == $blockid) {
  97. $bits = explode("|", $rowcol);
  98. $row = $bits[0];
  99. $col = $bits[1];
  100. $cell = $this->layout->layout_table->get_cell($row, $col);
  101. $cell->blockid = $b->blockid;
  102. $this->layout->layout_table->set_cell($row, $col, $cell);
  103. $this->layout->layout_blocks["$row|$col"] = $b->blockid;
  104. }
  105. }
  106. } while ($Blq->get_next());
  107. }
  108.  
  109. // Replicate all metadata..
  110. $Mlq = dbrecordset("SELECT * FROM ax_layout_metadata WHERE layout_id=$orig_layid");
  111. if ($Mlq->hasdata) {
  112. do {
  113. $Mins = new dbinsert("ax_layout_metadata");
  114. $Mins->set("layout_id", $this->layout->layoutid);
  115. $Mins->set("element_id", $Mlq->field("element_id"));
  116. $Mins->set("schema_name", $Mlq->field("schema_name"));
  117. if ($Mlq->field("enc_scheme_id" != "")) {
  118. $Mins->set("enc_scheme_id", $Mlq->field("enc_scheme_id"));
  119. }
  120. $Mins->set("metadata_value", $Mlq->field("metadata_value"));
  121. $Mins->set("linked_uri", $Mlq->field("linked_uri"));
  122. $Mins->set("language", $Mlq->field("language"));
  123. } while ($Mlq->get_next());
  124. }
  125.  
  126. // Update changes to layout table..
  127. $this->layout->put();
  128. }
  129. } // replicate
  130. // ....................................................................
  131. /**
  132. * Delete the hosted layout from the database. Afterwards, the current object
  133. * still exists as it was before this method was executed, but the
  134. * $this->layout->exists flag will have been reset to false.
  135. */
  136. function delete() {
  137. if ($this->layout->exists) {
  138. $external_transaction = transaction_open();
  139. if (!$external_transaction) {
  140. start_transaction();
  141. }
  142. // Remove blocks first..
  143. $lcq = new dbselect("ax_block");
  144. $lcq->fieldlist("block_id");
  145. $lcq->where("layout_id=" . $this->layout->layoutid);
  146. $lcq->execute();
  147. if ($lcq->hasdata) {
  148. do {
  149. $blockid = $lcq->field("block_id");
  150. $b = new block($blockid);
  151. $b->delete();
  152. } while ($lcq->get_next());
  153. }
  154. // Remove any layout set reference, but only if it
  155. // refers to the hosted layout alone. If versions exist then
  156. // it will refer to all versions, so don't remove..
  157. $q = "SELECT l.layout_id";
  158. $q .= " FROM ax_layout_set ls, ax_layout l";
  159. $q .= " WHERE ls.layout_name='" . $this->layout->layout_name . "'";
  160. $q .= " AND l.layout_name=ls.layout_name";
  161. $q .= " AND l.layout_id <> " . $this->layout->layoutid;
  162. $chk = dbrecordset($q);
  163. if ($chk->rowcount == 0) {
  164. $ldel = new dbdelete("ax_layout_set");
  165. $ldel->where("layout_name='" . $this->layout->layout_name . "'");
  166. $ldel->execute();
  167. }
  168. $ldel = new dbdelete("ax_layout");
  169. $ldel->where("layout_id=" . $this->layout->layoutid);
  170. $ldel->execute();
  171. if (!$external_transaction) {
  172. commit();
  173. }
  174. $this->layout->exists = false;
  175. }
  176. } // delete
  177. // ....................................................................
  178. /**
  179. * Render the layout editing suite.
  180. * @return string The HTML for the editing suite form etc.
  181. * @access private
  182. */
  183. function editform() {
  184. debug_trace($this);
  185. global $LIBDIR;
  186. global $RESPONSE;
  187. global $perm_groups, $perm_perms;
  188.  
  189. $pwidth = "150px";
  190.  
  191. // Layout table copy we will use..
  192. $Tlay = $this->layout->layout_table;
  193. $Tlay->setstyle("border-width:1px;border-style:dotted;border-color:#0000ff;padding:10px;");
  194. $Tlay->setborder(1);
  195.  
  196. // Make an Axyl colour combobox..
  197. $ss = new stylesheet($RESPONSE->site_docroot . $RESPONSE->head->stylesheet);
  198. $colourCombo = new form_combofield("colours");
  199. $colourCombo->setclass("axcombo");
  200. $colourCombo->setstyle("width:$pwidth;");
  201. $colourCombo->additem("", "default colour");
  202. $TotColours = defaulted($ss->style("axylpalette", "total_colours"), 0);
  203. if ($TotColours > 0) {
  204. for ($c = 1; $c <= $TotColours; $c++) {
  205. $colour_style = $ss->style("axylpalette", "colour_$c");
  206. $colour_bits = explode(",", $colour_style);
  207. if (isset($colour_bits[0]) && isset($colour_bits[1])) {
  208. $colourCombo->additem($colour_bits[0], $colour_bits[1]);
  209. }
  210. }
  211. }
  212. // Initialise content..
  213. $s = "";
  214.  
  215. // Buttons..
  216. $bnew = new form_imagebutton("_new", "", "", "$LIBDIR/img/_new.gif", "New layout", 42, 15);
  217. $bdone = new form_imagebutton("_done", "", "", "$LIBDIR/img/_done.gif", "Done", 57, 15);
  218. $bsave = new form_imagebutton("_save", "", "", "$LIBDIR/img/_save.gif", "Save layout", 57, 15);
  219. $bpublish = new form_imagebutton("_publish", "", "", "$LIBDIR/img/_publish.gif", "Publish", 57, 15);
  220. $brevert = new form_imagebutton("_revert", "", "", "$LIBDIR/img/_revert.gif", "Revert", 57, 15);
  221. $bsplit = new form_imagebutton("_split", "", "", "$LIBDIR/img/_split.gif", "Split", 15, 15);
  222. $bmgrow = new form_imagebutton("_mergerow", "", "", "$LIBDIR/img/_arrowD.gif", "Merge rows", 11, 11);
  223. $bmgcol = new form_imagebutton("_mergecol", "", "", "$LIBDIR/img/_arrowR.gif", "Merge columns", 11, 11);
  224. $bmgall = new form_imagebutton("_mergeall", "", "", "$LIBDIR/img/_arrowRR.gif", "Merge all cols", 11, 11);
  225. $bdelete = new form_imagebutton("_delete", "", "", "$LIBDIR/img/_delete.gif", "Delete block", 57, 15);
  226. $binsrow = new form_imagebutton("_insrow", "", "", "$LIBDIR/img/_chevR.gif", "Insert row", 13, 9);
  227. $binscol = new form_imagebutton("_inscol", "", "", "$LIBDIR/img/_chevD.gif", "Insert column", 9, 13);
  228. $bredx = new form_imagebutton("_redx", "", "", "$LIBDIR/img/_redx.gif", "Delete", 9, 9);
  229.  
  230. // Confirmation stuff
  231. $bdelete->set_confirm_text("Delete this block?");
  232. $bnew->set_confirm_text("This will DELETE the whole layout. Are you sure?");
  233. $bpublish->set_confirm_text("This will make this pending layout LIVE. Are you sure?");
  234. $brevert->set_confirm_text("This will revert to the previous Live layout. Current pending layout will be lost. Are you sure?");
  235.  
  236. // Version access combo
  237. $versionCombo = new form_combofield("version_id");
  238. $versionCombo->setclass("axcombo");
  239.  
  240. // Hidden fields..
  241. $layfm = new form_hiddenfield("edit_layoutform", $this->layout->layoutfm);
  242. $mode = new form_hiddenfield("layoutmode", $this->layout->mode);
  243. $elid = new form_hiddenfield("edit_layoutid", $this->layout->layoutid);
  244. $lver = new form_hiddenfield("layout_version", $this->layout->version);
  245. $merge = new form_hiddenfield("layout_action");
  246.  
  247. // Control table..
  248. $Ted = new table($this->layout->layoutfm);
  249.  
  250. // ..................................................................
  251. // TOOLBAR
  252. $toolbar = array();
  253.  
  254. // TOOLBAR: DONE button
  255. $toolbar[] = $bdone;
  256.  
  257. // TOOLBAR: PUBLISH or REVERT buttons
  258. if ($RESPONSE->ismemberof_group_in("Editor")) {
  259. switch ($this->layout->version) {
  260. case VERSION_PENDING:
  261. $toolbar[] = $bpublish;
  262. break;
  263. case VERSION_LIVE:
  264. $toolbar[] = $brevert;
  265. break;
  266. } // switch
  267. }
  268.  
  269. // TOOLBAR: NEW button
  270. if ($this->layout->user_can_edit()) {
  271. $toolbar[] = $bnew;
  272. }
  273.  
  274. // TOOLBAR: SAVE button
  275. if ($this->layout->user_can_edit()) {
  276. $toolbar[] = $bsave;
  277. }
  278.  
  279. // TOOLBAR: HEADING LABEL
  280. switch ($this->layout->version) {
  281. case VERSION_PENDING: $hdg = "PENDING"; break;
  282. case VERSION_LIVE: $hdg = "LIVE"; break;
  283. case VERSION_PREVIOUS: $hdg = "PREVIOUS"; break;
  284. case VERSION_UNDEFINED: $hdg = "EDITING"; break;
  285. default: $hdg = "VERSION " . $this->layout->version;
  286. } // switch
  287.  
  288. // TOOLBAR: Table
  289. $Tbar = new table("toolbar");
  290. //$Tbar->setwidth(500);
  291. $Tbar->tr("axtitle");
  292. $Tbar->th("<b>$verhdg</b> [" . $this->layout->layout_name . "]", "axtitle");
  293. $tools = "";
  294. foreach ($toolbar as $tool) {
  295. $tools .= $tool->render();
  296. }
  297. $Tbar->th($tools, "axtitle");
  298. $Tbar->th_css("text-align:right");
  299. $Ted->thead();
  300. $Ted->tr("axtitle");
  301. $Ted->td( $Tbar->render(), "axtitle" );
  302. $Ted->td_alignment("", "top");
  303.  
  304. // ..................................................................
  305. $Ted->tr("axhdg");
  306. $Ted->td("<b>LAYOUT SETTINGS</b>", "axhdg");
  307. $Ted->td_css("text-align:center");
  308. $Ted->td_colspan(2);
  309. // ..................................................................
  310. // Layout properties..
  311. $Trows = $Tlay->rowcount();
  312. $Tcols = $Tlay->cellcount();
  313.  
  314. $gentxt = new form_textfield();
  315. $gentxt->clearstyle();
  316. $gentxt->setclass("axtxtbox");
  317. $gentxt->setstyle("width:35px;text-align:center;");
  318.  
  319. $gentxt->setvalue($Tcols);
  320. $colsF = $gentxt->render("layout_cols");
  321.  
  322. $gentxt->setvalue($Trows);
  323. $rowsF = $gentxt->render("layout_rows");
  324.  
  325. $gentxt->setvalue($Tlay->cellpadding);
  326. $padF = $gentxt->render("layout_padding");
  327.  
  328. $colourCombo->setvalue($Tlay->bgcolor);
  329.  
  330. $showlastmod = new form_checkbox("show_last_modified");
  331. $showlastmod->checked = $this->layout->show_last_modified;
  332.  
  333. $lastmodCombo = new form_combofield("format_last_modified");
  334. $lastmodCombo->setclass("axcombo");
  335. $lastmodCombo->setstyle("width:$pwidth;");
  336. $lastmodCombo->additem(NICE_FULLDATETIME, "Mar 3rd 1999 1:30pm");
  337. $lastmodCombo->additem(NICE_DATE, "Mar 3rd 1999");
  338. $lastmodCombo->additem(DAY_AND_DATE, "Friday, 20th July 2001");
  339. $lastmodCombo->additem(DISPLAY_DATE_ONLY, "31/12/1999");
  340. $lastmodCombo->additem(DISPLAY_DATE_FORMAT, "31/12/1999 23:59");
  341. $lastmodCombo->additem(DISPLAY_TIMESTAMP_FORMAT, "31/12/1999 23:59:59");
  342. $lastmodCombo->additem(NICE_TIME_ONLY, "1:30pm");
  343. $lastmodCombo->setvalue($this->layout->format_last_modified);
  344.  
  345. $Tprop = new table("props");
  346.  
  347. // Multi-language selector, or hidden field..
  348. $Tprop->tr("axbglite");
  349. if ($RESPONSE->multilang) {
  350. $langsCombo = new form_combofield("language");
  351. $langsCombo->setclass("axcombo");
  352. $langsCombo->setstyle("width:$ewidth;");
  353. $LQ = dbrecordset("SELECT * FROM ax_language ORDER BY display_order");
  354. $langsCombo->add_querydata($LQ, "lang_id", "lang_desc");
  355. $Tprop->td("Layout language:", "axfg");
  356. }
  357. else {
  358. $langsCombo = new form_hiddenfield("language");
  359. $Tprop->td("&nbsp;");
  360. }
  361. $langsCombo->setvalue($this->layout->language);
  362. $Tprop->td( $langsCombo->render() );
  363. $Tprop->td_colspan(3);
  364.  
  365. $Tprop->setpadding(2);
  366. $Tprop->setstyle("padding-left:5px;padding-right:5px;");
  367. $Tprop->tr("axbgdark");
  368. $Tprop->td("Cols x Rows:", "axfg");
  369. $Tprop->td( $colsF . "&nbsp;x&nbsp;" . $rowsF );
  370.  
  371. $Tprop->td("Padding:", "axfg");
  372. $Tprop->td_alignment("right");
  373. $Tprop->td( $padF );
  374. $Tprop->td_alignment("right");
  375.  
  376. $Tprop->tr("axbglite");
  377. $Tprop->td("Background colour:", "axfg");
  378. $Tprop->td($colourCombo->render("background_colour"));
  379. $Tprop->td();
  380. $Tprop->td_colspan(2);
  381.  
  382. $Tprop->tr("axbgdark");
  383. $Tprop->td("Show last modified:", "axfg");
  384. $Tprop->td($showlastmod->render());
  385. $Tprop->td_colspan(3);
  386.  
  387. $Tprop->tr("axbglite");
  388. $Tprop->td("Last mod. format:", "axfg");
  389. $Tprop->td($lastmodCombo->render());
  390. $Tprop->td_colspan(3);
  391.  
  392. $gentxt->setvalue($this->layout->prefix_last_modified);
  393. $gentxt->clearstyle();
  394. $gentxt->setstyle("width:$pwidth");
  395. $Tprop->tr("axbgdark");
  396. $Tprop->td("Last mod. prefix:", "axfg");
  397. $Tprop->td($gentxt->render("prefix_last_modified"));
  398. $Tprop->td_colspan(3);
  399.  
  400. $gentxt->setvalue($this->layout->index_category);
  401. $gentxt->clearstyle();
  402. $gentxt->setstyle("width:$pwidth");
  403. $Tprop->tr("axbglite");
  404. $Tprop->td("Index category:", "axfg");
  405. $Tprop->td($gentxt->render("index_category"));
  406. $Tprop->td_colspan(3);
  407.  
  408. $gentxt->setvalue($this->layout->layout_style);
  409. $gentxt->clearstyle();
  410. $gentxt->setstyle("width:$pwidth");
  411. $Tprop->tr("axbgdark");
  412. $Tprop->td("CSS style:", "axfg");
  413. $Tprop->td($gentxt->render("layout_style"));
  414. $Tprop->td_colspan(3);
  415.  
  416. $gentxt->setvalue($this->layout->layout_table->width);
  417. $gentxt->clearstyle();
  418. $gentxt->setstyle("width:60;text-align:right;");
  419. $Tprop->tr("axbglite");
  420. $Tprop->td("Table width:", "axfg");
  421. $Tprop->td($gentxt->render("table_width"));
  422. $Tprop->td_colspan(3);
  423.  
  424. // These properties only appear if we have plain cells..
  425. if ($this->layout->tot_plain > 0) {
  426. $tstylesCombo = new form_combofield("table_style");
  427. $tstylesCombo->setclass("axcombo");
  428. $tstylesCombo->setstyle("width:$cbowidth;");
  429. $tstylesCombo->additem("", "default style");
  430. $Totstyles = defaulted($ss->style("axyl_tablestyles", "total_styles"), 0);
  431. if ($Totstyles > 0) {
  432. for ($c = 1; $c <= $Totstyles; $c++) {
  433. $tstyle_style = $ss->style("axyl_tablestyles", "style_$c");
  434. $tstyle_bits = explode(",", $tstyle_style);
  435. if (isset($tstyle_bits[0]) && isset($tstyle_bits[1])) {
  436. $tstylesCombo->additem($tstyle_bits[0], $tstyle_bits[1]);
  437. }
  438. }
  439. }
  440. $tstylesCombo->setvalue($this->layout->layout_table->class);
  441. $Tprop->tr("axbgdark");
  442. $Tprop->td("Table style:");
  443. $Tprop->td($tstylesCombo->render());
  444. $Tprop->td_colspan(3);
  445.  
  446. $autoj = new form_checkbox("table_autojustify");
  447. $autoj->setclass("axchkbox");
  448. $autoj->checked = $this->layout->layout_table->autojustify;
  449. $Tprop->tr("axbglite");
  450. $Tprop->td("Auto-justify:");
  451. $Tprop->td($autoj->render());
  452. $Tprop->td_colspan(3);
  453.  
  454. $rowstr = new form_checkbox("table_rowstripes");
  455. $rowstr->setclass("axchkbox");
  456. $rowstr->checked = (implode(",", $this->layout->layout_table->rowstripes) != "");
  457. $Tprop->tr("axbgdark");
  458. $Tprop->td("Row striping:");
  459. $Tprop->td($rowstr->render());
  460. $Tprop->td_colspan(3);
  461. }
  462.  
  463. // Render properties
  464. $Ted->tr("axbglite");
  465. $Ted->td( $Tprop->render() );
  466. $Ted->td_alignment("", "top");
  467.  
  468. // ..................................................................
  469. // PERMISSIONS
  470. if ($this->layout->tot_plain > 0) {
  471. $groups = new form_combofield("perm_groups", "", $perm_groups);
  472. $groups->multiselect = true;
  473. $groups->setclass("axlistbox");
  474. $groups->setstyle("width:150px;");
  475. $groups->set_size(5);
  476. $gps = dbrecordset("SELECT * FROM ax_group");
  477. if ($gps->hasdata) {
  478. do {
  479. $groups->additem($gps->field("group_desc"));
  480. } while ($gps->get_next());
  481. }
  482. $perms = new form_combofield("perm_perms", "", $perm_perms);
  483. $perms->multiselect = true;
  484. $perms->setclass("axlistbox");
  485. $perms->setstyle("width:150px;");
  486. $perms->set_size(5);
  487. $perms->additem(PERM_READ, "READ");
  488. $perms->additem(PERM_UPDATE, "UPDATE");
  489. $perms->additem(PERM_CREATE, "CREATE");
  490. $perms->additem(PERM_DELETE, "DELETE");
  491. $perms->additem(PERM_NONE, "NONE");
  492.  
  493. $btnset = new form_imagebutton("_perm_set");
  494. $btnset->setimage("$LIBDIR/img/_set.gif", "Set permissions");
  495. $btnunset = new form_imagebutton("_perm_unset");
  496. $btnunset->setimage("$LIBDIR/img/_unset.gif", "Unset permissions");
  497.  
  498. $Tperm = new table("perms");
  499. $Tperm->setwidth("500");
  500. $Tperm->tr();
  501. $blurb = "To set permissions for plain cells which have been selected below, choose ";
  502. $blurb .= "one or more groups, and select one or more access methods then click ";
  503. $blurb .= "the Set button. Unset clears permissions from the selected cells.";
  504. $Tperm->td($blurb);
  505. $Tperm->td_colspan(5);
  506. $Tperm->tr();
  507. $Tperm->td( "Group(s) " );
  508. $Tperm->td_alignment("", "top");
  509. $Tperm->td( $groups->render() );
  510. $Tperm->td_alignment("center", "top");
  511. $Tperm->td( " permitted to " );
  512. $Tperm->td_alignment("center", "top");
  513. $Tperm->td( $perms->render() );
  514. $Tperm->td_alignment("center", "top");
  515. $Tperm->td( $btnset->render() . "<br>" . $btnunset->render() );
  516. $Tperm->td_alignment("right", "top");
  517.  
  518. // Render perms
  519. $Ted->tr("axbgdark");
  520. $Ted->td( $Tperm->render() );
  521. $Ted->td_alignment("", "top");
  522. }
  523.  
  524. // ..................................................................
  525. // WIDTH PROFILE
  526. if ($Tcols > 1) {
  527. $Ted->tr("axhdg");
  528. $Ted->td("<b>LAYOUT COLUMN WIDTHS PROFILE</b>", "axhdg");
  529. $Ted->td_css("text-align:center");
  530. $Ted->td_colspan(2);
  531.  
  532. $prof = $Tlay->get_width_profile();
  533. $Tprf = new table("prfcols");
  534. $Tprf->setstyle("padding:10px;");
  535. $Tprf->tr();
  536. $gentxt->setcss("");
  537. $gentxt->setclass("axtxtbox");
  538. $gentxt->setcss("width:50px;text-align:center;");
  539. foreach ($prof as $width) {
  540. $gentxt->setvalue($width);
  541. $Tprf->td( $gentxt->render("width_profile[]") );
  542. $Tprf->td_alignment("center");
  543. }
  544. $Tprop = new table("profile");
  545. $Tprop->rowstripes("axyl_rowstripe_dark,axyl_rowstripe_lite");
  546. $Tprop->tr();
  547. $Tprop->td( $Tprf->render() );
  548. // Insert it in main table..
  549. $Ted->tr("axbglite");
  550. $Ted->td( $Tprop->render() );
  551. $Ted->td_alignment("", "top");
  552. }
  553.  
  554. // ..................................................................
  555. $Ted->tr("axhdg");
  556. $Ted->td("<b>LAYOUT PLANNER</b>", "axhdg");
  557. $Ted->td_css("text-align:center");
  558. $Ted->td_colspan(2);
  559.  
  560. // ..................................................................
  561. // BULK SETTING for CELL DEFINITION
  562. if ($this->layout->tot_empty > 0) {
  563. $bulkbtn = new form_imagebutton("_bulk_set");
  564. $bulkbtn->setimage("$LIBDIR/img/_set.gif", "Set all cells");
  565. $bulkbtn->set_onclick("bulk_set()");
  566. $bulkset = new form_combofield("layout_bulksetting");
  567. $bulkset->setclass("axcombo");
  568. $bulkset->setstyle("width:70px;");
  569. $bulkset->additem(EMPTY_CELL);
  570. $bulkset->additem(BLOCK_CONTENT, "Block");
  571. $bulkset->additem(WYSIWYG_EDITOR, "Wysiwyg");
  572. $bulkset->additem(PLAIN_CELL, "Cell");
  573. // Add the script it needs..
  574. $RESPONSE->body->add_script(
  575. "function bulk_set() {\n"
  576. . " var i,j;\n"
  577. . " ix=document.forms." . $this->layout->layoutfm . ".layout_bulksetting.selectedIndex;\n"
  578. . " if (ix != -1) {\n"
  579. . " var bulkval=document.forms." . $this->layout->layoutfm . ".layout_bulksetting[ix].value;\n"
  580. . " for (i=0; i < document." . $this->layout->layoutfm . ".length; i++) {\n"
  581. . " var e=document." . $this->layout->layoutfm . ".elements[i];\n"
  582. . " if (e.name == 'layout_newcell[]') {\n"
  583. . " for (j=0; j < e.length; j++) {\n"
  584. . " curval = e[j].value.substr(0,1);\n"
  585. . " if (curval == bulkval) {\n"
  586. . " e.selectedIndex = j;\n"
  587. . " break;\n"
  588. . " }\n"
  589. . " }\n"
  590. . " }\n"
  591. . " }\n"
  592. . " }\n"
  593. . "}\n"
  594. );
  595. // Insert it in main table..
  596. $Ted->tr("axbgdark");
  597. $Ted->td( "Set all to&nbsp;" . $bulkset->render() . "&nbsp;" . $bulkbtn->render() );
  598. $Ted->td_alignment("", "top");
  599. }
  600.  
  601. // Double-clicking left-most checkboxes..
  602. if ($this->layout->tot_plain > 0) {
  603. $RESPONSE->body->add_script(
  604. "function chkrow(fld) {\n"
  605. . " var newchk = !fld.checked;\n"
  606. . " var v = fld.value.split('|');\n"
  607. . " var row = v[0];\n"
  608. . " for (var i=0; i < document." . $this->layout->layoutfm . ".length; i++) {\n"
  609. . " var e=document." . $this->layout->layoutfm . ".elements[i];\n"
  610. . " if (e.name == 'layout_cellsel[]') {\n"
  611. . " v = e.value.split('|');\n"
  612. . " r = v[0];\n"
  613. . " if (r == row) {\n"
  614. . " e.checked = newchk;\n"
  615. . " }\n"
  616. . " }\n"
  617. . " }\n"
  618. . "}\n"
  619. );
  620. }
  621.  
  622. // ..................................................................
  623. // The Layout Table..
  624.  
  625. // This submits a generic layout request..
  626. $RESPONSE->body->add_script(
  627. "function layoutAction(val) {\n"
  628. . " document.forms." . $this->layout->layoutfm . ".layout_action.value=val;\n"
  629. . " document.forms." . $this->layout->layoutfm . ".submit();\n"
  630. . "}\n"
  631. );
  632.  
  633. // Controls table..
  634. $Tti = new table("controls");
  635. $Tti->setstyle("vertical-align:top");
  636. $Tti->tbody("font-size:8pt;vertical-align:top;background:white;");
  637. // Row & col insert buttons
  638. $Tti->tr();
  639. $Tti->td("tt_00");
  640. $Tti->td_height(22);
  641. //$Tti->td_alignment("", "top");
  642. $Tti->td("tt_01");
  643. $Tti->td("tt_02");
  644. $Tti->td_alignment("right");
  645. // Merge buttons etc.
  646. $Tti->tr();
  647. $Tti->td("tt_10");
  648. $Tti->td("tt_11");
  649. $Tti->td_alignment("center");
  650. $Tti->td("tt_12");
  651. $Tti->td_alignment("right");
  652. // Permissions
  653. $Tti->tr();
  654. $Tti->td("tt_20");
  655. $Tti->td_colspan(3);
  656. $Tti->td_alignment("tt_20_align");
  657. $Tti->close_group();
  658. $Tti->set_width_profile("15%,70%,15%");
  659. $Ttis = $Tti->render();
  660.  
  661. // Combo for each cell..
  662. $ccre = new form_combofield("layout_newcell[]");
  663. $ccre->setclass("axcombo");
  664. $ccre->setstyle("width:70px;");
  665.  
  666. // Checkbox for each cell..
  667. $cchk = new form_checkbox("layout_cellsel[]");
  668. $cchk->setclass("axchkbox");
  669.  
  670. // Populate our layout table with blocks..
  671. for ($r = 0; $r < $this->layout->tot_rows; $r++) {
  672. for ($c = 0; $c < $this->layout->tot_cols; $c++) {
  673. if ($Tlay->cell_exists($r, $c)) {
  674.  
  675. // Get existing cell for population with controls etc..
  676. $cell = $Tlay->get_cell($r, $c);
  677.  
  678. // If no block yet, offer the create checkbox and the
  679. // various merge/split controls..
  680. $rowmerge_controls = "";
  681. $colmerge_controls = "";
  682. $other_controls = "";
  683. $Tt = $Ttis;
  684. $Tt_cells = array();
  685. for ($ttr=0; $ttr < 3; $ttr++) {
  686. for ($ttc=0; $ttc < 3; $ttc++) {
  687. $ttid = "tt_" . $ttr . $ttc;
  688. $Tt_cells[$ttid] = "";
  689. }
  690. }
  691.  
  692. // Add row & column modifying buttons..
  693. if ($c == 0) {
  694. $binsrow->set_onclick("layoutAction('insrow|$r|$c')");
  695. $btns = $binsrow->render();
  696. if ($this->layout->tot_rows > 1) {
  697. $bredx->set_onclick("layoutAction('delrow|$r|$c')");
  698. $bredx->settitle("Delete row");
  699. $btns .= "<br>" . $bredx->render();
  700. }
  701. $Tt_cells["tt_00"] = $btns;
  702. }
  703. if ($r == 0) {
  704. $binscol->set_onclick("layoutAction('inscol|$r|$c')");
  705. $btns = $binscol->render();
  706. if ($this->layout->tot_cols > 1) {
  707. $bredx->set_onclick("layoutAction('delcol|$r|$c')");
  708. $bredx->settitle("Delete column");
  709. $btns .= "<br>" . $bredx->render();
  710. }
  711. $Tt_cells["tt_02"] = $btns;
  712. }
  713.  
  714. // If not defined, then offer defining controls..
  715. if (!isset($this->layout->layout_blocks["$r|$c"])) {
  716.  
  717. // Cell creation checkbox..
  718. $ccre->clearitems();
  719. $ccre->additem(EMPTY_CELL);
  720. $ccre->additem(BLOCK_CONTENT . "|$r|$c", "Block");
  721. $ccre->additem(WYSIWYG_EDITOR . "|$r|$c", "Wysiwyg");
  722. $ccre->additem(PLAIN_CELL . "|$r|$c", "Plain");
  723. $other_controls .= $ccre->render();
  724.  
  725. // Row merge controls
  726. if ($cell->colspan == 1 && $r < ($Tlay->visible_cellsincol($c) - 1)) {
  727. $ok = true;
  728. if ($Tlay->cell_exists($r + 1, $c)) {
  729. $nextcell = $Tlay->get_cell($r + 1, $c);
  730. if ($nextcell->rowspan > 1) $ok = false;
  731. }
  732. if ($ok) {
  733. $bmgrow->set_onclick("layoutAction('merge|row|$r|$c')");
  734. $rowmerge_controls .= $bmgrow->render();
  735. }
  736. }
  737. if ($cell->rowspan > 1) {
  738. $bsplit->set_onclick("layoutAction('split|row|$r|$c')");
  739. $rowmerge_controls .= $bsplit->render();
  740. }
  741. if ($rowmerge_controls == "") $rowmerge_controls = "&nbsp;";
  742. $Tt_cells["tt_10"] = $rowmerge_controls;
  743.  
  744. // Column merge controls
  745. if ($cell->rowspan == 1 && $c < ($Tlay->visible_cellsinrow($r) - 1)) {
  746. $ok = true;
  747. if ($Tlay->cell_exists($r, $c + 1)) {
  748. $nextcell = $Tlay->get_cell($r, $c + 1);
  749. if ($nextcell->rowspan > 1) $ok = false;
  750. }
  751. if ($ok) {
  752. $bmgcol->set_onclick("layoutAction('merge|col|$r|$c')");
  753. $colmerge_controls .= $bmgcol->render();
  754. }
  755. }
  756. if ($cell->colspan > 1) {
  757. $bsplit->set_onclick("layoutAction('split|col|$r|$c')");
  758. $colmerge_controls .= $bsplit->render();
  759. }
  760. if ($colmerge_controls == "") $colmerge_controls = "&nbsp;";
  761. $Tt_cells["tt_12"] = $colmerge_controls;
  762.  
  763. // Bulk column merge control..
  764. if ($c == 0) {
  765. $row = $this->layout->layout_table->get_row($r);
  766. if ($row && !$row->has_colspans()) {
  767. $bmgall->set_onclick("layoutAction('merge|allcols|$r|$c')");
  768. $Tt_cells["tt_20"] = $bmgall->render();
  769. $Tt = str_replace("tt_20_align", "right", $Tt);
  770. }
  771. }
  772. }
  773. else {
  774. // Cell is occupied, so we offer the delete option..
  775. $blockid = $this->layout->layout_blocks["$r|$c"];
  776. if ($this->layout->user_can_edit()) {
  777. if ($blockid != 0) {
  778. // Content managed cell..
  779. $bdelete->set_onclick("layoutAction('deletecell|$r|$c')");
  780. $other_controls .= ($cell->celltype == "w") ? "{wysiwyg}" : "{block}";
  781. $other_controls .= "<br>" . $bdelete->render();
  782. }
  783. else {
  784. // Plain cell..
  785. $bdelete->set_onclick("layoutAction('deletecell|$r|$c')");
  786. $other_controls .= "{plain}<br>" . $bdelete->render();
  787. }
  788. }
  789. }
  790.  
  791. // Insert permissions controls & info..
  792. if (isset($cell->access)) {
  793. $cchk->setvalue("$r|$c");
  794. if ($c == 0) {
  795. $cchk->set_ondblclick("chkrow(this,'" . $this->layout->layoutfm . "')");
  796. }
  797. $other_controls .= "<br>" . $cchk->render();
  798. $Tt_cells["tt_20"] = $cell->access->dump();
  799. $Tt = str_replace("tt_20_align", "center", $Tt);
  800. }
  801.  
  802. // Insert the miscellaneous controls..
  803. $Tt_cells["tt_11"] = $other_controls;
  804.  
  805. // Plug in the cell content..
  806. foreach ($Tt_cells as $cellid => $cellcontent) {
  807. $Tt = str_replace($cellid, $cellcontent, $Tt);
  808. }
  809. $cell->setcontent( $Tt );
  810. $cell->setcontentcss( "vertical-align:top" );
  811. $Tlay->set_cell($r, $c, $cell);
  812. }
  813. }
  814. }
  815. $Ted->tr();
  816. $Ted->td( $Tlay->render() );
  817. $Ted->td_alignment("", "top");
  818.  
  819. if ($this->layout->show_last_modified && $this->layout->last_modified != "") {
  820. $Ted->tr();
  821. $Ted->td($this->layout->last_modified, "axyl_lastmod");
  822. }
  823.  
  824. $Ted->tr("axfoot");
  825. $Ted->td("", "axfoot");
  826.  
  827. // ..................................................................
  828. // Finish off..
  829. $s .= "<form name=\"" . $this->layout->layoutfm . "\" method=\"post\">\n";
  830. $s .= $Ted->render()
  831. . $layfm->render()
  832. . $mode->render()
  833. . $elid->render()
  834. . $merge->render()
  835. . $lver->render();
  836. $s .= "</form>\n";
  837.  
  838. debug_trace();
  839. // Return the html..
  840. return $s;
  841. } // editform
  842.  
  843. } // layouteditor class
  844. // ----------------------------------------------------------------------
  845.  
  846. ?>

Documentation generated by phpDocumentor 1.3.0RC3