diff --git a/main/auth/profile.php b/main/auth/profile.php
index 9bde2718f3..ce26712cca 100755
--- a/main/auth/profile.php
+++ b/main/auth/profile.php
@@ -750,17 +750,97 @@ if ($allowJustification) {
Display::addFlash(Display::return_message($plugin->get_lang('JustificationSaved')));
}
}
+
+ header('Location: '.api_get_self());
+ exit;
}
$userJustifications = $plugin->getUserJustificationList(api_get_user_id());
$userJustificationList = '';
+ $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : '';
+
+ $justificationContent = '';
+ switch ($action) {
+ case 'edit_justification':
+ $justificationId = isset($_REQUEST['justification_id']) ? (int) $_REQUEST['justification_id'] : '';
+ $userJustification = $plugin->getUserJustification($justificationId);
+ $justification = $plugin->getJustification($userJustification['justification_document_id']);
+ if ($justification['date_manual_on'] == 0) {
+ api_not_allowed(true);
+ }
+ $formEdit = new FormValidator('edit', 'post', api_get_self().'?a=edit_justification&justification_id='.$justificationId);
+ $formEdit->addHeader($justification['name']);
+ $element = $formEdit->addDatePicker('date_validity', $plugin->get_lang('ValidityDate'));
+ $element->setValue($userJustification['date_validity']);
+ $formEdit->addButtonUpdate(get_lang('Update'));
+ $formEdit->setDefaults($userJustification);
+ $justificationContent = $formEdit->returnForm();
+ if ($formEdit->validate()) {
+ $values = $formEdit->getSubmitValues();
+ $date = Database::escape_string($values['date_validity']);
+ $sql = "UPDATE justification_document_rel_users SET date_validity = '$date'
+ WHERE id = $justificationId AND user_id = ".$user_data['id'];
+ Database::query($sql);
+ Display::addFlash(Display::return_message(get_lang('Updated')));
+ header('Location: '.api_get_self());
+ exit;
+ }
+ break;
+ case 'delete_justification':
+ $justificationId = isset($_REQUEST['justification_id']) ? (int) $_REQUEST['justification_id'] : '';
+ $userJustification = $plugin->getUserJustification($justificationId);
+ if ($userJustification && $userJustification['user_id'] == api_get_user_id()) {
+ api_remove_uploaded_file_by_id('justification', $justificationId, $userJustification['file_path']);
+ $sql = "DELETE FROM justification_document_rel_users
+ WHERE id = $justificationId AND user_id = ".$user_data['id'];
+ Database::query($sql);
+ Display::addFlash(Display::return_message(get_lang('Deleted')));
+ }
+
+ header('Location: '.api_get_self());
+ exit;
+ break;
+ }
+
if (!empty($userJustifications)) {
$userJustificationList .= Display::page_subheader3($plugin->get_lang('MyJustifications'));
+ $table = new HTML_Table(['class' => 'data_table']);
+ $column = 0;
+ $row = 0;
+ $headers = [
+ get_lang('Name'),
+ get_lang('File'),
+ $plugin->get_lang('ValidityDate'),
+ get_lang('Actions'),
+ ];
+ foreach ($headers as $header) {
+ $table->setHeaderContents($row, $column, $header);
+ $column++;
+ }
+ $row = 1;
foreach ($userJustifications as $userJustification) {
+ $justification = $plugin->getJustification($userJustification['justification_document_id']);
$url = api_get_uploaded_web_url('justification', $userJustification['id'], $userJustification['file_path']);
$link = Display::url($userJustification['file_path'], $url);
- $userJustificationList .= $link.'
';
+ $col = 0;
+ $table->setCellContents($row, $col++, $justification['name']);
+ $table->setCellContents($row, $col++, $link);
+ $date = $userJustification['date_validity'];
+ if ($userJustification['date_validity'] < api_get_local_time()) {
+ $date = Display::label($userJustification['date_validity'], 'warning');
+ }
+ $table->setCellContents($row, $col++, $date);
+ $actions = '';
+
+ if ($justification['date_manual_on'] == 1) {
+ $actions .= Display::url(get_lang('Edit'), api_get_self().'?a=edit_justification&justification_id='.$userJustification['id'], ['class' => 'btn btn-primary']);
+ }
+ $actions .= ' '.Display::url(get_lang('Delete'), api_get_self().'?a=delete_justification&justification_id='.$userJustification['id'], ['class' => 'btn btn-danger']);
+ $table->setCellContents($row, $col++, $actions);
+ $row++;
}
+
+ $userJustificationList .= $justificationContent.$table->toHtml();
}
$justification = $formValidator->returnForm().$userJustificationList;
diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php
index 24d1ea474a..9a9bbac581 100644
--- a/main/inc/lib/api.lib.php
+++ b/main/inc/lib/api.lib.php
@@ -1980,7 +1980,7 @@ function api_get_anonymous_id()
$ip = Database::escape_string(api_get_real_ip());
$max = (int) api_get_configuration_value('max_anonymous_users');
if ($max >= 2) {
- $sql = "SELECT * FROM $table as TEL
+ $sql = "SELECT * FROM $table as TEL
JOIN $tableU as U
ON U.user_id = TEL.login_user_id
WHERE TEL.user_ip = '$ip'
@@ -2015,8 +2015,8 @@ function api_get_anonymous_id()
}
$table = Database::get_main_table(TABLE_MAIN_USER);
- $sql = "SELECT user_id
- FROM $table
+ $sql = "SELECT user_id
+ FROM $table
WHERE status = ".ANONYMOUS." ";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
@@ -4753,7 +4753,7 @@ function api_display_language_form($hide_if_no_choice = false, $showAsButton = f
} else {
$html = '
-
+
'.$currentLanguageInfo['original_name'].'
@@ -4868,7 +4868,7 @@ function languageToCountryIsoCode($languageIsoCode)
function api_get_languages()
{
$tbl_language = Database::get_main_table(TABLE_MAIN_LANGUAGE);
- $sql = "SELECT * FROM $tbl_language WHERE available='1'
+ $sql = "SELECT * FROM $tbl_language WHERE available='1'
ORDER BY original_name ASC";
$result = Database::query($sql);
$language_list = [];
@@ -8217,8 +8217,8 @@ function api_get_password_checker_js($usernameInputId, $passwordInputId)
};
$(function() {
- var lang = ".json_encode($translations).";
- var options = {
+ var lang = ".json_encode($translations).";
+ var options = {
onLoad : function () {
//$('#messages').text('Start typing password');
},
@@ -8236,7 +8236,7 @@ function api_get_password_checker_js($usernameInputId, $passwordInputId)
options.i18n = {
t: function (key) {
var result = lang[key];
- return result === key ? '' : result; // This assumes you return the
+ return result === key ? '' : result; // This assumes you return the
}
};
$('".$passwordInputId."').pwstrength(options);
@@ -9568,7 +9568,7 @@ function api_set_noreply_and_from_address_to_mailer(PHPMailer $mailer, array $se
isset($platformEmail['SMTP_UNIQUE_SENDER']) &&
$platformEmail['SMTP_UNIQUE_SENDER']
) {
- $senderName = $notification->getDefaultPlatformSenderName();
+ $senderName = $notification->getDefaultPlatformSenderName();
$senderEmail = $notification->getDefaultPlatformSenderEmail();
if (PHPMailer::ValidateAddress($senderEmail)) {
@@ -9596,7 +9596,7 @@ function api_find_template($template)
function api_get_language_list_for_flag()
{
$table = Database::get_main_table(TABLE_MAIN_LANGUAGE);
- $sql = "SELECT english_name, isocode FROM $table
+ $sql = "SELECT english_name, isocode FROM $table
ORDER BY original_name ASC";
static $languages = [];
if (empty($languages)) {
@@ -9627,11 +9627,11 @@ function api_get_language_translate_html()
$hideAll .= '
$("span:lang('.$language['isocode'].')").filter(
function(e, val) {
- // Only find the spans if they have set the lang
- if ($(this).attr("lang") == null) {
+ // Only find the spans if they have set the lang
+ if ($(this).attr("lang") == null) {
return false;
}
-
+
// Ignore ckeditor classes
return !this.className.match(/cke(.*)/);
}).hide();'."\n";
@@ -9648,32 +9648,32 @@ function api_get_language_translate_html()
return '
$(function() {
- '.$hideAll.'
- var defaultLanguageFromUser = "'.$isoCode.'";
-
+ '.$hideAll.'
+ var defaultLanguageFromUser = "'.$isoCode.'";
+
$("span:lang('.$isoCode.')").filter(
function() {
// Ignore ckeditor classes
return !this.className.match(/cke(.*)/);
}).show();
-
+
var defaultLanguage = "";
var langFromUserFound = false;
-
+
$(this).find("span").filter(
function() {
// Ignore ckeditor classes
return !this.className.match(/cke(.*)/);
}).each(function() {
- defaultLanguage = $(this).attr("lang");
+ defaultLanguage = $(this).attr("lang");
if (defaultLanguage) {
- $(this).before().next("br").remove();
+ $(this).before().next("br").remove();
if (defaultLanguageFromUser == defaultLanguage) {
langFromUserFound = true;
}
}
});
-
+
// Show default language
if (langFromUserFound == false && defaultLanguage) {
$("span:lang("+defaultLanguage+")").filter(
diff --git a/main/inc/lib/formvalidator/FormValidator.class.php b/main/inc/lib/formvalidator/FormValidator.class.php
index 90f1cf4e44..6203f4e71b 100755
--- a/main/inc/lib/formvalidator/FormValidator.class.php
+++ b/main/inc/lib/formvalidator/FormValidator.class.php
@@ -237,7 +237,7 @@ EOT;
* @param string $label
* @param array $attributes
*
- * @return mixed
+ * @return DatePicker
*/
public function addDatePicker($name, $label, $attributes = [])
{
diff --git a/plugin/justification/add.php b/plugin/justification/add.php
index e7618f3411..e6d0c5bf9b 100644
--- a/plugin/justification/add.php
+++ b/plugin/justification/add.php
@@ -21,11 +21,12 @@ $form->addButtonSave(get_lang('Save'));
if ($form->validate()) {
$values = $form->getSubmitValues();
+ $dateManual = isset($values['date_manual_on']) ? 1 : 0;
$params = [
'name' => $values['name'],
'code' => $values['code'],
'validity_duration' => $values['validity_duration'],
- 'date_manual_on' => (int) $values['date_manual_on'],
+ 'date_manual_on' => $dateManual,
'comment' => $values['comment'],
];
Database::insert('justification_document', $params);
diff --git a/plugin/justification/justification_by_user.php b/plugin/justification/justification_by_user.php
index af52dadc4c..ac900fec7c 100644
--- a/plugin/justification/justification_by_user.php
+++ b/plugin/justification/justification_by_user.php
@@ -35,8 +35,10 @@ if ($userId) {
$list = $plugin->getUserJustificationList($userId);
if ($list) {
foreach ($list as &$item) {
+ if ($item['date_validity'] < api_get_local_time()) {
+ $item['date_validity'] = Display::label($item['date_validity'], 'warning');
+ }
$item['justification'] = $plugin->getJustification($item['justification_document_id']);
-
$item['file_path'] = Display::url(
$item['file_path'],
api_get_uploaded_web_url('justification', $item['id'], $item['file_path']),
@@ -50,7 +52,6 @@ if ($userId) {
$tpl->assign('list', $list);
}
-
$tpl->assign('user_id', $userId);
$content = $tpl->fetch('justification/view/justification_user_list.tpl');
@@ -60,6 +61,27 @@ $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : '';
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
switch ($action) {
+ case 'edit':
+ $userJustification = $plugin->getUserJustification($id);
+ $userInfo = api_get_user_info($userJustification['user_id']);
+ $form = new FormValidator('edit', 'post', api_get_self().'?a=edit&id='.$id.'&user_id='.$userId);
+ $form->addHeader($userInfo['complete_name']);
+ $element = $form->addDatePicker('date_validity', $plugin->get_lang('ValidityDate'));
+ $element->setValue($userJustification['date_validity']);
+ $form->addButtonUpdate(get_lang('Update'));
+ $form->setDefaults($userJustification);
+ $content = $form->returnForm();
+
+ if ($form->validate()) {
+ $values = $form->getSubmitValues();
+ $date = Database::escape_string($values['date_validity']);
+ $sql = "UPDATE justification_document_rel_users SET date_validity = '$date' WHERE id = $id";
+ Database::query($sql);
+ Display::addFlash(Display::return_message(get_lang('Updated')));
+ header('Location: '.api_get_self().'?user_id='.$userId);
+ exit;
+ }
+ break;
case 'delete':
$userJustification = $plugin->getUserJustification($id);
if ($userJustification) {
@@ -87,6 +109,5 @@ $tpl->assign(
Display::toolbarAction('toolbar', [$actionLinks])
);
-
$tpl->assign('content', $content);
$tpl->display_one_col_template();
diff --git a/plugin/justification/lang/english.php b/plugin/justification/lang/english.php
index db6f544134..58b60bdc66 100644
--- a/plugin/justification/lang/english.php
+++ b/plugin/justification/lang/english.php
@@ -9,7 +9,7 @@ $strings['ValidityDuration'] = "Validity Duration";
$strings['DateManualOn'] = "Date Manual On";
$strings['JustificationCode'] = "Justification code";
$strings['NoJustificationFound'] = "No justification found";
-$strings['DateValidity'] = "Date validity";
+$strings['ValidityDate'] = "Validity date";
$strings['Justification'] = "Justification";
$strings['MyJustifications'] = "My justifications";
diff --git a/plugin/justification/view/justification_user_list.tpl b/plugin/justification/view/justification_user_list.tpl
index 47a763da39..c9c96c8e77 100644
--- a/plugin/justification/view/justification_user_list.tpl
+++ b/plugin/justification/view/justification_user_list.tpl
@@ -8,21 +8,25 @@
| {{ 'Justification'| get_plugin_lang('Justification') }} | {{ 'File'| get_lang }} | {{ 'Date'| get_lang('Date') }} | {{ 'Actions'| get_lang }} | |
|---|---|---|---|---|
| {{ item.justification.name }} | {{ item.file_path }} | -{{ item.date_validity }} | ++ {{ item.date_validity }} + | - + + {{'Edit' | get_lang}} + + {{'Delete' | get_lang}} |