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

Documentation generated by phpDocumentor 1.3.0RC3