21 $this->Title = _(
"Tag");
23 parent::__construct();
24 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
32 $text = _(
"Tag files or containers");
33 menu_insert(
"Browse-Pfile::Tag",0,$this->Name,$text);
46 if (empty($Item) || empty($Upload)) {
50 if (isset($tag_array)) {
51 $tag_name = $tag_array[
"tag_name"];
52 $tag_notes = $tag_array[
"tag_notes"];
53 $tag_file = $tag_array[
"tag_file"];
54 $tag_package = $tag_array[
"tag_package"];
55 $tag_container = $tag_array[
"tag_container"];
56 $tag_desc = $tag_array[
"tag_desc"];
57 $tag_dir = $tag_array[
"tag_dir"];
68 if (empty($tag_name)) {
69 $text = _(
"TagName must be specified. Tag Not created.");
73 if (empty($tag_dir) && empty($tag_file) && empty($tag_package) &&
74 empty($tag_container)) {
76 "Need to select one option (dir/file/package/container) to create tag.");
83 $sql =
"SELECT * FROM tag WHERE tag = '$tag_name'";
86 if (pg_num_rows($result) < 1) {
87 pg_free_result($result);
89 $Val = str_replace(
"'",
"''", $tag_name);
90 $Val1 = str_replace(
"'",
"''", $tag_desc);
91 $sql =
"INSERT INTO tag (tag,tag_desc) VALUES ('$Val', '$Val1');";
94 pg_free_result($result);
96 pg_free_result($result);
100 $sql =
"SELECT * FROM tag WHERE tag = '$tag_name' LIMIT 1;";
103 if (pg_num_rows($result) < 1) {
104 pg_free_result($result);
105 $text = _(
"Failed to create tag.");
109 $row = pg_fetch_assoc($result);
110 $tag_pk = $row[
"tag_pk"];
111 pg_free_result($result);
113 $pfileArray = array();
116 if (! empty($tag_file)) {
118 $sql =
"SELECT pfile_fk FROM uploadtree
119 WHERE uploadtree_pk = $Item LIMIT 1";
122 while ($row = pg_fetch_assoc($result)) {
123 $pfileArray[$i] = $row[
'pfile_fk'];
126 pg_free_result($result);
129 if (! empty($tag_package)) {
132 $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);";
135 while ($row = pg_fetch_assoc($result)) {
136 $pfileArray[$i] = $row[
'pfile_pk'];
139 pg_free_result($result);
141 if (! empty($tag_container)) {
142 $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;";
145 while ($row = pg_fetch_assoc($result)) {
146 $pfileArray[$i] = $row[
'pfile_fk'];
149 pg_free_result($result);
152 if (! empty($tag_dir)) {
153 $sql =
"SELECT tag_uploadtree_pk FROM tag_uploadtree WHERE tag_fk = $tag_pk AND uploadtree_fk = $Item;";
156 if (pg_num_rows($result) < 1) {
157 pg_free_result($result);
159 $Val = str_replace(
"'",
"''", $tag_notes);
160 $sql =
"INSERT INTO tag_uploadtree (tag_fk,uploadtree_fk,tag_uploadtree_date,tag_uploadtree_text) VALUES ($tag_pk, $Item, now(), '$Val');";
163 pg_free_result($result);
165 $text = _(
"This Tag already associated with this Directory!");
166 pg_exec(
"ROLLBACK;");
167 pg_free_result($result);
171 foreach ($pfileArray as $pfile) {
172 $sql =
"SELECT tag_file_pk FROM tag_file WHERE tag_fk = $tag_pk AND pfile_fk = $pfile;";
175 if (pg_num_rows($result) < 1) {
176 pg_free_result($result);
178 $Val = str_replace(
"'",
"''", $tag_notes);
179 $sql =
"INSERT INTO tag_file (tag_fk,pfile_fk,tag_file_date,tag_file_text) VALUES ($tag_pk, $pfile, now(), '$Val');";
182 pg_free_result($result);
184 $text = _(
"This Tag already associated with this File!");
185 pg_exec(
"ROLLBACK;");
186 pg_free_result($result);
205 if (empty($Item) || empty($Upload)) {
219 if (empty($tag_name)) {
220 $text = _(
"TagName must be specified. Tag Not Updated.");
224 $sql =
"SELECT tag FROM tag WHERE tag_pk = '$tag_pk';";
227 $row = pg_fetch_row($result);
228 pg_free_result($result);
230 if ($row[0] <> $tag_name) {
231 $sql =
"SELECT * FROM tag WHERE tag = '$tag_name'";
235 if (pg_num_rows($result) >= 1) {
236 $row = pg_fetch_row($result);
237 pg_free_result($result);
243 $tag_data = array(
"tag_pk" => $row[0],
"tag_name" => $row[1],
"tag_desc" => $row[3],
244 "tag_notes" => $tag_notes,
"tag_file" => $tag_file,
"tag_package" => $tag_package,
245 "tag_container" => $tag_container,
"tag_dir" => $tag_dir);
249 pg_free_result($result);
255 $Val = str_replace(
"'",
"''", $tag_name);
256 $Val1 = str_replace(
"'",
"''", $tag_desc);
257 $sql =
"UPDATE tag SET tag = '$Val', tag_desc = '$Val1' WHERE tag_pk = $tag_pk;";
260 pg_free_result($result);
262 $Val = str_replace(
"'",
"''", $tag_notes);
263 if (! empty($tag_dir)) {
264 $sql =
"UPDATE tag_uploadtree SET tag_uploadtree_date = now(), tag_uploadtree_text = '$Val', tag_fk = $tag_pk WHERE tag_uploadtree_pk = $tag_file_pk;";
266 $sql =
"UPDATE tag_file SET tag_file_date = now(), tag_file_text = '$Val', tag_fk = $tag_pk WHERE tag_file_pk = $tag_file_pk;";
270 pg_free_result($result);
286 if (empty($Item) || empty($Upload)) {
291 $sql =
"SELECT ufile_name, ufile_mode FROM uploadtree
292 WHERE uploadtree_pk = $Item";
295 $row = pg_fetch_assoc($result);
296 $ufile_mode = $row[
"ufile_mode"];
297 pg_free_result($result);
299 if (
Isdir($ufile_mode)) {
300 $sql =
"DELETE FROM tag_uploadtree WHERE tag_uploadtree_pk = $tag_file_pk";
302 $sql =
"DELETE FROM tag_file WHERE tag_file_pk = $tag_file_pk";
306 pg_free_result($result);
318 $VE = _(
"<h3>Current Tags:</h3>\n");
319 $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;";
322 if (pg_num_rows($result) > 0) {
323 $VE .=
"<table border=1>\n";
325 $text2 = _(
"Tag Description");
326 $text3 = _(
"Tag Date");
327 $VE .=
"<tr><th>$text1</th><th>$text2</th><th>$text3</th><th></th></tr>\n";
328 while ($row = pg_fetch_assoc($result)) {
329 $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>";
330 if ($this->uploadDao->isEditable($Upload, Auth::getGroupId())) {
331 $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";
333 $nopermtext = _(
"No permission to edit tag.");
334 $VE .=
"<td align='center'>$nopermtext</td></tr>\n";
337 $VE .=
"</table><p>\n";
339 pg_free_result($result);
352 $VA .=
"<script language='javascript'>\n";
353 $VA .=
"var swtemp=0,objtemp;\n";
354 $VA .=
"function mouseout(o){\n";
355 $VA .=
" o.style.display = \"none\";\n";
356 $VA .=
" swtemp = 0;\n";
358 $VA .=
"function removediv(inputid){\n";
359 $VA .=
" getobj(inputid+\"mydiv\").style.display=\"none\";\n";
361 $VA .=
"function creatediv(_parent,_element,_id,_css){\n";
362 $VA .=
" var newObj = document.createElement(_element);\n";
363 $VA .=
" if(_id && _id!=\"\")newObj.id=_id;\n";
364 $VA .=
" if(_css && _css!=\"\"){\n";
365 $VA .=
" newObj.setAttribute(\"style\",_css);\n";
366 $VA .=
" newObj.style.cssText = _css;\n";
368 $VA .=
" if(_parent && _parent!=\"\"){\n";
369 $VA .=
" var theObj=getobj(_parent);\n";
370 $VA .=
" var parent = theObj.parentNode;\n";
371 $VA .=
" if(parent.lastChild == theObj){\n";
372 $VA .=
" theObj.appendChild(newObj);\n";
375 $VA .=
" theObj.insertBefore(newObj, theObj.nextSibling);\n";
378 $VA .=
" else document.body.appendChild(newObj);\n";
380 $VA .=
"function getobj(o){\n";
381 $VA .=
" return document.getElementById(o);\n";
383 $VA .=
"function Tags_Reply()\n";
385 $VA .=
" if ((Tags.readyState==4) && (Tags.status==200))\n";
387 $VA .=
" var list = Tags.responseText;\n";
388 $VA .=
" var text_list = list.split(\",\")\n";
389 $VA .=
" var inputid = getobj(\"tag_name\");\n";
390 $VA .=
" if (swtemp==1){getobj(objtemp+\"mydiv\").style.display=\"none\";}\n";
391 $VA .=
" if (!getobj(inputid+\"mydiv\") && list!=\"\"){\n";
392 $VA .=
" var divcss=\"width:240px;font-size:12px;position:absolute;left:\"+(inputid.offsetLeft+0)+\"px;top:\"+(inputid.offsetTop+23)+\"px;border:1px solid\";\n";
393 $VA .=
" creatediv(\"\",\"div\",inputid+\"mydiv\",divcss);\n";
394 $VA .=
" for (var i=0;i<text_list.length-1;i++){\n";
395 $VA .=
" creatediv(inputid+\"mydiv\",\"li\",inputid+\"li\"+i,\"color:#000;background:#fff;list-style-type:none;padding:9px;margin:0;CURSOR:pointer\");\n";
396 $VA .=
" getobj(inputid+\"li\"+i).innerHTML=text_list[i];\n";
397 $VA .=
" getobj(inputid+\"li\"+i).onmouseover=function(){this.style.background=\"#eee\";}\n";
398 $VA .=
" getobj(inputid+\"li\"+i).onmouseout=function(){this.style.background=\"#fff\"}\n";
399 $VA .=
" getobj(inputid+\"li\"+i).onclick=function(){\n";
400 $VA .=
" inputid.value=this.innerHTML;\n";
401 $VA .=
" removediv(inputid);\n";
405 $VA .=
" var newdiv=getobj(inputid+\"mydiv\");\n";
407 $VA .=
" document.body.onclick = function(){removediv(inputid);}\n";
408 $VA .=
" newdiv.onblur=function(){mouseout(this);}\n";
409 $VA .=
" newdiv.style.display=\"block\";\n";
410 $VA .=
" swtemp=1;\n";
411 $VA .=
" objtemp=inputid;\n";
412 $VA .=
" newdiv.focus();\n";
415 $VA .=
"</script>\n";
427 $VC .= _(
"<h3>Create Tag:</h3>\n");
430 $sql =
"SELECT ufile_name, ufile_mode FROM uploadtree
431 WHERE uploadtree_pk = $Item";
434 $row = pg_fetch_assoc($result);
435 $ufile_name = $row[
"ufile_name"];
436 $ufile_mode = $row[
"ufile_mode"];
437 pg_free_result($result);
439 $VC.=
"<form name='form' method='POST' action='" .
Traceback_uri() .
"?mod=tag&upload=$Upload&item=$Item'>\n";
443 $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\")'/> ";
449 $text = _(
"Tag description:");
450 $VC .=
"<p>$text <input type='text' name='tag_desc'/></p>";
451 $VC .= _(
"<p>Notes:</p>");
452 $VC .=
"<p><textarea rows='10' cols='80' name='tag_notes'></textarea></p>";
454 if (
Isdir($ufile_mode)) {
455 $VC .=
"<p><input type='hidden' name='tag_dir' value='1'/></p>";
466 $VC .=
"<p><input type='hidden' name='tag_file' value='1'/></p>";
468 $VC .=
"<p><input type='hidden' name='tag_file' value='1'/></p>";
471 $VC .=
"<input type='hidden' name='action' value='add'/>\n";
472 $VC .=
"<input type='submit' value='$text'>\n";
485 $text = _(
"Create New Tag");
486 $VEd .=
"<h4><a href='" .
Traceback_uri() .
"?mod=tag&upload=$Upload&item=$Item'>$text</a><h4>";
488 $VEd .= _(
"<h3>Edit Tag:</h3>\n");
492 $sql =
"SELECT ufile_name, ufile_mode FROM uploadtree
493 WHERE uploadtree_pk = $Item";
496 $row = pg_fetch_assoc($result);
497 $ufile_name = $row[
"ufile_name"];
498 $ufile_mode = $row[
"ufile_mode"];
499 pg_free_result($result);
502 if (
Isdir($ufile_mode)) {
503 $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";
505 $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";
509 $row = pg_fetch_assoc($result);
510 $tag_pk = $row[
'tag_pk'];
512 if (
Isdir($ufile_mode)) {
513 $tag_notes = $row[
'tag_uploadtree_text'];
515 $tag_notes = $row[
'tag_file_text'];
517 $tag_desc = $row[
'tag_desc'];
518 pg_free_result($result);
520 $VEd.=
"<form name='form' method='POST' action='" .
Traceback_uri() .
"?mod=tag&upload=$Upload&item=$Item'>\n";
523 $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\"/> ";
524 $text = _(
"Tag description:");
525 $VEd .=
"<p>$text <input type='text' name='tag_desc' value=\"$tag_desc\"/></p>";
526 $VEd .= _(
"<p>Notes:</p>");
527 $VEd .=
"<p><textarea rows='10' cols='80' name='tag_notes'>$tag_notes</textarea></p>";
529 if (
Isdir($ufile_mode)) {
530 $VEd .=
"<p><input type='hidden' name='tag_dir' value='1'/></p>";
540 $VEd .=
"<p><input type='hidden' name='tag_file' value='1'/></p>";
542 $VEd .=
"<p><input type='hidden' name='tag_file' value='1'/></p>";
545 $VEd .=
"<input type='hidden' name='action' value='update'/>\n";
546 $VEd .=
"<input type='hidden' name='tag_pk' value='$tag_pk'/>\n";
547 $VEd .=
"<input type='hidden' name='tag_file_pk' value='$tag_file_pk'/>\n";
548 $VEd .=
"<input type='submit' value='$text'>\n";
561 $VD .= _(
"<h3>Delete Tag:</h3>\n");
564 $sql =
"SELECT ufile_name, ufile_mode FROM uploadtree
565 WHERE uploadtree_pk = $Item";
568 $row = pg_fetch_assoc($result);
569 $ufile_name = $row[
"ufile_name"];
570 $ufile_mode = $row[
"ufile_mode"];
571 pg_free_result($result);
573 $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;";
576 if (pg_num_rows($result) > 0) {
577 $VD .=
"<form name='form' method='POST' action='" .
Traceback_uri() .
"?mod=tag&upload=$Upload&item=$Item'>\n";
578 $VD .=
"<select multiple size='10' name='tag_file_pk[]'>\n";
579 while ($row = pg_fetch_assoc($result)) {
580 $VD .=
"<option value='" . $row[
'tag_file_pk'] .
"'>" .
"-" . $row[
'tag'] .
"</option>\n";
582 $VD .=
"</select>\n";
584 $text = _(
"Delete Tag only for this file.");
585 $VD .=
"<p><input type='checkbox' name='tag_file' value='1' checked/>$text</p>";
586 $text = _(
"Delete Tag for all packages (source and binary) in this container tree.");
587 $VD .=
"<p><input type='checkbox' name='tag_package' value='1'/>$text</p>";
591 $VD .=
"<p><input type='hidden' name='tag_file' value='1'/></p>";
594 $VD .=
"<input type='hidden' name='action' value='delete'/>\n";
595 $VD .=
"<input type='submit' value='$text'>\n";
598 pg_free_result($result);
614 if (empty($Item) || empty($Upload)) {
622 $V .=
Dir2Browse(
"browse",$Item,NULL,1,
"Browse");
628 if ($action ==
'edit') {
632 if ($this->uploadDao->isEditable($Upload, Auth::getGroupId())) {
635 $nopermtext = _(
"You do not have permission to tag this upload.");
648 if ($action ==
'add') {
651 $text = _(
"Create Tag Failed");
652 $this->vars[
'message'] =
"$text: $rc";
654 $this->vars[
'message'] = _(
"Create Tag Successful!");
657 if ($action ==
'update') {
660 $text = _(
"Edit Tag Failed");
661 $this->vars[
'message'] =
"$text: $rc";
663 $this->vars[
'message'] = _(
"Edit Tag Successful!");
666 if ($action ==
'delete') {
669 $text = _(
"Delete Tag Failed");
670 $this->vars[
'message'] =
"$text: $rc";
672 $this->vars[
'message'] = _(
"Delete Tag Successful!");
681 $NewPlugin =
new ui_tag();
682 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
Contains the constants and helpers for authentication of user.
ShowDeleteTagPage($Upload, $Item)
Display the delete tag page.
ShowEditTagPage($Upload, $Item)
Display the edit tag page.
__construct()
base constructor. Most plugins will just use this
ShowAjaxPage()
Display the ajax page.
DeleteTag()
Delete exsit Tag.
ShowTaggingPage($action, $ShowHeader=0)
Display the tagging page.
ShowCreateTagPage($Upload, $Item)
Display the create tag page.
ShowExistTags($Upload, $Uploadtree_pk)
Show all tags about.
RegisterMenus()
Customize submenus.
Output()
This function is called when user output is requested. This function is responsible for content....
CreateTag($tag_array)
Add a new Tag.
ActiveHTTPscript($RequestName, $IncludeScriptTags=1)
Given a function name, create the JavaScript needed for doing the request.
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
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.
Traceback_uri()
Get the URI without query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
GetPkgMimetypes()
Get package mimetype.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN