Source for file admin.php

Documentation is available at admin.php

  1. <?php
  2.  
  3. class pl_olga_files_admin {
  4.  
  5. var $_debug_prefix;
  6.  
  7. var $_config;
  8. var $_topic;
  9. var $_view;
  10.  
  11. var $_article;
  12. var $_attachment;
  13. var $_layout;
  14.  
  15. var $errcode;
  16. var $errstr;
  17.  
  18.  
  19. function pl_olga_files_admin($topic, $config) {
  20.  
  21. $this->_debug_prefix = "pl.olga.files admin::";
  22.  
  23. $this->_config = $config;
  24. $this->_topic = $topic;
  25. $this->_view = "";
  26.  
  27. $this->_article = false;
  28. $this->_attachment = false;
  29. $this->_layout = false;
  30.  
  31. $this->errcode = MIDCOM_ERROK;
  32. $this->errstr = "";
  33. }
  34.  
  35.  
  36. function can_handle($argc, $argv) {
  37.  
  38. debug_push($this->_debug_prefix . "prepare");
  39.  
  40. if ($argc > 2)
  41. return false;
  42. if ($argc == 0)
  43. return true;
  44. switch ($argv[0]) {
  45. case "view":
  46. case "edit":
  47. return true;
  48. case "delete":
  49. case "create":
  50. default:
  51. return false;
  52. }
  53. }
  54.  
  55.  
  56. function handle($argc, $argv) {
  57.  
  58. debug_push($this->_debug_prefix . "handle");
  59.  
  60. if ($argc == 0) {
  61. $this->_view = "welcome";
  62. debug_add ("viewport = welcome");
  63. debug_pop ();
  64. return true;
  65. }
  66.  
  67. switch ($argv[0]) {
  68.  
  69. case "view":
  70. $result = $this->_init_view($argv[1]);
  71. break;
  72.  
  73. case "edit":
  74. $result = $this->_init_edit();
  75. break;
  76.  
  77. case "delete":
  78. $result = $this->_init_delete($argv[1]);
  79. break;
  80.  
  81. case "create":
  82. $result = $this->_init_create(($argc==2) ? $argv[1] : null);
  83. break;
  84.  
  85. default:
  86. $result = false;
  87. break;
  88. }
  89.  
  90. debug_pop();
  91. return $result;
  92. }
  93.  
  94.  
  95. function _init_view ($id) {
  96.  
  97. global $pl_olga_files_layouts;
  98.  
  99. $article = mgd_get_article($id);
  100. if (!$article) {
  101. debug_add("Article $id could not be loaded: " . mgd_errstr(),
  102. MIDCOM_LOG_INFO);
  103. $this->errstr = "Article $id could not be loaded: " . mgd_errstr();
  104. $this->errcode = MIDCOM_ERRNOTFOUND;
  105. return false;
  106. }
  107. $this->_article = $article;
  108. $GLOBALS["pl_olga_files_nap_activeid"] = $id;
  109.  
  110. $this->_layout = new midcom_helper_datamanager($pl_olga_files_layouts);
  111. if (! $this->_layout) {
  112. $this->errstr = "Could not create layout, see Debug Log";
  113. $this->errcode = MIDCOM_ERRCRIT;
  114. debug_add($this->errstr, MIDCOM_LOG_CRIT);
  115. return false;
  116. }
  117.  
  118. if (! $this->_layout->init($this->_article)) {
  119. $this->errstr = "Could not initialize layout, see Debug Log";
  120. $this->errcode = MIDCOM_ERRCRIT;
  121. debug_add($this->errstr, MIDCOM_LOG_CRIT);
  122. return false;
  123. }
  124. /* Can't tell why this is here, disabling for now (tn)
  125. * Reason: process_form gets called twice, which is bad. (in _edit or so also)
  126. * Have to look after this though. (tn)
  127. switch ($this->_layout->process_form()) {
  128.  
  129. case MIDCOM_DATAMGR_EDITING:
  130. case MIDCOM_DATAMGR_SAVED:
  131. case MIDCOM_DATAMGR_CANCELLED:
  132. $this->_view = "view";
  133. return true;
  134. case MIDCOM_DATAMGR_FAILED:
  135. $this->errstr = "Datamanager: " . $GLOBALS["midcom_errstr"];
  136. $this->errcode = MIDCOM_ERRCRIT;
  137. return false;
  138. }
  139. */
  140. $this->_view = "view";
  141. return true;
  142. }
  143.  
  144.  
  145. function _init_edit() {
  146.  
  147. if (!isset ($_REQUEST)) {
  148. $this->errstr = "No request data found.";
  149. $this->errcode = MIDCOM_ERRCRIT;
  150. debug_add($this->errstr, MIDCOM_LOG_INFO);
  151. return false;
  152. }
  153.  
  154. if (array_key_exists ("pl_olga_files_submit", $_REQUEST)) {
  155. if (! $this->_topic->parameter("pl.olga.files","root_path",$_REQUEST["pl_olga_files_root_path"]) ) {
  156. $error = mgd_errstr();
  157. if ($error != "Object does not exist") {
  158. $this->errstr = "Could not save parameter Root Path: " . $error;
  159. $this->errcode = MIDCOM_ERRAUTH;
  160. debug_add($this->errstr, MIDCOM_LOG_INFO);
  161. return false;
  162. }
  163. }
  164. }
  165. $this->_view = "welcome";
  166. return true;
  167. }
  168.  
  169.  
  170. function _init_create($id = null) {
  171.  
  172. if (is_null($id)) {
  173. $midgard = mgd_get_midgard();
  174.  
  175. $article = mgd_get_article();
  176. $article->topic = $this->_topic->id;
  177. $article->author = $midgard->user;
  178. $id = $article->create();
  179. if (! $id) {
  180. $this->errstr = "Could not create Article: " . mgd_errstr();
  181. $this->errcode = MIDCOM_ERRFORBIDDEN;
  182. return false;
  183. }
  184. else
  185. debug_add("Article $id created");
  186.  
  187. $article = mgd_get_article($id);
  188.  
  189. if (array_key_exists("pl_olga_files_createlayout", $_REQUEST)) {
  190. debug_add("creating parameter layout for article");
  191. $article->parameter("midcom.helper.datamanager", "layout",
  192. $_REQUEST["pl_olga_files_createlayout"]);
  193. }
  194.  
  195. $protocol = array_key_exists("SSL_PROTOCOL", $_SERVER) ?
  196. "https" : "http";
  197. $location = "Location: $protocol://" . $_SERVER['HTTP_HOST']
  198. . $midgard->uri . "/$id";
  199. debug_add("Relocating to $location");
  200. header($location);
  201. exit();
  202. }
  203. else {
  204. if (!$this->_init_view($id))
  205. return false;
  206.  
  207. switch ($this->_layout->process_form()) {
  208.  
  209. case MIDCOM_DATAMGR_EDITING:
  210. $this->_view = "edit";
  211. $GLOBALS["pl_olga_files_nap_activeid"] = $id;
  212. return true;
  213.  
  214. case MIDCOM_DATAMGR_SAVED:
  215. $this->_view = "view";
  216. $GLOBALS["pl_olga_files_nap_activeid"] = $id;
  217. return true;
  218.  
  219. case MIDCOM_DATAMGR_CANCELLED:
  220. $this->_view = "welcome";
  221. $GLOBALS["pl_olga_files_nap_activeid"] = false;
  222. return $this->_delete_record($id);
  223. case MIDCOM_DATAMGR_FAILED:
  224. $this->errstr = "Datamanager: " . $GLOBALS["midcom_errstr"];
  225. $this->errcode = MIDCOM_ERRCRIT;
  226. return false;
  227. }
  228. }
  229. }
  230.  
  231.  
  232. function _init_delete ($id) {
  233.  
  234. if (!$this->_init_view($id))
  235. return false;
  236. if (array_key_exists("pl_olga_files_deleteok", $_REQUEST)) {
  237. return $this->_delete_record($id);
  238. }
  239. else
  240. if (array_key_exists("pl_olga_files_deletecancel", $_REQUEST)) {
  241. $GLOBALS["pl_olga_files_nap_activeid"] = $id;
  242. $this->_view = "view";
  243. }
  244. else {
  245. $GLOBALS["pl_olga_files_nap_activeid"] = $id;
  246. $this->_view = "deletecheck";
  247. }
  248. return true;
  249. }
  250.  
  251.  
  252. function show() {
  253.  
  254. // get l10n libraries
  255. $i18n =& $GLOBALS["midcom"]->get_service("i18n");
  256. $GLOBALS["view_l10n"] = $i18n->get_l10n("pl.olga.files");
  257. $GLOBALS["view_l10n_midcom"] = $i18n->get_l10n("midcom");
  258. eval("\$result = \$this->_show_$this->_view();");
  259. return $result;
  260. }
  261.  
  262.  
  263. function _show_welcome() {
  264.  
  265. global $midcom;
  266. global $title;
  267.  
  268. global $pl_olga_files_layouts;
  269.  
  270. global $view_layouts;
  271.  
  272. global $view_config;
  273.  
  274. $view_config = $this->_config;
  275.  
  276. midcom_show_style("admin_welcome");
  277. }
  278.  
  279.  
  280. function _show_view() {
  281.  
  282. global $midcom;
  283. global $view;
  284. global $view_mgr;
  285. global $view_id;
  286. global $view_title;
  287. global $view_descriptions;
  288.  
  289. $view_descriptions = $this->_layout->get_fieldnames();
  290. $view_title = "Edit Article";
  291. $view_mgr = $this->_layout;
  292. $view = $this->_layout->get_array();
  293. $view_id = $this->_article->id;
  294.  
  295. midcom_show_style("admin_view");
  296. }
  297.  
  298.  
  299. function _show_edit (){
  300.  
  301. global $midcom;
  302. global $view;
  303. global $view_id;
  304. global $view_title;
  305. global $view_descriptions;
  306.  
  307. $view_descriptions = $this->_layout->get_fieldnames();
  308. $view_title = "Article";
  309. $view = $this->_layout;
  310. $view_id = $this->_article->id;
  311.  
  312. midcom_show_style("admin_edit");
  313. }
  314.  
  315.  
  316. function _show_deletecheck() {
  317.  
  318. global $midcom;
  319. global $view;
  320. global $view_id;
  321. global $view_title;
  322. global $view_descriptions;
  323.  
  324. $view_descriptions = $this->_layout->get_fieldnames();
  325. $view_title = "Article";
  326. $view = $this->_layout->get_array();
  327. $view_id = $this->_article->id;
  328.  
  329. midcom_show_style("admin_deletecheck");
  330. }
  331.  
  332.  
  333. function _delete_record($id) {
  334.  
  335. $article = mgd_get_article ($id);
  336. if (!mgd_delete_extensions($article)) {
  337. $this->errstr = "Could not delete Article $id extensions: "
  338. . mgd_errstr();
  339. $this->errcode = MIDCOM_ERRFORBIDDEN;
  340. debug_add($this->_errstr, MIDCOM_LOG_ERROR);
  341. return false;
  342. }
  343.  
  344. if (!$article->delete()) {
  345. $this->errstr = "Could not delete Article $id: ".mgd_errstr();
  346. $this->errcode = MIDCOM_ERRFORBIDDEN;
  347. debug_add($this->_errstr, MIDCOM_LOG_ERROR);
  348. return false;
  349. }
  350. $this->_view = "welcome";
  351. $GLOBALS["pl_olga_files_nap_activeid"] = false;
  352. return true;
  353. }
  354.  
  355.  
  356.  
  357. function get_metadata() {
  358.  
  359. if ($this->_article) {
  360. return array (
  361. MIDCOM_META_CREATOR => $this->_article->creator,
  362. MIDCOM_META_EDITOR => $this->_article->revisor,
  363. MIDCOM_META_CREATED => $this->_article->created,
  364. MIDCOM_META_EDITED => $this->_article->revised
  365. );
  366. }
  367. else
  368. return false;
  369. }
  370.  
  371.  
  372. function get_current_leaf() {
  373.  
  374. if ($this->_article)
  375. return $this->_article->id;
  376. else
  377. return false;
  378. }
  379.  
  380. } // admin
  381.  
  382. ?>

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