2013-11-07 Sergio Martin <sergio.martin@artica.es>

* include/functions_events.php: Change the way of store
	the event comments (supporting old way)

	* include/functions_api.php: Improve API clean process
	of the csv output.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@9034 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2013-11-07 16:37:43 +00:00
parent 5d6eb36fc8
commit 8400d8f60d
3 changed files with 149 additions and 61 deletions

View File

@ -1,3 +1,11 @@
2013-11-07 Sergio Martin <sergio.martin@artica.es>
* include/functions_events.php: Change the way of store
the event comments (supporting old way)
* include/functions_api.php: Improve API clean process
of the csv output.
2013-11-07 Miguel de Dios <miguel.dedios@artica.es> 2013-11-07 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_api.php: fixed the validate event with the * include/functions_api.php: fixed the validate event with the

View File

@ -135,9 +135,13 @@ function returnData($returnType, $data, $separator = ';') {
if (!empty($data['data'])) { if (!empty($data['data'])) {
foreach($data['data'] as $dataContent) { foreach($data['data'] as $dataContent) {
$clean = array_map("array_apply_io_safe_output", $dataContent); $clean = array_map("array_apply_io_safe_output", $dataContent);
foreach($clean as $k => $v) {
$clean[$k] = str_replace("\r", "\n", $clean[$k]);
$clean[$k] = str_replace("\n", " ", $clean[$k]);
$clean[$k] = strip_tags($clean[$k]);
$clean[$k] = str_replace(';',' ',$clean[$k]);
}
$row = implode($separator, $clean); $row = implode($separator, $clean);
$row = str_replace("\r", "\n", $row);
$row = str_replace("\n", " ", $row);
echo $row . "\n"; echo $row . "\n";
} }
@ -6116,6 +6120,9 @@ function api_get_event_info($id_event, $trash1, $trash, $returnType) {
$i = 0; $i = 0;
foreach ($event_data as $key => $data) { foreach ($event_data as $key => $data) {
$data = strip_tags($data);
$data = str_replace("\n",' ',$data);
$data = str_replace(';',' ',$data);
if ($i == 0) if ($i == 0)
$result = $key.': '.$data.'<br>'; $result = $key.': '.$data.'<br>';
else else

View File

@ -656,6 +656,44 @@ function events_comment ($id_event, $comment = '', $action = 'Added comment', $m
// If the event hasn't owner, assign the user as owner // If the event hasn't owner, assign the user as owner
events_change_owner ($id_event, $similars); events_change_owner ($id_event, $similars);
// Get the current event comments
$first_event = $id_event;
if (is_array($id_event)) {
$first_event = reset($id_event);
}
$event_comments = db_get_value('user_comment', 'tevento', 'id_evento', $first_event);
$event_comments_array = array();
if ($event_comments == '') {
$comments_format = 'new';
}
else {
// If comments are not stored in json, the format is old
$event_comments_array = json_decode($event_comments);
if (is_null($event_comments_array)) {
$comments_format = 'old';
}
else {
$comments_format = 'new';
}
}
switch($comments_format) {
case 'new':
$comment_for_json['comment'] = $comment;
$comment_for_json['action'] = $action;
$comment_for_json['id_user'] = $config['id_user'];
$comment_for_json['utimestamp'] = time();
$event_comments_array[] = $comment_for_json;
$event_comments = json_encode($event_comments_array);
// Update comment
$ret = db_process_sql_update($event_table, array('user_comment' => $event_comments), array('id_evento' => implode(',', $id_event)));
break;
case 'old':
// Give old ugly format to comment. TODO: Change this method for aux table or json // Give old ugly format to comment. TODO: Change this method for aux table or json
$comment = str_replace(array("\r\n", "\r", "\n"), '<br>', $comment); $comment = str_replace(array("\r\n", "\r", "\n"), '<br>', $comment);
@ -689,6 +727,8 @@ function events_comment ($id_event, $comment = '', $action = 'Added comment', $m
$ret = db_process_sql($sql_validation); $ret = db_process_sql($sql_validation);
break; break;
} }
break;
}
if (($ret === false) || ($ret === 0)) { if (($ret === false) || ($ret === 0)) {
return false; return false;
@ -2324,7 +2364,38 @@ function events_page_comments ($event) {
$table_comments->style[1] = 'text-align: left;'; $table_comments->style[1] = 'text-align: left;';
$table_comments->class = "alternate rounded_cells"; $table_comments->class = "alternate rounded_cells";
$comments_array = explode('<br>',io_safe_output($event["user_comment"])); $event_comments = io_safe_output($event["user_comment"]);
// If comments are not stored in json, the format is old
$event_comments_array = json_decode($event_comments, true);
if (is_null($event_comments_array)) {
$comments_format = 'old';
}
else {
$comments_format = 'new';
}
switch($comments_format) {
case 'new':
if (empty($event_comments_array)) {
$table_comments->style[0] = 'text-align:center;';
$table_comments->colspan[0][0] = 2;
$data = array();
$data[0] = __('There are no comments');
$table_comments->data[] = $data;
}
foreach($event_comments_array as $c) {
$data[0] = '<b>' . $c['action'] . ' by ' . $c['id_user'] . '</b>';
$data[0] .= '<br><br><i>' . date ($config["date_format"], $c['utimestamp']) . '</i>';
$data[1] = $c['comment'];
$table_comments->data[] = $data;
}
break;
case 'old':
$comments_array = explode('<br>',$event_comments);
// Split comments and put in table // Split comments and put in table
$col = 0; $col = 0;
@ -2361,6 +2432,8 @@ function events_page_comments ($event) {
$data[0] = __('There are no comments'); $data[0] = __('There are no comments');
$table_comments->data[] = $data; $table_comments->data[] = $data;
} }
break;
}
if (tags_check_acl ($config['id_user'], $event['id_grupo'], "EW", $event['clean_tags']) || tags_check_acl ($config['id_user'], $event['id_grupo'], "EM", $event['clean_tags'])) { if (tags_check_acl ($config['id_user'], $event['id_grupo'], "EW", $event['clean_tags']) || tags_check_acl ($config['id_user'], $event['id_grupo'], "EM", $event['clean_tags'])) {
$comments_form = '<br><div id="comments_form" style="width:98%;">'.html_print_textarea("comment", 3, 10, '', 'style="min-height: 15px; width: 100%;"', true); $comments_form = '<br><div id="comments_form" style="width:98%;">'.html_print_textarea("comment", 3, 10, '', 'style="min-height: 15px; width: 100%;"', true);