PageRenderTime 58ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/community/www/modules/module_journal/module_journal.class.php

https://github.com/svn2github/efront-lms
PHP | 896 lines | 656 code | 238 blank | 2 comment | 216 complexity | 7b49525705bff53ce9d1792662069fa5 MD5 | raw file
Possible License(s): BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0
  1. <?php
  2. class module_journal extends EfrontModule{
  3. public function getName(){
  4. return _JOURNAL_NAME;
  5. }
  6. public function getPermittedRoles(){
  7. return array("student", "professor", "administrator");
  8. }
  9. public function getModule(){
  10. return true;
  11. }
  12. public function getSmartyTpl(){
  13. $currentUser = $this->getCurrentUser();
  14. $rules = $this->getRules();
  15. $smarty = $this->getSmartyVar();
  16. if($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student'){
  17. $currentLesson = $this->getCurrentLesson();
  18. $currentLessonID = $currentLesson->lesson['id'];
  19. if(!isset($_SESSION['module_journal_dimension']) ||
  20. (count($_GET) == 2 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal') ||
  21. (count($_GET) == 3 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal' &&
  22. $_GET['new_lesson_id'] == $currentLessonID)){
  23. $_SESSION['module_journal_dimension'] = 'small';
  24. }
  25. if(!isset($_SESSION['module_journal_entries_from']) ||
  26. (count($_GET) == 2 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal') ||
  27. (count($_GET) == 3 && $_GET['ctg'] == 'module' && $_GET['op'] == 'module_journal' &&
  28. $_GET['new_lesson_id'] == $currentLessonID)){
  29. $_SESSION['module_journal_entries_from'] = '-1';
  30. }
  31. if(isset($_SESSION['module_journal_scroll_position']))
  32. $smarty->assign("T_JOURNAL_SCROLL_POSITION", $_SESSION['module_journal_scroll_position']);
  33. $smarty->assign("T_JOURNAL_DIMENSIONS", $_SESSION['module_journal_dimension']);
  34. $smarty->assign("T_JOURNAL_ENTRIES_FROM", $_SESSION['module_journal_entries_from']);
  35. $entries = $this->getEntries($currentUser->user['login'], $_SESSION['module_journal_entries_from']);
  36. global $popup;
  37. (isset($popup) && $popup == 1) ? $popup_ = '&popup=1' : $popup_ = '';
  38. }
  39. $smarty->assign("T_JOURNAL_BASEURL", $this->moduleBaseUrl);
  40. $smarty->assign("T_JOURNAL_BASELINK", $this->moduleBaseLink);
  41. if(isset($_GET['edit_allow_export']) && $_GET['edit_allow_export'] == '1' && isset($_GET['allow'])){
  42. try{
  43. $object = eF_getTableData("module_journal_settings", "id", "name='export'");
  44. eF_updateTableData("module_journal_settings", array("value" => $_GET['allow']), "id=".$object[0]['id']);
  45. }
  46. catch(Exception $e){
  47. handleAjaxExceptions($e);
  48. }
  49. exit;
  50. }
  51. if(isset($_GET['edit_professor_preview']) && $_GET['edit_professor_preview'] == '1' && isset($_GET['preview'])){
  52. try{
  53. $object = eF_getTableData("module_journal_settings", "id", "name='preview'");
  54. eF_updateTableData("module_journal_settings", array("value" => $_GET['preview']), "id=".$object[0]['id']);
  55. }
  56. catch(Exception $e){
  57. handleAjaxExceptions($e);
  58. }
  59. exit;
  60. }
  61. if(isset($_GET['dimension']) && eF_checkParameter($_GET['dimension'], 'string')){
  62. $smarty->assign("T_JOURNAL_DIMENSIONS", $_GET['dimension']);
  63. $_SESSION['module_journal_dimension'] = $_GET['dimension'];
  64. }
  65. if(isset($_GET['entries_from'])){
  66. $smarty->assign("T_JOURNAL_ENTRIES_FROM", $_GET['entries_from']);
  67. $_SESSION['module_journal_entries_from'] = $_GET['entries_from'];
  68. }
  69. if(isset($_GET['delete_rule']) && eF_checkParameter($_GET['delete_rule'], 'id') && in_array($_GET['delete_rule'], array_keys($rules))){
  70. try{
  71. eF_deleteTableData("module_journal_rules", "id=".$_GET['delete_rule']);
  72. }
  73. catch(Exception $e){
  74. handleAjaxExceptions($e);
  75. }
  76. exit;
  77. }
  78. if(isset($_GET['deactivate_rule']) && eF_checkParameter($_GET['deactivate_rule'], 'id') &&
  79. in_array($_GET['deactivate_rule'], array_keys($rules))){
  80. eF_updateTableData("module_journal_rules", array('active' => 0), "id=".$_GET['deactivate_rule']);
  81. }
  82. if(isset($_GET['activate_rule']) && eF_checkParameter($_GET['activate_rule'], 'id') &&
  83. in_array($_GET['activate_rule'], array_keys($rules))){
  84. eF_updateTableData("module_journal_rules", array('active' => 1), "id=".$_GET['activate_rule']);
  85. }
  86. if(isset($_GET['delete_entry']) && eF_checkParameter($_GET['delete_entry'], 'id') &&
  87. in_array($_GET['delete_entry'], array_keys($entries))){
  88. $object = eF_getTableData("module_journal_entries", "users_LOGIN", "id=".$_GET['delete_entry']);
  89. if($object[0]['users_LOGIN'] != $_SESSION['s_login']){
  90. eF_redirect($this->moduleBaseUrl."&message=".urlencode(_JOURNAL_NOACCESS).$popup_);
  91. exit;
  92. }
  93. eF_deleteTableData("module_journal_entries", "id=".$_GET['delete_entry']);
  94. }
  95. if(isset($_GET['saveas']) && $_GET['saveas'] == 'pdf'){
  96. $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);
  97. $pdf->SetCreator(PDF_CREATOR);
  98. $pdf->SetAuthor(PDF_AUTHOR);
  99. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  100. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  101. $pdf->setFontSubsetting(false);
  102. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  103. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  104. $pdf->setHeaderFont(Array('Freeserif', 'I', 11));
  105. $pdf->setFooterFont(Array('Freeserif', '', 8));
  106. $pdf->setHeaderData('', '', '', _JOURNAL_NAME);
  107. $pdf->AliasNbPages();
  108. $pdf->AddPage();
  109. $pdf->SetFont('Freeserif', '', 10);
  110. $pdf->SetTextColor(0, 0, 0);
  111. foreach($entries as $entry){
  112. $pdf->Cell(0, 0, $entry['entry_date_formatted'], 0, 1, L, 0);
  113. $pdf->writeHTML('<br/>', true, false, true, false, '');
  114. $pdf->writeHTML($entry['entry_body'], true, false, true, false, '');
  115. $pdf->writeHTML('<div style="height: 5px;"></div>', true, false, true, false, '');
  116. $pdf->writeHTML('<hr>', true, false, true, false, '');
  117. }
  118. $fileNamePdf = "journal.pdf";
  119. header("Content-type: application/pdf");
  120. header("Content-disposition: attachment; filename=".$fileNamePdf);
  121. echo $pdf->Output('', 'S');
  122. exit(0);
  123. }
  124. if(isset($_GET['saveas']) && $_GET['saveas'] == 'doc'){
  125. include(dirname(__FILE__)."/classes/html_to_doc.inc.php");
  126. $entriesHTML = '';
  127. foreach($entries as $entry){
  128. $entriesHTML .= $entry['entry_date_formatted'];
  129. $entriesHTML .= $entry['entry_body'];
  130. $entriesHTML .= '<hr><br/>';
  131. }
  132. $htmltodoc = new HTML_TO_DOC();
  133. $htmltodoc->createDoc($entriesHTML, "journal", true);
  134. exit(0);
  135. }
  136. if(isset($_GET['saveas']) && $_GET['saveas'] == 'txt'){
  137. include(dirname(__FILE__)."/classes/html2text.inc");
  138. header('Content-Type: text/plain');
  139. header('Content-Disposition: attachment; filename="journal.txt"');
  140. $entriesHTML = '';
  141. foreach($entries as $entry){
  142. $entriesHTML .= $entry['entry_date_formatted'];
  143. $entriesHTML .= $entry['entry_body'];
  144. $entriesHTML .= '<p></p>';
  145. $entriesHTML .= '_______________________________________________________';
  146. $entriesHTML .= '<p></p>';
  147. }
  148. $htmlToText = new Html2Text($entriesHTML, 100);
  149. $entriesHTMLtext = $htmlToText->convert();
  150. echo $entriesHTMLtext;
  151. exit(0);
  152. }
  153. if(isset($_GET['check_students_journals']) && $_GET['check_students_journals'] == '1'){
  154. $professorJournalLessons = $this->getProfessorJournalLessons($currentUser);
  155. $journalLessonsStudents = $this->getJournalLessonsStudents($professorJournalLessons);
  156. $smarty->assign("T_JOURNAL_STUDENTS", $journalLessonsStudents);
  157. }
  158. if(isset($_GET['preview_journal']) && $_GET['preview_journal'] == '1' &&
  159. isset($_GET['student']) && eF_checkParameter($_GET['student'], 'login')){
  160. $userLogin = $_GET['student'];
  161. $professorJournalLessons = $this->getProfessorJournalLessons($currentUser);
  162. $studentEntries = $this->getStudentEntries($userLogin, $professorJournalLessons);
  163. $smarty->assign("T_JOURNAL_STUDENT_ENTRIES", $studentEntries);
  164. }
  165. if(isset($_REQUEST['autosave']) && $_REQUEST['autosave'] == "1" && isset($_REQUEST['entry_body']) && isset($_REQUEST['edit_entry'])){
  166. if($_REQUEST['edit_entry'] != "-1"){
  167. $object = eF_getTableData("module_journal_entries", "lessons_ID", "id=".$_GET['edit_entry']);
  168. $fields = array(
  169. "entry_body" => $_REQUEST['entry_body'],
  170. "entry_date" => date('Y').'-'.date('m').'-'.date('d').' '.date('H').':'.date('i').':'.date('s'),
  171. "lessons_ID" => $object[0]['lessons_ID'],
  172. "users_LOGIN" => $currentUser->user['login'],
  173. );
  174. eF_updateTableData("module_journal_entries", $fields, "id=".$_REQUEST['edit_entry']);
  175. }
  176. else{
  177. $fields = array(
  178. "entry_body" => $_REQUEST['entry_body'],
  179. "entry_date" => date('Y').'-'.date('m').'-'.date('d').' '.date('H').':'.date('i').':'.date('s'),
  180. "lessons_ID" => $currentLessonID,
  181. "users_LOGIN" => $currentUser->user['login'],
  182. );
  183. $id = eF_insertTableData("module_journal_entries", $fields);
  184. if($id){
  185. if(isset($_SESSION['module_journal_autosave_entry'])){
  186. $this->deleteAutoSaveEntry();
  187. $_SESSION['module_journal_autosave_entry'] = $id;
  188. }
  189. else{
  190. $_SESSION['module_journal_autosave_entry'] = $id;
  191. }
  192. }
  193. }
  194. exit(0);
  195. }
  196. if(isset($_REQUEST['show_right']) && $_REQUEST['show_right'] == "1" && isset($_REQUEST['entry_body']) && $_REQUEST['entry_body'] != ""
  197. && isset($_REQUEST['edit']) && isset($_REQUEST['edit_entry'])){
  198. if(isset($_SESSION['module_journal_show_right_entry']))
  199. unset($_SESSION['module_journal_show_right_entry']);
  200. $_SESSION['module_journal_show_right_entry'] = $_REQUEST['entry_body'];
  201. }
  202. if(isset($_REQUEST['hide_right']) && $_REQUEST['hide_right'] == "1" && isset($_REQUEST['entry_body']) && $_REQUEST['entry_body'] != ""
  203. && isset($_REQUEST['edit']) && isset($_REQUEST['edit_entry'])){
  204. if(isset($_SESSION['module_journal_hide_right_entry']))
  205. unset($_SESSION['module_journal_hide_right_entry']);
  206. $_SESSION['module_journal_hide_right_entry'] = $_REQUEST['entry_body'];
  207. }
  208. if(isset($_REQUEST['hide_left']) && $_REQUEST['hide_left'] == "1" && isset($_REQUEST['entry_body']) && $_REQUEST['entry_body'] != ""
  209. && isset($_REQUEST['edit']) && isset($_REQUEST['edit_entry'])){
  210. if(isset($_SESSION['module_journal_hide_left_entry']))
  211. unset($_SESSION['module_journal_hide_left_entry']);
  212. $_SESSION['module_journal_hide_left_entry'] = $_REQUEST['entry_body'];
  213. }
  214. if(isset($_REQUEST['scroll_position']) && eF_checkParameter($_REQUEST['scroll_position'], 'id')){
  215. $_SESSION['module_journal_scroll_position'] = $_REQUEST['scroll_position'];
  216. }
  217. if(isset($_GET['add_rule']) ||
  218. (isset($_GET['edit_rule']) && eF_checkParameter($_GET['edit_rule'], 'id') && in_array($_GET['edit_rule'], array_keys($rules)))){
  219. if($_SESSION['s_type'] != "administrator")
  220. eF_redirect($this->moduleBaseUrl."&message=".urlencode(_JOURNAL_NOACCESS));
  221. isset($_GET['add_rule']) ? $postTarget = "&add_rule=1" : $postTarget = "&edit_rule=".$_GET['edit_rule'];
  222. global $load_editor;
  223. $load_editor = true;
  224. $form = new HTML_QuickForm("add_edit_rule_form", "post", $this->moduleBaseUrl.$postTarget, "", null, true);
  225. $form->addElement('text', 'title', _TITLE, 'class="inputText" style="width:498px;"');
  226. $form->addRule('title', _THEFIELD.' "'._TITLE.'" '._ISMANDATORY, 'required', null, 'client');
  227. $form->addElement('textarea', 'description', _DESCRIPTION,
  228. 'class="inputContentTextarea simpleEditor" style="width:500px;height:20em;"');
  229. $form->addElement('submit', 'submit', _SUBMIT, 'class="flatButton"');
  230. if(isset($_GET['edit_rule'])){
  231. $editRule = $rules[$_GET['edit_rule']];
  232. $form->setDefaults($editRule);
  233. }
  234. if($form->isSubmitted() && $form->validate()){
  235. $values = $form->exportValues();
  236. $fields = array(
  237. "title" => $values['title'],
  238. "description" => $values['description']
  239. );
  240. if($values['description'] == ''){
  241. $message = _JOURNAL_EMPTY_RULE_DESCRIPTION;
  242. if(isset($_GET['add_rule']))
  243. eF_redirect($this->moduleBaseUrl."&message=".$message."&message_type=failure&add_rule=1");
  244. else
  245. eF_redirect($this->moduleBaseUrl."&message=".$message."&message_type=failure&edit_rule=".$_GET['edit_rule']);
  246. }
  247. if(isset($_GET['add_rule'])){
  248. if(eF_insertTableData("module_journal_rules", $fields)){
  249. $message = _JOURNAL_RULE_SUCCESSFULLY_ADDED;
  250. eF_redirect($this->moduleBaseUrl."&message=".$message."&message_type=success");
  251. }
  252. else{
  253. $message = _JOURNAL_RULE_ADD_PROBLEM;
  254. eF_redirect($this->moduleBaseUrl."&message=".$message."&message_type=failure");
  255. }
  256. }
  257. else{
  258. if(eF_updateTableData("module_journal_rules", $fields, "id=".$_GET['edit_rule'])){
  259. $message = _JOURNAL_RULE_SUCCESSFULLY_EDITED;
  260. eF_redirect($this->moduleBaseUrl."&message=".$message."&message_type=success");
  261. }
  262. else{
  263. $message = _JOURNAL_RULE_EDIT_PROBLEM;
  264. eF_redirect($this->moduleBaseUrl."&message=".$message."&message_type=failure");
  265. }
  266. }
  267. }
  268. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
  269. $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
  270. $form->setRequiredNote(_REQUIREDNOTE);
  271. $form->accept($renderer);
  272. $smarty->assign('T_JOURNAL_ADD_EDIT_RULE_FORM', $renderer->toArray());
  273. }
  274. else{
  275. $rules = $this->getRules();
  276. $smarty->assign("T_JOURNAL_RULES", $rules);
  277. $object = eF_getTableData("module_journal_settings", "value", "name='export'");
  278. $smarty->assign("T_JOURNAL_ALLOW_EXPORT", $object[0]['value']);
  279. $object = eF_getTableData("module_journal_settings", "value", "name='preview'");
  280. $smarty->assign("T_JOURNAL_ALLOW_PROFESSOR_PREVIEW", $object[0]['value']);
  281. if($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student'){
  282. $activeRules = $this->getRules(true);
  283. $smarty->assign("T_JOURNAL_ACTIVE_RULES", $activeRules);
  284. $entries = $this->getEntries($currentUser->user['login'], $_SESSION['module_journal_entries_from']);
  285. $smarty->assign("T_JOURNAL_ENTRIES", $entries);
  286. $journalLessons = $this->getJournalLessons($currentUser->user['login']);
  287. $smarty->assign("T_JOURNAL_LESSONS", $journalLessons);
  288. /* */
  289. global $load_editor;
  290. $load_editor = true;
  291. if(isset($_GET['edit_entry']) && $_GET['edit_entry'] != '-1')
  292. $postTarget = "&edit_entry=".$_GET['edit_entry'];
  293. else
  294. $postTarget = "&add_entry=1";
  295. if(isset($_GET['hide_right']) && $_GET['hide_right'] == '1'){
  296. $editorStyle = array(
  297. 'small' => 'width:588px; height:320px;',
  298. 'medium' => 'width:673px; height:375px;',
  299. 'large' => 'width:759px; height:430px;'
  300. );
  301. }
  302. else{
  303. $editorStyle = array(
  304. 'small' => 'width:300px; height:320px;',
  305. 'medium' => 'width:344px; height:375px;',
  306. 'large' => 'width:388px; height:430px;'
  307. );
  308. }
  309. $form = new HTML_QuickForm("add_edit_entry_form", "post", $this->moduleBaseUrl.$postTarget, "", null, true);
  310. $form->addElement('textarea', 'entry_body', _DESCRIPTION,
  311. 'class="inputContentTextarea simpleEditor" style="'.$editorStyle[$_SESSION['module_journal_dimension']].'"');
  312. if(isset($_GET['edit_entry']) && $_GET['edit_entry'] != '-1')
  313. $form->addElement('submit', 'submit', _UPDATE.' '._JOURNAL_ENTRY, 'class="flatButton"');
  314. else
  315. $form->addElement('submit', 'submit', _SAVE.' '._JOURNAL_ENTRY, 'class="flatButton"');
  316. if(isset($_GET['edit_entry']) && $_GET['edit_entry'] != '-1'){
  317. $editEntry = $entries[$_GET['edit_entry']];
  318. $form->setDefaults($editEntry);
  319. if(!in_array($_GET['edit_entry'], array_keys($entries)))
  320. eF_redirect($this->moduleBaseUrl."&message=".urlencode(_JOURNAL_NOACCESS).$popup_);
  321. $object = eF_getTableData("module_journal_entries", "lessons_ID, users_LOGIN, entry_date","id=".$_GET['edit_entry']);
  322. if($object[0]['users_LOGIN'] != $_SESSION['s_login'])
  323. eF_redirect($this->moduleBaseUrl."&message=".urlencode(_JOURNAL_NOACCESS).$popup_);
  324. }
  325. if(isset($_GET['show_left']) && $_GET['show_left'] == '1' && isset($_GET['edit']) && isset($_GET['edit_entry'])){
  326. if(isset($_SESSION['module_journal_hide_left_entry'])){
  327. $form->setDefaults(array("entry_body" => $_SESSION['module_journal_hide_left_entry']));
  328. unset($_SESSION['module_journal_hide_left_entry']);
  329. }
  330. }
  331. if(isset($_GET['show_right']) && $_GET['show_right'] == '1' && isset($_GET['edit']) && isset($_GET['edit_entry'])){
  332. if(isset($_SESSION['module_journal_show_right_entry'])){
  333. $form->setDefaults(array("entry_body" => $_SESSION['module_journal_show_right_entry']));
  334. unset($_SESSION['module_journal_show_right_entry']);
  335. }
  336. }
  337. if(isset($_GET['hide_right']) && $_GET['hide_right'] == '1' && isset($_GET['edit']) && isset($_GET['edit_entry'])){
  338. if(isset($_SESSION['module_journal_hide_right_entry'])){
  339. $form->setDefaults(array("entry_body" => $_SESSION['module_journal_hide_right_entry']));
  340. unset($_SESSION['module_journal_hide_right_entry']);
  341. }
  342. }
  343. if($form->isSubmitted() && $form->validate()){
  344. $values = $form->exportValues();
  345. isset($_GET['add_entry']) ? $lessonID = $currentLessonID : $lessonID = $object[0]['lessons_ID'];
  346. if(isset($_GET['add_entry']))
  347. $date = date('Y').'-'.date('m').'-'.date('d').' '.date('H').':'.date('i').':'.date('s');
  348. else
  349. $date = $object[0]['entry_date'];
  350. $fields = array(
  351. "entry_body" => $values['entry_body'],
  352. "entry_date" => $date,
  353. "lessons_ID" => $lessonID,
  354. "users_LOGIN" => $currentUser->user['login'],
  355. );
  356. if($values['entry_body'] == ''){
  357. $message = _JOURNAL_EMPTY_ENTRY_BODY;
  358. eF_redirect($this->moduleBaseUrl."&message=".$message."&message_type=failure".$popup_);
  359. }
  360. if(isset($_GET['add_entry'])){
  361. if(eF_insertTableData("module_journal_entries", $fields)){
  362. if(isset($_SESSION['module_journal_autosave_entry']))
  363. $this->deleteAutoSaveEntry();
  364. $message = _JOURNAL_ENTRY_SUCCESSFULLY_ADDED;
  365. eF_redirect($this->moduleBaseUrl."&message=".$message."&message_type=success".$popup_);
  366. }
  367. else{
  368. $message = _JOURNAL_ENTRY_ADD_PROBLEM;
  369. eF_redirect($this->moduleBaseUrl."&message=".$message."&message_type=failure".$popup_);
  370. }
  371. }
  372. else{
  373. if(eF_updateTableData("module_journal_entries", $fields, "id=".$_GET['edit_entry'])){
  374. $message = _JOURNAL_ENTRY_SUCCESSFULLY_EDITED;
  375. eF_redirect($this->moduleBaseUrl."&message=".$message."&message_type=success".$popup_);
  376. }
  377. else{
  378. $message = _JOURNAL_ENTRY_EDIT_PROBLEM;
  379. eF_redirect($this->moduleBaseUrl."&message=".$message."&message_type=failure".$popup_);
  380. }
  381. }
  382. }
  383. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
  384. $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
  385. $form->setRequiredNote(_REQUIREDNOTE);
  386. $form->accept($renderer);
  387. $smarty->assign('T_JOURNAL_ADD_ENTRY_FORM', $renderer->toArray());
  388. if($currentUser->getRole($this->getCurrentLesson()) == 'professor'){
  389. $popupInfo[] = array(
  390. 'text' => _JOURNAL_POPUP_INFO,
  391. 'image' => $this->moduleBaseLink.'images/info.png',
  392. 'href' => $this->moduleBaseUrl.'&popup_info=1&popup=1',
  393. 'onClick' => "eF_js_showDivPopup('"._JOURNAL_POPUP_INFO."', 2)",
  394. 'target' => 'POPUP_FRAME',
  395. 'id' => 'popup_info'
  396. );
  397. $smarty->assign("T_JOURNAL_POPUP_INFO", $popupInfo);
  398. }
  399. }
  400. }
  401. if($currentUser->getType() == 'administrator')
  402. return $this->moduleBaseDir."module_journal_admin.tpl";
  403. else if($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student'){
  404. if(isset($_GET['hide_left']) && $_GET['hide_left'] == '1')
  405. return $this->moduleBaseDir."module_journal_user_right.tpl";
  406. if(isset($_GET['hide_right']) && $_GET['hide_right'] == '1')
  407. return $this->moduleBaseDir."module_journal_user_left.tpl";
  408. return $this->moduleBaseDir."module_journal_user.tpl";
  409. }
  410. }
  411. public function isLessonModule(){
  412. return true;
  413. }
  414. public function onInstall(){
  415. eF_executeNew("DROP TABLE IF EXISTS `module_journal_rules`");
  416. $t1 = eF_executeNew("CREATE TABLE IF NOT EXISTS `module_journal_rules` (
  417. `id` int(11) NOT NULL AUTO_INCREMENT,
  418. `title` varchar(255) NOT NULL,
  419. `description` text NOT NULL,
  420. `active` tinyint(1) NOT NULL DEFAULT '1',
  421. PRIMARY KEY (`id`)
  422. ) ENGINE=MyISAM DEFAULT CHARSET=utf8");
  423. eF_executeNew("DROP TABLE IF EXISTS `module_journal_entries`");
  424. $t2 = eF_executeNew("CREATE TABLE IF NOT EXISTS `module_journal_entries` (
  425. `id` int(11) NOT NULL AUTO_INCREMENT,
  426. `entry_body` text NOT NULL,
  427. `entry_date` datetime NOT NULL,
  428. `lessons_ID` int(11) NOT NULL,
  429. `users_LOGIN` varchar(255) NOT NULL,
  430. PRIMARY KEY (`id`)
  431. ) ENGINE=MyISAM DEFAULT CHARSET=utf8");
  432. eF_executeNew("DROP TABLE IF EXISTS `module_journal_settings`");
  433. $t3 = eF_executeNew("CREATE TABLE IF NOT EXISTS `module_journal_settings` (
  434. `id` int(11) NOT NULL AUTO_INCREMENT,
  435. `name` varchar(45) NOT NULL,
  436. `value` tinyint(1) NOT NULL,
  437. PRIMARY KEY (`id`)
  438. ) ENGINE=MyISAM DEFAULT CHARSET=utf8");
  439. eF_insertTableData("module_journal_settings", array('name' => 'export', 'value' => 1));
  440. eF_insertTableData("module_journal_settings", array('name' => 'preview', 'value' => 1));
  441. return($t1 && $t2 && $t3);
  442. }
  443. public function onUninstall(){
  444. $t1 = eF_executeNew("DROP TABLE IF EXISTS `module_journal_rules`");
  445. $t2 = eF_executeNew("DROP TABLE IF EXISTS `module_journal_entries`");
  446. $t3 = eF_executeNew("DROP TABLE IF EXISTS `module_journal_settings`");
  447. return($t1 && $t2 && $t3);
  448. }
  449. public function onUpgrade(){
  450. $t1 = eF_executeNew("CREATE TABLE IF NOT EXISTS `module_journal_settings` (
  451. `id` int(11) NOT NULL AUTO_INCREMENT,
  452. `name` varchar(45) NOT NULL,
  453. `value` tinyint(1) NOT NULL,
  454. PRIMARY KEY (`id`)
  455. ) ENGINE=MyISAM DEFAULT CHARSET=utf8");
  456. $resultNew = eF_getTableData("module_journal_settings", "*");
  457. if(count($resultNew) == 0){
  458. $result = eF_getTableData("module_journal_allow_export", "*");
  459. eF_insertTableData("module_journal_settings", array('name' => 'export', 'value' => $result[0]['allow']));
  460. eF_insertTableData("module_journal_settings", array('name' => 'preview', 'value' => 1));
  461. }
  462. $t2 = eF_executeNew("DROP TABLE IF EXISTS `module_journal_allow_export`");
  463. return($t1 && $t2);
  464. }
  465. public function getCenterLinkInfo(){
  466. return array(
  467. 'title' => _JOURNAL_NAME,
  468. 'image' => $this->moduleBaseDir.'images/journal_logo.png',
  469. 'link' => $this->moduleBaseUrl
  470. );
  471. }
  472. public function getLessonCenterLinkInfo(){
  473. return array(
  474. 'title' => _JOURNAL_NAME,
  475. 'image' => $this->moduleBaseDir.'images/journal_logo.png',
  476. 'link' => $this->moduleBaseUrl
  477. );
  478. }
  479. public function getSidebarLinkInfo(){
  480. $currentLessonMenu = array(array(
  481. 'id' => 'journal_link_1',
  482. 'title' => _JOURNAL_NAME,
  483. 'image' => $this->moduleBaseDir.'images/journal_logo16',
  484. 'eFrontExtensions' => '1',
  485. 'link' => $this->moduleBaseUrl)
  486. );
  487. return array("current_lesson" => $currentLessonMenu);
  488. }
  489. public function getLinkToHighlight(){
  490. return 'journal_link_1';
  491. }
  492. public function getNavigationLinks(){
  493. $currentUser = $this->getCurrentUser();
  494. if($currentUser->getType() == 'administrator'){
  495. if(isset($_GET['add_rule'])){
  496. return array(
  497. array('title' => _HOME, 'link' => $currentUser->getType().".php?ctg=control_panel"),
  498. array('title' => _JOURNAL_NAME, 'link' => $this->moduleBaseUrl),
  499. array('title' => _JOURNAL_ADD_RULE2, 'link' => $_SERVER['REQUEST_URI'])
  500. );
  501. }
  502. else if(isset($_GET['edit_rule'])){
  503. return array(
  504. array('title' => _HOME, 'link' => $currentUser->getType().".php?ctg=control_panel"),
  505. array('title' => _JOURNAL_NAME, 'link' => $this->moduleBaseUrl),
  506. array('title' => _JOURNAL_EDIT_RULE, 'link' => $_SERVER['REQUEST_URI'])
  507. );
  508. }
  509. else{
  510. return array(
  511. array('title' => _HOME, 'link' => $currentUser->getType().".php?ctg=control_panel"),
  512. array('title' => _JOURNAL_NAME, 'link' => $this->moduleBaseUrl)
  513. );
  514. }
  515. }
  516. else{
  517. $smarty = $this -> getSmartyVar();
  518. $currentLesson = $this->getCurrentLesson();
  519. $currentUserRole = $currentUser->getRole($currentLesson);
  520. $onClick = "location='".$currentUserRole.".php?ctg=lessons';top.sideframe.hideAllLessonSpecific();";
  521. if(isset($_GET['check_students_journals'])){
  522. return array(
  523. array('title' => _HOME, 'link' => $smarty->get_template_vars('T_HOME_LINK')),
  524. array('title' => $currentLesson->lesson['name'], 'link' => $currentUser->getType().".php?ctg=control_panel"),
  525. array('title' => _JOURNAL_NAME, 'link' => $this->moduleBaseUrl),
  526. array('title' => _JOURNAL_STUDENTS_JOURNAL, 'link' => $_SERVER['REQUEST_URI'])
  527. );
  528. }
  529. else{
  530. return array(
  531. array('title' => _HOME, 'link' => $smarty->get_template_vars('T_HOME_LINK')),
  532. array('title' => $currentLesson->lesson['name'], 'link' => $currentUser->getType().".php?ctg=control_panel"),
  533. array('title' => _JOURNAL_NAME, 'link' => $this->moduleBaseUrl)
  534. );
  535. }
  536. }
  537. }
  538. public function getModuleCSS(){
  539. if(isset($_GET['hide_left']) && $_GET['hide_left'] == '1')
  540. return $this->moduleBaseDir.'css/journal_right.css';
  541. if(isset($_GET['hide_right']) && $_GET['hide_right'] == '1')
  542. return $this->moduleBaseDir.'css/journal_left.css';
  543. return $this->moduleBaseDir.'css/journal.css';
  544. }
  545. // Inner Functions
  546. private function getRules($active=null){
  547. ($active == null) ? $where = "" : $where = "active=1";
  548. $result = eF_getTableData("module_journal_rules", "*", $where, "id");
  549. $rules = array();
  550. foreach($result as $value)
  551. $rules[$value['id']] = $value;
  552. return $rules;
  553. }
  554. private function getEntries($userLogin, $filter){
  555. if($filter == '-1')
  556. $where = "users_LOGIN='".$userLogin."'";
  557. else
  558. $where = "users_LOGIN='".$userLogin."' and lessons_ID=".$filter;
  559. $result = eF_getTableData("module_journal_entries", "*", $where, "id");
  560. $entries = array();
  561. $prev_datestamp = '';
  562. foreach($result as $value){
  563. $date_ = explode(' ', $value['entry_date']);
  564. $datestamp = $date_[0];
  565. $timestamp = $date_[1];
  566. $datestamp = explode('-', $datestamp);
  567. $timestampMktime = explode(':', $timestamp);
  568. $dateFormatted = formatTimestamp(mktime($timestampMktime[0], $timestampMktime[1], $timestampMktime[2],
  569. $datestamp[1], $datestamp[2], $datestamp[0]), 'time');
  570. $datestampFormatted = formatTimestamp(mktime(0, 0, 0, $datestamp[1], $datestamp[2], $datestamp[0]), 'date');
  571. $datestamp = $datestamp[2].'/'.$datestamp[1].'/'.$datestamp[0];
  572. if($prev_datestamp == '' || $prev_datestamp != $datestamp)
  573. $value['date_first'] = 1;
  574. else
  575. $value['date_first'] = 0;
  576. $value['entry_date'] = $datestamp.' '.$timestamp;
  577. $value['entry_date_formatted'] = $dateFormatted;
  578. $value['entry_datestamp'] = $datestamp;
  579. $value['entry_datestamp_formatted'] = $datestampFormatted;
  580. $value['entry_timestamp'] = $timestamp;
  581. $entries[$value['id']] = $value;
  582. $prev_datestamp = $datestamp;
  583. }
  584. return $entries;
  585. }
  586. function deleteAutoSaveEntry(){
  587. $autosaveEntry = $_SESSION['module_journal_autosave_entry'];
  588. eF_deleteTableData("module_journal_entries", "id=".$autosaveEntry);
  589. unset($_SESSION['module_journal_autosave_entry']);
  590. }
  591. function getJournalLessons($userLogin){
  592. $lessons = array();
  593. $ids = array();
  594. $result = eF_getTableData("module_journal_entries", "lessons_ID", "users_LOGIN='".$userLogin."'");
  595. foreach($result as $value)
  596. array_push($ids, $value['lessons_ID']);
  597. $ids = array_unique($ids, SORT_NUMERIC);
  598. $lessons[-1] = array("id" => -1, "name" => _JOURNAL_ALL_LESSONS);
  599. foreach($ids as $key => $value){
  600. $lesson = new EfrontLesson($value);
  601. $lessons[$value] = array("id" => $value, "name" => $lesson->lesson['name']);
  602. }
  603. return $lessons;
  604. }
  605. function getProfessorJournalLessons($currentUser){
  606. $userLessons = $currentUser->getLessons(false, 'professor');
  607. $lessons = array();
  608. foreach($userLessons as $key => $value){
  609. $lesson = new EfrontLesson($key);
  610. $installed = $lesson->getOptions(array('module_journal'));
  611. if(count($installed) != 0 && $installed['module_journal'] == 1)
  612. array_push($lessons, $key);
  613. }
  614. return $lessons;
  615. }
  616. function getJournalLessonsStudents($professorJournalLessons){
  617. $students = array();
  618. foreach($professorJournalLessons as $lessonID){
  619. $lesson = new EfrontLesson($lessonID);
  620. $lessonStudents = $lesson->getUsers('student');
  621. foreach($lessonStudents as $userLogin => $value){
  622. if(!in_array($userLogin, array_keys($students)))
  623. $students[$userLogin] = array('login' => $userLogin);
  624. }
  625. }
  626. return $students;
  627. }
  628. function getStudentEntries($userLogin, $professorJournalLessons){
  629. $where = "users_LOGIN='".$userLogin."' and (";
  630. for($count = 0; $count < count($professorJournalLessons); $count++){
  631. if($count != count($professorJournalLessons) -1)
  632. $where .= "lessons_ID=".$professorJournalLessons[$count]." OR ";
  633. else
  634. $where .= "lessons_ID=".$professorJournalLessons[$count];
  635. }
  636. $where .= ")";
  637. $result = eF_getTableData("module_journal_entries", "*", $where, "id");
  638. $entries = array();
  639. foreach($result as $value){
  640. $date_ = explode(' ', $value['entry_date']);
  641. $datestamp = $date_[0];
  642. $timestamp = $date_[1];
  643. $datestamp = explode('-', $datestamp);
  644. $timestampMktime = explode(':', $timestamp);
  645. $dateFormatted = formatTimestamp(mktime($timestampMktime[0], $timestampMktime[1], $timestampMktime[2],
  646. $datestamp[1], $datestamp[2], $datestamp[0]), 'time');
  647. $value['entry_date_formatted'] = $dateFormatted;
  648. $lesson = new EfrontLesson($value['lessons_ID']);
  649. $value['lesson'] = $lesson->lesson['name'];
  650. $entries[$value['id']] = $value;
  651. }
  652. return $entries;
  653. }
  654. public function getModuleIcon() {
  655. return $this -> moduleBaseLink.'images/journal_logo.png';
  656. }
  657. }
  658. ?>