function cloud_getLpViewId($cid, $lp_id, $user_id, $createRegIfNeeded = false) { $lpv_table = Database::get_course_table_from_code($cid, TABLE_LP_VIEW); //selecting by view_count descending allows to get the highest view_count first $sql = "SELECT * FROM {$lpv_table} WHERE lp_id = {$lp_id} AND user_id = {$user_id} ORDER BY view_count DESC"; $view_res = api_sql_query($sql, __FILE__, __LINE__); if (Database::num_rows($view_res) > 0) { $row = Database::fetch_array($view_res); $lp_view_id = $row['id']; } else { $sql_ins = "INSERT INTO {$lpv_table} (lp_id,user_id,view_count) VALUES ({$lp_id},{$user_id},1)"; $res_ins = api_sql_query($sql_ins, __FILE__, __LINE__); $lp_view_id = Database::get_last_insert_id(); if ($createRegIfNeeded) { cloud_createCloudRegistration($cid, $lp_id, $lp_view_id); } } return $lp_view_id; }
function insert_defaults() { // {{{ try { $db = new Database(); $db->execute("INSERT INTO users(name, pass, joindate, class) VALUES(:name, :pass, now(), :class)", array("name" => 'Anonymous', "pass" => null, "class" => 'anonymous')); $db->execute("INSERT INTO config(name, value) VALUES(:name, :value)", array("name" => 'anon_id', "value" => $db->get_last_insert_id('users_id_seq'))); if (check_im_version() > 0) { $db->execute("INSERT INTO config(name, value) VALUES(:name, :value)", array("name" => 'thumb_engine', "value" => 'convert')); } $db->commit(); } catch (PDOException $e) { print <<<EOD \t\t<div id="installer"> \t\t\t<h1>Shimmie Installer</h1> \t\t\t<h3>Database Error:</h3> \t\t\t<p>An error occured while trying to insert data into the database.</p> \t\t\t<p>Please check and ensure that the database configuration options are all correct.</p> \t\t\t<br/><br/> \t\t</div> EOD; exit($e->getMessage()); } catch (Exception $e) { print <<<EOD \t\t<div id="installer"> \t\t\t<h1>Shimmie Installer</h1> \t\t\t<h3>Unknown Error:</h3> \t\t\t<p>An unknown error occured while trying to insert data into the database.</p> \t\t\t<p>Please check the server log files for more information.</p> \t\t\t<br/><br/> \t\t</div> EOD; exit($e->getMessage()); } }
function insert_defaults() { // {{{ try { $db = new Database(); $db->execute("INSERT INTO users(name, pass, joindate, admin) VALUES(:name, :pass, now(), :admin)", array("name" => 'Anonymous', "pass" => null, "admin" => 'N')); $db->execute("INSERT INTO config(name, value) VALUES(:name, :value)", array("name" => 'anon_id', "value" => $db->get_last_insert_id())); if (check_im_version() > 0) { $db->execute("INSERT INTO config(name, value) VALUES(:name, :value)", array("name" => 'thumb_engine', "value" => 'convert')); } } catch (PDOException $e) { // FIXME: Make the error message user friendly exit($e->getMessage()); } }
/** * Creates a new course request within the database. * @param string $wanted_code The code for the created in the future course. * @param string $title * @param string $description * @param string $category_code * @param string $course_language * @param string $objetives * @param string $target_audience * @param int/string $user_id * @return int/bool The database id of the newly created course request or FALSE on failure. */ public static function create_course_request($wanted_code, $title, $description, $category_code, $course_language, $objetives, $target_audience, $user_id, $exemplary_content) { global $_configuration; $wanted_code = trim($wanted_code); $user_id = (int) $user_id; $exemplary_content = (bool) $exemplary_content ? 1 : 0; if ($wanted_code == '') { return false; } if (self::course_code_exists($wanted_code)) { return false; } if ($user_id <= 0) { return false; } $user_info = api_get_user_info($user_id); if (!is_array($user_info)) { return false; } $tutor_name = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, $course_language); $request_date = api_get_utc_datetime(); $status = COURSE_REQUEST_PENDING; $info = 0; $keys = define_course_keys($wanted_code, ''); if (!count($keys)) { return false; } $visual_code = $keys['currentCourseCode']; $code = $keys['currentCourseId']; $db_name = isset($keys['currentCourseDbName']) ? $keys['currentCourseDbName'] : null; $directory = $keys['currentCourseRepository']; $sql = sprintf('INSERT INTO %s ( code, user_id, directory, db_name, course_language, title, description, category_code, tutor_name, visual_code, request_date, objetives, target_audience, status, info, exemplary_content) VALUES ( "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s");', Database::get_main_table(TABLE_MAIN_COURSE_REQUEST), Database::escape_string($code), Database::escape_string($user_id), Database::escape_string($directory), Database::escape_string($db_name), Database::escape_string($course_language), Database::escape_string($title), Database::escape_string($description), Database::escape_string($category_code), Database::escape_string($tutor_name), Database::escape_string($visual_code), Database::escape_string($request_date), Database::escape_string($objetives), Database::escape_string($target_audience), Database::escape_string($status), Database::escape_string($info), Database::escape_string($exemplary_content)); $result_sql = Database::query($sql); if (!$result_sql) { return false; } $last_insert_id = Database::get_last_insert_id(); // E-mail notifications. // E-mail language: The platform language seems to be the best choice. //$email_language = $course_language; //$email_language = api_get_interface_language(); $email_language = api_get_setting('platformLanguage'); $email_subject = sprintf(get_lang('CourseRequestEmailSubject', null, $email_language), '[' . api_get_setting('siteName') . ']', $code); $email_body = get_lang('CourseRequestMailOpening', null, $email_language) . "\n\n"; $email_body .= get_lang('CourseName', null, $email_language) . ': ' . $title . "\n"; $email_body .= get_lang('Fac', null, $email_language) . ': ' . $category_code . "\n"; $email_body .= get_lang('CourseCode', null, $email_language) . ': ' . $code . "\n"; $email_body .= get_lang('Professor', null, $email_language) . ': ' . api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, $email_language) . "\n"; $email_body .= get_lang('Email', null, $email_language) . ': ' . $user_info['mail'] . "\n"; $email_body .= get_lang('Description', null, $email_language) . ': ' . $description . "\n"; $email_body .= get_lang('Objectives', null, $email_language) . ': ' . $objetives . "\n"; $email_body .= get_lang('TargetAudience', null, $email_language) . ': ' . $target_audience . "\n"; $email_body .= get_lang('Ln', null, $email_language) . ': ' . $course_language . "\n"; $email_body .= get_lang('FillWithExemplaryContent', null, $email_language) . ': ' . ($exemplary_content ? get_lang('Yes', null, $email_language) : get_lang('No', null, $email_language)) . "\n"; // Sending an e-mail to the platform administrator. $email_body_admin = $email_body; $email_body_admin .= "\n" . get_lang('CourseRequestPageForApproval', null, $email_language) . ' ' . api_get_path(WEB_CODE_PATH) . 'admin/course_request_edit.php?id=' . $last_insert_id . "\n"; $email_body_admin .= "\n" . get_lang('CourseRequestLegalNote', null, $email_language) . "\n"; $sender_name_teacher = api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS); $sender_email_teacher = $user_info['mail']; $recipient_name_admin = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS); $recipient_email_admin = get_setting('emailAdministrator'); $userInfo = api_get_user_info($user_id); $additionalParameters = array('smsType' => ClockworksmsPlugin::NEW_COURSE_SUGGESTED_TEACHER, 'userId' => $user_id, 'userUsername' => $userInfo['username']); api_mail_html($recipient_name_admin, $recipient_email_admin, $email_subject, $email_body_admin, $sender_name_teacher, $sender_email_teacher, null, null, null, $additionalParameters); // Sending an e-mail to the requestor. $email_body_teacher = get_lang('Dear', null, $email_language) . ' '; $email_body_teacher .= api_get_person_name($user_info['firstname'], $user_info['lastname'], null, null, $email_language) . ",\n\n"; $email_body_teacher .= $email_body; $email_body_teacher .= "\n" . get_lang('Formula', null, $email_language) . "\n"; $email_body_teacher .= api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, null, $email_language) . "\n"; $email_body_teacher .= get_lang('Manager', null, $email_language) . ' ' . api_get_setting('siteName') . "\n"; $email_body_teacher .= get_lang('Phone', null, $email_language) . ': ' . api_get_setting('administratorTelephone') . "\n"; $email_body_teacher .= get_lang('Email', null, $email_language) . ': ' . api_get_setting('emailAdministrator', null, $email_language) . "\n"; $email_body_teacher .= "\n" . get_lang('CourseRequestLegalNote', null, $email_language) . "\n"; // Swap the sender and the recipient. $sender_name_admin = $recipient_name_admin; $sender_email_admin = $recipient_email_admin; $recipient_name_teacher = $sender_name_teacher; $recipient_email_teacher = $sender_email_teacher; $additionalParameters = array('smsType' => ClockworksmsPlugin::COURSE_OPENING_REQUEST_CODE_REGISTERED, 'userId' => $user_info['user_id'], 'courseCode' => $wanted_code); api_mail_html($recipient_name_teacher, $recipient_email_teacher, $email_subject, $email_body_teacher, $sender_name_admin, $sender_email_admin, null, null, null, $additionalParameters); return $last_insert_id; }
/** * Create a question from a set of parameters * @param int Quiz ID * @param string Question name * @param int Maximum result for the question * @param int Type of question (see constants at beginning of question.class.php) * @param int Question level/category */ function create_question($quiz_id, $question_name, $question_description = "", $max_score = 0, $type = 1, $level = 1) { $course_id = api_get_course_int_id(); $tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION); $tbl_quiz_rel_question = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $quiz_id = intval($quiz_id); $max_score = (double) $max_score; $type = intval($type); $level = intval($level); // Get the max position $sql = "SELECT max(position) as max_position" . " FROM {$tbl_quiz_question} q INNER JOIN {$tbl_quiz_rel_question} r" . " ON q.id = r.question_id" . " AND exercice_id = {$quiz_id} AND q.c_id = {$course_id} AND r.c_id = {$course_id}"; $rs_max = Database::query($sql); $row_max = Database::fetch_object($rs_max); $max_position = $row_max->max_position + 1; // Insert the new question $sql = "INSERT INTO {$tbl_quiz_question} (c_id, question, description, ponderation, position, type, level)\n VALUES ({$course_id}, '" . Database::escape_string($question_name) . "', '" . Database::escape_string($question_description) . "', '{$max_score}', {$max_position}, {$type}, {$level})"; Database::query($sql); // Get the question ID $question_id = Database::get_last_insert_id(); // Get the max question_order $sql = "SELECT max(question_order) as max_order " . "FROM {$tbl_quiz_rel_question} WHERE c_id = {$course_id} AND exercice_id = {$quiz_id} "; $rs_max_order = Database::query($sql); $row_max_order = Database::fetch_object($rs_max_order); $max_order = $row_max_order->max_order + 1; // Attach questions to quiz $sql = "INSERT INTO {$tbl_quiz_rel_question} " . "(c_id, question_id,exercice_id,question_order)" . " VALUES({$course_id}, {$question_id}, {$quiz_id}, {$max_order})"; Database::query($sql); return $question_id; }
$res_name = api_sql_query($check_name, __FILE__, __LINE__); while (Database::num_rows($res_name)) { //there is already one such name, update the current one a bit $i++; $newtitle = $title . ' - ' . $i; $check_name = "SELECT * FROM {$tbl_lp} WHERE name = '{$newtitle}'"; //if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);} $res_name = api_sql_query($check_name, __FILE__, __LINE__); } $title = $newtitle; //echo $title; $type = 2; $get_max = "SELECT MAX(display_order) FROM {$tbl_lp}"; $res_max = api_sql_query($get_max, __FILE__, __LINE__); if (Database::num_rows($res_max) < 1) { $dsp = 1; } else { $row = Database::fetch_array($res_max); $dsp = $row[0] + 1; } $sql_insert = "INSERT INTO {$tbl_lp} " . "(lp_type,name,description,path,default_view_mod," . "default_encoding,display_order,content_maker," . "content_local) " . "VALUES ({$type},'{$title}','','','scormcloud'," . "'UTF-8','{$dsp}','{$content_maker}'," . "'remote')"; //echo $sql_insert; $res_insert = api_sql_query($sql_insert, __FILE__, __LINE__); $id = Database::get_last_insert_id(); $tbl_scorm_cloud = Database::get_main_table('scorm_cloud'); $sql_cloud_insert = "INSERT INTO {$tbl_scorm_cloud} " . "(course_code,lp_id,cloud_course_id)" . "VALUES ('{$cid}',{$id},'{$courseId}')"; $res_insert2 = api_sql_query($sql_cloud_insert, __FILE__, __LINE__); $dialogtype = 'confirmation'; header('location: ../newscorm/lp_controller.php?action=list&dialog_box=' . $msg . '&dialogtype=' . $dialogtype); exit; }