00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 function og_forums_admin_settings() {
00016 drupal_add_css(drupal_get_path('module', 'og_forums') .'/og_forums.admin.css');
00017
00018
00019 $description_structure = '<p>'. t('Here you can define a pre-configured structure for creating new groups forums.') .'</p>';
00020 $description_structure .= '<p>'. t('It can be used a simple or multiple structure. More information can be found in the module help.') .'</p>';
00021 $form['structure'] = array(
00022 '#type' => 'fieldset',
00023 '#title' => t('Forum structure'),
00024 '#description' => $description_structure,
00025 '#collapsible' => TRUE,
00026 );
00027 $current_default_name = t('General discussion;Other');
00028 $form['structure']['og_forums_default_name'] = array(
00029 '#type' => 'textfield',
00030 '#title' => t('Default forum structure'),
00031 '#description' => t('When a new group is created then the structure defined here is used. Note: But this will only be realized if the option <em>Same container</em> is activated.'),
00032 '#default_value' => variable_get('og_forums_default_name', $current_default_name),
00033 '#required' => TRUE,
00034 );
00035 $form['structure']['og_forums_default_container_yn'] = array(
00036 '#type' => 'checkbox',
00037 '#title' => t('Same container'),
00038 '#description' => t('The name of the container matches the name of the group. If you would like groups forums structures to all be under one container?'),
00039 '#default_value' => variable_get('og_forums_default_container_yn', TRUE),
00040 );
00041
00042
00043 $form['container'] = array(
00044 '#type' => 'fieldset',
00045 '#title' => t('Groups forums container'),
00046 '#collapsible' => TRUE,
00047 );
00048
00049 $forum_containers = variable_get('forum_containers', array());
00050
00051 $sql = "SELECT tid, name FROM {term_data} WHERE tid NOT IN (SELECT tid FROM {og_terms})";
00052 $result = db_query($sql);
00053
00054 $containers = array();
00055 $containers[-1] = t('No one');
00056 while ($term = db_fetch_object($result)) {
00057 if (in_array($term->tid, $forum_containers)) {
00058 $containers[$term->tid] = check_plain($term->name);
00059 }
00060 }
00061
00062 $form['container']['og_forums_default_container'] = array(
00063 '#type' => 'select',
00064 '#title' => t('Default container'),
00065 '#description' => t('All groups forums will be placed in a common container. You need to have setup the container before hand.'),
00066 '#default_value' => variable_get('og_forums_default_container', 0),
00067 '#options' => $containers,
00068 );
00069
00070
00071 $form['quota'] = array(
00072 '#type' => 'fieldset',
00073 '#title' => t('Forum quota'),
00074 '#description' => t('Limit number of forums per group.'),
00075 '#collapsible' => TRUE,
00076 );
00077 $form['quota']['og_forums_limit_forums'] = array(
00078 '#type' => 'select',
00079 '#title' => t('Quota'),
00080 '#description' => t('Set the number of forums a group can have. When forums are defined in the %structure field, then their number must be calculated here.', array('%structure' => t('Default forum structure'))),
00081 '#options' => _og_forums_quota(),
00082 '#default_value' => variable_get('og_forums_limit_forums', 7),
00083 );
00084 $form['quota']['og_forums_quota_message'] = array(
00085 '#type' => 'checkbox',
00086 '#title' => t('Display quota message'),
00087 '#description' => t('If the number of groups forums is limited, a group manager receives a message when the limit is reached. This message is displayed in the management of the forums of the group.'),
00088 '#default_value' => variable_get('og_forums_quota_message', 1),
00089 );
00090 $form['quota']['og_forums_add_link'] = array(
00091 '#type' => 'checkbox',
00092 '#title' => t('Display %link link', array('%link' => t('add forum'))),
00093 '#description' => t('If not reached the quota limit is displayed a %link link. This link is displayed in the management of the forums of the group.', array('%link' => t('add forum'))),
00094 '#default_value' => variable_get('og_forums_add_link', 1),
00095 );
00096
00097
00098 $form['availability'] = array(
00099 '#type' => 'fieldset',
00100 '#title' => t('Forum availability'),
00101 '#description' => ('The forum function is available by default in each group. Here you can allow the group managers to disable or enable this function for their groups.'),
00102 '#collapsible' => TRUE,
00103 );
00104 $form['availability']['og_forums_availability_grant'] = array(
00105 '#type' => 'checkbox',
00106 '#title' => t('Availability permission'),
00107 '#description' => t('Permission for group managers to disable the the forums function.'),
00108 '#default_value' => variable_get('og_forums_availability_grant', 1),
00109 );
00110
00111
00112 $form['update'] = array(
00113 '#type' => 'fieldset',
00114 '#title' => t('Retroactively update old groups'),
00115 '#description' => t('Pressing this button will create forums for any groups that do not already have them.'),
00116 '#collapsible' => TRUE,
00117 );
00118 $form['update']['button'] = array(
00119 '#type' => 'submit',
00120 '#name' => 'update_old_groups',
00121 '#value' => t('Update old groups'),
00122 );
00123
00124
00125 $form['main_visibility'] = array(
00126 '#type' => 'fieldset',
00127 '#title' => t('Main visibility'),
00128 '#description' => t('Visibility of the OG Forums in the main forum list.'),
00129 '#collapsible' => TRUE,
00130 );
00131 $form['main_visibility']['og_forums_main_visibility'] = array(
00132 '#type' => 'select',
00133 '#description' => t('Please choose the visibility.'),
00134 '#options' => array(
00135 0 => t('No, not visible in the main list.'),
00136 1 => t('Yes, visible in the main list.'),
00137 ),
00138 '#default_value' => variable_get('og_forums_main_visibility', 0),
00139 );
00140
00141
00142 $form['public_forums'] = array(
00143 '#type' => 'fieldset',
00144 '#title' => t('Forum publicity'),
00145 '#description' => t('Using these features is probably expensive in terms of SQL queries.'),
00146 '#collapsible' => TRUE,
00147 );
00148 $form['public_forums']['og_forums_auto_public'] = array(
00149 '#type' => 'checkbox',
00150 '#title' => t('Automatic forum publicity'),
00151 '#description' => t('If you would like to make the publicity, or public-ness, of forums automatic based on whether there are any public posts inside
00152 of them, then check this box.'),
00153 '#default_value' => variable_get('og_forums_auto_public', 0),
00154 );
00155 $form['public_forums']['og_forums_allow_public'] = array(
00156 '#type' => 'checkbox',
00157 '#title' => t('Allow public choice'),
00158 '#description' => t('If you would like to allow group owners the ability to decide which, if any, of their forums are publicly viewable, check the box.
00159 Those with the <em>make forums public</em> permission can always make forums and containers public. If auto mode is checked, above, then this will
00160 allow group owners to override auto settings on a case by case basis. The auto mode respects group owner-set values.'),
00161 '#default_value' => variable_get('og_forums_allow_public', 0),
00162 );
00163 $form['public_forums']['og_forums_all_public'] = array(
00164 '#type' => 'checkbox',
00165 '#title' => t('Make all forums public'),
00166 '#description' => t('This is only a display option and will not affect database entries. If you have both boxes unchecked above and no users assigned
00167 to the <em>make forums public</em> permission, no database entries will be made as to the publicity of forums, but all will be visible and traversable.
00168 User 1 can still affect the database through the normal "make public" and "make private" functionality, but such changes won\'t affect the forums\'
00169 display until such time as this feature is disabled. Individual posts will be public or private based on their own settings, just like if the above
00170 features are used. This is an easy way to get all forums visible to all users so they can see what posts they are missing out on (in the case where posts
00171 are private themselves). With this setting, no forums can be private. You could use this feature during a promotion period to temporarily open the whole
00172 site to guests.'),
00173 '#default_value' => variable_get('og_forums_all_public', 0),
00174 );
00175 $form['public_forums']['pb'] = array(
00176 '#type' => 'fieldset',
00177 '#title' => t('Manage publicity of old groups'),
00178 '#description' => t('If you check the "Automatic forum publicity" box, this will go through all existing forums and set them accordingly.
00179 Otherwise, a public forum topic will need to be created or resaved in each forum. You don\'t need to click this if you haven\'t checked that box.
00180 <strong>You should use this only once - usually the first time you upgrade to a version with this feature as it will not respect settings made by
00181 group owners.</strong>'),
00182 );
00183 $form['public_forums']['pb']['public_button'] = array(
00184 '#type' => 'submit',
00185 '#name' => 'public_button',
00186 '#value' => t('Publicize old groups'),
00187 );
00188 $form['public_forums']['rp'] = array(
00189 '#type' => 'fieldset',
00190 '#title' => t('Switch to automatic publicity'),
00191 '#description' => t('This will switch all group admin-set publicity values to automatic values. PUBLIC_BY_GROUP_OWNER -> PUBLIC_AUTO, PRIVATE_BY_GROUP_OWNER -> PRIVATE_DEFAULT. This will allow you to switch a site from
00192 group admin-controlled publicity to automatic publicity of forums.'),
00193 );
00194 $form['public_forums']['rp']['switch_auto'] = array(
00195 '#type' => 'submit',
00196 '#name' => 'switch_auto',
00197 '#value' => t('Switch to auto mode'),
00198 );
00199
00200
00201 $form['template']['og_forums_access'] = array(
00202 '#type' => 'fieldset',
00203 '#title' => t('Access templates'),
00204 '#description' => t('You can use the access templates as defaults for new groups forums and group containers. The templates are used when the group manager create forums. It is recommended to use this functionality.'),
00205 '#collapsible' => TRUE,
00206 '#suffix' => '<div style="text-align: right;">'. t('Module Development by') .' '. l('Quiptime Group', 'http://www.quiptime.com', array('attributes' => array('target' => '_blank'))) . '</div>',
00207 );
00208 $form['template']['og_forums_access']['og_forums_access_template'] = array(
00209 '#type' => 'checkbox',
00210 '#title' => t('Use access templates'),
00211 '#description' => '',
00212 '#default_value' => variable_get('og_forums_access_template', 1),
00213 );
00214 $form['template']['og_forums_access']['container'] = array(
00215 '#type' => 'fieldset',
00216 '#title' => t('Container'),
00217 '#collapsible' => TRUE,
00218 '#collapsed' => TRUE,
00219 );
00220 _og_forums_access_template_form(&$form, &$form_state, 'container');
00221
00222 $form['template']['og_forums_access']['forum'] = array(
00223 '#type' => 'fieldset',
00224 '#title' => t('Forum'),
00225 '#collapsible' => TRUE,
00226 '#collapsed' => TRUE,
00227 );
00228 _og_forums_access_template_form(&$form, &$form_state, 'forum');
00229
00230 $form['#submit'][] = 'og_forums_settings_submit';
00231
00232 return system_settings_form($form);
00233 }
00234
00235
00236
00237
00238
00239
00240 function og_forums_admin_settings_validate($form, &$form_state) {
00241 $not_saved = t('The configuration options were not saved.');
00242
00243
00244 if (strlen($form_state['values']['og_forums_default_name']) == 0) {
00245 drupal_set_message($not_saved, 'error');
00246 $names_error = t('There is no forum for the groups in the %structure. Please enter at least 1 name for a forum.', array('%structure' => t('Forum structure')));
00247 form_set_error('og_forums_default_name', $names_error);
00248 }
00249
00250
00251 if (strlen($form_state['values']['og_forums_default_name']) >= 1 && $form_state['values']['og_forums_default_container_yn'] == 1) {
00252 $default_name = _og_forums_clean_forum_names($form_state['values']['og_forums_default_name']);
00253 $forum_names = explode(';', $default_name);
00254
00255
00256 $count = 0;
00257 foreach ($forum_names as $key => $name) {
00258 $count++;
00259 if (strtoupper($name) == 'C') {
00260 $count--;
00261 $count--;
00262 }
00263 elseif (strtoupper($name) == 'R' || strtoupper($name) == 'P') {
00264 $count--;
00265 }
00266 }
00267
00268 if ($form_state['values']['og_forums_limit_forums'] > 0 && $form_state['values']['og_forums_limit_forums'] < $count) {
00269 drupal_set_message($not_saved, 'error');
00270 $names_error = t('The <em>Forum quota</em> of <strong>!quota</strong> is smaller than the number of <strong>!names</strong> forums in the <em>Forum structure</em>. Please increase the quota or reduce the number of forums.', array('!quota' => $form_state['values']['og_forums_limit_forums'], '!names' => $count));
00271 form_set_error('og_forums_default_name', $names_error);
00272 }
00273 }
00274 }
00275
00276
00277
00278
00279
00280
00281 function og_forums_settings_submit($form, &$form_state) {
00282 if ($form_state['clicked_button']['#name'] == 'update_old_groups') {
00283 og_forums_retroactively_apply();
00284 }
00285 elseif ($form_state['clicked_button']['#name'] == 'public_button') {
00286 $auto_public = variable_get('og_forums_auto_public', 0);
00287 if ($auto_public) {
00288
00289 $sql = "SELECT DISTINCT tn.tid, oa.group_nid FROM {node} n
00290 INNER JOIN {og_ancestry} oa ON oa.nid = n.nid
00291 INNER JOIN {og_access_post} oap ON oap.nid = oa.nid
00292 INNER JOIN {term_node} tn ON tn.nid = oa.nid
00293 WHERE n.type = 'forum' AND oap.og_public = 1";
00294 $results = db_query($sql);
00295
00296 while ($result = db_fetch_object($results)) {
00297 $gid = $result->group_nid;
00298 $container = og_forums_get_forum_container($gid);
00299 $sql2 = "UPDATE {og_terms} SET public = %d WHERE tid = %d and nid = %d";
00300 db_query($sql2, PUBLIC_AUTO, $result->tid, $gid);
00301 db_query($sql2, PUBLIC_AUTO, $container, $gid);
00302 }
00303 }
00304 else {
00305 drupal_set_message(t('You need to select "Automatic forum publicity" for this to work.'), 'error');
00306 }
00307 }
00308 elseif ($form_state['clicked_button']['#name'] == 'switch_auto') {
00309 $sql = "UPDATE {og_terms} SET public = %d WHERE public = %d";
00310 db_query($sql, PUBLIC_AUTO, PUBLIC_BY_GROUP_OWNER);
00311 db_query($sql, PRIVATE_DEFAULT, PRIVATE_BY_GROUP_OWNER);
00312 }
00313
00314 if ($form_state['clicked_button']['#id'] == 'edit-submit') {
00315 variable_set('og_forums_default_name', $form_state['values']['og_forums_default_name']);
00316 variable_set('og_forums_default_container_yn', $form_state['values']['og_forums_default_container_yn']);
00317 variable_set('og_forums_default_container', $form_state['values']['og_forums_default_container']);
00318 variable_set('og_forums_allow_public', $form_state['values']['og_forums_allow_public']);
00319 variable_set('og_forums_auto_public', $form_state['values']['og_forums_auto_public']);
00320 variable_set('og_forums_all_public', $form_state['values']['og_forums_all_public']);
00321 variable_set('og_forums_limit_forums', $form_state['values']['og_forums_limit_forums']);
00322
00323
00324 $access_template_container = array(
00325 DRUPAL_AUTHENTICATED_RID => array(
00326 'grant_view' => $form_state['values']['container-view'],
00327 'grant_create' => $form_state['values']['container-create'],
00328 'priority' => 0,
00329 ),
00330 );
00331 $access_template_forum = array(
00332 DRUPAL_ANONYMOUS_RID => array(
00333 'grant_view' => 0,
00334 'grant_update' => 0,
00335 'grant_delete' => 0,
00336 'grant_create' => 0,
00337 'priority' => 0,
00338 ),
00339 DRUPAL_AUTHENTICATED_RID => array(
00340 'grant_view' => $form_state['values']['forum-view'],
00341 'grant_update' => $form_state['values']['forum-update'],
00342 'grant_delete' => $form_state['values']['forum-delete'],
00343 'grant_create' => $form_state['values']['forum-create'],
00344 'priority' => 0,
00345 ),
00346 );
00347 variable_set('og_forums_access_template_container', $access_template_container);
00348 variable_set('og_forums_access_template_forum', $access_template_forum);
00349 }
00350 }
00351
00352
00353
00354
00355
00356
00357 function _og_forums_access_template_form(&$form, &$form_state, $op) {
00358 $tpl_settings_container = variable_get('og_forums_access_template_container', _og_forums_access_template_container_default());
00359 $tpl_settings_forum = variable_get('og_forums_access_template_forum', _og_forums_access_template_forum_default());
00360
00361 $roles = array();
00362 $result = db_query(db_rewrite_sql("SELECT r.rid, r.name FROM {role} r WHERE rid = ". DRUPAL_AUTHENTICATED_RID ." ORDER BY r.name", 'r', 'rid'));
00363 while ($obj = db_fetch_object($result)) {
00364 $roles[$obj->rid] = check_plain($obj->name);
00365 }
00366
00367 if ($op == 'container') {
00368 $is_container = TRUE;
00369 }
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380 $forum_vocabulary = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', ''));
00381 $form['template']['og_forums_access'][$op]['headers'][$op .'-create'] = array(
00382 '#type' => 'item',
00383 '#prefix' => '<div class="forum-access-div">',
00384 '#title' => t('See this container in the %Forums selection list', array('%Forums' => $forum_vocabulary->name)),
00385 '#suffix' => '</div>',
00386 );
00387
00388 if (!$is_container) {
00389 $form['template']['og_forums_access'][$op]['headers'][$op .'-create'] = array(
00390 '#type' => 'item',
00391 '#prefix' => '<div class="forum-access-div">',
00392 '#title' => t('Post in this forum'),
00393 '#suffix' => '</div>',
00394 );
00395
00396 $form['template']['og_forums_access'][$op]['headers'][$op .'-update'] = array(
00397 '#type' => 'item',
00398 '#prefix' => '<div class="forum-access-div">',
00399 '#title' => t('Edit posts'),
00400 '#suffix' => '</div>',
00401 );
00402 $form['template']['og_forums_access'][$op]['headers'][$op .'-delete'] = array(
00403 '#type' => 'item',
00404 '#prefix' => '<div class="forum-access-div">',
00405 '#title' => t('Delete posts'),
00406 '#suffix' => '</div>',
00407 );
00408 }
00409 $form['template']['og_forums_access'][$op]['headers']['clearer'] = array(
00410 '#value' => '<div class="forum-access-clearer"></div>',
00411 );
00412
00413
00414 if ($is_container) {
00415 $form['template']['og_forums_access'][$op][$op .'-view'] = array(
00416 '#type' => 'checkbox',
00417 '#title' => $roles[DRUPAL_AUTHENTICATED_RID],
00418 '#prefix' => '<div class="forum-access-div">',
00419 '#suffix' => '</div>',
00420 '#default_value' => _og_forums_template_value($op, 'grant_view'),
00421 );
00422 $form['template']['og_forums_access'][$op][$op .'-create'] = array(
00423 '#type' => 'checkbox',
00424 '#title' => $roles[DRUPAL_AUTHENTICATED_RID],
00425 '#prefix' => '<div class="forum-access-div">',
00426 '#suffix' => '</div>',
00427 '#default_value' => _og_forums_template_value($op, 'grant_create'),
00428 );
00429 }
00430
00431 if (!$is_container) {
00432 $form['template']['og_forums_access'][$op][$op .'-view'] = array(
00433 '#type' => 'checkbox',
00434 '#title' => $roles[DRUPAL_AUTHENTICATED_RID],
00435 '#prefix' => '<div class="forum-access-div">',
00436 '#suffix' => '</div>',
00437 '#default_value' => _og_forums_template_value($op, 'grant_view'),
00438 );
00439 $form['template']['og_forums_access'][$op][$op .'-create'] = array(
00440 '#type' => 'checkbox',
00441 '#title' => $roles[DRUPAL_AUTHENTICATED_RID],
00442 '#prefix' => '<div class="forum-access-div">',
00443 '#suffix' => '</div>',
00444 '#default_value' => _og_forums_template_value($op, 'grant_create'),
00445 );
00446 $form['template']['og_forums_access'][$op][$op .'-update'] = array(
00447 '#type' => 'checkbox',
00448 '#title' => $roles[DRUPAL_AUTHENTICATED_RID],
00449 '#prefix' => '<div class="forum-access-div">',
00450 '#suffix' => '</div>',
00451 '#default_value' => _og_forums_template_value($op, 'grant_update'),
00452 );
00453 $form['template']['og_forums_access'][$op][$op .'-delete'] = array(
00454 '#type' => 'checkbox',
00455 '#title' => $roles[DRUPAL_AUTHENTICATED_RID],
00456 '#prefix' => '<div class="forum-access-div">',
00457 '#suffix' => '</div>',
00458 '#default_value' => _og_forums_template_value($op, 'grant_delete'),
00459 );
00460 }
00461
00462 drupal_add_css(drupal_get_path('module', 'forum_access') .'/forum_access.css');
00463 }
00464
00465
00466
00467
00468
00469
00470 function _og_forums_template_value($op, $param) {
00471 $tpl_settings_container = variable_get('og_forums_access_template_container', _og_forums_access_template_container_default());
00472 $tpl_settings_forum = variable_get('og_forums_access_template_forum', _og_forums_access_template_forum_default());
00473
00474 if ($op == 'forum') {
00475 $value[$param] = $tpl_settings_forum[DRUPAL_AUTHENTICATED_RID][$param] ? isset($tpl_settings_forum[DRUPAL_AUTHENTICATED_RID][$param]) : 0;
00476 }
00477 elseif ($op == 'container') {
00478 $value[$param] = $tpl_settings_container[DRUPAL_AUTHENTICATED_RID][$param] ? isset($tpl_settings_forum[DRUPAL_AUTHENTICATED_RID][$param]) : 0;
00479 }
00480
00481 return $value[$param];
00482 }
00483
00484
00485
00486
00487
00488
00489 function _og_forums_quota() {
00490 $numbers = array(0 => t('No limitation')) + drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30, 35, 40, 45, 50));
00491 return $numbers;
00492 }