20 define(
"TITLE_COPYRIGHT_LIST", _(
"List Files for Copyright/Email/URL"));
36 $this->Name =
"copyright-list";
37 $this->Title = TITLE_COPYRIGHT_LIST;
38 $this->Version =
"1.0";
39 $this->Dependency = array(
"copyright-hist",
"ecc-hist",
"ipra-hist");
44 parent::__construct();
46 $this->
dbManager = $container->get(
'db.manager');
47 $this->uploadDao = $container->get(
'dao.upload');
56 if ($this->
State != PLUGIN_STATE_READY) {
67 $URL = $this->Name .
"&agent=$agent_pk&item=$uploadtree_pk&hash=$hash&type=$type&page=-1";
69 $URL .=
"&excl=$Excl";
71 $text = _(
"Show All Files");
72 menu_insert($this->Name.
"::Show All",0, $URL, $text);
87 function GetRows($Uploadtree_pk, $Agent_pk, &$upload_pk, $hash, $type, $tableName, $filter=
"")
90 $row = $this->uploadDao->getUploadEntry($Uploadtree_pk);
93 $upload_pk = $row[
"upload_fk"];
96 if ($type ==
"copyFindings") {
97 $sql =
"SELECT textfinding AS content, '$type' AS type, uploadtree_pk, ufile_name, PF, hash
99 (SELECT uploadtree_pk, pfile_fk AS PF, ufile_name FROM uploadtree
101 AND uploadtree.lft BETWEEN $2 AND $3) AS SS
102 WHERE PF=pfile_fk AND hash=$4 ORDER BY uploadtree_pk";
104 $upload_pk, $lft, $rgt, $hash
107 $eventTable = $tableName .
"_event";
108 $eventFk = $tableName .
"_fk";
109 $tablePk = $tableName .
"_pk";
111 if (!empty($filter)) {
112 if ($filter ==
"active") {
113 $active_filter =
"AND (ce.is_enabled IS NULL OR ce.is_enabled = 'true')";
114 } elseif ($filter =
"inactive") {
115 $active_filter =
"AND ce.is_enabled = 'false'";
120 (CASE WHEN (ce.content IS NULL OR ce.content = '') THEN cp.content ELSE ce.content END) AS content,
121 (CASE WHEN (ce.hash IS NULL OR ce.hash = '') THEN cp.hash ELSE ce.hash END) AS hash,
122 type, uploadtree_pk, ufile_name, cp.pfile_fk AS PF
123 FROM $tableName AS cp
124 INNER JOIN uploadtree UT ON cp.pfile_fk = ut.pfile_fk
126 AND ut.lft BETWEEN $2 AND $3
127 LEFT JOIN $eventTable AS ce ON ce.$eventFk = cp.$tablePk
128 AND ce.upload_fk = ut.upload_fk AND ce.uploadtree_fk = ut.uploadtree_pk
129 WHERE agent_fk = ANY($4::int[]) AND (cp.hash=$5 OR ce.hash=$5) AND type=$6
131 ORDER BY uploadtree_pk";
133 $upload_pk, $lft, $rgt,
"{". $Agent_pk .
"}", $hash, $type
136 $statement = __METHOD__.$tableName;
137 $this->
dbManager->prepare($statement, $sql);
138 $result = $this->
dbManager->execute($statement,$params);
140 $rows = $this->
dbManager->fetchAll($result);
158 $NumRows = count($rows);
160 $ExclArray = explode(
":", $excl);
163 if (!empty($filter) && ($filter ==
"nolic")) {
164 $NoLicStr =
"No_license_found";
165 $VoidLicStr =
"Void";
168 $sql =
"select rf_pk from license_ref where rf_shortname IN ($1, $2)";
169 $statement = __METHOD__.
"NoLicenseFoundORVoid";
170 $this->
dbManager->prepare($statement, $sql);
171 $result = $this->
dbManager->execute($statement,array(
"$NoLicStr",
"$VoidLicStr"));
172 $rf_rows = $this->
dbManager->fetchAll($result);
173 if (!empty($rf_rows)) {
174 foreach ($rf_rows as $row) {
175 if (!empty($rf_clause)) {
176 $rf_clause .=
" or ";
178 $rf_clause .=
" rf_fk=$row[rf_pk]";
184 for ($RowIdx = 0; $RowIdx < $NumRows; $RowIdx++) {
185 $row = $rows[$RowIdx];
187 if ($row[
'hash'] != $hash) {
188 unset($rows[$RowIdx]);
192 $FileExt =
GetFileExt($rows[$RowIdx][
'ufile_name']);
193 if (in_array($FileExt, $ExclArray)) {
194 unset($rows[$RowIdx]);
200 if (($filter ==
"nolic") && ($rf_clause)) {
202 $sql =
"select rf_fk from license_file where ($rf_clause) and pfile_fk=$1";
203 $statement = __METHOD__.
"CheckForNoLicenseFound";
204 $this->
dbManager->prepare($statement, $sql);
205 $result = $this->
dbManager->execute($statement,array(
"{$row['pf']}"));
206 $FoundRows = $this->
dbManager->fetchAll($result);
207 if (empty($FoundRows)) {
208 unset($rows[$RowIdx]);
216 foreach ($rows as $row) {
222 $NumRows = count($rows2);
224 for ($RowIdx = 0; $RowIdx < $NumRows; $RowIdx++) {
230 if ($rows2[$RowIdx-1][
'uploadtree_pk'] == $rows2[$RowIdx][
'uploadtree_pk']) {
231 unset($rows2[$RowIdx-1]);
237 usort($rows2,
'copyright_namecmp');
249 if ($this->
State != PLUGIN_STATE_READY) {
253 return parent::OutputOpen();
262 if ($this->
State != PLUGIN_STATE_READY) {
267 $Time = microtime(
true);
277 if (empty($uploadtree_pk) || empty($hash) || empty($type) || empty($agent_pk)) {
278 $this->vars[
'pageContent'] = $this->Name . _(
" is missing required parameters");
283 $Row = $this->uploadDao->getUploadEntry($uploadtree_pk);
284 if (!$this->uploadDao->isAccessible($Row[
'upload_fk'], Auth::getGroupId())) {
285 $this->vars[
'pageContent'] =
"<h2>" . _(
"Permission Denied") .
"</h2>";
290 if (empty($Page) || $Page == -1) {
294 list($tableName,$modBack,$viewName) = $this->
getTableName($type);
298 $allRows = $this->
GetRows($uploadtree_pk, $agent_pk, $upload_pk, $hash, $type, $tableName, $filter);
299 $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($upload_pk);
303 $rows = $this->
GetRequestedRows($allRows, $excl, $NumInstances, $filter, $hash);
308 $RowCount = count($rows);
311 $Content = htmlentities($rows[0][
'content']);
312 $Offset = ($Page < 0) ? 0 : $Page*$Max;
315 $text1 = _(
"unique");
316 $text3 = _(
"copyright");
321 case "scancode_statement":
325 case "scancode_email":
334 $TypeStr = _(
"Patent Relavent Analysis");
337 $TypeStr = _(
"Export Restriction");
340 $TypeStr = _(
"Keyword Analysis");
343 $TypeStr = _(
"User Findings");
345 $OutBuf .=
"$NumInstances $TypeStr instances found in $RowCount $text";
347 $OutBuf .=
": <b>$Content</b>";
349 $text = _(
"Display excludes files with these extensions");
351 $OutBuf .=
"<br>$text: $excl";
355 if (($RowCount >= $Max) && ($Page >= 0)) {
356 $PagingMenu =
"<P />\n" .
MenuPage($Page, intval($RowCount / $Max)) .
"<P />\n";
357 $OutBuf .= $PagingMenu;
363 $LinkLast =
"$viewName&agent=$agent_pk";
367 $baseURL =
"?mod=" . $this->Name .
"&agent=$agent_pk&item=$uploadtree_pk&hash=$hash&type=$type&page=-1";
371 foreach ($rows as $row) {
373 if ($RowNum < $Offset) {
376 if ($RowNum > $Offset + $Max) {
383 $URL = $baseURL .
"&excl=$FileExt";
385 $URL = $baseURL .
"&excl=$excl:$FileExt";
388 $text = _(
"Exclude this file type");
389 $Header =
"<a href=$URL>$text.</a>";
393 $ExclArray = explode(
":", $excl);
394 if (in_array($FileExt, $ExclArray)) {
400 $OutBuf .=
Dir2Browse($modBack, $row[
'uploadtree_pk'], $LinkLast,
401 $ShowBox, $ShowMicro, $RowNum, $Header,
'', $uploadtree_tablename);
405 $OutBuf .= _(
"No files found");
408 if (!empty($PagingMenu)) {
409 $OutBuf .= $PagingMenu .
"\n";
412 $Time = microtime(
true) - $Time;
413 $text = _(
"Elapsed time");
414 $text1 = _(
"seconds");
415 $OutBuf .= sprintf(
"<small>$text: %.2f $text1</small>\n", $Time);
417 $this->vars[
'pageContent'] = $OutBuf;
427 return 'copyrightlist.html.twig';
441 $modBack =
"ipra-hist";
442 $viewName =
"ipra-view";
446 $modBack =
"ecc-hist";
447 $viewName =
"ecc-view";
450 $tableName =
"keyword";
451 $modBack =
"keyword-hist";
452 $viewName =
"keyword-view";
455 $tableName =
"copyright";
456 $modBack =
"copyright-hist";
457 $viewName =
"copyright-view";
459 case "scancode_statement" :
460 $tableName =
"scancode_copyright";
461 $modBack =
"copyright-hist";
462 $viewName =
"copyright-view";
464 case "copyFindings" :
465 $tableName =
"copyright_decision";
466 $modBack =
"copyright-hist";
467 $viewName =
"copyright-view";
470 $tableName =
"author";
471 $modBack =
"email-hist";
472 $viewName =
"copyright-view";
474 return array($tableName, $modBack,$viewName);
479 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
Contains the constants and helpers for authentication of user.
OutputOpen()
This function is called when user output is requested. This function is responsible for assigning hea...
getTableName($type)
Get the table name, mod, and view based on type.
__construct()
base constructor. Most plugins will just use this
GetRows($Uploadtree_pk, $Agent_pk, &$upload_pk, $hash, $type, $tableName, $filter="")
Get statement rows for a specified set.
GetRequestedRows($rows, $excl, &$NumRows, $filter, $hash)
Remove unwanted rows by hash and type and exclusions and filter.
Output()
This function is called when user output is requested. This function is responsible for content....
RegisterMenus()
While menus can be added to any time at or after the PostInitialize phase, this is the standard locat...
Dir2Browse($Mod, $UploadtreePk, $LinkLast=NULL, $ShowBox=1, $ShowMicro=NULL, $Enumerate=-1, $PreText='', $PostText='', $uploadtree_tablename="uploadtree")
Get an html linked string of a file browse path.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
GetFileExt($fname)
Get File Extension (text after last period)
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
fo_dbManager * dbManager
fo_dbManager object