parent
8a84dda172
commit
2985761f4d
@ -0,0 +1,221 @@ |
||||
<?php |
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2009 Dokeos SPRL |
||||
Copyright (c) 2009 Julio Montoya Armas <gugli100@gmail.com> |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium |
||||
Mail: info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
/** |
||||
============================================================================== |
||||
* This script allows platform admins to add users to urls. |
||||
* It displays a list of users and a list of courses; |
||||
* you can select multiple users and courses and then click on |
||||
* @package dokeos.admin |
||||
============================================================================== |
||||
*/ |
||||
|
||||
// name of the language file that needs to be included |
||||
$language_file = 'admin'; |
||||
$cidReset = true; |
||||
require ('../inc/global.inc.php'); |
||||
$this_section=SECTION_PLATFORM_ADMIN; |
||||
|
||||
require_once (api_get_path(LIBRARY_PATH).'urlmanager.lib.php'); |
||||
api_protect_admin_script(); |
||||
if (!$_configuration['multiple_access_urls']) |
||||
header('Location: index.php'); |
||||
|
||||
/* |
||||
----------------------------------------------------------- |
||||
Global constants and variables |
||||
----------------------------------------------------------- |
||||
*/ |
||||
|
||||
$users = $_GET['users']; |
||||
$form_sent = 0; |
||||
$first_letter_user = ''; |
||||
$first_letter_course = ''; |
||||
$courses = array (); |
||||
$url_list = array(); |
||||
$users = array(); |
||||
|
||||
$tbl_access_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
||||
$tbl_access_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
||||
$tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
||||
|
||||
/* |
||||
----------------------------------------------------------- |
||||
Header |
||||
----------------------------------------------------------- |
||||
*/ |
||||
$tool_name = get_lang('AddUsersToURL'); |
||||
$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); |
||||
$interbreadcrumb[] = array ('url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs')); |
||||
|
||||
|
||||
/* |
||||
============================================================================== |
||||
MAIN CODE |
||||
============================================================================== |
||||
*/ |
||||
|
||||
|
||||
|
||||
/* |
||||
----------------------------------------------------------- |
||||
React on POSTed request |
||||
----------------------------------------------------------- |
||||
*/ |
||||
|
||||
|
||||
Display :: display_header($tool_name); |
||||
//api_display_tool_title($tool_name); |
||||
|
||||
if ($_POST['formSent']) { |
||||
$form_sent = $_POST['formSent']; |
||||
$users = is_array($_POST['UserList']) ? $_POST['UserList'] : array() ; |
||||
$url_list = is_array($_POST['URLList']) ? $_POST['URLList'] : array() ; |
||||
$first_letter_user = $_POST['firstLetterUser']; |
||||
//$first_letter_course = $_POST['firstLetterCourse']; |
||||
|
||||
foreach($users as $key => $value) { |
||||
$users[$key] = intval($value); |
||||
} |
||||
|
||||
if ($form_sent == 1) |
||||
{ |
||||
if ( count($users) == 0 || count($url_list) == 0) { |
||||
Display :: display_error_message(get_lang('AtLeastOneUserAndOneURL')); |
||||
//header('Location: access_urls.php?action=show_message&message='.get_lang('AtLeastOneUserAndOneURL')); |
||||
} else { |
||||
UrlManager::add_users_to_urls($users,$url_list); |
||||
Display :: display_confirmation_message(get_lang('UsersBelongURL')); |
||||
//header('Location: access_urls.php?action=show_message&message='.get_lang('UsersBelongURL')); |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
/* |
||||
----------------------------------------------------------- |
||||
Display GUI |
||||
----------------------------------------------------------- |
||||
*/ |
||||
|
||||
|
||||
if(empty($first_letter_user)) |
||||
{ |
||||
$sql = "SELECT count(*) as nb_users FROM $tbl_user"; |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$num_row = Database::fetch_array($result); |
||||
if($num_row['nb_users']>1000) |
||||
{//if there are too much users to gracefully handle with the HTML select list, |
||||
// assign a default filter on users names |
||||
$first_letter_user = 'A'; |
||||
} |
||||
unset($result); |
||||
} |
||||
$sql = "SELECT user_id,lastname,firstname,username FROM $tbl_user WHERE lastname LIKE '".$first_letter_user."%' ORDER BY ". (count($users) > 0 ? "(user_id IN(".implode(',', $users).")) DESC," : "")." lastname"; |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$db_users = api_store_result($result); |
||||
unset($result); |
||||
|
||||
$sql = "SELECT id, url FROM $tbl_access_url WHERE active=1 ORDER BY url"; |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$db_urls = api_store_result($result); |
||||
unset($result); |
||||
?> |
||||
|
||||
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
|
||||
<input type="hidden" name="formSent" value="1"/> |
||||
<table border="0" cellpadding="5" cellspacing="0" width="100%"> |
||||
<tr> |
||||
<td width="40%" align="center"> |
||||
<b><?php echo get_lang('UserList'); ?></b>
|
||||
<br/><br/> |
||||
<?php echo get_lang('FirstLetterUser'); ?> :
|
||||
<select name="firstLetterUser" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();"> |
||||
<option value="">--</option> |
||||
<?php |
||||
echo Display :: get_alphabet_options($first_letter_user); |
||||
?> |
||||
</select> |
||||
</td> |
||||
<td width="20%"> </td> |
||||
<td width="40%" align="center"> |
||||
<b><?php echo get_lang('URLList'); ?> :</b>
|
||||
</td> |
||||
<?php |
||||
// |
||||
/* |
||||
<td width="20%"> </td> |
||||
<td width="40%" align="center"> |
||||
<b><?php echo get_lang('URLList'); ?> :</b>
|
||||
<br/><br/> |
||||
<?php echo get_lang('FirstLetterCourse'); ?> :
|
||||
<select name="firstLetterCourse" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();"> |
||||
<option value="">--</option> |
||||
<?php |
||||
echo Display :: get_alphabet_options($first_letter_course); |
||||
?> |
||||
</select> |
||||
</td> |
||||
*/ |
||||
?> |
||||
|
||||
</tr> |
||||
<tr> |
||||
<td width="40%" align="center"> |
||||
<select name="UserList[]" multiple="multiple" size="20" style="width:230px;"> |
||||
<?php |
||||
foreach ($db_users as $user) |
||||
{ |
||||
?> |
||||
<option value="<?php echo $user['user_id']; ?>" <?php if(in_array($user['user_id'],$users)) echo 'selected="selected"'; ?>><?php echo $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'; ?></option>
|
||||
<?php |
||||
} |
||||
?> |
||||
</select> |
||||
</td> |
||||
<td width="20%" valign="middle" align="center"> |
||||
<input type="submit" value="<?php echo get_lang('AddToThatURL'); ?> >>"/>
|
||||
</td> |
||||
<td width="40%" align="center"> |
||||
<select name="URLList[]" multiple="multiple" size="20" style="width:230px;"> |
||||
<?php |
||||
foreach ($db_urls as $url_obj) |
||||
{ |
||||
?> |
||||
<option value="<?php echo $url_obj['id']; ?>" <?php if(in_array($url_obj['id'],$url_list)) echo 'selected="selected"'; ?>><?php echo $url_obj['url']; ?></option>
|
||||
<?php |
||||
} |
||||
?> |
||||
</select> |
||||
</td> |
||||
</tr> |
||||
</table> |
||||
</form> |
||||
<?php |
||||
/* |
||||
============================================================================== |
||||
FOOTER |
||||
============================================================================== |
||||
*/ |
||||
Display :: display_footer(); |
||||
?> |
@ -0,0 +1,260 @@ |
||||
<?php // $Id: usermanager.lib.php 17705 2009-01-13 20:13:58Z herodoto $
|
||||
/* |
||||
============================================================================== |
||||
Dokeos - elearning and course management software |
||||
|
||||
Copyright (c) 2009 Dokeos SPRL |
||||
Copyright (c) 2009 Julio Montoya Armas <gugli100@gmail.com> |
||||
|
||||
For a full list of contributors, see "credits.txt". |
||||
The full license can be read in "license.txt". |
||||
|
||||
This program is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU General Public License |
||||
as published by the Free Software Foundation; either version 2 |
||||
of the License, or (at your option) any later version. |
||||
|
||||
See the GNU General Public License for more details. |
||||
|
||||
Contact: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com |
||||
============================================================================== |
||||
*/ |
||||
/** |
||||
============================================================================== |
||||
* This library provides functions for the URL management. |
||||
* Include/require it in your code to use its functionality. |
||||
* |
||||
* @package dokeos.library |
||||
============================================================================== |
||||
*/ |
||||
// define constants for user extra field types |
||||
|
||||
class UrlManager |
||||
{ |
||||
/** |
||||
* Creates a new access to Dokeos |
||||
* @author Julio Montoya <gugli100@gmail.com>, |
||||
* |
||||
* @param string The URL of the site |
||||
* @param string The description of the site |
||||
* @param int is active or not |
||||
* @param int the user_id of the owner |
||||
* @return boolean if success |
||||
*/ |
||||
function add($url, $description, $active) |
||||
{ |
||||
$tms = time(); |
||||
$access_url_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
||||
$sql = "INSERT INTO $access_url_table |
||||
SET url = '".Database::escape_string($url)."/', |
||||
description = '".Database::escape_string($description)."', |
||||
active = '".Database::escape_string($active)."', |
||||
created_by = '".Database::escape_string(api_get_user_id())."', |
||||
tms = FROM_UNIXTIME(".$tms.")"; |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
return $result; |
||||
} |
||||
/** |
||||
* Updates an URL access to Dokeos |
||||
* @author Julio Montoya <gugli100@gmail.com>, |
||||
* |
||||
* @param int The url id |
||||
* @param string The description of the site |
||||
* @param int is active or not |
||||
* @param int the user_id of the owner |
||||
* @return boolean if success |
||||
*/ |
||||
function udpate($url_id, $url, $description, $active) { |
||||
$access_url_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
||||
$tms = time(); |
||||
$sql = "UPDATE $access_url_table |
||||
SET url = '".Database::escape_string($url)."', |
||||
description = '".Database::escape_string($description)."', |
||||
active = '".Database::escape_string($active)."', |
||||
created_by = '".Database::escape_string(api_get_user_id())."', |
||||
tms = FROM_UNIXTIME(".$tms.") WHERE id = '$url_id'"; |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* */ |
||||
function url_exist($url) { |
||||
$access_url_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
||||
$sql = "SELECT id FROM $access_url_table WHERE url = '".Database::escape_string($url)."' "; |
||||
$res = api_sql_query($sql,__FILE__,__LINE__); |
||||
$num = Database::num_rows($res); |
||||
return $num; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* */ |
||||
function url_id_exist($url) { |
||||
$access_url_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
||||
$sql = "SELECT id FROM $access_url_table WHERE id = '".Database::escape_string($url)."' "; |
||||
$res = api_sql_query($sql,__FILE__,__LINE__); |
||||
$num = Database::num_rows($res); |
||||
return $num; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* This function get the quantity of URL |
||||
* @author Julio Montoya |
||||
* @return int count of urls |
||||
* */ |
||||
function url_count() { |
||||
$access_url_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
||||
$sql = "SELECT count(id) as count_result FROM $access_url_table"; |
||||
$res = api_sql_query($sql, __FILE__, __LINE__); |
||||
$url = Database::fetch_row($res); |
||||
$result = $url['0']; |
||||
return $result; |
||||
} |
||||
|
||||
/** |
||||
* Gets the id, url, description, and active status of ALL URLs |
||||
* @author Julio Montoya |
||||
* @return array |
||||
* */ |
||||
function get_url_data() { |
||||
$access_url_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
||||
$sql = "SELECT id , url , description, active FROM $access_url_table"; |
||||
$res = api_sql_query($sql, __FILE__, __LINE__); |
||||
$urls = array (); |
||||
while ($url = Database::fetch_row($res)) |
||||
{ |
||||
$urls[] = $url; |
||||
} |
||||
return $urls; |
||||
} |
||||
|
||||
/** |
||||
* Gets the id, url, description, and active status of ALL URLs |
||||
* @author Julio Montoya |
||||
* @return array |
||||
* */ |
||||
function get_url_data_from_id($url_id) { |
||||
$access_url_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
||||
$sql = "SELECT id, url, description, active FROM $access_url_table WHERE id = ".Database::escape_string($url_id); |
||||
$res = api_sql_query($sql, __FILE__, __LINE__); |
||||
$row = Database::fetch_array($res); |
||||
return $row; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Sets the status of an URL 1 or 0 |
||||
* @author Julio Montoya |
||||
* @param string lock || unlock |
||||
* @param int url id |
||||
* */ |
||||
function set_url_status($status,$url_id) |
||||
{ |
||||
$url_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
||||
if ($status=='lock') { |
||||
$status_db='0'; |
||||
} |
||||
if ($status=='unlock') { |
||||
$status_db='1'; |
||||
} |
||||
if(($status_db=='1' OR $status_db=='0') AND is_numeric($url_id)) { |
||||
$sql="UPDATE $url_table SET active='".Database::escape_string($status_db)."' WHERE id='".Database::escape_string($url_id)."'"; |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Deletes an url |
||||
* @author Julio Montoya |
||||
* @param int url id |
||||
* @return boolean true if success |
||||
* */ |
||||
function delete($id) |
||||
{ |
||||
$access_url_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
||||
$sql= "DELETE FROM $access_url_table WHERE id = ".Database::escape_string($id).""; |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
return $result; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Deletes an url |
||||
* @author Julio Montoya |
||||
* @param int user id |
||||
* @param int url id |
||||
* @return boolean true if success |
||||
* */ |
||||
function relation_url_user_exist($user_id, $url_id) |
||||
{ |
||||
$access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
||||
$sql= "SELECT user_id FROM $access_url_rel_user_table WHERE access_url_id = ".Database::escape_string($url_id)." AND user_id = ".Database::escape_string($user_id)." "; |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
$num = Database::num_rows($result); |
||||
return $num; |
||||
} |
||||
|
||||
/** |
||||
* Add a group of users into a group of URLs |
||||
* @author Julio Montoya |
||||
* @param array of user_ids |
||||
* @param array of url_ids |
||||
* */ |
||||
function add_users_to_urls($user_list,$url_list) |
||||
{ |
||||
$access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
||||
$result_array=array(); |
||||
|
||||
if (is_array($user_list) && is_array($url_list)){ |
||||
foreach ($url_list as $url_id) { |
||||
foreach ($user_list as $user_id) { |
||||
$count = UrlManager::relation_url_user_exist($user_id,$url_id); |
||||
if ($count==0) { |
||||
$sql = "INSERT INTO $access_url_rel_user_table |
||||
SET user_id = ".Database::escape_string($user_id).", access_url_id = ".Database::escape_string($url_id); |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
if($result) |
||||
$result_array[$url_id][$user_id]=1; |
||||
else |
||||
$result_array[$url_id][$user_id]=0; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return $result_array; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Add a user into a url |
||||
* @author Julio Montoya |
||||
* @param user_id |
||||
* @param url_id |
||||
* @return boolean true if success |
||||
* */ |
||||
function add_user_to_url($user_id,$url_id=1) |
||||
{ |
||||
$access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
||||
$count = UrlManager::relation_url_user_exist($user_id,$url_id); |
||||
if (empty($count)) { |
||||
$sql = "INSERT INTO $access_url_rel_user_table |
||||
SET user_id = ".Database::escape_string($user_id).", access_url_id = ".Database::escape_string($url_id); |
||||
$result = api_sql_query($sql, __FILE__, __LINE__); |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
function check_status($url) |
||||
{ |
||||
$access_url_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); |
||||
$sql = "SELECT id FROM $access_url_table WHERE url = '".$url."'"; |
||||
$result = api_sql_query($sql); |
||||
$access_url_id = Database::result($result, 0, 0); |
||||
return $access_url_id; |
||||
} |
||||
|
||||
} |
||||
?> |
Loading…
Reference in new issue