32 define(
"TITLE_LICENSE_LIST_FILES", _(
"List Files for License"));
49 protected $agentNames = AgentRef::AGENT_LIST;
51 function __construct()
53 $this->Name =
"license_list_files";
54 $this->Title = TITLE_LICENSE_LIST_FILES;
55 $this->Dependency = array(
"browse",
"view");
58 parent::__construct();
59 $this->
dbManager = $GLOBALS[
'container']->get(
'db.manager');
60 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
61 $this->licenseDao = $GLOBALS[
'container']->get(
'dao.license');
62 $this->agentDao = $GLOBALS[
'container']->get(
'dao.agent');
70 if ($this->
State != PLUGIN_STATE_READY) {
78 $URL = $this->Name .
"&item=$uploadtree_pk&lic=".urlencode($rf_shortname).
"&page=-1";
80 $URL .=
"&excl=$Excl";
82 $text = _(
"Show All Files");
83 menu_insert($this->Name .
"::Show All", 0, $URL, $text);
96 if (empty($uploadtree_pk) || empty($rf_shortname)) {
97 $text = _(
"is missing required parameters.");
98 return $this->Name .
" $text";
108 $UploadtreeRec =
GetSingleRec(
"uploadtree",
"where uploadtree_pk=$uploadtree_pk");
109 $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($UploadtreeRec[
'upload_fk']);
115 $Offset = ($Page < 0) ? 0 : $Page * $Max;
121 if (empty($agentId)) {
122 $scannerAgents = array_keys($this->agentNames);
123 $scanJobProxy =
new ScanJobProxy($this->agentDao, $UploadtreeRec[
'upload_fk']);
124 $scannerVars = $scanJobProxy->createAgentStatus($scannerAgents);
125 $agentId = $scanJobProxy->getLatestSuccessfulAgentIds();
127 $CountArray = $this->
countFilesWithLicense($agentId, $rf_shortname, $uploadtree_pk, $tag_pk, $uploadtree_tablename);
129 if (empty($CountArray)) {
130 $V .= _(
"<b> No files found for license $rf_shortname !</b>\n");
132 $Count = $CountArray[
'count'];
133 $Unique = $CountArray[
'unique'];
135 $text = _(
"files found");
136 $text2 = _(
"with license");
137 $text3 = _(
"files are unique with same file hash.");
138 $V .=
"Total $Count $text $text2 <b>$rf_shortname</b>, $Unique $text3";
142 $limit = ($Page < 0) ?
"ALL" : $Max;
143 $order =
" order by ufile_name asc";
146 $PkgsOnly, $Offset, $limit, $order, $tag_pk, $uploadtree_tablename);
147 $NumFiles = pg_num_rows($filesresult);
149 $file_result_temp = pg_fetch_all($filesresult);
150 $sorted_file_result = array();
151 $max_num = $NumFiles;
153 for ($i = 0; $i < $max_num; $i++) {
154 $row = $file_result_temp[$i];
158 array_push($sorted_file_result, $row);
159 for ($j = $i + 1; $j < $max_num; $j ++) {
160 $row_next = $file_result_temp[$j];
161 if (! empty($row_next) && ($row[
'pfile_fk'] == $row_next[
'pfile_fk'])) {
162 array_push($sorted_file_result, $row_next);
163 $file_result_temp[$j] = null;
168 $text = _(
"Display");
169 $text1 = _(
"excludes");
170 $text2 = _(
"files with these extensions");
171 if (! empty($Excl)) {
172 $V .=
"<br>$text <b>$text1</b> $text2: $Excl";
175 $text2 = _(
"files with these licenses");
176 if (!empty($Exclic)) {
177 $V .=
"<br>$text <b>$text1</b> $text2: $Exclic";
181 if (($Max > 0) && ($Count >= $Max) && ($Page >= 0)) {
182 $VM =
"<P />\n" .
MenuEndlessPage($Page, intval((($Count + $Offset) / $Max))) .
"<P />\n";
190 $LinkLast =
"view-license";
195 $ushortname = rawurlencode($rf_shortname);
196 $baseURL =
"?mod=" . $this->Name .
"&item=$uploadtree_pk&lic=$ushortname&page=-1";
200 $V .=
"<tr><th>$text</th><th> ";
202 $ExclArray = explode(
":", $Excl);
203 $ExclicArray = explode(
":", $Exclic);
204 foreach ($sorted_file_result as $row) {
205 $pfile_pk = $row[
'pfile_fk'];
206 $licstring =
GetFileLicenses_string($row[
'agent_pk'], $pfile_pk, $row[
'uploadtree_pk'], $uploadtree_tablename);
207 $URLlicstring = urlencode($licstring);
213 $URL .=
"&excl=$Excl:$FileExt";
215 $URL .=
"&excl=$FileExt";
217 if (!empty($Exclic)) {
218 $URL .=
"&exclic=" . urlencode($Exclic);
220 $text = _(
"Exclude this file type.");
221 $Header =
"<a href=$URL>$text</a>";
225 if (!empty($Exclic)) {
226 $URL .=
"&exclic=" . urlencode($Exclic) .
":" . $URLlicstring;
228 $URL .=
"&exclic=$URLlicstring";
231 $URL .=
"&excl=$Excl";
234 $text = _(
"Exclude files with license");
235 $Header .=
"<br><a href=$URL>$text: $licstring.</a>";
237 $excludeByType = $Excl && in_array($FileExt, $ExclArray);
238 $excludeByLicense = $Exclic && in_array($licstring, $ExclicArray);
240 if (!empty($licstring) && !$excludeByType && !$excludeByLicense) {
243 $LinkLastpfile = $LinkLast .
"&pfile=$pfile_pk";
244 if ($LastPfilePk == $pfile_pk) {
245 $indent =
"<div style='margin-left:2em;'>";
252 $V .=
Dir2Browse(
"browse", $row[
'uploadtree_pk'], $LinkLastpfile,
253 $ShowBox, $ShowMicro, ++$RowNum, $Header,
'', $uploadtree_tablename);
256 $V .=
"<td> </td>";
257 $V .=
"<td>$row[agent_name]: $licstring</td></tr>";
258 $V .=
"<tr><td colspan=3><hr></td></tr>";
260 $LastPfilePk = $pfile_pk;
262 pg_free_result($filesresult);
285 $license = $this->licenseDao->getLicenseByShortname($rf_shortname);
286 if (null == $license) {
289 $itemBounds = $this->uploadDao->getItemTreeBounds($uploadtree_pk, $uploadtree_tablename);
291 $viewRelavantFiles =
"SELECT pfile_fk as PF, uploadtree_pk, ufile_name FROM $uploadtree_tablename";
294 if (!empty($tag_pk)) {
296 $viewRelavantFiles .=
" INNER JOIN tag_file ON PF=tag_file.pfile_fk and tag_fk=$".count($params);
299 $params[] = $itemBounds->getLeft();
300 $params[] = $itemBounds->getRight();
301 $viewRelavantFiles .=
' WHERE lft BETWEEN $'.(count($params)-1).
' AND $'.count($params);
302 if ($uploadtree_tablename ==
"uploadtree_a" || $uploadtree_tablename ==
"uploadtree") {
303 $params[] = $itemBounds->getUploadId();
304 $viewRelavantFiles .=
" AND upload_fk=$".count($params);
308 $params[] = $license->getId();
309 $sql =
"SELECT count(license_file.pfile_fk) as count, count(distinct license_file.pfile_fk) as unique 310 FROM license_file, ($viewRelavantFiles) as SS 311 WHERE PF=license_file.pfile_fk AND rf_fk = $".count($params);
313 if (is_array($agent_pk)) {
314 $params[] =
'{' . implode(
',', $agent_pk) .
'}';
315 $sql .=
' AND agent_fk=ANY($'.count($params).
')';
317 } elseif (!empty($agent_pk)) {
318 $params[] = $agent_pk;
319 $sql .=
" AND agent_fk=$".count($params);
323 $RetArray = $this->
dbManager->getSingleRow($sql,$params,$stmt);
328 $NewPlugin->Initialize();
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.
countFilesWithLicense($agent_pk, $rf_shortname, $uploadtree_pk, $tag_pk, $uploadtree_tablename)
Cloned from commen-license-file.php to refactor it.
RegisterMenus()
Customize submenus.
GetSingleRec($Table, $Where="")
Retrieve a single database record.
GetFileLicenses_string($agent_pk, $pfile_pk, $uploadtree_pk, $uploadtree_tablename='uploadtree')
Same as GetFileLicenses() but returns license list as a single string.
Output()
Display the loaded menu and plugins.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
GetFileExt($fname)
Get File Extension (text after last period)
fo_dbManager * dbManager
fo_dbManager object
This is the Plugin class. All plugins should:
GetFilesWithLicense($agent_pk, $rf_shortname, $uploadtree_pk, $PkgsOnly=false, $offset=0, $limit="ALL", $order="", $tag_pk=null, $uploadtree_tablename)
Get files with a given license (shortname).