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:
parent
5d6eb36fc8
commit
8400d8f60d
|
@ -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
|
||||||
|
|
|
@ -135,10 +135,14 @@ 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
|
||||||
|
|
|
@ -656,38 +656,78 @@ 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);
|
||||||
|
|
||||||
// Give old ugly format to comment. TODO: Change this method for aux table or json
|
// Get the current event comments
|
||||||
$comment = str_replace(array("\r\n", "\r", "\n"), '<br>', $comment);
|
$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 ($comment != '') {
|
if ($event_comments == '') {
|
||||||
$commentbox = '<div style="border:1px dotted #CCC; min-height: 10px;">'.$comment.'</div>';
|
$comments_format = 'new';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$commentbox = '';
|
// 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';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't translate 'by' word because if various users with different languages
|
switch($comments_format) {
|
||||||
// make comments in the same console will be a mess
|
case 'new':
|
||||||
$comment = '<b>-- ' . $action . ' by '.$config['id_user'].' '.'['.date ($config["date_format"]).'] --</b><br>'.$commentbox.'<br>';
|
$comment_for_json['comment'] = $comment;
|
||||||
|
$comment_for_json['action'] = $action;
|
||||||
// Update comment
|
$comment_for_json['id_user'] = $config['id_user'];
|
||||||
switch ($config['dbtype']) {
|
$comment_for_json['utimestamp'] = time();
|
||||||
// Oldstyle SQL to avoid innecesary PHP foreach
|
|
||||||
case 'mysql':
|
|
||||||
$sql_validation = "UPDATE $event_table
|
|
||||||
SET user_comment = concat('" . $comment . "', user_comment)
|
|
||||||
WHERE id_evento in (" . implode(',', $id_event) . ")";
|
|
||||||
|
|
||||||
$ret = db_process_sql($sql_validation);
|
$event_comments_array[] = $comment_for_json;
|
||||||
break;
|
|
||||||
case 'postgresql':
|
|
||||||
case 'oracle':
|
|
||||||
$sql_validation = "UPDATE $event_table
|
|
||||||
SET user_comment='" . $comment . "' || user_comment)
|
|
||||||
WHERE id_evento in (" . implode(',', $id_event) . ")";
|
|
||||||
|
|
||||||
$ret = db_process_sql($sql_validation);
|
$event_comments = json_encode($event_comments_array);
|
||||||
break;
|
|
||||||
|
// 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
|
||||||
|
$comment = str_replace(array("\r\n", "\r", "\n"), '<br>', $comment);
|
||||||
|
|
||||||
|
if ($comment != '') {
|
||||||
|
$commentbox = '<div style="border:1px dotted #CCC; min-height: 10px;">'.$comment.'</div>';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$commentbox = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't translate 'by' word because if various users with different languages
|
||||||
|
// make comments in the same console will be a mess
|
||||||
|
$comment = '<b>-- ' . $action . ' by '.$config['id_user'].' '.'['.date ($config["date_format"]).'] --</b><br>'.$commentbox.'<br>';
|
||||||
|
|
||||||
|
// Update comment
|
||||||
|
switch ($config['dbtype']) {
|
||||||
|
// Oldstyle SQL to avoid innecesary PHP foreach
|
||||||
|
case 'mysql':
|
||||||
|
$sql_validation = "UPDATE $event_table
|
||||||
|
SET user_comment = concat('" . $comment . "', user_comment)
|
||||||
|
WHERE id_evento in (" . implode(',', $id_event) . ")";
|
||||||
|
|
||||||
|
$ret = db_process_sql($sql_validation);
|
||||||
|
break;
|
||||||
|
case 'postgresql':
|
||||||
|
case 'oracle':
|
||||||
|
$sql_validation = "UPDATE $event_table
|
||||||
|
SET user_comment='" . $comment . "' || user_comment)
|
||||||
|
WHERE id_evento in (" . implode(',', $id_event) . ")";
|
||||||
|
|
||||||
|
$ret = db_process_sql($sql_validation);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($ret === false) || ($ret === 0)) {
|
if (($ret === false) || ($ret === 0)) {
|
||||||
|
@ -2324,42 +2364,75 @@ 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"]);
|
||||||
|
|
||||||
// Split comments and put in table
|
// If comments are not stored in json, the format is old
|
||||||
$col = 0;
|
$event_comments_array = json_decode($event_comments, true);
|
||||||
$data = array();
|
|
||||||
|
|
||||||
foreach ($comments_array as $c) {
|
if (is_null($event_comments_array)) {
|
||||||
switch ($col) {
|
$comments_format = 'old';
|
||||||
case 0:
|
|
||||||
$row_text = preg_replace('/\s*--\s*/',"",$c);
|
|
||||||
$row_text = preg_replace('/\<\/b\>/',"</i>",$row_text);
|
|
||||||
$row_text = preg_replace('/\[/',"</b><br><br><i>[",$row_text);
|
|
||||||
$row_text = preg_replace('/[\[|\]]/',"",$row_text);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
$row_text = preg_replace("/[\r\n|\r|\n]/","<br>",io_safe_output(strip_tags($c)));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data[$col] = $row_text;
|
|
||||||
|
|
||||||
$col++;
|
|
||||||
|
|
||||||
if($col == 2) {
|
|
||||||
$col = 0;
|
|
||||||
$table_comments->data[] = $data;
|
|
||||||
$data = array();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$comments_format = 'new';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (count($comments_array) == 1 && $comments_array[0] == '') {
|
switch($comments_format) {
|
||||||
$table_comments->style[0] = 'text-align:center;';
|
case 'new':
|
||||||
$table_comments->colspan[0][0] = 2;
|
if (empty($event_comments_array)) {
|
||||||
$data = array();
|
$table_comments->style[0] = 'text-align:center;';
|
||||||
$data[0] = __('There are no comments');
|
$table_comments->colspan[0][0] = 2;
|
||||||
$table_comments->data[] = $data;
|
$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
|
||||||
|
$col = 0;
|
||||||
|
$data = array();
|
||||||
|
|
||||||
|
foreach ($comments_array as $c) {
|
||||||
|
switch ($col) {
|
||||||
|
case 0:
|
||||||
|
$row_text = preg_replace('/\s*--\s*/',"",$c);
|
||||||
|
$row_text = preg_replace('/\<\/b\>/',"</i>",$row_text);
|
||||||
|
$row_text = preg_replace('/\[/',"</b><br><br><i>[",$row_text);
|
||||||
|
$row_text = preg_replace('/[\[|\]]/',"",$row_text);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
$row_text = preg_replace("/[\r\n|\r|\n]/","<br>",io_safe_output(strip_tags($c)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data[$col] = $row_text;
|
||||||
|
|
||||||
|
$col++;
|
||||||
|
|
||||||
|
if($col == 2) {
|
||||||
|
$col = 0;
|
||||||
|
$table_comments->data[] = $data;
|
||||||
|
$data = array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($comments_array) == 1 && $comments_array[0] == '') {
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
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'])) {
|
||||||
|
|
Loading…
Reference in New Issue