Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
tag_suggestion.php
1 <?php
17  define('SQ_SYSTEM_ROOT', dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])))));
18  require_once SQ_SYSTEM_ROOT.'/core/include/init.inc';
19  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
20  if (!isset($_GET['assetid'])) return FALSE;
21  if (!isset($_GET['prefix'])) return FALSE;
22 
23  $assetid = $_GET['assetid'];
24  if (!assert_valid_assetid($assetid)) {
25  exit;
26  }
27  //Sanitise
28  $prefix = preg_replace('/[\'"\(\);\[\]{}<>=]+/', '', $_GET['prefix']);
29 
30  $asset =& $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
31  if (is_null($asset)) {
32  exit;
33  }
34  // Make sure the current user has read access on this asset
35  if (!$asset->writeAccess()) {
36  $GLOBALS['SQ_SYSTEM']->paintLogin(translate('login'), translate('cannot_access_asset', $asset->name));
37  exit;
38  }
39 
40  $button_name = 'sq_asset_finder_'.$prefix.'_tags_more_btn';
41  $labelname = 'sq_asset_finder_'.$prefix.'_tags';
42  $idname = $prefix.'_tags';
43 
44 ?>
45 
46  <?php
47 $sm =& $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('search_manager');
48 if (empty($sm)) {
49  echo translate('tag_list_not_available');
50 } else {
51 
52  $keyword_ids = Array();
53  $keyword_names = Array();
54  $current_tag_ids = Array();
55  $quoted_keyword_ids = Array();
56  $keyword_ids = $sm->getAssetidsByWordIntersection($asset->id, 'thesaurus_term');
57 
58  $tm = $GLOBALS['SQ_SYSTEM']->getTagManager();
59  $current_tag_links = $tm->getTagLinks($asset->id);
60 
61  foreach ($current_tag_links as $key => $current_tag_link) {
62  $current_tag_ids[] = $current_tag_link['minorid'];
63  }
64 
65  $keyword_ids = array_values(array_diff($keyword_ids, $current_tag_ids));
66  foreach ($keyword_ids as $keyword_id) {
67  $quoted_keyword_ids[] = "'".$keyword_id."'";
68  }
69 
70  $keywords_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($keyword_ids);
71 
72  ?>
73 
74 <html>
75  <head>
76  <title><?php echo "'".$asset->attr('name')."' ".translate('tag_suggestion'); ?></title>
77  <style>
78  body {
79  background-color: #FFFFFF;
80  }
81 
82  body, p, td, ul, li, input, select, textarea{
83  color: #000000;
84  font-family: Arial, Verdana Helvetica, sans-serif;
85  font-size: 11px;
86  }
87 
88  fieldset {
89  padding: 0px 10px 5px 5px;
90  border: 1px solid #E0E0E0;
91  }
92 
93  legend {
94  color: #2086EA;
95  }
96  </style>
97  <script type="text/javascript">
98  displayedButtons = new Array(<?php echo implode(',', $quoted_keyword_ids); ?>);
99 
100 
101  function addTag(name, id)
102  {
103  next_index = 0;
104  while (opener.document.getElementById('<?php echo $labelname ?>_'+(next_index + 1)+'__label') != null){
105  next_index++;
106  }
107  label = opener.document.getElementById('<?php echo $labelname ?>_'+next_index+'__label');
108  label.value = name+' (id: #'+id+')';
109  assetid = opener.document.getElementById('<?php echo $idname ?>['+next_index+'][assetid]');
110  assetid.value = id;
111  more_btn = opener.document.getElementById('<?php echo $button_name ?>');
112  more_btn.onclick();
113  }
114  function hideTagButton(id)
115  {
116  removediv = document.getElementById(('tag'+id));
117  removediv.style.display = 'none';
118 
119  newArray = new Array();
120  for (var i=0; i<displayedButtons.length; i++)
121  {
122  if(displayedButtons[i] != id) {
123  newArray.push(displayedButtons[i]);
124  }
125  }
126  displayedButtons = newArray;
127  checkTagsLeft();
128 
129  }
130  function checkTagsLeft()
131  {
132 
133  if (displayedButtons.length == 0) {
134  noMoreTags = document.getElementById('noMoreTags');
135  noMoreTags.style.visibility = 'visible';
136 
137  addAll = document.getElementById('addAll');
138  addAll.style.display = 'none';
139  }
140  }
141 
142  </script>
143  </head>
144 
145  <body>
146  <?php
147  require_once dirname(__FILE__).'/../../include/backend_outputter.inc';
148  $o = new Backend_Outputter();
149  $o->addOnLoad('checkTagsLeft()');
150  $o->openSection(translate('suggested_tags_for').' '.get_asset_tag_line($asset->id));
151  $o->openField('');
152  ?>
153  <p><?php echo translate('suggested_tags_for').' '.get_asset_tag_line($asset->id); ?></p>
154  <p><?php echo translate('click_to_tag'); ?></p>
155 
156  <p>
157  <fieldset>
158  <legend><b><?php echo 'Suggested Tags'; ?></b></legend>
159 
160 
161  <?php
162  uasort($keywords_info, create_function('$a,$b', 'return strcasecmp($a[\'name\'], $b[\'name\']);'));
163  foreach ($keywords_info as $keyword_info) {
164  // reject any suggested tags that are not from the tagging thesaurus
165  if ($tm->isFromTaggingThesaurus($keyword_info['assetid'])) {
166  ?><input type="button" name="Tag" id="tag<?php echo $keyword_info['assetid']; ?>" value="<?php echo $keyword_info['name']; ?>"
167  onclick="javascript:
168  addTag('<?php echo $keyword_info['name']; ?>', '<?php echo $keyword_info['assetid']; ?>');
169  hideTagButton('<?php echo $keyword_info['assetid']; ?>');
170  "
171  class="sq-form-field" />
172  <?php
173  }
174  }
175 
176 }//end else
177 ?><div id="noMoreTags" style="visibility:hidden;">
178  <?php echo translate('no_tags_to_add'); ?>
179  </div>
180  <div id="addAll" onLoad="javascript: checkTagsLeft();" >
181  <input type="button" name="Tag" id="add_all" value="Add all"
182  onclick="javascript:
183  staticLength = displayedButtons.length
184  for (var i=0; i<staticLength; i++)
185  {
186  button = getElementById('tag'+displayedButtons[0]);
187  button.onclick();
188  }
189  "
190  class="sq-form-field" />
191  </div>
192  </fieldset>
193  </p>
194 <?php
195 $o->openField('', 'commit');
196 normal_button('cancel', translate('close_window'), 'window.close()');
197 $o->closeSection();
198 $o->paint();
199 ?>
200  </body>
201 </html>