Elgg  Version 1.11
friendspicker.php
Go to the documentation of this file.
1 <?php
18 elgg_load_js('elgg.friendspicker');
19 elgg_load_js('jquery.easing');
20 
21 
22 $chararray = elgg_echo('friendspicker:chararray');
23 
24 // Initialise name
25 if (!isset($vars['name'])) {
26  $name = "friend";
27 } else {
28  $name = $vars['name'];
29 }
30 
31 // Are we highlighting default or all?
32 if (empty($vars['highlight'])) {
33  $vars['highlight'] = 'default';
34 }
35 if ($vars['highlight'] != 'all') {
36  $vars['highlight'] = 'default';
37 }
38 
39 // Initialise values
40 if (!isset($vars['value'])) {
41  $vars['value'] = array();
42 } else {
43  if (!is_array($vars['value'])) {
44  $vars['value'] = (int) $vars['value'];
45  $vars['value'] = array($vars['value']);
46  }
47 }
48 
49 // Initialise whether we're calling back or not
50 if (isset($vars['callback'])) {
51  $callback = $vars['callback'];
52 } else {
53  $callback = false;
54 }
55 
56 // We need to count the number of friends pickers on the page.
57 if (!isset($vars['friendspicker'])) {
59  if (!isset($friendspicker)) {
60  $friendspicker = 0;
61  }
62  $friendspicker++;
63 } else {
64  $friendspicker = $vars['friendspicker'];
65 }
66 
67 $users = array();
68 $activeletters = array();
69 
70 // Are we displaying form tags and submit buttons?
71 // (If we've been given a target, then yes! Otherwise, no.)
72 if (isset($vars['formtarget'])) {
73  $formtarget = $vars['formtarget'];
74 } else {
75  $formtarget = false;
76 }
77 
78 // Sort users by letter
79 if (is_array($vars['entities']) && sizeof($vars['entities'])) {
80  foreach($vars['entities'] as $user) {
81  $letter = elgg_strtoupper(elgg_substr($user->name, 0, 1));
82 
83  if (!elgg_substr_count($chararray, $letter)) {
84  $letter = "*";
85  }
86  if (!isset($users[$letter])) {
87  $users[$letter] = array();
88  }
89  $users[$letter][$user->guid] = $user;
90  }
91 }
92 
93 // sort users in letters alphabetically
94 foreach ($users as $letter => $letter_users) {
95  usort($letter_users, create_function('$a, $b', '
96  return strcasecmp($a->name, $b->name);
97  '));
98  $users[$letter] = $letter_users;
99 }
100 
101 if (!$callback) {
102  ?>
103 
104  <div class="friends-picker-main-wrapper">
105 
106  <?php
107 
108  if (isset($vars['content'])) {
109  echo $vars['content'];
110  }
111  ?>
112 
113  <div id="friends-picker_placeholder<?php echo $friendspicker; ?>">
114 
115  <?php
116 }
117 
118 if (!isset($vars['replacement'])) {
119  if ($formtarget) {
120 ?>
121 <?php //@todo JS 1.8: no ?>
122 <script language="text/javascript">
123  $(function() { // onload...do
124  $('#collectionMembersForm<?php echo $friendspicker; ?>').submit(function() {
125  var inputs = [];
126  $(':input', this).each(function() {
127  if (this.type != 'checkbox' || (this.type == 'checkbox' && this.checked != false)) {
128  inputs.push(this.name + '=' + escape(this.value));
129  }
130  });
131  jQuery.ajax({
132  type: "POST",
133  data: inputs.join('&'),
134  url: this.action,
135  success: function(){
136  $('a.collectionmembers<?php echo $friendspicker; ?>').click();
137  }
138 
139  });
140  return false;
141  })
142  })
143 
144  </script>
145 
146 <!-- Collection members form -->
147 <form id="collectionMembersForm<?php echo $friendspicker; ?>" action="<?php echo $formtarget; ?>" method="post"> <!-- action="" method=""> -->
148 
149 <?php
150  echo elgg_view('input/securitytoken');
151  echo elgg_view('input/hidden', array(
152  'name' => 'collection_id',
153  'value' => $vars['collection_id'],
154  ));
155  }
156 ?>
157 
158 <div class="friends-picker-wrapper">
159 <div id="friends-picker<?php echo $friendspicker; ?>">
160  <div class="friends-picker-container">
161 <?php
162 
163 // Initialise letters
164  $chararray .= "*";
165  $letter = elgg_substr($chararray, 0, 1);
166  $letpos = 0;
167  while (1 == 1) {
168  ?>
169  <div class="panel" title="<?php echo $letter; ?>">
170  <div class="wrapper">
171  <h3><?php echo $letter; ?></h3>
172  <?php
173 
174  if (isset($users[$letter])) {
175  ksort($users[$letter]);
176 
177  echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
178  $col = 0;
179 
180  foreach($users[$letter] as $friend) {
181  if ($col == 0) {
182  echo "<tr>";
183  }
184 
185  //echo "<p>" . $user->name . "</p>";
186  $label = elgg_view_entity_icon($friend, 'tiny', array('use_hover' => false));
187  $options[$label] = $friend->getGUID();
188 
189  if ($vars['highlight'] == 'all' && !in_array($letter,$activeletters)) {
190  $activeletters[] = $letter;
191  }
192 
193 
194  if (in_array($friend->getGUID(),$vars['value'])) {
195  $checked = "checked = \"checked\"";
196  if (!in_array($letter,$activeletters) && $vars['highlight'] == 'default') {
197  $activeletters[] = $letter;
198  }
199  } else {
200  $checked = "";
201  }
202  ?>
203 
204  <td>
205 
206  <input type="checkbox" <?php echo $checked; ?> name="<?php echo $name; ?>[]" value="<?php echo $options[$label]; ?>" />
207 
208  </td>
209 
210  <td>
211 
212  <div style="width: 25px; margin-bottom: 15px;">
213  <?php
214  echo $label;
215  ?>
216  </div>
217  </td>
218  <td style="width: 200px; padding: 5px;">
219  <?php echo $friend->name; ?>
220  </td>
221  <?php
222  $col++;
223  if ($col == 3){
224  echo "</tr>";
225  $col = 0;
226  }
227  }
228  if ($col < 3) {
229  echo "</tr>";
230  }
231 
232  echo "</table>";
233  }
234 
235 ?>
236 
237  </div>
238  </div>
239 <?php
240 
241  $substr = elgg_substr($chararray, elgg_strlen($chararray) - 1, 1);
242  if ($letter == $substr) {
243  break;
244  }
245  //$letter++;
246  $letpos++;
247  $letter = elgg_substr($chararray, $letpos, 1);
248  }
249 
250 ?>
251  </div>
252 
253 <?php
254 
255 if ($formtarget) {
256 
257  if (isset($vars['formcontents']))
258  echo $vars['formcontents'];
259 
260 ?>
261  <div class="clearfix"></div>
262  <div class="friendspicker-savebuttons">
263  <input type="submit" class="elgg-button elgg-button-submit" value="<?php echo elgg_echo('save'); ?>" />
264  <input type="button" class="elgg-button elgg-button-cancel" value="<?php echo elgg_echo('cancel'); ?>" onclick="$('a.collectionmembers<?php echo $friendspicker; ?>').click();" />
265  <br /></div>
266  </form>
267 
268 <?php
269 
270 }
271 
272 ?>
273 
274 </div>
275 </div>
276 
277 <?php
278 } else {
279  echo $vars['replacement'];
280 }
281 if (!$callback) {
282 
283 ?>
284 
285 </div>
286 </div>
287 
288 
289 <?php
290 
291 }
292 
293 if (!isset($vars['replacement'])) {
294 ?>
295 <?php //@todo JS 1.8: no ?>
296 <script type="text/javascript">
297  // initialise picker
298  $("div#friends-picker<?php echo $friendspicker; ?>").friendsPicker(<?php echo $friendspicker; ?>);
299 </script>
300 <script type="text/javascript">
301 $(document).ready(function () {
302 // manually add class to corresponding tab for panels that have content
303 <?php
304 if (sizeof($activeletters) > 0)
305  //$chararray = elgg_echo('friendspicker:chararray');
306  foreach($activeletters as $letter) {
307  $tab = elgg_strpos($chararray, $letter) + 1;
308 ?>
309 $("div#friends-picker-navigation<?php echo $friendspicker; ?> li.tab<?php echo $tab; ?> a").addClass("tabHasContent");
310 <?php
311  }
312 
313 ?>
314 });
315 </script>
316 
317 <?php
318 
319 }
elgg message elgg state success
Definition: admin.php:252
ui datepicker title
Definition: admin.php:616
content header options form
Definition: admin.php:582
elgg_strtoupper()
Wrapper function for mb_strtoupper().
Definition: mb_wrapper.php:191
$activeletters
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
$friend
Definition: add.php:11
fieldset div
Definition: admin.php:470
$chararray
elgg_strlen()
Wrapper function for mb_strlen().
Definition: mb_wrapper.php:72
$options
Definition: index.php:14
elgg button submit
Definition: admin.php:545
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
GNU GENERAL PUBLIC LICENSE June Free Software Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license document
Definition: LICENSE.txt:4
if(!$members) $friendspicker
$users
Definition: newest.php:3
elgg_strpos()
Wrapper function for mb_strpos().
Definition: mb_wrapper.php:89
$user
Definition: ban.php:13
elgg echo
Translates a string.
Definition: languages.js:43
elgg global
Pointer to the global context.
Definition: elgglib.js:12
elgg_view($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
Return a parsed view.
Definition: views.php:354
function elgg combo checkbox click(function(){if($(this).is(':checked')){$(this).prev().attr('disabled', true);$(this).prev().val('');}else{$(this).prev().attr('disabled', false);}})
jQuery fn friendsPicker
td
Definition: admin.php:63
elgg_substr()
Wrapper function for mb_substr().
Definition: mb_wrapper.php:225
$site name
list style
Definition: admin.php:1174
$label
Elgg profile plugin edit default profile action.
Definition: add.php:7
elgg_load_js($name)
Load a JavaScript resource on this page.
Definition: elgglib.php:189
document ready(function(){$(document).on('click',"[data-toggle='wy-nav-top']", function(){$("[data-toggle='wy-nav-shift']").toggleClass("shift");$("[data-toggle='rst-versions']").toggleClass("shift");});$(document).on('click',".wy-menu-vertical .current ul li a", function(){$("[data-toggle='wy-nav-shift']").removeClass("shift");$("[data-toggle='rst-versions']").toggleClass("shift");});$(document).on('click',"[data-toggle='rst-current-version']", function(){$("[data-toggle='rst-versions']").toggleClass("shift-up");});$("table.docutils:not(.field-list)").wrap("<div class='wy-table-responsive'></div>");})
$CONFIG language
The current language for either the site or the user.
Definition: config.php:108
if(!$site) if(!($site instanceof ElggSite)) $site url
elgg_substr_count()
Wrapper function for mb_substr_count().
Definition: mb_wrapper.php:208
list style type
Definition: admin.php:748
elgg_view_entity_icon(\ElggEntity $entity, $size= 'medium', $vars=array())
View the icon of an entity.
Definition: views.php:865
elgg table input[type=checkbox]
Definition: admin.php:400
h3
Definition: admin.php:85
elgg action
Definition: ajax.js:197
if(file_exists($welcome)) $vars
Definition: upgrade.php:93