- Block usergroups pages using new function $usergroup->protectScript(); - Change breadcrumbs to not show the "Administration" in classes - Make number of users inside usergroup/classes clickable now we show the list of users. - Add LPCalendar link in "Reporting" - Add new ajax page usergroup.ajax.php - Add lp_item "calendar" extra fieldpull/2591/head
parent
4a8bace60f
commit
44208472ce
@ -0,0 +1,251 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* @package chamilo.admin |
||||
*/ |
||||
$cidReset = true; |
||||
require_once __DIR__.'/../inc/global.inc.php'; |
||||
|
||||
$this_section = SECTION_PLATFORM_ADMIN; |
||||
|
||||
$usergroup = new UserGroup(); |
||||
|
||||
$usergroup->protectScript(); |
||||
|
||||
// Add the JS needed to use the jqgrid |
||||
$htmlHeadXtra[] = api_get_jqgrid_js(); |
||||
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null; |
||||
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0; |
||||
$userId = isset($_GET['user_id']) ? (int) $_GET['user_id'] : 0; |
||||
$calendarId = isset($_GET['calendar_id']) ? (int) $_GET['calendar_id'] : 0; |
||||
|
||||
$userGroupInfo = $usergroup->get($id); |
||||
|
||||
if (empty($userGroupInfo)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
// setting breadcrumbs |
||||
$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')]; |
||||
$interbreadcrumb[] = ['url' => '#', 'name' => $userGroupInfo['name']]; |
||||
|
||||
switch ($action) { |
||||
case 'add_calendar': |
||||
$calendars = LpCalendarPlugin::getCalendars(0, 1000, ''); |
||||
if (empty($calendars)) { |
||||
echo Display::return_message(get_lang('Nodata')); |
||||
exit; |
||||
} |
||||
$userInfo = api_get_user_info($userId); |
||||
|
||||
$calendars = array_column($calendars, 'title', 'id'); |
||||
$calendars = array_map('strip_tags', $calendars); |
||||
|
||||
$form = new FormValidator( |
||||
'add_calendar', |
||||
'post', |
||||
api_get_self().'?id='.$id.'&user_id='.$userId.'&action=add_calendar' |
||||
); |
||||
$form->addHeader($userInfo['complete_name']); |
||||
$form->addSelect('calendar_id', get_lang('Calendar'), $calendars, ['disable_js' => true]); |
||||
$form->addButtonSave(get_lang('Save')); |
||||
$form->display(); |
||||
|
||||
if ($form->validate()) { |
||||
$calendarId = $form->getSubmitValue('calendar_id'); |
||||
if (!empty($calendarId)) { |
||||
LpCalendarPlugin::addUserToCalendar($calendarId, $userId); |
||||
Display::addFlash(Display::return_message(get_lang('Added'), 'confirmation')); |
||||
header('Location: '.api_get_self().'?id='.$id); |
||||
exit; |
||||
} |
||||
} |
||||
exit; |
||||
break; |
||||
case 'edit_calendar': |
||||
$calendars = LpCalendarPlugin::getCalendars(0, 1000, ''); |
||||
if (empty($calendars)) { |
||||
echo Display::return_message(get_lang('Nodata')); |
||||
exit; |
||||
} |
||||
|
||||
$calendars = array_column($calendars, 'title', 'id'); |
||||
$calendars = array_map('strip_tags', $calendars); |
||||
|
||||
$form = new FormValidator( |
||||
'add_calendar', |
||||
'post', |
||||
api_get_self().'?id='.$id.'&user_id='.$userId.'&action=edit_calendar&calendar_id='.$calendarId |
||||
); |
||||
$userInfo = api_get_user_info($userId); |
||||
$form->addHeader($userInfo['complete_name']); |
||||
$form->addSelect('calendar_id', get_lang('Calendar'), $calendars, ['disable_js' => true]); |
||||
$form->addButtonSave(get_lang('Update')); |
||||
$form->setDefaults(['calendar_id' => $calendarId]); |
||||
$form->display(); |
||||
|
||||
if ($form->validate()) { |
||||
$calendarId = $form->getSubmitValue('calendar_id'); |
||||
if (!empty($calendarId)) { |
||||
LpCalendarPlugin::updateUserToCalendar($calendarId, $userId); |
||||
Display::addFlash(Display::return_message(get_lang('Added'), 'confirmation')); |
||||
header('Location: '.api_get_self().'?id='.$id); |
||||
exit; |
||||
} |
||||
} |
||||
exit; |
||||
break; |
||||
case 'delete': |
||||
$res = $usergroup->delete_user_rel_group($_GET['user_id'], $_GET['id']); |
||||
|
||||
//LpCalendarPlugin::deleteAllCalendarFromUser(); |
||||
|
||||
Display::addFlash(Display::return_message(get_lang('Deleted'), 'confirmation')); |
||||
header('Location: '.api_get_self().'?id='.$id); |
||||
exit; |
||||
break; |
||||
} |
||||
|
||||
// The header. |
||||
Display::display_header(); |
||||
|
||||
// jqgrid will use this URL to do the selects |
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_users&id='.$id; |
||||
|
||||
// The order is important you need to check the the $column variable in the model.ajax.php file |
||||
$columns = [ |
||||
get_lang('Name'), |
||||
get_lang('Actions'), |
||||
]; |
||||
|
||||
// Column config |
||||
$column_model = [ |
||||
['name' => 'name', 'index' => 'name', 'width' => '35', 'align' => 'left', 'sortable' => 'false'], |
||||
[ |
||||
'name' => 'actions', |
||||
'index' => 'actions', |
||||
'width' => '20', |
||||
'align' => 'center', |
||||
'sortable' => 'false', |
||||
'formatter' => 'action_formatter', |
||||
], |
||||
]; |
||||
|
||||
|
||||
if (api_get_plugin_setting('lp_calendar', 'enabled') === 'true') { |
||||
$columns = [ |
||||
get_lang('Name'), |
||||
get_lang('Calendar'), |
||||
get_lang('Actions'), |
||||
]; |
||||
|
||||
// Column config |
||||
$column_model = [ |
||||
['name' => 'name', 'index' => 'name', 'width' => '35', 'align' => 'left', 'sortable' => 'false'], |
||||
[ |
||||
'name' => 'calendar', |
||||
'index' => 'calendar', |
||||
'width' => '35', |
||||
'align' => 'left', |
||||
'sortable' => 'false', |
||||
'formatter' => 'extra_formatter', |
||||
], |
||||
[ |
||||
'name' => 'actions', |
||||
'index' => 'actions', |
||||
'width' => '20', |
||||
'align' => 'center', |
||||
'sortable' => 'false', |
||||
'formatter' => 'action_formatter', |
||||
], |
||||
]; |
||||
} |
||||
|
||||
// Autowidth |
||||
$extraParams['autowidth'] = 'true'; |
||||
// height auto |
||||
$extraParams['height'] = 'auto'; |
||||
$extraParams['sortname'] = 'name'; |
||||
$extraParams['sortorder'] = 'desc'; |
||||
$extraParams['multiselect'] = true; |
||||
|
||||
$deleteIcon = Display::return_icon('delete.png', get_lang('Delete'), null, ICON_SIZE_SMALL); |
||||
$urlStats = api_get_path(WEB_CODE_PATH); |
||||
|
||||
//$addCalendar = '<a href="'.$urlStats.'mySpace/myStudents.php?student=\'+options.rowId+\'">'.Display::return_icon('agenda.png', get_lang('Agenda'), '', ICON_SIZE_SMALL).'</a>'; |
||||
|
||||
//return \'<a href="session_edit.php?page=resume_session.php&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'. |
||||
// With this function we can add actions to the jgrid |
||||
$action_links = ' |
||||
function action_formatter(cellvalue, options, rowObject) { |
||||
return \''. |
||||
' <a href="'.$urlStats.'mySpace/myStudents.php?student=\'+options.rowId+\'">'.Display::return_icon('stats.png', get_lang('Reporting'), '', ICON_SIZE_SMALL).'</a>'. |
||||
' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="?id='.$id.'&action=delete&user_id=\'+options.rowId+\'">'.$deleteIcon.'</a>\'; |
||||
} |
||||
|
||||
function extra_formatter(cellvalue, options, rowObject) { |
||||
var calendarName = rowObject[1]; |
||||
var calendarId = rowObject[3]; |
||||
|
||||
if (calendarName == "") { |
||||
return \'<a href="'. |
||||
api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?user_id=\'+options.rowId+\'&id='.$id.'&action=add_calendar&width=700" class="btn btn-primary ajax">'.get_lang('Add').'</a>\'; |
||||
} else { |
||||
return \' \'+calendarName+\' <a href="'. |
||||
api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?calendar_id=\'+calendarId+\'&user_id=\'+options.rowId+\'&id='.$id.'&action=edit_calendar&width=700" class="btn btn-primary ajax"> '.get_lang('Edit').'</a>\'; |
||||
} |
||||
|
||||
return calendarName; |
||||
|
||||
return \''. |
||||
' <a href="'.$urlStats.'mySpace/myStudents.php?student=\'+options.rowId+\'">'.Display::return_icon('stats.png', get_lang('Reporting'), '', ICON_SIZE_SMALL).'</a>'. |
||||
' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="?id='.$id.'&action=delete&user_id=\'+options.rowId+\'">'.$deleteIcon.'</a>\'; |
||||
} |
||||
|
||||
'; |
||||
|
||||
$deleteUrl = api_get_path(WEB_AJAX_PATH).'usergroup.ajax.php?a=delete_user_in_usergroup&group_id='.$id; |
||||
|
||||
?> |
||||
<script> |
||||
$(function() { |
||||
<?php |
||||
// grid definition see the $usergroup>display() function |
||||
echo Display::grid_js( |
||||
'usergroups', |
||||
$url, |
||||
$columns, |
||||
$column_model, |
||||
$extraParams, |
||||
[], |
||||
$action_links, |
||||
true |
||||
); |
||||
?> |
||||
$("#usergroups").jqGrid( |
||||
"navGrid", |
||||
"#usergroups_pager", |
||||
{ edit: false, add: false, del: true, search: false}, |
||||
{ height:280, reloadAfterSubmit:false }, // edit options |
||||
{ height:280, reloadAfterSubmit:false }, // add options |
||||
{ reloadAfterSubmit:false, url: "<?php echo $deleteUrl; ?>" }, // del options
|
||||
{ width:500 } // search options |
||||
); |
||||
}); |
||||
|
||||
</script> |
||||
<?php |
||||
|
||||
$usergroup->showGroupTypeSetting = true; |
||||
// Action handling: Adding a note |
||||
if ($action === 'delete' && is_numeric($_GET['id'])) { |
||||
$res = $usergroup->delete_user_rel_group($_GET['user_id'], $_GET['id']); |
||||
Display::addFlash(Display::return_message(get_lang('Deleted'), 'confirmation')); |
||||
header('Location: '.api_get_self().'?id='.$id); |
||||
exit; |
||||
} else { |
||||
$usergroup->displayToolBarUserGroupUsers(); |
||||
} |
||||
|
||||
Display::display_footer(); |
||||
@ -0,0 +1,24 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* Responses to AJAX calls. |
||||
*/ |
||||
require_once __DIR__.'/../global.inc.php'; |
||||
|
||||
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : ''; |
||||
$isAllowedToEdit = api_is_allowed_to_edit(); |
||||
|
||||
switch ($action) { |
||||
case 'delete_user_in_usergroup': |
||||
if ($isAllowedToEdit) { |
||||
$userGroup = new UserGroup(); |
||||
$userId = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0; |
||||
$groupId = isset($_REQUEST['group_id']) ? $_REQUEST['group_id'] : 0; |
||||
$userGroup->delete_user_rel_group($userId, $groupId); |
||||
} |
||||
break; |
||||
default: |
||||
echo ''; |
||||
break; |
||||
} |
||||
exit; |
||||
@ -0,0 +1,393 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
|
||||
use Doctrine\DBAL\Schema\Schema; |
||||
use Doctrine\DBAL\Types\Type; |
||||
use Doctrine\DBAL\DBALException; |
||||
use Symfony\Component\Filesystem\Filesystem; |
||||
|
||||
/** |
||||
* Class LpCalendarPlugin |
||||
*/ |
||||
class LpCalendarPlugin extends Plugin |
||||
{ |
||||
const EVENT_TYPE_TAKEN = 1; |
||||
const EVENT_TYPE_EXAM = 2; |
||||
|
||||
/** |
||||
* Class constructor |
||||
*/ |
||||
protected function __construct() |
||||
{ |
||||
$version = '0.1'; |
||||
$author = 'Julio Montoya'; |
||||
parent::__construct($version, $author, ['enabled' => 'boolean']); |
||||
} |
||||
|
||||
public static function getEventTypeList() |
||||
{ |
||||
return [ |
||||
//self::EVENT_TYPE_FREE => 'green', |
||||
self::EVENT_TYPE_TAKEN => 'red', |
||||
self::EVENT_TYPE_EXAM => 'yellow' |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* Get the class instance |
||||
* |
||||
* @return $this |
||||
*/ |
||||
public static function create() |
||||
{ |
||||
static $result = null; |
||||
|
||||
return $result ?: $result = new self(); |
||||
} |
||||
|
||||
/** |
||||
* Get the plugin directory name |
||||
*/ |
||||
public function get_name() |
||||
{ |
||||
return 'lp_calendar'; |
||||
} |
||||
|
||||
/** |
||||
* Install the plugin. Setup the database |
||||
*/ |
||||
public function install() |
||||
{ |
||||
$sql = " |
||||
CREATE TABLE IF NOT EXISTS learning_calendar( |
||||
id int not null AUTO_INCREMENT primary key, |
||||
title varchar(255) not null default '', |
||||
description longtext default null, |
||||
total_hours int not null default 0, |
||||
minutes_per_day int not null default 0, |
||||
disabled int default 0 |
||||
) |
||||
"; |
||||
Database::query($sql); |
||||
|
||||
$sql = " |
||||
CREATE TABLE IF NOT EXISTS learning_calendar_events( |
||||
id int not null AUTO_INCREMENT primary key, |
||||
name varchar(255) default '', |
||||
calendar_id int not null, |
||||
start_date date not null, |
||||
end_date date not null, |
||||
type int not null |
||||
) |
||||
"; |
||||
Database::query($sql); |
||||
|
||||
$sql = " |
||||
CREATE TABLE IF NOT EXISTS learning_calendar_user( |
||||
id int not null AUTO_INCREMENT primary key, |
||||
user_id int(11) not null, |
||||
calendar_id int not null |
||||
) |
||||
"; |
||||
Database::query($sql); |
||||
|
||||
$extraField = new ExtraField('lp_item'); |
||||
$params = [ |
||||
'variable' => 'calendar', |
||||
'visible_to_self' => 1, |
||||
'changeable' => 1, |
||||
'visible_to_others' => 1, |
||||
'field_type' => ExtraField::FIELD_TYPE_CHECKBOX |
||||
]; |
||||
|
||||
$extraField->save($params); |
||||
|
||||
$extraField = new ExtraField('course'); |
||||
$params = [ |
||||
'variable' => 'course_hours_duration', |
||||
'visible_to_self' => 1, |
||||
'changeable' => 1, |
||||
'visible_to_others' => 1, |
||||
'field_type' => ExtraField::FIELD_TYPE_TEXT |
||||
]; |
||||
|
||||
$extraField->save($params); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* uninstall plugin. Clear the database |
||||
*/ |
||||
public function uninstall() |
||||
{ |
||||
$tables = [ |
||||
'learning_calendar', |
||||
'learning_calendar_events', |
||||
'learning_calendar_user', |
||||
]; |
||||
|
||||
foreach ($tables as $table) { |
||||
$sql = "DROP TABLE IF EXISTS $table"; |
||||
Database::query($sql); |
||||
} |
||||
|
||||
$extraField = new ExtraField('lp_item'); |
||||
$fieldInfo = $extraField->get_handler_field_info_by_field_variable('calendar'); |
||||
|
||||
if ($fieldInfo) { |
||||
$extraField->delete($fieldInfo['id']); |
||||
} |
||||
|
||||
$extraField = new ExtraField('course'); |
||||
$fieldInfo = $extraField->get_handler_field_info_by_field_variable('course_hours_duration'); |
||||
if ($fieldInfo) { |
||||
$extraField->delete($fieldInfo['id']); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* @param int $from |
||||
* @param int $numberOfItems |
||||
* @param int $column |
||||
* @param string $direction |
||||
* |
||||
* @return array|\Doctrine\DBAL\Driver\Statement |
||||
*/ |
||||
public static function getCalendars( |
||||
$from, |
||||
$numberOfItems, |
||||
$column, |
||||
$direction = 'DESC' |
||||
) { |
||||
$column = (int) $column; |
||||
$from = (int) $from; |
||||
$numberOfItems = (int) $numberOfItems; |
||||
$direction = strtoupper($direction); |
||||
|
||||
if (!in_array($direction, ['ASC', 'DESC'])) { |
||||
$direction = 'DESC'; |
||||
} |
||||
|
||||
$sql = 'select * FROM learning_calendar'; |
||||
|
||||
$sql .= " LIMIT $from, $numberOfItems "; |
||||
|
||||
$result = Database::query($sql); |
||||
$list = []; |
||||
$link = api_get_path(WEB_PLUGIN_PATH).'lp_calendar/start.php'; |
||||
while ($row = Database::fetch_array($result)) { |
||||
$id = $row['id']; |
||||
$row['title'] = Display::url( |
||||
$row['title'], |
||||
api_get_path(WEB_PLUGIN_PATH).'lp_calendar/calendar.php?id='.$id |
||||
); |
||||
$actions = Display::url( |
||||
Display::return_icon('edit.png', get_lang('Edit')), |
||||
$link.'?action=edit&id='.$id |
||||
); |
||||
|
||||
$actions .= Display::url( |
||||
Display::return_icon('copy.png', get_lang('Copy')), |
||||
$link.'?action=copy&id='.$id |
||||
); |
||||
|
||||
$actions .= Display::url( |
||||
Display::return_icon('delete.png', get_lang('Delete')), |
||||
$link.'?action=delete&id='.$id |
||||
); |
||||
$row['actions'] = $actions; |
||||
$list[] = $row; |
||||
} |
||||
|
||||
return $list; |
||||
|
||||
} |
||||
|
||||
/** |
||||
* @return int |
||||
*/ |
||||
public static function getCalendarCount() |
||||
{ |
||||
$sql = 'select count(*) as count FROM learning_calendar'; |
||||
$result = Database::query($sql); |
||||
$result = Database::fetch_array($result); |
||||
|
||||
return (int) $result['count']; |
||||
} |
||||
|
||||
/** |
||||
* @param int $id |
||||
*/ |
||||
public function toggleVisibility($id) |
||||
{ |
||||
$extraField = new ExtraField('lp_item'); |
||||
$fieldInfo = $extraField->get_handler_field_info_by_field_variable('calendar'); |
||||
if ($fieldInfo) { |
||||
$itemInfo = $this->getItemVisibility($id); |
||||
if (empty($itemInfo)) { |
||||
$extraField = new ExtraFieldValue('lp_item'); |
||||
$value = 1; |
||||
$params = [ |
||||
'field_id' => $fieldInfo['id'], |
||||
'value' => $value, |
||||
'item_id' => $id, |
||||
]; |
||||
$extraField->save($params); |
||||
} else { |
||||
$newValue = (int) $itemInfo['value'] === 1 ? 0 : 1; |
||||
$extraField = new ExtraFieldValue('lp_item'); |
||||
$params = [ |
||||
'id' => $itemInfo['id'], |
||||
'value' => $newValue |
||||
]; |
||||
$extraField->update($params); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @param int $id |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function getItemVisibility($id) |
||||
{ |
||||
$extraField = new ExtraFieldValue('lp_item'); |
||||
$values = $extraField->get_values_by_handler_and_field_variable($id, 'calendar'); |
||||
|
||||
return $values; |
||||
} |
||||
|
||||
/** |
||||
* @param int $calendarId |
||||
* |
||||
* @return array|mixed |
||||
*/ |
||||
public static function getCalendar($calendarId) |
||||
{ |
||||
$calendarId = (int) $calendarId; |
||||
$sql = "SELECT * FROM learning_calendar WHERE id = $calendarId"; |
||||
$result = Database::query($sql); |
||||
$item = Database::fetch_array($result, 'ASSOC'); |
||||
|
||||
return $item; |
||||
} |
||||
|
||||
/** |
||||
* @param int $userId |
||||
* |
||||
* @return array|mixed |
||||
*/ |
||||
public static function getUserCalendar($userId) |
||||
{ |
||||
$userId = (int) $userId; |
||||
$sql = "SELECT * FROM learning_calendar_user WHERE user_id = $userId"; |
||||
$result = Database::query($sql); |
||||
$item = Database::fetch_array($result, 'ASSOC'); |
||||
|
||||
return $item; |
||||
} |
||||
|
||||
/** |
||||
* @param int $userId |
||||
* |
||||
* @return mixed|string |
||||
*/ |
||||
public static function getUserCalendarToString($userId) |
||||
{ |
||||
$calendar = self::getUserCalendar($userId); |
||||
if ($calendar) { |
||||
$calendarInfo = self::getCalendar($calendar['calendar_id']); |
||||
|
||||
return $calendarInfo['title']; |
||||
} |
||||
|
||||
return ''; |
||||
} |
||||
|
||||
/** |
||||
* @param int $calendarId |
||||
* @param int $userId |
||||
* |
||||
* @return bool |
||||
*/ |
||||
public static function addUserToCalendar($calendarId, $userId) |
||||
{ |
||||
$calendar = self::getUserCalendar($userId); |
||||
if (empty($calendar)) { |
||||
$params = [ |
||||
'calendar_id' => $calendarId, |
||||
'user_id' => $userId, |
||||
]; |
||||
|
||||
Database::insert('learning_calendar_user', $params); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* @param int $calendarId |
||||
* @param int $userId |
||||
* |
||||
* @return bool |
||||
*/ |
||||
public static function updateUserToCalendar($calendarId, $userId) |
||||
{ |
||||
$calendar = self::getUserCalendar($userId); |
||||
if (!empty($calendar)) { |
||||
$params = [ |
||||
'calendar_id' => $calendarId, |
||||
'user_id' => $userId, |
||||
]; |
||||
|
||||
Database::update('learning_calendar_user', $params, ['id = ?' => $calendar['id']]); |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* @param int $calendarId |
||||
* @param int $userId |
||||
* |
||||
* @return bool |
||||
*/ |
||||
public static function deleteAllCalendarFromUser($calendarId, $userId) |
||||
{ |
||||
$calendarId = (int) $calendarId; |
||||
$userId = (int) $userId; |
||||
$sql = "DELETE FROM learning_calendar_user |
||||
WHERE user_id = $userId AND calendar_id = $calendarId"; |
||||
Database::query($sql); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
|
||||
/*public static function getUserCalendar($calendarId, $userId) |
||||
{ |
||||
$params = [ |
||||
'calendar_id' => $calendarId, |
||||
'user_id' => $calendarId, |
||||
]; |
||||
|
||||
Database::insert('learning_calendar_user', $params); |
||||
|
||||
return true; |
||||
}*/ |
||||
|
||||
/** |
||||
* @param FormValidator $form |
||||
*/ |
||||
public function getForm(FormValidator &$form) |
||||
{ |
||||
$form->addText('title', get_lang('Title')); |
||||
$form->addText('total_hours', get_lang('TotalHours')); |
||||
$form->addText('minutes_per_day', get_lang('MinutesPerDay')); |
||||
$form->addHtmlEditor('description', get_lang('Description'), false); |
||||
} |
||||
} |
||||
@ -0,0 +1,2 @@ |
||||
## Learning path calendar |
||||
|
||||
@ -0,0 +1,69 @@ |
||||
<?php |
||||
|
||||
require_once __DIR__.'/../../main/inc/global.inc.php'; |
||||
|
||||
$allow = api_is_allowed_to_edit(); |
||||
|
||||
if (!$allow) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : ''; |
||||
$calendarId = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0; |
||||
|
||||
$eventTypeList = LpCalendarPlugin::getEventTypeList(); |
||||
|
||||
switch ($action) { |
||||
case 'toggle_day': |
||||
$startDate = isset($_REQUEST['date']) ? $_REQUEST['date'] : ''; |
||||
//$endDate = isset($_REQUEST['date']) ? $_REQUEST['date'] : 0; |
||||
|
||||
$sql = "SELECT * FROM learning_calendar_events |
||||
WHERE start_date = '$startDate' AND calendar_id = $calendarId "; |
||||
$result = Database::query($sql); |
||||
|
||||
if (Database::num_rows($result)) { |
||||
$row = Database::fetch_array($result, 'ASSOC'); |
||||
$currentType = $row['type']; |
||||
$currentType++; |
||||
if ($currentType > count($eventTypeList)) { |
||||
$currentType = 1; |
||||
Database::delete( |
||||
'learning_calendar_events', |
||||
[' calendar_id = ? AND start_date = ?' => [$calendarId, $startDate]] |
||||
); |
||||
} else { |
||||
$params = [ |
||||
'type' => $currentType, |
||||
]; |
||||
Database::update( |
||||
'learning_calendar_events', |
||||
$params, |
||||
[' calendar_id = ? AND start_date = ?' => [$calendarId, $startDate]] |
||||
); |
||||
} |
||||
} else { |
||||
$params = [ |
||||
'name' => '', |
||||
'calendar_id' => $calendarId, |
||||
'start_date' => $startDate, |
||||
'end_date' => $startDate, |
||||
'type' => LpCalendarPlugin::EVENT_TYPE_TAKEN |
||||
]; |
||||
Database::insert('learning_calendar_events', $params); |
||||
} |
||||
break; |
||||
case 'get_events': |
||||
$sql = "SELECT * FROM learning_calendar_events"; |
||||
$result = Database::query($sql); |
||||
$list = []; |
||||
while ($row = Database::fetch_array($result, 'ASSOC')) { |
||||
$list[] = [ |
||||
'start_date' => $row['start_date'], |
||||
'end_date' => $row['start_date'], |
||||
'color' => $eventTypeList[$row['type']] |
||||
]; |
||||
} |
||||
echo json_encode($list); |
||||
break; |
||||
} |
||||
@ -0,0 +1,64 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
|
||||
require_once __DIR__.'/../../main/inc/global.inc.php'; |
||||
|
||||
$allow = api_is_allowed_to_edit(); |
||||
|
||||
if (!$allow) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$calendarId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0; |
||||
|
||||
$item = LpCalendarPlugin::getCalendar($calendarId); |
||||
|
||||
if (empty($item)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$isoCode = api_get_language_isocode(); |
||||
$htmlHeadXtra[] = api_get_asset('bootstrap-year-calendar/js/bootstrap-year-calendar.js'); |
||||
$calendarLanguage = 'en'; |
||||
if ($isoCode !== 'en') { |
||||
$file = 'bootstrap-year-calendar/js/languages/bootstrap-year-calendar.'.$isoCode.'.js'; |
||||
$path = api_get_path(SYS_PUBLIC_PATH).'assets/'.$file; |
||||
if (file_exists($path)) { |
||||
$htmlHeadXtra[] = api_get_asset($file); |
||||
$calendarLanguage = $isoCode; |
||||
} |
||||
} |
||||
|
||||
$htmlHeadXtra[] = api_get_css_asset('bootstrap-year-calendar/css/bootstrap-year-calendar.css'); |
||||
|
||||
$plugin = LpCalendarPlugin::create(); |
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
||||
$formToString = ''; |
||||
|
||||
switch ($action) { |
||||
|
||||
} |
||||
|
||||
$template = new Template(); |
||||
|
||||
$actionLeft = Display::url( |
||||
Display::return_icon( |
||||
'back.png', |
||||
get_lang('Add'), |
||||
null, |
||||
ICON_SIZE_MEDIUM |
||||
), |
||||
api_get_path(WEB_PLUGIN_PATH).'lp_calendar/start.php' |
||||
); |
||||
|
||||
$actions = Display::toolbarAction('toolbar-forum', [$actionLeft]); |
||||
$template->assign('calendar_language', $calendarLanguage); |
||||
|
||||
$template->assign('ajax_url', api_get_path(WEB_PLUGIN_PATH).'lp_calendar/ajax.php?id='.$calendarId); |
||||
|
||||
$template->assign('header', $item['title']); |
||||
$content = $template->fetch('lp_calendar/view/calendar.tpl'); |
||||
$template->assign('actions', $actions); |
||||
$template->assign('content', $content); |
||||
|
||||
$template->display_one_col_template(); |
||||
@ -0,0 +1,8 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
|
||||
if (!api_is_platform_admin()) { |
||||
die('You must have admin permissions to install plugins'); |
||||
} |
||||
|
||||
LpCalendarPlugin::create()->install(); |
||||
@ -0,0 +1,6 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
|
||||
$strings['plugin_title'] = 'Learning path calendar'; |
||||
$strings['plugin_comment'] = ''; |
||||
$strings['enabled'] = 'Enabled'; |
||||
@ -0,0 +1,6 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
|
||||
$strings['plugin_title'] = 'Learning path calendar'; |
||||
$strings['plugin_comment'] = ''; |
||||
$strings['enabled'] = 'Enabled'; |
||||
@ -0,0 +1,6 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
|
||||
$strings['plugin_title'] = 'Learning path calendar'; |
||||
$strings['plugin_comment'] = ''; |
||||
$strings['enabled'] = 'Activado'; |
||||
@ -0,0 +1,4 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
|
||||
$plugin_info = LpCalendarPlugin::create()->get_info(); |
||||
@ -0,0 +1,222 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
|
||||
|
||||
require_once __DIR__.'/../../main/inc/global.inc.php'; |
||||
|
||||
$allow = api_is_allowed_to_edit(); |
||||
|
||||
if (!$allow) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$plugin = LpCalendarPlugin::create(); |
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
||||
$calendarId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0; |
||||
$formToString = ''; |
||||
|
||||
switch ($action) { |
||||
case 'add': |
||||
$form = new FormValidator('calendar', 'post', api_get_self().'?action=add'); |
||||
$plugin->getForm($form); |
||||
$form->addButtonSave(get_lang('Save')); |
||||
|
||||
$formToString = $form->returnForm(); |
||||
|
||||
if ($form->validate()) { |
||||
$values = $form->getSubmitValues(); |
||||
$params = [ |
||||
'title' => $values['title'], |
||||
'total_hours' => $values['total_hours'], |
||||
'minutes_per_day' => $values['minutes_per_day'], |
||||
'description' => $values['description'], |
||||
]; |
||||
Database::insert('learning_calendar', $params); |
||||
Display::addFlash(Display::return_message(get_lang('Saved'))); |
||||
header('Location: start.php'); |
||||
exit; |
||||
} |
||||
break; |
||||
case 'edit': |
||||
$form = new FormValidator('calendar', 'post', api_get_self().'?action=edit&id='.$calendarId); |
||||
$plugin->getForm($form); |
||||
$form->addButtonSave(get_lang('Update')); |
||||
|
||||
$item = LpCalendarPlugin::getCalendar($calendarId); |
||||
|
||||
if (empty($item)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$form->setDefaults($item); |
||||
|
||||
$formToString = $form->returnForm(); |
||||
|
||||
if ($form->validate()) { |
||||
$values = $form->getSubmitValues(); |
||||
$params = [ |
||||
'title' => $values['title'], |
||||
'total_hours' => $values['total_hours'], |
||||
'minutes_per_day' => $values['minutes_per_day'], |
||||
'description' => $values['description'], |
||||
]; |
||||
Database::update('learning_calendar', $params, ['id = ?' => $calendarId]); |
||||
Display::addFlash(Display::return_message(get_lang('Updated'))); |
||||
header('Location: start.php'); |
||||
exit; |
||||
} |
||||
break; |
||||
case 'copy': |
||||
$item = LpCalendarPlugin::getCalendar($calendarId); |
||||
|
||||
if (empty($item)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
unset($item['id']); |
||||
$item['title'] = $item['title'].' - '.get_lang('Copy'); |
||||
|
||||
$newCalendarId = Database::insert('learning_calendar', $item); |
||||
if ($newCalendarId) { |
||||
Display::addFlash(Display::return_message(get_lang('Saved'))); |
||||
$sql = "SELECT * FROM learning_calendar_events WHERE calendar_id = $calendarId"; |
||||
$result = Database::query($sql); |
||||
while ($row = Database::fetch_array($result, 'ASSOC')) { |
||||
unset($row['id']); |
||||
$row['calendar_id'] = $newCalendarId; |
||||
Database::insert('learning_calendar_events', $row); |
||||
} |
||||
} |
||||
|
||||
header('Location: start.php'); |
||||
exit; |
||||
break; |
||||
case 'delete': |
||||
$item = LpCalendarPlugin::getCalendar($calendarId); |
||||
|
||||
if (empty($item)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$sql = "DELETE FROM learning_calendar WHERE id = $calendarId"; |
||||
Database::query($sql); |
||||
|
||||
// Delete events |
||||
$sql = "DELETE FROM learning_calendar_events WHERE calendar_id = $calendarId"; |
||||
Database::query($sql); |
||||
|
||||
Display::addFlash(Display::return_message(get_lang('Deleted'))); |
||||
header('Location: start.php'); |
||||
exit; |
||||
|
||||
break; |
||||
case 'toggle_visibility': |
||||
$itemId = isset($_REQUEST['lp_item_id']) ? $_REQUEST['lp_item_id'] : ''; |
||||
$lpId = isset($_REQUEST['lp_id']) ? $_REQUEST['lp_id'] : ''; |
||||
$plugin->toggleVisibility($itemId); |
||||
Display::addFlash(Display::return_message(get_lang('Updated'))); |
||||
$url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?action=add_item&lp_id='.$lpId.'&'.api_get_cidreq(); |
||||
header("Location: $url"); |
||||
exit; |
||||
break; |
||||
} |
||||
|
||||
$htmlHeadXtra[] = api_get_jqgrid_js(); |
||||
|
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_learning_path_calendars'; |
||||
$columns = [ |
||||
get_lang('Title'), |
||||
get_lang('TotalHours'), |
||||
get_lang('MinutesPerDay'), |
||||
get_lang('Actions'), |
||||
]; |
||||
|
||||
$columnModel = [ |
||||
[ |
||||
'name' => 'title', |
||||
'index' => 'title', |
||||
'width' => '300', |
||||
'align' => 'left', |
||||
'sortable' => 'false', |
||||
], |
||||
[ |
||||
'name' => 'total_hours', |
||||
'index' => 'total_hours', |
||||
'width' => '100', |
||||
'align' => 'left', |
||||
'sortable' => 'false', |
||||
], |
||||
[ |
||||
'name' => 'minutes_per_day', |
||||
'index' => 'minutes_per_day', |
||||
'width' => '100', |
||||
'align' => 'left', |
||||
'sortable' => 'false', |
||||
], |
||||
[ |
||||
'name' => 'actions', |
||||
'index' => 'actions', |
||||
'width' => '150', |
||||
'align' => 'left', |
||||
//'formatter' => 'action_formatter', |
||||
'sortable' => 'false', |
||||
], |
||||
]; |
||||
|
||||
$extraParams = []; |
||||
$extraParams['autowidth'] = 'true'; |
||||
// height auto |
||||
$extraParams['height'] = 'auto'; |
||||
|
||||
$template = new Template(); |
||||
|
||||
if (in_array($action, ['add', 'edit'])) { |
||||
$actionLeft = Display::url( |
||||
Display::return_icon( |
||||
'back.png', |
||||
get_lang('Back'), |
||||
null, |
||||
ICON_SIZE_MEDIUM |
||||
), |
||||
api_get_self().'?'.api_get_cidreq() |
||||
); |
||||
|
||||
} else { |
||||
$actionLeft = Display::url( |
||||
Display::return_icon( |
||||
'add.png', |
||||
get_lang('Add'), |
||||
null, |
||||
ICON_SIZE_MEDIUM |
||||
), |
||||
api_get_self().'?'.api_get_cidreq().'&action=add' |
||||
); |
||||
|
||||
$content = '<script> |
||||
$(function() {'. |
||||
Display::grid_js( |
||||
'calendars', |
||||
$url, |
||||
$columns, |
||||
$columnModel, |
||||
$extraParams, |
||||
[], |
||||
'', |
||||
true |
||||
).' |
||||
}); |
||||
</script>'; |
||||
|
||||
$content .= Display::grid_html('calendars'); |
||||
$template->assign('grid', $content); |
||||
} |
||||
|
||||
$template->assign('form', $formToString); |
||||
$actions = Display::toolbarAction('toolbar-calendar', [$actionLeft]); |
||||
|
||||
$content = $template->fetch('lp_calendar/view/start.tpl'); |
||||
$template->assign('content', $content); |
||||
|
||||
$template->assign('actions', $actions); |
||||
|
||||
$template->display_one_col_template(); |
||||
@ -0,0 +1,4 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
|
||||
LpCalendarPlugin::create()->uninstall(); |
||||
@ -0,0 +1,65 @@ |
||||
<script> |
||||
function getEvents(e) { |
||||
var myData = []; |
||||
$.ajax({ |
||||
dataType: "json", |
||||
url: "{{ ajax_url }}&a=get_events", |
||||
success: function(response) { |
||||
for (var i = 0; i < response.length; i++) { |
||||
myData.push({ |
||||
id: response[i].id, |
||||
title: response[i].title, |
||||
startDate: new Date(response[i].start_date), |
||||
endDate: new Date(response[i].end_date), |
||||
color: response[i].color |
||||
}); |
||||
} |
||||
$(e.target).data('calendar').setDataSource(myData); |
||||
} |
||||
}); |
||||
} |
||||
$(document).ready(function() { |
||||
$('#calendar').calendar({ |
||||
style:'background', |
||||
language : '{{ calendar_language }}', |
||||
enableRangeSelection: false, |
||||
enableContextMenu: true, |
||||
/*contextMenuItems:[ |
||||
{ |
||||
text: 'Update', |
||||
//click: editEvent |
||||
}, |
||||
{ |
||||
text: 'Delete', |
||||
click: deleteEvent |
||||
} |
||||
],*/ |
||||
customDayRenderer: function(e) { |
||||
$(e).parent().css('background-color', 'green'); |
||||
}, |
||||
clickDay: function(e) { |
||||
var dateString = moment(e.date).format("YYYY-MM-DD"); |
||||
$.ajax({ |
||||
type: "GET", |
||||
url: "{{ ajax_url }}&a=toggle_day&date="+dateString, |
||||
success: function(returnValue) { |
||||
getEvents(e); |
||||
} |
||||
}); |
||||
}, |
||||
yearChanged: function(e) { |
||||
e.preventRendering = true; |
||||
$(e.target).append('<div style="text-align:center"><i class="fa fa-spinner fa-spin fa-2x"></i></div>'); |
||||
getEvents(e); |
||||
}, |
||||
}); |
||||
}); |
||||
</script> |
||||
|
||||
<style> |
||||
#calendar { |
||||
overflow: visible; |
||||
} |
||||
</style> |
||||
|
||||
<div id=calendar></div> |
||||
@ -0,0 +1,3 @@ |
||||
{{ form }} |
||||
|
||||
{{ grid }} |
||||
Loading…
Reference in new issue