Index: admin_templates/spam_reports/spam_report_edit.tpl
===================================================================
--- admin_templates/spam_reports/spam_report_edit.tpl (revision 0)
+++ admin_templates/spam_reports/spam_report_edit.tpl (revision 0)
@@ -0,0 +1,132 @@
+<inp2:adm_SetPopupSize width="550" height="400"/>
+
+<inp2:m_DefaultParam prefix="spam-report"/>
+<inp2:m_include t="incs/header"/>
+<inp2:m_RenderElement name="combined_header" section="in-portal:spam_reports" prefix="$prefix" title_preset="spam_report_edit"/>
+
+<!-- ToolBar -->
+<table class="toolbar" height="30" cellspacing="0" cellpadding="0" width="100%" border="0">
+<tbody>
+ <tr>
+ <td>
+ <script type="text/javascript">
+ a_toolbar = new ToolBar();
+
+ a_toolbar.AddButton(
+ new ToolBarButton(
+ 'select',
+ '<inp2:m_phrase label="la_ToolTip_Save" escape="1"/>',
+ function() {
+ submit_event('<inp2:m_Param name="prefix"/>', '<inp2:$prefix_SaveEvent/>');
+ }
+ )
+ );
+
+ a_toolbar.AddButton(
+ new ToolBarButton(
+ 'cancel',
+ '<inp2:m_phrase label="la_ToolTip_Cancel" escape="1"/>',
+ function() {
+ cancel_edit('<inp2:m_Param name="prefix"/>', 'OnCancelEdit', '<inp2:$prefix_SaveEvent/>', '<inp2:m_Phrase label="la_FormCancelConfirmation" escape="1"/>');
+ }
+ )
+ );
+
+ a_toolbar.AddButton(
+ new ToolBarButton(
+ 'reset_edit',
+ '<inp2:m_phrase label="la_ToolTip_Reset" escape="1"/>',
+ function() {
+ reset_form('<inp2:m_Param name="prefix"/>', 'OnReset', '<inp2:m_Phrase label="la_FormResetConfirmation" escape="1"/>');
+ }
+ )
+ );
+
+ a_toolbar.AddButton( new ToolBarSeparator('sep1') );
+
+ a_toolbar.AddButton(
+ new ToolBarButton(
+ 'prev',
+ '<inp2:m_phrase label="la_ToolTip_Prev" escape="1"/>',
+ function() {
+ go_to_id('<inp2:m_Param name="prefix"/>', '<inp2:$prefix_PrevId/>');
+ }
+ )
+ );
+
+ a_toolbar.AddButton(
+ new ToolBarButton(
+ 'next',
+ '<inp2:m_phrase label="la_ToolTip_Next" escape="1"/>',
+ function() {
+ go_to_id('<inp2:m_Param name="prefix"/>', '<inp2:$prefix_NextId/>');
+ }
+ )
+ );
+
+ a_toolbar.AddButton( new ToolBarSeparator('sep2') );
+
+ <inp2:m_if check="spam-report_IsReviewReport">
+ a_toolbar.AddButton(
+ new ToolBarButton(
+ 'delete',
+ '<inp2:m_phrase label="la_ToolTip_DeleteReview" escape="1"/>',
+ function() {
+ if ( confirm('<inp2:m_Phrase name="lu_AssociatedReviewRemovalConfirmation" js_escape="1"/>') ) {
+ submit_event('spam-report', 'OnDeleteAssocItem');
+ }
+ }
+ )
+ );
+ </inp2:m_if>
+
+ a_toolbar.Render();
+
+ <inp2:m_if check="{$prefix}_IsSingle">
+ a_toolbar.HideButton('prev');
+ a_toolbar.HideButton('next');
+ a_toolbar.HideButton('sep1');
+ <inp2:m_else/>
+ <inp2:m_if check="{$prefix}_IsLast">
+ a_toolbar.DisableButton('next');
+ </inp2:m_if>
+ <inp2:m_if check="{$prefix}_IsFirst">
+ a_toolbar.DisableButton('prev');
+ </inp2:m_if>
+ </inp2:m_if>
+ </script>
+ </td>
+
+ <inp2:m_RenderElement name="ml_selector" prefix="$prefix"/>
+ </tr>
+</tbody>
+</table>
+
+<inp2:$prefix_SaveWarning name="grid_save_warning"/>
+<inp2:$prefix_ErrorWarning name="form_error_warning"/>
+
+<div id="scroll_container">
+ <table class="edit-form">
+ <inp2:m_RenderElement name="subsection" title="la_section_General"/>
+ <inp2:m_RenderElement name="inp_id_label" prefix="$prefix" field="ReportId" title="la_fld_Id"/>
+ <inp2:m_RenderElement name="inp_label" prefix="$prefix" field="MessageText" title="la_fld_MessageText" nl2br="1"/>
+ <inp2:m_RenderElement name="inp_label" prefix="$prefix" field="ReportedOn" title="la_fld_ReportedOn"/>
+ <inp2:m_RenderElement name="inp_label" prefix="$prefix" field="ReportedBy" title="la_fld_ReportedBy"/>
+
+ <tr class="subsectiontitle">
+ <td colspan="3"><inp2:spam-report_Field name="ItemPrefix"/></td>
+ </tr>
+
+ <inp2:m_RenderElement name="inp_label" prefix="$prefix" field="ItemId" title="la_fld_ItemId"/>
+
+ <inp2:m_RenderElement design="form_row" prefix="$prefix" field="ItemName" title="la_fld_ItemName">
+ <td class="control-cell" valign="top">
+ <a href="<inp2:$prefix_ItemEditLink/>" title="<inp2:m_Phrase name='la_Text_Edit' no_editing='1'/>" onclick="return direct_edit('<inp2:m_param name="prefix"/>', this.href);"><inp2:$prefix_Field field="$field"/></a>
+ </td>
+ </inp2:m_RenderElement>
+
+ <inp2:m_RenderElement name="inp_edit_filler"/>
+ </table>
+</div>
+
+<inp2:m_include t="incs/footer"/>
\ No newline at end of file
Index: admin_templates/spam_reports/spam_report_list.tpl
===================================================================
--- admin_templates/spam_reports/spam_report_list.tpl (revision 0)
+++ admin_templates/spam_reports/spam_report_list.tpl (revision 0)
@@ -0,0 +1,95 @@
+<inp2:m_DefaultParam prefix="spam-report" grid="Default"/>
+<inp2:m_include t="incs/header"/>
+<inp2:m_RenderElement name="combined_header" section="in-portal:spam_reports" prefix="$prefix" grid="$grid" title_preset="spam_report_list" pagination="1"/>
+
+<!-- ToolBar -->
+<table class="toolbar" height="30" cellspacing="0" cellpadding="0" width="100%" border="0">
+<tbody>
+ <tr>
+ <td>
+ <script type="text/javascript">
+ //do not rename - this function is used in default grid for double click!
+ function edit() {
+ std_edit_temp_item('<inp2:m_Param name="prefix"/>', 'spam_reports/spam_report_edit');
+ }
+
+ var a_toolbar = new ToolBar();
+
+ a_toolbar.AddButton(
+ new ToolBarButton(
+ 'edit',
+ '<inp2:m_phrase label="la_ToolTip_Edit" escape="1"/>::<inp2:m_phrase label="la_ShortToolTip_Edit" escape="1"/>',
+ edit
+ )
+ );
+
+ a_toolbar.AddButton(
+ new ToolBarButton(
+ 'delete',
+ '<inp2:m_phrase label="la_ToolTip_DeleteSpamReportOnly" escape="1"/>',
+ function() {
+ std_delete_items('<inp2:m_Param name="prefix"/>')
+ }
+ )
+ );
+
+ a_toolbar.AddButton( new ToolBarSeparator('sep1') );
+
+ a_toolbar.AddButton(
+ new ToolBarButton(
+ 'view',
+ '<inp2:m_phrase label="la_ToolTip_View" escape="1"/>',
+ function() {
+ show_viewmenu(a_toolbar,'view');
+ }
+ )
+ );
+
+ a_toolbar.Render();
+ </script>
+ </td>
+ <inp2:m_RenderElement name="search_main_toolbar" prefix="$prefix" grid="$grid"/>
+ </tr>
+</tbody>
+</table>
+
+<inp2:m_DefineElement name="grid_edit_item_td">
+ <a href="<inp2:ItemEditLink/>" title="<inp2:m_Phrase name='la_Text_Edit' no_editing='1'/>" onclick="return direct_edit('<inp2:m_param name="PrefixSpecial"/>', this.href);"><inp2:Field field="$field"/></a>
+</inp2:m_DefineElement>
+
+<inp2:m_DefineElement name="grid_item_prefix_td">
+ <inp2:Field field="$field"/>
+
+ <inp2:m_if check="IsReviewReport">
+ (<a class="delete-item-link" item_prefix="<inp2:Field name='ItemPrefix' db='db'/>" href="<inp2:AssocItemDeleteLink/>"><inp2:m_Phrase name="la_btn_DeleteReview"/></a>)
+ </inp2:m_if>
+</inp2:m_DefineElement>
+
+<inp2:m_RenderElement name="grid" PrefixSpecial="$prefix" IdField="ReportId" grid="$grid"/>
+<script type="text/javascript">
+ Grids['<inp2:m_Param name="prefix"/>'].SetDependantToolbarButtons( new Array('edit','delete') );
+
+ $(document).ready(
+ function () {
+ $('a.delete-item-link').click(
+ function ($e) {
+ var $item_prefix = $(this).attr('item_prefix'),
+ $confirm_msg = {
+ 'rev$': '<inp2:m_Phrase name="lu_AssociatedReviewRemovalConfirmation" js_escape="1"/>'
+ };
+
+ for (var $regex in $confirm_msg) {
+ var $regexp = new RegExp($regex);
+
+ if ( $regexp.test($item_prefix) ) {
+ return confirm( $confirm_msg[$regexp] );
+ }
+ }
+
+ return false;
+ }
+ );
+ }
+ );
+</script>
+<inp2:m_include t="incs/footer"/>
\ No newline at end of file
Index: kernel/utility/formatters/date_formatter.php
===================================================================
--- kernel/utility/formatters/date_formatter.php (revision 14653)
+++ kernel/utility/formatters/date_formatter.php (working copy)
@@ -266,7 +266,7 @@
return adodb_gmdate($options['format'], $value);
}
- $format = $options['format'];
+ $format = defined($options['format']) ? constant($options['format']) : $options['format'];
$dt_separator = getArrayValue($options, 'date_time_separator');
if ($dt_separator) {
Index: units/spam_reports/spam_report_eh.php
===================================================================
--- units/spam_reports/spam_report_eh.php (revision 0)
+++ units/spam_reports/spam_report_eh.php (revision 0)
@@ -0,0 +1,126 @@
+<?php
+
+class SpamReportEventHandler extends kDBEventHandler {
+
+ /**
+ * Allows to override standard permission mapping
+ *
+ */
+ function mapPermissions()
+ {
+ parent::mapPermissions();
+
+ $permissions = Array (
+ 'OnNewReport' => Array ('self' => true),
+ 'OnDeleteAssocItem' => Array ('self' => 'delete'),
+ );
+
+ $this->permMapping = array_merge($this->permMapping, $permissions);
+ }
+
+ /**
+ * Checks permissions
+ *
+ * @param kEvent $event
+ */
+ function CheckPermission(&$event)
+ {
+ if ( $event->Name == 'OnNewReport' ) {
+ $perm_helper =& $this->Application->recallObject('PermissionsHelper');
+ /* @var $perm_helper kPermissionsHelper */
+
+ return $perm_helper->finalizePermissionCheck($event, $this->Application->LoggedIn());
+ }
+
+ return parent::CheckPermission($event);
+ }
+
+ /**
+ * Prefills missing fields
+ *
+ * @param kEvent $event
+ */
+ function OnBeforeItemCreate(&$event)
+ {
+ parent::OnBeforeItemCreate($event);
+
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
+ $item_prefix = $this->Application->GetVar('item_prefix');
+ $item_id = $this->Application->GetVar($item_prefix . '_id');
+
+ if ( $item_id ) {
+ $object->SetDBField('ItemPrefix', $item_prefix);
+ $object->SetDBField('ItemId', $item_id);
+ }
+
+ $object->SetDBField('ReportedById', $this->Application->RecallVar('user_id'));
+ }
+
+ /**
+ * Send e-mail after new spam report was created
+ *
+ * @param kEvent $event
+ */
+ function OnAfterItemCreate(&$event)
+ {
+ parent::OnAfterItemCreate($event);
+
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
+ $item_prefix = $object->GetDBField('ItemPrefix');
+
+ if ( preg_match('/rev$/', $item_prefix) ) {
+ $item =& $this->Application->recallObject($item_prefix);
+ /* @var $item kDBItem */
+
+ $object->SetDBField('ItemName', $item->GetDBField('ReviewText'));
+ }
+
+ $this->Application->EmailEventAdmin('SPAM.REPORT');
+ }
+
+ /**
+ * Sends new spam report
+ *
+ * @param kEvent $event
+ */
+ function OnNewReport(&$event)
+ {
+ $ajax_form_helper =& $this->Application->recallObject('AjaxFormHelper');
+ /* @var $ajax_form_helper AjaxFormHelper */
+
+ $ajax_form_helper->transitEvent($event, 'OnCreate');
+ }
+
+ /**
+ * Deletes item, associated with given spam report
+ *
+ * @param kEvent $event
+ */
+ function OnDeleteAssocItem(&$event)
+ {
+ $temp_handlers = Array ();
+ $ids = $this->StoreSelectedIDs($event);
+
+ $object =& $event->getObject( Array ('skip_autoload' => true) );
+ /* @var $object kDBItem */
+
+ foreach ($ids as $id) {
+ $object->Load($id);
+ $item_prefix = $object->GetDBField('ItemPrefix');
+
+ if ( !isset($temp_handlers[$item_prefix]) ) {
+ $temp_handlers[$item_prefix] =& $this->Application->recallObject($item_prefix . '_TempHandler', 'kTempTablesHandler');
+ }
+
+ $temp_handlers[$item_prefix]->DeleteItems($item_prefix, '', Array ($object->GetDBField('ItemId')));
+ }
+
+ $this->clearSelectedIDs($event);
+
+ $event->SetRedirectParam('opener', 'u');
+ }
+}
\ No newline at end of file
Index: units/spam_reports/spam_report_tp.php
===================================================================
--- units/spam_reports/spam_report_tp.php (revision 0)
+++ units/spam_reports/spam_report_tp.php (revision 0)
@@ -0,0 +1,74 @@
+<?php
+
+class SpamReportTagProcessor extends kDBTagProcessor {
+
+ /**
+ * Returns a link for editing ad/user
+ *
+ * @param Array $params
+ * @return string
+ */
+ function ItemEditLink($params)
+ {
+ $object =& $this->getObject();
+ /* @var $object kDBList */
+
+ $prefix = $object->GetDBField('ItemPrefix');
+
+ $url_params = Array (
+ 'm_opener' => 'd',
+ $prefix.'_mode' => 't',
+ $prefix.'_event' => 'OnEdit',
+ $prefix.'_id' => $object->GetDBField('ItemId'),
+ 'pass' => 'all,'.$prefix,
+ );
+
+ if ( $this->IsReviewReport($params) ) {
+ $edit_template = 'reviews/review_direct_edit';
+ $url_params['pass_through'] = 'item_prefix';
+ $url_params['item_prefix'] = $prefix;
+ }
+ else {
+ $edit_template = '';
+ }
+
+ return $this->Application->HREF($edit_template,'', $url_params);
+ }
+
+ /**
+ * Builds a link, to delete item, associated with this spam report
+ *
+ * @param Array $params
+ * @return string
+ */
+ function AssocItemDeleteLink($params)
+ {
+ $object =& $this->getObject();
+ /* @var $object kDBList */
+
+ $prefix = $this->getPrefixSpecial();
+
+ $url_params = Array (
+ $prefix . '_event' => 'OnDeleteAssocItem',
+ $prefix . '_id' => $object->GetID(),
+ 'pass' => 'm,'.$prefix,
+ );
+
+ return $this->Application->HREF('','', $url_params);
+ }
+
+ /**
+ * Checks, that it's review report
+ *
+ * @param Array $params
+ * @return string
+ * @access protected
+ */
+ protected function IsReviewReport($params)
+ {
+ $object =& $this->getObject($params);
+ /* @var $object kDBItem */
+
+ return preg_match('/rev$/', $object->GetDBField('ItemPrefix'));
+ }
+}
\ No newline at end of file
Index: units/spam_reports/spam_reports_config.php
===================================================================
--- units/spam_reports/spam_reports_config.php (revision 0)
+++ units/spam_reports/spam_reports_config.php (revision 0)
@@ -0,0 +1,110 @@
+<?php
+defined('FULL_PATH') or die('restricted access!');
+
+$config = Array (
+ 'Prefix' => 'spam-report',
+ 'ItemClass' => Array ('class' => 'kDBItem', 'file' => '', 'build_event' => 'OnItemBuild'),
+ 'ListClass' => Array ('class' => 'kDBList', 'file' => '', 'build_event' => 'OnListBuild'),
+ 'EventHandlerClass' => Array ('class' => 'SpamReportEventHandler', 'file' => 'spam_report_eh.php', 'build_event' => 'OnBuild'),
+ 'TagProcessorClass' => Array ('class' => 'SpamReportTagProcessor', 'file' => 'spam_report_tp.php', 'build_event' => 'OnBuild'),
+
+ 'AutoLoad' => true,
+
+ 'QueryString' => Array (
+ 1 => 'id',
+ 2 => 'Page',
+ 3 => 'PerPage',
+ 4 => 'event',
+ 5 => 'mode',
+ ),
+
+ 'IDField' => 'ReportId',
+
+ 'TableName' => TABLE_PREFIX . 'SpamReports',
+
+ 'TitleField' => 'MessageText',
+
+ 'TitlePresets' => Array (
+ 'default' => Array (
+ 'edit_status_labels' => Array ('spam-report' => '!la_title_EditingSpamReport!'),
+ ),
+
+ 'spam_report_list' => Array (
+ 'prefixes' => Array ('spam-report_List'), 'format' => "!la_title_SpamReports!",
+ ),
+
+ 'spam_report_edit' => Array (
+ 'prefixes' => Array ('spam-report'), 'format' => "#spam-report_status# '#spam-report_titlefield#'",
+ ),
+ ),
+
+ 'PermSection' => Array('main' => 'in-portal:spam_reports'),
+
+ 'Sections' => Array (
+ 'in-portal:spam_reports' => Array (
+ 'parent' => 'in-portal:reports',
+ 'icon' => 'conf_spam_reports',
+ 'label' => 'la_title_SpamReports',
+ 'url' => Array('t' => 'spam_reports/spam_report_list', 'pass' => 'm'),
+ 'permissions' => Array('view', 'edit', 'delete'),
+ 'priority' => 8,
+ 'type' => stTREE,
+ ),
+ ),
+
+ 'ListSQLs' => Array (
+ '' => ' SELECT %1$s.* %2$s
+ FROM %1$s
+ LEFT JOIN ' . TABLE_PREFIX . 'PortalUser reported_by ON reported_by.PortalUserId = %1$s.ReportedById
+ LEFT JOIN ' . TABLE_PREFIX . 'ItemReview review ON review.ReviewId = %1$s.ItemId AND %1$s.ItemPrefix LIKE "%rev"',
+ ),
+
+ 'CalculatedFields' => Array (
+ '' => Array (
+ 'ItemName' => 'IF(%1$s.ItemPrefix LIKE "%rev", review.ReviewText, "")',
+ 'ReportedBy' => 'reported_by.Login',
+ ),
+ ),
+
+ 'ListSortings' => Array (
+ '' => Array (
+ 'Sorting' => Array ('ReportId' => 'desc'),
+ )
+ ),
+
+ 'Fields' => Array (
+ 'ReportId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
+ 'ItemPrefix' => Array (
+ 'type' => 'string', 'max_len' => 255,
+ 'formatter' => 'kOptionsFormatter', 'options' => Array ('p-rev' => 'la_opt_ProductReview'), 'use_phrases' => 1,
+ 'not_null' => 1, 'default' => ''
+ ),
+ 'ItemId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
+ 'MessageText' => Array ('type' => 'string', 'required' => 1, 'default' => NULL),
+ 'ReportedOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => '#NOW#'),
+ 'ReportedById' => Array (
+ 'type' => 'int',
+ 'formatter' => 'kLEFTFormatter', 'options' => Array (USER_ROOT => 'root', USER_GUEST => 'Guest'), 'left_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'PortalUser WHERE `%s` = \'%s\'', 'left_key_field' => 'PortalUserId', 'left_title_field' => 'Login', 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'sample_value' => 'Guest',
+ 'default' => NULL
+ )
+ ),
+
+ 'VirtualFields' => Array (
+ 'ItemName' => Array ('type' => 'string', 'default' => ''),
+ 'ReportedBy' => Array ('type' => 'string', 'default' => ''),
+ ),
+
+ 'Grids' => Array (
+ 'Default' => Array (
+ 'Fields' => Array (
+ 'ReportId' => Array ('title' => 'column:la_fld_Id', 'filter_block' => 'grid_range_filter'),
+ 'ItemPrefix' => Array ('data_block' => 'grid_item_prefix_td', 'filter_block' => 'grid_options_filter', 'width' => 150),
+ 'ItemId' => Array ('filter_block' => 'grid_range_filter'),
+ 'ItemName' => Array ('data_block' => 'grid_edit_item_td', 'filter_block' => 'grid_like_filter'),
+ 'MessageText' => Array ('filter_block' => 'grid_like_filter'),
+ 'ReportedOn' => Array ('filter_block' => 'grid_date_range_filter'),
+ 'ReportedBy' => Array ('filter_block' => 'grid_like_filter'),
+ ),
+ ),
+ ),
+);
\ No newline at end of file