--- C:/Documents and Settings/Aldo/Local Settings/Temp/TCV8a3c.tmp/node_limitnumber.1.5.module Mon Jun 23 09:42:21 2008 +++ D:/drupal cvs/5.x/contributions/modules/node_limitnumber/node_limitnumber.module Mon Jun 23 09:34:36 2008 @@ -121,16 +121,47 @@ */ function node_limitnumber_nodeapi ($node, $op) { include_once ('node_limitnumber.inc'); + global $user; - if (($op == 'prepare' || $op == 'submit') && $user->uid != 1 && !$node->nid) { - $limit = _get_limits_for_user ($user, $node->type); + if (!$node->nid) { + $account = $user; + } else { + $account = user_load(array('uid' => $node->uid)); + } + + if (($op == 'prepare' || $op == 'submit')) { + $limit = _get_limits_for_user ($account, $node->type); if (!empty($limit)) { // We get the total number of nodes of this type owned by this user + $type_name = node_get_types('name', $node); $q = "SELECT * FROM {node} WHERE type = '%s' AND uid = %d"; - $result = db_num_rows(db_query( $q, $node->type, $user->uid)); - if ($result >= $limit) {// We have the data, now we check the limit - $nodetypename = node_get_types('name', $node); - drupal_set_message (t("You can't create more content of type !type, sorry.", array ('!type' => $nodetypename)), 'error'); + $count = db_num_rows(db_query( $q, $node->type, $account->uid)); + + // We have the data, now we check the limit + if (!$node->nid && $user->uid != 1) { + // This is an attempt to create a new post + if ($count >= $limit) { + drupal_set_message (t("You have reached the maximum of !limit number of @type items you may post.", array ('!limit' => $limit, '@type' => $type_name)), 'error'); drupal_goto ('node/add'); + } else { + drupal_set_message (t("This is item !count out of a maximum number of !limit of @type items you may post.", array ('!count' => $count+1, '!limit' => $limit, '@type' => $type_name)),NULL,false); + } + } else { + if($user->uid == $account->uid) { + // The user is editing an existing post + if ($count >= $limit) { + drupal_set_message ('
' . t("You have reached the maximum of !limit number of @type items you may post.", array ('!limit' => $limit, '@type' => $type_name)) . + '
' . t('You can\'t create any more items of this type, but you can edit this item.') . '
' ); + } else { + drupal_set_message (t("You have created !count out of a maximum number of !limit of @type items you may post.", array ('!count' => $count, '!limit' => $limit, '@type' => $type_name))); + } + } else { + // The user is editing someone else's exisiting post + if ($count >= $limit) { + drupal_set_message (t("@name has reached the maximum of !limit number of @type items.", array ('@name' => $account->name, '!limit' => $limit, '@type' => $type_name))); + } else { + drupal_set_message (t("@name has created !count out of a maximum number of !limit of @type items.", array ('@name' => $account->name, '!count' => $count, '!limit' => $limit, '@type' => $type_name))); + } + } } } }