/
flagrant.php
executable file
·118 lines (104 loc) · 3.78 KB
/
flagrant.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php /*
ocPortal
Copyright (c) ocProducts, 2004-2012
See text/EN/licence.txt for full licencing information.
NOTE TO PROGRAMMERS:
Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
**** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****
*/
/**
* @license http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
* @copyright ocProducts Ltd
* @package flagrant
*/
/**
* Add a flagrant text message.
*
* @param SHORT_TEXT The message
* @param integer The number of days to display for
* @param LONG_TEXT Notes
* @param BINARY Whether the message is for immediate use
* @return AUTO_LINK The ID of the newly added message
*/
function add_flagrant($message,$days,$notes,$validated)
{
$order_time=time();
$id=$GLOBALS['SITE_DB']->query_insert('text',array('notes'=>$notes,'activation_time'=>NULL,'active_now'=>0,'the_message'=>insert_lang_comcode($message,2),'days'=>$days,'order_time'=>$order_time,'user_id'=>get_member()),true);
log_it('ADD_FLAGRANT',strval($id),$message);
if ($validated==1) choose_flagrant($id);
return $id;
}
/**
* Edit a flagrant text message.
*
* @param AUTO_LINK The ID of what to edit
* @param SHORT_TEXT The message
* @param LONG_TEXT Notes
* @param BINARY Whether the message is the active message
*/
function edit_flagrant($id,$message,$notes,$validated)
{
$_message=$GLOBALS['SITE_DB']->query_value('text','the_message',array('id'=>$id));
log_it('EDIT_FLAGRANT',strval($id),$message);
$GLOBALS['SITE_DB']->query_update('text',array('notes'=>$notes,'the_message'=>lang_remap_comcode($_message,$message),'active_now'=>$validated),array('id'=>$id),'',1);
if ($validated==1) choose_flagrant($id); else persistant_cache_delete('FLAGRANT');
}
/**
* Delete a flagrant text message.
*
* @param AUTO_LINK The ID of the flagrant text message to delete
*/
function delete_flagrant($id)
{
$message=$GLOBALS['SITE_DB']->query_value('text','the_message',array('id'=>$id));
$_message=get_translated_text($message);
log_it('DELETE_FLAGRANT',strval($id),$_message);
$GLOBALS['SITE_DB']->query_delete('text',array('id'=>$id),'',1);
delete_lang($message);
persistant_cache_delete('FLAGRANT'); // In case it was active
}
/**
* Choose a flagrant text message.
*
* @param AUTO_LINK The ID of the flagrant text message to choose
*/
function choose_flagrant($id)
{
$message=$GLOBALS['SITE_DB']->query_value('text','the_message',array('id'=>$id));
$message=get_translated_text($message);
log_it('CHOOSE_FLAGRANT',strval($id),$message);
$GLOBALS['SITE_DB']->query_update('text',array('active_now'=>0));
$GLOBALS['SITE_DB']->query_update('text',array('activation_time'=>time(),'active_now'=>1),array('id'=>$id),'',1);
persistant_cache_delete('FLAGRANT');
}
/**
* Get a list of flagrant text messages to choose from.
*
* @return tempcode The list of flagrant text messages
*/
function nice_get_flagrant()
{
$rows=$GLOBALS['SITE_DB']->query_select('text',array('*'),NULL,'ORDER BY order_time ASC');
$time=$GLOBALS['SITE_DB']->query_value_null_ok('text','activation_time',array('active_now'=>1));
$out=new ocp_tempcode();
foreach ($rows as $row)
{
$selected=false;
if ($row['activation_time']<$time)
{
$status=do_lang_tempcode('USED_PREVIOUSLY');
}
elseif (is_null($row['activation_time']))
{
$status=do_lang_tempcode('NOT_USED_PREVIOUSLY');
} else
{
$status=do_lang_tempcode('CURRENT');
$selected=true;
}
$message=get_translated_text($row['the_message']);
$text=do_template('FLAGRANT_STORE_LIST_LINE',array('_GUID'=>'e4a5d54fa6cdc7848bd95bc017c60469','MESSAGE'=>$message,'STATUS'=>$status));
$out->attach(form_input_list_entry(strval($row['id']),$selected,$text->evaluate()));
}
return $out;
}