--- Downloads/tac_lite/tac_lite.module 2010-10-23 02:46:48.000000000 +0600 +++ www/drupal/sites/all/modules/tac_lite/tac_lite.module 2011-02-03 16:58:29.528600001 +0600 @@ -223,6 +223,13 @@ function tac_lite_admin_scheme_form($for '#description' => t('If checked, this scheme determines whether a user can view terms. Note the view permission in the select field above refers to node visibility. This checkbox refers to term visibility, for example in a content edit form or tag cloud.'), '#default_value' => $config['term_visibility'], ); + + $form['tac_lite_config_scheme_' . $i]['automatic_permission'] = array( + '#type' => 'checkbox', + '#title' => t('Automatic permissions for new terms'), + '#description' => t('This option allows automatically give the same permissions to new term that its parent has.'), + '#default_value' => $config['automatic_permission'], + ); $form['helptext'] = array( '#type' => 'markup', @@ -548,3 +555,91 @@ function tac_lite_db_rewrite_sql($query, return array('join' => $join, 'where' => $where); } } + + + + +function tac_lite_taxonomy($op, $type, $array = NULL) +{ + global $user; + + if ($op == "insert" && $type == "term") + { + $tac_lite_categories = variable_get('tac_lite_categories', 0); + $current_tid = $array['tid']; + $current_vid = $array['vid']; + + if (in_array($current_vid, $tac_lite_categories)) + { + $parents = taxonomy_get_parents($current_tid); + $schemes_number = variable_get('tac_lite_schemes', NULL); + + for ($i = 1; $i <= $schemes_number; $i++) + { + $configs = _tac_lite_config($i); + + if ($configs['automatic_permission']) + { + $grants_scheme = variable_get('tac_lite_grants_scheme_'.$i, NULL); + + foreach ($grants_scheme as $rid => $vocabularies_restricted) + { + foreach ($vocabularies_restricted as $vid => $terms_restricted) + { + foreach ($terms_restricted as $tid) + { + if (array_key_exists($tid, $parents)) + { + $grants_scheme[$rid][$vid][$current_tid] = $current_tid; + + } + } + } + } + variable_set('tac_lite_grants_scheme_'.$i, $grants_scheme); + + + // per-user terms + + + $realm = $configs['realm']; + + $result = db_query("SELECT u.uid FROM {users} u WHERE u.uid > '%d'", 1); + + while ($row = db_fetch_object($result)) + { + + $uid = $row->uid; + $user_loaded = user_load($user_info = array('uid' => $uid)); + if (isset($user_loaded->$realm) && count($user_loaded->$realm)) + { + $user_realm = $user_loaded->$realm; + foreach ($user_realm as $vid => $tids) + { + foreach ($tids as $tid) + { + if (array_key_exists($tid, $parents)) + { + $user_realm[$vid][$current_tid] = $current_tid; + } + } + } + user_save($user_loaded, array($realm => $user_realm), $category = 'account'); + } + } + } + } + } + } +} + + + + + + + + + + +