[ Index ]

PHP Cross Reference of MyBB 1.8.32

title

Body

[close]

/admin/inc/ -> functions_view_manager.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  /**
  12   * Builds the "view management" interface allowing administrators to edit their custom designed "views"
  13   *
  14   * @param string $base_url The base URL to this instance of the view manager
  15   * @param string $type The internal type identifier for this view
  16   * @param array $fields Array of fields this view supports
  17   * @param array $sort_options Array of possible sort options this view supports if any
  18   * @param string $conditions_callback Optional callback function which generates list of "conditions" for this view
  19   */
  20  function view_manager($base_url, $type, $fields, $sort_options=array(), $conditions_callback="")
  21  {
  22      global $mybb, $db, $page, $lang;
  23  
  24      $sub_tabs['views'] = array(
  25          'title' => $lang->views,
  26          'link' => "{$base_url}&amp;action=views",
  27          'description' => $lang->views_desc
  28      );
  29  
  30      $sub_tabs['create_view'] = array(
  31          'title' => $lang->create_new_view,
  32          'link' => "{$base_url}&amp;action=views&amp;do=add",
  33          'description' => $lang->create_new_view_desc
  34      );
  35  
  36      $page->add_breadcrumb_item($lang->view_manager, 'index.php?module=user-users&amp;action=views');
  37  
  38      // Lang strings should be in global lang file
  39  
  40      if($mybb->input['do'] == "set_default")
  41      {
  42          $query = $db->simple_select("adminviews", "vid, uid, visibility", "vid='".$mybb->get_input('vid', MyBB::INPUT_INT)."'");
  43          $admin_view = $db->fetch_array($query);
  44  
  45          if(!$admin_view['vid'] || $admin_view['visibility'] == 1 && $mybb->user['uid'] != $admin_view['uid'])
  46          {
  47              flash_message($lang->error_invalid_admin_view, 'error');
  48              admin_redirect($base_url."&action=views");
  49          }
  50          set_default_view($type, $admin_view['vid']);
  51          flash_message($lang->succuss_view_set_as_default, 'success');
  52          admin_redirect($base_url."&action=views");
  53      }
  54  
  55      $errors = array();
  56      if($mybb->input['do'] == "add")
  57      {
  58          if($mybb->request_method == "post")
  59          {
  60              if(!trim($mybb->input['title']))
  61              {
  62                  $errors[] = $lang->error_missing_view_title;
  63              }
  64              if($mybb->input['fields_js'])
  65              {
  66                  $mybb->input['fields'] = explode(",", $mybb->input['fields_js']);
  67              }
  68              if(!isset($mybb->input['fields']) || !is_array($mybb->input['fields']) || count($mybb->input['fields']) <= 0)
  69              {
  70                  $errors[] = $lang->error_no_view_fields;
  71              }
  72  
  73              if($mybb->get_input('perpage', MyBB::INPUT_INT) <= 0)
  74              {
  75                  $errors[] = $lang->error_invalid_view_perpage;
  76              }
  77  
  78              if(!in_array($mybb->input['sortby'], array_keys($sort_options)))
  79              {
  80                  $errors[] = $lang->error_invalid_view_sortby;
  81              }
  82  
  83              if($mybb->input['sortorder'] != "asc" && $mybb->input['sortorder'] != "desc")
  84              {
  85                  $errors[] = $lang->error_invalid_view_sortorder;
  86              }
  87  
  88              if($mybb->input['visibility'] == 0)
  89              {
  90                  $mybb->input['visibility'] = 2;
  91              }
  92  
  93              if(empty($errors))
  94              {
  95                  $new_view = array(
  96                      "uid" => $mybb->user['uid'],
  97                      "title" => $db->escape_string($mybb->input['title']),
  98                      "type" => $type,
  99                      "visibility" => $mybb->get_input('visibility', MyBB::INPUT_INT),
 100                      "fields" => $db->escape_string(my_serialize($mybb->input['fields'])),
 101                      "conditions" => $db->escape_string(my_serialize($mybb->input['conditions'])),
 102                      "custom_profile_fields" => $db->escape_string(my_serialize($mybb->input['profile_fields'])),
 103                      "sortby" => $db->escape_string($mybb->input['sortby']),
 104                      "sortorder" => $db->escape_string($mybb->input['sortorder']),
 105                      "perpage" => $mybb->get_input('perpage', MyBB::INPUT_INT),
 106                      "view_type" => $db->escape_string($mybb->input['view_type'])
 107                  );
 108  
 109                  $vid = $db->insert_query("adminviews", $new_view);
 110  
 111                  if($mybb->input['isdefault'])
 112                  {
 113                      set_default_view($type, $vid);
 114                  }
 115                  flash_message($lang->success_view_created, "success");
 116                  admin_redirect($base_url."&vid={$vid}");
 117              }
 118          }
 119          else
 120          {
 121              $mybb->input = array_merge($mybb->input, array('perpage' => 20));
 122          }
 123  
 124          // Write in our JS based field selector
 125          $page->extra_header .= "<script src=\"jscripts/view_manager.js\" type=\"text/javascript\"></script>\n";
 126  
 127          $page->add_breadcrumb_item($lang->create_new_view);
 128          $page->output_header($lang->create_new_view);
 129  
 130          $form = new Form($base_url."&amp;action=views&amp;do=add", "post");
 131  
 132          $page->output_nav_tabs($sub_tabs, 'create_view');
 133  
 134          // If we have any error messages, show them
 135          if(!empty($errors))
 136          {
 137              $page->output_inline_error($errors);
 138          }
 139  
 140          $form_container = new FormContainer($lang->create_new_view);
 141          $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $mybb->get_input('title'), array('id' => 'title')), 'title');
 142  
 143          $visibility_public_checked = $mybb->get_input('visibility') == 2;
 144          $visibility_private_checked = !$visibility_public_checked;
 145  
 146          $visibility_options = array(
 147              $form->generate_radio_button("visibility", "1", "<strong>{$lang->private}</strong> - {$lang->private_desc}", array("checked" => $visibility_private_checked)),
 148              $form->generate_radio_button("visibility", "2", "<strong>{$lang->public}</strong> - {$lang->public_desc}", array("checked" => $visibility_public_checked))
 149          );
 150          $form_container->output_row($lang->visibility, "", implode("<br />", $visibility_options));
 151  
 152          $form_container->output_row($lang->set_as_default_view, "", $form->generate_yes_no_radio("isdefault", $mybb->get_input('isdefault'), array('yes' => 1, 'no' => 0)));
 153  
 154          if(count($sort_options) > 0)
 155          {
 156              $sort_directions = array(
 157                  "asc" => $lang->ascending,
 158                  "desc" => $lang->descending
 159              );
 160              $form_container->output_row($lang->sort_results_by, "", $form->generate_select_box('sortby', $sort_options, $mybb->get_input('sortby'), array('id' => 'sortby'))." {$lang->in} ".$form->generate_select_box('sortorder', $sort_directions, $mybb->get_input('sortorder'), array('id' => 'sortorder')), 'sortby');
 161          }
 162  
 163          $form_container->output_row($lang->results_per_page, "", $form->generate_numeric_field('perpage', $mybb->get_input('perpage'), array('id' => 'perpage', 'min' => 1)), 'perpage');
 164  
 165          if($type == "user")
 166          {
 167              $form_container->output_row($lang->display_results_as, "", $form->generate_radio_button('view_type', 'table', $lang->table, array('checked' => ($mybb->get_input('view_type') != "card" ? true : false)))."<br />".$form->generate_radio_button('view_type', 'card', $lang->business_card, array('checked' => ($mybb->get_input('view_type') == "card" ? true : false))));
 168          }
 169  
 170          $form_container->end();
 171  
 172          $active = array();
 173  
 174          $field_select = "<div class=\"view_fields\">\n";
 175          $field_select .= "<div class=\"enabled\"><div class=\"fields_title\">{$lang->enabled}</div><ul id=\"fields_enabled\">\n";
 176          if(isset($mybb->input['fields']) && is_array($mybb->input['fields']))
 177          {
 178              foreach($mybb->input['fields'] as $field)
 179              {
 180                  if($fields[$field])
 181                  {
 182                      $field_select .= "<li id=\"field-{$field}\">&#149; {$fields[$field]['title']}</li>";
 183                      $active[$field] = 1;
 184                  }
 185              }
 186          }
 187          $field_select .= "</ul></div>\n";
 188          $field_select .= "<div class=\"disabled\"><div class=\"fields_title\">{$lang->disabled}</div><ul id=\"fields_disabled\">\n";
 189          foreach($fields as $key => $field)
 190          {
 191              if(!empty($active[$key]))
 192              {
 193                  continue;
 194              }
 195              $field_select .= "<li id=\"field-{$key}\">&#149; {$field['title']}</li>";
 196          }
 197          $field_select .= "</div></ul>\n";
 198          $field_select .= $form->generate_hidden_field("fields_js", @implode(",", @array_keys($active)), array('id' => 'fields_js'));
 199          $field_select = str_replace("'", "\\'", $field_select);
 200          $field_select = str_replace("\n", "", $field_select);
 201  
 202          $field_select = "<script type=\"text/javascript\">
 203  //<![CDATA[
 204  document.write('".str_replace("/", "\/", $field_select)."');
 205  //]]>
 206  </script>\n";
 207  
 208          foreach($fields as $key => $field)
 209          {
 210              $field_options[$key] = $field['title'];
 211          }
 212  
 213          $field_select .= "<noscript>".$form->generate_select_box('fields[]', $field_options, $mybb->get_input('fields'), array('id' => 'fields', 'multiple' => true))."</noscript>\n";
 214  
 215          $form_container = new FormContainer($lang->fields_to_show);
 216          $form_container->output_row($lang->fields_to_show_desc, '', $field_select);
 217          $form_container->end();
 218  
 219          // Build the search conditions
 220          if(function_exists($conditions_callback))
 221          {
 222              $conditions_callback($mybb->input, $form);
 223          }
 224  
 225          $buttons[] = $form->generate_submit_button($lang->save_view);
 226          $form->output_submit_wrapper($buttons);
 227  
 228          $form->end();
 229          $page->output_footer();
 230      }
 231      else if($mybb->input['do'] == "edit")
 232      {
 233          $query = $db->simple_select("adminviews", "*", "vid='".$mybb->get_input('vid', MyBB::INPUT_INT)."'");
 234          $admin_view = $db->fetch_array($query);
 235  
 236          // Does the view not exist?
 237          if(!$admin_view['vid'] || $admin_view['visibility'] == 1 && $mybb->user['uid'] != $admin_view['uid'])
 238          {
 239              flash_message($lang->error_invalid_admin_view, 'error');
 240              admin_redirect($base_url."&action=views");
 241          }
 242  
 243          if($mybb->request_method == "post")
 244          {
 245              if(!trim($mybb->input['title']))
 246              {
 247                  $errors[] = $lang->error_missing_view_title;
 248              }
 249              if($mybb->input['fields_js'])
 250              {
 251                  $mybb->input['fields'] = explode(",", $mybb->input['fields_js']);
 252              }
 253  
 254              if(!is_array($mybb->input['fields']) || count($mybb->input['fields']) <= 0)
 255              {
 256                  $errors[] = $lang->error_no_view_fields;
 257              }
 258  
 259              if($mybb->get_input('perpage', MyBB::INPUT_INT) <= 0)
 260              {
 261                  $errors[] = $lang->error_invalid_view_perpage;
 262              }
 263  
 264              if(!in_array($mybb->input['sortby'], array_keys($sort_options)))
 265              {
 266                  $errors[] = $lang->error_invalid_view_sortby;
 267              }
 268  
 269              if($mybb->input['sortorder'] != "asc" && $mybb->input['sortorder'] != "desc")
 270              {
 271                  $errors[] = $lang->error_invalid_view_sortorder;
 272              }
 273  
 274              if($mybb->input['visibility'] == 0)
 275              {
 276                  $mybb->input['visibility'] = 2;
 277              }
 278  
 279              if(empty($errors))
 280              {
 281                  $updated_view = array(
 282                      "title" => $db->escape_string($mybb->input['title']),
 283                      "type" => $type,
 284                      "visibility" => $mybb->get_input('visibility', MyBB::INPUT_INT),
 285                      "fields" => $db->escape_string(my_serialize($mybb->input['fields'])),
 286                      "conditions" => $db->escape_string(my_serialize($mybb->input['conditions'])),
 287                      "custom_profile_fields" => $db->escape_string(my_serialize($mybb->input['profile_fields'])),
 288                      "sortby" => $db->escape_string($mybb->input['sortby']),
 289                      "sortorder" => $db->escape_string($mybb->input['sortorder']),
 290                      "perpage" => $mybb->get_input('perpage', MyBB::INPUT_INT),
 291                      "view_type" => $db->escape_string($mybb->input['view_type'])
 292                  );
 293                  $db->update_query("adminviews", $updated_view, "vid='{$admin_view['vid']}'");
 294  
 295                  if($mybb->input['isdefault'])
 296                  {
 297                      set_default_view($type, $admin_view['vid']);
 298                  }
 299  
 300                  flash_message($lang->success_view_updated, "success");
 301                  admin_redirect($base_url."&vid={$admin_view['vid']}");
 302              }
 303          }
 304  
 305          // Write in our JS based field selector
 306          $page->extra_header .= "<script src=\"jscripts/view_manager.js\" type=\"text/javascript\"></script>\n";
 307  
 308          $page->add_breadcrumb_item($lang->edit_view);
 309          $page->output_header($lang->edit_view);
 310  
 311          $form = new Form($base_url."&amp;action=views&amp;do=edit&amp;vid={$admin_view['vid']}", "post");
 312  
 313          $sub_tabs = array();
 314          $sub_tabs['edit_view'] = array(
 315              'title' => $lang->edit_view,
 316              'link' => $base_url."&amp;action=views&amp;do=edit&amp;vid={$admin_view['vid']}",
 317              'description' => $lang->edit_view_desc
 318          );
 319  
 320          $page->output_nav_tabs($sub_tabs, 'edit_view');
 321  
 322          // If we have any error messages, show them
 323          if(!empty($errors))
 324          {
 325              $page->output_inline_error($errors);
 326          }
 327          else
 328          {
 329              $admin_view['conditions'] = my_unserialize($admin_view['conditions']);
 330              $admin_view['fields'] = my_unserialize($admin_view['fields']);
 331              $admin_view['profile_fields'] = my_unserialize($admin_view['custom_profile_fields']);
 332              $mybb->input = array_merge($mybb->input, $admin_view);
 333  
 334              $mybb->input['isdefault'] = 0;
 335              $default_view = fetch_default_view($type);
 336  
 337              if($default_view == $admin_view['vid'])
 338              {
 339                  $mybb->input['isdefault'] = 1;
 340              }
 341          }
 342  
 343          $form_container = new FormContainer($lang->edit_view);
 344          $form_container->output_row($lang->view." <em>*</em>", "", $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title');
 345  
 346          $visibility_public_checked = $mybb->input['visibility'] == 2;
 347          $visibility_private_checked = !$visibility_public_checked;
 348  
 349          $visibility_options = array(
 350              $form->generate_radio_button("visibility", "1", "<strong>{$lang->private}</strong> - {$lang->private_desc}", array("checked" => $visibility_private_checked)),
 351              $form->generate_radio_button("visibility", "2", "<strong>{$lang->public}</strong> - {$lang->public_desc}", array("checked" => $visibility_public_checked))
 352          );
 353          $form_container->output_row($lang->visibility, "", implode("<br />", $visibility_options));
 354  
 355          $form_container->output_row($lang->set_as_default_view, "", $form->generate_yes_no_radio("isdefault", $mybb->input['isdefault'], array('yes' => 1, 'no' => 0)));
 356  
 357          if(is_array($sort_options) && count($sort_options) > 0)
 358          {
 359              $sort_directions = array(
 360                  "asc" => $lang->ascending,
 361                  "desc" => $lang->descending
 362              );
 363              $form_container->output_row($lang->sort_results_by, "", $form->generate_select_box('sortby', $sort_options, $mybb->input['sortby'], array('id' => 'sortby'))." {$lang->in} ".$form->generate_select_box('sortorder', $sort_directions, $mybb->input['sortorder'], array('id' => 'sortorder')), 'sortby');
 364          }
 365  
 366          $form_container->output_row($lang->results_per_page, "", $form->generate_numeric_field('perpage', $mybb->input['perpage'], array('id' => 'perpage', 'min' => 1)), 'perpage');
 367  
 368          if($type == "user")
 369          {
 370              $form_container->output_row($lang->display_results_as, "", $form->generate_radio_button('view_type', 'table', $lang->table, array('checked' => ($mybb->input['view_type'] != "card" ? true : false)))."<br />".$form->generate_radio_button('view_type', 'card', $lang->business_card, array('checked' => ($mybb->input['view_type'] == "card" ? true : false))));
 371          }
 372  
 373          $form_container->end();
 374  
 375          $field_select = "<div class=\"view_fields\">\n";
 376          $field_select .= "<div class=\"enabled\"><div class=\"fields_title\">{$lang->enabled}</div><ul id=\"fields_enabled\">\n";
 377          if(is_array($mybb->input['fields']))
 378          {
 379              foreach($mybb->input['fields'] as $field)
 380              {
 381                  if($fields[$field])
 382                  {
 383                      $field_select .= "<li id=\"field-{$field}\">&#149; {$fields[$field]['title']}</li>";
 384                      $active[$field] = 1;
 385                  }
 386              }
 387          }
 388          $field_select .= "</ul></div>\n";
 389          $field_select .= "<div class=\"disabled\"><div class=\"fields_title\">{$lang->disabled}</div><ul id=\"fields_disabled\">\n";
 390          if(is_array($fields))
 391          {
 392              foreach($fields as $key => $field)
 393              {
 394                  if(!empty($active[$key]))
 395                  {
 396                      continue;
 397                  }
 398                  $field_select .= "<li id=\"field-{$key}\">&#149; {$field['title']}</li>";
 399              }
 400          }
 401          $field_select .= "</div></ul>\n";
 402          $field_select .= $form->generate_hidden_field("fields_js", @implode(",", @array_keys($active)), array('id' => 'fields_js'));
 403          $field_select = str_replace("'", "\\'", $field_select);
 404          $field_select = str_replace("\n", "", $field_select);
 405  
 406          $field_select = "<script type=\"text/javascript\">
 407  //<![CDATA[
 408  document.write('".str_replace("/", "\/", $field_select)."');
 409  //]]></script>\n";
 410  
 411          foreach($fields as $key => $field)
 412          {
 413              $field_options[$key] = $field['title'];
 414          }
 415  
 416          $field_select .= "<noscript>".$form->generate_select_box('fields[]', $field_options, $mybb->input['fields'], array('id' => 'fields', 'multiple' => true))."</noscript>\n";
 417  
 418          $form_container = new FormContainer($lang->fields_to_show);
 419          $form_container->output_row($lang->fields_to_show_desc, '', $field_select);
 420          $form_container->end();
 421  
 422          // Build the search conditions
 423          if(function_exists($conditions_callback))
 424          {
 425              $conditions_callback($mybb->input, $form);
 426          }
 427  
 428          $buttons[] = $form->generate_submit_button($lang->save_view);
 429          $form->output_submit_wrapper($buttons);
 430  
 431          $form->end();
 432          $page->output_footer();
 433      }
 434  
 435      else if($mybb->input['do'] == "delete")
 436      {
 437          if($mybb->get_input('no'))
 438          {
 439              admin_redirect($base_url."&action=views");
 440          }
 441  
 442          $query = $db->simple_select("adminviews", "COUNT(vid) as views");
 443          $views = $db->fetch_field($query, "views");
 444  
 445          if($views == 0)
 446          {
 447              flash_message($lang->error_cannot_delete_view, 'error');
 448              admin_redirect($base_url."&action=views");
 449          }
 450  
 451          $vid = $mybb->get_input('vid', MyBB::INPUT_INT);
 452          $query = $db->simple_select("adminviews", "vid, uid, visibility", "vid = '{$vid}'");
 453          $admin_view = $db->fetch_array($query);
 454  
 455          if($vid == 1 || !$admin_view['vid'] || $admin_view['visibility'] == 1 && $mybb->user['uid'] != $admin_view['uid'])
 456          {
 457              flash_message($lang->error_invalid_view_delete, 'error');
 458              admin_redirect($base_url."&action=views");
 459          }
 460  
 461          if($mybb->request_method == "post")
 462          {
 463              $db->delete_query("adminviews", "vid='{$admin_view['vid']}'");
 464              flash_message($lang->success_view_deleted, 'success');
 465              admin_redirect($base_url."&action=views");
 466          }
 467          else
 468          {
 469              $page->output_confirm_action($base_url."&amp;action=views&amp;do=delete&amp;vid={$admin_view['vid']}", $lang->confirm_view_deletion);
 470          }
 471      }
 472  
 473      // Export views
 474      else if($mybb->input['do'] == "export")
 475      {
 476          $xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?".">\n";
 477          $xml = "<adminviews version=\"".$mybb->version_code."\" exported=\"".TIME_NOW."\">\n";
 478  
 479          if($mybb->input['type'])
 480          {
 481              $type_where = "type='".$db->escape_string($mybb->input['type'])."'";
 482          }
 483  
 484          $query = $db->simple_select("adminviews", "*", $type_where);
 485          while($admin_view = $db->fetch_array($query))
 486          {
 487              $fields = my_unserialize($admin_view['fields']);
 488              $conditions = my_unserialize($admin_view['conditions']);
 489  
 490              $admin_view['title'] = str_replace(']]>', ']]]]><![CDATA[>', $admin_view['title']);
 491              $admin_view['sortby'] = str_replace(']]>', ']]]]><![CDATA[>', $admin_view['sortby']);
 492              $admin_view['sortorder'] = str_replace(']]>', ']]]]><![CDATA[>', $admin_view['sortorder']);
 493              $admin_view['view_type'] = str_replace(']]>', ']]]]><![CDATA[>', $admin_view['view_type']);
 494  
 495              $xml .= "\t<view vid=\"{$admin_view['vid']}\" uid=\"{$admin_view['uid']}\" type=\"{$admin_view['type']}\" visibility=\"{$admin_view['visibility']}\">\n";
 496              $xml .= "\t\t<title><![CDATA[{$admin_view['title']}]]></title>\n";
 497              $xml .= "\t\t<fields>\n";
 498              foreach($fields as $field)
 499              {
 500                  $xml .= "\t\t\t<field name=\"{$field}\" />\n";
 501              }
 502              $xml .= "\t\t</fields>\n";
 503              $xml .= "\t\t<conditions>\n";
 504              foreach($conditions as $name => $condition)
 505              {
 506                  if(!$conditions) continue;
 507                  if(is_array($condition))
 508                  {
 509                      $condition = my_serialize($condition);
 510                      $is_serialized = " is_serialized=\"1\"";
 511                  }
 512                  $condition = str_replace(']]>', ']]]]><![CDATA[>', $condition);
 513                  $xml .= "\t\t\t<condition name=\"{$name}\"{$is_serialized}><![CDATA[{$condition}]]></condition>\n";
 514              }
 515              $xml .= "\t\t</conditions>\n";
 516              $xml .= "\t\t<sortby><![CDATA[{$admin_view['sortby']}]]></sortby>\n";
 517              $xml .= "\t\t<sortorder><![CDATA[{$admin_view['sortorder']}]]></sortorder>\n";
 518              $xml .= "\t\t<perpage><![CDATA[{$admin_view['perpage']}]]></perpage>\n";
 519              $xml .= "\t\t<view_type><![CDATA[{$admin_view['view_type']}]]></view_type>\n";
 520              $xml .= "\t</view>\n";
 521          }
 522          $xml .= "</adminviews>\n";
 523          $mybb->settings['bbname'] = urlencode($mybb->settings['bbname']);
 524          header("Content-disposition: filename=".$mybb->settings['bbname']."-views.xml");
 525          header("Content-Length: ".my_strlen($xml));
 526          header("Content-type: unknown/unknown");
 527          header("Pragma: no-cache");
 528          header("Expires: 0");
 529          echo $xml;
 530          exit;
 531      }
 532  
 533      // Generate a listing of all current views
 534      else
 535      {
 536          $page->output_header($lang->view_manager);
 537  
 538          $page->output_nav_tabs($sub_tabs, 'views');
 539  
 540          $table = new Table;
 541          $table->construct_header($lang->view);
 542          $table->construct_header($lang->controls, array("class" => "align_center", "width" => 150));
 543  
 544          $default_view = fetch_default_view($type);
 545  
 546          $query = $db->simple_select("adminviews", "COUNT(vid) as views");
 547          $views = $db->fetch_field($query, "views");
 548  
 549          $query = $db->query("
 550              SELECT v.*, u.username
 551              FROM ".TABLE_PREFIX."adminviews v
 552              LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=v.uid)
 553              WHERE v.visibility='2' OR (v.visibility='1' AND v.uid='{$mybb->user['uid']}')
 554              ORDER BY title
 555          ");
 556          while($view = $db->fetch_array($query))
 557          {
 558              $created = "";
 559              if($view['uid'] == 0)
 560              {
 561                  $view_type = "default";
 562                  $default_class = "grey";
 563              }
 564              else if($view['visibility'] == 2)
 565              {
 566                  $view_type = "group";
 567                  if($view['username'])
 568                  {
 569                      $username = htmlspecialchars_uni($view['username']);
 570                      $created = "<br /><small>{$lang->created_by} {$username}</small>";
 571                  }
 572              }
 573              else
 574              {
 575                  $view_type = "user";
 576              }
 577  
 578              $default_add = '';
 579              if($default_view == $view['vid'])
 580              {
 581                  $default_add = " ({$lang->default})";
 582              }
 583  
 584              $title_string = "view_title_{$view['vid']}";
 585  
 586              if(isset($lang->$title_string))
 587              {
 588                  $view['title'] = $lang->$title_string;
 589              }
 590  
 591              $table->construct_cell("<div class=\"float_right\"><img src=\"styles/{$page->style}/images/icons/{$view_type}.png\" title=\"".$lang->sprintf($lang->this_is_a_view, $view_type)."\" alt=\"{$view_type}\" /></div><div class=\"{$default_class}\"><strong><a href=\"{$base_url}&amp;action=views&amp;do=edit&amp;vid={$view['vid']}\" >{$view['title']}</a></strong>{$default_add}{$created}</div>");
 592  
 593              $popup = new PopupMenu("view_{$view['vid']}", $lang->options);
 594              $popup->add_item($lang->edit_view, "{$base_url}&amp;action=views&amp;do=edit&amp;vid={$view['vid']}");
 595              if($view['vid'] != $default_view)
 596              {
 597                  $popup->add_item($lang->set_as_default, "{$base_url}&amp;action=views&amp;do=set_default&amp;vid={$view['vid']}");
 598              }
 599  
 600              if($views > 1 && $view['vid'] != 1)
 601              {
 602                  $popup->add_item($lang->delete_view, "{$base_url}&amp;action=views&amp;do=delete&amp;vid={$view['vid']}&amp;my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_view_deletion}')");
 603              }
 604              $controls = $popup->fetch();
 605              $table->construct_cell($controls, array("class" => "align_center"));
 606              $table->construct_row();
 607          }
 608  
 609          $table->output($lang->view);
 610  
 611          echo <<<LEGEND
 612  <br />
 613  <fieldset>
 614  <legend>{$lang->legend}</legend>
 615  <img src="styles/{$page->style}/images/icons/default.png" alt="{$lang->default}" style="vertical-align: middle;" /> {$lang->default_view_desc}<br />
 616  <img src="styles/{$page->style}/images/icons/group.png" alt="{$lang->public}" style="vertical-align: middle;" /> {$lang->public_view_desc}<br />
 617  <img src="styles/{$page->style}/images/icons/user.png" alt="{$lang->private}" style="vertical-align: middle;" /> {$lang->private_view_desc}</fieldset>
 618  LEGEND;
 619          $page->output_footer();
 620      }
 621  }
 622  
 623  function set_default_view($type, $vid)
 624  {
 625      global $mybb, $db;
 626  
 627      $query = $db->simple_select("adminoptions", "defaultviews", "uid='{$mybb->user['uid']}'");
 628      $default_views = my_unserialize($db->fetch_field($query, "defaultviews"));
 629      $create = !$db->num_rows($query);
 630  
 631      $default_views[$type] = $vid;
 632      $default_views = my_serialize($default_views);
 633      $updated_admin = array("defaultviews" => $db->escape_string($default_views));
 634  
 635      if($create == true)
 636      {
 637          $updated_admin['uid'] = $mybb->user['uid'];
 638          $updated_admin['notes'] = '';
 639          $updated_admin['permissions'] = '';
 640          $db->insert_query("adminoptions", $updated_admin);
 641      }
 642      else
 643      {
 644          $db->update_query("adminoptions", $updated_admin, "uid='{$mybb->user['uid']}'");
 645      }
 646  }
 647  
 648  /**
 649   * @param string $type
 650   *
 651   * @return bool|array
 652   */
 653  function fetch_default_view($type)
 654  {
 655      global $mybb, $db;
 656      $query = $db->simple_select("adminoptions", "defaultviews", "uid='{$mybb->user['uid']}'");
 657      $default_views = my_unserialize($db->fetch_field($query, "defaultviews"));
 658      if(!is_array($default_views))
 659      {
 660          return false;
 661      }
 662      return $default_views[$type];
 663  }


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref