Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
js_api_edit_fns.inc
1 <?php
17 require_once SQ_CORE_PACKAGE_PATH.'/page/page_edit_fns.inc';
18 
31 {
32 
33 
38  function __construct()
39  {
40  parent::__construct();
41 
42  }//end constructor
43 
44 
55  function paintAssetTypes(&$asset, &$o, $prefix)
56  {
57  $types = $asset->attr('types');
58 
59  if ($asset->writeAccess('attributes')) {
60 
61  asset_type_chooser($prefix.'_types', TRUE, array_keys($types));
62  return TRUE;
63  } else {
64  // print the read-only version
65  if (empty($types)) {
66  echo '<p class="sq-backend-warning">'.translate('js_api_no_asset_types_selected').'</p>';
67  } else {
68  $type_names = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo(array_keys($types), 'name');
69  ?>
70  <table class="sq-backend-table">
71  <tr>
72  <th><?php echo translate('type') ?></th>
73  </tr>
74  <?php
75  foreach ($types as $type => $value) {
76  ?>
77  <tr>
78  <td><?php
79  echo get_asset_type_icon($type);
80  echo $type_names[$type];
81  ?></td>
82  </tr>
83  <?php
84  }
85  ?>
86  </table>
87  <?php
88  }
89  return FALSE;
90  }//end else - if write access to content
91 
92  }//end paintAssetTypes()
93 
94 
109  function processAssetTypes(&$asset, &$o, $prefix)
110  {
111 
112  if (isset($_POST[$prefix.'_types'])) {
113  $types = Array();
114  foreach ($_POST[$prefix.'_types'] as $type) {
115  if (!empty($type)) $types[$type] = 1;
116  }
117  $asset->setAttrValue('types', $types);
118  return TRUE;
119  }
120  return FALSE;
121 
122  }//end processAssetTypes()
123 
124 
135  function paintRootNode(&$asset, &$o, $prefix)
136  {
137  $write_access = $asset->writeAccess('links');
138  $curr_list = $asset->getRootNodes();
139 
140  if ($write_access) {
141  multiple_asset_finder($prefix.'_roots', $curr_list, Array('asset' => 'D'));
142  } else {
143  if (empty($curr_list)) {
144  echo translate('js_api_no_root_nodes_selected');
145  } else {
146  ?><ul style="margin:1px 15px;"><?php
147  foreach ($curr_list as $assetid) {
148  echo '<li>'.get_asset_tag_line($assetid).'</li>';
149  }
150  ?></ul><?php
151  }
152  }
153 
154  return $write_access;
155 
156  }//end paintRootNode()
157 
158 
169  function processRootNode(&$asset, &$o, $prefix)
170  {
171  if (isset($asset->_tmp['reverting_to_system_version']) && $asset->_tmp['reverting_to_system_version']) {
172  return FALSE;
173  }
174  $roots = array_get_index($_POST, $prefix.'_roots', Array());
175  $root_nodes = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE, '', TRUE, 'major', 'root');
176  $curr_list = Array();
177 
178  foreach ($root_nodes as $node) {
179  $node_id = array_get_index($node, 'minorid', 0);
180  //while we are looping through each root node, lets remove if we are clearing any of the root node
181  $found = FALSE;
182  foreach ($roots as $root) {
183  if($node_id !== 0 && in_array($node_id, $root)) {
184  $found = TRUE;
185  }
186  }
187 
188  if ($node_id !== 0 && !$found) {
189  $GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($node['linkid']);
190  } else if ($node_id !== 0 && $found) {
191  $curr_list[] = $node_id;
192  }
193  }//end foreach
194 
195  foreach ($roots as $root) {
196  if (!empty($root['assetid']) && !in_array($root['assetid'], $curr_list)) {
197  $node = $GLOBALS['SQ_SYSTEM']->am->getAsset($root['assetid'], '', TRUE);
198  if (!is_null($node)) {
199  $new_link = $GLOBALS['SQ_SYSTEM']->am->createAssetLink($asset, $node, SQ_LINK_NOTICE, 'root');
200  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($node, TRUE);
201  }//end if
202  }//end if
203 
204  }//end foreach
205 
206  return TRUE;
207 
208  }//end processRootNode()
209 
210 
221  function paintApiKey(&$asset, &$o, $prefix)
222  {
223  $write_access = $asset->writeAccess('attributes');
224 
225  if ($write_access) {
226  text_box($prefix.'_key', $asset->attr('api_key'));
227  } else {
228  echo '<p class="sq-backend-warning">'.translate('js_api_api_key_lock').'</p>';
229  }//end else
230 
231  return $write_access;
232 
233  }//end paintApiKey()
234 
235 
246  function processApiKey(&$asset, &$o, $prefix)
247  {
248 
249  return $asset->setAttrValue('api_key', $_POST[$prefix.'_key']);
250 
251  }//end processRootNode()
252 
253 
264  function paintParentTypes(&$asset, &$o, $prefix)
265  {
266  $types = $asset->attr('types_restriction');
267 
268  if ($asset->writeAccess('attributes')) {
269 
270  asset_type_chooser($prefix.'_types_restrict', TRUE, array_keys($types));
271  return TRUE;
272  } else {
273  // print the read-only version
274  if (empty($types)) {
275  echo '<p class="sq-backend-warning">'.translate('js_api_no_asset_types_selected').'</p>';
276  } else {
277  $type_names = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo(array_keys($types), 'name');
278  ?>
279  <table class="sq-backend-table">
280  <tr>
281  <th><?php echo translate('type') ?></th>
282  </tr>
283  <?php
284  foreach ($types as $type => $value) {
285  ?>
286  <tr>
287  <td><?php
288  echo get_asset_type_icon($type);
289  echo $type_names[$type];
290  ?></td>
291  </tr>
292  <?php
293  }
294  ?>
295  </table>
296  <?php
297  }
298  return FALSE;
299  }//end else - if write access to content
300 
301  }//end paintParentTypes()
302 
303 
318  function processParentTypes(&$asset, &$o, $prefix)
319  {
320 
321  if (isset($_POST[$prefix.'_types_restrict'])) {
322  $types = Array();
323  foreach ($_POST[$prefix.'_types_restrict'] as $type) {
324  if (!empty($type)) $types[$type] = 1;
325  }
326  $asset->setAttrValue('types_restriction', $types);
327  return TRUE;
328  }
329  return FALSE;
330 
331  }//end processAssetTypes()
332 
333 
334 }//end class
335 ?>