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

Documentation generated by phpDocumentor 1.3.0RC3