PageRenderTime 29ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/ASTRA_Demo_Server/udrive/www/astra/interact/modules/dropbox/mark.php

https://github.com/shafiqissani/ASTRA-College-Website
PHP | 382 lines | 220 code | 119 blank | 43 comment | 31 complexity | 8d9fab3cb1550b7266a795b1eb889c64 MD5 | raw file
  1. <?php
  2. // +------------------------------------------------------------------------+
  3. // | This file is part of Interact. |
  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 (version 2) |
  8. // | |
  9. // | This program is distributed in the hope that it will be useful, but |
  10. // | WITHOUT ANY WARRANTY; without even the implied warranty of |
  11. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
  12. // | General Public License for more details. |
  13. // | |
  14. // | You should have received a copy of the GNU General Public License |
  15. // | along with this program; if not, you can view it at |
  16. // | http://www.opensource.org/licenses/gpl-license.php |
  17. // +------------------------------------------------------------------------+
  18. /**
  19. * Mark files
  20. *
  21. * Displays form for marking a file in dropbox
  22. *
  23. * @package Dropbox
  24. * @author Glen Davies <glen.davies@cce.ac.nz>
  25. * @copyright Christchurch College of Education 2001
  26. * @version $Id: mark.php,v 1.30 2007/07/30 01:56:58 glendavies Exp $
  27. *
  28. */
  29. /**
  30. * Include main system config file
  31. */
  32. require_once('../../local/config.inc.php');
  33. //get language strings
  34. require_once($CONFIG['LANGUAGE_CPATH'].'/dropbox_strings.inc.php');
  35. //set variables
  36. $space_key = get_space_key();
  37. if ($_GET['module_key']) {
  38. $module_key = $_GET['module_key'];
  39. $group_key = $_GET['group_key'];
  40. $file_key = $_GET['file_key'];
  41. } else {
  42. $module_key = $_POST['module_key'];
  43. $group_key = $_POST['group_key'];
  44. $file_key = $_POST['file_key'];
  45. $file_name = $_POST['file_name'];
  46. $item_key = $_POST['item_key'];
  47. $user_key = $_POST['user_key'];
  48. $status_key = $_POST['status_key'];
  49. }
  50. $link_key = get_link_key($module_key,$space_key);
  51. check_variables(true,true,true);
  52. //check to see if user is logged in. If not refer to Login page.
  53. $access_levels = authenticate();
  54. $accesslevel_key = $access_levels['accesslevel_key'];
  55. $group_access = $access_levels['groups'];
  56. $page_details = get_page_details($space_key,$link_key);
  57. if (isset($_POST['action'])) {
  58. switch($_POST['action']) {
  59. //if we are adding a new file form input needs to be checked
  60. case modify:
  61. $comments = $_POST['comments'];
  62. $status_key = $_POST['status_key'];
  63. $file = $_FILES['file']['tmp_name'];
  64. $new_file_name = $_FILES['file']['name'];
  65. $item_key = $_POST['item_key'];
  66. $user_key = $_POST['user_key'];
  67. $grade_key = $_POST['grade_key'];
  68. //if there is a gradebook link to this dropbox and gradebook grade selected
  69. //then update gradebook
  70. if ($item_key!='' && $grade_key!='' && $user_key!='') {
  71. require_once('../gradebook/lib.inc.php');
  72. $gradebook = new Interactgradebook($space_key, $module_key, $group_key, $is_admin, $gradebook_strings);
  73. $gradebook->modifygrade($item_key, $user_key, $grade_key, $comments);
  74. }
  75. if ($file!='' && $file!='none') {
  76. $description = ereg_replace('<b> - ('.$dropbox_strings['annotated_tag'].')</b>', "", $_POST['description']);
  77. $description = substr($description,0,30).'<b> - ('.$dropbox_strings['annotated_tag'].')</b>';
  78. $file_path = get_dropbox_file_path($module_key);
  79. $save_path = $CONFIG['MODULE_FILE_SAVE_PATH'].'/dropbox/'.$file_path;
  80. unlink($save_path.'/'.$file_name);
  81. $file_name = ereg_replace("\.[a-zA-Z]*", "", $file_name);
  82. $file_name = ereg_replace("_annotated", "", $file_name);
  83. $file_name = substr($file_name,0,30);
  84. $file_name = $file_name.'_annotated';
  85. if (preg_match("/\./",$new_file_name)) {
  86. $new_ext = ereg_replace("^.+\\.([^.]+)$", "\\1", $new_file_name);
  87. $new_ext = '.'.$new_ext;
  88. } else {
  89. $new_ext='';
  90. }
  91. $file_name = $file_name.$new_ext;
  92. move_uploaded_file($file,$save_path.'/'.$file_name);
  93. } else {
  94. $description = $_POST['description'];
  95. }
  96. $date_modified = $CONN->DBDate(date('Y-m-d H:i:s'));
  97. $sql = "UPDATE {$CONFIG['DB_PREFIX']}dropbox_files SET comments='$comments',status='$status_key',description='$description', date_status_changed=$date_modified, gradebook_item_key='$item_key', filename='$file_name' where file_key=$file_key";
  98. if ($CONN->Execute($sql) === false) {
  99. $message = 'There was an error modifying your file: '.$CONN->ErrorMsg().' <br />';
  100. } else {
  101. header("Location: {$CONFIG['FULL_URL']}/modules/dropbox/dropbox.php?space_key=$space_key&module_key=$module_key");
  102. }
  103. }
  104. }
  105. $description_error = sprint_error($errors['description']);
  106. $file_error = sprint_error($errors['file']);
  107. $sql = "SELECT file_key,description,{$CONFIG['DB_PREFIX']}dropbox_file_status.name, first_name, last_name ,{$CONFIG['DB_PREFIX']}dropbox_files.date_added,comments,{$CONFIG['DB_PREFIX']}dropbox_files.status,{$CONFIG['DB_PREFIX']}dropbox_files.filename, {$CONFIG['DB_PREFIX']}dropbox_files.user_key, {$CONFIG['DB_PREFIX']}dropbox_files.gradebook_item_key FROM {$CONFIG['DB_PREFIX']}dropbox_files,{$CONFIG['DB_PREFIX']}dropbox_file_status,{$CONFIG['DB_PREFIX']}users WHERE {$CONFIG['DB_PREFIX']}dropbox_files.user_key={$CONFIG['DB_PREFIX']}users.user_key AND {$CONFIG['DB_PREFIX']}dropbox_files.status={$CONFIG['DB_PREFIX']}dropbox_file_status.status_key AND (file_key='$file_key')";
  108. require_once($CONFIG['TEMPLATE_CLASS_PATH'].'/template.inc');
  109. $t = new Template($CONFIG['TEMPLATES_PATH']);
  110. $t->set_file(array(
  111. 'header' => 'header.ihtml',
  112. 'navigation' => 'navigation.ihtml',
  113. 'mark' => 'dropboxes/mark.ihtml',
  114. 'footer' => 'footer.ihtml'
  115. ));
  116. set_common_template_vars($space_key,$module_key,$page_details, $message, $accesslevel_key, $group_accesslevel);
  117. //generate the editor components
  118. if (!class_exists('InteractHtml')) {
  119. require_once('../includes/lib/html.inc.php');
  120. }
  121. $html = new InteractHtml();
  122. $html->setTextEditor($t, $_SESSION['auto_editor'], 'comments');
  123. $t->parse('CONTENTS', 'header', true);
  124. $rs = $CONN->Execute($sql);
  125. if (!is_object($objDates)) {
  126. if (!class_exists('InteractDate')) {
  127. require_once($CONFIG['BASE_PATH'].'/includes/lib/date.inc.php');
  128. }
  129. $objDates = new InteractDate();
  130. }
  131. while (!$rs->EOF) {
  132. $file_key = $rs->fields[0];
  133. $description = $rs->fields[1];
  134. $status = $rs->fields[2];
  135. $username = $rs->fields[3].' '.$rs->fields[4];
  136. $date_added = $objDates->formatDate($CONN->UnixTimeStamp($rs->fields[5]),'short', true);
  137. $comments = $rs->fields[6];
  138. $status_key = $rs->fields[7];
  139. $file_name = $rs->fields[8];
  140. $user_key = $rs->fields[9];
  141. if (!$item_key && $rs->fields[10]!=0) {
  142. $item_key = $rs->fields[10];
  143. }
  144. $file_path = get_dropbox_file_path($module_key);
  145. $t->set_var('FILE_KEY',$file_key);
  146. $t->set_var('DESCRIPTION2',$description);
  147. $t->set_var('ORIGINAL_DESCRIPTION',$description);
  148. $t->set_var('COMMENTS',$comments);
  149. $t->set_var('USER_NAME',$username);
  150. $t->set_var('DATE_ADDED',$date_added);
  151. $t->set_var('FILE_NAME',$file_name);
  152. $t->set_var('FILE_PATH',$file_path);
  153. if( $CONN->GetOne("SELECT type_key FROM {$CONFIG['DB_PREFIX']}dropbox_settings WHERE module_key='$module_key'") =='3') {
  154. $domname=ereg_replace("https?://([^/]+)","\\1",$CONFIG['SERVER_URL']);
  155. $filedownloadpath=$CONFIG['PATH'].$CONFIG['VIEWFILE_PATH'].'recordings/'.$domname.'/modules/dropbox/';
  156. $file_url=$filedownloadpath.'/'.$file_path.'/'.$file_name.'.flv';
  157. $t->set_var('FILE_STUFF','{DESCRIPTION2}<br />
  158. <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="66" height="33" id="av" align="middle">
  159. <param name="allowScriptAccess" value="sameDomain" />
  160. <param name="movie" value="{PATH}/includes/players/AVPLAYER.swf" />
  161. <param name="FlashVars" value="sndname={URL}" />
  162. <param name="quality" value="high" />
  163. <embed src="{PATH}/includes/players/AVPLAYER.swf" flashvars="sndname={URL}" quality="high" width="66" height="33" name="av" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
  164. </object>');
  165. $t->set_block('mark','AmendBlock');
  166. $t->clear_var('AmendBlock');
  167. } else {
  168. $file_url = $CONFIG['MODULE_FILE_VIEW_PATH'].$space_key.'/dropbox/'.$file_path.'/'.$file_name;
  169. $t->set_var('FILE_STUFF','<a href="{URL}">
  170. {DESCRIPTION2}</a>');
  171. }
  172. $t->set_var('URL',$file_url);
  173. $t->parse('FILE','FILE_STUFF');
  174. $rs->MoveNext();
  175. }
  176. $rs->Close();
  177. //see of there are any gradebook links to this dropbox
  178. $t->set_block('mark', 'gradebookBlock', 'GBlock');
  179. require_once('../gradebook/lib.inc.php');
  180. $gradebook = new Interactgradebook($space_key, $module_key, $group_key, $is_admin, $gradebook_strings);
  181. if ($item_key!='' && $item_key!=0) {
  182. $rs = $CONN->Execute("SELECT scale_key FROM {$CONFIG['DB_PREFIX']}gradebook_items WHERE item_key='$item_key'");
  183. while (!$rs->EOF) {
  184. $scale_key = $rs->fields[0];
  185. $rs->MoveNext();
  186. }
  187. $grade_data = $gradebook->getgradeData($item_key, $user_key);
  188. $grade_menu = $gradebook->makegradeMenu($item_key, $grade_data['grade_key'], $scale_key);
  189. $t->set_var('GRADE_MENU',$grade_menu);
  190. $gradebook_item_sql = "SELECT name,item_key FROM {$CONFIG['DB_PREFIX']}gradebook_items WHERE content_module_key='$module_key'";
  191. $item_menu = make_menu($gradebook_item_sql,'item_key',$item_key,'1',false);
  192. $t->set_var('ITEM_MENU',$item_menu);
  193. $t->set_var('ACTION','modify');
  194. $t->set_var('GRADE_BOOK_STRING',$dropbox_strings['gradebook']);
  195. $t->Parse('GBlock', 'gradebookBlock', true);
  196. } else {
  197. $rs = $CONN->Execute("SELECT item_key, scale_key FROM {$CONFIG['DB_PREFIX']}gradebook_items WHERE content_module_key='$module_key'");
  198. if ($rs->EOF) {
  199. $t->set_var('GBlock','');
  200. $t->set_var('ACTION','modify');
  201. } else {
  202. if ($rs->RecordCount()>1) {
  203. $gradebook_item_sql = "SELECT name,item_key FROM {$CONFIG['DB_PREFIX']}gradebook_items WHERE content_module_key='$module_key'";
  204. $item_menu = make_menu($gradebook_item_sql,'item_key',$item_key,'1',false);
  205. $t->set_var('ITEM_MENU',$item_menu);
  206. $t->set_var('GRADE_MENU','');
  207. $t->set_var('ACTION','get_grades');
  208. $t->set_var('GRADE_BOOK_STRING',$dropbox_strings['select_gradebook_item']);
  209. $t->set_var('GET_GRADES_BUTTON','<input type="submit" name="Submit" value="'.$dropbox_strings['get_grades'].'">');
  210. } else {
  211. while (!$rs->EOF) {
  212. $item_key = $rs->fields[0];
  213. $scale_key = $rs->fields[1];
  214. $rs->MoveNext();
  215. }
  216. $rs->Close();
  217. $grade_data = $gradebook->getgradeData($item_key, $user_key);
  218. $grade_menu = $gradebook->makegradeMenu($item_key, $grade_data['grade_key'], $scale_key);
  219. $t->set_var('GRADE_MENU',$grade_menu);
  220. $t->set_var('ACTION','modify');
  221. $t->set_var('GRADE_BOOK_STRING',$dropbox_strings['gradebook']);
  222. }
  223. $t->Parse('GBlock', 'gradebookBlock', true);
  224. }
  225. }
  226. $t->set_var('STATUS_STRING',$general_strings['status']);
  227. $t->set_var('COMMENTS_STRING',$general_strings['comments']);
  228. $t->set_var('OPTIONAL_STRING',$general_strings['optional']);
  229. $t->set_var('SUBMIT_STRING',$general_strings['submit']);
  230. $t->set_var('AMMENDED_STRING',$dropbox_strings['ammended']);
  231. $t->set_var('BACK_LINK_STRING',$general_strings['back_to'].' '. $page_details['module_name']);
  232. get_navigation();
  233. $status_sql = "select name, status_key from {$CONFIG['DB_PREFIX']}dropbox_file_status order by name";
  234. $status_menu = make_menu($status_sql,'status_key',$status_key,'4');
  235. $t->set_var('STATUS_MENU',$status_menu);
  236. $t->set_var('SPACE_KEY',$space_key);
  237. $t->set_var('MODULE_KEY',$module_key);
  238. $t->set_var('ITEM_KEY',$item_key);
  239. $t->set_var('USER_KEY',$user_key);
  240. $t->parse('CONTENTS', 'mark', true);
  241. $t->parse('CONTENTS', 'footer', true);
  242. print_headers();
  243. $t->p('CONTENTS');
  244. $CONN->Close();
  245. exit;
  246. /**
  247. * Return a dropbox file path
  248. *
  249. * @return string $file_path path to drop box directory
  250. */
  251. function get_dropbox_file_path($module_key)
  252. {
  253. global $CONN, $CONFIG;
  254. $sql = "SELECT file_path FROM {$CONFIG['DB_PREFIX']}dropbox_settings WHERE module_key='$module_key'";
  255. $rs = $CONN->Execute($sql);
  256. while (!$rs->EOF) {
  257. $file_path = $rs->fields[0];
  258. $rs->MoveNext();
  259. }
  260. $rs->Close();
  261. return $file_path;
  262. } //end get_dropbox_file_path
  263. ?>