/** * {@inheritdoc} */ public function getConfiguration() { if ($this->allow()) { $userId = api_get_user_id(); if (!empty($userId)) { // Adding user personal files $dir = \UserManager::getUserPathById($userId, 'system'); $dirWeb = \UserManager::getUserPathById($userId, 'web'); $driver = array('driver' => 'PersonalDriver', 'alias' => get_lang('MyFiles'), 'path' => $dir . 'my_files', 'URL' => $dirWeb . 'my_files', 'accessControl' => array($this, 'access'), 'disabled' => array('duplicate', 'mkfile', 'copy', 'cut', 'paste', 'edit', 'extract', 'archive', 'help', 'resize')); return $driver; } } return array(); }
/** * Checks if the certificate user path directory is created */ public function check_certificate_path() { $this->certification_user_path = null; //Setting certification path $path_info = UserManager::getUserPathById($this->user_id, 'system'); $web_path_info = UserManager::getUserPathById($this->user_id, 'web'); if (!empty($path_info) && isset($path_info)) { $this->certification_user_path = $path_info . 'certificate/'; $this->certification_web_user_path = $web_path_info . 'certificate/'; if (!is_dir($path_info)) { mkdir($path_info, 0777, true); } if (!is_dir($this->certification_user_path)) { mkdir($this->certification_user_path, 0777); } } }
/** * Save the extra fields values * In order to save this function needs a item_id (user id, course id, etc) * This function is used with $extraField->addElements() * @param array $params array for the insertion into the *_field_values table * * @return mixed false on empty params, void otherwise * @assert (array()) === false */ public function saveFieldValues($params) { foreach ($params as $key => $value) { $found = strpos($key, '__persist__'); if ($found) { $tempKey = str_replace('__persist__', '', $key); if (!isset($params[$tempKey])) { $params[$tempKey] = array(); } } } if (empty($params['item_id'])) { return false; } $type = $this->getExtraField()->getExtraFieldType(); // Parse params. foreach ($params as $key => $value) { if (substr($key, 0, 6) == 'extra_' || substr($key, 0, 7) == '_extra_') { // An extra field. $field_variable = substr($key, 6); $extraFieldInfo = $this->getExtraField()->get_handler_field_info_by_field_variable($field_variable); if ($extraFieldInfo) { $commentVariable = 'extra_' . $field_variable . '_comment'; $comment = isset($params[$commentVariable]) ? $params[$commentVariable] : null; switch ($extraFieldInfo['field_type']) { case ExtraField::FIELD_TYPE_TAG: if ($type == EntityExtraField::USER_FIELD_TYPE) { UserManager::delete_user_tags($params['item_id'], $extraFieldInfo['id']); UserManager::process_tags($value, $params['item_id'], $extraFieldInfo['id']); } else { $em = Database::getManager(); $tagValues = is_array($value) ? $value : [$value]; $tags = []; foreach ($tagValues as $tagValue) { $tagsResult = $em->getRepository('ChamiloCoreBundle:Tag')->findBy(['tag' => $tagValue, 'fieldId' => $extraFieldInfo['id']]); if (empty($tagsResult)) { $tag = new \Chamilo\CoreBundle\Entity\Tag(); $tag->setCount(0); $tag->setFieldId($extraFieldInfo['id']); $tag->setTag($tagValue); $tags[] = $tag; } else { $tags = array_merge($tags, $tagsResult); } } foreach ($tags as $tag) { $fieldTags = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag')->findBy(['fieldId' => $extraFieldInfo['id'], 'itemId' => $params['item_id'], 'tagId' => $tag->getId()]); foreach ($fieldTags as $fieldTag) { $em->remove($fieldTag); $tag->setCount($tag->getCount() - 1); $em->persist($tag); $em->flush(); } $tag->setCount($tag->getCount() + 1); $em->persist($tag); $em->flush(); $fieldRelTag = new Chamilo\CoreBundle\Entity\ExtraFieldRelTag(); $fieldRelTag->setFieldId($extraFieldInfo['id']); $fieldRelTag->setItemId($params['item_id']); $fieldRelTag->setTagId($tag->getId()); $em->persist($fieldRelTag); $em->flush(); } } break; case ExtraField::FIELD_TYPE_FILE_IMAGE: $dirPermissions = api_get_permissions_for_new_directories(); switch ($this->type) { case 'course': $fileDir = api_get_path(SYS_UPLOAD_PATH) . "courses/"; $fileDirStored = "courses/"; break; case 'session': $fileDir = api_get_path(SYS_UPLOAD_PATH) . "sessions/"; $fileDirStored = "sessions/"; break; case 'user': $fileDir = UserManager::getUserPathById($params['item_id'], 'system'); $fileDirStored = UserManager::getUserPathById($params['item_id'], 'last'); break; } $fileName = ExtraField::FIELD_TYPE_FILE_IMAGE . "_{$params['item_id']}.png"; if (!file_exists($fileDir)) { mkdir($fileDir, $dirPermissions, true); } if ($value['error'] == 0) { $imageExtraField = new Image($value['tmp_name']); $imageExtraField->send_image($fileDir . $fileName, -1, 'png'); $newParams = array('item_id' => $params['item_id'], 'field_id' => $extraFieldInfo['id'], 'value' => $fileDirStored . $fileName, 'comment' => $comment); self::save($newParams); } break; case ExtraField::FIELD_TYPE_FILE: $dirPermissions = api_get_permissions_for_new_directories(); switch ($this->type) { case 'course': $fileDir = api_get_path(SYS_UPLOAD_PATH) . "courses/"; $fileDirStored = "courses/"; break; case 'session': $fileDir = api_get_path(SYS_UPLOAD_PATH) . "sessions/"; $fileDirStored = "sessions/"; break; case 'user': $fileDir = UserManager::getUserPathById($params['item_id'], 'system'); $fileDirStored = UserManager::getUserPathById($params['item_id'], 'last'); break; } $cleanedName = api_replace_dangerous_char($value['name']); $fileName = ExtraField::FIELD_TYPE_FILE . "_{$params['item_id']}_{$cleanedName}"; if (!file_exists($fileDir)) { mkdir($fileDir, $dirPermissions, true); } if ($value['error'] == 0) { moveUploadedFile($value, $fileDir . $fileName); $new_params = array('item_id' => $params['item_id'], 'field_id' => $extraFieldInfo['id'], 'value' => $fileDirStored . $fileName); if ($this->type !== 'session' && $this->type !== 'course') { $new_params['comment'] = $comment; } self::save($new_params); } break; default: $newParams = array('item_id' => $params['item_id'], 'field_id' => $extraFieldInfo['id'], 'value' => $value, 'comment' => $comment); self::save($newParams); } } } } }
/** * Delete message attachment files (logically updating the row with a suffix _DELETE_id) * @param int message id * @param int message user id (receiver user id or sender user id) * @param int group id (optional) * @return void */ public static function delete_message_attachment_file($message_id, $message_uid, $group_id = 0) { $message_id = intval($message_id); $message_uid = intval($message_uid); $table_message_attach = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT); $sql = "SELECT * FROM {$table_message_attach} WHERE message_id = '{$message_id}'"; $rs = Database::query($sql); while ($row = Database::fetch_array($rs)) { $path = $row['path']; $attach_id = $row['id']; $new_path = $path . '_DELETED_' . $attach_id; if (!empty($group_id)) { $userGroup = new UserGroup(); $path_user_info = $userGroup->get_group_picture_path_by_id($group_id, 'system', true); } else { $path_user_info['dir'] = UserManager::getUserPathById($message_uid, 'system'); } $path_message_attach = $path_user_info['dir'] . 'message_attachments/'; if (is_file($path_message_attach . $path)) { if (rename($path_message_attach . $path, $path_message_attach . $new_path)) { $sql_upd = "UPDATE {$table_message_attach} set path='{$new_path}' WHERE id ='{$attach_id}'"; Database::query($sql_upd); } } } }
DocumentManager::export_to_pdf($document_id, $course_code); } break; case 'copytomyfiles': // Copy a file to general my files user's if (api_get_setting('social.allow_social_tool') == 'true' && api_get_setting('document.users_copy_files') == 'true' && api_get_user_id() != 0 && !api_is_anonymous()) { // Get the document data from the ID $document_info = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true, $sessionId); if ($sessionId != 0 && !$document_info) { /* If there is a session defined and asking for the document from the session didn't work, try it from the course (out of a session context)*/ $document_info = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), 0); } $parent_id = $document_info['parent_id']; $my_path = UserManager::getUserPathById(api_get_user_id(), 'system'); $user_folder = $my_path . 'my_files/'; $my_path = null; if (!file_exists($user_folder)) { $perm = api_get_permissions_for_new_directories(); @mkdir($user_folder, $perm, true); } $file = $sys_course_path . $courseInfo['directory'] . '/document' . $document_info['path']; $copyfile = $user_folder . basename($document_info['path']); $cidReq = Security::remove_XSS($_GET['cidReq']); $id_session = Security::remove_XSS($_GET['id_session']); $gidReq = Security::remove_XSS($_GET['gidReq']); $id = Security::remove_XSS($_GET['id']); if (empty($parent_id)) { $parent_id = 0; }
$objSkill = new Skill(); $skills = $objSkill->get($skillId); $unbakedBadge = api_get_path(SYS_UPLOAD_PATH) . "badges/" . $skills['icon']; $unbakedBadge = file_get_contents($unbakedBadge); $badgeInfoError = false; $personalBadge = ""; $png = new PNGImageBaker($unbakedBadge); if ($png->checkChunks("tEXt", "openbadges")) { $bakedInfo = $png->addChunk("tEXt", "openbadges", $assertionUrl); $bakedBadge = UserManager::getUserPathById($userId, "system"); $bakedBadge = $bakedBadge . 'badges'; if (!file_exists($bakedBadge)) { mkdir($bakedBadge, api_get_permissions_for_new_directories(), true); } $skillRelUserId = $userSkills[0]->getId(); if (!file_exists($bakedBadge . "/badge_" . $skillRelUserId)) { file_put_contents($bakedBadge . "/badge_" . $skillRelUserId . ".png", $bakedInfo); } //Process to validate a baked badge $badgeContent = file_get_contents($bakedBadge . "/badge_" . $skillRelUserId . ".png"); $verifyBakedBadge = $png->extractBadgeInfo($badgeContent); if (!is_array($verifyBakedBadge)) { $badgeInfoError = true; } if (!$badgeInfoError) { $personalBadge = UserManager::getUserPathById($userId, "web"); $personalBadge = $personalBadge . "badges/badge_" . $skillRelUserId . ".png"; } } echo Container::getTemplating()->render('@template_style/skill/issued.html.twig', ['assertions' => $badgeAssertions, 'skill_info' => $skillInfo, 'user_info' => $userInfo, 'allow_export' => $allowExport, 'badge_error' => $badgeInfoError, 'personal_badge' => $personalBadge]); //$template->assign('header', get_lang('IssuedBadgeInformation'));
/** * Upload a submitted user production. * * @param $user_id User id * @return The filename of the new production or FALSE if the upload has failed */ function upload_user_production($user_id) { $production_repository = UserManager::getUserPathById($user_id, 'system'); if (!file_exists($production_repository)) { @mkdir($production_repository, api_get_permissions_for_new_directories(), true); } $filename = api_replace_dangerous_char($_FILES['production']['name']); $filename = disable_dangerous_file($filename); if (filter_extension($filename)) { if (@move_uploaded_file($_FILES['production']['tmp_name'], $production_repository . $filename)) { return $filename; } } return false; // this should be returned if anything went wrong with the upload }
/** * Send File attachment (jpg,png) * @author Anibal Copitan * @param int $userId id user * @param array $fileAttach * @param int $messageId id message (relation with main message) * @param string $fileComment description attachment file * @return bool */ public static function sendWallMessageAttachmentFile($userId, $fileAttach, $messageId, $fileComment = '') { $tbl_message_attach = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT); // create directory $social = '/social/'; $pathMessageAttach = UserManager::getUserPathById($userId, 'system') . 'message_attachments' . $social; $safeFileComment = Database::escape_string($fileComment); $safeFileName = Database::escape_string($fileAttach['name']); $extension = strtolower(substr(strrchr($safeFileName, '.'), 1)); $allowedTypes = api_get_supported_image_extensions(); if (!in_array($extension, $allowedTypes)) { $flag = false; } else { $newFileName = uniqid('') . '.' . $extension; if (!file_exists($pathMessageAttach)) { @mkdir($pathMessageAttach, api_get_permissions_for_new_directories(), true); } $newPath = $pathMessageAttach . $newFileName; if (is_uploaded_file($fileAttach['tmp_name'])) { @copy($fileAttach['tmp_name'], $newPath); } $small = self::resize_picture($newPath, IMAGE_WALL_SMALL_SIZE); $medium = self::resize_picture($newPath, IMAGE_WALL_MEDIUM_SIZE); $big = new Image($newPath); $ok = $small && $small->send_image($pathMessageAttach . IMAGE_WALL_SMALL . '_' . $newFileName) && $medium && $medium->send_image($pathMessageAttach . IMAGE_WALL_MEDIUM . '_' . $newFileName) && $big && $big->send_image($pathMessageAttach . IMAGE_WALL_BIG . '_' . $newFileName); // Insert $newFileName = $social . $newFileName; $params = ['filename' => $safeFileName, 'comment' => $safeFileComment, 'path' => $newFileName, 'message_id' => $messageId, 'size' => $fileAttach['size']]; Database::insert($tbl_message_attach, $params); $flag = true; } return $flag; }
DocumentManager::export_to_pdf($document_id, $course_code); } break; case 'copytomyfiles': // Copy a file to general my files user's if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('users_copy_files') == 'true' && api_get_user_id() != 0 && !api_is_anonymous()) { // Get the document data from the ID $document_info = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true, $sessionId); if ($sessionId != 0 && !$document_info) { /* If there is a session defined and asking for the document from the session didn't work, try it from the course (out of a session context)*/ $document_info = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), 0); } $parent_id = $document_info['parent_id']; $my_path = UserManager::getUserPathById(api_get_user_id()); $user_folder = $my_path . 'my_files/'; $my_path = null; if (!file_exists($user_folder)) { $perm = api_get_permissions_for_new_directories(); @mkdir($user_folder, $perm, true); } $file = $sys_course_path . $courseInfo['directory'] . '/document' . $document_info['path']; $copyfile = $user_folder . basename($document_info['path']); $cidReq = Security::remove_XSS($_GET['cidReq']); $id_session = Security::remove_XSS($_GET['id_session']); $gidReq = Security::remove_XSS($_GET['gidReq']); $id = Security::remove_XSS($_GET['id']); if (empty($parent_id)) { $parent_id = 0; }
<?php /* Integrate svg-edit libraries with Chamilo default documents * @author Juan Carlos Raña Trabado * @since 25/september/2010 */ //Chamilo load libraries require_once '../../../../../inc/global.inc.php'; //Add security from Chamilo api_protect_course_script(); api_block_anonymous_users(); $userId = api_get_user_id(); $user_disk_path = UserManager::getUserPathById($userId, 'system') . 'my_files/'; $user_web_path = UserManager::getUserPathById($userId, 'web') . 'my_files/'; //get all files and folders $scan_files = scandir($user_disk_path); //get all svg and png files $accepted_extensions = array('.svg', '.png'); if (is_array($scan_files) && count($scan_files) > 0) { foreach ($scan_files as &$file) { $slideshow_extension = strrchr($file, '.'); $slideshow_extension = strtolower($slideshow_extension); if (in_array($slideshow_extension, $accepted_extensions)) { $png_svg_files[] = $file; } } } $style = '<style>'; $style .= '@import "' . api_get_path(WEB_CSS_PATH) . 'base.css";'; $style .= '@import "' . api_get_path(WEB_CSS_PATH) . 'themes/' . api_get_visual_theme() . '/default.css";'; $style .= '</style>';
} // allow to the correct user for download this file $not_allowed_to_edit = false; $userGroup = new UserGroup(); if (!empty($row_users['group_id'])) { $users_group = $userGroup->get_all_users_by_group($row_users['group_id']); if (!in_array($current_uid, array_keys($users_group))) { $not_allowed_to_edit = true; } } else { if ($current_uid != $message_uid) { $not_allowed_to_edit = true; } } if ($not_allowed_to_edit) { api_not_allowed(); exit; } // set the path directory file if (!empty($row_users['group_id'])) { $path_user_info = $userGroup->get_group_picture_path_by_id($row_users['group_id'], 'system', true); } else { $path_user_info['dir'] = UserManager::getUserPathById($message_uid, 'system'); } $full_file_name = $path_user_info['dir'] . 'message_attachments/' . $file_url; if (Security::check_abs_path($full_file_name, $path_user_info['dir'] . 'message_attachments/')) { // launch event Event::event_download($file_url); DocumentManager::file_send_for_download($full_file_name, TRUE, $title); } exit;