Skip to content

Commit

Permalink
Add feature to send/delete legal contracts see BT#11196
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Jun 1, 2016
1 parent 90f1794 commit 97dc7d9
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 98 deletions.
11 changes: 11 additions & 0 deletions app/Migrations/Schema/V111/Version111.php
Expand Up @@ -273,6 +273,17 @@ public function up(Schema $schema)
$this->addSql("ALTER TABLE c_quiz_question_rel_category ADD INDEX idx_qqrc_qid (question_id)");
$this->addSql("ALTER TABLE c_quiz_answer ADD INDEX idx_cqa_q (question_id)");
$this->addSql("ALTER TABLE c_student_publication ADD INDEX idx_csp_u (user_id)");

$this->addSql('ALTER TABLE legal DROP PRIMARY KEY;');
$this->addSql('ALTER TABLE legal ADD id INT');
$this->addSql('UPDATE legal SET id = legal_id');
$this->addSql('UPDATE legal SET id = 1 WHERE id = 0');
$this->addSql('ALTER TABLE legal MODIFY COLUMN language_id INT NOT NULL');
$this->addSql('ALTER TABLE legal DROP legal_id');
$this->addSql('ALTER TABLE legal CHANGE id id INT NOT NULL;');
$this->addSql('ALTER TABLE legal ADD PRIMARY KEY (id);');


}
}

Expand Down
4 changes: 2 additions & 2 deletions main/admin/configure_inscription.php
Expand Up @@ -303,8 +303,8 @@

// Version and language //password
$form->addElement('hidden', 'legal_accept_type', $term_preview['version'].':'.$term_preview['language_id']);
$form->addElement('hidden', 'legal_info', $term_preview['legal_id'].':'.$term_preview['language_id']);
$form->addElement('hidden', 'legal_info', $term_preview['id'].':'.$term_preview['language_id']);

if ($term_preview['type'] == 1) {
$form->addElement(
'checkbox',
Expand Down
144 changes: 96 additions & 48 deletions main/admin/user_information.php
Expand Up @@ -17,6 +17,7 @@

$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array("url" => 'user_list.php', "name" => get_lang('UserList'));

if (!isset($_GET['user_id'])) {
api_not_allowed();
}
Expand Down Expand Up @@ -58,9 +59,79 @@
),
api_get_path(WEB_PATH).'main/social/vcard_export.php?userId='.$userId
);
}


$studentBossList = UserManager::getStudentBossList($userId);
$studentBossListToString = '';
if ($studentBossList) {
$table = new HTML_Table(array('class' => 'data_table'));
$table->setHeaderContents(0, 0, get_lang('User'));
$csvContent[] = [get_lang('StudentBoss')];

$row = 1;
foreach ($studentBossList as $studentBossId) {
$studentBoss = api_get_user_info($studentBossId['boss_id']);
$table->setCellContents($row, 0, $studentBoss['complete_name_with_username']);
$csvContent[] = array($studentBoss['complete_name_with_username']);
$row++;
}
$studentBossListToString = $table->toHtml();
}

if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'send_legal':
$subject = get_lang('SendLegalSubject');
$content = sprintf(
get_lang('SendLegalDescriptionToUrlX'),
api_get_path(WEB_CODE_PATH).'auth/inscription.php'
);
MessageManager::send_message_simple($userId, $subject, $content);
Display::addFlash(Display::return_message(get_lang('Sent')));
break;
case 'delete_legal':
$extraFieldValue = new ExtraFieldValue('user');
$value = $extraFieldValue->get_values_by_handler_and_field_variable($userId, 'legal_accept');

$result = $extraFieldValue->delete($value['id']);
if ($result) {
Display::addFlash(Display::return_message(get_lang('Deleted')));
}
break;
case 'unsubscribe':
$courseCode = empty($_GET['course_code']) ? '' : intval($_GET['course_code']);
$sessionId = empty($_GET['id_session']) ? 0 : intval($_GET['id_session']);
if (CourseManager::get_user_in_course_status($userId, $courseCode) == STUDENT) {
CourseManager::unsubscribe_user($userId, $courseCode, $sessionId);
Display::addFlash(Display::return_message(get_lang('UserUnsubscribed')));
} else {
Display::addFlash(Display::return_message(
get_lang('CannotUnsubscribeUserFromCourse'),
'error',
false
));
}
break;
case 'unsubscribeSessionCourse':
$userId = empty($_GET['user_id']) ? 0 : intval($_GET['user_id']);
$courseCode = empty($_GET['course_code']) ? '' : intval($_GET['course_code']);
$sessionId = empty($_GET['id_session']) ? 0 : intval($_GET['id_session']);
SessionManager::removeUsersFromCourseSession(
array($userId),
$sessionId,
api_get_course_info($courseCode)
);
Display::addFlash(Display::return_message(get_lang('UserUnsubscribed')));
break;
case 'export':
Export :: arrayToCsv($csvContent, 'user_information_'.$user);
exit;
break;
}
}


// Show info about who created this user and when
$creatorId = $user['creator_id'];
$creatorInfo = api_get_user_info($creatorId);
Expand Down Expand Up @@ -88,7 +159,7 @@
.$creatorId,
$creatorInfo['username'],
api_get_utc_datetime($registrationDate)
),
)
);

$row = 1;
Expand All @@ -109,6 +180,29 @@
get_lang('FirstLogin') => Tracking :: get_first_connection_date($userId),
get_lang('LatestLogin') => Tracking :: get_last_connection_date($userId, true)
);

if (api_get_setting('allow_terms_conditions') === 'true') {
$extraFieldValue = new ExtraFieldValue('user');
$value = $extraFieldValue->get_values_by_handler_and_field_variable($userId, 'legal_accept');
$icon = Display::return_icon('accept_na.png');
if (isset($value['value'])) {
list($legalId, $legalLanguageId, $legalTime) = explode(':', $value['value']);
$icon = Display::return_icon('accept.png').' '.api_get_local_time($legalTime);
$icon .= ' '.Display::url(
get_lang('DeleteLegal'),
api_get_self().'?action=delete_legal&user_id='.$userId,
['class' => 'btn btn-danger btn-xs']
);
} else {
$icon .= ' '.Display::url(
get_lang('SendLegal'),
api_get_self().'?action=send_legal&user_id='.$userId,
['class' => 'btn btn-primary btn-xs']
);
}

$data[get_lang('LegalAccepted')] = $icon;
}
$row = 1;
foreach ($data as $label => $item) {
if (!empty($label)) {
Expand Down Expand Up @@ -381,60 +475,16 @@
}
}

$studentBossList = UserManager::getStudentBossList($userId);
$studentBossListToString = '';
if ($studentBossList) {
$table = new HTML_Table(array('class' => 'data_table'));
$table->setHeaderContents(0, 0, get_lang('User'));
$csvContent[] = [get_lang('StudentBoss')];

$row = 1;
foreach ($studentBossList as $studentBossId) {
$studentBoss = api_get_user_info($studentBossId['boss_id']);
$table->setCellContents($row, 0, $studentBoss['complete_name_with_username']);
$csvContent[] = array($studentBoss['complete_name_with_username']);
$row++;
}
$studentBossListToString = $table->toHtml();
}

$message = null;

if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'unsubscribe':
$userId = empty($_GET['user_id']) ? 0 : intval($_GET['user_id']);
$courseCode = empty($_GET['course_code']) ? '' : intval($_GET['course_code']);
$sessionId = empty($_GET['id_session']) ? 0 : intval($_GET['id_session']);
if (CourseManager::get_user_in_course_status($userId, $courseCode) == STUDENT) {
CourseManager::unsubscribe_user($userId, $courseCode, $sessionId);
$message = Display::return_message(get_lang('UserUnsubscribed'));
} else {
$message = Display::return_message(
get_lang('CannotUnsubscribeUserFromCourse'),
'error',
false
);
}
break;
case 'unsubscribeSessionCourse':
$userId = empty($_GET['user_id']) ? 0 : intval($_GET['user_id']);
$courseCode = empty($_GET['course_code']) ? '' : intval($_GET['course_code']);
$sessionId = empty($_GET['id_session']) ? 0 : intval($_GET['id_session']);
SessionManager::removeUsersFromCourseSession(
array($userId),
$sessionId,
api_get_course_info($courseCode)
);
$message = Display::return_message(get_lang('UserUnsubscribed'));
break;
case 'export':
Export :: arrayToCsv($csvContent, 'user_information_'.$user);
exit;
break;
}
}


Display::display_header($tool_name);

echo '<div class="actions">
Expand All @@ -461,8 +511,6 @@

echo '<div class="row">';

echo $message;

echo '<div class="col-md-2">';
echo '<a class="expand-image" href="'.$fullUrlBig.'">'
.'<img src="'.$fullUrl.'" /></a><br />';
Expand Down
14 changes: 9 additions & 5 deletions main/auth/inscription.php
Expand Up @@ -515,7 +515,7 @@ function initializeGeo(address, latLng) {

// Version and language
$form->addElement('hidden', 'legal_accept_type', $term_preview['version'].':'.$term_preview['language_id']);
$form->addElement('hidden', 'legal_info', $term_preview['legal_id'].':'.$term_preview['language_id']);
$form->addElement('hidden', 'legal_info', $term_preview['id'].':'.$term_preview['language_id']);
$form->addElement('hidden', 'legal_course_id', api_get_course_int_id());

if ($term_preview['type'] == 1) {
Expand Down Expand Up @@ -800,10 +800,14 @@ function initializeGeo(address, latLng) {
$form_data['action'] = api_get_path(WEB_PATH).'user_portal.php';
} else {
$courseInfo = api_get_course_info();
$form_data['action'] = $courseInfo['course_public_url'].'?id_session='.api_get_session_id();
$cidReset = true;
Session::erase('_course');
Session::erase('_cid');
if (!empty($courseInfo)) {
$form_data['action'] = $courseInfo['course_public_url'].'?id_session='.api_get_session_id();
$cidReset = true;
Session::erase('_course');
Session::erase('_cid');
} else {
$form_data['action'] = api_get_path(WEB_PATH).'user_portal.php';
}
}
} else {
if (!empty($values['email'])) {
Expand Down
14 changes: 7 additions & 7 deletions main/inc/lib/legal.lib.php
Expand Up @@ -45,14 +45,14 @@ public static function add($language, $content, $type, $changes)

return true;
} elseif($last['type'] != $type && $language == $last['language_id']) {
//update
$id = $last['legal_id'];
// Update
$id = $last['id'];
$params = [
'changes' => $changes,
'type' => $type,
'date' => $time
];
Database::update($legal_table, $params, ['legal_id => ?' => $id]);
Database::update($legal_table, $params, ['id => ?' => $id]);

return true;
} else {
Expand All @@ -69,7 +69,7 @@ public static function delete($id)
/*
$legal_table = Database::get_main_table(TABLE_MAIN_LEGAL);
$id = intval($id);
$sql = "DELETE FROM $legal_table WHERE legal_id = '".$id."'";
$sql = "DELETE FROM $legal_table WHERE id = '".$id."'";
*/
}

Expand All @@ -84,7 +84,7 @@ public static function get_last_condition_version($language)
$language= Database::escape_string($language);
$sql = "SELECT version FROM $legal_conditions_table
WHERE language_id = '".$language."'
ORDER BY legal_id DESC LIMIT 1 ";
ORDER BY id DESC LIMIT 1 ";
$result = Database::query($sql);
$row = Database::fetch_array($result);
if (Database::num_rows($result) > 0) {
Expand Down Expand Up @@ -224,7 +224,7 @@ public static function count()
$legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL);
$sql = "SELECT count(*) as count_result
FROM $legal_conditions_table
ORDER BY legal_id DESC ";
ORDER BY id DESC ";
$result = Database::query($sql);
$url = Database::fetch_array($result,'ASSOC');
$result = $url['count_result'];
Expand All @@ -244,7 +244,7 @@ public static function get_type_of_terms_and_conditions($legal_id, $language_id)
$legal_id = intval($legal_id);
$language_id = intval($language_id);
$sql = 'SELECT type FROM '.$legal_conditions_table.'
WHERE legal_id="'.$legal_id.'" AND language_id="'.$language_id.'"';
WHERE id = "'.$legal_id.'" AND language_id="'.$language_id.'"';
$rs = Database::query($sql);

return Database::result($rs,0,'type');
Expand Down
1 change: 1 addition & 0 deletions main/inc/lib/model.lib.php
Expand Up @@ -59,6 +59,7 @@ public function delete($id)
// Database table definition
$result = Database::delete($this->table, $params);
if ($result != 1) {

return false;
}

Expand Down
3 changes: 0 additions & 3 deletions main/inc/local.inc.php
Expand Up @@ -1148,9 +1148,6 @@
exit;
}
}



}

if (isset($user_id) && $user_id && isset($_real_cid) && $_real_cid) {
Expand Down

0 comments on commit 97dc7d9

Please sign in to comment.