Merge branch '1.10.x' of https://github.com/chamilo/chamilo-lms into 1.10.x
commit
69b5943743
@ -0,0 +1,248 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class CourseDescriptionController |
||||
* This file contains class used like controller, |
||||
* it should be included inside a dispatcher file (e.g: index.php) |
||||
* @author Christian Fasanando <christian1827@gmail.com> |
||||
* @package chamilo.course_description |
||||
*/ |
||||
class CourseDescriptionController |
||||
{ |
||||
private $toolname; |
||||
private $view; |
||||
|
||||
/** |
||||
* Constructor |
||||
*/ |
||||
public function __construct() |
||||
{ |
||||
$this->toolname = 'course_description'; |
||||
$this->view = new View($this->toolname); |
||||
} |
||||
|
||||
/** |
||||
* It's used for listing course description, |
||||
* render to listing view |
||||
* @param boolean true for listing history (optional) |
||||
* @param array message for showing by action['edit','add','destroy'] (optional) |
||||
*/ |
||||
public function listing($history = false, $messages = array()) |
||||
{ |
||||
$course_description = new CourseDescription(); |
||||
$session_id = api_get_session_id(); |
||||
$course_description->set_session_id($session_id); |
||||
$data = array(); |
||||
$course_description_data = $course_description->get_description_data(); |
||||
$data['descriptions'] = $course_description_data['descriptions']; |
||||
$data['default_description_titles'] = $course_description->get_default_description_title(); |
||||
$data['default_description_title_editable'] = $course_description->get_default_description_title_editable(); |
||||
$data['default_description_icon'] = $course_description->get_default_description_icon(); |
||||
$data['messages'] = $messages; |
||||
$browser = api_get_navigator(); |
||||
|
||||
if (!is_array($data['descriptions'])) { |
||||
$data['descriptions'] = array($data['descriptions']); |
||||
} |
||||
foreach ($data['descriptions'] as $description) { |
||||
if (!empty($description['content']) |
||||
&& strpos($description['content'], '<iframe') !== false |
||||
&& $browser['name'] == 'Chrome' |
||||
) { |
||||
header("X-XSS-Protection: 0"); |
||||
} |
||||
} |
||||
|
||||
// render to the view |
||||
$this->view->set_data($data); |
||||
$this->view->set_layout('layout'); |
||||
$this->view->set_template('listing'); |
||||
$this->view->render(); |
||||
} |
||||
|
||||
/** |
||||
* It's used for editing a course description, |
||||
* render to listing or edit view |
||||
* @param int description type |
||||
*/ |
||||
public function edit($id, $description_type) |
||||
{ |
||||
$course_description = new CourseDescription(); |
||||
$session_id = api_get_session_id(); |
||||
$course_description->set_session_id($session_id); |
||||
$data = array(); |
||||
$data['id'] = $id; |
||||
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { |
||||
if (!empty($_POST['title']) && !empty($_POST['contentDescription'])) { |
||||
$check = Security::check_token(); |
||||
if ($check) { |
||||
$title = $_POST['title']; |
||||
if (api_get_setting('wcag_anysurfer_public_pages') == 'true') { |
||||
$content = WCAG_Rendering::prepareXHTML(); |
||||
} else { |
||||
$content = $_POST['contentDescription']; |
||||
} |
||||
$description_type = $_POST['description_type']; |
||||
$id = $_POST['id']; |
||||
$progress = $_POST['progress']; |
||||
$course_description->set_description_type($description_type); |
||||
$course_description->set_title($title); |
||||
$course_description->set_content($content); |
||||
$course_description->set_progress($progress); |
||||
$thematic_advance = $course_description->get_data_by_id($id); |
||||
|
||||
if (!empty($thematic_advance)) { |
||||
$course_description->set_id($id); |
||||
$affected_rows = $course_description->update(); |
||||
} else { |
||||
$affected_rows = $course_description->insert(); |
||||
} |
||||
Security::clear_token(); |
||||
} |
||||
|
||||
if ($affected_rows) { |
||||
$message['edit'] = true; |
||||
} |
||||
$this->listing(false, $message); |
||||
} else { |
||||
$data['error'] = 1; |
||||
$data['default_description_titles'] = $course_description->get_default_description_title(); |
||||
$data['default_description_title_editable'] = $course_description->get_default_description_title_editable(); |
||||
$data['default_description_icon'] = $course_description->get_default_description_icon(); |
||||
$data['question'] = $course_description->get_default_question(); |
||||
$data['information'] = $course_description->get_default_information(); |
||||
$data['description_title'] = $_POST['title']; |
||||
$data['description_content'] = $_POST['contentDescription']; |
||||
$data['description_type'] = $_POST['description_type']; |
||||
$data['progress'] = $_POST['progress']; |
||||
$data['descriptions'] = $course_description->get_data_by_id($_POST['id']); |
||||
// render to the view |
||||
$this->view->set_data($data); |
||||
$this->view->set_layout('layout'); |
||||
$this->view->set_template('edit'); |
||||
$this->view->render(); |
||||
} |
||||
} else { |
||||
|
||||
$data['default_description_titles'] = $course_description->get_default_description_title(); |
||||
$data['default_description_title_editable'] = $course_description->get_default_description_title_editable(); |
||||
$data['default_description_icon'] = $course_description->get_default_description_icon(); |
||||
$data['question'] = $course_description->get_default_question(); |
||||
$data['information'] = $course_description->get_default_information(); |
||||
|
||||
$data['description_type'] = $description_type; |
||||
|
||||
if (!empty($id)) { |
||||
if (isset($_GET['id_session'])) { |
||||
$session_id = intval($_GET['id_session']); |
||||
} |
||||
$course_description_data = $course_description->get_data_by_id( |
||||
$id, |
||||
null, |
||||
$session_id |
||||
); |
||||
$data['description_type'] = $course_description_data['description_type']; |
||||
$data['description_title'] = $course_description_data['description_title']; |
||||
$data['description_content'] = $course_description_data['description_content']; |
||||
$data['progress'] = $course_description_data['progress']; |
||||
$data['descriptions'] = $course_description->get_data_by_description_type( |
||||
$description_type, |
||||
null, |
||||
$session_id |
||||
); |
||||
} |
||||
|
||||
// render to the view |
||||
$this->view->set_data($data); |
||||
$this->view->set_layout('layout'); |
||||
$this->view->set_template('edit'); |
||||
$this->view->render(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* It's used for adding a course description, |
||||
* render to listing or add view |
||||
*/ |
||||
public function add() |
||||
{ |
||||
$course_description = new CourseDescription(); |
||||
$session_id = api_get_session_id(); |
||||
$course_description->set_session_id($session_id); |
||||
|
||||
$data = array(); |
||||
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") { |
||||
if (!empty($_POST['title']) && !empty($_POST['contentDescription'])) { |
||||
|
||||
$check = Security::check_token(); |
||||
if ($check) { |
||||
$title = $_POST['title']; |
||||
if (api_get_setting('wcag_anysurfer_public_pages') == 'true') { |
||||
$content = WCAG_Rendering::prepareXHTML(); |
||||
} else { |
||||
$content = $_POST['contentDescription']; |
||||
} |
||||
$description_type = $_POST['description_type']; |
||||
if ($description_type >= ADD_BLOCK) { |
||||
$course_description->set_description_type($description_type); |
||||
$course_description->set_title($title); |
||||
$course_description->set_content($content); |
||||
$affected_rows = $course_description->insert(api_get_course_int_id()); |
||||
} |
||||
Security::clear_token(); |
||||
} |
||||
if ($affected_rows) { |
||||
$message['add'] = true; |
||||
} |
||||
$this->listing(false, $message); |
||||
} else { |
||||
$data['error'] = 1; |
||||
$data['default_description_titles'] = $course_description->get_default_description_title(); |
||||
$data['default_description_title_editable'] = $course_description->get_default_description_title_editable(); |
||||
$data['default_description_icon'] = $course_description->get_default_description_icon(); |
||||
$data['question'] = $course_description->get_default_question(); |
||||
$data['information'] = $course_description->get_default_information(); |
||||
$data['description_title'] = $_POST['title']; |
||||
$data['description_content'] = $_POST['contentDescription']; |
||||
$data['description_type'] = $_POST['description_type']; |
||||
$this->view->set_data($data); |
||||
$this->view->set_layout('layout'); |
||||
$this->view->set_template('add'); |
||||
$this->view->render(); |
||||
} |
||||
} else { |
||||
$data['default_description_titles'] = $course_description->get_default_description_title(); |
||||
$data['default_description_title_editable'] = $course_description->get_default_description_title_editable(); |
||||
$data['default_description_icon'] = $course_description->get_default_description_icon(); |
||||
$data['question'] = $course_description->get_default_question(); |
||||
$data['information'] = $course_description->get_default_information(); |
||||
$data['description_type'] = $course_description->get_max_description_type(); |
||||
// render to the view |
||||
$this->view->set_data($data); |
||||
$this->view->set_layout('layout'); |
||||
$this->view->set_template('add'); |
||||
$this->view->render(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* It's used for destroy a course description, |
||||
* render to listing view |
||||
* @param int description type |
||||
*/ |
||||
public function destroy($id) |
||||
{ |
||||
$course_description = new CourseDescription(); |
||||
$session_id = api_get_session_id(); |
||||
$course_description->set_session_id($session_id); |
||||
if (!empty($id)) { |
||||
$course_description->set_id($id); |
||||
$affected_rows = $course_description->delete(); |
||||
} |
||||
if ($affected_rows) { |
||||
$message['destroy'] = true; |
||||
} |
||||
$this->listing(false, $message); |
||||
} |
||||
} |
@ -0,0 +1,71 @@ |
||||
<?php |
||||
/** |
||||
* Move user fields "ruc" and "razon_social" to (social) groups (create groups) |
||||
* and assign the related users to those groups. |
||||
*/ |
||||
if (PHP_SAPI != 'cli') { |
||||
die('This script can only be launched from the command line'); |
||||
} |
||||
require __DIR__ . '/../../main/inc/global.inc.php'; |
||||
|
||||
// We assume all these fields represent the same value, so they are on a 1-1 |
||||
// relationship. |
||||
$referenceFields = array('razon_social', 'ruc'); |
||||
|
||||
$tUserField = Database::get_main_table(TABLE_MAIN_USER_FIELD); |
||||
$tUserFieldValue = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES); |
||||
$tUser = Database::get_main_table(TABLE_MAIN_USER); |
||||
$tGroup = Database::get_main_table(TABLE_MAIN_GROUP); |
||||
$tGroupUser = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP); |
||||
|
||||
// First get the IDs of the selected fields |
||||
$sql = "SELECT id, field_type, field_variable FROM $tUserField"; |
||||
$result = Database::query($sql); |
||||
$foundFields = array(); |
||||
$fieldsNames = array(); |
||||
while ($row = Database::fetch_assoc($result)) { |
||||
if ($row['field_type'] == 1 && in_array($row['field_variable'], $referenceFields)) { |
||||
$foundFields[$row['field_variable']] = array('id' => $row['id']); |
||||
$fieldsNames[$row['id']] = $row['field_variable']; |
||||
} |
||||
} |
||||
|
||||
// Second get all the possible values of this field (in user data) |
||||
$usersData = array(); |
||||
foreach ($foundFields as $key => $value) { |
||||
$sql = "SELECT user_id, field_value FROM $tUserFieldValue WHERE field_id = " . $value['id']; |
||||
$result = Database::query($sql); |
||||
while ($row = Database::fetch_assoc($result)) { |
||||
$foundFields[$key]['options'][$row['field_value']][] = $row['user_id']; |
||||
if (empty($usersData[$row['user_id']])) { |
||||
$usersData[$row['user_id']] = ''; |
||||
} |
||||
if ($referenceFields[0] == $key) { |
||||
$usersData[$row['user_id']] = $row['field_value'] . ' - ' . $usersData[$row['user_id']]; |
||||
} else { |
||||
$usersData[$row['user_id']] .= $row['field_value'] . ' - '; |
||||
} |
||||
} |
||||
} |
||||
// Clean the user string |
||||
$distinctGroups = array(); |
||||
foreach ($usersData as $userId => $value) { |
||||
$usersData[$userId] = substr($usersData[$userId], 0, -3); |
||||
$distinctGroups[$usersData[$userId]][] = $userId; |
||||
} |
||||
|
||||
// Third, we create groups based on the combined strings by user and insert |
||||
// users in them (as reader) |
||||
foreach ($distinctGroups as $name => $usersList) { |
||||
$now = api_get_utc_datetime(); |
||||
$sql = "INSERT INTO $tGroup (name, visibility, updated_on, created_on) VALUES ('$name', 1, '$now', '$now')"; |
||||
echo $sql . PHP_EOL; |
||||
$result = Database::query($sql); |
||||
$groupId = Database::insert_id(); |
||||
echo $groupId . PHP_EOL; |
||||
foreach ($usersList as $user) { |
||||
$sql = "INSERT INTO $tGroupUser (group_id, user_id, relation_type) VALUES ($groupId, $user, 2)"; |
||||
echo $sql . PHP_EOL; |
||||
$result = Database::query($sql); |
||||
} |
||||
} |
Loading…
Reference in new issue