PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/view/view.php

https://gitlab.com/mahara-contrib/janrain-auth
PHP | 297 lines | 221 code | 38 blank | 38 comment | 60 complexity | 4b9859928e6e4b96d4de52d701e87191 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, MIT
  1. <?php
  2. /**
  3. * Mahara: Electronic portfolio, weblog, resume builder and social networking
  4. * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
  5. * http://wiki.mahara.org/Contributors
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * @package mahara
  21. * @subpackage core
  22. * @author Catalyst IT Ltd
  23. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
  24. * @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
  25. *
  26. */
  27. define('INTERNAL', 1);
  28. define('PUBLIC', 1);
  29. define('SECTION_PLUGINTYPE', 'core');
  30. define('SECTION_PLUGINNAME', 'view');
  31. define('SECTION_PAGE', 'view');
  32. require(dirname(dirname(__FILE__)) . '/init.php');
  33. require_once(get_config('libroot') . 'view.php');
  34. require_once(get_config('libroot') . 'collection.php');
  35. require_once('group.php');
  36. safe_require('artefact', 'comment');
  37. // access key for roaming teachers
  38. $mnettoken = $SESSION->get('mnetuser') ? param_alphanum('mt', null) : null;
  39. // access key for logged out users
  40. $usertoken = (is_null($mnettoken) && get_config('allowpublicviews')) ? param_alphanum('t', null) : null;
  41. if ($mnettoken) {
  42. if (!$viewid = get_view_from_token($mnettoken, false)) {
  43. throw new AccessDeniedException(get_string('accessdenied', 'error'));
  44. }
  45. }
  46. else if ($usertoken) {
  47. if (!$viewid = get_view_from_token($usertoken, true)) {
  48. throw new AccessDeniedException(get_string('accessdenied', 'error'));
  49. }
  50. }
  51. else {
  52. $viewid = param_integer('id');
  53. }
  54. $new = param_boolean('new');
  55. if (!can_view_view($viewid)) {
  56. throw new AccessDeniedException(get_string('accessdenied', 'error'));
  57. }
  58. // Feedback list pagination requires limit/offset params
  59. $limit = param_integer('limit', 10);
  60. $offset = param_integer('offset', 0);
  61. $showcomment = param_integer('showcomment', null);
  62. $view = new View($viewid);
  63. // Create the "make feedback private form" now if it's been submitted
  64. if (param_variable('make_public_submit', null)) {
  65. pieform(ArtefactTypeComment::make_public_form(param_integer('comment')));
  66. }
  67. else if (param_variable('delete_comment_submit', null)) {
  68. pieform(ArtefactTypeComment::delete_comment_form(param_integer('comment')));
  69. }
  70. $owner = $view->get('owner');
  71. $viewtype = $view->get('type');
  72. if ($viewtype == 'profile' || $viewtype == 'dashboard' || $viewtype == 'grouphomepage') {
  73. redirect($view->get_url());
  74. }
  75. define('TITLE', $view->get('title'));
  76. $submittedgroup = (int)$view->get('submittedgroup');
  77. if ($USER->is_logged_in() && $submittedgroup && group_user_can_assess_submitted_views($submittedgroup, $USER->get('id'))) {
  78. // The user is a tutor of the group that this view has
  79. // been submitted to, and is entitled to release the view
  80. $submittedgroup = get_record('group', 'id', $submittedgroup);
  81. if ($view->get('submittedtime')) {
  82. $text = get_string('viewsubmittedtogroupon', 'view', get_config('wwwroot') . 'group/view.php?id=' . $submittedgroup->id, hsc($submittedgroup->name), format_date(strtotime($view->get('submittedtime'))));
  83. }
  84. else {
  85. $text = get_string('viewsubmittedtogroup', 'view', get_config('wwwroot') . 'group/view.php?id=' . $submittedgroup->id, hsc($submittedgroup->name));
  86. }
  87. $releaseform = pieform(array(
  88. 'name' => 'releaseview',
  89. 'method' => 'post',
  90. 'plugintype' => 'core',
  91. 'pluginname' => 'view',
  92. 'autofocus' => false,
  93. 'elements' => array(
  94. 'submittedview' => array(
  95. 'type' => 'html',
  96. 'value' => $text,
  97. ),
  98. 'submit' => array(
  99. 'type' => 'submit',
  100. 'value' => get_string('releaseview', 'group'),
  101. ),
  102. ),
  103. ));
  104. }
  105. else {
  106. $releaseform = '';
  107. }
  108. function releaseview_submit() {
  109. global $USER, $SESSION, $view;
  110. $groupid = $view->get('submittedgroup');
  111. $view->release($USER);
  112. $SESSION->add_ok_msg(get_string('viewreleasedsuccess', 'group'));
  113. if ($groupid) {
  114. // The tutor might not have access to the view any more; send
  115. // them back to the group page.
  116. redirect(get_config('wwwroot') . 'group/view.php?id='.$groupid);
  117. }
  118. redirect(get_config('wwwroot') . 'view/view.php?id='.$view->get('id'));
  119. }
  120. $javascript = array('paginator', 'viewmenu', 'jquery', 'artefact/resume/resumeshowhide.js');
  121. $javascript = array_merge($javascript, $view->get_blocktype_javascript());
  122. $extrastylesheets = array('style/views.css');
  123. // If the view has comments turned off, tutors can still leave
  124. // comments if the view is submitted to their group.
  125. if (!empty($releaseform) || ($commenttype = $view->user_comments_allowed($USER))) {
  126. $defaultprivate = !empty($releaseform);
  127. $moderate = isset($commenttype) && $commenttype === 'private';
  128. $addfeedbackform = pieform(ArtefactTypeComment::add_comment_form($defaultprivate, $moderate));
  129. $extrastylesheets[] = 'style/jquery.rating.css';
  130. $javascript[] = 'jquery.rating';
  131. }
  132. if ($USER->is_logged_in()) {
  133. $objectionform = pieform(objection_form());
  134. if ($notrudeform = $view->notrude_form()) {
  135. $notrudeform = pieform($notrudeform);
  136. }
  137. }
  138. $viewbeingwatched = (int)record_exists('usr_watchlist_view', 'usr', $USER->get('id'), 'view', $viewid);
  139. $feedback = ArtefactTypeComment::get_comments($limit, $offset, $showcomment, $view);
  140. // Set up theme
  141. $viewtheme = $view->get('theme');
  142. if ($viewtheme && $THEME->basename != $viewtheme) {
  143. $THEME = new Theme($viewtheme);
  144. }
  145. $stylesheets = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">');
  146. $can_edit = $USER->can_edit_view($view) && !$submittedgroup && !$view->is_submitted();
  147. $smarty = smarty(
  148. $javascript,
  149. $stylesheets,
  150. array(),
  151. array(
  152. 'stylesheets' => $extrastylesheets,
  153. 'sidebars' => false,
  154. )
  155. );
  156. $javascript = <<<EOF
  157. var viewid = {$viewid};
  158. addLoadEvent(function () {
  159. paginator = {$feedback->pagination_js}
  160. });
  161. EOF;
  162. // collection top navigation
  163. if ($collection = $view->get('collection')) {
  164. $shownav = $collection->get('navigation');
  165. if ($shownav) {
  166. if ($views = $collection->get('views')) {
  167. if (count($views['views']) > 1) {
  168. $smarty->assign_by_ref('collection', array_chunk($views['views'], 5));
  169. }
  170. }
  171. }
  172. }
  173. $smarty->assign('INLINEJAVASCRIPT', $javascript);
  174. $smarty->assign('new', $new);
  175. $smarty->assign('viewid', $viewid);
  176. $smarty->assign('viewtype', $viewtype);
  177. $smarty->assign('feedback', $feedback);
  178. $smarty->assign('owner', $owner);
  179. $smarty->assign('tags', $view->get('tags'));
  180. if (get_config('viewmicroheaders')) {
  181. $smarty->assign('microheaders', true);
  182. $smarty->assign('microheadertitle', $collection ? hsc($collection->get('name')) : $view->display_title(true, false));
  183. if ($can_edit) {
  184. $smarty->assign('visitstring', $view->visit_message());
  185. if ($new) {
  186. $microheaderlinks = array(
  187. array(
  188. 'name' => get_string('back'),
  189. 'url' => get_config('wwwroot') . 'view/blocks.php?id=' . $viewid . '&new=1',
  190. 'type' => 'reply',
  191. ),
  192. );
  193. }
  194. else {
  195. $microheaderlinks = array(
  196. array(
  197. 'name' => get_string('editthisview', 'view'),
  198. 'image' => $THEME->get_url('images/edit.gif'),
  199. 'url' => get_config('wwwroot') . 'view/blocks.php?id=' . $viewid,
  200. ),
  201. );
  202. }
  203. $smarty->assign('microheaderlinks', $microheaderlinks);
  204. }
  205. if ($USER->is_logged_in()) {
  206. if (!empty($_SERVER['HTTP_REFERER'])) {
  207. $page = get_config('wwwroot') . 'view/view.php?id=' . $viewid . ($new ? '&new=1' : '');
  208. if ($_SERVER['HTTP_REFERER'] != $page) {
  209. $smarty->assign('backurl', $_SERVER['HTTP_REFERER']);
  210. }
  211. }
  212. }
  213. }
  214. else if ($can_edit) {
  215. $smarty->assign('editurl', get_config('wwwroot') . 'view/blocks.php?id=' . $viewid . ($new ? '&new=1' : ''));
  216. }
  217. $title = hsc(TITLE);
  218. if (!get_config('viewmicroheaders')) {
  219. $title = $collection ? hsc($collection->get('name')) : $view->display_title();
  220. $smarty->assign('maintitle', $title);
  221. }
  222. // Provide a link for roaming teachers to return
  223. if ($mnetviewlist = $SESSION->get('mnetviewaccess')) {
  224. if (isset($mnetviewlist[$view->get('id')])) {
  225. $returnurl = $SESSION->get('mnetuserfrom');
  226. require_once(get_config('docroot') . 'api/xmlrpc/lib.php');
  227. if ($peer = get_peer_from_instanceid($SESSION->get('authinstance'))) {
  228. $smarty->assign('mnethost', array(
  229. 'name' => $peer->name,
  230. 'url' => $returnurl ? $returnurl : $peer->wwwroot,
  231. ));
  232. }
  233. }
  234. }
  235. $smarty->assign('viewdescription', $view->get('description'));
  236. $smarty->assign('viewcontent', $view->build_columns());
  237. $smarty->assign('releaseform', $releaseform);
  238. if (isset($addfeedbackform)) {
  239. $smarty->assign('enablecomments', 1);
  240. $smarty->assign('addfeedbackform', $addfeedbackform);
  241. }
  242. if (isset($objectionform)) {
  243. $smarty->assign('objectionform', $objectionform);
  244. $smarty->assign('notrudeform', $notrudeform);
  245. }
  246. $smarty->assign('viewbeingwatched', $viewbeingwatched);
  247. if ($owner && $owner == $USER->get('id')) {
  248. if ($tutorgroupdata = group_get_user_course_groups()) {
  249. if (!$view->get('submittedgroup') && !$view->get('submittedhost')) {
  250. $smarty->assign(
  251. 'view_group_submission_form',
  252. view_group_submission_form($view->get('id'), $tutorgroupdata, 'view')
  253. );
  254. }
  255. }
  256. }
  257. $smarty->display('view/view.tpl');
  258. mahara_log('views', "$viewid"); // Log view visits
  259. ?>