/** * Persist glossary properties * * This function can be used to persist with the database * any changes made to the current glossary object. * <br/>Example: * <code> * $glossary -> glossary['name'] = 'new Title'; //Change the name * $glossary -> persist(); //Make the change permanent * </code> * * @since 3.6.0 * @access public */ public function persist() { // added to fix http://forum.efrontlearning.net/viewtopic.php?f=5&t=2851&p=14715 if (mb_substr($this->glossary['info'], 0, 3) == "<p>") { $this->glossary['info'] = mb_substr($this->glossary['info'], 3); if (mb_substr($this->glossary['info'], -4, 4) == "</p>") { $this->glossary['info'] = mb_substr($this->glossary['info'], 0, -4); } } parent::persist(); EfrontSearch::removeText('glossary', $this->glossary['id'], 'data'); EfrontSearch::insertText($this->glossary['info'], $this->glossary['id'], "glossary", "data"); EfrontSearch::removeText('glossary', $this->glossary['id'], 'title'); EfrontSearch::insertText($this->glossary['title'], $this->glossary['id'], "glossary", "title"); }
/** * Send a personal message * * This function is used to send the personal message. If $email is specified, * the message is also emailed to the recipients * <br/>Example: * <code> * $pm = new eF_PersonalMessage("professor", array("professor", "student", "admin"), 'Test subject', 'Test personal message body'); * $pm -> send(); * </code> * * @param boolean If true, the personal message will be send as an email as well * @return true on success, false on error * @since 1.0 * @access public */ public function send($email = false) { if (sizeof($this->recipients) == 0) { $this->errorMessage = _INVALIDRECIPIENT; return false; } $timestamp = time(); if ($email) { //Check if the messag should be sent as an email also. This will be sent no matter the user quotas $recipientsMail = array(); foreach ($this->recipients as $recipient) { if ($this->userData[$recipient]['email'] != "") { $recipientsMail[] = $this->userData[$recipient]['email']; } else { $this->errorMessage .= $this->userData[$recipient]['login'] . ' ' . _HASNOTANEMAILADDRESS . '<br/>'; } } $recipientsList = implode(",", $recipientsMail); $this->body = _THISISAPMFROMSITE . " <a href=" . G_SERVERNAME . ">" . G_SERVERNAME . "</a><br />" . $this->body; $emailBody = str_replace('##EFRONTINNERLINK##', 'student', $this->body); if (($result = eF_mail($this->userData[$this->sender]['email'], $recipientsList, $this->subject, $emailBody, $this->attachments, false, $this->bcc)) !== true) { $this->errorMessage .= _THEMESSAGEWASNOTSENTASEMAIL . '<br/>'; } } foreach ($this->recipients as $recipient) { $fields_insert = array("users_LOGIN" => $recipient, "recipient" => implode(", ", $this->recipients), "sender" => $this->sender, "timestamp" => $timestamp, "title" => $this->subject, "body" => $this->body, "bcc" => $this->bcc ? 1 : 0, "f_folders_ID" => $this->userData[$recipient]['folders']['Incoming'], "viewed" => 0); //It is not viewed yet if (!empty($this->attachments) && $this->attachments[0]) { if ($this->checkUserQuota($recipient)) { $attachment = new EfrontFile($this->sender_attachment_fileId); $recipient_dir = G_UPLOADPATH . $recipient . '/message_attachments/Incoming/' . $timestamp . '/'; mkdir($recipient_dir, 0755); $newFile = $attachment->copy($recipient_dir, false, true); $fields_insert["attachments"] = $newFile['id']; } else { $fields_insert["body"] .= '<br /><span class="failure">' . _THEREWASATTACHMENTCUTBECAUSEOFQUOTA . '</span>'; } } $id = eF_insertTableData("f_personal_messages", $fields_insert); EfrontSearch::insertText($fields_insert['body'], $id, "f_personal_messages", "data"); EfrontSearch::insertText($fields_insert['title'], $id, "f_personal_messages", "title"); } //it should not come here if sender has reached maximum space limit //if ($this -> checkUserQuota($this -> sender)) { $fields_insert = array("users_LOGIN" => $this->sender, "recipient" => implode(", ", $this->recipients), "sender" => $this->sender, "timestamp" => $timestamp, "title" => $this->subject, "body" => $this->body, "bcc" => $this->bcc ? 1 : 0, "f_folders_ID" => $this->userData[$this->sender]['folders']['Sent'], "viewed" => 0); if (!empty($this->attachments) && $this->attachments[0]) { $attachment = new EfrontFile($this->sender_attachment_fileId); $fields_insert["attachments"] = $this->sender_attachment_fileId; } $id = eF_insertTableData("f_personal_messages", $fields_insert); EfrontSearch::insertText($fields_insert['body'], $id, "f_personal_messages", "data"); EfrontSearch::insertText($fields_insert['title'], $id, "f_personal_messages", "title"); //} else { // $this -> errorMessage .= _COULDNOTBECOPIEDTOYOURSENTBOX.' '._BECAUSEYOURMESSAGEBOXISFULL.'<br />'; //} if ($this->errorMessage) { return false; } else { return true; } }
/** * Create new course * * Create a new course based on the specified $fields * <br/>Example: * <code> * $fields = array('name' => 'new course', 'languages_NAME' => 'english'); * $course = EfrontCourse :: createCourse($fields); * </code> * * @param array $fields The new fields * @return EfrontCourse the new course * @since 3.5.0 * @access public */ public static function createCourse($fields) { $fields['metadata'] = self::createCourseMetadata($fields); $fields = self::validateAndSanitizeCourseFields($fields); isset($fields['creator_LOGIN']) or $fields['creator_LOGIN'] = $_SESSION['s_login']; $newId = eF_insertTableData("courses", $fields); // Insert the corresponding lesson skill to the skill and lesson_offers_skill tables. Automatic skill generation only for the educational version if (G_VERSIONTYPE == 'educational') { #cpp#ifdef EDUCATIONAL $courseSkillId = eF_insertTableData("module_hcd_skills", array("description" => _KNOWLEDGEOFCOURSE . " " . $fields['name'], "categories_ID" => -1)); eF_insertTableData("module_hcd_course_offers_skill", array("courses_ID" => $newId, "skill_ID" => $courseSkillId)); } #cpp#endif EfrontSearch::insertText($fields['name'], $newId, "courses", "title"); $course = new EfrontCourse($newId); self::notifyModuleListenersForCourseCreation($course); return $course; }
private function importUnitFromXML($unitelement, $parentid) { $fields = array(); $fields['name'] = (string) $unitelement->name; $fields['data'] = (string) $unitelement->data; $fields['ctg_type'] = (string) $unitelement->ctg_type; $fields['parent_content_ID'] = $parentid; $uid = ef_insertTableData("content", $fields); EfrontSearch::insertText($fields['name'], $uid, "content", "title"); EfrontSearch::insertText($fields['data'], $uid, "content", "data"); if ($fields['ctg_type'] == 'tests') { $testfields = array(); $testfields['content_id'] = (string) $unitelement->id; $testfields['duration'] = (string) $unitelement->test[0]->duration; $testfields['redoable'] = (string) $unitelement->test[0]->redoable; $testfields['onebyone'] = (string) $unitelement->test[0]->onebyone; $testfields['answers'] = (string) $unitelement->test[0]->answers; $testfields['description'] = (string) $unitelement->test[0]->description; $testfields['shuffle_questions'] = (string) $unitelement->test[0]->shuffle_questions; $testfields['shuffle_answers'] = (string) $unitelement->test[0]->shuffle_answers; $testfields['given_answers'] = (string) $unitelement->test[0]->given_answers; $tid = ef_insertTableData("tests", $testfields); } //import the subunits for ($i = 0; $i < sizeof($unitelement->unit); $i++) { importUnitFromXML($unitelement->unit[$i]); } }
/** * Store database values * * This function is used to store changed lesson properties * to the database. * <br/>Example: * <code> * $lesson = new EfrontLesson(4); //Instantiate lesson with id 4 * $lesson -> lesson['name'] = 'new name'; //Change a lesson's property, for example its name * $lesson -> persist(); //Store any changed values to the database * </code> * * @since 3.5.0 * @access public */ public function persist() { $localeSettings = localeconv(); $fields = array('name' => $this->lesson['name'], 'directions_ID' => $this->lesson['directions_ID'], 'info' => $this->lesson['info'], 'price' => str_replace($localeSettings['decimal_point'], '.', $this->lesson['price']), 'active' => $this->lesson['active'], 'duration' => $this->lesson['duration'] ? $this->lesson['duration'] : 0, 'access_limit' => $this->lesson['access_limit'] ? $this->lesson['access_limit'] : 0, 'share_folder' => $this->lesson['share_folder'] ? $this->lesson['share_folder'] : 0, 'show_catalog' => $this->lesson['course_only'] ? 1 : $this->lesson['show_catalog'], 'options' => serialize($this->options), 'languages_NAME' => $this->lesson['languages_NAME'], 'metadata' => $this->lesson['metadata'], 'course_only' => $this->lesson['course_only'], 'certificate' => $this->lesson['certificate'], 'publish' => $this->lesson['publish'] ? 1 : 0, 'max_users' => $this->lesson['max_users'] ? $this->lesson['max_users'] : null, 'from_timestamp' => $this->lesson['from_timestamp'] ? $this->lesson['from_timestamp'] : 0, 'to_timestamp' => $this->lesson['to_timestamp'] ? $this->lesson['to_timestamp'] : 0, 'shift' => $this->lesson['shift'], 'archive' => $this->lesson['archive'], 'created' => $this->lesson['created']); if (!eF_updateTableData("lessons", $fields, "id=" . $this->lesson['id'])) { throw new EfrontUserException(_DATABASEERROR, EfrontUserException::DATABASE_ERROR); } EfrontSearch::removeText('lessons', $this->lesson['id'], 'title'); //Refresh the search keywords EfrontSearch::insertText($fields['name'], $this->lesson['id'], "lessons", "title"); }
/** * Function reBuiltIndex() * * This function is used to built the keywords from scratch * * @since 3.5.0 * @access public */ public static function reBuiltIndex() { eF_deleteTableData("search_keywords"); //Delete old search terms // eF_deleteTableData("search"); $GLOBALS['db']->Execute("truncate table search_invertedindex"); //Courses Data $courses = eF_getTableData("courses", "id,name"); for ($i = 0; $i < sizeof($courses); $i++) { EfrontSearch::insertText($courses[$i]['name'], $courses[$i]['id'], "courses", "title"); } //Lesson Data $lessons = eF_getTableData("lessons", "id,name"); for ($i = 0; $i < sizeof($lessons); $i++) { EfrontSearch::insertText($lessons[$i]['name'], $lessons[$i]['id'], "lessons", "title"); } //Content Data $content = eF_getTableData("content", "id,name,data"); for ($i = 0; $i < sizeof($content); $i++) { EfrontSearch::insertText($content[$i]['name'], $content[$i]['id'], "content", "title"); EfrontSearch::insertText(strip_tags($content[$i]['data']), $content[$i]['id'], "content", "data"); } //Forum Messages $forum_messages = eF_getTableData("f_messages", "id, title, body"); for ($i = 0; $i < sizeof($forum_messages); $i++) { EfrontSearch::insertText(strip_tags($forum_messages[$i]['body']), $forum_messages[$i]['id'], "f_messages", "data"); EfrontSearch::insertText($forum_messages[$i]['title'], $forum_messages[$i]['id'], "f_messages", "title"); } //Forums $forums = eF_getTableData("f_forums", "id, title, comments"); for ($i = 0; $i < sizeof($forums); $i++) { EfrontSearch::insertText($forums[$i]['title'], $forums[$i]['id'], "f_forums", "title"); if (strlen($forums[$i]['comments']) > 3) { EfrontSearch::insertText(strip_tags($forums[$i]['comments']), $forums[$i]['id'], "f_forums", "data"); } } //Forums Topics $f_topics = eF_getTableData("f_topics", "id, title, comments"); for ($i = 0; $i < sizeof($f_topics); $i++) { EfrontSearch::insertText($f_topics[$i]['title'], $f_topics[$i]['id'], "f_topics", "title"); if (strlen($f_topics[$i]['comments']) > 3) { EfrontSearch::insertText(strip_tags($f_topics[$i]['comments']), $f_topics[$i]['id'], "f_topics", "data"); } } //Forums Polls $f_poll = eF_getTableData("f_poll", "id, title, question"); for ($i = 0; $i < sizeof($f_poll); $i++) { EfrontSearch::insertText($f_poll[$i]['title'], $f_poll[$i]['id'], "f_poll", "title"); if (strlen($f_poll[$i]['question']) > 3) { EfrontSearch::insertText(strip_tags($f_poll[$i]['question']), $f_poll[$i]['id'], "f_poll", "data"); } } //Personal Messages $personal_messages = eF_getTableData("f_personal_messages", "id, title, body"); //Get all the personal messages for ($i = 0; $i < sizeof($personal_messages); $i++) { EfrontSearch::insertText($personal_messages[$i]['body'], $personal_messages[$i]['id'], "f_personal_messages", "data"); EfrontSearch::insertText($personal_messages[$i]['title'], $personal_messages[$i]['id'], "f_personal_messages", "title"); } //Questions $questions = eF_getTableData("questions", "id, text"); for ($i = 0; $i < sizeof($questions); $i++) { EfrontSearch::insertText(strip_tags($questions[$i]['data']), $questions[$i]['id'], "questions", "data"); } //Glossary terms $glossary = eF_getTableData("glossary", "id, name, info"); for ($i = 0; $i < sizeof($glossary); $i++) { EfrontSearch::insertText(strip_tags($glossary[$i]['info']), $glossary[$i]['id'], "glossary", "data"); EfrontSearch::insertText($glossary[$i]['name'], $glossary[$i]['id'], "glossary", "title"); } }
/** * Persist news properties * * This function can be used to persist with the database * any changes made to the current news object. * <br/>Example: * <code> * $news -> news['title'] = 'new Title'; //Change the news title * $news -> persist(); //Make the change permanent * </code> * * @since 3.6.0 * @access public */ public function persist() { parent::persist(); EfrontSearch::removeText('news', $this->news['id'], 'data'); EfrontSearch::insertText($this->news['data'], $this->news['id'], "news", "data"); EfrontSearch::removeText('news', $this->news['id'], 'title'); EfrontSearch::insertText($this->news['title'], $this->news['id'], "news", "title"); }
/** * Import files to filesystem * * This function imports the specified files (in $list array) to the filesystem, * by creating a corresponding database representation. The $list * array should contain full paths to the files. The function returns an array * of the same size and contents as $list , but this time the file ids being the keys * <br/>Example: * <code> * $list = array('/var/www/text.txt', '/var/www/user.txt'); * $newList = FileSystemTree :: importFiles($list); * </code> * * @param array $list The files list * @param array $options extra options to set for the files, such as whether they should be renamed, or the proper permissions * @return array An array with the new file ids * @access public * @since 3.0 * @static */ public static function importFiles($list, $options = array()) { if (!is_array($list)) { $list = array($list); } $allFiles = eF_getTableDataFlat("files", "path"); //Get all files, so that if a file already exists, a duplicate entry in the database won't be created for ($i = 0; $i < sizeof($list); $i++) { $list[$i] = EfrontFile::encode($list[$i]); if (!in_array($list[$i], $allFiles['path']) && strpos(dirname($list[$i]), rtrim(G_ROOTPATH, "/")) !== false) { $fileMetadata = array('title' => basename($list[$i]), 'creator' => $GLOBALS['currentUser']->user['name'] . ' ' . $GLOBALS['currentUser']->user['surname'], 'publisher' => $GLOBALS['currentUser']->user['name'] . ' ' . $GLOBALS['currentUser']->user['surname'], 'contributor' => $GLOBALS['currentUser']->user['name'] . ' ' . $GLOBALS['currentUser']->user['surname'], 'date' => date("Y/m/d", time()), 'type' => 'file'); $fields = array('path' => str_replace(G_ROOTPATH, '', $list[$i]), 'users_LOGIN' => isset($_SESSION['s_login']) ? $_SESSION['s_login'] : '', 'timestamp' => time(), 'metadata' => serialize($fileMetadata)); isset($options['access']) ? $fields['access'] = $options['access'] : null; $fileId = eF_insertTableData("files", $fields); if ($fileId) { $newList[$fileId] = $list[$i]; foreach ($fileMetadata as $key => $value) { EfrontSearch::insertText($value, $fileId, "files", "data"); } } } } return $newList; }
/** * Create a new question * * This function is used to create a new question * <br/>Example: * <code> * $fields = array('text' => 'new questions', 'type' => 'multiple_one', 'content_ID' => 10); * $question = Question :: createQuestion($fields); * </code> * * @param array $question The new question attributes * @return Question the new question object or false * @since 3.5.0 * @access public * @static */ public static function createQuestion($question) { !isset($question['difficulty']) ? $question['difficulty'] = 'medium' : null; if ($newId = eF_insertTableData("questions", $question)) { EfrontSearch::insertText(eF_addSlashes($question['text']), $newId, "questions", "title"); return QuestionFactory::factory($newId); } else { return false; } }
/** * * @param $fields * @return unknown_type */ public static function create($fields = array()) { $new_id = eF_insertTableData("f_poll", $fields); EfrontSearch::insertText($fields['title'], $new_id, "f_poll", "title"); if (mb_strlen($fields['question']) > 3) { EfrontSearch::insertText(strip_tags($fields['question']), $new_id, "f_poll", "data"); } $post_lesson_id = $post_lesson_name = null; $result = eF_getTableData("lessons l, f_forums f", "l.id,l.name", "l.id=f.lessons_ID and f.id={$fields['f_forums_ID']}"); if (!empty($result)) { $post_lesson_id = $result[0]['id']; $post_lesson_name = $result[0]['name']; } // Timelines add event EfrontEvent::triggerEvent(array("type" => EfrontEvent::NEW_POLL, "users_LOGIN" => $_SESSION['s_login'], "lessons_ID" => $post_lesson_id, "lessons_name" => $post_lesson_name, "entity_ID" => $new_id, "entity_name" => $fields['title'])); }