21 define(
"TITLE_LICENSE_LIST_FILES", _(
"List Files for License"));
38 protected $agentNames = AgentRef::AGENT_LIST;
42 $this->Name =
"license_list_files";
43 $this->Title = TITLE_LICENSE_LIST_FILES;
44 $this->Dependency = array(
"browse",
"view");
47 parent::__construct();
48 $this->
dbManager = $GLOBALS[
'container']->get(
'db.manager');
49 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
50 $this->licenseDao = $GLOBALS[
'container']->get(
'dao.license');
51 $this->agentDao = $GLOBALS[
'container']->get(
'dao.agent');
59 if ($this->
State != PLUGIN_STATE_READY) {
67 $URL = $this->Name .
"&item=$uploadtree_pk&lic=".urlencode($rf_shortname).
"&page=-1";
69 $URL .=
"&excl=$Excl";
71 $text = _(
"Show All Files");
72 menu_insert($this->Name .
"::Show All", 0, $URL, $text);
85 if (empty($uploadtree_pk) || empty($rf_shortname)) {
86 $text = _(
"is missing required parameters.");
87 return $this->Name .
" $text";
97 $UploadtreeRec =
GetSingleRec(
"uploadtree",
"where uploadtree_pk=$uploadtree_pk");
98 $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($UploadtreeRec[
'upload_fk']);
104 $Offset = ($Page < 0) ? 0 : $Page * $Max;
110 if (empty($agentId)) {
111 $scannerAgents = array_keys($this->agentNames);
112 $scanJobProxy =
new ScanJobProxy($this->agentDao, $UploadtreeRec[
'upload_fk']);
113 $scannerVars = $scanJobProxy->createAgentStatus($scannerAgents);
114 $agentId = $scanJobProxy->getLatestSuccessfulAgentIds();
116 $CountArray = $this->
countFilesWithLicense($agentId, $rf_shortname, $uploadtree_pk, $tag_pk, $uploadtree_tablename);
118 if (empty($CountArray)) {
119 $V .= _(
"<b> No files found for license $rf_shortname !</b>\n");
121 $Count = $CountArray[
'count'];
122 $Unique = $CountArray[
'unique'];
124 $text = _(
"files found");
125 $text2 = _(
"with license");
126 $text3 = _(
"files are unique with same file hash.");
127 $V .=
"Total $Count $text $text2 <b>$rf_shortname</b>, $Unique $text3";
131 $limit = ($Page < 0) ?
"ALL" : $Max;
132 $order =
" order by ufile_name asc";
135 $PkgsOnly, $Offset, $limit, $order, $tag_pk, $uploadtree_tablename);
136 $NumFiles = pg_num_rows($filesresult);
138 $file_result_temp = pg_fetch_all($filesresult);
139 $sorted_file_result = array();
140 $max_num = $NumFiles;
142 for ($i = 0; $i < $max_num; $i++) {
143 $row = $file_result_temp[$i];
147 $sorted_file_result[] = $row;
148 for ($j = $i + 1; $j < $max_num; $j ++) {
149 $row_next = $file_result_temp[$j];
150 if (! empty($row_next) && ($row[
'pfile_fk'] == $row_next[
'pfile_fk'])) {
151 $sorted_file_result[] = $row_next;
152 $file_result_temp[$j] =
null;
157 $text = _(
"Display");
158 $text1 = _(
"excludes");
159 $text2 = _(
"files with these extensions");
160 if (! empty($Excl)) {
161 $V .=
"<br>$text <b>$text1</b> $text2: $Excl";
164 $text2 = _(
"files with these licenses");
165 if (!empty($Exclic)) {
166 $V .=
"<br>$text <b>$text1</b> $text2: $Exclic";
170 if (($Max > 0) && ($Count >= $Max) && ($Page >= 0)) {
171 $VM =
"<P />\n" .
MenuEndlessPage($Page, intval((($Count + $Offset) / $Max))) .
"<P />\n";
179 $LinkLast =
"view-license";
184 $ushortname = rawurlencode($rf_shortname);
185 $baseURL =
"?mod=" . $this->Name .
"&item=$uploadtree_pk&lic=$ushortname&page=-1";
189 $ExclArray = explode(
":", $Excl);
190 $ExclicArray = explode(
":", $Exclic);
191 foreach ($sorted_file_result as $row) {
192 $pfile_pk = $row[
'pfile_fk'];
193 $licstring =
GetFileLicenses_string($row[
'agent_pk'], $pfile_pk, $row[
'uploadtree_pk'], $uploadtree_tablename);
194 $URLlicstring = urlencode($licstring);
200 $URL .=
"&excl=$Excl:$FileExt";
202 $URL .=
"&excl=$FileExt";
204 if (!empty($Exclic)) {
205 $URL .=
"&exclic=" . urlencode($Exclic);
207 $text = _(
"Exclude this file type.");
208 $Header =
"<a href=$URL>$text</a>";
212 if (!empty($Exclic)) {
213 $URL .=
"&exclic=" . urlencode($Exclic) .
":" . $URLlicstring;
215 $URL .=
"&exclic=$URLlicstring";
218 $URL .=
"&excl=$Excl";
221 $text = _(
"Exclude files with license");
222 $Header .=
"<br><a href=$URL>$text: $licstring.</a>";
224 $excludeByType = $Excl && in_array($FileExt, $ExclArray);
225 $excludeByLicense = $Exclic && in_array($licstring, $ExclicArray);
227 if (!empty($licstring) && !$excludeByType && !$excludeByLicense) {
230 $LinkLastpfile = $LinkLast .
"&pfile=$pfile_pk";
231 if ($LastPfilePk == $pfile_pk) {
232 $indent =
"<div style='margin-left:2em;'>";
239 $V .=
Dir2Browse(
"browse", $row[
'uploadtree_pk'], $LinkLastpfile,
240 $ShowBox, $ShowMicro, ++$RowNum, $Header,
'', $uploadtree_tablename);
243 $V .=
"<td> </td>";
244 $V .=
"<td>$row[agent_name]: $licstring</td></tr>";
245 $V .=
"<tr><td colspan=3><hr></td></tr>";
247 $LastPfilePk = $pfile_pk;
249 pg_free_result($filesresult);
272 $license = $this->licenseDao->getLicenseByShortname($rf_shortname);
273 if (
null == $license) {
276 $itemBounds = $this->uploadDao->getItemTreeBounds($uploadtree_pk, $uploadtree_tablename);
278 $viewRelavantFiles =
"SELECT pfile_fk as PF, uploadtree_pk, ufile_name FROM $uploadtree_tablename";
281 if (!empty($tag_pk)) {
283 $viewRelavantFiles .=
" INNER JOIN tag_file ON PF=tag_file.pfile_fk and tag_fk=$".count($params);
286 $params[] = $itemBounds->getLeft();
287 $params[] = $itemBounds->getRight();
288 $viewRelavantFiles .=
' WHERE lft BETWEEN $'.(count($params)-1).
' AND $'.count($params);
289 if ($uploadtree_tablename ==
"uploadtree_a" || $uploadtree_tablename ==
"uploadtree") {
290 $params[] = $itemBounds->getUploadId();
291 $viewRelavantFiles .=
" AND upload_fk=$".count($params);
295 $params[] = $license->getId();
296 $sql =
"SELECT count(license_file.pfile_fk) as count, count(distinct license_file.pfile_fk) as unique
297 FROM license_file, ($viewRelavantFiles) as SS
298 WHERE PF=license_file.pfile_fk AND rf_fk = $".count($params);
300 if (is_array($agent_pk)) {
301 $params[] =
'{' . implode(
',', $agent_pk) .
'}';
302 $sql .=
' AND agent_fk=ANY($'.count($params).
')';
304 } elseif (!empty($agent_pk)) {
305 $params[] = $agent_pk;
306 $sql .=
" AND agent_fk=$".count($params);
310 $RetArray = $this->
dbManager->getSingleRow($sql,$params,$stmt);
315 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
Output()
Display the loaded menu and plugins.
__construct()
base constructor. Most plugins will just use this
RegisterMenus()
Customize submenus.
countFilesWithLicense($agent_pk, $rf_shortname, $uploadtree_pk, $tag_pk, $uploadtree_tablename)
Cloned from commen-license-file.php to refactor it.
GetSingleRec($Table, $Where="")
Retrieve a single database record.
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.
GetFilesWithLicense($agent_pk, $rf_shortname, $uploadtree_pk, $PkgsOnly=false, $offset=0, $limit="ALL", $order="", $tag_pk=null, $uploadtree_tablename="uploadtree")
Get files with a given license (shortname).
GetFileLicenses_string($agent_pk, $pfile_pk, $uploadtree_pk, $uploadtree_tablename='uploadtree')
Same as GetFileLicenses() but returns license list as a single string.
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