parent
0bcd181f7d
commit
196bfc4702
@ -0,0 +1,61 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use Chamilo\CoreBundle\Component\Utils\ChamiloApi; |
||||
|
||||
$cidReset = true; |
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php'; |
||||
|
||||
api_block_anonymous_users(); |
||||
|
||||
$current_course_tool = TOOL_CALENDAR_EVENT; |
||||
$this_section = SECTION_MYAGENDA; |
||||
|
||||
$timezone = new DateTimeZone(api_get_timezone()); |
||||
$now = new DateTime('now', $timezone); |
||||
$currentYear = (int) $now->format('Y'); |
||||
|
||||
$searchYear = isset($_GET['year']) ? (int) $_GET['year'] : $currentYear; |
||||
|
||||
$userInfo = api_get_user_info(); |
||||
$userId = $userInfo['id']; |
||||
|
||||
$sessions = []; |
||||
|
||||
if (api_is_drh()) { |
||||
$count = SessionManager::get_sessions_followed_by_drh($userId, null, null, true); |
||||
} else { |
||||
$count = UserManager::get_sessions_by_category($userId, false, true, true, true); |
||||
} |
||||
|
||||
$sessionsList = UserManager::getSubscribedSessionsByYear($userInfo, $searchYear); |
||||
|
||||
if ($count > 50) { |
||||
$message = Display::return_message('TooMuchSessionsInPlanification', 'warning'); |
||||
|
||||
api_not_allowed(true, $message); |
||||
} |
||||
|
||||
$sessions = UserManager::getSessionsCalendarByYear($sessionsList, $searchYear); |
||||
|
||||
$colors = ChamiloApi::getColorPalette(false, true, count($sessions)); |
||||
|
||||
$agenda = new Agenda('personal'); |
||||
$actions = $agenda->displayActions('list', $userId); |
||||
|
||||
$toolName = get_lang('SessionsPlanCalendar'); |
||||
|
||||
$interbreadcrumb[] = [ |
||||
'url' => api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=personal', |
||||
'name' => get_lang('Agenda'), |
||||
]; |
||||
|
||||
$template = new Template($toolName); |
||||
$template->assign('toolbar', $actions); |
||||
$template->assign('student_id', $userId); |
||||
$template->assign('search_year', $searchYear); |
||||
$template->assign('colors', $colors); |
||||
$template->assign('sessions', $sessions); |
||||
$layout = $template->get_template('agenda/planification.tpl'); |
||||
$template->display($layout); |
@ -0,0 +1,68 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* This file is responsible for passing requested file attachments from messages |
||||
* Html files are parsed to fix a few problems with URLs, |
||||
* but this code will hopefully be replaced soon by an Apache URL |
||||
* rewrite mechanism. |
||||
* |
||||
* @package chamilo.messages |
||||
*/ |
||||
session_cache_limiter('public'); |
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php'; |
||||
|
||||
api_block_anonymous_users(); |
||||
|
||||
// IMPORTANT to avoid caching of documents |
||||
header('Expires: Wed, 01 Jan 1990 00:00:00 GMT'); |
||||
header('Cache-Control: public'); |
||||
header('Pragma: no-cache'); |
||||
|
||||
$messageId = isset($_GET['message_id']) ? $_GET['message_id'] : 0; |
||||
$attachmentId = isset($_GET['attachment_id']) ? $_GET['attachment_id'] : 0; |
||||
|
||||
$messageInfo = MessageManager::get_message_by_id($messageId); |
||||
$attachmentInfo = MessageManager::getAttachment($attachmentId); |
||||
|
||||
if (empty($messageInfo) || empty($attachmentInfo)) { |
||||
api_not_allowed(); |
||||
} |
||||
|
||||
// Attachment belongs to the message? |
||||
if ($messageInfo['id'] != $attachmentInfo['message_id']) { |
||||
api_not_allowed(); |
||||
} |
||||
|
||||
// Do not process group items |
||||
if (!empty($messageInfo['group_id'])) { |
||||
api_not_allowed(); |
||||
} |
||||
|
||||
// Only process wall messages |
||||
if (!in_array($messageInfo['msg_status'], [MESSAGE_STATUS_WALL, MESSAGE_STATUS_WALL_POST])) { |
||||
api_not_allowed(); |
||||
} |
||||
|
||||
$dir = UserManager::getUserPathById($messageInfo['user_sender_id'], 'system'); |
||||
if (empty($dir)) { |
||||
api_not_allowed(); |
||||
} |
||||
|
||||
$file = $dir.'message_attachments/'.$attachmentInfo['path']; |
||||
$title = api_replace_dangerous_char($attachmentInfo['filename']); |
||||
|
||||
if (Security::check_abs_path($file, $dir.'message_attachments/')) { |
||||
// launch event |
||||
Event::event_download($file); |
||||
$result = DocumentManager::file_send_for_download( |
||||
$file, |
||||
false, |
||||
$title |
||||
); |
||||
if ($result === false) { |
||||
api_not_allowed(true); |
||||
} |
||||
} |
||||
exit; |
@ -0,0 +1,148 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* @package chamilo.social |
||||
* |
||||
* @author Julio Montoya <gugli100@gmail.com> |
||||
*/ |
||||
$cidReset = true; |
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php'; |
||||
|
||||
api_block_anonymous_users(); |
||||
|
||||
$fields = api_get_configuration_value('allow_social_map_fields'); |
||||
|
||||
if (!$fields) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$fields = isset($fields['fields']) ? $fields['fields'] : ''; |
||||
|
||||
if (empty($fields)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$extraField = new ExtraField('user'); |
||||
$infoStage = $extraField->get_handler_field_info_by_field_variable($fields['0']); |
||||
$infoVille = $extraField->get_handler_field_info_by_field_variable($fields['1']); |
||||
|
||||
if (empty($infoStage) || empty($infoVille)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$gMapsPlugin = GoogleMapsPlugin::create(); |
||||
$localization = $gMapsPlugin->get('enable_api') === 'true'; |
||||
|
||||
if ($localization) { |
||||
$apiKey = $gMapsPlugin->get('api_key'); |
||||
if (empty($apiKey)) { |
||||
api_not_allowed(true); |
||||
} |
||||
} else { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$tableUser = Database::get_main_table(TABLE_MAIN_USER); |
||||
$sql = "SELECT u.id, firstname, lastname, ev.value ville, ev2.value stage |
||||
FROM $tableUser u |
||||
INNER JOIN extra_field_values ev |
||||
ON ev.item_id = u.id |
||||
INNER JOIN extra_field_values ev2 |
||||
ON ev2.item_id = u.id |
||||
WHERE |
||||
ev.field_id = ".$infoStage['id']." AND |
||||
ev2.field_id = ".$infoVille['id']." AND |
||||
u.status = ".STUDENT." AND |
||||
u.active = 1 AND |
||||
(ev.value <> '' OR ev2.value <> '') AND |
||||
(ev.value LIKE '%::%' OR ev2.value LIKE '%::%') |
||||
"; |
||||
|
||||
$cacheDriver = new \Doctrine\Common\Cache\ApcuCache(); |
||||
$keyDate = 'map_cache_date'; |
||||
$keyData = 'map_cache_data'; |
||||
|
||||
$now = time(); |
||||
|
||||
// Refresh cache every day |
||||
//$tomorrow = strtotime('+1 day', $now); |
||||
$tomorrow = strtotime('+5 minute', $now); |
||||
|
||||
$loadFromDatabase = true; |
||||
if ($cacheDriver->contains($keyData) && $cacheDriver->contains($keyDate)) { |
||||
$savedDate = $cacheDriver->fetch($keyDate); |
||||
$loadFromDatabase = false; |
||||
if ($savedDate < $now) { |
||||
$loadFromDatabase = true; |
||||
} |
||||
} |
||||
|
||||
$loadFromDatabase = true; |
||||
if ($loadFromDatabase) { |
||||
$result = Database::query($sql); |
||||
$data = Database::store_result($result, 'ASSOC'); |
||||
|
||||
$cacheDriver->save($keyData, $data); |
||||
$cacheDriver->save($keyDate, $tomorrow); |
||||
} else { |
||||
$data = $cacheDriver->fetch($keyData); |
||||
} |
||||
|
||||
foreach ($data as &$result) { |
||||
$result['complete_name'] = addslashes(api_get_person_name($result['firstname'], $result['lastname'])); |
||||
$parts = explode('::', $result['ville']); |
||||
if (isset($parts[1]) && !empty($parts[1])) { |
||||
$parts2 = explode(',', $parts[1]); |
||||
$result['ville_lat'] = $parts2[0]; |
||||
$result['ville_long'] = $parts2[1]; |
||||
|
||||
unset($result['ville']); |
||||
} |
||||
|
||||
$parts = explode('::', $result['stage']); |
||||
if (isset($parts[1]) && !empty($parts[1])) { |
||||
$parts2 = explode(',', $parts[1]); |
||||
$result['stage_lat'] = $parts2[0]; |
||||
$result['stage_long'] = $parts2[1]; |
||||
unset($result['stage']); |
||||
} |
||||
} |
||||
|
||||
$htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_JS_PATH).'map/markerclusterer.js"></script>'; |
||||
$htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_JS_PATH).'map/oms.min.js"></script>'; |
||||
|
||||
$tpl = new Template(null); |
||||
$tpl->assign('url', api_get_path(WEB_CODE_PATH).'social/profile.php'); |
||||
$tpl->assign( |
||||
'image_city', |
||||
Display::return_icon( |
||||
'red-dot.png', |
||||
'', |
||||
[], |
||||
ICON_SIZE_SMALL, |
||||
false, |
||||
true |
||||
) |
||||
); |
||||
$tpl->assign( |
||||
'image_stage', |
||||
Display::return_icon( |
||||
'blue-dot.png', |
||||
'', |
||||
[], |
||||
ICON_SIZE_SMALL, |
||||
false, |
||||
true |
||||
) |
||||
); |
||||
|
||||
$tpl->assign('places', json_encode($data)); |
||||
$tpl->assign('api_key', $apiKey); |
||||
|
||||
$tpl->assign('field_1', $infoStage['display_text']); |
||||
$tpl->assign('field_2', $infoVille['display_text']); |
||||
|
||||
$layout = $tpl->get_template('social/map.tpl'); |
||||
$tpl->display($layout); |
@ -0,0 +1,255 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php'; |
||||
|
||||
$this_section = SECTION_COURSES; |
||||
|
||||
if (!api_is_allowed_to_edit()) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
if (!api_is_allowed_to_edit()) { |
||||
if (!api_is_session_general_coach() || |
||||
(!empty($_GET['survey_id']) && |
||||
!api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id'])) |
||||
) { |
||||
api_not_allowed(true); |
||||
} |
||||
} |
||||
|
||||
$htmlHeadXtra[] = api_get_css_asset('jt.timepicker/jquery.timepicker.css'); |
||||
$htmlHeadXtra[] = api_get_asset('jt.timepicker/jquery.timepicker.js'); |
||||
$htmlHeadXtra[] = api_get_asset('datepair.js/dist/datepair.js'); |
||||
$htmlHeadXtra[] = api_get_asset('datepair.js/dist/jquery.datepair.js'); |
||||
|
||||
$interbreadcrumb[] = [ |
||||
'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(), |
||||
'name' => get_lang('SurveyList'), |
||||
]; |
||||
|
||||
$surveyId = isset($_GET['survey_id']) ? (int) $_GET['survey_id'] : null; |
||||
$surveyData = SurveyManager::get_survey($surveyId); |
||||
|
||||
if (empty($surveyData)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$courseInfo = api_get_course_info(); |
||||
|
||||
$tool_name = get_lang('Edit'); |
||||
|
||||
$form = new FormValidator( |
||||
'survey', |
||||
'post', |
||||
api_get_self().'?action=edit&'.api_get_cidreq().'&survey_id='.$surveyId |
||||
); |
||||
|
||||
$form->addElement('header', $tool_name); |
||||
$form->addHidden('anonymous', 0); |
||||
$form->addHidden('survey_language', $courseInfo['language']); |
||||
$form->addHidden('survey_subtitle', ''); |
||||
$form->addHidden('survey_thanks', ''); |
||||
$form->addHidden('visible_results', '0'); |
||||
$form->addHidden('survey_type', 3); |
||||
|
||||
$text = $form->addText( |
||||
'survey_title', |
||||
get_lang('Title') |
||||
); |
||||
|
||||
$allowSurveyAvailabilityDatetime = api_get_configuration_value('allow_survey_availability_datetime'); |
||||
|
||||
if ($allowSurveyAvailabilityDatetime) { |
||||
$startDateElement = $form->addDateTimePicker('start_date', get_lang('StartDate')); |
||||
$endDateElement = $form->addDateTimePicker('end_date', get_lang('EndDate')); |
||||
$form->addRule('start_date', get_lang('InvalidDate'), 'datetime'); |
||||
$form->addRule('end_date', get_lang('InvalidDate'), 'datetime'); |
||||
} else { |
||||
$startDateElement = $form->addElement('date_picker', 'start_date', get_lang('StartDate')); |
||||
$endDateElement = $form->addElement('date_picker', 'end_date', get_lang('EndDate')); |
||||
$form->addRule('start_date', get_lang('InvalidDate'), 'date'); |
||||
$form->addRule('end_date', get_lang('InvalidDate'), 'date'); |
||||
} |
||||
|
||||
$form->addRule( |
||||
['start_date', 'end_date'], |
||||
get_lang('StartDateShouldBeBeforeEndDate'), |
||||
'date_compare', |
||||
'lte' |
||||
); |
||||
|
||||
$form->addHtmlEditor('survey_introduction', get_lang('Description'), false); |
||||
$form->setRequired($text); |
||||
|
||||
$questions = SurveyManager::get_questions($surveyData['iid']); |
||||
$currentQuestionsCount = count($questions); |
||||
$counter = 1; |
||||
foreach ($questions as $question) { |
||||
$name = 'time_'.$counter; |
||||
$parts = explode('@@', $question['question']); |
||||
$surveyData[$name] = api_get_local_time($parts[0]).'@@'.api_get_local_time($parts[1]); |
||||
|
||||
$form->addDateTimeRangePicker($name, get_lang('Date')); |
||||
$form->addHidden($name.'_question_id', $question['question_id']); |
||||
$counter++; |
||||
} |
||||
$currentQuestionsCount++; |
||||
|
||||
$hideList = ''; |
||||
$maxEvents = $currentQuestionsCount + 10; |
||||
for ($i = $currentQuestionsCount; $i <= $maxEvents; $i++) { |
||||
$name = 'time_'.$i; |
||||
$form->addDateTimeRangePicker($name, get_lang('Date')); |
||||
$hideList .= "$('#".$name."_date_time_wrapper').hide();"; |
||||
} |
||||
|
||||
$form->addHtml('<script> |
||||
$(function() { |
||||
'.$hideList.' |
||||
var number = "'.--$currentQuestionsCount.'"; |
||||
$("#add_button").on("click", function() { |
||||
number++; |
||||
$("#time_" + number + "_date_time_wrapper").show(); |
||||
$("#time_" + number + "_time_range_start").val(""); |
||||
$("#time_" + number + "_time_range_end").val(""); |
||||
$("#time_" + number + "_alt").val(""); |
||||
}); |
||||
|
||||
$("#remove_button").on("click", function() { |
||||
if (number > 1) { |
||||
console.log("#time_" + number + "_time_range_start"); |
||||
$("#time_" + number + "_date_time_wrapper").hide(); |
||||
$("#time_" + number).val("delete"); |
||||
|
||||
$("#time_" + number + "_alt").val("delete"); |
||||
$("#time_" + number + "_time_range_start").val("delete"); |
||||
number--; |
||||
} |
||||
}); |
||||
}); |
||||
</script>'); |
||||
|
||||
$form->addLabel( |
||||
'', |
||||
Display::url(get_lang('Add'), 'javascript:void(0)', ['id' => 'add_button', 'class' => 'btn btn-default']) |
||||
.' '. |
||||
Display::url( |
||||
get_lang('Remove'), |
||||
'javascript:void(0)', |
||||
['id' => 'remove_button', 'class' => 'btn btn-danger'] |
||||
) |
||||
); |
||||
|
||||
$form->addButtonUpdate(get_lang('Edit'), 'submit_survey'); |
||||
|
||||
$form->setDefaults($surveyData); |
||||
|
||||
// The validation or display |
||||
if ($form->validate()) { |
||||
// Exporting the values |
||||
$values = $form->getSubmitValues(); |
||||
|
||||
$values['survey_id'] = $surveyId; |
||||
$values['survey_code'] = SurveyManager::generateSurveyCode($values['survey_title']); |
||||
// Storing the survey |
||||
SurveyManager::store_survey($values); |
||||
|
||||
$dates = []; |
||||
$deleteItems = []; |
||||
|
||||
for ($i = 1; $i <= $maxEvents; $i++) { |
||||
$name = 'time_'.$i; |
||||
|
||||
if (isset($values[$name]) && !empty($values[$name])) { |
||||
$id = ''; |
||||
if (isset($values[$name.'_question_id'])) { |
||||
$id = $values[$name.'_question_id']; |
||||
} |
||||
|
||||
$date = $values[$name]; |
||||
|
||||
if ($date === 'delete' && !empty($id)) { |
||||
$deleteItems[] = $id; |
||||
} |
||||
|
||||
if (empty($date)) { |
||||
continue; |
||||
} |
||||
|
||||
$start = $name.'_time_range_start'; |
||||
$end = $name.'_time_range_end'; |
||||
|
||||
$start = $values[$start]; |
||||
$end = $values[$end]; |
||||
|
||||
$part = explode('@@', $values[$name]); |
||||
$firstDate = substr($part[0], 0, 10); |
||||
|
||||
$start = api_get_utc_datetime($firstDate.' '.$start); |
||||
$end = api_get_utc_datetime($firstDate.' '.$end); |
||||
|
||||
if (!empty($start) && !empty($start)) { |
||||
$row = [ |
||||
'id' => $id, |
||||
'start' => $start, |
||||
'end' => $end, |
||||
]; |
||||
$dates[] = $row; |
||||
} |
||||
} |
||||
} |
||||
|
||||
$questionTable = Database::get_course_table(TABLE_SURVEY_QUESTION); |
||||
$counter = 1; |
||||
if (!empty($surveyData['iid'])) { |
||||
$questions = SurveyManager::get_questions($surveyData['iid']); |
||||
if (!empty($questions)) { |
||||
$questions = array_column($questions, 'question'); |
||||
} |
||||
|
||||
foreach ($dates as $date) { |
||||
$formattedDate = $date['start'].'@@'.$date['end']; |
||||
|
||||
if (!empty($date['id'])) { |
||||
$questionId = $date['id']; |
||||
$sql = "UPDATE $questionTable SET survey_question = '$formattedDate' |
||||
WHERE iid = $questionId"; |
||||
Database::query($sql); |
||||
} else { |
||||
$params = [ |
||||
'c_id' => api_get_course_int_id(), |
||||
'survey_id' => $surveyData['iid'], |
||||
'survey_question' => $formattedDate, |
||||
'survey_question_comment' => '', |
||||
'type' => 'doodle', |
||||
'display' => 'horizontal', |
||||
'sort' => $counter, |
||||
'shared_question_id' => '0', |
||||
'max_value' => 0, |
||||
]; |
||||
$questionId = Database::insert($questionTable, $params); |
||||
if ($questionId) { |
||||
$sql = "UPDATE $questionTable SET question_id = $questionId |
||||
WHERE iid = $questionId"; |
||||
Database::query($sql); |
||||
} |
||||
$counter++; |
||||
} |
||||
} |
||||
|
||||
foreach ($deleteItems as $deleteId) { |
||||
SurveyManager::delete_survey_question($surveyData['iid'], $deleteId); |
||||
} |
||||
} |
||||
|
||||
// Redirecting to the survey page (whilst showing the return message) |
||||
header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq()); |
||||
exit; |
||||
} else { |
||||
// Displaying the header |
||||
Display::display_header($tool_name); |
||||
$form->display(); |
||||
} |
||||
|
||||
Display::display_footer(); |
@ -0,0 +1,307 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* Configures the WSUser SOAP service. |
||||
* |
||||
* @package chamilo.webservices |
||||
*/ |
||||
require_once __DIR__.'/webservice_user.php'; |
||||
require_once __DIR__.'/soap.php'; |
||||
|
||||
/** |
||||
* Configures the WSUser SOAP service. |
||||
* |
||||
* @package chamilo.webservices |
||||
*/ |
||||
$s = WSSoapServer::singleton(); |
||||
|
||||
$s->wsdl->addComplexType( |
||||
'user_id', |
||||
'complexType', |
||||
'struct', |
||||
'all', |
||||
'', |
||||
[ |
||||
'user_id_field_name' => [ |
||||
'name' => 'user_id_field_name', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'user_id_value' => [ |
||||
'name' => 'user_id_value', |
||||
'type' => 'xsd:string', |
||||
], |
||||
] |
||||
); |
||||
|
||||
$s->wsdl->addComplexType( |
||||
'user_result', |
||||
'complexType', |
||||
'struct', |
||||
'all', |
||||
'', |
||||
[ |
||||
'user_id_value' => [ |
||||
'name' => 'user_id_value', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'result' => ['name' => 'result', 'type' => 'tns:result'], |
||||
] |
||||
); |
||||
|
||||
$s->wsdl->addComplexType( |
||||
'user_result_array', |
||||
'complexType', |
||||
'array', |
||||
'', |
||||
'SOAP-ENC:Array', |
||||
[], |
||||
[ |
||||
[ |
||||
'ref' => 'SOAP-ENC:arrayType', |
||||
'wsdl:arrayType' => 'tns:user_result[]', |
||||
], |
||||
], |
||||
'tns:user_result' |
||||
); |
||||
|
||||
$s->register( |
||||
'WSUser.DisableUser', |
||||
[ |
||||
'secret_key' => 'xsd:string', |
||||
'user_id_field_name' => 'xsd:string', |
||||
'user_id_value' => 'xsd:string', |
||||
] |
||||
); |
||||
|
||||
$s->register( |
||||
'WSUser.DisableUsers', |
||||
['secret_key' => 'xsd:string', 'users' => 'tns:user_id[]'], |
||||
['return' => 'tns:user_result_array'] |
||||
); |
||||
|
||||
$s->register( |
||||
'WSUser.EnableUser', |
||||
[ |
||||
'secret_key' => 'xsd:string', |
||||
'user_id_field_name' => 'xsd:string', |
||||
'user_id_value' => 'xsd:string', |
||||
] |
||||
); |
||||
|
||||
$s->register( |
||||
'WSUser.EnableUsers', |
||||
['secret_key' => 'xsd:string', 'users' => 'tns:user_id[]'], |
||||
['return' => 'tns:user_result_array'] |
||||
); |
||||
|
||||
$s->register( |
||||
'WSUser.DeleteUser', |
||||
[ |
||||
'secret_key' => 'xsd:string', |
||||
'user_id_field_name' => 'xsd:string', |
||||
'user_id_value' => 'xsd:string', |
||||
] |
||||
); |
||||
|
||||
$s->register( |
||||
'WSUser.DeleteUsers', |
||||
['secret_key' => 'xsd:string', 'users' => 'tns:user_id[]'], |
||||
['return' => 'tns:user_result_array'] |
||||
); |
||||
|
||||
$s->register( |
||||
'WSUser.CreateUser', |
||||
[ |
||||
'secret_key' => 'xsd:string', |
||||
'firstname' => 'xsd:string', |
||||
'lastname' => 'xsd:string', |
||||
'status' => 'xsd:int', |
||||
'loginname' => 'xsd:string', |
||||
'password' => 'xsd:string', |
||||
'encrypt_method' => 'xsd:string', |
||||
'user_id_field_name' => 'xsd:string', |
||||
'user_id_value' => 'xsd:string', |
||||
'visibility' => 'xsd:int', |
||||
'email' => 'xsd:string', |
||||
'language' => 'xsd:string', |
||||
'phone' => 'xsd:string', |
||||
'expiration_date' => 'xsd:string', |
||||
'extras' => 'tns:extra_field', |
||||
], |
||||
['return' => 'xsd:int'] |
||||
); |
||||
|
||||
$s->wsdl->addComplexType( |
||||
'user_create', |
||||
'complexType', |
||||
'struct', |
||||
'all', |
||||
'', |
||||
[ |
||||
'firstname' => ['name' => 'firstname', 'type' => 'xsd:string'], |
||||
'lastname' => ['name' => 'lastname', 'type' => 'xsd:string'], |
||||
'status' => ['name' => 'status', 'type' => 'xsd:int'], |
||||
'loginname' => ['name' => 'loginname', 'type' => 'xsd:string'], |
||||
'password' => ['name' => 'password', 'type' => 'xsd:string'], |
||||
'encrypt_method' => [ |
||||
'name' => 'encrypt_method', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'user_id_field_name' => [ |
||||
'name' => 'user_id_field_name', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'user_id_value' => [ |
||||
'name' => 'user_id_value', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'visibility' => ['name' => 'visibility', 'type' => 'xsd:int'], |
||||
'email' => ['name' => 'email', 'type' => 'xsd:string'], |
||||
'language' => ['name' => 'language', 'type' => 'xsd:string'], |
||||
'phone' => ['name' => 'phone', 'type' => 'xsd:string'], |
||||
'expiration_date' => [ |
||||
'name' => 'expiration_date', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'extras' => ['name' => 'extras', 'type' => 'tns:extra_field'], |
||||
] |
||||
); |
||||
|
||||
$s->wsdl->addComplexType( |
||||
'user_create_result', |
||||
'complexType', |
||||
'struct', |
||||
'all', |
||||
'', |
||||
[ |
||||
'user_id_value' => [ |
||||
'name' => 'user_id_value', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'user_id_generated' => [ |
||||
'name' => 'user_id_generated', |
||||
'type' => 'xsd:int', |
||||
], |
||||
'result' => ['name' => 'result', 'type' => 'tns:result'], |
||||
] |
||||
); |
||||
|
||||
$s->wsdl->addComplexType( |
||||
'user_create_result_array', |
||||
'complexType', |
||||
'array', |
||||
'', |
||||
'SOAP-ENC:Array', |
||||
[], |
||||
[ |
||||
[ |
||||
'ref' => 'SOAP-ENC:arrayType', |
||||
'wsdl:arrayType' => 'tns:user_create_result[]', |
||||
], |
||||
], |
||||
'tns:user_create_result' |
||||
); |
||||
|
||||
$s->register( |
||||
'WSUser.CreateUsers', |
||||
[ |
||||
'secret_key' => 'xsd:string', |
||||
'users' => 'tns:user_create[]', |
||||
], |
||||
['return' => 'tns:user_create_result_array'] |
||||
); |
||||
|
||||
$s->register( |
||||
'WSUser.EditUser', |
||||
[ |
||||
'secret_key' => 'xsd:string', |
||||
'user_id_field_name' => 'xsd:string', |
||||
'user_id_value' => 'xsd:string', |
||||
'firstname' => 'xsd:string', |
||||
'lastname' => 'xsd:string', |
||||
'status' => 'xsd:int', |
||||
'loginname' => 'xsd:string', |
||||
'password' => 'xsd:string', |
||||
'encrypt_method' => 'xsd:string', |
||||
'email' => 'xsd:string', |
||||
'language' => 'xsd:string', |
||||
'phone' => 'xsd:string', |
||||
'expiration_date' => 'xsd:string', |
||||
'extras' => 'tns:extra_field', |
||||
] |
||||
); |
||||
|
||||
$s->wsdl->addComplexType( |
||||
'user_edit', |
||||
'complexType', |
||||
'struct', |
||||
'all', |
||||
'', |
||||
[ |
||||
'user_id_field_name' => [ |
||||
'name' => 'user_id_field_name', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'user_id_value' => [ |
||||
'name' => 'user_id_value', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'firstname' => ['name' => 'firstname', 'type' => 'xsd:string'], |
||||
'lastname' => ['name' => 'lastname', 'type' => 'xsd:string'], |
||||
'status' => ['name' => 'status', 'type' => 'xsd:int'], |
||||
'loginname' => ['name' => 'loginname', 'type' => 'xsd:string'], |
||||
'password' => ['name' => 'password', 'type' => 'xsd:string'], |
||||
'encrypt_method' => [ |
||||
'name' => 'encrypt_method', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'email' => ['name' => 'email', 'type' => 'xsd:string'], |
||||
'language' => ['name' => 'language', 'type' => 'xsd:string'], |
||||
'phone' => ['name' => 'phone', 'type' => 'xsd:string'], |
||||
'expiration_date' => [ |
||||
'name' => 'expiration_date', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'extras' => ['name' => 'extras', 'type' => 'tns:extra_field'], |
||||
] |
||||
); |
||||
|
||||
$s->wsdl->addComplexType( |
||||
'user_edit_result', |
||||
'complexType', |
||||
'struct', |
||||
'all', |
||||
'', |
||||
[ |
||||
'user_id_value' => [ |
||||
'name' => 'user_id_value', |
||||
'type' => 'xsd:string', |
||||
], |
||||
'result' => ['name' => 'result', 'type' => 'tns:result'], |
||||
] |
||||
); |
||||
|
||||
$s->wsdl->addComplexType( |
||||
'user_edit_result_array', |
||||
'complexType', |
||||
'array', |
||||
'', |
||||
'SOAP-ENC:Array', |
||||
[], |
||||
[ |
||||
[ |
||||
'ref' => 'SOAP-ENC:arrayType', |
||||
'wsdl:arrayType' => 'tns:user_edit_result[]', |
||||
], |
||||
], |
||||
'tns:user_edit_result' |
||||
); |
||||
|
||||
$s->register( |
||||
'WSUser.EditUsers', |
||||
[ |
||||
'secret_key' => 'xsd:string', |
||||
'users' => 'tns:user_edit[]', |
||||
], |
||||
['return' => 'tns:user_edit_result_array'] |
||||
); |
@ -0,0 +1,649 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* @package chamilo.webservices |
||||
*/ |
||||
require_once __DIR__.'/../inc/global.inc.php'; |
||||
require_once __DIR__.'/webservice.php'; |
||||
|
||||
/** |
||||
* Web services available for the User module. This class extends the WS class. |
||||
*/ |
||||
class WSUser extends WS |
||||
{ |
||||
/** |
||||
* Disables a user. |
||||
* |
||||
* @param string API secret key |
||||
* @param string User id field name. Use "chamilo_user_id" as the field name if you want to use the internal user_id |
||||
* @param string User id value |
||||
*/ |
||||
public function DisableUser( |
||||
$secret_key, |
||||
$user_id_field_name, |
||||
$user_id_value |
||||
) { |
||||
$verifKey = $this->verifyKey($secret_key); |
||||
if ($verifKey instanceof WSError) { |
||||
// Let the implementation handle it |
||||
$this->handleError($verifKey); |
||||
} else { |
||||
$result = $this->changeUserActiveState( |
||||
$user_id_field_name, |
||||
$user_id_value, |
||||
0 |
||||
); |
||||
if ($result instanceof WSError) { |
||||
$this->handleError($result); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Disables multiple users. |
||||
* |
||||
* @param string API secret key |
||||
* @param array Array of users with elements of the form |
||||
* array('user_id_field_name' => 'name_of_field', 'user_id_value' => 'value') |
||||
* |
||||
* @return array Array with elements like |
||||
* array('user_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). |
||||
* Note that if the result array contains a code different |
||||
* than 0, an error occured |
||||
*/ |
||||
public function DisableUsers($secret_key, $users) |
||||
{ |
||||
$verifKey = $this->verifyKey($secret_key); |
||||
if ($verifKey instanceof WSError) { |
||||
// Let the implementation handle it |
||||
$this->handleError($verifKey); |
||||
} else { |
||||
return $this->changeUsersActiveState($users, 0); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Enables a user. |
||||
* |
||||
* @param string API secret key |
||||
* @param string User id field name. Use "chamilo_user_id" as the field name if you want to use the internal user_id |
||||
* @param string User id value |
||||
*/ |
||||
public function EnableUser($secret_key, $user_id_field_name, $user_id_value) |
||||
{ |
||||
$verifKey = $this->verifyKey($secret_key); |
||||
if ($verifKey instanceof WSError) { |
||||
$this->handleError($verifKey); |
||||
} else { |
||||
$result = $this->changeUserActiveState( |
||||
$user_id_field_name, |
||||
$user_id_value, |
||||
1 |
||||
); |
||||
if ($result instanceof WSError) { |
||||
$this->handleError($result); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Enables multiple users. |
||||
* |
||||
* @param string API secret key |
||||
* @param array Array of users with elements of the form |
||||
* array('user_id_field_name' => 'name_of_field', 'user_id_value' => 'value') |
||||
* |
||||
* @return array Array with elements like |
||||
* array('user_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). |
||||
* Note that if the result array contains a code different |
||||
* than 0, an error occured |
||||
*/ |
||||
public function EnableUsers($secret_key, $users) |
||||
{ |
||||
$verifKey = $this->verifyKey($secret_key); |
||||
if ($verifKey instanceof WSError) { |
||||
// Let the implementation handle it |
||||
$this->handleError($verifKey); |
||||
} else { |
||||
return $this->changeUsersActiveState($users, 1); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Deletes a user. |
||||
* |
||||
* @param string API secret key |
||||
* @param string User id field name. Use "chamilo_user_id" as the field name if you want to use the internal user_id |
||||
* @param string User id value |
||||
*/ |
||||
public function DeleteUser($secret_key, $user_id_field_name, $user_id_value) |
||||
{ |
||||
$verifKey = $this->verifyKey($secret_key); |
||||
if ($verifKey instanceof WSError) { |
||||
$this->handleError($verifKey); |
||||
} else { |
||||
$result = $this->deleteUserHelper( |
||||
$user_id_field_name, |
||||
$user_id_value |
||||
); |
||||
if ($result instanceof WSError) { |
||||
$this->handleError($result); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Deletes multiple users. |
||||
* |
||||
* @param string API secret key |
||||
* @param array Array of users with elements of the form |
||||
* array('user_id_field_name' => 'name_of_field', 'user_id_value' => 'value') |
||||
* |
||||
* @return array Array with elements like |
||||
* array('user_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). |
||||
* Note that if the result array contains a code different |
||||
* than 0, an error occured |
||||
*/ |
||||
public function DeleteUsers($secret_key, $users) |
||||
{ |
||||
$verifKey = $this->verifyKey($secret_key); |
||||
if ($verifKey instanceof WSError) { |
||||
$this->handleError($verifKey); |
||||
} else { |
||||
$results = []; |
||||
foreach ($users as $user) { |
||||
$result_tmp = []; |
||||
$result_op = $this->deleteUserHelper( |
||||
$user['user_id_field_name'], |
||||
$user['user_id_value'] |
||||
); |
||||
$result_tmp['user_id_value'] = $user['user_id_value']; |
||||
if ($result_op instanceof WSError) { |
||||
// Return the error in the results |
||||
$result_tmp['result'] = $result_op->toArray(); |
||||
} else { |
||||
$result_tmp['result'] = $this->getSuccessfulResult(); |
||||
} |
||||
$results[] = $result_tmp; |
||||
} |
||||
|
||||
return $results; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Creates a user. |
||||
* |
||||
* @param string API secret key |
||||
* @param string User first name |
||||
* @param string User last name |
||||
* @param int User status |
||||
* @param string Login name |
||||
* @param string Password (encrypted or not) |
||||
* @param string Encrypt method. Leave blank if you are passing the password in clear text, |
||||
* set to the encrypt method used to encrypt the password otherwise. Remember |
||||
* to include the salt in the extra fields if you are encrypting the password |
||||
* @param string User id field name. Use "chamilo_user_id" as the field name if you want to use the internal user_id |
||||
* @param string User id value. Leave blank if you are using the internal user_id |
||||
* @param int Visibility. Set by default to 1 |
||||
* @param string User email. Set by default to an empty string |
||||
* @param string Language. Set by default to english |
||||
* @param string Phone. Set by default to an empty string |
||||
* @param string Expiration date. Set to null by default |
||||
* @param array Extra fields. An array with elements of the form |
||||
* array('field_name' => 'name_of_the_field', 'field_value' => 'value_of_the_field'). Set to an empty array by default |
||||
* |
||||
* @return int New user id generated by the system |
||||
*/ |
||||
public function CreateUser( |
||||
$secret_key, |
||||
$firstname, |
||||
$lastname, |
||||
$status, |
||||
$login, |
||||
$password, |
||||
$encrypt_method, |
||||
$user_id_field_name, |
||||
$user_id_value, |
||||
$visibility = 1, |
||||
$email = '', |
||||
$language = 'english', |
||||
$phone = '', |
||||
$expiration_date = '0000-00-00 00:00:00', |
||||
$extras = [] |
||||
) { |
||||
// First, verify the secret key |
||||
$verifKey = $this->verifyKey($secret_key); |
||||
if ($verifKey instanceof WSError) { |
||||
$this->handleError($verifKey); |
||||
} else { |
||||
$result = $this->createUserHelper( |
||||
$firstname, |
||||
$lastname, |
||||
$status, |
||||
$login, |
||||
$password, |
||||
$encrypt_method, |
||||
$user_id_field_name, |
||||
$user_id_value, |
||||
$visibility, |
||||
$email, |
||||
$language, |
||||
$phone, |
||||
$expiration_date, |
||||
$extras |
||||
); |
||||
if ($result instanceof WSError) { |
||||
$this->handleError($result); |
||||
} else { |
||||
return $result; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Creates multiple users. |
||||
* |
||||
* @param string API secret key |
||||
* @param array Users array. Each member of this array must follow the structure imposed by the CreateUser method |
||||
* |
||||
* @return array Array with elements of the form |
||||
* array('user_id_value' => 'original value sent', 'user_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful')) |
||||
*/ |
||||
public function CreateUsers($secret_key, $users) |
||||
{ |
||||
$verifKey = $this->verifyKey($secret_key); |
||||
if ($verifKey instanceof WSError) { |
||||
$this->handleError($verifKey); |
||||
} else { |
||||
$results = []; |
||||
foreach ($users as $user) { |
||||
$result_tmp = []; |
||||
// re-initialize variables just in case |
||||
$firstname = $lastname = $status = $login = $password = $encrypt_method = $user_id_field_name = $user_id_value = $visibility = $email = $language = $phone = $expiration_date = $extras = null; |
||||
extract($user); |
||||
$result = $this->createUserHelper( |
||||
$firstname, |
||||
$lastname, |
||||
$status, |
||||
$login, |
||||
$password, |
||||
$encrypt_method, |
||||
$user_id_field_name, |
||||
$user_id_value, |
||||
$visibility, |
||||
$email, |
||||
$language, |
||||
$phone, |
||||
$expiration_date, |
||||
$extras |
||||
); |
||||
if ($result instanceof WSError) { |
||||
$result_tmp['result'] = $result->toArray(); |
||||
$result_tmp['user_id_value'] = $user_id_value; |
||||
$result_tmp['user_id_generated'] = 0; |
||||
} else { |
||||
$result_tmp['result'] = $this->getSuccessfulResult(); |
||||
$result_tmp['user_id_value'] = $user_id_value; |
||||
$result_tmp['user_id_generated'] = $result; |
||||
} |
||||
$results[] = $result_tmp; |
||||
} |
||||
|
||||
return $results; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Edits user info. |
||||
* |
||||
* @param string API secret key |
||||
* @param string User id field name. Use "chamilo_user_id" in order to use internal system id |
||||
* @param string User id value |
||||
* @param string First name |
||||
* @param string Last name |
||||
* @param int User status |
||||
* @param string Login name |
||||
* @param string Password. Leave blank if you don't want to update it |
||||
* @param string Encrypt method |
||||
* @param string User email |
||||
* @param string Language. Set by default to english |
||||
* @param string Phone. Set by default to an empty string |
||||
* @param string Expiration date. Set to null by default |
||||
* @param array Extra fields. An array with elements of the form |
||||
* ('field_name' => 'name_of_the_field', 'field_value' => 'value_of_the_field'). Leave empty if you don't want to update |
||||
*/ |
||||
public function EditUser( |
||||
$secret_key, |
||||
$user_id_field_name, |
||||
$user_id_value, |
||||
$firstname, |
||||
$lastname, |
||||
$status, |
||||
$loginname, |
||||
$password, |
||||
$encrypt_method, |
||||
$email, |
||||
$language, |
||||
$phone, |
||||
$expiration_date, |
||||
$extras |
||||
) { |
||||
// First, verify the secret key |
||||
$verifKey = $this->verifyKey($secret_key); |
||||
if ($verifKey instanceof WSError) { |
||||
$this->handleError($verifKey); |
||||
} else { |
||||
$extras_associative = []; |
||||
if (!empty($extras)) { |
||||
foreach ($extras as $extra) { |
||||
$extras_associative[$extra['field_name']] = $extra['field_value']; |
||||
} |
||||
} |
||||
|
||||
$result = $this->editUserHelper( |
||||
$user_id_field_name, |
||||
$user_id_value, |
||||
$firstname, |
||||
$lastname, |
||||
$status, |
||||
$loginname, |
||||
$password, |
||||
$encrypt_method, |
||||
$email, |
||||
$language, |
||||
$phone, |
||||
$expiration_date, |
||||
$extras_associative |
||||
); |
||||
if ($result instanceof WSError) { |
||||
$this->handleError($result); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Edits multiple users. |
||||
* |
||||
* @param string API secret key |
||||
* @param array Users array. Each member of this array must follow the structure imposed by the EditUser method |
||||
* |
||||
* @return array Array with elements like |
||||
* array('user_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). |
||||
* Note that if the result array contains a code different |
||||
* than 0, an error occured |
||||
*/ |
||||
public function EditUsers($secret_key, $users) |
||||
{ |
||||
$verifKey = $this->verifyKey($secret_key); |
||||
if ($verifKey instanceof WSError) { |
||||
$this->handleError($verifKey); |
||||
} else { |
||||
$results = []; |
||||
foreach ($users as $user) { |
||||
$result_tmp = []; |
||||
// re-initialize variables just in case |
||||
$user_id_field_name = $user_id_value = $firstname = $lastname = $status = $loginname = $password = $encrypt_method = $email = $language = $phone = $expiration_date = $extras = null; |
||||
extract($user); |
||||
$result_op = $this->editUserHelper( |
||||
$user_id_field_name, |
||||
$user_id_value, |
||||
$firstname, |
||||
$lastname, |
||||
$status, |
||||
$loginname, |
||||
$password, |
||||
$encrypt_method, |
||||
$email, |
||||
$language, |
||||
$phone, |
||||
$expiration_date, |
||||
$extras |
||||
); |
||||
$result_tmp['user_id_value'] = $user['user_id_value']; |
||||
if ($result_op instanceof WSError) { |
||||
// Return the error in the results |
||||
$result_tmp['result'] = $result_op->toArray(); |
||||
} else { |
||||
$result_tmp['result'] = $this->getSuccessfulResult(); |
||||
} |
||||
$results[] = $result_tmp; |
||||
} |
||||
|
||||
return $results; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Enables or disables a user. |
||||
* |
||||
* @param string User id field name |
||||
* @param string User id value |
||||
* @param int Set to 1 to enable and to 0 to disable |
||||
* |
||||
* @return int |
||||
*/ |
||||
protected function changeUserActiveState( |
||||
$user_id_field_name, |
||||
$user_id_value, |
||||
$state |
||||
) { |
||||
$user_id = $this->getUserId($user_id_field_name, $user_id_value); |
||||
if ($user_id instanceof WSError) { |
||||
return $user_id; |
||||
} else { |
||||
if ($state == 0) { |
||||
UserManager::disable($user_id); |
||||
} else { |
||||
if ($state == 1) { |
||||
UserManager::enable($user_id); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Enables or disables multiple users. |
||||
* |
||||
* @param array Users |
||||
* @param int Set to 1 to enable and to 0 to disable |
||||
* |
||||
* @return array Array of results |
||||
*/ |
||||
protected function changeUsersActiveState($users, $state) |
||||
{ |
||||
$results = []; |
||||
foreach ($users as $user) { |
||||
$result_tmp = []; |
||||
$result_op = $this->changeUserActiveState( |
||||
$user['user_id_field_name'], |
||||
$user['user_id_value'], |
||||
$state |
||||
); |
||||
$result_tmp['user_id_value'] = $user['user_id_value']; |
||||
if ($result_op instanceof WSError) { |
||||
// Return the error in the results |
||||
$result_tmp['result'] = $result_op->toArray(); |
||||
} else { |
||||
$result_tmp['result'] = $this->getSuccessfulResult(); |
||||
} |
||||
$results[] = $result_tmp; |
||||
} |
||||
|
||||
return $results; |
||||
} |
||||
|
||||
/** |
||||
* Deletes a user (helper method). |
||||
* |
||||
* @param string User id field name. Use "chamilo_user_id" as the field name if you want to use the internal user_id |
||||
* @param string User id value |
||||
* |
||||
* @return mixed True if user was successfully deleted, WSError otherwise |
||||
*/ |
||||
protected function deleteUserHelper($user_id_field_name, $user_id_value) |
||||
{ |
||||
$user_id = $this->getUserId($user_id_field_name, $user_id_value); |
||||
if ($user_id instanceof WSError) { |
||||
return $user_id; |
||||
} else { |
||||
if (!UserManager::delete_user($user_id)) { |
||||
return new WSError( |
||||
101, |
||||
"There was a problem while deleting this user" |
||||
); |
||||
} else { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Creates a user (helper method). |
||||
* |
||||
* @param string User first name |
||||
* @param string User last name |
||||
* @param int User status |
||||
* @param string Login name |
||||
* @param string Password (encrypted or not) |
||||
* @param string Encrypt method. Leave blank if you are passing the password in clear text, |
||||
* set to the encrypt method used to encrypt the password otherwise. Remember |
||||
* to include the salt in the extra fields if you are encrypting the password |
||||
* @param string User id field name. Use "chamilo_user_id" as the field name if you want to use the internal user_id |
||||
* @param string User id value. Leave blank if you are using the internal user_id |
||||
* @param int visibility |
||||
* @param string user email |
||||
* @param string language |
||||
* @param string phone |
||||
* @param string Expiration date |
||||
* @param array Extra fields. An array with elements of the form |
||||
* array('field_name' => 'name_of_the_field', 'field_value' => 'value_of_the_field'). |
||||
* |
||||
* @return mixed New user id generated by the system, WSError otherwise |
||||
*/ |
||||
protected function createUserHelper( |
||||
$firstname, |
||||
$lastname, |
||||
$status, |
||||
$login, |
||||
$password, |
||||
$encrypt_method, |
||||
$user_id_field_name, |
||||
$user_id_value, |
||||
$visibility, |
||||
$email, |
||||
$language, |
||||
$phone, |
||||
$expiration_date, |
||||
$extras = [] |
||||
) { |
||||
// Add the original user id field name and value to the extra fields if needed |
||||
$extras_associative = []; |
||||
if ($user_id_field_name != "chamilo_user_id") { |
||||
$extras_associative[$user_id_field_name] = $user_id_value; |
||||
} |
||||
if (!empty($extras)) { |
||||
foreach ($extras as $extra) { |
||||
$extras_associative[$extra['field_name']] = $extra['field_value']; |
||||
} |
||||
} |
||||
$result = UserManager::create_user( |
||||
$firstname, |
||||
$lastname, |
||||
$status, |
||||
$email, |
||||
$login, |
||||
$password, |
||||
'', |
||||
$language, |
||||
$phone, |
||||
'', |
||||
PLATFORM_AUTH_SOURCE, |
||||
$expiration_date, |
||||
$visibility, |
||||
0, |
||||
$extras_associative, |
||||
$encrypt_method |
||||
); |
||||
if (!$result) { |
||||
return new WSError(104, 'There was an error creating the user'); |
||||
} else { |
||||
return $result; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Edits user info (helper method). |
||||
* |
||||
* @param string User id field name. Use "chamilo_user_id" in order to use internal system id |
||||
* @param string User id value |
||||
* @param string First name |
||||
* @param string Last name |
||||
* @param int User status |
||||
* @param string Login name |
||||
* @param string Password. Leave blank if you don't want to update it |
||||
* @param string Encrypt method |
||||
* @param string User email |
||||
* @param string Language. Set by default to english |
||||
* @param string Phone. Set by default to an empty string |
||||
* @param string Expiration date. Set to null by default |
||||
* @param array Extra fields. An array with elements of the form |
||||
* ('field_name' => 'name_of_the_field', 'field_value' => 'value_of_the_field'). |
||||
* Leave empty if you don't want to update |
||||
* |
||||
* @return mixed True if user was successfully updated, WSError otherwise |
||||
*/ |
||||
protected function editUserHelper( |
||||
$user_id_field_name, |
||||
$user_id_value, |
||||
$firstname, |
||||
$lastname, |
||||
$status, |
||||
$loginname, |
||||
$password, |
||||
$encrypt_method, |
||||
$email, |
||||
$language, |
||||
$phone, |
||||
$expiration_date, |
||||
$extras |
||||
) { |
||||
$user_id = $this->getUserId($user_id_field_name, $user_id_value); |
||||
if ($user_id instanceof WSError) { |
||||
return $user_id; |
||||
} else { |
||||
if ($password == '') { |
||||
$password = null; |
||||
} |
||||
$user_info = api_get_user_info($user_id); |
||||
if (count($extras) == 0) { |
||||
$extras = null; |
||||
} |
||||
|
||||
$result = UserManager::update_user( |
||||
$user_id, |
||||
$firstname, |
||||
$lastname, |
||||
$loginname, |
||||
$password, |
||||
PLATFORM_AUTH_SOURCE, |
||||
$email, |
||||
$status, |
||||
'', |
||||
$phone, |
||||
$user_info['picture_uri'], |
||||
$expiration_date, |
||||
$user_info['active'], |
||||
null, |
||||
$user_info['hr_dept_id'], |
||||
$extras, |
||||
$encrypt_method |
||||
); |
||||
if (!$result) { |
||||
return new WSError(105, 'There was an error updating the user'); |
||||
} else { |
||||
return $result; |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue