/** * * @param int $user_id * @param string $api_key * @param string $api_service * @param string $api_end_point * @param int $validity_start_date * @param int $validity_end_date * @param string $description * @return AccessToken */ public static function create_token($user_id = null, $api_key = null, $api_service = null, $api_end_point = null, $validity_start_date = null, $validity_end_date = null, $description = '') { $time = time(); $user_id = $user_id ? $user_id : Chamilo::user()->user_id(); $api_key = $api_key ? $api_key : uniqid('', true); $api_service = $api_service ? $api_service : self::default_service(); $api_end_point = $api_end_point ? $api_end_point : ''; $validity_start_date = $validity_start_date ? $validity_start_date : $time; $validity_end_date = $validity_end_date ? $validity_end_date : self::end_of_time(); $created_date = $time; $user_id = (int) $user_id; $api_key = Database::escape_string($api_key); $api_service = Database::escape_string($api_service); $api_end_point = Database::escape_string($api_end_point); $validity_start_date = date('Y-m-d H:i:s', $validity_start_date); $validity_end_date = date('Y-m-d H:i:s', $validity_end_date); $created_date = date('Y-m-d H:i:s', $created_date); $values = array(); $values['user_id'] = $user_id; $values['api_key'] = $api_key; $values['api_service'] = $api_service; $values['api_end_point'] = $api_end_point; $values['validity_start_date'] = $validity_start_date; $values['validity_end_date'] = $validity_end_date; $values['created_date'] = $created_date; $table = Database::get_main_table(TABLE_MAIN_USER_API_KEY); $id = Database::insert($table, $values); return AccessToken::create($id, $user_id, $api_key); }
/** * Export tabular data to CSV-file * @param array $data * @param string $filename */ public static function export_table_csv_utf8($data, $filename = 'export') { if (empty($data)) { return false; } $path = Chamilo::temp_file(); $converter = new Utf8Encoder(null, true); $file = FileWriter::create($path, $converter); $file = CsvWriter::create($file); foreach ($data as $row) { $file->put($row); } $file->close(); DocumentManager::file_send_for_download($path, false, $filename . '.csv'); unlink($path); exit; }
public function run() { $this->synch(Chamilo::path('/main')); ksort($this->map); }
*/ if (count($files) == 0) { Response::not_found(); } $root_dir = ''; $items = array_merge($folders, $files); foreach ($items as $item) { $path = $item->get_absolute_path(); $path = realpath($path); $dir = dirname($path); if (empty($root_dir) || strlen($root_dir) > strlen($dir)) { $root_dir = $dir; } } /** * Zip files together. */ $temp_zip_path = Chamilo::temp_file('zip'); $zip_folder = new PclZip($temp_zip_path); foreach ($files as $file) { if (empty($root_dir)) { $root_dir = dirname($file); } $file = (string) $file; $zip_folder->add($file, PCLZIP_OPT_REMOVE_PATH, $root_dir); } /** * Send file for download */ event_download(Uri::here()); DocumentManager::file_send_for_download($temp_zip_path, false, get_lang('Documents') . '.zip');
/** * * @return ChamiloSession */ function session() { return Chamilo::session(); }
/** * Render a template using data. Adds a few common parameters to data. * * @see /main/template/default/course_description/ * @param string $template * @param array $data */ protected function render($template_name, $data) { $data = (object) $data; $data->www = \Chamilo::url(); $data->messages = isset($data->messages) ? $data->messages : array(); $javascript = $this->javascript(); if ($javascript) { $data->javascript = $javascript; } $tpl = new Template(); foreach ($data as $key => $value) { $tpl->assign($key, $value); } $template = $tpl->get_template($template_name); $content = $tpl->fetch($template); $tpl->assign('content', $content); $tpl->display_one_col_template(); }
public function is_dev() { return !Chamilo::is_production_server(); }
public function run() { if (!$this->accept()) { return false; } $course = Course::current(); $pathes = Request::get('path'); $pathes = is_array($pathes) ? $pathes : array($pathes); $ids = array(); foreach ($pathes as $path) { $doc = Document::get_by_path($course, $path); if ($doc) { $ids[] = $doc->get_id(); } } if (empty($ids)) { return false; } $user = new \Portfolio\User(); $user->email = Chamilo::user()->email(); $artefact = new Portfolio\Artefact(); $artefact->url = Portfolio::download_url($ids); $portfolio = $this->get_portfolio(); $result = $portfolio->send($user, $artefact); return $result; }
$charset_initial_value = $charset; // Initialization of the internationalization library. api_initialize_internationalization(); // Initialization of the default encoding that will be used by the multibyte string routines in the internationalization library. api_set_internationalization_default_encoding($charset); // Initialization of the database encoding to be used. Database::query("SET SESSION character_set_server='utf8';"); Database::query("SET SESSION collation_server='utf8_general_ci';"); if (api_is_utf8($charset)) { // See Bug #1802: For UTF-8 systems we prefer to use "SET NAMES 'utf8'" statement in order to avoid a bizarre problem with Chinese language. Database::query("SET NAMES 'utf8';"); } else { Database::query("SET CHARACTER SET '" . Database::to_db_encoding($charset) . "';"); } // Start session after the internationalization library has been initialized. Chamilo::session()->start($already_installed); // Remove quotes added by PHP - get_magic_quotes_gpc() is deprecated in PHP 5 see #2970 if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { array_walk_recursive_limited($_GET, 'stripslashes', true); array_walk_recursive_limited($_POST, 'stripslashes', true); array_walk_recursive_limited($_COOKIE, 'stripslashes', true); array_walk_recursive_limited($_REQUEST, 'stripslashes', true); } // access_url == 1 is the default chamilo location if ($_configuration['access_url'] != 1) { $url_info = api_get_access_url($_configuration['access_url']); if ($url_info['active'] == 1) { $settings_by_access =& api_get_settings(null, 'list', $_configuration['access_url'], 1); foreach ($settings_by_access as &$row) { if (empty($row['variable'])) { $row['variable'] = 0;
$pub = StudentPublication::get_by_id($course, $id); if (!$pub->is_accessible()) { break; } if ($pub->is_file()) { $items[] = $pub; } /** * We ignore folders */ } /** * Requested files may not be accessible. */ if (count($items) == 0) { Response::not_found(); } /** * Zip files together. */ $zip = Chamilo::temp_zip(); foreach ($items as $item) { $path = $item->get_absolute_path(); $title = $item->get_title(); $zip->add($path, $title); } /** * Send file for download */ event_download(Uri::here()); DocumentManager::file_send_for_download($zip->get_path(), false, get_lang('StudentPublications') . '.zip');
/** * returns all the javascript that is required for easily * setting the target people/groups * this goes into the $htmlHeadXtra[] array */ public static function to_javascript() { $www = api_get_path(WEB_PATH); $src = $www . 'main/announcements/resources/js/main.js'; $result = Javascript::tag($src); $root = Chamilo::url(); $code = "var www = '{$root}';\n"; $code .= Javascript::get_lang('FieldRequired', 'Send2All', 'AddAnAttachment', 'Everybody'); $result .= Javascript::tag_code($code); return $result; }
/** * Returns the file path based on the key. * * @param any Identifier for the variable * @return string Path of the file where this * variable is/should-be stored */ static function path($key = '') { return Chamilo::path('archive/temp/cache/' . self::key($key)); }
/** * returns all the javascript that is required for easily * setting the target people/groups * this goes into the $htmlHeadXtra[] array */ public static function to_javascript() { $www = api_get_path(WEB_PATH); /* * Do not allow this kind of behaviour. js minifieds should be manage by the template class or assetic or whatever see #4757 for more info if (api_get_setting('server_type') == 'test') { $src = $www . 'main/announcements/resources/js/main.js'; } else { $src = $www . 'main/announcements/resources/js/main.min.js'; }*/ $src = $www . 'main/announcements/resources/js/main.js'; $result = Javascript::tag($src); $root = Chamilo::url(); $code = "var www = '{$root}';\n"; $code .= Javascript::get_lang('FieldRequired', 'Send2All', 'AddAnAttachment', 'Everybody'); $result .= Javascript::tag_code($code); return $result; }