29 define(
"TITLE_COPYRIGHTHISTOGRAMPROCESSPOST", _(
"Private: Browse post"));
44 private $uploadtree_tablename;
56 private $copyrightDao;
61 private $dataTablesUtility;
68 function __construct()
70 $this->Name =
"ajax-copyright-hist";
71 $this->Title = TITLE_COPYRIGHTHISTOGRAMPROCESSPOST;
73 $this->OutputType =
'JSON';
77 parent::__construct();
79 $this->dataTablesUtility = $container->get(
'utils.data_tables_utility');
80 $this->uploadDao = $container->get(
'dao.upload');
81 $this->
dbManager = $container->get(
'db.manager');
82 $this->copyrightDao = $container->get(
'dao.copyright');
93 if ($this->
State != PLUGIN_STATE_READY) {
101 if ($action==
"deletedecision" || $action==
"undodecision") {
104 }
else if ($action==
"deleteHashDecision" || $action==
"undoHashDecision") {
106 }
else if($action==
"update" || $action==
"delete" || $action==
"undo") {
108 $getEachID = array_filter(explode(
",",
trim($id,
',')),
function($var) {
111 if(count($getEachID) == 4) {
112 list($upload, $item, $hash, $type) = $getEachID;
114 return new Response(
'bad request while '.$action,
115 Response::HTTP_BAD_REQUEST,
116 array(
'Content-type'=>
'text/plain')
122 if (!(($action ==
"getData" || $action ==
"getDeactivatedData") &&
123 ($this->uploadDao->isAccessible($upload, Auth::getGroupId())) ||
124 ($this->uploadDao->isEditable($upload, Auth::getGroupId())))) {
125 $permDeniedText = _(
"Permission Denied");
126 $returnValue =
"<h2>$permDeniedText</h2>";
131 if (in_array($type, $this->textFindingTypes) &&
132 ($action ==
"getData" || $action ==
"getDeactivatedData")) {
134 if ($action ==
"getData") {
135 $returnValue = $textFindingsHandler->doGetData($type, $upload);
136 } elseif ($action ==
"getDeactivatedData") {
137 $returnValue = $textFindingsHandler->doGetData($type, $upload,
false);
142 $returnValue = $this->
doGetData($upload);
144 case "getDeactivatedData":
145 $returnValue = $this->
doGetData($upload,
false);
148 $returnValue = $this->
doUpdate($item, $hash, $type);
151 $returnValue = $this->
doDelete($item, $hash, $type);
154 $returnValue = $this->
doUndo($item, $hash, $type);
156 case "deletedecision":
162 case "deleteHashDecision":
165 case "undoHashDecision":
169 $returnValue =
"<h2>" . _(
"Unknown action") .
"</h2>";
184 protected function doGetData($upload, $activated =
true)
192 header(
'Content-type: text/json');
193 list($aaData, $iTotalRecords, $iTotalDisplayRecords) = $this->
getTableData($upload, $item, $agent_pk, $type,
$listPage, $filter, $activated);
194 return new JsonResponse(array(
195 'sEcho' => intval($_GET[
'sEcho']),
197 'iTotalRecords' => $iTotalRecords,
198 'iTotalDisplayRecords' => $iTotalDisplayRecords
220 $rw = $this->uploadDao->isEditable($upload, Auth::getGroupId());
221 foreach ($rows as $row)
223 $aaData [] = $this->
fillTableRow($row, $item, $upload, $agent_pk, $type,
$listPage, $filter, $activated, $rw);
227 return array($aaData, $iTotalRecords, $iTotalDisplayRecords);
242 protected function getCopyrights($upload_pk, $item, $uploadTreeTableName, $agentId, $type, $filter, $activated =
true)
250 list($left, $right) = $this->uploadDao->getLeftAndRight($item, $uploadTreeTableName);
258 if (
'uploadtree_a' == $uploadTreeTableName)
260 $sql_upload =
" AND UT.upload_fk=$upload_pk ";
265 if ($type ==
'statement' && $filter ==
"nolic")
267 $noLicStr =
"No_license_found";
268 $voidLicStr =
"Void";
269 $join =
" INNER JOIN license_file AS LF on cp.pfile_fk=LF.pfile_fk ";
270 $filterQuery =
" AND LF.rf_fk IN (SELECT rf_pk FROM license_ref WHERE rf_shortname IN ('$noLicStr','$voidLicStr')) ";
275 $params = array($left, $right, $type, $agentId);
277 $filterParms = $params;
279 $unorderedQuery =
"FROM $tableName AS cp " .
280 "INNER JOIN $uploadTreeTableName AS UT ON cp.pfile_fk = UT.pfile_fk " .
282 "WHERE cp.content!='' " .
283 "AND ( UT.lft BETWEEN $1 AND $2 ) " .
284 "AND cp.type = $3 " .
285 "AND cp.agent_fk= $4 " .
286 "AND cp.is_enabled=" . ($activated ?
'true' :
'false') .
288 $totalFilter = $filterQuery .
" " . $searchFilter;
290 $grouping =
" GROUP BY content ";
292 $countQuery =
"SELECT count(*) FROM (SELECT content, count(*) $unorderedQuery $totalFilter $grouping) as K";
293 $iTotalDisplayRecordsRow = $this->
dbManager->getSingleRow($countQuery,
294 $filterParms, __METHOD__.$tableName .
".count" . ($activated ?
'' :
'_deactivated'));
295 $iTotalDisplayRecords = $iTotalDisplayRecordsRow[
'count'];
297 $countAllQuery =
"SELECT count(*) FROM (SELECT content, count(*) $unorderedQuery$grouping) as K";
298 $iTotalRecordsRow = $this->
dbManager->getSingleRow($countAllQuery, $params, __METHOD__,$tableName .
"count.all" . ($activated ?
'' :
'_deactivated'));
299 $iTotalRecords = $iTotalRecordsRow[
'count'];
302 $filterParms[] = $offset;
303 $range .=
' OFFSET $' . count($filterParms);
304 $filterParms[] = $limit;
305 $range .=
' LIMIT $' . count($filterParms);
307 $sql =
"SELECT content, hash, count(*) as copyright_count " .
308 $unorderedQuery . $totalFilter .
" GROUP BY content, hash " . $orderString . $range;
309 $statement = __METHOD__ . $filter.$tableName . $uploadTreeTableName . ($activated ?
'' :
'_deactivated');
310 $this->
dbManager->prepare($statement, $sql);
311 $result = $this->
dbManager->execute($statement, $filterParms);
312 $rows = $this->
dbManager->fetchAll($result);
315 return array($rows, $iTotalDisplayRecords, $iTotalRecords);
334 $tableName =
"keyword";
338 $tableName =
"copyright";
341 $tableName =
"author";
352 $columnNamesInDatabase = array(
'copyright_count',
'content');
356 $orderString = $this->dataTablesUtility->getSortingString($_GET, $columnNamesInDatabase, $defaultOrder);
369 if (empty($searchPattern))
373 $filterParams[] =
"%$searchPattern%";
374 return ' AND CP.content ilike $'.count($filterParams).
' ';
387 private function getTableRowAction($hash, $uploadTreeId, $upload, $type, $activated =
true, $rw =
true)
394 $act .=
" hidden='true'";
396 $act .=
" id='delete$type$hash' onClick='delete$type($upload,$uploadTreeId,\"$hash\",\"$type\");' class=\"delete\" src=\"images/space_16.png\">";
399 $act .=
" hidden='true'";
401 $act .=
" id='update$type$hash'>deactivated [<a href=\"#\" id='undo$type$hash' onClick='undo$type($upload,$uploadTreeId,\"$hash\",\"$type\");return false;'>Undo</a>]</span>";
405 return "deactivated";
423 private function fillTableRow($row, $uploadTreeId, $upload, $agentId, $type,
$listPage, $filter =
"", $activated =
true, $rw =
true)
425 $hash = $row[
'hash'];
426 $output = array(
'DT_RowId' =>
"$upload,$uploadTreeId,$hash,$type" );
430 $urlArgs =
"?mod=".$listPage.
"&agent=$agentId&item=$uploadTreeId&hash=$hash&type=$type";
431 if (!empty($filter)) {
432 $urlArgs .=
"&filter=$filter";
434 $link .= $urlArgs .
"'>" . $row[
'copyright_count'] .
"</a>";
435 $output[
'0'] = $link;
437 $output[
'2'] = $this->
getTableRowAction($hash, $uploadTreeId, $upload, $type, $activated, $rw);
438 if($rw && $activated)
440 $output[
'3'] =
"<input type='checkbox' class='deleteBySelect$type' id='deleteBySelect$type$hash' value='".$upload.
",".$uploadTreeId.
",".$hash.
",".$type.
"'>";
461 return new Response(
'empty content not allowed', Response::HTTP_BAD_REQUEST ,array(
'Content-type'=>
'text/plain'));
466 $this->copyrightDao->updateTable($item, $hash, $content, Auth::getUserId(), $cpTable);
468 return new Response(
'success', Response::HTTP_OK,array(
'Content-type'=>
'text/plain'));
482 $this->copyrightDao->updateTable($item, $hash,
'', Auth::getUserId(), $cpTable,
'delete');
483 return new Response(
'Successfully deleted', Response::HTTP_OK, array(
'Content-type'=>
'text/plain'));
493 protected function doUndo($itemId, $hash, $type) {
496 $this->copyrightDao->updateTable($item, $hash,
'', Auth::getUserId(), $cpTable,
'rollback');
497 return new Response(
'Successfully restored', Response::HTTP_OK, array(
'Content-type'=>
'text/plain'));
508 $this->copyrightDao->removeDecision($type.
"_decision", $pfileId, $decisionId);
509 return new JsonResponse(array(
"msg" => $decisionId .
" .. " . $pfileId .
" .. " . $type));
520 $this->copyrightDao->undoDecision($type.
"_decision", $pfileId, $decisionId);
521 return new JsonResponse(array(
"msg" => $decisionId .
" .. " . $pfileId .
" .. " . $type));
533 $tableName = $type.
"_decision";
534 $decisions = $this->copyrightDao->getDecisionsFromHash($tableName, $hash,
536 foreach ($decisions as $decision) {
537 $this->copyrightDao->removeDecision($tableName, $decision[
'pfile_fk'],
538 $decision[$tableName .
'_pk']);
540 return new JsonResponse(array(
"msg" =>
"$hash .. $upload .. $type"));
552 $tableName = $type.
"_decision";
553 $decisions = $this->copyrightDao->getDecisionsFromHash($tableName, $hash,
555 foreach ($decisions as $decision) {
556 $this->copyrightDao->undoDecision($tableName, $decision[
'pfile_fk'],
557 $decision[$tableName .
'_pk']);
559 return new JsonResponse(array(
"msg" =>
"$hash .. $upload .. $type"));
564 $NewPlugin->Initialize();
Handles Ajax requests for copyright.
getTableName($type)
Get table name based on statement type.
Traceback_uri()
Get the URI without query to this location.
doGetData($upload, $activated=true)
Handles GET request and create a JSON response.
doUndoHashDecision($hash, $upload, $type)
Rollback decisions for an upload which matches a hash.
doDelete($itemId, $hash, $type)
Disable a result.
addSearchFilter(&$filterParams)
Add filter on content.
doUndo($itemId, $hash, $type)
Rollback a result.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
Handles Ajax requests for text findings.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
getOrderString()
Create sorting string for database query.
getTableData($upload, $item, $agent_pk, $type, $listPage, $filter, $activated=true)
Get the copyright data and fill in expected format.
doDeleteHashDecision($hash, $upload, $type)
Disable decisions for an upload which matches a hash.
char * uploadtree_tablename
upload.uploadtree_tablename
doUndoDecision($decisionId, $pfileId, $type)
Rollback a decision.
fo_dbManager * dbManager
fo_dbManager object
This is the Plugin class. All plugins should:
getCopyrights($upload_pk, $item, $uploadTreeTableName, $agentId, $type, $filter, $activated=true)
Get results from database and format for JSON.
fillTableRow($row, $uploadTreeId, $upload, $agentId, $type, $listPage, $filter="", $activated=true, $rw=true)
Fill table content for JSON response.
doUpdate($itemId, $hash, $type)
Update result.
Output()
Display the loaded menu and plugins.
if(!defined('ENT_SUBSTITUTE')) convertToUTF8($content, $toHTML=true)
returnSortOrder()
Get sorting orders.
char * trim(char *ptext)
Trimming whitespace.
getTableRowAction($hash, $uploadTreeId, $upload, $type, $activated=true, $rw=true)
Helper to create action column for results.
doDeleteDecision($decisionId, $pfileId, $type)
Disable a decision.