// Implementation of hook_user(). // // This just add a field in the user profile showing how much // quota this user has left. function quota_by_role_user($op, &$edit, &$account, $category = NULL) { switch ($op) { case 'view': //We are in "My Account" //We check the quota of the user $sql_result1 = db_query("SELECT q.limit_to, q.per FROM {quota_by_role_rules} q JOIN {role} r ON (q.rid = r.rid) JOIN {users_roles} dur ON (r.rid = dur.rid) WHERE dur.uid = %d ORDER BY q.weight ASC,q.qid ASC LIMIT 1", $account->uid); //if useful, we check his posts if ($quota = db_fetch_object($sql_result1) and $account->uid != 1) { $count = (int)_quota_by_role_fetch_count('all', $quota->per, $account->uid); switch($quota->per) { case 60 : $per = t('minute'); break; case 60*60 : $per = t('hour'); break; case 60*60*24 : $per = t('day'); break; case 60*60*24*7 : $per = t('week'); break; case 60*60*24*30 : $per = t('month'); break; case 999999999 : $per = t('forever'); break; } return array( t('Quota left') => array( 'Quota' => array( 'title' => 'quota left', 'value' => t('You have @left / @total posts left for the @period .', array('@left' => $quota->limit_to - $count, '@total' => $quota->limit_to, '@period' => $per)), 'class' => 'member' ))); } else { return array( t('Quota left') => array('Quota' =>array('title' => 'Global quota left', 'value' => t('You are not limited by any quota.'), 'class' => 'member'))); } break; } }