Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
sharepoint_saved_search_edit_fns.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
18 require_once SQ_CORE_PACKAGE_PATH.'/data_source/data_source/data_source_edit_fns.inc';
19 require_once SQ_PACKAGES_PATH.'/sharepoint/lib/sharepoint_common.inc';
20 
33 {
34 
35 
40  function __construct()
41  {
42  parent::__construct();
43  $this->static_screens['details']['force_unlock'] = FALSE;
44 
45  }//end constructor
46 
47 
48  //-- Dynamic Data --//
49 
50 
61  function paintSearchConfig(&$asset, &$o, $prefix)
62  {
63  $write_access = $asset->writeAccess('attributes');
64 
65  $current_search_options = $asset->attr('search_options');
66 
67  $available_operators = Array (
68  '>' => '>',
69  '>=' => '>=',
70  '<' => '<',
71  '<=' => '<=',
72  '=' => '=',
73  '!=' => '!=',
74  'Contains' => 'Contains',
75  'BeginsWith' => 'BeginsWith',
76  'IsNotNull' => 'IsNotNull',
77  'IsNull' => 'IsNull',
78  );
79 
80 
81  $o->openRaw();
82 
83  $connection = $asset->getConnection();
84  $data_list = $asset->attr('data_list');
85  $search_logic = $asset->attr('search_logic');
86  $row_limit = $asset->attr('row_limit');
87  $available_fields = Array( 'None' => '');
88 
89  if (!empty($data_list) && $data_list != 'None') {
90  $sp_available_fields = Sharepoint_Common::getListAvailableFields($connection, $data_list, TRUE);
91 
92  //(refer to http://www.sharepointblogs.com/ssa/archive/2007/10/03/invalid-column-name-c2.aspx )
93  if (isset($sp_available_fields['LinkFilename'])) {
94  unset($sp_available_fields['LinkFilename']);
95  }//end if
96  if (isset($sp_available_fields['LinkFilenameNoMenu'])) {
97  unset($sp_available_fields['LinkFilenameNoMenu']);
98  }//end if
99  if (isset($sp_available_fields['BaseName'])) {
100  unset($sp_available_fields['BaseName']);
101  }//end if
102 
103  foreach ($sp_available_fields as $raw_name => $display_name) {
104  $sp_available_fields[$raw_name] = $display_name.' ('.$raw_name.')';
105  }//end foreach
106 
107  $available_fields += $sp_available_fields;
108  }//end if
109 
110  $options = array_get_index($current_search_options, $data_list, Array());
111 
112  ?>
113  <span class="sq-backend-section-subheading" style="margin-left:60px;">Row Limit</span><br />
114  <?php
115  if (!$write_access) {
116  echo '<span style="margin:5 0 20 120px;font-weight:bold;">'.$row_limit.'</span>';
117  } else {
118  text_box($prefix.'_row_limit', $row_limit, 4, '', FALSE, 'style="margin:7 0 20 120px;"');
119  ?><span style="margin-left:0px;">&nbsp;This limit the number of records returned.</span><?php
120  }//end else
121 
122  if (!empty($options)) {
123  ?>
124  <br /><br />
125  <span class="sq-backend-section-subheading" style="margin-left:60px;">Search Logic</span><br />
126  <?php
127  if (!$write_access) {
128  echo '<span style="margin:5 0 20 120px;font-weight:bold;">'.strtoupper($search_logic).'</span>';
129  } else {
130  combo_box($prefix.'_search_logic', Array('And' => 'AND', 'Or' => 'OR'), FALSE, $search_logic, 0, ' style="margin:7 0 20 120px;"');
131  }//end else
132 
133  ?>
134  <br />
135 
136 
137  <p class="sq-backend-section-subheading" style="margin-left:60px;">Criterion</p>
138  <table class="sq-backend-table" style="width:auto; margin-left:120px;">
139  <th>Field Name</th>
140  <th>Operator</th>
141  <th>Value</th>
142  <?php if ($write_access) { ?>
143  <th>Delete?</th>
144  <?php } ?>
145  <?php
146 
147 
148 
149  foreach ($options as $index => $field_info) {
150  $field_name = key($field_info);
151  $crit = $field_info[$field_name];
152  $field_name_info = isset($available_fields[$field_name]) ? $available_fields[$field_name] : '';
153 
154  if ($write_access) {
155  ?>
156  <tr>
157  <td style="width:330px;"><p><?php combo_box($prefix.'_edit_field_name['.$index.']', $available_fields, FALSE, $field_name); ?></p></td>
158  <td><?php combo_box($prefix.'_edit_op['.$index.']', $available_operators, FALSE, $crit['operator']); ?></td>
159  <td><p><?php text_box($prefix.'_edit_val['.$index.']', $crit['value'], 50); ?></p></td>
160  <td><?php check_box($prefix.'_delete_crit['.$data_list.']['.$field_name.']'); ?></td>
161  </tr>
162 
163  <?php
164  } else {
165  ?>
166  <tr>
167  <td style="width:330px;"><p><?php echo $available_fields[$field_name]; ?></p></td>
168  <td align="center"><?php echo $available_operators[$crit['operator']]; ?></td>
169  <td><p><?php echo $crit['value']; ?></p></td>
170  </tr>
171 
172  <?php
173  }// end else
174  }//end foreach
175 
176  ?>
177  </table>
178  <br /><br />
179  <?php
180  }//end if empty current_search_options
181  if ($write_access) {
182  ?>
183  <p class="sq-backend-section-subheading" style="margin-left:60px;">Add New Criteria</p>
184  <table class="sq-backend-table" style="width:auto; margin-left:120px;">
185  <th>Field Name</th>
186  <th>Operator</th>
187  <th>Value</th>
188  <tr>
189  <td style="width:330px;"><?php combo_box($prefix.'_new_search_criteria_field', $available_fields, FALSE); ?></td>
190  <td><?php combo_box($prefix.'_new_search_criteria_operator', $available_operators, FALSE); ?></td>
191  <td><p><?php text_box($prefix.'_new_search_criteria_value', '', 50); ?></p></td>
192  </tr>
193  </table>
194  <?php
195 
196  }//end if
197  ?>
198 
199  <?php
200  $o->closeRaw();
201 
202 
203 
204  return $write_access;
205 
206  }//end paintSearchConfig()
207 
208 
219  function processSearchConfig(&$asset, &$o, $prefix)
220  {
221  $criteria_field = array_get_index($_POST, $prefix.'_new_search_criteria_field', NULL);
222  $criteria_operator = array_get_index($_POST, $prefix.'_new_search_criteria_operator', NULL);
223  $criteria_value = array_get_index($_POST, $prefix.'_new_search_criteria_value', NULL);
224  $search_logic = array_get_index($_POST, $prefix.'_search_logic', 'And');
225  $row_limit = array_get_index($_POST, $prefix.'_row_limit', '');
226 
227 
228  if (!empty($row_limit) && $row_limit > 0) {
229  $asset->setAttrValue('row_limit', $row_limit);
230  }//end if
231 
232  $editing_criterion = array_get_index($_POST, $prefix.'_edit_val', Array());
233  $editing_operator = array_get_index($_POST, $prefix.'_edit_op', Array());
234  $editing_field_name = array_get_index($_POST, $prefix.'_edit_field_name', Array());
235 
236  $current_search_options = $asset->attr('search_options');
237  $current_data_list = $asset->attr('data_list');
238 
239  if (isset($current_search_options[$current_data_list])) {
240  foreach ($current_search_options[$current_data_list] as $index => $field_info) {
241  foreach ($editing_criterion as $edit_val_index => $new_value) {
242  if (isset($current_search_options[$current_data_list][$edit_val_index])) {
243  $field_crit_info_1 = $current_search_options[$current_data_list][$edit_val_index];
244  $field_crit_value = $field_crit_info_1[key($field_crit_info_1)]['value'];
245  if ($field_crit_value != $new_value) {
246  $current_search_options[$current_data_list][$edit_val_index][key($field_crit_info_1)]['value'] = $new_value;
247  }//end if
248  }//end if
249  }//end foreach
250 
251  foreach ($editing_operator as $edit_op_index => $new_operator) {
252  if (isset($current_search_options[$current_data_list][$edit_op_index])) {
253  $field_crit_info_2 = $current_search_options[$current_data_list][$edit_op_index];
254  $field_crit_op = $field_crit_info_2[key($field_crit_info_2)]['operator'];
255  if ($field_crit_op != $new_operator) {
256  $current_search_options[$current_data_list][$edit_op_index][key($field_crit_info_2)]['operator'] = $new_operator;
257  }//end if
258  }//end if
259  }//end foreach
260 
261  foreach ($editing_field_name as $edit_fn_index => $new_field_name) {
262  if (isset($current_search_options[$current_data_list][$edit_fn_index])) {
263  $field_crit_info_3 = $current_search_options[$current_data_list][$edit_fn_index];
264  $field_crit_fn = key($field_crit_info_3);
265  if ($field_crit_fn != $new_field_name) {
266  $current_search_options[$current_data_list][$edit_fn_index][$new_field_name] = $field_crit_info_3[$field_crit_fn];
267  unset($current_search_options[$current_data_list][$edit_fn_index][$field_crit_fn]);
268  }//end if
269  }//end if
270  }//end foreach
271  }//end foreach
272  }//end if
273 
274  $new_data_list = array_get_index($_POST, $prefix.'_data_list', '');
275  if ($new_data_list != $current_data_list && !empty($new_data_list)) {
276  $asset->setAttrValue('data_list', $new_data_list);
277  }//end if
278  $current_data_list = $asset->attr('data_list');
279 
280  if (!empty($criteria_field) && $criteria_field != 'None' && !is_null($criteria_value)) {
281  $new_criteria = Array (
282  'operator' => $criteria_operator,
283  'value' => $criteria_value,
284  );
285 
286  $current_search_options[$current_data_list][] = Array (
287  $criteria_field => $new_criteria,
288  );
289  }//end if
290 
291  $delete_array = array_get_index($_POST, $prefix.'_delete_crit', Array());
292 
293  if (!empty($delete_array) && isset($delete_array[$current_data_list])) {
294  foreach ($current_search_options[$current_data_list] as $index => $field_info) {
295  foreach ($delete_array[$current_data_list] as $remove_field_name => $value) {
296  if (key($field_info) == $remove_field_name) {
297  unset($current_search_options[$current_data_list][$index]);
298  }//end if
299  }//end foreach
300  }//end foreach
301  }//end if
302 
303  $asset->setAttrValue('search_logic', $search_logic);
304  $asset->setAttrValue('search_options', $current_search_options);
305 
306  return TRUE;
307 
308  }//end processSearchConfig()
309 
310 
321  function paintTestConnection(&$asset, &$o, $prefix)
322  {
323  $connection = $asset->getConnection();
324 
325  $wa = $asset->writeAccess('attributes');
326  require_once SQ_PACKAGES_PATH.'/sharepoint/lib/sharepoint_common.inc';
327 
328  $valid = FALSE;
329  if (!empty($connection['url'])) {
330  $valid = Sharepoint_Common::test_sharepoint_connection($connection, TRUE);
331  }//end if
332 
333  if ($valid) {
334  echo '<span style="color:green;font-weight:bold">Connected</span>';
335  } else {
336  echo '<span style="color:red;font-weight:bold">Not Connected</span>';
337  }//end if
338 
339  return $wa;
340 
341  }//end paintTestConnection()
342 
343 
354  function processTestConnection(&$asset, &$o, $prefix)
355  {
356  return FALSE;
357  }//end processTestConnection()
358 
359 
368  function paintSystemUrl(&$asset, &$o, $prefix)
369  {
370  $write_access = $asset->writeAccess('attributes');
371  $wsdl = $asset->attr('url');
372  if ($write_access) {
373  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
374  text_box($prefix.'_sys_url', $wsdl, '35');
375  } else {
376  echo $wsdl;
377  }//end else if
378 
379  return $write_access;
380 
381  }//end paintSystemUrl()
382 
383 
392  function processSystemUrl(&$asset, &$o, $prefix)
393  {
394  if (!$asset->writeAccess('attributes')) return FALSE;
395 
396  $new_name = NULL;
397  $old_wsdl = $asset->attr('url');
398  if (!empty($_POST[$prefix.'_sys_url'])) {
399  $new_wsdl = trim($_POST[$prefix.'_sys_url']);
400  if ($old_wsdl != $new_wsdl) {
401  $res = $asset->setAttrValue('url', $new_wsdl);
402  return TRUE;
403  } else {
404  return FALSE;
405  }
406  }
407  return TRUE;
408 
409  }//end processSystemUrl()
410 
411 
422  function paintConnectorLink(&$asset, &$o, $prefix)
423  {
424  // get root links
425  $connector_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'sharepoint_connector', FALSE, 'sharepoint_connector');
426  if (empty($connector_link)) {
427  $connector_asset_id = NULL;
428  } else {
429  $connector_asset_id = $connector_link['minorid'];
430  }
431 
432  if ($asset->writeAccess('links')) {
433  asset_finder($prefix.'_connector_node', $connector_asset_id, Array('sharepoint_connector'=>'D'));
434  } else {
435  if (empty($connector_asset_id)) {
436  echo 'No connector selected';
437  } else {
438  echo get_asset_tag_line($connector_asset_id);
439  }
440  }
441  return TRUE;
442 
443  }//end paintConnectorLink()
444 
445 
456  function processConnectorLink(&$asset, &$o, $prefix)
457  {
458  $new_connector_id = @$_REQUEST[$prefix.'_connector_node']['assetid'];
459 
460  if (!$asset->writeAccess('links')) {
461  return FALSE;
462  }
463 
464  $current_connector_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'sharepoint_connector', FALSE, 'sharepoint_connector');
465  $current_connector_asset_id = @$current_connector_link['minorid'];
466 
467  if (!empty($current_connector_link)) {
468  // if the new connector id is not null and is equal to the current
469  // connector asset id then return
470  if ((!empty($new_connector_id)) && ($current_connector_asset_id === $new_connector_id)) {
471  return TRUE;
472  } else {
473  // else means that we want to create a new link or we want to
474  // clear the link
475  $GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($current_connector_link['linkid']);
476 
477  // if the new connector id is empty means we want to clear the
478  // link we got nothing else to do so return TRUE
479  if (empty($new_connector_id)) return TRUE;
480  }
481  }
482 
483  if (!empty($new_connector_id)) {
484  $new_connector_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($new_connector_id);
485  $result_id = $GLOBALS['SQ_SYSTEM']->am->createAssetLink($asset, $new_connector_asset, SQ_LINK_NOTICE, 'sharepoint_connector');
486 
487  if (empty($result_id)) {
488  trigger_error('Could not link the connector to this asset', E_USER_WARNING);
489  return FALSE;
490  }
491 
492  }
493 
494  return TRUE;
495 
496  }//end processConnectorLink()
497 
498 
509  function paintListSelection(&$asset, $o, $prefix)
510  {
511  $write_access = $asset->writeAccess('attributes');
512 
513  $current_data_list = $asset->attr('data_list');
514  if ($current_data_list == '') $current_data_list = 'None';
515  $connection = $asset->getConnection();
516  $list_names = Array (
517  'None' => 'None' // We want to keep this option on top
518  );
519 
520  $valid = FALSE;
521  if (isset($connection['url']) && !empty($connection['url'])) {
522  $valid = Sharepoint_Common::test_sharepoint_connection($connection);
523  }//end if
524  if ($valid) {
525  $all_lists = Sharepoint_Common::getListCollections($connection);
526  $sp_lists = Sharepoint_Common::getListNames($connection, $all_lists);
527  $list_names += $sp_lists;
528  }//end if
529 
530  if (!$write_access) {
531  if (isset($list_names[$current_data_list])) {
532  echo $list_names[$current_data_list];
533  }//end if
534  } else {
535  combo_box($prefix.'_data_list', $list_names, FALSE, $current_data_list);
536  }//end else
537 
538  }//end paintListSelection()
539 
540 
551  function processListSelection(&$asset, $o, $prefix)
552  {
553  $write_access = $asset->writeAccess('attributes');
554  if (!$write_access) return FALSE;
555 
556  $new_data_list = array_get_index($_POST, $prefix.'_data_list', '');
557  $current_data_list = $asset->attr('data_list');
558  if ($new_data_list != $current_data_list) {
559  $asset->setAttrValue('data_list', $new_data_list);
560  }//end if
561 
562  return TRUE;
563 
564  }//end processListSeletion()
565 
566 
577  function paintSynchCheck(&$asset, &$o, $prefix)
578  {
579  $wa = $asset->writeAccess('attributes');
580  $o->openRaw();
581  ?>
582  <script type="text/javascript" src="<?php echo sq_web_path('data').'/asset_types/sharepoint_saved_search/js/ajax.js' ?>"></script>
583 
584  <div style="position:relative;top:0px;">
585  <table style="width:auto;border-spacing:0px;" border="0">
586  <tr>
587  <td width="90"><span style="font-weight:bold;">Check Update</span><br /><br /></td>
588  <td width="150"><span id="update_text">Not Checked</span><br /><br /></td>
589  <td><?php //if ($wa) normal_button($prefix.'_update', 'Check for Updates', 'checkUpdate()'); ?><br /><br /></td>
590  <td><?php if ($wa) normal_button($prefix.'_synch', 'Synchronize Now', 'sendRequest(\''.$asset->getURL().'?synch_now=1\', \'updateSynchInterface\');'); ?><br /><br /></td>
591  </tr>
592  </table>
593  </div>
594 
595  <?php
596  $o->closeRaw();
597 
598  }//end paintSynchCheck()
599 
600 
611  function processSynchCheck(&$asset, &$o, $prefix)
612  {
613 
614  }//end processSynchCheck()
615 
616 
627  function paintDownloadFile(&$asset, $o, $prefix)
628  {
629  $write_access = $asset->writeAccess('attributes');
630 
631  $download_file_attr = $asset->attr('download_file');
632  $options = Array (
633  0 => "No",
634  1 => "Yes",
635  );
636  if (!$write_access) {
637  echo $download_file_attr ? "Yes" : "No";
638  } else {
639  combo_box($prefix.'_download_file', $options, FALSE, $download_file_attr);
640  }//end else
641 
642  }//end paintDownloadFile
643 
644 
655  function processDownloadFile(&$asset, $o, $prefix)
656  {
657  $write_access = $asset->writeAccess('attributes');
658  if (!$write_access) return FALSE;
659  $download_file_attr = array_get_index($_POST, $prefix.'_download_file', 1);
660  $current_download_file_attr = $asset->attr('download_file');
661 
662  if ($current_download_file_attr != $download_file_attr) {
663  $asset->setAttrValue('download_file', $download_file_attr);
664  }//end if
665 
666  return TRUE;
667 
668  }//end processDownloadFile()
669 
670 
671 }//end class
672 ?>