29 function __construct()
32 $this->Title = _(
"Tag");
34 parent::__construct();
35 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
43 $text = _(
"Tag files or containers");
44 menu_insert(
"Browse-Pfile::Tag",0,$this->Name,$text);
57 if (empty($Item) || empty($Upload)) {
61 if (isset($tag_array)) {
62 $tag_name = $tag_array[
"tag_name"];
63 $tag_notes = $tag_array[
"tag_notes"];
64 $tag_file = $tag_array[
"tag_file"];
65 $tag_package = $tag_array[
"tag_package"];
66 $tag_container = $tag_array[
"tag_container"];
67 $tag_desc = $tag_array[
"tag_desc"];
68 $tag_dir = $tag_array[
"tag_dir"];
79 if (empty($tag_name)) {
80 $text = _(
"TagName must be specified. Tag Not created.");
84 if (empty($tag_dir) && empty($tag_file) && empty($tag_package) &&
85 empty($tag_container)) {
87 "Need to select one option (dir/file/package/container) to create tag.");
94 $sql =
"SELECT * FROM tag WHERE tag = '$tag_name'";
95 $result = pg_query($PG_CONN, $sql);
97 if (pg_num_rows($result) < 1) {
98 pg_free_result($result);
100 $Val = str_replace(
"'",
"''", $tag_name);
101 $Val1 = str_replace(
"'",
"''", $tag_desc);
102 $sql =
"INSERT INTO tag (tag,tag_desc) VALUES ('$Val', '$Val1');";
103 $result = pg_query($PG_CONN, $sql);
105 pg_free_result($result);
107 pg_free_result($result);
111 $sql =
"SELECT * FROM tag WHERE tag = '$tag_name' LIMIT 1;";
112 $result = pg_query($PG_CONN, $sql);
114 if (pg_num_rows($result) < 1) {
115 pg_free_result($result);
116 $text = _(
"Failed to create tag.");
120 $row = pg_fetch_assoc($result);
121 $tag_pk = $row[
"tag_pk"];
122 pg_free_result($result);
124 $pfileArray = array();
127 if (! empty($tag_file)) {
129 $sql =
"SELECT pfile_fk FROM uploadtree 130 WHERE uploadtree_pk = $Item LIMIT 1";
131 $result = pg_query($PG_CONN, $sql);
133 while ($row = pg_fetch_assoc($result)) {
134 $pfileArray[$i] = $row[
'pfile_fk'];
137 pg_free_result($result);
140 if (! empty($tag_package)) {
143 $sql =
"SELECT distinct pfile.pfile_pk FROM uploadtree, pfile WHERE uploadtree.pfile_fk = pfile.pfile_pk AND (pfile.pfile_mimetypefk = $MimetypeArray[0] OR pfile.pfile_mimetypefk = $MimetypeArray[1] OR pfile.pfile_mimetypefk = $MimetypeArray[2]) AND uploadtree.upload_fk = $Upload AND uploadtree.lft >= (SELECT lft FROM uploadtree WHERE uploadtree_pk = $Item) AND uploadtree.rgt <= (SELECT rgt FROM uploadtree WHERE uploadtree_pk = $Item);";
144 $result = pg_query($PG_CONN, $sql);
146 while ($row = pg_fetch_assoc($result)) {
147 $pfileArray[$i] = $row[
'pfile_pk'];
150 pg_free_result($result);
152 if (! empty($tag_container)) {
153 $sql =
"SELECT distinct pfile_fk FROM uploadtree WHERE upload_fk = $Upload AND lft >= (SELECT lft FROM uploadtree WHERE uploadtree_pk = $Item) AND rgt <= (SELECT rgt FROM uploadtree WHERE uploadtree_pk = $Item) AND ((ufile_mode & (1<<28))=0) AND pfile_fk!=0;";
154 $result = pg_query($PG_CONN, $sql);
156 while ($row = pg_fetch_assoc($result)) {
157 $pfileArray[$i] = $row[
'pfile_fk'];
160 pg_free_result($result);
163 if (! empty($tag_dir)) {
164 $sql =
"SELECT tag_uploadtree_pk FROM tag_uploadtree WHERE tag_fk = $tag_pk AND uploadtree_fk = $Item;";
165 $result = pg_query($PG_CONN, $sql);
167 if (pg_num_rows($result) < 1) {
168 pg_free_result($result);
170 $Val = str_replace(
"'",
"''", $tag_notes);
171 $sql =
"INSERT INTO tag_uploadtree (tag_fk,uploadtree_fk,tag_uploadtree_date,tag_uploadtree_text) VALUES ($tag_pk, $Item, now(), '$Val');";
172 $result = pg_query($PG_CONN, $sql);
174 pg_free_result($result);
176 $text = _(
"This Tag already associated with this Directory!");
177 pg_exec(
"ROLLBACK;");
178 pg_free_result($result);
182 foreach ($pfileArray as $pfile) {
183 $sql =
"SELECT tag_file_pk FROM tag_file WHERE tag_fk = $tag_pk AND pfile_fk = $pfile;";
184 $result = pg_query($PG_CONN, $sql);
186 if (pg_num_rows($result) < 1) {
187 pg_free_result($result);
189 $Val = str_replace(
"'",
"''", $tag_notes);
190 $sql =
"INSERT INTO tag_file (tag_fk,pfile_fk,tag_file_date,tag_file_text) VALUES ($tag_pk, $pfile, now(), '$Val');";
191 $result = pg_query($PG_CONN, $sql);
193 pg_free_result($result);
195 $text = _(
"This Tag already associated with this File!");
196 pg_exec(
"ROLLBACK;");
197 pg_free_result($result);
216 if (empty($Item) || empty($Upload)) {
230 if (empty($tag_name)) {
231 $text = _(
"TagName must be specified. Tag Not Updated.");
235 $sql =
"SELECT tag FROM tag WHERE tag_pk = '$tag_pk';";
236 $result = pg_query($PG_CONN, $sql);
238 $row = pg_fetch_row($result);
239 pg_free_result($result);
241 if ($row[0] <> $tag_name) {
242 $sql =
"SELECT * FROM tag WHERE tag = '$tag_name'";
243 $result = pg_query($PG_CONN, $sql);
246 if (pg_num_rows($result) >= 1) {
247 $row = pg_fetch_row($result);
248 pg_free_result($result);
254 $tag_data = array(
"tag_pk" => $row[0],
"tag_name" => $row[1],
"tag_desc" => $row[3],
255 "tag_notes" => $tag_notes,
"tag_file" => $tag_file,
"tag_package" => $tag_package,
256 "tag_container" => $tag_container,
"tag_dir" => $tag_dir);
260 pg_free_result($result);
266 $Val = str_replace(
"'",
"''", $tag_name);
267 $Val1 = str_replace(
"'",
"''", $tag_desc);
268 $sql =
"UPDATE tag SET tag = '$Val', tag_desc = '$Val1' WHERE tag_pk = $tag_pk;";
269 $result = pg_query($PG_CONN, $sql);
271 pg_free_result($result);
273 $Val = str_replace(
"'",
"''", $tag_notes);
274 if (! empty($tag_dir)) {
275 $sql =
"UPDATE tag_uploadtree SET tag_uploadtree_date = now(), tag_uploadtree_text = '$Val', tag_fk = $tag_pk WHERE tag_uploadtree_pk = $tag_file_pk;";
277 $sql =
"UPDATE tag_file SET tag_file_date = now(), tag_file_text = '$Val', tag_fk = $tag_pk WHERE tag_file_pk = $tag_file_pk;";
279 $result = pg_query($PG_CONN, $sql);
281 pg_free_result($result);
297 if (empty($Item) || empty($Upload)) {
302 $sql =
"SELECT ufile_name, ufile_mode FROM uploadtree 303 WHERE uploadtree_pk = $Item";
304 $result = pg_query($PG_CONN, $sql);
306 $row = pg_fetch_assoc($result);
307 $ufile_mode = $row[
"ufile_mode"];
308 pg_free_result($result);
310 if (
Isdir($ufile_mode)) {
311 $sql =
"DELETE FROM tag_uploadtree WHERE tag_uploadtree_pk = $tag_file_pk";
313 $sql =
"DELETE FROM tag_file WHERE tag_file_pk = $tag_file_pk";
315 $result = pg_query($PG_CONN, $sql);
317 pg_free_result($result);
329 $VE = _(
"<h3>Current Tags:</h3>\n");
330 $sql =
"SELECT tag_pk, tag, tag_desc, tag_file_pk, tag_file_date, tag_file_text FROM tag, tag_file, uploadtree WHERE tag.tag_pk = tag_file.tag_fk AND tag_file.pfile_fk = uploadtree.pfile_fk AND uploadtree.uploadtree_pk = $Uploadtree_pk UNION SELECT tag_pk, tag, tag_desc, tag_uploadtree_pk AS tag_file_pk, tag_uploadtree_date AS tag_file_date, tag_uploadtree_text AS tag_file_text FROM tag, tag_uploadtree WHERE tag.tag_pk = tag_uploadtree.tag_fk AND tag_uploadtree.uploadtree_fk = $Uploadtree_pk;";
331 $result = pg_query($PG_CONN, $sql);
333 if (pg_num_rows($result) > 0) {
334 $VE .=
"<table border=1>\n";
336 $text2 = _(
"Tag Description");
337 $text3 = _(
"Tag Date");
338 $VE .=
"<tr><th>$text1</th><th>$text2</th><th>$text3</th><th></th></tr>\n";
339 while ($row = pg_fetch_assoc($result)) {
340 $VE .=
"<tr><td align='center'>" . $row[
'tag'] .
"</td><td align='center'>" . $row[
'tag_desc'] .
"</td><td align='center'>" . substr($row[
'tag_file_date'],0,19) .
"</td>";
341 if ($this->uploadDao->isEditable($Upload, Auth::getGroupId())) {
342 $VE .=
"<td align='center'><a href='" .
Traceback_uri() .
"?mod=tag&action=edit&upload=$Upload&item=$Uploadtree_pk&tag_file_pk=" . $row[
'tag_file_pk'] .
"'>View/Edit</a>|<a href='" .
Traceback_uri() .
"?mod=tag&action=delete&upload=$Upload&item=$Uploadtree_pk&tag_file_pk=" . $row[
'tag_file_pk'] .
"'>Delete</a></td></tr>\n";
344 $nopermtext = _(
"No permission to edit tag.");
345 $VE .=
"<td align='center'>$nopermtext</td></tr>\n";
348 $VE .=
"</table><p>\n";
350 pg_free_result($result);
363 $VA .=
"<script language='javascript'>\n";
364 $VA .=
"var swtemp=0,objtemp;\n";
365 $VA .=
"function mouseout(o){\n";
366 $VA .=
" o.style.display = \"none\";\n";
367 $VA .=
" swtemp = 0;\n";
369 $VA .=
"function removediv(inputid){\n";
370 $VA .=
" getobj(inputid+\"mydiv\").style.display=\"none\";\n";
372 $VA .=
"function creatediv(_parent,_element,_id,_css){\n";
373 $VA .=
" var newObj = document.createElement(_element);\n";
374 $VA .=
" if(_id && _id!=\"\")newObj.id=_id;\n";
375 $VA .=
" if(_css && _css!=\"\"){\n";
376 $VA .=
" newObj.setAttribute(\"style\",_css);\n";
377 $VA .=
" newObj.style.cssText = _css;\n";
379 $VA .=
" if(_parent && _parent!=\"\"){\n";
380 $VA .=
" var theObj=getobj(_parent);\n";
381 $VA .=
" var parent = theObj.parentNode;\n";
382 $VA .=
" if(parent.lastChild == theObj){\n";
383 $VA .=
" theObj.appendChild(newObj);\n";
386 $VA .=
" theObj.insertBefore(newObj, theObj.nextSibling);\n";
389 $VA .=
" else document.body.appendChild(newObj);\n";
391 $VA .=
"function getobj(o){\n";
392 $VA .=
" return document.getElementById(o);\n";
394 $VA .=
"function Tags_Reply()\n";
396 $VA .=
" if ((Tags.readyState==4) && (Tags.status==200))\n";
398 $VA .=
" var list = Tags.responseText;\n";
399 $VA .=
" var text_list = list.split(\",\")\n";
400 $VA .=
" var inputid = getobj(\"tag_name\");\n";
401 $VA .=
" if (swtemp==1){getobj(objtemp+\"mydiv\").style.display=\"none\";}\n";
402 $VA .=
" if (!getobj(inputid+\"mydiv\") && list!=\"\"){\n";
403 $VA .=
" var divcss=\"width:240px;font-size:12px;position:absolute;left:\"+(inputid.offsetLeft+0)+\"px;top:\"+(inputid.offsetTop+23)+\"px;border:1px solid\";\n";
404 $VA .=
" creatediv(\"\",\"div\",inputid+\"mydiv\",divcss);\n";
405 $VA .=
" for (var i=0;i<text_list.length-1;i++){\n";
406 $VA .=
" creatediv(inputid+\"mydiv\",\"li\",inputid+\"li\"+i,\"color:#000;background:#fff;list-style-type:none;padding:9px;margin:0;CURSOR:pointer\");\n";
407 $VA .=
" getobj(inputid+\"li\"+i).innerHTML=text_list[i];\n";
408 $VA .=
" getobj(inputid+\"li\"+i).onmouseover=function(){this.style.background=\"#eee\";}\n";
409 $VA .=
" getobj(inputid+\"li\"+i).onmouseout=function(){this.style.background=\"#fff\"}\n";
410 $VA .=
" getobj(inputid+\"li\"+i).onclick=function(){\n";
411 $VA .=
" inputid.value=this.innerHTML;\n";
412 $VA .=
" removediv(inputid);\n";
416 $VA .=
" var newdiv=getobj(inputid+\"mydiv\");\n";
418 $VA .=
" document.body.onclick = function(){removediv(inputid);}\n";
419 $VA .=
" newdiv.onblur=function(){mouseout(this);}\n";
420 $VA .=
" newdiv.style.display=\"block\";\n";
421 $VA .=
" swtemp=1;\n";
422 $VA .=
" objtemp=inputid;\n";
423 $VA .=
" newdiv.focus();\n";
426 $VA .=
"</script>\n";
438 $VC .= _(
"<h3>Create Tag:</h3>\n");
441 $sql =
"SELECT ufile_name, ufile_mode FROM uploadtree 442 WHERE uploadtree_pk = $Item";
443 $result = pg_query($PG_CONN, $sql);
445 $row = pg_fetch_assoc($result);
446 $ufile_name = $row[
"ufile_name"];
447 $ufile_mode = $row[
"ufile_mode"];
448 pg_free_result($result);
450 $VC.=
"<form name='form' method='POST' action='" .
Traceback_uri() .
"?mod=tag&upload=$Upload&item=$Item'>\n";
454 $VC .=
"$text: <input type='text' id='tag_name' name='tag_name' maxlength='32' utocomplete='off' onclick='Tags_Get(\"".
Traceback_uri() .
"?mod=tag_get&uploadtree_pk=$Item\")'/> ";
460 $text = _(
"Tag description:");
461 $VC .=
"<p>$text <input type='text' name='tag_desc'/></p>";
462 $VC .= _(
"<p>Notes:</p>");
463 $VC .=
"<p><textarea rows='10' cols='80' name='tag_notes'></textarea></p>";
465 if (
Isdir($ufile_mode)) {
466 $VC .=
"<p><input type='hidden' name='tag_dir' value='1'/></p>";
477 $VC .=
"<p><input type='hidden' name='tag_file' value='1'/></p>";
479 $VC .=
"<p><input type='hidden' name='tag_file' value='1'/></p>";
482 $VC .=
"<input type='hidden' name='action' value='add'/>\n";
483 $VC .=
"<input type='submit' value='$text'>\n";
496 $text = _(
"Create New Tag");
497 $VEd .=
"<h4><a href='" .
Traceback_uri() .
"?mod=tag&upload=$Upload&item=$Item'>$text</a><h4>";
499 $VEd .= _(
"<h3>Edit Tag:</h3>\n");
503 $sql =
"SELECT ufile_name, ufile_mode FROM uploadtree 504 WHERE uploadtree_pk = $Item";
505 $result = pg_query($PG_CONN, $sql);
507 $row = pg_fetch_assoc($result);
508 $ufile_name = $row[
"ufile_name"];
509 $ufile_mode = $row[
"ufile_mode"];
510 pg_free_result($result);
513 if (
Isdir($ufile_mode)) {
514 $sql =
"SELECT tag_pk, tag_uploadtree_text, tag, tag_desc FROM tag_uploadtree, tag WHERE tag_uploadtree_pk=$tag_file_pk AND tag_uploadtree.tag_fk = tag.tag_pk";
516 $sql =
"SELECT tag_pk, tag_file_text, tag, tag_desc FROM tag_file, tag WHERE tag_file_pk=$tag_file_pk AND tag_file.tag_fk = tag.tag_pk";
518 $result = pg_query($PG_CONN, $sql);
520 $row = pg_fetch_assoc($result);
521 $tag_pk = $row[
'tag_pk'];
523 if (
Isdir($ufile_mode)) {
524 $tag_notes = $row[
'tag_uploadtree_text'];
526 $tag_notes = $row[
'tag_file_text'];
528 $tag_desc = $row[
'tag_desc'];
529 pg_free_result($result);
531 $VEd.=
"<form name='form' method='POST' action='" .
Traceback_uri() .
"?mod=tag&upload=$Upload&item=$Item'>\n";
534 $VEd .=
"$text: <input type='text' id='tag_name' name='tag_name' autocomplete='off' onclick='Tags_Get(\"".
Traceback_uri() .
"?mod=tag_get&uploadtree_pk=$Item\")' value=\"$tag\"/> ";
535 $text = _(
"Tag description:");
536 $VEd .=
"<p>$text <input type='text' name='tag_desc' value=\"$tag_desc\"/></p>";
537 $VEd .= _(
"<p>Notes:</p>");
538 $VEd .=
"<p><textarea rows='10' cols='80' name='tag_notes'>$tag_notes</textarea></p>";
540 if (
Isdir($ufile_mode)) {
541 $VEd .=
"<p><input type='hidden' name='tag_dir' value='1'/></p>";
551 $VEd .=
"<p><input type='hidden' name='tag_file' value='1'/></p>";
553 $VEd .=
"<p><input type='hidden' name='tag_file' value='1'/></p>";
556 $VEd .=
"<input type='hidden' name='action' value='update'/>\n";
557 $VEd .=
"<input type='hidden' name='tag_pk' value='$tag_pk'/>\n";
558 $VEd .=
"<input type='hidden' name='tag_file_pk' value='$tag_file_pk'/>\n";
559 $VEd .=
"<input type='submit' value='$text'>\n";
572 $VD .= _(
"<h3>Delete Tag:</h3>\n");
575 $sql =
"SELECT ufile_name, ufile_mode FROM uploadtree 576 WHERE uploadtree_pk = $Item";
577 $result = pg_query($PG_CONN, $sql);
579 $row = pg_fetch_assoc($result);
580 $ufile_name = $row[
"ufile_name"];
581 $ufile_mode = $row[
"ufile_mode"];
582 pg_free_result($result);
584 $sql =
"SELECT tag_pk, tag, tag_file_pk, tag_file_date, tag_file_text FROM tag, tag_file, uploadtree WHERE tag.tag_pk = tag_file.tag_fk AND tag_file.pfile_fk = uploadtree.pfile_fk AND uploadtree.uploadtree_pk = $Item;";
585 $result = pg_query($PG_CONN, $sql);
587 if (pg_num_rows($result) > 0) {
588 $VD .=
"<form name='form' method='POST' action='" .
Traceback_uri() .
"?mod=tag&upload=$Upload&item=$Item'>\n";
589 $VD .=
"<select multiple size='10' name='tag_file_pk[]'>\n";
590 while ($row = pg_fetch_assoc($result)) {
591 $VD .=
"<option value='" . $row[
'tag_file_pk'] .
"'>" .
"-" . $row[
'tag'] .
"</option>\n";
593 $VD .=
"</select>\n";
595 $text = _(
"Delete Tag only for this file.");
596 $VD .=
"<p><input type='checkbox' name='tag_file' value='1' checked/>$text</p>";
597 $text = _(
"Delete Tag for all packages (source and binary) in this container tree.");
598 $VD .=
"<p><input type='checkbox' name='tag_package' value='1'/>$text</p>";
602 $VD .=
"<p><input type='hidden' name='tag_file' value='1'/></p>";
605 $VD .=
"<input type='hidden' name='action' value='delete'/>\n";
606 $VD .=
"<input type='submit' value='$text'>\n";
609 pg_free_result($result);
625 if (empty($Item) || empty($Upload)) {
633 $V .=
Dir2Browse(
"browse",$Item,NULL,1,
"Browse");
639 if ($action ==
'edit') {
643 if ($this->uploadDao->isEditable($Upload, Auth::getGroupId())) {
646 $nopermtext = _(
"You do not have permission to tag this upload.");
654 public function Output()
659 if ($action ==
'add') {
662 $text = _(
"Create Tag Failed");
663 $this->vars[
'message'] =
"$text: $rc";
665 $this->vars[
'message'] = _(
"Create Tag Successful!");
668 if ($action ==
'update') {
671 $text = _(
"Edit Tag Failed");
672 $this->vars[
'message'] =
"$text: $rc";
674 $this->vars[
'message'] = _(
"Edit Tag Successful!");
677 if ($action ==
'delete') {
680 $text = _(
"Delete Tag Failed");
681 $this->vars[
'message'] =
"$text: $rc";
683 $this->vars[
'message'] = _(
"Delete Tag Successful!");
692 $NewPlugin =
new ui_tag();
693 $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.
CreateTag($tag_array)
Add a new Tag.
ShowCreateTagPage($Upload, $Item)
Display the create tag page.
Traceback_uri()
Get the URI without query to this location.
GetPkgMimetypes()
Get package mimetype.
ActiveHTTPscript($RequestName, $IncludeScriptTags=1)
Given a function name, create the JavaScript needed for doing the request.
ShowDeleteTagPage($Upload, $Item)
Display the delete tag page.
ShowExistTags($Upload, $Uploadtree_pk)
Show all tags about.
ShowEditTagPage($Upload, $Item)
Display the edit tag page.
RegisterMenus()
Customize submenus.
DeleteTag()
Delete exsit Tag.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
ShowTaggingPage($action, $ShowHeader=0)
Display the tagging page.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
This is the Plugin class. All plugins should:
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
ShowAjaxPage()
Display the ajax page.