Source for file admin.php

Documentation is available at admin.php

  1. <?php
  2.  
  3. class de_linkm_collector_admin {
  4.  
  5. var $_topic;
  6. var $_config;
  7. var $_categories;
  8. var $_parameters;
  9. var $_modeessage;
  10. var $errcode;
  11. var $errstr;
  12. var $_mode;
  13. var $_l10n;
  14. var $_l10n_midcom;
  15. var $_datamanager;
  16. var $_local_toolbar;
  17. var $_topic_toolbar;
  18.  
  19. function de_linkm_collector_admin ($topic, $config) {
  20. $this->_config = $GLOBALS['de_linkm_collector__default_config'];
  21. $this->_config->store($config->get_all());
  22. $this->_topic = $topic;
  23. $this->errcode = MIDCOM_ERROK;
  24. $this->errstr = "";
  25. $this->_message = "";
  26. $this->_categories = Array();
  27. $this->_mode = "index";
  28. $i18n =& $GLOBALS["midcom"]->get_service("i18n");
  29. $this->_l10n =& $i18n->get_l10n("de.linkm.collector");
  30. $this->_l10n_midcom =& $i18n->get_l10n("midcom");
  31. $this->_datamanager = null;
  32. if (trim($this->_config->get("parameters")) != "") {
  33. $snippet = mgd_get_snippet_by_path ($this->_config->get("parameters"));
  34. if (!$snippet)
  35. die ("CRITICAL: Could not load Snippet " . $this->_config->get("parameters"));
  36. eval ("\$params = Array ( $snippet->code \n );");
  37. $this->_parameters = $params;
  38. } else {
  39. $this->_parameters = Array();
  40. }
  41. $this->_local_toolbar =& $GLOBALS['midcom_admin_content_toolbar_component'];
  42. $this->_topic_toolbar =& $GLOBALS['midcom_admin_content_toolbar_main'];
  43. }
  44.  
  45. function get_metadata() {
  46. return Array(
  47. MIDCOM_META_CREATOR => 0,
  48. MIDCOM_META_CREATED => 0,
  49. MIDCOM_META_EDITOR => 0,
  50. MIDCOM_META_EDITED => 0
  51. );
  52. }
  53.  
  54. function can_handle ($argc, $argv) {
  55. if ($argc == 0)
  56. return true;
  57. return false;
  58. }
  59.  
  60. function handle ($argc, $argv) {
  61. debug_push("de.linkm.collector::handle");
  62. /* Add the topic configuration item */
  63. $this->_topic_toolbar->add_item(Array(
  64. MIDCOM_TOOLBAR_URL => '',
  65. MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('component configuration'),
  66. MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('component configuration helptext'),
  67. MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_folder-properties.png',
  68. MIDCOM_TOOLBAR_ENABLED => true
  69. ));
  70. $this->_datamanager = new midcom_helper_datamanager ($this->_config->get("schemadb"));
  71. if ($this->_datamanager == false) {
  72. $this->errstr = "Could not create layout, see Debug Log";
  73. $this->errcode = MIDCOM_ERRCRIT;
  74. debug_add($this->errstr, MIDCOM_LOGCRIT);
  75. return false;
  76. }
  77. if ($this->_datamanager->init($this->_topic) == false) {
  78. $this->errstr = "Could not create layout, see Debug Log";
  79. $this->errcode = MIDCOM_ERRCRIT;
  80. debug_add($this->errstr, MIDCOM_LOGCRIT);
  81. return false;
  82. }
  83. $this->_datamanager->process_form();
  84. $result = true;
  85. if (array_key_exists("form_create_submit", $_REQUEST))
  86. $result = $this->_create_topic($_REQUEST["form_url"],$_REQUEST["form_name"]);
  87. if (array_key_exists("form_move_submit", $_REQUEST))
  88. $result = $this->_move_element($_REQUEST["form_id"], $_REQUEST["form_dest"]);
  89. $this->_load_categories();
  90. debug_pop();
  91. return $result;
  92. }
  93.  
  94. function show () {
  95. $GLOBALS["view_l10n"] =& $this->_l10n;
  96. $GLOBALS["view_l10n_midcom"] =& $this->_l10n_midcom;
  97. $GLOBALS["view_config"] =& $this->_config;
  98. $GLOBALS["view_categories"] =& $this->_categories;
  99. $GLOBALS["view_name"] = $this->_topic->extra;
  100. $GLOBALS["view_datamanager"] =& $this->_datamanager;
  101. $GLOBALS["view_message"] =& $this->_message;
  102. switch ($this->_mode) {
  103. case "index":
  104. $this->_show_index();
  105. break;
  106. default:
  107. die ("We should not reach this line. Collector mode was " . $this->_mode . ", which is not supported.");
  108. break;
  109. }
  110. }
  111. function _show_index() {
  112. midcom_show_style("admin-index");
  113. }
  114. function _load_categories() {
  115. $this->_categories = Array();
  116. $contextid = $GLOBALS["midcom"]->get_current_context();
  117. $nap = new midcom_helper_nav($contextid);
  118. $subnodeids = $nap->list_nodes($this->_topic->id);
  119. if (count($subnodeids)>0)
  120. foreach ($subnodeids as $id) {
  121. $topic = mgd_get_topic($id);
  122. if ($topic->parameter("de.linkm.collector","id") != $this->_config->get("id"))
  123. continue;
  124. $node = $nap->get_node($id);
  125. $this->_categories[$id] = Array(
  126. "name" => $node[MIDCOM_NAV_NAME],
  127. "url" => substr($node[MIDCOM_NAV_URL],0,-1)
  128. );
  129. }
  130. }
  131.  
  132. function _create_topic ($url, $desc) {
  133. $topic = mgd_get_topic();
  134. $topic->up = $this->_topic->id;
  135. $topic->owner = $this->_topic->owner;
  136. $topic->name = $url;
  137. $topic->extra = $desc;
  138. if (!$topic->create()) {
  139. $this->errcode = MIDCOM_ERR_INTERNAL;
  140. $this->errstr = $this->_l10n->get("could not create category") . ": " . mgd_errstr();
  141. return false;
  142. }
  143. $topic->parameter("de.linkm.collector","id",$this->_config->get("id"));
  144. $topic->parameter("midcom","component",$this->_config->get("component"));
  145. $topic->parameter("midcom","style",$this->_config->get("style"));
  146. foreach ($this->_parameters as $key => $value)
  147. $topic->parameter($this->_config->get("component"), $key, $value);
  148. return true;
  149. }
  150.  
  151. function _move_element ($id, $dest) {
  152. $article = mgd_get_article ($id);
  153. if (!$article) {
  154. $this->_message = $this->_l10n->get("move source element not found") . ": " . mgd_errstr();
  155. return true;
  156. }
  157. $topic = mgd_get_topic($article->topic);
  158. if (!$topic) {
  159. die("de_linkm_collector_admin::_move_element: Could not load article $id's Topic. This is definitly weird: "
  160. . mgd_errstr());
  161. }
  162. if ($topic->parameter("de.linkm.collector","id") != $this->_config->get("id")) {
  163. $this->_message = $this->_l10n->get("move source element in unkown category");
  164. return true;
  165. }
  166. $topic = mgd_get_topic($dest);
  167. if (!$topic) {
  168. die("de_linkm_collector_admin::_move_element: Could not load destination Topic $dest. This is definitly weird: "
  169. . mgd_errstr());
  170. }
  171. if ($topic->parameter("de.linkm.collector","id") != $this->_config->get("id")) {
  172. die("de_linkm_collector_admin::_move_element: Destination topic resembels no known category. This is definitly weird.");
  173. return true;
  174. }
  175. if (!mgd_move_article ($id, $dest)) {
  176. $this->_message = $this->_l10n->get("move failed") . ": " . mgd_errstr();
  177. return true;
  178. }
  179. $this->_message = $this->_l10n->get("move successful");
  180. return true;
  181. }
  182. }
  183.  
  184. ?>

Documentation generated on Mon, 21 Nov 2005 18:11:20 +0100 by phpDocumentor 1.3.0RC3