parent
48be88bd44
commit
a42bd70875
@ -0,0 +1,181 @@ |
||||
<?php // $Id: user_list.php 22041 2009-07-13 18:29:45Z juliomontoya $
|
||||
/* For licensing terms, see /dokeos_license.txt */ |
||||
|
||||
$language_file = array('admin','registration'); |
||||
$cidReset = true; |
||||
require '../inc/global.inc.php'; |
||||
$this_section = SECTION_PLATFORM_ADMIN; |
||||
|
||||
api_protect_admin_script(); |
||||
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; |
||||
require_once api_get_path(LIBRARY_PATH).'security.lib.php'; |
||||
require_once api_get_path(LIBRARY_PATH).'legal.lib.php'; |
||||
//var_dump($_POST); |
||||
// Create the form |
||||
$form = new FormValidator('addlegal'); |
||||
//var_dump($_POST); var_dump($_GET); |
||||
$defaults=array(); |
||||
if( $form->validate()) { |
||||
$check = Security::check_token('post'); |
||||
if ($check) { |
||||
$values = $form->getSubmitValues(); |
||||
$lang = $values['language']; |
||||
//language id |
||||
$lang = api_get_language_id($lang); |
||||
|
||||
$type = $values['type']; |
||||
$content = $values['content']; |
||||
$changes = $values['changes']; |
||||
$submit = $values['send']; |
||||
|
||||
if (isset($values['language'])){ |
||||
if($submit=='back') { |
||||
header('Location: legal_add.php'); |
||||
exit; |
||||
} elseif($submit=='save') { |
||||
$insert_result = LegalManager::add($lang,$content,$type,$changes); |
||||
if ($insert_result ) |
||||
$message = get_lang('TermAndConditionSaved'); |
||||
else |
||||
$message = get_lang('TermAndConditionNotSaved'); |
||||
Security::clear_token(); |
||||
$tok = Security::get_token(); |
||||
header('Location: legal_list.php?action=show_message&message='.urlencode($message).'&sec_token='.$tok); |
||||
exit(); |
||||
} elseif($submit=='preview') { |
||||
$defaults['type']=$type; |
||||
$defaults['content']=$content; |
||||
$defaults['changes']=$changes; |
||||
$term_preview = $defaults; |
||||
$term_preview['type'] = intval($_POST['type']); |
||||
} else { |
||||
$my_lang = $_POST['language']; |
||||
if (isset($_POST['language'])){ |
||||
$all_langs = api_get_languages(); |
||||
if (in_array($my_lang, $all_langs['folder'])){ |
||||
$language = api_get_language_id($my_lang); |
||||
$term_preview = LegalManager::get_last_condition($language); |
||||
$defaults = $term_preview; |
||||
if ($term_preview==false) { |
||||
// there are not terms and conditions |
||||
$term_preview['type']=-1; |
||||
$defaults['type']=0; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} else { |
||||
/* |
||||
if (!isset($_POST['language'])) { |
||||
$language = api_get_setting('platformLanguage'); |
||||
$language = api_get_language_id($language); |
||||
$term_preview = LegalManager::get_last_condition($language); |
||||
$defaults['type']=$term_preview['type']; |
||||
if ($term_preview==false) { |
||||
// there are not terms and conditions |
||||
$term_preview['type']=-1; |
||||
$defaults['type']=0; |
||||
} |
||||
$defaults['content']=$term_preview['content']; |
||||
$defaults['changes']=$term_preview['changes']; |
||||
}*/ |
||||
} |
||||
|
||||
//var_dump($term_preview); |
||||
if(isset($_POST['send'])) { |
||||
Security::clear_token(); |
||||
} |
||||
$token = Security::get_token(); |
||||
|
||||
$form->addElement('hidden','sec_token'); |
||||
$form->setConstants(array('sec_token' => $token)); |
||||
|
||||
$text = '<div class="row"> |
||||
<div class="label"></div> |
||||
<div class="formw"> |
||||
'.get_lang('DisplayTermsConditions').' |
||||
</div> |
||||
</div>'; |
||||
|
||||
$form->addElement('html',$text); |
||||
|
||||
//$form->addElement('select_language', 'language', get_lang('Language'),null,array('id'=>'language','onchange'=>'sendlang();')); |
||||
|
||||
|
||||
if (isset($_POST['language'])) { |
||||
//$form->addElement('html_editor', 'content', null, null, array('ToolbarSet' => 'Basic', 'Width' => '100%', 'Height' => '250')); |
||||
$form->addElement('static', $_POST['language']); |
||||
$form->addElement('hidden', 'language',$_POST['language']); |
||||
$form->addElement('textarea', 'content', get_lang('Content'),array('cols'=>'120','rows'=>'10')); |
||||
$form->addElement('radio', 'type', '', get_lang('HTMLText') ,'0'); |
||||
$form->addElement('radio', 'type', '', get_lang('PageLink') ,'1'); |
||||
$form->addElement('textarea', 'changes', get_lang('ExplainChanges'),array('width'=>'20')); |
||||
|
||||
$preview = LegalManager::show_last_condition($term_preview); |
||||
if ($term_preview['type']!=-1) { |
||||
$term_preview = '<div class="row"> |
||||
<div class="label">'.get_lang('Preview').'</div> |
||||
<div class="formw"> |
||||
'.$preview.' |
||||
</div> |
||||
</div>'; |
||||
$form->addElement('html',$term_preview); |
||||
} |
||||
// Submit & preview button |
||||
$buttons = '<div class="row"> |
||||
<div class="formw"> |
||||
<button type="submit" class="back" name="send" value="back">'.get_lang('Back').'</button> |
||||
<button type="submit" class="search" name="send" value="preview">'.get_lang('Preview').'</button> |
||||
<button type="submit" class="save" name="send" value="save">'.get_lang('Save').'</button> |
||||
</div> |
||||
</div>'; |
||||
$form->addElement('html',$buttons); |
||||
} else { |
||||
$form->addElement('select_language', 'language', get_lang('Language'),null,array()); |
||||
$buttons = '<div class="row"> |
||||
<div class="formw"> |
||||
<button type="submit" class="save" name="send" value="load">'.get_lang('Load').'</button> |
||||
</div> |
||||
</div>'; |
||||
$form->addElement('html',$buttons); |
||||
|
||||
} |
||||
//var_dump($defaults); |
||||
|
||||
|
||||
$tool_name = get_lang('AddTermsAndConditions'); |
||||
$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin')); |
||||
Display :: display_header($tool_name); |
||||
|
||||
echo '<script> |
||||
function sendlang(){ |
||||
//document.addlegal.send.value=\'load\'; |
||||
// alert(document.addlegal.send.value); |
||||
document.addlegal.sec_token.value=\''.$token.'\'; |
||||
document.addlegal.submit(); |
||||
} |
||||
</script>'; |
||||
|
||||
// action menu |
||||
echo '<div class="actions" style="height:22px;">'; |
||||
echo '<div style="float:right;"> |
||||
<a href="'.api_get_path(WEB_CODE_PATH).'admin/legal_list.php">'.Display::return_icon('search.gif',get_lang('EditTermsAndConditions'),'').get_lang('AllVersions').'</a> |
||||
</div><br />'; |
||||
echo '</div>'; |
||||
|
||||
if (isset ($_GET['action'])) { |
||||
switch ($_GET['action']) { |
||||
case 'show_message' : |
||||
Display :: display_normal_message(stripslashes($_GET['message'])); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
|
||||
//var_dump($defaults); |
||||
|
||||
$form->setDefaults($defaults); |
||||
$form->display(); |
||||
?> |
@ -0,0 +1,111 @@ |
||||
<?php |
||||
// 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; |
||||
|
||||
api_protect_admin_script(); |
||||
|
||||
$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin')); |
||||
$tool_name = get_lang('TermsAndConditions'); |
||||
Display :: display_header($tool_name); |
||||
|
||||
require_once (api_get_path(LIBRARY_PATH).'sortabletable.class.php'); |
||||
require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'); |
||||
require_once (api_get_path(LIBRARY_PATH).'security.lib.php'); |
||||
require_once (api_get_path(LIBRARY_PATH).'legal.lib.php'); |
||||
|
||||
$parameters['sec_token'] = Security::get_token(); |
||||
|
||||
// action menu |
||||
echo '<div class="actions" style="height:22px;">'; |
||||
echo '<div style="float:right;"> |
||||
<a href="'.api_get_path(WEB_CODE_PATH).'admin/legal_add.php">'.Display::return_icon('edit.gif',get_lang('EditTermsAndConditions'),'').get_lang('EditTermsAndConditions').'</a> |
||||
</div><br />'; |
||||
echo '</div>'; |
||||
|
||||
// Actions |
||||
if (isset ($_GET['action'])) { |
||||
if ($_GET['action'] == 'show_message') |
||||
Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message']))); |
||||
Security::clear_token(); |
||||
} |
||||
|
||||
$table = new SortableTable('conditions', 'count_mask', 'get_legal_data_mask',2); |
||||
$table->set_additional_parameters($parameters); |
||||
$table->set_header(0, get_lang('Version'), false, 'width="15px"'); |
||||
$table->set_header(1, get_lang('Language'), false, 'width="30px"'); |
||||
$table->set_header(2, get_lang('Content'),false); |
||||
$table->set_header(3, get_lang('Changes'), false, 'width="60px"'); |
||||
$table->set_header(4, get_lang('Type'), false, 'width="60px"'); |
||||
$table->set_header(5, get_lang('Date'), false, 'width="50px"'); |
||||
|
||||
//$table->set_header(4, get_lang('Status')); |
||||
//$table->set_header(5, get_lang('Modify')); |
||||
//$table->set_column_filter(3, 'active_filter'); |
||||
//$table->set_column_filter(4, 'status_filter'); |
||||
//$table->set_column_filter(4, 'modify_filter'); |
||||
//$table->set_form_actions(array ('delete' => get_lang('DeleteFromPlatform'))); |
||||
$table->display(); |
||||
/* |
||||
function status_filter($active, $url_params, $row) { |
||||
$url_id =UrlManager::get_url_id($row[1]); |
||||
if ($row[0] == $url_id ) { |
||||
$action='lock'; |
||||
$image='right'; |
||||
} else { |
||||
$image='wrong'; |
||||
} |
||||
// you cannot lock the default |
||||
$result = Display::return_icon($image.'.gif', get_lang(ucfirst($action))); |
||||
|
||||
return $result; |
||||
} |
||||
*/ |
||||
/* |
||||
function modify_filter($active, $url_params, $row) { |
||||
global $charset; |
||||
$url_id = $row['0']; |
||||
$result .= '<a href="access_url_edit.php?url_id='.$url_id.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a> '; |
||||
if ($url_id != '1') { |
||||
$result .= '<a href="access_urls.php?action=delete_url&url_id='.$url_id.'&sec_token='.$_SESSION['sec_token'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."'".')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>'; |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
function active_filter($active, $url_params, $row) { |
||||
$active = $row['3']; |
||||
if ($active=='1') { |
||||
$action='lock'; |
||||
$image='right'; |
||||
} |
||||
if ($active=='0') { |
||||
$action='unlock'; |
||||
$image='wrong'; |
||||
} |
||||
// you cannot lock the default |
||||
if ($row['0']=='1') { |
||||
$result = Display::return_icon($image.'.gif', get_lang(ucfirst($action))); |
||||
} else { |
||||
$result = '<a href="access_urls.php?action='.$action.'&url_id='.$row['0'].'&sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon($image.'.gif', get_lang(ucfirst($action))).'</a>'; |
||||
} |
||||
return $result; |
||||
} |
||||
*/ |
||||
|
||||
// this 2 "mask" function are here just because the SortableTable |
||||
function get_legal_data_mask($id, $params=null, $row=null) { |
||||
return LegalManager::get_legal_data($id, $params, $row); |
||||
} |
||||
function count_mask() { |
||||
return LegalManager::count(); |
||||
} |
||||
|
||||
/* |
||||
============================================================================== |
||||
FOOTER |
||||
============================================================================== |
||||
*/ |
||||
Display :: display_footer(); |
||||
?> |
@ -0,0 +1,177 @@ |
||||
<?php // $Id: usermanager.lib.php 21700 2009-07-01 19:05:11Z aportugal $
|
||||
/* |
||||
============================================================================== |
||||
*/ |
||||
class LegalManager |
||||
{ |
||||
function add($language, $content, $type, $changes) { |
||||
$legal_table = Database::get_main_table(TABLE_MAIN_LEGAL); |
||||
$last = LegalManager::get_last_condition($language); |
||||
$language = Database::escape_string($language); |
||||
$content = Database::escape_string($content); |
||||
$type = intval($type); |
||||
$changes = Database::escape_string($changes); |
||||
$time = time(); |
||||
|
||||
if ($last['content'] != $content) { |
||||
$version = intval(Legalmanager::get_last_condition_version($language)); |
||||
$version++; |
||||
$sql = "INSERT INTO $legal_table |
||||
SET language_id = '".Database::escape_string($language)."', |
||||
content = '".Database::escape_string($content)."', |
||||
changes= '".Database::escape_string($changes)."', |
||||
type = '".Database::escape_string($type)."', |
||||
version = '".Database::escape_string($version)."', |
||||
date = '".$time."'"; |
||||
$result = Database::query($sql, __FILE__, __LINE__); |
||||
return true; |
||||
} elseif($last['type'] != $type && $language==$last['language_id']) { |
||||
//update |
||||
$id = $last['legal_id']; |
||||
$sql = "UPDATE $legal_table |
||||
SET changes= '".Database::escape_string($changes)."', |
||||
type = '".Database::escape_string($type)."', |
||||
date = '".$time."' |
||||
WHERE legal_id= $id "; |
||||
$result = Database::query($sql, __FILE__, __LINE__); |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
function delete($id) { |
||||
/* |
||||
$legal_table = Database::get_main_table(TABLE_MAIN_LEGAL); |
||||
$id = intval($id); |
||||
$sql = "DELETE FROM $legal_table WHERE legal_id = '".$id."'"; |
||||
*/ |
||||
} |
||||
|
||||
function get_last_condition_version($language){ |
||||
$legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL); |
||||
$language= Database::escape_string($language); |
||||
$sql = "SELECT version FROM $legal_conditions_table WHERE language_id = '".$language."' ORDER BY legal_id DESC LIMIT 1 "; |
||||
$result = Database::query($sql, __FILE__, __LINE__); |
||||
$row = Database::fetch_array($result); |
||||
if (Database::num_rows($result)>0) { |
||||
return $row['version']; |
||||
} else { |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
function get_last_condition($language) { |
||||
$legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL); |
||||
$language= Database::escape_string($language); |
||||
$sql = "SELECT * FROM $legal_conditions_table WHERE language_id = '".$language."' ORDER BY version DESC LIMIT 1 "; |
||||
$result = Database::query($sql, __FILE__, __LINE__); |
||||
return Database::fetch_array($result); |
||||
} |
||||
|
||||
function show_last_condition($term_preview) |
||||
{ |
||||
$preview = ''; |
||||
switch ($term_preview['type']) { |
||||
/*// scroll box |
||||
case 0: |
||||
$preview ='<fieldset> |
||||
<legend>'.get_lang('TermsAndConditions').'</legend>'; |
||||
$preview .= '<div class="form-item"> |
||||
<label>'.get_lang('TermsAndConditions').': </label> |
||||
<div class="resizable-textarea"> |
||||
<span> |
||||
<textarea id="" class="form-textarea resizable textarea-processed" readonly="readonly" name="" rows="10" cols="60">'; |
||||
$preview .= $term_preview['content']; |
||||
$preview .= '</textarea> |
||||
<div class="grippie" style="margin-right: -2px;"/> |
||||
</span> |
||||
</div> |
||||
</div> |
||||
<div id="edit-legal-accept-wrapper" class="form-item"> |
||||
<label class="option" for="edit-legal-accept"> |
||||
<input id="edit-legal-accept" class="form-checkbox" type="checkbox" value="1" name="legal_accept"/> |
||||
<strong>'.get_lang('Accept').'</strong> |
||||
'.get_lang('TermsAndConditions').' |
||||
</label> |
||||
</div> |
||||
</fieldset>'; |
||||
break;*/ |
||||
// html |
||||
case 0: |
||||
$preview = '<div class="legal-terms"> '.$term_preview['content'].' </div>'; |
||||
$preview .= '<br/>'.get_lang('ByClickingAccept'); |
||||
break; |
||||
// page link |
||||
case 1: |
||||
$preview ='<fieldset> |
||||
<legend>'.get_lang('TermsAndConditions').'</legend>'; |
||||
$preview .= '<div id="legal-accept-wrapper" class="form-item"> |
||||
<label class="option" for="legal-accept"> |
||||
<input id="legal-accept" type="checkbox" value="1" name="legal_accept"/> |
||||
<strong>'.get_lang('Accept').'</strong> |
||||
<a href="">'.get_lang('TermsAndConditions').'</a> |
||||
'.get_lang('OfUse').' |
||||
</label> |
||||
</div> |
||||
</fieldset>'; |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
return $preview; |
||||
} |
||||
function get_last_version($language){ |
||||
$legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL); |
||||
$language= Database::escape_string($language); |
||||
$sql = "SELECT version FROM $legal_conditions_table WHERE language_id = '".$language."' ORDER BY version DESC LIMIT 1 "; |
||||
$result = Database::query($sql, __FILE__, __LINE__); |
||||
if (Database::num_rows($result)>0){ |
||||
$version = Database::fetch_array($result); |
||||
$version = explode(':',$version[0]); |
||||
return $version[0]; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
function get_legal_data($from, $number_of_items, $column) { |
||||
$legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL); |
||||
$lang_table = Database::get_main_table(TABLE_MAIN_LANGUAGE); |
||||
$from = intval($from); |
||||
$number_of_items = intval($number_of_items); |
||||
$column = intval($column); |
||||
|
||||
$sql = "SELECT version, original_name as language, content, changes, type, FROM_UNIXTIME(date) |
||||
FROM $legal_conditions_table inner join $lang_table l on(language_id = l.id) "; |
||||
$sql .= "ORDER BY language, version ASC "; |
||||
$sql .= "LIMIT $from,$number_of_items "; |
||||
|
||||
$result = Database::query($sql, __FILE__, __LINE__); |
||||
$legals = array (); |
||||
$versions = array (); |
||||
while ($legal = Database::fetch_array($result)) { |
||||
// max 2000 chars |
||||
//echo strlen($legal[1]); echo '<br>'; |
||||
$versions[]=$legal[0]; |
||||
$languages[]=$legal[1]; |
||||
if (strlen($legal[2])>2000) |
||||
$legal[2]= substr($legal[2],0,2000).' ... '; |
||||
if ($legal[4]==0) |
||||
$legal[4]= get_lang('HTMLText'); |
||||
elseif($legal[4]==1) |
||||
$legal[4]=get_lang('PageLink'); |
||||
$legals[] = $legal; |
||||
} |
||||
return $legals; |
||||
} |
||||
|
||||
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 "; |
||||
$result = Database::query($sql, __FILE__, __LINE__); |
||||
$url = Database::fetch_array($result,'ASSOC'); |
||||
$result = $url['count_result']; |
||||
return $result; |
||||
} |
||||
} |
Loading…
Reference in new issue