/** * Update the file or directory path in the document db document table * * @author - Hugues Peeters <*****@*****.**> * @param - action (string) - action type require : 'delete' or 'update' * @param - old_path (string) - old path info stored to change * @param - new_path (string) - new path info to substitute * @desc Update the file or directory path in the document db document table * */ static function update_db_info($action, $old_path, $new_path = '') { $dbTable = Database::get_course_table(TABLE_DOCUMENT); $course_id = api_get_course_int_id(); /* DELETE */ if ($action == 'delete') { $old_path = Database::escape_string($old_path); $to_delete = "WHERE c_id = {$course_id} AND path LIKE BINARY '" . $old_path . "' OR path LIKE BINARY '" . $old_path . "/%'"; $query = "DELETE FROM {$dbTable} " . $to_delete; $result = Database::query("SELECT id FROM {$dbTable} " . $to_delete); if (Database::num_rows($result)) { require_once api_get_path(INCLUDE_PATH) . '../metadata/md_funcs.php'; $mdStore = new mdstore(true); // create if needed $md_type = substr($dbTable, -13) == 'scormdocument' ? 'Scorm' : 'Document'; while ($row = Database::fetch_array($result)) { $eid = $md_type . '.' . $row['id']; $mdStore->mds_delete($eid); $mdStore->mds_delete_offspring($eid); } } } /* UPDATE */ if ($action == 'update') { if ($new_path[0] == '.') { $new_path = substr($new_path, 1); } $new_path = str_replace('//', '/', $new_path); // Attempt to update - tested & working for root dir $new_path = Database::escape_string($new_path); $query = "UPDATE {$dbTable}\n SET path = CONCAT('" . $new_path . "', SUBSTRING(path, LENGTH('" . $old_path . "')+1) )\n WHERE c_id = {$course_id} AND path LIKE BINARY '" . $old_path . "' OR path LIKE BINARY '" . $old_path . "/%'"; } Database::query($query); }
function search_users($needle, $type) { global $_configuration, $tbl_access_url_rel_user, $tbl_user, $user_anonymous, $current_user_id, $user_id; $xajax_response = new XajaxResponse(); $return = ''; if (!empty($needle) && !empty($type)) { // xajax send utf8 datas... datas in db can be non-utf8 datas $charset = api_get_system_encoding(); $needle = api_convert_encoding($needle, $charset, 'utf-8'); $assigned_users_to_hrm = UserManager::get_users_followed_by_drh($user_id); $assigned_users_id = array_keys($assigned_users_to_hrm); $without_assigned_users = ''; if (count($assigned_users_id) > 0) { $without_assigned_users = " AND user.user_id NOT IN(" . implode(',', $assigned_users_id) . ")"; } if ($_configuration['multiple_access_urls']) { $sql = "SELECT user.user_id, username, lastname, firstname FROM {$tbl_user} user LEFT JOIN {$tbl_access_url_rel_user} au ON (au.user_id = user.user_id)\n\t\t\tWHERE " . (api_sort_by_first_name() ? 'firstname' : 'lastname') . " LIKE '{$needle}%' AND status NOT IN(" . DRH . ", " . SESSIONADMIN . ") AND user.user_id NOT IN ({$user_anonymous}, {$current_user_id}, {$user_id}) {$without_assigned_users} AND access_url_id = " . api_get_current_access_url_id() . ""; } else { $sql = "SELECT user_id, username, lastname, firstname FROM {$tbl_user} user\n\t\t\tWHERE " . (api_sort_by_first_name() ? 'firstname' : 'lastname') . " LIKE '{$needle}%' AND status NOT IN(" . DRH . ", " . SESSIONADMIN . ") AND user_id NOT IN ({$user_anonymous}, {$current_user_id}, {$user_id}) {$without_assigned_users}"; } $rs = Database::query($sql); $return .= '<select id="origin" name="NoAssignedUsersList[]" multiple="multiple" size="20" style="width:340px;">'; while ($user = Database::fetch_array($rs)) { $person_name = api_get_person_name($user['firstname'], $user['lastname']); $return .= '<option value="' . $user['user_id'] . '" title="' . htmlspecialchars($person_name, ENT_QUOTES) . '">' . $person_name . ' (' . $user['username'] . ')</option>'; } $return .= '</select>'; $xajax_response->addAssign('ajax_list_users_multiple', 'innerHTML', api_utf8_encode($return)); } return $xajax_response; }
/** * Search for a list of available courses by title or code, based on * a given string * @param string String to search for * @param int Deprecated param * @return string A formatted, xajax answer block * @assert () === false */ function search_courses($needle, $id) { global $tbl_course; $xajax_response = new XajaxResponse(); $return = ''; if (!empty($needle)) { // xajax send utf8 datas... datas in db can be non-utf8 datas $charset = api_get_system_encoding(); $needle = api_convert_encoding($needle, $charset, 'utf-8'); $needle = Database::escape_string($needle); // search courses where username or firstname or lastname begins likes $needle $sql = 'SELECT code, title FROM ' . $tbl_course . ' u ' . ' WHERE (title LIKE "' . $needle . '%" ' . ' OR code LIKE "' . $needle . '%" ' . ' ) ' . ' ORDER BY title, code ' . ' LIMIT 11'; $rs = Database::query($sql); $i = 0; while ($course = Database::fetch_array($rs)) { $i++; if ($i <= 10) { $return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_url(\'' . addslashes($course['code']) . '\',\'' . addslashes($course['title']) . ' (' . addslashes($course['code']) . ')' . '\')">' . $course['title'] . ' (' . $course['code'] . ')</a><br />'; } else { $return .= '...<br />'; } } } $xajax_response->addAssign('ajax_list_courses', 'innerHTML', api_utf8_encode($return)); return $xajax_response; }
/** * Sets the surveylist and the plainsurveylist */ public function __construct() { // Database table definitions $table_survey = Database::get_course_table(TABLE_SURVEY); $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION); $table_user = Database::get_main_table(TABLE_MAIN_USER); // searching $search_restriction = SurveyUtil::survey_search_restriction(); if ($search_restriction) { $search_restriction = ' AND ' . $search_restriction; } $course_id = api_get_course_int_id(); $sql = "SELECT\n survey.survey_id,\n survey.parent_id,\n survey_version,\n survey.code as name\n\t\t\t\tFROM {$table_survey} survey\n\t\t\t\tLEFT JOIN {$table_survey_question} survey_question\n\t\t\t\tON survey.survey_id = survey_question.survey_id , {$table_user} user\n\t\t\t\tWHERE\n\t\t\t\t\tsurvey.c_id \t\t\t= {$course_id} AND\n\t\t\t\t\tsurvey_question.c_id \t= {$course_id} AND\n\t\t\t\t\tsurvey.author \t\t\t= user.user_id\n\t\t\t\tGROUP BY survey.survey_id"; $res = Database::query($sql); $surveys_parents = array(); $refs = array(); $list = array(); $plain_array = array(); while ($survey = Database::fetch_array($res, 'ASSOC')) { $plain_array[$survey['survey_id']] = $survey; $surveys_parents[] = $survey['survey_version']; $thisref =& $refs[$survey['survey_id']]; $thisref['parent_id'] = $survey['parent_id']; $thisref['name'] = $survey['name']; $thisref['id'] = $survey['survey_id']; $thisref['survey_version'] = $survey['survey_version']; if ($survey['parent_id'] == 0) { $list[$survey['survey_id']] =& $thisref; } else { $refs[$survey['parent_id']]['children'][$survey['survey_id']] =& $thisref; } } $this->surveylist = $list; $this->plainsurveylist = $plain_array; }
function ShowMenuFiche($p_dossier) { $cn = new Database($p_dossier); $mod = "&ac=" . $_REQUEST['ac']; $str_dossier = dossier::get() . $mod; echo '<div class="lmenu">'; echo '<TABLE>'; echo '<TR><TD colspan="1" class="mtitle" style="width:auto" > <A class="mtitle" HREF="?p_action=fiche&action=add_modele&fiche=modele&' . $str_dossier . '">' . _('Création') . '</A></TD> <TD><A class="mtitle" HREF="?p_action=fiche&' . $str_dossier . '">' . _('Recherche') . '</A></TD> </TR>'; $Res = $cn->exec_sql("select fd_id,fd_label from fiche_def order by fd_label"); $Max = Database::num_row($Res); for ($i = 0; $i < $Max; $i++) { $l_line = Database::fetch_array($Res, $i); printf('<TR><TD class="cell"> <A class="mtitle" HREF="?p_action=fiche&action=modifier&fiche=%d&%s">%s</A></TD> <TD class="mshort"> <A class="mtitle" HREF="?p_action=fiche&action=vue&fiche=%d&%s">Liste</A> </TD> </TR>', $l_line['fd_id'], $str_dossier, $l_line['fd_label'], $l_line['fd_id'], $str_dossier); } echo "</TABLE>"; echo '</div>'; }
/** * @Route("/edit/{tool}") * @Method({"GET"}) * * @param string $tool * @return Response */ public function editAction($tool) { $message = null; // @todo use proper functions not api functions. $courseId = api_get_course_int_id(); $sessionId = api_get_session_id(); $tool = \Database::escape_string($tool); $TBL_INTRODUCTION = \Database::get_course_table(TABLE_TOOL_INTRO); $url = $this->generateUrl('introduction.controller:editAction', array('tool' => $tool, 'course' => api_get_course_id())); $form = $this->getForm($url, $tool); if ($form->validate()) { $values = $form->exportValues(); $content = $values['content']; $sql = "REPLACE {$TBL_INTRODUCTION}\n SET c_id = {$courseId},\n id = '{$tool}',\n intro_text='" . \Database::escape_string($content) . "',\n session_id='" . intval($sessionId) . "'"; \Database::query($sql); $message = \Display::return_message(get_lang('IntroductionTextUpdated'), 'confirmation', false); } else { $sql = "SELECT intro_text FROM {$TBL_INTRODUCTION}\n WHERE c_id = {$courseId} AND id='" . $tool . "' AND session_id = '" . intval($sessionId) . "'"; $result = \Database::query($sql); $content = null; if (\Database::num_rows($result) > 0) { $row = \Database::fetch_array($result); $content = $row['intro_text']; } $form->setDefaults(array('content' => $content)); } $this->getTemplate()->assign('content', $form->return_form()); $this->getTemplate()->assign('message', $message); $response = $this->getTemplate()->renderLayout('layout_1_col.tpl'); return new Response($response, 200, array()); }
public function get_announcement_data($username, $password, $course_code, $announcement_id, $field) { if ($this->verifyUserPass($username, $password) == "valid") { $htmlcode = false; $user_id = UserManager::get_user_id_from_username($username); $result = self::get_announcements($username, $course_code, $announcement_id); while ($announcement = Database::fetch_array($result)) { $announcements[] = $announcement; } switch ($field) { case 'sender': $field_table = "insert_user_id"; $sender = api_get_user_info($announcements[0][$field_table]); $announcements[0][$field_table] = $sender['firstname'] . " " . $sender['lastname']; break; case 'title': $htmlcode = true; $field_table = "title"; break; case 'date': $field_table = "end_date"; break; case 'content': $htmlcode = true; $field_table = "content"; $announcements[0][$field_table] = nl2br_revert($announcements[0][$field_table]); break; default: $field_table = "title"; } return htmlcode ? html_entity_decode($announcements[0][$field_table]) : $announcements[0][$field_table]; } else { return get_lang('InvalidId'); } }
public function getPriceChanges() { if (isset($this->sc_id)) { $database = new Database(); $datbase = new Database(); $query = "SELECT id,cur_val,date_t FROM " . self::$table; $query .= " WHERE sc_id = " . $this->sc_id; $query .= " ORDER BY id DESC"; $amt_chg_wrp = $database->query($query); if ($amt_chg_wrp) { $flag = 0; while ($p_change = $datbase->fetch_array($amt_chg_wrp)) { //Updating the current amount if ($flag === 0) { $this->cur_amt = $p_change['cur_val']; $flag++; } $this->priceChanges[] = array($p_change['cur_val'], $p_change['date_t']); unset($database); } } else { $this->priceChanges[] = 0; unset($database); } } }
public function __construct($in_c_id = 0, $in_id = 0) { if ($in_c_id > 0 && $in_id > 0) { $item_view_table = Database::get_course_table(TABLE_LP_ITEM); $sql = "SELECT * FROM {$item_view_table}\n WHERE\n c_id=" . intval($in_c_id) . " AND\n id=" . intval($in_id); $res = Database::query($sql); $data = Database::fetch_array($res); if (Database::num_rows($res) > 0) { $this->c_id = $data['c_id']; $this->id = $data['id']; $this->lp_id = $data['lp_id']; $this->item_type = $data['item_type']; $this->ref = $data['ref']; $this->title = $data['title']; $this->description = $data['description']; $this->path = $data['path']; $this->min_score = $data['min_score']; $this->max_score = $data['max_score']; $this->mastery_score = $data['mastery_score']; $this->parent_item_id = $data['parent_item_id']; $this->previous_item_id = $data['previous_item_id']; $this->next_item_id = $data['next_item_id']; $this->display_order = $data['display_order']; $this->prerequisite = $data['prerequisite']; $this->parameters = $data['parameters']; $this->launch_data = $data['launch_data']; $this->max_time_allowed = $data['max_time_allowed']; $this->terms = $data['terms']; $this->search_did = $data['search_did']; $this->audio = $data['audio']; } } }
function checkLogin($login, $pass) { $db = new Database(); //Traigo el usuario $q = "select salt from jugador where login='******' limit 1"; $r = $db->query($q); //Controlo que exista el usuario con el login $login if ($db->num_rows($r) > 0) { //Traigo el registro $data = $db->fetch_array($r); $salt_db = $data['salt']; //Genero el mismo hash que se creo al registrar jugador $hashedpass = hash('sha512', $pass . $salt_db); $q2 = "select * from jugador where login='******' and pass=PASSWORD('{$hashedpass}')"; $r2 = $db->query($q2); if ($db->num_rows($r2) > 0) { return 1; } else { return 0; } } else { alertMessage('El usuario no existe'); exit; } $db->close(); }
function search_sessions($needle, $type) { global $_configuration, $tbl_session_rel_access_url, $tbl_session, $user_id; $xajax_response = new XajaxResponse(); $return = ''; if (!empty($needle) && !empty($type)) { // xajax send utf8 datas... datas in db can be non-utf8 datas $charset = api_get_system_encoding(); $needle = api_convert_encoding($needle, $charset, 'utf-8'); $assigned_sessions_to_hrm = SessionManager::get_sessions_followed_by_drh($user_id); $assigned_sessions_id = array_keys($assigned_sessions_to_hrm); $without_assigned_sessions = ''; if (count($assigned_sessions_id) > 0) { $without_assigned_sessions = " AND s.id NOT IN(" . implode(',', $assigned_sessions_id) . ")"; } if ($_configuration['multiple_access_urls']) { $sql = " SELECT s.id, s.name FROM {$tbl_session} s LEFT JOIN {$tbl_session_rel_access_url} a ON (s.id = a.session_id)\n\t\t\t\t\t\tWHERE s.name LIKE '{$needle}%' {$without_assigned_sessions} AND access_url_id = " . api_get_current_access_url_id() . ""; } else { $sql = "SELECT s.id, s.name FROM {$tbl_session} s\n\t\t\t\tWHERE s.name LIKE '{$needle}%' {$without_assigned_sessions} "; } $rs = Database::query($sql); $return .= '<select id="origin" name="NoAssignedSessionsList[]" multiple="multiple" size="20" style="width:340px;">'; while ($session = Database::fetch_array($rs)) { $return .= '<option value="' . $session['id'] . '" title="' . htmlspecialchars($session['name'], ENT_QUOTES) . '">' . $session['name'] . '</option>'; } $return .= '</select>'; $xajax_response->addAssign('ajax_list_sessions_multiple', 'innerHTML', api_utf8_encode($return)); } return $xajax_response; }
/** * Search sessions by name, based on a search string * @param string Search string * @param int Deprecated param * @return string Xajax response block * @assert () === false */ function search_sessions($needle, $id) { global $tbl_session; $xajax_response = new XajaxResponse(); $return = ''; if (!empty($needle)) { // xajax send utf8 datas... datas in db can be non-utf8 datas $charset = api_get_system_encoding(); $needle = api_convert_encoding($needle, $charset, 'utf-8'); $needle = Database::escape_string($needle); // search sessiones where username or firstname or lastname begins likes $needle $sql = 'SELECT id, name FROM ' . $tbl_session . ' u WHERE (name LIKE "' . $needle . '%") ORDER BY name, id LIMIT 11'; $rs = Database::query($sql); $i = 0; while ($session = Database::fetch_array($rs)) { $i++; if ($i <= 10) { $return .= '<a href="#" onclick="add_user_to_url(\'' . addslashes($session['id']) . '\',\'' . addslashes($session['name']) . ' (' . addslashes($session['id']) . ')' . '\')">' . $session['name'] . ' </a><br />'; } else { $return .= '...<br />'; } } } $xajax_response->addAssign('ajax_list_courses', 'innerHTML', api_utf8_encode($return)); return $xajax_response; }
function search_courses($needle, $type) { global $tbl_course, $tbl_course_rel_access_url, $user_id; $xajax_response = new xajaxResponse(); $return = ''; if (!empty($needle) && !empty($type)) { // xajax send utf8 datas... datas in db can be non-utf8 datas $needle = Database::escape_string($needle); $assigned_courses_to_hrm = CourseManager::get_courses_followed_by_drh($user_id); $assigned_courses_code = array_keys($assigned_courses_to_hrm); foreach ($assigned_courses_code as &$value) { $value = "'" . $value . "'"; } $without_assigned_courses = ''; if (count($assigned_courses_code) > 0) { $without_assigned_courses = " AND c.code NOT IN(" . implode(',', $assigned_courses_code) . ")"; } if (api_is_multiple_url_enabled()) { $sql = "SELECT c.code, c.title\n FROM {$tbl_course} c\n\t\t\t\t\tLEFT JOIN {$tbl_course_rel_access_url} a\n ON (a.c_id = c.id)\n \tWHERE\n \t\tc.code LIKE '{$needle}%' {$without_assigned_courses} AND\n \t\taccess_url_id = " . api_get_current_access_url_id(); } else { $sql = "SELECT c.code, c.title\n \t\tFROM {$tbl_course} c\n \tWHERE\n \t\tc.code LIKE '{$needle}%'\n \t\t{$without_assigned_courses} "; } $rs = Database::query($sql); $return .= '<select id="origin" name="NoAssignedCoursesList[]" multiple="multiple" size="20" style="width:340px;">'; while ($course = Database::fetch_array($rs)) { $return .= '<option value="' . $course['code'] . '" title="' . htmlspecialchars($course['title'], ENT_QUOTES) . '">' . $course['title'] . ' (' . $course['code'] . ')</option>'; } $return .= '</select>'; $xajax_response->addAssign('ajax_list_courses_multiple', 'innerHTML', api_utf8_encode($return)); } return $xajax_response; }
function mdobject($_course, $id) { global $ieee_dcmap_e, $ieee_dcmap_v; // md_funcs $scormdocument = Database::get_course_table(TABLE_LP_MAIN); $this->mdo_course = $_course; $this->mdo_type = 'Scorm'; $this->mdo_id = $id; $this->mdo_eid = $this->mdo_type . '.' . $id; $this->mdo_dcmap_e = $ieee_dcmap_e; $this->mdo_dcmap_v = $ieee_dcmap_v; $sql = "SELECT path,description,lp_type FROM {$scormdocument} WHERE id='" . addslashes($id) . "'"; if ($docinfo = @Database::fetch_array(Database::query($sql))) { $this->mdo_path = $docinfo['path']; //Sometimes the new scorm-tool adds '/.' at the end of a directory name, so remove this before continue //the process -- bmol if (substr($this->mdo_path, -2) == '/.') { $this->mdo_path = substr($this->mdo_path, 0, strlen($this->mdo_path) - 2); } $this->mdo_comment = $docinfo['description']; //Don't think the next line is correct. There used to be a 'type' field in the scormdocument table. //This metadata tool only works on folder types -- bmol $this->mdo_filetype = $docinfo['lp_type'] == 2 ? 'folder' : 'xxx'; $this->mdo_url = get_course_web() . $this->mdo_course['path'] . '/scorm/' . $this->mdo_path . '/index.php'; } }
function search_sessions($needle, $type) { global $tbl_session_rel_access_url, $tbl_session, $user_id; $xajax_response = new xajaxResponse(); $return = ''; if (!empty($needle) && !empty($type)) { $needle = Database::escape_string($needle); $assigned_sessions_to_hrm = SessionManager::get_sessions_followed_by_drh($user_id); $assigned_sessions_id = array_keys($assigned_sessions_to_hrm); $without_assigned_sessions = ''; if (count($assigned_sessions_id) > 0) { $without_assigned_sessions = " AND s.id NOT IN(" . implode(',', $assigned_sessions_id) . ")"; } if (api_is_multiple_url_enabled()) { $sql = " SELECT s.id, s.name FROM {$tbl_session} s\n LEFT JOIN {$tbl_session_rel_access_url} a ON (s.id = a.session_id)\n WHERE s.name LIKE '{$needle}%' {$without_assigned_sessions} AND access_url_id = " . api_get_current_access_url_id() . ""; } else { $sql = "SELECT s.id, s.name FROM {$tbl_session} s\n WHERE s.name LIKE '{$needle}%' {$without_assigned_sessions} "; } $rs = Database::query($sql); $return .= '<select class="form-control" id="origin" name="NoAssignedSessionsList[]" multiple="multiple" size="20">'; while ($session = Database::fetch_array($rs)) { $return .= '<option value="' . $session['id'] . '" title="' . htmlspecialchars($session['name'], ENT_QUOTES) . '">' . $session['name'] . '</option>'; } $return .= '</select>'; $xajax_response->addAssign('ajax_list_sessions_multiple', 'innerHTML', api_utf8_encode($return)); } return $xajax_response; }
/** * Search users by username, firstname or lastname, based on the given * search string * @param string Search string * @param int Deprecated param * @return string Xajax response block * @assert () === false */ public static function search_users($needle, $id) { global $tbl_user, $tbl_access_url_rel_user; $xajax_response = new XajaxResponse(); $return = ''; if (!empty($needle)) { // xajax send utf8 datas... datas in db can be non-utf8 datas $charset = api_get_system_encoding(); $needle = api_convert_encoding($needle, $charset, 'utf-8'); $needle = Database::escape_string($needle); // search users where username or firstname or lastname begins likes $needle $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username'; $sql = 'SELECT u.user_id, username, lastname, firstname FROM ' . $tbl_user . ' u ' . ' WHERE (username LIKE "' . $needle . '%" ' . ' OR firstname LIKE "' . $needle . '%" ' . ' OR lastname LIKE "' . $needle . '%") ' . $order_clause . ' LIMIT 11'; $rs = Database::query($sql); $i = 0; while ($user = Database::fetch_array($rs)) { $i++; if ($i <= 10) { $return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_url(\'' . addslashes($user['user_id']) . '\',\'' . api_get_person_name(addslashes($user['firstname']), addslashes($user['lastname'])) . ' (' . addslashes($user['username']) . ')' . '\')">' . api_get_person_name($user['firstname'], $user['lastname']) . ' (' . $user['username'] . ')</a><br />'; } else { $return .= '...<br />'; } } } $xajax_response->addAssign('ajax_list_users', 'innerHTML', api_utf8_encode($return)); return $xajax_response; }
/** * Get glossary term by glossary id * @author Isaac Flores <*****@*****.**> * @param String The glossary term name * @return String The glossary description */ public static function get_glossary_term_by_glossary_name($glossary_name) { global $_course; $glossary_table = Database::get_course_table(TABLE_GLOSSARY); $sql = 'SELECT description FROM ' . $glossary_table . ' WHERE name like trim("' . Database::escape_string($glossary_name) . '") '; $rs = Database::query($sql, __FILE__, __LINE__); $row = Database::fetch_array($rs); return $row['description']; }
/** * @param $query string A query * * @return array|mixed */ protected function _fetch_array($query) { $_cacheResult = $this->_getFromCache($query); if ($_cacheResult !== false && $_cacheResult !== null) { return $_cacheResult; } $result = $this->con->fetch_array($query); $this->_setInCache($query, $result); return $result; }
public static function find_by_sql($sql = "") { $database = new Database(); $result_set = $database->db_query($sql); $object_array = array(); while ($row = $database->fetch_array($result_set)) { $object_array[] = self::instantiate($row); } return $object_array; }
/** * Refreshes the chat windows (usually called every x seconds through AJAX) * @return void (prints JSON array of chat windows) */ public function heartbeat() { $to_user_id = api_get_user_id(); $minutes = 60; $now = time() - $minutes * 60; $now = api_get_utc_datetime($now); //OR sent > '$now' $sql = "SELECT * FROM " . $this->table . "\n WHERE to_user = '******' AND ( recd = 0 ) ORDER BY id ASC"; $result = Database::query($sql); $chat_list = array(); while ($chat = Database::fetch_array($result, 'ASSOC')) { $chat_list[$chat['from_user']]['items'][] = $chat; } $items = array(); foreach ($chat_list as $from_user_id => $rows) { $rows = $rows['items']; $user_info = api_get_user_info($from_user_id, true); //Cleaning tsChatBoxes unset($_SESSION['tsChatBoxes'][$from_user_id]); foreach ($rows as $chat) { $chat['message'] = Security::remove_XSS($chat['message']); $item = array('s' => '0', 'f' => $from_user_id, 'm' => $chat['message'], 'username' => $user_info['complete_name'], 'id' => $chat['id']); $items[$from_user_id]['items'][] = $item; $items[$from_user_id]['user_info']['user_name'] = $user_info['complete_name']; $items[$from_user_id]['user_info']['online'] = $user_info['user_is_online']; $_SESSION['openChatBoxes'][$from_user_id] = api_strtotime($chat['sent'], 'UTC'); } $_SESSION['chatHistory'][$from_user_id]['items'][] = $item; $_SESSION['chatHistory'][$from_user_id]['user_info']['user_name'] = $user_info['complete_name']; $_SESSION['chatHistory'][$from_user_id]['user_info']['online'] = $user_info['user_is_online']; } if (!empty($_SESSION['openChatBoxes'])) { foreach ($_SESSION['openChatBoxes'] as $user_id => $time) { if (!isset($_SESSION['tsChatBoxes'][$user_id])) { $now = time() - $time; $time = api_convert_and_format_date($time, DATE_TIME_FORMAT_SHORT_TIME_FIRST); $message = sprintf(get_lang('SentAtX'), $time); if ($now > 180) { $item = array('s' => '2', 'f' => $user_id, 'm' => $message); if (isset($_SESSION['chatHistory'][$user_id])) { $_SESSION['chatHistory'][$user_id]['items'][] = $item; } $_SESSION['tsChatBoxes'][$user_id] = 1; } } } } //print_r($_SESSION['chatHistory']); $sql = "UPDATE " . $this->table . " SET recd = 1 WHERE to_user = '******' AND recd = 0"; Database::query($sql); if ($items != '') { //$items = substr($items, 0, -1); } echo json_encode(array('items' => $items)); }
public static function get_by_id($id) { $table = Database::get_main_table(TABLE_MAIN_USER_API_KEY); $sql = "SELECT * FROM {$table} WHERE id={$id}"; $res = Database::query($sql); if (Database::num_rows($res) < 1) { return false; } $result = Database::fetch_array($res, 'ASSOC'); return $result; }
public static function find_by_sql($sql) { global $db; $result_set = $db->query($sql); $object_array = array(); $row = Database::fetch_array($result_set); do { $object_array[] = static::instantiate($row); } while ($row = Database::fetch_array($result_set)); return $object_array; }
function load() { $sql = "select jr_id,id_type,ji_value from jrn_info where ji_id=" . $this->ji_id; $r = $this->cn->exec_sql($sql); if (Database::num_row($r) > 0) { $this->from_array(Database::fetch_array($r, 0)); return 0; } else { return 1; } }
function get_lib() { $ret = $this->db->exec_sql("select pcm_lib from tmp_pcmn where\n pcm_val=\$1", array($this->pcm_val)); if (Database::num_row($ret) != 0) { $r = Database::fetch_array($ret); $this->pcm_lib = $r['pcm_lib']; } else { $this->pcm_lib = _("Poste inconnu"); } return $this->pcm_lib; }
public function count() { if ($this->count === false) { $sql = $this->sql(); $sql = "SELECT COUNT(*) AS alpha FROM ({$sql}) AS dat "; $rs = Database::query($sql); $data = Database::fetch_array($rs); $count = $data ? $data['alpha'] : 0; $this->count = (int) $count; } return $this->count; }
function Own($p_cn) { $this->db = $p_cn; $Res = $p_cn->exec_sql("select * from parameter where pr_id like 'MY_%'"); for ($i = 0; $i < Database::num_row($Res); $i++) { $row = Database::fetch_array($Res, $i); $key = $row['pr_id']; $elt = $row['pr_value']; // store value here $this->{"{$key}"} = $elt; } }
/** * \brief Get all the data for this dt_id */ function get() { $sql = "select * from document_type where dt_id=\$1"; $R = $this->db->exec_sql($sql, array($this->dt_id)); if (count($R) == 0) { return 1; } $r = Database::fetch_array($R, 0); $this->dt_id = $r['dt_id']; $this->dt_value = $r['dt_value']; $this->dt_prefix = $r['dt_prefix']; return 0; }
/** * @param int $userId * @param int $courseId * @param int $sessionId * * @return array */ public function getUserAcceptedLegal($userId, $courseId, $sessionId) { $userId = intval($userId); $courseId = intval($courseId); $sessionId = intval($sessionId); $table = Database::get_main_table('session_rel_course_rel_user_legal'); $sql = "SELECT *\n FROM {$table}\n WHERE user_id = {$userId} AND c_id = {$courseId} AND session_id = {$sessionId}"; $result = Database::query($sql); $data = array(); if (Database::num_rows($result) > 0) { $data = Database::fetch_array($result, 'ASSOC'); } return $data; }
/** * Gets the comment about a file from the corresponding database record. * @param string File path * @return string Comment from the database record * Added conditional to the table if is empty. */ function GetComment($path, $course_code = '') { $dbTable = Database::get_course_table(TABLE_DOCUMENT); $course_info = api_get_course_info($course_code); $path = Database::escape_string($path); if (!empty($course_info) && !empty($path)) { $query = "SELECT comment FROM {$dbTable} WHERE c_id = {$course_info['real_id']}"; $result = Database::query($query); while ($row = Database::fetch_array($result)) { return $row[0]; } } return null; }
public function unreadMessage($username, $password) { if ($this->verifyUserPass($username, $password) == "valid") { $table_message = Database::get_main_table(TABLE_MESSAGE); $user_id = UserManager::get_user_id_from_username($username); $condition_msg_status = ' msg_status = 1 '; // define('MESSAGE_STATUS_UNREAD', '1'); $sql_query = "SELECT COUNT(*) as number_messages FROM {$table_message} WHERE {$condition_msg_status} AND user_receiver_id=" . $user_id; $sql_result = Database::query($sql_query); $result = Database::fetch_array($sql_result); return $result['number_messages']; } return "0"; }