Source for file microsite-defs.php

Documentation is available at microsite-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: microsite-defs.php */
  22. /* Author: Paul Waite */
  23. /* Description: Definitions for managing a microsite. The microsite */
  24. /* definitions are defined and stored in the Axyl database */
  25. /* and 'published' onto disk by this interface. This is */
  26. /* therefore Add/Modify/Delete/Publish for a microsite. */
  27. /* */
  28. /* ******************************************************************** */
  29. /** @package microsite */
  30. include_once("catalog-defs.php");
  31.  
  32. // Minimum plugins slot we provide to edit page plugins
  33. define("MIN_PLUGIN_SLOTS", 7);
  34.  
  35. // ......................................................................
  36. /**
  37. * The Microsite Class
  38. * Encapsulates a microsite definition. Holds the meta-data associated
  39. * with a microsite, and allows this data to be modified via a dedicated
  40. * form/POSTprocess. Also allows the microsite to be requested for 'publishing'
  41. * to the appropriate destination for microsites, depending on webserver
  42. * requirements/configuration.
  43. * @package microsite
  44. */
  45. class microsite extends HTMLObject {
  46. // Public
  47. /** The name of the microsite */
  48.  
  49. var $microsite_name = "";
  50. /** The description of the microsite */
  51.  
  52. var $microsite_desc = "";
  53. /** The domain of the microsite */
  54.  
  55. var $microsite_domain = "";
  56. /** The ID of the microsite menu */
  57.  
  58. var $menu_id;
  59. /** The main stylesheet of the microsite */
  60.  
  61. var $css = "";
  62. /** The IE stylesheet of the microsite */
  63.  
  64. var $css_ie = "";
  65. /** The Netscape stylesheet of the microsite */
  66.  
  67. var $css_ns = "";
  68. /** Whether microsite publish is being requested */
  69.  
  70. var $req_microsite_publish = false;
  71. /** Whether microsite removal is being requested */
  72.  
  73. var $req_microsite_remove = false;
  74. /** Whether microsite is currently installed (built) */
  75.  
  76. var $currently_installed = false;
  77. /** When microsite was last installed (timestamp) */
  78.  
  79. var $last_installed_ts;
  80. /** When microsite was last modified (timestamp) */
  81.  
  82. var $last_modified_ts;
  83.  
  84. // Private
  85. /** Whether this microsite exists in database
  86. @access private */
  87. var $exists = false;
  88. /** Templates in this microsite (array)
  89. @access private */
  90. var $templates = array();
  91. /** Pages in this microsite (array)
  92. @access private */
  93. var $pages = array();
  94. /** Media items in this microsite (array)
  95. @access private */
  96. var $catalogitems = array();
  97. /** mode of operation
  98. @access private */
  99. var $mode = "";
  100. /** The name of our form
  101. @access private */
  102. var $formname = "";
  103. /** An array of error messages to report
  104. @access private */
  105. var $errmsgs = array();
  106. /** Number of plugin slots we provide to edit page plugins
  107. @access private */
  108. var $plugin_slots = MIN_PLUGIN_SLOTS;
  109. // ....................................................................
  110. /**
  111. * Constructor
  112. * Create a new microsite instance.
  113. * @param string $name The unique name/identity of the microsite.
  114. */
  115. function microsite($name="") {
  116. global $mode, $microsite_name;
  117. global $RESPONSE;
  118.  
  119. // Mode
  120. if (isset($mode)) $this->mode = $mode;
  121. else $this->mode = "editing";
  122.  
  123. // Set up microsite name..
  124. if ($name != "") {
  125. $this->microsite_name = $name;
  126. }
  127. elseif (isset($microsite_name)) {
  128. $this->microsite_name = $microsite_name;
  129. }
  130. else {
  131. // Try for the first one we can get..
  132. $ms = dbrecordset("SELECT microsite_name FROM ax_microsite ORDER BY microsite_desc,microsite_name");
  133. if ($ms->hasdata) {
  134. $this->microsite_name = $ms->field("microsite_name");
  135. }
  136. }
  137.  
  138. // Set the form name we will use..
  139. $this->formname = "fm_microsite";
  140.  
  141. // Process anything POSTed via form..
  142. $this->POSTprocess();
  143.  
  144. // Edit new, or get the existing microsite..
  145. if ($this->mode != "adding") {
  146. $this->get();
  147. }
  148.  
  149. } // microsite
  150. // ....................................................................
  151. /**
  152. * Get the microsite
  153. * Retrieves the specified microsite from database. If it doesn't exist
  154. * then we create a new one.
  155. * @return boolean True if the record was acquired successfully
  156. */
  157. function get($name="") {
  158. debug_trace($this);
  159. $this->exists = false;
  160. if ($name != "") {
  161. $this->microsite_name = $name;
  162. }
  163. if ($this->microsite_name != "") {
  164. $q = "SELECT * FROM ax_microsite";
  165. $q .= " WHERE microsite_name='" . addslashes($this->microsite_name) . "'";
  166. $mQ = dbrecordset($q);
  167. if ($mQ->hasdata) {
  168. $this->exists = true;
  169. $this->microsite_name = $mQ->field("microsite_name");
  170. $this->microsite_desc = $mQ->field("microsite_desc");
  171. $this->microsite_domain = $mQ->field("microsite_domain");
  172. $this->css = $mQ->field("css");
  173. $this->css_ie = $mQ->field("css_ie");
  174. $this->css_ns = $mQ->field("css_ns");
  175. $this->req_microsite_publish = $mQ->istrue("req_microsite_publish");
  176. $this->req_microsite_remove = $mQ->istrue("req_microsite_remove");
  177. $this->currently_installed = $mQ->istrue("currently_installed");
  178. $this->last_installed_ts = datetime_to_timestamp($mQ->field("last_installed"));
  179. $this->last_modified_ts = datetime_to_timestamp($mQ->field("last_modified"));
  180. if ($mQ->field("menu_id") != "") {
  181. $this->menu_id = $mQ->field("menu_id");
  182. }
  183. // Get microsite pages
  184. $q = "SELECT *";
  185. $q .= " FROM ax_microsite_page";
  186. $q .= " WHERE microsite_name='" . addslashes($this->microsite_name) . "'";
  187. $q .= " ORDER BY display_order";
  188. $mpQ = dbrecordset($q);
  189. if ($mpQ->hasdata) {
  190. do {
  191. $pgid = $mpQ->field("microsite_page_id");
  192. $page = new microsite_page(
  193. $pgid,
  194. $this->microsite_name,
  195. $mpQ->field("page_title"),
  196. $mpQ->field("cache_seconds"),
  197. $mpQ->istrue("corepage"),
  198. $mpQ->istrue("microsite_homepage"),
  199. $mpQ->istrue("enabled"),
  200. $mpQ->field("menuoption_label"),
  201. $mpQ->field("menuoption_id"),
  202. $mpQ->field("display_order"),
  203. $mpQ->field("microsite_template_id"),
  204. $mpQ->field("page_id")
  205. );
  206. // Retrieve associated info..
  207. $page->get_info();
  208. $this->pages[$pgid] = $page;
  209. } while ($mpQ->get_next());
  210. }
  211.  
  212. // Get templates
  213. $q = "SELECT *";
  214. $q .= " FROM ax_microsite_template";
  215. $q .= " WHERE microsite_name='" . addslashes($this->microsite_name) . "'";
  216. $mtQ = dbrecordset($q);
  217. if ($mtQ->hasdata) {
  218. do {
  219. $mtid = $mtQ->field("microsite_template_id");
  220. $template = new microsite_template(
  221. $mtid,
  222. $mtQ->field("microsite_name"),
  223. $mtQ->field("template_name"),
  224. $mtQ->field("template_type"),
  225. $mtQ->field("template_content")
  226. );
  227. $this->templates[$mtid] = $template;
  228. } while ($mtQ->get_next());
  229. }
  230.  
  231. // Get microsite media
  232. $q = "SELECT m.* FROM ax_microsite_media m, ax_catalog c";
  233. $q .= " WHERE m.microsite_name='" . addslashes($this->microsite_name) . "'";
  234. $q .= " AND c.cat_id=m.cat_id";
  235. $q .= " ORDER BY c.mime_category,c.upload_timestamp DESC";
  236. $mmQ = dbrecordset($q);
  237. if ($mmQ->hasdata) {
  238. do {
  239. $cat_id = $mmQ->field("cat_id");
  240. $catitem = new catalogitem($cat_id);
  241. if ($catitem->valid) {
  242. $this->catalogitems[$cat_id] = $catitem;
  243. }
  244. } while ($mmQ->get_next());
  245. }
  246. }
  247. }
  248. debug_trace();
  249. // Return true if at least the microsite exists..
  250. return $this->exists;
  251. } // get
  252. // ....................................................................
  253. /**
  254. * Save this microsite to the database. Create a new one if it doesn't
  255. * already exist.
  256. */
  257. function save() {
  258. debug_trace($this);
  259. // Deal with brand new microsite..
  260. if ($this->exists) {
  261. $mQ = new dbupdate("ax_microsite");
  262. $mQ->where("microsite_name='" . addslashes($this->microsite_name) . "'");
  263. }
  264. else {
  265. $mQ = new dbinsert("ax_microsite");
  266. $mQ->set("microsite_name", $this->microsite_name);
  267. }
  268. $mQ->set("microsite_desc", $this->microsite_desc);
  269. $mQ->set("microsite_domain", $this->microsite_domain);
  270. $mQ->set("css", $this->css);
  271. $mQ->set("css_ie", $this->css_ie);
  272. $mQ->set("css_ns", $this->css_ns);
  273. $mQ->set("req_microsite_publish", $this->req_microsite_publish);
  274. $mQ->set("req_microsite_remove", $this->req_microsite_remove);
  275. $mQ->set("currently_installed", $this->currently_installed);
  276. if (isset($this->menu_id) && $this->menu_id != "") {
  277. $mQ->set("menu_id", $this->menu_id);
  278. }
  279. else {
  280. $mQ->set("menu_id", NULLVALUE);
  281. }
  282. $mQ->set("last_modified", 'now()');
  283. $this->exists = $mQ->execute();
  284.  
  285. // Save microsite pages & any attached templates..
  286. foreach ($this->pages as $pgid => $page) {
  287. $page->save();
  288. }
  289.  
  290. // Save media..
  291. $delm = new dbdelete("ax_microsite_media");
  292. $delm->where("microsite_name='" . addslashes($this->microsite_name) . "'");
  293. $delm->execute();
  294. foreach ($this->catalogitems as $cat_id => $catitem) {
  295. $inm = new dbinsert("ax_microsite_media");
  296. $inm->set("microsite_name", $this->microsite_name);
  297. $inm->set("cat_id", $cat_id);
  298. $inm->execute();
  299. }
  300.  
  301. debug_trace();
  302. } // save
  303. // ....................................................................
  304. /**
  305. * Initialise this object to default values. Eg. this is done after a
  306. * delete, so we don't see the deleted object data.
  307. */
  308. function initialise() {
  309. $this->exists = false;
  310. $this->microsite_name = "";
  311. $this->microsite_desc = "";
  312. $this->microsite_domain = "";
  313. if (isset($this->menu_id)) unset($this->menu_id);
  314. $this->css = "";
  315. $this->css_ie = "";
  316. $this->css_ns = "";
  317. $this->req_microsite_publish = false;
  318. $this->req_microsite_remove = false;
  319. $this->currently_installed = false;
  320. if (isset($this->last_installed_ts)) unset($this->last_installed_ts);
  321. if (isset($this->last_modified_ts)) unset($this->last_modified_ts);
  322. $this->templates = array();
  323. $this->pages = array();
  324. $this->catalogitems = array();
  325. $this->errmsgs = array();
  326. $this->plugin_slots = MIN_PLUGIN_SLOTS;
  327. } // initialise
  328. // ....................................................................
  329. /**
  330. * Delete this microsite from the database. We do not rely on RI to
  331. * delete all of the associated records, since the database in use
  332. * might not support it.
  333. */
  334. function delete() {
  335. debug_trace($this);
  336. if ($this->exists) {
  337. start_transaction();
  338.  
  339. // Delete all stories associated with this microsite..
  340. include_once("story-defs.php");
  341. $q = "SELECT * FROM ax_microsite_story";
  342. $q .= " WHERE microsite_name='" . addslashes($this->microsite_name) . "'";
  343. $storyQ = dbrecordset($q);
  344. if ($storyQ->hasdata) {
  345. do {
  346. $sid = $storyQ->field("story_id");
  347. $story = new story($sid);
  348. if ($story->valid) {
  349. // Flag as deleted & unindex Lucene
  350. $story->delete_story();
  351. // Delete story record completely now..
  352. $stdel = new dbdelete("ax_story");
  353. $stdel->where("story_id", $sid);
  354. $stdel->execute();
  355. }
  356. } while($storyQ->get_next());
  357. }
  358.  
  359. // Delete all pages. This deletes page-menuoption, page-template,
  360. // and the microsite page record itself..
  361. if (count($this->pages) > 0) {
  362. foreach ($this->pages as $pgid => $page) {
  363. $page->delete();
  364. }
  365. }
  366.  
  367. // Delete associated menuoptions and menu..
  368. if (isset($this->menu_id)) {
  369. $del = new dbdelete("ax_menuoption");
  370. $del->where("menu_id=$this->menu_id");
  371. $del->execute();
  372.  
  373. $del = new dbdelete("ax_menu");
  374. $del->where("menu_id=$this->menu_id");
  375. $del->execute();
  376. }
  377.  
  378. // Delete all associated templates..
  379. if (count($this->templates) > 0) {
  380. $del = new dbdelete("ax_microsite_template");
  381. $del->where("microsite_name='" . addslashes($this->microsite_name) . "'");
  382. $del->execute();
  383. }
  384.  
  385. // Delete all associated microsite media..
  386. if (count($this->catalogitems) > 0) {
  387. // Remove the ones uploaded for this site from catalog..
  388. foreach ($this->catalogitems as $catitem) {
  389. if ($catitem->category == $this->microsite_name) {
  390. $catitem->delete();
  391. }
  392. }
  393. // Remove all microsite link records..
  394. $del = new dbdelete("ax_microsite_media");
  395. $del->where("microsite_name='" . addslashes($this->microsite_name) . "'");
  396. $del->execute();
  397. }
  398.  
  399. // Finally, delete the site record iteself..
  400. $del = new dbdelete("ax_microsite");
  401. $del->where("microsite_name='" . addslashes($this->microsite_name) . "'");
  402. $del->execute();
  403.  
  404. // Final act..
  405. commit();
  406.  
  407. // Remove physical file structures..
  408. $this->unpublish();
  409.  
  410. // Initialise local variables..
  411. $this->initialise();
  412. }
  413. debug_trace();
  414. } // delete
  415. // ....................................................................
  416. /**
  417. * Remove publishing for this microsite. We just set a database flag
  418. * so that the cron script will do the work. Note that this doesn't
  419. * remove the actual definition of the microsite - just the bits and
  420. * pieces (files) which are the physical instance of it, and which
  421. * make it viewable to the internet.
  422. */
  423. function remove_request() {
  424. $requp = new dbupdate("ax_microsite");
  425. $requp->set("req_microsite_publish", false);
  426. $requp->set("req_microsite_remove", true);
  427. $requp->where("microsite_name='" . addslashes($this->microsite_name) . "'");
  428. $requp->execute();
  429. } // remove_request
  430. // ....................................................................
  431. /**
  432. * Request publishing for this microsite. We just set a database flag
  433. * so that the cron script will do the work.
  434. */
  435. function publish_request() {
  436. $requp = new dbupdate("ax_microsite");
  437. $requp->set("req_microsite_publish", true);
  438. $requp->set("req_microsite_remove", false);
  439. $requp->where("microsite_name='" . addslashes($this->microsite_name) . "'");
  440. $requp->execute();
  441. } // publish_request
  442. // ....................................................................
  443. /**
  444. * Publish this microsite. We build the dir structures which actually
  445. * create this as an Axyl theme-website under the ./var directory, which
  446. * is writeable to the webserver. If the microsite has been published
  447. * already, then a symlink to our microsite will exist in the ./templates
  448. * directory. If not, then we request it to be done by a cron-driven
  449. * command-line Php script which has the required permissions.
  450. */
  451. function publish() {
  452. global $RESPONSE, $TEMPLATESDIR, $CMDIR;
  453.  
  454. // Document root for whole site..
  455. $DOCROOT = $RESPONSE->site_docroot;
  456.  
  457. // These are the website-relative paths..
  458. $pub_dir = "$CMDIR/microsites";
  459. if (!is_dir($DOCROOT . $pub_dir)) {
  460. mkpath($DOCROOT . $pub_dir);
  461. chmod($DOCROOT . $pub_dir, 0775);
  462. }
  463. $pub_themedir = "$pub_dir/themes/$this->microsite_name";
  464. $pub_pagesdir = "$pub_dir/pages/$this->microsite_name";
  465.  
  466. // Assert the presence of physical directories..
  467. if (!is_dir($DOCROOT . $pub_themedir)) {
  468. mkpath($DOCROOT . $pub_themedir);
  469. chmod($DOCROOT . $pub_themedir, 0775);
  470. }
  471. if (!is_dir($DOCROOT . $pub_pagesdir)) {
  472. mkpath($DOCROOT . $pub_pagesdir);
  473. chmod($DOCROOT . $pub_pagesdir, 0775);
  474. }
  475.  
  476. // After the microsite is installed (symlinked), the website-relative
  477. // path for content will be as follows. This is required for menu
  478. // options.
  479. $real_pagesdir = "$CMDIR/$this->microsite_name";
  480.  
  481. // MENU
  482. if (!isset($this->menu_id) || $this->menu_id == "") {
  483. $mnuQ = new dbinsert("ax_menu");
  484. $this->menu_id = get_next_sequencevalue("seq_menu_id", "ax_menu", "menu_id");
  485. $mnuQ->set("menu_id", $this->menu_id);
  486. $mnuQ->set("menu_name", $this->microsite_name . "_menu");
  487. $mnuQ->set("menu_desc", "Menu generated for microsite " . $this->microsite_name);
  488. $mnuQ->set("last_modified", 'now()');
  489. $mnuQ->execute();
  490. $this->save();
  491. }
  492.  
  493. // STYLESHEETS
  494. $css = new outputfile($DOCROOT . "$pub_themedir/sitestyle.css");
  495. if ($css->opened) {
  496. $css->write($this->css);
  497. $css->closefile();
  498. }
  499. $css_ie = new outputfile($DOCROOT . "$pub_themedir/sitestyle_ie.css");
  500. if ($css_ie->opened) {
  501. $css_ie->write($this->css_ie);
  502. $css_ie->closefile();
  503. }
  504.  
  505. // TEMPLATES
  506. foreach ($this->templates as $tpid => $template) {
  507. $template->publishto($pub_themedir);
  508. }
  509.  
  510. // IMAGES & OTHER MEDIA
  511. if (!is_dir($DOCROOT . "$pub_themedir/img")) {
  512. mkpath($DOCROOT . "$pub_themedir/img");
  513. chmod($DOCROOT . "$pub_themedir/img", 0775);
  514. }
  515. foreach ($this->catalogitems as $cat_id => $catitem) {
  516. if (copy($DOCROOT . $catitem->filepath, $DOCROOT . "$pub_themedir/img/" . basename($catitem->filepath))) {
  517. debugbr("publish: copied media: $catitem->filepath --> $pub_themedir/img/" . basename($catitem->filepath), DBG_DEBUG);
  518. }
  519. }
  520.  
  521. // MICROSITE PAGES
  522. foreach ($this->pages as $pgid => $page) {
  523. debugbr("publish: microsite page $page->microsite_page_id start (menu=$this->menu_id)", DBG_DEBUG);
  524. $page->publishto($pub_pagesdir, $real_pagesdir, $this->menu_id);
  525. }
  526.  
  527. // REQUEST SYMLINKAGE
  528. if (!$this->currently_installed || !is_link($DOCROOT . "$TEMPLATESDIR/$this->microsite_name")) {
  529. $this->publish_request();
  530. debugbr("publish: making publish request for site linkage", DBG_DEBUG);
  531. }
  532. else {
  533. debugbr("publish: site linkage exists (microsite is installed/live)", DBG_DEBUG);
  534. }
  535.  
  536. } // publish
  537. // ....................................................................
  538. /**
  539. * Un-publish this microsite. This just removes the physical contents
  540. * of the microsite which were created in the ./var area.
  541. */
  542. function unpublish() {
  543. global $RESPONSE, $TEMPLATESDIR, $CMDIR;
  544.  
  545. // Document root for whole site..
  546. $DOCROOT = $RESPONSE->site_docroot;
  547.  
  548. // These are the website-relative paths..
  549. $pub_dir = "$CMDIR/microsites";
  550. $real_pub_themedir = $DOCROOT . "$pub_dir/themes/$this->microsite_name";
  551. $real_pub_pagesdir = $DOCROOT . "$pub_dir/pages/$this->microsite_name";
  552.  
  553. if (is_dir($real_pub_themedir)) {
  554. shell_exec("rm -rf $real_pub_themedir");
  555. }
  556. if (is_dir($real_pub_pagesdir)) {
  557. shell_exec("rm -rf $real_pub_pagesdir");
  558. }
  559.  
  560. } // unpublish
  561. // ....................................................................
  562. /**
  563. * Return a copy of the template object named as specified, and with the
  564. * given type. Or false if it wasn't found.
  565. * @return mixed The template object by name & type, or else false
  566. * @access private
  567. */
  568. function get_template_by_name_and_type($tpname, $tptype) {
  569. foreach ($this->templates as $tpid => $template) {
  570. if ($template->template_name == $tpname && $template->template_type == $tptype) {
  571. return $template;
  572. }
  573. }
  574. return false;
  575. } // get_template_by_name_and_type
  576. // ....................................................................
  577. /**
  578. * Return a copy of the page object which has a menuoption label
  579. * as specified.
  580. * @return mixed The page object by menu label, or else false
  581. * @access private
  582. */
  583. function get_page_by_menulabel($menulabel) {
  584. foreach ($this->pages as $pgid => $page) {
  585. if ($page->menuoption_label == $menulabel) {
  586. return $page;
  587. }
  588. }
  589. return false;
  590. } // get_page_by_menulabel
  591. // ....................................................................
  592. /**
  593. * Return a copy of the page object which has a sitepage ID
  594. * as specified.
  595. * @return mixed The page object by sitepage ID, or else false
  596. * @access private
  597. */
  598. function get_page_by_sitepage_id($page_id) {
  599. foreach ($this->pages as $pgid => $page) {
  600. if ($page->page_id == $page_id) {
  601. return $page;
  602. }
  603. }
  604. return false;
  605. } // get_page_by_sitepage_id
  606. // ....................................................................
  607. /**
  608. * Render the microsite editing suite.
  609. * @return string The HTML for the editing suite form etc.
  610. * @access private
  611. */
  612. function editform() {
  613. debug_trace($this);
  614. global $LIBDIR;
  615. global $RESPONSE;
  616. global $MIN_PLUGIN_SLOTS;
  617.  
  618. // Widths..
  619. $form_width = "640";
  620. $num_widthpx = "70px";
  621. $sml_widthpx = ceil(0.30 * $form_width) . "px";
  622. $mid_widthpx = ceil(0.45 * $form_width) . "px";
  623. $big_widthpx = ceil(0.60 * $form_width) . "px";
  624. $combo_widthpx = $big_widthpx;
  625.  
  626. // Heights
  627. $tall_heightpx = "250px";
  628. $short_heightpx = "100px";
  629.  
  630. // Initialise content..
  631. $s = "";
  632.  
  633. // Create toolbar buttons..
  634. $bpub = new form_imagebutton("_publish", "", "", "$LIBDIR/img/_publish.gif", "Publish to web", 57, 15);
  635. $brem = new form_imagebutton("_remove", "", "", "$LIBDIR/img/_remove.gif", "Remove from web", 57, 15);
  636. $bdel = new form_imagebutton("_delete", "", "", "$LIBDIR/img/_delete.gif", "Delete microsite", 57, 15);
  637. $badd = new form_imagebutton("_add", "", "", "$LIBDIR/img/_add.gif", "Add new", 57, 15);
  638. $bcan = new form_imagebutton("_cancel", "", "", "$LIBDIR/img/_cancel.gif", "Cancel add", 57, 15);
  639. $bsave = new form_imagebutton("_save", "", "", "$LIBDIR/img/_save.gif", "Save changes", 57, 15);
  640. $bdef = new form_imagebutton("_defcss", "", "", "$LIBDIR/img/_default.gif", "Reset to default CSS", 57, 15);
  641. $bdef->setstyle("padding-left:5px");
  642.  
  643. $bpub->set_onclick("microgo('publish')");
  644. $brem->set_onclick("microgo('remove')");
  645. $bdel->set_onclick("microgo('delete')");
  646. $badd->set_onclick("microgo('add')");
  647. $bcan->set_onclick("microgo('cancel')");
  648. $bdef->set_onclick("microgo('default_css')");
  649.  
  650. // Buttons for templates maintainer..
  651. $tm_badd = new form_imagebutton("_addtm", "", "", "$LIBDIR/img/_add.gif", "Add new template", 57, 15);
  652. $tm_bdel = new form_imagebutton("_deltm", "", "", "$LIBDIR/img/_delete.gif", "Delete template", 57, 15);
  653. $tm_bdef = new form_imagebutton("_deftm", "", "", "$LIBDIR/img/_default.gif", "Reset to default templates", 57, 15);
  654. $tm_bdef->set_onclick("microgo('default_templates')");
  655.  
  656. // Buttons for pages maintainer..
  657. $pg_badd = new form_imagebutton("_addpg", "", "", "$LIBDIR/img/_add.gif", "Add new page", 57, 15);
  658. $pg_bdel = new form_imagebutton("_delpg", "", "", "$LIBDIR/img/_delete.gif", "Delete page", 57, 15);
  659. $pg_bup = new form_imagebutton("_uppg", "", "", "$LIBDIR/img/_up.gif", "Move up", 57, 15);
  660. $pg_bdown = new form_imagebutton("_downpg", "", "", "$LIBDIR/img/_down.gif", "Move down", 57, 15);
  661. $pg_bdef = new form_imagebutton("_defpg", "", "", "$LIBDIR/img/_default.gif", "Install default pages", 57, 15);
  662. $pg_bdef->set_onclick("microgo('default_pages')");
  663.  
  664. // Buttons for media maintainer..
  665. $me_badd = new form_imagebutton("_addme", "", "", "$LIBDIR/img/_add.gif", "Add new media", 57, 15);
  666. $me_bdel = new form_imagebutton("_delme", "", "", "$LIBDIR/img/_delete.gif", "Delete media", 57, 15);
  667. $me_bdef = new form_imagebutton("_defme", "", "", "$LIBDIR/img/_default.gif", "Reset to default media", 57, 15);
  668. $me_bdef->set_onclick("microgo('default_images')");
  669.  
  670. // ..................................................................
  671. // MICROSITE TEMPLATES MAINTAINER
  672. // Declared here so we can create the maintainer and register buttons
  673. // before they are used in the form, later on.
  674.  
  675. $templates_listbox = new form_combofield("microsite_template_id");
  676. $templates_listbox->setclass("axlistbox");
  677. $templates_listbox->setstyle("width:$combo_widthpx;");
  678. $templates_listbox->size = 5;
  679.  
  680. // Make a new templates record maintainer, and attach the buttons..
  681. $templates_maintainer = new recmaintainer($this->formname, $templates_listbox, "templates_");
  682.  
  683. // Register templates maintainer buttons..
  684. $templates_maintainer->register_button("store", $bsave); // Save button is common to all
  685. $templates_maintainer->register_button("store", $bpub);
  686. $templates_maintainer->register_button("store", $bdef);
  687. $templates_maintainer->register_button("store", $pg_bdef);
  688. $templates_maintainer->register_button("store", $tm_bdef);
  689. $templates_maintainer->register_button("store", $me_bdef);
  690. $templates_maintainer->register_button("add", $tm_badd);
  691. $templates_maintainer->register_button("del", $tm_bdel);
  692.  
  693. // ..................................................................
  694. // MICROSITE PAGES MAINTAINER
  695. // Declared here so we can create the maintainer and register buttons
  696. // before they are used in the form, later on.
  697.  
  698. $pages_listbox = new form_combofield("microsite_page_id");
  699. $pages_listbox->setclass("axlistbox");
  700. $pages_listbox->setstyle("width:$combo_widthpx;");
  701. $pages_listbox->size = 10;
  702.  
  703. // Make a new pages record maintainer, and attach the buttons..
  704. $pages_maintainer = new recmaintainer($this->formname, $pages_listbox, "pages_");
  705.  
  706. // Register pages maintainer buttons..
  707. $pages_maintainer->register_button("store", $bsave); // Save button is common to all
  708. $pages_maintainer->register_button("store", $bpub);
  709. $pages_maintainer->register_button("store", $bdef);
  710. $pages_maintainer->register_button("store", $pg_bdef);
  711. $pages_maintainer->register_button("store", $tm_bdef);
  712. $pages_maintainer->register_button("store", $me_bdef);
  713. $pages_maintainer->register_button("add", $pg_badd);
  714. $pages_maintainer->register_button("del", $pg_bdel);
  715. $pages_maintainer->register_button("up" , $pg_bup);
  716. $pages_maintainer->register_button("down", $pg_bdown);
  717.  
  718. // ..................................................................
  719. // MICROSITE MEDIA MAINTAINER
  720. // Declared here so we can create the maintainer and register buttons
  721. // before they are used in the form, later on.
  722.  
  723. $media_listbox = new form_combofield("microsite_cat_id");
  724. $media_listbox->setclass("axlistbox");
  725. $media_listbox->setstyle("width:$combo_widthpx;");
  726. $media_listbox->size = 15;
  727.  
  728. // Make a new media record maintainer, and attach the buttons..
  729. $media_maintainer = new recmaintainer($this->formname, $media_listbox, "media_");
  730.  
  731. // Register media maintainer buttons..
  732. $media_maintainer->register_button("store", $bsave); // Save button is common to all
  733. $media_maintainer->register_button("store", $bpub);
  734. $media_maintainer->register_button("store", $bdef);
  735. $media_maintainer->register_button("store", $pg_bdef);
  736. $media_maintainer->register_button("store", $tm_bdef);
  737. $media_maintainer->register_button("store", $me_bdef);
  738. $media_maintainer->register_button("add", $me_badd);
  739. $media_maintainer->register_button("del", $me_bdel);
  740.  
  741. // Control table..
  742. $Ted = new table("microsite_$this->microsite_name");
  743. $Ted->setpadding(2);
  744. $Ted->setwidth("640");
  745. $Ted->setalign("center");
  746.  
  747. // ..................................................................
  748. // HEADING & NAVBAR
  749. // Navigation to edit existing microsites
  750. $MicroSel = new form_combofield("microsite_name", "", $this->microsite_name);
  751. $MicroSel->additem("");
  752. $MicroSel->setclass("axcombo");
  753. $micros = dbrecordset("SELECT * FROM ax_microsite ORDER BY microsite_desc");
  754. if ($micros->hasdata) {
  755. $microsite_name = $micros->field("microsite_name");
  756. $desc = $micros->field("microsite_desc");
  757. $dom = $micros->field("microsite_domain");
  758. $MicroSel->additem($microsite_name, (dom != "") ? $dom : $desc);
  759. }
  760. $Ted->tr("axtitle");
  761. $Ted->th("<b>MICROSITE</b> <small>$this->microsite_name</small>", "axtitle");
  762. if ($this->mode != "adding") {
  763. $Ted->td( $MicroSel->render() );
  764. $Ted->td_alignment("right");
  765. }
  766. else {
  767. $Ted->td_colspan(2);
  768. }
  769.  
  770. // ..................................................................
  771. // TOOLBAR
  772. // Apply the hook for form submit just prior to rendering..
  773. if ($this->mode == "adding") {
  774. $bsave->set_onclick("microgo('adding')", SCRIPT_APPEND);
  775. $toolbar[] = $bsave;
  776. $toolbar[] = $bcan;
  777. }
  778. else {
  779. $bsave->set_onclick("microgo('save')", SCRIPT_APPEND);
  780. $toolbar[] = $badd;
  781. if ($this->microsite_name != "") {
  782. $toolbar[] = $bsave;
  783. // Mere Authors can't do this stuff, only Editors..
  784. if ($RESPONSE->ismemberof_group_in("Editor")) {
  785. // Request miscrosite is published to web
  786. $toolbar[] = $bpub;
  787. if ($this->currently_installed) {
  788. if (!$this->req_microsite_remove) {
  789. // Request microsite is removed from web
  790. $toolbar[] = $brem;
  791. }
  792. }
  793. else {
  794. if (!$this->req_microsite_publish) {
  795. // Delete the whole microsite definition
  796. $toolbar[] = $bdel;
  797. }
  798. }
  799. }
  800. }
  801. }
  802. $Tbar = new table("toolbar");
  803. $Tbar->setpadding(1);
  804. $Tbar->setwidth("");
  805. $Tbar->tr();
  806. foreach ($toolbar as $tool) {
  807. $Tbar->td($tool->render());
  808. }
  809. $Ted->tr("axhdg");
  810. $Ted->td( $Tbar->render() );
  811. $Ted->td_colspan(2);
  812. $Ted->td_alignment("right");
  813.  
  814. // ..................................................................
  815. // Error messages - if any
  816. if (count($this->errmsgs) > 0) {
  817. $Ted->tr("axhdg");
  818. $Ted->td("<b>ERRORS</b>", "axhdg");
  819. $Ted->td_colspan(2);
  820.  
  821. foreach ($this->errmsgs as $errmsg) {
  822. $Ted->tr("axbglite");
  823. $Ted->td( $errmsg, "axerror" );
  824. $Ted->td_colspan(2);
  825. $Ted->td_alignment("center");
  826. }
  827. }
  828.  
  829. // ..................................................................
  830. // Global Microsite Properties..
  831. $Ted->tr("axhdg");
  832. $Ted->td("<b>MICROSITE PROPERTIES</b>", "axhdg");
  833. $Ted->td_colspan(2);
  834.  
  835. // ..................................................................
  836. // Microsite name - adding only..
  837. if ($this->mode == "adding") {
  838. $Fld = new form_textfield("new_microsite_name", "", $this->microsite_name);
  839. $Fld->setstyle("width:$mid_widthpx;");
  840. $Fld->setclass("axtxtbox");
  841. $Ted->tr("axbgdark");
  842. $Ted->td("New name (no spaces):", "axfg");
  843. $Ted->td( $Fld->render() );
  844. }
  845.  
  846. // ..................................................................
  847. // Microsite description
  848. $Fld = new form_textfield("microsite_desc", "", $this->microsite_desc);
  849. $Fld->setstyle("width:$big_widthpx;");
  850. $Fld->setclass("axtxtbox");
  851. $Ted->tr("axbgdark");
  852. $Ted->td("Description:", "axfg");
  853. $Ted->td( $Fld->render() );
  854.  
  855. // ..................................................................
  856. // Microsite domain
  857. $Fld = new form_textfield("microsite_domain", "", $this->microsite_domain);
  858. $Fld->setstyle("width:$mid_widthpx;");
  859. $Fld->setclass("axtxtbox");
  860. $Ted->tr("axbglite");
  861. $Ted->td("Domain (URL):", "axfg");
  862. $Ted->td( $Fld->render() );
  863.  
  864. // ..................................................................
  865. // Microsite CSS
  866. if ($this->mode != "adding") {
  867. $Fld = new form_memofield("css", "", $this->css);
  868. $Fld->set_wrapmode("off");
  869. $Fld->setstyle("width:$big_widthpx;height:$tall_heightpx;");
  870. $Fld->setclass("axmemo");
  871.  
  872. $T = new table("css");
  873. $T->tr();
  874. $T->td( $Fld->render() );
  875. $T->td( $bdef->render() );
  876. $T->td_alignment("", "top");
  877. $T->set_width_profile("60%,40%");
  878.  
  879. $Ted->tr("axbgdark");
  880. $Ted->td("CSS:", "axfg");
  881. $Ted->td_alignment("", "top");
  882. $Ted->td( $T->render() );
  883. }
  884.  
  885. // ..................................................................
  886. // Microsite CSS overrides for Internet Explorer
  887. // This one has a "default" button so we do it in a table..
  888. if ($this->mode != "adding") {
  889. $Fld = new form_memofield("css_ie", "", $this->css_ie);
  890. $Fld->set_wrapmode("off");
  891. $Fld->setstyle("width:$big_widthpx;height:$short_heightpx;");
  892. $Fld->setclass("axmemo");
  893. $Ted->tr("axbglite");
  894. $Ted->td("CSS (IE overrides):", "axfg");
  895. $Ted->td_alignment("", "top");
  896. $Ted->td( $Fld->render() );
  897. }
  898.  
  899. // ..................................................................
  900. // Microsite installed flag - display-only
  901. if ($this->mode != "adding") {
  902. $Fld = new form_labelfield("", $this->currently_installed ? "Yes" : "No");
  903. $Ted->tr("axbgdark");
  904. $Ted->td("Published to web:", "axfg");
  905. $Ted->td( $Fld->render() );
  906. }
  907.  
  908. // ..................................................................
  909. // Microsite last-installed timestamp - display-only
  910. if ($this->mode != "adding" && $this->currently_installed && $this->last_installed_ts != "") {
  911. $Fld = new form_labelfield("", timestamp_to_displaydate(NICE_DATETIME, $this->last_installed_ts));
  912. $Ted->tr("axbglite");
  913. $Ted->td("Last published:", "axfg");
  914. $Ted->td( $Fld->render() );
  915. }
  916. // ..................................................................
  917. // MICROSITE TEMPLATES, PAGES and MEDIA etc.
  918. if ($this->mode != "adding") {
  919. // ..................................................................
  920. // MICROSITE TEMPLATES
  921. $Ted->tr("axhdg");
  922. $Ted->td("<b>MICROSITE TEMPLATES</b>", "axhdg");
  923. $Ted->td_colspan(2);
  924.  
  925. foreach ($this->templates as $tpid => $template) {
  926. // Populate listbox..
  927. $templates_listbox->additem(
  928. $template->microsite_template_id,
  929. $template->template_name . " (" . $template->template_type . ")"
  930. );
  931.  
  932. // Populate maintainer data. The maintainer add_record method
  933. // requires an associative array keyed on listbox key id..
  934. $rec = array(
  935. "template_name" => $template->template_name,
  936. "template_type" => $template->template_type,
  937. "template_content" => $template->template_content
  938. );
  939. $templates_maintainer->add_record($template->microsite_template_id, $rec);
  940. }
  941. // Now set the defaults for each of the fields. These are
  942. // necessary for when a new record is created..
  943. $defaults = array(
  944. "template_name" => "new_template",
  945. "template_type" => "html",
  946. "template_content" => ""
  947. );
  948. $templates_maintainer->add_defaults($defaults);
  949.  
  950. // The listbox field..
  951. $templates_listbox->setvalue($template->microsite_template_id);
  952.  
  953. $Tin = new table("templates");
  954. $Tin->tr();
  955. $Tin->td( $templates_listbox->render() );
  956. $Tin->td(
  957. $tm_badd->render() . "<br>"
  958. . $tm_bdel->render() . "<br>"
  959. . $tm_bdef->render()
  960. );
  961. $Tin->td_alignment("", "top");
  962. $Tin->set_width_profile("50%,50%");
  963.  
  964. $Ted->tr("axbgdark");
  965. $Ted->td( "&nbsp;" );
  966. $Ted->td( $Tin->render() );
  967.  
  968. // ..................................................................
  969. $Ted->tr("axbglite");
  970. $Ted->td("<b>TEMPLATE SETTINGS</b>", "axfg");
  971. $Ted->td_colspan(2);
  972.  
  973. // ..................................................................
  974. // Microsite template name
  975. $Fld = new form_textfield("template_name", "", $template->template_name);
  976. $templates_maintainer->register_field($Fld);
  977. $Fld->setstyle("width:$mid_widthpx;");
  978. $Fld->setclass("axtxtbox");
  979. $Ted->tr("axbgdark");
  980. $Ted->td( "Template name:", "axfg" );
  981. $Ted->td( $Fld->render() );
  982.  
  983. // ..................................................................
  984. // Microsite menuoption lable
  985. $Fld = new form_combofield("template_type", "", $template->template_type);
  986. $Fld->additem("html", "HTML");
  987. $Fld->additem("wml", "WML");
  988. $templates_maintainer->register_field($Fld);
  989. $Fld->setstyle("width:$mid_widthpx;");
  990. $Fld->setclass("axcombo");
  991. $Ted->tr("axbglite");
  992. $Ted->td( "Type:", "axfg" );
  993. $Ted->td( $Fld->render() );
  994.  
  995. // ..................................................................
  996. // Template content
  997. $Fld = new form_memofield("template_content", "", $template->template_content);
  998. $Fld->set_wrapmode("off");
  999. $templates_maintainer->register_field($Fld);
  1000. $Fld->setstyle("width:$big_widthpx;height:$tall_heightpx;");
  1001. $Fld->setclass("axmemo");
  1002. $Ted->tr("axbgdark");
  1003. $Ted->td("Template content", "axfg");
  1004. $Ted->td_alignment("", "top");
  1005. $Ted->td( $Fld->render() );
  1006.  
  1007. $Ted->tr("axbgdark");
  1008. $Ted->td( "", "axfg" );
  1009. $Ted->td( "The template above is simply an HTML (or WML) page, with 'plugin areas' "
  1010. . "provided by HTML comments, eg. &LT;!--MAIN_CONTENT--&GT;. You can edit "
  1011. . "the template in-situ, or use some third-party HTML editor and paste it "
  1012. . "into the form here and then save it.",
  1013. "axnote"
  1014. );
  1015.  
  1016. // ..................................................................
  1017. // MICROSITE PAGES
  1018. $Ted->tr("axhdg");
  1019. $Ted->td("<b>MICROSITE PAGES</b>", "axhdg");
  1020. $Ted->td_colspan(2);
  1021.  
  1022. // Load up our page plugins data..
  1023. $q = "SELECT *";
  1024. $q .= " FROM ax_microsite_page p, ax_microsite_page_plugin pp,";
  1025. $q .= " ax_plugin_area pa, ax_plugin_content pc";
  1026. $q .= " WHERE p.microsite_name='" . addslashes($this->microsite_name) . "'";
  1027. $q .= " AND pp.microsite_page_id=p.microsite_page_id";
  1028. $q .= " AND pa.plugin_pattern=pp.plugin_pattern";
  1029. $q .= " AND pc.plugin_content=pp.plugin_content";
  1030. $pQ = dbrecordset($q);
  1031. $plugins = array();
  1032. $plugin_counts = array();
  1033. if ($pQ->hasdata) {
  1034. do {
  1035. $pageid = $pQ->field("microsite_page_id");
  1036. $plugin_pattern = $pQ->field("plugin_pattern");
  1037. $plugin_content = $pQ->field("plugin_content");
  1038. $plugins[$pageid][] = "$plugin_pattern|$plugin_content";
  1039. if (!isset($plugin_counts[$pageid])) {
  1040. $plugin_counts[$pageid] = 0;
  1041. }
  1042. $plugin_counts[$pageid] += 1;
  1043. } while ($pQ->get_next());
  1044. }
  1045. if (count($plugin_counts) > 0) {
  1046. $this->plugin_slots = max(max($plugin_counts) + 2, MIN_PLUGIN_SLOTS);
  1047. }
  1048. else {
  1049. $this->plugin_slots = MIN_PLUGIN_SLOTS;
  1050. }
  1051.  
  1052. foreach ($this->pages as $pgid => $page) {
  1053. // Populate listbox..
  1054. $page_desc = $page->page_title;
  1055. if ($page->microsite_homepage) {
  1056. $page_desc .= " (home)";
  1057. }
  1058. $pages_listbox->additem($page->microsite_page_id, $page_desc);
  1059.  
  1060. // Populate maintainer data. The maintainer add_record method
  1061. // requires an associative array keyed on listbox key id..
  1062. $rec = array(
  1063. "page_title" => $page->page_title,
  1064. "menuoption_label" => $page->menuoption_label,
  1065. "page_microsite_template_id" => $page->microsite_template_id,
  1066. "cache_minutes" => (int)($page->cache_seconds / 60),
  1067. "microsite_homepage" => ($page->microsite_homepage) ? "t" : "f",
  1068. "enabled" => ($page->enabled) ? "t" : "f"
  1069. );
  1070. // Add the plugin stuff..
  1071. $tot = 0;
  1072. if (isset($plugins[$page->microsite_page_id])) {
  1073. $plugin_infos = $plugins[$page->microsite_page_id];
  1074. sort($plugin_infos);
  1075. foreach ($plugin_infos as $plugin_info) {
  1076. $bits = explode("|", $plugin_info);
  1077. $pattern = $bits[0];
  1078. $content = $bits[1];
  1079. $rec["plugin_pattern_$tot"] = $pattern;
  1080. $rec["plugin_content_$tot"] = $content;
  1081. $tot += 1;
  1082. if ($tot >= $this->plugin_slots) break;
  1083. }
  1084. }
  1085. while ($tot < $this->plugin_slots) {
  1086. $rec["plugin_pattern_$tot"] = "";
  1087. $rec["plugin_content_$tot"] = "";
  1088. $tot += 1;
  1089. }
  1090. $pages_maintainer->add_record($page->microsite_page_id, $rec);
  1091. }
  1092. // Now set the defaults for each of the fields. These are
  1093. // necessary for when a new record is created..
  1094. $defaults = array(
  1095. "page_title" => "New Page",
  1096. "menuoption_label" => "New Page",
  1097. "page_microsite_template_id" => "",
  1098. "cache_minutes" => 0,
  1099. "microsite_homepage" => 'f',
  1100. "enabled" => 't',
  1101. "plugin_pattern_0" => 'FOOTER',
  1102. "plugin_content_0" => 'cm',
  1103. "plugin_pattern_1" => 'HEADER',
  1104. "plugin_content_1" => 'cm',
  1105. "plugin_pattern_2" => 'MAIN_MENU',
  1106. "plugin_content_2" => 'main_menu',
  1107. "plugin_pattern_3" => 'MAIN_CONTENT',
  1108. "plugin_content_3" => 'cm',
  1109. "plugin_pattern_4" => 'RIGHT_SIDEBAR',
  1110. "plugin_content_4" => 'cm'
  1111. );
  1112. for ($i = 5; $i < $this->plugin_slots; $i++) {
  1113. $defaults[] = "plugin_pattern_$i";
  1114. $defaults[] = "plugin_content_$i";
  1115. }
  1116. $pages_maintainer->add_defaults($defaults);
  1117.  
  1118. // The listbox field..
  1119. $pages_listbox->setvalue($page->microsite_page_id);
  1120.  
  1121. $pgbuttons =
  1122. $pg_badd->render() . "<br>"
  1123. . $pg_bdel->render() . "<br>"
  1124. . $pg_bup->render() . "<br>"
  1125. . $pg_bdown->render();
  1126.  
  1127. // Only allow them to install default pages if they
  1128. // actually have some templates defined..
  1129. if ($this->get_template_by_name_and_type("main", "html") !== false) {
  1130. $pgbuttons .= "<br>" . $pg_bdef->render();
  1131. }
  1132.  
  1133. $Tin = new table("pages");
  1134. $Tin->tr();
  1135. $Tin->td( $pages_listbox->render() );
  1136. $Tin->td($pgbuttons);
  1137. $Tin->td_alignment("", "top");
  1138. $Tin->set_width_profile("50%,50%");
  1139.  
  1140. $Ted->tr("axbgdark");
  1141. $Ted->td( "&nbsp;" );
  1142. $Ted->td( $Tin->render() );
  1143.  
  1144. // ..................................................................
  1145. $Ted->tr("axbglite");
  1146. $Ted->td("<b>PAGE SETTINGS</b>", "axfg");
  1147. $Ted->td_colspan(2);
  1148.  
  1149. // ..................................................................
  1150. // Microsite page title
  1151. $Fld = new form_textfield("page_title", "", $page->page_title);
  1152. $pages_maintainer->register_field($Fld);
  1153. $Fld->setstyle("width:$mid_widthpx;");
  1154. $Fld->setclass("axtxtbox");
  1155. $Ted->tr("axbgdark");
  1156. $Ted->td( "Page title:", "axfg" );
  1157. $Ted->td( $Fld->render() );
  1158.  
  1159. // ..................................................................
  1160. // Microsite menuoption lable
  1161. $Fld = new form_textfield("menuoption_label", "", $page->menuoption_label);
  1162. $pages_maintainer->register_field($Fld);
  1163. $Fld->setstyle("width:$mid_widthpx;");
  1164. $Fld->setclass("axtxtbox");
  1165. $Ted->tr("axbglite");
  1166. $Ted->td( "Menu label:", "axfg" );
  1167. $Ted->td( $Fld->render() );
  1168.  
  1169. // ..................................................................
  1170. // Microsite template
  1171. $Fld = new form_combofield("page_microsite_template_id", "", $page->microsite_template_id);
  1172. $Fld->additem("");
  1173. foreach ($this->templates as $tp) {
  1174. $Fld->additem($tp->microsite_template_id, $tp->template_name);
  1175. }
  1176. $pages_maintainer->register_field($Fld);
  1177. $Fld->setstyle("width:$mid_widthpx;");
  1178. $Fld->setclass("axcombo");
  1179. $Ted->tr("axbglite");
  1180. $Ted->td( "Template:", "axfg" );
  1181. $Ted->td( $Fld->render() );
  1182.  
  1183. // ..................................................................
  1184. // Microsite cache minutes (stored as seconds)
  1185. $Fld = new form_textfield("cache_minutes", "", (int)($page->cache_seconds / 60));
  1186. $pages_maintainer->register_field($Fld);
  1187. $Fld->setstyle("width:$num_widthpx;");
  1188. $Fld->setclass("axnumbox");
  1189. $Fld->set_onblur("limitInt(this, 0, 99999, 0)");
  1190. $Ted->tr("axbglite");
  1191. $Ted->td( "Cache minutes:", "axfg" );
  1192. $Ted->td( $Fld->render() );
  1193.  
  1194. // ..................................................................
  1195. // Microsite homepage flag
  1196. $Fld = new form_checkbox("microsite_homepage");
  1197. $pages_maintainer->register_field($Fld);
  1198. $Fld->checked = $page->microsite_homepage;
  1199. $Fld->setclass("axchkbox");
  1200. $Ted->tr("axbgdark");
  1201. $Ted->td( "Is microsite homepage:", "axfg" );
  1202. $Ted->td( $Fld->render() );
  1203.  
  1204. // ..................................................................
  1205. // Microsite page enabled flag
  1206. $Fld = new form_checkbox("enabled");
  1207. $pages_maintainer->register_field($Fld);
  1208. $Fld->checked = $page->enabled;
  1209. $Fld->setclass("axchkbox");
  1210. $Ted->tr("axbgdark");
  1211. $Ted->td( "Enable for publish:", "axfg" );
  1212. $Ted->td( $Fld->render() );
  1213.  
  1214. // ..................................................................
  1215. // Microsite page content definitions
  1216. $pattcombo = new form_combofield("");
  1217. $pattcombo->setclass("axcombo");
  1218. $pattcombo->setstyle("width:200px");
  1219. $patts = dbrecordset("SELECT * FROM ax_plugin_area");
  1220. $pattcombo->additem("");
  1221. $pattcombo->add_querydata($patts, "plugin_pattern", "plugin_pattern");
  1222. $contcombo = new form_combofield("");
  1223. $contcombo->setclass("axcombo");
  1224. $contcombo->setstyle("width:200px");
  1225. $conts = dbrecordset("SELECT * FROM ax_plugin_content");
  1226. $contcombo->additem("");
  1227. $contcombo->add_querydata($conts, "plugin_content", "plugin_content_desc");
  1228.  
  1229. $Tin = new table("plugins");
  1230. $Tin->setpadding(1);
  1231. $Tin->tr();
  1232. $Tin->td( "Plugin Area" );
  1233. $Tin->td( "Contains" );
  1234. for ($i = 0; $i < $this->plugin_slots; $i++) {
  1235. $pattcombo->setname("plugin_pattern_$i");
  1236. $pages_maintainer->register_field($pattcombo);
  1237. $contcombo->setname("plugin_content_$i");
  1238. $pages_maintainer->register_field($contcombo);
  1239. $Tin->tr();
  1240. $Tin->td( $pattcombo->render() );
  1241. $Tin->td( $contcombo->render() );
  1242. }
  1243.  
  1244. $Ted->tr("axbglite");
  1245. $Ted->td( "Plugins:", "axfg" );
  1246. $Ted->td_alignment("", "top");
  1247. $Ted->td( $Tin->render() );
  1248. $Ted->tr("axbglite");
  1249. $Ted->td( "", "axfg" );
  1250. $Ted->td( "The plugin areas above correspond to the ones in your templates "
  1251. . "named in HTML comments, eg. &LT;!--MAIN_CONTENT--&GT;. When you "
  1252. . "assign content to one of these using the right-hand menus, then "
  1253. . "that content will turn up in the plugin area.",
  1254. "axnote"
  1255. );
  1256.  
  1257. // ..................................................................
  1258. // MICROSITE MEDIA
  1259. $Ted->tr("axhdg");
  1260. $Ted->td("<b>MICROSITE LOCAL MEDIA</b>", "axhdg");
  1261. $Ted->td_colspan(2);
  1262.  
  1263. foreach ($this->catalogitems as $cat_id => $catitem) {
  1264. // Populate listbox..
  1265. $catitem_desc = $catitem->cat_name;
  1266. if ($catitem->filepath != "") {
  1267. $catitem_desc .= " (" . basename($catitem->filepath) . ")";
  1268. }
  1269. $media_listbox->additem(
  1270. $cat_id,
  1271. $catitem_desc
  1272. );
  1273.  
  1274. // Populate maintainer data. The maintainer add_record method
  1275. // requires an associative array keyed on listbox key id..
  1276. $rec = array(
  1277. "cat_id" => $cat_id,
  1278. "cat_name" => $catitem->cat_name,
  1279. "mime_category" => $catitem->mime_category,
  1280. "mime_type" => $catitem->mime_type,
  1281. "cat_desc" => $catitem->cat_desc
  1282. );
  1283. $media_maintainer->add_record($cat_id, $rec);
  1284. }
  1285. // Now set the defaults for each of the fields. These are
  1286. // necessary for when a new record is created..
  1287. $defaults = array(
  1288. "cat_id" => 0,
  1289. "cat_name" => "",
  1290. "mime_category" => "",
  1291. "mime_type" => "",
  1292. "cat_desc" => ""
  1293. );
  1294. $media_maintainer->add_defaults($defaults);
  1295.  
  1296. // The listbox field..
  1297. $media_listbox->setvalue($catitem->cat_id);
  1298. $media_listbox->set_onchange("cat_id_preview_func(this.value)", SCRIPT_APPEND);
  1299.  
  1300. // Ensure the first item gets previewed..
  1301. if (count($this->catalogitems) > 0) {
  1302. reset($this->catalogitems);
  1303. list($cat_id, $catitem) = each($this->catalogitems);
  1304. $RESPONSE->set_onload(
  1305. "cat_id_preview_func($cat_id);"
  1306. );
  1307. }
  1308.  
  1309. $Tin = new table("media");
  1310. $Tin->tr();
  1311. $Tin->td( $media_listbox->render() );
  1312. $Tin->td(
  1313. $me_badd->render() . "<br>"
  1314. . $me_bdel->render() . "<br>"
  1315. . $me_bdef->render()
  1316. );
  1317. $Tin->td_alignment("", "top");
  1318. $Tin->set_width_profile("50%,50%");
  1319.  
  1320. $Ted->tr("axbgdark");
  1321. $Ted->td( "&nbsp;" );
  1322. $Ted->td( $Tin->render() );
  1323.  
  1324. $Ted->tr("axbgdark");
  1325. $Ted->td( "&nbsp;" );
  1326. $Ted->td( "These media files are stored in the images directory which is local "
  1327. . "to this microsite. They can be used in templates by referring to them "
  1328. . "with a path like: 'img/foo.gif' and the proper path will be prefixed. "
  1329. . "Note that these media files are also placed into the global Media "
  1330. . "Catalog, and are therefore also available to be picked from there.",
  1331. "axnote"
  1332. );
  1333.  
  1334. // ..................................................................
  1335. $Ted->tr("axbglite");
  1336. $Ted->td("<b>MEDIA DETAILS</b>", "axfg");
  1337. $Ted->td_colspan(2);
  1338.  
  1339. // ..................................................................
  1340. // Media catalog item
  1341. $q = "SELECT * FROM ax_catalog c";
  1342. $q .= " ORDER BY c.mime_category";
  1343. $cat = dbrecordset($q);
  1344. $Fld = new form_imagecombo("cat_id");
  1345. $Fld->set_formname($this->formname);
  1346. if ($cat->hasdata) {
  1347. do {
  1348. $Fld->additem(
  1349. $cat->field("cat_id"),
  1350. $cat->field("cat_name") . " (" . $cat->field("mime_category") . ")",
  1351. $cat->field("filepath")
  1352. );
  1353. } while ($cat->get_next());
  1354. }
  1355. $media_maintainer->register_field($Fld);
  1356. $Fld->setstyle("width:$big_widthpx;");
  1357. $Fld->setclass("axcombo");
  1358. $Ted->tr("axbgdark");
  1359. $Ted->td( "Media item:", "axfg" );
  1360. $Ted->td_alignment("", "top");
  1361. $Ted->td( $Fld->render() );
  1362.  
  1363. // ..................................................................
  1364. // Microsite media name
  1365. $Fld = new form_textfield("cat_name");
  1366. $media_maintainer->register_field($Fld);
  1367. $Fld->setstyle("width:$mid_widthpx;");
  1368. $Fld->set_displayonly();
  1369. $Fld->setclass("axtxtbox");
  1370. $Ted->tr("axbglite");
  1371. $Ted->td( "Name:", "axfg" );
  1372. $Ted->td( $Fld->render() );
  1373.  
  1374. // ..................................................................
  1375. // Microsite media mime category
  1376. $Fld = new form_textfield("mime_category");
  1377. $media_maintainer->register_field($Fld);
  1378. $Fld->setstyle("width:$mid_widthpx;");
  1379. $Fld->set_displayonly();
  1380. $Fld->setclass("axtxtbox");
  1381. $Ted->tr("axbglite");
  1382. $Ted->td( "Mime category:", "axfg" );
  1383. $Ted->td( $Fld->render() );
  1384.  
  1385. // ..................................................................
  1386. // Microsite media mime type
  1387. $Fld = new form_textfield("mime_type");
  1388. $media_maintainer->register_field($Fld);
  1389. $Fld->setstyle("width:$mid_widthpx;");
  1390. $Fld->set_displayonly();
  1391. $Fld->setclass("axtxtbox");
  1392. $Ted->tr("axbglite");
  1393. $Ted->td( "Mime type:", "axfg" );
  1394. $Ted->td( $Fld->render() );
  1395.  
  1396. // ..................................................................
  1397. // Microsite media description
  1398. $Fld = new form_textfield("cat_desc");
  1399. $media_maintainer->register_field($Fld);
  1400. $Fld->setstyle("width:$mid_widthpx;");
  1401. $Fld->set_displayonly();
  1402. $Fld->setclass("axtxtbox");
  1403. $Ted->tr("axbglite");
  1404. $Ted->td( "Description:", "axfg" );
  1405. $Ted->td( $Fld->render() );
  1406.  
  1407. // ..................................................................
  1408. // Microsite media new file upload
  1409. // File upload field - allows them to add media on the
  1410. // fly to go with a story..
  1411. $Fld = new form_fileuploadfield("new_media");
  1412. $Fld->setsize(38);
  1413. $Ted->tr("axbgdark");
  1414. $Ted->td( "New media:", "axfg" );
  1415. $Ted->td( $Fld->render() );
  1416.  
  1417. // And the 'name' to go with it..
  1418. $Fld = new form_textfield("new_media_name");
  1419. $Fld->setstyle("width:$mid_widthpx;");
  1420. $Fld->setclass("axtxtbox");
  1421. $Ted->tr("axbglite");
  1422. $Ted->td( "New media name:", "axfg" );
  1423. $Ted->td( $Fld->render() );
  1424. } // not adding mode
  1425.  
  1426. // ..................................................................
  1427. // Render the whole form..
  1428. $Ted->tr("axtitle");
  1429. $Ted->td("&nbsp;", "axtitle");
  1430. $Ted->td_colspan(2);
  1431.  
  1432. $Ted->inherit_attributes($this);
  1433. $Ted->set_width_profile("25%,75%");
  1434. $s .= $Ted->render();
  1435.  
  1436. // Render the maintainers. This adds the Javascript data structures
  1437. // and renders the hidden fields for submitting changed field data..
  1438. $s .= $pages_maintainer->render();
  1439. $s .= $templates_maintainer->render();
  1440. $s .= $media_maintainer->render();
  1441.  
  1442. // When you have one of these, you need this script..
  1443. $RESPONSE->add_script(
  1444. "function microgo(mode) {\n"
  1445. . " var rc=true;\n"
  1446. . " if(mode=='delete') {\n"
  1447. . " var msg = \"CONFIRM:\\n\\n\";\n"
  1448. . " msg+='Do you really want to delete this microsite definition?\\n';\n"
  1449. . " msg+='This step is permanent!\\n\\n';\n"
  1450. . " rc = confirm(msg);\n"
  1451. . " }\n"
  1452. . " if(mode=='remove') {\n"
  1453. . " var msg = \"CONFIRM:\\n\\n\";\n"
  1454. . " msg+='Do you really want to remove the microsite from view?\\n';\n"
  1455. . " msg+='(the PUBLISH function can be used to make it available again)\\n\\n';\n"
  1456. . " rc = confirm(msg);\n"
  1457. . " }\n"
  1458. . " if(rc) {\n"
  1459. . " document.forms." . $this->formname . ".mode.value=mode;\n"
  1460. . " document.forms." . $this->formname . ".submit();\n"
  1461. . " }\n"
  1462. . "}\n"
  1463. );
  1464. // ....................................................................
  1465. debug_trace();
  1466. // Return the html..
  1467. return $s;
  1468. } // editform
  1469. // ....................................................................
  1470. /**
  1471. * Render the block content according to the mode of operation
  1472. * we are in. Possible modes: 'viewing', 'editing', 'saving'.
  1473. * @return string The HTML
  1474. */
  1475. function html() {
  1476. debug_trace($this);
  1477. global $RESPONSE;
  1478.  
  1479. // Something to propagate the mode..
  1480. $hidmode = new form_hiddenfield("mode", $this->mode);
  1481.  
  1482. $s = "";
  1483. $s .= "<form name=\"$this->formname\" method=\"post\" enctype=\"multipart/form-data\">\n";
  1484. $s .= $this->editform();
  1485. $s .= $hidmode->render();
  1486. $s .= "</form>\n";
  1487.  
  1488. debug_trace();
  1489. return $s;
  1490. } // html
  1491. // ....................................................................
  1492. /**
  1493. * Process a block edit form POST for "saving" the data. This is called
  1494. * from the main POSTprocess method.
  1495. * @access private
  1496. */
  1497. function POSTprocess_save() {
  1498. global $RESPONSE;
  1499. global $pages_recmaintpost_form;
  1500.  
  1501. // Sanity check for posted record maintenance data..
  1502. if ( isset($pages_recmaintpost_form)
  1503. && $pages_recmaintpost_form == $this->formname) {
  1504.  
  1505. // Access to all recmaint posted data..
  1506. global $pages_recmaintpost_form, $templates_recmaintpost_form, $media_recmaintpost_form;
  1507. global $pages_recmaintpost_data, $templates_recmaintpost_data, $media_recmaintpost_data;
  1508. global $pages_recmaintpost_flds, $templates_recmaintpost_flds, $media_recmaintpost_flds;
  1509. global $pages_recmaintpost_dels, $templates_recmaintpost_dels, $media_recmaintpost_dels;
  1510. global $pages_recmaintpost_order, $templates_recmaintpost_order, $media_recmaintpost_order;
  1511.  
  1512. // MICROSITE PAGES
  1513. // Page deletes..
  1514. if (isset($pages_recmaintpost_dels) && $pages_recmaintpost_dels != "") {
  1515. $pages_delids = explode(FIELD_DELIM, $pages_recmaintpost_dels);
  1516. foreach ($pages_delids as $delpageid) {
  1517. $page = new microsite_page($delpageid);
  1518. $page->get();
  1519. // Delete page & all associated entities..
  1520. $page->delete();
  1521. }
  1522. }
  1523. // Page adds and saves..
  1524. if (isset($pages_recmaintpost_data) && $pages_recmaintpost_data != "") {
  1525. $page_recs = explode(RECORD_DELIM, $pages_recmaintpost_data);
  1526. $page_fields = explode(",", $pages_recmaintpost_flds);
  1527. foreach ($page_recs as $page_rec) {
  1528. $page_values = explode(FIELD_DELIM, $page_rec);
  1529. $microsite_page_id = array_shift($page_values);
  1530. // Cater for new creations..
  1531. if (strstr($microsite_page_id, "NEW_")) {
  1532. $savedid = $microsite_page_id;
  1533. $page = new microsite_page(NEW_MICROSITE_PAGE, $this->microsite_name);
  1534. $page->save();
  1535. $microsite_page_id = $page->microsite_page_id;
  1536. // Fix up potential re-ordering id..
  1537. if (isset($pages_recmaintpost_order)) {
  1538. $pages_recmaintpost_order = str_replace($savedid, $microsite_page_id, $pages_recmaintpost_order);
  1539. }
  1540. }
  1541. // Remove existing plugins, so we can add them back..
  1542. $delpi = new dbdelete("ax_microsite_page_plugin");
  1543. $delpi->where("microsite_page_id=$microsite_page_id");
  1544. $delpi->execute();
  1545. // Update the microsite page data..
  1546. $um = new dbupdate("ax_microsite_page");
  1547. $um->where("microsite_page_id=$microsite_page_id");
  1548. $pos = 0;
  1549. $plugins = array();
  1550. $plugin_count = 0;
  1551. foreach ($page_fields as $page_field) {
  1552. $field_value = $page_values[$pos++];
  1553. // Make sure there's only ever one homepage..
  1554. if ($page_field == "microsite_homepage" && $field_value == "t") {
  1555. $hpunset = new dbupdate("ax_microsite_page");
  1556. $hpunset->set("microsite_homepage", false);
  1557. $hpunset->where("microsite_name='" . addslashes($this->microsite_name) . "'");
  1558. $hpunset->where("AND microsite_homepage=TRUE");
  1559. $hpunset->execute();
  1560. }
  1561. if ($page_field == "page_microsite_template_id") {
  1562. $page_field = "microsite_template_id";
  1563. if ($field_value == "") {
  1564. $field_value = NULLVALUE;
  1565. }
  1566. }
  1567. if ($page_field == "cache_minutes") {
  1568. $page_field = "cache_seconds";
  1569. $field_value = (int)($field_value * 60);
  1570. }
  1571. // Process either plugins, or normal data..
  1572. if (substr($page_field, 0, 6) == "plugin") {
  1573. if ($field_value != "") {
  1574. $plugin_field = substr($page_field, 7, 7);
  1575. if ($plugin_field == "pattern") {
  1576. $plugin_count += 1;
  1577. }
  1578. $plugin_index = (int)(substr($page_field, 15));
  1579. $plugins[$plugin_index][$plugin_field] = $field_value;
  1580. }
  1581. }
  1582. else {
  1583. if ($page_value == "") {
  1584. $page_value = NULLVALUE;
  1585. }
  1586. $um->set($page_field, $field_value);
  1587. }
  1588. } // foreach
  1589. $um->execute();
  1590. // Process any plugins we got..
  1591. if ($plugin_count > 0) {
  1592. for ($ix = 0; $ix < $plugin_count; $ix++) {
  1593. if ($plugins[$ix]["pattern"] != "" && $plugins[$ix]["content"] != "") {
  1594. $plin = new dbinsert("ax_microsite_page_plugin");
  1595. $pluginid = get_next_sequencevalue("seq_plugin_id", "ax_microsite_page_plugin", "plugin_id");
  1596. $plin->set("plugin_id", $pluginid);
  1597. $plin->set("microsite_page_id", $microsite_page_id);
  1598. $plin->set("plugin_pattern", $plugins[$ix]["pattern"]);
  1599. $plin->set("plugin_content", $plugins[$ix]["content"]);
  1600. $plin->execute();
  1601. }
  1602. }
  1603. }
  1604. } // foreach
  1605. }
  1606. // Check/save page ordering..
  1607. if (isset($pages_recmaintpost_order) && $pages_recmaintpost_order != "") {
  1608. $ord = 1;
  1609. $idlist = explode(FIELD_DELIM, $pages_recmaintpost_order);
  1610. foreach ($idlist as $microsite_page_id) {
  1611. $upd = new dbupdate("ax_microsite_page");
  1612. $upd->where("microsite_page_id=$microsite_page_id");
  1613. $upd->set("display_order", $ord);
  1614. $upd->execute();
  1615. $ord += 1;
  1616. }
  1617. }
  1618. // MICROSITE TEMPLATES
  1619. // Template deletes..
  1620. if (isset($templates_recmaintpost_dels) && $templates_recmaintpost_dels != "") {
  1621. $templates_delids = explode(FIELD_DELIM, $templates_recmaintpost_dels);
  1622. foreach ($templates_delids as $deltemplateid) {
  1623. $template = new microsite_template($deltemplateid);
  1624. $template->get();
  1625. $template->delete();
  1626. }
  1627. }
  1628. // Template adds and saves..
  1629. if (isset($templates_recmaintpost_data) && $templates_recmaintpost_data != "") {
  1630. $template_recs = explode(RECORD_DELIM, $templates_recmaintpost_data);
  1631. $template_fields = explode(",", $templates_recmaintpost_flds);
  1632. foreach ($template_recs as $template_rec) {
  1633. $template_values = explode(FIELD_DELIM, $template_rec);
  1634. $microsite_template_id = array_shift($template_values);
  1635. // Cater for new creations..
  1636. if (strstr($microsite_template_id, "NEW_")) {
  1637. $savedid = $microsite_template_id;
  1638. $template = new microsite_template(NEW_MICROSITE_TEMPLATE, $this->microsite_name);
  1639. $template->save();
  1640. $microsite_template_id = $template->microsite_template_id;
  1641. }
  1642. // Update the microsite template data..
  1643. $um = new dbupdate("ax_microsite_template");
  1644. $um->where("microsite_template_id=$microsite_template_id");
  1645. $pos = 0;
  1646. foreach ($template_fields as $template_field) {
  1647. // Set the current value assignment..
  1648. $um->set($template_field, $template_values[$pos++]);
  1649. } // foreach
  1650. $um->execute();
  1651. } // foreach
  1652. }
  1653. // MICROSITE MEDIA
  1654. // Media deletes..
  1655. if (isset($media_recmaintpost_dels) && $media_recmaintpost_dels != "") {
  1656. $media_delids = explode(FIELD_DELIM, $media_recmaintpost_dels);
  1657. foreach ($media_delids as $delcat_id) {
  1658. $medel = new dbdelete("ax_microsite_media");
  1659. $medel->where("microsite_name='" . addslashes($this->microsite_name) . "'");
  1660. $medel->where("AND cat_id=$delcat_id");
  1661. $medel->execute();
  1662. }
  1663. }
  1664. // Media adds and saves..
  1665. if (isset($media_recmaintpost_data) && $media_recmaintpost_data != "") {
  1666. $media_recs = explode(RECORD_DELIM, $media_recmaintpost_data);
  1667. $media_fields = explode(",", $media_recmaintpost_flds);
  1668. foreach ($media_recs as $media_rec) {
  1669. $media_values = explode(FIELD_DELIM, $media_rec);
  1670. $dummy = array_shift($media_values);
  1671. if (strstr($dummy, "NEW_")) {
  1672. $im = new dbinsert("ax_microsite_media");
  1673. $pos = 0;
  1674. foreach ($media_fields as $media_field) {
  1675. $media_value = $media_values[$pos++];
  1676. if ($media_field == "cat_id") {
  1677. $cat_id = $media_value;
  1678. $im->set($media_field, $cat_id);
  1679. }
  1680. } // foreach
  1681. $im->set("microsite_name", $this->microsite_name);
  1682. if (isset($cat_id) && $cat_id != 0) {
  1683. $im->execute();
  1684. }
  1685. }
  1686. } // foreach
  1687. }
  1688. // Uploaded media - automatically added to microsite..
  1689. global $new_media_name;
  1690. $newci = new catalogitem();
  1691. $errmsgs = $newci->upload($new_media_name, $this->microsite_name, "Created for microsite $this->microsite_name");
  1692. if ($newci->valid) {
  1693. $mmin = new dbinsert("ax_microsite_media");
  1694. $mmin->set("microsite_name", $this->microsite_name);
  1695. $mmin->set("cat_id", $newci->cat_id);
  1696. $mmin->execute();
  1697. }
  1698.  
  1699. // Save the global microsite information..
  1700. global $microsite_desc, $microsite_domain;
  1701. global $css, $css_ie;
  1702. $mup = new dbupdate("ax_microsite");
  1703. $mup->set("microsite_desc", $microsite_desc);
  1704. $mup->set("microsite_domain", $microsite_domain);
  1705. $mup->set("css", $css);
  1706. $mup->set("css_ie", $css_ie);
  1707. $mup->set("last_modified", 'now()');
  1708. $mup->execute();
  1709.  
  1710. $this->mode = "editing";
  1711. } // if our microsite being saved
  1712.  
  1713. } // POSTprocess_save
  1714. // ....................................................................
  1715. /**
  1716. * Process a block edit form POST.
  1717. * Assume that the fields have been submitted in a form as named
  1718. * in the config, and grab the POSTed values. This method is executed
  1719. * from the constructor usually, before anything is read in from
  1720. * the database. We get first shot to change data here.
  1721. * @access private
  1722. */
  1723. function POSTprocess() {
  1724. debug_trace($this);
  1725. global $HTTP_POST_VARS, $RESPONSE;
  1726. global $INCDIR, $CATALOGDIR, $IMAGESDIR;
  1727. if (isset($HTTP_POST_VARS["mode"])) {
  1728. $this->mode = $HTTP_POST_VARS["mode"];
  1729. debugbr("POSTprocess: initial mode: $this->mode", DBG_DEBUG);
  1730. switch ($this->mode) {
  1731. case "publish":
  1732. // Publish microsite instance to the internet..
  1733. $this->POSTprocess_save();
  1734. $this->get();
  1735. $this->publish();
  1736. $this->mode = "editing";
  1737. break;
  1738.  
  1739. case "remove":
  1740. // Remove microsite instance from the internet..
  1741. $this->remove_request();
  1742. $this->mode = "editing";
  1743. break;
  1744.  
  1745. case "delete":
  1746. // Delete microsite definition completely..
  1747. $this->get();
  1748. $this->delete();
  1749. // Try for the first microsite we can get..
  1750. $ms = dbrecordset(
  1751. "SELECT microsite_name"
  1752. . " FROM ax_microsite"
  1753. . " ORDER BY microsite_desc,microsite_name"
  1754. );
  1755. if ($ms->hasdata) {
  1756. $this->microsite_name = $ms->field("microsite_name");
  1757. }
  1758. $this->mode = "editing";
  1759. break;
  1760.  
  1761. case "add":
  1762. // Add new microsite definition..
  1763. $this->microsite_name = "new_microsite";
  1764. $this->microsite_desc = "My New Microsite";
  1765. $this->mode = "adding";
  1766. break;
  1767.  
  1768. case "cancel":
  1769. // Cancelling add mode..
  1770. $this->mode = "editing";
  1771. break;
  1772.  
  1773. case "adding":
  1774. global $new_microsite_name;
  1775. $this->microsite_name = $new_microsite_name;
  1776. $exists = dbrecordset("SELECT * FROM ax_microsite WHERE microsite_name='" . addslashes($new_microsite_name) . "'");
  1777. if ($exists->hasdata) {
  1778. $this->errmsgs[] = "Microsite '$new_microsite_name' already exists. Pick another name.";
  1779. $this->mode = "editing";
  1780. return;
  1781. }
  1782. // Insert the microsite record..
  1783. $min = new dbinsert("ax_microsite");
  1784. $min->set("microsite_name", $new_microsite_name);
  1785. if (!$min->execute()) {
  1786. $this->errmsgs[] = "Unable to create microsite '$new_microsite_name'. Please inform your sysadmin.";
  1787. $this->mode = "editing";
  1788. return;
  1789. }
  1790. // If all went well, save it..
  1791. $this->POSTprocess_save();
  1792. break;
  1793.  
  1794. case "save":
  1795. $this->POSTprocess_save();
  1796. break;
  1797.  
  1798. case "default_css":
  1799. $this->POSTprocess_save();
  1800. $sheets = $RESPONSE->get_stylesheets("", "");
  1801. $csspath = $RESPONSE->site_docroot . $sheets["ss"];
  1802. $cssin = new inputfile($csspath);
  1803. if ($cssin->opened) {
  1804. $css = $cssin->readall();
  1805. $cssin->closefile();
  1806. if ($css !== false) {
  1807. $this->get();
  1808. $this->css = $css;
  1809. $this->save();
  1810. }
  1811. }
  1812. break;
  1813.  
  1814. case "default_templates":
  1815. $this->POSTprocess_save();
  1816. $this->get();
  1817. // Get array of available default templates..
  1818. $template_paths = get_dirlist(
  1819. $RESPONSE->site_docroot . $INCDIR,
  1820. false, // no recursion
  1821. $regex="/.*default_.*/"
  1822. );
  1823. // Create new templates, or redefine existing..
  1824. foreach ($template_paths as $template_path) {
  1825. $tpfile = new inputfile($template_path);
  1826. if ($tpfile->opened) {
  1827. $tpcontent = $tpfile->readall();
  1828. if ($tpcontent !== false) {
  1829. $tptype = get_file_extn($template_path);
  1830. $tpname = basename($template_path);
  1831. $tpname = str_replace("default_template_", "", $tpname);
  1832. $tpname = get_file_stem($tpname);
  1833. $template = $this->get_template_by_name_and_type($tpname, $tptype);
  1834. if ($template === false) {
  1835. $template = new microsite_template(NEW_MICROSITE_TEMPLATE, $this->microsite_name);
  1836. }
  1837. // Assert values and store it..
  1838. $template->template_name = $tpname;
  1839. $template->template_type = $tptype;
  1840. $template->template_content = $tpcontent;
  1841. $template->save();
  1842. $this->templates[$template->microsite_template_id] = $template;
  1843. }
  1844. } // opened
  1845. }
  1846. // Now fix up our page templates..
  1847. $newpages = array();
  1848. foreach ($this->pages as $pgid => $page) {
  1849. if (isset($page->template)) {
  1850. $tpname = $page->template->template_name;
  1851. $tptype = $page->template->template_type;
  1852. $template = $this->get_template_by_name_and_type($tpname, $tptype);
  1853. if ($template !== false) {
  1854. $page->template == $template;
  1855. }
  1856. }
  1857. $newpages[$pgid] = $page;
  1858. }
  1859. $this->pages = $newpages;
  1860. // Save microsite, including all pages data..
  1861. $this->save();
  1862. break;
  1863.  
  1864. case "default_pages":
  1865. $this->POSTprocess_save();
  1866. $this->get();
  1867. // Add the default pages to this new microsite object.
  1868. // Select template to use. We want to find the "main"
  1869. // template by its ID here..
  1870. $main_template = $this->get_template_by_name_and_type("main", "html");
  1871.  
  1872. // Install default Cm pages..
  1873. $default_pages = array(
  1874. "cm-home.php" => "HOME|Home page|index|MAIN_MENU~tree_menu%HEADER~cm%FOOTER~cm%MAIN_CONTENT~feat%RIGHT_SIDEBAR~latest",
  1875. "cm-about.php" => "ABOUT|About|main|MAIN_MENU~tree_menu%HEADER~cm%FOOTER~cm%MAIN_CONTENT~cm%SITE_SEARCH~search_form%MAIN_CONTENT~search_results",
  1876. "cm-products.php" => "PRODUCTS|Products|main|MAIN_MENU~tree_menu%HEADER~cm%FOOTER~cm%MAIN_CONTENT~cm%SITE_SEARCH~search_form%MAIN_CONTENT~search_results",
  1877. "cm-services.php" => "SERVICES|Services|main|MAIN_MENU~tree_menu%HEADER~cm%FOOTER~cm%MAIN_CONTENT~cm%SITE_SEARCH~search_form%MAIN_CONTENT~search_results",
  1878. "cm-contact.php" => "CONTACT|Contact us|main|MAIN_MENU~tree_menu%HEADER~cm%FOOTER~cm%MAIN_CONTENT~cm%SITE_SEARCH~search_form%MAIN_CONTENT~search_results"
  1879. );
  1880. foreach ($default_pages as $page_path => $page_info) {
  1881. $info = explode("|", $page_info);
  1882. $menu_label = $info[0];
  1883. if ($this->get_page_by_menulabel($menu_label) === false) {
  1884. $page_desc = $info[1];
  1885. $template_name = $info[2];
  1886. $template = $this->get_template_by_name_and_type($template_name, "html");
  1887. if ($template === false) {
  1888. $template = $main_template;
  1889. }
  1890. $page = new microsite_page(
  1891. NEW_MICROSITE_PAGE,
  1892. $this->microsite_name,
  1893. $page_desc,
  1894. 0, // cache secs
  1895. false, // corepage
  1896. ($page_path == "cm-home.php") ? true : false, // homepage
  1897. true, // enabled
  1898. $menu_label,
  1899. "", // menuopt ID
  1900. "", // order
  1901. $template->template_id
  1902. );
  1903. $page->save();
  1904. // Plugins defined for the page..
  1905. if (trim($info[3]) != "") {
  1906. $plugins = explode("%", $info[3]);
  1907. if (count($plugins) > 0) {
  1908. foreach ($plugins as $plugin_info) {
  1909. $plugin_bits = explode("~", $plugin_info);
  1910. $plugin_pattern = $plugin_bits[0];
  1911. $plugin_content = $plugin_bits[1];
  1912. if ($plugin_pattern != "" && $plugin_content != "") {
  1913. $plin = new dbinsert("ax_microsite_page_plugin");
  1914. $pluginid = get_next_sequencevalue("seq_plugin_id", "ax_microsite_page_plugin", "plugin_id");
  1915. $plin->set("plugin_id", $pluginid);
  1916. $plin->set("microsite_page_id", $page->microsite_page_id);
  1917. $plin->set("plugin_pattern", $plugin_pattern);
  1918. $plin->set("plugin_content", $plugin_content);
  1919. $plin->execute();
  1920. }
  1921. }
  1922. }
  1923. }
  1924. } // not found by menu label
  1925. } // foreach
  1926.  
  1927. // Now install core Axyl pages..
  1928. $core_pages = array(
  1929. "/axyl-news.php" => "LATEST NEWS|Latest news",
  1930. "/axyl-story-admin.php" => "NEWS EDITOR|News editor",
  1931. "/axyl-catalog.php" => "MEDIA CATALOG|Media catalog",
  1932. "/axyl-forums.php" => "FORUMS|Forums",
  1933. "/axyl-login.php" => "LOGIN|Member login"
  1934. );
  1935. foreach ($core_pages as $page_path => $page_info) {
  1936. $info = explode("|", $page_info);
  1937. $menu_label = $info[0];
  1938. $page_desc = $info[1];
  1939. $pg = dbrecordset("SELECT * FROM ax_sitepage WHERE page_path='$page_path'");
  1940. if ($pg->hasdata) {
  1941. $spgid = $pg->field("page_id");
  1942. if ($this->get_page_by_sitepage_id($spgid) === false) {
  1943. $page = new microsite_page(
  1944. NEW_MICROSITE_PAGE,
  1945. $this->microsite_name,
  1946. $page_desc,
  1947. 0, // cache secs
  1948. true, // corepage
  1949. false, // homepage
  1950. true, // enabled
  1951. $menu_label,
  1952. "", // menuopt ID
  1953. "", // order
  1954. $main_template->template_id,
  1955. $spgid
  1956. );
  1957. $page->save();
  1958. }
  1959. }
  1960. } // foreach
  1961. break;
  1962.  
  1963. case "default_images":
  1964. include_once("catalog-defs.php");
  1965. $this->POSTprocess_save();
  1966. $this->get();
  1967. // These are the images we consider worthy of copying across
  1968. // from the 'top' Axyl website, to this microsite. If these
  1969. // images aren't found, we do nothing. If we already have them
  1970. // on this microsite, we do nothing.
  1971. $default_images = array(
  1972. "axyl_logo.png" => "Axyl logo",
  1973. "loginBot.gif" => "Axyl login bottom piece",
  1974. "masterTile.gif" => "Axyl main tile",
  1975. "footerTile.gif" => "Axyl footer tile",
  1976. "topTile.gif" => "Axyl header tile",
  1977. "axyl_news.gif" => "Axyl news icon",
  1978. "axylMini.gif" => "Axyl popup logo",
  1979. "axyl01.gif" => "Axyl logo piece",
  1980. "axyl01b.gif" => "Axyl line piece",
  1981. "axyl02.gif" => "Axyl black block",
  1982. "axyl03.gif" => "Axyl black/olive block",
  1983. "axyl04.gif" => "Axyl search left angle",
  1984. "axyl05.gif" => "Axyl search main piece",
  1985. "axyl06.gif" => "Axyl search right angle",
  1986. "axyl08.gif" => "Axyl white block",
  1987. "axyl09.gif" => "Axyl copyright footer",
  1988. "buildingBack.jpg" => "Right sidebar black",
  1989. "corner.gif" => "Axyl corner piece",
  1990. "corner1.gif" => "Axyl corner piece"
  1991. );
  1992. // Get existing media catalog, complete..
  1993. $catalog = new catalog();
  1994. $catalog->search();
  1995.  
  1996. // Get array of available default templates..
  1997. $media_paths = get_dirlist(
  1998. $RESPONSE->site_docroot . $IMAGESDIR,
  1999. false // no recursion
  2000. );
  2001. foreach ($media_paths as $media_path) {
  2002. $media_fname = basename($media_path);
  2003. if (isset($default_images[$media_fname])) {
  2004. $media_filepath = str_replace($RESPONSE->site_docroot, "", $media_path);
  2005. $catitem = $catalog->get_catalogitem_by_filepath($media_filepath);
  2006. if ($catitem === false) {
  2007. $name = ucfirst(get_file_stem($media_fname));
  2008. $desc = $default_images[$media_fname];
  2009. $keywords = "axyl default";
  2010.  
  2011. // Make new catalog item & save..
  2012. $catitem = new catalogitem();
  2013. // Move file into place, and create DB record..
  2014. $cataloged = $catitem->create(
  2015. $media_path, $media_path, $media_filepath,
  2016. "",
  2017. 0, 0,
  2018. $name, $this->microsite_name, $desc, $keywords
  2019. );
  2020. }
  2021. else {
  2022. $cataloged = true;
  2023. }
  2024. if ($cataloged && !isset($this->catalogitems[$catitem->cat_id])) {
  2025. $mmin = new dbinsert("ax_microsite_media");
  2026. $mmin->set("cat_id", $catitem->cat_id);
  2027. $mmin->set("microsite_name", $this->microsite_name);
  2028. $mmin->execute();
  2029. $this->catalogitems[$catitem->cat_id] = $catitem;
  2030. }
  2031. }
  2032. } // foreach
  2033. break;
  2034.  
  2035. } // switch
  2036. }
  2037. debugbr("POSTprocess: final mode: $this->mode", DBG_DEBUG);
  2038. debug_trace();
  2039. } // POSTprocess
  2040.  
  2041.  
  2042.  
  2043. } // micrositemaintainer class
  2044. // ----------------------------------------------------------------------
  2045.  
  2046. define("NEW_MICROSITE_PAGE", -1);
  2047. /**
  2048. * Microsite Page - a container class.
  2049. * @package microsite
  2050. */
  2051. class microsite_page {
  2052. // Public
  2053. /** Unique microsite page ID */
  2054.  
  2055. var $microsite_page_id;
  2056. /** Name of microsite this page is for */
  2057.  
  2058. var $microsite_name;
  2059. /** Title of this page */
  2060.  
  2061. var $page_title = "";
  2062. /** How many seconds to cache this page */
  2063.  
  2064. var $cache_seconds = 0;
  2065. /** Whether this page is an Axyl core page */
  2066.  
  2067. var $corepage = false;
  2068. /** Whether this page is the microsite home page */
  2069.  
  2070. var $microsite_homepage = false;
  2071. /** Whether this page is to be published */
  2072.  
  2073. var $enabled = true;
  2074. /** Label for menu option of this page */
  2075.  
  2076. var $menuoption_label = "";
  2077. /** Order (for displaying menu lables) */
  2078.  
  2079. var $display_order = 999;
  2080. /** Axyl sitepage ID (Fk) */
  2081.  
  2082. var $page_id;
  2083. /** Microsite template ID (Fk) */
  2084.  
  2085. var $microsite_template_id;
  2086. /** Axyl sitepage page filepath */
  2087.  
  2088. var $page_path;
  2089. // Private
  2090. /** The microsite template object applied to this page
  2091. @access private */
  2092. var $template;
  2093. /** Menuoption ID - FK to ax_menuoption record */
  2094.  
  2095. var $menuoption_id;
  2096. // ....................................................................
  2097. /**
  2098. * Constructor
  2099. * Create a new microsite_page
  2100. * @param integer $id The unique microsite page ID
  2101. * @param string $microsite_name The name of the microsite this is for
  2102. * @param string $title The title of this page
  2103. * @param boolean $homepage True if this page is the site homepage (indexpage)
  2104. * @param boolean $enabled True if this page is ok to publish
  2105. * @param string $label The label to use for the menu option for this page
  2106. * @param integer $order The display order (for the menu option)
  2107. * @param integer $template_id The ID of the template record of this page (Fk)
  2108. * @param integer $page_id The ID of the Axyl sitepage record of this page (Fk)
  2109. */
  2110. function microsite_page(
  2111. $id=NEW_MICROSITE_PAGE,
  2112. $microsite_name="",
  2113. $title="",
  2114. $cache_seconds=0,
  2115. $corepage=false,
  2116. $homepage=false,
  2117. $enabled=true,
  2118. $label="",
  2119. $mopid="",
  2120. $order="",
  2121. $template_id="",
  2122. $page_id=""
  2123. ) {
  2124. $this->microsite_page_id = $id;
  2125. $this->microsite_name = $microsite_name;
  2126. $this->page_title = $title;
  2127. $this->cache_seconds = (is_numeric($cache_seconds) ? $cache_seconds : 0);
  2128. $this->corepage = $corepage;
  2129. $this->microsite_homepage = $homepage;
  2130. $this->enabled = $enabled;
  2131. $this->menuoption_label = $label;
  2132. if ($mopid != "") {
  2133. $this->menuoption_id = $mopid;
  2134. }
  2135. if ($order != "") {
  2136. $this->display_order = $order;
  2137. }
  2138. if ($template_id != "") {
  2139. $this->microsite_template_id = $template_id;
  2140. }
  2141. if ($page_id != "") {
  2142. $this->page_id = $page_id;
  2143. }
  2144. } // constructor
  2145. // ....................................................................
  2146. /**
  2147. * Get the microsite page details from the databse.
  2148. * @return boolean True if we successfully got the record
  2149. */
  2150. function get($pageid="") {
  2151. $res = false;
  2152. if ($pageid != "") {
  2153. $this->microsite_page_id = $pageid;
  2154. }
  2155. if (isset($this->microsite_page_id) && $this->microsite_page_id != NEW_MICROSITE_PAGE) {
  2156. $q = "SELECT *";
  2157. $q .= " FROM ax_microsite_page";
  2158. $q .= " WHERE microsite_page_id=$this->microsite_page_id";
  2159. $mpQ = dbrecordset($q);
  2160. if ($mpQ->hasdata) {
  2161. $this->microsite_name = $mpQ->field("microsite_name");
  2162. $this->page_title = $mpQ->field("page_title");
  2163. $this->cache_seconds = $mpQ->field("cache_seconds");
  2164. $this->corepage = $mpQ->istrue("corepage");
  2165. $this->microsite_homepage = $mpQ->istrue("microsite_homepage");
  2166. $this->enabled = $mpQ->istrue("enabled");
  2167. $this->menuoption_label = $mpQ->field("menuoption_label");
  2168. $this->display_order = $mpQ->field("display_order");
  2169. if ($mpQ->field("menuoption_id") != "") {
  2170. $this->menuoption_id = $mpQ->field("menuoption_id");
  2171. }
  2172. if ($mpQ->field("microsite_template_id") != "") {
  2173. $this->microsite_template_id = $mpQ->field("microsite_template_id");
  2174. }
  2175. if ($mpQ->field("page_id") != "") {
  2176. $this->page_id = $mpQ->field("page_id");
  2177. }
  2178. $res = true;
  2179. }
  2180. }
  2181. return $res;
  2182. } // get
  2183. // ....................................................................
  2184. /**
  2185. * Get the associated details for this page, from the database. This
  2186. * includes the template(s) associated with the page, and also the
  2187. * menuoption_id linking to the associated menu option record.
  2188. */
  2189. function get_info() {
  2190. if (isset($this->template)) {
  2191. unset($this->template);
  2192. }
  2193. if (isset($this->microsite_page_id)) {
  2194. // Template
  2195. if (isset($this->microsite_template_id) && $this->microsite_template_id != "") {
  2196. $q = "SELECT *";
  2197. $q .= " FROM ax_microsite_template";
  2198. $q .= " WHERE microsite_template_id=$this->microsite_template_id";
  2199. $tptQ = dbrecordset($q);
  2200. if ($tptQ->hasdata) {
  2201. $this->template = new microsite_template(
  2202. $tptQ->field("microsite_template_id"),
  2203. $tptQ->field("microsite_name"),
  2204. $tptQ->field("template_name"),
  2205. $tptQ->field("template_type"),
  2206. $tptQ->field("template_content")
  2207. );
  2208. }
  2209. }
  2210. // Sitepage
  2211. if (isset($this->page_id) && $this->page_id != "") {
  2212. $q = "SELECT *";
  2213. $q .= " FROM ax_sitepage";
  2214. $q .= " WHERE page_id=$this->page_id";
  2215. $pgQ = dbrecordset($q);
  2216. if ($pgQ->hasdata) {
  2217. $this->page_path = $pgQ->field("page_path");
  2218. }
  2219. }
  2220. }
  2221. } // get_info
  2222. // ....................................................................
  2223. /**
  2224. * Delete this page from the database. We also delete all other records
  2225. * associated with this page, and do not rely on RI.
  2226. */
  2227. function delete() {
  2228. global $RESPONSE;
  2229. $res = false;
  2230. if (isset($this->microsite_page_id) && $this->microsite_page_id != NEW_MICROSITE_PAGE) {
  2231. start_transaction();
  2232. // Page plugins..
  2233. $del = new dbdelete("ax_microsite_page_plugin");
  2234. $del->where("microsite_page_id=$this->microsite_page_id");
  2235. $del->execute();
  2236.  
  2237. // Delete associated menuoption..
  2238. if (isset($this->menuoption_id) && $this->menuoption_id != "") {
  2239. $del = new dbdelete("ax_menuoption");
  2240. $del->where("menuoption_id=$this->menuoption_id");
  2241. if ($del->execute()) {
  2242. unset($this->menuoption_id);
  2243. }
  2244. }
  2245.  
  2246. // Delete associated sitepage. Note that we don't delete it
  2247. // if it is a corepage, since those are Axyl system pages..
  2248. if (isset($this->page_id) && $this->page_id != "") {
  2249. if (!$this->corepage) {
  2250. $del = new dbdelete("ax_sitepage");
  2251. $del->where("page_id=$this->page_id");
  2252. }
  2253. unset($this->page_id);
  2254. unset($this->page_path);
  2255. }
  2256.  
  2257. // Delete the page itself..
  2258. $del = new dbdelete("ax_microsite_page");
  2259. $del->where("microsite_page_id=$this->microsite_page_id");
  2260. $del->execute();
  2261.  
  2262. if ( commit() ) {
  2263. $res = true;
  2264. if (!$this->corepage) {
  2265. if (isset($this->page_path) && $this->page_path != "") {
  2266. $DOCROOT = $RESPONSE->site_docroot;
  2267. if (file_exists("$DOCROOT/$this->page_path")) {
  2268. unlink("$DOCROOT/$this->page_path");
  2269. unset($this->page_path);
  2270. }
  2271. }
  2272. }
  2273. }
  2274. }
  2275. return $res;
  2276. } // delete
  2277. // ....................................................................
  2278. /**
  2279. * Update or create the microsite page. Also saves the template data
  2280. * associated with it.
  2281. * @return boolean True if we successfully saved the record
  2282. */
  2283. function save() {
  2284. $res = false;
  2285. if (isset($this->microsite_name) && $this->microsite_name != "") {
  2286. if ($this->microsite_page_id == NEW_MICROSITE_PAGE) {
  2287. $create_new = true;
  2288. $this->microsite_page_id =
  2289. get_next_sequencevalue(
  2290. "seq_microsite_page_id",
  2291. "ax_microsite_page",
  2292. "microsite_page_id"
  2293. );
  2294. $pgQ = new dbinsert("ax_microsite_page");
  2295. $pgQ->set("microsite_page_id", $this->microsite_page_id);
  2296. }
  2297. else {
  2298. $pgQ = new dbupdate("ax_microsite_page");
  2299. $pgQ->where("microsite_page_id=$this->microsite_page_id");
  2300. }
  2301. // Set data..
  2302. $pgQ->set("microsite_name", $this->microsite_name);
  2303. $pgQ->set("page_title", $this->page_title);
  2304. $pgQ->set("cache_seconds", $this->cache_seconds);
  2305. $pgQ->set("corepage", $this->corepage);
  2306. $pgQ->set("microsite_homepage", $this->microsite_homepage);
  2307. $pgQ->set("enabled", $this->enabled);
  2308. $pgQ->set("menuoption_label", $this->menuoption_label);
  2309. $pgQ->set("display_order", $this->display_order);
  2310. if (isset($this->menuoption_id) && $this->menuoption_id != "") {
  2311. $pgQ->set("menuoption_id", $this->menuoption_id);
  2312. }
  2313. else {
  2314. $pgQ->set("menuoption_id", NULLVALUE);
  2315. }
  2316. if (isset($this->microsite_template_id) && $this->microsite_template_id != "") {
  2317. $pgQ->set("microsite_template_id", $this->microsite_template_id);
  2318. }
  2319. else {
  2320. $pgQ->set("microsite_template_id", NULLVALUE);
  2321. }
  2322. if (isset($this->page_id) && $this->page_id != "") {
  2323. $pgQ->set("page_id", $this->page_id);
  2324. }
  2325. else {
  2326. $pgQ->set("page_id", NULLVALUE);
  2327. }
  2328. $res = $pgQ->execute();
  2329. }
  2330. return $res;
  2331. } // save
  2332. // ....................................................................
  2333. /**
  2334. * Publish this microsite page. We create a sitepage record, and save
  2335. * a FK to it, create a menuoption for the page and FK to that, and
  2336. * we create a physical page from the microsite template.
  2337. * @param string $pubdir Web-relative path to dir to save the page file
  2338. * @param string $realdir Path for menuoption - for page access when published
  2339. * @param integer $menu_id ID of the menu to create menuoptions for
  2340. */
  2341. function publishto($pubdir, $realdir, $menu_id) {
  2342. global $RESPONSE, $TEMPLATESDIR, $INCDIR, $CMDIR;
  2343.  
  2344. // Document root for whole site..
  2345. $DOCROOT = $RESPONSE->site_docroot;
  2346.  
  2347. // Have we got a sitepage at all yet..
  2348. if (!$this->corepage) {
  2349. if (!isset($this->page_id) || $this->page_id == "") {
  2350. $this->page_id = get_next_sequencevalue("seq_page_id", "ax_sitepage", "page_id");
  2351. $pgup = new dbinsert("ax_sitepage");
  2352. $pgup->set("page_id", $this->page_id);
  2353. $pgup->set("managed", true);
  2354. $pgup->set("enabled", true);
  2355. debugbr("publish page: inserting new page $this->page_id", DBG_DEBUG);
  2356. }
  2357. else {
  2358. $pgup = new dbupdate("ax_sitepage");
  2359. $pgup->where("page_id=$this->page_id");
  2360. debugbr("publish page: updating existing page $this->page_id", DBG_DEBUG);
  2361. }
  2362. if ($this->page_title != "") {
  2363. $pagename = $this->page_title;
  2364. }
  2365. elseif ($this->menuoption_label != "") {
  2366. $pagename = $this->menuoption_label;
  2367. }
  2368. else {
  2369. $this->pagename = $this->page_id;
  2370. }
  2371. $this->page_path = "$realdir/cm-" . str_replace(" ", "_", strtolower($pagename)) . ".php";
  2372. $phys_path = $DOCROOT . "$pubdir/cm-" . str_replace(" ", "_", strtolower($pagename)) . ".php";
  2373. $pgup->set("page_title", $this->page_title);
  2374. $pgup->set("page_path", $this->page_path);
  2375. $pgup->execute();
  2376.  
  2377. // Always refresh the file itself, and reassert the template
  2378. // and title settings..
  2379. if (file_exists($phys_path)) {
  2380. unlink($phys_path);
  2381. debugbr("publish page: unlinking existing page: $phys_path", DBG_DEBUG);
  2382. }
  2383.  
  2384. // Make a new physical page from the template..
  2385. $template_page = $DOCROOT . "$INCDIR/microsite-template.inc";
  2386. if (isset($this->template)) {
  2387. $page_template = $this->template->template_name;
  2388. }
  2389. else {
  2390. $page_template = "main";
  2391. }
  2392. if (file_exists($template_page)) {
  2393. // Generate a unique layout ID for CM..
  2394. $layout_id = $this->microsite_name . "_"
  2395. . $this->microsite_page_id . "_"
  2396. . str_replace(" ", "_", $this->page_title);
  2397. // Make our new page on disk..
  2398. $newpage = new outputfile($phys_path);
  2399. $newpage->template($template_page);
  2400. $newpage->replace("microsite-template.inc", $this->page_path);
  2401. $newpage->replace("My Layout Title", $this->page_title);
  2402. $newpage->replace("My Template Name", $page_template);
  2403.  
  2404. // Are we caching the page?..
  2405. if ($this->cache_seconds > 0) {
  2406. $newpage->replace(
  2407. "// THIS PAGE IS NOT CACHED (do not remove this line!)",
  2408. "\$RESPONSE->cache($this->cache_seconds);"
  2409. );
  2410. }
  2411.  
  2412. // Plugin content we will insert..
  2413. $PLUGIN_CONTENT = "";
  2414.  
  2415. // Build up our plugins replacement string..
  2416. $q = "SELECT * FROM ax_microsite_page_plugin pp, ax_plugin_content pc";
  2417. $q .= " WHERE pp.microsite_page_id=$this->microsite_page_id";
  2418. $q .= " AND pc.plugin_content=pp.plugin_content";
  2419. $q .= " ORDER BY replace_content";
  2420. $pluginQ = dbrecordset($q);
  2421. if ($pluginQ->hasdata) {
  2422. do {
  2423. $pluginid = $pluginQ->field("plugin_id");
  2424. $plugin_pattern = $pluginQ->field("plugin_pattern");
  2425. $generator = $pluginQ->field("generator");
  2426. $generator_type = $pluginQ->field("generator_type");
  2427. $content_type = $pluginQ->field("plugin_content");
  2428. $replace_content = $pluginQ->istrue("replace_content");
  2429. // Generate the plugin content according to type..
  2430. switch ($generator_type) {
  2431. case "cm":
  2432. $content = new cm_plugin_content(
  2433. $layout_id . "_"
  2434. . strtolower($plugin_pattern)
  2435. );
  2436. if ($content->valid) {
  2437. $plugin_content = $content->render();
  2438. }
  2439. break;
  2440. case "func":
  2441. $content = new func_plugin_content($generator);
  2442. if ($content->valid) {
  2443. $plugin_content = $generator;
  2444. }
  2445. break;
  2446. case "defer":
  2447. $plugin_content = "\"" . addslashes($generator) . "\"";
  2448. break;
  2449. case "lit":
  2450. $plugin_content = "\"" . addslashes($generator) . "\"";
  2451. break;
  2452. case "file":
  2453. $content = new file_plugin_content($generator);
  2454. if (!$content->valid) {
  2455. $content = new file_plugin_content($RESPONSE->site_docroot . $generator);
  2456. }
  2457. if ($content->valid) {
  2458. $plugin_content = "\"" . addslashes($content->render()) . "\"";
  2459. }
  2460. break;
  2461. } // switch
  2462.  
  2463. // Render the complete plugin..
  2464. $s = "\n// Plugin ID #$pluginid\n";
  2465. if ($replace_content && $generator_type != "cm" && $generator_type != "defer") {
  2466. // Replace existing content, if content is immediately available
  2467. // and is not a nullstring..
  2468. $arg = "\"" . strtoupper($plugin_pattern) . "\", \$content";
  2469. $s .= "\$content = $plugin_content;\n";
  2470. $s .= "if (trim(\$content) != \"\") {\n";
  2471. $s .= " \$RESPONSE->plugin_replace($arg);\n";
  2472. $s .= "}";
  2473. }
  2474. else {
  2475. // Append content - ie. the usual plugin methodology..
  2476. $arg = "\"" . strtoupper($plugin_pattern) . "\", " . $plugin_content;
  2477. $s .= "\$RESPONSE->plugin($arg);";
  2478. }
  2479. // Accumulate..
  2480. $PLUGIN_CONTENT .= "$s\n";
  2481.  
  2482. } while ($pluginQ->get_next());
  2483.  
  2484. if ($PLUGIN_CONTENT != "") {
  2485. $newpage->replace(
  2486. "// PLUGIN CONTENT PLACEMENT (do not remove this line!)",
  2487. $PLUGIN_CONTENT
  2488. );
  2489. }
  2490. }
  2491. $newpage->closefile();
  2492. debugbr("publish page: writing the page out to disk: $phys_path", DBG_DEBUG);
  2493. }
  2494. } // if corepage
  2495.  
  2496. // Update or create microsite menuoption..
  2497. if (isset($this->menuoption_id) && $this->menuoption_id != "") {
  2498. $mnuQ = new dbupdate("ax_menuoption");
  2499. $mnuQ->where("menuoption_id=$this->menuoption_id");
  2500. }
  2501. else {
  2502. $this->menuoption_id = get_next_sequencevalue("seq_menuoption_id", "ax_menuoption", "menuoption_id");
  2503. $mnuQ = new dbinsert("ax_menuoption");
  2504. $mnuQ->set("menuoption_id", $this->menuoption_id);
  2505. $mnuQ->set("width", 189); // a default width (px)
  2506. debugbr("publish page: creating new menuoption $this->menuoption_id", DBG_DEBUG);
  2507. }
  2508. $mnuQ->set("menu_id", $menu_id);
  2509. $mnuQ->set("parent_id", 0);
  2510. $mnuQ->set("menu_level", 0);
  2511. $mnuQ->set("label", $this->menuoption_label);
  2512. $mnuQ->set("description", $this->page_title);
  2513. $mnuQ->set("display_order", $this->display_order);
  2514. $mnuQ->set("action", $this->page_path);
  2515. $mnuQ->set("sitepage", $this->page_path);
  2516. $mnuQ->set("active", $this->enabled);
  2517. $mnuQ->set("last_modified", 'now()');
  2518. $mnuQ->execute();
  2519.  
  2520. // Save any new ID's etc..
  2521. $this->save();
  2522. } // publishto
  2523.  
  2524.  
  2525.  
  2526. } // class microsite_page
  2527. // ----------------------------------------------------------------------
  2528.  
  2529. define("NEW_MICROSITE_TEMPLATE", -1);
  2530. /**
  2531. * Microsite Template - a container class.
  2532. * @package microsite
  2533. */
  2534. class microsite_template {
  2535. // Public
  2536. /** Unique microsite template ID */
  2537.  
  2538. var $microsite_template_id;
  2539. /** Template name */
  2540.  
  2541. var $template_name = "";
  2542. /** Template type 'html' or 'wml' */
  2543.  
  2544. var $template_type = "html";
  2545. /** Template content */
  2546.  
  2547. var $template_content = "";
  2548.  
  2549. // Private
  2550. /** The name of the microsite this template is for
  2551. @access private */
  2552. var $microsite_name;
  2553. // ....................................................................
  2554. /**
  2555. * Constructor
  2556. * Create a new microsite_template
  2557. * @param integer $id The unique microsite template ID
  2558. * @param string $microsite_name The name of the microsite this is for
  2559. * @param string $name The name of this temaplate
  2560. * @param string $type The type of this temaplate 'html' or 'wml'
  2561. * @param string $content The actual template content
  2562. */
  2563. function microsite_template($id=NEW_MICROSITE_TEMPLATE, $microsite_name="", $name="", $type="html", $content="") {
  2564. $this->microsite_template_id = $id;
  2565. $this->microsite_name = $microsite_name;
  2566. $this->template_name = $name;
  2567. $this->template_type = $type;
  2568. $this->template_content = $content;
  2569. }// microsite_template
  2570. // ....................................................................
  2571. /**
  2572. * Get the current microsite template, as identified by the ID, from
  2573. * the database.
  2574. * @return boolean True if we successfully got the record
  2575. */
  2576. function get() {
  2577. $res = false;
  2578. if (isset($this->microsite_template_id)
  2579. && $this->microsite_template_id != NEW_MICROSITE_TEMPLATE) {
  2580. $q = "SELECT * FROM ax_microsite_template";
  2581. $q .= " WHERE microsite_template_id=$this->microsite_template_id";
  2582. $tpQ = dbrecordset($q);
  2583. if ($tpQ->hasdata) {
  2584. $this->microsite_name = $tpQ->field("microsite_name");
  2585. $this->template_name = $tpQ->field("template_name");
  2586. $this->template_type = $tpQ->field("template_type");
  2587. $this->template_content = $tpQ->field("template_content");
  2588. $res = true;
  2589. }
  2590. }
  2591. return $res;
  2592. } // get
  2593. // ....................................................................
  2594. /**
  2595. * Update or create the microsite template to the database.
  2596. * @return boolean True if we successfully saved the record
  2597. */
  2598. function save() {
  2599. if (isset($this->microsite_name) && $this->microsite_name != "") {
  2600. if ($this->microsite_template_id == NEW_MICROSITE_TEMPLATE) {
  2601. $this->microsite_template_id =
  2602. get_next_sequencevalue(
  2603. "seq_microsite_template_id",
  2604. "ax_microsite_template",
  2605. "microsite_template_id"
  2606. );
  2607. $mstQ = new dbinsert("ax_microsite_template");
  2608. $mstQ->set("microsite_template_id", $this->microsite_template_id);
  2609. }
  2610. else {
  2611. $mstQ = new dbupdate("ax_microsite_template");
  2612. $mstQ->where("microsite_template_id=$this->microsite_template_id");
  2613. }
  2614. // Set data..
  2615. $mstQ->set("microsite_name", $this->microsite_name);
  2616. $mstQ->set("template_name", $this->template_name);
  2617. $mstQ->set("template_type", $this->template_type);
  2618. $mstQ->set("template_content", $this->template_content);
  2619. return $mstQ->execute();
  2620. }
  2621. } // save
  2622. // ....................................................................
  2623. /**
  2624. * Delete the current microsite template, from the database.
  2625. * @return boolean True if we successfully deleted the record
  2626. */
  2627. function delete() {
  2628. if (isset($this->microsite_template_id)
  2629. && $this->microsite_template_id != NEW_MICROSITE_TEMPLATE) {
  2630. $tpdel = new dbdelete("ax_microsite_template");
  2631. $tpdel->where("microsite_template_id=$this->microsite_template_id");
  2632. return $tpdel->execute();
  2633. }
  2634. } // delete
  2635. // ....................................................................
  2636. /**
  2637. * Publish the template(s) into the given directory. The filename will
  2638. * be as per the Axyl standard, depending on template name and type.
  2639. * @param string $dirpath Path to a directory to publish this template.
  2640. */
  2641. function publishto($pubdir) {
  2642. global $RESPONSE;
  2643. $template_file = "template_" . $this->template_name . "." . strtolower($this->template_type);
  2644. $template_path = $RESPONSE->site_docroot . "$pubdir/$template_file";
  2645. $template = new outputfile($template_path);
  2646. $template->write($this->template_content);
  2647. $template->closefile();
  2648. } // publish
  2649.  
  2650.  
  2651.  
  2652. } // class microsite_template
  2653. // --------------------------------------------------------------------
  2654.  
  2655. ?>

Documentation generated by phpDocumentor 1.3.0RC3