[ Index ] |
PHP Cross Reference of MyBB |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id$ 10 */ 11 12 // Disallow direct access to this file for security reasons 13 if(!defined("IN_MYBB")) 14 { 15 die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined."); 16 } 17 18 $page->add_breadcrumb_item($lang->calendars, "index.php?module=config-calendars"); 19 20 if($mybb->input['action'] == "add" || $mybb->input['action'] == "permissions" || !$mybb->input['action']) 21 { 22 $sub_tabs['manage_calendars'] = array( 23 'title' => $lang->manage_calendars, 24 'link' => "index.php?module=config-calendars", 25 'description' => $lang->manage_calendars_desc 26 ); 27 $sub_tabs['add_calendar'] = array( 28 'title' => $lang->add_calendar, 29 'link' => "index.php?module=config-calendars&action=add", 30 ); 31 } 32 33 $plugins->run_hooks("admin_config_calendars_begin"); 34 35 if($mybb->input['action'] == "add") 36 { 37 $plugins->run_hooks("admin_config_calendars_add"); 38 39 if($mybb->request_method == "post") 40 { 41 $plugins->run_hooks("admin_config_calendars_add_commit"); 42 43 if(!trim($mybb->input['name'])) 44 { 45 $errors[] = $lang->error_missing_name; 46 } 47 48 if(!isset($mybb->input['disporder'])) 49 { 50 $errors[] = $lang->error_missing_order; 51 } 52 53 if(!$errors) 54 { 55 $calendar = array( 56 "name" => $db->escape_string($mybb->input['name']), 57 "disporder" => intval($mybb->input['disporder']), 58 "startofweek" => intval($mybb->input['startofweek']), 59 "eventlimit" => intval($mybb->input['eventlimit']), 60 "showbirthdays" => intval($mybb->input['showbirthdays']), 61 "moderation" => intval($mybb->input['moderation']), 62 "allowhtml" => $db->escape_string($mybb->input['allowhtml']), 63 "allowmycode" => $db->escape_string($mybb->input['allowmycode']), 64 "allowimgcode" => $db->escape_string($mybb->input['allowimgcode']), 65 "allowvideocode" => $db->escape_string($mybb->input['allowvideocode']), 66 "allowsmilies" => $db->escape_string($mybb->input['allowsmilies']) 67 ); 68 69 $cid = $db->insert_query("calendars", $calendar); 70 71 // Log admin action 72 log_admin_action($cid, $mybb->input['name']); 73 74 flash_message($lang->success_calendar_created, 'success'); 75 admin_redirect("index.php?module=config-calendars"); 76 } 77 } 78 else 79 { 80 $mybb->input = array( 81 "allowhtml" => 0, 82 "eventlimit" => 4, 83 "disporder" => 1, 84 "moderation" => 0 85 ); 86 } 87 88 $page->add_breadcrumb_item($lang->add_calendar); 89 $page->output_header($lang->calendars." - ".$lang->add_calendar); 90 91 $sub_tabs['add_calendar'] = array( 92 'title' => $lang->add_calendar, 93 'link' => "index.php?module=config-calendars&action=add", 94 'description' => $lang->add_calendar_desc 95 ); 96 97 $page->output_nav_tabs($sub_tabs, 'add_calendar'); 98 $form = new Form("index.php?module=config-calendars&action=add", "post"); 99 100 101 if($errors) 102 { 103 $page->output_inline_error($errors); 104 } 105 106 $form_container = new FormContainer($lang->add_calendar); 107 $form_container->output_row($lang->name." <em>*</em>", "", $form->generate_text_box('name', $mybb->input['name'], array('id' => 'name')), 'name'); 108 $form_container->output_row($lang->display_order, $lang->display_order_desc, $form->generate_text_box('disporder', $mybb->input['disporder'], array('id' => 'disporder')), 'disporder'); 109 $select_list = array($lang->sunday, $lang->monday, $lang->tuesday, $lang->wednesday, $lang->thursday, $lang->friday, $lang->saturday); 110 $form_container->output_row($lang->week_start, $lang->week_start_desc, $form->generate_select_box('startofweek', $select_list, $mybb->input['startofweek'], array('id' => 'startofweek')), 'startofweek'); 111 $form_container->output_row($lang->event_limit, $lang->event_limit_desc, $form->generate_text_box('eventlimit', $mybb->input['eventlimit'], array('id' => 'eventlimit')), 'eventlimit'); 112 $form_container->output_row($lang->show_birthdays, $lang->show_birthdays_desc, $form->generate_yes_no_radio('showbirthdays', $mybb->input['showbirthdays'], true)); 113 $form_container->output_row($lang->moderate_events, $lang->moderate_events_desc, $form->generate_yes_no_radio('moderation', $mybb->input['moderation'], true)); 114 $form_container->output_row($lang->allow_html, "", $form->generate_yes_no_radio('allowhtml', $mybb->input['allowhtml'])); 115 $form_container->output_row($lang->allow_mycode, "", $form->generate_yes_no_radio('allowmycode', $mybb->input['allowmycode'])); 116 $form_container->output_row($lang->allow_img, "", $form->generate_yes_no_radio('allowimgcode', $mybb->input['allowimgcode'])); 117 $form_container->output_row($lang->allow_video, "", $form->generate_yes_no_radio('allowvideocode', $mybb->input['allowvideocode'])); 118 $form_container->output_row($lang->allow_smilies, "", $form->generate_yes_no_radio('allowsmilies', $mybb->input['allowsmilies'])); 119 $form_container->end(); 120 121 $buttons[] = $form->generate_submit_button($lang->save_calendar); 122 123 $form->output_submit_wrapper($buttons); 124 $form->end(); 125 126 $page->output_footer(); 127 } 128 129 if($mybb->input['action'] == "permissions") 130 { 131 $plugins->run_hooks("admin_config_calendars_permissions"); 132 133 $query = $db->simple_select("calendars", "*", "cid='".intval($mybb->input['cid'])."'"); 134 $calendar = $db->fetch_array($query); 135 136 // Does the calendar not exist? 137 if(!$calendar['cid']) 138 { 139 flash_message($lang->error_invalid_calendar, 'error'); 140 admin_redirect("index.php?module=config-calendars"); 141 } 142 143 $query = $db->simple_select("usergroups", "*", "", array("order_dir" => "name")); 144 while($usergroup = $db->fetch_array($query)) 145 { 146 $usergroups[$usergroup['gid']] = $usergroup; 147 } 148 149 $query = $db->simple_select("calendarpermissions", "*", "cid='{$calendar['cid']}'"); 150 while($existing = $db->fetch_array($query)) 151 { 152 $existing_permissions[$existing['gid']] = $existing; 153 } 154 155 if($mybb->request_method == "post") 156 { 157 foreach(array_keys($usergroups) as $group_id) 158 { 159 $permissions = $mybb->input['permissions'][$group_id]; 160 $db->delete_query("calendarpermissions", "cid='{$calendar['cid']}' AND gid='".intval($group_id)."'"); 161 162 if(!$mybb->input['default_permissions'][$group_id]) 163 { 164 foreach(array('canviewcalendar','canaddevents','canbypasseventmod','canmoderateevents') as $calendar_permission) 165 { 166 if($permissions[$calendar_permission] == 1) 167 { 168 $permissions_array[$calendar_permission] = 1; 169 } 170 else 171 { 172 $permissions_array[$calendar_permission] = 0; 173 } 174 } 175 $permissions_array['gid'] = intval($group_id); 176 $permissions_array['cid'] = $calendar['cid']; 177 $db->insert_query("calendarpermissions", $permissions_array); 178 } 179 } 180 181 $plugins->run_hooks("admin_config_calendars_permissions_commit"); 182 183 // Log admin action 184 log_admin_action($calendar['cid'], $calendar['name']); 185 186 flash_message($lang->success_calendar_permissions_updated, 'success'); 187 admin_redirect("index.php?module=config-calendars"); 188 } 189 190 $calendar['name'] = htmlspecialchars_uni($calendar['name']); 191 $page->add_breadcrumb_item($calendar['name'], "index.php?module=config-calendars&action=edit&cid={$calendar['cid']}"); 192 $page->add_breadcrumb_item($lang->permissions); 193 $page->output_header($lang->calendars." - ".$lang->edit_permissions); 194 195 $form = new Form("index.php?module=config-calendars&action=permissions", "post"); 196 echo $form->generate_hidden_field("cid", $calendar['cid']); 197 198 $table = new Table; 199 $table->construct_header($lang->permissions_group); 200 $table->construct_header($lang->permissions_view, array("class" => "align_center", "width" => "10%")); 201 $table->construct_header($lang->permissions_post_events, array("class" => "align_center", "width" => "10%")); 202 $table->construct_header($lang->permissions_bypass_moderation, array("class" => "align_center", "width" => "10%")); 203 $table->construct_header($lang->permissions_moderator, array("class" => "align_center", "width" => "10%")); 204 $table->construct_header($lang->permissions_all, array("class" => "align_center", "width" => "10%")); 205 206 foreach($usergroups as $usergroup) 207 { 208 if($existing_permissions[$usergroup['gid']]) 209 { 210 $perms = $existing_permissions[$usergroup['gid']]; 211 $default_checked = false; 212 } 213 else 214 { 215 $perms = $usergroup; 216 $default_checked = true; 217 } 218 $perm_check = $all_check = ""; 219 $all_checked = true; 220 foreach(array('canviewcalendar','canaddevents','canbypasseventmod','canmoderateevents') as $calendar_permission) 221 { 222 if($usergroup[$calendar_permission] == 1) 223 { 224 $value = "true"; 225 } 226 else 227 { 228 $value = "false"; 229 } 230 if($perms[$calendar_permission] != 1) 231 { 232 $all_checked = false; 233 } 234 if($perms[$calendar_permission] == 1) 235 { 236 $perms_checked[$calendar_permission] = 1; 237 } 238 else 239 { 240 $perms_checked[$calendar_permission] = 0; 241 } 242 $all_check .= "\$('permissions_{$usergroup['gid']}_{$calendar_permission}').checked = \$('permissions_{$usergroup['gid']}_all').checked;\n"; 243 $perm_check .= "\$('permissions_{$usergroup['gid']}_{$calendar_permission}').checked = $value;\n"; 244 } 245 $default_click = "if(this.checked == true) { $perm_check }"; 246 $reset_default = "\$('default_permissions_{$usergroup['gid']}').checked = false; if(this.checked == false) { \$('permissions_{$usergroup['gid']}_all').checked = false; }\n"; 247 $usergroup['title'] = htmlspecialchars_uni($usergroup['title']); 248 $table->construct_cell("<strong>{$usergroup['title']}</strong><br /><small style=\"vertical-align: middle;\">".$form->generate_check_box("default_permissions[{$usergroup['gid']}];", 1, "", array("id" => "default_permissions_{$usergroup['gid']}", "checked" => $default_checked, "onclick" => $default_click))." <label for=\"default_permissions_{$usergroup['gid']}\">{$lang->permissions_use_group_default}</label></small>"); 249 $table->construct_cell($form->generate_check_box("permissions[{$usergroup['gid']}][canviewcalendar]", 1, "", array("id" => "permissions_{$usergroup['gid']}_canviewcalendar", "checked" => $perms_checked['canviewcalendar'], "onclick" => $reset_default)), array('class' => 'align_center')); 250 $table->construct_cell($form->generate_check_box("permissions[{$usergroup['gid']}][canaddevents]", 1, "", array("id" => "permissions_{$usergroup['gid']}_canaddevents", "checked" => $perms_checked['canaddevents'], "onclick" => $reset_default)), array('class' => 'align_center')); 251 $table->construct_cell($form->generate_check_box("permissions[{$usergroup['gid']}][canbypasseventmod]", 1, "", array("id" => "permissions_{$usergroup['gid']}_canbypasseventmod", "checked" => $perms_checked['canbypasseventmod'], "onclick" => $reset_default)), array('class' => 'align_center')); 252 $table->construct_cell($form->generate_check_box("permissions[{$usergroup['gid']}][canmoderateevents]", 1, "", array("id" => "permissions_{$usergroup['gid']}_canmoderateevents", "checked" => $perms_checked['canmoderateevents'], "onclick" => $reset_default)), array('class' => 'align_center')); 253 $table->construct_cell($form->generate_check_box("permissions[{$usergroup['gid']}][all]", 1, "", array("id" => "permissions_{$usergroup['gid']}_all", "checked" => $all_checked, "onclick" => $all_check)), array('class' => 'align_center')); 254 $table->construct_row(); 255 } 256 $table->output("{$lang->calendar_permissions_for} {$calendar['name']}"); 257 258 if(!$no_results) 259 { 260 $buttons[] = $form->generate_submit_button($lang->save_permissions); 261 $form->output_submit_wrapper($buttons); 262 } 263 264 $form->end(); 265 266 $page->output_footer(); 267 268 } 269 270 if($mybb->input['action'] == "edit") 271 { 272 $plugins->run_hooks("admin_config_calendars_edit"); 273 274 $query = $db->simple_select("calendars", "*", "cid='".intval($mybb->input['cid'])."'"); 275 $calendar = $db->fetch_array($query); 276 277 // Does the calendar not exist? 278 if(!$calendar['cid']) 279 { 280 flash_message($lang->error_invalid_calendar, 'error'); 281 admin_redirect("index.php?module=config-calendars"); 282 } 283 284 if($mybb->request_method == "post") 285 { 286 if(!trim($mybb->input['name'])) 287 { 288 $errors[] = $lang->error_missing_name; 289 } 290 291 if(!isset($mybb->input['disporder'])) 292 { 293 $errors[] = $lang->error_missing_order; 294 } 295 296 if(!$errors) 297 { 298 $updated_calendar = array( 299 "name" => $db->escape_string($mybb->input['name']), 300 "disporder" => intval($mybb->input['disporder']), 301 "startofweek" => intval($mybb->input['startofweek']), 302 "eventlimit" => intval($mybb->input['eventlimit']), 303 "showbirthdays" => intval($mybb->input['showbirthdays']), 304 "moderation" => intval($mybb->input['moderation']), 305 "allowhtml" => $db->escape_string($mybb->input['allowhtml']), 306 "allowmycode" => $db->escape_string($mybb->input['allowmycode']), 307 "allowimgcode" => $db->escape_string($mybb->input['allowimgcode']), 308 "allowvideocode" => $db->escape_string($mybb->input['allowvideocode']), 309 "allowsmilies" => $db->escape_string($mybb->input['allowsmilies']) 310 ); 311 312 $db->update_query("calendars", $updated_calendar, "cid = '".intval($mybb->input['cid'])."'"); 313 314 $plugins->run_hooks("admin_config_calendars_edit_commit"); 315 316 // Log admin action 317 log_admin_action($calendar['cid'], $mybb->input['name']); 318 319 flash_message($lang->success_calendar_updated, 'success'); 320 admin_redirect("index.php?module=config-calendars"); 321 } 322 } 323 324 $page->add_breadcrumb_item($lang->edit_calendar); 325 $page->output_header($lang->calendars." - ".$lang->edit_calendar); 326 327 $sub_tabs['edit_calendar'] = array( 328 'title' => $lang->edit_calendar, 329 'link' => "index.php?module=config-calendars&action=edit", 330 'description' => $lang->edit_calendar_desc 331 ); 332 333 $page->output_nav_tabs($sub_tabs, 'edit_calendar'); 334 $form = new Form("index.php?module=config-calendars&action=edit", "post"); 335 336 echo $form->generate_hidden_field("cid", $calendar['cid']); 337 338 if($errors) 339 { 340 $page->output_inline_error($errors); 341 } 342 else 343 { 344 $mybb->input = $calendar; 345 } 346 347 $form_container = new FormContainer($lang->edit_calendar); 348 $form_container->output_row($lang->name." <em>*</em>", "", $form->generate_text_box('name', $mybb->input['name'], array('id' => 'name')), 'name'); 349 $form_container->output_row($lang->display_order." <em>*</em>", $lang->display_order_desc, $form->generate_text_box('disporder', $mybb->input['disporder'], array('id' => 'disporder')), 'disporder'); 350 $select_list = array($lang->sunday, $lang->monday, $lang->tuesday, $lang->wednesday, $lang->thursday, $lang->friday, $lang->saturday); 351 $form_container->output_row($lang->week_start, $lang->week_start_desc, $form->generate_select_box('startofweek', $select_list, $mybb->input['startofweek'], array('id' => 'startofweek')), 'startofweek'); 352 $form_container->output_row($lang->event_limit, $lang->event_limit_desc, $form->generate_text_box('eventlimit', $mybb->input['eventlimit'], array('id' => 'eventlimit')), 'eventlimit'); 353 $form_container->output_row($lang->show_birthdays, $lang->show_birthdays_desc, $form->generate_yes_no_radio('showbirthdays', $mybb->input['showbirthdays'], true)); 354 $form_container->output_row($lang->moderate_events, $lang->moderate_events_desc, $form->generate_yes_no_radio('moderation', $mybb->input['moderation'], true)); 355 $form_container->output_row($lang->allow_html, "", $form->generate_yes_no_radio('allowhtml', $mybb->input['allowhtml'])); 356 $form_container->output_row($lang->allow_mycode, "", $form->generate_yes_no_radio('allowmycode', $mybb->input['allowmycode'])); 357 $form_container->output_row($lang->allow_img, "", $form->generate_yes_no_radio('allowimgcode', $mybb->input['allowimgcode'])); 358 $form_container->output_row($lang->allow_video, "", $form->generate_yes_no_radio('allowvideocode', $mybb->input['allowvideocode'])); 359 $form_container->output_row($lang->allow_smilies, "", $form->generate_yes_no_radio('allowsmilies', $mybb->input['allowsmilies'])); 360 $form_container->end(); 361 362 $buttons[] = $form->generate_submit_button($lang->save_calendar); 363 364 $form->output_submit_wrapper($buttons); 365 $form->end(); 366 367 $page->output_footer(); 368 } 369 370 if($mybb->input['action'] == "delete") 371 { 372 $plugins->run_hooks("admin_config_calendars_delete"); 373 374 $query = $db->simple_select("calendars", "*", "cid='".intval($mybb->input['cid'])."'"); 375 $calendar = $db->fetch_array($query); 376 377 // Does the calendar not exist? 378 if(!$calendar['cid']) 379 { 380 flash_message($lang->error_invalid_calendar, 'error'); 381 admin_redirect("index.php?module=config-calendars"); 382 } 383 384 // User clicked no 385 if($mybb->input['no']) 386 { 387 admin_redirect("index.php?module=config-calendars"); 388 } 389 390 if($mybb->request_method == "post") 391 { 392 // Delete the calendar 393 $db->delete_query("calendars", "cid='{$calendar['cid']}'"); 394 $db->delete_query("calendarpermissions", "cid='{$calendar['cid']}'"); 395 $db->delete_query("events", "cid='{$calendar['cid']}'"); 396 397 $plugins->run_hooks("admin_config_calendars_delete_commit"); 398 399 // Log admin action 400 log_admin_action($calendar['cid'], $calendar['name']); 401 402 flash_message($lang->success_calendar_deleted, 'success'); 403 admin_redirect("index.php?module=config-calendars"); 404 } 405 else 406 { 407 $page->output_confirm_action("index.php?module=config-calendars&action=delete&cid={$calendar['cid']}", $lang->confirm_calendar_deletion); 408 } 409 } 410 411 if($mybb->input['action'] == "update_order" && $mybb->request_method == "post") 412 { 413 $plugins->run_hooks("admin_config_calendars_update_order"); 414 415 if(!is_array($mybb->input['disporder'])) 416 { 417 admin_redirect("index.php?module=config-calendars"); 418 } 419 420 foreach($mybb->input['disporder'] as $cid => $order) 421 { 422 $update_query = array( 423 "disporder" => intval($order) 424 ); 425 $db->update_query("calendars", $update_query, "cid='".intval($cid)."'"); 426 } 427 428 $plugins->run_hooks("admin_config_calendars_update_order_commit"); 429 430 // Log admin action 431 log_admin_action(); 432 433 flash_message($lang->success_calendar_orders_updated, 'success'); 434 admin_redirect("index.php?module=config-calendars"); 435 } 436 437 if(!$mybb->input['action']) 438 { 439 $page->output_header($lang->manage_calendars); 440 441 $page->output_nav_tabs($sub_tabs, 'manage_calendars'); 442 443 $form = new Form("index.php?module=config-calendars&action=update_order", "post"); 444 $table = new Table; 445 $table->construct_header($lang->calendar); 446 $table->construct_header($lang->order, array('width' => '5%', 'class' => 'align_center')); 447 $table->construct_header($lang->controls, array("class" => "align_center", "colspan" => 3, "width" => 300)); 448 449 $query = $db->simple_select("calendars", "*", "", array('order_by' => 'disporder')); 450 while($calendar = $db->fetch_array($query)) 451 { 452 $calendar['name'] = htmlspecialchars_uni($calendar['name']); 453 $table->construct_cell("<a href=\"index.php?module=config-calendars&action=edit&cid={$calendar['cid']}\"><strong>{$calendar['name']}</strong></a>"); 454 $table->construct_cell($form->generate_text_box("disporder[{$calendar['cid']}]", $calendar['disporder'], array('id' => 'disporder', 'style' => 'width: 80%', 'class' => 'align_center'))); 455 $table->construct_cell("<a href=\"index.php?module=config-calendars&action=edit&cid={$calendar['cid']}\">{$lang->edit}</a>", array("width" => 100, "class" => "align_center")); 456 $table->construct_cell("<a href=\"index.php?module=config-calendars&action=permissions&cid={$calendar['cid']}\">{$lang->permissions}</a>", array("width" => 100, "class" => "align_center")); 457 $table->construct_cell("<a href=\"index.php?module=config-calendars&action=delete&cid={$calendar['cid']}&my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_calendar_deletion}')\">{$lang->delete}</a>", array("width" => 100, "class" => "align_center")); 458 $table->construct_row(); 459 } 460 461 if($table->num_rows() == 0) 462 { 463 $table->construct_cell($lang->no_calendars, array('colspan' => 5)); 464 $table->construct_row(); 465 $no_results = true; 466 } 467 468 $table->output($lang->manage_calendars); 469 470 if(!$no_results) 471 { 472 $buttons[] = $form->generate_submit_button($lang->save_calendar_orders); 473 $form->output_submit_wrapper($buttons); 474 } 475 476 $form->end(); 477 478 $page->output_footer(); 479 } 480 481 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |