/** * 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; }
/** * Add a term (like xapian definition) * @param string Term * @param string Flag (one character) */ public function addTerm($term, $flag) { global $charset; if (strlen($flag) == 1) { $this->terms[] = array('name' => api_convert_encoding(stripslashes($term), 'UTF-8', $charset), 'flag' => $flag); } }
/** * 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_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; }
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; }
function search_courses($needle, $type) { global $_configuration, $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 $charset = api_get_system_encoding(); $needle = api_convert_encoding($needle, $charset, 'utf-8'); $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 ($_configuration['multiple_access_urls']) { $sql = "SELECT c.code, c.title FROM {$tbl_course} c LEFT JOIN {$tbl_course_rel_access_url} a ON (a.course_code = c.code)\n WHERE c.code LIKE '{$needle}%' {$without_assigned_courses} AND access_url_id = " . api_get_current_access_url_id() . ""; } else { $sql = "SELECT c.code, c.title FROM {$tbl_course} c\n WHERE c.code LIKE '{$needle}%' {$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; }
/** * 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; }
function convert($string) { $from = $this->from_encoding; $to = $this->to_encoding; if ($from == $to) { return $string; } return api_convert_encoding($string, $to, $from); }
/** * Gets html pages and compose them into a learning path * @param array The files that will compose the generated learning path. Unused so far. * @return boolean False if file does not exit. Nothing otherwise. */ function make_lp($files = array()) { global $_course; // We get a content where ||page_break|| indicates where the page is broken. if (!file_exists($this->base_work_dir.'/'.$this->created_dir.'/'.$this->file_name.'.html')) { return false; } $content = file_get_contents($this->base_work_dir.'/'.$this->created_dir.'/'.$this->file_name.'.html'); unlink($this->base_work_dir.'/'.$this->file_path); unlink($this->base_work_dir.'/'.$this->created_dir.'/'.$this->file_name.'.html'); // The file is utf8 encoded and it seems to make problems with special quotes. // Then we htmlentities that, we replace these quotes and html_entity_decode that in good charset. $charset = api_get_system_encoding(); $content = api_htmlentities($content, ENT_COMPAT, $this->original_charset); $content = str_replace('’', '\'', $content); $content = api_convert_encoding($content, $charset, $this->original_charset); $content = str_replace($this->original_charset, $charset, $content); $content = api_html_entity_decode($content, ENT_COMPAT, $charset); // Set the path to pictures to absolute (so that it can be modified in fckeditor). $content = preg_replace("|src=\"([^\"]*)|i", "src=\"".api_get_path(REL_COURSE_PATH).$_course['path'].'/document'.$this->created_dir."/\\1", $content); list($header, $body) = explode('<BODY', $content); $body = '<BODY'.$body; // Remove font-family styles. $header = preg_replace("|font\-family[^;]*;|i", '', $header); // Chamilo styles. $my_style = api_get_setting('stylesheets'); if (empty($my_style)) { $my_style = 'chamilo'; } $style_to_import = "<style type=\"text/css\">\r\n"; $style_to_import .= '@import "'.api_get_path(WEB_CODE_PATH).'css/'.$my_style.'/default.css";'."\n"; $style_to_import .= "</style>\r\n"; $header = preg_replace("|</head>|i", "\r\n$style_to_import\r\n\\0", $header); // Line break before and after picture. $header = str_replace('p {', 'p {clear:both;', $header); $header = str_replace('absolute', 'relative', $header); switch ($this->split_steps) { case 'per_page': $this -> dealPerPage($header, $body); break; case 'per_chapter': $this -> dealPerChapter($header, $body); break; } }
/** * This method return content html containing information about sessions and its position for showing it inside dashboard interface * it's important to use the name 'get_block' for beeing used from dashboard controller * @return array column and content html */ public function get_block() { global $charset; $column = 1; $data = array(); $evaluations_base_courses_graph = $this->get_evaluations_base_courses_graph(); $evaluations_courses_in_sessions_graph = $this->get_evaluations_courses_in_sessions_graph(); $html = '<div class="panel panel-default" id="intro"> <div class="panel-heading"> ' . get_lang('EvaluationsGraph') . ' <div class="pull-right"><a class="btn btn-danger btn-xs" onclick="javascript:if(!confirm(\'' . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)) . '\')) return false;" href="index.php?action=disable_block&path=' . $this->path . '"> <em class="fa fa-times"></em> </a></div> </div> <div class="panel-body">'; if (empty($evaluations_base_courses_graph) && empty($evaluations_courses_in_sessions_graph)) { $html .= '<p>' . api_convert_encoding(get_lang('GraphicNotAvailable'), 'UTF-8') . '</p>'; } else { // display evaluations base courses graph if (!empty($evaluations_base_courses_graph)) { foreach ($evaluations_base_courses_graph as $course_code => $img_html) { $html .= '<div><strong>' . $course_code . '</strong></div>'; $html .= $img_html; } } // display evaluations base courses graph if (!empty($evaluations_courses_in_sessions_graph)) { foreach ($evaluations_courses_in_sessions_graph as $session_id => $courses) { $session_name = api_get_session_name($session_id); $html .= '<div><strong>' . $session_name . ':' . get_lang('Evaluations') . '</strong></div>'; foreach ($courses as $course_code => $img_html) { $html .= '<div><strong>' . $course_code . '</strong></div>'; $html .= $img_html; } } } } $html .= '</div> </div>'; $data['column'] = $column; $data['content_html'] = $html; return $data; }
/** * This method return content html containing information about sessions and its position for showing it inside dashboard interface * it's important to use the name 'get_block' for beeing used from dashboard controller * @return array column and content html */ public function get_block() { global $charset; $column = 1; $data = array(); $evaluations_base_courses_graph = $this->get_evaluations_base_courses_graph(); $evaluations_courses_in_sessions_graph = $this->get_evaluations_courses_in_sessions_graph(); $html = '<li class="widget color-orange" id="intro"> <div class="widget-head"> <h3>' . get_lang('EvaluationsGraph') . '</h3> <div class="widget-actions"><a onclick="javascript:if(!confirm(\'' . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)) . '\')) return false;" href="index.php?action=disable_block&path=' . $this->path . '">' . Display::return_icon('close.gif', get_lang('Close')) . '</a></div> </div> <div class="widget-content" align="center">'; if (empty($evaluations_base_courses_graph) && empty($evaluations_courses_in_sessions_graph)) { $html .= '<p>' . api_convert_encoding(get_lang('GraphicNotAvailable'), 'UTF-8') . '</p>'; } else { // display evaluations base courses graph if (!empty($evaluations_base_courses_graph)) { foreach ($evaluations_base_courses_graph as $course_code => $img_html) { $html .= '<div><strong>' . $course_code . '</strong></div>'; $html .= $img_html; } } // display evaluations base courses graph if (!empty($evaluations_courses_in_sessions_graph)) { foreach ($evaluations_courses_in_sessions_graph as $session_id => $courses) { $session_name = api_get_session_name($session_id); $html .= '<div><strong>' . $session_name . ':' . get_lang('Evaluations') . '</strong></div>'; foreach ($courses as $course_code => $img_html) { $html .= '<div><strong>' . $course_code . '</strong></div>'; $html .= $img_html; } } } } $html .= '</div> </li>'; $data['column'] = $column; $data['content_html'] = $html; return $data; }
function search_coachs($needle) { global $tbl_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'); $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username'; // search users where username or firstname or lastname begins likes $needle $sql = 'SELECT username, lastname, firstname FROM ' . $tbl_user . ' user WHERE (username LIKE "' . $needle . '%" OR firstname LIKE "' . $needle . '%" OR lastname LIKE "' . $needle . '%") AND status=1' . $order_clause . ' LIMIT 10'; if (api_is_multiple_url_enabled()) { $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); $access_url_id = api_get_current_access_url_id(); if ($access_url_id != -1) { $sql = 'SELECT username, lastname, firstname FROM ' . $tbl_user . ' user INNER JOIN ' . $tbl_user_rel_access_url . ' url_user ON (url_user.user_id=user.user_id) WHERE access_url_id = ' . $access_url_id . ' AND (username LIKE "' . $needle . '%" OR firstname LIKE "' . $needle . '%" OR lastname LIKE "' . $needle . '%") AND status=1' . $order_clause . ' LIMIT 10'; } } $rs = Database::query($sql); while ($user = Database::fetch_array($rs)) { $return .= '<a href="javascript: void(0);" onclick="javascript: fill_coach_field(\'' . $user['username'] . '\')">' . api_get_person_name($user['firstname'], $user['lastname']) . ' (' . $user['username'] . ')</a><br />'; } } $xajax_response->addAssign('ajax_list_coachs', 'innerHTML', api_utf8_encode($return)); return $xajax_response; }
/** * Search for a session based on a given search string * @param string A search string * @param string A search box type (single or anything else) * @return string XajaxResponse * @assert ('abc','single') !== '' */ function search_courses($needle, $type) { global $tbl_session; $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'); $needle = Database::escape_string($needle); $sql = 'SELECT * FROM ' . $tbl_session . ' WHERE name LIKE "' . $needle . '%" ORDER BY id'; $rs = Database::query($sql); $course_list = array(); $return .= '<select id="origin" name="NoSessionCategoryList[]" multiple="multiple" size="20" style="width:340px;">'; while ($course = Database::fetch_array($rs)) { $course_list[] = $course['id']; $return .= '<option value="' . $course['id'] . '" title="' . htmlspecialchars($course['name'], ENT_QUOTES) . '">' . $course['name'] . '</option>'; } $return .= '</select>'; $xajax_response->addAssign('ajax_list_courses_multiple', 'innerHTML', api_utf8_encode($return)); } $_SESSION['course_list'] = $course_list; return $xajax_response; }
function search($needle, $type) { global $tbl_user, $elements_in; $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 = Database::escape_string($needle); $needle = api_convert_encoding($needle, $charset, 'utf-8'); if ($type == 'single') { // search users where username or firstname or lastname begins likes $needle /* $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user WHERE (username LIKE "'.$needle.'%" OR firstname LIKE "'.$needle.'%" OR lastname LIKE "'.$needle.'%") AND user.user_id<>"'.$user_anonymous.'" AND user.status<>'.DRH.''. $order_clause. ' LIMIT 11';*/ } else { $list = CourseManager::get_courses_list(0, 0, 2, 'ASC', -1, $needle); } $i = 0; if ($type == 'single') { /* while ($user = Database :: fetch_array($rs)) { $i++; if ($i<=10) { $person_name = api_get_person_name($user['firstname'], $user['lastname']); $return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_session(\''.$user['user_id'].'\',\''.$person_name.' ('.$user['username'].')'.'\')">'.$person_name.' ('.$user['username'].')</a><br />'; } else { $return .= '...<br />'; } } $xajax_response -> addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return));*/ } else { $return .= '<select id="elements_not_in" name="elements_not_in_name[]" multiple="multiple" size="15" style="width:360px;">'; foreach ($list as $row) { if (!in_array($row['id'], array_keys($elements_in))) { $return .= '<option value="' . $row['id'] . '">' . $row['title'] . ' (' . $row['visual_code'] . ')</option>'; } } $return .= '</select>'; $xajax_response->addAssign('ajax_list_multiple', 'innerHTML', api_utf8_encode($return)); } } return $xajax_response; }
/** * Static function to parse AICC ini files. * Based on work by sinedeo at gmail dot com published on php.net (parse_ini_file()) * @param string File path * @return array Structured array */ function parse_ini_file_quotes_safe($f) { $null = ""; $r = $null; $sec = $null; $f = @file($f); for ($i = 0; $i < @count($f); $i++) { $newsec = 0; $w = @trim($f[$i]); if ($w) { if ($w[0] == ';') { continue; } if (!$r or $sec) { if (@substr($w, 0, 1) == "[" and @substr($w, -1, 1) == "]") { $sec = @substr($w, 1, @strlen($w) - 2); $newsec = 1; } } if (!$newsec) { $w = @explode("=", $w); $k = @trim($w[0]); unset($w[0]); $v = @trim(@implode("=", $w)); $v = api_convert_encoding($v, api_get_system_encoding(), mb_detect_encoding($v)); if (@substr($v, 0, 1) == "\"" and @substr($v, -1, 1) == "\"") { $v = @substr($v, 1, @strlen($v) - 2); } if ($sec) { if (strtolower($sec) == 'course_description') { //special case $r[strtolower($sec)] = $k; } else { $r[strtolower($sec)][strtolower($k)] = $v; } } else { $r[strtolower($k)] = $v; } } } } return $r; }
if (empty($event['end_date'])) { $y2 = $y; $m2 = $m; $d2 = $d; $h2 = $h; $M2 = $M + 15; $s2 = $s; if ($M2 > 60) { $M2 = $M2 - 60; $h2 += 1; } } else { list($y2, $m2, $d2, $h2, $M2, $s2) = preg_split('/[\\s:-]/', $event['end_date']); } $vevent->setProperty('dtend', array('year' => $y2, 'month' => $m2, 'day' => $d2, 'hour' => $h2, 'min' => $M2, 'sec' => $s2)); $vevent->setProperty('description', api_convert_encoding($event['description'], 'UTF-8', $charset)); //$vevent->setProperty( 'comment', 'This is a comment' ); //$user = api_get_user_info($event['user']); //$vevent->setProperty('organizer',$user['mail']); //$vevent->setProperty('attendee',$user['mail']); //$course = api_get_course_info(); $vevent->setProperty('location', $course_info['name']); // property name - case independent /*if($ai['repeat']) { $trans = array('daily'=>'DAILY','weekly'=>'WEEKLY','monthlyByDate'=>'MONTHLY','yearly'=>'YEARLY'); $freq = $trans[$ai['repeat_type']]; list($e_y,$e_m,$e_d) = split('/',date('Y/m/d',$ai['repeat_end'])); $vevent->setProperty('rrule',array('FREQ'=>$freq,'UNTIL'=>array('year'=>$e_y,'month'=>$e_m,'day'=>$e_d),'INTERVAL'=>'1')); }*/ //$vevent->setProperty( 'rrule', array( 'FREQ' => 'WEEKLY', 'count' => 4));// occurs also four next weeks $ical->setConfig('filename', $y . $m . $d . $h . $M . $s . '-' . rand(1, 1000) . '.ics');
/** * @param array $courseInfo * @param $file * @return array|bool|string */ public function importEventFile($courseInfo, $file) { $charset = api_get_system_encoding(); $filepath = api_get_path(SYS_ARCHIVE_PATH) . $file['name']; $messages = array(); if (!@move_uploaded_file($file['tmp_name'], $filepath)) { error_log('Problem moving uploaded file: ' . $file['error'] . ' in ' . __FILE__ . ' line ' . __LINE__); return false; } $data = file_get_contents($filepath); $trans = array('DAILY' => 'daily', 'WEEKLY' => 'weekly', 'MONTHLY' => 'monthlyByDate', 'YEARLY' => 'yearly'); $sentTo = array('everyone' => true); $calendar = Sabre\VObject\Reader::read($data); $currentTimeZone = _api_get_timezone(); if (!empty($calendar->VEVENT)) { foreach ($calendar->VEVENT as $event) { $start = $event->DTSTART->getDateTime(); $end = $event->DTEND->getDateTime(); //Sabre\VObject\DateTimeParser::parseDateTime(string $dt, \Sabre\VObject\DateTimeZone $tz) $startDateTime = api_get_local_time($start->format('Y-m-d H:i:s'), $currentTimeZone, $start->format('e')); $endDateTime = api_get_local_time($end->format('Y-m-d H:i'), $currentTimeZone, $end->format('e')); $title = api_convert_encoding((string) $event->summary, $charset, 'UTF-8'); $description = api_convert_encoding((string) $event->description, $charset, 'UTF-8'); $id = $this->addEvent($startDateTime, $endDateTime, 'false', $title, $description, $sentTo); $messages[] = " {$title} - " . $startDateTime . " - " . $endDateTime; //$attendee = (string)$event->attendee; /** @var Sabre\VObject\Property\ICalendar\Recur $repeat */ $repeat = $event->RRULE; if ($id && !empty($repeat)) { $repeat = $repeat->getParts(); $freq = $trans[$repeat['FREQ']]; if (isset($repeat['UNTIL']) && !empty($repeat['UNTIL'])) { // Check if datetime or just date (strlen == 8) if (strlen($repeat['UNTIL']) == 8) { // Fix the datetime format to avoid exception in the next step $repeat['UNTIL'] .= 'T000000'; } $until = Sabre\VObject\DateTimeParser::parseDateTime($repeat['UNTIL'], new DateTimeZone($currentTimeZone)); $until = $until->format('Y-m-d H:i'); //$res = agenda_add_repeat_item($courseInfo, $id, $freq, $until, $attendee); $this->addRepeatedItem($id, $freq, $until, $sentTo); } if (!empty($repeat['COUNT'])) { /*$count = $repeat['COUNT']; $interval = $repeat['INTERVAL']; $endDate = null; switch($freq) { case 'daily': $start = api_strtotime($startDateTime); $date = new DateTime($startDateTime); $days = $count * $interval; var_dump($days); $date->add(new DateInterval("P".$days."D")); $endDate = $date->format('Y-m-d H:i'); //$endDate = $count * for ($i = 0; $i < $count; $i++) { $days = 86400 * 7 } } }*/ //$res = agenda_add_repeat_item($courseInfo, $id, $freq, $count, $attendee); /*$this->addRepeatedItem( $id, $freq, $endDate, $sentTo );*/ } } } } if (!empty($messages)) { $messages = implode('<br /> ', $messages); } else { $messages = get_lang('NoAgendaItems'); } return $messages; }
} if ($debug > 0) { error_log('Videoconf upload path: ' . VIDEOCONF_UPLOAD_PATH); } /* $canDelete = ($canDelete && $isBellowVideoConfUploadPath); */ $can_delete = $is_manager && $is_below_videoconf_dir; // get files list $files = DocumentManager::get_all_document_data($_course, $cwd, 0, null, false); printf("<dokeosobject><fileListMeta></fileListMeta><fileList>"); printf("<folders>"); // title filter if (is_array($files)) { foreach (array_keys($files) as $k) { // converting to UTF-8 $files[$k]['title'] = api_convert_encoding(api_strlen($files[$k]['title']) > 32 ? api_substr($files[$k]['title'], 0, 32) . "..." : $files[$k]['title'], 'utf-8', api_get_system_encoding()); // removing '<', '>' and '_' $files[$k]['title'] = str_replace(array('<', '>', '_'), ' ', $files[$k]['title']); } } if (is_array($files)) { foreach ($files as $i) { if ($i["filetype"] == "folder") { printf('<folder><path>%s</path><title>%s</title><canDelete>%s</canDelete></folder>', $i['path'], $i['title'], $can_delete ? 'true' : 'false'); } } } printf("</folders><files>"); if (is_array($files)) { foreach ($files as $i) { $extension = strrpos($i['path'], '.') > 0 ? substr($i['path'], strrpos($i['path'], '.'), 10) : '';
/** * Export tabular data to XLS-file (as html table) * @param array $data * @param string $filename */ public static function export_table_xls_html($data, $filename = 'export', $encoding = 'utf-8') { $file = api_get_path(SYS_ARCHIVE_PATH) . uniqid('') . '.xls'; $handle = fopen($file, 'a+'); $systemEncoding = api_get_system_encoding(); fwrite($handle, '<!DOCTYPE html><html><meta http-equiv="Content-Type" content="text/html" charset="utf-8" /><body><table>'); foreach ($data as $id => $row) { foreach ($row as $id2 => $row2) { $data[$id][$id2] = api_htmlentities($row2); } } foreach ($data as $row) { $string = implode("</td><td>", $row); $string = '<tr><td>' . $string . '</td></tr>'; if ($encoding != 'utf-8') { $string = api_convert_encoding($string, $encoding, $systemEncoding); } fwrite($handle, $string . "\n"); } fwrite($handle, '</table></body></html>'); fclose($handle); DocumentManager::file_send_for_download($file, true, $filename . '.xls'); exit; }
/** * This function draw the graphic to be displayed on the user view as an image * * @param array $sql_result * @param string $start_date * @param string $end_date * @param string $type * @author Jorge Frisancho Jibaja * @version OCT-22- 2010 * @return string */ function grapher($sql_result, $start_date, $end_date, $type = "") { if (empty($start_date)) { $start_date = ""; } if (empty($end_date)) { $end_date = ""; } if ($type == "") { $type = 'day'; } $main_year = $main_month_year = $main_day = array(); // get last 8 days/months $last_days = 5; $last_months = 3; for ($i = $last_days; $i >= 0; $i--) { $main_day[date('d-m-Y', mktime() - $i * 3600 * 24)] = 0; } for ($i = $last_months; $i >= 0; $i--) { $main_month_year[date('m-Y', mktime() - $i * 30 * 3600 * 24)] = 0; } $i = 0; if (is_array($sql_result) && count($sql_result) > 0) { foreach ($sql_result as $key => $data) { //creating the main array $main_month_year[date('m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0); $main_day[date('d-m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0); if ($i > 500) { break; } $i++; } switch ($type) { case 'day': $main_date = $main_day; break; case 'month': $main_date = $main_month_year; break; case 'year': $main_date = $main_year; break; } // the nice graphics :D $labels = array_keys($main_date); if (count($main_date) == 1) { $labels = $labels[0]; $main_date = $main_date[$labels]; } /* Create and populate the pData object */ $myData = new pData(); $myData->addPoints($main_date, 'Serie1'); if (count($main_date) != 1) { $myData->addPoints($labels, 'Labels'); $myData->setSerieDescription('Labels', 'Months'); $myData->setAbscissa('Labels'); } $myData->setSerieWeight('Serie1', 1); $myData->setSerieDescription('Serie1', get_lang('MyResults')); $myData->setAxisName(0, get_lang('Minutes')); $myData->loadPalette(api_get_path(SYS_CODE_PATH) . 'palettes/pchart/default.color', true); // Cache definition $cachePath = api_get_path(SYS_ARCHIVE_PATH); $myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1))); $chartHash = $myCache->getHash($myData); if ($myCache->isInCache($chartHash)) { //if we already created the img $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; $myCache->saveFromCache($chartHash, $imgPath); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; } else { /* Define width, height and angle */ $mainWidth = 760; $mainHeight = 230; $angle = 50; /* Create the pChart object */ $myPicture = new pImage($mainWidth, $mainHeight, $myData); /* Turn of Antialiasing */ $myPicture->Antialias = false; /* Draw the background */ $settings = array("R" => 255, "G" => 255, "B" => 255); $myPicture->drawFilledRectangle(0, 0, $mainWidth, $mainHeight, $settings); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, $mainWidth - 1, $mainHeight - 1, array("R" => 0, "G" => 0, "B" => 0)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', "FontSize" => 10)); /* Write the chart title */ $myPicture->drawText($mainWidth / 2, 30, get_lang('ExercisesInTimeProgressChart'), array("FontSize" => 12, "Align" => TEXT_ALIGN_BOTTOMMIDDLE)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', "FontSize" => 8)); /* Define the chart area */ $myPicture->setGraphArea(50, 40, $mainWidth - 40, $mainHeight - 80); /* Draw the scale */ $scaleSettings = array('XMargin' => 10, 'YMargin' => 10, 'Floating' => true, 'GridR' => 200, 'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true, 'LabelRotation' => $angle, 'Mode' => SCALE_MODE_ADDALL_START0); $myPicture->drawScale($scaleSettings); /* Turn on Antialiasing */ $myPicture->Antialias = true; /* Enable shadow computing */ $myPicture->setShadow(true, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); /* Draw the line chart */ $myPicture->setFontProperties(array("FontName" => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', "FontSize" => 10)); $myPicture->drawSplineChart(); $myPicture->drawPlotChart(array("DisplayValues" => true, "PlotBorder" => true, "BorderSize" => 1, "Surrounding" => -60, "BorderAlpha" => 80)); /* Do NOT Write the chart legend */ /* Write and save into cache */ $myCache->writeToCache($chartHash, $myPicture); $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; $myCache->saveFromCache($chartHash, $imgPath); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; } $html = '<img src="' . $imgPath . '">'; return $html; } else { $foo_img = api_convert_encoding('<div id="messages" class="warning-message">' . get_lang('GraphicNotAvailable') . '</div>', 'UTF-8'); return $foo_img; } }
/** * Adds a user to the Dokeos database or updates its data * @param string username (and uid inside LDAP) * @author Mustapha Alouani */ function ldap_add_user($login) { global $ldap_basedn, $ldap_host, $ldap_port, $ldap_rdn, $ldap_pass; $ds = ldap_connect($ldap_host, $ldap_port); ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ds, LDAP_OPT_REFERRALS, 0); if ($ds) { $str_query = "(uid=" . $login . ")"; $r = false; $res = ldap_handle_bind($ds, $r); $sr = ldap_search($ds, $ldap_basedn, $str_query); //echo "Le nombre de resultats est : ".ldap_count_entries($ds,$sr)."<p>"; $info = ldap_get_entries($ds, $sr); for ($key = 0; $key < $info['count']; $key++) { $lastname = api_convert_encoding($info[$key]['sn'][0], api_get_system_encoding(), 'UTF-8'); $firstname = api_convert_encoding($info[$key]['givenname'][0], api_get_system_encoding(), 'UTF-8'); $email = $info[$key]['mail'][0]; // Get uid from dn $dn_array = ldap_explode_dn($info[$key]['dn'], 1); $username = $dn_array[0]; // uid is first key $outab[] = $info[$key]['edupersonprimaryaffiliation'][0]; // Ici "student" //$val = ldap_get_values_len($ds, $entry, "userPassword"); //$val = ldap_get_values_len($ds, $info[$key], "userPassword"); //$password = $val[0]; // TODO the password, if encrypted at the source, will be encrypted twice, which makes it useless. Try to fix that. $password = $info[$key]['userPassword'][0]; $structure = $info[$key]['edupersonprimaryorgunitdn'][0]; $array_structure = explode(",", $structure); $array_val = explode("=", $array_structure[0]); $etape = $array_val[1]; $array_val = explode("=", $array_structure[1]); $annee = $array_val[1]; // Pour faciliter la gestion on ajoute le code "etape-annee" $official_code = $etape . "-" . $annee; $auth_source = 'ldap'; // Pas de date d'expiration d'etudiant (a recuperer par rapport au shadow expire LDAP) $expiration_date = '0000-00-00 00:00:00'; $active = 1; if (empty($status)) { $status = 5; } if (empty($phone)) { $phone = ''; } if (empty($picture_uri)) { $picture_uri = ''; } // Ajout de l'utilisateur if (UserManager::is_username_available($username)) { $user_id = UserManager::create_user($firstname, $lastname, $status, $email, $username, $password, $official_code, api_get_setting('platformLanguage'), $phone, $picture_uri, $auth_source, $expiration_date, $active); } else { $user = UserManager::get_user_info($username); $user_id = $user['user_id']; UserManager::update_user($user_id, $firstname, $lastname, $username, null, null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active); } } } else { Display::display_error_message(get_lang('LDAPConnectionError')); } return $user_id; }
/** * @param $needle * @return xajaxResponse */ public static function searchUserGroupAjax($needle) { $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 id, name FROM ' . Database::get_main_table(TABLE_USERGROUP) . ' u WHERE name LIKE "' . $needle . '%" ORDER BY name LIMIT 11'; $result = Database::query($sql); $i = 0; while ($data = Database::fetch_array($result)) { $i++; if ($i <= 10) { $return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_url(\'' . addslashes($data['id']) . '\',\'' . addslashes($data['name']) . ' \')">' . $data['name'] . ' </a><br />'; } else { $return .= '...<br />'; } } } $response->addAssign('ajax_list_courses', 'innerHTML', api_utf8_encode($return)); return $response; }
$course_filter = chamilo_get_boolean_query(XAPIAN_PREFIX_COURSEID . $cid); } if (count($term_array)) { $fixed_queries = chamilo_join_queries($term_array, null, $op); if ($course_filter != NULL) { $fixed_queries = chamilo_join_queries($fixed_queries, $course_filter, 'and'); } } else { if (!empty($query)) { $fixed_queries = array($course_filter); } } list($count, $results) = chamilo_query_query(api_convert_encoding($query, 'UTF-8', $charset), 0, 1000, $fixed_queries); // Prepare blocks to show. $blocks = array(); if ($count > 0) { foreach ($results as $result) { // Fill the result array. if (empty($result['thumbnail'])) { $result['thumbnail'] = '../img/no_document_thumb.jpg'; } if (!empty($result['url'])) { $a_prefix = '<a href="'.$result['url'].'">'; $a_sufix = '</a>'; } else {
function add_docs_to_visio($files = array()) { global $_course; foreach ($files as $file) { list($slide_name,$file_name) = explode('||',$file); // '||' is used as separator between slide name (with accents) and file name (without accents). $slide_name = api_htmlentities($slide_name, ENT_COMPAT, $this->original_charset); $slide_name = str_replace('’', '\'', $slide_name); $slide_name = api_convert_encoding($slide_name, api_get_system_encoding(), $this->original_charset); $slide_name = api_html_entity_decode($slide_name, ENT_COMPAT, api_get_system_encoding()); $did = add_document($_course, $this->created_dir.'/'.urlencode($file_name), 'file', filesize($this->base_work_dir.$this->created_dir.'/'.$file_name), $slide_name); if ($did) { api_item_property_update($_course, TOOL_DOCUMENT, $did, 'DocumentAdded', $_SESSION['_uid'], 0, null, null, null, api_get_session_id()); } } }
function search_users($needle, $type) { global $tbl_user, $tbl_session_rel_user, $id_session; $xajax_response = new XajaxResponse(); $return = ''; if (!empty($needle) && !empty($type)) { //normal behaviour if ($type == 'any_session' && $needle == 'false') { $type = 'multiple'; $needle = ''; } // xajax send utf8 datas... datas in db can be non-utf8 datas $charset = api_get_system_encoding(); $needle = Database::escape_string($needle); $needle = api_convert_encoding($needle, $charset, 'utf-8'); $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username'; $cond_user_id = ''; //Only for single & multiple if (in_array($type, array('single', 'multiple'))) { if (!empty($id_session)) { $id_session = intval($id_session); // check id_user from session_rel_user table $sql = 'SELECT id_user FROM ' . $tbl_session_rel_user . ' WHERE id_session ="' . $id_session . '" AND relation_type<>' . SESSION_RELATION_TYPE_RRHH . ' '; $res = Database::query($sql); $user_ids = array(); if (Database::num_rows($res) > 0) { while ($row = Database::fetch_row($res)) { $user_ids[] = (int) $row[0]; } } if (count($user_ids) > 0) { $cond_user_id = ' AND user.user_id NOT IN(' . implode(",", $user_ids) . ')'; } } } switch ($type) { case 'single': // search users where username or firstname or lastname begins likes $needle $sql = 'SELECT user.user_id, username, lastname, firstname, official_code FROM ' . $tbl_user . ' user WHERE (username LIKE "' . $needle . '%" OR firstname LIKE "' . $needle . '%" OR lastname LIKE "' . $needle . '%") AND user.status<>6 AND user.status<>' . DRH . '' . $order_clause . ' LIMIT 11'; break; case 'multiple': $sql = 'SELECT user.user_id, username, lastname, firstname, official_code FROM ' . $tbl_user . ' user WHERE ' . (api_sort_by_first_name() ? 'firstname' : 'lastname') . ' LIKE "' . $needle . '%" AND user.status<>' . DRH . ' AND user.status<>6 ' . $cond_user_id . $order_clause; break; case 'any_session': $sql = 'SELECT DISTINCT user.user_id, username, lastname, firstname, official_code FROM ' . $tbl_user . ' user LEFT OUTER JOIN ' . $tbl_session_rel_user . ' s ON (s.id_user = user.user_id) WHERE s.id_user IS null AND user.status<>' . DRH . ' AND user.status<>6 ' . $cond_user_id . $order_clause; break; } if (api_is_multiple_url_enabled()) { $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); $access_url_id = api_get_current_access_url_id(); if ($access_url_id != -1) { switch ($type) { case 'single': $sql = 'SELECT user.user_id, username, lastname, firstname, official_code FROM ' . $tbl_user . ' user INNER JOIN ' . $tbl_user_rel_access_url . ' url_user ON (url_user.user_id=user.user_id) WHERE access_url_id = ' . $access_url_id . ' AND (username LIKE "' . $needle . '%" OR firstname LIKE "' . $needle . '%" OR lastname LIKE "' . $needle . '%") AND user.status<>6 AND user.status<>' . DRH . ' ' . $order_clause . ' LIMIT 11'; break; case 'multiple': $sql = 'SELECT user.user_id, username, lastname, firstname , official_code FROM ' . $tbl_user . ' user INNER JOIN ' . $tbl_user_rel_access_url . ' url_user ON (url_user.user_id=user.user_id) WHERE access_url_id = ' . $access_url_id . ' AND ' . (api_sort_by_first_name() ? 'firstname' : 'lastname') . ' LIKE "' . $needle . '%" AND user.status<>' . DRH . ' AND user.status<>6 ' . $cond_user_id . $order_clause; break; case 'any_session': $sql = 'SELECT DISTINCT user.user_id, username, lastname, firstname, official_code FROM ' . $tbl_user . ' user LEFT OUTER JOIN ' . $tbl_session_rel_user . ' s ON (s.id_user = user.user_id) INNER JOIN ' . $tbl_user_rel_access_url . ' url_user ON (url_user.user_id=user.user_id) WHERE access_url_id = ' . $access_url_id . ' AND s.id_user IS null AND user.status<>' . DRH . ' AND user.status<>6 ' . $cond_user_id . $order_clause; break; } } } $rs = Database::query($sql); $i = 0; if ($type == 'single') { while ($user = Database::fetch_array($rs)) { $i++; if ($i <= 10) { $person_name = api_get_person_name($user['firstname'], $user['lastname']) . ' (' . $user['username'] . ') ' . $user['official_code']; $return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_session(\'' . $user['user_id'] . '\',\'' . $person_name . ' ' . '\')">' . $person_name . ' </a><br />'; } else { $return .= '...<br />'; } } $xajax_response->addAssign('ajax_list_users_single', 'innerHTML', api_utf8_encode($return)); } else { global $nosessionUsersList; $return .= '<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" style="width:360px;">'; while ($user = Database::fetch_array($rs)) { $person_name = api_get_person_name($user['firstname'], $user['lastname']) . ' (' . $user['username'] . ') ' . $user['official_code']; $return .= '<option value="' . $user['user_id'] . '">' . $person_name . ' </option>'; } $return .= '</select>'; $xajax_response->addAssign('ajax_list_users_multiple', 'innerHTML', api_utf8_encode($return)); } } return $xajax_response; }
function ldap_add_user_by_array($data, $update_if_exists = true) { $lastname = api_convert_encoding($data['sn'][0], api_get_system_encoding(), 'UTF-8'); $firstname = api_convert_encoding($data['cn'][0], api_get_system_encoding(), 'UTF-8'); $email = $data['mail'][0]; // Get uid from dn $dn_array = ldap_explode_dn($data['dn'], 1); $username = $dn_array[0]; // uid is first key $outab[] = $data['edupersonprimaryaffiliation'][0]; // Here, "student" //$val = ldap_get_values_len($ds, $entry, "userPassword"); //$val = ldap_get_values_len($ds, $data, "userPassword"); //$password = $val[0]; // TODO the password, if encrypted at the source, will be encrypted twice, which makes it useless. Try to fix that. $password = $data['userPassword'][0]; $structure = $data['edupersonprimaryorgunitdn'][0]; $array_structure = explode(",", $structure); $array_val = explode("=", $array_structure[0]); $etape = $array_val[1]; $array_val = explode("=", $array_structure[1]); $annee = $array_val[1]; // To ease management, we add the step-year (etape-annee) code $official_code = $etape . "-" . $annee; $auth_source = 'ldap'; // No expiration date for students (recover from LDAP's shadow expiry) $expiration_date = '0000-00-00 00:00:00'; $active = 1; if (empty($status)) { $status = 5; } if (empty($phone)) { $phone = ''; } if (empty($picture_uri)) { $picture_uri = ''; } // Adding user $user_id = 0; if (UserManager::is_username_available($username)) { $user_id = UserManager::create_user($firstname, $lastname, $status, $email, $username, $password, $official_code, api_get_setting('platformLanguage'), $phone, $picture_uri, $auth_source, $expiration_date, $active); } else { if ($update_if_exists) { $user = UserManager::get_user_info($username); $user_id = $user['user_id']; UserManager::update_user($user_id, $firstname, $lastname, $username, null, null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active); } } return $user_id; }
/** * Creates a list with all the assignments in it * * @return string */ function get_student_publication() { global $charset; $table_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); $sp_lang_var = api_convert_encoding(get_lang('LpAssignment'), $charset, api_get_system_encoding()); $return = '<a href="#" onclick="javascript:popup(\'popUpDiv5\');" class="big_button four_buttons rounded grey_border assignement_button">' . $sp_lang_var . '</a>'; $assignments_lang_var = api_convert_encoding(get_lang('Assignments'), $charset, api_get_system_encoding()); $close_lang_var = api_convert_encoding(get_lang('Close'), $charset, api_get_system_encoding()); $newassignment_lang_var = api_convert_encoding(get_lang('LpNewAssignment'), $charset, api_get_system_encoding()); $return .= '<div id="popUpDiv5" class="author_popup gradient rounded_10 grey_border" style="display:none;">' . '<span class="title">' . $assignments_lang_var . '</span>' . '<a href="#" class="close" onclick="javascript:popup(\'popUpDiv5\');">' . $close_lang_var . '</a>'; $return .= '<div id="resDoc" class="content">'; $sql = "SELECT id,url FROM {$table_work} s INNER JOIN {$table_item_property} i ON s.id = i.ref WHERE i.insert_user_id = '" . api_get_user_id() . "' AND session_id = '" . api_get_session_id() . "' AND filetype='folder' AND i.tool = 'work' AND i.visibility=1 "; $a_work = array(); $rs = Database::query($sql, __FILE__, __LINE__); while ($row = Database::fetch_array($rs)) { $a_work[] = $row; } foreach ($a_work as $work) { $return .= '<div class="lp_resource_element">'; if (!empty($work['id'])) { $return .= '<img alt="" src="../img/assignment_22.png" style="margin-right:5px;" title="" />'; $return .= '<a style="cursor:hand" style="vertical-align:middle"></a> <a href="' . api_get_self() . '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&action=add_item&type=' . TOOL_STUDENTPUBLICATION . '&work_id=' . $work['id'] . '&lp_id=' . $this->lp_id . '" style="vertical-align:middle">' . api_convert_encoding(substr($work['url'], 1), $charset, api_get_system_encoding()) . '</a>'; } $return .= '</div>'; } $return .= '<div class="lp_resource_element">'; $return .= Display::return_icon('pixel.gif', '', array('class' => 'actionplaceholdericon actionnewlist', 'alt' => "' . {$newassignment_lang_var} . '", 'style' => 'margin-right:5px;', 'title' => "' . {$newassignment_lang_var} . '")); $return .= '<a href="../work/work.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&toolgroup=&curdirpath=/&createdir=1&origin=&gradebook=type=' . TOOL_STUDENTPUBLICATION . '&lp_id=' . $this->lp_id . '">' . $newassignment_lang_var . '</a>'; $return .= '</div>'; $return .= '</div>'; $return .= '</div>'; return $return; }
/** * Static function that parses CSV files into simple arrays, based on a function * by spam at cyber-space dot nl published on php.net (fgetcsv()). * @param string Filepath * @param string CSV delimiter * @param string CSV enclosure * @param boolean Might one field name happen more than once on the same line? (then split by comma in the values) * @return array Simple structured array */ function parse_csv_file($f, $delim = ',', $enclosure = '"', $multiples = false) { $data = @file_get_contents($f); $data = api_convert_encoding($data, api_get_system_encoding(), $this->config_encoding); $enclosed = false; $fldcount = 0; $linecount = 0; $fldval = ''; for ($i = 0; $i < strlen($data); $i++) { $chr = $data{$i}; switch ($chr) { case $enclosure: if ($enclosed && $data{$i+1} == $enclosure) { $fldval .= $chr; ++$i; // Skip the next character. } else $enclosed = !$enclosed; break; case $delim: if (!$enclosed) { $ret_array[$linecount][$fldcount++] = $fldval; $fldval = ''; } else $fldval .= $chr; break; case "\r": if (!$enclosed&&$data{$i+1} == "\n") continue; case "\n": if (!$enclosed) { $ret_array[$linecount++][$fldcount] = $fldval; $fldcount = 0; $fldval = ''; } else $fldval .= $chr; break; case "\\r": if (!$enclosed&&$data{$i+1} == "\\n") continue; case "\\n": if (!$enclosed) { $ret_array[$linecount++][$fldcount] = $fldval; $fldcount = 0; $fldval = ''; } else $fldval .= $chr; break; default: $fldval .= $chr; } } if ($fldval) { $ret_array[$linecount][$fldcount] = $fldval; } // Transform the array to use the first line as titles. $titles = array(); $ret_ret_array = array(); foreach ($ret_array as $line_idx => $line) { if ($line_idx == 0) { $titles = $line; } else { $ret_ret_array[$line_idx] = array(); foreach ($line as $idx => $val) { if ($multiples && !empty($ret_ret_array[$line_idx][api_strtolower($titles[$idx])])) { $ret_ret_array[$line_idx][api_strtolower($titles[$idx])] .= ','.$val; } else { $ret_ret_array[$line_idx][api_strtolower($titles[$idx])] = $val; } } } } return $ret_ret_array; }
/** * Converts character encoding of a xml-formatted text. If inside the text the encoding is declared, it is modified accordingly. * @param string $string The text being converted. * @param string $to_encoding The encoding that text is being converted to. * @param string $from_encoding (optional) The encoding that text is being converted from. If the value is empty, it is tried to be detected then. * @return string Returns the converted xml-text. */ function _api_convert_encoding_xml(&$string, $to_encoding, $from_encoding) { if (empty($from_encoding)) { $from_encoding = api_detect_encoding_xml($string); } $to_encoding = api_refine_encoding_id($to_encoding); if (!preg_match('/<\\?xml.*\\?>/m', $string, $matches)) { return api_convert_encoding('<?xml version="1.0" encoding="' . $to_encoding . '"?>' . "\n" . $string, $to_encoding, $from_encoding); } if (!preg_match(_PCRE_XML_ENCODING, $string)) { if (strpos($matches[0], 'standalone') !== false) { // The encoding option should precede the standalone option, othewise DOMDocument fails to load the document. $replace = str_replace('standalone', ' encoding="' . $to_encoding . '" standalone', $matches[0]); } else { $replace = str_replace('?>', ' encoding="' . $to_encoding . '"?>', $matches[0]); } return api_convert_encoding(str_replace($matches[0], $replace, $string), $to_encoding, $from_encoding); } global $_api_encoding; $_api_encoding = api_refine_encoding_id($to_encoding); return api_convert_encoding(preg_replace_callback(_PCRE_XML_ENCODING, '_api_convert_encoding_xml_callback', $string), $to_encoding, $from_encoding); }
/** * Converts a given string into the system ecoding (or platform character set). * When $from encoding is omited on UTF-8 platforms then language dependent encoding * is guessed/assumed. On non-UTF-8 platforms omited $from encoding is assumed as UTF-8. * When the parameter $check_utf8_validity is true the function checks string's * UTF-8 validity and decides whether to try to convert it or not. * This function is useful for problem detection or making workarounds. * @param string $string The string being converted. * @param string $from_encoding (optional) The encoding that $string is being converted from. It is guessed when it is omited. * @param bool $check_utf8_validity (optional) A flag for UTF-8 validity check as condition for making conversion. * @return string Returns the converted string. */ function api_to_system_encoding($string, $from_encoding = null, $check_utf8_validity = false) { $system_encoding = api_get_system_encoding(); return api_convert_encoding($string, $system_encoding, $from_encoding); }